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"
95 char *program_name
= "readelf";
96 unsigned long dynamic_addr
;
97 bfd_size_type dynamic_size
;
98 char *dynamic_strings
;
100 unsigned long string_table_length
;
101 unsigned long num_dynamic_syms
;
102 Elf_Internal_Sym
*dynamic_symbols
;
103 Elf_Internal_Syminfo
*dynamic_syminfo
;
104 unsigned long dynamic_syminfo_offset
;
105 unsigned int dynamic_syminfo_nent
;
106 char program_interpreter
[64];
107 long dynamic_info
[DT_JMPREL
+ 1];
108 long version_info
[16];
110 Elf_Internal_Ehdr elf_header
;
111 Elf_Internal_Shdr
*section_headers
;
112 Elf_Internal_Dyn
*dynamic_segment
;
113 Elf_Internal_Shdr
*symtab_shndx_hdr
;
121 int do_using_dynamic
;
129 int do_debug_abbrevs
;
131 int do_debug_pubnames
;
132 int do_debug_aranges
;
134 int do_debug_frames_interp
;
135 int do_debug_macinfo
;
142 /* A dynamic array of flags indicating which sections require dumping. */
143 char *dump_sects
= NULL
;
144 unsigned int num_dump_sects
= 0;
146 #define HEX_DUMP (1 << 0)
147 #define DISASS_DUMP (1 << 1)
148 #define DEBUG_DUMP (1 << 2)
150 /* How to rpint a vma value. */
151 typedef enum print_mode
163 /* Forward declarations for dumb compilers. */
164 static void print_vma
165 PARAMS ((bfd_vma
, print_mode
));
166 static void print_symbol
167 PARAMS ((int, const char *));
168 static bfd_vma (*byte_get
)
169 PARAMS ((unsigned char *, int));
170 static bfd_vma byte_get_little_endian
171 PARAMS ((unsigned char *, int));
172 static bfd_vma byte_get_big_endian
173 PARAMS ((unsigned char *, int));
174 static const char *get_mips_dynamic_type
175 PARAMS ((unsigned long));
176 static const char *get_sparc64_dynamic_type
177 PARAMS ((unsigned long));
178 static const char *get_ppc64_dynamic_type
179 PARAMS ((unsigned long));
180 static const char *get_parisc_dynamic_type
181 PARAMS ((unsigned long));
182 static const char *get_ia64_dynamic_type
183 PARAMS ((unsigned long));
184 static const char *get_dynamic_type
185 PARAMS ((unsigned long));
186 static int slurp_rela_relocs
187 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela
**,
189 static int slurp_rel_relocs
190 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela
**,
192 static int dump_relocations
193 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*,
194 unsigned long, char *, int));
195 static char *get_file_type
197 static char *get_machine_name
199 static void decode_ARM_machine_flags
200 PARAMS ((unsigned, char[]));
201 static char *get_machine_flags
202 PARAMS ((unsigned, unsigned));
203 static const char *get_mips_segment_type
204 PARAMS ((unsigned long));
205 static const char *get_parisc_segment_type
206 PARAMS ((unsigned long));
207 static const char *get_ia64_segment_type
208 PARAMS ((unsigned long));
209 static const char *get_segment_type
210 PARAMS ((unsigned long));
211 static const char *get_mips_section_type_name
212 PARAMS ((unsigned int));
213 static const char *get_parisc_section_type_name
214 PARAMS ((unsigned int));
215 static const char *get_ia64_section_type_name
216 PARAMS ((unsigned int));
217 static const char *get_section_type_name
218 PARAMS ((unsigned int));
219 static const char *get_symbol_binding
220 PARAMS ((unsigned int));
221 static const char *get_symbol_type
222 PARAMS ((unsigned int));
223 static const char *get_symbol_visibility
224 PARAMS ((unsigned int));
225 static const char *get_symbol_index_type
226 PARAMS ((unsigned int));
227 static const char *get_dynamic_flags
231 static void parse_args
232 PARAMS ((int, char **));
233 static int process_file_header
235 static int process_program_headers
237 static int process_section_headers
239 static int process_unwind
241 static void dynamic_segment_mips_val
242 PARAMS ((Elf_Internal_Dyn
*));
243 static void dynamic_segment_parisc_val
244 PARAMS ((Elf_Internal_Dyn
*));
245 static void dynamic_segment_ia64_val
246 PARAMS ((Elf_Internal_Dyn
*));
247 static int process_dynamic_segment
249 static int process_symbol_table
251 static int process_syminfo
253 static int process_section_contents
255 static void process_mips_fpe_exception
257 static int process_mips_specific
259 static int process_file
261 static int process_relocs
263 static int process_version_sections
265 static char *get_ver_flags
266 PARAMS ((unsigned int));
267 static int get_32bit_section_headers
268 PARAMS ((FILE *, unsigned int));
269 static int get_64bit_section_headers
270 PARAMS ((FILE *, unsigned int));
271 static int get_32bit_program_headers
272 PARAMS ((FILE *, Elf_Internal_Phdr
*));
273 static int get_64bit_program_headers
274 PARAMS ((FILE *, Elf_Internal_Phdr
*));
275 static int get_file_header
277 static Elf_Internal_Sym
*get_32bit_elf_symbols
278 PARAMS ((FILE *, Elf_Internal_Shdr
*));
279 static Elf_Internal_Sym
*get_64bit_elf_symbols
280 PARAMS ((FILE *, Elf_Internal_Shdr
*));
281 static const char *get_elf_section_flags
283 static int *get_dynamic_data
284 PARAMS ((FILE *, unsigned int));
285 static int get_32bit_dynamic_segment
287 static int get_64bit_dynamic_segment
289 #ifdef SUPPORT_DISASSEMBLY
290 static int disassemble_section
291 PARAMS ((Elf_Internal_Shdr
*, FILE *));
293 static int dump_section
294 PARAMS ((Elf_Internal_Shdr
*, FILE *));
295 static int display_debug_section
296 PARAMS ((Elf_Internal_Shdr
*, FILE *));
297 static int display_debug_info
298 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
299 static int display_debug_not_supported
300 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
301 static int prescan_debug_info
302 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
303 static int display_debug_lines
304 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
305 static int display_debug_pubnames
306 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
307 static int display_debug_abbrev
308 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
309 static int display_debug_aranges
310 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
311 static int display_debug_frames
312 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
313 static int display_debug_macinfo
314 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
315 static int display_debug_str
316 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
317 static int display_debug_loc
318 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
319 static unsigned char *process_abbrev_section
320 PARAMS ((unsigned char *, unsigned char *));
321 static void load_debug_str
323 static void free_debug_str
325 static const char *fetch_indirect_string
326 PARAMS ((unsigned long));
327 static void load_debug_loc
329 static void free_debug_loc
331 static unsigned long read_leb128
332 PARAMS ((unsigned char *, int *, int));
333 static int process_extended_line_op
334 PARAMS ((unsigned char *, int, int));
335 static void reset_state_machine
337 static char *get_TAG_name
338 PARAMS ((unsigned long));
339 static char *get_AT_name
340 PARAMS ((unsigned long));
341 static char *get_FORM_name
342 PARAMS ((unsigned long));
343 static void free_abbrevs
345 static void add_abbrev
346 PARAMS ((unsigned long, unsigned long, int));
347 static void add_abbrev_attr
348 PARAMS ((unsigned long, unsigned long));
349 static unsigned char *read_and_display_attr
350 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
351 unsigned long, unsigned long, int));
352 static unsigned char *read_and_display_attr_value
353 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
354 unsigned long, unsigned long, int));
355 static unsigned char *display_block
356 PARAMS ((unsigned char *, unsigned long));
357 static void decode_location_expression
358 PARAMS ((unsigned char *, unsigned int, unsigned long));
359 static void request_dump
360 PARAMS ((unsigned int, int));
361 static const char *get_elf_class
362 PARAMS ((unsigned int));
363 static const char *get_data_encoding
364 PARAMS ((unsigned int));
365 static const char *get_osabi_name
366 PARAMS ((unsigned int));
367 static int guess_is_rela
368 PARAMS ((unsigned long));
369 static const char *get_note_type
370 PARAMS ((unsigned int));
371 static const char *get_netbsd_elfcore_note_type
372 PARAMS ((unsigned int));
373 static int process_note
374 PARAMS ((Elf_Internal_Note
*));
375 static int process_corefile_note_segment
376 PARAMS ((FILE *, bfd_vma
, bfd_vma
));
377 static int process_corefile_note_segments
379 static int process_corefile_contents
381 static int process_arch_specific
383 static int process_gnu_liblist
386 typedef int Elf32_Word
;
390 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
391 ((X)->sh_name >= string_table_length \
392 ? "<corrupt>" : string_table + (X)->sh_name))
394 /* Given st_shndx I, map to section_headers index. */
395 #define SECTION_HEADER_INDEX(I) \
396 ((I) < SHN_LORESERVE \
398 : ((I) <= SHN_HIRESERVE \
400 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
402 /* Reverse of the above. */
403 #define SECTION_HEADER_NUM(N) \
404 ((N) < SHN_LORESERVE \
406 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
408 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
410 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
412 #define BYTE_GET(field) byte_get (field, sizeof (field))
414 /* If we can support a 64 bit data type then BFD64 should be defined
415 and sizeof (bfd_vma) == 8. In this case when translating from an
416 external 8 byte field to an internal field, we can assume that the
417 internal field is also 8 bytes wide and so we can extract all the data.
418 If, however, BFD64 is not defined, then we must assume that the
419 internal data structure only has 4 byte wide fields that are the
420 equivalent of the 8 byte wide external counterparts, and so we must
421 truncate the data. */
423 #define BYTE_GET8(field) byte_get (field, -8)
425 #define BYTE_GET8(field) byte_get (field, 8)
428 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
430 #define GET_ELF_SYMBOLS(file, section) \
431 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
432 : get_64bit_elf_symbols (file, section))
436 error
VPARAMS ((const char *message
, ...))
438 VA_OPEN (args
, message
);
439 VA_FIXEDARG (args
, const char *, message
);
441 fprintf (stderr
, _("%s: Error: "), program_name
);
442 vfprintf (stderr
, message
, args
);
447 warn
VPARAMS ((const char *message
, ...))
449 VA_OPEN (args
, message
);
450 VA_FIXEDARG (args
, const char *, message
);
452 fprintf (stderr
, _("%s: Warning: "), program_name
);
453 vfprintf (stderr
, message
, args
);
457 static PTR get_data
PARAMS ((PTR
, FILE *, long, size_t, const char *));
460 get_data (var
, file
, offset
, size
, reason
)
472 if (fseek (file
, offset
, SEEK_SET
))
474 error (_("Unable to seek to %x for %s\n"), offset
, reason
);
481 mvar
= (PTR
) malloc (size
);
485 error (_("Out of memory allocating %d bytes for %s\n"),
491 if (fread (mvar
, size
, 1, file
) != 1)
493 error (_("Unable to read in %d bytes of %s\n"), size
, reason
);
503 byte_get_little_endian (field
, size
)
504 unsigned char *field
;
513 return ((unsigned int) (field
[0]))
514 | (((unsigned int) (field
[1])) << 8);
518 /* We want to extract data from an 8 byte wide field and
519 place it into a 4 byte wide field. Since this is a little
520 endian source we can just use the 4 byte extraction code. */
524 return ((unsigned long) (field
[0]))
525 | (((unsigned long) (field
[1])) << 8)
526 | (((unsigned long) (field
[2])) << 16)
527 | (((unsigned long) (field
[3])) << 24);
532 /* This is a special case, generated by the BYTE_GET8 macro.
533 It means that we are loading an 8 byte value from a field
534 in an external structure into an 8 byte value in a field
535 in an internal strcuture. */
536 return ((bfd_vma
) (field
[0]))
537 | (((bfd_vma
) (field
[1])) << 8)
538 | (((bfd_vma
) (field
[2])) << 16)
539 | (((bfd_vma
) (field
[3])) << 24)
540 | (((bfd_vma
) (field
[4])) << 32)
541 | (((bfd_vma
) (field
[5])) << 40)
542 | (((bfd_vma
) (field
[6])) << 48)
543 | (((bfd_vma
) (field
[7])) << 56);
546 error (_("Unhandled data length: %d\n"), size
);
551 /* Print a VMA value. */
553 print_vma (vma
, mode
)
563 case FULL_HEX
: printf ("0x"); /* drop through */
564 case LONG_HEX
: printf ("%8.8lx", (unsigned long) vma
); break;
565 case PREFIX_HEX
: printf ("0x"); /* drop through */
566 case HEX
: printf ("%lx", (unsigned long) vma
); break;
567 case DEC
: printf ("%ld", (unsigned long) vma
); break;
568 case DEC_5
: printf ("%5ld", (long) vma
); break;
569 case UNSIGNED
: printf ("%lu", (unsigned long) vma
); break;
590 #if BFD_HOST_64BIT_LONG
593 if (_bfd_int64_high (vma
))
594 printf ("%lx%8.8lx", _bfd_int64_high (vma
), _bfd_int64_low (vma
));
596 printf ("%lx", _bfd_int64_low (vma
));
601 #if BFD_HOST_64BIT_LONG
604 if (_bfd_int64_high (vma
))
606 printf ("++%ld", _bfd_int64_low (vma
));
608 printf ("%ld", _bfd_int64_low (vma
));
613 #if BFD_HOST_64BIT_LONG
614 printf ("%5ld", vma
);
616 if (_bfd_int64_high (vma
))
618 printf ("++%ld", _bfd_int64_low (vma
));
620 printf ("%5ld", _bfd_int64_low (vma
));
625 #if BFD_HOST_64BIT_LONG
628 if (_bfd_int64_high (vma
))
630 printf ("++%lu", _bfd_int64_low (vma
));
632 printf ("%lu", _bfd_int64_low (vma
));
640 /* Display a symbol on stdout. If do_wide is not true then
641 format the symbol to be at most WIDTH characters,
642 truncating as necessary. If WIDTH is negative then
643 format the string to be exactly - WIDTH characters,
644 truncating or padding as necessary. */
647 print_symbol (width
, symbol
)
652 printf ("%s", symbol
);
654 printf ("%-*.*s", width
, width
, symbol
);
656 printf ("%-.*s", width
, symbol
);
660 byte_get_big_endian (field
, size
)
661 unsigned char *field
;
670 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
673 return ((unsigned long) (field
[3]))
674 | (((unsigned long) (field
[2])) << 8)
675 | (((unsigned long) (field
[1])) << 16)
676 | (((unsigned long) (field
[0])) << 24);
680 /* Although we are extracing data from an 8 byte wide field, we
681 are returning only 4 bytes of data. */
682 return ((unsigned long) (field
[7]))
683 | (((unsigned long) (field
[6])) << 8)
684 | (((unsigned long) (field
[5])) << 16)
685 | (((unsigned long) (field
[4])) << 24);
689 /* This is a special case, generated by the BYTE_GET8 macro.
690 It means that we are loading an 8 byte value from a field
691 in an external structure into an 8 byte value in a field
692 in an internal strcuture. */
693 return ((bfd_vma
) (field
[7]))
694 | (((bfd_vma
) (field
[6])) << 8)
695 | (((bfd_vma
) (field
[5])) << 16)
696 | (((bfd_vma
) (field
[4])) << 24)
697 | (((bfd_vma
) (field
[3])) << 32)
698 | (((bfd_vma
) (field
[2])) << 40)
699 | (((bfd_vma
) (field
[1])) << 48)
700 | (((bfd_vma
) (field
[0])) << 56);
704 error (_("Unhandled data length: %d\n"), size
);
709 /* Guess the relocation size commonly used by the specific machines. */
712 guess_is_rela (e_machine
)
713 unsigned long e_machine
;
717 /* Targets that use REL relocations. */
733 /* Targets that use RELA relocations. */
748 case EM_CYGNUS_MN10200
:
750 case EM_CYGNUS_MN10300
:
793 warn (_("Don't know about relocations on this machine architecture\n"));
799 slurp_rela_relocs (file
, rel_offset
, rel_size
, relasp
, nrelasp
)
801 unsigned long rel_offset
;
802 unsigned long rel_size
;
803 Elf_Internal_Rela
**relasp
;
804 unsigned long *nrelasp
;
806 Elf_Internal_Rela
*relas
;
807 unsigned long nrelas
;
812 Elf32_External_Rela
*erelas
;
814 erelas
= (Elf32_External_Rela
*) get_data (NULL
, file
, rel_offset
,
815 rel_size
, _("relocs"));
819 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
821 relas
= (Elf_Internal_Rela
*)
822 malloc (nrelas
* sizeof (Elf_Internal_Rela
));
826 error(_("out of memory parsing relocs"));
830 for (i
= 0; i
< nrelas
; i
++)
832 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
833 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
834 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
841 Elf64_External_Rela
*erelas
;
843 erelas
= (Elf64_External_Rela
*) get_data (NULL
, file
, rel_offset
,
844 rel_size
, _("relocs"));
848 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
850 relas
= (Elf_Internal_Rela
*)
851 malloc (nrelas
* sizeof (Elf_Internal_Rela
));
855 error(_("out of memory parsing relocs"));
859 for (i
= 0; i
< nrelas
; i
++)
861 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
862 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
863 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
874 slurp_rel_relocs (file
, rel_offset
, rel_size
, relsp
, nrelsp
)
876 unsigned long rel_offset
;
877 unsigned long rel_size
;
878 Elf_Internal_Rela
**relsp
;
879 unsigned long *nrelsp
;
881 Elf_Internal_Rela
*rels
;
887 Elf32_External_Rel
*erels
;
889 erels
= (Elf32_External_Rel
*) get_data (NULL
, file
, rel_offset
,
890 rel_size
, _("relocs"));
894 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
896 rels
= (Elf_Internal_Rela
*) malloc (nrels
* sizeof (Elf_Internal_Rela
));
900 error(_("out of memory parsing relocs"));
904 for (i
= 0; i
< nrels
; i
++)
906 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
907 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
908 rels
[i
].r_addend
= 0;
915 Elf64_External_Rel
*erels
;
917 erels
= (Elf64_External_Rel
*) get_data (NULL
, file
, rel_offset
,
918 rel_size
, _("relocs"));
922 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
924 rels
= (Elf_Internal_Rela
*) malloc (nrels
* sizeof (Elf_Internal_Rela
));
928 error(_("out of memory parsing relocs"));
932 for (i
= 0; i
< nrels
; i
++)
934 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
935 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
936 rels
[i
].r_addend
= 0;
946 /* Display the contents of the relocation data found at the specified offset. */
949 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
951 unsigned long rel_offset
;
952 unsigned long rel_size
;
953 Elf_Internal_Sym
*symtab
;
959 Elf_Internal_Rela
*rels
;
962 if (is_rela
== UNKNOWN
)
963 is_rela
= guess_is_rela (elf_header
.e_machine
);
967 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
972 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
981 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
983 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
988 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
990 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
998 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1000 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1005 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1007 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1011 for (i
= 0; i
< rel_size
; i
++)
1014 const char *rtype2
= NULL
;
1015 const char *rtype3
= NULL
;
1018 bfd_vma symtab_index
;
1020 bfd_vma type2
= (bfd_vma
) NULL
;
1021 bfd_vma type3
= (bfd_vma
) NULL
;
1023 offset
= rels
[i
].r_offset
;
1024 info
= rels
[i
].r_info
;
1028 type
= ELF32_R_TYPE (info
);
1029 symtab_index
= ELF32_R_SYM (info
);
1033 /* The #ifdef BFD64 below is to prevent a compile time warning.
1034 We know that if we do not have a 64 bit data type that we
1035 will never execute this code anyway. */
1037 if (elf_header
.e_machine
== EM_MIPS
)
1039 /* In little-endian objects, r_info isn't really a 64-bit
1040 little-endian value: it has a 32-bit little-endian
1041 symbol index followed by four individual byte fields.
1042 Reorder INFO accordingly. */
1043 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1044 info
= (((info
& 0xffffffff) << 32)
1045 | ((info
>> 56) & 0xff)
1046 | ((info
>> 40) & 0xff00)
1047 | ((info
>> 24) & 0xff0000)
1048 | ((info
>> 8) & 0xff000000));
1049 type
= ELF64_MIPS_R_TYPE (info
);
1050 type2
= ELF64_MIPS_R_TYPE2 (info
);
1051 type3
= ELF64_MIPS_R_TYPE3 (info
);
1053 else if (elf_header
.e_machine
== EM_SPARCV9
)
1054 type
= ELF64_R_TYPE_ID (info
);
1056 type
= ELF64_R_TYPE (info
);
1058 symtab_index
= ELF64_R_SYM (info
);
1064 #ifdef _bfd_int64_low
1065 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
1067 printf ("%8.8lx %8.8lx ", offset
, info
);
1072 #ifdef _bfd_int64_low
1074 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1075 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1076 _bfd_int64_high (offset
),
1077 _bfd_int64_low (offset
),
1078 _bfd_int64_high (info
),
1079 _bfd_int64_low (info
));
1082 ? "%16.16lx %16.16lx "
1083 : "%12.12lx %12.12lx ",
1088 switch (elf_header
.e_machine
)
1095 case EM_CYGNUS_M32R
:
1096 rtype
= elf_m32r_reloc_type (type
);
1101 rtype
= elf_i386_reloc_type (type
);
1106 rtype
= elf_m68hc11_reloc_type (type
);
1110 rtype
= elf_m68k_reloc_type (type
);
1114 rtype
= elf_i960_reloc_type (type
);
1119 rtype
= elf_avr_reloc_type (type
);
1122 case EM_OLD_SPARCV9
:
1123 case EM_SPARC32PLUS
:
1126 rtype
= elf_sparc_reloc_type (type
);
1130 case EM_CYGNUS_V850
:
1131 rtype
= v850_reloc_type (type
);
1135 case EM_CYGNUS_D10V
:
1136 rtype
= elf_d10v_reloc_type (type
);
1140 case EM_CYGNUS_D30V
:
1141 rtype
= elf_d30v_reloc_type (type
);
1145 rtype
= elf_dlx_reloc_type (type
);
1149 rtype
= elf_sh_reloc_type (type
);
1153 case EM_CYGNUS_MN10300
:
1154 rtype
= elf_mn10300_reloc_type (type
);
1158 case EM_CYGNUS_MN10200
:
1159 rtype
= elf_mn10200_reloc_type (type
);
1163 case EM_CYGNUS_FR30
:
1164 rtype
= elf_fr30_reloc_type (type
);
1168 rtype
= elf_frv_reloc_type (type
);
1172 rtype
= elf_mcore_reloc_type (type
);
1176 rtype
= elf_mmix_reloc_type (type
);
1181 rtype
= elf_msp430_reloc_type (type
);
1185 rtype
= elf_ppc_reloc_type (type
);
1189 rtype
= elf_ppc64_reloc_type (type
);
1193 case EM_MIPS_RS3_LE
:
1194 rtype
= elf_mips_reloc_type (type
);
1197 rtype2
= elf_mips_reloc_type (type2
);
1198 rtype3
= elf_mips_reloc_type (type3
);
1203 rtype
= elf_alpha_reloc_type (type
);
1207 rtype
= elf_arm_reloc_type (type
);
1211 rtype
= elf_arc_reloc_type (type
);
1215 rtype
= elf_hppa_reloc_type (type
);
1221 rtype
= elf_h8_reloc_type (type
);
1226 rtype
= elf_or32_reloc_type (type
);
1231 rtype
= elf_pj_reloc_type (type
);
1234 rtype
= elf_ia64_reloc_type (type
);
1238 rtype
= elf_cris_reloc_type (type
);
1242 rtype
= elf_i860_reloc_type (type
);
1246 rtype
= elf_x86_64_reloc_type (type
);
1250 rtype
= i370_reloc_type (type
);
1255 rtype
= elf_s390_reloc_type (type
);
1259 rtype
= elf_xstormy16_reloc_type (type
);
1263 rtype
= elf_vax_reloc_type (type
);
1268 rtype
= elf_ip2k_reloc_type (type
);
1272 rtype
= elf_iq2000_reloc_type (type
);
1277 #ifdef _bfd_int64_low
1278 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1280 printf (_("unrecognized: %-7lx"), type
);
1283 printf (do_wide
? "%-21.21s" : "%-17.17s", rtype
);
1287 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1288 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1291 Elf_Internal_Sym
*psym
;
1293 psym
= symtab
+ symtab_index
;
1296 print_vma (psym
->st_value
, LONG_HEX
);
1297 printf (is_32bit_elf
? " " : " ");
1299 if (psym
->st_name
== 0)
1301 const char *sec_name
= "<null>";
1304 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1306 bfd_vma sec_index
= (bfd_vma
) -1;
1308 if (psym
->st_shndx
< SHN_LORESERVE
)
1309 sec_index
= psym
->st_shndx
;
1310 else if (psym
->st_shndx
> SHN_LORESERVE
)
1311 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1314 if (sec_index
!= (bfd_vma
) -1)
1315 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1316 else if (psym
->st_shndx
== SHN_ABS
)
1318 else if (psym
->st_shndx
== SHN_COMMON
)
1319 sec_name
= "COMMON";
1322 sprintf (name_buf
, "<section 0x%x>",
1323 (unsigned int) psym
->st_shndx
);
1324 sec_name
= name_buf
;
1327 print_symbol (22, sec_name
);
1329 else if (strtab
== NULL
)
1330 printf (_("<string table index %3ld>"), psym
->st_name
);
1332 print_symbol (22, strtab
+ psym
->st_name
);
1335 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1340 printf ("%*c", is_32bit_elf
? (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1341 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1344 if (elf_header
.e_machine
== EM_SPARCV9
1345 && !strcmp (rtype
, "R_SPARC_OLO10"))
1346 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1350 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1352 printf (" Type2: ");
1355 #ifdef _bfd_int64_low
1356 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1358 printf (_("unrecognized: %-7lx"), type2
);
1361 printf ("%-17.17s", rtype2
);
1363 printf("\n Type3: ");
1366 #ifdef _bfd_int64_low
1367 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1369 printf (_("unrecognized: %-7lx"), type3
);
1372 printf ("%-17.17s", rtype3
);
1384 get_mips_dynamic_type (type
)
1389 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1390 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1391 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1392 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1393 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1394 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1395 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1396 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1397 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1398 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1399 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1400 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1401 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1402 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1403 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1404 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1405 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1406 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1407 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1408 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1409 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1410 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1411 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1412 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1413 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1414 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1415 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1416 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1417 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1418 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1419 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1420 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1421 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1422 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1423 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1424 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1425 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1426 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1427 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1428 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1429 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1430 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1431 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1438 get_sparc64_dynamic_type (type
)
1443 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1450 get_ppc64_dynamic_type (type
)
1455 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1456 case DT_PPC64_OPD
: return "PPC64_OPD";
1457 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1464 get_parisc_dynamic_type (type
)
1469 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1470 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1471 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1472 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1473 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1474 case DT_HP_PREINIT
: return "HP_PREINIT";
1475 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1476 case DT_HP_NEEDED
: return "HP_NEEDED";
1477 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1478 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1479 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1480 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1481 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1488 get_ia64_dynamic_type (type
)
1493 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1500 get_dynamic_type (type
)
1503 static char buff
[32];
1507 case DT_NULL
: return "NULL";
1508 case DT_NEEDED
: return "NEEDED";
1509 case DT_PLTRELSZ
: return "PLTRELSZ";
1510 case DT_PLTGOT
: return "PLTGOT";
1511 case DT_HASH
: return "HASH";
1512 case DT_STRTAB
: return "STRTAB";
1513 case DT_SYMTAB
: return "SYMTAB";
1514 case DT_RELA
: return "RELA";
1515 case DT_RELASZ
: return "RELASZ";
1516 case DT_RELAENT
: return "RELAENT";
1517 case DT_STRSZ
: return "STRSZ";
1518 case DT_SYMENT
: return "SYMENT";
1519 case DT_INIT
: return "INIT";
1520 case DT_FINI
: return "FINI";
1521 case DT_SONAME
: return "SONAME";
1522 case DT_RPATH
: return "RPATH";
1523 case DT_SYMBOLIC
: return "SYMBOLIC";
1524 case DT_REL
: return "REL";
1525 case DT_RELSZ
: return "RELSZ";
1526 case DT_RELENT
: return "RELENT";
1527 case DT_PLTREL
: return "PLTREL";
1528 case DT_DEBUG
: return "DEBUG";
1529 case DT_TEXTREL
: return "TEXTREL";
1530 case DT_JMPREL
: return "JMPREL";
1531 case DT_BIND_NOW
: return "BIND_NOW";
1532 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1533 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1534 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1535 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1536 case DT_RUNPATH
: return "RUNPATH";
1537 case DT_FLAGS
: return "FLAGS";
1539 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1540 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1542 case DT_CHECKSUM
: return "CHECKSUM";
1543 case DT_PLTPADSZ
: return "PLTPADSZ";
1544 case DT_MOVEENT
: return "MOVEENT";
1545 case DT_MOVESZ
: return "MOVESZ";
1546 case DT_FEATURE
: return "FEATURE";
1547 case DT_POSFLAG_1
: return "POSFLAG_1";
1548 case DT_SYMINSZ
: return "SYMINSZ";
1549 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1551 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1552 case DT_CONFIG
: return "CONFIG";
1553 case DT_DEPAUDIT
: return "DEPAUDIT";
1554 case DT_AUDIT
: return "AUDIT";
1555 case DT_PLTPAD
: return "PLTPAD";
1556 case DT_MOVETAB
: return "MOVETAB";
1557 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1559 case DT_VERSYM
: return "VERSYM";
1561 case DT_RELACOUNT
: return "RELACOUNT";
1562 case DT_RELCOUNT
: return "RELCOUNT";
1563 case DT_FLAGS_1
: return "FLAGS_1";
1564 case DT_VERDEF
: return "VERDEF";
1565 case DT_VERDEFNUM
: return "VERDEFNUM";
1566 case DT_VERNEED
: return "VERNEED";
1567 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1569 case DT_AUXILIARY
: return "AUXILIARY";
1570 case DT_USED
: return "USED";
1571 case DT_FILTER
: return "FILTER";
1573 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1574 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1575 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1576 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1577 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1580 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1584 switch (elf_header
.e_machine
)
1587 case EM_MIPS_RS3_LE
:
1588 result
= get_mips_dynamic_type (type
);
1591 result
= get_sparc64_dynamic_type (type
);
1594 result
= get_ppc64_dynamic_type (type
);
1597 result
= get_ia64_dynamic_type (type
);
1607 sprintf (buff
, _("Processor Specific: %lx"), type
);
1609 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1613 switch (elf_header
.e_machine
)
1616 result
= get_parisc_dynamic_type (type
);
1626 sprintf (buff
, _("Operating System specific: %lx"), type
);
1629 sprintf (buff
, _("<unknown>: %lx"), type
);
1636 get_file_type (e_type
)
1639 static char buff
[32];
1643 case ET_NONE
: return _("NONE (None)");
1644 case ET_REL
: return _("REL (Relocatable file)");
1645 case ET_EXEC
: return _("EXEC (Executable file)");
1646 case ET_DYN
: return _("DYN (Shared object file)");
1647 case ET_CORE
: return _("CORE (Core file)");
1650 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1651 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
1652 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1653 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
1655 sprintf (buff
, _("<unknown>: %x"), e_type
);
1661 get_machine_name (e_machine
)
1664 static char buff
[64]; /* XXX */
1668 case EM_NONE
: return _("None");
1669 case EM_M32
: return "WE32100";
1670 case EM_SPARC
: return "Sparc";
1671 case EM_386
: return "Intel 80386";
1672 case EM_68K
: return "MC68000";
1673 case EM_88K
: return "MC88000";
1674 case EM_486
: return "Intel 80486";
1675 case EM_860
: return "Intel 80860";
1676 case EM_MIPS
: return "MIPS R3000";
1677 case EM_S370
: return "IBM System/370";
1678 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1679 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1680 case EM_PARISC
: return "HPPA";
1681 case EM_PPC_OLD
: return "Power PC (old)";
1682 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1683 case EM_960
: return "Intel 90860";
1684 case EM_PPC
: return "PowerPC";
1685 case EM_PPC64
: return "PowerPC64";
1686 case EM_V800
: return "NEC V800";
1687 case EM_FR20
: return "Fujitsu FR20";
1688 case EM_RH32
: return "TRW RH32";
1689 case EM_MCORE
: return "MCORE";
1690 case EM_ARM
: return "ARM";
1691 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1692 case EM_SH
: return "Hitachi SH";
1693 case EM_SPARCV9
: return "Sparc v9";
1694 case EM_TRICORE
: return "Siemens Tricore";
1695 case EM_ARC
: return "ARC";
1696 case EM_H8_300
: return "Hitachi H8/300";
1697 case EM_H8_300H
: return "Hitachi H8/300H";
1698 case EM_H8S
: return "Hitachi H8S";
1699 case EM_H8_500
: return "Hitachi H8/500";
1700 case EM_IA_64
: return "Intel IA-64";
1701 case EM_MIPS_X
: return "Stanford MIPS-X";
1702 case EM_COLDFIRE
: return "Motorola Coldfire";
1703 case EM_68HC12
: return "Motorola M68HC12";
1704 case EM_ALPHA
: return "Alpha";
1705 case EM_CYGNUS_D10V
:
1706 case EM_D10V
: return "d10v";
1707 case EM_CYGNUS_D30V
:
1708 case EM_D30V
: return "d30v";
1709 case EM_CYGNUS_M32R
:
1710 case EM_M32R
: return "Mitsubishi M32r";
1711 case EM_CYGNUS_V850
:
1712 case EM_V850
: return "NEC v850";
1713 case EM_CYGNUS_MN10300
:
1714 case EM_MN10300
: return "mn10300";
1715 case EM_CYGNUS_MN10200
:
1716 case EM_MN10200
: return "mn10200";
1717 case EM_CYGNUS_FR30
:
1718 case EM_FR30
: return "Fujitsu FR30";
1719 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1721 case EM_PJ
: return "picoJava";
1722 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1723 case EM_PCP
: return "Siemens PCP";
1724 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1725 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1726 case EM_STARCORE
: return "Motorola Star*Core processor";
1727 case EM_ME16
: return "Toyota ME16 processor";
1728 case EM_ST100
: return "STMicroelectronics ST100 processor";
1729 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1730 case EM_FX66
: return "Siemens FX66 microcontroller";
1731 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1732 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1733 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1734 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1735 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1736 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1737 case EM_SVX
: return "Silicon Graphics SVx";
1738 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1739 case EM_VAX
: return "Digital VAX";
1741 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1742 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1743 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1744 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1745 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1746 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1747 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1748 case EM_PRISM
: return "Vitesse Prism";
1749 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1751 case EM_S390
: return "IBM S/390";
1752 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1754 case EM_OR32
: return "OpenRISC";
1755 case EM_DLX
: return "OpenDLX";
1757 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1758 case EM_IQ2000
: return "Vitesse IQ2000";
1760 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1766 decode_ARM_machine_flags (e_flags
, buf
)
1773 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1774 e_flags
&= ~ EF_ARM_EABIMASK
;
1776 /* Handle "generic" ARM flags. */
1777 if (e_flags
& EF_ARM_RELEXEC
)
1779 strcat (buf
, ", relocatable executable");
1780 e_flags
&= ~ EF_ARM_RELEXEC
;
1783 if (e_flags
& EF_ARM_HASENTRY
)
1785 strcat (buf
, ", has entry point");
1786 e_flags
&= ~ EF_ARM_HASENTRY
;
1789 /* Now handle EABI specific flags. */
1793 strcat (buf
, ", <unrecognized EABI>");
1798 case EF_ARM_EABI_VER1
:
1799 strcat (buf
, ", Version1 EABI");
1804 /* Process flags one bit at a time. */
1805 flag
= e_flags
& - e_flags
;
1810 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1811 strcat (buf
, ", sorted symbol tables");
1821 case EF_ARM_EABI_VER2
:
1822 strcat (buf
, ", Version2 EABI");
1827 /* Process flags one bit at a time. */
1828 flag
= e_flags
& - e_flags
;
1833 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1834 strcat (buf
, ", sorted symbol tables");
1837 case EF_ARM_DYNSYMSUSESEGIDX
:
1838 strcat (buf
, ", dynamic symbols use segment index");
1841 case EF_ARM_MAPSYMSFIRST
:
1842 strcat (buf
, ", mapping symbols precede others");
1852 case EF_ARM_EABI_UNKNOWN
:
1853 strcat (buf
, ", GNU EABI");
1858 /* Process flags one bit at a time. */
1859 flag
= e_flags
& - e_flags
;
1864 case EF_ARM_INTERWORK
:
1865 strcat (buf
, ", interworking enabled");
1868 case EF_ARM_APCS_26
:
1869 strcat (buf
, ", uses APCS/26");
1872 case EF_ARM_APCS_FLOAT
:
1873 strcat (buf
, ", uses APCS/float");
1877 strcat (buf
, ", position independent");
1881 strcat (buf
, ", 8 bit structure alignment");
1884 case EF_ARM_NEW_ABI
:
1885 strcat (buf
, ", uses new ABI");
1888 case EF_ARM_OLD_ABI
:
1889 strcat (buf
, ", uses old ABI");
1892 case EF_ARM_SOFT_FLOAT
:
1893 strcat (buf
, ", software FP");
1896 case EF_ARM_MAVERICK_FLOAT
:
1897 strcat (buf
, ", Maverick FP");
1908 strcat (buf
,", <unknown>");
1912 get_machine_flags (e_flags
, e_machine
)
1916 static char buf
[1024];
1928 decode_ARM_machine_flags (e_flags
, buf
);
1932 if (e_flags
& EF_CPU32
)
1933 strcat (buf
, ", cpu32");
1934 if (e_flags
& EF_M68000
)
1935 strcat (buf
, ", m68000");
1939 if (e_flags
& EF_PPC_EMB
)
1940 strcat (buf
, ", emb");
1942 if (e_flags
& EF_PPC_RELOCATABLE
)
1943 strcat (buf
, ", relocatable");
1945 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1946 strcat (buf
, ", relocatable-lib");
1950 case EM_CYGNUS_V850
:
1951 switch (e_flags
& EF_V850_ARCH
)
1954 strcat (buf
, ", v850e");
1957 strcat (buf
, ", v850");
1960 strcat (buf
, ", unknown v850 architecture variant");
1966 case EM_CYGNUS_M32R
:
1967 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1968 strcat (buf
, ", m32r");
1973 case EM_MIPS_RS3_LE
:
1974 if (e_flags
& EF_MIPS_NOREORDER
)
1975 strcat (buf
, ", noreorder");
1977 if (e_flags
& EF_MIPS_PIC
)
1978 strcat (buf
, ", pic");
1980 if (e_flags
& EF_MIPS_CPIC
)
1981 strcat (buf
, ", cpic");
1983 if (e_flags
& EF_MIPS_UCODE
)
1984 strcat (buf
, ", ugen_reserved");
1986 if (e_flags
& EF_MIPS_ABI2
)
1987 strcat (buf
, ", abi2");
1989 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
1990 strcat (buf
, ", odk first");
1992 if (e_flags
& EF_MIPS_32BITMODE
)
1993 strcat (buf
, ", 32bitmode");
1995 switch ((e_flags
& EF_MIPS_MACH
))
1997 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
1998 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
1999 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2000 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2001 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2002 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2003 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2004 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2005 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2007 /* We simply ignore the field in this case to avoid confusion:
2008 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2011 default: strcat (buf
, ", unknown CPU"); break;
2014 switch ((e_flags
& EF_MIPS_ABI
))
2016 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2017 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2018 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2019 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2021 /* We simply ignore the field in this case to avoid confusion:
2022 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2023 This means it is likely to be an o32 file, but not for
2026 default: strcat (buf
, ", unknown ABI"); break;
2029 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2030 strcat (buf
, ", mdmx");
2032 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2033 strcat (buf
, ", mips16");
2035 switch ((e_flags
& EF_MIPS_ARCH
))
2037 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2038 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2039 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2040 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2041 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2042 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2043 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2044 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2045 default: strcat (buf
, ", unknown ISA"); break;
2051 if (e_flags
& EF_SPARC_32PLUS
)
2052 strcat (buf
, ", v8+");
2054 if (e_flags
& EF_SPARC_SUN_US1
)
2055 strcat (buf
, ", ultrasparcI");
2057 if (e_flags
& EF_SPARC_SUN_US3
)
2058 strcat (buf
, ", ultrasparcIII");
2060 if (e_flags
& EF_SPARC_HAL_R1
)
2061 strcat (buf
, ", halr1");
2063 if (e_flags
& EF_SPARC_LEDATA
)
2064 strcat (buf
, ", ledata");
2066 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2067 strcat (buf
, ", tso");
2069 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2070 strcat (buf
, ", pso");
2072 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2073 strcat (buf
, ", rmo");
2077 switch (e_flags
& EF_PARISC_ARCH
)
2079 case EFA_PARISC_1_0
:
2080 strcpy (buf
, ", PA-RISC 1.0");
2082 case EFA_PARISC_1_1
:
2083 strcpy (buf
, ", PA-RISC 1.1");
2085 case EFA_PARISC_2_0
:
2086 strcpy (buf
, ", PA-RISC 2.0");
2091 if (e_flags
& EF_PARISC_TRAPNIL
)
2092 strcat (buf
, ", trapnil");
2093 if (e_flags
& EF_PARISC_EXT
)
2094 strcat (buf
, ", ext");
2095 if (e_flags
& EF_PARISC_LSB
)
2096 strcat (buf
, ", lsb");
2097 if (e_flags
& EF_PARISC_WIDE
)
2098 strcat (buf
, ", wide");
2099 if (e_flags
& EF_PARISC_NO_KABP
)
2100 strcat (buf
, ", no kabp");
2101 if (e_flags
& EF_PARISC_LAZYSWAP
)
2102 strcat (buf
, ", lazyswap");
2107 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2108 strcat (buf
, ", new calling convention");
2110 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2111 strcat (buf
, ", gnu calling convention");
2115 if ((e_flags
& EF_IA_64_ABI64
))
2116 strcat (buf
, ", 64-bit");
2118 strcat (buf
, ", 32-bit");
2119 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2120 strcat (buf
, ", reduced fp model");
2121 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2122 strcat (buf
, ", no function descriptors, constant gp");
2123 else if ((e_flags
& EF_IA_64_CONS_GP
))
2124 strcat (buf
, ", constant gp");
2125 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2126 strcat (buf
, ", absolute");
2130 if ((e_flags
& EF_VAX_NONPIC
))
2131 strcat (buf
, ", non-PIC");
2132 if ((e_flags
& EF_VAX_DFLOAT
))
2133 strcat (buf
, ", D-Float");
2134 if ((e_flags
& EF_VAX_GFLOAT
))
2135 strcat (buf
, ", G-Float");
2144 get_mips_segment_type (type
)
2149 case PT_MIPS_REGINFO
:
2151 case PT_MIPS_RTPROC
:
2153 case PT_MIPS_OPTIONS
:
2163 get_parisc_segment_type (type
)
2168 case PT_HP_TLS
: return "HP_TLS";
2169 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2170 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2171 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2172 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2173 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2174 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2175 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2176 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2177 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2178 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2179 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2180 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2181 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2190 get_ia64_segment_type (type
)
2195 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2196 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2197 case PT_HP_TLS
: return "HP_TLS";
2198 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2199 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2200 case PT_IA_64_HP_STACK
: return "HP_STACK";
2209 get_segment_type (p_type
)
2210 unsigned long p_type
;
2212 static char buff
[32];
2216 case PT_NULL
: return "NULL";
2217 case PT_LOAD
: return "LOAD";
2218 case PT_DYNAMIC
: return "DYNAMIC";
2219 case PT_INTERP
: return "INTERP";
2220 case PT_NOTE
: return "NOTE";
2221 case PT_SHLIB
: return "SHLIB";
2222 case PT_PHDR
: return "PHDR";
2223 case PT_TLS
: return "TLS";
2225 case PT_GNU_EH_FRAME
:
2226 return "GNU_EH_FRAME";
2229 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2233 switch (elf_header
.e_machine
)
2236 case EM_MIPS_RS3_LE
:
2237 result
= get_mips_segment_type (p_type
);
2240 result
= get_parisc_segment_type (p_type
);
2243 result
= get_ia64_segment_type (p_type
);
2253 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2255 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2259 switch (elf_header
.e_machine
)
2262 result
= get_parisc_segment_type (p_type
);
2265 result
= get_ia64_segment_type (p_type
);
2275 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2278 sprintf (buff
, _("<unknown>: %lx"), p_type
);
2285 get_mips_section_type_name (sh_type
)
2286 unsigned int sh_type
;
2290 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2291 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2292 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2293 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2294 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2295 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2296 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2297 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2298 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2299 case SHT_MIPS_RELD
: return "MIPS_RELD";
2300 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2301 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2302 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2303 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2304 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2305 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2306 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2307 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2308 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2309 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2310 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2311 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2312 case SHT_MIPS_LINE
: return "MIPS_LINE";
2313 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2314 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2315 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2316 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2317 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2318 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2319 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2320 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2321 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2322 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2323 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2324 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2325 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2326 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2327 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2328 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2336 get_parisc_section_type_name (sh_type
)
2337 unsigned int sh_type
;
2341 case SHT_PARISC_EXT
: return "PARISC_EXT";
2342 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2343 case SHT_PARISC_DOC
: return "PARISC_DOC";
2351 get_ia64_section_type_name (sh_type
)
2352 unsigned int sh_type
;
2354 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2355 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2356 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2360 case SHT_IA_64_EXT
: return "IA_64_EXT";
2361 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2362 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2370 get_section_type_name (sh_type
)
2371 unsigned int sh_type
;
2373 static char buff
[32];
2377 case SHT_NULL
: return "NULL";
2378 case SHT_PROGBITS
: return "PROGBITS";
2379 case SHT_SYMTAB
: return "SYMTAB";
2380 case SHT_STRTAB
: return "STRTAB";
2381 case SHT_RELA
: return "RELA";
2382 case SHT_HASH
: return "HASH";
2383 case SHT_DYNAMIC
: return "DYNAMIC";
2384 case SHT_NOTE
: return "NOTE";
2385 case SHT_NOBITS
: return "NOBITS";
2386 case SHT_REL
: return "REL";
2387 case SHT_SHLIB
: return "SHLIB";
2388 case SHT_DYNSYM
: return "DYNSYM";
2389 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2390 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2391 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2392 case SHT_GROUP
: return "GROUP";
2393 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2394 case SHT_GNU_verdef
: return "VERDEF";
2395 case SHT_GNU_verneed
: return "VERNEED";
2396 case SHT_GNU_versym
: return "VERSYM";
2397 case 0x6ffffff0: return "VERSYM";
2398 case 0x6ffffffc: return "VERDEF";
2399 case 0x7ffffffd: return "AUXILIARY";
2400 case 0x7fffffff: return "FILTER";
2401 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2404 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2408 switch (elf_header
.e_machine
)
2411 case EM_MIPS_RS3_LE
:
2412 result
= get_mips_section_type_name (sh_type
);
2415 result
= get_parisc_section_type_name (sh_type
);
2418 result
= get_ia64_section_type_name (sh_type
);
2428 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2430 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2431 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2432 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2433 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2435 sprintf (buff
, _("<unknown>: %x"), sh_type
);
2441 #define OPTION_DEBUG_DUMP 512
2443 struct option options
[] =
2445 {"all", no_argument
, 0, 'a'},
2446 {"file-header", no_argument
, 0, 'h'},
2447 {"program-headers", no_argument
, 0, 'l'},
2448 {"headers", no_argument
, 0, 'e'},
2449 {"histogram", no_argument
, 0, 'I'},
2450 {"segments", no_argument
, 0, 'l'},
2451 {"sections", no_argument
, 0, 'S'},
2452 {"section-headers", no_argument
, 0, 'S'},
2453 {"symbols", no_argument
, 0, 's'},
2454 {"syms", no_argument
, 0, 's'},
2455 {"relocs", no_argument
, 0, 'r'},
2456 {"notes", no_argument
, 0, 'n'},
2457 {"dynamic", no_argument
, 0, 'd'},
2458 {"arch-specific", no_argument
, 0, 'A'},
2459 {"version-info", no_argument
, 0, 'V'},
2460 {"use-dynamic", no_argument
, 0, 'D'},
2461 {"hex-dump", required_argument
, 0, 'x'},
2462 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2463 {"unwind", no_argument
, 0, 'u'},
2464 #ifdef SUPPORT_DISASSEMBLY
2465 {"instruction-dump", required_argument
, 0, 'i'},
2468 {"version", no_argument
, 0, 'v'},
2469 {"wide", no_argument
, 0, 'W'},
2470 {"help", no_argument
, 0, 'H'},
2471 {0, no_argument
, 0, 0}
2477 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2478 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2479 fprintf (stdout
, _(" Options are:\n\
2480 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2481 -h --file-header Display the ELF file header\n\
2482 -l --program-headers Display the program headers\n\
2483 --segments An alias for --program-headers\n\
2484 -S --section-headers Display the sections' header\n\
2485 --sections An alias for --section-headers\n\
2486 -e --headers Equivalent to: -h -l -S\n\
2487 -s --syms Display the symbol table\n\
2488 --symbols An alias for --syms\n\
2489 -n --notes Display the core notes (if present)\n\
2490 -r --relocs Display the relocations (if present)\n\
2491 -u --unwind Display the unwind info (if present)\n\
2492 -d --dynamic Display the dynamic segment (if present)\n\
2493 -V --version-info Display the version sections (if present)\n\
2494 -A --arch-specific Display architecture specific information (if any).\n\
2495 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2496 -x --hex-dump=<number> Dump the contents of section <number>\n\
2497 -w[liaprmfFso] or\n\
2498 --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
2499 Display the contents of DWARF2 debug sections\n"));
2500 #ifdef SUPPORT_DISASSEMBLY
2501 fprintf (stdout
, _("\
2502 -i --instruction-dump=<number>\n\
2503 Disassemble the contents of section <number>\n"));
2505 fprintf (stdout
, _("\
2506 -I --histogram Display histogram of bucket list lengths\n\
2507 -W --wide Allow output width to exceed 80 characters\n\
2508 -H --help Display this information\n\
2509 -v --version Display the version number of readelf\n"));
2510 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2516 request_dump (section
, type
)
2517 unsigned int section
;
2520 if (section
>= num_dump_sects
)
2522 char *new_dump_sects
;
2524 new_dump_sects
= (char *) calloc (section
+ 1, 1);
2526 if (new_dump_sects
== NULL
)
2527 error (_("Out of memory allocating dump request table."));
2530 /* Copy current flag settings. */
2531 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2535 dump_sects
= new_dump_sects
;
2536 num_dump_sects
= section
+ 1;
2541 dump_sects
[section
] |= type
;
2547 parse_args (argc
, argv
)
2556 while ((c
= getopt_long
2557 (argc
, argv
, "ersuahnldSDAIw::x:i:vVWH", options
, NULL
)) != EOF
)
2624 section
= strtoul (optarg
, & cp
, 0);
2625 if (! *cp
&& section
>= 0)
2627 request_dump (section
, HEX_DUMP
);
2637 unsigned int index
= 0;
2641 while (optarg
[index
])
2642 switch (optarg
[index
++])
2651 do_debug_abbrevs
= 1;
2661 do_debug_pubnames
= 1;
2666 do_debug_aranges
= 1;
2670 do_debug_frames_interp
= 1;
2672 do_debug_frames
= 1;
2677 do_debug_macinfo
= 1;
2691 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2696 case OPTION_DEBUG_DUMP
:
2702 static const char *debug_dump_opt
[]
2703 = { "line", "info", "abbrev", "pubnames", "ranges",
2704 "macro", "frames", "frames-interp", "str", "loc", NULL
};
2713 for (index
= 0; debug_dump_opt
[index
]; index
++)
2715 size_t len
= strlen (debug_dump_opt
[index
]);
2717 if (strncmp (p
, debug_dump_opt
[index
], len
) == 0
2718 && (p
[len
] == ',' || p
[len
] == '\0'))
2727 do_debug_abbrevs
= 1;
2738 do_debug_pubnames
= 1;
2742 do_debug_aranges
= 1;
2747 do_debug_frames_interp
= 1;
2748 do_debug_frames
= 1;
2752 do_debug_macinfo
= 1;
2765 if (debug_dump_opt
[index
] == NULL
)
2767 warn (_("Unrecognized debug option '%s'\n"), p
);
2768 p
= strchr (p
, ',');
2778 #ifdef SUPPORT_DISASSEMBLY
2781 section
= strtoul (optarg
, & cp
, 0);
2782 if (! *cp
&& section
>= 0)
2784 request_dump (section
, DISASS_DUMP
);
2790 print_version (program_name
);
2800 /* xgettext:c-format */
2801 error (_("Invalid option '-%c'\n"), c
);
2808 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2809 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2810 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
)
2814 warn (_("Nothing to do.\n"));
2820 get_elf_class (elf_class
)
2821 unsigned int elf_class
;
2823 static char buff
[32];
2827 case ELFCLASSNONE
: return _("none");
2828 case ELFCLASS32
: return "ELF32";
2829 case ELFCLASS64
: return "ELF64";
2831 sprintf (buff
, _("<unknown: %x>"), elf_class
);
2837 get_data_encoding (encoding
)
2838 unsigned int encoding
;
2840 static char buff
[32];
2844 case ELFDATANONE
: return _("none");
2845 case ELFDATA2LSB
: return _("2's complement, little endian");
2846 case ELFDATA2MSB
: return _("2's complement, big endian");
2848 sprintf (buff
, _("<unknown: %x>"), encoding
);
2854 get_osabi_name (osabi
)
2857 static char buff
[32];
2861 case ELFOSABI_NONE
: return "UNIX - System V";
2862 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2863 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2864 case ELFOSABI_LINUX
: return "UNIX - Linux";
2865 case ELFOSABI_HURD
: return "GNU/Hurd";
2866 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2867 case ELFOSABI_AIX
: return "UNIX - AIX";
2868 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2869 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2870 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2871 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2872 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2873 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2874 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2875 case ELFOSABI_AROS
: return "Amiga Research OS";
2876 case ELFOSABI_STANDALONE
: return _("Standalone App");
2877 case ELFOSABI_ARM
: return "ARM";
2879 sprintf (buff
, _("<unknown: %x>"), osabi
);
2884 /* Decode the data held in 'elf_header'. */
2887 process_file_header ()
2889 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2890 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2891 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2892 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2895 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2903 printf (_("ELF Header:\n"));
2904 printf (_(" Magic: "));
2905 for (i
= 0; i
< EI_NIDENT
; i
++)
2906 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2908 printf (_(" Class: %s\n"),
2909 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2910 printf (_(" Data: %s\n"),
2911 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2912 printf (_(" Version: %d %s\n"),
2913 elf_header
.e_ident
[EI_VERSION
],
2914 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
2916 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
2919 printf (_(" OS/ABI: %s\n"),
2920 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
2921 printf (_(" ABI Version: %d\n"),
2922 elf_header
.e_ident
[EI_ABIVERSION
]);
2923 printf (_(" Type: %s\n"),
2924 get_file_type (elf_header
.e_type
));
2925 printf (_(" Machine: %s\n"),
2926 get_machine_name (elf_header
.e_machine
));
2927 printf (_(" Version: 0x%lx\n"),
2928 (unsigned long) elf_header
.e_version
);
2930 printf (_(" Entry point address: "));
2931 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2932 printf (_("\n Start of program headers: "));
2933 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2934 printf (_(" (bytes into file)\n Start of section headers: "));
2935 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
2936 printf (_(" (bytes into file)\n"));
2938 printf (_(" Flags: 0x%lx%s\n"),
2939 (unsigned long) elf_header
.e_flags
,
2940 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
2941 printf (_(" Size of this header: %ld (bytes)\n"),
2942 (long) elf_header
.e_ehsize
);
2943 printf (_(" Size of program headers: %ld (bytes)\n"),
2944 (long) elf_header
.e_phentsize
);
2945 printf (_(" Number of program headers: %ld\n"),
2946 (long) elf_header
.e_phnum
);
2947 printf (_(" Size of section headers: %ld (bytes)\n"),
2948 (long) elf_header
.e_shentsize
);
2949 printf (_(" Number of section headers: %ld"),
2950 (long) elf_header
.e_shnum
);
2951 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
2952 printf (" (%ld)", (long) section_headers
[0].sh_size
);
2953 putc ('\n', stdout
);
2954 printf (_(" Section header string table index: %ld"),
2955 (long) elf_header
.e_shstrndx
);
2956 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
2957 printf (" (%ld)", (long) section_headers
[0].sh_link
);
2958 putc ('\n', stdout
);
2961 if (section_headers
!= NULL
)
2963 if (elf_header
.e_shnum
== 0)
2964 elf_header
.e_shnum
= section_headers
[0].sh_size
;
2965 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
2966 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
2967 free (section_headers
);
2968 section_headers
= NULL
;
2976 get_32bit_program_headers (file
, program_headers
)
2978 Elf_Internal_Phdr
*program_headers
;
2980 Elf32_External_Phdr
*phdrs
;
2981 Elf32_External_Phdr
*external
;
2982 Elf_Internal_Phdr
*internal
;
2985 phdrs
= ((Elf32_External_Phdr
*)
2986 get_data (NULL
, file
, elf_header
.e_phoff
,
2987 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2988 _("program headers")));
2992 for (i
= 0, internal
= program_headers
, external
= phdrs
;
2993 i
< elf_header
.e_phnum
;
2994 i
++, internal
++, external
++)
2996 internal
->p_type
= BYTE_GET (external
->p_type
);
2997 internal
->p_offset
= BYTE_GET (external
->p_offset
);
2998 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
2999 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3000 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3001 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3002 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3003 internal
->p_align
= BYTE_GET (external
->p_align
);
3012 get_64bit_program_headers (file
, program_headers
)
3014 Elf_Internal_Phdr
*program_headers
;
3016 Elf64_External_Phdr
*phdrs
;
3017 Elf64_External_Phdr
*external
;
3018 Elf_Internal_Phdr
*internal
;
3021 phdrs
= ((Elf64_External_Phdr
*)
3022 get_data (NULL
, file
, elf_header
.e_phoff
,
3023 elf_header
.e_phentsize
* elf_header
.e_phnum
,
3024 _("program headers")));
3028 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3029 i
< elf_header
.e_phnum
;
3030 i
++, internal
++, external
++)
3032 internal
->p_type
= BYTE_GET (external
->p_type
);
3033 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3034 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
3035 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
3036 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
3037 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
3038 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
3039 internal
->p_align
= BYTE_GET8 (external
->p_align
);
3047 /* Returns 1 if the program headers were loaded. */
3050 process_program_headers (file
)
3053 Elf_Internal_Phdr
*program_headers
;
3054 Elf_Internal_Phdr
*segment
;
3057 if (elf_header
.e_phnum
== 0)
3060 printf (_("\nThere are no program headers in this file.\n"));
3064 if (do_segments
&& !do_header
)
3066 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3067 printf (_("Entry point "));
3068 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3069 printf (_("\nThere are %d program headers, starting at offset "),
3070 elf_header
.e_phnum
);
3071 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3075 program_headers
= (Elf_Internal_Phdr
*) malloc
3076 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
3078 if (program_headers
== NULL
)
3080 error (_("Out of memory\n"));
3085 i
= get_32bit_program_headers (file
, program_headers
);
3087 i
= get_64bit_program_headers (file
, program_headers
);
3091 free (program_headers
);
3097 if (elf_header
.e_phnum
> 1)
3098 printf (_("\nProgram Headers:\n"));
3100 printf (_("\nProgram Headers:\n"));
3104 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3107 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3111 (_(" Type Offset VirtAddr PhysAddr\n"));
3113 (_(" FileSiz MemSiz Flags Align\n"));
3121 for (i
= 0, segment
= program_headers
;
3122 i
< elf_header
.e_phnum
;
3127 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3131 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3132 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3133 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3134 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3135 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3137 (segment
->p_flags
& PF_R
? 'R' : ' '),
3138 (segment
->p_flags
& PF_W
? 'W' : ' '),
3139 (segment
->p_flags
& PF_X
? 'E' : ' '));
3140 printf ("%#lx", (unsigned long) segment
->p_align
);
3144 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3145 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3148 print_vma (segment
->p_offset
, FULL_HEX
);
3152 print_vma (segment
->p_vaddr
, FULL_HEX
);
3154 print_vma (segment
->p_paddr
, FULL_HEX
);
3157 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3158 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3161 print_vma (segment
->p_filesz
, FULL_HEX
);
3165 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3166 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3169 print_vma (segment
->p_offset
, FULL_HEX
);
3173 (segment
->p_flags
& PF_R
? 'R' : ' '),
3174 (segment
->p_flags
& PF_W
? 'W' : ' '),
3175 (segment
->p_flags
& PF_X
? 'E' : ' '));
3177 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3178 printf ("%#lx", (unsigned long) segment
->p_align
);
3181 print_vma (segment
->p_align
, PREFIX_HEX
);
3186 print_vma (segment
->p_offset
, FULL_HEX
);
3188 print_vma (segment
->p_vaddr
, FULL_HEX
);
3190 print_vma (segment
->p_paddr
, FULL_HEX
);
3192 print_vma (segment
->p_filesz
, FULL_HEX
);
3194 print_vma (segment
->p_memsz
, FULL_HEX
);
3196 (segment
->p_flags
& PF_R
? 'R' : ' '),
3197 (segment
->p_flags
& PF_W
? 'W' : ' '),
3198 (segment
->p_flags
& PF_X
? 'E' : ' '));
3199 print_vma (segment
->p_align
, HEX
);
3203 switch (segment
->p_type
)
3208 unsigned long align_mask
= -segment
->p_align
;
3210 if (align_mask
== 0)
3212 loadaddr
= ((segment
->p_vaddr
& align_mask
)
3213 - (segment
->p_offset
& align_mask
));
3219 error (_("more than one dynamic segment\n"));
3221 dynamic_addr
= segment
->p_offset
;
3222 dynamic_size
= segment
->p_filesz
;
3226 if (fseek (file
, (long) segment
->p_offset
, SEEK_SET
))
3227 error (_("Unable to find program interpreter name\n"));
3230 program_interpreter
[0] = 0;
3231 fscanf (file
, "%63s", program_interpreter
);
3234 printf (_("\n [Requesting program interpreter: %s]"),
3235 program_interpreter
);
3241 putc ('\n', stdout
);
3250 if (do_segments
&& section_headers
!= NULL
)
3252 printf (_("\n Section to Segment mapping:\n"));
3253 printf (_(" Segment Sections...\n"));
3255 assert (string_table
!= NULL
);
3257 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3260 Elf_Internal_Shdr
*section
;
3262 segment
= program_headers
+ i
;
3263 section
= section_headers
;
3265 printf (" %2.2d ", i
);
3267 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3269 if (section
->sh_size
> 0
3270 /* Compare allocated sections by VMA, unallocated
3271 sections by file offset. */
3272 && (section
->sh_flags
& SHF_ALLOC
3273 ? (section
->sh_addr
>= segment
->p_vaddr
3274 && section
->sh_addr
+ section
->sh_size
3275 <= segment
->p_vaddr
+ segment
->p_memsz
)
3276 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3277 && (section
->sh_offset
+ section
->sh_size
3278 <= segment
->p_offset
+ segment
->p_filesz
))))
3279 printf ("%s ", SECTION_NAME (section
));
3286 free (program_headers
);
3293 get_32bit_section_headers (file
, num
)
3297 Elf32_External_Shdr
*shdrs
;
3298 Elf_Internal_Shdr
*internal
;
3301 shdrs
= ((Elf32_External_Shdr
*)
3302 get_data (NULL
, file
, elf_header
.e_shoff
,
3303 elf_header
.e_shentsize
* num
,
3304 _("section headers")));
3308 section_headers
= ((Elf_Internal_Shdr
*)
3309 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3311 if (section_headers
== NULL
)
3313 error (_("Out of memory\n"));
3317 for (i
= 0, internal
= section_headers
;
3321 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3322 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3323 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3324 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3325 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3326 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3327 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3328 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3329 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3330 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3339 get_64bit_section_headers (file
, num
)
3343 Elf64_External_Shdr
*shdrs
;
3344 Elf_Internal_Shdr
*internal
;
3347 shdrs
= ((Elf64_External_Shdr
*)
3348 get_data (NULL
, file
, elf_header
.e_shoff
,
3349 elf_header
.e_shentsize
* num
,
3350 _("section headers")));
3354 section_headers
= ((Elf_Internal_Shdr
*)
3355 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3357 if (section_headers
== NULL
)
3359 error (_("Out of memory\n"));
3363 for (i
= 0, internal
= section_headers
;
3367 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3368 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3369 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
3370 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
3371 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
3372 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
3373 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3374 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3375 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3376 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3384 static Elf_Internal_Sym
*
3385 get_32bit_elf_symbols (file
, section
)
3387 Elf_Internal_Shdr
*section
;
3389 unsigned long number
;
3390 Elf32_External_Sym
*esyms
;
3391 Elf_External_Sym_Shndx
*shndx
;
3392 Elf_Internal_Sym
*isyms
;
3393 Elf_Internal_Sym
*psym
;
3396 esyms
= ((Elf32_External_Sym
*)
3397 get_data (NULL
, file
, section
->sh_offset
,
3398 section
->sh_size
, _("symbols")));
3403 if (symtab_shndx_hdr
!= NULL
3404 && (symtab_shndx_hdr
->sh_link
3405 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3407 shndx
= ((Elf_External_Sym_Shndx
*)
3408 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3409 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3417 number
= section
->sh_size
/ section
->sh_entsize
;
3418 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3422 error (_("Out of memory\n"));
3429 for (j
= 0, psym
= isyms
;
3433 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3434 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3435 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3436 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3437 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3439 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3440 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3441 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3451 static Elf_Internal_Sym
*
3452 get_64bit_elf_symbols (file
, section
)
3454 Elf_Internal_Shdr
*section
;
3456 unsigned long number
;
3457 Elf64_External_Sym
*esyms
;
3458 Elf_External_Sym_Shndx
*shndx
;
3459 Elf_Internal_Sym
*isyms
;
3460 Elf_Internal_Sym
*psym
;
3463 esyms
= ((Elf64_External_Sym
*)
3464 get_data (NULL
, file
, section
->sh_offset
,
3465 section
->sh_size
, _("symbols")));
3470 if (symtab_shndx_hdr
!= NULL
3471 && (symtab_shndx_hdr
->sh_link
3472 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3474 shndx
= ((Elf_External_Sym_Shndx
*)
3475 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3476 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3484 number
= section
->sh_size
/ section
->sh_entsize
;
3485 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3489 error (_("Out of memory\n"));
3496 for (j
= 0, psym
= isyms
;
3500 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3501 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3502 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3503 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3504 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3506 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3507 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
3508 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
3519 get_elf_section_flags (sh_flags
)
3522 static char buff
[32];
3530 flag
= sh_flags
& - sh_flags
;
3535 case SHF_WRITE
: strcat (buff
, "W"); break;
3536 case SHF_ALLOC
: strcat (buff
, "A"); break;
3537 case SHF_EXECINSTR
: strcat (buff
, "X"); break;
3538 case SHF_MERGE
: strcat (buff
, "M"); break;
3539 case SHF_STRINGS
: strcat (buff
, "S"); break;
3540 case SHF_INFO_LINK
: strcat (buff
, "I"); break;
3541 case SHF_LINK_ORDER
: strcat (buff
, "L"); break;
3542 case SHF_OS_NONCONFORMING
: strcat (buff
, "O"); break;
3543 case SHF_GROUP
: strcat (buff
, "G"); break;
3544 case SHF_TLS
: strcat (buff
, "T"); break;
3547 if (flag
& SHF_MASKOS
)
3550 sh_flags
&= ~ SHF_MASKOS
;
3552 else if (flag
& SHF_MASKPROC
)
3555 sh_flags
&= ~ SHF_MASKPROC
;
3567 process_section_headers (file
)
3570 Elf_Internal_Shdr
*section
;
3573 section_headers
= NULL
;
3575 if (elf_header
.e_shnum
== 0)
3578 printf (_("\nThere are no sections in this file.\n"));
3583 if (do_sections
&& !do_header
)
3584 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3585 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3589 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3592 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3595 /* Read in the string table, so that we have names to display. */
3596 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3598 if (section
->sh_size
!= 0)
3600 string_table
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3601 section
->sh_size
, _("string table"));
3603 string_table_length
= section
->sh_size
;
3606 /* Scan the sections for the dynamic symbol table
3607 and dynamic string table and debug sections. */
3608 dynamic_symbols
= NULL
;
3609 dynamic_strings
= NULL
;
3610 dynamic_syminfo
= NULL
;
3611 symtab_shndx_hdr
= NULL
;
3613 for (i
= 0, section
= section_headers
;
3614 i
< elf_header
.e_shnum
;
3617 char *name
= SECTION_NAME (section
);
3619 if (section
->sh_type
== SHT_DYNSYM
)
3621 if (dynamic_symbols
!= NULL
)
3623 error (_("File contains multiple dynamic symbol tables\n"));
3627 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3628 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3630 else if (section
->sh_type
== SHT_STRTAB
3631 && strcmp (name
, ".dynstr") == 0)
3633 if (dynamic_strings
!= NULL
)
3635 error (_("File contains multiple dynamic string tables\n"));
3639 dynamic_strings
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3641 _("dynamic strings"));
3643 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3645 if (symtab_shndx_hdr
!= NULL
)
3647 error (_("File contains multiple symtab shndx tables\n"));
3650 symtab_shndx_hdr
= section
;
3652 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3653 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3654 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3656 && strncmp (name
, ".debug_", 7) == 0)
3661 || (do_debug_info
&& (strcmp (name
, "info") == 0))
3662 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
3663 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
3664 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
3665 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
3666 || (do_debug_frames
&& (strcmp (name
, "frame") == 0))
3667 || (do_debug_macinfo
&& (strcmp (name
, "macinfo") == 0))
3668 || (do_debug_str
&& (strcmp (name
, "str") == 0))
3669 || (do_debug_loc
&& (strcmp (name
, "loc") == 0))
3671 request_dump (i
, DEBUG_DUMP
);
3673 /* linkonce section to be combined with .debug_info at link time. */
3674 else if ((do_debugging
|| do_debug_info
)
3675 && strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
3676 request_dump (i
, DEBUG_DUMP
);
3677 else if (do_debug_frames
&& strcmp (name
, ".eh_frame") == 0)
3678 request_dump (i
, DEBUG_DUMP
);
3684 if (elf_header
.e_shnum
> 1)
3685 printf (_("\nSection Headers:\n"));
3687 printf (_("\nSection Header:\n"));
3691 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3694 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3697 printf (_(" [Nr] Name Type Address Offset\n"));
3698 printf (_(" Size EntSize Flags Link Info Align\n"));
3701 for (i
= 0, section
= section_headers
;
3702 i
< elf_header
.e_shnum
;
3705 printf (" [%2u] %-17.17s %-15.15s ",
3706 SECTION_HEADER_NUM (i
),
3707 SECTION_NAME (section
),
3708 get_section_type_name (section
->sh_type
));
3712 print_vma (section
->sh_addr
, LONG_HEX
);
3714 printf ( " %6.6lx %6.6lx %2.2lx",
3715 (unsigned long) section
->sh_offset
,
3716 (unsigned long) section
->sh_size
,
3717 (unsigned long) section
->sh_entsize
);
3719 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3721 printf ("%2ld %3lx %2ld\n",
3722 (unsigned long) section
->sh_link
,
3723 (unsigned long) section
->sh_info
,
3724 (unsigned long) section
->sh_addralign
);
3728 print_vma (section
->sh_addr
, LONG_HEX
);
3730 if ((long) section
->sh_offset
== section
->sh_offset
)
3731 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
3735 print_vma (section
->sh_offset
, LONG_HEX
);
3738 if ((unsigned long) section
->sh_size
== section
->sh_size
)
3739 printf (" %6.6lx", (unsigned long) section
->sh_size
);
3743 print_vma (section
->sh_size
, LONG_HEX
);
3746 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
3747 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
3751 print_vma (section
->sh_entsize
, LONG_HEX
);
3754 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3756 printf ("%2ld %3lx ",
3757 (unsigned long) section
->sh_link
,
3758 (unsigned long) section
->sh_info
);
3760 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
3761 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
3764 print_vma (section
->sh_addralign
, DEC
);
3771 print_vma (section
->sh_addr
, LONG_HEX
);
3772 if ((long) section
->sh_offset
== section
->sh_offset
)
3773 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
3777 print_vma (section
->sh_offset
, LONG_HEX
);
3780 print_vma (section
->sh_size
, LONG_HEX
);
3782 print_vma (section
->sh_entsize
, LONG_HEX
);
3784 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3786 printf (" %2ld %3lx %ld\n",
3787 (unsigned long) section
->sh_link
,
3788 (unsigned long) section
->sh_info
,
3789 (unsigned long) section
->sh_addralign
);
3793 printf (_("Key to Flags:\n\
3794 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3795 I (info), L (link order), G (group), x (unknown)\n\
3796 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3801 /* Process the reloc section. */
3803 process_relocs (file
)
3806 unsigned long rel_size
;
3807 unsigned long rel_offset
;
3813 if (do_using_dynamic
)
3815 int is_rela
= FALSE
;
3820 if (dynamic_info
[DT_REL
])
3822 rel_offset
= dynamic_info
[DT_REL
];
3823 rel_size
= dynamic_info
[DT_RELSZ
];
3826 else if (dynamic_info
[DT_RELA
])
3828 rel_offset
= dynamic_info
[DT_RELA
];
3829 rel_size
= dynamic_info
[DT_RELASZ
];
3832 else if (dynamic_info
[DT_JMPREL
])
3834 rel_offset
= dynamic_info
[DT_JMPREL
];
3835 rel_size
= dynamic_info
[DT_PLTRELSZ
];
3837 switch (dynamic_info
[DT_PLTREL
])
3854 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3855 rel_offset
, rel_size
);
3857 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
3858 dynamic_symbols
, num_dynamic_syms
, dynamic_strings
,
3862 printf (_("\nThere are no dynamic relocations in this file.\n"));
3866 Elf_Internal_Shdr
*section
;
3870 for (i
= 0, section
= section_headers
;
3871 i
< elf_header
.e_shnum
;
3874 if ( section
->sh_type
!= SHT_RELA
3875 && section
->sh_type
!= SHT_REL
)
3878 rel_offset
= section
->sh_offset
;
3879 rel_size
= section
->sh_size
;
3883 Elf_Internal_Shdr
*strsec
;
3884 Elf_Internal_Sym
*symtab
;
3887 unsigned long nsyms
;
3889 printf (_("\nRelocation section "));
3891 if (string_table
== NULL
)
3892 printf ("%d", section
->sh_name
);
3894 printf (_("'%s'"), SECTION_NAME (section
));
3896 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3897 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
3902 if (section
->sh_link
)
3904 Elf_Internal_Shdr
*symsec
;
3906 symsec
= SECTION_HEADER (section
->sh_link
);
3907 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
3908 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
3913 strsec
= SECTION_HEADER (symsec
->sh_link
);
3915 strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
3919 is_rela
= section
->sh_type
== SHT_RELA
;
3921 dump_relocations (file
, rel_offset
, rel_size
,
3922 symtab
, nsyms
, strtab
, is_rela
);
3934 printf (_("\nThere are no relocations in this file.\n"));
3940 #include "unwind-ia64.h"
3942 /* An absolute address consists of a section and an offset. If the
3943 section is NULL, the offset itself is the address, otherwise, the
3944 address equals to LOAD_ADDRESS(section) + offset. */
3948 unsigned short section
;
3954 struct unw_table_entry
3956 struct absaddr start
;
3958 struct absaddr info
;
3960 *table
; /* Unwind table. */
3961 unsigned long table_len
; /* Length of unwind table. */
3962 unsigned char *info
; /* Unwind info. */
3963 unsigned long info_size
; /* Size of unwind info. */
3964 bfd_vma info_addr
; /* starting address of unwind info. */
3965 bfd_vma seg_base
; /* Starting address of segment. */
3966 Elf_Internal_Sym
*symtab
; /* The symbol table. */
3967 unsigned long nsyms
; /* Number of symbols. */
3968 char *strtab
; /* The string table. */
3969 unsigned long strtab_size
; /* Size of string table. */
3972 static void find_symbol_for_address
3973 PARAMS ((struct unw_aux_info
*, struct absaddr
, const char **, bfd_vma
*));
3974 static void dump_ia64_unwind
3975 PARAMS ((struct unw_aux_info
*));
3976 static int slurp_ia64_unwind_table
3977 PARAMS ((FILE *, struct unw_aux_info
*, Elf_Internal_Shdr
*));
3980 find_symbol_for_address (aux
, addr
, symname
, offset
)
3981 struct unw_aux_info
*aux
;
3982 struct absaddr addr
;
3983 const char **symname
;
3986 bfd_vma dist
= (bfd_vma
) 0x100000;
3987 Elf_Internal_Sym
*sym
, *best
= NULL
;
3990 for (i
= 0, sym
= aux
->symtab
; i
< aux
->nsyms
; ++i
, ++sym
)
3992 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
3993 && sym
->st_name
!= 0
3994 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
3995 && addr
.offset
>= sym
->st_value
3996 && addr
.offset
- sym
->st_value
< dist
)
3999 dist
= addr
.offset
- sym
->st_value
;
4006 *symname
= (best
->st_name
>= aux
->strtab_size
4007 ? "<corrupt>" : aux
->strtab
+ best
->st_name
);
4012 *offset
= addr
.offset
;
4016 dump_ia64_unwind (aux
)
4017 struct unw_aux_info
*aux
;
4020 struct unw_table_entry
*tp
;
4023 addr_size
= is_32bit_elf
? 4 : 8;
4025 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4029 const unsigned char *dp
;
4030 const unsigned char *head
;
4031 const char *procname
;
4033 find_symbol_for_address (aux
, tp
->start
, &procname
, &offset
);
4035 fputs ("\n<", stdout
);
4039 fputs (procname
, stdout
);
4042 printf ("+%lx", (unsigned long) offset
);
4045 fputs (">: [", stdout
);
4046 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4047 fputc ('-', stdout
);
4048 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4049 printf ("], info at +0x%lx\n",
4050 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4052 head
= aux
->info
+ (tp
->info
.offset
- aux
->info_addr
);
4053 stamp
= BYTE_GET8 ((unsigned char *) head
);
4055 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4056 (unsigned) UNW_VER (stamp
),
4057 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4058 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4059 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4060 (unsigned long) (addr_size
* UNW_LENGTH (stamp
)));
4062 if (UNW_VER (stamp
) != 1)
4064 printf ("\tUnknown version.\n");
4069 for (dp
= head
+ 8; dp
< head
+ 8 + addr_size
* UNW_LENGTH (stamp
);)
4070 dp
= unw_decode (dp
, in_body
, & in_body
);
4075 slurp_ia64_unwind_table (file
, aux
, sec
)
4077 struct unw_aux_info
*aux
;
4078 Elf_Internal_Shdr
*sec
;
4080 unsigned long size
, addr_size
, nrelas
, i
;
4081 Elf_Internal_Phdr
*prog_hdrs
, *seg
;
4082 struct unw_table_entry
*tep
;
4083 Elf_Internal_Shdr
*relsec
;
4084 Elf_Internal_Rela
*rela
, *rp
;
4085 unsigned char *table
, *tp
;
4086 Elf_Internal_Sym
*sym
;
4087 const char *relname
;
4090 addr_size
= is_32bit_elf
? 4 : 8;
4092 /* First, find the starting address of the segment that includes
4095 if (elf_header
.e_phnum
)
4097 prog_hdrs
= (Elf_Internal_Phdr
*)
4098 xmalloc (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
4101 result
= get_32bit_program_headers (file
, prog_hdrs
);
4103 result
= get_64bit_program_headers (file
, prog_hdrs
);
4111 for (seg
= prog_hdrs
; seg
< prog_hdrs
+ elf_header
.e_phnum
; ++seg
)
4113 if (seg
->p_type
!= PT_LOAD
)
4116 if (sec
->sh_addr
>= seg
->p_vaddr
4117 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4119 aux
->seg_base
= seg
->p_vaddr
;
4127 /* Second, build the unwind table from the contents of the unwind section: */
4128 size
= sec
->sh_size
;
4129 table
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4130 size
, _("unwind table"));
4134 tep
= aux
->table
= xmalloc (size
/ (3 * addr_size
) * sizeof (aux
->table
[0]));
4135 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * addr_size
, ++tep
)
4137 tep
->start
.section
= SHN_UNDEF
;
4138 tep
->end
.section
= SHN_UNDEF
;
4139 tep
->info
.section
= SHN_UNDEF
;
4142 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4143 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4144 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4148 tep
->start
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 0);
4149 tep
->end
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 8);
4150 tep
->info
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 16);
4152 tep
->start
.offset
+= aux
->seg_base
;
4153 tep
->end
.offset
+= aux
->seg_base
;
4154 tep
->info
.offset
+= aux
->seg_base
;
4158 /* Third, apply any relocations to the unwind table: */
4160 for (relsec
= section_headers
;
4161 relsec
< section_headers
+ elf_header
.e_shnum
;
4164 if (relsec
->sh_type
!= SHT_RELA
4165 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4168 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4172 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4176 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4177 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4179 if (ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4181 warn (_("Skipping unexpected symbol type %u\n"),
4182 ELF32_ST_TYPE (sym
->st_info
));
4188 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4189 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4191 if (ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4193 warn (_("Skipping unexpected symbol type %u\n"),
4194 ELF64_ST_TYPE (sym
->st_info
));
4199 if (strncmp (relname
, "R_IA64_SEGREL", 13) != 0)
4201 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4205 i
= rp
->r_offset
/ (3 * addr_size
);
4207 switch (rp
->r_offset
/addr_size
% 3)
4210 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4211 aux
->table
[i
].start
.offset
+= rp
->r_addend
;
4214 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4215 aux
->table
[i
].end
.offset
+= rp
->r_addend
;
4218 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4219 aux
->table
[i
].info
.offset
+= rp
->r_addend
;
4229 aux
->table_len
= size
/ (3 * addr_size
);
4234 process_unwind (file
)
4237 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4238 unsigned long i
, addr_size
, unwcount
= 0, unwstart
= 0;
4239 struct unw_aux_info aux
;
4244 if (elf_header
.e_machine
!= EM_IA_64
)
4246 printf (_("\nThere are no unwind sections in this file.\n"));
4250 memset (& aux
, 0, sizeof (aux
));
4252 addr_size
= is_32bit_elf
? 4 : 8;
4254 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4256 if (sec
->sh_type
== SHT_SYMTAB
)
4258 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4259 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4261 strsec
= SECTION_HEADER (sec
->sh_link
);
4262 aux
.strtab_size
= strsec
->sh_size
;
4263 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
4264 aux
.strtab_size
, _("string table"));
4266 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4271 printf (_("\nThere are no unwind sections in this file.\n"));
4273 while (unwcount
-- > 0)
4278 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4279 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4280 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4287 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4289 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
,
4292 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
4293 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4294 suffix
= SECTION_NAME (unwsec
) + len
;
4295 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4297 if (strncmp (SECTION_NAME (sec
),
4298 ELF_STRING_ia64_unwind_info_once
, len2
) == 0
4299 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4304 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4305 .IA_64.unwind or BAR -> .IA_64.unwind_info */
4306 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4307 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4309 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
,
4311 suffix
= SECTION_NAME (unwsec
) + len
;
4312 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4314 if (strncmp (SECTION_NAME (sec
),
4315 ELF_STRING_ia64_unwind_info
, len2
) == 0
4316 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4320 if (i
== elf_header
.e_shnum
)
4322 printf (_("\nCould not find unwind info section for "));
4324 if (string_table
== NULL
)
4325 printf ("%d", unwsec
->sh_name
);
4327 printf (_("'%s'"), SECTION_NAME (unwsec
));
4331 aux
.info_size
= sec
->sh_size
;
4332 aux
.info_addr
= sec
->sh_addr
;
4333 aux
.info
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4334 aux
.info_size
, _("unwind info"));
4336 printf (_("\nUnwind section "));
4338 if (string_table
== NULL
)
4339 printf ("%d", unwsec
->sh_name
);
4341 printf (_("'%s'"), SECTION_NAME (unwsec
));
4343 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4344 (unsigned long) unwsec
->sh_offset
,
4345 (unsigned long) (unwsec
->sh_size
/ (3 * addr_size
)));
4347 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4349 if (aux
.table_len
> 0)
4350 dump_ia64_unwind (& aux
);
4353 free ((char *) aux
.table
);
4355 free ((char *) aux
.info
);
4364 free ((char *) aux
.strtab
);
4370 dynamic_segment_mips_val (entry
)
4371 Elf_Internal_Dyn
*entry
;
4373 switch (entry
->d_tag
)
4376 if (entry
->d_un
.d_val
== 0)
4380 static const char * opts
[] =
4382 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
4383 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
4384 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
4385 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
4390 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
4391 if (entry
->d_un
.d_val
& (1 << cnt
))
4393 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
4400 case DT_MIPS_IVERSION
:
4401 if (dynamic_strings
!= NULL
)
4402 printf ("Interface Version: %s\n",
4403 dynamic_strings
+ entry
->d_un
.d_val
);
4405 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4408 case DT_MIPS_TIME_STAMP
:
4413 time_t time
= entry
->d_un
.d_val
;
4414 tmp
= gmtime (&time
);
4415 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
4416 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
4417 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
4418 printf ("Time Stamp: %s\n", timebuf
);
4422 case DT_MIPS_RLD_VERSION
:
4423 case DT_MIPS_LOCAL_GOTNO
:
4424 case DT_MIPS_CONFLICTNO
:
4425 case DT_MIPS_LIBLISTNO
:
4426 case DT_MIPS_SYMTABNO
:
4427 case DT_MIPS_UNREFEXTNO
:
4428 case DT_MIPS_HIPAGENO
:
4429 case DT_MIPS_DELTA_CLASS_NO
:
4430 case DT_MIPS_DELTA_INSTANCE_NO
:
4431 case DT_MIPS_DELTA_RELOC_NO
:
4432 case DT_MIPS_DELTA_SYM_NO
:
4433 case DT_MIPS_DELTA_CLASSSYM_NO
:
4434 case DT_MIPS_COMPACT_SIZE
:
4435 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4439 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
4445 dynamic_segment_parisc_val (entry
)
4446 Elf_Internal_Dyn
*entry
;
4448 switch (entry
->d_tag
)
4450 case DT_HP_DLD_FLAGS
:
4459 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
4460 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
4461 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
4462 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
4463 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
4464 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
4465 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
4466 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
4467 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
4468 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
4469 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" }
4473 bfd_vma val
= entry
->d_un
.d_val
;
4475 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
4476 if (val
& flags
[cnt
].bit
)
4480 fputs (flags
[cnt
].str
, stdout
);
4482 val
^= flags
[cnt
].bit
;
4485 if (val
!= 0 || first
)
4489 print_vma (val
, HEX
);
4495 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4502 dynamic_segment_ia64_val (entry
)
4503 Elf_Internal_Dyn
*entry
;
4505 switch (entry
->d_tag
)
4507 case DT_IA_64_PLT_RESERVE
:
4508 /* First 3 bytes reserved. */
4509 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4511 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
4517 get_32bit_dynamic_segment (file
)
4520 Elf32_External_Dyn
*edyn
;
4521 Elf_Internal_Dyn
*entry
;
4524 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4525 dynamic_size
, _("dynamic segment"));
4529 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4530 how large this .dynamic is now. We can do this even before the byte
4531 swapping since the DT_NULL tag is recognizable. */
4533 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4536 dynamic_segment
= (Elf_Internal_Dyn
*)
4537 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4539 if (dynamic_segment
== NULL
)
4541 error (_("Out of memory\n"));
4546 for (i
= 0, entry
= dynamic_segment
;
4550 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
4551 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
4560 get_64bit_dynamic_segment (file
)
4563 Elf64_External_Dyn
*edyn
;
4564 Elf_Internal_Dyn
*entry
;
4567 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4568 dynamic_size
, _("dynamic segment"));
4572 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4573 how large this .dynamic is now. We can do this even before the byte
4574 swapping since the DT_NULL tag is recognizable. */
4576 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4579 dynamic_segment
= (Elf_Internal_Dyn
*)
4580 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4582 if (dynamic_segment
== NULL
)
4584 error (_("Out of memory\n"));
4589 for (i
= 0, entry
= dynamic_segment
;
4593 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
4594 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
4603 get_dynamic_flags (flags
)
4606 static char buff
[128];
4614 flag
= flags
& - flags
;
4622 case DF_ORIGIN
: strcpy (p
, "ORIGIN"); break;
4623 case DF_SYMBOLIC
: strcpy (p
, "SYMBOLIC"); break;
4624 case DF_TEXTREL
: strcpy (p
, "TEXTREL"); break;
4625 case DF_BIND_NOW
: strcpy (p
, "BIND_NOW"); break;
4626 case DF_STATIC_TLS
: strcpy (p
, "STATIC_TLS"); break;
4627 default: strcpy (p
, "unknown"); break;
4630 p
= strchr (p
, '\0');
4635 /* Parse and display the contents of the dynamic segment. */
4637 process_dynamic_segment (file
)
4640 Elf_Internal_Dyn
*entry
;
4643 if (dynamic_size
== 0)
4646 printf (_("\nThere is no dynamic segment in this file.\n"));
4653 if (! get_32bit_dynamic_segment (file
))
4656 else if (! get_64bit_dynamic_segment (file
))
4659 /* Find the appropriate symbol table. */
4660 if (dynamic_symbols
== NULL
)
4662 for (i
= 0, entry
= dynamic_segment
;
4666 Elf_Internal_Shdr section
;
4668 if (entry
->d_tag
!= DT_SYMTAB
)
4671 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
4673 /* Since we do not know how big the symbol table is,
4674 we default to reading in the entire file (!) and
4675 processing that. This is overkill, I know, but it
4677 section
.sh_offset
= entry
->d_un
.d_val
- loadaddr
;
4679 if (fseek (file
, 0, SEEK_END
))
4680 error (_("Unable to seek to end of file!"));
4682 section
.sh_size
= ftell (file
) - section
.sh_offset
;
4684 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
4686 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
4688 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
4689 if (num_dynamic_syms
< 1)
4691 error (_("Unable to determine the number of symbols to load\n"));
4695 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
4699 /* Similarly find a string table. */
4700 if (dynamic_strings
== NULL
)
4702 for (i
= 0, entry
= dynamic_segment
;
4706 unsigned long offset
;
4709 if (entry
->d_tag
!= DT_STRTAB
)
4712 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
4714 /* Since we do not know how big the string table is,
4715 we default to reading in the entire file (!) and
4716 processing that. This is overkill, I know, but it
4719 offset
= entry
->d_un
.d_val
- loadaddr
;
4720 if (fseek (file
, 0, SEEK_END
))
4721 error (_("Unable to seek to end of file\n"));
4722 str_tab_len
= ftell (file
) - offset
;
4724 if (str_tab_len
< 1)
4727 (_("Unable to determine the length of the dynamic string table\n"));
4731 dynamic_strings
= (char *) get_data (NULL
, file
, offset
, str_tab_len
,
4732 _("dynamic string table"));
4737 /* And find the syminfo section if available. */
4738 if (dynamic_syminfo
== NULL
)
4740 unsigned long syminsz
= 0;
4742 for (i
= 0, entry
= dynamic_segment
;
4746 if (entry
->d_tag
== DT_SYMINENT
)
4748 /* Note: these braces are necessary to avoid a syntax
4749 error from the SunOS4 C compiler. */
4750 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
4752 else if (entry
->d_tag
== DT_SYMINSZ
)
4753 syminsz
= entry
->d_un
.d_val
;
4754 else if (entry
->d_tag
== DT_SYMINFO
)
4755 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
4758 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
4760 Elf_External_Syminfo
*extsyminfo
;
4761 Elf_Internal_Syminfo
*syminfo
;
4763 /* There is a syminfo section. Read the data. */
4764 extsyminfo
= ((Elf_External_Syminfo
*)
4765 get_data (NULL
, file
, dynamic_syminfo_offset
,
4766 syminsz
, _("symbol information")));
4770 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
4771 if (dynamic_syminfo
== NULL
)
4773 error (_("Out of memory\n"));
4777 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
4778 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
4781 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
4782 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
4789 if (do_dynamic
&& dynamic_addr
)
4790 printf (_("\nDynamic segment at offset 0x%lx contains %ld entries:\n"),
4791 dynamic_addr
, (long) dynamic_size
);
4793 printf (_(" Tag Type Name/Value\n"));
4795 for (i
= 0, entry
= dynamic_segment
;
4804 print_vma (entry
->d_tag
, FULL_HEX
);
4805 dtype
= get_dynamic_type (entry
->d_tag
);
4806 printf (" (%s)%*s", dtype
,
4807 ((is_32bit_elf
? 27 : 19)
4808 - (int) strlen (dtype
)),
4812 switch (entry
->d_tag
)
4816 puts (get_dynamic_flags (entry
->d_un
.d_val
));
4826 switch (entry
->d_tag
)
4829 printf (_("Auxiliary library"));
4833 printf (_("Filter library"));
4837 printf (_("Configuration file"));
4841 printf (_("Dependency audit library"));
4845 printf (_("Audit library"));
4849 if (dynamic_strings
)
4850 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
4854 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4863 printf (_("Flags:"));
4865 if (entry
->d_un
.d_val
== 0)
4866 printf (_(" None\n"));
4869 unsigned long int val
= entry
->d_un
.d_val
;
4871 if (val
& DTF_1_PARINIT
)
4873 printf (" PARINIT");
4874 val
^= DTF_1_PARINIT
;
4876 if (val
& DTF_1_CONFEXP
)
4878 printf (" CONFEXP");
4879 val
^= DTF_1_CONFEXP
;
4882 printf (" %lx", val
);
4891 printf (_("Flags:"));
4893 if (entry
->d_un
.d_val
== 0)
4894 printf (_(" None\n"));
4897 unsigned long int val
= entry
->d_un
.d_val
;
4899 if (val
& DF_P1_LAZYLOAD
)
4901 printf (" LAZYLOAD");
4902 val
^= DF_P1_LAZYLOAD
;
4904 if (val
& DF_P1_GROUPPERM
)
4906 printf (" GROUPPERM");
4907 val
^= DF_P1_GROUPPERM
;
4910 printf (" %lx", val
);
4919 printf (_("Flags:"));
4920 if (entry
->d_un
.d_val
== 0)
4921 printf (_(" None\n"));
4924 unsigned long int val
= entry
->d_un
.d_val
;
4931 if (val
& DF_1_GLOBAL
)
4936 if (val
& DF_1_GROUP
)
4941 if (val
& DF_1_NODELETE
)
4943 printf (" NODELETE");
4944 val
^= DF_1_NODELETE
;
4946 if (val
& DF_1_LOADFLTR
)
4948 printf (" LOADFLTR");
4949 val
^= DF_1_LOADFLTR
;
4951 if (val
& DF_1_INITFIRST
)
4953 printf (" INITFIRST");
4954 val
^= DF_1_INITFIRST
;
4956 if (val
& DF_1_NOOPEN
)
4961 if (val
& DF_1_ORIGIN
)
4966 if (val
& DF_1_DIRECT
)
4971 if (val
& DF_1_TRANS
)
4976 if (val
& DF_1_INTERPOSE
)
4978 printf (" INTERPOSE");
4979 val
^= DF_1_INTERPOSE
;
4981 if (val
& DF_1_NODEFLIB
)
4983 printf (" NODEFLIB");
4984 val
^= DF_1_NODEFLIB
;
4986 if (val
& DF_1_NODUMP
)
4991 if (val
& DF_1_CONLFAT
)
4993 printf (" CONLFAT");
4994 val
^= DF_1_CONLFAT
;
4997 printf (" %lx", val
);
5005 puts (get_dynamic_type (entry
->d_un
.d_val
));
5025 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5031 if (dynamic_strings
== NULL
)
5034 name
= dynamic_strings
+ entry
->d_un
.d_val
;
5038 switch (entry
->d_tag
)
5041 printf (_("Shared library: [%s]"), name
);
5043 if (strcmp (name
, program_interpreter
) == 0)
5044 printf (_(" program interpreter"));
5048 printf (_("Library soname: [%s]"), name
);
5052 printf (_("Library rpath: [%s]"), name
);
5056 printf (_("Library runpath: [%s]"), name
);
5060 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5065 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5081 case DT_INIT_ARRAYSZ
:
5082 case DT_FINI_ARRAYSZ
:
5083 case DT_GNU_CONFLICTSZ
:
5084 case DT_GNU_LIBLISTSZ
:
5087 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5088 printf (" (bytes)\n");
5098 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5111 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
5115 name
= dynamic_strings
+ entry
->d_un
.d_val
;
5119 printf (_("Not needed object: [%s]\n"), name
);
5124 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5130 /* The value of this entry is ignored. */
5135 case DT_GNU_PRELINKED
:
5139 time_t time
= entry
->d_un
.d_val
;
5141 tmp
= gmtime (&time
);
5142 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
5143 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5144 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5150 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
5151 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
5156 switch (elf_header
.e_machine
)
5159 case EM_MIPS_RS3_LE
:
5160 dynamic_segment_mips_val (entry
);
5163 dynamic_segment_parisc_val (entry
);
5166 dynamic_segment_ia64_val (entry
);
5169 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5181 get_ver_flags (flags
)
5184 static char buff
[32];
5191 if (flags
& VER_FLG_BASE
)
5192 strcat (buff
, "BASE ");
5194 if (flags
& VER_FLG_WEAK
)
5196 if (flags
& VER_FLG_BASE
)
5197 strcat (buff
, "| ");
5199 strcat (buff
, "WEAK ");
5202 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
5203 strcat (buff
, "| <unknown>");
5208 /* Display the contents of the version sections. */
5210 process_version_sections (file
)
5213 Elf_Internal_Shdr
*section
;
5220 for (i
= 0, section
= section_headers
;
5221 i
< elf_header
.e_shnum
;
5224 switch (section
->sh_type
)
5226 case SHT_GNU_verdef
:
5228 Elf_External_Verdef
*edefs
;
5235 (_("\nVersion definition section '%s' contains %ld entries:\n"),
5236 SECTION_NAME (section
), section
->sh_info
);
5238 printf (_(" Addr: 0x"));
5239 printf_vma (section
->sh_addr
);
5240 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5241 (unsigned long) section
->sh_offset
, section
->sh_link
,
5242 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5244 edefs
= ((Elf_External_Verdef
*)
5245 get_data (NULL
, file
, section
->sh_offset
,
5247 _("version definition section")));
5251 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5254 Elf_External_Verdef
*edef
;
5255 Elf_Internal_Verdef ent
;
5256 Elf_External_Verdaux
*eaux
;
5257 Elf_Internal_Verdaux aux
;
5261 vstart
= ((char *) edefs
) + idx
;
5263 edef
= (Elf_External_Verdef
*) vstart
;
5265 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
5266 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
5267 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
5268 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
5269 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
5270 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
5271 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
5273 printf (_(" %#06x: Rev: %d Flags: %s"),
5274 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
5276 printf (_(" Index: %d Cnt: %d "),
5277 ent
.vd_ndx
, ent
.vd_cnt
);
5279 vstart
+= ent
.vd_aux
;
5281 eaux
= (Elf_External_Verdaux
*) vstart
;
5283 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5284 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5286 if (dynamic_strings
)
5287 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
5289 printf (_("Name index: %ld\n"), aux
.vda_name
);
5291 isum
= idx
+ ent
.vd_aux
;
5293 for (j
= 1; j
< ent
.vd_cnt
; j
++)
5295 isum
+= aux
.vda_next
;
5296 vstart
+= aux
.vda_next
;
5298 eaux
= (Elf_External_Verdaux
*) vstart
;
5300 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5301 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5303 if (dynamic_strings
)
5304 printf (_(" %#06x: Parent %d: %s\n"),
5305 isum
, j
, dynamic_strings
+ aux
.vda_name
);
5307 printf (_(" %#06x: Parent %d, name index: %ld\n"),
5308 isum
, j
, aux
.vda_name
);
5318 case SHT_GNU_verneed
:
5320 Elf_External_Verneed
*eneed
;
5326 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
5327 SECTION_NAME (section
), section
->sh_info
);
5329 printf (_(" Addr: 0x"));
5330 printf_vma (section
->sh_addr
);
5331 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
5332 (unsigned long) section
->sh_offset
, section
->sh_link
,
5333 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5335 eneed
= ((Elf_External_Verneed
*)
5336 get_data (NULL
, file
, section
->sh_offset
,
5337 section
->sh_size
, _("version need section")));
5341 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5343 Elf_External_Verneed
*entry
;
5344 Elf_Internal_Verneed ent
;
5349 vstart
= ((char *) eneed
) + idx
;
5351 entry
= (Elf_External_Verneed
*) vstart
;
5353 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
5354 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
5355 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
5356 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
5357 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
5359 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
5361 if (dynamic_strings
)
5362 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
5364 printf (_(" File: %lx"), ent
.vn_file
);
5366 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
5368 vstart
+= ent
.vn_aux
;
5370 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
5372 Elf_External_Vernaux
*eaux
;
5373 Elf_Internal_Vernaux aux
;
5375 eaux
= (Elf_External_Vernaux
*) vstart
;
5377 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
5378 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
5379 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
5380 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
5381 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
5383 if (dynamic_strings
)
5384 printf (_(" %#06x: Name: %s"),
5385 isum
, dynamic_strings
+ aux
.vna_name
);
5387 printf (_(" %#06x: Name index: %lx"),
5388 isum
, aux
.vna_name
);
5390 printf (_(" Flags: %s Version: %d\n"),
5391 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
5393 isum
+= aux
.vna_next
;
5394 vstart
+= aux
.vna_next
;
5404 case SHT_GNU_versym
:
5406 Elf_Internal_Shdr
*link_section
;
5409 unsigned char *edata
;
5410 unsigned short *data
;
5412 Elf_Internal_Sym
*symbols
;
5413 Elf_Internal_Shdr
*string_sec
;
5415 link_section
= SECTION_HEADER (section
->sh_link
);
5416 total
= section
->sh_size
/ section
->sh_entsize
;
5420 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
5422 string_sec
= SECTION_HEADER (link_section
->sh_link
);
5424 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5425 string_sec
->sh_size
,
5426 _("version string table"));
5430 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
5431 SECTION_NAME (section
), total
);
5433 printf (_(" Addr: "));
5434 printf_vma (section
->sh_addr
);
5435 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5436 (unsigned long) section
->sh_offset
, section
->sh_link
,
5437 SECTION_NAME (link_section
));
5441 get_data (NULL
, file
,
5442 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] - loadaddr
,
5443 total
* sizeof (short), _("version symbol data")));
5450 data
= (unsigned short *) malloc (total
* sizeof (short));
5452 for (cnt
= total
; cnt
--;)
5453 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
5458 for (cnt
= 0; cnt
< total
; cnt
+= 4)
5461 int check_def
, check_need
;
5464 printf (" %03x:", cnt
);
5466 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
5467 switch (data
[cnt
+ j
])
5470 fputs (_(" 0 (*local*) "), stdout
);
5474 fputs (_(" 1 (*global*) "), stdout
);
5478 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
5479 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
5483 if (SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
5486 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
5493 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
5495 Elf_Internal_Verneed ivn
;
5496 unsigned long offset
;
5498 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5503 Elf_Internal_Vernaux ivna
;
5504 Elf_External_Verneed evn
;
5505 Elf_External_Vernaux evna
;
5506 unsigned long a_off
;
5508 get_data (&evn
, file
, offset
, sizeof (evn
),
5511 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5512 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5514 a_off
= offset
+ ivn
.vn_aux
;
5518 get_data (&evna
, file
, a_off
, sizeof (evna
),
5519 _("version need aux (2)"));
5521 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5522 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5524 a_off
+= ivna
.vna_next
;
5526 while (ivna
.vna_other
!= data
[cnt
+ j
]
5527 && ivna
.vna_next
!= 0);
5529 if (ivna
.vna_other
== data
[cnt
+ j
])
5531 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5533 name
= strtab
+ ivna
.vna_name
;
5534 nn
+= printf ("(%s%-*s",
5536 12 - (int) strlen (name
),
5542 offset
+= ivn
.vn_next
;
5544 while (ivn
.vn_next
);
5547 if (check_def
&& data
[cnt
+ j
] != 0x8001
5548 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5550 Elf_Internal_Verdef ivd
;
5551 Elf_External_Verdef evd
;
5552 unsigned long offset
;
5554 offset
= (version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
5559 get_data (&evd
, file
, offset
, sizeof (evd
),
5562 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
5563 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
5565 offset
+= ivd
.vd_next
;
5567 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
5568 && ivd
.vd_next
!= 0);
5570 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
5572 Elf_External_Verdaux evda
;
5573 Elf_Internal_Verdaux ivda
;
5575 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
5577 get_data (&evda
, file
,
5578 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
5579 sizeof (evda
), _("version def aux"));
5581 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
5583 name
= strtab
+ ivda
.vda_name
;
5584 nn
+= printf ("(%s%-*s",
5586 12 - (int) strlen (name
),
5592 printf ("%*c", 18 - nn
, ' ');
5610 printf (_("\nNo version information found in this file.\n"));
5616 get_symbol_binding (binding
)
5617 unsigned int binding
;
5619 static char buff
[32];
5623 case STB_LOCAL
: return "LOCAL";
5624 case STB_GLOBAL
: return "GLOBAL";
5625 case STB_WEAK
: return "WEAK";
5627 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
5628 sprintf (buff
, _("<processor specific>: %d"), binding
);
5629 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
5630 sprintf (buff
, _("<OS specific>: %d"), binding
);
5632 sprintf (buff
, _("<unknown>: %d"), binding
);
5638 get_symbol_type (type
)
5641 static char buff
[32];
5645 case STT_NOTYPE
: return "NOTYPE";
5646 case STT_OBJECT
: return "OBJECT";
5647 case STT_FUNC
: return "FUNC";
5648 case STT_SECTION
: return "SECTION";
5649 case STT_FILE
: return "FILE";
5650 case STT_COMMON
: return "COMMON";
5651 case STT_TLS
: return "TLS";
5653 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
5655 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
5656 return "THUMB_FUNC";
5658 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
5661 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
5662 return "PARISC_MILLI";
5664 sprintf (buff
, _("<processor specific>: %d"), type
);
5666 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
5668 if (elf_header
.e_machine
== EM_PARISC
)
5670 if (type
== STT_HP_OPAQUE
)
5672 if (type
== STT_HP_STUB
)
5676 sprintf (buff
, _("<OS specific>: %d"), type
);
5679 sprintf (buff
, _("<unknown>: %d"), type
);
5685 get_symbol_visibility (visibility
)
5686 unsigned int visibility
;
5690 case STV_DEFAULT
: return "DEFAULT";
5691 case STV_INTERNAL
: return "INTERNAL";
5692 case STV_HIDDEN
: return "HIDDEN";
5693 case STV_PROTECTED
: return "PROTECTED";
5699 get_symbol_index_type (type
)
5702 static char buff
[32];
5706 case SHN_UNDEF
: return "UND";
5707 case SHN_ABS
: return "ABS";
5708 case SHN_COMMON
: return "COM";
5710 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
5711 sprintf (buff
, "PRC[0x%04x]", type
);
5712 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
5713 sprintf (buff
, "OS [0x%04x]", type
);
5714 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
5715 sprintf (buff
, "RSV[0x%04x]", type
);
5717 sprintf (buff
, "%3d", type
);
5725 get_dynamic_data (file
, number
)
5727 unsigned int number
;
5729 unsigned char *e_data
;
5732 e_data
= (unsigned char *) malloc (number
* 4);
5736 error (_("Out of memory\n"));
5740 if (fread (e_data
, 4, number
, file
) != number
)
5742 error (_("Unable to read in dynamic data\n"));
5746 i_data
= (int *) malloc (number
* sizeof (*i_data
));
5750 error (_("Out of memory\n"));
5756 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
5763 /* Dump the symbol table. */
5765 process_symbol_table (file
)
5768 Elf_Internal_Shdr
*section
;
5769 unsigned char nb
[4];
5770 unsigned char nc
[4];
5773 int *buckets
= NULL
;
5776 if (! do_syms
&& !do_histogram
)
5779 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
5782 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
5784 error (_("Unable to seek to start of dynamic information"));
5788 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
5790 error (_("Failed to read in number of buckets\n"));
5794 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
5796 error (_("Failed to read in number of chains\n"));
5800 nbuckets
= byte_get (nb
, 4);
5801 nchains
= byte_get (nc
, 4);
5803 buckets
= get_dynamic_data (file
, nbuckets
);
5804 chains
= get_dynamic_data (file
, nchains
);
5806 if (buckets
== NULL
|| chains
== NULL
)
5811 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
5816 printf (_("\nSymbol table for image:\n"));
5818 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5820 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5822 for (hn
= 0; hn
< nbuckets
; hn
++)
5827 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
5829 Elf_Internal_Sym
*psym
;
5831 psym
= dynamic_symbols
+ si
;
5833 printf (" %3d %3d: ", si
, hn
);
5834 print_vma (psym
->st_value
, LONG_HEX
);
5836 print_vma (psym
->st_size
, DEC_5
);
5838 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5839 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5840 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5841 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
5842 print_symbol (25, dynamic_strings
+ psym
->st_name
);
5847 else if (do_syms
&& !do_using_dynamic
)
5851 for (i
= 0, section
= section_headers
;
5852 i
< elf_header
.e_shnum
;
5857 Elf_Internal_Sym
*symtab
;
5858 Elf_Internal_Sym
*psym
;
5861 if ( section
->sh_type
!= SHT_SYMTAB
5862 && section
->sh_type
!= SHT_DYNSYM
)
5865 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5866 SECTION_NAME (section
),
5867 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
5869 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5871 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5873 symtab
= GET_ELF_SYMBOLS (file
, section
);
5877 if (section
->sh_link
== elf_header
.e_shstrndx
)
5878 strtab
= string_table
;
5881 Elf_Internal_Shdr
*string_sec
;
5883 string_sec
= SECTION_HEADER (section
->sh_link
);
5885 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5886 string_sec
->sh_size
,
5890 for (si
= 0, psym
= symtab
;
5891 si
< section
->sh_size
/ section
->sh_entsize
;
5894 printf ("%6d: ", si
);
5895 print_vma (psym
->st_value
, LONG_HEX
);
5897 print_vma (psym
->st_size
, DEC_5
);
5898 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5899 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5900 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5901 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
5902 print_symbol (25, strtab
+ psym
->st_name
);
5904 if (section
->sh_type
== SHT_DYNSYM
&&
5905 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
5907 unsigned char data
[2];
5908 unsigned short vers_data
;
5909 unsigned long offset
;
5913 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
5916 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
5917 sizeof (data
), _("version data"));
5919 vers_data
= byte_get (data
, 2);
5921 is_nobits
= (SECTION_HEADER (psym
->st_shndx
)->sh_type
5924 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
5926 if ((vers_data
& 0x8000) || vers_data
> 1)
5928 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5929 && (is_nobits
|| ! check_def
))
5931 Elf_External_Verneed evn
;
5932 Elf_Internal_Verneed ivn
;
5933 Elf_Internal_Vernaux ivna
;
5935 /* We must test both. */
5936 offset
= (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5941 unsigned long vna_off
;
5943 get_data (&evn
, file
, offset
, sizeof (evn
),
5946 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5947 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5949 vna_off
= offset
+ ivn
.vn_aux
;
5953 Elf_External_Vernaux evna
;
5955 get_data (&evna
, file
, vna_off
,
5957 _("version need aux (3)"));
5959 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5960 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5961 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5963 vna_off
+= ivna
.vna_next
;
5965 while (ivna
.vna_other
!= vers_data
5966 && ivna
.vna_next
!= 0);
5968 if (ivna
.vna_other
== vers_data
)
5971 offset
+= ivn
.vn_next
;
5973 while (ivn
.vn_next
!= 0);
5975 if (ivna
.vna_other
== vers_data
)
5978 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
5981 else if (! is_nobits
)
5982 error (_("bad dynamic symbol"));
5989 if (vers_data
!= 0x8001
5990 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5992 Elf_Internal_Verdef ivd
;
5993 Elf_Internal_Verdaux ivda
;
5994 Elf_External_Verdaux evda
;
5995 unsigned long offset
;
5998 = (version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
6003 Elf_External_Verdef evd
;
6005 get_data (&evd
, file
, offset
, sizeof (evd
),
6008 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6009 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6010 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6012 offset
+= ivd
.vd_next
;
6014 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
6015 && ivd
.vd_next
!= 0);
6017 offset
-= ivd
.vd_next
;
6018 offset
+= ivd
.vd_aux
;
6020 get_data (&evda
, file
, offset
, sizeof (evda
),
6021 _("version def aux"));
6023 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6025 if (psym
->st_name
!= ivda
.vda_name
)
6026 printf ((vers_data
& 0x8000)
6028 strtab
+ ivda
.vda_name
);
6038 if (strtab
!= string_table
)
6044 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
6046 if (do_histogram
&& buckets
!= NULL
)
6053 int nzero_counts
= 0;
6056 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
6058 printf (_(" Length Number %% of total Coverage\n"));
6060 lengths
= (int *) calloc (nbuckets
, sizeof (int));
6061 if (lengths
== NULL
)
6063 error (_("Out of memory"));
6066 for (hn
= 0; hn
< nbuckets
; ++hn
)
6071 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
6074 if (maxlength
< ++lengths
[hn
])
6079 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
6082 error (_("Out of memory"));
6086 for (hn
= 0; hn
< nbuckets
; ++hn
)
6087 ++counts
[lengths
[hn
]];
6091 printf (" 0 %-10d (%5.1f%%)\n",
6092 counts
[0], (counts
[0] * 100.0) / nbuckets
);
6093 for (si
= 1; si
<= maxlength
; ++si
)
6095 nzero_counts
+= counts
[si
] * si
;
6096 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
6097 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
6098 (nzero_counts
* 100.0) / nsyms
);
6106 if (buckets
!= NULL
)
6116 process_syminfo (file
)
6117 FILE *file ATTRIBUTE_UNUSED
;
6121 if (dynamic_syminfo
== NULL
6123 /* No syminfo, this is ok. */
6126 /* There better should be a dynamic symbol section. */
6127 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
6131 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
6132 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
6134 printf (_(" Num: Name BoundTo Flags\n"));
6135 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
6137 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
6139 printf ("%4d: ", i
);
6140 print_symbol (30, dynamic_strings
+ dynamic_symbols
[i
].st_name
);
6143 switch (dynamic_syminfo
[i
].si_boundto
)
6145 case SYMINFO_BT_SELF
:
6146 fputs ("SELF ", stdout
);
6148 case SYMINFO_BT_PARENT
:
6149 fputs ("PARENT ", stdout
);
6152 if (dynamic_syminfo
[i
].si_boundto
> 0
6153 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
6158 [dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
6162 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
6166 if (flags
& SYMINFO_FLG_DIRECT
)
6168 if (flags
& SYMINFO_FLG_PASSTHRU
)
6169 printf (" PASSTHRU");
6170 if (flags
& SYMINFO_FLG_COPY
)
6172 if (flags
& SYMINFO_FLG_LAZYLOAD
)
6173 printf (" LAZYLOAD");
6181 #ifdef SUPPORT_DISASSEMBLY
6183 disassemble_section (section
, file
)
6184 Elf_Internal_Shdr
*section
;
6187 printf (_("\nAssembly dump of section %s\n"),
6188 SECTION_NAME (section
));
6190 /* XXX -- to be done --- XXX */
6197 dump_section (section
, file
)
6198 Elf_Internal_Shdr
*section
;
6201 bfd_size_type bytes
;
6203 unsigned char *data
;
6204 unsigned char *start
;
6206 bytes
= section
->sh_size
;
6210 printf (_("\nSection '%s' has no data to dump.\n"),
6211 SECTION_NAME (section
));
6215 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
6217 addr
= section
->sh_addr
;
6219 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, bytes
,
6232 lbytes
= (bytes
> 16 ? 16 : bytes
);
6234 printf (" 0x%8.8lx ", (unsigned long) addr
);
6236 switch (elf_header
.e_ident
[EI_DATA
])
6240 for (j
= 15; j
>= 0; j
--)
6243 printf ("%2.2x", data
[j
]);
6253 for (j
= 0; j
< 16; j
++)
6256 printf ("%2.2x", data
[j
]);
6266 for (j
= 0; j
< lbytes
; j
++)
6269 if (k
>= ' ' && k
< 0x80)
6288 static unsigned long int
6289 read_leb128 (data
, length_return
, sign
)
6290 unsigned char *data
;
6294 unsigned long int result
= 0;
6295 unsigned int num_read
= 0;
6304 result
|= (byte
& 0x7f) << shift
;
6309 while (byte
& 0x80);
6311 if (length_return
!= NULL
)
6312 *length_return
= num_read
;
6314 if (sign
&& (shift
< 32) && (byte
& 0x40))
6315 result
|= -1 << shift
;
6320 typedef struct State_Machine_Registers
6322 unsigned long address
;
6325 unsigned int column
;
6329 /* This variable hold the number of the last entry seen
6330 in the File Table. */
6331 unsigned int last_file_entry
;
6334 static SMR state_machine_regs
;
6337 reset_state_machine (is_stmt
)
6340 state_machine_regs
.address
= 0;
6341 state_machine_regs
.file
= 1;
6342 state_machine_regs
.line
= 1;
6343 state_machine_regs
.column
= 0;
6344 state_machine_regs
.is_stmt
= is_stmt
;
6345 state_machine_regs
.basic_block
= 0;
6346 state_machine_regs
.end_sequence
= 0;
6347 state_machine_regs
.last_file_entry
= 0;
6350 /* Handled an extend line op. Returns true if this is the end
6353 process_extended_line_op (data
, is_stmt
, pointer_size
)
6354 unsigned char *data
;
6358 unsigned char op_code
;
6361 unsigned char *name
;
6364 len
= read_leb128 (data
, & bytes_read
, 0);
6369 warn (_("badly formed extended line op encountered!\n"));
6376 printf (_(" Extended opcode %d: "), op_code
);
6380 case DW_LNE_end_sequence
:
6381 printf (_("End of Sequence\n\n"));
6382 reset_state_machine (is_stmt
);
6385 case DW_LNE_set_address
:
6386 adr
= byte_get (data
, pointer_size
);
6387 printf (_("set Address to 0x%lx\n"), adr
);
6388 state_machine_regs
.address
= adr
;
6391 case DW_LNE_define_file
:
6392 printf (_(" define new File Table entry\n"));
6393 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6395 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6397 data
+= strlen ((char *) data
) + 1;
6398 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6400 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6402 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6403 printf (_("%s\n\n"), name
);
6407 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
6414 /* Size of pointers in the .debug_line section. This information is not
6415 really present in that section. It's obtained before dumping the debug
6416 sections by doing some pre-scan of the .debug_info section. */
6417 static int debug_line_pointer_size
= 4;
6420 display_debug_lines (section
, start
, file
)
6421 Elf_Internal_Shdr
*section
;
6422 unsigned char * start
;
6423 FILE *file ATTRIBUTE_UNUSED
;
6425 unsigned char *hdrptr
;
6426 DWARF2_Internal_LineInfo info
;
6427 unsigned char *standard_opcodes
;
6428 unsigned char *data
= start
;
6429 unsigned char *end
= start
+ section
->sh_size
;
6430 unsigned char *end_of_sequence
;
6433 int initial_length_size
;
6435 printf (_("\nDump of debug contents of section %s:\n\n"),
6436 SECTION_NAME (section
));
6442 /* Check the length of the block. */
6443 info
.li_length
= byte_get (hdrptr
, 4);
6446 if (info
.li_length
== 0xffffffff)
6448 /* This section is 64-bit DWARF 3. */
6449 info
.li_length
= byte_get (hdrptr
, 8);
6452 initial_length_size
= 12;
6457 initial_length_size
= 4;
6460 if (info
.li_length
+ initial_length_size
> section
->sh_size
)
6463 (_("The line info appears to be corrupt - the section is too small\n"));
6467 /* Check its version number. */
6468 info
.li_version
= byte_get (hdrptr
, 2);
6470 if (info
.li_version
!= 2 && info
.li_version
!= 3)
6472 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
6476 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
6477 hdrptr
+= offset_size
;
6478 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
6480 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
6482 info
.li_line_base
= byte_get (hdrptr
, 1);
6484 info
.li_line_range
= byte_get (hdrptr
, 1);
6486 info
.li_opcode_base
= byte_get (hdrptr
, 1);
6489 /* Sign extend the line base field. */
6490 info
.li_line_base
<<= 24;
6491 info
.li_line_base
>>= 24;
6493 printf (_(" Length: %ld\n"), info
.li_length
);
6494 printf (_(" DWARF Version: %d\n"), info
.li_version
);
6495 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
6496 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
6497 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
6498 printf (_(" Line Base: %d\n"), info
.li_line_base
);
6499 printf (_(" Line Range: %d\n"), info
.li_line_range
);
6500 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
6502 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
6504 reset_state_machine (info
.li_default_is_stmt
);
6506 /* Display the contents of the Opcodes table. */
6507 standard_opcodes
= hdrptr
;
6509 printf (_("\n Opcodes:\n"));
6511 for (i
= 1; i
< info
.li_opcode_base
; i
++)
6512 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
6514 /* Display the contents of the Directory table. */
6515 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
6518 printf (_("\n The Directory Table is empty.\n"));
6521 printf (_("\n The Directory Table:\n"));
6525 printf (_(" %s\n"), data
);
6527 data
+= strlen ((char *) data
) + 1;
6531 /* Skip the NUL at the end of the table. */
6534 /* Display the contents of the File Name table. */
6536 printf (_("\n The File Name Table is empty.\n"));
6539 printf (_("\n The File Name Table:\n"));
6540 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6544 unsigned char *name
;
6547 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6550 data
+= strlen ((char *) data
) + 1;
6552 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6554 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6556 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6558 printf (_("%s\n"), name
);
6562 /* Skip the NUL at the end of the table. */
6565 /* Now display the statements. */
6566 printf (_("\n Line Number Statements:\n"));
6569 while (data
< end_of_sequence
)
6571 unsigned char op_code
;
6577 if (op_code
>= info
.li_opcode_base
)
6579 op_code
-= info
.li_opcode_base
;
6580 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
6581 state_machine_regs
.address
+= adv
;
6582 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6583 op_code
, adv
, state_machine_regs
.address
);
6584 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
6585 state_machine_regs
.line
+= adv
;
6586 printf (_(" and Line by %d to %d\n"),
6587 adv
, state_machine_regs
.line
);
6589 else switch (op_code
)
6591 case DW_LNS_extended_op
:
6592 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
6593 debug_line_pointer_size
);
6597 printf (_(" Copy\n"));
6600 case DW_LNS_advance_pc
:
6601 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
6603 state_machine_regs
.address
+= adv
;
6604 printf (_(" Advance PC by %d to %lx\n"), adv
,
6605 state_machine_regs
.address
);
6608 case DW_LNS_advance_line
:
6609 adv
= read_leb128 (data
, & bytes_read
, 1);
6611 state_machine_regs
.line
+= adv
;
6612 printf (_(" Advance Line by %d to %d\n"), adv
,
6613 state_machine_regs
.line
);
6616 case DW_LNS_set_file
:
6617 adv
= read_leb128 (data
, & bytes_read
, 0);
6619 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6621 state_machine_regs
.file
= adv
;
6624 case DW_LNS_set_column
:
6625 adv
= read_leb128 (data
, & bytes_read
, 0);
6627 printf (_(" Set column to %d\n"), adv
);
6628 state_machine_regs
.column
= adv
;
6631 case DW_LNS_negate_stmt
:
6632 adv
= state_machine_regs
.is_stmt
;
6634 printf (_(" Set is_stmt to %d\n"), adv
);
6635 state_machine_regs
.is_stmt
= adv
;
6638 case DW_LNS_set_basic_block
:
6639 printf (_(" Set basic block\n"));
6640 state_machine_regs
.basic_block
= 1;
6643 case DW_LNS_const_add_pc
:
6644 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
6645 * info
.li_min_insn_length
);
6646 state_machine_regs
.address
+= adv
;
6647 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
6648 state_machine_regs
.address
);
6651 case DW_LNS_fixed_advance_pc
:
6652 adv
= byte_get (data
, 2);
6654 state_machine_regs
.address
+= adv
;
6655 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6656 adv
, state_machine_regs
.address
);
6659 case DW_LNS_set_prologue_end
:
6660 printf (_(" Set prologue_end to true\n"));
6663 case DW_LNS_set_epilogue_begin
:
6664 printf (_(" Set epilogue_begin to true\n"));
6667 case DW_LNS_set_isa
:
6668 adv
= read_leb128 (data
, & bytes_read
, 0);
6670 printf (_(" Set ISA to %d\n"), adv
);
6674 printf (_(" Unknown opcode %d with operands: "), op_code
);
6677 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
6679 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
6680 i
== 1 ? "" : ", ");
6695 display_debug_pubnames (section
, start
, file
)
6696 Elf_Internal_Shdr
*section
;
6697 unsigned char *start
;
6698 FILE *file ATTRIBUTE_UNUSED
;
6700 DWARF2_Internal_PubNames pubnames
;
6703 end
= start
+ section
->sh_size
;
6705 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6709 unsigned char *data
;
6710 unsigned long offset
;
6711 int offset_size
, initial_length_size
;
6715 pubnames
.pn_length
= byte_get (data
, 4);
6717 if (pubnames
.pn_length
== 0xffffffff)
6719 pubnames
.pn_length
= byte_get (data
, 8);
6722 initial_length_size
= 12;
6727 initial_length_size
= 4;
6730 pubnames
.pn_version
= byte_get (data
, 2);
6732 pubnames
.pn_offset
= byte_get (data
, offset_size
);
6733 data
+= offset_size
;
6734 pubnames
.pn_size
= byte_get (data
, offset_size
);
6735 data
+= offset_size
;
6737 start
+= pubnames
.pn_length
+ initial_length_size
;
6739 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
6741 static int warned
= 0;
6745 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6752 printf (_(" Length: %ld\n"),
6753 pubnames
.pn_length
);
6754 printf (_(" Version: %d\n"),
6755 pubnames
.pn_version
);
6756 printf (_(" Offset into .debug_info section: %ld\n"),
6757 pubnames
.pn_offset
);
6758 printf (_(" Size of area in .debug_info section: %ld\n"),
6761 printf (_("\n Offset\tName\n"));
6765 offset
= byte_get (data
, offset_size
);
6769 data
+= offset_size
;
6770 printf (" %ld\t\t%s\n", offset
, data
);
6771 data
+= strlen ((char *) data
) + 1;
6774 while (offset
!= 0);
6787 case DW_TAG_padding
: return "DW_TAG_padding";
6788 case DW_TAG_array_type
: return "DW_TAG_array_type";
6789 case DW_TAG_class_type
: return "DW_TAG_class_type";
6790 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
6791 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
6792 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
6793 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
6794 case DW_TAG_label
: return "DW_TAG_label";
6795 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
6796 case DW_TAG_member
: return "DW_TAG_member";
6797 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
6798 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
6799 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
6800 case DW_TAG_string_type
: return "DW_TAG_string_type";
6801 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
6802 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
6803 case DW_TAG_typedef
: return "DW_TAG_typedef";
6804 case DW_TAG_union_type
: return "DW_TAG_union_type";
6805 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
6806 case DW_TAG_variant
: return "DW_TAG_variant";
6807 case DW_TAG_common_block
: return "DW_TAG_common_block";
6808 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
6809 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
6810 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
6811 case DW_TAG_module
: return "DW_TAG_module";
6812 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
6813 case DW_TAG_set_type
: return "DW_TAG_set_type";
6814 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
6815 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
6816 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
6817 case DW_TAG_base_type
: return "DW_TAG_base_type";
6818 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
6819 case DW_TAG_const_type
: return "DW_TAG_const_type";
6820 case DW_TAG_constant
: return "DW_TAG_constant";
6821 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
6822 case DW_TAG_file_type
: return "DW_TAG_file_type";
6823 case DW_TAG_friend
: return "DW_TAG_friend";
6824 case DW_TAG_namelist
: return "DW_TAG_namelist";
6825 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
6826 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
6827 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
6828 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
6829 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
6830 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
6831 case DW_TAG_try_block
: return "DW_TAG_try_block";
6832 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
6833 case DW_TAG_variable
: return "DW_TAG_variable";
6834 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
6835 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
6836 case DW_TAG_format_label
: return "DW_TAG_format_label";
6837 case DW_TAG_function_template
: return "DW_TAG_function_template";
6838 case DW_TAG_class_template
: return "DW_TAG_class_template";
6839 /* DWARF 2.1 values. */
6840 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
6841 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
6842 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
6843 case DW_TAG_namespace
: return "DW_TAG_namespace";
6844 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
6845 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
6846 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
6847 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
6849 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
6850 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
6851 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
6854 static char buffer
[100];
6856 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
6863 get_AT_name (attribute
)
6864 unsigned long attribute
;
6868 case DW_AT_sibling
: return "DW_AT_sibling";
6869 case DW_AT_location
: return "DW_AT_location";
6870 case DW_AT_name
: return "DW_AT_name";
6871 case DW_AT_ordering
: return "DW_AT_ordering";
6872 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
6873 case DW_AT_byte_size
: return "DW_AT_byte_size";
6874 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
6875 case DW_AT_bit_size
: return "DW_AT_bit_size";
6876 case DW_AT_element_list
: return "DW_AT_element_list";
6877 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
6878 case DW_AT_low_pc
: return "DW_AT_low_pc";
6879 case DW_AT_high_pc
: return "DW_AT_high_pc";
6880 case DW_AT_language
: return "DW_AT_language";
6881 case DW_AT_member
: return "DW_AT_member";
6882 case DW_AT_discr
: return "DW_AT_discr";
6883 case DW_AT_discr_value
: return "DW_AT_discr_value";
6884 case DW_AT_visibility
: return "DW_AT_visibility";
6885 case DW_AT_import
: return "DW_AT_import";
6886 case DW_AT_string_length
: return "DW_AT_string_length";
6887 case DW_AT_common_reference
: return "DW_AT_common_reference";
6888 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
6889 case DW_AT_const_value
: return "DW_AT_const_value";
6890 case DW_AT_containing_type
: return "DW_AT_containing_type";
6891 case DW_AT_default_value
: return "DW_AT_default_value";
6892 case DW_AT_inline
: return "DW_AT_inline";
6893 case DW_AT_is_optional
: return "DW_AT_is_optional";
6894 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
6895 case DW_AT_producer
: return "DW_AT_producer";
6896 case DW_AT_prototyped
: return "DW_AT_prototyped";
6897 case DW_AT_return_addr
: return "DW_AT_return_addr";
6898 case DW_AT_start_scope
: return "DW_AT_start_scope";
6899 case DW_AT_stride_size
: return "DW_AT_stride_size";
6900 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
6901 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
6902 case DW_AT_accessibility
: return "DW_AT_accessibility";
6903 case DW_AT_address_class
: return "DW_AT_address_class";
6904 case DW_AT_artificial
: return "DW_AT_artificial";
6905 case DW_AT_base_types
: return "DW_AT_base_types";
6906 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
6907 case DW_AT_count
: return "DW_AT_count";
6908 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
6909 case DW_AT_decl_column
: return "DW_AT_decl_column";
6910 case DW_AT_decl_file
: return "DW_AT_decl_file";
6911 case DW_AT_decl_line
: return "DW_AT_decl_line";
6912 case DW_AT_declaration
: return "DW_AT_declaration";
6913 case DW_AT_discr_list
: return "DW_AT_discr_list";
6914 case DW_AT_encoding
: return "DW_AT_encoding";
6915 case DW_AT_external
: return "DW_AT_external";
6916 case DW_AT_frame_base
: return "DW_AT_frame_base";
6917 case DW_AT_friend
: return "DW_AT_friend";
6918 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
6919 case DW_AT_macro_info
: return "DW_AT_macro_info";
6920 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
6921 case DW_AT_priority
: return "DW_AT_priority";
6922 case DW_AT_segment
: return "DW_AT_segment";
6923 case DW_AT_specification
: return "DW_AT_specification";
6924 case DW_AT_static_link
: return "DW_AT_static_link";
6925 case DW_AT_type
: return "DW_AT_type";
6926 case DW_AT_use_location
: return "DW_AT_use_location";
6927 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
6928 case DW_AT_virtuality
: return "DW_AT_virtuality";
6929 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
6930 /* DWARF 2.1 values. */
6931 case DW_AT_allocated
: return "DW_AT_allocated";
6932 case DW_AT_associated
: return "DW_AT_associated";
6933 case DW_AT_data_location
: return "DW_AT_data_location";
6934 case DW_AT_stride
: return "DW_AT_stride";
6935 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
6936 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
6937 case DW_AT_extension
: return "DW_AT_extension";
6938 case DW_AT_ranges
: return "DW_AT_ranges";
6939 case DW_AT_trampoline
: return "DW_AT_trampoline";
6940 case DW_AT_call_column
: return "DW_AT_call_column";
6941 case DW_AT_call_file
: return "DW_AT_call_file";
6942 case DW_AT_call_line
: return "DW_AT_call_line";
6943 /* SGI/MIPS extensions. */
6944 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
6945 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
6946 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
6947 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
6948 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
6949 case DW_AT_MIPS_software_pipeline_depth
:
6950 return "DW_AT_MIPS_software_pipeline_depth";
6951 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
6952 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
6953 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
6954 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
6955 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
6956 /* GNU extensions. */
6957 case DW_AT_sf_names
: return "DW_AT_sf_names";
6958 case DW_AT_src_info
: return "DW_AT_src_info";
6959 case DW_AT_mac_info
: return "DW_AT_mac_info";
6960 case DW_AT_src_coords
: return "DW_AT_src_coords";
6961 case DW_AT_body_begin
: return "DW_AT_body_begin";
6962 case DW_AT_body_end
: return "DW_AT_body_end";
6963 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
6964 /* UPC extension. */
6965 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
6968 static char buffer
[100];
6970 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
6977 get_FORM_name (form
)
6982 case DW_FORM_addr
: return "DW_FORM_addr";
6983 case DW_FORM_block2
: return "DW_FORM_block2";
6984 case DW_FORM_block4
: return "DW_FORM_block4";
6985 case DW_FORM_data2
: return "DW_FORM_data2";
6986 case DW_FORM_data4
: return "DW_FORM_data4";
6987 case DW_FORM_data8
: return "DW_FORM_data8";
6988 case DW_FORM_string
: return "DW_FORM_string";
6989 case DW_FORM_block
: return "DW_FORM_block";
6990 case DW_FORM_block1
: return "DW_FORM_block1";
6991 case DW_FORM_data1
: return "DW_FORM_data1";
6992 case DW_FORM_flag
: return "DW_FORM_flag";
6993 case DW_FORM_sdata
: return "DW_FORM_sdata";
6994 case DW_FORM_strp
: return "DW_FORM_strp";
6995 case DW_FORM_udata
: return "DW_FORM_udata";
6996 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
6997 case DW_FORM_ref1
: return "DW_FORM_ref1";
6998 case DW_FORM_ref2
: return "DW_FORM_ref2";
6999 case DW_FORM_ref4
: return "DW_FORM_ref4";
7000 case DW_FORM_ref8
: return "DW_FORM_ref8";
7001 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
7002 case DW_FORM_indirect
: return "DW_FORM_indirect";
7005 static char buffer
[100];
7007 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
7013 /* FIXME: There are better and more effiecint ways to handle
7014 these structures. For now though, I just want something that
7015 is simple to implement. */
7016 typedef struct abbrev_attr
7018 unsigned long attribute
;
7020 struct abbrev_attr
*next
;
7024 typedef struct abbrev_entry
7026 unsigned long entry
;
7029 struct abbrev_attr
*first_attr
;
7030 struct abbrev_attr
*last_attr
;
7031 struct abbrev_entry
*next
;
7035 static abbrev_entry
*first_abbrev
= NULL
;
7036 static abbrev_entry
*last_abbrev
= NULL
;
7041 abbrev_entry
*abbrev
;
7043 for (abbrev
= first_abbrev
; abbrev
;)
7045 abbrev_entry
*next
= abbrev
->next
;
7048 for (attr
= abbrev
->first_attr
; attr
;)
7050 abbrev_attr
*next
= attr
->next
;
7060 last_abbrev
= first_abbrev
= NULL
;
7064 add_abbrev (number
, tag
, children
)
7065 unsigned long number
;
7069 abbrev_entry
*entry
;
7071 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
7077 entry
->entry
= number
;
7079 entry
->children
= children
;
7080 entry
->first_attr
= NULL
;
7081 entry
->last_attr
= NULL
;
7084 if (first_abbrev
== NULL
)
7085 first_abbrev
= entry
;
7087 last_abbrev
->next
= entry
;
7089 last_abbrev
= entry
;
7093 add_abbrev_attr (attribute
, form
)
7094 unsigned long attribute
;
7099 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
7105 attr
->attribute
= attribute
;
7109 if (last_abbrev
->first_attr
== NULL
)
7110 last_abbrev
->first_attr
= attr
;
7112 last_abbrev
->last_attr
->next
= attr
;
7114 last_abbrev
->last_attr
= attr
;
7117 /* Processes the (partial) contents of a .debug_abbrev section.
7118 Returns NULL if the end of the section was encountered.
7119 Returns the address after the last byte read if the end of
7120 an abbreviation set was found. */
7122 static unsigned char *
7123 process_abbrev_section (start
, end
)
7124 unsigned char *start
;
7127 if (first_abbrev
!= NULL
)
7133 unsigned long entry
;
7135 unsigned long attribute
;
7138 entry
= read_leb128 (start
, & bytes_read
, 0);
7139 start
+= bytes_read
;
7141 /* A single zero is supposed to end the section according
7142 to the standard. If there's more, then signal that to
7145 return start
== end
? NULL
: start
;
7147 tag
= read_leb128 (start
, & bytes_read
, 0);
7148 start
+= bytes_read
;
7150 children
= *start
++;
7152 add_abbrev (entry
, tag
, children
);
7158 attribute
= read_leb128 (start
, & bytes_read
, 0);
7159 start
+= bytes_read
;
7161 form
= read_leb128 (start
, & bytes_read
, 0);
7162 start
+= bytes_read
;
7165 add_abbrev_attr (attribute
, form
);
7167 while (attribute
!= 0);
7175 display_debug_macinfo (section
, start
, file
)
7176 Elf_Internal_Shdr
*section
;
7177 unsigned char *start
;
7178 FILE *file ATTRIBUTE_UNUSED
;
7180 unsigned char *end
= start
+ section
->sh_size
;
7181 unsigned char *curr
= start
;
7182 unsigned int bytes_read
;
7183 enum dwarf_macinfo_record_type op
;
7185 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7189 unsigned int lineno
;
7197 case DW_MACINFO_start_file
:
7199 unsigned int filenum
;
7201 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7203 filenum
= read_leb128 (curr
, & bytes_read
, 0);
7206 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno
, filenum
);
7210 case DW_MACINFO_end_file
:
7211 printf (_(" DW_MACINFO_end_file\n"));
7214 case DW_MACINFO_define
:
7215 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7218 curr
+= strlen (string
) + 1;
7219 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno
, string
);
7222 case DW_MACINFO_undef
:
7223 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7226 curr
+= strlen (string
) + 1;
7227 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno
, string
);
7230 case DW_MACINFO_vendor_ext
:
7232 unsigned int constant
;
7234 constant
= read_leb128 (curr
, & bytes_read
, 0);
7237 curr
+= strlen (string
) + 1;
7238 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant
, string
);
7249 display_debug_abbrev (section
, start
, file
)
7250 Elf_Internal_Shdr
*section
;
7251 unsigned char *start
;
7252 FILE *file ATTRIBUTE_UNUSED
;
7254 abbrev_entry
*entry
;
7255 unsigned char *end
= start
+ section
->sh_size
;
7257 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7261 start
= process_abbrev_section (start
, end
);
7263 if (first_abbrev
== NULL
)
7266 printf (_(" Number TAG\n"));
7268 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
7272 printf (_(" %ld %s [%s]\n"),
7274 get_TAG_name (entry
->tag
),
7275 entry
->children
? _("has children") : _("no children"));
7277 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
7279 printf (_(" %-18s %s\n"),
7280 get_AT_name (attr
->attribute
),
7281 get_FORM_name (attr
->form
));
7295 static unsigned char *
7296 display_block (data
, length
)
7297 unsigned char *data
;
7298 unsigned long length
;
7300 printf (_(" %lu byte block: "), length
);
7303 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
7309 decode_location_expression (data
, pointer_size
, length
)
7310 unsigned char * data
;
7311 unsigned int pointer_size
;
7312 unsigned long length
;
7316 unsigned long uvalue
;
7317 unsigned char *end
= data
+ length
;
7326 printf ("DW_OP_addr: %lx",
7327 (unsigned long) byte_get (data
, pointer_size
));
7328 data
+= pointer_size
;
7331 printf ("DW_OP_deref");
7334 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
7337 printf ("DW_OP_const1s: %ld", (long) byte_get (data
++, 1));
7340 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
7344 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
7348 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
7352 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
7356 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
7357 (unsigned long) byte_get (data
+ 4, 4));
7361 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
7362 (long) byte_get (data
+ 4, 4));
7366 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
7370 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
7374 printf ("DW_OP_dup");
7377 printf ("DW_OP_drop");
7380 printf ("DW_OP_over");
7383 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
7386 printf ("DW_OP_swap");
7389 printf ("DW_OP_rot");
7392 printf ("DW_OP_xderef");
7395 printf ("DW_OP_abs");
7398 printf ("DW_OP_and");
7401 printf ("DW_OP_div");
7404 printf ("DW_OP_minus");
7407 printf ("DW_OP_mod");
7410 printf ("DW_OP_mul");
7413 printf ("DW_OP_neg");
7416 printf ("DW_OP_not");
7419 printf ("DW_OP_or");
7422 printf ("DW_OP_plus");
7424 case DW_OP_plus_uconst
:
7425 printf ("DW_OP_plus_uconst: %lu",
7426 read_leb128 (data
, &bytes_read
, 0));
7430 printf ("DW_OP_shl");
7433 printf ("DW_OP_shr");
7436 printf ("DW_OP_shra");
7439 printf ("DW_OP_xor");
7442 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
7446 printf ("DW_OP_eq");
7449 printf ("DW_OP_ge");
7452 printf ("DW_OP_gt");
7455 printf ("DW_OP_le");
7458 printf ("DW_OP_lt");
7461 printf ("DW_OP_ne");
7464 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
7500 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
7535 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
7570 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
7571 read_leb128 (data
, &bytes_read
, 1));
7576 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
7580 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
7584 uvalue
= read_leb128 (data
, &bytes_read
, 0);
7586 printf ("DW_OP_bregx: %lu %ld", uvalue
,
7587 read_leb128 (data
, &bytes_read
, 1));
7591 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
7594 case DW_OP_deref_size
:
7595 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
7597 case DW_OP_xderef_size
:
7598 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
7601 printf ("DW_OP_nop");
7604 /* DWARF 3 extensions. */
7605 case DW_OP_push_object_address
:
7606 printf ("DW_OP_push_object_address");
7609 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2));
7613 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4));
7616 case DW_OP_call_ref
:
7617 printf ("DW_OP_call_ref");
7620 /* GNU extensions. */
7621 case DW_OP_GNU_push_tls_address
:
7622 printf ("DW_OP_GNU_push_tls_address");
7626 if (op
>= DW_OP_lo_user
7627 && op
<= DW_OP_hi_user
)
7628 printf (_("(User defined location op)"));
7630 printf (_("(Unknown location op)"));
7631 /* No way to tell where the next op is, so just bail. */
7635 /* Separate the ops. */
7640 static const char *debug_loc_contents
;
7641 static bfd_vma debug_loc_size
;
7644 load_debug_loc (file
)
7647 Elf_Internal_Shdr
*sec
;
7650 /* If it is already loaded, do nothing. */
7651 if (debug_loc_contents
!= NULL
)
7654 /* Locate the .debug_loc section. */
7655 for (i
= 0, sec
= section_headers
;
7656 i
< elf_header
.e_shnum
;
7658 if (strcmp (SECTION_NAME (sec
), ".debug_loc") == 0)
7661 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7664 debug_loc_size
= sec
->sh_size
;
7666 debug_loc_contents
= ((char *)
7667 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7668 _("debug_loc section data")));
7674 if (debug_loc_contents
== NULL
)
7677 free ((char *) debug_loc_contents
);
7678 debug_loc_contents
= NULL
;
7684 display_debug_loc (section
, start
, file
)
7685 Elf_Internal_Shdr
*section
;
7686 unsigned char *start
;
7687 FILE *file ATTRIBUTE_UNUSED
;
7689 unsigned char *section_end
;
7690 unsigned long bytes
;
7691 unsigned char *section_begin
= start
;
7694 addr
= section
->sh_addr
;
7695 bytes
= section
->sh_size
;
7696 section_end
= start
+ bytes
;
7700 printf (_("\nThe .debug_loc section is empty.\n"));
7704 printf (_("Contents of the .debug_loc section:\n\n"));
7705 printf (_("\n Offset Begin End Expression\n"));
7707 while (start
< section_end
)
7709 unsigned long begin
;
7711 unsigned short length
;
7712 unsigned long offset
;
7714 offset
= start
- section_begin
;
7718 /* Normally, the lists in the debug_loc section are related to a
7719 given compilation unit, and thus, we would use the pointer size
7720 of that compilation unit. However, since we are displaying it
7721 seperately here, we either have to store pointer sizes of all
7722 compilation units, or assume they don't change. We assume,
7723 like the debug_line display, that it doesn't change. */
7724 begin
= byte_get (start
, debug_line_pointer_size
);
7725 start
+= debug_line_pointer_size
;
7726 end
= byte_get (start
, debug_line_pointer_size
);
7727 start
+= debug_line_pointer_size
;
7729 if (begin
== 0 && end
== 0)
7732 /* For now, skip any base address specifiers. */
7733 if (begin
== 0xffffffff)
7739 length
= byte_get (start
, 2);
7742 printf (" %8.8lx %8.8lx %8.8lx (", offset
, begin
, end
);
7743 decode_location_expression (start
, debug_line_pointer_size
, length
);
7753 static const char *debug_str_contents
;
7754 static bfd_vma debug_str_size
;
7757 load_debug_str (file
)
7760 Elf_Internal_Shdr
*sec
;
7763 /* If it is already loaded, do nothing. */
7764 if (debug_str_contents
!= NULL
)
7767 /* Locate the .debug_str section. */
7768 for (i
= 0, sec
= section_headers
;
7769 i
< elf_header
.e_shnum
;
7771 if (strcmp (SECTION_NAME (sec
), ".debug_str") == 0)
7774 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7777 debug_str_size
= sec
->sh_size
;
7779 debug_str_contents
= ((char *)
7780 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7781 _("debug_str section data")));
7787 if (debug_str_contents
== NULL
)
7790 free ((char *) debug_str_contents
);
7791 debug_str_contents
= NULL
;
7796 fetch_indirect_string (offset
)
7797 unsigned long offset
;
7799 if (debug_str_contents
== NULL
)
7800 return _("<no .debug_str section>");
7802 if (offset
> debug_str_size
)
7803 return _("<offset is too big>");
7805 return debug_str_contents
+ offset
;
7809 display_debug_str (section
, start
, file
)
7810 Elf_Internal_Shdr
*section
;
7811 unsigned char *start
;
7812 FILE *file ATTRIBUTE_UNUSED
;
7814 unsigned long bytes
;
7817 addr
= section
->sh_addr
;
7818 bytes
= section
->sh_size
;
7822 printf (_("\nThe .debug_str section is empty.\n"));
7826 printf (_("Contents of the .debug_str section:\n\n"));
7834 lbytes
= (bytes
> 16 ? 16 : bytes
);
7836 printf (" 0x%8.8lx ", (unsigned long) addr
);
7838 for (j
= 0; j
< 16; j
++)
7841 printf ("%2.2x", start
[j
]);
7849 for (j
= 0; j
< lbytes
; j
++)
7852 if (k
>= ' ' && k
< 0x80)
7868 static unsigned char *
7869 read_and_display_attr_value (attribute
, form
, data
, cu_offset
, pointer_size
,
7870 offset_size
, dwarf_version
)
7871 unsigned long attribute
;
7873 unsigned char *data
;
7874 unsigned long cu_offset
;
7875 unsigned long pointer_size
;
7876 unsigned long offset_size
;
7879 unsigned long uvalue
= 0;
7880 unsigned char *block_start
= NULL
;
7888 case DW_FORM_ref_addr
:
7889 if (dwarf_version
== 2)
7891 uvalue
= byte_get (data
, pointer_size
);
7892 data
+= pointer_size
;
7894 else if (dwarf_version
== 3)
7896 uvalue
= byte_get (data
, offset_size
);
7897 data
+= offset_size
;
7901 error (_("Internal error: DWARF version is not 2 or 3.\n"));
7906 uvalue
= byte_get (data
, pointer_size
);
7907 data
+= pointer_size
;
7911 uvalue
= byte_get (data
, offset_size
);
7912 data
+= offset_size
;
7918 uvalue
= byte_get (data
++, 1);
7923 uvalue
= byte_get (data
, 2);
7929 uvalue
= byte_get (data
, 4);
7934 uvalue
= read_leb128 (data
, & bytes_read
, 1);
7938 case DW_FORM_ref_udata
:
7940 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7944 case DW_FORM_indirect
:
7945 form
= read_leb128 (data
, & bytes_read
, 0);
7947 printf (" %s", get_FORM_name (form
));
7948 return read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
7949 pointer_size
, offset_size
,
7955 case DW_FORM_ref_addr
:
7956 printf (" <#%lx>", uvalue
);
7962 case DW_FORM_ref_udata
:
7963 printf (" <%lx>", uvalue
+ cu_offset
);
7967 printf (" %#lx", uvalue
);
7975 printf (" %ld", uvalue
);
7980 uvalue
= byte_get (data
, 4);
7981 printf (" %lx", uvalue
);
7982 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
7986 case DW_FORM_string
:
7987 printf (" %s", data
);
7988 data
+= strlen ((char *) data
) + 1;
7992 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7993 block_start
= data
+ bytes_read
;
7994 data
= display_block (block_start
, uvalue
);
7997 case DW_FORM_block1
:
7998 uvalue
= byte_get (data
, 1);
7999 block_start
= data
+ 1;
8000 data
= display_block (block_start
, uvalue
);
8003 case DW_FORM_block2
:
8004 uvalue
= byte_get (data
, 2);
8005 block_start
= data
+ 2;
8006 data
= display_block (block_start
, uvalue
);
8009 case DW_FORM_block4
:
8010 uvalue
= byte_get (data
, 4);
8011 block_start
= data
+ 4;
8012 data
= display_block (block_start
, uvalue
);
8016 printf (_(" (indirect string, offset: 0x%lx): %s"),
8017 uvalue
, fetch_indirect_string (uvalue
));
8020 case DW_FORM_indirect
:
8021 /* Handled above. */
8025 warn (_("Unrecognized form: %d\n"), form
);
8029 /* For some attributes we can display futher information. */
8038 case DW_INL_not_inlined
:
8039 printf (_("(not inlined)"));
8041 case DW_INL_inlined
:
8042 printf (_("(inlined)"));
8044 case DW_INL_declared_not_inlined
:
8045 printf (_("(declared as inline but ignored)"));
8047 case DW_INL_declared_inlined
:
8048 printf (_("(declared as inline and inlined)"));
8051 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
8056 case DW_AT_language
:
8059 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
8060 case DW_LANG_C89
: printf ("(ANSI C)"); break;
8061 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
8062 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
8063 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
8064 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
8065 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
8066 case DW_LANG_Ada83
: printf ("(Ada)"); break;
8067 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
8068 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
8069 /* DWARF 2.1 values. */
8070 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
8071 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
8072 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
8073 /* MIPS extension. */
8074 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
8075 /* UPC extension. */
8076 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
8078 printf ("(Unknown: %lx)", uvalue
);
8083 case DW_AT_encoding
:
8086 case DW_ATE_void
: printf ("(void)"); break;
8087 case DW_ATE_address
: printf ("(machine address)"); break;
8088 case DW_ATE_boolean
: printf ("(boolean)"); break;
8089 case DW_ATE_complex_float
: printf ("(complex float)"); break;
8090 case DW_ATE_float
: printf ("(float)"); break;
8091 case DW_ATE_signed
: printf ("(signed)"); break;
8092 case DW_ATE_signed_char
: printf ("(signed char)"); break;
8093 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
8094 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
8095 /* DWARF 2.1 value. */
8096 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
8098 if (uvalue
>= DW_ATE_lo_user
8099 && uvalue
<= DW_ATE_hi_user
)
8100 printf ("(user defined type)");
8102 printf ("(unknown type)");
8107 case DW_AT_accessibility
:
8110 case DW_ACCESS_public
: printf ("(public)"); break;
8111 case DW_ACCESS_protected
: printf ("(protected)"); break;
8112 case DW_ACCESS_private
: printf ("(private)"); break;
8114 printf ("(unknown accessibility)");
8119 case DW_AT_visibility
:
8122 case DW_VIS_local
: printf ("(local)"); break;
8123 case DW_VIS_exported
: printf ("(exported)"); break;
8124 case DW_VIS_qualified
: printf ("(qualified)"); break;
8125 default: printf ("(unknown visibility)"); break;
8129 case DW_AT_virtuality
:
8132 case DW_VIRTUALITY_none
: printf ("(none)"); break;
8133 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
8134 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
8135 default: printf ("(unknown virtuality)"); break;
8139 case DW_AT_identifier_case
:
8142 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
8143 case DW_ID_up_case
: printf ("(up_case)"); break;
8144 case DW_ID_down_case
: printf ("(down_case)"); break;
8145 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
8146 default: printf ("(unknown case)"); break;
8150 case DW_AT_calling_convention
:
8153 case DW_CC_normal
: printf ("(normal)"); break;
8154 case DW_CC_program
: printf ("(program)"); break;
8155 case DW_CC_nocall
: printf ("(nocall)"); break;
8157 if (uvalue
>= DW_CC_lo_user
8158 && uvalue
<= DW_CC_hi_user
)
8159 printf ("(user defined)");
8161 printf ("(unknown convention)");
8165 case DW_AT_ordering
:
8168 case -1: printf ("(undefined)"); break;
8169 case 0: printf ("(row major)"); break;
8170 case 1: printf ("(column major)"); break;
8174 case DW_AT_frame_base
:
8175 case DW_AT_location
:
8176 case DW_AT_data_member_location
:
8177 case DW_AT_vtable_elem_location
:
8178 case DW_AT_allocated
:
8179 case DW_AT_associated
:
8180 case DW_AT_data_location
:
8182 case DW_AT_upper_bound
:
8183 case DW_AT_lower_bound
:
8187 decode_location_expression (block_start
, pointer_size
, uvalue
);
8190 else if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
8193 printf ("location list");
8205 static unsigned char *
8206 read_and_display_attr (attribute
, form
, data
, cu_offset
, pointer_size
,
8207 offset_size
, dwarf_version
)
8208 unsigned long attribute
;
8210 unsigned char *data
;
8211 unsigned long cu_offset
;
8212 unsigned long pointer_size
;
8213 unsigned long offset_size
;
8216 printf (" %-18s:", get_AT_name (attribute
));
8217 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
8218 pointer_size
, offset_size
, dwarf_version
);
8224 display_debug_info (section
, start
, file
)
8225 Elf_Internal_Shdr
*section
;
8226 unsigned char *start
;
8229 unsigned char *end
= start
+ section
->sh_size
;
8230 unsigned char *section_begin
= start
;
8232 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8234 load_debug_str (file
);
8235 load_debug_loc (file
);
8239 DWARF2_Internal_CompUnit compunit
;
8240 Elf_Internal_Shdr
*relsec
;
8241 unsigned char *hdrptr
;
8242 unsigned char *cu_abbrev_offset_ptr
;
8243 unsigned char *tags
;
8246 unsigned long cu_offset
;
8248 int initial_length_size
;
8252 compunit
.cu_length
= byte_get (hdrptr
, 4);
8255 if (compunit
.cu_length
== 0xffffffff)
8257 compunit
.cu_length
= byte_get (hdrptr
, 8);
8260 initial_length_size
= 12;
8265 initial_length_size
= 4;
8268 compunit
.cu_version
= byte_get (hdrptr
, 2);
8271 cu_abbrev_offset_ptr
= hdrptr
;
8272 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
8273 hdrptr
+= offset_size
;
8275 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
8278 /* Check for RELA relocations in the
8279 abbrev_offset address, and apply them. */
8280 for (relsec
= section_headers
;
8281 relsec
< section_headers
+ elf_header
.e_shnum
;
8284 unsigned long nrelas
;
8285 Elf_Internal_Rela
*rela
, *rp
;
8286 Elf_Internal_Shdr
*symsec
;
8287 Elf_Internal_Sym
*symtab
;
8288 Elf_Internal_Sym
*sym
;
8290 if (relsec
->sh_type
!= SHT_RELA
8291 || SECTION_HEADER (relsec
->sh_info
) != section
8292 || relsec
->sh_size
== 0)
8295 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8299 symsec
= SECTION_HEADER (relsec
->sh_link
);
8300 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
8302 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8305 != (bfd_vma
) (cu_abbrev_offset_ptr
- section_begin
))
8310 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
8312 if (ELF32_R_SYM (rp
->r_info
) != 0
8313 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8315 warn (_("Skipping unexpected symbol type %u\n"),
8316 ELF32_ST_TYPE (sym
->st_info
));
8322 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
8324 if (ELF64_R_SYM (rp
->r_info
) != 0
8325 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8327 warn (_("Skipping unexpected symbol type %u\n"),
8328 ELF64_ST_TYPE (sym
->st_info
));
8333 compunit
.cu_abbrev_offset
= rp
->r_addend
;
8342 cu_offset
= start
- section_begin
;
8343 start
+= compunit
.cu_length
+ initial_length_size
;
8345 printf (_(" Compilation Unit @ %lx:\n"), cu_offset
);
8346 printf (_(" Length: %ld\n"), compunit
.cu_length
);
8347 printf (_(" Version: %d\n"), compunit
.cu_version
);
8348 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
8349 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
8351 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
8353 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
8359 /* Read in the abbrevs used by this compilation unit. */
8361 Elf_Internal_Shdr
*sec
;
8362 unsigned char *begin
;
8364 /* Locate the .debug_abbrev section and process it. */
8365 for (i
= 0, sec
= section_headers
;
8366 i
< elf_header
.e_shnum
;
8368 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
8371 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
8373 warn (_("Unable to locate .debug_abbrev section!\n"));
8377 begin
= ((unsigned char *)
8378 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
8379 _("debug_abbrev section data")));
8383 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
8384 begin
+ sec
->sh_size
);
8390 while (tags
< start
)
8393 unsigned long abbrev_number
;
8394 abbrev_entry
*entry
;
8397 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
8400 /* A null DIE marks the end of a list of children. */
8401 if (abbrev_number
== 0)
8407 /* Scan through the abbreviation list until we reach the
8409 for (entry
= first_abbrev
;
8410 entry
&& entry
->entry
!= abbrev_number
;
8411 entry
= entry
->next
)
8416 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8421 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8423 (unsigned long) (tags
- section_begin
- bytes_read
),
8425 get_TAG_name (entry
->tag
));
8427 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
8428 tags
= read_and_display_attr (attr
->attribute
,
8431 compunit
.cu_pointer_size
,
8433 compunit
.cu_version
);
8435 if (entry
->children
)
8449 display_debug_aranges (section
, start
, file
)
8450 Elf_Internal_Shdr
*section
;
8451 unsigned char *start
;
8452 FILE *file ATTRIBUTE_UNUSED
;
8454 unsigned char *end
= start
+ section
->sh_size
;
8456 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8460 unsigned char *hdrptr
;
8461 DWARF2_Internal_ARange arange
;
8462 unsigned char *ranges
;
8463 unsigned long length
;
8464 unsigned long address
;
8467 int initial_length_size
;
8471 arange
.ar_length
= byte_get (hdrptr
, 4);
8474 if (arange
.ar_length
== 0xffffffff)
8476 arange
.ar_length
= byte_get (hdrptr
, 8);
8479 initial_length_size
= 12;
8484 initial_length_size
= 4;
8487 arange
.ar_version
= byte_get (hdrptr
, 2);
8490 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
8491 hdrptr
+= offset_size
;
8493 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
8496 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
8499 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
8501 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
8505 printf (_(" Length: %ld\n"), arange
.ar_length
);
8506 printf (_(" Version: %d\n"), arange
.ar_version
);
8507 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
8508 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
8509 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
8511 printf (_("\n Address Length\n"));
8515 /* Must pad to an alignment boundary that is twice the pointer size. */
8516 excess
= (hdrptr
- start
) % (2 * arange
.ar_pointer_size
);
8518 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
8522 address
= byte_get (ranges
, arange
.ar_pointer_size
);
8524 ranges
+= arange
.ar_pointer_size
;
8526 length
= byte_get (ranges
, arange
.ar_pointer_size
);
8528 ranges
+= arange
.ar_pointer_size
;
8530 /* A pair of zeros marks the end of the list. */
8531 if (address
== 0 && length
== 0)
8534 printf (" %8.8lx %lu\n", address
, length
);
8537 start
+= arange
.ar_length
+ initial_length_size
;
8545 typedef struct Frame_Chunk
8547 struct Frame_Chunk
*next
;
8548 unsigned char *chunk_start
;
8550 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8551 short int *col_type
;
8554 unsigned int code_factor
;
8556 unsigned long pc_begin
;
8557 unsigned long pc_range
;
8561 unsigned char fde_encoding
;
8565 /* A marker for a col_type that means this column was never referenced
8566 in the frame info. */
8567 #define DW_CFA_unreferenced (-1)
8569 static void frame_need_space
PARAMS ((Frame_Chunk
*, int));
8570 static void frame_display_row
PARAMS ((Frame_Chunk
*, int *, int *));
8571 static int size_of_encoded_value
PARAMS ((int));
8574 frame_need_space (fc
, reg
)
8578 int prev
= fc
->ncols
;
8580 if (reg
< fc
->ncols
)
8583 fc
->ncols
= reg
+ 1;
8584 fc
->col_type
= (short int *) xrealloc (fc
->col_type
,
8585 fc
->ncols
* sizeof (short int));
8586 fc
->col_offset
= (int *) xrealloc (fc
->col_offset
,
8587 fc
->ncols
* sizeof (int));
8589 while (prev
< fc
->ncols
)
8591 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8592 fc
->col_offset
[prev
] = 0;
8598 frame_display_row (fc
, need_col_headers
, max_regs
)
8600 int *need_col_headers
;
8606 if (*max_regs
< fc
->ncols
)
8607 *max_regs
= fc
->ncols
;
8609 if (*need_col_headers
)
8611 *need_col_headers
= 0;
8613 printf (" LOC CFA ");
8615 for (r
= 0; r
< *max_regs
; r
++)
8616 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8621 printf ("r%-4d", r
);
8627 printf ("%08lx ", fc
->pc_begin
);
8628 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
8629 printf ("%-8s ", tmp
);
8631 for (r
= 0; r
< fc
->ncols
; r
++)
8633 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8635 switch (fc
->col_type
[r
])
8637 case DW_CFA_undefined
:
8640 case DW_CFA_same_value
:
8644 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8646 case DW_CFA_register
:
8647 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
8650 strcpy (tmp
, "n/a");
8653 printf ("%-5s", tmp
);
8660 size_of_encoded_value (encoding
)
8663 switch (encoding
& 0x7)
8666 case 0: return is_32bit_elf
? 4 : 8;
8673 #define GET(N) byte_get (start, N); start += N
8674 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8675 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8678 display_debug_frames (section
, start
, file
)
8679 Elf_Internal_Shdr
*section
;
8680 unsigned char *start
;
8681 FILE *file ATTRIBUTE_UNUSED
;
8683 unsigned char *end
= start
+ section
->sh_size
;
8684 unsigned char *section_start
= start
;
8685 Frame_Chunk
*chunks
= 0;
8686 Frame_Chunk
*remembered_state
= 0;
8688 int is_eh
= (strcmp (SECTION_NAME (section
), ".eh_frame") == 0);
8691 int addr_size
= is_32bit_elf
? 4 : 8;
8693 printf (_("The section %s contains:\n"), SECTION_NAME (section
));
8697 unsigned char *saved_start
;
8698 unsigned char *block_end
;
8699 unsigned long length
;
8700 unsigned long cie_id
;
8703 int need_col_headers
= 1;
8704 unsigned char *augmentation_data
= NULL
;
8705 unsigned long augmentation_data_len
= 0;
8706 int encoded_ptr_size
= addr_size
;
8708 int initial_length_size
;
8710 saved_start
= start
;
8711 length
= byte_get (start
, 4); start
+= 4;
8715 printf ("\n%08lx ZERO terminator\n\n",
8716 (unsigned long)(saved_start
- section_start
));
8720 if (length
== 0xffffffff)
8722 length
= byte_get (start
, 8);
8725 initial_length_size
= 12;
8730 initial_length_size
= 4;
8733 block_end
= saved_start
+ length
+ initial_length_size
;
8734 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
8736 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
8740 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8741 memset (fc
, 0, sizeof (Frame_Chunk
));
8745 fc
->chunk_start
= saved_start
;
8747 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8748 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8749 frame_need_space (fc
, max_regs
-1);
8753 fc
->augmentation
= start
;
8754 start
= strchr (start
, '\0') + 1;
8756 if (fc
->augmentation
[0] == 'z')
8758 fc
->code_factor
= LEB ();
8759 fc
->data_factor
= SLEB ();
8760 fc
->ra
= byte_get (start
, 1); start
+= 1;
8761 augmentation_data_len
= LEB ();
8762 augmentation_data
= start
;
8763 start
+= augmentation_data_len
;
8765 else if (strcmp (fc
->augmentation
, "eh") == 0)
8768 fc
->code_factor
= LEB ();
8769 fc
->data_factor
= SLEB ();
8770 fc
->ra
= byte_get (start
, 1); start
+= 1;
8774 fc
->code_factor
= LEB ();
8775 fc
->data_factor
= SLEB ();
8776 fc
->ra
= byte_get (start
, 1); start
+= 1;
8780 if (do_debug_frames_interp
)
8781 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8782 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8783 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
8787 printf ("\n%08lx %08lx %08lx CIE\n",
8788 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
8789 printf (" Version: %d\n", version
);
8790 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8791 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8792 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8793 printf (" Return address column: %d\n", fc
->ra
);
8795 if (augmentation_data_len
)
8798 printf (" Augmentation data: ");
8799 for (i
= 0; i
< augmentation_data_len
; ++i
)
8800 printf (" %02x", augmentation_data
[i
]);
8806 if (augmentation_data_len
)
8808 unsigned char *p
, *q
;
8809 p
= fc
->augmentation
+ 1;
8810 q
= augmentation_data
;
8817 q
+= 1 + size_of_encoded_value (*q
);
8819 fc
->fde_encoding
= *q
++;
8825 if (fc
->fde_encoding
)
8826 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8829 frame_need_space (fc
, fc
->ra
);
8833 unsigned char *look_for
;
8834 static Frame_Chunk fde_fc
;
8837 memset (fc
, 0, sizeof (Frame_Chunk
));
8839 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
8841 for (cie
= chunks
; cie
; cie
= cie
->next
)
8842 if (cie
->chunk_start
== look_for
)
8847 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8848 cie_id
, saved_start
);
8851 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8852 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8853 frame_need_space (fc
, max_regs
- 1);
8855 fc
->augmentation
= "";
8856 fc
->fde_encoding
= 0;
8860 fc
->ncols
= cie
->ncols
;
8861 fc
->col_type
= (short int *) xmalloc (fc
->ncols
* sizeof (short int));
8862 fc
->col_offset
= (int *) xmalloc (fc
->ncols
* sizeof (int));
8863 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8864 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8865 fc
->augmentation
= cie
->augmentation
;
8866 fc
->code_factor
= cie
->code_factor
;
8867 fc
->data_factor
= cie
->data_factor
;
8868 fc
->cfa_reg
= cie
->cfa_reg
;
8869 fc
->cfa_offset
= cie
->cfa_offset
;
8871 frame_need_space (fc
, max_regs
-1);
8872 fc
->fde_encoding
= cie
->fde_encoding
;
8875 if (fc
->fde_encoding
)
8876 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8878 fc
->pc_begin
= byte_get (start
, encoded_ptr_size
);
8879 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
8880 fc
->pc_begin
+= section
->sh_addr
+ (start
- section_start
);
8881 start
+= encoded_ptr_size
;
8882 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
8883 start
+= encoded_ptr_size
;
8885 if (cie
->augmentation
[0] == 'z')
8887 augmentation_data_len
= LEB ();
8888 augmentation_data
= start
;
8889 start
+= augmentation_data_len
;
8892 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8893 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8894 (unsigned long)(cie
->chunk_start
- section_start
),
8895 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
8896 if (! do_debug_frames_interp
&& augmentation_data_len
)
8899 printf (" Augmentation data: ");
8900 for (i
= 0; i
< augmentation_data_len
; ++i
)
8901 printf (" %02x", augmentation_data
[i
]);
8907 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8908 about to interpret instructions for the chunk. */
8910 if (do_debug_frames_interp
)
8912 /* Start by making a pass over the chunk, allocating storage
8913 and taking note of what registers are used. */
8914 unsigned char *tmp
= start
;
8916 while (start
< block_end
)
8926 /* Warning: if you add any more cases to this switch, be
8927 sure to add them to the corresponding switch below. */
8930 case DW_CFA_advance_loc
:
8934 frame_need_space (fc
, opa
);
8935 fc
->col_type
[opa
] = DW_CFA_undefined
;
8937 case DW_CFA_restore
:
8938 frame_need_space (fc
, opa
);
8939 fc
->col_type
[opa
] = DW_CFA_undefined
;
8941 case DW_CFA_set_loc
:
8942 start
+= encoded_ptr_size
;
8944 case DW_CFA_advance_loc1
:
8947 case DW_CFA_advance_loc2
:
8950 case DW_CFA_advance_loc4
:
8953 case DW_CFA_offset_extended
:
8954 reg
= LEB (); LEB ();
8955 frame_need_space (fc
, reg
);
8956 fc
->col_type
[reg
] = DW_CFA_undefined
;
8958 case DW_CFA_restore_extended
:
8960 frame_need_space (fc
, reg
);
8961 fc
->col_type
[reg
] = DW_CFA_undefined
;
8963 case DW_CFA_undefined
:
8965 frame_need_space (fc
, reg
);
8966 fc
->col_type
[reg
] = DW_CFA_undefined
;
8968 case DW_CFA_same_value
:
8970 frame_need_space (fc
, reg
);
8971 fc
->col_type
[reg
] = DW_CFA_undefined
;
8973 case DW_CFA_register
:
8974 reg
= LEB (); LEB ();
8975 frame_need_space (fc
, reg
);
8976 fc
->col_type
[reg
] = DW_CFA_undefined
;
8978 case DW_CFA_def_cfa
:
8981 case DW_CFA_def_cfa_register
:
8984 case DW_CFA_def_cfa_offset
:
8987 case DW_CFA_offset_extended_sf
:
8988 reg
= LEB (); SLEB ();
8989 frame_need_space (fc
, reg
);
8990 fc
->col_type
[reg
] = DW_CFA_undefined
;
8992 case DW_CFA_def_cfa_sf
:
8995 case DW_CFA_def_cfa_offset_sf
:
8998 case DW_CFA_GNU_args_size
:
9001 case DW_CFA_GNU_negative_offset_extended
:
9002 reg
= LEB (); LEB ();
9003 frame_need_space (fc
, reg
);
9004 fc
->col_type
[reg
] = DW_CFA_undefined
;
9013 /* Now we know what registers are used, make a second pass over
9014 the chunk, this time actually printing out the info. */
9016 while (start
< block_end
)
9019 unsigned long ul
, reg
, roffs
;
9028 /* Warning: if you add any more cases to this switch, be
9029 sure to add them to the corresponding switch above. */
9032 case DW_CFA_advance_loc
:
9033 if (do_debug_frames_interp
)
9034 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9036 printf (" DW_CFA_advance_loc: %d to %08lx\n",
9037 opa
* fc
->code_factor
,
9038 fc
->pc_begin
+ opa
* fc
->code_factor
);
9039 fc
->pc_begin
+= opa
* fc
->code_factor
;
9044 if (! do_debug_frames_interp
)
9045 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
9046 opa
, roffs
* fc
->data_factor
);
9047 fc
->col_type
[opa
] = DW_CFA_offset
;
9048 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9051 case DW_CFA_restore
:
9052 if (! do_debug_frames_interp
)
9053 printf (" DW_CFA_restore: r%d\n", opa
);
9054 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9055 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9058 case DW_CFA_set_loc
:
9059 vma
= byte_get (start
, encoded_ptr_size
);
9060 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
9061 vma
+= section
->sh_addr
+ (start
- section_start
);
9062 start
+= encoded_ptr_size
;
9063 if (do_debug_frames_interp
)
9064 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9066 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
9070 case DW_CFA_advance_loc1
:
9071 ofs
= byte_get (start
, 1); start
+= 1;
9072 if (do_debug_frames_interp
)
9073 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9075 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
9076 ofs
* fc
->code_factor
,
9077 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9078 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9081 case DW_CFA_advance_loc2
:
9082 ofs
= byte_get (start
, 2); start
+= 2;
9083 if (do_debug_frames_interp
)
9084 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9086 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
9087 ofs
* fc
->code_factor
,
9088 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9089 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9092 case DW_CFA_advance_loc4
:
9093 ofs
= byte_get (start
, 4); start
+= 4;
9094 if (do_debug_frames_interp
)
9095 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9097 printf (" DW_CFA_advance_loc4: %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_offset_extended
:
9106 if (! do_debug_frames_interp
)
9107 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
9108 reg
, roffs
* fc
->data_factor
);
9109 fc
->col_type
[reg
] = DW_CFA_offset
;
9110 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9113 case DW_CFA_restore_extended
:
9115 if (! do_debug_frames_interp
)
9116 printf (" DW_CFA_restore_extended: r%ld\n", reg
);
9117 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9118 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9121 case DW_CFA_undefined
:
9123 if (! do_debug_frames_interp
)
9124 printf (" DW_CFA_undefined: r%ld\n", reg
);
9125 fc
->col_type
[reg
] = DW_CFA_undefined
;
9126 fc
->col_offset
[reg
] = 0;
9129 case DW_CFA_same_value
:
9131 if (! do_debug_frames_interp
)
9132 printf (" DW_CFA_same_value: r%ld\n", reg
);
9133 fc
->col_type
[reg
] = DW_CFA_same_value
;
9134 fc
->col_offset
[reg
] = 0;
9137 case DW_CFA_register
:
9140 if (! do_debug_frames_interp
)
9141 printf (" DW_CFA_register: r%ld\n", reg
);
9142 fc
->col_type
[reg
] = DW_CFA_register
;
9143 fc
->col_offset
[reg
] = roffs
;
9146 case DW_CFA_remember_state
:
9147 if (! do_debug_frames_interp
)
9148 printf (" DW_CFA_remember_state\n");
9149 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9150 rs
->ncols
= fc
->ncols
;
9151 rs
->col_type
= (short int *) xmalloc (rs
->ncols
* sizeof (short int));
9152 rs
->col_offset
= (int *) xmalloc (rs
->ncols
* sizeof (int));
9153 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
9154 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
9155 rs
->next
= remembered_state
;
9156 remembered_state
= rs
;
9159 case DW_CFA_restore_state
:
9160 if (! do_debug_frames_interp
)
9161 printf (" DW_CFA_restore_state\n");
9162 rs
= remembered_state
;
9163 remembered_state
= rs
->next
;
9164 frame_need_space (fc
, rs
->ncols
-1);
9165 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
9166 memcpy (fc
->col_offset
, rs
->col_offset
, rs
->ncols
* sizeof (int));
9167 free (rs
->col_type
);
9168 free (rs
->col_offset
);
9172 case DW_CFA_def_cfa
:
9173 fc
->cfa_reg
= LEB ();
9174 fc
->cfa_offset
= LEB ();
9175 if (! do_debug_frames_interp
)
9176 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
9177 fc
->cfa_reg
, fc
->cfa_offset
);
9180 case DW_CFA_def_cfa_register
:
9181 fc
->cfa_reg
= LEB ();
9182 if (! do_debug_frames_interp
)
9183 printf (" DW_CFA_def_cfa_reg: r%d\n", fc
->cfa_reg
);
9186 case DW_CFA_def_cfa_offset
:
9187 fc
->cfa_offset
= LEB ();
9188 if (! do_debug_frames_interp
)
9189 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
9193 if (! do_debug_frames_interp
)
9194 printf (" DW_CFA_nop\n");
9197 case DW_CFA_offset_extended_sf
:
9200 frame_need_space (fc
, reg
);
9201 if (! do_debug_frames_interp
)
9202 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
9203 reg
, l
* fc
->data_factor
);
9204 fc
->col_type
[reg
] = DW_CFA_offset
;
9205 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9208 case DW_CFA_def_cfa_sf
:
9209 fc
->cfa_reg
= LEB ();
9210 fc
->cfa_offset
= SLEB ();
9211 if (! do_debug_frames_interp
)
9212 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
9213 fc
->cfa_reg
, fc
->cfa_offset
);
9216 case DW_CFA_def_cfa_offset_sf
:
9217 fc
->cfa_offset
= SLEB ();
9218 if (! do_debug_frames_interp
)
9219 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
9222 case DW_CFA_GNU_window_save
:
9223 if (! do_debug_frames_interp
)
9224 printf (" DW_CFA_GNU_window_save\n");
9227 case DW_CFA_GNU_args_size
:
9229 if (! do_debug_frames_interp
)
9230 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9233 case DW_CFA_GNU_negative_offset_extended
:
9236 frame_need_space (fc
, reg
);
9237 if (! do_debug_frames_interp
)
9238 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
9239 reg
, l
* fc
->data_factor
);
9240 fc
->col_type
[reg
] = DW_CFA_offset
;
9241 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9244 /* FIXME: How do we handle these? */
9245 case DW_CFA_def_cfa_expression
:
9246 fprintf (stderr
, "unsupported DW_CFA_def_cfa_expression\n");
9250 case DW_CFA_expression
:
9251 fprintf (stderr
, "unsupported DW_CFA_expression\n");
9256 fprintf (stderr
, "unsupported or unknown DW_CFA_%d\n", op
);
9261 if (do_debug_frames_interp
)
9262 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9277 display_debug_not_supported (section
, start
, file
)
9278 Elf_Internal_Shdr
*section
;
9279 unsigned char *start ATTRIBUTE_UNUSED
;
9280 FILE *file ATTRIBUTE_UNUSED
;
9282 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9283 SECTION_NAME (section
));
9288 /* Pre-scan the .debug_info section to record the size of address.
9289 When dumping the .debug_line, we use that size information, assuming
9290 that all compilation units have the same address size. */
9292 prescan_debug_info (section
, start
, file
)
9293 Elf_Internal_Shdr
*section ATTRIBUTE_UNUSED
;
9294 unsigned char *start
;
9295 FILE *file ATTRIBUTE_UNUSED
;
9297 unsigned long length
;
9299 /* Read the first 4 bytes. For a 32-bit DWARF section, this will
9300 be the length. For a 64-bit DWARF section, it'll be the escape
9301 code 0xffffffff followed by an 8 byte length. For the purposes
9302 of this prescan, we don't care about the actual length, but the
9303 presence of the escape bytes does affect the location of the byte
9304 which describes the address size. */
9305 length
= byte_get (start
, 4);
9307 if (length
== 0xffffffff)
9309 /* For 64-bit DWARF, the 1-byte address_size field is 22 bytes
9310 from the start of the section. This is computed as follows:
9312 unit_length: 12 bytes
9314 debug_abbrev_offset: 8 bytes
9315 -----------------------------
9318 debug_line_pointer_size
= byte_get (start
+ 22, 1);
9322 /* For 32-bit DWARF, the 1-byte address_size field is 10 bytes from
9323 the start of the section:
9324 unit_length: 4 bytes
9326 debug_abbrev_offset: 4 bytes
9327 -----------------------------
9330 debug_line_pointer_size
= byte_get (start
+ 10, 1);
9335 /* A structure containing the name of a debug section and a pointer
9336 to a function that can decode it. The third field is a prescan
9337 function to be run over the section before displaying any of the
9341 const char *const name
;
9342 int (*display
) PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
9343 int (*prescan
) PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
9347 { ".debug_abbrev", display_debug_abbrev
, NULL
},
9348 { ".debug_aranges", display_debug_aranges
, NULL
},
9349 { ".debug_frame", display_debug_frames
, NULL
},
9350 { ".debug_info", display_debug_info
, prescan_debug_info
},
9351 { ".debug_line", display_debug_lines
, NULL
},
9352 { ".debug_pubnames", display_debug_pubnames
, NULL
},
9353 { ".eh_frame", display_debug_frames
, NULL
},
9354 { ".debug_macinfo", display_debug_macinfo
, NULL
},
9355 { ".debug_str", display_debug_str
, NULL
},
9356 { ".debug_loc", display_debug_loc
, NULL
},
9357 { ".debug_pubtypes", display_debug_not_supported
, NULL
},
9358 { ".debug_ranges", display_debug_not_supported
, NULL
},
9359 { ".debug_static_func", display_debug_not_supported
, NULL
},
9360 { ".debug_static_vars", display_debug_not_supported
, NULL
},
9361 { ".debug_types", display_debug_not_supported
, NULL
},
9362 { ".debug_weaknames", display_debug_not_supported
, NULL
}
9366 display_debug_section (section
, file
)
9367 Elf_Internal_Shdr
*section
;
9370 char *name
= SECTION_NAME (section
);
9371 bfd_size_type length
;
9372 unsigned char *start
;
9375 length
= section
->sh_size
;
9378 printf (_("\nSection '%s' has no debugging data.\n"), name
);
9382 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, length
,
9383 _("debug section data"));
9387 /* See if we know how to display the contents of this section. */
9388 if (strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
9389 name
= ".debug_info";
9391 for (i
= NUM_ELEM (debug_displays
); i
--;)
9392 if (strcmp (debug_displays
[i
].name
, name
) == 0)
9394 debug_displays
[i
].display (section
, start
, file
);
9399 printf (_("Unrecognized debug section: %s\n"), name
);
9403 /* If we loaded in the abbrev section at some point,
9404 we must release it here. */
9411 process_section_contents (file
)
9414 Elf_Internal_Shdr
*section
;
9420 /* Pre-scan the debug sections to find some debug information not
9421 present in some of them. For the .debug_line, we must find out the
9422 size of address (specified in .debug_info and .debug_aranges). */
9423 for (i
= 0, section
= section_headers
;
9424 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9427 char *name
= SECTION_NAME (section
);
9430 if (section
->sh_size
== 0)
9433 /* See if there is some pre-scan operation for this section. */
9434 for (j
= NUM_ELEM (debug_displays
); j
--;)
9435 if (strcmp (debug_displays
[j
].name
, name
) == 0)
9437 if (debug_displays
[j
].prescan
!= NULL
)
9439 bfd_size_type length
;
9440 unsigned char *start
;
9442 length
= section
->sh_size
;
9443 start
= ((unsigned char *)
9444 get_data (NULL
, file
, section
->sh_offset
, length
,
9445 _("debug section data")));
9449 debug_displays
[j
].prescan (section
, start
, file
);
9457 for (i
= 0, section
= section_headers
;
9458 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9461 #ifdef SUPPORT_DISASSEMBLY
9462 if (dump_sects
[i
] & DISASS_DUMP
)
9463 disassemble_section (section
, file
);
9465 if (dump_sects
[i
] & HEX_DUMP
)
9466 dump_section (section
, file
);
9468 if (dump_sects
[i
] & DEBUG_DUMP
)
9469 display_debug_section (section
, file
);
9472 if (i
< num_dump_sects
)
9473 warn (_("Some sections were not dumped because they do not exist!\n"));
9479 process_mips_fpe_exception (mask
)
9485 if (mask
& OEX_FPU_INEX
)
9486 fputs ("INEX", stdout
), first
= 0;
9487 if (mask
& OEX_FPU_UFLO
)
9488 printf ("%sUFLO", first
? "" : "|"), first
= 0;
9489 if (mask
& OEX_FPU_OFLO
)
9490 printf ("%sOFLO", first
? "" : "|"), first
= 0;
9491 if (mask
& OEX_FPU_DIV0
)
9492 printf ("%sDIV0", first
? "" : "|"), first
= 0;
9493 if (mask
& OEX_FPU_INVAL
)
9494 printf ("%sINVAL", first
? "" : "|");
9497 fputs ("0", stdout
);
9501 process_mips_specific (file
)
9504 Elf_Internal_Dyn
*entry
;
9505 size_t liblist_offset
= 0;
9506 size_t liblistno
= 0;
9507 size_t conflictsno
= 0;
9508 size_t options_offset
= 0;
9509 size_t conflicts_offset
= 0;
9511 /* We have a lot of special sections. Thanks SGI! */
9512 if (dynamic_segment
== NULL
)
9513 /* No information available. */
9516 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
9517 switch (entry
->d_tag
)
9519 case DT_MIPS_LIBLIST
:
9520 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
9522 case DT_MIPS_LIBLISTNO
:
9523 liblistno
= entry
->d_un
.d_val
;
9525 case DT_MIPS_OPTIONS
:
9526 options_offset
= entry
->d_un
.d_val
- loadaddr
;
9528 case DT_MIPS_CONFLICT
:
9529 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
9531 case DT_MIPS_CONFLICTNO
:
9532 conflictsno
= entry
->d_un
.d_val
;
9538 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9540 Elf32_External_Lib
*elib
;
9543 elib
= ((Elf32_External_Lib
*)
9544 get_data (NULL
, file
, liblist_offset
,
9545 liblistno
* sizeof (Elf32_External_Lib
),
9549 printf ("\nSection '.liblist' contains %lu entries:\n",
9550 (unsigned long) liblistno
);
9551 fputs (" Library Time Stamp Checksum Version Flags\n",
9554 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9561 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9562 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9563 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9564 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9565 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9567 tmp
= gmtime (&time
);
9568 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9569 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9570 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9572 printf ("%3lu: ", (unsigned long) cnt
);
9573 print_symbol (20, dynamic_strings
+ liblist
.l_name
);
9574 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9577 if (liblist
.l_flags
== 0)
9588 { " EXACT_MATCH", LL_EXACT_MATCH
},
9589 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9590 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9591 { " EXPORTS", LL_EXPORTS
},
9592 { " DELAY_LOAD", LL_DELAY_LOAD
},
9593 { " DELTA", LL_DELTA
}
9595 int flags
= liblist
.l_flags
;
9599 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
9601 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9603 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9604 flags
^= l_flags_vals
[fcnt
].bit
;
9607 printf (" %#x", (unsigned int) flags
);
9617 if (options_offset
!= 0)
9619 Elf_External_Options
*eopt
;
9620 Elf_Internal_Shdr
*sect
= section_headers
;
9621 Elf_Internal_Options
*iopt
;
9622 Elf_Internal_Options
*option
;
9626 /* Find the section header so that we get the size. */
9627 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9630 eopt
= (Elf_External_Options
*) get_data (NULL
, file
, options_offset
,
9631 sect
->sh_size
, _("options"));
9634 iopt
= ((Elf_Internal_Options
*)
9635 malloc ((sect
->sh_size
/ sizeof (eopt
)) * sizeof (*iopt
)));
9638 error (_("Out of memory"));
9645 while (offset
< sect
->sh_size
)
9647 Elf_External_Options
*eoption
;
9649 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9651 option
->kind
= BYTE_GET (eoption
->kind
);
9652 option
->size
= BYTE_GET (eoption
->size
);
9653 option
->section
= BYTE_GET (eoption
->section
);
9654 option
->info
= BYTE_GET (eoption
->info
);
9656 offset
+= option
->size
;
9662 printf (_("\nSection '%s' contains %d entries:\n"),
9663 SECTION_NAME (sect
), cnt
);
9671 switch (option
->kind
)
9674 /* This shouldn't happen. */
9675 printf (" NULL %d %lx", option
->section
, option
->info
);
9678 printf (" REGINFO ");
9679 if (elf_header
.e_machine
== EM_MIPS
)
9682 Elf32_External_RegInfo
*ereg
;
9683 Elf32_RegInfo reginfo
;
9685 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9686 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9687 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9688 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9689 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9690 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9691 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9693 printf ("GPR %08lx GP 0x%lx\n",
9695 (unsigned long) reginfo
.ri_gp_value
);
9696 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9697 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9698 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9703 Elf64_External_RegInfo
*ereg
;
9704 Elf64_Internal_RegInfo reginfo
;
9706 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9707 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9708 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9709 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9710 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9711 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9712 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
9714 printf ("GPR %08lx GP 0x",
9715 reginfo
.ri_gprmask
);
9716 printf_vma (reginfo
.ri_gp_value
);
9719 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9720 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9721 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9725 case ODK_EXCEPTIONS
:
9726 fputs (" EXCEPTIONS fpe_min(", stdout
);
9727 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9728 fputs (") fpe_max(", stdout
);
9729 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9730 fputs (")", stdout
);
9732 if (option
->info
& OEX_PAGE0
)
9733 fputs (" PAGE0", stdout
);
9734 if (option
->info
& OEX_SMM
)
9735 fputs (" SMM", stdout
);
9736 if (option
->info
& OEX_FPDBUG
)
9737 fputs (" FPDBUG", stdout
);
9738 if (option
->info
& OEX_DISMISS
)
9739 fputs (" DISMISS", stdout
);
9742 fputs (" PAD ", stdout
);
9743 if (option
->info
& OPAD_PREFIX
)
9744 fputs (" PREFIX", stdout
);
9745 if (option
->info
& OPAD_POSTFIX
)
9746 fputs (" POSTFIX", stdout
);
9747 if (option
->info
& OPAD_SYMBOL
)
9748 fputs (" SYMBOL", stdout
);
9751 fputs (" HWPATCH ", stdout
);
9752 if (option
->info
& OHW_R4KEOP
)
9753 fputs (" R4KEOP", stdout
);
9754 if (option
->info
& OHW_R8KPFETCH
)
9755 fputs (" R8KPFETCH", stdout
);
9756 if (option
->info
& OHW_R5KEOP
)
9757 fputs (" R5KEOP", stdout
);
9758 if (option
->info
& OHW_R5KCVTL
)
9759 fputs (" R5KCVTL", stdout
);
9762 fputs (" FILL ", stdout
);
9763 /* XXX Print content of info word? */
9766 fputs (" TAGS ", stdout
);
9767 /* XXX Print content of info word? */
9770 fputs (" HWAND ", stdout
);
9771 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9772 fputs (" R4KEOP_CHECKED", stdout
);
9773 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9774 fputs (" R4KEOP_CLEAN", stdout
);
9777 fputs (" HWOR ", stdout
);
9778 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9779 fputs (" R4KEOP_CHECKED", stdout
);
9780 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9781 fputs (" R4KEOP_CLEAN", stdout
);
9784 printf (" GP_GROUP %#06lx self-contained %#06lx",
9785 option
->info
& OGP_GROUP
,
9786 (option
->info
& OGP_SELF
) >> 16);
9789 printf (" IDENT %#06lx self-contained %#06lx",
9790 option
->info
& OGP_GROUP
,
9791 (option
->info
& OGP_SELF
) >> 16);
9794 /* This shouldn't happen. */
9795 printf (" %3d ??? %d %lx",
9796 option
->kind
, option
->section
, option
->info
);
9800 len
= sizeof (*eopt
);
9801 while (len
< option
->size
)
9802 if (((char *) option
)[len
] >= ' '
9803 && ((char *) option
)[len
] < 0x7f)
9804 printf ("%c", ((char *) option
)[len
++]);
9806 printf ("\\%03o", ((char *) option
)[len
++]);
9808 fputs ("\n", stdout
);
9816 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9818 Elf32_Conflict
*iconf
;
9821 if (dynamic_symbols
== NULL
)
9823 error (_("conflict list found without a dynamic symbol table"));
9827 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
9830 error (_("Out of memory"));
9836 Elf32_External_Conflict
*econf32
;
9838 econf32
= ((Elf32_External_Conflict
*)
9839 get_data (NULL
, file
, conflicts_offset
,
9840 conflictsno
* sizeof (*econf32
),
9845 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9846 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9852 Elf64_External_Conflict
*econf64
;
9854 econf64
= ((Elf64_External_Conflict
*)
9855 get_data (NULL
, file
, conflicts_offset
,
9856 conflictsno
* sizeof (*econf64
),
9861 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9862 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9867 printf (_("\nSection '.conflict' contains %ld entries:\n"),
9868 (long) conflictsno
);
9869 puts (_(" Num: Index Value Name"));
9871 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9873 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
9875 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9876 print_vma (psym
->st_value
, FULL_HEX
);
9878 print_symbol (25, dynamic_strings
+ psym
->st_name
);
9889 process_gnu_liblist (file
)
9892 Elf_Internal_Shdr
*section
, *string_sec
;
9893 Elf32_External_Lib
*elib
;
9901 for (i
= 0, section
= section_headers
;
9902 i
< elf_header
.e_shnum
;
9905 switch (section
->sh_type
)
9907 case SHT_GNU_LIBLIST
:
9908 elib
= ((Elf32_External_Lib
*)
9909 get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
9914 string_sec
= SECTION_HEADER (section
->sh_link
);
9916 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
9917 string_sec
->sh_size
,
9918 _("liblist string table"));
9921 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9927 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9928 SECTION_NAME (section
),
9929 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9931 puts (" Library Time Stamp Checksum Version Flags");
9933 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9941 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9942 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9943 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9944 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9945 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9947 tmp
= gmtime (&time
);
9948 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9949 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9950 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9952 printf ("%3lu: ", (unsigned long) cnt
);
9954 printf ("%-20s", strtab
+ liblist
.l_name
);
9956 printf ("%-20.20s", strtab
+ liblist
.l_name
);
9957 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9958 liblist
.l_version
, liblist
.l_flags
);
9969 get_note_type (e_type
)
9972 static char buff
[64];
9976 case NT_PRSTATUS
: return _("NT_PRSTATUS (prstatus structure)");
9977 case NT_FPREGSET
: return _("NT_FPREGSET (floating point registers)");
9978 case NT_PRPSINFO
: return _("NT_PRPSINFO (prpsinfo structure)");
9979 case NT_TASKSTRUCT
: return _("NT_TASKSTRUCT (task structure)");
9980 case NT_PRXFPREG
: return _("NT_PRXFPREG (user_xfpregs structure)");
9981 case NT_PSTATUS
: return _("NT_PSTATUS (pstatus structure)");
9982 case NT_FPREGS
: return _("NT_FPREGS (floating point registers)");
9983 case NT_PSINFO
: return _("NT_PSINFO (psinfo structure)");
9984 case NT_LWPSTATUS
: return _("NT_LWPSTATUS (lwpstatus_t structure)");
9985 case NT_LWPSINFO
: return _("NT_LWPSINFO (lwpsinfo_t structure)");
9986 case NT_WIN32PSTATUS
: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9988 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
9994 get_netbsd_elfcore_note_type (e_type
)
9997 static char buff
[64];
9999 if (e_type
== NT_NETBSDCORE_PROCINFO
)
10001 /* NetBSD core "procinfo" structure. */
10002 return _("NetBSD procinfo structure");
10005 /* As of Jan 2002 there are no other machine-independent notes
10006 defined for NetBSD core files. If the note type is less
10007 than the start of the machine-dependent note types, we don't
10010 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
10012 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
10016 switch (elf_header
.e_machine
)
10018 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
10019 and PT_GETFPREGS == mach+2. */
10024 case EM_SPARC32PLUS
:
10028 case NT_NETBSDCORE_FIRSTMACH
+0:
10029 return _("PT_GETREGS (reg structure)");
10030 case NT_NETBSDCORE_FIRSTMACH
+2:
10031 return _("PT_GETFPREGS (fpreg structure)");
10037 /* On all other arch's, PT_GETREGS == mach+1 and
10038 PT_GETFPREGS == mach+3. */
10042 case NT_NETBSDCORE_FIRSTMACH
+1:
10043 return _("PT_GETREGS (reg structure)");
10044 case NT_NETBSDCORE_FIRSTMACH
+3:
10045 return _("PT_GETFPREGS (fpreg structure)");
10051 sprintf (buff
, _("PT_FIRSTMACH+%d"), e_type
- NT_NETBSDCORE_FIRSTMACH
);
10055 /* Note that by the ELF standard, the name field is already null byte
10056 terminated, and namesz includes the terminating null byte.
10057 I.E. the value of namesz for the name "FSF" is 4.
10059 If the value of namesz is zero, there is no name present. */
10061 process_note (pnote
)
10062 Elf_Internal_Note
*pnote
;
10066 if (pnote
->namesz
== 0)
10068 /* If there is no note name, then use the default set of
10069 note type strings. */
10070 nt
= get_note_type (pnote
->type
);
10072 else if (strncmp (pnote
->namedata
, "NetBSD-CORE", 11) == 0)
10074 /* NetBSD-specific core file notes. */
10075 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
10079 /* Don't recognize this note name; just use the default set of
10080 note type strings. */
10081 nt
= get_note_type (pnote
->type
);
10084 printf (" %s\t\t0x%08lx\t%s\n",
10085 pnote
->namesz
? pnote
->namedata
: "(NONE)",
10086 pnote
->descsz
, nt
);
10092 process_corefile_note_segment (file
, offset
, length
)
10097 Elf_External_Note
*pnotes
;
10098 Elf_External_Note
*external
;
10104 pnotes
= (Elf_External_Note
*) get_data (NULL
, file
, offset
, length
,
10111 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
10112 (unsigned long) offset
, (unsigned long) length
);
10113 printf (_(" Owner\t\tData size\tDescription\n"));
10115 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
10117 Elf_External_Note
*next
;
10118 Elf_Internal_Note inote
;
10121 inote
.type
= BYTE_GET (external
->type
);
10122 inote
.namesz
= BYTE_GET (external
->namesz
);
10123 inote
.namedata
= external
->name
;
10124 inote
.descsz
= BYTE_GET (external
->descsz
);
10125 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
10126 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
10128 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
10130 if (((char *) next
) > (((char *) pnotes
) + length
))
10132 warn (_("corrupt note found at offset %x into core notes\n"),
10133 ((char *) external
) - ((char *) pnotes
));
10134 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
10135 inote
.type
, inote
.namesz
, inote
.descsz
);
10141 /* Verify that name is null terminated. It appears that at least
10142 one version of Linux (RedHat 6.0) generates corefiles that don't
10143 comply with the ELF spec by failing to include the null byte in
10145 if (inote
.namedata
[inote
.namesz
] != '\0')
10147 temp
= malloc (inote
.namesz
+ 1);
10151 error (_("Out of memory\n"));
10156 strncpy (temp
, inote
.namedata
, inote
.namesz
);
10157 temp
[inote
.namesz
] = 0;
10159 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
10160 inote
.namedata
= temp
;
10163 res
&= process_note (& inote
);
10178 process_corefile_note_segments (file
)
10181 Elf_Internal_Phdr
*program_headers
;
10182 Elf_Internal_Phdr
*segment
;
10186 program_headers
= (Elf_Internal_Phdr
*) malloc
10187 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
10189 if (program_headers
== NULL
)
10191 error (_("Out of memory\n"));
10196 i
= get_32bit_program_headers (file
, program_headers
);
10198 i
= get_64bit_program_headers (file
, program_headers
);
10202 free (program_headers
);
10206 for (i
= 0, segment
= program_headers
;
10207 i
< elf_header
.e_phnum
;
10210 if (segment
->p_type
== PT_NOTE
)
10211 res
&= process_corefile_note_segment (file
,
10212 (bfd_vma
) segment
->p_offset
,
10213 (bfd_vma
) segment
->p_filesz
);
10216 free (program_headers
);
10222 process_corefile_contents (file
)
10225 /* If we have not been asked to display the notes then do nothing. */
10229 /* If file is not a core file then exit. */
10230 if (elf_header
.e_type
!= ET_CORE
)
10233 /* No program headers means no NOTE segment. */
10234 if (elf_header
.e_phnum
== 0)
10236 printf (_("No note segments present in the core file.\n"));
10240 return process_corefile_note_segments (file
);
10244 process_arch_specific (file
)
10250 switch (elf_header
.e_machine
)
10253 case EM_MIPS_RS3_LE
:
10254 return process_mips_specific (file
);
10263 get_file_header (file
)
10266 /* Read in the identity array. */
10267 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
10270 /* Determine how to read the rest of the header. */
10271 switch (elf_header
.e_ident
[EI_DATA
])
10273 default: /* fall through */
10274 case ELFDATANONE
: /* fall through */
10275 case ELFDATA2LSB
: byte_get
= byte_get_little_endian
; break;
10276 case ELFDATA2MSB
: byte_get
= byte_get_big_endian
; break;
10279 /* For now we only support 32 bit and 64 bit ELF files. */
10280 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
10282 /* Read in the rest of the header. */
10285 Elf32_External_Ehdr ehdr32
;
10287 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
10290 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
10291 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
10292 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
10293 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
10294 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
10295 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
10296 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
10297 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
10298 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
10299 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
10300 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
10301 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
10302 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
10306 Elf64_External_Ehdr ehdr64
;
10308 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10309 we will not be able to cope with the 64bit data found in
10310 64 ELF files. Detect this now and abort before we start
10311 overwritting things. */
10312 if (sizeof (bfd_vma
) < 8)
10314 error (_("This instance of readelf has been built without support for a\n\
10315 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10319 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
10322 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
10323 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
10324 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
10325 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
10326 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
10327 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
10328 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
10329 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
10330 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
10331 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
10332 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
10333 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
10334 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
10337 if (elf_header
.e_shoff
)
10339 /* There may be some extensions in the first section header. Don't
10340 bomb if we can't read it. */
10342 get_32bit_section_headers (file
, 1);
10344 get_64bit_section_headers (file
, 1);
10351 process_file (file_name
)
10355 struct stat statbuf
;
10358 if (stat (file_name
, & statbuf
) < 0)
10360 error (_("Cannot stat input file %s.\n"), file_name
);
10364 file
= fopen (file_name
, "rb");
10367 error (_("Input file %s not found.\n"), file_name
);
10371 if (! get_file_header (file
))
10373 error (_("%s: Failed to read file header\n"), file_name
);
10378 /* Initialise per file variables. */
10379 for (i
= NUM_ELEM (version_info
); i
--;)
10380 version_info
[i
] = 0;
10382 for (i
= NUM_ELEM (dynamic_info
); i
--;)
10383 dynamic_info
[i
] = 0;
10385 /* Process the file. */
10387 printf (_("\nFile: %s\n"), file_name
);
10389 if (! process_file_header ())
10395 if (! process_section_headers (file
))
10397 /* Without loaded section headers we
10398 cannot process lots of things. */
10399 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10401 if (! do_using_dynamic
)
10402 do_syms
= do_reloc
= 0;
10405 if (process_program_headers (file
))
10406 process_dynamic_segment (file
);
10408 process_relocs (file
);
10410 process_unwind (file
);
10412 process_symbol_table (file
);
10414 process_syminfo (file
);
10416 process_version_sections (file
);
10418 process_section_contents (file
);
10420 process_corefile_contents (file
);
10422 process_gnu_liblist (file
);
10424 process_arch_specific (file
);
10428 if (section_headers
)
10430 free (section_headers
);
10431 section_headers
= NULL
;
10436 free (string_table
);
10437 string_table
= NULL
;
10438 string_table_length
= 0;
10441 if (dynamic_strings
)
10443 free (dynamic_strings
);
10444 dynamic_strings
= NULL
;
10447 if (dynamic_symbols
)
10449 free (dynamic_symbols
);
10450 dynamic_symbols
= NULL
;
10451 num_dynamic_syms
= 0;
10454 if (dynamic_syminfo
)
10456 free (dynamic_syminfo
);
10457 dynamic_syminfo
= NULL
;
10463 #ifdef SUPPORT_DISASSEMBLY
10464 /* Needed by the i386 disassembler. For extra credit, someone could
10465 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10469 print_address (unsigned int addr
, FILE *outfile
)
10471 fprintf (outfile
,"0x%8.8x", addr
);
10474 /* Needed by the i386 disassembler. */
10476 db_task_printsym (unsigned int addr
)
10478 print_address (addr
, stderr
);
10482 int main
PARAMS ((int, char **));
10490 char *cmdline_dump_sects
= NULL
;
10491 unsigned num_cmdline_dump_sects
= 0;
10493 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10494 setlocale (LC_MESSAGES
, "");
10496 #if defined (HAVE_SETLOCALE)
10497 setlocale (LC_CTYPE
, "");
10499 bindtextdomain (PACKAGE
, LOCALEDIR
);
10500 textdomain (PACKAGE
);
10502 parse_args (argc
, argv
);
10504 if (optind
< (argc
- 1))
10507 /* When processing more than one file remember the dump requests
10508 issued on command line to reset them after each file. */
10509 if (optind
+ 1 < argc
&& dump_sects
!= NULL
)
10511 cmdline_dump_sects
= malloc (num_dump_sects
);
10512 if (cmdline_dump_sects
== NULL
)
10513 error (_("Out of memory allocating dump request table."));
10516 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
10517 num_cmdline_dump_sects
= num_dump_sects
;
10522 while (optind
< argc
)
10524 err
|= process_file (argv
[optind
++]);
10526 /* Reset dump requests. */
10527 if (optind
< argc
&& dump_sects
!= NULL
)
10529 num_dump_sects
= num_cmdline_dump_sects
;
10530 if (num_cmdline_dump_sects
> 0)
10531 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
10535 if (dump_sects
!= NULL
)
10537 if (cmdline_dump_sects
!= NULL
)
10538 free (cmdline_dump_sects
);