1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.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
52 #include "elf/alpha.h"
71 #include "elf/m68hc11.h"
72 #include "elf/mcore.h"
75 #include "elf/mn10200.h"
76 #include "elf/mn10300.h"
82 #include "elf/sparc.h"
85 #include "elf/x86-64.h"
86 #include "elf/xstormy16.h"
91 char * program_name
= "readelf";
92 unsigned int dynamic_addr
;
93 bfd_size_type dynamic_size
;
94 unsigned int rela_addr
;
95 unsigned int rela_size
;
96 char * dynamic_strings
;
98 unsigned long string_table_length
;
99 unsigned long num_dynamic_syms
;
100 Elf_Internal_Sym
* dynamic_symbols
;
101 Elf_Internal_Syminfo
* dynamic_syminfo
;
102 unsigned long dynamic_syminfo_offset
;
103 unsigned int dynamic_syminfo_nent
;
104 char program_interpreter
[64];
105 int dynamic_info
[DT_JMPREL
+ 1];
106 int version_info
[16];
108 Elf_Internal_Ehdr elf_header
;
109 Elf_Internal_Shdr
* section_headers
;
110 Elf_Internal_Dyn
* dynamic_segment
;
111 Elf_Internal_Shdr
* symtab_shndx_hdr
;
119 int do_using_dynamic
;
127 int do_debug_abbrevs
;
129 int do_debug_pubnames
;
130 int do_debug_aranges
;
132 int do_debug_frames_interp
;
133 int do_debug_macinfo
;
140 /* A dynamic array of flags indicating which sections require dumping. */
141 char * dump_sects
= NULL
;
142 unsigned int num_dump_sects
= 0;
144 #define HEX_DUMP (1 << 0)
145 #define DISASS_DUMP (1 << 1)
146 #define DEBUG_DUMP (1 << 2)
148 /* How to rpint a vma value. */
149 typedef enum print_mode
161 /* Forward declarations for dumb compilers. */
162 static void print_vma
PARAMS ((bfd_vma
, print_mode
));
163 static void print_symbol
PARAMS ((int, char *));
164 static bfd_vma (* byte_get
) PARAMS ((unsigned char *, int));
165 static bfd_vma byte_get_little_endian
PARAMS ((unsigned char *, int));
166 static bfd_vma byte_get_big_endian
PARAMS ((unsigned char *, int));
167 static const char * get_mips_dynamic_type
PARAMS ((unsigned long));
168 static const char * get_sparc64_dynamic_type
PARAMS ((unsigned long));
169 static const char * get_ppc64_dynamic_type
PARAMS ((unsigned long));
170 static const char * get_parisc_dynamic_type
PARAMS ((unsigned long));
171 static const char * get_dynamic_type
PARAMS ((unsigned long));
172 static int slurp_rela_relocs
PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela
**, unsigned long *));
173 static int slurp_rel_relocs
PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel
**, unsigned long *));
174 static int dump_relocations
PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*, unsigned long, char *, int));
175 static char * get_file_type
PARAMS ((unsigned));
176 static char * get_machine_name
PARAMS ((unsigned));
177 static void decode_ARM_machine_flags
PARAMS ((unsigned, char []));
178 static char * get_machine_flags
PARAMS ((unsigned, unsigned));
179 static const char * get_mips_segment_type
PARAMS ((unsigned long));
180 static const char * get_parisc_segment_type
PARAMS ((unsigned long));
181 static const char * get_ia64_segment_type
PARAMS ((unsigned long));
182 static const char * get_segment_type
PARAMS ((unsigned long));
183 static const char * get_mips_section_type_name
PARAMS ((unsigned int));
184 static const char * get_parisc_section_type_name
PARAMS ((unsigned int));
185 static const char * get_ia64_section_type_name
PARAMS ((unsigned int));
186 static const char * get_section_type_name
PARAMS ((unsigned int));
187 static const char * get_symbol_binding
PARAMS ((unsigned int));
188 static const char * get_symbol_type
PARAMS ((unsigned int));
189 static const char * get_symbol_visibility
PARAMS ((unsigned int));
190 static const char * get_symbol_index_type
PARAMS ((unsigned int));
191 static const char * get_dynamic_flags
PARAMS ((bfd_vma
));
192 static void usage
PARAMS ((void));
193 static void parse_args
PARAMS ((int, char **));
194 static int process_file_header
PARAMS ((void));
195 static int process_program_headers
PARAMS ((FILE *));
196 static int process_section_headers
PARAMS ((FILE *));
197 static int process_unwind
PARAMS ((FILE *));
198 static void dynamic_segment_mips_val
PARAMS ((Elf_Internal_Dyn
*));
199 static void dynamic_segment_parisc_val
PARAMS ((Elf_Internal_Dyn
*));
200 static int process_dynamic_segment
PARAMS ((FILE *));
201 static int process_symbol_table
PARAMS ((FILE *));
202 static int process_syminfo
PARAMS ((FILE *));
203 static int process_section_contents
PARAMS ((FILE *));
204 static void process_mips_fpe_exception
PARAMS ((int));
205 static int process_mips_specific
PARAMS ((FILE *));
206 static int process_file
PARAMS ((char *));
207 static int process_relocs
PARAMS ((FILE *));
208 static int process_version_sections
PARAMS ((FILE *));
209 static char * get_ver_flags
PARAMS ((unsigned int));
210 static int get_32bit_section_headers
PARAMS ((FILE *, unsigned int));
211 static int get_64bit_section_headers
PARAMS ((FILE *, unsigned int));
212 static int get_32bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
213 static int get_64bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
214 static int get_file_header
PARAMS ((FILE *));
215 static Elf_Internal_Sym
* get_32bit_elf_symbols
PARAMS ((FILE *, Elf_Internal_Shdr
*));
216 static Elf_Internal_Sym
* get_64bit_elf_symbols
PARAMS ((FILE *, Elf_Internal_Shdr
*));
217 static const char * get_elf_section_flags
PARAMS ((bfd_vma
));
218 static int * get_dynamic_data
PARAMS ((FILE *, unsigned int));
219 static int get_32bit_dynamic_segment
PARAMS ((FILE *));
220 static int get_64bit_dynamic_segment
PARAMS ((FILE *));
221 #ifdef SUPPORT_DISASSEMBLY
222 static int disassemble_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
224 static int dump_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
225 static int display_debug_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
226 static int display_debug_info
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
227 static int display_debug_not_supported
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
228 static int prescan_debug_info
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
229 static int display_debug_lines
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
230 static int display_debug_pubnames
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
231 static int display_debug_abbrev
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
232 static int display_debug_aranges
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
233 static int display_debug_frames
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
234 static int display_debug_macinfo
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
235 static int display_debug_str
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
236 static int display_debug_loc
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
237 static unsigned char * process_abbrev_section
PARAMS ((unsigned char *, unsigned char *));
238 static void load_debug_str
PARAMS ((FILE *));
239 static void free_debug_str
PARAMS ((void));
240 static const char * fetch_indirect_string
PARAMS ((unsigned long));
241 static void load_debug_loc
PARAMS ((FILE *));
242 static void free_debug_loc
PARAMS ((void));
243 static unsigned long read_leb128
PARAMS ((unsigned char *, int *, int));
244 static int process_extended_line_op
PARAMS ((unsigned char *, int, int));
245 static void reset_state_machine
PARAMS ((int));
246 static char * get_TAG_name
PARAMS ((unsigned long));
247 static char * get_AT_name
PARAMS ((unsigned long));
248 static char * get_FORM_name
PARAMS ((unsigned long));
249 static void free_abbrevs
PARAMS ((void));
250 static void add_abbrev
PARAMS ((unsigned long, unsigned long, int));
251 static void add_abbrev_attr
PARAMS ((unsigned long, unsigned long));
252 static unsigned char * read_and_display_attr
PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
253 static unsigned char * read_and_display_attr_value
PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
254 static unsigned char * display_block
PARAMS ((unsigned char *, unsigned long));
255 static void decode_location_expression
PARAMS ((unsigned char *, unsigned int, unsigned long));
256 static void request_dump
PARAMS ((unsigned int, int));
257 static const char * get_elf_class
PARAMS ((unsigned int));
258 static const char * get_data_encoding
PARAMS ((unsigned int));
259 static const char * get_osabi_name
PARAMS ((unsigned int));
260 static int guess_is_rela
PARAMS ((unsigned long));
261 static const char * get_note_type
PARAMS ((unsigned int));
262 static const char * get_netbsd_elfcore_note_type
PARAMS ((unsigned int));
263 static int process_note
PARAMS ((Elf32_Internal_Note
*));
264 static int process_corefile_note_segment
PARAMS ((FILE *, bfd_vma
, bfd_vma
));
265 static int process_corefile_note_segments
PARAMS ((FILE *));
266 static int process_corefile_contents
PARAMS ((FILE *));
267 static int process_arch_specific
PARAMS ((FILE *));
268 static int process_gnu_liblist
PARAMS ((FILE *));
270 typedef int Elf32_Word
;
278 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
279 ((X)->sh_name >= string_table_length \
280 ? "<corrupt>" : string_table + (X)->sh_name))
282 /* Given st_shndx I, map to section_headers index. */
283 #define SECTION_HEADER_INDEX(I) \
284 ((I) < SHN_LORESERVE \
286 : ((I) <= SHN_HIRESERVE \
288 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
290 /* Reverse of the above. */
291 #define SECTION_HEADER_NUM(N) \
292 ((N) < SHN_LORESERVE \
294 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
296 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
298 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
300 #define BYTE_GET(field) byte_get (field, sizeof (field))
302 /* If we can support a 64 bit data type then BFD64 should be defined
303 and sizeof (bfd_vma) == 8. In this case when translating from an
304 external 8 byte field to an internal field, we can assume that the
305 internal field is also 8 bytes wide and so we can extract all the data.
306 If, however, BFD64 is not defined, then we must assume that the
307 internal data structure only has 4 byte wide fields that are the
308 equivalent of the 8 byte wide external counterparts, and so we must
309 truncate the data. */
311 #define BYTE_GET8(field) byte_get (field, -8)
313 #define BYTE_GET8(field) byte_get (field, 8)
316 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
318 #define GET_ELF_SYMBOLS(file, section) \
319 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
320 : get_64bit_elf_symbols (file, section))
324 error
VPARAMS ((const char *message
, ...))
326 VA_OPEN (args
, message
);
327 VA_FIXEDARG (args
, const char *, message
);
329 fprintf (stderr
, _("%s: Error: "), program_name
);
330 vfprintf (stderr
, message
, args
);
335 warn
VPARAMS ((const char *message
, ...))
337 VA_OPEN (args
, message
);
338 VA_FIXEDARG (args
, const char *, message
);
340 fprintf (stderr
, _("%s: Warning: "), program_name
);
341 vfprintf (stderr
, message
, args
);
345 static PTR get_data
PARAMS ((PTR
, FILE *, long, size_t, const char *));
348 get_data (var
, file
, offset
, size
, reason
)
360 if (fseek (file
, offset
, SEEK_SET
))
362 error (_("Unable to seek to %x for %s\n"), offset
, reason
);
369 mvar
= (PTR
) malloc (size
);
373 error (_("Out of memory allocating %d bytes for %s\n"),
379 if (fread (mvar
, size
, 1, file
) != 1)
381 error (_("Unable to read in %d bytes of %s\n"), size
, reason
);
391 byte_get_little_endian (field
, size
)
392 unsigned char * field
;
401 return ((unsigned int) (field
[0]))
402 | (((unsigned int) (field
[1])) << 8);
406 /* We want to extract data from an 8 byte wide field and
407 place it into a 4 byte wide field. Since this is a little
408 endian source we can juts use the 4 byte extraction code. */
412 return ((unsigned long) (field
[0]))
413 | (((unsigned long) (field
[1])) << 8)
414 | (((unsigned long) (field
[2])) << 16)
415 | (((unsigned long) (field
[3])) << 24);
420 /* This is a special case, generated by the BYTE_GET8 macro.
421 It means that we are loading an 8 byte value from a field
422 in an external structure into an 8 byte value in a field
423 in an internal strcuture. */
424 return ((bfd_vma
) (field
[0]))
425 | (((bfd_vma
) (field
[1])) << 8)
426 | (((bfd_vma
) (field
[2])) << 16)
427 | (((bfd_vma
) (field
[3])) << 24)
428 | (((bfd_vma
) (field
[4])) << 32)
429 | (((bfd_vma
) (field
[5])) << 40)
430 | (((bfd_vma
) (field
[6])) << 48)
431 | (((bfd_vma
) (field
[7])) << 56);
434 error (_("Unhandled data length: %d\n"), size
);
439 /* Print a VMA value. */
441 print_vma (vma
, mode
)
451 case FULL_HEX
: printf ("0x"); /* drop through */
452 case LONG_HEX
: printf ("%8.8lx", (unsigned long) vma
); break;
453 case PREFIX_HEX
: printf ("0x"); /* drop through */
454 case HEX
: printf ("%lx", (unsigned long) vma
); break;
455 case DEC
: printf ("%ld", (unsigned long) vma
); break;
456 case DEC_5
: printf ("%5ld", (long) vma
); break;
457 case UNSIGNED
: printf ("%lu", (unsigned long) vma
); break;
478 #if BFD_HOST_64BIT_LONG
481 if (_bfd_int64_high (vma
))
482 printf ("%lx%8.8lx", _bfd_int64_high (vma
), _bfd_int64_low (vma
));
484 printf ("%lx", _bfd_int64_low (vma
));
489 #if BFD_HOST_64BIT_LONG
492 if (_bfd_int64_high (vma
))
494 printf ("++%ld", _bfd_int64_low (vma
));
496 printf ("%ld", _bfd_int64_low (vma
));
501 #if BFD_HOST_64BIT_LONG
502 printf ("%5ld", vma
);
504 if (_bfd_int64_high (vma
))
506 printf ("++%ld", _bfd_int64_low (vma
));
508 printf ("%5ld", _bfd_int64_low (vma
));
513 #if BFD_HOST_64BIT_LONG
516 if (_bfd_int64_high (vma
))
518 printf ("++%lu", _bfd_int64_low (vma
));
520 printf ("%lu", _bfd_int64_low (vma
));
528 /* Display a symbol on stdout. If do_wide is not true then
529 format the symbol to be at most WIDTH characters,
530 truncating as necessary. If WIDTH is negative then
531 format the string to be exactly - WIDTH characters,
532 truncating or padding as necessary. */
535 print_symbol (width
, symbol
)
542 printf ("%-*.*s", width
, width
, symbol
);
544 printf ("%-.*s", width
, symbol
);
548 byte_get_big_endian (field
, size
)
549 unsigned char * field
;
558 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
561 return ((unsigned long) (field
[3]))
562 | (((unsigned long) (field
[2])) << 8)
563 | (((unsigned long) (field
[1])) << 16)
564 | (((unsigned long) (field
[0])) << 24);
568 /* Although we are extracing data from an 8 byte wide field, we
569 are returning only 4 bytes of data. */
570 return ((unsigned long) (field
[7]))
571 | (((unsigned long) (field
[6])) << 8)
572 | (((unsigned long) (field
[5])) << 16)
573 | (((unsigned long) (field
[4])) << 24);
577 /* This is a special case, generated by the BYTE_GET8 macro.
578 It means that we are loading an 8 byte value from a field
579 in an external structure into an 8 byte value in a field
580 in an internal strcuture. */
581 return ((bfd_vma
) (field
[7]))
582 | (((bfd_vma
) (field
[6])) << 8)
583 | (((bfd_vma
) (field
[5])) << 16)
584 | (((bfd_vma
) (field
[4])) << 24)
585 | (((bfd_vma
) (field
[3])) << 32)
586 | (((bfd_vma
) (field
[2])) << 40)
587 | (((bfd_vma
) (field
[1])) << 48)
588 | (((bfd_vma
) (field
[0])) << 56);
592 error (_("Unhandled data length: %d\n"), size
);
597 /* Guess the relocation size commonly used by the specific machines. */
600 guess_is_rela (e_machine
)
601 unsigned long e_machine
;
605 /* Targets that use REL relocations. */
621 /* Targets that use RELA relocations. */
636 case EM_CYGNUS_MN10200
:
638 case EM_CYGNUS_MN10300
:
678 warn (_("Don't know about relocations on this machine architecture\n"));
684 slurp_rela_relocs (file
, rel_offset
, rel_size
, relasp
, nrelasp
)
686 unsigned long rel_offset
;
687 unsigned long rel_size
;
688 Elf_Internal_Rela
**relasp
;
689 unsigned long *nrelasp
;
691 Elf_Internal_Rela
*relas
;
692 unsigned long nrelas
;
697 Elf32_External_Rela
* erelas
;
699 erelas
= (Elf32_External_Rela
*) get_data (NULL
, file
, rel_offset
,
700 rel_size
, _("relocs"));
704 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
706 relas
= (Elf_Internal_Rela
*)
707 malloc (nrelas
* sizeof (Elf_Internal_Rela
));
711 error(_("out of memory parsing relocs"));
715 for (i
= 0; i
< nrelas
; i
++)
717 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
718 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
719 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
726 Elf64_External_Rela
* erelas
;
728 erelas
= (Elf64_External_Rela
*) get_data (NULL
, file
, rel_offset
,
729 rel_size
, _("relocs"));
733 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
735 relas
= (Elf_Internal_Rela
*)
736 malloc (nrelas
* sizeof (Elf_Internal_Rela
));
740 error(_("out of memory parsing relocs"));
744 for (i
= 0; i
< nrelas
; i
++)
746 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
747 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
748 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
759 slurp_rel_relocs (file
, rel_offset
, rel_size
, relsp
, nrelsp
)
761 unsigned long rel_offset
;
762 unsigned long rel_size
;
763 Elf_Internal_Rel
**relsp
;
764 unsigned long *nrelsp
;
766 Elf_Internal_Rel
*rels
;
772 Elf32_External_Rel
* erels
;
774 erels
= (Elf32_External_Rel
*) get_data (NULL
, file
, rel_offset
,
775 rel_size
, _("relocs"));
779 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
781 rels
= (Elf_Internal_Rel
*) malloc (nrels
* sizeof (Elf_Internal_Rel
));
785 error(_("out of memory parsing relocs"));
789 for (i
= 0; i
< nrels
; i
++)
791 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
792 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
799 Elf64_External_Rel
* erels
;
801 erels
= (Elf64_External_Rel
*) get_data (NULL
, file
, rel_offset
,
802 rel_size
, _("relocs"));
806 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
808 rels
= (Elf_Internal_Rel
*) malloc (nrels
* sizeof (Elf_Internal_Rel
));
812 error(_("out of memory parsing relocs"));
816 for (i
= 0; i
< nrels
; i
++)
818 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
819 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
829 /* Display the contents of the relocation data found at the specified offset. */
831 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
833 unsigned long rel_offset
;
834 unsigned long rel_size
;
835 Elf_Internal_Sym
* symtab
;
841 Elf_Internal_Rel
* rels
;
842 Elf_Internal_Rela
* relas
;
845 if (is_rela
== UNKNOWN
)
846 is_rela
= guess_is_rela (elf_header
.e_machine
);
850 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &relas
, &rel_size
))
855 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
864 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
866 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
871 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
873 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
881 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
883 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
888 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
890 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
894 for (i
= 0; i
< rel_size
; i
++)
897 const char * rtype2
= NULL
;
898 const char * rtype3
= NULL
;
901 bfd_vma symtab_index
;
903 bfd_vma type2
= (bfd_vma
) NULL
;
904 bfd_vma type3
= (bfd_vma
) NULL
;
908 offset
= relas
[i
].r_offset
;
909 info
= relas
[i
].r_info
;
913 offset
= rels
[i
].r_offset
;
914 info
= rels
[i
].r_info
;
919 type
= ELF32_R_TYPE (info
);
920 symtab_index
= ELF32_R_SYM (info
);
924 if (elf_header
.e_machine
== EM_MIPS
)
926 type
= ELF64_MIPS_R_TYPE (info
);
927 type2
= ELF64_MIPS_R_TYPE2 (info
);
928 type3
= ELF64_MIPS_R_TYPE3 (info
);
930 else if (elf_header
.e_machine
== EM_SPARCV9
)
931 type
= ELF64_R_TYPE_ID (info
);
933 type
= ELF64_R_TYPE (info
);
934 /* The #ifdef BFD64 below is to prevent a compile time warning.
935 We know that if we do not have a 64 bit data type that we
936 will never execute this code anyway. */
938 symtab_index
= ELF64_R_SYM (info
);
944 #ifdef _bfd_int64_low
945 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
947 printf ("%8.8lx %8.8lx ", offset
, info
);
952 #ifdef _bfd_int64_low
954 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
955 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
956 _bfd_int64_high (offset
),
957 _bfd_int64_low (offset
),
958 _bfd_int64_high (info
),
959 _bfd_int64_low (info
));
962 ? "%16.16lx %16.16lx "
963 : "%12.12lx %12.12lx ",
968 switch (elf_header
.e_machine
)
976 rtype
= elf_m32r_reloc_type (type
);
981 rtype
= elf_i386_reloc_type (type
);
986 rtype
= elf_m68hc11_reloc_type (type
);
990 rtype
= elf_m68k_reloc_type (type
);
994 rtype
= elf_i960_reloc_type (type
);
999 rtype
= elf_avr_reloc_type (type
);
1002 case EM_OLD_SPARCV9
:
1003 case EM_SPARC32PLUS
:
1006 rtype
= elf_sparc_reloc_type (type
);
1010 case EM_CYGNUS_V850
:
1011 rtype
= v850_reloc_type (type
);
1015 case EM_CYGNUS_D10V
:
1016 rtype
= elf_d10v_reloc_type (type
);
1020 case EM_CYGNUS_D30V
:
1021 rtype
= elf_d30v_reloc_type (type
);
1025 rtype
= elf_dlx_reloc_type (type
);
1029 rtype
= elf_sh_reloc_type (type
);
1033 case EM_CYGNUS_MN10300
:
1034 rtype
= elf_mn10300_reloc_type (type
);
1038 case EM_CYGNUS_MN10200
:
1039 rtype
= elf_mn10200_reloc_type (type
);
1043 case EM_CYGNUS_FR30
:
1044 rtype
= elf_fr30_reloc_type (type
);
1048 rtype
= elf_frv_reloc_type (type
);
1052 rtype
= elf_mcore_reloc_type (type
);
1056 rtype
= elf_mmix_reloc_type (type
);
1061 rtype
= elf_ppc_reloc_type (type
);
1065 case EM_MIPS_RS3_LE
:
1066 rtype
= elf_mips_reloc_type (type
);
1069 rtype2
= elf_mips_reloc_type (type2
);
1070 rtype3
= elf_mips_reloc_type (type3
);
1075 rtype
= elf_alpha_reloc_type (type
);
1079 rtype
= elf_arm_reloc_type (type
);
1083 rtype
= elf_arc_reloc_type (type
);
1087 rtype
= elf_hppa_reloc_type (type
);
1093 rtype
= elf_h8_reloc_type (type
);
1098 rtype
= elf_or32_reloc_type (type
);
1103 rtype
= elf_pj_reloc_type (type
);
1106 rtype
= elf_ia64_reloc_type (type
);
1110 rtype
= elf_cris_reloc_type (type
);
1114 rtype
= elf_i860_reloc_type (type
);
1118 rtype
= elf_x86_64_reloc_type (type
);
1123 rtype
= elf_s390_reloc_type (type
);
1127 rtype
= elf_xstormy16_reloc_type (type
);
1131 rtype
= elf_vax_reloc_type (type
);
1136 rtype
= elf_ip2k_reloc_type (type
);
1141 #ifdef _bfd_int64_low
1142 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1144 printf (_("unrecognized: %-7lx"), type
);
1147 printf (do_wide
? "%-21.21s" : "%-17.17s", rtype
);
1151 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1152 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1155 Elf_Internal_Sym
* psym
;
1157 psym
= symtab
+ symtab_index
;
1160 print_vma (psym
->st_value
, LONG_HEX
);
1161 printf (is_32bit_elf
? " " : " ");
1163 if (psym
->st_name
== 0)
1164 print_symbol (22, SECTION_NAME (section_headers
+ psym
->st_shndx
));
1165 else if (strtab
== NULL
)
1166 printf (_("<string table index %3ld>"), psym
->st_name
);
1168 print_symbol (22, strtab
+ psym
->st_name
);
1171 printf (" + %lx", (unsigned long) relas
[i
].r_addend
);
1176 printf ("%*c", is_32bit_elf
? (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1177 print_vma (relas
[i
].r_addend
, LONG_HEX
);
1180 if (elf_header
.e_machine
== EM_SPARCV9
1181 && !strcmp (rtype
, "R_SPARC_OLO10"))
1182 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1186 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1188 printf (" Type2: ");
1191 #ifdef _bfd_int64_low
1192 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1194 printf (_("unrecognized: %-7lx"), type2
);
1197 printf ("%-17.17s", rtype2
);
1199 printf("\n Type3: ");
1202 #ifdef _bfd_int64_low
1203 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1205 printf (_("unrecognized: %-7lx"), type3
);
1208 printf ("%-17.17s", rtype3
);
1223 get_mips_dynamic_type (type
)
1228 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1229 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1230 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1231 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1232 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1233 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1234 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1235 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1236 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1237 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1238 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1239 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1240 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1241 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1242 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1243 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1244 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1245 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1246 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1247 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1248 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1249 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1250 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1251 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1252 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1253 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1254 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1255 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1256 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1257 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1258 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1259 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1260 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1261 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1262 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1263 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1264 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1265 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1266 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1267 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1268 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1269 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1270 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1277 get_sparc64_dynamic_type (type
)
1282 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1289 get_ppc64_dynamic_type (type
)
1294 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1295 case DT_PPC64_OPD
: return "PPC64_OPD";
1296 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1303 get_parisc_dynamic_type (type
)
1308 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1309 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1310 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1311 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1312 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1313 case DT_HP_PREINIT
: return "HP_PREINIT";
1314 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1315 case DT_HP_NEEDED
: return "HP_NEEDED";
1316 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1317 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1318 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1319 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1320 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1327 get_dynamic_type (type
)
1330 static char buff
[32];
1334 case DT_NULL
: return "NULL";
1335 case DT_NEEDED
: return "NEEDED";
1336 case DT_PLTRELSZ
: return "PLTRELSZ";
1337 case DT_PLTGOT
: return "PLTGOT";
1338 case DT_HASH
: return "HASH";
1339 case DT_STRTAB
: return "STRTAB";
1340 case DT_SYMTAB
: return "SYMTAB";
1341 case DT_RELA
: return "RELA";
1342 case DT_RELASZ
: return "RELASZ";
1343 case DT_RELAENT
: return "RELAENT";
1344 case DT_STRSZ
: return "STRSZ";
1345 case DT_SYMENT
: return "SYMENT";
1346 case DT_INIT
: return "INIT";
1347 case DT_FINI
: return "FINI";
1348 case DT_SONAME
: return "SONAME";
1349 case DT_RPATH
: return "RPATH";
1350 case DT_SYMBOLIC
: return "SYMBOLIC";
1351 case DT_REL
: return "REL";
1352 case DT_RELSZ
: return "RELSZ";
1353 case DT_RELENT
: return "RELENT";
1354 case DT_PLTREL
: return "PLTREL";
1355 case DT_DEBUG
: return "DEBUG";
1356 case DT_TEXTREL
: return "TEXTREL";
1357 case DT_JMPREL
: return "JMPREL";
1358 case DT_BIND_NOW
: return "BIND_NOW";
1359 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1360 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1361 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1362 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1363 case DT_RUNPATH
: return "RUNPATH";
1364 case DT_FLAGS
: return "FLAGS";
1366 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1367 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1369 case DT_CHECKSUM
: return "CHECKSUM";
1370 case DT_PLTPADSZ
: return "PLTPADSZ";
1371 case DT_MOVEENT
: return "MOVEENT";
1372 case DT_MOVESZ
: return "MOVESZ";
1373 case DT_FEATURE
: return "FEATURE";
1374 case DT_POSFLAG_1
: return "POSFLAG_1";
1375 case DT_SYMINSZ
: return "SYMINSZ";
1376 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1378 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1379 case DT_CONFIG
: return "CONFIG";
1380 case DT_DEPAUDIT
: return "DEPAUDIT";
1381 case DT_AUDIT
: return "AUDIT";
1382 case DT_PLTPAD
: return "PLTPAD";
1383 case DT_MOVETAB
: return "MOVETAB";
1384 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1386 case DT_VERSYM
: return "VERSYM";
1388 case DT_RELACOUNT
: return "RELACOUNT";
1389 case DT_RELCOUNT
: return "RELCOUNT";
1390 case DT_FLAGS_1
: return "FLAGS_1";
1391 case DT_VERDEF
: return "VERDEF";
1392 case DT_VERDEFNUM
: return "VERDEFNUM";
1393 case DT_VERNEED
: return "VERNEED";
1394 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1396 case DT_AUXILIARY
: return "AUXILIARY";
1397 case DT_USED
: return "USED";
1398 case DT_FILTER
: return "FILTER";
1400 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1401 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1402 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1403 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1404 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1407 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1409 const char * result
;
1411 switch (elf_header
.e_machine
)
1414 case EM_MIPS_RS3_LE
:
1415 result
= get_mips_dynamic_type (type
);
1418 result
= get_sparc64_dynamic_type (type
);
1421 result
= get_ppc64_dynamic_type (type
);
1431 sprintf (buff
, _("Processor Specific: %lx"), type
);
1433 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1435 const char * result
;
1437 switch (elf_header
.e_machine
)
1440 result
= get_parisc_dynamic_type (type
);
1450 sprintf (buff
, _("Operating System specific: %lx"), type
);
1453 sprintf (buff
, _("<unknown>: %lx"), type
);
1460 get_file_type (e_type
)
1463 static char buff
[32];
1467 case ET_NONE
: return _("NONE (None)");
1468 case ET_REL
: return _("REL (Relocatable file)");
1469 case ET_EXEC
: return _("EXEC (Executable file)");
1470 case ET_DYN
: return _("DYN (Shared object file)");
1471 case ET_CORE
: return _("CORE (Core file)");
1474 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1475 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
1476 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1477 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
1479 sprintf (buff
, _("<unknown>: %x"), e_type
);
1485 get_machine_name (e_machine
)
1488 static char buff
[64]; /* XXX */
1492 case EM_NONE
: return _("None");
1493 case EM_M32
: return "WE32100";
1494 case EM_SPARC
: return "Sparc";
1495 case EM_386
: return "Intel 80386";
1496 case EM_68K
: return "MC68000";
1497 case EM_88K
: return "MC88000";
1498 case EM_486
: return "Intel 80486";
1499 case EM_860
: return "Intel 80860";
1500 case EM_MIPS
: return "MIPS R3000";
1501 case EM_S370
: return "IBM System/370";
1502 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1503 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1504 case EM_PARISC
: return "HPPA";
1505 case EM_PPC_OLD
: return "Power PC (old)";
1506 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1507 case EM_960
: return "Intel 90860";
1508 case EM_PPC
: return "PowerPC";
1509 case EM_PPC64
: return "PowerPC64";
1510 case EM_V800
: return "NEC V800";
1511 case EM_FR20
: return "Fujitsu FR20";
1512 case EM_RH32
: return "TRW RH32";
1513 case EM_MCORE
: return "MCORE";
1514 case EM_ARM
: return "ARM";
1515 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1516 case EM_SH
: return "Hitachi SH";
1517 case EM_SPARCV9
: return "Sparc v9";
1518 case EM_TRICORE
: return "Siemens Tricore";
1519 case EM_ARC
: return "ARC";
1520 case EM_H8_300
: return "Hitachi H8/300";
1521 case EM_H8_300H
: return "Hitachi H8/300H";
1522 case EM_H8S
: return "Hitachi H8S";
1523 case EM_H8_500
: return "Hitachi H8/500";
1524 case EM_IA_64
: return "Intel IA-64";
1525 case EM_MIPS_X
: return "Stanford MIPS-X";
1526 case EM_COLDFIRE
: return "Motorola Coldfire";
1527 case EM_68HC12
: return "Motorola M68HC12";
1528 case EM_ALPHA
: return "Alpha";
1529 case EM_CYGNUS_D10V
:
1530 case EM_D10V
: return "d10v";
1531 case EM_CYGNUS_D30V
:
1532 case EM_D30V
: return "d30v";
1533 case EM_CYGNUS_M32R
:
1534 case EM_M32R
: return "Mitsubishi M32r";
1535 case EM_CYGNUS_V850
:
1536 case EM_V850
: return "NEC v850";
1537 case EM_CYGNUS_MN10300
:
1538 case EM_MN10300
: return "mn10300";
1539 case EM_CYGNUS_MN10200
:
1540 case EM_MN10200
: return "mn10200";
1541 case EM_CYGNUS_FR30
:
1542 case EM_FR30
: return "Fujitsu FR30";
1543 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1545 case EM_PJ
: return "picoJava";
1546 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1547 case EM_PCP
: return "Siemens PCP";
1548 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1549 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1550 case EM_STARCORE
: return "Motorola Star*Core processor";
1551 case EM_ME16
: return "Toyota ME16 processor";
1552 case EM_ST100
: return "STMicroelectronics ST100 processor";
1553 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1554 case EM_FX66
: return "Siemens FX66 microcontroller";
1555 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1556 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1557 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1558 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1559 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1560 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1561 case EM_SVX
: return "Silicon Graphics SVx";
1562 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1563 case EM_VAX
: return "Digital VAX";
1565 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1566 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1567 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1568 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1569 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1570 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1571 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1572 case EM_PRISM
: return "SiTera Prism";
1573 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1575 case EM_S390
: return "IBM S/390";
1576 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1578 case EM_OR32
: return "OpenRISC";
1579 case EM_DLX
: return "OpenDLX";
1581 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1583 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1589 decode_ARM_machine_flags (e_flags
, buf
)
1596 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1597 e_flags
&= ~ EF_ARM_EABIMASK
;
1599 /* Handle "generic" ARM flags. */
1600 if (e_flags
& EF_ARM_RELEXEC
)
1602 strcat (buf
, ", relocatable executable");
1603 e_flags
&= ~ EF_ARM_RELEXEC
;
1606 if (e_flags
& EF_ARM_HASENTRY
)
1608 strcat (buf
, ", has entry point");
1609 e_flags
&= ~ EF_ARM_HASENTRY
;
1612 /* Now handle EABI specific flags. */
1616 strcat (buf
, ", <unrecognized EABI>");
1621 case EF_ARM_EABI_VER1
:
1622 strcat (buf
, ", Version1 EABI");
1627 /* Process flags one bit at a time. */
1628 flag
= e_flags
& - e_flags
;
1633 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1634 strcat (buf
, ", sorted symbol tables");
1644 case EF_ARM_EABI_VER2
:
1645 strcat (buf
, ", Version2 EABI");
1650 /* Process flags one bit at a time. */
1651 flag
= e_flags
& - e_flags
;
1656 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1657 strcat (buf
, ", sorted symbol tables");
1660 case EF_ARM_DYNSYMSUSESEGIDX
:
1661 strcat (buf
, ", dynamic symbols use segment index");
1664 case EF_ARM_MAPSYMSFIRST
:
1665 strcat (buf
, ", mapping symbols precede others");
1675 case EF_ARM_EABI_UNKNOWN
:
1676 strcat (buf
, ", GNU EABI");
1681 /* Process flags one bit at a time. */
1682 flag
= e_flags
& - e_flags
;
1687 case EF_ARM_INTERWORK
:
1688 strcat (buf
, ", interworking enabled");
1691 case EF_ARM_APCS_26
:
1692 strcat (buf
, ", uses APCS/26");
1695 case EF_ARM_APCS_FLOAT
:
1696 strcat (buf
, ", uses APCS/float");
1700 strcat (buf
, ", position independent");
1704 strcat (buf
, ", 8 bit structure alignment");
1707 case EF_ARM_NEW_ABI
:
1708 strcat (buf
, ", uses new ABI");
1711 case EF_ARM_OLD_ABI
:
1712 strcat (buf
, ", uses old ABI");
1715 case EF_ARM_SOFT_FLOAT
:
1716 strcat (buf
, ", software FP");
1727 strcat (buf
,", <unknown>");
1731 get_machine_flags (e_flags
, e_machine
)
1735 static char buf
[1024];
1747 decode_ARM_machine_flags (e_flags
, buf
);
1751 if (e_flags
& EF_CPU32
)
1752 strcat (buf
, ", cpu32");
1753 if (e_flags
& EF_M68000
)
1754 strcat (buf
, ", m68000");
1758 if (e_flags
& EF_PPC_EMB
)
1759 strcat (buf
, ", emb");
1761 if (e_flags
& EF_PPC_RELOCATABLE
)
1762 strcat (buf
, ", relocatable");
1764 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1765 strcat (buf
, ", relocatable-lib");
1769 case EM_CYGNUS_V850
:
1770 switch (e_flags
& EF_V850_ARCH
)
1773 strcat (buf
, ", v850e");
1776 strcat (buf
, ", v850ea");
1779 strcat (buf
, ", v850");
1782 strcat (buf
, ", unknown v850 architecture variant");
1788 case EM_CYGNUS_M32R
:
1789 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1790 strcat (buf
, ", m32r");
1795 case EM_MIPS_RS3_LE
:
1796 if (e_flags
& EF_MIPS_NOREORDER
)
1797 strcat (buf
, ", noreorder");
1799 if (e_flags
& EF_MIPS_PIC
)
1800 strcat (buf
, ", pic");
1802 if (e_flags
& EF_MIPS_CPIC
)
1803 strcat (buf
, ", cpic");
1805 if (e_flags
& EF_MIPS_UCODE
)
1806 strcat (buf
, ", ugen_reserved");
1808 if (e_flags
& EF_MIPS_ABI2
)
1809 strcat (buf
, ", abi2");
1811 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
1812 strcat (buf
, ", odk first");
1814 if (e_flags
& EF_MIPS_32BITMODE
)
1815 strcat (buf
, ", 32bitmode");
1817 switch ((e_flags
& EF_MIPS_MACH
))
1819 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
1820 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
1821 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
1822 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
1823 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
1824 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
1826 /* We simply ignore the field in this case to avoid confusion:
1827 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
1830 default: strcat (buf
, ", unknown CPU"); break;
1833 switch ((e_flags
& EF_MIPS_ABI
))
1835 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
1836 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
1837 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
1838 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
1840 /* We simply ignore the field in this case to avoid confusion:
1841 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
1842 This means it is likely to be an o32 file, but not for
1845 default: strcat (buf
, ", unknown ABI"); break;
1848 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
1849 strcat (buf
, ", mdmx");
1851 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
1852 strcat (buf
, ", mips16");
1854 switch ((e_flags
& EF_MIPS_ARCH
))
1856 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
1857 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
1858 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
1859 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
1860 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
1861 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
1862 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
1863 default: strcat (buf
, ", unknown ISA"); break;
1869 if (e_flags
& EF_SPARC_32PLUS
)
1870 strcat (buf
, ", v8+");
1872 if (e_flags
& EF_SPARC_SUN_US1
)
1873 strcat (buf
, ", ultrasparcI");
1875 if (e_flags
& EF_SPARC_SUN_US3
)
1876 strcat (buf
, ", ultrasparcIII");
1878 if (e_flags
& EF_SPARC_HAL_R1
)
1879 strcat (buf
, ", halr1");
1881 if (e_flags
& EF_SPARC_LEDATA
)
1882 strcat (buf
, ", ledata");
1884 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
1885 strcat (buf
, ", tso");
1887 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
1888 strcat (buf
, ", pso");
1890 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
1891 strcat (buf
, ", rmo");
1895 switch (e_flags
& EF_PARISC_ARCH
)
1897 case EFA_PARISC_1_0
:
1898 strcpy (buf
, ", PA-RISC 1.0");
1900 case EFA_PARISC_1_1
:
1901 strcpy (buf
, ", PA-RISC 1.1");
1903 case EFA_PARISC_2_0
:
1904 strcpy (buf
, ", PA-RISC 2.0");
1909 if (e_flags
& EF_PARISC_TRAPNIL
)
1910 strcat (buf
, ", trapnil");
1911 if (e_flags
& EF_PARISC_EXT
)
1912 strcat (buf
, ", ext");
1913 if (e_flags
& EF_PARISC_LSB
)
1914 strcat (buf
, ", lsb");
1915 if (e_flags
& EF_PARISC_WIDE
)
1916 strcat (buf
, ", wide");
1917 if (e_flags
& EF_PARISC_NO_KABP
)
1918 strcat (buf
, ", no kabp");
1919 if (e_flags
& EF_PARISC_LAZYSWAP
)
1920 strcat (buf
, ", lazyswap");
1925 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
1926 strcat (buf
, ", new calling convention");
1928 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
1929 strcat (buf
, ", gnu calling convention");
1933 if ((e_flags
& EF_IA_64_ABI64
))
1934 strcat (buf
, ", 64-bit");
1936 strcat (buf
, ", 32-bit");
1937 if ((e_flags
& EF_IA_64_REDUCEDFP
))
1938 strcat (buf
, ", reduced fp model");
1939 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
1940 strcat (buf
, ", no function descriptors, constant gp");
1941 else if ((e_flags
& EF_IA_64_CONS_GP
))
1942 strcat (buf
, ", constant gp");
1943 if ((e_flags
& EF_IA_64_ABSOLUTE
))
1944 strcat (buf
, ", absolute");
1948 if ((e_flags
& EF_VAX_NONPIC
))
1949 strcat (buf
, ", non-PIC");
1950 if ((e_flags
& EF_VAX_DFLOAT
))
1951 strcat (buf
, ", D-Float");
1952 if ((e_flags
& EF_VAX_GFLOAT
))
1953 strcat (buf
, ", G-Float");
1962 get_mips_segment_type (type
)
1967 case PT_MIPS_REGINFO
:
1969 case PT_MIPS_RTPROC
:
1971 case PT_MIPS_OPTIONS
:
1981 get_parisc_segment_type (type
)
1986 case PT_HP_TLS
: return "HP_TLS";
1987 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
1988 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
1989 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
1990 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
1991 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
1992 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
1993 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
1994 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
1995 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
1996 case PT_HP_PARALLEL
: return "HP_PARALLEL";
1997 case PT_HP_FASTBIND
: return "HP_FASTBIND";
1998 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
1999 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2008 get_ia64_segment_type (type
)
2013 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2014 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2015 case PT_HP_TLS
: return "HP_TLS";
2016 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2017 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2018 case PT_IA_64_HP_STACK
: return "HP_STACK";
2027 get_segment_type (p_type
)
2028 unsigned long p_type
;
2030 static char buff
[32];
2034 case PT_NULL
: return "NULL";
2035 case PT_LOAD
: return "LOAD";
2036 case PT_DYNAMIC
: return "DYNAMIC";
2037 case PT_INTERP
: return "INTERP";
2038 case PT_NOTE
: return "NOTE";
2039 case PT_SHLIB
: return "SHLIB";
2040 case PT_PHDR
: return "PHDR";
2041 case PT_TLS
: return "TLS";
2043 case PT_GNU_EH_FRAME
:
2044 return "GNU_EH_FRAME";
2047 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2049 const char * result
;
2051 switch (elf_header
.e_machine
)
2054 case EM_MIPS_RS3_LE
:
2055 result
= get_mips_segment_type (p_type
);
2058 result
= get_parisc_segment_type (p_type
);
2061 result
= get_ia64_segment_type (p_type
);
2071 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2073 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2075 const char * result
;
2077 switch (elf_header
.e_machine
)
2080 result
= get_parisc_segment_type (p_type
);
2083 result
= get_ia64_segment_type (p_type
);
2093 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2096 sprintf (buff
, _("<unknown>: %lx"), p_type
);
2103 get_mips_section_type_name (sh_type
)
2104 unsigned int sh_type
;
2108 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2109 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2110 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2111 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2112 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2113 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2114 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2115 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2116 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2117 case SHT_MIPS_RELD
: return "MIPS_RELD";
2118 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2119 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2120 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2121 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2122 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2123 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2124 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2125 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2126 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2127 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2128 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2129 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2130 case SHT_MIPS_LINE
: return "MIPS_LINE";
2131 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2132 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2133 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2134 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2135 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2136 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2137 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2138 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2139 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2140 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2141 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2142 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2143 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2144 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2145 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2146 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2154 get_parisc_section_type_name (sh_type
)
2155 unsigned int sh_type
;
2159 case SHT_PARISC_EXT
: return "PARISC_EXT";
2160 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2161 case SHT_PARISC_DOC
: return "PARISC_DOC";
2169 get_ia64_section_type_name (sh_type
)
2170 unsigned int sh_type
;
2174 case SHT_IA_64_EXT
: return "IA_64_EXT";
2175 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2183 get_section_type_name (sh_type
)
2184 unsigned int sh_type
;
2186 static char buff
[32];
2190 case SHT_NULL
: return "NULL";
2191 case SHT_PROGBITS
: return "PROGBITS";
2192 case SHT_SYMTAB
: return "SYMTAB";
2193 case SHT_STRTAB
: return "STRTAB";
2194 case SHT_RELA
: return "RELA";
2195 case SHT_HASH
: return "HASH";
2196 case SHT_DYNAMIC
: return "DYNAMIC";
2197 case SHT_NOTE
: return "NOTE";
2198 case SHT_NOBITS
: return "NOBITS";
2199 case SHT_REL
: return "REL";
2200 case SHT_SHLIB
: return "SHLIB";
2201 case SHT_DYNSYM
: return "DYNSYM";
2202 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2203 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2204 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2205 case SHT_GROUP
: return "GROUP";
2206 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2207 case SHT_GNU_verdef
: return "VERDEF";
2208 case SHT_GNU_verneed
: return "VERNEED";
2209 case SHT_GNU_versym
: return "VERSYM";
2210 case 0x6ffffff0: return "VERSYM";
2211 case 0x6ffffffc: return "VERDEF";
2212 case 0x7ffffffd: return "AUXILIARY";
2213 case 0x7fffffff: return "FILTER";
2214 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2217 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2219 const char * result
;
2221 switch (elf_header
.e_machine
)
2224 case EM_MIPS_RS3_LE
:
2225 result
= get_mips_section_type_name (sh_type
);
2228 result
= get_parisc_section_type_name (sh_type
);
2231 result
= get_ia64_section_type_name (sh_type
);
2241 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2243 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2244 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2245 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2246 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2248 sprintf (buff
, _("<unknown>: %x"), sh_type
);
2254 struct option options
[] =
2256 {"all", no_argument
, 0, 'a'},
2257 {"file-header", no_argument
, 0, 'h'},
2258 {"program-headers", no_argument
, 0, 'l'},
2259 {"headers", no_argument
, 0, 'e'},
2260 {"histogram", no_argument
, 0, 'I'},
2261 {"segments", no_argument
, 0, 'l'},
2262 {"sections", no_argument
, 0, 'S'},
2263 {"section-headers", no_argument
, 0, 'S'},
2264 {"symbols", no_argument
, 0, 's'},
2265 {"syms", no_argument
, 0, 's'},
2266 {"relocs", no_argument
, 0, 'r'},
2267 {"notes", no_argument
, 0, 'n'},
2268 {"dynamic", no_argument
, 0, 'd'},
2269 {"arch-specific", no_argument
, 0, 'A'},
2270 {"version-info", no_argument
, 0, 'V'},
2271 {"use-dynamic", no_argument
, 0, 'D'},
2272 {"hex-dump", required_argument
, 0, 'x'},
2273 {"debug-dump", optional_argument
, 0, 'w'},
2274 {"unwind", no_argument
, 0, 'u'},
2275 #ifdef SUPPORT_DISASSEMBLY
2276 {"instruction-dump", required_argument
, 0, 'i'},
2279 {"version", no_argument
, 0, 'v'},
2280 {"wide", no_argument
, 0, 'W'},
2281 {"help", no_argument
, 0, 'H'},
2282 {0, no_argument
, 0, 0}
2288 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2289 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2290 fprintf (stdout
, _(" Options are:\n\
2291 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2292 -h --file-header Display the ELF file header\n\
2293 -l --program-headers Display the program headers\n\
2294 --segments An alias for --program-headers\n\
2295 -S --section-headers Display the sections' header\n\
2296 --sections An alias for --section-headers\n\
2297 -e --headers Equivalent to: -h -l -S\n\
2298 -s --syms Display the symbol table\n\
2299 --symbols An alias for --syms\n\
2300 -n --notes Display the core notes (if present)\n\
2301 -r --relocs Display the relocations (if present)\n\
2302 -u --unwind Display the unwind info (if present)\n\
2303 -d --dynamic Display the dynamic segment (if present)\n\
2304 -V --version-info Display the version sections (if present)\n\
2305 -A --arch-specific Display architecture specific information (if any).\n\
2306 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2307 -x --hex-dump=<number> Dump the contents of section <number>\n\
2308 -w --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
2309 Display the contents of DWARF2 debug sections\n"));
2310 #ifdef SUPPORT_DISASSEMBLY
2311 fprintf (stdout
, _("\
2312 -i --instruction-dump=<number>\n\
2313 Disassemble the contents of section <number>\n"));
2315 fprintf (stdout
, _("\
2316 -I --histogram Display histogram of bucket list lengths\n\
2317 -W --wide Allow output width to exceed 80 characters\n\
2318 -H --help Display this information\n\
2319 -v --version Display the version number of readelf\n"));
2320 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2326 request_dump (section
, type
)
2327 unsigned int section
;
2330 if (section
>= num_dump_sects
)
2332 char * new_dump_sects
;
2334 new_dump_sects
= (char *) calloc (section
+ 1, 1);
2336 if (new_dump_sects
== NULL
)
2337 error (_("Out of memory allocating dump request table."));
2340 /* Copy current flag settings. */
2341 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2345 dump_sects
= new_dump_sects
;
2346 num_dump_sects
= section
+ 1;
2351 dump_sects
[section
] |= type
;
2357 parse_args (argc
, argv
)
2366 while ((c
= getopt_long
2367 (argc
, argv
, "ersuahnldSDAIw::x:i:vVW", options
, NULL
)) != EOF
)
2403 do_using_dynamic
++;
2434 section
= strtoul (optarg
, & cp
, 0);
2435 if (! * cp
&& section
>= 0)
2437 request_dump (section
, HEX_DUMP
);
2447 unsigned int index
= 0;
2451 while (optarg
[index
])
2452 switch (optarg
[index
++])
2461 do_debug_abbrevs
= 1;
2471 do_debug_pubnames
= 1;
2476 do_debug_aranges
= 1;
2480 do_debug_frames_interp
= 1;
2482 do_debug_frames
= 1;
2487 do_debug_macinfo
= 1;
2501 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2506 #ifdef SUPPORT_DISASSEMBLY
2509 section
= strtoul (optarg
, & cp
, 0);
2510 if (! * cp
&& section
>= 0)
2512 request_dump (section
, DISASS_DUMP
);
2518 print_version (program_name
);
2528 /* xgettext:c-format */
2529 error (_("Invalid option '-%c'\n"), c
);
2536 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2537 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2538 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
)
2542 warn (_("Nothing to do.\n"));
2548 get_elf_class (elf_class
)
2549 unsigned int elf_class
;
2551 static char buff
[32];
2555 case ELFCLASSNONE
: return _("none");
2556 case ELFCLASS32
: return "ELF32";
2557 case ELFCLASS64
: return "ELF64";
2559 sprintf (buff
, _("<unknown: %x>"), elf_class
);
2565 get_data_encoding (encoding
)
2566 unsigned int encoding
;
2568 static char buff
[32];
2572 case ELFDATANONE
: return _("none");
2573 case ELFDATA2LSB
: return _("2's complement, little endian");
2574 case ELFDATA2MSB
: return _("2's complement, big endian");
2576 sprintf (buff
, _("<unknown: %x>"), encoding
);
2582 get_osabi_name (osabi
)
2585 static char buff
[32];
2589 case ELFOSABI_NONE
: return "UNIX - System V";
2590 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2591 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2592 case ELFOSABI_LINUX
: return "UNIX - Linux";
2593 case ELFOSABI_HURD
: return "GNU/Hurd";
2594 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2595 case ELFOSABI_AIX
: return "UNIX - AIX";
2596 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2597 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2598 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2599 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2600 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2601 case ELFOSABI_STANDALONE
: return _("Standalone App");
2602 case ELFOSABI_ARM
: return "ARM";
2604 sprintf (buff
, _("<unknown: %x>"), osabi
);
2609 /* Decode the data held in 'elf_header'. */
2611 process_file_header ()
2613 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2614 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2615 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2616 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2619 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2627 printf (_("ELF Header:\n"));
2628 printf (_(" Magic: "));
2629 for (i
= 0; i
< EI_NIDENT
; i
++)
2630 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2632 printf (_(" Class: %s\n"),
2633 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2634 printf (_(" Data: %s\n"),
2635 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2636 printf (_(" Version: %d %s\n"),
2637 elf_header
.e_ident
[EI_VERSION
],
2638 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
2640 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
2643 printf (_(" OS/ABI: %s\n"),
2644 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
2645 printf (_(" ABI Version: %d\n"),
2646 elf_header
.e_ident
[EI_ABIVERSION
]);
2647 printf (_(" Type: %s\n"),
2648 get_file_type (elf_header
.e_type
));
2649 printf (_(" Machine: %s\n"),
2650 get_machine_name (elf_header
.e_machine
));
2651 printf (_(" Version: 0x%lx\n"),
2652 (unsigned long) elf_header
.e_version
);
2654 printf (_(" Entry point address: "));
2655 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2656 printf (_("\n Start of program headers: "));
2657 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2658 printf (_(" (bytes into file)\n Start of section headers: "));
2659 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
2660 printf (_(" (bytes into file)\n"));
2662 printf (_(" Flags: 0x%lx%s\n"),
2663 (unsigned long) elf_header
.e_flags
,
2664 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
2665 printf (_(" Size of this header: %ld (bytes)\n"),
2666 (long) elf_header
.e_ehsize
);
2667 printf (_(" Size of program headers: %ld (bytes)\n"),
2668 (long) elf_header
.e_phentsize
);
2669 printf (_(" Number of program headers: %ld\n"),
2670 (long) elf_header
.e_phnum
);
2671 printf (_(" Size of section headers: %ld (bytes)\n"),
2672 (long) elf_header
.e_shentsize
);
2673 printf (_(" Number of section headers: %ld"),
2674 (long) elf_header
.e_shnum
);
2675 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
2676 printf (" (%ld)", (long) section_headers
[0].sh_size
);
2677 putc ('\n', stdout
);
2678 printf (_(" Section header string table index: %ld"),
2679 (long) elf_header
.e_shstrndx
);
2680 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
2681 printf (" (%ld)", (long) section_headers
[0].sh_link
);
2682 putc ('\n', stdout
);
2685 if (section_headers
!= NULL
)
2687 if (elf_header
.e_shnum
== 0)
2688 elf_header
.e_shnum
= section_headers
[0].sh_size
;
2689 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
2690 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
2691 free (section_headers
);
2692 section_headers
= NULL
;
2700 get_32bit_program_headers (file
, program_headers
)
2702 Elf_Internal_Phdr
* program_headers
;
2704 Elf32_External_Phdr
* phdrs
;
2705 Elf32_External_Phdr
* external
;
2706 Elf32_Internal_Phdr
* internal
;
2709 phdrs
= ((Elf32_External_Phdr
*)
2710 get_data (NULL
, file
, elf_header
.e_phoff
,
2711 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2712 _("program headers")));
2716 for (i
= 0, internal
= program_headers
, external
= phdrs
;
2717 i
< elf_header
.e_phnum
;
2718 i
++, internal
++, external
++)
2720 internal
->p_type
= BYTE_GET (external
->p_type
);
2721 internal
->p_offset
= BYTE_GET (external
->p_offset
);
2722 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
2723 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
2724 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
2725 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
2726 internal
->p_flags
= BYTE_GET (external
->p_flags
);
2727 internal
->p_align
= BYTE_GET (external
->p_align
);
2736 get_64bit_program_headers (file
, program_headers
)
2738 Elf_Internal_Phdr
* program_headers
;
2740 Elf64_External_Phdr
* phdrs
;
2741 Elf64_External_Phdr
* external
;
2742 Elf64_Internal_Phdr
* internal
;
2745 phdrs
= ((Elf64_External_Phdr
*)
2746 get_data (NULL
, file
, elf_header
.e_phoff
,
2747 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2748 _("program headers")));
2752 for (i
= 0, internal
= program_headers
, external
= phdrs
;
2753 i
< elf_header
.e_phnum
;
2754 i
++, internal
++, external
++)
2756 internal
->p_type
= BYTE_GET (external
->p_type
);
2757 internal
->p_flags
= BYTE_GET (external
->p_flags
);
2758 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
2759 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
2760 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
2761 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
2762 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
2763 internal
->p_align
= BYTE_GET8 (external
->p_align
);
2772 process_program_headers (file
)
2775 Elf_Internal_Phdr
* program_headers
;
2776 Elf_Internal_Phdr
* segment
;
2779 if (elf_header
.e_phnum
== 0)
2782 printf (_("\nThere are no program headers in this file.\n"));
2786 if (do_segments
&& !do_header
)
2788 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
2789 printf (_("Entry point "));
2790 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2791 printf (_("\nThere are %d program headers, starting at offset "),
2792 elf_header
.e_phnum
);
2793 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2797 program_headers
= (Elf_Internal_Phdr
*) malloc
2798 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
2800 if (program_headers
== NULL
)
2802 error (_("Out of memory\n"));
2807 i
= get_32bit_program_headers (file
, program_headers
);
2809 i
= get_64bit_program_headers (file
, program_headers
);
2813 free (program_headers
);
2819 if (elf_header
.e_phnum
> 1)
2820 printf (_("\nProgram Headers:\n"));
2822 printf (_("\nProgram Headers:\n"));
2826 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2829 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2833 (_(" Type Offset VirtAddr PhysAddr\n"));
2835 (_(" FileSiz MemSiz Flags Align\n"));
2843 for (i
= 0, segment
= program_headers
;
2844 i
< elf_header
.e_phnum
;
2849 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
2853 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
2854 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
2855 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
2856 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
2857 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
2859 (segment
->p_flags
& PF_R
? 'R' : ' '),
2860 (segment
->p_flags
& PF_W
? 'W' : ' '),
2861 (segment
->p_flags
& PF_X
? 'E' : ' '));
2862 printf ("%#lx", (unsigned long) segment
->p_align
);
2866 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
2867 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
2870 print_vma (segment
->p_offset
, FULL_HEX
);
2874 print_vma (segment
->p_vaddr
, FULL_HEX
);
2876 print_vma (segment
->p_paddr
, FULL_HEX
);
2879 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
2880 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
2883 print_vma (segment
->p_filesz
, FULL_HEX
);
2887 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
2888 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
2891 print_vma (segment
->p_offset
, FULL_HEX
);
2895 (segment
->p_flags
& PF_R
? 'R' : ' '),
2896 (segment
->p_flags
& PF_W
? 'W' : ' '),
2897 (segment
->p_flags
& PF_X
? 'E' : ' '));
2899 if ((unsigned long) segment
->p_align
== segment
->p_align
)
2900 printf ("%#lx", (unsigned long) segment
->p_align
);
2903 print_vma (segment
->p_align
, PREFIX_HEX
);
2908 print_vma (segment
->p_offset
, FULL_HEX
);
2910 print_vma (segment
->p_vaddr
, FULL_HEX
);
2912 print_vma (segment
->p_paddr
, FULL_HEX
);
2914 print_vma (segment
->p_filesz
, FULL_HEX
);
2916 print_vma (segment
->p_memsz
, FULL_HEX
);
2918 (segment
->p_flags
& PF_R
? 'R' : ' '),
2919 (segment
->p_flags
& PF_W
? 'W' : ' '),
2920 (segment
->p_flags
& PF_X
? 'E' : ' '));
2921 print_vma (segment
->p_align
, HEX
);
2925 switch (segment
->p_type
)
2929 loadaddr
= (segment
->p_vaddr
& 0xfffff000)
2930 - (segment
->p_offset
& 0xfffff000);
2935 error (_("more than one dynamic segment\n"));
2937 dynamic_addr
= segment
->p_offset
;
2938 dynamic_size
= segment
->p_filesz
;
2942 if (fseek (file
, (long) segment
->p_offset
, SEEK_SET
))
2943 error (_("Unable to find program interpreter name\n"));
2946 program_interpreter
[0] = 0;
2947 fscanf (file
, "%63s", program_interpreter
);
2950 printf (_("\n [Requesting program interpreter: %s]"),
2951 program_interpreter
);
2957 putc ('\n', stdout
);
2966 if (do_segments
&& section_headers
!= NULL
)
2968 printf (_("\n Section to Segment mapping:\n"));
2969 printf (_(" Segment Sections...\n"));
2971 assert (string_table
!= NULL
);
2973 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
2976 Elf_Internal_Shdr
* section
;
2978 segment
= program_headers
+ i
;
2979 section
= section_headers
;
2981 printf (" %2.2d ", i
);
2983 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
2985 if (section
->sh_size
> 0
2986 /* Compare allocated sections by VMA, unallocated
2987 sections by file offset. */
2988 && (section
->sh_flags
& SHF_ALLOC
2989 ? (section
->sh_addr
>= segment
->p_vaddr
2990 && section
->sh_addr
+ section
->sh_size
2991 <= segment
->p_vaddr
+ segment
->p_memsz
)
2992 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
2993 && (section
->sh_offset
+ section
->sh_size
2994 <= segment
->p_offset
+ segment
->p_filesz
))))
2995 printf ("%s ", SECTION_NAME (section
));
3002 free (program_headers
);
3009 get_32bit_section_headers (file
, num
)
3013 Elf32_External_Shdr
* shdrs
;
3014 Elf32_Internal_Shdr
* internal
;
3017 shdrs
= ((Elf32_External_Shdr
*)
3018 get_data (NULL
, file
, elf_header
.e_shoff
,
3019 elf_header
.e_shentsize
* num
,
3020 _("section headers")));
3024 section_headers
= ((Elf_Internal_Shdr
*)
3025 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3027 if (section_headers
== NULL
)
3029 error (_("Out of memory\n"));
3033 for (i
= 0, internal
= section_headers
;
3037 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3038 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3039 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3040 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3041 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3042 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3043 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3044 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3045 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3046 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3055 get_64bit_section_headers (file
, num
)
3059 Elf64_External_Shdr
* shdrs
;
3060 Elf64_Internal_Shdr
* internal
;
3063 shdrs
= ((Elf64_External_Shdr
*)
3064 get_data (NULL
, file
, elf_header
.e_shoff
,
3065 elf_header
.e_shentsize
* num
,
3066 _("section headers")));
3070 section_headers
= ((Elf_Internal_Shdr
*)
3071 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3073 if (section_headers
== NULL
)
3075 error (_("Out of memory\n"));
3079 for (i
= 0, internal
= section_headers
;
3083 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3084 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3085 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
3086 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
3087 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
3088 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
3089 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3090 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3091 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3092 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3100 static Elf_Internal_Sym
*
3101 get_32bit_elf_symbols (file
, section
)
3103 Elf_Internal_Shdr
*section
;
3105 unsigned long number
;
3106 Elf32_External_Sym
* esyms
;
3107 Elf_External_Sym_Shndx
*shndx
;
3108 Elf_Internal_Sym
* isyms
;
3109 Elf_Internal_Sym
* psym
;
3112 esyms
= ((Elf32_External_Sym
*)
3113 get_data (NULL
, file
, section
->sh_offset
,
3114 section
->sh_size
, _("symbols")));
3119 if (symtab_shndx_hdr
!= NULL
3120 && (symtab_shndx_hdr
->sh_link
3121 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3123 shndx
= ((Elf_External_Sym_Shndx
*)
3124 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3125 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3133 number
= section
->sh_size
/ section
->sh_entsize
;
3134 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3138 error (_("Out of memory\n"));
3145 for (j
= 0, psym
= isyms
;
3149 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3150 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3151 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3152 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3153 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3155 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3156 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3157 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3167 static Elf_Internal_Sym
*
3168 get_64bit_elf_symbols (file
, section
)
3170 Elf_Internal_Shdr
*section
;
3172 unsigned long number
;
3173 Elf64_External_Sym
* esyms
;
3174 Elf_External_Sym_Shndx
*shndx
;
3175 Elf_Internal_Sym
* isyms
;
3176 Elf_Internal_Sym
* psym
;
3179 esyms
= ((Elf64_External_Sym
*)
3180 get_data (NULL
, file
, section
->sh_offset
,
3181 section
->sh_size
, _("symbols")));
3186 if (symtab_shndx_hdr
!= NULL
3187 && (symtab_shndx_hdr
->sh_link
3188 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3190 shndx
= ((Elf_External_Sym_Shndx
*)
3191 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3192 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3200 number
= section
->sh_size
/ section
->sh_entsize
;
3201 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3205 error (_("Out of memory\n"));
3212 for (j
= 0, psym
= isyms
;
3216 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3217 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3218 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3219 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3220 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3222 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3223 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
3224 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
3235 get_elf_section_flags (sh_flags
)
3238 static char buff
[32];
3246 flag
= sh_flags
& - sh_flags
;
3251 case SHF_WRITE
: strcat (buff
, "W"); break;
3252 case SHF_ALLOC
: strcat (buff
, "A"); break;
3253 case SHF_EXECINSTR
: strcat (buff
, "X"); break;
3254 case SHF_MERGE
: strcat (buff
, "M"); break;
3255 case SHF_STRINGS
: strcat (buff
, "S"); break;
3256 case SHF_INFO_LINK
: strcat (buff
, "I"); break;
3257 case SHF_LINK_ORDER
: strcat (buff
, "L"); break;
3258 case SHF_OS_NONCONFORMING
: strcat (buff
, "O"); break;
3259 case SHF_GROUP
: strcat (buff
, "G"); break;
3260 case SHF_TLS
: strcat (buff
, "T"); break;
3263 if (flag
& SHF_MASKOS
)
3266 sh_flags
&= ~ SHF_MASKOS
;
3268 else if (flag
& SHF_MASKPROC
)
3271 sh_flags
&= ~ SHF_MASKPROC
;
3283 process_section_headers (file
)
3286 Elf_Internal_Shdr
* section
;
3289 section_headers
= NULL
;
3291 if (elf_header
.e_shnum
== 0)
3294 printf (_("\nThere are no sections in this file.\n"));
3299 if (do_sections
&& !do_header
)
3300 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3301 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3305 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3308 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3311 /* Read in the string table, so that we have names to display. */
3312 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3314 if (section
->sh_size
!= 0)
3316 string_table
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3317 section
->sh_size
, _("string table"));
3319 string_table_length
= section
->sh_size
;
3322 /* Scan the sections for the dynamic symbol table
3323 and dynamic string table and debug sections. */
3324 dynamic_symbols
= NULL
;
3325 dynamic_strings
= NULL
;
3326 dynamic_syminfo
= NULL
;
3328 for (i
= 0, section
= section_headers
;
3329 i
< elf_header
.e_shnum
;
3332 char * name
= SECTION_NAME (section
);
3334 if (section
->sh_type
== SHT_DYNSYM
)
3336 if (dynamic_symbols
!= NULL
)
3338 error (_("File contains multiple dynamic symbol tables\n"));
3342 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3343 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3345 else if (section
->sh_type
== SHT_STRTAB
3346 && strcmp (name
, ".dynstr") == 0)
3348 if (dynamic_strings
!= NULL
)
3350 error (_("File contains multiple dynamic string tables\n"));
3354 dynamic_strings
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3356 _("dynamic strings"));
3358 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3360 if (symtab_shndx_hdr
!= NULL
)
3362 error (_("File contains multiple symtab shndx tables\n"));
3365 symtab_shndx_hdr
= section
;
3367 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3368 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3369 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3371 && strncmp (name
, ".debug_", 7) == 0)
3376 || (do_debug_info
&& (strcmp (name
, "info") == 0))
3377 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
3378 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
3379 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
3380 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
3381 || (do_debug_frames
&& (strcmp (name
, "frame") == 0))
3382 || (do_debug_macinfo
&& (strcmp (name
, "macinfo") == 0))
3383 || (do_debug_str
&& (strcmp (name
, "str") == 0))
3384 || (do_debug_loc
&& (strcmp (name
, "loc") == 0))
3386 request_dump (i
, DEBUG_DUMP
);
3388 /* linkonce section to be combined with .debug_info at link time. */
3389 else if ((do_debugging
|| do_debug_info
)
3390 && strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
3391 request_dump (i
, DEBUG_DUMP
);
3392 else if (do_debug_frames
&& strcmp (name
, ".eh_frame") == 0)
3393 request_dump (i
, DEBUG_DUMP
);
3399 if (elf_header
.e_shnum
> 1)
3400 printf (_("\nSection Headers:\n"));
3402 printf (_("\nSection Header:\n"));
3406 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3409 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3412 printf (_(" [Nr] Name Type Address Offset\n"));
3413 printf (_(" Size EntSize Flags Link Info Align\n"));
3416 for (i
= 0, section
= section_headers
;
3417 i
< elf_header
.e_shnum
;
3420 printf (" [%2u] %-17.17s %-15.15s ",
3421 SECTION_HEADER_NUM (i
),
3422 SECTION_NAME (section
),
3423 get_section_type_name (section
->sh_type
));
3427 print_vma (section
->sh_addr
, LONG_HEX
);
3429 printf ( " %6.6lx %6.6lx %2.2lx",
3430 (unsigned long) section
->sh_offset
,
3431 (unsigned long) section
->sh_size
,
3432 (unsigned long) section
->sh_entsize
);
3434 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3436 printf ("%2ld %3lx %2ld\n",
3437 (unsigned long) section
->sh_link
,
3438 (unsigned long) section
->sh_info
,
3439 (unsigned long) section
->sh_addralign
);
3443 print_vma (section
->sh_addr
, LONG_HEX
);
3445 if ((long) section
->sh_offset
== section
->sh_offset
)
3446 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
3450 print_vma (section
->sh_offset
, LONG_HEX
);
3453 if ((unsigned long) section
->sh_size
== section
->sh_size
)
3454 printf (" %6.6lx", (unsigned long) section
->sh_size
);
3458 print_vma (section
->sh_size
, LONG_HEX
);
3461 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
3462 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
3466 print_vma (section
->sh_entsize
, LONG_HEX
);
3469 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3471 printf ("%2ld %3lx ",
3472 (unsigned long) section
->sh_link
,
3473 (unsigned long) section
->sh_info
);
3475 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
3476 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
3479 print_vma (section
->sh_addralign
, DEC
);
3486 print_vma (section
->sh_addr
, LONG_HEX
);
3487 if ((long) section
->sh_offset
== section
->sh_offset
)
3488 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
3492 print_vma (section
->sh_offset
, LONG_HEX
);
3495 print_vma (section
->sh_size
, LONG_HEX
);
3497 print_vma (section
->sh_entsize
, LONG_HEX
);
3499 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3501 printf (" %2ld %3lx %ld\n",
3502 (unsigned long) section
->sh_link
,
3503 (unsigned long) section
->sh_info
,
3504 (unsigned long) section
->sh_addralign
);
3508 printf (_("Key to Flags:\n\
3509 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3510 I (info), L (link order), G (group), x (unknown)\n\
3511 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3516 /* Process the reloc section. */
3518 process_relocs (file
)
3521 unsigned long rel_size
;
3522 unsigned long rel_offset
;
3528 if (do_using_dynamic
)
3530 int is_rela
= FALSE
;
3535 if (dynamic_info
[DT_REL
])
3537 rel_offset
= dynamic_info
[DT_REL
];
3538 rel_size
= dynamic_info
[DT_RELSZ
];
3541 else if (dynamic_info
[DT_RELA
])
3543 rel_offset
= dynamic_info
[DT_RELA
];
3544 rel_size
= dynamic_info
[DT_RELASZ
];
3547 else if (dynamic_info
[DT_JMPREL
])
3549 rel_offset
= dynamic_info
[DT_JMPREL
];
3550 rel_size
= dynamic_info
[DT_PLTRELSZ
];
3552 switch (dynamic_info
[DT_PLTREL
])
3569 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3570 rel_offset
, rel_size
);
3572 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
3573 dynamic_symbols
, num_dynamic_syms
, dynamic_strings
, is_rela
);
3576 printf (_("\nThere are no dynamic relocations in this file.\n"));
3580 Elf32_Internal_Shdr
* section
;
3584 for (i
= 0, section
= section_headers
;
3585 i
< elf_header
.e_shnum
;
3588 if ( section
->sh_type
!= SHT_RELA
3589 && section
->sh_type
!= SHT_REL
)
3592 rel_offset
= section
->sh_offset
;
3593 rel_size
= section
->sh_size
;
3597 Elf32_Internal_Shdr
* strsec
;
3598 Elf_Internal_Sym
* symtab
;
3601 unsigned long nsyms
;
3603 printf (_("\nRelocation section "));
3605 if (string_table
== NULL
)
3606 printf ("%d", section
->sh_name
);
3608 printf (_("'%s'"), SECTION_NAME (section
));
3610 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3611 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
3616 if (section
->sh_link
)
3618 Elf32_Internal_Shdr
* symsec
;
3620 symsec
= SECTION_HEADER (section
->sh_link
);
3621 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
3622 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
3627 strsec
= SECTION_HEADER (symsec
->sh_link
);
3629 strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
3633 is_rela
= section
->sh_type
== SHT_RELA
;
3635 dump_relocations (file
, rel_offset
, rel_size
,
3636 symtab
, nsyms
, strtab
, is_rela
);
3648 printf (_("\nThere are no relocations in this file.\n"));
3654 #include "unwind-ia64.h"
3656 /* An absolute address consists of a section and an offset. If the
3657 section is NULL, the offset itself is the address, otherwise, the
3658 address equals to LOAD_ADDRESS(section) + offset. */
3662 unsigned short section
;
3668 struct unw_table_entry
3670 struct absaddr start
;
3672 struct absaddr info
;
3674 *table
; /* Unwind table. */
3675 unsigned long table_len
; /* Length of unwind table. */
3676 unsigned char * info
; /* Unwind info. */
3677 unsigned long info_size
; /* Size of unwind info. */
3678 bfd_vma info_addr
; /* starting address of unwind info. */
3679 bfd_vma seg_base
; /* Starting address of segment. */
3680 Elf_Internal_Sym
* symtab
; /* The symbol table. */
3681 unsigned long nsyms
; /* Number of symbols. */
3682 char * strtab
; /* The string table. */
3683 unsigned long strtab_size
; /* Size of string table. */
3686 static void find_symbol_for_address
PARAMS ((struct unw_aux_info
*,
3687 struct absaddr
, const char **,
3689 static void dump_ia64_unwind
PARAMS ((struct unw_aux_info
*));
3690 static int slurp_ia64_unwind_table
PARAMS ((FILE *, struct unw_aux_info
*,
3691 Elf32_Internal_Shdr
*));
3694 find_symbol_for_address (aux
, addr
, symname
, offset
)
3695 struct unw_aux_info
*aux
;
3696 struct absaddr addr
;
3697 const char **symname
;
3700 bfd_vma dist
= (bfd_vma
) 0x100000;
3701 Elf_Internal_Sym
*sym
, *best
= NULL
;
3704 for (i
= 0, sym
= aux
->symtab
; i
< aux
->nsyms
; ++i
, ++sym
)
3706 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
3707 && sym
->st_name
!= 0
3708 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
3709 && addr
.offset
>= sym
->st_value
3710 && addr
.offset
- sym
->st_value
< dist
)
3713 dist
= addr
.offset
- sym
->st_value
;
3720 *symname
= (best
->st_name
>= aux
->strtab_size
3721 ? "<corrupt>" : aux
->strtab
+ best
->st_name
);
3726 *offset
= addr
.offset
;
3730 dump_ia64_unwind (aux
)
3731 struct unw_aux_info
*aux
;
3734 struct unw_table_entry
* tp
;
3737 addr_size
= is_32bit_elf
? 4 : 8;
3739 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
3743 const unsigned char * dp
;
3744 const unsigned char * head
;
3745 const char * procname
;
3747 find_symbol_for_address (aux
, tp
->start
, &procname
, &offset
);
3749 fputs ("\n<", stdout
);
3753 fputs (procname
, stdout
);
3756 printf ("+%lx", (unsigned long) offset
);
3759 fputs (">: [", stdout
);
3760 print_vma (tp
->start
.offset
, PREFIX_HEX
);
3761 fputc ('-', stdout
);
3762 print_vma (tp
->end
.offset
, PREFIX_HEX
);
3763 printf ("), info at +0x%lx\n",
3764 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
3766 head
= aux
->info
+ (tp
->info
.offset
- aux
->info_addr
);
3767 stamp
= BYTE_GET8 ((unsigned char *) head
);
3769 printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n",
3770 (unsigned) UNW_VER (stamp
),
3771 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
3772 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
3773 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
3774 (unsigned long) (addr_size
* UNW_LENGTH (stamp
)));
3776 if (UNW_VER (stamp
) != 1)
3778 printf ("\tUnknown version.\n");
3783 for (dp
= head
+ 8; dp
< head
+ 8 + addr_size
* UNW_LENGTH (stamp
);)
3784 dp
= unw_decode (dp
, in_body
, & in_body
);
3789 slurp_ia64_unwind_table (file
, aux
, sec
)
3791 struct unw_aux_info
*aux
;
3792 Elf32_Internal_Shdr
*sec
;
3794 unsigned long size
, addr_size
, nrelas
, i
;
3795 Elf_Internal_Phdr
*prog_hdrs
, *seg
;
3796 struct unw_table_entry
*tep
;
3797 Elf32_Internal_Shdr
*relsec
;
3798 Elf_Internal_Rela
*rela
, *rp
;
3799 unsigned char *table
, *tp
;
3800 Elf_Internal_Sym
*sym
;
3801 const char *relname
;
3804 addr_size
= is_32bit_elf
? 4 : 8;
3806 /* First, find the starting address of the segment that includes
3809 if (elf_header
.e_phnum
)
3811 prog_hdrs
= (Elf_Internal_Phdr
*)
3812 xmalloc (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
3815 result
= get_32bit_program_headers (file
, prog_hdrs
);
3817 result
= get_64bit_program_headers (file
, prog_hdrs
);
3825 for (seg
= prog_hdrs
; seg
< prog_hdrs
+ elf_header
.e_phnum
; ++seg
)
3827 if (seg
->p_type
!= PT_LOAD
)
3830 if (sec
->sh_addr
>= seg
->p_vaddr
3831 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
3833 aux
->seg_base
= seg
->p_vaddr
;
3841 /* Second, build the unwind table from the contents of the unwind section: */
3842 size
= sec
->sh_size
;
3843 table
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
3844 size
, _("unwind table"));
3848 tep
= aux
->table
= xmalloc (size
/ (3 * addr_size
) * sizeof (aux
->table
[0]));
3849 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * addr_size
, ++ tep
)
3851 tep
->start
.section
= SHN_UNDEF
;
3852 tep
->end
.section
= SHN_UNDEF
;
3853 tep
->info
.section
= SHN_UNDEF
;
3856 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
3857 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
3858 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
3862 tep
->start
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 0);
3863 tep
->end
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 8);
3864 tep
->info
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 16);
3866 tep
->start
.offset
+= aux
->seg_base
;
3867 tep
->end
.offset
+= aux
->seg_base
;
3868 tep
->info
.offset
+= aux
->seg_base
;
3872 /* Third, apply any relocations to the unwind table: */
3874 for (relsec
= section_headers
;
3875 relsec
< section_headers
+ elf_header
.e_shnum
;
3878 if (relsec
->sh_type
!= SHT_RELA
3879 || SECTION_HEADER (relsec
->sh_info
) != sec
)
3882 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
3886 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
3890 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
3891 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
3893 if (ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3895 warn (_("Skipping unexpected symbol type %u\n"),
3896 ELF32_ST_TYPE (sym
->st_info
));
3902 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
3903 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
3905 if (ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3907 warn (_("Skipping unexpected symbol type %u\n"),
3908 ELF64_ST_TYPE (sym
->st_info
));
3913 if (strncmp (relname
, "R_IA64_SEGREL", 13) != 0)
3915 warn (_("Skipping unexpected relocation type %s\n"), relname
);
3919 i
= rp
->r_offset
/ (3 * addr_size
);
3921 switch (rp
->r_offset
/addr_size
% 3)
3924 aux
->table
[i
].start
.section
= sym
->st_shndx
;
3925 aux
->table
[i
].start
.offset
+= rp
->r_addend
;
3928 aux
->table
[i
].end
.section
= sym
->st_shndx
;
3929 aux
->table
[i
].end
.offset
+= rp
->r_addend
;
3932 aux
->table
[i
].info
.section
= sym
->st_shndx
;
3933 aux
->table
[i
].info
.offset
+= rp
->r_addend
;
3943 aux
->table_len
= size
/ (3 * addr_size
);
3948 process_unwind (file
)
3951 Elf32_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
3952 unsigned long i
, addr_size
, unwcount
= 0, unwstart
= 0;
3953 struct unw_aux_info aux
;
3958 if (elf_header
.e_machine
!= EM_IA_64
)
3960 printf (_("\nThere are no unwind sections in this file.\n"));
3964 memset (& aux
, 0, sizeof (aux
));
3966 addr_size
= is_32bit_elf
? 4 : 8;
3968 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
3970 if (sec
->sh_type
== SHT_SYMTAB
)
3972 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
3973 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
3975 strsec
= SECTION_HEADER (sec
->sh_link
);
3976 aux
.strtab_size
= strsec
->sh_size
;
3977 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
3978 aux
.strtab_size
, _("string table"));
3980 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
3985 printf (_("\nThere are no unwind sections in this file.\n"));
3987 while (unwcount
-- > 0)
3992 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
3993 i
< elf_header
.e_shnum
; ++i
, ++sec
)
3994 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4001 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4003 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
,
4006 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
4007 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4008 suffix
= SECTION_NAME (unwsec
) + len
;
4009 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4011 if (strncmp (SECTION_NAME (sec
),
4012 ELF_STRING_ia64_unwind_info_once
, len2
) == 0
4013 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4018 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4019 .IA_64.unwind or BAR -> .IA_64.unwind_info */
4020 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4021 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4023 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
,
4025 suffix
= SECTION_NAME (unwsec
) + len
;
4026 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4028 if (strncmp (SECTION_NAME (sec
),
4029 ELF_STRING_ia64_unwind_info
, len2
) == 0
4030 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4034 if (i
== elf_header
.e_shnum
)
4036 printf (_("\nCould not find unwind info section for "));
4038 if (string_table
== NULL
)
4039 printf ("%d", unwsec
->sh_name
);
4041 printf (_("'%s'"), SECTION_NAME (unwsec
));
4045 aux
.info_size
= sec
->sh_size
;
4046 aux
.info_addr
= sec
->sh_addr
;
4047 aux
.info
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4048 aux
.info_size
, _("unwind info"));
4050 printf (_("\nUnwind section "));
4052 if (string_table
== NULL
)
4053 printf ("%d", unwsec
->sh_name
);
4055 printf (_("'%s'"), SECTION_NAME (unwsec
));
4057 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4058 (unsigned long) unwsec
->sh_offset
,
4059 (unsigned long) (unwsec
->sh_size
/ (3 * addr_size
)));
4061 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4063 if (aux
.table_len
> 0)
4064 dump_ia64_unwind (& aux
);
4067 free ((char *) aux
.table
);
4069 free ((char *) aux
.info
);
4078 free ((char *) aux
.strtab
);
4084 dynamic_segment_mips_val (entry
)
4085 Elf_Internal_Dyn
* entry
;
4087 switch (entry
->d_tag
)
4090 if (entry
->d_un
.d_val
== 0)
4094 static const char * opts
[] =
4096 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
4097 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
4098 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
4099 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
4104 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++ cnt
)
4105 if (entry
->d_un
.d_val
& (1 << cnt
))
4107 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
4114 case DT_MIPS_IVERSION
:
4115 if (dynamic_strings
!= NULL
)
4116 printf ("Interface Version: %s\n",
4117 dynamic_strings
+ entry
->d_un
.d_val
);
4119 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4122 case DT_MIPS_TIME_STAMP
:
4127 time_t time
= entry
->d_un
.d_val
;
4128 tmp
= gmtime (&time
);
4129 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
4130 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
4131 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
4132 printf ("Time Stamp: %s\n", timebuf
);
4136 case DT_MIPS_RLD_VERSION
:
4137 case DT_MIPS_LOCAL_GOTNO
:
4138 case DT_MIPS_CONFLICTNO
:
4139 case DT_MIPS_LIBLISTNO
:
4140 case DT_MIPS_SYMTABNO
:
4141 case DT_MIPS_UNREFEXTNO
:
4142 case DT_MIPS_HIPAGENO
:
4143 case DT_MIPS_DELTA_CLASS_NO
:
4144 case DT_MIPS_DELTA_INSTANCE_NO
:
4145 case DT_MIPS_DELTA_RELOC_NO
:
4146 case DT_MIPS_DELTA_SYM_NO
:
4147 case DT_MIPS_DELTA_CLASSSYM_NO
:
4148 case DT_MIPS_COMPACT_SIZE
:
4149 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4153 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
4159 dynamic_segment_parisc_val (entry
)
4160 Elf_Internal_Dyn
* entry
;
4162 switch (entry
->d_tag
)
4164 case DT_HP_DLD_FLAGS
:
4173 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
4174 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
4175 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
4176 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
4177 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
4178 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
4179 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
4180 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
4181 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
4182 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
4183 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" }
4187 bfd_vma val
= entry
->d_un
.d_val
;
4189 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
4190 if (val
& flags
[cnt
].bit
)
4194 fputs (flags
[cnt
].str
, stdout
);
4196 val
^= flags
[cnt
].bit
;
4199 if (val
!= 0 || first
)
4203 print_vma (val
, HEX
);
4209 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4215 get_32bit_dynamic_segment (file
)
4218 Elf32_External_Dyn
* edyn
;
4219 Elf_Internal_Dyn
* entry
;
4222 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4223 dynamic_size
, _("dynamic segment"));
4227 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4228 how large this .dynamic is now. We can do this even before the byte
4229 swapping since the DT_NULL tag is recognizable. */
4231 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4234 dynamic_segment
= (Elf_Internal_Dyn
*)
4235 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4237 if (dynamic_segment
== NULL
)
4239 error (_("Out of memory\n"));
4244 for (i
= 0, entry
= dynamic_segment
;
4248 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
4249 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
4258 get_64bit_dynamic_segment (file
)
4261 Elf64_External_Dyn
* edyn
;
4262 Elf_Internal_Dyn
* entry
;
4265 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4266 dynamic_size
, _("dynamic segment"));
4270 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4271 how large this .dynamic is now. We can do this even before the byte
4272 swapping since the DT_NULL tag is recognizable. */
4274 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4277 dynamic_segment
= (Elf_Internal_Dyn
*)
4278 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4280 if (dynamic_segment
== NULL
)
4282 error (_("Out of memory\n"));
4287 for (i
= 0, entry
= dynamic_segment
;
4291 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
4292 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
4301 get_dynamic_flags (flags
)
4304 static char buff
[128];
4312 flag
= flags
& - flags
;
4320 case DF_ORIGIN
: strcpy (p
, "ORIGIN"); break;
4321 case DF_SYMBOLIC
: strcpy (p
, "SYMBOLIC"); break;
4322 case DF_TEXTREL
: strcpy (p
, "TEXTREL"); break;
4323 case DF_BIND_NOW
: strcpy (p
, "BIND_NOW"); break;
4324 case DF_STATIC_TLS
: strcpy (p
, "STATIC_TLS"); break;
4325 default: strcpy (p
, "unknown"); break;
4328 p
= strchr (p
, '\0');
4333 /* Parse and display the contents of the dynamic segment. */
4335 process_dynamic_segment (file
)
4338 Elf_Internal_Dyn
* entry
;
4341 if (dynamic_size
== 0)
4344 printf (_("\nThere is no dynamic segment in this file.\n"));
4351 if (! get_32bit_dynamic_segment (file
))
4354 else if (! get_64bit_dynamic_segment (file
))
4357 /* Find the appropriate symbol table. */
4358 if (dynamic_symbols
== NULL
)
4360 for (i
= 0, entry
= dynamic_segment
;
4364 Elf32_Internal_Shdr section
;
4366 if (entry
->d_tag
!= DT_SYMTAB
)
4369 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
4371 /* Since we do not know how big the symbol table is,
4372 we default to reading in the entire file (!) and
4373 processing that. This is overkill, I know, but it
4375 section
.sh_offset
= entry
->d_un
.d_val
- loadaddr
;
4377 if (fseek (file
, 0, SEEK_END
))
4378 error (_("Unable to seek to end of file!"));
4380 section
.sh_size
= ftell (file
) - section
.sh_offset
;
4382 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
4384 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
4386 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
4387 if (num_dynamic_syms
< 1)
4389 error (_("Unable to determine the number of symbols to load\n"));
4393 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
4397 /* Similarly find a string table. */
4398 if (dynamic_strings
== NULL
)
4400 for (i
= 0, entry
= dynamic_segment
;
4404 unsigned long offset
;
4407 if (entry
->d_tag
!= DT_STRTAB
)
4410 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
4412 /* Since we do not know how big the string table is,
4413 we default to reading in the entire file (!) and
4414 processing that. This is overkill, I know, but it
4417 offset
= entry
->d_un
.d_val
- loadaddr
;
4418 if (fseek (file
, 0, SEEK_END
))
4419 error (_("Unable to seek to end of file\n"));
4420 str_tab_len
= ftell (file
) - offset
;
4422 if (str_tab_len
< 1)
4425 (_("Unable to determine the length of the dynamic string table\n"));
4429 dynamic_strings
= (char *) get_data (NULL
, file
, offset
, str_tab_len
,
4430 _("dynamic string table"));
4435 /* And find the syminfo section if available. */
4436 if (dynamic_syminfo
== NULL
)
4438 unsigned int syminsz
= 0;
4440 for (i
= 0, entry
= dynamic_segment
;
4444 if (entry
->d_tag
== DT_SYMINENT
)
4446 /* Note: these braces are necessary to avoid a syntax
4447 error from the SunOS4 C compiler. */
4448 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
4450 else if (entry
->d_tag
== DT_SYMINSZ
)
4451 syminsz
= entry
->d_un
.d_val
;
4452 else if (entry
->d_tag
== DT_SYMINFO
)
4453 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
4456 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
4458 Elf_External_Syminfo
* extsyminfo
;
4459 Elf_Internal_Syminfo
* syminfo
;
4461 /* There is a syminfo section. Read the data. */
4462 extsyminfo
= ((Elf_External_Syminfo
*)
4463 get_data (NULL
, file
, dynamic_syminfo_offset
,
4464 syminsz
, _("symbol information")));
4468 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
4469 if (dynamic_syminfo
== NULL
)
4471 error (_("Out of memory\n"));
4475 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
4476 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
4479 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
4480 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
4487 if (do_dynamic
&& dynamic_addr
)
4488 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
4489 dynamic_addr
, (long) dynamic_size
);
4491 printf (_(" Tag Type Name/Value\n"));
4493 for (i
= 0, entry
= dynamic_segment
;
4502 print_vma (entry
->d_tag
, FULL_HEX
);
4503 dtype
= get_dynamic_type (entry
->d_tag
);
4504 printf (" (%s)%*s", dtype
,
4505 ((is_32bit_elf
? 27 : 19)
4506 - (int) strlen (dtype
)),
4510 switch (entry
->d_tag
)
4514 puts (get_dynamic_flags (entry
->d_un
.d_val
));
4524 switch (entry
->d_tag
)
4527 printf (_("Auxiliary library"));
4531 printf (_("Filter library"));
4535 printf (_("Configuration file"));
4539 printf (_("Dependency audit library"));
4543 printf (_("Audit library"));
4547 if (dynamic_strings
)
4548 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
4552 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4561 printf (_("Flags:"));
4562 if (entry
->d_un
.d_val
== 0)
4563 printf (_(" None\n"));
4566 unsigned long int val
= entry
->d_un
.d_val
;
4567 if (val
& DTF_1_PARINIT
)
4569 printf (" PARINIT");
4570 val
^= DTF_1_PARINIT
;
4572 if (val
& DTF_1_CONFEXP
)
4574 printf (" CONFEXP");
4575 val
^= DTF_1_CONFEXP
;
4578 printf (" %lx", val
);
4587 printf (_("Flags:"));
4588 if (entry
->d_un
.d_val
== 0)
4589 printf (_(" None\n"));
4592 unsigned long int val
= entry
->d_un
.d_val
;
4593 if (val
& DF_P1_LAZYLOAD
)
4595 printf (" LAZYLOAD");
4596 val
^= DF_P1_LAZYLOAD
;
4598 if (val
& DF_P1_GROUPPERM
)
4600 printf (" GROUPPERM");
4601 val
^= DF_P1_GROUPPERM
;
4604 printf (" %lx", val
);
4613 printf (_("Flags:"));
4614 if (entry
->d_un
.d_val
== 0)
4615 printf (_(" None\n"));
4618 unsigned long int val
= entry
->d_un
.d_val
;
4624 if (val
& DF_1_GLOBAL
)
4629 if (val
& DF_1_GROUP
)
4634 if (val
& DF_1_NODELETE
)
4636 printf (" NODELETE");
4637 val
^= DF_1_NODELETE
;
4639 if (val
& DF_1_LOADFLTR
)
4641 printf (" LOADFLTR");
4642 val
^= DF_1_LOADFLTR
;
4644 if (val
& DF_1_INITFIRST
)
4646 printf (" INITFIRST");
4647 val
^= DF_1_INITFIRST
;
4649 if (val
& DF_1_NOOPEN
)
4654 if (val
& DF_1_ORIGIN
)
4659 if (val
& DF_1_DIRECT
)
4664 if (val
& DF_1_TRANS
)
4669 if (val
& DF_1_INTERPOSE
)
4671 printf (" INTERPOSE");
4672 val
^= DF_1_INTERPOSE
;
4674 if (val
& DF_1_NODEFLIB
)
4676 printf (" NODEFLIB");
4677 val
^= DF_1_NODEFLIB
;
4679 if (val
& DF_1_NODUMP
)
4684 if (val
& DF_1_CONLFAT
)
4686 printf (" CONLFAT");
4687 val
^= DF_1_CONLFAT
;
4690 printf (" %lx", val
);
4698 puts (get_dynamic_type (entry
->d_un
.d_val
));
4718 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
4724 if (dynamic_strings
== NULL
)
4727 name
= dynamic_strings
+ entry
->d_un
.d_val
;
4731 switch (entry
->d_tag
)
4734 printf (_("Shared library: [%s]"), name
);
4736 if (strcmp (name
, program_interpreter
) == 0)
4737 printf (_(" program interpreter"));
4741 printf (_("Library soname: [%s]"), name
);
4745 printf (_("Library rpath: [%s]"), name
);
4749 printf (_("Library runpath: [%s]"), name
);
4753 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4758 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4774 case DT_INIT_ARRAYSZ
:
4775 case DT_FINI_ARRAYSZ
:
4776 case DT_GNU_CONFLICTSZ
:
4777 case DT_GNU_LIBLISTSZ
:
4780 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
4781 printf (" (bytes)\n");
4791 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
4804 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
4808 name
= dynamic_strings
+ entry
->d_un
.d_val
;
4812 printf (_("Not needed object: [%s]\n"), name
);
4817 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4823 /* The value of this entry is ignored. */
4826 case DT_GNU_PRELINKED
:
4830 time_t time
= entry
->d_un
.d_val
;
4832 tmp
= gmtime (&time
);
4833 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
4834 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
4835 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
4841 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
4842 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
4847 switch (elf_header
.e_machine
)
4850 case EM_MIPS_RS3_LE
:
4851 dynamic_segment_mips_val (entry
);
4854 dynamic_segment_parisc_val (entry
);
4857 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4869 get_ver_flags (flags
)
4872 static char buff
[32];
4879 if (flags
& VER_FLG_BASE
)
4880 strcat (buff
, "BASE ");
4882 if (flags
& VER_FLG_WEAK
)
4884 if (flags
& VER_FLG_BASE
)
4885 strcat (buff
, "| ");
4887 strcat (buff
, "WEAK ");
4890 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
4891 strcat (buff
, "| <unknown>");
4896 /* Display the contents of the version sections. */
4898 process_version_sections (file
)
4901 Elf32_Internal_Shdr
* section
;
4908 for (i
= 0, section
= section_headers
;
4909 i
< elf_header
.e_shnum
;
4912 switch (section
->sh_type
)
4914 case SHT_GNU_verdef
:
4916 Elf_External_Verdef
* edefs
;
4923 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4924 SECTION_NAME (section
), section
->sh_info
);
4926 printf (_(" Addr: 0x"));
4927 printf_vma (section
->sh_addr
);
4928 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4929 (unsigned long) section
->sh_offset
, section
->sh_link
,
4930 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
4932 edefs
= ((Elf_External_Verdef
*)
4933 get_data (NULL
, file
, section
->sh_offset
,
4935 _("version definition section")));
4939 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++ cnt
)
4942 Elf_External_Verdef
* edef
;
4943 Elf_Internal_Verdef ent
;
4944 Elf_External_Verdaux
* eaux
;
4945 Elf_Internal_Verdaux aux
;
4949 vstart
= ((char *) edefs
) + idx
;
4951 edef
= (Elf_External_Verdef
*) vstart
;
4953 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
4954 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
4955 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
4956 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
4957 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
4958 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
4959 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
4961 printf (_(" %#06x: Rev: %d Flags: %s"),
4962 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
4964 printf (_(" Index: %d Cnt: %d "),
4965 ent
.vd_ndx
, ent
.vd_cnt
);
4967 vstart
+= ent
.vd_aux
;
4969 eaux
= (Elf_External_Verdaux
*) vstart
;
4971 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
4972 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
4974 if (dynamic_strings
)
4975 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
4977 printf (_("Name index: %ld\n"), aux
.vda_name
);
4979 isum
= idx
+ ent
.vd_aux
;
4981 for (j
= 1; j
< ent
.vd_cnt
; j
++)
4983 isum
+= aux
.vda_next
;
4984 vstart
+= aux
.vda_next
;
4986 eaux
= (Elf_External_Verdaux
*) vstart
;
4988 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
4989 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
4991 if (dynamic_strings
)
4992 printf (_(" %#06x: Parent %d: %s\n"),
4993 isum
, j
, dynamic_strings
+ aux
.vda_name
);
4995 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4996 isum
, j
, aux
.vda_name
);
5006 case SHT_GNU_verneed
:
5008 Elf_External_Verneed
* eneed
;
5014 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
5015 SECTION_NAME (section
), section
->sh_info
);
5017 printf (_(" Addr: 0x"));
5018 printf_vma (section
->sh_addr
);
5019 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
5020 (unsigned long) section
->sh_offset
, section
->sh_link
,
5021 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5023 eneed
= ((Elf_External_Verneed
*)
5024 get_data (NULL
, file
, section
->sh_offset
,
5025 section
->sh_size
, _("version need section")));
5029 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5031 Elf_External_Verneed
* entry
;
5032 Elf_Internal_Verneed ent
;
5037 vstart
= ((char *) eneed
) + idx
;
5039 entry
= (Elf_External_Verneed
*) vstart
;
5041 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
5042 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
5043 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
5044 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
5045 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
5047 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
5049 if (dynamic_strings
)
5050 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
5052 printf (_(" File: %lx"), ent
.vn_file
);
5054 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
5056 vstart
+= ent
.vn_aux
;
5058 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
5060 Elf_External_Vernaux
* eaux
;
5061 Elf_Internal_Vernaux aux
;
5063 eaux
= (Elf_External_Vernaux
*) vstart
;
5065 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
5066 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
5067 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
5068 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
5069 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
5071 if (dynamic_strings
)
5072 printf (_(" %#06x: Name: %s"),
5073 isum
, dynamic_strings
+ aux
.vna_name
);
5075 printf (_(" %#06x: Name index: %lx"),
5076 isum
, aux
.vna_name
);
5078 printf (_(" Flags: %s Version: %d\n"),
5079 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
5081 isum
+= aux
.vna_next
;
5082 vstart
+= aux
.vna_next
;
5092 case SHT_GNU_versym
:
5094 Elf32_Internal_Shdr
* link_section
;
5097 unsigned char * edata
;
5098 unsigned short * data
;
5100 Elf_Internal_Sym
* symbols
;
5101 Elf32_Internal_Shdr
* string_sec
;
5103 link_section
= SECTION_HEADER (section
->sh_link
);
5104 total
= section
->sh_size
/ section
->sh_entsize
;
5108 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
5110 string_sec
= SECTION_HEADER (link_section
->sh_link
);
5112 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5113 string_sec
->sh_size
,
5114 _("version string table"));
5118 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
5119 SECTION_NAME (section
), total
);
5121 printf (_(" Addr: "));
5122 printf_vma (section
->sh_addr
);
5123 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5124 (unsigned long) section
->sh_offset
, section
->sh_link
,
5125 SECTION_NAME (link_section
));
5129 get_data (NULL
, file
,
5130 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] - loadaddr
,
5131 total
* sizeof (short), _("version symbol data")));
5138 data
= (unsigned short *) malloc (total
* sizeof (short));
5140 for (cnt
= total
; cnt
--;)
5141 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
5146 for (cnt
= 0; cnt
< total
; cnt
+= 4)
5149 int check_def
, check_need
;
5152 printf (" %03x:", cnt
);
5154 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
5155 switch (data
[cnt
+ j
])
5158 fputs (_(" 0 (*local*) "), stdout
);
5162 fputs (_(" 1 (*global*) "), stdout
);
5166 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
5167 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
5171 if (SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
5174 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
5181 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
5183 Elf_Internal_Verneed ivn
;
5184 unsigned long offset
;
5186 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5191 Elf_Internal_Vernaux ivna
;
5192 Elf_External_Verneed evn
;
5193 Elf_External_Vernaux evna
;
5194 unsigned long a_off
;
5196 get_data (&evn
, file
, offset
, sizeof (evn
),
5199 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5200 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5202 a_off
= offset
+ ivn
.vn_aux
;
5206 get_data (&evna
, file
, a_off
, sizeof (evna
),
5207 _("version need aux (2)"));
5209 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5210 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5212 a_off
+= ivna
.vna_next
;
5214 while (ivna
.vna_other
!= data
[cnt
+ j
]
5215 && ivna
.vna_next
!= 0);
5217 if (ivna
.vna_other
== data
[cnt
+ j
])
5219 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5221 name
= strtab
+ ivna
.vna_name
;
5222 nn
+= printf ("(%s%-*s",
5224 12 - (int) strlen (name
),
5230 offset
+= ivn
.vn_next
;
5232 while (ivn
.vn_next
);
5235 if (check_def
&& data
[cnt
+ j
] != 0x8001
5236 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5238 Elf_Internal_Verdef ivd
;
5239 Elf_External_Verdef evd
;
5240 unsigned long offset
;
5242 offset
= version_info
5243 [DT_VERSIONTAGIDX (DT_VERDEF
)] - loadaddr
;
5247 get_data (&evd
, file
, offset
, sizeof (evd
),
5250 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
5251 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
5253 offset
+= ivd
.vd_next
;
5255 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
5256 && ivd
.vd_next
!= 0);
5258 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
5260 Elf_External_Verdaux evda
;
5261 Elf_Internal_Verdaux ivda
;
5263 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
5265 get_data (&evda
, file
,
5266 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
5267 sizeof (evda
), _("version def aux"));
5269 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
5271 name
= strtab
+ ivda
.vda_name
;
5272 nn
+= printf ("(%s%-*s",
5274 12 - (int) strlen (name
),
5280 printf ("%*c", 18 - nn
, ' ');
5298 printf (_("\nNo version information found in this file.\n"));
5304 get_symbol_binding (binding
)
5305 unsigned int binding
;
5307 static char buff
[32];
5311 case STB_LOCAL
: return "LOCAL";
5312 case STB_GLOBAL
: return "GLOBAL";
5313 case STB_WEAK
: return "WEAK";
5315 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
5316 sprintf (buff
, _("<processor specific>: %d"), binding
);
5317 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
5318 sprintf (buff
, _("<OS specific>: %d"), binding
);
5320 sprintf (buff
, _("<unknown>: %d"), binding
);
5326 get_symbol_type (type
)
5329 static char buff
[32];
5333 case STT_NOTYPE
: return "NOTYPE";
5334 case STT_OBJECT
: return "OBJECT";
5335 case STT_FUNC
: return "FUNC";
5336 case STT_SECTION
: return "SECTION";
5337 case STT_FILE
: return "FILE";
5338 case STT_COMMON
: return "COMMON";
5339 case STT_TLS
: return "TLS";
5341 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
5343 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
5344 return "THUMB_FUNC";
5346 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
5349 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
5350 return "PARISC_MILLI";
5352 sprintf (buff
, _("<processor specific>: %d"), type
);
5354 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
5356 if (elf_header
.e_machine
== EM_PARISC
)
5358 if (type
== STT_HP_OPAQUE
)
5360 if (type
== STT_HP_STUB
)
5364 sprintf (buff
, _("<OS specific>: %d"), type
);
5367 sprintf (buff
, _("<unknown>: %d"), type
);
5373 get_symbol_visibility (visibility
)
5374 unsigned int visibility
;
5378 case STV_DEFAULT
: return "DEFAULT";
5379 case STV_INTERNAL
: return "INTERNAL";
5380 case STV_HIDDEN
: return "HIDDEN";
5381 case STV_PROTECTED
: return "PROTECTED";
5387 get_symbol_index_type (type
)
5392 case SHN_UNDEF
: return "UND";
5393 case SHN_ABS
: return "ABS";
5394 case SHN_COMMON
: return "COM";
5396 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
5398 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
5400 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
5404 static char buff
[32];
5406 sprintf (buff
, "%3d", type
);
5413 get_dynamic_data (file
, number
)
5415 unsigned int number
;
5417 unsigned char * e_data
;
5420 e_data
= (unsigned char *) malloc (number
* 4);
5424 error (_("Out of memory\n"));
5428 if (fread (e_data
, 4, number
, file
) != number
)
5430 error (_("Unable to read in dynamic data\n"));
5434 i_data
= (int *) malloc (number
* sizeof (* i_data
));
5438 error (_("Out of memory\n"));
5444 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
5451 /* Dump the symbol table. */
5453 process_symbol_table (file
)
5456 Elf32_Internal_Shdr
* section
;
5457 unsigned char nb
[4];
5458 unsigned char nc
[4];
5461 int * buckets
= NULL
;
5462 int * chains
= NULL
;
5464 if (! do_syms
&& !do_histogram
)
5467 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
5470 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
5472 error (_("Unable to seek to start of dynamic information"));
5476 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
5478 error (_("Failed to read in number of buckets\n"));
5482 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
5484 error (_("Failed to read in number of chains\n"));
5488 nbuckets
= byte_get (nb
, 4);
5489 nchains
= byte_get (nc
, 4);
5491 buckets
= get_dynamic_data (file
, nbuckets
);
5492 chains
= get_dynamic_data (file
, nchains
);
5494 if (buckets
== NULL
|| chains
== NULL
)
5499 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
5504 printf (_("\nSymbol table for image:\n"));
5506 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5508 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5510 for (hn
= 0; hn
< nbuckets
; hn
++)
5515 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
5517 Elf_Internal_Sym
* psym
;
5519 psym
= dynamic_symbols
+ si
;
5521 printf (" %3d %3d: ", si
, hn
);
5522 print_vma (psym
->st_value
, LONG_HEX
);
5524 print_vma (psym
->st_size
, DEC_5
);
5526 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5527 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5528 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5529 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
5530 print_symbol (25, dynamic_strings
+ psym
->st_name
);
5535 else if (do_syms
&& !do_using_dynamic
)
5539 for (i
= 0, section
= section_headers
;
5540 i
< elf_header
.e_shnum
;
5545 Elf_Internal_Sym
* symtab
;
5546 Elf_Internal_Sym
* psym
;
5549 if ( section
->sh_type
!= SHT_SYMTAB
5550 && section
->sh_type
!= SHT_DYNSYM
)
5553 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5554 SECTION_NAME (section
),
5555 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
5557 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5559 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5561 symtab
= GET_ELF_SYMBOLS (file
, section
);
5565 if (section
->sh_link
== elf_header
.e_shstrndx
)
5566 strtab
= string_table
;
5569 Elf32_Internal_Shdr
* string_sec
;
5571 string_sec
= SECTION_HEADER (section
->sh_link
);
5573 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5574 string_sec
->sh_size
,
5578 for (si
= 0, psym
= symtab
;
5579 si
< section
->sh_size
/ section
->sh_entsize
;
5582 printf ("%6d: ", si
);
5583 print_vma (psym
->st_value
, LONG_HEX
);
5585 print_vma (psym
->st_size
, DEC_5
);
5586 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5587 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5588 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5589 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
5590 print_symbol (25, strtab
+ psym
->st_name
);
5592 if (section
->sh_type
== SHT_DYNSYM
&&
5593 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
5595 unsigned char data
[2];
5596 unsigned short vers_data
;
5597 unsigned long offset
;
5601 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
5604 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
5605 sizeof (data
), _("version data"));
5607 vers_data
= byte_get (data
, 2);
5609 is_nobits
= (SECTION_HEADER (psym
->st_shndx
)->sh_type
5612 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
5614 if ((vers_data
& 0x8000) || vers_data
> 1)
5616 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5617 && (is_nobits
|| ! check_def
))
5619 Elf_External_Verneed evn
;
5620 Elf_Internal_Verneed ivn
;
5621 Elf_Internal_Vernaux ivna
;
5623 /* We must test both. */
5624 offset
= version_info
5625 [DT_VERSIONTAGIDX (DT_VERNEED
)] - loadaddr
;
5629 unsigned long vna_off
;
5631 get_data (&evn
, file
, offset
, sizeof (evn
),
5634 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5635 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5637 vna_off
= offset
+ ivn
.vn_aux
;
5641 Elf_External_Vernaux evna
;
5643 get_data (&evna
, file
, vna_off
,
5645 _("version need aux (3)"));
5647 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5648 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5649 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5651 vna_off
+= ivna
.vna_next
;
5653 while (ivna
.vna_other
!= vers_data
5654 && ivna
.vna_next
!= 0);
5656 if (ivna
.vna_other
== vers_data
)
5659 offset
+= ivn
.vn_next
;
5661 while (ivn
.vn_next
!= 0);
5663 if (ivna
.vna_other
== vers_data
)
5666 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
5669 else if (! is_nobits
)
5670 error (_("bad dynamic symbol"));
5677 if (vers_data
!= 0x8001
5678 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5680 Elf_Internal_Verdef ivd
;
5681 Elf_Internal_Verdaux ivda
;
5682 Elf_External_Verdaux evda
;
5683 unsigned long offset
;
5686 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
5691 Elf_External_Verdef evd
;
5693 get_data (&evd
, file
, offset
, sizeof (evd
),
5696 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
5697 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
5698 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
5700 offset
+= ivd
.vd_next
;
5702 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
5703 && ivd
.vd_next
!= 0);
5705 offset
-= ivd
.vd_next
;
5706 offset
+= ivd
.vd_aux
;
5708 get_data (&evda
, file
, offset
, sizeof (evda
),
5709 _("version def aux"));
5711 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
5713 if (psym
->st_name
!= ivda
.vda_name
)
5714 printf ((vers_data
& 0x8000)
5716 strtab
+ ivda
.vda_name
);
5726 if (strtab
!= string_table
)
5732 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5734 if (do_histogram
&& buckets
!= NULL
)
5741 int nzero_counts
= 0;
5744 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5746 printf (_(" Length Number %% of total Coverage\n"));
5748 lengths
= (int *) calloc (nbuckets
, sizeof (int));
5749 if (lengths
== NULL
)
5751 error (_("Out of memory"));
5754 for (hn
= 0; hn
< nbuckets
; ++hn
)
5759 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
5762 if (maxlength
< ++lengths
[hn
])
5767 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
5770 error (_("Out of memory"));
5774 for (hn
= 0; hn
< nbuckets
; ++hn
)
5775 ++ counts
[lengths
[hn
]];
5779 printf (" 0 %-10d (%5.1f%%)\n",
5780 counts
[0], (counts
[0] * 100.0) / nbuckets
);
5781 for (si
= 1; si
<= maxlength
; ++si
)
5783 nzero_counts
+= counts
[si
] * si
;
5784 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5785 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
5786 (nzero_counts
* 100.0) / nsyms
);
5794 if (buckets
!= NULL
)
5804 process_syminfo (file
)
5805 FILE * file ATTRIBUTE_UNUSED
;
5809 if (dynamic_syminfo
== NULL
5811 /* No syminfo, this is ok. */
5814 /* There better should be a dynamic symbol section. */
5815 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
5819 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5820 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
5822 printf (_(" Num: Name BoundTo Flags\n"));
5823 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
5825 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
5827 printf ("%4d: ", i
);
5828 print_symbol (30, dynamic_strings
+ dynamic_symbols
[i
].st_name
);
5831 switch (dynamic_syminfo
[i
].si_boundto
)
5833 case SYMINFO_BT_SELF
:
5834 fputs ("SELF ", stdout
);
5836 case SYMINFO_BT_PARENT
:
5837 fputs ("PARENT ", stdout
);
5840 if (dynamic_syminfo
[i
].si_boundto
> 0
5841 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
5843 print_symbol (10, dynamic_strings
5845 [dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
);
5849 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
5853 if (flags
& SYMINFO_FLG_DIRECT
)
5855 if (flags
& SYMINFO_FLG_PASSTHRU
)
5856 printf (" PASSTHRU");
5857 if (flags
& SYMINFO_FLG_COPY
)
5859 if (flags
& SYMINFO_FLG_LAZYLOAD
)
5860 printf (" LAZYLOAD");
5868 #ifdef SUPPORT_DISASSEMBLY
5870 disassemble_section (section
, file
)
5871 Elf32_Internal_Shdr
* section
;
5874 printf (_("\nAssembly dump of section %s\n"),
5875 SECTION_NAME (section
));
5877 /* XXX -- to be done --- XXX */
5884 dump_section (section
, file
)
5885 Elf32_Internal_Shdr
* section
;
5888 bfd_size_type bytes
;
5890 unsigned char * data
;
5891 unsigned char * start
;
5893 bytes
= section
->sh_size
;
5897 printf (_("\nSection '%s' has no data to dump.\n"),
5898 SECTION_NAME (section
));
5902 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
5904 addr
= section
->sh_addr
;
5906 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, bytes
,
5919 lbytes
= (bytes
> 16 ? 16 : bytes
);
5921 printf (" 0x%8.8lx ", (unsigned long) addr
);
5923 switch (elf_header
.e_ident
[EI_DATA
])
5927 for (j
= 15; j
>= 0; j
--)
5930 printf ("%2.2x", data
[j
]);
5940 for (j
= 0; j
< 16; j
++)
5943 printf ("%2.2x", data
[j
]);
5953 for (j
= 0; j
< lbytes
; j
++)
5956 if (k
>= ' ' && k
< 0x80)
5975 static unsigned long int
5976 read_leb128 (data
, length_return
, sign
)
5977 unsigned char * data
;
5978 int * length_return
;
5981 unsigned long int result
= 0;
5982 unsigned int num_read
= 0;
5991 result
|= (byte
& 0x7f) << shift
;
5996 while (byte
& 0x80);
5998 if (length_return
!= NULL
)
5999 * length_return
= num_read
;
6001 if (sign
&& (shift
< 32) && (byte
& 0x40))
6002 result
|= -1 << shift
;
6007 typedef struct State_Machine_Registers
6009 unsigned long address
;
6012 unsigned int column
;
6016 /* This variable hold the number of the last entry seen
6017 in the File Table. */
6018 unsigned int last_file_entry
;
6021 static SMR state_machine_regs
;
6024 reset_state_machine (is_stmt
)
6027 state_machine_regs
.address
= 0;
6028 state_machine_regs
.file
= 1;
6029 state_machine_regs
.line
= 1;
6030 state_machine_regs
.column
= 0;
6031 state_machine_regs
.is_stmt
= is_stmt
;
6032 state_machine_regs
.basic_block
= 0;
6033 state_machine_regs
.end_sequence
= 0;
6034 state_machine_regs
.last_file_entry
= 0;
6037 /* Handled an extend line op. Returns true if this is the end
6040 process_extended_line_op (data
, is_stmt
, pointer_size
)
6041 unsigned char * data
;
6045 unsigned char op_code
;
6048 unsigned char * name
;
6051 len
= read_leb128 (data
, & bytes_read
, 0);
6056 warn (_("badly formed extended line op encountered!\n"));
6061 op_code
= * data
++;
6063 printf (_(" Extended opcode %d: "), op_code
);
6067 case DW_LNE_end_sequence
:
6068 printf (_("End of Sequence\n\n"));
6069 reset_state_machine (is_stmt
);
6072 case DW_LNE_set_address
:
6073 adr
= byte_get (data
, pointer_size
);
6074 printf (_("set Address to 0x%lx\n"), adr
);
6075 state_machine_regs
.address
= adr
;
6078 case DW_LNE_define_file
:
6079 printf (_(" define new File Table entry\n"));
6080 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6082 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
6084 data
+= strlen ((char *) data
) + 1;
6085 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6087 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6089 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6090 printf (_("%s\n\n"), name
);
6094 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
6101 /* Size of pointers in the .debug_line section. This information is not
6102 really present in that section. It's obtained before dumping the debug
6103 sections by doing some pre-scan of the .debug_info section. */
6104 static int debug_line_pointer_size
= 4;
6107 display_debug_lines (section
, start
, file
)
6108 Elf32_Internal_Shdr
* section
;
6109 unsigned char * start
;
6110 FILE * file ATTRIBUTE_UNUSED
;
6112 DWARF2_External_LineInfo
* external
;
6113 DWARF2_Internal_LineInfo info
;
6114 unsigned char * standard_opcodes
;
6115 unsigned char * data
= start
;
6116 unsigned char * end
= start
+ section
->sh_size
;
6117 unsigned char * end_of_sequence
;
6120 printf (_("\nDump of debug contents of section %s:\n\n"),
6121 SECTION_NAME (section
));
6125 external
= (DWARF2_External_LineInfo
*) data
;
6127 /* Check the length of the block. */
6128 info
.li_length
= BYTE_GET (external
->li_length
);
6130 if (info
.li_length
== 0xffffffff)
6132 warn (_("64-bit DWARF line info is not supported yet.\n"));
6136 if (info
.li_length
+ sizeof (external
->li_length
) > section
->sh_size
)
6139 (_("The line info appears to be corrupt - the section is too small\n"));
6143 /* Check its version number. */
6144 info
.li_version
= BYTE_GET (external
->li_version
);
6145 if (info
.li_version
!= 2)
6147 warn (_("Only DWARF version 2 line info is currently supported.\n"));
6151 info
.li_prologue_length
= BYTE_GET (external
->li_prologue_length
);
6152 info
.li_min_insn_length
= BYTE_GET (external
->li_min_insn_length
);
6153 info
.li_default_is_stmt
= BYTE_GET (external
->li_default_is_stmt
);
6154 info
.li_line_base
= BYTE_GET (external
->li_line_base
);
6155 info
.li_line_range
= BYTE_GET (external
->li_line_range
);
6156 info
.li_opcode_base
= BYTE_GET (external
->li_opcode_base
);
6158 /* Sign extend the line base field. */
6159 info
.li_line_base
<<= 24;
6160 info
.li_line_base
>>= 24;
6162 printf (_(" Length: %ld\n"), info
.li_length
);
6163 printf (_(" DWARF Version: %d\n"), info
.li_version
);
6164 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
6165 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
6166 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
6167 printf (_(" Line Base: %d\n"), info
.li_line_base
);
6168 printf (_(" Line Range: %d\n"), info
.li_line_range
);
6169 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
6171 end_of_sequence
= data
+ info
.li_length
+ sizeof (external
->li_length
);
6173 reset_state_machine (info
.li_default_is_stmt
);
6175 /* Display the contents of the Opcodes table. */
6176 standard_opcodes
= data
+ sizeof (* external
);
6178 printf (_("\n Opcodes:\n"));
6180 for (i
= 1; i
< info
.li_opcode_base
; i
++)
6181 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
6183 /* Display the contents of the Directory table. */
6184 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
6187 printf (_("\n The Directory Table is empty.\n"));
6190 printf (_("\n The Directory Table:\n"));
6194 printf (_(" %s\n"), data
);
6196 data
+= strlen ((char *) data
) + 1;
6200 /* Skip the NUL at the end of the table. */
6203 /* Display the contents of the File Name table. */
6205 printf (_("\n The File Name Table is empty.\n"));
6208 printf (_("\n The File Name Table:\n"));
6209 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6213 unsigned char * name
;
6216 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
6219 data
+= strlen ((char *) data
) + 1;
6221 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6223 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6225 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6227 printf (_("%s\n"), name
);
6231 /* Skip the NUL at the end of the table. */
6234 /* Now display the statements. */
6235 printf (_("\n Line Number Statements:\n"));
6238 while (data
< end_of_sequence
)
6240 unsigned char op_code
;
6244 op_code
= * data
++;
6246 if (op_code
>= info
.li_opcode_base
)
6248 op_code
-= info
.li_opcode_base
;
6249 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
6250 state_machine_regs
.address
+= adv
;
6251 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6252 op_code
, adv
, state_machine_regs
.address
);
6253 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
6254 state_machine_regs
.line
+= adv
;
6255 printf (_(" and Line by %d to %d\n"),
6256 adv
, state_machine_regs
.line
);
6258 else switch (op_code
)
6260 case DW_LNS_extended_op
:
6261 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
6262 debug_line_pointer_size
);
6266 printf (_(" Copy\n"));
6269 case DW_LNS_advance_pc
:
6270 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
6272 state_machine_regs
.address
+= adv
;
6273 printf (_(" Advance PC by %d to %lx\n"), adv
,
6274 state_machine_regs
.address
);
6277 case DW_LNS_advance_line
:
6278 adv
= read_leb128 (data
, & bytes_read
, 1);
6280 state_machine_regs
.line
+= adv
;
6281 printf (_(" Advance Line by %d to %d\n"), adv
,
6282 state_machine_regs
.line
);
6285 case DW_LNS_set_file
:
6286 adv
= read_leb128 (data
, & bytes_read
, 0);
6288 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6290 state_machine_regs
.file
= adv
;
6293 case DW_LNS_set_column
:
6294 adv
= read_leb128 (data
, & bytes_read
, 0);
6296 printf (_(" Set column to %d\n"), adv
);
6297 state_machine_regs
.column
= adv
;
6300 case DW_LNS_negate_stmt
:
6301 adv
= state_machine_regs
.is_stmt
;
6303 printf (_(" Set is_stmt to %d\n"), adv
);
6304 state_machine_regs
.is_stmt
= adv
;
6307 case DW_LNS_set_basic_block
:
6308 printf (_(" Set basic block\n"));
6309 state_machine_regs
.basic_block
= 1;
6312 case DW_LNS_const_add_pc
:
6313 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
6314 * info
.li_min_insn_length
);
6315 state_machine_regs
.address
+= adv
;
6316 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
6317 state_machine_regs
.address
);
6320 case DW_LNS_fixed_advance_pc
:
6321 adv
= byte_get (data
, 2);
6323 state_machine_regs
.address
+= adv
;
6324 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6325 adv
, state_machine_regs
.address
);
6328 case DW_LNS_set_prologue_end
:
6329 printf (_(" Set prologue_end to true\n"));
6332 case DW_LNS_set_epilogue_begin
:
6333 printf (_(" Set epilogue_begin to true\n"));
6336 case DW_LNS_set_isa
:
6337 adv
= read_leb128 (data
, & bytes_read
, 0);
6339 printf (_(" Set ISA to %d\n"), adv
);
6343 printf (_(" Unknown opcode %d with operands: "), op_code
);
6346 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
6348 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
6349 i
== 1 ? "" : ", ");
6364 display_debug_pubnames (section
, start
, file
)
6365 Elf32_Internal_Shdr
* section
;
6366 unsigned char * start
;
6367 FILE * file ATTRIBUTE_UNUSED
;
6369 DWARF2_External_PubNames
* external
;
6370 DWARF2_Internal_PubNames pubnames
;
6371 unsigned char * end
;
6373 end
= start
+ section
->sh_size
;
6375 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6379 unsigned char * data
;
6380 unsigned long offset
;
6382 external
= (DWARF2_External_PubNames
*) start
;
6384 pubnames
.pn_length
= BYTE_GET (external
->pn_length
);
6385 pubnames
.pn_version
= BYTE_GET (external
->pn_version
);
6386 pubnames
.pn_offset
= BYTE_GET (external
->pn_offset
);
6387 pubnames
.pn_size
= BYTE_GET (external
->pn_size
);
6389 data
= start
+ sizeof (* external
);
6390 start
+= pubnames
.pn_length
+ sizeof (external
->pn_length
);
6392 if (pubnames
.pn_length
== 0xffffffff)
6394 warn (_("64-bit DWARF pubnames are not supported yet.\n"));
6398 if (pubnames
.pn_version
!= 2)
6400 static int warned
= 0;
6404 warn (_("Only DWARF 2 pubnames are currently supported\n"));
6411 printf (_(" Length: %ld\n"),
6412 pubnames
.pn_length
);
6413 printf (_(" Version: %d\n"),
6414 pubnames
.pn_version
);
6415 printf (_(" Offset into .debug_info section: %ld\n"),
6416 pubnames
.pn_offset
);
6417 printf (_(" Size of area in .debug_info section: %ld\n"),
6420 printf (_("\n Offset\tName\n"));
6424 offset
= byte_get (data
, 4);
6429 printf (" %ld\t\t%s\n", offset
, data
);
6430 data
+= strlen ((char *) data
) + 1;
6433 while (offset
!= 0);
6446 case DW_TAG_padding
: return "DW_TAG_padding";
6447 case DW_TAG_array_type
: return "DW_TAG_array_type";
6448 case DW_TAG_class_type
: return "DW_TAG_class_type";
6449 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
6450 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
6451 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
6452 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
6453 case DW_TAG_label
: return "DW_TAG_label";
6454 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
6455 case DW_TAG_member
: return "DW_TAG_member";
6456 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
6457 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
6458 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
6459 case DW_TAG_string_type
: return "DW_TAG_string_type";
6460 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
6461 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
6462 case DW_TAG_typedef
: return "DW_TAG_typedef";
6463 case DW_TAG_union_type
: return "DW_TAG_union_type";
6464 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
6465 case DW_TAG_variant
: return "DW_TAG_variant";
6466 case DW_TAG_common_block
: return "DW_TAG_common_block";
6467 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
6468 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
6469 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
6470 case DW_TAG_module
: return "DW_TAG_module";
6471 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
6472 case DW_TAG_set_type
: return "DW_TAG_set_type";
6473 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
6474 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
6475 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
6476 case DW_TAG_base_type
: return "DW_TAG_base_type";
6477 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
6478 case DW_TAG_const_type
: return "DW_TAG_const_type";
6479 case DW_TAG_constant
: return "DW_TAG_constant";
6480 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
6481 case DW_TAG_file_type
: return "DW_TAG_file_type";
6482 case DW_TAG_friend
: return "DW_TAG_friend";
6483 case DW_TAG_namelist
: return "DW_TAG_namelist";
6484 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
6485 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
6486 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
6487 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
6488 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
6489 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
6490 case DW_TAG_try_block
: return "DW_TAG_try_block";
6491 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
6492 case DW_TAG_variable
: return "DW_TAG_variable";
6493 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
6494 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
6495 case DW_TAG_format_label
: return "DW_TAG_format_label";
6496 case DW_TAG_function_template
: return "DW_TAG_function_template";
6497 case DW_TAG_class_template
: return "DW_TAG_class_template";
6498 /* DWARF 2.1 values. */
6499 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
6500 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
6501 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
6502 case DW_TAG_namespace
: return "DW_TAG_namespace";
6503 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
6504 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
6505 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
6506 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
6509 static char buffer
[100];
6511 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
6518 get_AT_name (attribute
)
6519 unsigned long attribute
;
6523 case DW_AT_sibling
: return "DW_AT_sibling";
6524 case DW_AT_location
: return "DW_AT_location";
6525 case DW_AT_name
: return "DW_AT_name";
6526 case DW_AT_ordering
: return "DW_AT_ordering";
6527 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
6528 case DW_AT_byte_size
: return "DW_AT_byte_size";
6529 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
6530 case DW_AT_bit_size
: return "DW_AT_bit_size";
6531 case DW_AT_element_list
: return "DW_AT_element_list";
6532 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
6533 case DW_AT_low_pc
: return "DW_AT_low_pc";
6534 case DW_AT_high_pc
: return "DW_AT_high_pc";
6535 case DW_AT_language
: return "DW_AT_language";
6536 case DW_AT_member
: return "DW_AT_member";
6537 case DW_AT_discr
: return "DW_AT_discr";
6538 case DW_AT_discr_value
: return "DW_AT_discr_value";
6539 case DW_AT_visibility
: return "DW_AT_visibility";
6540 case DW_AT_import
: return "DW_AT_import";
6541 case DW_AT_string_length
: return "DW_AT_string_length";
6542 case DW_AT_common_reference
: return "DW_AT_common_reference";
6543 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
6544 case DW_AT_const_value
: return "DW_AT_const_value";
6545 case DW_AT_containing_type
: return "DW_AT_containing_type";
6546 case DW_AT_default_value
: return "DW_AT_default_value";
6547 case DW_AT_inline
: return "DW_AT_inline";
6548 case DW_AT_is_optional
: return "DW_AT_is_optional";
6549 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
6550 case DW_AT_producer
: return "DW_AT_producer";
6551 case DW_AT_prototyped
: return "DW_AT_prototyped";
6552 case DW_AT_return_addr
: return "DW_AT_return_addr";
6553 case DW_AT_start_scope
: return "DW_AT_start_scope";
6554 case DW_AT_stride_size
: return "DW_AT_stride_size";
6555 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
6556 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
6557 case DW_AT_accessibility
: return "DW_AT_accessibility";
6558 case DW_AT_address_class
: return "DW_AT_address_class";
6559 case DW_AT_artificial
: return "DW_AT_artificial";
6560 case DW_AT_base_types
: return "DW_AT_base_types";
6561 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
6562 case DW_AT_count
: return "DW_AT_count";
6563 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
6564 case DW_AT_decl_column
: return "DW_AT_decl_column";
6565 case DW_AT_decl_file
: return "DW_AT_decl_file";
6566 case DW_AT_decl_line
: return "DW_AT_decl_line";
6567 case DW_AT_declaration
: return "DW_AT_declaration";
6568 case DW_AT_discr_list
: return "DW_AT_discr_list";
6569 case DW_AT_encoding
: return "DW_AT_encoding";
6570 case DW_AT_external
: return "DW_AT_external";
6571 case DW_AT_frame_base
: return "DW_AT_frame_base";
6572 case DW_AT_friend
: return "DW_AT_friend";
6573 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
6574 case DW_AT_macro_info
: return "DW_AT_macro_info";
6575 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
6576 case DW_AT_priority
: return "DW_AT_priority";
6577 case DW_AT_segment
: return "DW_AT_segment";
6578 case DW_AT_specification
: return "DW_AT_specification";
6579 case DW_AT_static_link
: return "DW_AT_static_link";
6580 case DW_AT_type
: return "DW_AT_type";
6581 case DW_AT_use_location
: return "DW_AT_use_location";
6582 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
6583 case DW_AT_virtuality
: return "DW_AT_virtuality";
6584 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
6585 /* DWARF 2.1 values. */
6586 case DW_AT_allocated
: return "DW_AT_allocated";
6587 case DW_AT_associated
: return "DW_AT_associated";
6588 case DW_AT_data_location
: return "DW_AT_data_location";
6589 case DW_AT_stride
: return "DW_AT_stride";
6590 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
6591 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
6592 case DW_AT_extension
: return "DW_AT_extension";
6593 case DW_AT_ranges
: return "DW_AT_ranges";
6594 case DW_AT_trampoline
: return "DW_AT_trampoline";
6595 case DW_AT_call_column
: return "DW_AT_call_column";
6596 case DW_AT_call_file
: return "DW_AT_call_file";
6597 case DW_AT_call_line
: return "DW_AT_call_line";
6598 /* SGI/MIPS extensions. */
6599 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
6600 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
6601 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
6602 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
6603 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
6604 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
6605 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
6606 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
6607 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
6608 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
6609 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
6610 /* GNU extensions. */
6611 case DW_AT_sf_names
: return "DW_AT_sf_names";
6612 case DW_AT_src_info
: return "DW_AT_src_info";
6613 case DW_AT_mac_info
: return "DW_AT_mac_info";
6614 case DW_AT_src_coords
: return "DW_AT_src_coords";
6615 case DW_AT_body_begin
: return "DW_AT_body_begin";
6616 case DW_AT_body_end
: return "DW_AT_body_end";
6617 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
6620 static char buffer
[100];
6622 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
6629 get_FORM_name (form
)
6634 case DW_FORM_addr
: return "DW_FORM_addr";
6635 case DW_FORM_block2
: return "DW_FORM_block2";
6636 case DW_FORM_block4
: return "DW_FORM_block4";
6637 case DW_FORM_data2
: return "DW_FORM_data2";
6638 case DW_FORM_data4
: return "DW_FORM_data4";
6639 case DW_FORM_data8
: return "DW_FORM_data8";
6640 case DW_FORM_string
: return "DW_FORM_string";
6641 case DW_FORM_block
: return "DW_FORM_block";
6642 case DW_FORM_block1
: return "DW_FORM_block1";
6643 case DW_FORM_data1
: return "DW_FORM_data1";
6644 case DW_FORM_flag
: return "DW_FORM_flag";
6645 case DW_FORM_sdata
: return "DW_FORM_sdata";
6646 case DW_FORM_strp
: return "DW_FORM_strp";
6647 case DW_FORM_udata
: return "DW_FORM_udata";
6648 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
6649 case DW_FORM_ref1
: return "DW_FORM_ref1";
6650 case DW_FORM_ref2
: return "DW_FORM_ref2";
6651 case DW_FORM_ref4
: return "DW_FORM_ref4";
6652 case DW_FORM_ref8
: return "DW_FORM_ref8";
6653 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
6654 case DW_FORM_indirect
: return "DW_FORM_indirect";
6657 static char buffer
[100];
6659 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
6665 /* FIXME: There are better and more effiecint ways to handle
6666 these structures. For now though, I just want something that
6667 is simple to implement. */
6668 typedef struct abbrev_attr
6670 unsigned long attribute
;
6672 struct abbrev_attr
* next
;
6676 typedef struct abbrev_entry
6678 unsigned long entry
;
6681 struct abbrev_attr
* first_attr
;
6682 struct abbrev_attr
* last_attr
;
6683 struct abbrev_entry
* next
;
6687 static abbrev_entry
* first_abbrev
= NULL
;
6688 static abbrev_entry
* last_abbrev
= NULL
;
6691 free_abbrevs
PARAMS ((void))
6693 abbrev_entry
* abbrev
;
6695 for (abbrev
= first_abbrev
; abbrev
;)
6697 abbrev_entry
* next
= abbrev
->next
;
6700 for (attr
= abbrev
->first_attr
; attr
;)
6702 abbrev_attr
* next
= attr
->next
;
6712 last_abbrev
= first_abbrev
= NULL
;
6716 add_abbrev (number
, tag
, children
)
6717 unsigned long number
;
6721 abbrev_entry
* entry
;
6723 entry
= (abbrev_entry
*) malloc (sizeof (* entry
));
6729 entry
->entry
= number
;
6731 entry
->children
= children
;
6732 entry
->first_attr
= NULL
;
6733 entry
->last_attr
= NULL
;
6736 if (first_abbrev
== NULL
)
6737 first_abbrev
= entry
;
6739 last_abbrev
->next
= entry
;
6741 last_abbrev
= entry
;
6745 add_abbrev_attr (attribute
, form
)
6746 unsigned long attribute
;
6751 attr
= (abbrev_attr
*) malloc (sizeof (* attr
));
6757 attr
->attribute
= attribute
;
6761 if (last_abbrev
->first_attr
== NULL
)
6762 last_abbrev
->first_attr
= attr
;
6764 last_abbrev
->last_attr
->next
= attr
;
6766 last_abbrev
->last_attr
= attr
;
6769 /* Processes the (partial) contents of a .debug_abbrev section.
6770 Returns NULL if the end of the section was encountered.
6771 Returns the address after the last byte read if the end of
6772 an abbreviation set was found. */
6774 static unsigned char *
6775 process_abbrev_section (start
, end
)
6776 unsigned char * start
;
6777 unsigned char * end
;
6779 if (first_abbrev
!= NULL
)
6785 unsigned long entry
;
6787 unsigned long attribute
;
6790 entry
= read_leb128 (start
, & bytes_read
, 0);
6791 start
+= bytes_read
;
6793 /* A single zero is supposed to end the section according
6794 to the standard. If there's more, then signal that to
6797 return start
== end
? NULL
: start
;
6799 tag
= read_leb128 (start
, & bytes_read
, 0);
6800 start
+= bytes_read
;
6802 children
= * start
++;
6804 add_abbrev (entry
, tag
, children
);
6810 attribute
= read_leb128 (start
, & bytes_read
, 0);
6811 start
+= bytes_read
;
6813 form
= read_leb128 (start
, & bytes_read
, 0);
6814 start
+= bytes_read
;
6817 add_abbrev_attr (attribute
, form
);
6819 while (attribute
!= 0);
6827 display_debug_macinfo (section
, start
, file
)
6828 Elf32_Internal_Shdr
* section
;
6829 unsigned char * start
;
6830 FILE * file ATTRIBUTE_UNUSED
;
6832 unsigned char * end
= start
+ section
->sh_size
;
6833 unsigned char * curr
= start
;
6834 unsigned int bytes_read
;
6835 enum dwarf_macinfo_record_type op
;
6837 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6841 unsigned int lineno
;
6842 const char * string
;
6849 case DW_MACINFO_start_file
:
6851 unsigned int filenum
;
6853 lineno
= read_leb128 (curr
, & bytes_read
, 0);
6855 filenum
= read_leb128 (curr
, & bytes_read
, 0);
6858 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno
, filenum
);
6862 case DW_MACINFO_end_file
:
6863 printf (_(" DW_MACINFO_end_file\n"));
6866 case DW_MACINFO_define
:
6867 lineno
= read_leb128 (curr
, & bytes_read
, 0);
6870 curr
+= strlen (string
) + 1;
6871 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno
, string
);
6874 case DW_MACINFO_undef
:
6875 lineno
= read_leb128 (curr
, & bytes_read
, 0);
6878 curr
+= strlen (string
) + 1;
6879 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno
, string
);
6882 case DW_MACINFO_vendor_ext
:
6884 unsigned int constant
;
6886 constant
= read_leb128 (curr
, & bytes_read
, 0);
6889 curr
+= strlen (string
) + 1;
6890 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant
, string
);
6901 display_debug_abbrev (section
, start
, file
)
6902 Elf32_Internal_Shdr
* section
;
6903 unsigned char * start
;
6904 FILE * file ATTRIBUTE_UNUSED
;
6906 abbrev_entry
* entry
;
6907 unsigned char * end
= start
+ section
->sh_size
;
6909 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6913 start
= process_abbrev_section (start
, end
);
6915 if (first_abbrev
== NULL
)
6918 printf (_(" Number TAG\n"));
6920 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
6924 printf (_(" %ld %s [%s]\n"),
6926 get_TAG_name (entry
->tag
),
6927 entry
->children
? _("has children") : _("no children"));
6929 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6931 printf (_(" %-18s %s\n"),
6932 get_AT_name (attr
->attribute
),
6933 get_FORM_name (attr
->form
));
6947 static unsigned char *
6948 display_block (data
, length
)
6949 unsigned char * data
;
6950 unsigned long length
;
6952 printf (_(" %lu byte block: "), length
);
6955 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
6961 decode_location_expression (data
, pointer_size
, length
)
6962 unsigned char * data
;
6963 unsigned int pointer_size
;
6964 unsigned long length
;
6968 unsigned long uvalue
;
6969 unsigned char * end
= data
+ length
;
6978 printf ("DW_OP_addr: %lx",
6979 (unsigned long) byte_get (data
, pointer_size
));
6980 data
+= pointer_size
;
6983 printf ("DW_OP_deref");
6986 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
6989 printf ("DW_OP_const1s: %ld", (long) byte_get (data
++, 1));
6992 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
6996 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
7000 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
7004 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
7008 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
7009 (unsigned long) byte_get (data
+ 4, 4));
7013 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
7014 (long) byte_get (data
+ 4, 4));
7018 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
7022 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
7026 printf ("DW_OP_dup");
7029 printf ("DW_OP_drop");
7032 printf ("DW_OP_over");
7035 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
7038 printf ("DW_OP_swap");
7041 printf ("DW_OP_rot");
7044 printf ("DW_OP_xderef");
7047 printf ("DW_OP_abs");
7050 printf ("DW_OP_and");
7053 printf ("DW_OP_div");
7056 printf ("DW_OP_minus");
7059 printf ("DW_OP_mod");
7062 printf ("DW_OP_mul");
7065 printf ("DW_OP_neg");
7068 printf ("DW_OP_not");
7071 printf ("DW_OP_or");
7074 printf ("DW_OP_plus");
7076 case DW_OP_plus_uconst
:
7077 printf ("DW_OP_plus_uconst: %lu",
7078 read_leb128 (data
, &bytes_read
, 0));
7082 printf ("DW_OP_shl");
7085 printf ("DW_OP_shr");
7088 printf ("DW_OP_shra");
7091 printf ("DW_OP_xor");
7094 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
7098 printf ("DW_OP_eq");
7101 printf ("DW_OP_ge");
7104 printf ("DW_OP_gt");
7107 printf ("DW_OP_le");
7110 printf ("DW_OP_lt");
7113 printf ("DW_OP_ne");
7116 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
7152 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
7187 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
7222 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
7223 read_leb128 (data
, &bytes_read
, 1));
7228 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
7232 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
7236 uvalue
= read_leb128 (data
, &bytes_read
, 0);
7238 printf ("DW_OP_bregx: %lu %ld", uvalue
,
7239 read_leb128 (data
, &bytes_read
, 1));
7243 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
7246 case DW_OP_deref_size
:
7247 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
7249 case DW_OP_xderef_size
:
7250 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
7253 printf ("DW_OP_nop");
7256 /* DWARF 2.1 extensions. */
7257 case DW_OP_push_object_address
:
7258 printf ("DW_OP_push_object_address");
7261 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2));
7265 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4));
7269 printf ("DW_OP_calli");
7273 if (op
>= DW_OP_lo_user
7274 && op
<= DW_OP_hi_user
)
7275 printf (_("(User defined location op)"));
7277 printf (_("(Unknown location op)"));
7278 /* No way to tell where the next op is, so just bail. */
7282 /* Separate the ops. */
7287 static const char * debug_loc_contents
;
7288 static bfd_vma debug_loc_size
;
7291 load_debug_loc (file
)
7294 Elf32_Internal_Shdr
* sec
;
7297 /* If it is already loaded, do nothing. */
7298 if (debug_loc_contents
!= NULL
)
7301 /* Locate the .debug_loc section. */
7302 for (i
= 0, sec
= section_headers
;
7303 i
< elf_header
.e_shnum
;
7305 if (strcmp (SECTION_NAME (sec
), ".debug_loc") == 0)
7308 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7311 debug_loc_size
= sec
->sh_size
;
7313 debug_loc_contents
= ((char *)
7314 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7315 _("debug_loc section data")));
7321 if (debug_loc_contents
== NULL
)
7324 free ((char *) debug_loc_contents
);
7325 debug_loc_contents
= NULL
;
7331 display_debug_loc (section
, start
, file
)
7332 Elf32_Internal_Shdr
* section
;
7333 unsigned char * start
;
7334 FILE * file ATTRIBUTE_UNUSED
;
7336 unsigned char *section_end
;
7337 unsigned long bytes
;
7338 unsigned char *section_begin
= start
;
7341 addr
= section
->sh_addr
;
7342 bytes
= section
->sh_size
;
7343 section_end
= start
+ bytes
;
7346 printf (_("\nThe .debug_loc section is empty.\n"));
7349 printf (_("Contents of the .debug_loc section:\n\n"));
7350 printf (_("\n Offset Begin End Expression\n"));
7351 while (start
< section_end
)
7353 unsigned long begin
;
7355 unsigned short length
;
7356 unsigned long offset
;
7358 offset
= start
- section_begin
;
7362 /* Normally, the lists in the debug_loc section are related to a
7363 given compilation unit, and thus, we would use the
7364 pointer size of that compilation unit. However, since we are
7365 displaying it seperately here, we either have to store
7366 pointer sizes of all compilation units, or assume they don't
7367 change. We assume, like the debug_line display, that
7368 it doesn't change. */
7369 begin
= byte_get (start
, debug_line_pointer_size
);
7370 start
+= debug_line_pointer_size
;
7371 end
= byte_get (start
, debug_line_pointer_size
);
7372 start
+= debug_line_pointer_size
;
7374 if (begin
== 0 && end
== 0)
7380 length
= byte_get (start
, 2);
7383 printf (" %8.8lx %8.8lx %8.8lx (", offset
, begin
, end
);
7384 decode_location_expression (start
, debug_line_pointer_size
, length
);
7394 static const char * debug_str_contents
;
7395 static bfd_vma debug_str_size
;
7398 load_debug_str (file
)
7401 Elf32_Internal_Shdr
* sec
;
7404 /* If it is already loaded, do nothing. */
7405 if (debug_str_contents
!= NULL
)
7408 /* Locate the .debug_str section. */
7409 for (i
= 0, sec
= section_headers
;
7410 i
< elf_header
.e_shnum
;
7412 if (strcmp (SECTION_NAME (sec
), ".debug_str") == 0)
7415 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7418 debug_str_size
= sec
->sh_size
;
7420 debug_str_contents
= ((char *)
7421 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7422 _("debug_str section data")));
7428 if (debug_str_contents
== NULL
)
7431 free ((char *) debug_str_contents
);
7432 debug_str_contents
= NULL
;
7437 fetch_indirect_string (offset
)
7438 unsigned long offset
;
7440 if (debug_str_contents
== NULL
)
7441 return _("<no .debug_str section>");
7443 if (offset
> debug_str_size
)
7444 return _("<offset is too big>");
7446 return debug_str_contents
+ offset
;
7451 display_debug_str (section
, start
, file
)
7452 Elf32_Internal_Shdr
* section
;
7453 unsigned char * start
;
7454 FILE * file ATTRIBUTE_UNUSED
;
7456 unsigned long bytes
;
7459 addr
= section
->sh_addr
;
7460 bytes
= section
->sh_size
;
7464 printf (_("\nThe .debug_str section is empty.\n"));
7468 printf (_("Contents of the .debug_str section:\n\n"));
7476 lbytes
= (bytes
> 16 ? 16 : bytes
);
7478 printf (" 0x%8.8lx ", (unsigned long) addr
);
7480 for (j
= 0; j
< 16; j
++)
7483 printf ("%2.2x", start
[j
]);
7491 for (j
= 0; j
< lbytes
; j
++)
7494 if (k
>= ' ' && k
< 0x80)
7511 static unsigned char *
7512 read_and_display_attr_value (attribute
, form
, data
, cu_offset
, pointer_size
)
7513 unsigned long attribute
;
7515 unsigned char * data
;
7516 unsigned long cu_offset
;
7517 unsigned long pointer_size
;
7519 unsigned long uvalue
= 0;
7520 unsigned char * block_start
= NULL
;
7528 case DW_FORM_ref_addr
:
7530 uvalue
= byte_get (data
, pointer_size
);
7531 data
+= pointer_size
;
7535 uvalue
= byte_get (data
, /* offset_size */ 4);
7536 data
+= /* offset_size */ 4;
7542 uvalue
= byte_get (data
++, 1);
7547 uvalue
= byte_get (data
, 2);
7553 uvalue
= byte_get (data
, 4);
7558 uvalue
= read_leb128 (data
, & bytes_read
, 1);
7562 case DW_FORM_ref_udata
:
7564 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7568 case DW_FORM_indirect
:
7569 form
= read_leb128 (data
, & bytes_read
, 0);
7571 printf (" %s", get_FORM_name (form
));
7572 return read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
7578 case DW_FORM_ref_addr
:
7579 printf (" <#%lx>", uvalue
);
7585 case DW_FORM_ref_udata
:
7586 printf (" <%lx>", uvalue
+ cu_offset
);
7590 printf (" %#lx", uvalue
);
7598 printf (" %ld", uvalue
);
7603 uvalue
= byte_get (data
, 4);
7604 printf (" %lx", uvalue
);
7605 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
7609 case DW_FORM_string
:
7610 printf (" %s", data
);
7611 data
+= strlen ((char *) data
) + 1;
7615 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7616 block_start
= data
+ bytes_read
;
7617 data
= display_block (block_start
, uvalue
);
7620 case DW_FORM_block1
:
7621 uvalue
= byte_get (data
, 1);
7622 block_start
= data
+ 1;
7623 data
= display_block (block_start
, uvalue
);
7626 case DW_FORM_block2
:
7627 uvalue
= byte_get (data
, 2);
7628 block_start
= data
+ 2;
7629 data
= display_block (block_start
, uvalue
);
7632 case DW_FORM_block4
:
7633 uvalue
= byte_get (data
, 4);
7634 block_start
= data
+ 4;
7635 data
= display_block (block_start
, uvalue
);
7639 printf (_(" (indirect string, offset: 0x%lx): "), uvalue
);
7640 printf (fetch_indirect_string (uvalue
));
7643 case DW_FORM_indirect
:
7644 /* Handled above. */
7648 warn (_("Unrecognized form: %d\n"), form
);
7652 /* For some attributes we can display futher information. */
7661 case DW_INL_not_inlined
: printf (_("(not inlined)")); break;
7662 case DW_INL_inlined
: printf (_("(inlined)")); break;
7663 case DW_INL_declared_not_inlined
: printf (_("(declared as inline but ignored)")); break;
7664 case DW_INL_declared_inlined
: printf (_("(declared as inline and inlined)")); break;
7665 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue
); break;
7669 case DW_AT_language
:
7672 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
7673 case DW_LANG_C89
: printf ("(ANSI C)"); break;
7674 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
7675 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
7676 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
7677 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
7678 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
7679 case DW_LANG_Ada83
: printf ("(Ada)"); break;
7680 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
7681 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
7682 /* DWARF 2.1 values. */
7683 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
7684 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
7685 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
7686 /* MIPS extension. */
7687 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
7688 default: printf ("(Unknown: %lx)", uvalue
); break;
7692 case DW_AT_encoding
:
7695 case DW_ATE_void
: printf ("(void)"); break;
7696 case DW_ATE_address
: printf ("(machine address)"); break;
7697 case DW_ATE_boolean
: printf ("(boolean)"); break;
7698 case DW_ATE_complex_float
: printf ("(complex float)"); break;
7699 case DW_ATE_float
: printf ("(float)"); break;
7700 case DW_ATE_signed
: printf ("(signed)"); break;
7701 case DW_ATE_signed_char
: printf ("(signed char)"); break;
7702 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
7703 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
7704 /* DWARF 2.1 value. */
7705 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
7707 if (uvalue
>= DW_ATE_lo_user
7708 && uvalue
<= DW_ATE_hi_user
)
7709 printf ("(user defined type)");
7711 printf ("(unknown type)");
7716 case DW_AT_accessibility
:
7719 case DW_ACCESS_public
: printf ("(public)"); break;
7720 case DW_ACCESS_protected
: printf ("(protected)"); break;
7721 case DW_ACCESS_private
: printf ("(private)"); break;
7722 default: printf ("(unknown accessibility)"); break;
7726 case DW_AT_visibility
:
7729 case DW_VIS_local
: printf ("(local)"); break;
7730 case DW_VIS_exported
: printf ("(exported)"); break;
7731 case DW_VIS_qualified
: printf ("(qualified)"); break;
7732 default: printf ("(unknown visibility)"); break;
7736 case DW_AT_virtuality
:
7739 case DW_VIRTUALITY_none
: printf ("(none)"); break;
7740 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
7741 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
7742 default: printf ("(unknown virtuality)"); break;
7746 case DW_AT_identifier_case
:
7749 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
7750 case DW_ID_up_case
: printf ("(up_case)"); break;
7751 case DW_ID_down_case
: printf ("(down_case)"); break;
7752 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
7753 default: printf ("(unknown case)"); break;
7757 case DW_AT_calling_convention
:
7760 case DW_CC_normal
: printf ("(normal)"); break;
7761 case DW_CC_program
: printf ("(program)"); break;
7762 case DW_CC_nocall
: printf ("(nocall)"); break;
7764 if (uvalue
>= DW_CC_lo_user
7765 && uvalue
<= DW_CC_hi_user
)
7766 printf ("(user defined)");
7768 printf ("(unknown convention)");
7772 case DW_AT_ordering
:
7775 case -1: printf ("(undefined)"); break;
7776 case 0: printf ("(row major)"); break;
7777 case 1: printf ("(column major)"); break;
7781 case DW_AT_frame_base
:
7782 case DW_AT_location
:
7783 case DW_AT_data_member_location
:
7784 case DW_AT_vtable_elem_location
:
7785 case DW_AT_allocated
:
7786 case DW_AT_associated
:
7787 case DW_AT_data_location
:
7789 case DW_AT_upper_bound
:
7790 case DW_AT_lower_bound
:
7794 decode_location_expression (block_start
, pointer_size
, uvalue
);
7797 else if (form
== DW_FORM_data4
)
7800 printf ("location list");
7812 static unsigned char *
7813 read_and_display_attr (attribute
, form
, data
, cu_offset
, pointer_size
)
7814 unsigned long attribute
;
7816 unsigned char * data
;
7817 unsigned long cu_offset
;
7818 unsigned long pointer_size
;
7820 printf (" %-18s:", get_AT_name (attribute
));
7821 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
7828 display_debug_info (section
, start
, file
)
7829 Elf32_Internal_Shdr
* section
;
7830 unsigned char * start
;
7833 unsigned char * end
= start
+ section
->sh_size
;
7834 unsigned char * section_begin
= start
;
7836 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
7838 load_debug_str (file
);
7839 load_debug_loc (file
);
7843 DWARF2_External_CompUnit
* external
;
7844 DWARF2_Internal_CompUnit compunit
;
7845 Elf32_Internal_Shdr
* relsec
;
7846 unsigned char * tags
;
7849 unsigned long cu_offset
;
7851 external
= (DWARF2_External_CompUnit
*) start
;
7853 compunit
.cu_length
= BYTE_GET (external
->cu_length
);
7854 compunit
.cu_version
= BYTE_GET (external
->cu_version
);
7855 compunit
.cu_abbrev_offset
= BYTE_GET (external
->cu_abbrev_offset
);
7856 compunit
.cu_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
7858 if (compunit
.cu_length
== 0xffffffff)
7860 warn (_("64-bit DWARF debug info is not supported yet.\n"));
7864 /* Check for RELA relocations in the abbrev_offset address, and
7866 for (relsec
= section_headers
;
7867 relsec
< section_headers
+ elf_header
.e_shnum
;
7870 unsigned long nrelas
;
7871 Elf_Internal_Rela
*rela
, *rp
;
7872 Elf32_Internal_Shdr
*symsec
;
7873 Elf_Internal_Sym
*symtab
;
7874 Elf_Internal_Sym
*sym
;
7876 if (relsec
->sh_type
!= SHT_RELA
7877 || SECTION_HEADER (relsec
->sh_info
) != section
)
7880 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7884 symsec
= SECTION_HEADER (relsec
->sh_link
);
7885 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7887 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7890 != (bfd_vma
) ((unsigned char *) &external
->cu_abbrev_offset
7896 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7898 if (ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
7900 warn (_("Skipping unexpected symbol type %u\n"),
7901 ELF32_ST_TYPE (sym
->st_info
));
7907 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7909 if (ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
7911 warn (_("Skipping unexpected symbol type %u\n"),
7912 ELF64_ST_TYPE (sym
->st_info
));
7917 compunit
.cu_abbrev_offset
+= rp
->r_addend
;
7925 tags
= start
+ sizeof (* external
);
7926 cu_offset
= start
- section_begin
;
7927 start
+= compunit
.cu_length
+ sizeof (external
->cu_length
);
7929 printf (_(" Compilation Unit @ %lx:\n"), cu_offset
);
7930 printf (_(" Length: %ld\n"), compunit
.cu_length
);
7931 printf (_(" Version: %d\n"), compunit
.cu_version
);
7932 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
7933 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
7935 if (compunit
.cu_version
!= 2)
7937 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
7943 /* Read in the abbrevs used by this compilation unit. */
7946 Elf32_Internal_Shdr
* sec
;
7947 unsigned char * begin
;
7949 /* Locate the .debug_abbrev section and process it. */
7950 for (i
= 0, sec
= section_headers
;
7951 i
< elf_header
.e_shnum
;
7953 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
7956 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7958 warn (_("Unable to locate .debug_abbrev section!\n"));
7962 begin
= ((unsigned char *)
7963 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7964 _("debug_abbrev section data")));
7968 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
7969 begin
+ sec
->sh_size
);
7975 while (tags
< start
)
7978 unsigned long abbrev_number
;
7979 abbrev_entry
* entry
;
7982 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
7985 /* A null DIE marks the end of a list of children. */
7986 if (abbrev_number
== 0)
7992 /* Scan through the abbreviation list until we reach the
7994 for (entry
= first_abbrev
;
7995 entry
&& entry
->entry
!= abbrev_number
;
7996 entry
= entry
->next
)
8001 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8006 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8008 (unsigned long) (tags
- section_begin
- bytes_read
),
8010 get_TAG_name (entry
->tag
));
8012 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
8013 tags
= read_and_display_attr (attr
->attribute
,
8016 compunit
.cu_pointer_size
);
8018 if (entry
->children
)
8032 display_debug_aranges (section
, start
, file
)
8033 Elf32_Internal_Shdr
* section
;
8034 unsigned char * start
;
8035 FILE * file ATTRIBUTE_UNUSED
;
8037 unsigned char * end
= start
+ section
->sh_size
;
8039 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8043 DWARF2_External_ARange
* external
;
8044 DWARF2_Internal_ARange arange
;
8045 unsigned char * ranges
;
8046 unsigned long length
;
8047 unsigned long address
;
8050 external
= (DWARF2_External_ARange
*) start
;
8052 arange
.ar_length
= BYTE_GET (external
->ar_length
);
8053 arange
.ar_version
= BYTE_GET (external
->ar_version
);
8054 arange
.ar_info_offset
= BYTE_GET (external
->ar_info_offset
);
8055 arange
.ar_pointer_size
= BYTE_GET (external
->ar_pointer_size
);
8056 arange
.ar_segment_size
= BYTE_GET (external
->ar_segment_size
);
8058 if (arange
.ar_length
== 0xffffffff)
8060 warn (_("64-bit DWARF aranges are not supported yet.\n"));
8064 if (arange
.ar_version
!= 2)
8066 warn (_("Only DWARF 2 aranges are currently supported.\n"));
8070 printf (_(" Length: %ld\n"), arange
.ar_length
);
8071 printf (_(" Version: %d\n"), arange
.ar_version
);
8072 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
8073 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
8074 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
8076 printf (_("\n Address Length\n"));
8078 ranges
= start
+ sizeof (* external
);
8080 /* Must pad to an alignment boundary that is twice the pointer size. */
8081 excess
= sizeof (* external
) % (2 * arange
.ar_pointer_size
);
8083 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
8087 address
= byte_get (ranges
, arange
.ar_pointer_size
);
8089 ranges
+= arange
.ar_pointer_size
;
8091 length
= byte_get (ranges
, arange
.ar_pointer_size
);
8093 ranges
+= arange
.ar_pointer_size
;
8095 /* A pair of zeros marks the end of the list. */
8096 if (address
== 0 && length
== 0)
8099 printf (" %8.8lx %lu\n", address
, length
);
8102 start
+= arange
.ar_length
+ sizeof (external
->ar_length
);
8110 typedef struct Frame_Chunk
8112 struct Frame_Chunk
* next
;
8113 unsigned char * chunk_start
;
8115 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8116 short int * col_type
;
8118 char * augmentation
;
8119 unsigned int code_factor
;
8121 unsigned long pc_begin
;
8122 unsigned long pc_range
;
8126 unsigned char fde_encoding
;
8130 /* A marker for a col_type that means this column was never referenced
8131 in the frame info. */
8132 #define DW_CFA_unreferenced (-1)
8134 static void frame_need_space
PARAMS ((Frame_Chunk
*, int));
8135 static void frame_display_row
PARAMS ((Frame_Chunk
*, int *, int *));
8136 static int size_of_encoded_value
PARAMS ((int));
8139 frame_need_space (fc
, reg
)
8143 int prev
= fc
->ncols
;
8145 if (reg
< fc
->ncols
)
8148 fc
->ncols
= reg
+ 1;
8149 fc
->col_type
= (short int *) xrealloc (fc
->col_type
,
8150 fc
->ncols
* sizeof (short int));
8151 fc
->col_offset
= (int *) xrealloc (fc
->col_offset
,
8152 fc
->ncols
* sizeof (int));
8154 while (prev
< fc
->ncols
)
8156 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8157 fc
->col_offset
[prev
] = 0;
8163 frame_display_row (fc
, need_col_headers
, max_regs
)
8165 int * need_col_headers
;
8171 if (* max_regs
< fc
->ncols
)
8172 * max_regs
= fc
->ncols
;
8174 if (* need_col_headers
)
8176 * need_col_headers
= 0;
8178 printf (" LOC CFA ");
8180 for (r
= 0; r
< * max_regs
; r
++)
8181 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8186 printf ("r%-4d", r
);
8192 printf ("%08lx ", fc
->pc_begin
);
8193 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
8194 printf ("%-8s ", tmp
);
8196 for (r
= 0; r
< fc
->ncols
; r
++)
8198 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8200 switch (fc
->col_type
[r
])
8202 case DW_CFA_undefined
:
8205 case DW_CFA_same_value
:
8209 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8211 case DW_CFA_register
:
8212 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
8215 strcpy (tmp
, "n/a");
8218 printf ("%-5s", tmp
);
8225 size_of_encoded_value (encoding
)
8228 switch (encoding
& 0x7)
8231 case 0: return is_32bit_elf
? 4 : 8;
8238 #define GET(N) byte_get (start, N); start += N
8239 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8240 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8243 display_debug_frames (section
, start
, file
)
8244 Elf32_Internal_Shdr
* section
;
8245 unsigned char * start
;
8246 FILE * file ATTRIBUTE_UNUSED
;
8248 unsigned char * end
= start
+ section
->sh_size
;
8249 unsigned char * section_start
= start
;
8250 Frame_Chunk
* chunks
= 0;
8251 Frame_Chunk
* remembered_state
= 0;
8253 int is_eh
= (strcmp (SECTION_NAME (section
), ".eh_frame") == 0);
8256 int addr_size
= is_32bit_elf
? 4 : 8;
8258 printf (_("The section %s contains:\n"), SECTION_NAME (section
));
8262 unsigned char * saved_start
;
8263 unsigned char * block_end
;
8264 unsigned long length
;
8265 unsigned long cie_id
;
8268 int need_col_headers
= 1;
8269 unsigned char * augmentation_data
= NULL
;
8270 unsigned long augmentation_data_len
= 0;
8271 int encoded_ptr_size
= addr_size
;
8273 saved_start
= start
;
8274 length
= byte_get (start
, 4); start
+= 4;
8279 if (length
== 0xffffffff)
8281 warn (_("64-bit DWARF format frames are not supported yet.\n"));
8285 block_end
= saved_start
+ length
+ 4;
8286 cie_id
= byte_get (start
, 4); start
+= 4;
8288 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
8292 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8293 memset (fc
, 0, sizeof (Frame_Chunk
));
8297 fc
->chunk_start
= saved_start
;
8299 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8300 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8301 frame_need_space (fc
, max_regs
-1);
8305 fc
->augmentation
= start
;
8306 start
= strchr (start
, '\0') + 1;
8308 if (fc
->augmentation
[0] == 'z')
8310 fc
->code_factor
= LEB ();
8311 fc
->data_factor
= SLEB ();
8312 fc
->ra
= byte_get (start
, 1); start
+= 1;
8313 augmentation_data_len
= LEB ();
8314 augmentation_data
= start
;
8315 start
+= augmentation_data_len
;
8317 else if (strcmp (fc
->augmentation
, "eh") == 0)
8320 fc
->code_factor
= LEB ();
8321 fc
->data_factor
= SLEB ();
8322 fc
->ra
= byte_get (start
, 1); start
+= 1;
8326 fc
->code_factor
= LEB ();
8327 fc
->data_factor
= SLEB ();
8328 fc
->ra
= byte_get (start
, 1); start
+= 1;
8332 if (do_debug_frames_interp
)
8333 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8334 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8335 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
8339 printf ("\n%08lx %08lx %08lx CIE\n",
8340 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
8341 printf (" Version: %d\n", version
);
8342 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8343 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8344 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8345 printf (" Return address column: %d\n", fc
->ra
);
8347 if (augmentation_data_len
)
8350 printf (" Augmentation data: ");
8351 for (i
= 0; i
< augmentation_data_len
; ++i
)
8352 printf (" %02x", augmentation_data
[i
]);
8358 if (augmentation_data_len
)
8360 unsigned char *p
, *q
;
8361 p
= fc
->augmentation
+ 1;
8362 q
= augmentation_data
;
8369 q
+= 1 + size_of_encoded_value (*q
);
8371 fc
->fde_encoding
= *q
++;
8377 if (fc
->fde_encoding
)
8378 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8381 frame_need_space (fc
, fc
->ra
);
8385 unsigned char * look_for
;
8386 static Frame_Chunk fde_fc
;
8389 memset (fc
, 0, sizeof (Frame_Chunk
));
8391 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
8393 for (cie
= chunks
; cie
; cie
= cie
->next
)
8394 if (cie
->chunk_start
== look_for
)
8399 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8400 cie_id
, saved_start
);
8403 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8404 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8405 frame_need_space (fc
, max_regs
- 1);
8407 fc
->augmentation
= "";
8408 fc
->fde_encoding
= 0;
8412 fc
->ncols
= cie
->ncols
;
8413 fc
->col_type
= (short int *) xmalloc (fc
->ncols
* sizeof (short int));
8414 fc
->col_offset
= (int *) xmalloc (fc
->ncols
* sizeof (int));
8415 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8416 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8417 fc
->augmentation
= cie
->augmentation
;
8418 fc
->code_factor
= cie
->code_factor
;
8419 fc
->data_factor
= cie
->data_factor
;
8420 fc
->cfa_reg
= cie
->cfa_reg
;
8421 fc
->cfa_offset
= cie
->cfa_offset
;
8423 frame_need_space (fc
, max_regs
-1);
8424 fc
->fde_encoding
= cie
->fde_encoding
;
8427 if (fc
->fde_encoding
)
8428 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8430 fc
->pc_begin
= byte_get (start
, encoded_ptr_size
);
8431 start
+= encoded_ptr_size
;
8432 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
8433 start
+= encoded_ptr_size
;
8435 if (cie
->augmentation
[0] == 'z')
8437 augmentation_data_len
= LEB ();
8438 augmentation_data
= start
;
8439 start
+= augmentation_data_len
;
8442 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8443 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8444 (unsigned long)(cie
->chunk_start
- section_start
),
8445 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
8446 if (! do_debug_frames_interp
&& augmentation_data_len
)
8449 printf (" Augmentation data: ");
8450 for (i
= 0; i
< augmentation_data_len
; ++i
)
8451 printf (" %02x", augmentation_data
[i
]);
8457 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8458 about to interpret instructions for the chunk. */
8460 if (do_debug_frames_interp
)
8462 /* Start by making a pass over the chunk, allocating storage
8463 and taking note of what registers are used. */
8464 unsigned char * tmp
= start
;
8466 while (start
< block_end
)
8476 /* Warning: if you add any more cases to this switch, be
8477 sure to add them to the corresponding switch below. */
8480 case DW_CFA_advance_loc
:
8484 frame_need_space (fc
, opa
);
8485 fc
->col_type
[opa
] = DW_CFA_undefined
;
8487 case DW_CFA_restore
:
8488 frame_need_space (fc
, opa
);
8489 fc
->col_type
[opa
] = DW_CFA_undefined
;
8491 case DW_CFA_set_loc
:
8492 start
+= encoded_ptr_size
;
8494 case DW_CFA_advance_loc1
:
8497 case DW_CFA_advance_loc2
:
8500 case DW_CFA_advance_loc4
:
8503 case DW_CFA_offset_extended
:
8504 reg
= LEB (); LEB ();
8505 frame_need_space (fc
, reg
);
8506 fc
->col_type
[reg
] = DW_CFA_undefined
;
8508 case DW_CFA_restore_extended
:
8510 frame_need_space (fc
, reg
);
8511 fc
->col_type
[reg
] = DW_CFA_undefined
;
8513 case DW_CFA_undefined
:
8515 frame_need_space (fc
, reg
);
8516 fc
->col_type
[reg
] = DW_CFA_undefined
;
8518 case DW_CFA_same_value
:
8520 frame_need_space (fc
, reg
);
8521 fc
->col_type
[reg
] = DW_CFA_undefined
;
8523 case DW_CFA_register
:
8524 reg
= LEB (); LEB ();
8525 frame_need_space (fc
, reg
);
8526 fc
->col_type
[reg
] = DW_CFA_undefined
;
8528 case DW_CFA_def_cfa
:
8531 case DW_CFA_def_cfa_register
:
8534 case DW_CFA_def_cfa_offset
:
8537 case DW_CFA_offset_extended_sf
:
8538 reg
= LEB (); SLEB ();
8539 frame_need_space (fc
, reg
);
8540 fc
->col_type
[reg
] = DW_CFA_undefined
;
8542 case DW_CFA_def_cfa_sf
:
8545 case DW_CFA_def_cfa_offset_sf
:
8548 case DW_CFA_GNU_args_size
:
8551 case DW_CFA_GNU_negative_offset_extended
:
8552 reg
= LEB (); LEB ();
8553 frame_need_space (fc
, reg
);
8554 fc
->col_type
[reg
] = DW_CFA_undefined
;
8563 /* Now we know what registers are used, make a second pass over
8564 the chunk, this time actually printing out the info. */
8566 while (start
< block_end
)
8569 unsigned long ul
, reg
, roffs
;
8578 /* Warning: if you add any more cases to this switch, be
8579 sure to add them to the corresponding switch above. */
8582 case DW_CFA_advance_loc
:
8583 if (do_debug_frames_interp
)
8584 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8586 printf (" DW_CFA_advance_loc: %d to %08lx\n",
8587 opa
* fc
->code_factor
,
8588 fc
->pc_begin
+ opa
* fc
->code_factor
);
8589 fc
->pc_begin
+= opa
* fc
->code_factor
;
8594 if (! do_debug_frames_interp
)
8595 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
8596 opa
, roffs
* fc
->data_factor
);
8597 fc
->col_type
[opa
] = DW_CFA_offset
;
8598 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8601 case DW_CFA_restore
:
8602 if (! do_debug_frames_interp
)
8603 printf (" DW_CFA_restore: r%d\n", opa
);
8604 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8605 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8608 case DW_CFA_set_loc
:
8609 vma
= byte_get (start
, encoded_ptr_size
);
8610 start
+= encoded_ptr_size
;
8611 if (do_debug_frames_interp
)
8612 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8614 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
8618 case DW_CFA_advance_loc1
:
8619 ofs
= byte_get (start
, 1); start
+= 1;
8620 if (do_debug_frames_interp
)
8621 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8623 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
8624 ofs
* fc
->code_factor
,
8625 fc
->pc_begin
+ ofs
* fc
->code_factor
);
8626 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8629 case DW_CFA_advance_loc2
:
8630 ofs
= byte_get (start
, 2); start
+= 2;
8631 if (do_debug_frames_interp
)
8632 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8634 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
8635 ofs
* fc
->code_factor
,
8636 fc
->pc_begin
+ ofs
* fc
->code_factor
);
8637 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8640 case DW_CFA_advance_loc4
:
8641 ofs
= byte_get (start
, 4); start
+= 4;
8642 if (do_debug_frames_interp
)
8643 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8645 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
8646 ofs
* fc
->code_factor
,
8647 fc
->pc_begin
+ ofs
* fc
->code_factor
);
8648 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8651 case DW_CFA_offset_extended
:
8654 if (! do_debug_frames_interp
)
8655 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
8656 reg
, roffs
* fc
->data_factor
);
8657 fc
->col_type
[reg
] = DW_CFA_offset
;
8658 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8661 case DW_CFA_restore_extended
:
8663 if (! do_debug_frames_interp
)
8664 printf (" DW_CFA_restore_extended: r%ld\n", reg
);
8665 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8666 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8669 case DW_CFA_undefined
:
8671 if (! do_debug_frames_interp
)
8672 printf (" DW_CFA_undefined: r%ld\n", reg
);
8673 fc
->col_type
[reg
] = DW_CFA_undefined
;
8674 fc
->col_offset
[reg
] = 0;
8677 case DW_CFA_same_value
:
8679 if (! do_debug_frames_interp
)
8680 printf (" DW_CFA_same_value: r%ld\n", reg
);
8681 fc
->col_type
[reg
] = DW_CFA_same_value
;
8682 fc
->col_offset
[reg
] = 0;
8685 case DW_CFA_register
:
8688 if (! do_debug_frames_interp
)
8689 printf (" DW_CFA_register: r%ld\n", reg
);
8690 fc
->col_type
[reg
] = DW_CFA_register
;
8691 fc
->col_offset
[reg
] = roffs
;
8694 case DW_CFA_remember_state
:
8695 if (! do_debug_frames_interp
)
8696 printf (" DW_CFA_remember_state\n");
8697 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8698 rs
->ncols
= fc
->ncols
;
8699 rs
->col_type
= (short int *) xmalloc (rs
->ncols
* sizeof (short int));
8700 rs
->col_offset
= (int *) xmalloc (rs
->ncols
* sizeof (int));
8701 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
8702 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
8703 rs
->next
= remembered_state
;
8704 remembered_state
= rs
;
8707 case DW_CFA_restore_state
:
8708 if (! do_debug_frames_interp
)
8709 printf (" DW_CFA_restore_state\n");
8710 rs
= remembered_state
;
8711 remembered_state
= rs
->next
;
8712 frame_need_space (fc
, rs
->ncols
-1);
8713 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
8714 memcpy (fc
->col_offset
, rs
->col_offset
, rs
->ncols
* sizeof (int));
8715 free (rs
->col_type
);
8716 free (rs
->col_offset
);
8720 case DW_CFA_def_cfa
:
8721 fc
->cfa_reg
= LEB ();
8722 fc
->cfa_offset
= LEB ();
8723 if (! do_debug_frames_interp
)
8724 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
8725 fc
->cfa_reg
, fc
->cfa_offset
);
8728 case DW_CFA_def_cfa_register
:
8729 fc
->cfa_reg
= LEB ();
8730 if (! do_debug_frames_interp
)
8731 printf (" DW_CFA_def_cfa_reg: r%d\n", fc
->cfa_reg
);
8734 case DW_CFA_def_cfa_offset
:
8735 fc
->cfa_offset
= LEB ();
8736 if (! do_debug_frames_interp
)
8737 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
8741 if (! do_debug_frames_interp
)
8742 printf (" DW_CFA_nop\n");
8745 case DW_CFA_offset_extended_sf
:
8748 frame_need_space (fc
, reg
);
8749 if (! do_debug_frames_interp
)
8750 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
8751 reg
, l
* fc
->data_factor
);
8752 fc
->col_type
[reg
] = DW_CFA_offset
;
8753 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8756 case DW_CFA_def_cfa_sf
:
8757 fc
->cfa_reg
= LEB ();
8758 fc
->cfa_offset
= SLEB ();
8759 if (! do_debug_frames_interp
)
8760 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
8761 fc
->cfa_reg
, fc
->cfa_offset
);
8764 case DW_CFA_def_cfa_offset_sf
:
8765 fc
->cfa_offset
= SLEB ();
8766 if (! do_debug_frames_interp
)
8767 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
8770 case DW_CFA_GNU_window_save
:
8771 if (! do_debug_frames_interp
)
8772 printf (" DW_CFA_GNU_window_save\n");
8775 case DW_CFA_GNU_args_size
:
8777 if (! do_debug_frames_interp
)
8778 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8781 case DW_CFA_GNU_negative_offset_extended
:
8784 frame_need_space (fc
, reg
);
8785 if (! do_debug_frames_interp
)
8786 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
8787 reg
, l
* fc
->data_factor
);
8788 fc
->col_type
[reg
] = DW_CFA_offset
;
8789 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8792 /* FIXME: How do we handle these? */
8793 case DW_CFA_def_cfa_expression
:
8794 fprintf (stderr
, "unsupported DW_CFA_def_cfa_expression\n");
8798 case DW_CFA_expression
:
8799 fprintf (stderr
, "unsupported DW_CFA_expression\n");
8804 fprintf (stderr
, "unsupported or unknown DW_CFA_%d\n", op
);
8809 if (do_debug_frames_interp
)
8810 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8825 display_debug_not_supported (section
, start
, file
)
8826 Elf32_Internal_Shdr
* section
;
8827 unsigned char * start ATTRIBUTE_UNUSED
;
8828 FILE * file ATTRIBUTE_UNUSED
;
8830 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8831 SECTION_NAME (section
));
8836 /* Pre-scan the .debug_info section to record the size of address.
8837 When dumping the .debug_line, we use that size information, assuming
8838 that all compilation units have the same address size. */
8840 prescan_debug_info (section
, start
, file
)
8841 Elf32_Internal_Shdr
* section ATTRIBUTE_UNUSED
;
8842 unsigned char * start
;
8843 FILE * file ATTRIBUTE_UNUSED
;
8845 DWARF2_External_CompUnit
* external
;
8847 external
= (DWARF2_External_CompUnit
*) start
;
8849 debug_line_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
8853 /* A structure containing the name of a debug section and a pointer
8854 to a function that can decode it. The third field is a prescan
8855 function to be run over the section before displaying any of the
8859 const char * const name
;
8860 int (* display
) PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
8861 int (* prescan
) PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
8865 { ".debug_abbrev", display_debug_abbrev
, NULL
},
8866 { ".debug_aranges", display_debug_aranges
, NULL
},
8867 { ".debug_frame", display_debug_frames
, NULL
},
8868 { ".debug_info", display_debug_info
, prescan_debug_info
},
8869 { ".debug_line", display_debug_lines
, NULL
},
8870 { ".debug_pubnames", display_debug_pubnames
, NULL
},
8871 { ".eh_frame", display_debug_frames
, NULL
},
8872 { ".debug_macinfo", display_debug_macinfo
, NULL
},
8873 { ".debug_str", display_debug_str
, NULL
},
8874 { ".debug_loc", display_debug_loc
, NULL
},
8875 { ".debug_pubtypes", display_debug_not_supported
, NULL
},
8876 { ".debug_ranges", display_debug_not_supported
, NULL
},
8877 { ".debug_static_func", display_debug_not_supported
, NULL
},
8878 { ".debug_static_vars", display_debug_not_supported
, NULL
},
8879 { ".debug_types", display_debug_not_supported
, NULL
},
8880 { ".debug_weaknames", display_debug_not_supported
, NULL
}
8884 display_debug_section (section
, file
)
8885 Elf32_Internal_Shdr
* section
;
8888 char * name
= SECTION_NAME (section
);
8889 bfd_size_type length
;
8890 unsigned char * start
;
8893 length
= section
->sh_size
;
8896 printf (_("\nSection '%s' has no debugging data.\n"), name
);
8900 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, length
,
8901 _("debug section data"));
8905 /* See if we know how to display the contents of this section. */
8906 if (strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
8907 name
= ".debug_info";
8909 for (i
= NUM_ELEM (debug_displays
); i
--;)
8910 if (strcmp (debug_displays
[i
].name
, name
) == 0)
8912 debug_displays
[i
].display (section
, start
, file
);
8917 printf (_("Unrecognized debug section: %s\n"), name
);
8921 /* If we loaded in the abbrev section at some point,
8922 we must release it here. */
8929 process_section_contents (file
)
8932 Elf32_Internal_Shdr
* section
;
8938 /* Pre-scan the debug sections to find some debug information not
8939 present in some of them. For the .debug_line, we must find out the
8940 size of address (specified in .debug_info and .debug_aranges). */
8941 for (i
= 0, section
= section_headers
;
8942 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8945 char * name
= SECTION_NAME (section
);
8948 if (section
->sh_size
== 0)
8951 /* See if there is some pre-scan operation for this section. */
8952 for (j
= NUM_ELEM (debug_displays
); j
--;)
8953 if (strcmp (debug_displays
[j
].name
, name
) == 0)
8955 if (debug_displays
[j
].prescan
!= NULL
)
8957 bfd_size_type length
;
8958 unsigned char * start
;
8960 length
= section
->sh_size
;
8961 start
= ((unsigned char *)
8962 get_data (NULL
, file
, section
->sh_offset
, length
,
8963 _("debug section data")));
8967 debug_displays
[j
].prescan (section
, start
, file
);
8975 for (i
= 0, section
= section_headers
;
8976 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8979 #ifdef SUPPORT_DISASSEMBLY
8980 if (dump_sects
[i
] & DISASS_DUMP
)
8981 disassemble_section (section
, file
);
8983 if (dump_sects
[i
] & HEX_DUMP
)
8984 dump_section (section
, file
);
8986 if (dump_sects
[i
] & DEBUG_DUMP
)
8987 display_debug_section (section
, file
);
8990 if (i
< num_dump_sects
)
8991 warn (_("Some sections were not dumped because they do not exist!\n"));
8997 process_mips_fpe_exception (mask
)
9003 if (mask
& OEX_FPU_INEX
)
9004 fputs ("INEX", stdout
), first
= 0;
9005 if (mask
& OEX_FPU_UFLO
)
9006 printf ("%sUFLO", first
? "" : "|"), first
= 0;
9007 if (mask
& OEX_FPU_OFLO
)
9008 printf ("%sOFLO", first
? "" : "|"), first
= 0;
9009 if (mask
& OEX_FPU_DIV0
)
9010 printf ("%sDIV0", first
? "" : "|"), first
= 0;
9011 if (mask
& OEX_FPU_INVAL
)
9012 printf ("%sINVAL", first
? "" : "|");
9015 fputs ("0", stdout
);
9019 process_mips_specific (file
)
9022 Elf_Internal_Dyn
* entry
;
9023 size_t liblist_offset
= 0;
9024 size_t liblistno
= 0;
9025 size_t conflictsno
= 0;
9026 size_t options_offset
= 0;
9027 size_t conflicts_offset
= 0;
9029 /* We have a lot of special sections. Thanks SGI! */
9030 if (dynamic_segment
== NULL
)
9031 /* No information available. */
9034 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
9035 switch (entry
->d_tag
)
9037 case DT_MIPS_LIBLIST
:
9038 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
9040 case DT_MIPS_LIBLISTNO
:
9041 liblistno
= entry
->d_un
.d_val
;
9043 case DT_MIPS_OPTIONS
:
9044 options_offset
= entry
->d_un
.d_val
- loadaddr
;
9046 case DT_MIPS_CONFLICT
:
9047 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
9049 case DT_MIPS_CONFLICTNO
:
9050 conflictsno
= entry
->d_un
.d_val
;
9056 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9058 Elf32_External_Lib
* elib
;
9061 elib
= ((Elf32_External_Lib
*)
9062 get_data (NULL
, file
, liblist_offset
,
9063 liblistno
* sizeof (Elf32_External_Lib
),
9067 printf ("\nSection '.liblist' contains %lu entries:\n",
9068 (unsigned long) liblistno
);
9069 fputs (" Library Time Stamp Checksum Version Flags\n",
9072 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9079 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9080 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9081 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9082 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9083 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9085 tmp
= gmtime (&time
);
9086 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9087 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9088 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9090 printf ("%3lu: ", (unsigned long) cnt
);
9091 print_symbol (20, dynamic_strings
+ liblist
.l_name
);
9092 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9095 if (liblist
.l_flags
== 0)
9106 { " EXACT_MATCH", LL_EXACT_MATCH
},
9107 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9108 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9109 { " EXPORTS", LL_EXPORTS
},
9110 { " DELAY_LOAD", LL_DELAY_LOAD
},
9111 { " DELTA", LL_DELTA
}
9113 int flags
= liblist
.l_flags
;
9117 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
9119 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9121 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9122 flags
^= l_flags_vals
[fcnt
].bit
;
9125 printf (" %#x", (unsigned int) flags
);
9135 if (options_offset
!= 0)
9137 Elf_External_Options
* eopt
;
9138 Elf_Internal_Shdr
* sect
= section_headers
;
9139 Elf_Internal_Options
* iopt
;
9140 Elf_Internal_Options
* option
;
9144 /* Find the section header so that we get the size. */
9145 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9148 eopt
= (Elf_External_Options
*) get_data (NULL
, file
, options_offset
,
9149 sect
->sh_size
, _("options"));
9152 iopt
= ((Elf_Internal_Options
*)
9153 malloc ((sect
->sh_size
/ sizeof (eopt
)) * sizeof (* iopt
)));
9156 error (_("Out of memory"));
9163 while (offset
< sect
->sh_size
)
9165 Elf_External_Options
* eoption
;
9167 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9169 option
->kind
= BYTE_GET (eoption
->kind
);
9170 option
->size
= BYTE_GET (eoption
->size
);
9171 option
->section
= BYTE_GET (eoption
->section
);
9172 option
->info
= BYTE_GET (eoption
->info
);
9174 offset
+= option
->size
;
9180 printf (_("\nSection '%s' contains %d entries:\n"),
9181 SECTION_NAME (sect
), cnt
);
9189 switch (option
->kind
)
9192 /* This shouldn't happen. */
9193 printf (" NULL %d %lx", option
->section
, option
->info
);
9196 printf (" REGINFO ");
9197 if (elf_header
.e_machine
== EM_MIPS
)
9200 Elf32_External_RegInfo
* ereg
;
9201 Elf32_RegInfo reginfo
;
9203 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9204 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9205 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9206 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9207 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9208 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9209 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9211 printf ("GPR %08lx GP 0x%lx\n",
9213 (unsigned long) reginfo
.ri_gp_value
);
9214 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9215 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9216 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9221 Elf64_External_RegInfo
* ereg
;
9222 Elf64_Internal_RegInfo reginfo
;
9224 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9225 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9226 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9227 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9228 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9229 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9230 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
9232 printf ("GPR %08lx GP 0x",
9233 reginfo
.ri_gprmask
);
9234 printf_vma (reginfo
.ri_gp_value
);
9237 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9238 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9239 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9243 case ODK_EXCEPTIONS
:
9244 fputs (" EXCEPTIONS fpe_min(", stdout
);
9245 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9246 fputs (") fpe_max(", stdout
);
9247 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9248 fputs (")", stdout
);
9250 if (option
->info
& OEX_PAGE0
)
9251 fputs (" PAGE0", stdout
);
9252 if (option
->info
& OEX_SMM
)
9253 fputs (" SMM", stdout
);
9254 if (option
->info
& OEX_FPDBUG
)
9255 fputs (" FPDBUG", stdout
);
9256 if (option
->info
& OEX_DISMISS
)
9257 fputs (" DISMISS", stdout
);
9260 fputs (" PAD ", stdout
);
9261 if (option
->info
& OPAD_PREFIX
)
9262 fputs (" PREFIX", stdout
);
9263 if (option
->info
& OPAD_POSTFIX
)
9264 fputs (" POSTFIX", stdout
);
9265 if (option
->info
& OPAD_SYMBOL
)
9266 fputs (" SYMBOL", stdout
);
9269 fputs (" HWPATCH ", stdout
);
9270 if (option
->info
& OHW_R4KEOP
)
9271 fputs (" R4KEOP", stdout
);
9272 if (option
->info
& OHW_R8KPFETCH
)
9273 fputs (" R8KPFETCH", stdout
);
9274 if (option
->info
& OHW_R5KEOP
)
9275 fputs (" R5KEOP", stdout
);
9276 if (option
->info
& OHW_R5KCVTL
)
9277 fputs (" R5KCVTL", stdout
);
9280 fputs (" FILL ", stdout
);
9281 /* XXX Print content of info word? */
9284 fputs (" TAGS ", stdout
);
9285 /* XXX Print content of info word? */
9288 fputs (" HWAND ", stdout
);
9289 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9290 fputs (" R4KEOP_CHECKED", stdout
);
9291 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9292 fputs (" R4KEOP_CLEAN", stdout
);
9295 fputs (" HWOR ", stdout
);
9296 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9297 fputs (" R4KEOP_CHECKED", stdout
);
9298 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9299 fputs (" R4KEOP_CLEAN", stdout
);
9302 printf (" GP_GROUP %#06lx self-contained %#06lx",
9303 option
->info
& OGP_GROUP
,
9304 (option
->info
& OGP_SELF
) >> 16);
9307 printf (" IDENT %#06lx self-contained %#06lx",
9308 option
->info
& OGP_GROUP
,
9309 (option
->info
& OGP_SELF
) >> 16);
9312 /* This shouldn't happen. */
9313 printf (" %3d ??? %d %lx",
9314 option
->kind
, option
->section
, option
->info
);
9318 len
= sizeof (* eopt
);
9319 while (len
< option
->size
)
9320 if (((char *) option
)[len
] >= ' '
9321 && ((char *) option
)[len
] < 0x7f)
9322 printf ("%c", ((char *) option
)[len
++]);
9324 printf ("\\%03o", ((char *) option
)[len
++]);
9326 fputs ("\n", stdout
);
9334 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9336 Elf32_Conflict
* iconf
;
9339 if (dynamic_symbols
== NULL
)
9341 error (_("conflict list found without a dynamic symbol table"));
9345 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (* iconf
));
9348 error (_("Out of memory"));
9354 Elf32_External_Conflict
* econf32
;
9356 econf32
= ((Elf32_External_Conflict
*)
9357 get_data (NULL
, file
, conflicts_offset
,
9358 conflictsno
* sizeof (* econf32
),
9363 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9364 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9370 Elf64_External_Conflict
* econf64
;
9372 econf64
= ((Elf64_External_Conflict
*)
9373 get_data (NULL
, file
, conflicts_offset
,
9374 conflictsno
* sizeof (* econf64
),
9379 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9380 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9385 printf (_("\nSection '.conflict' contains %ld entries:\n"),
9386 (long) conflictsno
);
9387 puts (_(" Num: Index Value Name"));
9389 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9391 Elf_Internal_Sym
* psym
= & dynamic_symbols
[iconf
[cnt
]];
9393 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9394 print_vma (psym
->st_value
, FULL_HEX
);
9396 print_symbol (25, dynamic_strings
+ psym
->st_name
);
9407 process_gnu_liblist (file
)
9410 Elf_Internal_Shdr
* section
, * string_sec
;
9411 Elf32_External_Lib
* elib
;
9419 for (i
= 0, section
= section_headers
;
9420 i
< elf_header
.e_shnum
;
9423 switch (section
->sh_type
)
9425 case SHT_GNU_LIBLIST
:
9426 elib
= ((Elf32_External_Lib
*)
9427 get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
9432 string_sec
= SECTION_HEADER (section
->sh_link
);
9434 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
9435 string_sec
->sh_size
,
9436 _("liblist string table"));
9439 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9445 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9446 SECTION_NAME (section
),
9447 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9449 puts (" Library Time Stamp Checksum Version Flags");
9451 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9459 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9460 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9461 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9462 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9463 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9465 tmp
= gmtime (&time
);
9466 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9467 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9468 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9470 printf ("%3lu: ", (unsigned long) cnt
);
9472 printf ("%-20s", strtab
+ liblist
.l_name
);
9474 printf ("%-20.20s", strtab
+ liblist
.l_name
);
9475 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9476 liblist
.l_version
, liblist
.l_flags
);
9487 get_note_type (e_type
)
9490 static char buff
[64];
9494 case NT_PRSTATUS
: return _("NT_PRSTATUS (prstatus structure)");
9495 case NT_FPREGSET
: return _("NT_FPREGSET (floating point registers)");
9496 case NT_PRPSINFO
: return _("NT_PRPSINFO (prpsinfo structure)");
9497 case NT_TASKSTRUCT
: return _("NT_TASKSTRUCT (task structure)");
9498 case NT_PRXFPREG
: return _("NT_PRXFPREG (user_xfpregs structure)");
9499 case NT_PSTATUS
: return _("NT_PSTATUS (pstatus structure)");
9500 case NT_FPREGS
: return _("NT_FPREGS (floating point registers)");
9501 case NT_PSINFO
: return _("NT_PSINFO (psinfo structure)");
9502 case NT_LWPSTATUS
: return _("NT_LWPSTATUS (lwpstatus_t structure)");
9503 case NT_LWPSINFO
: return _("NT_LWPSINFO (lwpsinfo_t structure)");
9504 case NT_WIN32PSTATUS
: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9506 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
9512 get_netbsd_elfcore_note_type (e_type
)
9515 static char buff
[64];
9517 if (e_type
== NT_NETBSDCORE_PROCINFO
)
9519 /* NetBSD core "procinfo" structure. */
9520 return _("NetBSD procinfo structure");
9523 /* As of Jan 2002 there are no other machine-independent notes
9524 defined for NetBSD core files. If the note type is less
9525 than the start of the machine-dependent note types, we don't
9528 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
9530 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
9534 switch (elf_header
.e_machine
)
9536 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9537 and PT_GETFPREGS == mach+2. */
9542 case EM_SPARC32PLUS
:
9546 case NT_NETBSDCORE_FIRSTMACH
+0:
9547 return _("PT_GETREGS (reg structure)");
9548 case NT_NETBSDCORE_FIRSTMACH
+2:
9549 return _("PT_GETFPREGS (fpreg structure)");
9555 /* On all other arch's, PT_GETREGS == mach+1 and
9556 PT_GETFPREGS == mach+3. */
9560 case NT_NETBSDCORE_FIRSTMACH
+1:
9561 return _("PT_GETREGS (reg structure)");
9562 case NT_NETBSDCORE_FIRSTMACH
+3:
9563 return _("PT_GETFPREGS (fpreg structure)");
9569 sprintf (buff
, _("PT_FIRSTMACH+%d"), e_type
- NT_NETBSDCORE_FIRSTMACH
);
9573 /* Note that by the ELF standard, the name field is already null byte
9574 terminated, and namesz includes the terminating null byte.
9575 I.E. the value of namesz for the name "FSF" is 4.
9577 If the value of namesz is zero, there is no name present. */
9579 process_note (pnote
)
9580 Elf32_Internal_Note
* pnote
;
9584 if (pnote
->namesz
== 0)
9586 /* If there is no note name, then use the default set of
9587 note type strings. */
9588 nt
= get_note_type (pnote
->type
);
9590 else if (strncmp (pnote
->namedata
, "NetBSD-CORE", 11) == 0)
9592 /* NetBSD-specific core file notes. */
9593 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
9597 /* Don't recognize this note name; just use the default set of
9598 note type strings. */
9599 nt
= get_note_type (pnote
->type
);
9602 printf (" %s\t\t0x%08lx\t%s\n",
9603 pnote
->namesz
? pnote
->namedata
: "(NONE)",
9610 process_corefile_note_segment (file
, offset
, length
)
9615 Elf_External_Note
* pnotes
;
9616 Elf_External_Note
* external
;
9622 pnotes
= (Elf_External_Note
*) get_data (NULL
, file
, offset
, length
,
9629 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9630 (unsigned long) offset
, (unsigned long) length
);
9631 printf (_(" Owner\t\tData size\tDescription\n"));
9633 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
9635 Elf_External_Note
* next
;
9636 Elf32_Internal_Note inote
;
9639 inote
.type
= BYTE_GET (external
->type
);
9640 inote
.namesz
= BYTE_GET (external
->namesz
);
9641 inote
.namedata
= external
->name
;
9642 inote
.descsz
= BYTE_GET (external
->descsz
);
9643 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
9644 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
9646 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
9648 if (((char *) next
) > (((char *) pnotes
) + length
))
9650 warn (_("corrupt note found at offset %x into core notes\n"),
9651 ((char *) external
) - ((char *) pnotes
));
9652 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
9653 inote
.type
, inote
.namesz
, inote
.descsz
);
9659 /* Verify that name is null terminated. It appears that at least
9660 one version of Linux (RedHat 6.0) generates corefiles that don't
9661 comply with the ELF spec by failing to include the null byte in
9663 if (inote
.namedata
[inote
.namesz
] != '\0')
9665 temp
= malloc (inote
.namesz
+ 1);
9669 error (_("Out of memory\n"));
9674 strncpy (temp
, inote
.namedata
, inote
.namesz
);
9675 temp
[inote
.namesz
] = 0;
9677 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9678 inote
.namedata
= temp
;
9681 res
&= process_note (& inote
);
9696 process_corefile_note_segments (file
)
9699 Elf_Internal_Phdr
* program_headers
;
9700 Elf_Internal_Phdr
* segment
;
9704 program_headers
= (Elf_Internal_Phdr
*) malloc
9705 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
9707 if (program_headers
== NULL
)
9709 error (_("Out of memory\n"));
9714 i
= get_32bit_program_headers (file
, program_headers
);
9716 i
= get_64bit_program_headers (file
, program_headers
);
9720 free (program_headers
);
9724 for (i
= 0, segment
= program_headers
;
9725 i
< elf_header
.e_phnum
;
9728 if (segment
->p_type
== PT_NOTE
)
9729 res
&= process_corefile_note_segment (file
,
9730 (bfd_vma
) segment
->p_offset
,
9731 (bfd_vma
) segment
->p_filesz
);
9734 free (program_headers
);
9740 process_corefile_contents (file
)
9743 /* If we have not been asked to display the notes then do nothing. */
9747 /* If file is not a core file then exit. */
9748 if (elf_header
.e_type
!= ET_CORE
)
9751 /* No program headers means no NOTE segment. */
9752 if (elf_header
.e_phnum
== 0)
9754 printf (_("No note segments present in the core file.\n"));
9758 return process_corefile_note_segments (file
);
9762 process_arch_specific (file
)
9768 switch (elf_header
.e_machine
)
9771 case EM_MIPS_RS3_LE
:
9772 return process_mips_specific (file
);
9781 get_file_header (file
)
9784 /* Read in the identity array. */
9785 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
9788 /* Determine how to read the rest of the header. */
9789 switch (elf_header
.e_ident
[EI_DATA
])
9791 default: /* fall through */
9792 case ELFDATANONE
: /* fall through */
9793 case ELFDATA2LSB
: byte_get
= byte_get_little_endian
; break;
9794 case ELFDATA2MSB
: byte_get
= byte_get_big_endian
; break;
9797 /* For now we only support 32 bit and 64 bit ELF files. */
9798 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
9800 /* Read in the rest of the header. */
9803 Elf32_External_Ehdr ehdr32
;
9805 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
9808 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
9809 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
9810 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
9811 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
9812 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
9813 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
9814 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
9815 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
9816 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
9817 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
9818 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
9819 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
9820 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
9824 Elf64_External_Ehdr ehdr64
;
9826 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9827 we will not be able to cope with the 64bit data found in
9828 64 ELF files. Detect this now and abort before we start
9829 overwritting things. */
9830 if (sizeof (bfd_vma
) < 8)
9832 error (_("This instance of readelf has been built without support for a\n\
9833 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9837 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
9840 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
9841 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
9842 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
9843 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
9844 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
9845 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
9846 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
9847 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
9848 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
9849 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
9850 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
9851 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
9852 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
9855 if (elf_header
.e_shoff
)
9857 /* There may be some extensions in the first section header. Don't
9858 bomb if we can't read it. */
9860 get_32bit_section_headers (file
, 1);
9862 get_64bit_section_headers (file
, 1);
9869 process_file (file_name
)
9873 struct stat statbuf
;
9876 if (stat (file_name
, & statbuf
) < 0)
9878 error (_("Cannot stat input file %s.\n"), file_name
);
9882 file
= fopen (file_name
, "rb");
9885 error (_("Input file %s not found.\n"), file_name
);
9889 if (! get_file_header (file
))
9891 error (_("%s: Failed to read file header\n"), file_name
);
9896 /* Initialise per file variables. */
9897 for (i
= NUM_ELEM (version_info
); i
--;)
9898 version_info
[i
] = 0;
9900 for (i
= NUM_ELEM (dynamic_info
); i
--;)
9901 dynamic_info
[i
] = 0;
9903 /* Process the file. */
9905 printf (_("\nFile: %s\n"), file_name
);
9907 if (! process_file_header ())
9913 process_section_headers (file
);
9915 process_program_headers (file
);
9917 process_dynamic_segment (file
);
9919 process_relocs (file
);
9921 process_unwind (file
);
9923 process_symbol_table (file
);
9925 process_syminfo (file
);
9927 process_version_sections (file
);
9929 process_section_contents (file
);
9931 process_corefile_contents (file
);
9933 process_gnu_liblist (file
);
9935 process_arch_specific (file
);
9939 if (section_headers
)
9941 free (section_headers
);
9942 section_headers
= NULL
;
9947 free (string_table
);
9948 string_table
= NULL
;
9949 string_table_length
= 0;
9952 if (dynamic_strings
)
9954 free (dynamic_strings
);
9955 dynamic_strings
= NULL
;
9958 if (dynamic_symbols
)
9960 free (dynamic_symbols
);
9961 dynamic_symbols
= NULL
;
9962 num_dynamic_syms
= 0;
9965 if (dynamic_syminfo
)
9967 free (dynamic_syminfo
);
9968 dynamic_syminfo
= NULL
;
9974 #ifdef SUPPORT_DISASSEMBLY
9975 /* Needed by the i386 disassembler. For extra credit, someone could
9976 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9980 print_address (unsigned int addr
, FILE * outfile
)
9982 fprintf (outfile
,"0x%8.8x", addr
);
9985 /* Needed by the i386 disassembler. */
9987 db_task_printsym (unsigned int addr
)
9989 print_address (addr
, stderr
);
9993 int main
PARAMS ((int, char **));
10002 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10003 setlocale (LC_MESSAGES
, "");
10005 #if defined (HAVE_SETLOCALE)
10006 setlocale (LC_CTYPE
, "");
10008 bindtextdomain (PACKAGE
, LOCALEDIR
);
10009 textdomain (PACKAGE
);
10011 parse_args (argc
, argv
);
10013 if (optind
< (argc
- 1))
10017 while (optind
< argc
)
10018 err
|= process_file (argv
[optind
++]);
10020 if (dump_sects
!= NULL
)