1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 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 believe 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"
72 #include "elf/m68hc11.h"
73 #include "elf/mcore.h"
76 #include "elf/mn10200.h"
77 #include "elf/mn10300.h"
78 #include "elf/msp430.h"
82 #include "elf/ppc64.h"
85 #include "elf/sparc.h"
88 #include "elf/x86-64.h"
89 #include "elf/xstormy16.h"
90 #include "elf/iq2000.h"
91 #include "elf/xtensa.h"
95 #include "libiberty.h"
97 char *program_name
= "readelf";
98 unsigned long dynamic_addr
;
99 bfd_size_type dynamic_size
;
100 char *dynamic_strings
;
102 unsigned long string_table_length
;
103 unsigned long num_dynamic_syms
;
104 Elf_Internal_Sym
*dynamic_symbols
;
105 Elf_Internal_Syminfo
*dynamic_syminfo
;
106 unsigned long dynamic_syminfo_offset
;
107 unsigned int dynamic_syminfo_nent
;
108 char program_interpreter
[64];
109 long dynamic_info
[DT_JMPREL
+ 1];
110 long version_info
[16];
112 Elf_Internal_Ehdr elf_header
;
113 Elf_Internal_Shdr
*section_headers
;
114 Elf_Internal_Dyn
*dynamic_segment
;
115 Elf_Internal_Shdr
*symtab_shndx_hdr
;
123 int do_using_dynamic
;
131 int do_debug_abbrevs
;
133 int do_debug_pubnames
;
134 int do_debug_aranges
;
136 int do_debug_frames_interp
;
137 int do_debug_macinfo
;
144 /* A dynamic array of flags indicating which sections require dumping. */
145 char *dump_sects
= NULL
;
146 unsigned int num_dump_sects
= 0;
148 #define HEX_DUMP (1 << 0)
149 #define DISASS_DUMP (1 << 1)
150 #define DEBUG_DUMP (1 << 2)
152 /* How to rpint a vma value. */
153 typedef enum print_mode
165 /* Forward declarations for dumb compilers. */
166 static void print_vma
167 PARAMS ((bfd_vma
, print_mode
));
168 static void print_symbol
169 PARAMS ((int, const char *));
170 static bfd_vma (*byte_get
)
171 PARAMS ((unsigned char *, int));
172 static bfd_vma byte_get_little_endian
173 PARAMS ((unsigned char *, int));
174 static bfd_vma byte_get_big_endian
175 PARAMS ((unsigned char *, int));
176 static const char *get_mips_dynamic_type
177 PARAMS ((unsigned long));
178 static const char *get_sparc64_dynamic_type
179 PARAMS ((unsigned long));
180 static const char *get_ppc64_dynamic_type
181 PARAMS ((unsigned long));
182 static const char *get_parisc_dynamic_type
183 PARAMS ((unsigned long));
184 static const char *get_ia64_dynamic_type
185 PARAMS ((unsigned long));
186 static const char *get_dynamic_type
187 PARAMS ((unsigned long));
188 static int slurp_rela_relocs
189 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela
**,
191 static int slurp_rel_relocs
192 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela
**,
194 static int dump_relocations
195 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*,
196 unsigned long, char *, int));
197 static char *get_file_type
199 static char *get_machine_name
201 static void decode_ARM_machine_flags
202 PARAMS ((unsigned, char[]));
203 static char *get_machine_flags
204 PARAMS ((unsigned, unsigned));
205 static const char *get_mips_segment_type
206 PARAMS ((unsigned long));
207 static const char *get_parisc_segment_type
208 PARAMS ((unsigned long));
209 static const char *get_ia64_segment_type
210 PARAMS ((unsigned long));
211 static const char *get_segment_type
212 PARAMS ((unsigned long));
213 static const char *get_mips_section_type_name
214 PARAMS ((unsigned int));
215 static const char *get_parisc_section_type_name
216 PARAMS ((unsigned int));
217 static const char *get_ia64_section_type_name
218 PARAMS ((unsigned int));
219 static const char *get_section_type_name
220 PARAMS ((unsigned int));
221 static const char *get_symbol_binding
222 PARAMS ((unsigned int));
223 static const char *get_symbol_type
224 PARAMS ((unsigned int));
225 static const char *get_symbol_visibility
226 PARAMS ((unsigned int));
227 static const char *get_symbol_index_type
228 PARAMS ((unsigned int));
229 static const char *get_dynamic_flags
233 static void parse_args
234 PARAMS ((int, char **));
235 static int process_file_header
237 static int process_program_headers
239 static int process_section_headers
241 static int process_unwind
243 static void dynamic_segment_mips_val
244 PARAMS ((Elf_Internal_Dyn
*));
245 static void dynamic_segment_parisc_val
246 PARAMS ((Elf_Internal_Dyn
*));
247 static void dynamic_segment_ia64_val
248 PARAMS ((Elf_Internal_Dyn
*));
249 static int process_dynamic_segment
251 static int process_symbol_table
253 static int process_syminfo
255 static int process_section_contents
257 static void process_mips_fpe_exception
259 static int process_mips_specific
261 static int process_file
263 static int process_relocs
265 static int process_version_sections
267 static char *get_ver_flags
268 PARAMS ((unsigned int));
269 static int get_32bit_section_headers
270 PARAMS ((FILE *, unsigned int));
271 static int get_64bit_section_headers
272 PARAMS ((FILE *, unsigned int));
273 static int get_32bit_program_headers
274 PARAMS ((FILE *, Elf_Internal_Phdr
*));
275 static int get_64bit_program_headers
276 PARAMS ((FILE *, Elf_Internal_Phdr
*));
277 static int get_file_header
279 static Elf_Internal_Sym
*get_32bit_elf_symbols
280 PARAMS ((FILE *, Elf_Internal_Shdr
*));
281 static Elf_Internal_Sym
*get_64bit_elf_symbols
282 PARAMS ((FILE *, Elf_Internal_Shdr
*));
283 static const char *get_elf_section_flags
285 static int *get_dynamic_data
286 PARAMS ((FILE *, unsigned int));
287 static int get_32bit_dynamic_segment
289 static int get_64bit_dynamic_segment
291 #ifdef SUPPORT_DISASSEMBLY
292 static int disassemble_section
293 PARAMS ((Elf_Internal_Shdr
*, FILE *));
295 static int dump_section
296 PARAMS ((Elf_Internal_Shdr
*, FILE *));
297 static int display_debug_section
298 PARAMS ((Elf_Internal_Shdr
*, FILE *));
299 static int display_debug_info
300 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
301 static int display_debug_not_supported
302 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
303 static int prescan_debug_info
304 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
305 static int display_debug_lines
306 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
307 static int display_debug_pubnames
308 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
309 static int display_debug_abbrev
310 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
311 static int display_debug_aranges
312 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
313 static int display_debug_frames
314 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
315 static int display_debug_macinfo
316 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
317 static int display_debug_str
318 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
319 static int display_debug_loc
320 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
321 static unsigned char *process_abbrev_section
322 PARAMS ((unsigned char *, unsigned char *));
323 static void load_debug_str
325 static void free_debug_str
327 static const char *fetch_indirect_string
328 PARAMS ((unsigned long));
329 static void load_debug_loc
331 static void free_debug_loc
333 static unsigned long read_leb128
334 PARAMS ((unsigned char *, int *, int));
335 static int process_extended_line_op
336 PARAMS ((unsigned char *, int, int));
337 static void reset_state_machine
339 static char *get_TAG_name
340 PARAMS ((unsigned long));
341 static char *get_AT_name
342 PARAMS ((unsigned long));
343 static char *get_FORM_name
344 PARAMS ((unsigned long));
345 static void free_abbrevs
347 static void add_abbrev
348 PARAMS ((unsigned long, unsigned long, int));
349 static void add_abbrev_attr
350 PARAMS ((unsigned long, unsigned long));
351 static unsigned char *read_and_display_attr
352 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
353 unsigned long, unsigned long, int));
354 static unsigned char *read_and_display_attr_value
355 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
356 unsigned long, unsigned long, int));
357 static unsigned char *display_block
358 PARAMS ((unsigned char *, unsigned long));
359 static void decode_location_expression
360 PARAMS ((unsigned char *, unsigned int, unsigned long));
361 static void request_dump
362 PARAMS ((unsigned int, int));
363 static const char *get_elf_class
364 PARAMS ((unsigned int));
365 static const char *get_data_encoding
366 PARAMS ((unsigned int));
367 static const char *get_osabi_name
368 PARAMS ((unsigned int));
369 static int guess_is_rela
370 PARAMS ((unsigned long));
371 static const char *get_note_type
372 PARAMS ((unsigned int));
373 static const char *get_netbsd_elfcore_note_type
374 PARAMS ((unsigned int));
375 static int process_note
376 PARAMS ((Elf_Internal_Note
*));
377 static int process_corefile_note_segment
378 PARAMS ((FILE *, bfd_vma
, bfd_vma
));
379 static int process_corefile_note_segments
381 static int process_corefile_contents
383 static int process_arch_specific
385 static int process_gnu_liblist
388 typedef int Elf32_Word
;
392 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
393 ((X)->sh_name >= string_table_length \
394 ? "<corrupt>" : string_table + (X)->sh_name))
396 /* Given st_shndx I, map to section_headers index. */
397 #define SECTION_HEADER_INDEX(I) \
398 ((I) < SHN_LORESERVE \
400 : ((I) <= SHN_HIRESERVE \
402 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
404 /* Reverse of the above. */
405 #define SECTION_HEADER_NUM(N) \
406 ((N) < SHN_LORESERVE \
408 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
410 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
412 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
414 #define BYTE_GET(field) byte_get (field, sizeof (field))
416 /* If we can support a 64 bit data type then BFD64 should be defined
417 and sizeof (bfd_vma) == 8. In this case when translating from an
418 external 8 byte field to an internal field, we can assume that the
419 internal field is also 8 bytes wide and so we can extract all the data.
420 If, however, BFD64 is not defined, then we must assume that the
421 internal data structure only has 4 byte wide fields that are the
422 equivalent of the 8 byte wide external counterparts, and so we must
423 truncate the data. */
425 #define BYTE_GET8(field) byte_get (field, -8)
427 #define BYTE_GET8(field) byte_get (field, 8)
430 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
432 #define GET_ELF_SYMBOLS(file, section) \
433 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
434 : get_64bit_elf_symbols (file, section))
438 error
VPARAMS ((const char *message
, ...))
440 VA_OPEN (args
, message
);
441 VA_FIXEDARG (args
, const char *, message
);
443 fprintf (stderr
, _("%s: Error: "), program_name
);
444 vfprintf (stderr
, message
, args
);
449 warn
VPARAMS ((const char *message
, ...))
451 VA_OPEN (args
, message
);
452 VA_FIXEDARG (args
, const char *, message
);
454 fprintf (stderr
, _("%s: Warning: "), program_name
);
455 vfprintf (stderr
, message
, args
);
459 static PTR get_data
PARAMS ((PTR
, FILE *, long, size_t, const char *));
462 get_data (var
, file
, offset
, size
, reason
)
474 if (fseek (file
, offset
, SEEK_SET
))
476 error (_("Unable to seek to %x for %s\n"), offset
, reason
);
483 mvar
= (PTR
) malloc (size
);
487 error (_("Out of memory allocating %d bytes for %s\n"),
493 if (fread (mvar
, size
, 1, file
) != 1)
495 error (_("Unable to read in %d bytes of %s\n"), size
, reason
);
505 byte_get_little_endian (field
, size
)
506 unsigned char *field
;
515 return ((unsigned int) (field
[0]))
516 | (((unsigned int) (field
[1])) << 8);
520 /* We want to extract data from an 8 byte wide field and
521 place it into a 4 byte wide field. Since this is a little
522 endian source we can just use the 4 byte extraction code. */
526 return ((unsigned long) (field
[0]))
527 | (((unsigned long) (field
[1])) << 8)
528 | (((unsigned long) (field
[2])) << 16)
529 | (((unsigned long) (field
[3])) << 24);
534 /* This is a special case, generated by the BYTE_GET8 macro.
535 It means that we are loading an 8 byte value from a field
536 in an external structure into an 8 byte value in a field
537 in an internal strcuture. */
538 return ((bfd_vma
) (field
[0]))
539 | (((bfd_vma
) (field
[1])) << 8)
540 | (((bfd_vma
) (field
[2])) << 16)
541 | (((bfd_vma
) (field
[3])) << 24)
542 | (((bfd_vma
) (field
[4])) << 32)
543 | (((bfd_vma
) (field
[5])) << 40)
544 | (((bfd_vma
) (field
[6])) << 48)
545 | (((bfd_vma
) (field
[7])) << 56);
548 error (_("Unhandled data length: %d\n"), size
);
553 /* Print a VMA value. */
555 print_vma (vma
, mode
)
565 case FULL_HEX
: printf ("0x"); /* drop through */
566 case LONG_HEX
: printf ("%8.8lx", (unsigned long) vma
); break;
567 case PREFIX_HEX
: printf ("0x"); /* drop through */
568 case HEX
: printf ("%lx", (unsigned long) vma
); break;
569 case DEC
: printf ("%ld", (unsigned long) vma
); break;
570 case DEC_5
: printf ("%5ld", (long) vma
); break;
571 case UNSIGNED
: printf ("%lu", (unsigned long) vma
); break;
592 #if BFD_HOST_64BIT_LONG
595 if (_bfd_int64_high (vma
))
596 printf ("%lx%8.8lx", _bfd_int64_high (vma
), _bfd_int64_low (vma
));
598 printf ("%lx", _bfd_int64_low (vma
));
603 #if BFD_HOST_64BIT_LONG
606 if (_bfd_int64_high (vma
))
608 printf ("++%ld", _bfd_int64_low (vma
));
610 printf ("%ld", _bfd_int64_low (vma
));
615 #if BFD_HOST_64BIT_LONG
616 printf ("%5ld", vma
);
618 if (_bfd_int64_high (vma
))
620 printf ("++%ld", _bfd_int64_low (vma
));
622 printf ("%5ld", _bfd_int64_low (vma
));
627 #if BFD_HOST_64BIT_LONG
630 if (_bfd_int64_high (vma
))
632 printf ("++%lu", _bfd_int64_low (vma
));
634 printf ("%lu", _bfd_int64_low (vma
));
642 /* Display a symbol on stdout. If do_wide is not true then
643 format the symbol to be at most WIDTH characters,
644 truncating as necessary. If WIDTH is negative then
645 format the string to be exactly - WIDTH characters,
646 truncating or padding as necessary. */
649 print_symbol (width
, symbol
)
654 printf ("%s", symbol
);
656 printf ("%-*.*s", width
, width
, symbol
);
658 printf ("%-.*s", width
, symbol
);
662 byte_get_big_endian (field
, size
)
663 unsigned char *field
;
672 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
675 return ((unsigned long) (field
[3]))
676 | (((unsigned long) (field
[2])) << 8)
677 | (((unsigned long) (field
[1])) << 16)
678 | (((unsigned long) (field
[0])) << 24);
682 /* Although we are extracing data from an 8 byte wide field, we
683 are returning only 4 bytes of data. */
684 return ((unsigned long) (field
[7]))
685 | (((unsigned long) (field
[6])) << 8)
686 | (((unsigned long) (field
[5])) << 16)
687 | (((unsigned long) (field
[4])) << 24);
691 /* This is a special case, generated by the BYTE_GET8 macro.
692 It means that we are loading an 8 byte value from a field
693 in an external structure into an 8 byte value in a field
694 in an internal strcuture. */
695 return ((bfd_vma
) (field
[7]))
696 | (((bfd_vma
) (field
[6])) << 8)
697 | (((bfd_vma
) (field
[5])) << 16)
698 | (((bfd_vma
) (field
[4])) << 24)
699 | (((bfd_vma
) (field
[3])) << 32)
700 | (((bfd_vma
) (field
[2])) << 40)
701 | (((bfd_vma
) (field
[1])) << 48)
702 | (((bfd_vma
) (field
[0])) << 56);
706 error (_("Unhandled data length: %d\n"), size
);
711 /* Guess the relocation size commonly used by the specific machines. */
714 guess_is_rela (e_machine
)
715 unsigned long e_machine
;
719 /* Targets that use REL relocations. */
735 /* Targets that use RELA relocations. */
750 case EM_CYGNUS_MN10200
:
752 case EM_CYGNUS_MN10300
:
797 warn (_("Don't know about relocations on this machine architecture\n"));
803 slurp_rela_relocs (file
, rel_offset
, rel_size
, relasp
, nrelasp
)
805 unsigned long rel_offset
;
806 unsigned long rel_size
;
807 Elf_Internal_Rela
**relasp
;
808 unsigned long *nrelasp
;
810 Elf_Internal_Rela
*relas
;
811 unsigned long nrelas
;
816 Elf32_External_Rela
*erelas
;
818 erelas
= (Elf32_External_Rela
*) get_data (NULL
, file
, rel_offset
,
819 rel_size
, _("relocs"));
823 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
825 relas
= (Elf_Internal_Rela
*)
826 malloc (nrelas
* sizeof (Elf_Internal_Rela
));
830 error(_("out of memory parsing relocs"));
834 for (i
= 0; i
< nrelas
; i
++)
836 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
837 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
838 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
845 Elf64_External_Rela
*erelas
;
847 erelas
= (Elf64_External_Rela
*) get_data (NULL
, file
, rel_offset
,
848 rel_size
, _("relocs"));
852 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
854 relas
= (Elf_Internal_Rela
*)
855 malloc (nrelas
* sizeof (Elf_Internal_Rela
));
859 error(_("out of memory parsing relocs"));
863 for (i
= 0; i
< nrelas
; i
++)
865 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
866 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
867 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
878 slurp_rel_relocs (file
, rel_offset
, rel_size
, relsp
, nrelsp
)
880 unsigned long rel_offset
;
881 unsigned long rel_size
;
882 Elf_Internal_Rela
**relsp
;
883 unsigned long *nrelsp
;
885 Elf_Internal_Rela
*rels
;
891 Elf32_External_Rel
*erels
;
893 erels
= (Elf32_External_Rel
*) get_data (NULL
, file
, rel_offset
,
894 rel_size
, _("relocs"));
898 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
900 rels
= (Elf_Internal_Rela
*) malloc (nrels
* sizeof (Elf_Internal_Rela
));
904 error(_("out of memory parsing relocs"));
908 for (i
= 0; i
< nrels
; i
++)
910 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
911 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
912 rels
[i
].r_addend
= 0;
919 Elf64_External_Rel
*erels
;
921 erels
= (Elf64_External_Rel
*) get_data (NULL
, file
, rel_offset
,
922 rel_size
, _("relocs"));
926 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
928 rels
= (Elf_Internal_Rela
*) malloc (nrels
* sizeof (Elf_Internal_Rela
));
932 error(_("out of memory parsing relocs"));
936 for (i
= 0; i
< nrels
; i
++)
938 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
939 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
940 rels
[i
].r_addend
= 0;
950 /* Display the contents of the relocation data found at the specified offset. */
953 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
955 unsigned long rel_offset
;
956 unsigned long rel_size
;
957 Elf_Internal_Sym
*symtab
;
963 Elf_Internal_Rela
*rels
;
966 if (is_rela
== UNKNOWN
)
967 is_rela
= guess_is_rela (elf_header
.e_machine
);
971 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
976 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
985 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
987 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
992 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
994 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1002 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1004 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1009 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1011 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1015 for (i
= 0; i
< rel_size
; i
++)
1018 const char *rtype2
= NULL
;
1019 const char *rtype3
= NULL
;
1022 bfd_vma symtab_index
;
1024 bfd_vma type2
= (bfd_vma
) NULL
;
1025 bfd_vma type3
= (bfd_vma
) NULL
;
1027 offset
= rels
[i
].r_offset
;
1028 info
= rels
[i
].r_info
;
1032 type
= ELF32_R_TYPE (info
);
1033 symtab_index
= ELF32_R_SYM (info
);
1037 /* The #ifdef BFD64 below is to prevent a compile time warning.
1038 We know that if we do not have a 64 bit data type that we
1039 will never execute this code anyway. */
1041 if (elf_header
.e_machine
== EM_MIPS
)
1043 /* In little-endian objects, r_info isn't really a 64-bit
1044 little-endian value: it has a 32-bit little-endian
1045 symbol index followed by four individual byte fields.
1046 Reorder INFO accordingly. */
1047 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1048 info
= (((info
& 0xffffffff) << 32)
1049 | ((info
>> 56) & 0xff)
1050 | ((info
>> 40) & 0xff00)
1051 | ((info
>> 24) & 0xff0000)
1052 | ((info
>> 8) & 0xff000000));
1053 type
= ELF64_MIPS_R_TYPE (info
);
1054 type2
= ELF64_MIPS_R_TYPE2 (info
);
1055 type3
= ELF64_MIPS_R_TYPE3 (info
);
1057 else if (elf_header
.e_machine
== EM_SPARCV9
)
1058 type
= ELF64_R_TYPE_ID (info
);
1060 type
= ELF64_R_TYPE (info
);
1062 symtab_index
= ELF64_R_SYM (info
);
1068 #ifdef _bfd_int64_low
1069 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
1071 printf ("%8.8lx %8.8lx ", offset
, info
);
1076 #ifdef _bfd_int64_low
1078 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1079 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1080 _bfd_int64_high (offset
),
1081 _bfd_int64_low (offset
),
1082 _bfd_int64_high (info
),
1083 _bfd_int64_low (info
));
1086 ? "%16.16lx %16.16lx "
1087 : "%12.12lx %12.12lx ",
1092 switch (elf_header
.e_machine
)
1099 case EM_CYGNUS_M32R
:
1100 rtype
= elf_m32r_reloc_type (type
);
1105 rtype
= elf_i386_reloc_type (type
);
1110 rtype
= elf_m68hc11_reloc_type (type
);
1114 rtype
= elf_m68k_reloc_type (type
);
1118 rtype
= elf_i960_reloc_type (type
);
1123 rtype
= elf_avr_reloc_type (type
);
1126 case EM_OLD_SPARCV9
:
1127 case EM_SPARC32PLUS
:
1130 rtype
= elf_sparc_reloc_type (type
);
1134 case EM_CYGNUS_V850
:
1135 rtype
= v850_reloc_type (type
);
1139 case EM_CYGNUS_D10V
:
1140 rtype
= elf_d10v_reloc_type (type
);
1144 case EM_CYGNUS_D30V
:
1145 rtype
= elf_d30v_reloc_type (type
);
1149 rtype
= elf_dlx_reloc_type (type
);
1153 rtype
= elf_sh_reloc_type (type
);
1157 case EM_CYGNUS_MN10300
:
1158 rtype
= elf_mn10300_reloc_type (type
);
1162 case EM_CYGNUS_MN10200
:
1163 rtype
= elf_mn10200_reloc_type (type
);
1167 case EM_CYGNUS_FR30
:
1168 rtype
= elf_fr30_reloc_type (type
);
1172 rtype
= elf_frv_reloc_type (type
);
1176 rtype
= elf_mcore_reloc_type (type
);
1180 rtype
= elf_mmix_reloc_type (type
);
1185 rtype
= elf_msp430_reloc_type (type
);
1189 rtype
= elf_ppc_reloc_type (type
);
1193 rtype
= elf_ppc64_reloc_type (type
);
1197 case EM_MIPS_RS3_LE
:
1198 rtype
= elf_mips_reloc_type (type
);
1201 rtype2
= elf_mips_reloc_type (type2
);
1202 rtype3
= elf_mips_reloc_type (type3
);
1207 rtype
= elf_alpha_reloc_type (type
);
1211 rtype
= elf_arm_reloc_type (type
);
1215 rtype
= elf_arc_reloc_type (type
);
1219 rtype
= elf_hppa_reloc_type (type
);
1225 rtype
= elf_h8_reloc_type (type
);
1230 rtype
= elf_or32_reloc_type (type
);
1235 rtype
= elf_pj_reloc_type (type
);
1238 rtype
= elf_ia64_reloc_type (type
);
1242 rtype
= elf_cris_reloc_type (type
);
1246 rtype
= elf_i860_reloc_type (type
);
1250 rtype
= elf_x86_64_reloc_type (type
);
1254 rtype
= i370_reloc_type (type
);
1259 rtype
= elf_s390_reloc_type (type
);
1263 rtype
= elf_xstormy16_reloc_type (type
);
1267 rtype
= elf_vax_reloc_type (type
);
1272 rtype
= elf_ip2k_reloc_type (type
);
1276 rtype
= elf_iq2000_reloc_type (type
);
1281 rtype
= elf_xtensa_reloc_type (type
);
1286 #ifdef _bfd_int64_low
1287 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1289 printf (_("unrecognized: %-7lx"), type
);
1292 printf (do_wide
? "%-21.21s" : "%-17.17s", rtype
);
1296 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1297 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1300 Elf_Internal_Sym
*psym
;
1302 psym
= symtab
+ symtab_index
;
1305 print_vma (psym
->st_value
, LONG_HEX
);
1306 printf (is_32bit_elf
? " " : " ");
1308 if (psym
->st_name
== 0)
1310 const char *sec_name
= "<null>";
1313 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1315 bfd_vma sec_index
= (bfd_vma
) -1;
1317 if (psym
->st_shndx
< SHN_LORESERVE
)
1318 sec_index
= psym
->st_shndx
;
1319 else if (psym
->st_shndx
> SHN_LORESERVE
)
1320 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1323 if (sec_index
!= (bfd_vma
) -1)
1324 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1325 else if (psym
->st_shndx
== SHN_ABS
)
1327 else if (psym
->st_shndx
== SHN_COMMON
)
1328 sec_name
= "COMMON";
1331 sprintf (name_buf
, "<section 0x%x>",
1332 (unsigned int) psym
->st_shndx
);
1333 sec_name
= name_buf
;
1336 print_symbol (22, sec_name
);
1338 else if (strtab
== NULL
)
1339 printf (_("<string table index %3ld>"), psym
->st_name
);
1341 print_symbol (22, strtab
+ psym
->st_name
);
1344 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1349 printf ("%*c", is_32bit_elf
? (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1350 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1353 if (elf_header
.e_machine
== EM_SPARCV9
1354 && !strcmp (rtype
, "R_SPARC_OLO10"))
1355 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1359 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1361 printf (" Type2: ");
1364 #ifdef _bfd_int64_low
1365 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1367 printf (_("unrecognized: %-7lx"), type2
);
1370 printf ("%-17.17s", rtype2
);
1372 printf("\n Type3: ");
1375 #ifdef _bfd_int64_low
1376 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1378 printf (_("unrecognized: %-7lx"), type3
);
1381 printf ("%-17.17s", rtype3
);
1393 get_mips_dynamic_type (type
)
1398 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1399 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1400 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1401 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1402 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1403 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1404 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1405 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1406 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1407 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1408 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1409 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1410 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1411 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1412 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1413 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1414 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1415 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1416 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1417 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1418 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1419 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1420 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1421 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1422 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1423 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1424 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1425 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1426 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1427 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1428 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1429 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1430 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1431 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1432 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1433 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1434 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1435 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1436 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1437 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1438 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1439 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1440 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1447 get_sparc64_dynamic_type (type
)
1452 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1459 get_ppc64_dynamic_type (type
)
1464 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1465 case DT_PPC64_OPD
: return "PPC64_OPD";
1466 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1473 get_parisc_dynamic_type (type
)
1478 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1479 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1480 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1481 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1482 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1483 case DT_HP_PREINIT
: return "HP_PREINIT";
1484 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1485 case DT_HP_NEEDED
: return "HP_NEEDED";
1486 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1487 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1488 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1489 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1490 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1497 get_ia64_dynamic_type (type
)
1502 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1509 get_dynamic_type (type
)
1512 static char buff
[32];
1516 case DT_NULL
: return "NULL";
1517 case DT_NEEDED
: return "NEEDED";
1518 case DT_PLTRELSZ
: return "PLTRELSZ";
1519 case DT_PLTGOT
: return "PLTGOT";
1520 case DT_HASH
: return "HASH";
1521 case DT_STRTAB
: return "STRTAB";
1522 case DT_SYMTAB
: return "SYMTAB";
1523 case DT_RELA
: return "RELA";
1524 case DT_RELASZ
: return "RELASZ";
1525 case DT_RELAENT
: return "RELAENT";
1526 case DT_STRSZ
: return "STRSZ";
1527 case DT_SYMENT
: return "SYMENT";
1528 case DT_INIT
: return "INIT";
1529 case DT_FINI
: return "FINI";
1530 case DT_SONAME
: return "SONAME";
1531 case DT_RPATH
: return "RPATH";
1532 case DT_SYMBOLIC
: return "SYMBOLIC";
1533 case DT_REL
: return "REL";
1534 case DT_RELSZ
: return "RELSZ";
1535 case DT_RELENT
: return "RELENT";
1536 case DT_PLTREL
: return "PLTREL";
1537 case DT_DEBUG
: return "DEBUG";
1538 case DT_TEXTREL
: return "TEXTREL";
1539 case DT_JMPREL
: return "JMPREL";
1540 case DT_BIND_NOW
: return "BIND_NOW";
1541 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1542 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1543 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1544 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1545 case DT_RUNPATH
: return "RUNPATH";
1546 case DT_FLAGS
: return "FLAGS";
1548 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1549 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1551 case DT_CHECKSUM
: return "CHECKSUM";
1552 case DT_PLTPADSZ
: return "PLTPADSZ";
1553 case DT_MOVEENT
: return "MOVEENT";
1554 case DT_MOVESZ
: return "MOVESZ";
1555 case DT_FEATURE
: return "FEATURE";
1556 case DT_POSFLAG_1
: return "POSFLAG_1";
1557 case DT_SYMINSZ
: return "SYMINSZ";
1558 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1560 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1561 case DT_CONFIG
: return "CONFIG";
1562 case DT_DEPAUDIT
: return "DEPAUDIT";
1563 case DT_AUDIT
: return "AUDIT";
1564 case DT_PLTPAD
: return "PLTPAD";
1565 case DT_MOVETAB
: return "MOVETAB";
1566 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1568 case DT_VERSYM
: return "VERSYM";
1570 case DT_RELACOUNT
: return "RELACOUNT";
1571 case DT_RELCOUNT
: return "RELCOUNT";
1572 case DT_FLAGS_1
: return "FLAGS_1";
1573 case DT_VERDEF
: return "VERDEF";
1574 case DT_VERDEFNUM
: return "VERDEFNUM";
1575 case DT_VERNEED
: return "VERNEED";
1576 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1578 case DT_AUXILIARY
: return "AUXILIARY";
1579 case DT_USED
: return "USED";
1580 case DT_FILTER
: return "FILTER";
1582 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1583 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1584 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1585 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1586 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1589 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1593 switch (elf_header
.e_machine
)
1596 case EM_MIPS_RS3_LE
:
1597 result
= get_mips_dynamic_type (type
);
1600 result
= get_sparc64_dynamic_type (type
);
1603 result
= get_ppc64_dynamic_type (type
);
1606 result
= get_ia64_dynamic_type (type
);
1616 sprintf (buff
, _("Processor Specific: %lx"), type
);
1618 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1622 switch (elf_header
.e_machine
)
1625 result
= get_parisc_dynamic_type (type
);
1635 sprintf (buff
, _("Operating System specific: %lx"), type
);
1638 sprintf (buff
, _("<unknown>: %lx"), type
);
1645 get_file_type (e_type
)
1648 static char buff
[32];
1652 case ET_NONE
: return _("NONE (None)");
1653 case ET_REL
: return _("REL (Relocatable file)");
1654 case ET_EXEC
: return _("EXEC (Executable file)");
1655 case ET_DYN
: return _("DYN (Shared object file)");
1656 case ET_CORE
: return _("CORE (Core file)");
1659 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1660 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
1661 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1662 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
1664 sprintf (buff
, _("<unknown>: %x"), e_type
);
1670 get_machine_name (e_machine
)
1673 static char buff
[64]; /* XXX */
1677 case EM_NONE
: return _("None");
1678 case EM_M32
: return "WE32100";
1679 case EM_SPARC
: return "Sparc";
1680 case EM_386
: return "Intel 80386";
1681 case EM_68K
: return "MC68000";
1682 case EM_88K
: return "MC88000";
1683 case EM_486
: return "Intel 80486";
1684 case EM_860
: return "Intel 80860";
1685 case EM_MIPS
: return "MIPS R3000";
1686 case EM_S370
: return "IBM System/370";
1687 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1688 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1689 case EM_PARISC
: return "HPPA";
1690 case EM_PPC_OLD
: return "Power PC (old)";
1691 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1692 case EM_960
: return "Intel 90860";
1693 case EM_PPC
: return "PowerPC";
1694 case EM_PPC64
: return "PowerPC64";
1695 case EM_V800
: return "NEC V800";
1696 case EM_FR20
: return "Fujitsu FR20";
1697 case EM_RH32
: return "TRW RH32";
1698 case EM_MCORE
: return "MCORE";
1699 case EM_ARM
: return "ARM";
1700 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1701 case EM_SH
: return "Hitachi SH";
1702 case EM_SPARCV9
: return "Sparc v9";
1703 case EM_TRICORE
: return "Siemens Tricore";
1704 case EM_ARC
: return "ARC";
1705 case EM_H8_300
: return "Hitachi H8/300";
1706 case EM_H8_300H
: return "Hitachi H8/300H";
1707 case EM_H8S
: return "Hitachi H8S";
1708 case EM_H8_500
: return "Hitachi H8/500";
1709 case EM_IA_64
: return "Intel IA-64";
1710 case EM_MIPS_X
: return "Stanford MIPS-X";
1711 case EM_COLDFIRE
: return "Motorola Coldfire";
1712 case EM_68HC12
: return "Motorola M68HC12";
1713 case EM_ALPHA
: return "Alpha";
1714 case EM_CYGNUS_D10V
:
1715 case EM_D10V
: return "d10v";
1716 case EM_CYGNUS_D30V
:
1717 case EM_D30V
: return "d30v";
1718 case EM_CYGNUS_M32R
:
1719 case EM_M32R
: return "Mitsubishi M32r";
1720 case EM_CYGNUS_V850
:
1721 case EM_V850
: return "NEC v850";
1722 case EM_CYGNUS_MN10300
:
1723 case EM_MN10300
: return "mn10300";
1724 case EM_CYGNUS_MN10200
:
1725 case EM_MN10200
: return "mn10200";
1726 case EM_CYGNUS_FR30
:
1727 case EM_FR30
: return "Fujitsu FR30";
1728 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1730 case EM_PJ
: return "picoJava";
1731 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1732 case EM_PCP
: return "Siemens PCP";
1733 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1734 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1735 case EM_STARCORE
: return "Motorola Star*Core processor";
1736 case EM_ME16
: return "Toyota ME16 processor";
1737 case EM_ST100
: return "STMicroelectronics ST100 processor";
1738 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1739 case EM_FX66
: return "Siemens FX66 microcontroller";
1740 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1741 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1742 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1743 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1744 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1745 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1746 case EM_SVX
: return "Silicon Graphics SVx";
1747 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1748 case EM_VAX
: return "Digital VAX";
1750 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1751 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1752 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1753 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1754 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1755 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1756 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1757 case EM_PRISM
: return "Vitesse Prism";
1758 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1760 case EM_S390
: return "IBM S/390";
1761 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1763 case EM_OR32
: return "OpenRISC";
1764 case EM_DLX
: return "OpenDLX";
1766 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1767 case EM_IQ2000
: return "Vitesse IQ2000";
1769 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1771 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1777 decode_ARM_machine_flags (e_flags
, buf
)
1784 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1785 e_flags
&= ~ EF_ARM_EABIMASK
;
1787 /* Handle "generic" ARM flags. */
1788 if (e_flags
& EF_ARM_RELEXEC
)
1790 strcat (buf
, ", relocatable executable");
1791 e_flags
&= ~ EF_ARM_RELEXEC
;
1794 if (e_flags
& EF_ARM_HASENTRY
)
1796 strcat (buf
, ", has entry point");
1797 e_flags
&= ~ EF_ARM_HASENTRY
;
1800 /* Now handle EABI specific flags. */
1804 strcat (buf
, ", <unrecognized EABI>");
1809 case EF_ARM_EABI_VER1
:
1810 strcat (buf
, ", Version1 EABI");
1815 /* Process flags one bit at a time. */
1816 flag
= e_flags
& - e_flags
;
1821 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1822 strcat (buf
, ", sorted symbol tables");
1832 case EF_ARM_EABI_VER2
:
1833 strcat (buf
, ", Version2 EABI");
1838 /* Process flags one bit at a time. */
1839 flag
= e_flags
& - e_flags
;
1844 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1845 strcat (buf
, ", sorted symbol tables");
1848 case EF_ARM_DYNSYMSUSESEGIDX
:
1849 strcat (buf
, ", dynamic symbols use segment index");
1852 case EF_ARM_MAPSYMSFIRST
:
1853 strcat (buf
, ", mapping symbols precede others");
1863 case EF_ARM_EABI_UNKNOWN
:
1864 strcat (buf
, ", GNU EABI");
1869 /* Process flags one bit at a time. */
1870 flag
= e_flags
& - e_flags
;
1875 case EF_ARM_INTERWORK
:
1876 strcat (buf
, ", interworking enabled");
1879 case EF_ARM_APCS_26
:
1880 strcat (buf
, ", uses APCS/26");
1883 case EF_ARM_APCS_FLOAT
:
1884 strcat (buf
, ", uses APCS/float");
1888 strcat (buf
, ", position independent");
1892 strcat (buf
, ", 8 bit structure alignment");
1895 case EF_ARM_NEW_ABI
:
1896 strcat (buf
, ", uses new ABI");
1899 case EF_ARM_OLD_ABI
:
1900 strcat (buf
, ", uses old ABI");
1903 case EF_ARM_SOFT_FLOAT
:
1904 strcat (buf
, ", software FP");
1907 case EF_ARM_MAVERICK_FLOAT
:
1908 strcat (buf
, ", Maverick FP");
1919 strcat (buf
,", <unknown>");
1923 get_machine_flags (e_flags
, e_machine
)
1927 static char buf
[1024];
1939 decode_ARM_machine_flags (e_flags
, buf
);
1943 if (e_flags
& EF_CPU32
)
1944 strcat (buf
, ", cpu32");
1945 if (e_flags
& EF_M68000
)
1946 strcat (buf
, ", m68000");
1950 if (e_flags
& EF_PPC_EMB
)
1951 strcat (buf
, ", emb");
1953 if (e_flags
& EF_PPC_RELOCATABLE
)
1954 strcat (buf
, ", relocatable");
1956 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1957 strcat (buf
, ", relocatable-lib");
1961 case EM_CYGNUS_V850
:
1962 switch (e_flags
& EF_V850_ARCH
)
1965 strcat (buf
, ", v850e");
1968 strcat (buf
, ", v850");
1971 strcat (buf
, ", unknown v850 architecture variant");
1977 case EM_CYGNUS_M32R
:
1978 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1979 strcat (buf
, ", m32r");
1984 case EM_MIPS_RS3_LE
:
1985 if (e_flags
& EF_MIPS_NOREORDER
)
1986 strcat (buf
, ", noreorder");
1988 if (e_flags
& EF_MIPS_PIC
)
1989 strcat (buf
, ", pic");
1991 if (e_flags
& EF_MIPS_CPIC
)
1992 strcat (buf
, ", cpic");
1994 if (e_flags
& EF_MIPS_UCODE
)
1995 strcat (buf
, ", ugen_reserved");
1997 if (e_flags
& EF_MIPS_ABI2
)
1998 strcat (buf
, ", abi2");
2000 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2001 strcat (buf
, ", odk first");
2003 if (e_flags
& EF_MIPS_32BITMODE
)
2004 strcat (buf
, ", 32bitmode");
2006 switch ((e_flags
& EF_MIPS_MACH
))
2008 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2009 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2010 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2011 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2012 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2013 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2014 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2015 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2016 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2018 /* We simply ignore the field in this case to avoid confusion:
2019 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2022 default: strcat (buf
, ", unknown CPU"); break;
2025 switch ((e_flags
& EF_MIPS_ABI
))
2027 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2028 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2029 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2030 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2032 /* We simply ignore the field in this case to avoid confusion:
2033 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2034 This means it is likely to be an o32 file, but not for
2037 default: strcat (buf
, ", unknown ABI"); break;
2040 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2041 strcat (buf
, ", mdmx");
2043 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2044 strcat (buf
, ", mips16");
2046 switch ((e_flags
& EF_MIPS_ARCH
))
2048 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2049 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2050 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2051 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2052 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2053 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2054 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2055 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2056 default: strcat (buf
, ", unknown ISA"); break;
2062 if (e_flags
& EF_SPARC_32PLUS
)
2063 strcat (buf
, ", v8+");
2065 if (e_flags
& EF_SPARC_SUN_US1
)
2066 strcat (buf
, ", ultrasparcI");
2068 if (e_flags
& EF_SPARC_SUN_US3
)
2069 strcat (buf
, ", ultrasparcIII");
2071 if (e_flags
& EF_SPARC_HAL_R1
)
2072 strcat (buf
, ", halr1");
2074 if (e_flags
& EF_SPARC_LEDATA
)
2075 strcat (buf
, ", ledata");
2077 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2078 strcat (buf
, ", tso");
2080 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2081 strcat (buf
, ", pso");
2083 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2084 strcat (buf
, ", rmo");
2088 switch (e_flags
& EF_PARISC_ARCH
)
2090 case EFA_PARISC_1_0
:
2091 strcpy (buf
, ", PA-RISC 1.0");
2093 case EFA_PARISC_1_1
:
2094 strcpy (buf
, ", PA-RISC 1.1");
2096 case EFA_PARISC_2_0
:
2097 strcpy (buf
, ", PA-RISC 2.0");
2102 if (e_flags
& EF_PARISC_TRAPNIL
)
2103 strcat (buf
, ", trapnil");
2104 if (e_flags
& EF_PARISC_EXT
)
2105 strcat (buf
, ", ext");
2106 if (e_flags
& EF_PARISC_LSB
)
2107 strcat (buf
, ", lsb");
2108 if (e_flags
& EF_PARISC_WIDE
)
2109 strcat (buf
, ", wide");
2110 if (e_flags
& EF_PARISC_NO_KABP
)
2111 strcat (buf
, ", no kabp");
2112 if (e_flags
& EF_PARISC_LAZYSWAP
)
2113 strcat (buf
, ", lazyswap");
2118 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2119 strcat (buf
, ", new calling convention");
2121 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2122 strcat (buf
, ", gnu calling convention");
2126 if ((e_flags
& EF_IA_64_ABI64
))
2127 strcat (buf
, ", 64-bit");
2129 strcat (buf
, ", 32-bit");
2130 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2131 strcat (buf
, ", reduced fp model");
2132 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2133 strcat (buf
, ", no function descriptors, constant gp");
2134 else if ((e_flags
& EF_IA_64_CONS_GP
))
2135 strcat (buf
, ", constant gp");
2136 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2137 strcat (buf
, ", absolute");
2141 if ((e_flags
& EF_VAX_NONPIC
))
2142 strcat (buf
, ", non-PIC");
2143 if ((e_flags
& EF_VAX_DFLOAT
))
2144 strcat (buf
, ", D-Float");
2145 if ((e_flags
& EF_VAX_GFLOAT
))
2146 strcat (buf
, ", G-Float");
2155 get_mips_segment_type (type
)
2160 case PT_MIPS_REGINFO
:
2162 case PT_MIPS_RTPROC
:
2164 case PT_MIPS_OPTIONS
:
2174 get_parisc_segment_type (type
)
2179 case PT_HP_TLS
: return "HP_TLS";
2180 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2181 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2182 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2183 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2184 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2185 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2186 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2187 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2188 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2189 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2190 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2191 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2192 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2201 get_ia64_segment_type (type
)
2206 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2207 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2208 case PT_HP_TLS
: return "HP_TLS";
2209 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2210 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2211 case PT_IA_64_HP_STACK
: return "HP_STACK";
2220 get_segment_type (p_type
)
2221 unsigned long p_type
;
2223 static char buff
[32];
2227 case PT_NULL
: return "NULL";
2228 case PT_LOAD
: return "LOAD";
2229 case PT_DYNAMIC
: return "DYNAMIC";
2230 case PT_INTERP
: return "INTERP";
2231 case PT_NOTE
: return "NOTE";
2232 case PT_SHLIB
: return "SHLIB";
2233 case PT_PHDR
: return "PHDR";
2234 case PT_TLS
: return "TLS";
2236 case PT_GNU_EH_FRAME
:
2237 return "GNU_EH_FRAME";
2240 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2244 switch (elf_header
.e_machine
)
2247 case EM_MIPS_RS3_LE
:
2248 result
= get_mips_segment_type (p_type
);
2251 result
= get_parisc_segment_type (p_type
);
2254 result
= get_ia64_segment_type (p_type
);
2264 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2266 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2270 switch (elf_header
.e_machine
)
2273 result
= get_parisc_segment_type (p_type
);
2276 result
= get_ia64_segment_type (p_type
);
2286 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2289 sprintf (buff
, _("<unknown>: %lx"), p_type
);
2296 get_mips_section_type_name (sh_type
)
2297 unsigned int sh_type
;
2301 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2302 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2303 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2304 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2305 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2306 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2307 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2308 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2309 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2310 case SHT_MIPS_RELD
: return "MIPS_RELD";
2311 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2312 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2313 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2314 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2315 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2316 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2317 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2318 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2319 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2320 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2321 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2322 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2323 case SHT_MIPS_LINE
: return "MIPS_LINE";
2324 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2325 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2326 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2327 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2328 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2329 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2330 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2331 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2332 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2333 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2334 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2335 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2336 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2337 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2338 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2339 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2347 get_parisc_section_type_name (sh_type
)
2348 unsigned int sh_type
;
2352 case SHT_PARISC_EXT
: return "PARISC_EXT";
2353 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2354 case SHT_PARISC_DOC
: return "PARISC_DOC";
2362 get_ia64_section_type_name (sh_type
)
2363 unsigned int sh_type
;
2365 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2366 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2367 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2371 case SHT_IA_64_EXT
: return "IA_64_EXT";
2372 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2373 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2381 get_section_type_name (sh_type
)
2382 unsigned int sh_type
;
2384 static char buff
[32];
2388 case SHT_NULL
: return "NULL";
2389 case SHT_PROGBITS
: return "PROGBITS";
2390 case SHT_SYMTAB
: return "SYMTAB";
2391 case SHT_STRTAB
: return "STRTAB";
2392 case SHT_RELA
: return "RELA";
2393 case SHT_HASH
: return "HASH";
2394 case SHT_DYNAMIC
: return "DYNAMIC";
2395 case SHT_NOTE
: return "NOTE";
2396 case SHT_NOBITS
: return "NOBITS";
2397 case SHT_REL
: return "REL";
2398 case SHT_SHLIB
: return "SHLIB";
2399 case SHT_DYNSYM
: return "DYNSYM";
2400 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2401 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2402 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2403 case SHT_GROUP
: return "GROUP";
2404 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2405 case SHT_GNU_verdef
: return "VERDEF";
2406 case SHT_GNU_verneed
: return "VERNEED";
2407 case SHT_GNU_versym
: return "VERSYM";
2408 case 0x6ffffff0: return "VERSYM";
2409 case 0x6ffffffc: return "VERDEF";
2410 case 0x7ffffffd: return "AUXILIARY";
2411 case 0x7fffffff: return "FILTER";
2412 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2415 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2419 switch (elf_header
.e_machine
)
2422 case EM_MIPS_RS3_LE
:
2423 result
= get_mips_section_type_name (sh_type
);
2426 result
= get_parisc_section_type_name (sh_type
);
2429 result
= get_ia64_section_type_name (sh_type
);
2439 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2441 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2442 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2443 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2444 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2446 sprintf (buff
, _("<unknown>: %x"), sh_type
);
2452 #define OPTION_DEBUG_DUMP 512
2454 struct option options
[] =
2456 {"all", no_argument
, 0, 'a'},
2457 {"file-header", no_argument
, 0, 'h'},
2458 {"program-headers", no_argument
, 0, 'l'},
2459 {"headers", no_argument
, 0, 'e'},
2460 {"histogram", no_argument
, 0, 'I'},
2461 {"segments", no_argument
, 0, 'l'},
2462 {"sections", no_argument
, 0, 'S'},
2463 {"section-headers", no_argument
, 0, 'S'},
2464 {"symbols", no_argument
, 0, 's'},
2465 {"syms", no_argument
, 0, 's'},
2466 {"relocs", no_argument
, 0, 'r'},
2467 {"notes", no_argument
, 0, 'n'},
2468 {"dynamic", no_argument
, 0, 'd'},
2469 {"arch-specific", no_argument
, 0, 'A'},
2470 {"version-info", no_argument
, 0, 'V'},
2471 {"use-dynamic", no_argument
, 0, 'D'},
2472 {"hex-dump", required_argument
, 0, 'x'},
2473 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2474 {"unwind", no_argument
, 0, 'u'},
2475 #ifdef SUPPORT_DISASSEMBLY
2476 {"instruction-dump", required_argument
, 0, 'i'},
2479 {"version", no_argument
, 0, 'v'},
2480 {"wide", no_argument
, 0, 'W'},
2481 {"help", no_argument
, 0, 'H'},
2482 {0, no_argument
, 0, 0}
2488 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2489 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2490 fprintf (stdout
, _(" Options are:\n\
2491 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2492 -h --file-header Display the ELF file header\n\
2493 -l --program-headers Display the program headers\n\
2494 --segments An alias for --program-headers\n\
2495 -S --section-headers Display the sections' header\n\
2496 --sections An alias for --section-headers\n\
2497 -e --headers Equivalent to: -h -l -S\n\
2498 -s --syms Display the symbol table\n\
2499 --symbols An alias for --syms\n\
2500 -n --notes Display the core notes (if present)\n\
2501 -r --relocs Display the relocations (if present)\n\
2502 -u --unwind Display the unwind info (if present)\n\
2503 -d --dynamic Display the dynamic segment (if present)\n\
2504 -V --version-info Display the version sections (if present)\n\
2505 -A --arch-specific Display architecture specific information (if any).\n\
2506 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2507 -x --hex-dump=<number> Dump the contents of section <number>\n\
2508 -w[liaprmfFso] or\n\
2509 --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
2510 Display the contents of DWARF2 debug sections\n"));
2511 #ifdef SUPPORT_DISASSEMBLY
2512 fprintf (stdout
, _("\
2513 -i --instruction-dump=<number>\n\
2514 Disassemble the contents of section <number>\n"));
2516 fprintf (stdout
, _("\
2517 -I --histogram Display histogram of bucket list lengths\n\
2518 -W --wide Allow output width to exceed 80 characters\n\
2519 -H --help Display this information\n\
2520 -v --version Display the version number of readelf\n"));
2521 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2527 request_dump (section
, type
)
2528 unsigned int section
;
2531 if (section
>= num_dump_sects
)
2533 char *new_dump_sects
;
2535 new_dump_sects
= (char *) calloc (section
+ 1, 1);
2537 if (new_dump_sects
== NULL
)
2538 error (_("Out of memory allocating dump request table."));
2541 /* Copy current flag settings. */
2542 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2546 dump_sects
= new_dump_sects
;
2547 num_dump_sects
= section
+ 1;
2552 dump_sects
[section
] |= type
;
2558 parse_args (argc
, argv
)
2567 while ((c
= getopt_long
2568 (argc
, argv
, "ersuahnldSDAIw::x:i:vVWH", options
, NULL
)) != EOF
)
2635 section
= strtoul (optarg
, & cp
, 0);
2636 if (! *cp
&& section
>= 0)
2638 request_dump (section
, HEX_DUMP
);
2648 unsigned int index
= 0;
2652 while (optarg
[index
])
2653 switch (optarg
[index
++])
2662 do_debug_abbrevs
= 1;
2672 do_debug_pubnames
= 1;
2677 do_debug_aranges
= 1;
2681 do_debug_frames_interp
= 1;
2683 do_debug_frames
= 1;
2688 do_debug_macinfo
= 1;
2702 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2707 case OPTION_DEBUG_DUMP
:
2713 static const char *debug_dump_opt
[]
2714 = { "line", "info", "abbrev", "pubnames", "ranges",
2715 "macro", "frames", "frames-interp", "str", "loc", NULL
};
2724 for (index
= 0; debug_dump_opt
[index
]; index
++)
2726 size_t len
= strlen (debug_dump_opt
[index
]);
2728 if (strncmp (p
, debug_dump_opt
[index
], len
) == 0
2729 && (p
[len
] == ',' || p
[len
] == '\0'))
2738 do_debug_abbrevs
= 1;
2749 do_debug_pubnames
= 1;
2753 do_debug_aranges
= 1;
2758 do_debug_frames_interp
= 1;
2759 do_debug_frames
= 1;
2763 do_debug_macinfo
= 1;
2776 if (debug_dump_opt
[index
] == NULL
)
2778 warn (_("Unrecognized debug option '%s'\n"), p
);
2779 p
= strchr (p
, ',');
2789 #ifdef SUPPORT_DISASSEMBLY
2792 section
= strtoul (optarg
, & cp
, 0);
2793 if (! *cp
&& section
>= 0)
2795 request_dump (section
, DISASS_DUMP
);
2801 print_version (program_name
);
2811 /* xgettext:c-format */
2812 error (_("Invalid option '-%c'\n"), c
);
2819 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2820 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2821 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
)
2825 warn (_("Nothing to do.\n"));
2831 get_elf_class (elf_class
)
2832 unsigned int elf_class
;
2834 static char buff
[32];
2838 case ELFCLASSNONE
: return _("none");
2839 case ELFCLASS32
: return "ELF32";
2840 case ELFCLASS64
: return "ELF64";
2842 sprintf (buff
, _("<unknown: %x>"), elf_class
);
2848 get_data_encoding (encoding
)
2849 unsigned int encoding
;
2851 static char buff
[32];
2855 case ELFDATANONE
: return _("none");
2856 case ELFDATA2LSB
: return _("2's complement, little endian");
2857 case ELFDATA2MSB
: return _("2's complement, big endian");
2859 sprintf (buff
, _("<unknown: %x>"), encoding
);
2865 get_osabi_name (osabi
)
2868 static char buff
[32];
2872 case ELFOSABI_NONE
: return "UNIX - System V";
2873 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2874 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2875 case ELFOSABI_LINUX
: return "UNIX - Linux";
2876 case ELFOSABI_HURD
: return "GNU/Hurd";
2877 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2878 case ELFOSABI_AIX
: return "UNIX - AIX";
2879 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2880 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2881 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2882 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2883 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2884 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2885 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2886 case ELFOSABI_AROS
: return "Amiga Research OS";
2887 case ELFOSABI_STANDALONE
: return _("Standalone App");
2888 case ELFOSABI_ARM
: return "ARM";
2890 sprintf (buff
, _("<unknown: %x>"), osabi
);
2895 /* Decode the data held in 'elf_header'. */
2898 process_file_header ()
2900 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2901 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2902 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2903 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2906 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2914 printf (_("ELF Header:\n"));
2915 printf (_(" Magic: "));
2916 for (i
= 0; i
< EI_NIDENT
; i
++)
2917 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2919 printf (_(" Class: %s\n"),
2920 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2921 printf (_(" Data: %s\n"),
2922 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2923 printf (_(" Version: %d %s\n"),
2924 elf_header
.e_ident
[EI_VERSION
],
2925 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
2927 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
2930 printf (_(" OS/ABI: %s\n"),
2931 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
2932 printf (_(" ABI Version: %d\n"),
2933 elf_header
.e_ident
[EI_ABIVERSION
]);
2934 printf (_(" Type: %s\n"),
2935 get_file_type (elf_header
.e_type
));
2936 printf (_(" Machine: %s\n"),
2937 get_machine_name (elf_header
.e_machine
));
2938 printf (_(" Version: 0x%lx\n"),
2939 (unsigned long) elf_header
.e_version
);
2941 printf (_(" Entry point address: "));
2942 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2943 printf (_("\n Start of program headers: "));
2944 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2945 printf (_(" (bytes into file)\n Start of section headers: "));
2946 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
2947 printf (_(" (bytes into file)\n"));
2949 printf (_(" Flags: 0x%lx%s\n"),
2950 (unsigned long) elf_header
.e_flags
,
2951 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
2952 printf (_(" Size of this header: %ld (bytes)\n"),
2953 (long) elf_header
.e_ehsize
);
2954 printf (_(" Size of program headers: %ld (bytes)\n"),
2955 (long) elf_header
.e_phentsize
);
2956 printf (_(" Number of program headers: %ld\n"),
2957 (long) elf_header
.e_phnum
);
2958 printf (_(" Size of section headers: %ld (bytes)\n"),
2959 (long) elf_header
.e_shentsize
);
2960 printf (_(" Number of section headers: %ld"),
2961 (long) elf_header
.e_shnum
);
2962 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
2963 printf (" (%ld)", (long) section_headers
[0].sh_size
);
2964 putc ('\n', stdout
);
2965 printf (_(" Section header string table index: %ld"),
2966 (long) elf_header
.e_shstrndx
);
2967 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
2968 printf (" (%ld)", (long) section_headers
[0].sh_link
);
2969 putc ('\n', stdout
);
2972 if (section_headers
!= NULL
)
2974 if (elf_header
.e_shnum
== 0)
2975 elf_header
.e_shnum
= section_headers
[0].sh_size
;
2976 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
2977 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
2978 free (section_headers
);
2979 section_headers
= NULL
;
2987 get_32bit_program_headers (file
, program_headers
)
2989 Elf_Internal_Phdr
*program_headers
;
2991 Elf32_External_Phdr
*phdrs
;
2992 Elf32_External_Phdr
*external
;
2993 Elf_Internal_Phdr
*internal
;
2996 phdrs
= ((Elf32_External_Phdr
*)
2997 get_data (NULL
, file
, elf_header
.e_phoff
,
2998 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2999 _("program headers")));
3003 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3004 i
< elf_header
.e_phnum
;
3005 i
++, internal
++, external
++)
3007 internal
->p_type
= BYTE_GET (external
->p_type
);
3008 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3009 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3010 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3011 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3012 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3013 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3014 internal
->p_align
= BYTE_GET (external
->p_align
);
3023 get_64bit_program_headers (file
, program_headers
)
3025 Elf_Internal_Phdr
*program_headers
;
3027 Elf64_External_Phdr
*phdrs
;
3028 Elf64_External_Phdr
*external
;
3029 Elf_Internal_Phdr
*internal
;
3032 phdrs
= ((Elf64_External_Phdr
*)
3033 get_data (NULL
, file
, elf_header
.e_phoff
,
3034 elf_header
.e_phentsize
* elf_header
.e_phnum
,
3035 _("program headers")));
3039 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3040 i
< elf_header
.e_phnum
;
3041 i
++, internal
++, external
++)
3043 internal
->p_type
= BYTE_GET (external
->p_type
);
3044 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3045 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
3046 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
3047 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
3048 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
3049 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
3050 internal
->p_align
= BYTE_GET8 (external
->p_align
);
3058 /* Returns 1 if the program headers were loaded. */
3061 process_program_headers (file
)
3064 Elf_Internal_Phdr
*program_headers
;
3065 Elf_Internal_Phdr
*segment
;
3068 if (elf_header
.e_phnum
== 0)
3071 printf (_("\nThere are no program headers in this file.\n"));
3075 if (do_segments
&& !do_header
)
3077 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3078 printf (_("Entry point "));
3079 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3080 printf (_("\nThere are %d program headers, starting at offset "),
3081 elf_header
.e_phnum
);
3082 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3086 program_headers
= (Elf_Internal_Phdr
*) malloc
3087 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
3089 if (program_headers
== NULL
)
3091 error (_("Out of memory\n"));
3096 i
= get_32bit_program_headers (file
, program_headers
);
3098 i
= get_64bit_program_headers (file
, program_headers
);
3102 free (program_headers
);
3108 if (elf_header
.e_phnum
> 1)
3109 printf (_("\nProgram Headers:\n"));
3111 printf (_("\nProgram Headers:\n"));
3115 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3118 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3122 (_(" Type Offset VirtAddr PhysAddr\n"));
3124 (_(" FileSiz MemSiz Flags Align\n"));
3132 for (i
= 0, segment
= program_headers
;
3133 i
< elf_header
.e_phnum
;
3138 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3142 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3143 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3144 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3145 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3146 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3148 (segment
->p_flags
& PF_R
? 'R' : ' '),
3149 (segment
->p_flags
& PF_W
? 'W' : ' '),
3150 (segment
->p_flags
& PF_X
? 'E' : ' '));
3151 printf ("%#lx", (unsigned long) segment
->p_align
);
3155 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3156 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3159 print_vma (segment
->p_offset
, FULL_HEX
);
3163 print_vma (segment
->p_vaddr
, FULL_HEX
);
3165 print_vma (segment
->p_paddr
, FULL_HEX
);
3168 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3169 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3172 print_vma (segment
->p_filesz
, FULL_HEX
);
3176 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3177 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3180 print_vma (segment
->p_offset
, FULL_HEX
);
3184 (segment
->p_flags
& PF_R
? 'R' : ' '),
3185 (segment
->p_flags
& PF_W
? 'W' : ' '),
3186 (segment
->p_flags
& PF_X
? 'E' : ' '));
3188 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3189 printf ("%#lx", (unsigned long) segment
->p_align
);
3192 print_vma (segment
->p_align
, PREFIX_HEX
);
3197 print_vma (segment
->p_offset
, FULL_HEX
);
3199 print_vma (segment
->p_vaddr
, FULL_HEX
);
3201 print_vma (segment
->p_paddr
, FULL_HEX
);
3203 print_vma (segment
->p_filesz
, FULL_HEX
);
3205 print_vma (segment
->p_memsz
, FULL_HEX
);
3207 (segment
->p_flags
& PF_R
? 'R' : ' '),
3208 (segment
->p_flags
& PF_W
? 'W' : ' '),
3209 (segment
->p_flags
& PF_X
? 'E' : ' '));
3210 print_vma (segment
->p_align
, HEX
);
3214 switch (segment
->p_type
)
3219 unsigned long align_mask
= -segment
->p_align
;
3221 if (align_mask
== 0)
3223 loadaddr
= ((segment
->p_vaddr
& align_mask
)
3224 - (segment
->p_offset
& align_mask
));
3230 error (_("more than one dynamic segment\n"));
3232 dynamic_addr
= segment
->p_offset
;
3233 dynamic_size
= segment
->p_filesz
;
3237 if (fseek (file
, (long) segment
->p_offset
, SEEK_SET
))
3238 error (_("Unable to find program interpreter name\n"));
3241 program_interpreter
[0] = 0;
3242 fscanf (file
, "%63s", program_interpreter
);
3245 printf (_("\n [Requesting program interpreter: %s]"),
3246 program_interpreter
);
3252 putc ('\n', stdout
);
3261 if (do_segments
&& section_headers
!= NULL
)
3263 printf (_("\n Section to Segment mapping:\n"));
3264 printf (_(" Segment Sections...\n"));
3266 assert (string_table
!= NULL
);
3268 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3271 Elf_Internal_Shdr
*section
;
3273 segment
= program_headers
+ i
;
3274 section
= section_headers
;
3276 printf (" %2.2d ", i
);
3278 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3280 if (section
->sh_size
> 0
3281 /* Compare allocated sections by VMA, unallocated
3282 sections by file offset. */
3283 && (section
->sh_flags
& SHF_ALLOC
3284 ? (section
->sh_addr
>= segment
->p_vaddr
3285 && section
->sh_addr
+ section
->sh_size
3286 <= segment
->p_vaddr
+ segment
->p_memsz
)
3287 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3288 && (section
->sh_offset
+ section
->sh_size
3289 <= segment
->p_offset
+ segment
->p_filesz
))))
3290 printf ("%s ", SECTION_NAME (section
));
3297 free (program_headers
);
3304 get_32bit_section_headers (file
, num
)
3308 Elf32_External_Shdr
*shdrs
;
3309 Elf_Internal_Shdr
*internal
;
3312 shdrs
= ((Elf32_External_Shdr
*)
3313 get_data (NULL
, file
, elf_header
.e_shoff
,
3314 elf_header
.e_shentsize
* num
,
3315 _("section headers")));
3319 section_headers
= ((Elf_Internal_Shdr
*)
3320 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3322 if (section_headers
== NULL
)
3324 error (_("Out of memory\n"));
3328 for (i
= 0, internal
= section_headers
;
3332 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3333 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3334 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3335 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3336 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3337 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3338 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3339 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3340 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3341 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3350 get_64bit_section_headers (file
, num
)
3354 Elf64_External_Shdr
*shdrs
;
3355 Elf_Internal_Shdr
*internal
;
3358 shdrs
= ((Elf64_External_Shdr
*)
3359 get_data (NULL
, file
, elf_header
.e_shoff
,
3360 elf_header
.e_shentsize
* num
,
3361 _("section headers")));
3365 section_headers
= ((Elf_Internal_Shdr
*)
3366 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3368 if (section_headers
== NULL
)
3370 error (_("Out of memory\n"));
3374 for (i
= 0, internal
= section_headers
;
3378 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3379 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3380 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
3381 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
3382 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
3383 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
3384 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3385 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3386 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3387 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3395 static Elf_Internal_Sym
*
3396 get_32bit_elf_symbols (file
, section
)
3398 Elf_Internal_Shdr
*section
;
3400 unsigned long number
;
3401 Elf32_External_Sym
*esyms
;
3402 Elf_External_Sym_Shndx
*shndx
;
3403 Elf_Internal_Sym
*isyms
;
3404 Elf_Internal_Sym
*psym
;
3407 esyms
= ((Elf32_External_Sym
*)
3408 get_data (NULL
, file
, section
->sh_offset
,
3409 section
->sh_size
, _("symbols")));
3414 if (symtab_shndx_hdr
!= NULL
3415 && (symtab_shndx_hdr
->sh_link
3416 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3418 shndx
= ((Elf_External_Sym_Shndx
*)
3419 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3420 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3428 number
= section
->sh_size
/ section
->sh_entsize
;
3429 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3433 error (_("Out of memory\n"));
3440 for (j
= 0, psym
= isyms
;
3444 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3445 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3446 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3447 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3448 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3450 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3451 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3452 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3462 static Elf_Internal_Sym
*
3463 get_64bit_elf_symbols (file
, section
)
3465 Elf_Internal_Shdr
*section
;
3467 unsigned long number
;
3468 Elf64_External_Sym
*esyms
;
3469 Elf_External_Sym_Shndx
*shndx
;
3470 Elf_Internal_Sym
*isyms
;
3471 Elf_Internal_Sym
*psym
;
3474 esyms
= ((Elf64_External_Sym
*)
3475 get_data (NULL
, file
, section
->sh_offset
,
3476 section
->sh_size
, _("symbols")));
3481 if (symtab_shndx_hdr
!= NULL
3482 && (symtab_shndx_hdr
->sh_link
3483 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3485 shndx
= ((Elf_External_Sym_Shndx
*)
3486 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3487 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3495 number
= section
->sh_size
/ section
->sh_entsize
;
3496 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3500 error (_("Out of memory\n"));
3507 for (j
= 0, psym
= isyms
;
3511 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3512 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3513 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3514 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3515 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3517 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3518 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
3519 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
3530 get_elf_section_flags (sh_flags
)
3533 static char buff
[32];
3541 flag
= sh_flags
& - sh_flags
;
3546 case SHF_WRITE
: strcat (buff
, "W"); break;
3547 case SHF_ALLOC
: strcat (buff
, "A"); break;
3548 case SHF_EXECINSTR
: strcat (buff
, "X"); break;
3549 case SHF_MERGE
: strcat (buff
, "M"); break;
3550 case SHF_STRINGS
: strcat (buff
, "S"); break;
3551 case SHF_INFO_LINK
: strcat (buff
, "I"); break;
3552 case SHF_LINK_ORDER
: strcat (buff
, "L"); break;
3553 case SHF_OS_NONCONFORMING
: strcat (buff
, "O"); break;
3554 case SHF_GROUP
: strcat (buff
, "G"); break;
3555 case SHF_TLS
: strcat (buff
, "T"); break;
3558 if (flag
& SHF_MASKOS
)
3561 sh_flags
&= ~ SHF_MASKOS
;
3563 else if (flag
& SHF_MASKPROC
)
3566 sh_flags
&= ~ SHF_MASKPROC
;
3578 process_section_headers (file
)
3581 Elf_Internal_Shdr
*section
;
3584 section_headers
= NULL
;
3586 if (elf_header
.e_shnum
== 0)
3589 printf (_("\nThere are no sections in this file.\n"));
3594 if (do_sections
&& !do_header
)
3595 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3596 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3600 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3603 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3606 /* Read in the string table, so that we have names to display. */
3607 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3609 if (section
->sh_size
!= 0)
3611 string_table
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3612 section
->sh_size
, _("string table"));
3614 string_table_length
= section
->sh_size
;
3617 /* Scan the sections for the dynamic symbol table
3618 and dynamic string table and debug sections. */
3619 dynamic_symbols
= NULL
;
3620 dynamic_strings
= NULL
;
3621 dynamic_syminfo
= NULL
;
3622 symtab_shndx_hdr
= NULL
;
3624 for (i
= 0, section
= section_headers
;
3625 i
< elf_header
.e_shnum
;
3628 char *name
= SECTION_NAME (section
);
3630 if (section
->sh_type
== SHT_DYNSYM
)
3632 if (dynamic_symbols
!= NULL
)
3634 error (_("File contains multiple dynamic symbol tables\n"));
3638 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3639 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3641 else if (section
->sh_type
== SHT_STRTAB
3642 && strcmp (name
, ".dynstr") == 0)
3644 if (dynamic_strings
!= NULL
)
3646 error (_("File contains multiple dynamic string tables\n"));
3650 dynamic_strings
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3652 _("dynamic strings"));
3654 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3656 if (symtab_shndx_hdr
!= NULL
)
3658 error (_("File contains multiple symtab shndx tables\n"));
3661 symtab_shndx_hdr
= section
;
3663 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3664 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3665 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3667 && strncmp (name
, ".debug_", 7) == 0)
3672 || (do_debug_info
&& (strcmp (name
, "info") == 0))
3673 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
3674 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
3675 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
3676 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
3677 || (do_debug_frames
&& (strcmp (name
, "frame") == 0))
3678 || (do_debug_macinfo
&& (strcmp (name
, "macinfo") == 0))
3679 || (do_debug_str
&& (strcmp (name
, "str") == 0))
3680 || (do_debug_loc
&& (strcmp (name
, "loc") == 0))
3682 request_dump (i
, DEBUG_DUMP
);
3684 /* linkonce section to be combined with .debug_info at link time. */
3685 else if ((do_debugging
|| do_debug_info
)
3686 && strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
3687 request_dump (i
, DEBUG_DUMP
);
3688 else if (do_debug_frames
&& strcmp (name
, ".eh_frame") == 0)
3689 request_dump (i
, DEBUG_DUMP
);
3695 if (elf_header
.e_shnum
> 1)
3696 printf (_("\nSection Headers:\n"));
3698 printf (_("\nSection Header:\n"));
3702 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3705 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3708 printf (_(" [Nr] Name Type Address Offset\n"));
3709 printf (_(" Size EntSize Flags Link Info Align\n"));
3712 for (i
= 0, section
= section_headers
;
3713 i
< elf_header
.e_shnum
;
3716 printf (" [%2u] %-17.17s %-15.15s ",
3717 SECTION_HEADER_NUM (i
),
3718 SECTION_NAME (section
),
3719 get_section_type_name (section
->sh_type
));
3723 print_vma (section
->sh_addr
, LONG_HEX
);
3725 printf ( " %6.6lx %6.6lx %2.2lx",
3726 (unsigned long) section
->sh_offset
,
3727 (unsigned long) section
->sh_size
,
3728 (unsigned long) section
->sh_entsize
);
3730 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3732 printf ("%2ld %3lx %2ld\n",
3733 (unsigned long) section
->sh_link
,
3734 (unsigned long) section
->sh_info
,
3735 (unsigned long) section
->sh_addralign
);
3739 print_vma (section
->sh_addr
, LONG_HEX
);
3741 if ((long) section
->sh_offset
== section
->sh_offset
)
3742 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
3746 print_vma (section
->sh_offset
, LONG_HEX
);
3749 if ((unsigned long) section
->sh_size
== section
->sh_size
)
3750 printf (" %6.6lx", (unsigned long) section
->sh_size
);
3754 print_vma (section
->sh_size
, LONG_HEX
);
3757 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
3758 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
3762 print_vma (section
->sh_entsize
, LONG_HEX
);
3765 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3767 printf ("%2ld %3lx ",
3768 (unsigned long) section
->sh_link
,
3769 (unsigned long) section
->sh_info
);
3771 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
3772 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
3775 print_vma (section
->sh_addralign
, DEC
);
3782 print_vma (section
->sh_addr
, LONG_HEX
);
3783 if ((long) section
->sh_offset
== section
->sh_offset
)
3784 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
3788 print_vma (section
->sh_offset
, LONG_HEX
);
3791 print_vma (section
->sh_size
, LONG_HEX
);
3793 print_vma (section
->sh_entsize
, LONG_HEX
);
3795 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3797 printf (" %2ld %3lx %ld\n",
3798 (unsigned long) section
->sh_link
,
3799 (unsigned long) section
->sh_info
,
3800 (unsigned long) section
->sh_addralign
);
3804 printf (_("Key to Flags:\n\
3805 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3806 I (info), L (link order), G (group), x (unknown)\n\
3807 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3818 } dynamic_relocations
[] =
3820 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
3821 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
3822 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
3825 /* Process the reloc section. */
3827 process_relocs (file
)
3830 unsigned long rel_size
;
3831 unsigned long rel_offset
;
3837 if (do_using_dynamic
)
3841 int has_dynamic_reloc
;
3844 has_dynamic_reloc
= 0;
3846 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
3848 is_rela
= dynamic_relocations
[i
].rela
;
3849 name
= dynamic_relocations
[i
].name
;
3850 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
3851 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
3853 has_dynamic_reloc
|= rel_size
;
3855 if (is_rela
== UNKNOWN
)
3857 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
3858 switch (dynamic_info
[DT_PLTREL
])
3872 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
3873 name
, rel_offset
, rel_size
);
3875 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
3876 dynamic_symbols
, num_dynamic_syms
,
3877 dynamic_strings
, is_rela
);
3881 if (! has_dynamic_reloc
)
3882 printf (_("\nThere are no dynamic relocations in this file.\n"));
3886 Elf_Internal_Shdr
*section
;
3890 for (i
= 0, section
= section_headers
;
3891 i
< elf_header
.e_shnum
;
3894 if ( section
->sh_type
!= SHT_RELA
3895 && section
->sh_type
!= SHT_REL
)
3898 rel_offset
= section
->sh_offset
;
3899 rel_size
= section
->sh_size
;
3903 Elf_Internal_Shdr
*strsec
;
3904 Elf_Internal_Sym
*symtab
;
3907 unsigned long nsyms
;
3909 printf (_("\nRelocation section "));
3911 if (string_table
== NULL
)
3912 printf ("%d", section
->sh_name
);
3914 printf (_("'%s'"), SECTION_NAME (section
));
3916 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3917 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
3922 if (section
->sh_link
)
3924 Elf_Internal_Shdr
*symsec
;
3926 symsec
= SECTION_HEADER (section
->sh_link
);
3927 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
3928 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
3933 strsec
= SECTION_HEADER (symsec
->sh_link
);
3935 strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
3939 is_rela
= section
->sh_type
== SHT_RELA
;
3941 dump_relocations (file
, rel_offset
, rel_size
,
3942 symtab
, nsyms
, strtab
, is_rela
);
3954 printf (_("\nThere are no relocations in this file.\n"));
3960 #include "unwind-ia64.h"
3962 /* An absolute address consists of a section and an offset. If the
3963 section is NULL, the offset itself is the address, otherwise, the
3964 address equals to LOAD_ADDRESS(section) + offset. */
3968 unsigned short section
;
3974 struct unw_table_entry
3976 struct absaddr start
;
3978 struct absaddr info
;
3980 *table
; /* Unwind table. */
3981 unsigned long table_len
; /* Length of unwind table. */
3982 unsigned char *info
; /* Unwind info. */
3983 unsigned long info_size
; /* Size of unwind info. */
3984 bfd_vma info_addr
; /* starting address of unwind info. */
3985 bfd_vma seg_base
; /* Starting address of segment. */
3986 Elf_Internal_Sym
*symtab
; /* The symbol table. */
3987 unsigned long nsyms
; /* Number of symbols. */
3988 char *strtab
; /* The string table. */
3989 unsigned long strtab_size
; /* Size of string table. */
3992 static void find_symbol_for_address
3993 PARAMS ((struct unw_aux_info
*, struct absaddr
, const char **, bfd_vma
*));
3994 static void dump_ia64_unwind
3995 PARAMS ((struct unw_aux_info
*));
3996 static int slurp_ia64_unwind_table
3997 PARAMS ((FILE *, struct unw_aux_info
*, Elf_Internal_Shdr
*));
4000 find_symbol_for_address (aux
, addr
, symname
, offset
)
4001 struct unw_aux_info
*aux
;
4002 struct absaddr addr
;
4003 const char **symname
;
4006 bfd_vma dist
= (bfd_vma
) 0x100000;
4007 Elf_Internal_Sym
*sym
, *best
= NULL
;
4010 for (i
= 0, sym
= aux
->symtab
; i
< aux
->nsyms
; ++i
, ++sym
)
4012 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4013 && sym
->st_name
!= 0
4014 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4015 && addr
.offset
>= sym
->st_value
4016 && addr
.offset
- sym
->st_value
< dist
)
4019 dist
= addr
.offset
- sym
->st_value
;
4026 *symname
= (best
->st_name
>= aux
->strtab_size
4027 ? "<corrupt>" : aux
->strtab
+ best
->st_name
);
4032 *offset
= addr
.offset
;
4036 dump_ia64_unwind (aux
)
4037 struct unw_aux_info
*aux
;
4040 struct unw_table_entry
*tp
;
4043 addr_size
= is_32bit_elf
? 4 : 8;
4045 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4049 const unsigned char *dp
;
4050 const unsigned char *head
;
4051 const char *procname
;
4053 find_symbol_for_address (aux
, tp
->start
, &procname
, &offset
);
4055 fputs ("\n<", stdout
);
4059 fputs (procname
, stdout
);
4062 printf ("+%lx", (unsigned long) offset
);
4065 fputs (">: [", stdout
);
4066 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4067 fputc ('-', stdout
);
4068 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4069 printf ("], info at +0x%lx\n",
4070 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4072 head
= aux
->info
+ (tp
->info
.offset
- aux
->info_addr
);
4073 stamp
= BYTE_GET8 ((unsigned char *) head
);
4075 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4076 (unsigned) UNW_VER (stamp
),
4077 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4078 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4079 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4080 (unsigned long) (addr_size
* UNW_LENGTH (stamp
)));
4082 if (UNW_VER (stamp
) != 1)
4084 printf ("\tUnknown version.\n");
4089 for (dp
= head
+ 8; dp
< head
+ 8 + addr_size
* UNW_LENGTH (stamp
);)
4090 dp
= unw_decode (dp
, in_body
, & in_body
);
4095 slurp_ia64_unwind_table (file
, aux
, sec
)
4097 struct unw_aux_info
*aux
;
4098 Elf_Internal_Shdr
*sec
;
4100 unsigned long size
, addr_size
, nrelas
, i
;
4101 Elf_Internal_Phdr
*prog_hdrs
, *seg
;
4102 struct unw_table_entry
*tep
;
4103 Elf_Internal_Shdr
*relsec
;
4104 Elf_Internal_Rela
*rela
, *rp
;
4105 unsigned char *table
, *tp
;
4106 Elf_Internal_Sym
*sym
;
4107 const char *relname
;
4110 addr_size
= is_32bit_elf
? 4 : 8;
4112 /* First, find the starting address of the segment that includes
4115 if (elf_header
.e_phnum
)
4117 prog_hdrs
= (Elf_Internal_Phdr
*)
4118 xmalloc (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
4121 result
= get_32bit_program_headers (file
, prog_hdrs
);
4123 result
= get_64bit_program_headers (file
, prog_hdrs
);
4131 for (seg
= prog_hdrs
; seg
< prog_hdrs
+ elf_header
.e_phnum
; ++seg
)
4133 if (seg
->p_type
!= PT_LOAD
)
4136 if (sec
->sh_addr
>= seg
->p_vaddr
4137 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4139 aux
->seg_base
= seg
->p_vaddr
;
4147 /* Second, build the unwind table from the contents of the unwind section: */
4148 size
= sec
->sh_size
;
4149 table
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4150 size
, _("unwind table"));
4154 tep
= aux
->table
= xmalloc (size
/ (3 * addr_size
) * sizeof (aux
->table
[0]));
4155 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * addr_size
, ++tep
)
4157 tep
->start
.section
= SHN_UNDEF
;
4158 tep
->end
.section
= SHN_UNDEF
;
4159 tep
->info
.section
= SHN_UNDEF
;
4162 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4163 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4164 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4168 tep
->start
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 0);
4169 tep
->end
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 8);
4170 tep
->info
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 16);
4172 tep
->start
.offset
+= aux
->seg_base
;
4173 tep
->end
.offset
+= aux
->seg_base
;
4174 tep
->info
.offset
+= aux
->seg_base
;
4178 /* Third, apply any relocations to the unwind table: */
4180 for (relsec
= section_headers
;
4181 relsec
< section_headers
+ elf_header
.e_shnum
;
4184 if (relsec
->sh_type
!= SHT_RELA
4185 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4188 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4192 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4196 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4197 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4199 if (ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4201 warn (_("Skipping unexpected symbol type %u\n"),
4202 ELF32_ST_TYPE (sym
->st_info
));
4208 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4209 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4211 if (ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4213 warn (_("Skipping unexpected symbol type %u\n"),
4214 ELF64_ST_TYPE (sym
->st_info
));
4219 if (strncmp (relname
, "R_IA64_SEGREL", 13) != 0)
4221 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4225 i
= rp
->r_offset
/ (3 * addr_size
);
4227 switch (rp
->r_offset
/addr_size
% 3)
4230 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4231 aux
->table
[i
].start
.offset
+= rp
->r_addend
;
4234 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4235 aux
->table
[i
].end
.offset
+= rp
->r_addend
;
4238 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4239 aux
->table
[i
].info
.offset
+= rp
->r_addend
;
4249 aux
->table_len
= size
/ (3 * addr_size
);
4254 process_unwind (file
)
4257 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4258 unsigned long i
, addr_size
, unwcount
= 0, unwstart
= 0;
4259 struct unw_aux_info aux
;
4264 if (elf_header
.e_machine
!= EM_IA_64
)
4266 printf (_("\nThere are no unwind sections in this file.\n"));
4270 memset (& aux
, 0, sizeof (aux
));
4272 addr_size
= is_32bit_elf
? 4 : 8;
4274 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4276 if (sec
->sh_type
== SHT_SYMTAB
)
4278 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4279 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4281 strsec
= SECTION_HEADER (sec
->sh_link
);
4282 aux
.strtab_size
= strsec
->sh_size
;
4283 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
4284 aux
.strtab_size
, _("string table"));
4286 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4291 printf (_("\nThere are no unwind sections in this file.\n"));
4293 while (unwcount
-- > 0)
4298 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4299 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4300 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4307 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4309 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
,
4312 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
4313 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4314 suffix
= SECTION_NAME (unwsec
) + len
;
4315 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4317 if (strncmp (SECTION_NAME (sec
),
4318 ELF_STRING_ia64_unwind_info_once
, len2
) == 0
4319 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4324 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4325 .IA_64.unwind or BAR -> .IA_64.unwind_info */
4326 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4327 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4329 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
,
4331 suffix
= SECTION_NAME (unwsec
) + len
;
4332 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4334 if (strncmp (SECTION_NAME (sec
),
4335 ELF_STRING_ia64_unwind_info
, len2
) == 0
4336 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4340 if (i
== elf_header
.e_shnum
)
4342 printf (_("\nCould not find unwind info section for "));
4344 if (string_table
== NULL
)
4345 printf ("%d", unwsec
->sh_name
);
4347 printf (_("'%s'"), SECTION_NAME (unwsec
));
4351 aux
.info_size
= sec
->sh_size
;
4352 aux
.info_addr
= sec
->sh_addr
;
4353 aux
.info
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4354 aux
.info_size
, _("unwind info"));
4356 printf (_("\nUnwind section "));
4358 if (string_table
== NULL
)
4359 printf ("%d", unwsec
->sh_name
);
4361 printf (_("'%s'"), SECTION_NAME (unwsec
));
4363 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4364 (unsigned long) unwsec
->sh_offset
,
4365 (unsigned long) (unwsec
->sh_size
/ (3 * addr_size
)));
4367 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4369 if (aux
.table_len
> 0)
4370 dump_ia64_unwind (& aux
);
4373 free ((char *) aux
.table
);
4375 free ((char *) aux
.info
);
4384 free ((char *) aux
.strtab
);
4390 dynamic_segment_mips_val (entry
)
4391 Elf_Internal_Dyn
*entry
;
4393 switch (entry
->d_tag
)
4396 if (entry
->d_un
.d_val
== 0)
4400 static const char * opts
[] =
4402 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
4403 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
4404 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
4405 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
4410 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
4411 if (entry
->d_un
.d_val
& (1 << cnt
))
4413 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
4420 case DT_MIPS_IVERSION
:
4421 if (dynamic_strings
!= NULL
)
4422 printf ("Interface Version: %s\n",
4423 dynamic_strings
+ entry
->d_un
.d_val
);
4425 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4428 case DT_MIPS_TIME_STAMP
:
4433 time_t time
= entry
->d_un
.d_val
;
4434 tmp
= gmtime (&time
);
4435 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
4436 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
4437 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
4438 printf ("Time Stamp: %s\n", timebuf
);
4442 case DT_MIPS_RLD_VERSION
:
4443 case DT_MIPS_LOCAL_GOTNO
:
4444 case DT_MIPS_CONFLICTNO
:
4445 case DT_MIPS_LIBLISTNO
:
4446 case DT_MIPS_SYMTABNO
:
4447 case DT_MIPS_UNREFEXTNO
:
4448 case DT_MIPS_HIPAGENO
:
4449 case DT_MIPS_DELTA_CLASS_NO
:
4450 case DT_MIPS_DELTA_INSTANCE_NO
:
4451 case DT_MIPS_DELTA_RELOC_NO
:
4452 case DT_MIPS_DELTA_SYM_NO
:
4453 case DT_MIPS_DELTA_CLASSSYM_NO
:
4454 case DT_MIPS_COMPACT_SIZE
:
4455 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4459 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
4465 dynamic_segment_parisc_val (entry
)
4466 Elf_Internal_Dyn
*entry
;
4468 switch (entry
->d_tag
)
4470 case DT_HP_DLD_FLAGS
:
4479 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
4480 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
4481 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
4482 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
4483 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
4484 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
4485 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
4486 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
4487 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
4488 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
4489 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" }
4493 bfd_vma val
= entry
->d_un
.d_val
;
4495 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
4496 if (val
& flags
[cnt
].bit
)
4500 fputs (flags
[cnt
].str
, stdout
);
4502 val
^= flags
[cnt
].bit
;
4505 if (val
!= 0 || first
)
4509 print_vma (val
, HEX
);
4515 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4522 dynamic_segment_ia64_val (entry
)
4523 Elf_Internal_Dyn
*entry
;
4525 switch (entry
->d_tag
)
4527 case DT_IA_64_PLT_RESERVE
:
4528 /* First 3 bytes reserved. */
4529 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4531 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
4537 get_32bit_dynamic_segment (file
)
4540 Elf32_External_Dyn
*edyn
;
4541 Elf_Internal_Dyn
*entry
;
4544 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4545 dynamic_size
, _("dynamic segment"));
4549 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4550 how large this .dynamic is now. We can do this even before the byte
4551 swapping since the DT_NULL tag is recognizable. */
4553 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4556 dynamic_segment
= (Elf_Internal_Dyn
*)
4557 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4559 if (dynamic_segment
== NULL
)
4561 error (_("Out of memory\n"));
4566 for (i
= 0, entry
= dynamic_segment
;
4570 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
4571 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
4580 get_64bit_dynamic_segment (file
)
4583 Elf64_External_Dyn
*edyn
;
4584 Elf_Internal_Dyn
*entry
;
4587 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4588 dynamic_size
, _("dynamic segment"));
4592 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4593 how large this .dynamic is now. We can do this even before the byte
4594 swapping since the DT_NULL tag is recognizable. */
4596 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4599 dynamic_segment
= (Elf_Internal_Dyn
*)
4600 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4602 if (dynamic_segment
== NULL
)
4604 error (_("Out of memory\n"));
4609 for (i
= 0, entry
= dynamic_segment
;
4613 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
4614 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
4623 get_dynamic_flags (flags
)
4626 static char buff
[128];
4634 flag
= flags
& - flags
;
4642 case DF_ORIGIN
: strcpy (p
, "ORIGIN"); break;
4643 case DF_SYMBOLIC
: strcpy (p
, "SYMBOLIC"); break;
4644 case DF_TEXTREL
: strcpy (p
, "TEXTREL"); break;
4645 case DF_BIND_NOW
: strcpy (p
, "BIND_NOW"); break;
4646 case DF_STATIC_TLS
: strcpy (p
, "STATIC_TLS"); break;
4647 default: strcpy (p
, "unknown"); break;
4650 p
= strchr (p
, '\0');
4655 /* Parse and display the contents of the dynamic segment. */
4657 process_dynamic_segment (file
)
4660 Elf_Internal_Dyn
*entry
;
4663 if (dynamic_size
== 0)
4666 printf (_("\nThere is no dynamic segment in this file.\n"));
4673 if (! get_32bit_dynamic_segment (file
))
4676 else if (! get_64bit_dynamic_segment (file
))
4679 /* Find the appropriate symbol table. */
4680 if (dynamic_symbols
== NULL
)
4682 for (i
= 0, entry
= dynamic_segment
;
4686 Elf_Internal_Shdr section
;
4688 if (entry
->d_tag
!= DT_SYMTAB
)
4691 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
4693 /* Since we do not know how big the symbol table is,
4694 we default to reading in the entire file (!) and
4695 processing that. This is overkill, I know, but it
4697 section
.sh_offset
= entry
->d_un
.d_val
- loadaddr
;
4699 if (fseek (file
, 0, SEEK_END
))
4700 error (_("Unable to seek to end of file!"));
4702 section
.sh_size
= ftell (file
) - section
.sh_offset
;
4704 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
4706 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
4708 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
4709 if (num_dynamic_syms
< 1)
4711 error (_("Unable to determine the number of symbols to load\n"));
4715 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
4719 /* Similarly find a string table. */
4720 if (dynamic_strings
== NULL
)
4722 for (i
= 0, entry
= dynamic_segment
;
4726 unsigned long offset
;
4729 if (entry
->d_tag
!= DT_STRTAB
)
4732 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
4734 /* Since we do not know how big the string table is,
4735 we default to reading in the entire file (!) and
4736 processing that. This is overkill, I know, but it
4739 offset
= entry
->d_un
.d_val
- loadaddr
;
4740 if (fseek (file
, 0, SEEK_END
))
4741 error (_("Unable to seek to end of file\n"));
4742 str_tab_len
= ftell (file
) - offset
;
4744 if (str_tab_len
< 1)
4747 (_("Unable to determine the length of the dynamic string table\n"));
4751 dynamic_strings
= (char *) get_data (NULL
, file
, offset
, str_tab_len
,
4752 _("dynamic string table"));
4757 /* And find the syminfo section if available. */
4758 if (dynamic_syminfo
== NULL
)
4760 unsigned long syminsz
= 0;
4762 for (i
= 0, entry
= dynamic_segment
;
4766 if (entry
->d_tag
== DT_SYMINENT
)
4768 /* Note: these braces are necessary to avoid a syntax
4769 error from the SunOS4 C compiler. */
4770 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
4772 else if (entry
->d_tag
== DT_SYMINSZ
)
4773 syminsz
= entry
->d_un
.d_val
;
4774 else if (entry
->d_tag
== DT_SYMINFO
)
4775 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
4778 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
4780 Elf_External_Syminfo
*extsyminfo
;
4781 Elf_Internal_Syminfo
*syminfo
;
4783 /* There is a syminfo section. Read the data. */
4784 extsyminfo
= ((Elf_External_Syminfo
*)
4785 get_data (NULL
, file
, dynamic_syminfo_offset
,
4786 syminsz
, _("symbol information")));
4790 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
4791 if (dynamic_syminfo
== NULL
)
4793 error (_("Out of memory\n"));
4797 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
4798 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
4801 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
4802 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
4809 if (do_dynamic
&& dynamic_addr
)
4810 printf (_("\nDynamic segment at offset 0x%lx contains %ld entries:\n"),
4811 dynamic_addr
, (long) dynamic_size
);
4813 printf (_(" Tag Type Name/Value\n"));
4815 for (i
= 0, entry
= dynamic_segment
;
4824 print_vma (entry
->d_tag
, FULL_HEX
);
4825 dtype
= get_dynamic_type (entry
->d_tag
);
4826 printf (" (%s)%*s", dtype
,
4827 ((is_32bit_elf
? 27 : 19)
4828 - (int) strlen (dtype
)),
4832 switch (entry
->d_tag
)
4836 puts (get_dynamic_flags (entry
->d_un
.d_val
));
4846 switch (entry
->d_tag
)
4849 printf (_("Auxiliary library"));
4853 printf (_("Filter library"));
4857 printf (_("Configuration file"));
4861 printf (_("Dependency audit library"));
4865 printf (_("Audit library"));
4869 if (dynamic_strings
)
4870 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
4874 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4883 printf (_("Flags:"));
4885 if (entry
->d_un
.d_val
== 0)
4886 printf (_(" None\n"));
4889 unsigned long int val
= entry
->d_un
.d_val
;
4891 if (val
& DTF_1_PARINIT
)
4893 printf (" PARINIT");
4894 val
^= DTF_1_PARINIT
;
4896 if (val
& DTF_1_CONFEXP
)
4898 printf (" CONFEXP");
4899 val
^= DTF_1_CONFEXP
;
4902 printf (" %lx", val
);
4911 printf (_("Flags:"));
4913 if (entry
->d_un
.d_val
== 0)
4914 printf (_(" None\n"));
4917 unsigned long int val
= entry
->d_un
.d_val
;
4919 if (val
& DF_P1_LAZYLOAD
)
4921 printf (" LAZYLOAD");
4922 val
^= DF_P1_LAZYLOAD
;
4924 if (val
& DF_P1_GROUPPERM
)
4926 printf (" GROUPPERM");
4927 val
^= DF_P1_GROUPPERM
;
4930 printf (" %lx", val
);
4939 printf (_("Flags:"));
4940 if (entry
->d_un
.d_val
== 0)
4941 printf (_(" None\n"));
4944 unsigned long int val
= entry
->d_un
.d_val
;
4951 if (val
& DF_1_GLOBAL
)
4956 if (val
& DF_1_GROUP
)
4961 if (val
& DF_1_NODELETE
)
4963 printf (" NODELETE");
4964 val
^= DF_1_NODELETE
;
4966 if (val
& DF_1_LOADFLTR
)
4968 printf (" LOADFLTR");
4969 val
^= DF_1_LOADFLTR
;
4971 if (val
& DF_1_INITFIRST
)
4973 printf (" INITFIRST");
4974 val
^= DF_1_INITFIRST
;
4976 if (val
& DF_1_NOOPEN
)
4981 if (val
& DF_1_ORIGIN
)
4986 if (val
& DF_1_DIRECT
)
4991 if (val
& DF_1_TRANS
)
4996 if (val
& DF_1_INTERPOSE
)
4998 printf (" INTERPOSE");
4999 val
^= DF_1_INTERPOSE
;
5001 if (val
& DF_1_NODEFLIB
)
5003 printf (" NODEFLIB");
5004 val
^= DF_1_NODEFLIB
;
5006 if (val
& DF_1_NODUMP
)
5011 if (val
& DF_1_CONLFAT
)
5013 printf (" CONLFAT");
5014 val
^= DF_1_CONLFAT
;
5017 printf (" %lx", val
);
5024 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5026 puts (get_dynamic_type (entry
->d_un
.d_val
));
5046 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5052 if (dynamic_strings
== NULL
)
5055 name
= dynamic_strings
+ entry
->d_un
.d_val
;
5059 switch (entry
->d_tag
)
5062 printf (_("Shared library: [%s]"), name
);
5064 if (strcmp (name
, program_interpreter
) == 0)
5065 printf (_(" program interpreter"));
5069 printf (_("Library soname: [%s]"), name
);
5073 printf (_("Library rpath: [%s]"), name
);
5077 printf (_("Library runpath: [%s]"), name
);
5081 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5086 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5099 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5103 case DT_INIT_ARRAYSZ
:
5104 case DT_FINI_ARRAYSZ
:
5105 case DT_GNU_CONFLICTSZ
:
5106 case DT_GNU_LIBLISTSZ
:
5109 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5110 printf (" (bytes)\n");
5120 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5133 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
5137 name
= dynamic_strings
+ entry
->d_un
.d_val
;
5141 printf (_("Not needed object: [%s]\n"), name
);
5146 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5152 /* The value of this entry is ignored. */
5157 case DT_GNU_PRELINKED
:
5161 time_t time
= entry
->d_un
.d_val
;
5163 tmp
= gmtime (&time
);
5164 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
5165 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5166 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5172 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
5173 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
5178 switch (elf_header
.e_machine
)
5181 case EM_MIPS_RS3_LE
:
5182 dynamic_segment_mips_val (entry
);
5185 dynamic_segment_parisc_val (entry
);
5188 dynamic_segment_ia64_val (entry
);
5191 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5203 get_ver_flags (flags
)
5206 static char buff
[32];
5213 if (flags
& VER_FLG_BASE
)
5214 strcat (buff
, "BASE ");
5216 if (flags
& VER_FLG_WEAK
)
5218 if (flags
& VER_FLG_BASE
)
5219 strcat (buff
, "| ");
5221 strcat (buff
, "WEAK ");
5224 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
5225 strcat (buff
, "| <unknown>");
5230 /* Display the contents of the version sections. */
5232 process_version_sections (file
)
5235 Elf_Internal_Shdr
*section
;
5242 for (i
= 0, section
= section_headers
;
5243 i
< elf_header
.e_shnum
;
5246 switch (section
->sh_type
)
5248 case SHT_GNU_verdef
:
5250 Elf_External_Verdef
*edefs
;
5257 (_("\nVersion definition section '%s' contains %ld entries:\n"),
5258 SECTION_NAME (section
), section
->sh_info
);
5260 printf (_(" Addr: 0x"));
5261 printf_vma (section
->sh_addr
);
5262 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5263 (unsigned long) section
->sh_offset
, section
->sh_link
,
5264 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5266 edefs
= ((Elf_External_Verdef
*)
5267 get_data (NULL
, file
, section
->sh_offset
,
5269 _("version definition section")));
5273 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5276 Elf_External_Verdef
*edef
;
5277 Elf_Internal_Verdef ent
;
5278 Elf_External_Verdaux
*eaux
;
5279 Elf_Internal_Verdaux aux
;
5283 vstart
= ((char *) edefs
) + idx
;
5285 edef
= (Elf_External_Verdef
*) vstart
;
5287 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
5288 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
5289 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
5290 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
5291 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
5292 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
5293 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
5295 printf (_(" %#06x: Rev: %d Flags: %s"),
5296 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
5298 printf (_(" Index: %d Cnt: %d "),
5299 ent
.vd_ndx
, ent
.vd_cnt
);
5301 vstart
+= ent
.vd_aux
;
5303 eaux
= (Elf_External_Verdaux
*) vstart
;
5305 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5306 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5308 if (dynamic_strings
)
5309 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
5311 printf (_("Name index: %ld\n"), aux
.vda_name
);
5313 isum
= idx
+ ent
.vd_aux
;
5315 for (j
= 1; j
< ent
.vd_cnt
; j
++)
5317 isum
+= aux
.vda_next
;
5318 vstart
+= aux
.vda_next
;
5320 eaux
= (Elf_External_Verdaux
*) vstart
;
5322 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5323 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5325 if (dynamic_strings
)
5326 printf (_(" %#06x: Parent %d: %s\n"),
5327 isum
, j
, dynamic_strings
+ aux
.vda_name
);
5329 printf (_(" %#06x: Parent %d, name index: %ld\n"),
5330 isum
, j
, aux
.vda_name
);
5340 case SHT_GNU_verneed
:
5342 Elf_External_Verneed
*eneed
;
5348 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
5349 SECTION_NAME (section
), section
->sh_info
);
5351 printf (_(" Addr: 0x"));
5352 printf_vma (section
->sh_addr
);
5353 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
5354 (unsigned long) section
->sh_offset
, section
->sh_link
,
5355 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5357 eneed
= ((Elf_External_Verneed
*)
5358 get_data (NULL
, file
, section
->sh_offset
,
5359 section
->sh_size
, _("version need section")));
5363 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5365 Elf_External_Verneed
*entry
;
5366 Elf_Internal_Verneed ent
;
5371 vstart
= ((char *) eneed
) + idx
;
5373 entry
= (Elf_External_Verneed
*) vstart
;
5375 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
5376 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
5377 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
5378 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
5379 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
5381 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
5383 if (dynamic_strings
)
5384 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
5386 printf (_(" File: %lx"), ent
.vn_file
);
5388 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
5390 vstart
+= ent
.vn_aux
;
5392 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
5394 Elf_External_Vernaux
*eaux
;
5395 Elf_Internal_Vernaux aux
;
5397 eaux
= (Elf_External_Vernaux
*) vstart
;
5399 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
5400 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
5401 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
5402 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
5403 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
5405 if (dynamic_strings
)
5406 printf (_(" %#06x: Name: %s"),
5407 isum
, dynamic_strings
+ aux
.vna_name
);
5409 printf (_(" %#06x: Name index: %lx"),
5410 isum
, aux
.vna_name
);
5412 printf (_(" Flags: %s Version: %d\n"),
5413 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
5415 isum
+= aux
.vna_next
;
5416 vstart
+= aux
.vna_next
;
5426 case SHT_GNU_versym
:
5428 Elf_Internal_Shdr
*link_section
;
5431 unsigned char *edata
;
5432 unsigned short *data
;
5434 Elf_Internal_Sym
*symbols
;
5435 Elf_Internal_Shdr
*string_sec
;
5437 link_section
= SECTION_HEADER (section
->sh_link
);
5438 total
= section
->sh_size
/ section
->sh_entsize
;
5442 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
5444 string_sec
= SECTION_HEADER (link_section
->sh_link
);
5446 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5447 string_sec
->sh_size
,
5448 _("version string table"));
5452 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
5453 SECTION_NAME (section
), total
);
5455 printf (_(" Addr: "));
5456 printf_vma (section
->sh_addr
);
5457 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5458 (unsigned long) section
->sh_offset
, section
->sh_link
,
5459 SECTION_NAME (link_section
));
5463 get_data (NULL
, file
,
5464 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] - loadaddr
,
5465 total
* sizeof (short), _("version symbol data")));
5472 data
= (unsigned short *) malloc (total
* sizeof (short));
5474 for (cnt
= total
; cnt
--;)
5475 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
5480 for (cnt
= 0; cnt
< total
; cnt
+= 4)
5483 int check_def
, check_need
;
5486 printf (" %03x:", cnt
);
5488 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
5489 switch (data
[cnt
+ j
])
5492 fputs (_(" 0 (*local*) "), stdout
);
5496 fputs (_(" 1 (*global*) "), stdout
);
5500 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
5501 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
5505 if (SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
5508 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
5515 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
5517 Elf_Internal_Verneed ivn
;
5518 unsigned long offset
;
5520 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5525 Elf_Internal_Vernaux ivna
;
5526 Elf_External_Verneed evn
;
5527 Elf_External_Vernaux evna
;
5528 unsigned long a_off
;
5530 get_data (&evn
, file
, offset
, sizeof (evn
),
5533 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5534 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5536 a_off
= offset
+ ivn
.vn_aux
;
5540 get_data (&evna
, file
, a_off
, sizeof (evna
),
5541 _("version need aux (2)"));
5543 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5544 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5546 a_off
+= ivna
.vna_next
;
5548 while (ivna
.vna_other
!= data
[cnt
+ j
]
5549 && ivna
.vna_next
!= 0);
5551 if (ivna
.vna_other
== data
[cnt
+ j
])
5553 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5555 name
= strtab
+ ivna
.vna_name
;
5556 nn
+= printf ("(%s%-*s",
5558 12 - (int) strlen (name
),
5564 offset
+= ivn
.vn_next
;
5566 while (ivn
.vn_next
);
5569 if (check_def
&& data
[cnt
+ j
] != 0x8001
5570 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5572 Elf_Internal_Verdef ivd
;
5573 Elf_External_Verdef evd
;
5574 unsigned long offset
;
5576 offset
= (version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
5581 get_data (&evd
, file
, offset
, sizeof (evd
),
5584 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
5585 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
5587 offset
+= ivd
.vd_next
;
5589 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
5590 && ivd
.vd_next
!= 0);
5592 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
5594 Elf_External_Verdaux evda
;
5595 Elf_Internal_Verdaux ivda
;
5597 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
5599 get_data (&evda
, file
,
5600 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
5601 sizeof (evda
), _("version def aux"));
5603 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
5605 name
= strtab
+ ivda
.vda_name
;
5606 nn
+= printf ("(%s%-*s",
5608 12 - (int) strlen (name
),
5614 printf ("%*c", 18 - nn
, ' ');
5632 printf (_("\nNo version information found in this file.\n"));
5638 get_symbol_binding (binding
)
5639 unsigned int binding
;
5641 static char buff
[32];
5645 case STB_LOCAL
: return "LOCAL";
5646 case STB_GLOBAL
: return "GLOBAL";
5647 case STB_WEAK
: return "WEAK";
5649 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
5650 sprintf (buff
, _("<processor specific>: %d"), binding
);
5651 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
5652 sprintf (buff
, _("<OS specific>: %d"), binding
);
5654 sprintf (buff
, _("<unknown>: %d"), binding
);
5660 get_symbol_type (type
)
5663 static char buff
[32];
5667 case STT_NOTYPE
: return "NOTYPE";
5668 case STT_OBJECT
: return "OBJECT";
5669 case STT_FUNC
: return "FUNC";
5670 case STT_SECTION
: return "SECTION";
5671 case STT_FILE
: return "FILE";
5672 case STT_COMMON
: return "COMMON";
5673 case STT_TLS
: return "TLS";
5675 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
5677 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
5678 return "THUMB_FUNC";
5680 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
5683 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
5684 return "PARISC_MILLI";
5686 sprintf (buff
, _("<processor specific>: %d"), type
);
5688 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
5690 if (elf_header
.e_machine
== EM_PARISC
)
5692 if (type
== STT_HP_OPAQUE
)
5694 if (type
== STT_HP_STUB
)
5698 sprintf (buff
, _("<OS specific>: %d"), type
);
5701 sprintf (buff
, _("<unknown>: %d"), type
);
5707 get_symbol_visibility (visibility
)
5708 unsigned int visibility
;
5712 case STV_DEFAULT
: return "DEFAULT";
5713 case STV_INTERNAL
: return "INTERNAL";
5714 case STV_HIDDEN
: return "HIDDEN";
5715 case STV_PROTECTED
: return "PROTECTED";
5721 get_symbol_index_type (type
)
5724 static char buff
[32];
5728 case SHN_UNDEF
: return "UND";
5729 case SHN_ABS
: return "ABS";
5730 case SHN_COMMON
: return "COM";
5732 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
5733 sprintf (buff
, "PRC[0x%04x]", type
);
5734 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
5735 sprintf (buff
, "OS [0x%04x]", type
);
5736 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
5737 sprintf (buff
, "RSV[0x%04x]", type
);
5739 sprintf (buff
, "%3d", type
);
5747 get_dynamic_data (file
, number
)
5749 unsigned int number
;
5751 unsigned char *e_data
;
5754 e_data
= (unsigned char *) malloc (number
* 4);
5758 error (_("Out of memory\n"));
5762 if (fread (e_data
, 4, number
, file
) != number
)
5764 error (_("Unable to read in dynamic data\n"));
5768 i_data
= (int *) malloc (number
* sizeof (*i_data
));
5772 error (_("Out of memory\n"));
5778 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
5785 /* Dump the symbol table. */
5787 process_symbol_table (file
)
5790 Elf_Internal_Shdr
*section
;
5791 unsigned char nb
[4];
5792 unsigned char nc
[4];
5795 int *buckets
= NULL
;
5798 if (! do_syms
&& !do_histogram
)
5801 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
5804 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
5806 error (_("Unable to seek to start of dynamic information"));
5810 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
5812 error (_("Failed to read in number of buckets\n"));
5816 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
5818 error (_("Failed to read in number of chains\n"));
5822 nbuckets
= byte_get (nb
, 4);
5823 nchains
= byte_get (nc
, 4);
5825 buckets
= get_dynamic_data (file
, nbuckets
);
5826 chains
= get_dynamic_data (file
, nchains
);
5828 if (buckets
== NULL
|| chains
== NULL
)
5833 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
5838 printf (_("\nSymbol table for image:\n"));
5840 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5842 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5844 for (hn
= 0; hn
< nbuckets
; hn
++)
5849 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
5851 Elf_Internal_Sym
*psym
;
5853 psym
= dynamic_symbols
+ si
;
5855 printf (" %3d %3d: ", si
, hn
);
5856 print_vma (psym
->st_value
, LONG_HEX
);
5858 print_vma (psym
->st_size
, DEC_5
);
5860 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5861 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5862 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5863 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
5864 print_symbol (25, dynamic_strings
+ psym
->st_name
);
5869 else if (do_syms
&& !do_using_dynamic
)
5873 for (i
= 0, section
= section_headers
;
5874 i
< elf_header
.e_shnum
;
5879 Elf_Internal_Sym
*symtab
;
5880 Elf_Internal_Sym
*psym
;
5883 if ( section
->sh_type
!= SHT_SYMTAB
5884 && section
->sh_type
!= SHT_DYNSYM
)
5887 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5888 SECTION_NAME (section
),
5889 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
5891 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5893 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5895 symtab
= GET_ELF_SYMBOLS (file
, section
);
5899 if (section
->sh_link
== elf_header
.e_shstrndx
)
5900 strtab
= string_table
;
5903 Elf_Internal_Shdr
*string_sec
;
5905 string_sec
= SECTION_HEADER (section
->sh_link
);
5907 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5908 string_sec
->sh_size
,
5912 for (si
= 0, psym
= symtab
;
5913 si
< section
->sh_size
/ section
->sh_entsize
;
5916 printf ("%6d: ", si
);
5917 print_vma (psym
->st_value
, LONG_HEX
);
5919 print_vma (psym
->st_size
, DEC_5
);
5920 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5921 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5922 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5923 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
5924 print_symbol (25, strtab
+ psym
->st_name
);
5926 if (section
->sh_type
== SHT_DYNSYM
&&
5927 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
5929 unsigned char data
[2];
5930 unsigned short vers_data
;
5931 unsigned long offset
;
5935 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
5938 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
5939 sizeof (data
), _("version data"));
5941 vers_data
= byte_get (data
, 2);
5943 is_nobits
= (SECTION_HEADER (psym
->st_shndx
)->sh_type
5946 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
5948 if ((vers_data
& 0x8000) || vers_data
> 1)
5950 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5951 && (is_nobits
|| ! check_def
))
5953 Elf_External_Verneed evn
;
5954 Elf_Internal_Verneed ivn
;
5955 Elf_Internal_Vernaux ivna
;
5957 /* We must test both. */
5958 offset
= (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5963 unsigned long vna_off
;
5965 get_data (&evn
, file
, offset
, sizeof (evn
),
5968 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5969 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5971 vna_off
= offset
+ ivn
.vn_aux
;
5975 Elf_External_Vernaux evna
;
5977 get_data (&evna
, file
, vna_off
,
5979 _("version need aux (3)"));
5981 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5982 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5983 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5985 vna_off
+= ivna
.vna_next
;
5987 while (ivna
.vna_other
!= vers_data
5988 && ivna
.vna_next
!= 0);
5990 if (ivna
.vna_other
== vers_data
)
5993 offset
+= ivn
.vn_next
;
5995 while (ivn
.vn_next
!= 0);
5997 if (ivna
.vna_other
== vers_data
)
6000 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
6003 else if (! is_nobits
)
6004 error (_("bad dynamic symbol"));
6011 if (vers_data
!= 0x8001
6012 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6014 Elf_Internal_Verdef ivd
;
6015 Elf_Internal_Verdaux ivda
;
6016 Elf_External_Verdaux evda
;
6017 unsigned long offset
;
6020 = (version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
6025 Elf_External_Verdef evd
;
6027 get_data (&evd
, file
, offset
, sizeof (evd
),
6030 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6031 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6032 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6034 offset
+= ivd
.vd_next
;
6036 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
6037 && ivd
.vd_next
!= 0);
6039 offset
-= ivd
.vd_next
;
6040 offset
+= ivd
.vd_aux
;
6042 get_data (&evda
, file
, offset
, sizeof (evda
),
6043 _("version def aux"));
6045 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6047 if (psym
->st_name
!= ivda
.vda_name
)
6048 printf ((vers_data
& 0x8000)
6050 strtab
+ ivda
.vda_name
);
6060 if (strtab
!= string_table
)
6066 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
6068 if (do_histogram
&& buckets
!= NULL
)
6075 int nzero_counts
= 0;
6078 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
6080 printf (_(" Length Number %% of total Coverage\n"));
6082 lengths
= (int *) calloc (nbuckets
, sizeof (int));
6083 if (lengths
== NULL
)
6085 error (_("Out of memory"));
6088 for (hn
= 0; hn
< nbuckets
; ++hn
)
6093 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
6096 if (maxlength
< ++lengths
[hn
])
6101 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
6104 error (_("Out of memory"));
6108 for (hn
= 0; hn
< nbuckets
; ++hn
)
6109 ++counts
[lengths
[hn
]];
6113 printf (" 0 %-10d (%5.1f%%)\n",
6114 counts
[0], (counts
[0] * 100.0) / nbuckets
);
6115 for (si
= 1; si
<= maxlength
; ++si
)
6117 nzero_counts
+= counts
[si
] * si
;
6118 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
6119 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
6120 (nzero_counts
* 100.0) / nsyms
);
6128 if (buckets
!= NULL
)
6138 process_syminfo (file
)
6139 FILE *file ATTRIBUTE_UNUSED
;
6143 if (dynamic_syminfo
== NULL
6145 /* No syminfo, this is ok. */
6148 /* There better should be a dynamic symbol section. */
6149 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
6153 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
6154 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
6156 printf (_(" Num: Name BoundTo Flags\n"));
6157 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
6159 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
6161 printf ("%4d: ", i
);
6162 print_symbol (30, dynamic_strings
+ dynamic_symbols
[i
].st_name
);
6165 switch (dynamic_syminfo
[i
].si_boundto
)
6167 case SYMINFO_BT_SELF
:
6168 fputs ("SELF ", stdout
);
6170 case SYMINFO_BT_PARENT
:
6171 fputs ("PARENT ", stdout
);
6174 if (dynamic_syminfo
[i
].si_boundto
> 0
6175 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
6180 [dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
6184 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
6188 if (flags
& SYMINFO_FLG_DIRECT
)
6190 if (flags
& SYMINFO_FLG_PASSTHRU
)
6191 printf (" PASSTHRU");
6192 if (flags
& SYMINFO_FLG_COPY
)
6194 if (flags
& SYMINFO_FLG_LAZYLOAD
)
6195 printf (" LAZYLOAD");
6203 #ifdef SUPPORT_DISASSEMBLY
6205 disassemble_section (section
, file
)
6206 Elf_Internal_Shdr
*section
;
6209 printf (_("\nAssembly dump of section %s\n"),
6210 SECTION_NAME (section
));
6212 /* XXX -- to be done --- XXX */
6219 dump_section (section
, file
)
6220 Elf_Internal_Shdr
*section
;
6223 bfd_size_type bytes
;
6225 unsigned char *data
;
6226 unsigned char *start
;
6228 bytes
= section
->sh_size
;
6232 printf (_("\nSection '%s' has no data to dump.\n"),
6233 SECTION_NAME (section
));
6237 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
6239 addr
= section
->sh_addr
;
6241 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, bytes
,
6254 lbytes
= (bytes
> 16 ? 16 : bytes
);
6256 printf (" 0x%8.8lx ", (unsigned long) addr
);
6258 switch (elf_header
.e_ident
[EI_DATA
])
6262 for (j
= 15; j
>= 0; j
--)
6265 printf ("%2.2x", data
[j
]);
6275 for (j
= 0; j
< 16; j
++)
6278 printf ("%2.2x", data
[j
]);
6288 for (j
= 0; j
< lbytes
; j
++)
6291 if (k
>= ' ' && k
< 0x80)
6310 static unsigned long int
6311 read_leb128 (data
, length_return
, sign
)
6312 unsigned char *data
;
6316 unsigned long int result
= 0;
6317 unsigned int num_read
= 0;
6326 result
|= (byte
& 0x7f) << shift
;
6331 while (byte
& 0x80);
6333 if (length_return
!= NULL
)
6334 *length_return
= num_read
;
6336 if (sign
&& (shift
< 32) && (byte
& 0x40))
6337 result
|= -1 << shift
;
6342 typedef struct State_Machine_Registers
6344 unsigned long address
;
6347 unsigned int column
;
6351 /* This variable hold the number of the last entry seen
6352 in the File Table. */
6353 unsigned int last_file_entry
;
6356 static SMR state_machine_regs
;
6359 reset_state_machine (is_stmt
)
6362 state_machine_regs
.address
= 0;
6363 state_machine_regs
.file
= 1;
6364 state_machine_regs
.line
= 1;
6365 state_machine_regs
.column
= 0;
6366 state_machine_regs
.is_stmt
= is_stmt
;
6367 state_machine_regs
.basic_block
= 0;
6368 state_machine_regs
.end_sequence
= 0;
6369 state_machine_regs
.last_file_entry
= 0;
6372 /* Handled an extend line op. Returns true if this is the end
6375 process_extended_line_op (data
, is_stmt
, pointer_size
)
6376 unsigned char *data
;
6380 unsigned char op_code
;
6383 unsigned char *name
;
6386 len
= read_leb128 (data
, & bytes_read
, 0);
6391 warn (_("badly formed extended line op encountered!\n"));
6398 printf (_(" Extended opcode %d: "), op_code
);
6402 case DW_LNE_end_sequence
:
6403 printf (_("End of Sequence\n\n"));
6404 reset_state_machine (is_stmt
);
6407 case DW_LNE_set_address
:
6408 adr
= byte_get (data
, pointer_size
);
6409 printf (_("set Address to 0x%lx\n"), adr
);
6410 state_machine_regs
.address
= adr
;
6413 case DW_LNE_define_file
:
6414 printf (_(" define new File Table entry\n"));
6415 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6417 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6419 data
+= strlen ((char *) data
) + 1;
6420 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6422 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6424 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6425 printf (_("%s\n\n"), name
);
6429 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
6436 /* Size of pointers in the .debug_line section. This information is not
6437 really present in that section. It's obtained before dumping the debug
6438 sections by doing some pre-scan of the .debug_info section. */
6439 static int debug_line_pointer_size
= 4;
6442 display_debug_lines (section
, start
, file
)
6443 Elf_Internal_Shdr
*section
;
6444 unsigned char * start
;
6445 FILE *file ATTRIBUTE_UNUSED
;
6447 unsigned char *hdrptr
;
6448 DWARF2_Internal_LineInfo info
;
6449 unsigned char *standard_opcodes
;
6450 unsigned char *data
= start
;
6451 unsigned char *end
= start
+ section
->sh_size
;
6452 unsigned char *end_of_sequence
;
6455 int initial_length_size
;
6457 printf (_("\nDump of debug contents of section %s:\n\n"),
6458 SECTION_NAME (section
));
6464 /* Check the length of the block. */
6465 info
.li_length
= byte_get (hdrptr
, 4);
6468 if (info
.li_length
== 0xffffffff)
6470 /* This section is 64-bit DWARF 3. */
6471 info
.li_length
= byte_get (hdrptr
, 8);
6474 initial_length_size
= 12;
6479 initial_length_size
= 4;
6482 if (info
.li_length
+ initial_length_size
> section
->sh_size
)
6485 (_("The line info appears to be corrupt - the section is too small\n"));
6489 /* Check its version number. */
6490 info
.li_version
= byte_get (hdrptr
, 2);
6492 if (info
.li_version
!= 2 && info
.li_version
!= 3)
6494 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
6498 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
6499 hdrptr
+= offset_size
;
6500 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
6502 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
6504 info
.li_line_base
= byte_get (hdrptr
, 1);
6506 info
.li_line_range
= byte_get (hdrptr
, 1);
6508 info
.li_opcode_base
= byte_get (hdrptr
, 1);
6511 /* Sign extend the line base field. */
6512 info
.li_line_base
<<= 24;
6513 info
.li_line_base
>>= 24;
6515 printf (_(" Length: %ld\n"), info
.li_length
);
6516 printf (_(" DWARF Version: %d\n"), info
.li_version
);
6517 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
6518 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
6519 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
6520 printf (_(" Line Base: %d\n"), info
.li_line_base
);
6521 printf (_(" Line Range: %d\n"), info
.li_line_range
);
6522 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
6524 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
6526 reset_state_machine (info
.li_default_is_stmt
);
6528 /* Display the contents of the Opcodes table. */
6529 standard_opcodes
= hdrptr
;
6531 printf (_("\n Opcodes:\n"));
6533 for (i
= 1; i
< info
.li_opcode_base
; i
++)
6534 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
6536 /* Display the contents of the Directory table. */
6537 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
6540 printf (_("\n The Directory Table is empty.\n"));
6543 printf (_("\n The Directory Table:\n"));
6547 printf (_(" %s\n"), data
);
6549 data
+= strlen ((char *) data
) + 1;
6553 /* Skip the NUL at the end of the table. */
6556 /* Display the contents of the File Name table. */
6558 printf (_("\n The File Name Table is empty.\n"));
6561 printf (_("\n The File Name Table:\n"));
6562 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6566 unsigned char *name
;
6569 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6572 data
+= strlen ((char *) data
) + 1;
6574 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6576 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6578 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6580 printf (_("%s\n"), name
);
6584 /* Skip the NUL at the end of the table. */
6587 /* Now display the statements. */
6588 printf (_("\n Line Number Statements:\n"));
6591 while (data
< end_of_sequence
)
6593 unsigned char op_code
;
6599 if (op_code
>= info
.li_opcode_base
)
6601 op_code
-= info
.li_opcode_base
;
6602 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
6603 state_machine_regs
.address
+= adv
;
6604 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6605 op_code
, adv
, state_machine_regs
.address
);
6606 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
6607 state_machine_regs
.line
+= adv
;
6608 printf (_(" and Line by %d to %d\n"),
6609 adv
, state_machine_regs
.line
);
6611 else switch (op_code
)
6613 case DW_LNS_extended_op
:
6614 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
6615 debug_line_pointer_size
);
6619 printf (_(" Copy\n"));
6622 case DW_LNS_advance_pc
:
6623 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
6625 state_machine_regs
.address
+= adv
;
6626 printf (_(" Advance PC by %d to %lx\n"), adv
,
6627 state_machine_regs
.address
);
6630 case DW_LNS_advance_line
:
6631 adv
= read_leb128 (data
, & bytes_read
, 1);
6633 state_machine_regs
.line
+= adv
;
6634 printf (_(" Advance Line by %d to %d\n"), adv
,
6635 state_machine_regs
.line
);
6638 case DW_LNS_set_file
:
6639 adv
= read_leb128 (data
, & bytes_read
, 0);
6641 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6643 state_machine_regs
.file
= adv
;
6646 case DW_LNS_set_column
:
6647 adv
= read_leb128 (data
, & bytes_read
, 0);
6649 printf (_(" Set column to %d\n"), adv
);
6650 state_machine_regs
.column
= adv
;
6653 case DW_LNS_negate_stmt
:
6654 adv
= state_machine_regs
.is_stmt
;
6656 printf (_(" Set is_stmt to %d\n"), adv
);
6657 state_machine_regs
.is_stmt
= adv
;
6660 case DW_LNS_set_basic_block
:
6661 printf (_(" Set basic block\n"));
6662 state_machine_regs
.basic_block
= 1;
6665 case DW_LNS_const_add_pc
:
6666 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
6667 * info
.li_min_insn_length
);
6668 state_machine_regs
.address
+= adv
;
6669 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
6670 state_machine_regs
.address
);
6673 case DW_LNS_fixed_advance_pc
:
6674 adv
= byte_get (data
, 2);
6676 state_machine_regs
.address
+= adv
;
6677 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6678 adv
, state_machine_regs
.address
);
6681 case DW_LNS_set_prologue_end
:
6682 printf (_(" Set prologue_end to true\n"));
6685 case DW_LNS_set_epilogue_begin
:
6686 printf (_(" Set epilogue_begin to true\n"));
6689 case DW_LNS_set_isa
:
6690 adv
= read_leb128 (data
, & bytes_read
, 0);
6692 printf (_(" Set ISA to %d\n"), adv
);
6696 printf (_(" Unknown opcode %d with operands: "), op_code
);
6699 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
6701 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
6702 i
== 1 ? "" : ", ");
6717 display_debug_pubnames (section
, start
, file
)
6718 Elf_Internal_Shdr
*section
;
6719 unsigned char *start
;
6720 FILE *file ATTRIBUTE_UNUSED
;
6722 DWARF2_Internal_PubNames pubnames
;
6725 end
= start
+ section
->sh_size
;
6727 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6731 unsigned char *data
;
6732 unsigned long offset
;
6733 int offset_size
, initial_length_size
;
6737 pubnames
.pn_length
= byte_get (data
, 4);
6739 if (pubnames
.pn_length
== 0xffffffff)
6741 pubnames
.pn_length
= byte_get (data
, 8);
6744 initial_length_size
= 12;
6749 initial_length_size
= 4;
6752 pubnames
.pn_version
= byte_get (data
, 2);
6754 pubnames
.pn_offset
= byte_get (data
, offset_size
);
6755 data
+= offset_size
;
6756 pubnames
.pn_size
= byte_get (data
, offset_size
);
6757 data
+= offset_size
;
6759 start
+= pubnames
.pn_length
+ initial_length_size
;
6761 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
6763 static int warned
= 0;
6767 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6774 printf (_(" Length: %ld\n"),
6775 pubnames
.pn_length
);
6776 printf (_(" Version: %d\n"),
6777 pubnames
.pn_version
);
6778 printf (_(" Offset into .debug_info section: %ld\n"),
6779 pubnames
.pn_offset
);
6780 printf (_(" Size of area in .debug_info section: %ld\n"),
6783 printf (_("\n Offset\tName\n"));
6787 offset
= byte_get (data
, offset_size
);
6791 data
+= offset_size
;
6792 printf (" %ld\t\t%s\n", offset
, data
);
6793 data
+= strlen ((char *) data
) + 1;
6796 while (offset
!= 0);
6809 case DW_TAG_padding
: return "DW_TAG_padding";
6810 case DW_TAG_array_type
: return "DW_TAG_array_type";
6811 case DW_TAG_class_type
: return "DW_TAG_class_type";
6812 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
6813 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
6814 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
6815 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
6816 case DW_TAG_label
: return "DW_TAG_label";
6817 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
6818 case DW_TAG_member
: return "DW_TAG_member";
6819 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
6820 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
6821 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
6822 case DW_TAG_string_type
: return "DW_TAG_string_type";
6823 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
6824 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
6825 case DW_TAG_typedef
: return "DW_TAG_typedef";
6826 case DW_TAG_union_type
: return "DW_TAG_union_type";
6827 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
6828 case DW_TAG_variant
: return "DW_TAG_variant";
6829 case DW_TAG_common_block
: return "DW_TAG_common_block";
6830 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
6831 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
6832 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
6833 case DW_TAG_module
: return "DW_TAG_module";
6834 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
6835 case DW_TAG_set_type
: return "DW_TAG_set_type";
6836 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
6837 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
6838 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
6839 case DW_TAG_base_type
: return "DW_TAG_base_type";
6840 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
6841 case DW_TAG_const_type
: return "DW_TAG_const_type";
6842 case DW_TAG_constant
: return "DW_TAG_constant";
6843 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
6844 case DW_TAG_file_type
: return "DW_TAG_file_type";
6845 case DW_TAG_friend
: return "DW_TAG_friend";
6846 case DW_TAG_namelist
: return "DW_TAG_namelist";
6847 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
6848 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
6849 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
6850 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
6851 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
6852 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
6853 case DW_TAG_try_block
: return "DW_TAG_try_block";
6854 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
6855 case DW_TAG_variable
: return "DW_TAG_variable";
6856 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
6857 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
6858 case DW_TAG_format_label
: return "DW_TAG_format_label";
6859 case DW_TAG_function_template
: return "DW_TAG_function_template";
6860 case DW_TAG_class_template
: return "DW_TAG_class_template";
6861 /* DWARF 2.1 values. */
6862 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
6863 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
6864 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
6865 case DW_TAG_namespace
: return "DW_TAG_namespace";
6866 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
6867 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
6868 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
6869 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
6871 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
6872 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
6873 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
6876 static char buffer
[100];
6878 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
6885 get_AT_name (attribute
)
6886 unsigned long attribute
;
6890 case DW_AT_sibling
: return "DW_AT_sibling";
6891 case DW_AT_location
: return "DW_AT_location";
6892 case DW_AT_name
: return "DW_AT_name";
6893 case DW_AT_ordering
: return "DW_AT_ordering";
6894 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
6895 case DW_AT_byte_size
: return "DW_AT_byte_size";
6896 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
6897 case DW_AT_bit_size
: return "DW_AT_bit_size";
6898 case DW_AT_element_list
: return "DW_AT_element_list";
6899 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
6900 case DW_AT_low_pc
: return "DW_AT_low_pc";
6901 case DW_AT_high_pc
: return "DW_AT_high_pc";
6902 case DW_AT_language
: return "DW_AT_language";
6903 case DW_AT_member
: return "DW_AT_member";
6904 case DW_AT_discr
: return "DW_AT_discr";
6905 case DW_AT_discr_value
: return "DW_AT_discr_value";
6906 case DW_AT_visibility
: return "DW_AT_visibility";
6907 case DW_AT_import
: return "DW_AT_import";
6908 case DW_AT_string_length
: return "DW_AT_string_length";
6909 case DW_AT_common_reference
: return "DW_AT_common_reference";
6910 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
6911 case DW_AT_const_value
: return "DW_AT_const_value";
6912 case DW_AT_containing_type
: return "DW_AT_containing_type";
6913 case DW_AT_default_value
: return "DW_AT_default_value";
6914 case DW_AT_inline
: return "DW_AT_inline";
6915 case DW_AT_is_optional
: return "DW_AT_is_optional";
6916 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
6917 case DW_AT_producer
: return "DW_AT_producer";
6918 case DW_AT_prototyped
: return "DW_AT_prototyped";
6919 case DW_AT_return_addr
: return "DW_AT_return_addr";
6920 case DW_AT_start_scope
: return "DW_AT_start_scope";
6921 case DW_AT_stride_size
: return "DW_AT_stride_size";
6922 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
6923 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
6924 case DW_AT_accessibility
: return "DW_AT_accessibility";
6925 case DW_AT_address_class
: return "DW_AT_address_class";
6926 case DW_AT_artificial
: return "DW_AT_artificial";
6927 case DW_AT_base_types
: return "DW_AT_base_types";
6928 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
6929 case DW_AT_count
: return "DW_AT_count";
6930 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
6931 case DW_AT_decl_column
: return "DW_AT_decl_column";
6932 case DW_AT_decl_file
: return "DW_AT_decl_file";
6933 case DW_AT_decl_line
: return "DW_AT_decl_line";
6934 case DW_AT_declaration
: return "DW_AT_declaration";
6935 case DW_AT_discr_list
: return "DW_AT_discr_list";
6936 case DW_AT_encoding
: return "DW_AT_encoding";
6937 case DW_AT_external
: return "DW_AT_external";
6938 case DW_AT_frame_base
: return "DW_AT_frame_base";
6939 case DW_AT_friend
: return "DW_AT_friend";
6940 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
6941 case DW_AT_macro_info
: return "DW_AT_macro_info";
6942 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
6943 case DW_AT_priority
: return "DW_AT_priority";
6944 case DW_AT_segment
: return "DW_AT_segment";
6945 case DW_AT_specification
: return "DW_AT_specification";
6946 case DW_AT_static_link
: return "DW_AT_static_link";
6947 case DW_AT_type
: return "DW_AT_type";
6948 case DW_AT_use_location
: return "DW_AT_use_location";
6949 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
6950 case DW_AT_virtuality
: return "DW_AT_virtuality";
6951 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
6952 /* DWARF 2.1 values. */
6953 case DW_AT_allocated
: return "DW_AT_allocated";
6954 case DW_AT_associated
: return "DW_AT_associated";
6955 case DW_AT_data_location
: return "DW_AT_data_location";
6956 case DW_AT_stride
: return "DW_AT_stride";
6957 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
6958 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
6959 case DW_AT_extension
: return "DW_AT_extension";
6960 case DW_AT_ranges
: return "DW_AT_ranges";
6961 case DW_AT_trampoline
: return "DW_AT_trampoline";
6962 case DW_AT_call_column
: return "DW_AT_call_column";
6963 case DW_AT_call_file
: return "DW_AT_call_file";
6964 case DW_AT_call_line
: return "DW_AT_call_line";
6965 /* SGI/MIPS extensions. */
6966 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
6967 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
6968 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
6969 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
6970 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
6971 case DW_AT_MIPS_software_pipeline_depth
:
6972 return "DW_AT_MIPS_software_pipeline_depth";
6973 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
6974 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
6975 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
6976 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
6977 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
6978 /* GNU extensions. */
6979 case DW_AT_sf_names
: return "DW_AT_sf_names";
6980 case DW_AT_src_info
: return "DW_AT_src_info";
6981 case DW_AT_mac_info
: return "DW_AT_mac_info";
6982 case DW_AT_src_coords
: return "DW_AT_src_coords";
6983 case DW_AT_body_begin
: return "DW_AT_body_begin";
6984 case DW_AT_body_end
: return "DW_AT_body_end";
6985 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
6986 /* UPC extension. */
6987 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
6990 static char buffer
[100];
6992 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
6999 get_FORM_name (form
)
7004 case DW_FORM_addr
: return "DW_FORM_addr";
7005 case DW_FORM_block2
: return "DW_FORM_block2";
7006 case DW_FORM_block4
: return "DW_FORM_block4";
7007 case DW_FORM_data2
: return "DW_FORM_data2";
7008 case DW_FORM_data4
: return "DW_FORM_data4";
7009 case DW_FORM_data8
: return "DW_FORM_data8";
7010 case DW_FORM_string
: return "DW_FORM_string";
7011 case DW_FORM_block
: return "DW_FORM_block";
7012 case DW_FORM_block1
: return "DW_FORM_block1";
7013 case DW_FORM_data1
: return "DW_FORM_data1";
7014 case DW_FORM_flag
: return "DW_FORM_flag";
7015 case DW_FORM_sdata
: return "DW_FORM_sdata";
7016 case DW_FORM_strp
: return "DW_FORM_strp";
7017 case DW_FORM_udata
: return "DW_FORM_udata";
7018 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
7019 case DW_FORM_ref1
: return "DW_FORM_ref1";
7020 case DW_FORM_ref2
: return "DW_FORM_ref2";
7021 case DW_FORM_ref4
: return "DW_FORM_ref4";
7022 case DW_FORM_ref8
: return "DW_FORM_ref8";
7023 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
7024 case DW_FORM_indirect
: return "DW_FORM_indirect";
7027 static char buffer
[100];
7029 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
7035 /* FIXME: There are better and more effiecint ways to handle
7036 these structures. For now though, I just want something that
7037 is simple to implement. */
7038 typedef struct abbrev_attr
7040 unsigned long attribute
;
7042 struct abbrev_attr
*next
;
7046 typedef struct abbrev_entry
7048 unsigned long entry
;
7051 struct abbrev_attr
*first_attr
;
7052 struct abbrev_attr
*last_attr
;
7053 struct abbrev_entry
*next
;
7057 static abbrev_entry
*first_abbrev
= NULL
;
7058 static abbrev_entry
*last_abbrev
= NULL
;
7063 abbrev_entry
*abbrev
;
7065 for (abbrev
= first_abbrev
; abbrev
;)
7067 abbrev_entry
*next
= abbrev
->next
;
7070 for (attr
= abbrev
->first_attr
; attr
;)
7072 abbrev_attr
*next
= attr
->next
;
7082 last_abbrev
= first_abbrev
= NULL
;
7086 add_abbrev (number
, tag
, children
)
7087 unsigned long number
;
7091 abbrev_entry
*entry
;
7093 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
7099 entry
->entry
= number
;
7101 entry
->children
= children
;
7102 entry
->first_attr
= NULL
;
7103 entry
->last_attr
= NULL
;
7106 if (first_abbrev
== NULL
)
7107 first_abbrev
= entry
;
7109 last_abbrev
->next
= entry
;
7111 last_abbrev
= entry
;
7115 add_abbrev_attr (attribute
, form
)
7116 unsigned long attribute
;
7121 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
7127 attr
->attribute
= attribute
;
7131 if (last_abbrev
->first_attr
== NULL
)
7132 last_abbrev
->first_attr
= attr
;
7134 last_abbrev
->last_attr
->next
= attr
;
7136 last_abbrev
->last_attr
= attr
;
7139 /* Processes the (partial) contents of a .debug_abbrev section.
7140 Returns NULL if the end of the section was encountered.
7141 Returns the address after the last byte read if the end of
7142 an abbreviation set was found. */
7144 static unsigned char *
7145 process_abbrev_section (start
, end
)
7146 unsigned char *start
;
7149 if (first_abbrev
!= NULL
)
7155 unsigned long entry
;
7157 unsigned long attribute
;
7160 entry
= read_leb128 (start
, & bytes_read
, 0);
7161 start
+= bytes_read
;
7163 /* A single zero is supposed to end the section according
7164 to the standard. If there's more, then signal that to
7167 return start
== end
? NULL
: start
;
7169 tag
= read_leb128 (start
, & bytes_read
, 0);
7170 start
+= bytes_read
;
7172 children
= *start
++;
7174 add_abbrev (entry
, tag
, children
);
7180 attribute
= read_leb128 (start
, & bytes_read
, 0);
7181 start
+= bytes_read
;
7183 form
= read_leb128 (start
, & bytes_read
, 0);
7184 start
+= bytes_read
;
7187 add_abbrev_attr (attribute
, form
);
7189 while (attribute
!= 0);
7197 display_debug_macinfo (section
, start
, file
)
7198 Elf_Internal_Shdr
*section
;
7199 unsigned char *start
;
7200 FILE *file ATTRIBUTE_UNUSED
;
7202 unsigned char *end
= start
+ section
->sh_size
;
7203 unsigned char *curr
= start
;
7204 unsigned int bytes_read
;
7205 enum dwarf_macinfo_record_type op
;
7207 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7211 unsigned int lineno
;
7219 case DW_MACINFO_start_file
:
7221 unsigned int filenum
;
7223 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7225 filenum
= read_leb128 (curr
, & bytes_read
, 0);
7228 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno
, filenum
);
7232 case DW_MACINFO_end_file
:
7233 printf (_(" DW_MACINFO_end_file\n"));
7236 case DW_MACINFO_define
:
7237 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7240 curr
+= strlen (string
) + 1;
7241 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno
, string
);
7244 case DW_MACINFO_undef
:
7245 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7248 curr
+= strlen (string
) + 1;
7249 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno
, string
);
7252 case DW_MACINFO_vendor_ext
:
7254 unsigned int constant
;
7256 constant
= read_leb128 (curr
, & bytes_read
, 0);
7259 curr
+= strlen (string
) + 1;
7260 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant
, string
);
7271 display_debug_abbrev (section
, start
, file
)
7272 Elf_Internal_Shdr
*section
;
7273 unsigned char *start
;
7274 FILE *file ATTRIBUTE_UNUSED
;
7276 abbrev_entry
*entry
;
7277 unsigned char *end
= start
+ section
->sh_size
;
7279 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7283 start
= process_abbrev_section (start
, end
);
7285 if (first_abbrev
== NULL
)
7288 printf (_(" Number TAG\n"));
7290 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
7294 printf (_(" %ld %s [%s]\n"),
7296 get_TAG_name (entry
->tag
),
7297 entry
->children
? _("has children") : _("no children"));
7299 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
7301 printf (_(" %-18s %s\n"),
7302 get_AT_name (attr
->attribute
),
7303 get_FORM_name (attr
->form
));
7317 static unsigned char *
7318 display_block (data
, length
)
7319 unsigned char *data
;
7320 unsigned long length
;
7322 printf (_(" %lu byte block: "), length
);
7325 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
7331 decode_location_expression (data
, pointer_size
, length
)
7332 unsigned char * data
;
7333 unsigned int pointer_size
;
7334 unsigned long length
;
7338 unsigned long uvalue
;
7339 unsigned char *end
= data
+ length
;
7348 printf ("DW_OP_addr: %lx",
7349 (unsigned long) byte_get (data
, pointer_size
));
7350 data
+= pointer_size
;
7353 printf ("DW_OP_deref");
7356 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
7359 printf ("DW_OP_const1s: %ld", (long) byte_get (data
++, 1));
7362 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
7366 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
7370 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
7374 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
7378 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
7379 (unsigned long) byte_get (data
+ 4, 4));
7383 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
7384 (long) byte_get (data
+ 4, 4));
7388 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
7392 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
7396 printf ("DW_OP_dup");
7399 printf ("DW_OP_drop");
7402 printf ("DW_OP_over");
7405 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
7408 printf ("DW_OP_swap");
7411 printf ("DW_OP_rot");
7414 printf ("DW_OP_xderef");
7417 printf ("DW_OP_abs");
7420 printf ("DW_OP_and");
7423 printf ("DW_OP_div");
7426 printf ("DW_OP_minus");
7429 printf ("DW_OP_mod");
7432 printf ("DW_OP_mul");
7435 printf ("DW_OP_neg");
7438 printf ("DW_OP_not");
7441 printf ("DW_OP_or");
7444 printf ("DW_OP_plus");
7446 case DW_OP_plus_uconst
:
7447 printf ("DW_OP_plus_uconst: %lu",
7448 read_leb128 (data
, &bytes_read
, 0));
7452 printf ("DW_OP_shl");
7455 printf ("DW_OP_shr");
7458 printf ("DW_OP_shra");
7461 printf ("DW_OP_xor");
7464 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
7468 printf ("DW_OP_eq");
7471 printf ("DW_OP_ge");
7474 printf ("DW_OP_gt");
7477 printf ("DW_OP_le");
7480 printf ("DW_OP_lt");
7483 printf ("DW_OP_ne");
7486 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
7522 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
7557 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
7592 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
7593 read_leb128 (data
, &bytes_read
, 1));
7598 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
7602 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
7606 uvalue
= read_leb128 (data
, &bytes_read
, 0);
7608 printf ("DW_OP_bregx: %lu %ld", uvalue
,
7609 read_leb128 (data
, &bytes_read
, 1));
7613 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
7616 case DW_OP_deref_size
:
7617 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
7619 case DW_OP_xderef_size
:
7620 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
7623 printf ("DW_OP_nop");
7626 /* DWARF 3 extensions. */
7627 case DW_OP_push_object_address
:
7628 printf ("DW_OP_push_object_address");
7631 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2));
7635 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4));
7638 case DW_OP_call_ref
:
7639 printf ("DW_OP_call_ref");
7642 /* GNU extensions. */
7643 case DW_OP_GNU_push_tls_address
:
7644 printf ("DW_OP_GNU_push_tls_address");
7648 if (op
>= DW_OP_lo_user
7649 && op
<= DW_OP_hi_user
)
7650 printf (_("(User defined location op)"));
7652 printf (_("(Unknown location op)"));
7653 /* No way to tell where the next op is, so just bail. */
7657 /* Separate the ops. */
7662 static const char *debug_loc_contents
;
7663 static bfd_vma debug_loc_size
;
7666 load_debug_loc (file
)
7669 Elf_Internal_Shdr
*sec
;
7672 /* If it is already loaded, do nothing. */
7673 if (debug_loc_contents
!= NULL
)
7676 /* Locate the .debug_loc section. */
7677 for (i
= 0, sec
= section_headers
;
7678 i
< elf_header
.e_shnum
;
7680 if (strcmp (SECTION_NAME (sec
), ".debug_loc") == 0)
7683 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7686 debug_loc_size
= sec
->sh_size
;
7688 debug_loc_contents
= ((char *)
7689 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7690 _("debug_loc section data")));
7696 if (debug_loc_contents
== NULL
)
7699 free ((char *) debug_loc_contents
);
7700 debug_loc_contents
= NULL
;
7706 display_debug_loc (section
, start
, file
)
7707 Elf_Internal_Shdr
*section
;
7708 unsigned char *start
;
7709 FILE *file ATTRIBUTE_UNUSED
;
7711 unsigned char *section_end
;
7712 unsigned long bytes
;
7713 unsigned char *section_begin
= start
;
7716 addr
= section
->sh_addr
;
7717 bytes
= section
->sh_size
;
7718 section_end
= start
+ bytes
;
7722 printf (_("\nThe .debug_loc section is empty.\n"));
7726 printf (_("Contents of the .debug_loc section:\n\n"));
7727 printf (_("\n Offset Begin End Expression\n"));
7729 while (start
< section_end
)
7731 unsigned long begin
;
7733 unsigned short length
;
7734 unsigned long offset
;
7736 offset
= start
- section_begin
;
7740 /* Normally, the lists in the debug_loc section are related to a
7741 given compilation unit, and thus, we would use the pointer size
7742 of that compilation unit. However, since we are displaying it
7743 seperately here, we either have to store pointer sizes of all
7744 compilation units, or assume they don't change. We assume,
7745 like the debug_line display, that it doesn't change. */
7746 begin
= byte_get (start
, debug_line_pointer_size
);
7747 start
+= debug_line_pointer_size
;
7748 end
= byte_get (start
, debug_line_pointer_size
);
7749 start
+= debug_line_pointer_size
;
7751 if (begin
== 0 && end
== 0)
7754 /* For now, skip any base address specifiers. */
7755 if (begin
== 0xffffffff)
7761 length
= byte_get (start
, 2);
7764 printf (" %8.8lx %8.8lx %8.8lx (", offset
, begin
, end
);
7765 decode_location_expression (start
, debug_line_pointer_size
, length
);
7775 static const char *debug_str_contents
;
7776 static bfd_vma debug_str_size
;
7779 load_debug_str (file
)
7782 Elf_Internal_Shdr
*sec
;
7785 /* If it is already loaded, do nothing. */
7786 if (debug_str_contents
!= NULL
)
7789 /* Locate the .debug_str section. */
7790 for (i
= 0, sec
= section_headers
;
7791 i
< elf_header
.e_shnum
;
7793 if (strcmp (SECTION_NAME (sec
), ".debug_str") == 0)
7796 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7799 debug_str_size
= sec
->sh_size
;
7801 debug_str_contents
= ((char *)
7802 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7803 _("debug_str section data")));
7809 if (debug_str_contents
== NULL
)
7812 free ((char *) debug_str_contents
);
7813 debug_str_contents
= NULL
;
7818 fetch_indirect_string (offset
)
7819 unsigned long offset
;
7821 if (debug_str_contents
== NULL
)
7822 return _("<no .debug_str section>");
7824 if (offset
> debug_str_size
)
7825 return _("<offset is too big>");
7827 return debug_str_contents
+ offset
;
7831 display_debug_str (section
, start
, file
)
7832 Elf_Internal_Shdr
*section
;
7833 unsigned char *start
;
7834 FILE *file ATTRIBUTE_UNUSED
;
7836 unsigned long bytes
;
7839 addr
= section
->sh_addr
;
7840 bytes
= section
->sh_size
;
7844 printf (_("\nThe .debug_str section is empty.\n"));
7848 printf (_("Contents of the .debug_str section:\n\n"));
7856 lbytes
= (bytes
> 16 ? 16 : bytes
);
7858 printf (" 0x%8.8lx ", (unsigned long) addr
);
7860 for (j
= 0; j
< 16; j
++)
7863 printf ("%2.2x", start
[j
]);
7871 for (j
= 0; j
< lbytes
; j
++)
7874 if (k
>= ' ' && k
< 0x80)
7890 static unsigned char *
7891 read_and_display_attr_value (attribute
, form
, data
, cu_offset
, pointer_size
,
7892 offset_size
, dwarf_version
)
7893 unsigned long attribute
;
7895 unsigned char *data
;
7896 unsigned long cu_offset
;
7897 unsigned long pointer_size
;
7898 unsigned long offset_size
;
7901 unsigned long uvalue
= 0;
7902 unsigned char *block_start
= NULL
;
7910 case DW_FORM_ref_addr
:
7911 if (dwarf_version
== 2)
7913 uvalue
= byte_get (data
, pointer_size
);
7914 data
+= pointer_size
;
7916 else if (dwarf_version
== 3)
7918 uvalue
= byte_get (data
, offset_size
);
7919 data
+= offset_size
;
7923 error (_("Internal error: DWARF version is not 2 or 3.\n"));
7928 uvalue
= byte_get (data
, pointer_size
);
7929 data
+= pointer_size
;
7933 uvalue
= byte_get (data
, offset_size
);
7934 data
+= offset_size
;
7940 uvalue
= byte_get (data
++, 1);
7945 uvalue
= byte_get (data
, 2);
7951 uvalue
= byte_get (data
, 4);
7956 uvalue
= read_leb128 (data
, & bytes_read
, 1);
7960 case DW_FORM_ref_udata
:
7962 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7966 case DW_FORM_indirect
:
7967 form
= read_leb128 (data
, & bytes_read
, 0);
7969 printf (" %s", get_FORM_name (form
));
7970 return read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
7971 pointer_size
, offset_size
,
7977 case DW_FORM_ref_addr
:
7978 printf (" <#%lx>", uvalue
);
7984 case DW_FORM_ref_udata
:
7985 printf (" <%lx>", uvalue
+ cu_offset
);
7989 printf (" %#lx", uvalue
);
7997 printf (" %ld", uvalue
);
8002 uvalue
= byte_get (data
, 4);
8003 printf (" %lx", uvalue
);
8004 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
8008 case DW_FORM_string
:
8009 printf (" %s", data
);
8010 data
+= strlen ((char *) data
) + 1;
8014 uvalue
= read_leb128 (data
, & bytes_read
, 0);
8015 block_start
= data
+ bytes_read
;
8016 data
= display_block (block_start
, uvalue
);
8019 case DW_FORM_block1
:
8020 uvalue
= byte_get (data
, 1);
8021 block_start
= data
+ 1;
8022 data
= display_block (block_start
, uvalue
);
8025 case DW_FORM_block2
:
8026 uvalue
= byte_get (data
, 2);
8027 block_start
= data
+ 2;
8028 data
= display_block (block_start
, uvalue
);
8031 case DW_FORM_block4
:
8032 uvalue
= byte_get (data
, 4);
8033 block_start
= data
+ 4;
8034 data
= display_block (block_start
, uvalue
);
8038 printf (_(" (indirect string, offset: 0x%lx): %s"),
8039 uvalue
, fetch_indirect_string (uvalue
));
8042 case DW_FORM_indirect
:
8043 /* Handled above. */
8047 warn (_("Unrecognized form: %d\n"), form
);
8051 /* For some attributes we can display futher information. */
8060 case DW_INL_not_inlined
:
8061 printf (_("(not inlined)"));
8063 case DW_INL_inlined
:
8064 printf (_("(inlined)"));
8066 case DW_INL_declared_not_inlined
:
8067 printf (_("(declared as inline but ignored)"));
8069 case DW_INL_declared_inlined
:
8070 printf (_("(declared as inline and inlined)"));
8073 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
8078 case DW_AT_language
:
8081 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
8082 case DW_LANG_C89
: printf ("(ANSI C)"); break;
8083 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
8084 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
8085 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
8086 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
8087 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
8088 case DW_LANG_Ada83
: printf ("(Ada)"); break;
8089 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
8090 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
8091 /* DWARF 2.1 values. */
8092 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
8093 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
8094 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
8095 /* MIPS extension. */
8096 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
8097 /* UPC extension. */
8098 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
8100 printf ("(Unknown: %lx)", uvalue
);
8105 case DW_AT_encoding
:
8108 case DW_ATE_void
: printf ("(void)"); break;
8109 case DW_ATE_address
: printf ("(machine address)"); break;
8110 case DW_ATE_boolean
: printf ("(boolean)"); break;
8111 case DW_ATE_complex_float
: printf ("(complex float)"); break;
8112 case DW_ATE_float
: printf ("(float)"); break;
8113 case DW_ATE_signed
: printf ("(signed)"); break;
8114 case DW_ATE_signed_char
: printf ("(signed char)"); break;
8115 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
8116 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
8117 /* DWARF 2.1 value. */
8118 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
8120 if (uvalue
>= DW_ATE_lo_user
8121 && uvalue
<= DW_ATE_hi_user
)
8122 printf ("(user defined type)");
8124 printf ("(unknown type)");
8129 case DW_AT_accessibility
:
8132 case DW_ACCESS_public
: printf ("(public)"); break;
8133 case DW_ACCESS_protected
: printf ("(protected)"); break;
8134 case DW_ACCESS_private
: printf ("(private)"); break;
8136 printf ("(unknown accessibility)");
8141 case DW_AT_visibility
:
8144 case DW_VIS_local
: printf ("(local)"); break;
8145 case DW_VIS_exported
: printf ("(exported)"); break;
8146 case DW_VIS_qualified
: printf ("(qualified)"); break;
8147 default: printf ("(unknown visibility)"); break;
8151 case DW_AT_virtuality
:
8154 case DW_VIRTUALITY_none
: printf ("(none)"); break;
8155 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
8156 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
8157 default: printf ("(unknown virtuality)"); break;
8161 case DW_AT_identifier_case
:
8164 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
8165 case DW_ID_up_case
: printf ("(up_case)"); break;
8166 case DW_ID_down_case
: printf ("(down_case)"); break;
8167 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
8168 default: printf ("(unknown case)"); break;
8172 case DW_AT_calling_convention
:
8175 case DW_CC_normal
: printf ("(normal)"); break;
8176 case DW_CC_program
: printf ("(program)"); break;
8177 case DW_CC_nocall
: printf ("(nocall)"); break;
8179 if (uvalue
>= DW_CC_lo_user
8180 && uvalue
<= DW_CC_hi_user
)
8181 printf ("(user defined)");
8183 printf ("(unknown convention)");
8187 case DW_AT_ordering
:
8190 case -1: printf ("(undefined)"); break;
8191 case 0: printf ("(row major)"); break;
8192 case 1: printf ("(column major)"); break;
8196 case DW_AT_frame_base
:
8197 case DW_AT_location
:
8198 case DW_AT_data_member_location
:
8199 case DW_AT_vtable_elem_location
:
8200 case DW_AT_allocated
:
8201 case DW_AT_associated
:
8202 case DW_AT_data_location
:
8204 case DW_AT_upper_bound
:
8205 case DW_AT_lower_bound
:
8209 decode_location_expression (block_start
, pointer_size
, uvalue
);
8212 else if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
8215 printf ("location list");
8227 static unsigned char *
8228 read_and_display_attr (attribute
, form
, data
, cu_offset
, pointer_size
,
8229 offset_size
, dwarf_version
)
8230 unsigned long attribute
;
8232 unsigned char *data
;
8233 unsigned long cu_offset
;
8234 unsigned long pointer_size
;
8235 unsigned long offset_size
;
8238 printf (" %-18s:", get_AT_name (attribute
));
8239 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
8240 pointer_size
, offset_size
, dwarf_version
);
8246 display_debug_info (section
, start
, file
)
8247 Elf_Internal_Shdr
*section
;
8248 unsigned char *start
;
8251 unsigned char *end
= start
+ section
->sh_size
;
8252 unsigned char *section_begin
= start
;
8254 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8256 load_debug_str (file
);
8257 load_debug_loc (file
);
8261 DWARF2_Internal_CompUnit compunit
;
8262 Elf_Internal_Shdr
*relsec
;
8263 unsigned char *hdrptr
;
8264 unsigned char *cu_abbrev_offset_ptr
;
8265 unsigned char *tags
;
8268 unsigned long cu_offset
;
8270 int initial_length_size
;
8274 compunit
.cu_length
= byte_get (hdrptr
, 4);
8277 if (compunit
.cu_length
== 0xffffffff)
8279 compunit
.cu_length
= byte_get (hdrptr
, 8);
8282 initial_length_size
= 12;
8287 initial_length_size
= 4;
8290 compunit
.cu_version
= byte_get (hdrptr
, 2);
8293 cu_abbrev_offset_ptr
= hdrptr
;
8294 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
8295 hdrptr
+= offset_size
;
8297 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
8300 /* Check for RELA relocations in the
8301 abbrev_offset address, and apply them. */
8302 for (relsec
= section_headers
;
8303 relsec
< section_headers
+ elf_header
.e_shnum
;
8306 unsigned long nrelas
;
8307 Elf_Internal_Rela
*rela
, *rp
;
8308 Elf_Internal_Shdr
*symsec
;
8309 Elf_Internal_Sym
*symtab
;
8310 Elf_Internal_Sym
*sym
;
8312 if (relsec
->sh_type
!= SHT_RELA
8313 || SECTION_HEADER (relsec
->sh_info
) != section
8314 || relsec
->sh_size
== 0)
8317 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8321 symsec
= SECTION_HEADER (relsec
->sh_link
);
8322 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
8324 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8327 != (bfd_vma
) (cu_abbrev_offset_ptr
- section_begin
))
8332 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
8334 if (ELF32_R_SYM (rp
->r_info
) != 0
8335 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8337 warn (_("Skipping unexpected symbol type %u\n"),
8338 ELF32_ST_TYPE (sym
->st_info
));
8344 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
8346 if (ELF64_R_SYM (rp
->r_info
) != 0
8347 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8349 warn (_("Skipping unexpected symbol type %u\n"),
8350 ELF64_ST_TYPE (sym
->st_info
));
8355 compunit
.cu_abbrev_offset
= rp
->r_addend
;
8364 cu_offset
= start
- section_begin
;
8365 start
+= compunit
.cu_length
+ initial_length_size
;
8367 printf (_(" Compilation Unit @ %lx:\n"), cu_offset
);
8368 printf (_(" Length: %ld\n"), compunit
.cu_length
);
8369 printf (_(" Version: %d\n"), compunit
.cu_version
);
8370 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
8371 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
8373 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
8375 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
8381 /* Read in the abbrevs used by this compilation unit. */
8383 Elf_Internal_Shdr
*sec
;
8384 unsigned char *begin
;
8386 /* Locate the .debug_abbrev section and process it. */
8387 for (i
= 0, sec
= section_headers
;
8388 i
< elf_header
.e_shnum
;
8390 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
8393 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
8395 warn (_("Unable to locate .debug_abbrev section!\n"));
8399 begin
= ((unsigned char *)
8400 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
8401 _("debug_abbrev section data")));
8405 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
8406 begin
+ sec
->sh_size
);
8412 while (tags
< start
)
8415 unsigned long abbrev_number
;
8416 abbrev_entry
*entry
;
8419 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
8422 /* A null DIE marks the end of a list of children. */
8423 if (abbrev_number
== 0)
8429 /* Scan through the abbreviation list until we reach the
8431 for (entry
= first_abbrev
;
8432 entry
&& entry
->entry
!= abbrev_number
;
8433 entry
= entry
->next
)
8438 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8443 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8445 (unsigned long) (tags
- section_begin
- bytes_read
),
8447 get_TAG_name (entry
->tag
));
8449 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
8450 tags
= read_and_display_attr (attr
->attribute
,
8453 compunit
.cu_pointer_size
,
8455 compunit
.cu_version
);
8457 if (entry
->children
)
8471 display_debug_aranges (section
, start
, file
)
8472 Elf_Internal_Shdr
*section
;
8473 unsigned char *start
;
8474 FILE *file ATTRIBUTE_UNUSED
;
8476 unsigned char *end
= start
+ section
->sh_size
;
8478 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8482 unsigned char *hdrptr
;
8483 DWARF2_Internal_ARange arange
;
8484 unsigned char *ranges
;
8485 unsigned long length
;
8486 unsigned long address
;
8489 int initial_length_size
;
8493 arange
.ar_length
= byte_get (hdrptr
, 4);
8496 if (arange
.ar_length
== 0xffffffff)
8498 arange
.ar_length
= byte_get (hdrptr
, 8);
8501 initial_length_size
= 12;
8506 initial_length_size
= 4;
8509 arange
.ar_version
= byte_get (hdrptr
, 2);
8512 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
8513 hdrptr
+= offset_size
;
8515 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
8518 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
8521 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
8523 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
8527 printf (_(" Length: %ld\n"), arange
.ar_length
);
8528 printf (_(" Version: %d\n"), arange
.ar_version
);
8529 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
8530 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
8531 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
8533 printf (_("\n Address Length\n"));
8537 /* Must pad to an alignment boundary that is twice the pointer size. */
8538 excess
= (hdrptr
- start
) % (2 * arange
.ar_pointer_size
);
8540 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
8544 address
= byte_get (ranges
, arange
.ar_pointer_size
);
8546 ranges
+= arange
.ar_pointer_size
;
8548 length
= byte_get (ranges
, arange
.ar_pointer_size
);
8550 ranges
+= arange
.ar_pointer_size
;
8552 /* A pair of zeros marks the end of the list. */
8553 if (address
== 0 && length
== 0)
8556 printf (" %8.8lx %lu\n", address
, length
);
8559 start
+= arange
.ar_length
+ initial_length_size
;
8567 typedef struct Frame_Chunk
8569 struct Frame_Chunk
*next
;
8570 unsigned char *chunk_start
;
8572 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8573 short int *col_type
;
8576 unsigned int code_factor
;
8578 unsigned long pc_begin
;
8579 unsigned long pc_range
;
8583 unsigned char fde_encoding
;
8587 /* A marker for a col_type that means this column was never referenced
8588 in the frame info. */
8589 #define DW_CFA_unreferenced (-1)
8591 static void frame_need_space
PARAMS ((Frame_Chunk
*, int));
8592 static void frame_display_row
PARAMS ((Frame_Chunk
*, int *, int *));
8593 static int size_of_encoded_value
PARAMS ((int));
8596 frame_need_space (fc
, reg
)
8600 int prev
= fc
->ncols
;
8602 if (reg
< fc
->ncols
)
8605 fc
->ncols
= reg
+ 1;
8606 fc
->col_type
= (short int *) xrealloc (fc
->col_type
,
8607 fc
->ncols
* sizeof (short int));
8608 fc
->col_offset
= (int *) xrealloc (fc
->col_offset
,
8609 fc
->ncols
* sizeof (int));
8611 while (prev
< fc
->ncols
)
8613 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8614 fc
->col_offset
[prev
] = 0;
8620 frame_display_row (fc
, need_col_headers
, max_regs
)
8622 int *need_col_headers
;
8628 if (*max_regs
< fc
->ncols
)
8629 *max_regs
= fc
->ncols
;
8631 if (*need_col_headers
)
8633 *need_col_headers
= 0;
8635 printf (" LOC CFA ");
8637 for (r
= 0; r
< *max_regs
; r
++)
8638 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8643 printf ("r%-4d", r
);
8649 printf ("%08lx ", fc
->pc_begin
);
8650 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
8651 printf ("%-8s ", tmp
);
8653 for (r
= 0; r
< fc
->ncols
; r
++)
8655 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8657 switch (fc
->col_type
[r
])
8659 case DW_CFA_undefined
:
8662 case DW_CFA_same_value
:
8666 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8668 case DW_CFA_register
:
8669 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
8672 strcpy (tmp
, "n/a");
8675 printf ("%-5s", tmp
);
8682 size_of_encoded_value (encoding
)
8685 switch (encoding
& 0x7)
8688 case 0: return is_32bit_elf
? 4 : 8;
8695 #define GET(N) byte_get (start, N); start += N
8696 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8697 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8700 display_debug_frames (section
, start
, file
)
8701 Elf_Internal_Shdr
*section
;
8702 unsigned char *start
;
8703 FILE *file ATTRIBUTE_UNUSED
;
8705 unsigned char *end
= start
+ section
->sh_size
;
8706 unsigned char *section_start
= start
;
8707 Frame_Chunk
*chunks
= 0;
8708 Frame_Chunk
*remembered_state
= 0;
8710 int is_eh
= (strcmp (SECTION_NAME (section
), ".eh_frame") == 0);
8713 int addr_size
= is_32bit_elf
? 4 : 8;
8715 printf (_("The section %s contains:\n"), SECTION_NAME (section
));
8719 unsigned char *saved_start
;
8720 unsigned char *block_end
;
8721 unsigned long length
;
8722 unsigned long cie_id
;
8725 int need_col_headers
= 1;
8726 unsigned char *augmentation_data
= NULL
;
8727 unsigned long augmentation_data_len
= 0;
8728 int encoded_ptr_size
= addr_size
;
8730 int initial_length_size
;
8732 saved_start
= start
;
8733 length
= byte_get (start
, 4); start
+= 4;
8737 printf ("\n%08lx ZERO terminator\n\n",
8738 (unsigned long)(saved_start
- section_start
));
8742 if (length
== 0xffffffff)
8744 length
= byte_get (start
, 8);
8747 initial_length_size
= 12;
8752 initial_length_size
= 4;
8755 block_end
= saved_start
+ length
+ initial_length_size
;
8756 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
8758 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
8762 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8763 memset (fc
, 0, sizeof (Frame_Chunk
));
8767 fc
->chunk_start
= saved_start
;
8769 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8770 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8771 frame_need_space (fc
, max_regs
-1);
8775 fc
->augmentation
= start
;
8776 start
= strchr (start
, '\0') + 1;
8778 if (fc
->augmentation
[0] == 'z')
8780 fc
->code_factor
= LEB ();
8781 fc
->data_factor
= SLEB ();
8782 fc
->ra
= byte_get (start
, 1); start
+= 1;
8783 augmentation_data_len
= LEB ();
8784 augmentation_data
= start
;
8785 start
+= augmentation_data_len
;
8787 else if (strcmp (fc
->augmentation
, "eh") == 0)
8790 fc
->code_factor
= LEB ();
8791 fc
->data_factor
= SLEB ();
8792 fc
->ra
= byte_get (start
, 1); start
+= 1;
8796 fc
->code_factor
= LEB ();
8797 fc
->data_factor
= SLEB ();
8798 fc
->ra
= byte_get (start
, 1); start
+= 1;
8802 if (do_debug_frames_interp
)
8803 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8804 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8805 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
8809 printf ("\n%08lx %08lx %08lx CIE\n",
8810 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
8811 printf (" Version: %d\n", version
);
8812 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8813 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8814 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8815 printf (" Return address column: %d\n", fc
->ra
);
8817 if (augmentation_data_len
)
8820 printf (" Augmentation data: ");
8821 for (i
= 0; i
< augmentation_data_len
; ++i
)
8822 printf (" %02x", augmentation_data
[i
]);
8828 if (augmentation_data_len
)
8830 unsigned char *p
, *q
;
8831 p
= fc
->augmentation
+ 1;
8832 q
= augmentation_data
;
8839 q
+= 1 + size_of_encoded_value (*q
);
8841 fc
->fde_encoding
= *q
++;
8847 if (fc
->fde_encoding
)
8848 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8851 frame_need_space (fc
, fc
->ra
);
8855 unsigned char *look_for
;
8856 static Frame_Chunk fde_fc
;
8859 memset (fc
, 0, sizeof (Frame_Chunk
));
8861 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
8863 for (cie
= chunks
; cie
; cie
= cie
->next
)
8864 if (cie
->chunk_start
== look_for
)
8869 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8870 cie_id
, saved_start
);
8873 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8874 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8875 frame_need_space (fc
, max_regs
- 1);
8877 fc
->augmentation
= "";
8878 fc
->fde_encoding
= 0;
8882 fc
->ncols
= cie
->ncols
;
8883 fc
->col_type
= (short int *) xmalloc (fc
->ncols
* sizeof (short int));
8884 fc
->col_offset
= (int *) xmalloc (fc
->ncols
* sizeof (int));
8885 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8886 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8887 fc
->augmentation
= cie
->augmentation
;
8888 fc
->code_factor
= cie
->code_factor
;
8889 fc
->data_factor
= cie
->data_factor
;
8890 fc
->cfa_reg
= cie
->cfa_reg
;
8891 fc
->cfa_offset
= cie
->cfa_offset
;
8893 frame_need_space (fc
, max_regs
-1);
8894 fc
->fde_encoding
= cie
->fde_encoding
;
8897 if (fc
->fde_encoding
)
8898 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8900 fc
->pc_begin
= byte_get (start
, encoded_ptr_size
);
8901 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
8902 fc
->pc_begin
+= section
->sh_addr
+ (start
- section_start
);
8903 start
+= encoded_ptr_size
;
8904 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
8905 start
+= encoded_ptr_size
;
8907 if (cie
->augmentation
[0] == 'z')
8909 augmentation_data_len
= LEB ();
8910 augmentation_data
= start
;
8911 start
+= augmentation_data_len
;
8914 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8915 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8916 (unsigned long)(cie
->chunk_start
- section_start
),
8917 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
8918 if (! do_debug_frames_interp
&& augmentation_data_len
)
8921 printf (" Augmentation data: ");
8922 for (i
= 0; i
< augmentation_data_len
; ++i
)
8923 printf (" %02x", augmentation_data
[i
]);
8929 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8930 about to interpret instructions for the chunk. */
8932 if (do_debug_frames_interp
)
8934 /* Start by making a pass over the chunk, allocating storage
8935 and taking note of what registers are used. */
8936 unsigned char *tmp
= start
;
8938 while (start
< block_end
)
8948 /* Warning: if you add any more cases to this switch, be
8949 sure to add them to the corresponding switch below. */
8952 case DW_CFA_advance_loc
:
8956 frame_need_space (fc
, opa
);
8957 fc
->col_type
[opa
] = DW_CFA_undefined
;
8959 case DW_CFA_restore
:
8960 frame_need_space (fc
, opa
);
8961 fc
->col_type
[opa
] = DW_CFA_undefined
;
8963 case DW_CFA_set_loc
:
8964 start
+= encoded_ptr_size
;
8966 case DW_CFA_advance_loc1
:
8969 case DW_CFA_advance_loc2
:
8972 case DW_CFA_advance_loc4
:
8975 case DW_CFA_offset_extended
:
8976 reg
= LEB (); LEB ();
8977 frame_need_space (fc
, reg
);
8978 fc
->col_type
[reg
] = DW_CFA_undefined
;
8980 case DW_CFA_restore_extended
:
8982 frame_need_space (fc
, reg
);
8983 fc
->col_type
[reg
] = DW_CFA_undefined
;
8985 case DW_CFA_undefined
:
8987 frame_need_space (fc
, reg
);
8988 fc
->col_type
[reg
] = DW_CFA_undefined
;
8990 case DW_CFA_same_value
:
8992 frame_need_space (fc
, reg
);
8993 fc
->col_type
[reg
] = DW_CFA_undefined
;
8995 case DW_CFA_register
:
8996 reg
= LEB (); LEB ();
8997 frame_need_space (fc
, reg
);
8998 fc
->col_type
[reg
] = DW_CFA_undefined
;
9000 case DW_CFA_def_cfa
:
9003 case DW_CFA_def_cfa_register
:
9006 case DW_CFA_def_cfa_offset
:
9009 case DW_CFA_offset_extended_sf
:
9010 reg
= LEB (); SLEB ();
9011 frame_need_space (fc
, reg
);
9012 fc
->col_type
[reg
] = DW_CFA_undefined
;
9014 case DW_CFA_def_cfa_sf
:
9017 case DW_CFA_def_cfa_offset_sf
:
9020 case DW_CFA_GNU_args_size
:
9023 case DW_CFA_GNU_negative_offset_extended
:
9024 reg
= LEB (); LEB ();
9025 frame_need_space (fc
, reg
);
9026 fc
->col_type
[reg
] = DW_CFA_undefined
;
9035 /* Now we know what registers are used, make a second pass over
9036 the chunk, this time actually printing out the info. */
9038 while (start
< block_end
)
9041 unsigned long ul
, reg
, roffs
;
9050 /* Warning: if you add any more cases to this switch, be
9051 sure to add them to the corresponding switch above. */
9054 case DW_CFA_advance_loc
:
9055 if (do_debug_frames_interp
)
9056 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9058 printf (" DW_CFA_advance_loc: %d to %08lx\n",
9059 opa
* fc
->code_factor
,
9060 fc
->pc_begin
+ opa
* fc
->code_factor
);
9061 fc
->pc_begin
+= opa
* fc
->code_factor
;
9066 if (! do_debug_frames_interp
)
9067 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
9068 opa
, roffs
* fc
->data_factor
);
9069 fc
->col_type
[opa
] = DW_CFA_offset
;
9070 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9073 case DW_CFA_restore
:
9074 if (! do_debug_frames_interp
)
9075 printf (" DW_CFA_restore: r%d\n", opa
);
9076 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9077 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9080 case DW_CFA_set_loc
:
9081 vma
= byte_get (start
, encoded_ptr_size
);
9082 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
9083 vma
+= section
->sh_addr
+ (start
- section_start
);
9084 start
+= encoded_ptr_size
;
9085 if (do_debug_frames_interp
)
9086 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9088 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
9092 case DW_CFA_advance_loc1
:
9093 ofs
= byte_get (start
, 1); start
+= 1;
9094 if (do_debug_frames_interp
)
9095 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9097 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
9098 ofs
* fc
->code_factor
,
9099 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9100 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9103 case DW_CFA_advance_loc2
:
9104 ofs
= byte_get (start
, 2); start
+= 2;
9105 if (do_debug_frames_interp
)
9106 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9108 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
9109 ofs
* fc
->code_factor
,
9110 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9111 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9114 case DW_CFA_advance_loc4
:
9115 ofs
= byte_get (start
, 4); start
+= 4;
9116 if (do_debug_frames_interp
)
9117 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9119 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
9120 ofs
* fc
->code_factor
,
9121 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9122 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9125 case DW_CFA_offset_extended
:
9128 if (! do_debug_frames_interp
)
9129 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
9130 reg
, roffs
* fc
->data_factor
);
9131 fc
->col_type
[reg
] = DW_CFA_offset
;
9132 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9135 case DW_CFA_restore_extended
:
9137 if (! do_debug_frames_interp
)
9138 printf (" DW_CFA_restore_extended: r%ld\n", reg
);
9139 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9140 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9143 case DW_CFA_undefined
:
9145 if (! do_debug_frames_interp
)
9146 printf (" DW_CFA_undefined: r%ld\n", reg
);
9147 fc
->col_type
[reg
] = DW_CFA_undefined
;
9148 fc
->col_offset
[reg
] = 0;
9151 case DW_CFA_same_value
:
9153 if (! do_debug_frames_interp
)
9154 printf (" DW_CFA_same_value: r%ld\n", reg
);
9155 fc
->col_type
[reg
] = DW_CFA_same_value
;
9156 fc
->col_offset
[reg
] = 0;
9159 case DW_CFA_register
:
9162 if (! do_debug_frames_interp
)
9163 printf (" DW_CFA_register: r%ld\n", reg
);
9164 fc
->col_type
[reg
] = DW_CFA_register
;
9165 fc
->col_offset
[reg
] = roffs
;
9168 case DW_CFA_remember_state
:
9169 if (! do_debug_frames_interp
)
9170 printf (" DW_CFA_remember_state\n");
9171 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9172 rs
->ncols
= fc
->ncols
;
9173 rs
->col_type
= (short int *) xmalloc (rs
->ncols
* sizeof (short int));
9174 rs
->col_offset
= (int *) xmalloc (rs
->ncols
* sizeof (int));
9175 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
9176 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
9177 rs
->next
= remembered_state
;
9178 remembered_state
= rs
;
9181 case DW_CFA_restore_state
:
9182 if (! do_debug_frames_interp
)
9183 printf (" DW_CFA_restore_state\n");
9184 rs
= remembered_state
;
9185 remembered_state
= rs
->next
;
9186 frame_need_space (fc
, rs
->ncols
-1);
9187 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
9188 memcpy (fc
->col_offset
, rs
->col_offset
, rs
->ncols
* sizeof (int));
9189 free (rs
->col_type
);
9190 free (rs
->col_offset
);
9194 case DW_CFA_def_cfa
:
9195 fc
->cfa_reg
= LEB ();
9196 fc
->cfa_offset
= LEB ();
9197 if (! do_debug_frames_interp
)
9198 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
9199 fc
->cfa_reg
, fc
->cfa_offset
);
9202 case DW_CFA_def_cfa_register
:
9203 fc
->cfa_reg
= LEB ();
9204 if (! do_debug_frames_interp
)
9205 printf (" DW_CFA_def_cfa_reg: r%d\n", fc
->cfa_reg
);
9208 case DW_CFA_def_cfa_offset
:
9209 fc
->cfa_offset
= LEB ();
9210 if (! do_debug_frames_interp
)
9211 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
9215 if (! do_debug_frames_interp
)
9216 printf (" DW_CFA_nop\n");
9219 case DW_CFA_offset_extended_sf
:
9222 frame_need_space (fc
, reg
);
9223 if (! do_debug_frames_interp
)
9224 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
9225 reg
, l
* fc
->data_factor
);
9226 fc
->col_type
[reg
] = DW_CFA_offset
;
9227 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9230 case DW_CFA_def_cfa_sf
:
9231 fc
->cfa_reg
= LEB ();
9232 fc
->cfa_offset
= SLEB ();
9233 if (! do_debug_frames_interp
)
9234 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
9235 fc
->cfa_reg
, fc
->cfa_offset
);
9238 case DW_CFA_def_cfa_offset_sf
:
9239 fc
->cfa_offset
= SLEB ();
9240 if (! do_debug_frames_interp
)
9241 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
9244 case DW_CFA_GNU_window_save
:
9245 if (! do_debug_frames_interp
)
9246 printf (" DW_CFA_GNU_window_save\n");
9249 case DW_CFA_GNU_args_size
:
9251 if (! do_debug_frames_interp
)
9252 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9255 case DW_CFA_GNU_negative_offset_extended
:
9258 frame_need_space (fc
, reg
);
9259 if (! do_debug_frames_interp
)
9260 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
9261 reg
, l
* fc
->data_factor
);
9262 fc
->col_type
[reg
] = DW_CFA_offset
;
9263 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9266 /* FIXME: How do we handle these? */
9267 case DW_CFA_def_cfa_expression
:
9268 fprintf (stderr
, "unsupported DW_CFA_def_cfa_expression\n");
9272 case DW_CFA_expression
:
9273 fprintf (stderr
, "unsupported DW_CFA_expression\n");
9278 fprintf (stderr
, "unsupported or unknown DW_CFA_%d\n", op
);
9283 if (do_debug_frames_interp
)
9284 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9299 display_debug_not_supported (section
, start
, file
)
9300 Elf_Internal_Shdr
*section
;
9301 unsigned char *start ATTRIBUTE_UNUSED
;
9302 FILE *file ATTRIBUTE_UNUSED
;
9304 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9305 SECTION_NAME (section
));
9310 /* Pre-scan the .debug_info section to record the size of address.
9311 When dumping the .debug_line, we use that size information, assuming
9312 that all compilation units have the same address size. */
9314 prescan_debug_info (section
, start
, file
)
9315 Elf_Internal_Shdr
*section ATTRIBUTE_UNUSED
;
9316 unsigned char *start
;
9317 FILE *file ATTRIBUTE_UNUSED
;
9319 unsigned long length
;
9321 /* Read the first 4 bytes. For a 32-bit DWARF section, this will
9322 be the length. For a 64-bit DWARF section, it'll be the escape
9323 code 0xffffffff followed by an 8 byte length. For the purposes
9324 of this prescan, we don't care about the actual length, but the
9325 presence of the escape bytes does affect the location of the byte
9326 which describes the address size. */
9327 length
= byte_get (start
, 4);
9329 if (length
== 0xffffffff)
9331 /* For 64-bit DWARF, the 1-byte address_size field is 22 bytes
9332 from the start of the section. This is computed as follows:
9334 unit_length: 12 bytes
9336 debug_abbrev_offset: 8 bytes
9337 -----------------------------
9340 debug_line_pointer_size
= byte_get (start
+ 22, 1);
9344 /* For 32-bit DWARF, the 1-byte address_size field is 10 bytes from
9345 the start of the section:
9346 unit_length: 4 bytes
9348 debug_abbrev_offset: 4 bytes
9349 -----------------------------
9352 debug_line_pointer_size
= byte_get (start
+ 10, 1);
9357 /* A structure containing the name of a debug section and a pointer
9358 to a function that can decode it. The third field is a prescan
9359 function to be run over the section before displaying any of the
9363 const char *const name
;
9364 int (*display
) PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
9365 int (*prescan
) PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
9369 { ".debug_abbrev", display_debug_abbrev
, NULL
},
9370 { ".debug_aranges", display_debug_aranges
, NULL
},
9371 { ".debug_frame", display_debug_frames
, NULL
},
9372 { ".debug_info", display_debug_info
, prescan_debug_info
},
9373 { ".debug_line", display_debug_lines
, NULL
},
9374 { ".debug_pubnames", display_debug_pubnames
, NULL
},
9375 { ".eh_frame", display_debug_frames
, NULL
},
9376 { ".debug_macinfo", display_debug_macinfo
, NULL
},
9377 { ".debug_str", display_debug_str
, NULL
},
9378 { ".debug_loc", display_debug_loc
, NULL
},
9379 { ".debug_pubtypes", display_debug_not_supported
, NULL
},
9380 { ".debug_ranges", display_debug_not_supported
, NULL
},
9381 { ".debug_static_func", display_debug_not_supported
, NULL
},
9382 { ".debug_static_vars", display_debug_not_supported
, NULL
},
9383 { ".debug_types", display_debug_not_supported
, NULL
},
9384 { ".debug_weaknames", display_debug_not_supported
, NULL
}
9388 display_debug_section (section
, file
)
9389 Elf_Internal_Shdr
*section
;
9392 char *name
= SECTION_NAME (section
);
9393 bfd_size_type length
;
9394 unsigned char *start
;
9397 length
= section
->sh_size
;
9400 printf (_("\nSection '%s' has no debugging data.\n"), name
);
9404 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, length
,
9405 _("debug section data"));
9409 /* See if we know how to display the contents of this section. */
9410 if (strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
9411 name
= ".debug_info";
9413 for (i
= NUM_ELEM (debug_displays
); i
--;)
9414 if (strcmp (debug_displays
[i
].name
, name
) == 0)
9416 debug_displays
[i
].display (section
, start
, file
);
9421 printf (_("Unrecognized debug section: %s\n"), name
);
9425 /* If we loaded in the abbrev section at some point,
9426 we must release it here. */
9433 process_section_contents (file
)
9436 Elf_Internal_Shdr
*section
;
9442 /* Pre-scan the debug sections to find some debug information not
9443 present in some of them. For the .debug_line, we must find out the
9444 size of address (specified in .debug_info and .debug_aranges). */
9445 for (i
= 0, section
= section_headers
;
9446 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9449 char *name
= SECTION_NAME (section
);
9452 if (section
->sh_size
== 0)
9455 /* See if there is some pre-scan operation for this section. */
9456 for (j
= NUM_ELEM (debug_displays
); j
--;)
9457 if (strcmp (debug_displays
[j
].name
, name
) == 0)
9459 if (debug_displays
[j
].prescan
!= NULL
)
9461 bfd_size_type length
;
9462 unsigned char *start
;
9464 length
= section
->sh_size
;
9465 start
= ((unsigned char *)
9466 get_data (NULL
, file
, section
->sh_offset
, length
,
9467 _("debug section data")));
9471 debug_displays
[j
].prescan (section
, start
, file
);
9479 for (i
= 0, section
= section_headers
;
9480 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9483 #ifdef SUPPORT_DISASSEMBLY
9484 if (dump_sects
[i
] & DISASS_DUMP
)
9485 disassemble_section (section
, file
);
9487 if (dump_sects
[i
] & HEX_DUMP
)
9488 dump_section (section
, file
);
9490 if (dump_sects
[i
] & DEBUG_DUMP
)
9491 display_debug_section (section
, file
);
9494 if (i
< num_dump_sects
)
9495 warn (_("Some sections were not dumped because they do not exist!\n"));
9501 process_mips_fpe_exception (mask
)
9507 if (mask
& OEX_FPU_INEX
)
9508 fputs ("INEX", stdout
), first
= 0;
9509 if (mask
& OEX_FPU_UFLO
)
9510 printf ("%sUFLO", first
? "" : "|"), first
= 0;
9511 if (mask
& OEX_FPU_OFLO
)
9512 printf ("%sOFLO", first
? "" : "|"), first
= 0;
9513 if (mask
& OEX_FPU_DIV0
)
9514 printf ("%sDIV0", first
? "" : "|"), first
= 0;
9515 if (mask
& OEX_FPU_INVAL
)
9516 printf ("%sINVAL", first
? "" : "|");
9519 fputs ("0", stdout
);
9523 process_mips_specific (file
)
9526 Elf_Internal_Dyn
*entry
;
9527 size_t liblist_offset
= 0;
9528 size_t liblistno
= 0;
9529 size_t conflictsno
= 0;
9530 size_t options_offset
= 0;
9531 size_t conflicts_offset
= 0;
9533 /* We have a lot of special sections. Thanks SGI! */
9534 if (dynamic_segment
== NULL
)
9535 /* No information available. */
9538 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
9539 switch (entry
->d_tag
)
9541 case DT_MIPS_LIBLIST
:
9542 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
9544 case DT_MIPS_LIBLISTNO
:
9545 liblistno
= entry
->d_un
.d_val
;
9547 case DT_MIPS_OPTIONS
:
9548 options_offset
= entry
->d_un
.d_val
- loadaddr
;
9550 case DT_MIPS_CONFLICT
:
9551 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
9553 case DT_MIPS_CONFLICTNO
:
9554 conflictsno
= entry
->d_un
.d_val
;
9560 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9562 Elf32_External_Lib
*elib
;
9565 elib
= ((Elf32_External_Lib
*)
9566 get_data (NULL
, file
, liblist_offset
,
9567 liblistno
* sizeof (Elf32_External_Lib
),
9571 printf ("\nSection '.liblist' contains %lu entries:\n",
9572 (unsigned long) liblistno
);
9573 fputs (" Library Time Stamp Checksum Version Flags\n",
9576 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9583 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9584 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9585 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9586 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9587 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9589 tmp
= gmtime (&time
);
9590 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9591 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9592 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9594 printf ("%3lu: ", (unsigned long) cnt
);
9595 print_symbol (20, dynamic_strings
+ liblist
.l_name
);
9596 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9599 if (liblist
.l_flags
== 0)
9610 { " EXACT_MATCH", LL_EXACT_MATCH
},
9611 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9612 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9613 { " EXPORTS", LL_EXPORTS
},
9614 { " DELAY_LOAD", LL_DELAY_LOAD
},
9615 { " DELTA", LL_DELTA
}
9617 int flags
= liblist
.l_flags
;
9621 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
9623 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9625 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9626 flags
^= l_flags_vals
[fcnt
].bit
;
9629 printf (" %#x", (unsigned int) flags
);
9639 if (options_offset
!= 0)
9641 Elf_External_Options
*eopt
;
9642 Elf_Internal_Shdr
*sect
= section_headers
;
9643 Elf_Internal_Options
*iopt
;
9644 Elf_Internal_Options
*option
;
9648 /* Find the section header so that we get the size. */
9649 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9652 eopt
= (Elf_External_Options
*) get_data (NULL
, file
, options_offset
,
9653 sect
->sh_size
, _("options"));
9656 iopt
= ((Elf_Internal_Options
*)
9657 malloc ((sect
->sh_size
/ sizeof (eopt
)) * sizeof (*iopt
)));
9660 error (_("Out of memory"));
9667 while (offset
< sect
->sh_size
)
9669 Elf_External_Options
*eoption
;
9671 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9673 option
->kind
= BYTE_GET (eoption
->kind
);
9674 option
->size
= BYTE_GET (eoption
->size
);
9675 option
->section
= BYTE_GET (eoption
->section
);
9676 option
->info
= BYTE_GET (eoption
->info
);
9678 offset
+= option
->size
;
9684 printf (_("\nSection '%s' contains %d entries:\n"),
9685 SECTION_NAME (sect
), cnt
);
9693 switch (option
->kind
)
9696 /* This shouldn't happen. */
9697 printf (" NULL %d %lx", option
->section
, option
->info
);
9700 printf (" REGINFO ");
9701 if (elf_header
.e_machine
== EM_MIPS
)
9704 Elf32_External_RegInfo
*ereg
;
9705 Elf32_RegInfo reginfo
;
9707 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9708 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9709 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9710 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9711 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9712 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9713 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9715 printf ("GPR %08lx GP 0x%lx\n",
9717 (unsigned long) reginfo
.ri_gp_value
);
9718 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9719 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9720 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9725 Elf64_External_RegInfo
*ereg
;
9726 Elf64_Internal_RegInfo reginfo
;
9728 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9729 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9730 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9731 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9732 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9733 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9734 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
9736 printf ("GPR %08lx GP 0x",
9737 reginfo
.ri_gprmask
);
9738 printf_vma (reginfo
.ri_gp_value
);
9741 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9742 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9743 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9747 case ODK_EXCEPTIONS
:
9748 fputs (" EXCEPTIONS fpe_min(", stdout
);
9749 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9750 fputs (") fpe_max(", stdout
);
9751 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9752 fputs (")", stdout
);
9754 if (option
->info
& OEX_PAGE0
)
9755 fputs (" PAGE0", stdout
);
9756 if (option
->info
& OEX_SMM
)
9757 fputs (" SMM", stdout
);
9758 if (option
->info
& OEX_FPDBUG
)
9759 fputs (" FPDBUG", stdout
);
9760 if (option
->info
& OEX_DISMISS
)
9761 fputs (" DISMISS", stdout
);
9764 fputs (" PAD ", stdout
);
9765 if (option
->info
& OPAD_PREFIX
)
9766 fputs (" PREFIX", stdout
);
9767 if (option
->info
& OPAD_POSTFIX
)
9768 fputs (" POSTFIX", stdout
);
9769 if (option
->info
& OPAD_SYMBOL
)
9770 fputs (" SYMBOL", stdout
);
9773 fputs (" HWPATCH ", stdout
);
9774 if (option
->info
& OHW_R4KEOP
)
9775 fputs (" R4KEOP", stdout
);
9776 if (option
->info
& OHW_R8KPFETCH
)
9777 fputs (" R8KPFETCH", stdout
);
9778 if (option
->info
& OHW_R5KEOP
)
9779 fputs (" R5KEOP", stdout
);
9780 if (option
->info
& OHW_R5KCVTL
)
9781 fputs (" R5KCVTL", stdout
);
9784 fputs (" FILL ", stdout
);
9785 /* XXX Print content of info word? */
9788 fputs (" TAGS ", stdout
);
9789 /* XXX Print content of info word? */
9792 fputs (" HWAND ", stdout
);
9793 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9794 fputs (" R4KEOP_CHECKED", stdout
);
9795 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9796 fputs (" R4KEOP_CLEAN", stdout
);
9799 fputs (" HWOR ", stdout
);
9800 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9801 fputs (" R4KEOP_CHECKED", stdout
);
9802 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9803 fputs (" R4KEOP_CLEAN", stdout
);
9806 printf (" GP_GROUP %#06lx self-contained %#06lx",
9807 option
->info
& OGP_GROUP
,
9808 (option
->info
& OGP_SELF
) >> 16);
9811 printf (" IDENT %#06lx self-contained %#06lx",
9812 option
->info
& OGP_GROUP
,
9813 (option
->info
& OGP_SELF
) >> 16);
9816 /* This shouldn't happen. */
9817 printf (" %3d ??? %d %lx",
9818 option
->kind
, option
->section
, option
->info
);
9822 len
= sizeof (*eopt
);
9823 while (len
< option
->size
)
9824 if (((char *) option
)[len
] >= ' '
9825 && ((char *) option
)[len
] < 0x7f)
9826 printf ("%c", ((char *) option
)[len
++]);
9828 printf ("\\%03o", ((char *) option
)[len
++]);
9830 fputs ("\n", stdout
);
9838 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9840 Elf32_Conflict
*iconf
;
9843 if (dynamic_symbols
== NULL
)
9845 error (_("conflict list found without a dynamic symbol table"));
9849 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
9852 error (_("Out of memory"));
9858 Elf32_External_Conflict
*econf32
;
9860 econf32
= ((Elf32_External_Conflict
*)
9861 get_data (NULL
, file
, conflicts_offset
,
9862 conflictsno
* sizeof (*econf32
),
9867 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9868 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9874 Elf64_External_Conflict
*econf64
;
9876 econf64
= ((Elf64_External_Conflict
*)
9877 get_data (NULL
, file
, conflicts_offset
,
9878 conflictsno
* sizeof (*econf64
),
9883 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9884 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9889 printf (_("\nSection '.conflict' contains %ld entries:\n"),
9890 (long) conflictsno
);
9891 puts (_(" Num: Index Value Name"));
9893 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9895 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
9897 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9898 print_vma (psym
->st_value
, FULL_HEX
);
9900 print_symbol (25, dynamic_strings
+ psym
->st_name
);
9911 process_gnu_liblist (file
)
9914 Elf_Internal_Shdr
*section
, *string_sec
;
9915 Elf32_External_Lib
*elib
;
9923 for (i
= 0, section
= section_headers
;
9924 i
< elf_header
.e_shnum
;
9927 switch (section
->sh_type
)
9929 case SHT_GNU_LIBLIST
:
9930 elib
= ((Elf32_External_Lib
*)
9931 get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
9936 string_sec
= SECTION_HEADER (section
->sh_link
);
9938 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
9939 string_sec
->sh_size
,
9940 _("liblist string table"));
9943 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9949 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9950 SECTION_NAME (section
),
9951 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9953 puts (" Library Time Stamp Checksum Version Flags");
9955 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9963 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9964 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9965 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9966 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9967 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9969 tmp
= gmtime (&time
);
9970 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9971 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9972 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9974 printf ("%3lu: ", (unsigned long) cnt
);
9976 printf ("%-20s", strtab
+ liblist
.l_name
);
9978 printf ("%-20.20s", strtab
+ liblist
.l_name
);
9979 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9980 liblist
.l_version
, liblist
.l_flags
);
9991 get_note_type (e_type
)
9994 static char buff
[64];
9998 case NT_PRSTATUS
: return _("NT_PRSTATUS (prstatus structure)");
9999 case NT_FPREGSET
: return _("NT_FPREGSET (floating point registers)");
10000 case NT_PRPSINFO
: return _("NT_PRPSINFO (prpsinfo structure)");
10001 case NT_TASKSTRUCT
: return _("NT_TASKSTRUCT (task structure)");
10002 case NT_PRXFPREG
: return _("NT_PRXFPREG (user_xfpregs structure)");
10003 case NT_PSTATUS
: return _("NT_PSTATUS (pstatus structure)");
10004 case NT_FPREGS
: return _("NT_FPREGS (floating point registers)");
10005 case NT_PSINFO
: return _("NT_PSINFO (psinfo structure)");
10006 case NT_LWPSTATUS
: return _("NT_LWPSTATUS (lwpstatus_t structure)");
10007 case NT_LWPSINFO
: return _("NT_LWPSINFO (lwpsinfo_t structure)");
10008 case NT_WIN32PSTATUS
: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
10010 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
10015 static const char *
10016 get_netbsd_elfcore_note_type (e_type
)
10019 static char buff
[64];
10021 if (e_type
== NT_NETBSDCORE_PROCINFO
)
10023 /* NetBSD core "procinfo" structure. */
10024 return _("NetBSD procinfo structure");
10027 /* As of Jan 2002 there are no other machine-independent notes
10028 defined for NetBSD core files. If the note type is less
10029 than the start of the machine-dependent note types, we don't
10032 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
10034 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
10038 switch (elf_header
.e_machine
)
10040 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
10041 and PT_GETFPREGS == mach+2. */
10046 case EM_SPARC32PLUS
:
10050 case NT_NETBSDCORE_FIRSTMACH
+0:
10051 return _("PT_GETREGS (reg structure)");
10052 case NT_NETBSDCORE_FIRSTMACH
+2:
10053 return _("PT_GETFPREGS (fpreg structure)");
10059 /* On all other arch's, PT_GETREGS == mach+1 and
10060 PT_GETFPREGS == mach+3. */
10064 case NT_NETBSDCORE_FIRSTMACH
+1:
10065 return _("PT_GETREGS (reg structure)");
10066 case NT_NETBSDCORE_FIRSTMACH
+3:
10067 return _("PT_GETFPREGS (fpreg structure)");
10073 sprintf (buff
, _("PT_FIRSTMACH+%d"), e_type
- NT_NETBSDCORE_FIRSTMACH
);
10077 /* Note that by the ELF standard, the name field is already null byte
10078 terminated, and namesz includes the terminating null byte.
10079 I.E. the value of namesz for the name "FSF" is 4.
10081 If the value of namesz is zero, there is no name present. */
10083 process_note (pnote
)
10084 Elf_Internal_Note
*pnote
;
10088 if (pnote
->namesz
== 0)
10090 /* If there is no note name, then use the default set of
10091 note type strings. */
10092 nt
= get_note_type (pnote
->type
);
10094 else if (strncmp (pnote
->namedata
, "NetBSD-CORE", 11) == 0)
10096 /* NetBSD-specific core file notes. */
10097 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
10101 /* Don't recognize this note name; just use the default set of
10102 note type strings. */
10103 nt
= get_note_type (pnote
->type
);
10106 printf (" %s\t\t0x%08lx\t%s\n",
10107 pnote
->namesz
? pnote
->namedata
: "(NONE)",
10108 pnote
->descsz
, nt
);
10114 process_corefile_note_segment (file
, offset
, length
)
10119 Elf_External_Note
*pnotes
;
10120 Elf_External_Note
*external
;
10126 pnotes
= (Elf_External_Note
*) get_data (NULL
, file
, offset
, length
,
10133 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
10134 (unsigned long) offset
, (unsigned long) length
);
10135 printf (_(" Owner\t\tData size\tDescription\n"));
10137 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
10139 Elf_External_Note
*next
;
10140 Elf_Internal_Note inote
;
10143 inote
.type
= BYTE_GET (external
->type
);
10144 inote
.namesz
= BYTE_GET (external
->namesz
);
10145 inote
.namedata
= external
->name
;
10146 inote
.descsz
= BYTE_GET (external
->descsz
);
10147 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
10148 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
10150 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
10152 if (((char *) next
) > (((char *) pnotes
) + length
))
10154 warn (_("corrupt note found at offset %x into core notes\n"),
10155 ((char *) external
) - ((char *) pnotes
));
10156 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
10157 inote
.type
, inote
.namesz
, inote
.descsz
);
10163 /* Verify that name is null terminated. It appears that at least
10164 one version of Linux (RedHat 6.0) generates corefiles that don't
10165 comply with the ELF spec by failing to include the null byte in
10167 if (inote
.namedata
[inote
.namesz
] != '\0')
10169 temp
= malloc (inote
.namesz
+ 1);
10173 error (_("Out of memory\n"));
10178 strncpy (temp
, inote
.namedata
, inote
.namesz
);
10179 temp
[inote
.namesz
] = 0;
10181 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
10182 inote
.namedata
= temp
;
10185 res
&= process_note (& inote
);
10200 process_corefile_note_segments (file
)
10203 Elf_Internal_Phdr
*program_headers
;
10204 Elf_Internal_Phdr
*segment
;
10208 program_headers
= (Elf_Internal_Phdr
*) malloc
10209 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
10211 if (program_headers
== NULL
)
10213 error (_("Out of memory\n"));
10218 i
= get_32bit_program_headers (file
, program_headers
);
10220 i
= get_64bit_program_headers (file
, program_headers
);
10224 free (program_headers
);
10228 for (i
= 0, segment
= program_headers
;
10229 i
< elf_header
.e_phnum
;
10232 if (segment
->p_type
== PT_NOTE
)
10233 res
&= process_corefile_note_segment (file
,
10234 (bfd_vma
) segment
->p_offset
,
10235 (bfd_vma
) segment
->p_filesz
);
10238 free (program_headers
);
10244 process_corefile_contents (file
)
10247 /* If we have not been asked to display the notes then do nothing. */
10251 /* If file is not a core file then exit. */
10252 if (elf_header
.e_type
!= ET_CORE
)
10255 /* No program headers means no NOTE segment. */
10256 if (elf_header
.e_phnum
== 0)
10258 printf (_("No note segments present in the core file.\n"));
10262 return process_corefile_note_segments (file
);
10266 process_arch_specific (file
)
10272 switch (elf_header
.e_machine
)
10275 case EM_MIPS_RS3_LE
:
10276 return process_mips_specific (file
);
10285 get_file_header (file
)
10288 /* Read in the identity array. */
10289 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
10292 /* Determine how to read the rest of the header. */
10293 switch (elf_header
.e_ident
[EI_DATA
])
10295 default: /* fall through */
10296 case ELFDATANONE
: /* fall through */
10297 case ELFDATA2LSB
: byte_get
= byte_get_little_endian
; break;
10298 case ELFDATA2MSB
: byte_get
= byte_get_big_endian
; break;
10301 /* For now we only support 32 bit and 64 bit ELF files. */
10302 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
10304 /* Read in the rest of the header. */
10307 Elf32_External_Ehdr ehdr32
;
10309 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
10312 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
10313 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
10314 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
10315 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
10316 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
10317 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
10318 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
10319 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
10320 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
10321 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
10322 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
10323 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
10324 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
10328 Elf64_External_Ehdr ehdr64
;
10330 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10331 we will not be able to cope with the 64bit data found in
10332 64 ELF files. Detect this now and abort before we start
10333 overwritting things. */
10334 if (sizeof (bfd_vma
) < 8)
10336 error (_("This instance of readelf has been built without support for a\n\
10337 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10341 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
10344 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
10345 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
10346 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
10347 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
10348 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
10349 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
10350 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
10351 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
10352 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
10353 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
10354 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
10355 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
10356 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
10359 if (elf_header
.e_shoff
)
10361 /* There may be some extensions in the first section header. Don't
10362 bomb if we can't read it. */
10364 get_32bit_section_headers (file
, 1);
10366 get_64bit_section_headers (file
, 1);
10373 process_file (file_name
)
10377 struct stat statbuf
;
10380 if (stat (file_name
, & statbuf
) < 0)
10382 error (_("Cannot stat input file %s.\n"), file_name
);
10386 file
= fopen (file_name
, "rb");
10389 error (_("Input file %s not found.\n"), file_name
);
10393 if (! get_file_header (file
))
10395 error (_("%s: Failed to read file header\n"), file_name
);
10400 /* Initialise per file variables. */
10401 for (i
= NUM_ELEM (version_info
); i
--;)
10402 version_info
[i
] = 0;
10404 for (i
= NUM_ELEM (dynamic_info
); i
--;)
10405 dynamic_info
[i
] = 0;
10407 /* Process the file. */
10409 printf (_("\nFile: %s\n"), file_name
);
10411 if (! process_file_header ())
10417 if (! process_section_headers (file
))
10419 /* Without loaded section headers we
10420 cannot process lots of things. */
10421 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10423 if (! do_using_dynamic
)
10424 do_syms
= do_reloc
= 0;
10427 if (process_program_headers (file
))
10428 process_dynamic_segment (file
);
10430 process_relocs (file
);
10432 process_unwind (file
);
10434 process_symbol_table (file
);
10436 process_syminfo (file
);
10438 process_version_sections (file
);
10440 process_section_contents (file
);
10442 process_corefile_contents (file
);
10444 process_gnu_liblist (file
);
10446 process_arch_specific (file
);
10450 if (section_headers
)
10452 free (section_headers
);
10453 section_headers
= NULL
;
10458 free (string_table
);
10459 string_table
= NULL
;
10460 string_table_length
= 0;
10463 if (dynamic_strings
)
10465 free (dynamic_strings
);
10466 dynamic_strings
= NULL
;
10469 if (dynamic_symbols
)
10471 free (dynamic_symbols
);
10472 dynamic_symbols
= NULL
;
10473 num_dynamic_syms
= 0;
10476 if (dynamic_syminfo
)
10478 free (dynamic_syminfo
);
10479 dynamic_syminfo
= NULL
;
10485 #ifdef SUPPORT_DISASSEMBLY
10486 /* Needed by the i386 disassembler. For extra credit, someone could
10487 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10491 print_address (unsigned int addr
, FILE *outfile
)
10493 fprintf (outfile
,"0x%8.8x", addr
);
10496 /* Needed by the i386 disassembler. */
10498 db_task_printsym (unsigned int addr
)
10500 print_address (addr
, stderr
);
10504 int main
PARAMS ((int, char **));
10512 char *cmdline_dump_sects
= NULL
;
10513 unsigned num_cmdline_dump_sects
= 0;
10515 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10516 setlocale (LC_MESSAGES
, "");
10518 #if defined (HAVE_SETLOCALE)
10519 setlocale (LC_CTYPE
, "");
10521 bindtextdomain (PACKAGE
, LOCALEDIR
);
10522 textdomain (PACKAGE
);
10524 parse_args (argc
, argv
);
10526 if (optind
< (argc
- 1))
10529 /* When processing more than one file remember the dump requests
10530 issued on command line to reset them after each file. */
10531 if (optind
+ 1 < argc
&& dump_sects
!= NULL
)
10533 cmdline_dump_sects
= malloc (num_dump_sects
);
10534 if (cmdline_dump_sects
== NULL
)
10535 error (_("Out of memory allocating dump request table."));
10538 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
10539 num_cmdline_dump_sects
= num_dump_sects
;
10544 while (optind
< argc
)
10546 err
|= process_file (argv
[optind
++]);
10548 /* Reset dump requests. */
10549 if (optind
< argc
&& dump_sects
!= NULL
)
10551 num_dump_sects
= num_cmdline_dump_sects
;
10552 if (num_cmdline_dump_sects
> 0)
10553 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
10557 if (dump_sects
!= NULL
)
10559 if (cmdline_dump_sects
!= NULL
)
10560 free (cmdline_dump_sects
);