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,
352 static unsigned char *read_and_display_attr_value
353 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
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. */
948 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
950 unsigned long rel_offset
;
951 unsigned long rel_size
;
952 Elf_Internal_Sym
*symtab
;
958 Elf_Internal_Rela
*rels
;
961 if (is_rela
== UNKNOWN
)
962 is_rela
= guess_is_rela (elf_header
.e_machine
);
966 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
971 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
980 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
982 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
987 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
989 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
997 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
999 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1004 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1006 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1010 for (i
= 0; i
< rel_size
; i
++)
1013 const char *rtype2
= NULL
;
1014 const char *rtype3
= NULL
;
1017 bfd_vma symtab_index
;
1019 bfd_vma type2
= (bfd_vma
) NULL
;
1020 bfd_vma type3
= (bfd_vma
) NULL
;
1022 offset
= rels
[i
].r_offset
;
1023 info
= rels
[i
].r_info
;
1027 type
= ELF32_R_TYPE (info
);
1028 symtab_index
= ELF32_R_SYM (info
);
1032 /* The #ifdef BFD64 below is to prevent a compile time warning.
1033 We know that if we do not have a 64 bit data type that we
1034 will never execute this code anyway. */
1036 if (elf_header
.e_machine
== EM_MIPS
)
1038 /* In little-endian objects, r_info isn't really a 64-bit
1039 little-endian value: it has a 32-bit little-endian
1040 symbol index followed by four individual byte fields.
1041 Reorder INFO accordingly. */
1042 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1043 info
= (((info
& 0xffffffff) << 32)
1044 | ((info
>> 56) & 0xff)
1045 | ((info
>> 40) & 0xff00)
1046 | ((info
>> 24) & 0xff0000)
1047 | ((info
>> 8) & 0xff000000));
1048 type
= ELF64_MIPS_R_TYPE (info
);
1049 type2
= ELF64_MIPS_R_TYPE2 (info
);
1050 type3
= ELF64_MIPS_R_TYPE3 (info
);
1052 else if (elf_header
.e_machine
== EM_SPARCV9
)
1053 type
= ELF64_R_TYPE_ID (info
);
1055 type
= ELF64_R_TYPE (info
);
1057 symtab_index
= ELF64_R_SYM (info
);
1063 #ifdef _bfd_int64_low
1064 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
1066 printf ("%8.8lx %8.8lx ", offset
, info
);
1071 #ifdef _bfd_int64_low
1073 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1074 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1075 _bfd_int64_high (offset
),
1076 _bfd_int64_low (offset
),
1077 _bfd_int64_high (info
),
1078 _bfd_int64_low (info
));
1081 ? "%16.16lx %16.16lx "
1082 : "%12.12lx %12.12lx ",
1087 switch (elf_header
.e_machine
)
1094 case EM_CYGNUS_M32R
:
1095 rtype
= elf_m32r_reloc_type (type
);
1100 rtype
= elf_i386_reloc_type (type
);
1105 rtype
= elf_m68hc11_reloc_type (type
);
1109 rtype
= elf_m68k_reloc_type (type
);
1113 rtype
= elf_i960_reloc_type (type
);
1118 rtype
= elf_avr_reloc_type (type
);
1121 case EM_OLD_SPARCV9
:
1122 case EM_SPARC32PLUS
:
1125 rtype
= elf_sparc_reloc_type (type
);
1129 case EM_CYGNUS_V850
:
1130 rtype
= v850_reloc_type (type
);
1134 case EM_CYGNUS_D10V
:
1135 rtype
= elf_d10v_reloc_type (type
);
1139 case EM_CYGNUS_D30V
:
1140 rtype
= elf_d30v_reloc_type (type
);
1144 rtype
= elf_dlx_reloc_type (type
);
1148 rtype
= elf_sh_reloc_type (type
);
1152 case EM_CYGNUS_MN10300
:
1153 rtype
= elf_mn10300_reloc_type (type
);
1157 case EM_CYGNUS_MN10200
:
1158 rtype
= elf_mn10200_reloc_type (type
);
1162 case EM_CYGNUS_FR30
:
1163 rtype
= elf_fr30_reloc_type (type
);
1167 rtype
= elf_frv_reloc_type (type
);
1171 rtype
= elf_mcore_reloc_type (type
);
1175 rtype
= elf_mmix_reloc_type (type
);
1180 rtype
= elf_msp430_reloc_type (type
);
1184 rtype
= elf_ppc_reloc_type (type
);
1188 rtype
= elf_ppc64_reloc_type (type
);
1192 case EM_MIPS_RS3_LE
:
1193 rtype
= elf_mips_reloc_type (type
);
1196 rtype2
= elf_mips_reloc_type (type2
);
1197 rtype3
= elf_mips_reloc_type (type3
);
1202 rtype
= elf_alpha_reloc_type (type
);
1206 rtype
= elf_arm_reloc_type (type
);
1210 rtype
= elf_arc_reloc_type (type
);
1214 rtype
= elf_hppa_reloc_type (type
);
1220 rtype
= elf_h8_reloc_type (type
);
1225 rtype
= elf_or32_reloc_type (type
);
1230 rtype
= elf_pj_reloc_type (type
);
1233 rtype
= elf_ia64_reloc_type (type
);
1237 rtype
= elf_cris_reloc_type (type
);
1241 rtype
= elf_i860_reloc_type (type
);
1245 rtype
= elf_x86_64_reloc_type (type
);
1249 rtype
= i370_reloc_type (type
);
1254 rtype
= elf_s390_reloc_type (type
);
1258 rtype
= elf_xstormy16_reloc_type (type
);
1262 rtype
= elf_vax_reloc_type (type
);
1267 rtype
= elf_ip2k_reloc_type (type
);
1271 rtype
= elf_iq2000_reloc_type (type
);
1276 #ifdef _bfd_int64_low
1277 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1279 printf (_("unrecognized: %-7lx"), type
);
1282 printf (do_wide
? "%-21.21s" : "%-17.17s", rtype
);
1286 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1287 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1290 Elf_Internal_Sym
*psym
;
1292 psym
= symtab
+ symtab_index
;
1295 print_vma (psym
->st_value
, LONG_HEX
);
1296 printf (is_32bit_elf
? " " : " ");
1298 if (psym
->st_name
== 0)
1300 const char *sec_name
= "<null>";
1303 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1305 bfd_vma sec_index
= (bfd_vma
) -1;
1307 if (psym
->st_shndx
< SHN_LORESERVE
)
1308 sec_index
= psym
->st_shndx
;
1309 else if (psym
->st_shndx
> SHN_LORESERVE
)
1310 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1313 if (sec_index
!= (bfd_vma
) -1)
1314 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1315 else if (psym
->st_shndx
== SHN_ABS
)
1317 else if (psym
->st_shndx
== SHN_COMMON
)
1318 sec_name
= "COMMON";
1321 sprintf (name_buf
, "<section 0x%x>",
1322 (unsigned int) psym
->st_shndx
);
1323 sec_name
= name_buf
;
1326 print_symbol (22, sec_name
);
1328 else if (strtab
== NULL
)
1329 printf (_("<string table index %3ld>"), psym
->st_name
);
1331 print_symbol (22, strtab
+ psym
->st_name
);
1334 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1339 printf ("%*c", is_32bit_elf
? (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1340 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1343 if (elf_header
.e_machine
== EM_SPARCV9
1344 && !strcmp (rtype
, "R_SPARC_OLO10"))
1345 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1349 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1351 printf (" Type2: ");
1354 #ifdef _bfd_int64_low
1355 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1357 printf (_("unrecognized: %-7lx"), type2
);
1360 printf ("%-17.17s", rtype2
);
1362 printf("\n Type3: ");
1365 #ifdef _bfd_int64_low
1366 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1368 printf (_("unrecognized: %-7lx"), type3
);
1371 printf ("%-17.17s", rtype3
);
1383 get_mips_dynamic_type (type
)
1388 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1389 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1390 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1391 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1392 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1393 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1394 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1395 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1396 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1397 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1398 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1399 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1400 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1401 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1402 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1403 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1404 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1405 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1406 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1407 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1408 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1409 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1410 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1411 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1412 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1413 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1414 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1415 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1416 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1417 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1418 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1419 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1420 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1421 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1422 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1423 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1424 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1425 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1426 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1427 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1428 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1429 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1430 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1437 get_sparc64_dynamic_type (type
)
1442 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1449 get_ppc64_dynamic_type (type
)
1454 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1455 case DT_PPC64_OPD
: return "PPC64_OPD";
1456 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1463 get_parisc_dynamic_type (type
)
1468 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1469 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1470 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1471 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1472 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1473 case DT_HP_PREINIT
: return "HP_PREINIT";
1474 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1475 case DT_HP_NEEDED
: return "HP_NEEDED";
1476 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1477 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1478 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1479 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1480 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1487 get_ia64_dynamic_type (type
)
1492 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1499 get_dynamic_type (type
)
1502 static char buff
[32];
1506 case DT_NULL
: return "NULL";
1507 case DT_NEEDED
: return "NEEDED";
1508 case DT_PLTRELSZ
: return "PLTRELSZ";
1509 case DT_PLTGOT
: return "PLTGOT";
1510 case DT_HASH
: return "HASH";
1511 case DT_STRTAB
: return "STRTAB";
1512 case DT_SYMTAB
: return "SYMTAB";
1513 case DT_RELA
: return "RELA";
1514 case DT_RELASZ
: return "RELASZ";
1515 case DT_RELAENT
: return "RELAENT";
1516 case DT_STRSZ
: return "STRSZ";
1517 case DT_SYMENT
: return "SYMENT";
1518 case DT_INIT
: return "INIT";
1519 case DT_FINI
: return "FINI";
1520 case DT_SONAME
: return "SONAME";
1521 case DT_RPATH
: return "RPATH";
1522 case DT_SYMBOLIC
: return "SYMBOLIC";
1523 case DT_REL
: return "REL";
1524 case DT_RELSZ
: return "RELSZ";
1525 case DT_RELENT
: return "RELENT";
1526 case DT_PLTREL
: return "PLTREL";
1527 case DT_DEBUG
: return "DEBUG";
1528 case DT_TEXTREL
: return "TEXTREL";
1529 case DT_JMPREL
: return "JMPREL";
1530 case DT_BIND_NOW
: return "BIND_NOW";
1531 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1532 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1533 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1534 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1535 case DT_RUNPATH
: return "RUNPATH";
1536 case DT_FLAGS
: return "FLAGS";
1538 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1539 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1541 case DT_CHECKSUM
: return "CHECKSUM";
1542 case DT_PLTPADSZ
: return "PLTPADSZ";
1543 case DT_MOVEENT
: return "MOVEENT";
1544 case DT_MOVESZ
: return "MOVESZ";
1545 case DT_FEATURE
: return "FEATURE";
1546 case DT_POSFLAG_1
: return "POSFLAG_1";
1547 case DT_SYMINSZ
: return "SYMINSZ";
1548 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1550 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1551 case DT_CONFIG
: return "CONFIG";
1552 case DT_DEPAUDIT
: return "DEPAUDIT";
1553 case DT_AUDIT
: return "AUDIT";
1554 case DT_PLTPAD
: return "PLTPAD";
1555 case DT_MOVETAB
: return "MOVETAB";
1556 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1558 case DT_VERSYM
: return "VERSYM";
1560 case DT_RELACOUNT
: return "RELACOUNT";
1561 case DT_RELCOUNT
: return "RELCOUNT";
1562 case DT_FLAGS_1
: return "FLAGS_1";
1563 case DT_VERDEF
: return "VERDEF";
1564 case DT_VERDEFNUM
: return "VERDEFNUM";
1565 case DT_VERNEED
: return "VERNEED";
1566 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1568 case DT_AUXILIARY
: return "AUXILIARY";
1569 case DT_USED
: return "USED";
1570 case DT_FILTER
: return "FILTER";
1572 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1573 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1574 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1575 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1576 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1579 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1583 switch (elf_header
.e_machine
)
1586 case EM_MIPS_RS3_LE
:
1587 result
= get_mips_dynamic_type (type
);
1590 result
= get_sparc64_dynamic_type (type
);
1593 result
= get_ppc64_dynamic_type (type
);
1596 result
= get_ia64_dynamic_type (type
);
1606 sprintf (buff
, _("Processor Specific: %lx"), type
);
1608 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1612 switch (elf_header
.e_machine
)
1615 result
= get_parisc_dynamic_type (type
);
1625 sprintf (buff
, _("Operating System specific: %lx"), type
);
1628 sprintf (buff
, _("<unknown>: %lx"), type
);
1635 get_file_type (e_type
)
1638 static char buff
[32];
1642 case ET_NONE
: return _("NONE (None)");
1643 case ET_REL
: return _("REL (Relocatable file)");
1644 case ET_EXEC
: return _("EXEC (Executable file)");
1645 case ET_DYN
: return _("DYN (Shared object file)");
1646 case ET_CORE
: return _("CORE (Core file)");
1649 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1650 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
1651 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1652 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
1654 sprintf (buff
, _("<unknown>: %x"), e_type
);
1660 get_machine_name (e_machine
)
1663 static char buff
[64]; /* XXX */
1667 case EM_NONE
: return _("None");
1668 case EM_M32
: return "WE32100";
1669 case EM_SPARC
: return "Sparc";
1670 case EM_386
: return "Intel 80386";
1671 case EM_68K
: return "MC68000";
1672 case EM_88K
: return "MC88000";
1673 case EM_486
: return "Intel 80486";
1674 case EM_860
: return "Intel 80860";
1675 case EM_MIPS
: return "MIPS R3000";
1676 case EM_S370
: return "IBM System/370";
1677 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1678 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1679 case EM_PARISC
: return "HPPA";
1680 case EM_PPC_OLD
: return "Power PC (old)";
1681 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1682 case EM_960
: return "Intel 90860";
1683 case EM_PPC
: return "PowerPC";
1684 case EM_PPC64
: return "PowerPC64";
1685 case EM_V800
: return "NEC V800";
1686 case EM_FR20
: return "Fujitsu FR20";
1687 case EM_RH32
: return "TRW RH32";
1688 case EM_MCORE
: return "MCORE";
1689 case EM_ARM
: return "ARM";
1690 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1691 case EM_SH
: return "Hitachi SH";
1692 case EM_SPARCV9
: return "Sparc v9";
1693 case EM_TRICORE
: return "Siemens Tricore";
1694 case EM_ARC
: return "ARC";
1695 case EM_H8_300
: return "Hitachi H8/300";
1696 case EM_H8_300H
: return "Hitachi H8/300H";
1697 case EM_H8S
: return "Hitachi H8S";
1698 case EM_H8_500
: return "Hitachi H8/500";
1699 case EM_IA_64
: return "Intel IA-64";
1700 case EM_MIPS_X
: return "Stanford MIPS-X";
1701 case EM_COLDFIRE
: return "Motorola Coldfire";
1702 case EM_68HC12
: return "Motorola M68HC12";
1703 case EM_ALPHA
: return "Alpha";
1704 case EM_CYGNUS_D10V
:
1705 case EM_D10V
: return "d10v";
1706 case EM_CYGNUS_D30V
:
1707 case EM_D30V
: return "d30v";
1708 case EM_CYGNUS_M32R
:
1709 case EM_M32R
: return "Mitsubishi M32r";
1710 case EM_CYGNUS_V850
:
1711 case EM_V850
: return "NEC v850";
1712 case EM_CYGNUS_MN10300
:
1713 case EM_MN10300
: return "mn10300";
1714 case EM_CYGNUS_MN10200
:
1715 case EM_MN10200
: return "mn10200";
1716 case EM_CYGNUS_FR30
:
1717 case EM_FR30
: return "Fujitsu FR30";
1718 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1720 case EM_PJ
: return "picoJava";
1721 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1722 case EM_PCP
: return "Siemens PCP";
1723 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1724 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1725 case EM_STARCORE
: return "Motorola Star*Core processor";
1726 case EM_ME16
: return "Toyota ME16 processor";
1727 case EM_ST100
: return "STMicroelectronics ST100 processor";
1728 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1729 case EM_FX66
: return "Siemens FX66 microcontroller";
1730 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1731 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1732 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1733 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1734 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1735 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1736 case EM_SVX
: return "Silicon Graphics SVx";
1737 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1738 case EM_VAX
: return "Digital VAX";
1740 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1741 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1742 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1743 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1744 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1745 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1746 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1747 case EM_PRISM
: return "Vitesse Prism";
1748 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1750 case EM_S390
: return "IBM S/390";
1751 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1753 case EM_OR32
: return "OpenRISC";
1754 case EM_DLX
: return "OpenDLX";
1756 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1757 case EM_IQ2000
: return "Vitesse IQ2000";
1759 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1765 decode_ARM_machine_flags (e_flags
, buf
)
1772 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1773 e_flags
&= ~ EF_ARM_EABIMASK
;
1775 /* Handle "generic" ARM flags. */
1776 if (e_flags
& EF_ARM_RELEXEC
)
1778 strcat (buf
, ", relocatable executable");
1779 e_flags
&= ~ EF_ARM_RELEXEC
;
1782 if (e_flags
& EF_ARM_HASENTRY
)
1784 strcat (buf
, ", has entry point");
1785 e_flags
&= ~ EF_ARM_HASENTRY
;
1788 /* Now handle EABI specific flags. */
1792 strcat (buf
, ", <unrecognized EABI>");
1797 case EF_ARM_EABI_VER1
:
1798 strcat (buf
, ", Version1 EABI");
1803 /* Process flags one bit at a time. */
1804 flag
= e_flags
& - e_flags
;
1809 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1810 strcat (buf
, ", sorted symbol tables");
1820 case EF_ARM_EABI_VER2
:
1821 strcat (buf
, ", Version2 EABI");
1826 /* Process flags one bit at a time. */
1827 flag
= e_flags
& - e_flags
;
1832 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1833 strcat (buf
, ", sorted symbol tables");
1836 case EF_ARM_DYNSYMSUSESEGIDX
:
1837 strcat (buf
, ", dynamic symbols use segment index");
1840 case EF_ARM_MAPSYMSFIRST
:
1841 strcat (buf
, ", mapping symbols precede others");
1851 case EF_ARM_EABI_UNKNOWN
:
1852 strcat (buf
, ", GNU EABI");
1857 /* Process flags one bit at a time. */
1858 flag
= e_flags
& - e_flags
;
1863 case EF_ARM_INTERWORK
:
1864 strcat (buf
, ", interworking enabled");
1867 case EF_ARM_APCS_26
:
1868 strcat (buf
, ", uses APCS/26");
1871 case EF_ARM_APCS_FLOAT
:
1872 strcat (buf
, ", uses APCS/float");
1876 strcat (buf
, ", position independent");
1880 strcat (buf
, ", 8 bit structure alignment");
1883 case EF_ARM_NEW_ABI
:
1884 strcat (buf
, ", uses new ABI");
1887 case EF_ARM_OLD_ABI
:
1888 strcat (buf
, ", uses old ABI");
1891 case EF_ARM_SOFT_FLOAT
:
1892 strcat (buf
, ", software FP");
1895 case EF_ARM_MAVERICK_FLOAT
:
1896 strcat (buf
, ", Maverick FP");
1907 strcat (buf
,", <unknown>");
1911 get_machine_flags (e_flags
, e_machine
)
1915 static char buf
[1024];
1927 decode_ARM_machine_flags (e_flags
, buf
);
1931 if (e_flags
& EF_CPU32
)
1932 strcat (buf
, ", cpu32");
1933 if (e_flags
& EF_M68000
)
1934 strcat (buf
, ", m68000");
1938 if (e_flags
& EF_PPC_EMB
)
1939 strcat (buf
, ", emb");
1941 if (e_flags
& EF_PPC_RELOCATABLE
)
1942 strcat (buf
, ", relocatable");
1944 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1945 strcat (buf
, ", relocatable-lib");
1949 case EM_CYGNUS_V850
:
1950 switch (e_flags
& EF_V850_ARCH
)
1953 strcat (buf
, ", v850e");
1956 strcat (buf
, ", v850");
1959 strcat (buf
, ", unknown v850 architecture variant");
1965 case EM_CYGNUS_M32R
:
1966 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1967 strcat (buf
, ", m32r");
1972 case EM_MIPS_RS3_LE
:
1973 if (e_flags
& EF_MIPS_NOREORDER
)
1974 strcat (buf
, ", noreorder");
1976 if (e_flags
& EF_MIPS_PIC
)
1977 strcat (buf
, ", pic");
1979 if (e_flags
& EF_MIPS_CPIC
)
1980 strcat (buf
, ", cpic");
1982 if (e_flags
& EF_MIPS_UCODE
)
1983 strcat (buf
, ", ugen_reserved");
1985 if (e_flags
& EF_MIPS_ABI2
)
1986 strcat (buf
, ", abi2");
1988 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
1989 strcat (buf
, ", odk first");
1991 if (e_flags
& EF_MIPS_32BITMODE
)
1992 strcat (buf
, ", 32bitmode");
1994 switch ((e_flags
& EF_MIPS_MACH
))
1996 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
1997 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
1998 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
1999 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2000 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2001 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2002 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2003 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2004 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2006 /* We simply ignore the field in this case to avoid confusion:
2007 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2010 default: strcat (buf
, ", unknown CPU"); break;
2013 switch ((e_flags
& EF_MIPS_ABI
))
2015 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2016 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2017 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2018 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2020 /* We simply ignore the field in this case to avoid confusion:
2021 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2022 This means it is likely to be an o32 file, but not for
2025 default: strcat (buf
, ", unknown ABI"); break;
2028 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2029 strcat (buf
, ", mdmx");
2031 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2032 strcat (buf
, ", mips16");
2034 switch ((e_flags
& EF_MIPS_ARCH
))
2036 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2037 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2038 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2039 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2040 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2041 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2042 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2043 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2044 default: strcat (buf
, ", unknown ISA"); break;
2050 if (e_flags
& EF_SPARC_32PLUS
)
2051 strcat (buf
, ", v8+");
2053 if (e_flags
& EF_SPARC_SUN_US1
)
2054 strcat (buf
, ", ultrasparcI");
2056 if (e_flags
& EF_SPARC_SUN_US3
)
2057 strcat (buf
, ", ultrasparcIII");
2059 if (e_flags
& EF_SPARC_HAL_R1
)
2060 strcat (buf
, ", halr1");
2062 if (e_flags
& EF_SPARC_LEDATA
)
2063 strcat (buf
, ", ledata");
2065 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2066 strcat (buf
, ", tso");
2068 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2069 strcat (buf
, ", pso");
2071 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2072 strcat (buf
, ", rmo");
2076 switch (e_flags
& EF_PARISC_ARCH
)
2078 case EFA_PARISC_1_0
:
2079 strcpy (buf
, ", PA-RISC 1.0");
2081 case EFA_PARISC_1_1
:
2082 strcpy (buf
, ", PA-RISC 1.1");
2084 case EFA_PARISC_2_0
:
2085 strcpy (buf
, ", PA-RISC 2.0");
2090 if (e_flags
& EF_PARISC_TRAPNIL
)
2091 strcat (buf
, ", trapnil");
2092 if (e_flags
& EF_PARISC_EXT
)
2093 strcat (buf
, ", ext");
2094 if (e_flags
& EF_PARISC_LSB
)
2095 strcat (buf
, ", lsb");
2096 if (e_flags
& EF_PARISC_WIDE
)
2097 strcat (buf
, ", wide");
2098 if (e_flags
& EF_PARISC_NO_KABP
)
2099 strcat (buf
, ", no kabp");
2100 if (e_flags
& EF_PARISC_LAZYSWAP
)
2101 strcat (buf
, ", lazyswap");
2106 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2107 strcat (buf
, ", new calling convention");
2109 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2110 strcat (buf
, ", gnu calling convention");
2114 if ((e_flags
& EF_IA_64_ABI64
))
2115 strcat (buf
, ", 64-bit");
2117 strcat (buf
, ", 32-bit");
2118 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2119 strcat (buf
, ", reduced fp model");
2120 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2121 strcat (buf
, ", no function descriptors, constant gp");
2122 else if ((e_flags
& EF_IA_64_CONS_GP
))
2123 strcat (buf
, ", constant gp");
2124 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2125 strcat (buf
, ", absolute");
2129 if ((e_flags
& EF_VAX_NONPIC
))
2130 strcat (buf
, ", non-PIC");
2131 if ((e_flags
& EF_VAX_DFLOAT
))
2132 strcat (buf
, ", D-Float");
2133 if ((e_flags
& EF_VAX_GFLOAT
))
2134 strcat (buf
, ", G-Float");
2143 get_mips_segment_type (type
)
2148 case PT_MIPS_REGINFO
:
2150 case PT_MIPS_RTPROC
:
2152 case PT_MIPS_OPTIONS
:
2162 get_parisc_segment_type (type
)
2167 case PT_HP_TLS
: return "HP_TLS";
2168 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2169 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2170 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2171 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2172 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2173 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2174 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2175 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2176 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2177 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2178 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2179 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2180 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2189 get_ia64_segment_type (type
)
2194 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2195 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2196 case PT_HP_TLS
: return "HP_TLS";
2197 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2198 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2199 case PT_IA_64_HP_STACK
: return "HP_STACK";
2208 get_segment_type (p_type
)
2209 unsigned long p_type
;
2211 static char buff
[32];
2215 case PT_NULL
: return "NULL";
2216 case PT_LOAD
: return "LOAD";
2217 case PT_DYNAMIC
: return "DYNAMIC";
2218 case PT_INTERP
: return "INTERP";
2219 case PT_NOTE
: return "NOTE";
2220 case PT_SHLIB
: return "SHLIB";
2221 case PT_PHDR
: return "PHDR";
2222 case PT_TLS
: return "TLS";
2224 case PT_GNU_EH_FRAME
:
2225 return "GNU_EH_FRAME";
2228 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2232 switch (elf_header
.e_machine
)
2235 case EM_MIPS_RS3_LE
:
2236 result
= get_mips_segment_type (p_type
);
2239 result
= get_parisc_segment_type (p_type
);
2242 result
= get_ia64_segment_type (p_type
);
2252 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2254 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2258 switch (elf_header
.e_machine
)
2261 result
= get_parisc_segment_type (p_type
);
2264 result
= get_ia64_segment_type (p_type
);
2274 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2277 sprintf (buff
, _("<unknown>: %lx"), p_type
);
2284 get_mips_section_type_name (sh_type
)
2285 unsigned int sh_type
;
2289 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2290 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2291 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2292 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2293 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2294 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2295 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2296 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2297 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2298 case SHT_MIPS_RELD
: return "MIPS_RELD";
2299 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2300 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2301 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2302 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2303 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2304 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2305 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2306 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2307 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2308 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2309 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2310 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2311 case SHT_MIPS_LINE
: return "MIPS_LINE";
2312 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2313 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2314 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2315 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2316 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2317 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2318 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2319 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2320 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2321 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2322 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2323 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2324 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2325 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2326 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2327 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2335 get_parisc_section_type_name (sh_type
)
2336 unsigned int sh_type
;
2340 case SHT_PARISC_EXT
: return "PARISC_EXT";
2341 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2342 case SHT_PARISC_DOC
: return "PARISC_DOC";
2350 get_ia64_section_type_name (sh_type
)
2351 unsigned int sh_type
;
2353 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2354 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2355 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2359 case SHT_IA_64_EXT
: return "IA_64_EXT";
2360 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2361 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2369 get_section_type_name (sh_type
)
2370 unsigned int sh_type
;
2372 static char buff
[32];
2376 case SHT_NULL
: return "NULL";
2377 case SHT_PROGBITS
: return "PROGBITS";
2378 case SHT_SYMTAB
: return "SYMTAB";
2379 case SHT_STRTAB
: return "STRTAB";
2380 case SHT_RELA
: return "RELA";
2381 case SHT_HASH
: return "HASH";
2382 case SHT_DYNAMIC
: return "DYNAMIC";
2383 case SHT_NOTE
: return "NOTE";
2384 case SHT_NOBITS
: return "NOBITS";
2385 case SHT_REL
: return "REL";
2386 case SHT_SHLIB
: return "SHLIB";
2387 case SHT_DYNSYM
: return "DYNSYM";
2388 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2389 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2390 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2391 case SHT_GROUP
: return "GROUP";
2392 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2393 case SHT_GNU_verdef
: return "VERDEF";
2394 case SHT_GNU_verneed
: return "VERNEED";
2395 case SHT_GNU_versym
: return "VERSYM";
2396 case 0x6ffffff0: return "VERSYM";
2397 case 0x6ffffffc: return "VERDEF";
2398 case 0x7ffffffd: return "AUXILIARY";
2399 case 0x7fffffff: return "FILTER";
2400 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2403 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2407 switch (elf_header
.e_machine
)
2410 case EM_MIPS_RS3_LE
:
2411 result
= get_mips_section_type_name (sh_type
);
2414 result
= get_parisc_section_type_name (sh_type
);
2417 result
= get_ia64_section_type_name (sh_type
);
2427 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2429 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2430 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2431 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2432 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2434 sprintf (buff
, _("<unknown>: %x"), sh_type
);
2440 #define OPTION_DEBUG_DUMP 512
2442 struct option options
[] =
2444 {"all", no_argument
, 0, 'a'},
2445 {"file-header", no_argument
, 0, 'h'},
2446 {"program-headers", no_argument
, 0, 'l'},
2447 {"headers", no_argument
, 0, 'e'},
2448 {"histogram", no_argument
, 0, 'I'},
2449 {"segments", no_argument
, 0, 'l'},
2450 {"sections", no_argument
, 0, 'S'},
2451 {"section-headers", no_argument
, 0, 'S'},
2452 {"symbols", no_argument
, 0, 's'},
2453 {"syms", no_argument
, 0, 's'},
2454 {"relocs", no_argument
, 0, 'r'},
2455 {"notes", no_argument
, 0, 'n'},
2456 {"dynamic", no_argument
, 0, 'd'},
2457 {"arch-specific", no_argument
, 0, 'A'},
2458 {"version-info", no_argument
, 0, 'V'},
2459 {"use-dynamic", no_argument
, 0, 'D'},
2460 {"hex-dump", required_argument
, 0, 'x'},
2461 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2462 {"unwind", no_argument
, 0, 'u'},
2463 #ifdef SUPPORT_DISASSEMBLY
2464 {"instruction-dump", required_argument
, 0, 'i'},
2467 {"version", no_argument
, 0, 'v'},
2468 {"wide", no_argument
, 0, 'W'},
2469 {"help", no_argument
, 0, 'H'},
2470 {0, no_argument
, 0, 0}
2476 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2477 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2478 fprintf (stdout
, _(" Options are:\n\
2479 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2480 -h --file-header Display the ELF file header\n\
2481 -l --program-headers Display the program headers\n\
2482 --segments An alias for --program-headers\n\
2483 -S --section-headers Display the sections' header\n\
2484 --sections An alias for --section-headers\n\
2485 -e --headers Equivalent to: -h -l -S\n\
2486 -s --syms Display the symbol table\n\
2487 --symbols An alias for --syms\n\
2488 -n --notes Display the core notes (if present)\n\
2489 -r --relocs Display the relocations (if present)\n\
2490 -u --unwind Display the unwind info (if present)\n\
2491 -d --dynamic Display the dynamic segment (if present)\n\
2492 -V --version-info Display the version sections (if present)\n\
2493 -A --arch-specific Display architecture specific information (if any).\n\
2494 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2495 -x --hex-dump=<number> Dump the contents of section <number>\n\
2496 -w[liaprmfFso] or\n\
2497 --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
2498 Display the contents of DWARF2 debug sections\n"));
2499 #ifdef SUPPORT_DISASSEMBLY
2500 fprintf (stdout
, _("\
2501 -i --instruction-dump=<number>\n\
2502 Disassemble the contents of section <number>\n"));
2504 fprintf (stdout
, _("\
2505 -I --histogram Display histogram of bucket list lengths\n\
2506 -W --wide Allow output width to exceed 80 characters\n\
2507 -H --help Display this information\n\
2508 -v --version Display the version number of readelf\n"));
2509 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2515 request_dump (section
, type
)
2516 unsigned int section
;
2519 if (section
>= num_dump_sects
)
2521 char *new_dump_sects
;
2523 new_dump_sects
= (char *) calloc (section
+ 1, 1);
2525 if (new_dump_sects
== NULL
)
2526 error (_("Out of memory allocating dump request table."));
2529 /* Copy current flag settings. */
2530 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2534 dump_sects
= new_dump_sects
;
2535 num_dump_sects
= section
+ 1;
2540 dump_sects
[section
] |= type
;
2546 parse_args (argc
, argv
)
2555 while ((c
= getopt_long
2556 (argc
, argv
, "ersuahnldSDAIw::x:i:vVWH", options
, NULL
)) != EOF
)
2623 section
= strtoul (optarg
, & cp
, 0);
2624 if (! *cp
&& section
>= 0)
2626 request_dump (section
, HEX_DUMP
);
2636 unsigned int index
= 0;
2640 while (optarg
[index
])
2641 switch (optarg
[index
++])
2650 do_debug_abbrevs
= 1;
2660 do_debug_pubnames
= 1;
2665 do_debug_aranges
= 1;
2669 do_debug_frames_interp
= 1;
2671 do_debug_frames
= 1;
2676 do_debug_macinfo
= 1;
2690 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2695 case OPTION_DEBUG_DUMP
:
2701 static const char *debug_dump_opt
[]
2702 = { "line", "info", "abbrev", "pubnames", "ranges",
2703 "macro", "frames", "frames-interp", "str", "loc", NULL
};
2712 for (index
= 0; debug_dump_opt
[index
]; index
++)
2714 size_t len
= strlen (debug_dump_opt
[index
]);
2716 if (strncmp (p
, debug_dump_opt
[index
], len
) == 0
2717 && (p
[len
] == ',' || p
[len
] == '\0'))
2726 do_debug_abbrevs
= 1;
2737 do_debug_pubnames
= 1;
2741 do_debug_aranges
= 1;
2746 do_debug_frames_interp
= 1;
2747 do_debug_frames
= 1;
2751 do_debug_macinfo
= 1;
2764 if (debug_dump_opt
[index
] == NULL
)
2766 warn (_("Unrecognized debug option '%s'\n"), p
);
2767 p
= strchr (p
, ',');
2777 #ifdef SUPPORT_DISASSEMBLY
2780 section
= strtoul (optarg
, & cp
, 0);
2781 if (! *cp
&& section
>= 0)
2783 request_dump (section
, DISASS_DUMP
);
2789 print_version (program_name
);
2799 /* xgettext:c-format */
2800 error (_("Invalid option '-%c'\n"), c
);
2807 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2808 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2809 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
)
2813 warn (_("Nothing to do.\n"));
2819 get_elf_class (elf_class
)
2820 unsigned int elf_class
;
2822 static char buff
[32];
2826 case ELFCLASSNONE
: return _("none");
2827 case ELFCLASS32
: return "ELF32";
2828 case ELFCLASS64
: return "ELF64";
2830 sprintf (buff
, _("<unknown: %x>"), elf_class
);
2836 get_data_encoding (encoding
)
2837 unsigned int encoding
;
2839 static char buff
[32];
2843 case ELFDATANONE
: return _("none");
2844 case ELFDATA2LSB
: return _("2's complement, little endian");
2845 case ELFDATA2MSB
: return _("2's complement, big endian");
2847 sprintf (buff
, _("<unknown: %x>"), encoding
);
2853 get_osabi_name (osabi
)
2856 static char buff
[32];
2860 case ELFOSABI_NONE
: return "UNIX - System V";
2861 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2862 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2863 case ELFOSABI_LINUX
: return "UNIX - Linux";
2864 case ELFOSABI_HURD
: return "GNU/Hurd";
2865 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2866 case ELFOSABI_AIX
: return "UNIX - AIX";
2867 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2868 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2869 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2870 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2871 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2872 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2873 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2874 case ELFOSABI_AROS
: return "Amiga Research OS";
2875 case ELFOSABI_STANDALONE
: return _("Standalone App");
2876 case ELFOSABI_ARM
: return "ARM";
2878 sprintf (buff
, _("<unknown: %x>"), osabi
);
2883 /* Decode the data held in 'elf_header'. */
2885 process_file_header ()
2887 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2888 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2889 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2890 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2893 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2901 printf (_("ELF Header:\n"));
2902 printf (_(" Magic: "));
2903 for (i
= 0; i
< EI_NIDENT
; i
++)
2904 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2906 printf (_(" Class: %s\n"),
2907 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2908 printf (_(" Data: %s\n"),
2909 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2910 printf (_(" Version: %d %s\n"),
2911 elf_header
.e_ident
[EI_VERSION
],
2912 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
2914 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
2917 printf (_(" OS/ABI: %s\n"),
2918 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
2919 printf (_(" ABI Version: %d\n"),
2920 elf_header
.e_ident
[EI_ABIVERSION
]);
2921 printf (_(" Type: %s\n"),
2922 get_file_type (elf_header
.e_type
));
2923 printf (_(" Machine: %s\n"),
2924 get_machine_name (elf_header
.e_machine
));
2925 printf (_(" Version: 0x%lx\n"),
2926 (unsigned long) elf_header
.e_version
);
2928 printf (_(" Entry point address: "));
2929 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2930 printf (_("\n Start of program headers: "));
2931 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2932 printf (_(" (bytes into file)\n Start of section headers: "));
2933 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
2934 printf (_(" (bytes into file)\n"));
2936 printf (_(" Flags: 0x%lx%s\n"),
2937 (unsigned long) elf_header
.e_flags
,
2938 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
2939 printf (_(" Size of this header: %ld (bytes)\n"),
2940 (long) elf_header
.e_ehsize
);
2941 printf (_(" Size of program headers: %ld (bytes)\n"),
2942 (long) elf_header
.e_phentsize
);
2943 printf (_(" Number of program headers: %ld\n"),
2944 (long) elf_header
.e_phnum
);
2945 printf (_(" Size of section headers: %ld (bytes)\n"),
2946 (long) elf_header
.e_shentsize
);
2947 printf (_(" Number of section headers: %ld"),
2948 (long) elf_header
.e_shnum
);
2949 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
2950 printf (" (%ld)", (long) section_headers
[0].sh_size
);
2951 putc ('\n', stdout
);
2952 printf (_(" Section header string table index: %ld"),
2953 (long) elf_header
.e_shstrndx
);
2954 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
2955 printf (" (%ld)", (long) section_headers
[0].sh_link
);
2956 putc ('\n', stdout
);
2959 if (section_headers
!= NULL
)
2961 if (elf_header
.e_shnum
== 0)
2962 elf_header
.e_shnum
= section_headers
[0].sh_size
;
2963 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
2964 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
2965 free (section_headers
);
2966 section_headers
= NULL
;
2974 get_32bit_program_headers (file
, program_headers
)
2976 Elf_Internal_Phdr
*program_headers
;
2978 Elf32_External_Phdr
*phdrs
;
2979 Elf32_External_Phdr
*external
;
2980 Elf_Internal_Phdr
*internal
;
2983 phdrs
= ((Elf32_External_Phdr
*)
2984 get_data (NULL
, file
, elf_header
.e_phoff
,
2985 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2986 _("program headers")));
2990 for (i
= 0, internal
= program_headers
, external
= phdrs
;
2991 i
< elf_header
.e_phnum
;
2992 i
++, internal
++, external
++)
2994 internal
->p_type
= BYTE_GET (external
->p_type
);
2995 internal
->p_offset
= BYTE_GET (external
->p_offset
);
2996 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
2997 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
2998 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
2999 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3000 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3001 internal
->p_align
= BYTE_GET (external
->p_align
);
3010 get_64bit_program_headers (file
, program_headers
)
3012 Elf_Internal_Phdr
*program_headers
;
3014 Elf64_External_Phdr
*phdrs
;
3015 Elf64_External_Phdr
*external
;
3016 Elf_Internal_Phdr
*internal
;
3019 phdrs
= ((Elf64_External_Phdr
*)
3020 get_data (NULL
, file
, elf_header
.e_phoff
,
3021 elf_header
.e_phentsize
* elf_header
.e_phnum
,
3022 _("program headers")));
3026 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3027 i
< elf_header
.e_phnum
;
3028 i
++, internal
++, external
++)
3030 internal
->p_type
= BYTE_GET (external
->p_type
);
3031 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3032 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
3033 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
3034 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
3035 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
3036 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
3037 internal
->p_align
= BYTE_GET8 (external
->p_align
);
3045 /* Returns 1 if the program headers were loaded. */
3048 process_program_headers (file
)
3051 Elf_Internal_Phdr
*program_headers
;
3052 Elf_Internal_Phdr
*segment
;
3055 if (elf_header
.e_phnum
== 0)
3058 printf (_("\nThere are no program headers in this file.\n"));
3062 if (do_segments
&& !do_header
)
3064 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3065 printf (_("Entry point "));
3066 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3067 printf (_("\nThere are %d program headers, starting at offset "),
3068 elf_header
.e_phnum
);
3069 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3073 program_headers
= (Elf_Internal_Phdr
*) malloc
3074 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
3076 if (program_headers
== NULL
)
3078 error (_("Out of memory\n"));
3083 i
= get_32bit_program_headers (file
, program_headers
);
3085 i
= get_64bit_program_headers (file
, program_headers
);
3089 free (program_headers
);
3095 if (elf_header
.e_phnum
> 1)
3096 printf (_("\nProgram Headers:\n"));
3098 printf (_("\nProgram Headers:\n"));
3102 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3105 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3109 (_(" Type Offset VirtAddr PhysAddr\n"));
3111 (_(" FileSiz MemSiz Flags Align\n"));
3119 for (i
= 0, segment
= program_headers
;
3120 i
< elf_header
.e_phnum
;
3125 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3129 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3130 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3131 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3132 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3133 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3135 (segment
->p_flags
& PF_R
? 'R' : ' '),
3136 (segment
->p_flags
& PF_W
? 'W' : ' '),
3137 (segment
->p_flags
& PF_X
? 'E' : ' '));
3138 printf ("%#lx", (unsigned long) segment
->p_align
);
3142 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3143 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3146 print_vma (segment
->p_offset
, FULL_HEX
);
3150 print_vma (segment
->p_vaddr
, FULL_HEX
);
3152 print_vma (segment
->p_paddr
, FULL_HEX
);
3155 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3156 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3159 print_vma (segment
->p_filesz
, FULL_HEX
);
3163 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3164 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3167 print_vma (segment
->p_offset
, FULL_HEX
);
3171 (segment
->p_flags
& PF_R
? 'R' : ' '),
3172 (segment
->p_flags
& PF_W
? 'W' : ' '),
3173 (segment
->p_flags
& PF_X
? 'E' : ' '));
3175 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3176 printf ("%#lx", (unsigned long) segment
->p_align
);
3179 print_vma (segment
->p_align
, PREFIX_HEX
);
3184 print_vma (segment
->p_offset
, FULL_HEX
);
3186 print_vma (segment
->p_vaddr
, FULL_HEX
);
3188 print_vma (segment
->p_paddr
, FULL_HEX
);
3190 print_vma (segment
->p_filesz
, FULL_HEX
);
3192 print_vma (segment
->p_memsz
, FULL_HEX
);
3194 (segment
->p_flags
& PF_R
? 'R' : ' '),
3195 (segment
->p_flags
& PF_W
? 'W' : ' '),
3196 (segment
->p_flags
& PF_X
? 'E' : ' '));
3197 print_vma (segment
->p_align
, HEX
);
3201 switch (segment
->p_type
)
3206 unsigned long align_mask
= -segment
->p_align
;
3208 if (align_mask
== 0)
3210 loadaddr
= ((segment
->p_vaddr
& align_mask
)
3211 - (segment
->p_offset
& align_mask
));
3217 error (_("more than one dynamic segment\n"));
3219 dynamic_addr
= segment
->p_offset
;
3220 dynamic_size
= segment
->p_filesz
;
3224 if (fseek (file
, (long) segment
->p_offset
, SEEK_SET
))
3225 error (_("Unable to find program interpreter name\n"));
3228 program_interpreter
[0] = 0;
3229 fscanf (file
, "%63s", program_interpreter
);
3232 printf (_("\n [Requesting program interpreter: %s]"),
3233 program_interpreter
);
3239 putc ('\n', stdout
);
3248 if (do_segments
&& section_headers
!= NULL
)
3250 printf (_("\n Section to Segment mapping:\n"));
3251 printf (_(" Segment Sections...\n"));
3253 assert (string_table
!= NULL
);
3255 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3258 Elf_Internal_Shdr
*section
;
3260 segment
= program_headers
+ i
;
3261 section
= section_headers
;
3263 printf (" %2.2d ", i
);
3265 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3267 if (section
->sh_size
> 0
3268 /* Compare allocated sections by VMA, unallocated
3269 sections by file offset. */
3270 && (section
->sh_flags
& SHF_ALLOC
3271 ? (section
->sh_addr
>= segment
->p_vaddr
3272 && section
->sh_addr
+ section
->sh_size
3273 <= segment
->p_vaddr
+ segment
->p_memsz
)
3274 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3275 && (section
->sh_offset
+ section
->sh_size
3276 <= segment
->p_offset
+ segment
->p_filesz
))))
3277 printf ("%s ", SECTION_NAME (section
));
3284 free (program_headers
);
3291 get_32bit_section_headers (file
, num
)
3295 Elf32_External_Shdr
*shdrs
;
3296 Elf_Internal_Shdr
*internal
;
3299 shdrs
= ((Elf32_External_Shdr
*)
3300 get_data (NULL
, file
, elf_header
.e_shoff
,
3301 elf_header
.e_shentsize
* num
,
3302 _("section headers")));
3306 section_headers
= ((Elf_Internal_Shdr
*)
3307 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3309 if (section_headers
== NULL
)
3311 error (_("Out of memory\n"));
3315 for (i
= 0, internal
= section_headers
;
3319 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3320 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3321 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3322 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3323 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3324 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3325 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3326 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3327 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3328 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3337 get_64bit_section_headers (file
, num
)
3341 Elf64_External_Shdr
*shdrs
;
3342 Elf_Internal_Shdr
*internal
;
3345 shdrs
= ((Elf64_External_Shdr
*)
3346 get_data (NULL
, file
, elf_header
.e_shoff
,
3347 elf_header
.e_shentsize
* num
,
3348 _("section headers")));
3352 section_headers
= ((Elf_Internal_Shdr
*)
3353 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3355 if (section_headers
== NULL
)
3357 error (_("Out of memory\n"));
3361 for (i
= 0, internal
= section_headers
;
3365 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3366 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3367 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
3368 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
3369 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
3370 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
3371 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3372 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3373 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3374 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3382 static Elf_Internal_Sym
*
3383 get_32bit_elf_symbols (file
, section
)
3385 Elf_Internal_Shdr
*section
;
3387 unsigned long number
;
3388 Elf32_External_Sym
*esyms
;
3389 Elf_External_Sym_Shndx
*shndx
;
3390 Elf_Internal_Sym
*isyms
;
3391 Elf_Internal_Sym
*psym
;
3394 esyms
= ((Elf32_External_Sym
*)
3395 get_data (NULL
, file
, section
->sh_offset
,
3396 section
->sh_size
, _("symbols")));
3401 if (symtab_shndx_hdr
!= NULL
3402 && (symtab_shndx_hdr
->sh_link
3403 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3405 shndx
= ((Elf_External_Sym_Shndx
*)
3406 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3407 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3415 number
= section
->sh_size
/ section
->sh_entsize
;
3416 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3420 error (_("Out of memory\n"));
3427 for (j
= 0, psym
= isyms
;
3431 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3432 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3433 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3434 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3435 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3437 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3438 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3439 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3449 static Elf_Internal_Sym
*
3450 get_64bit_elf_symbols (file
, section
)
3452 Elf_Internal_Shdr
*section
;
3454 unsigned long number
;
3455 Elf64_External_Sym
*esyms
;
3456 Elf_External_Sym_Shndx
*shndx
;
3457 Elf_Internal_Sym
*isyms
;
3458 Elf_Internal_Sym
*psym
;
3461 esyms
= ((Elf64_External_Sym
*)
3462 get_data (NULL
, file
, section
->sh_offset
,
3463 section
->sh_size
, _("symbols")));
3468 if (symtab_shndx_hdr
!= NULL
3469 && (symtab_shndx_hdr
->sh_link
3470 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3472 shndx
= ((Elf_External_Sym_Shndx
*)
3473 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3474 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3482 number
= section
->sh_size
/ section
->sh_entsize
;
3483 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3487 error (_("Out of memory\n"));
3494 for (j
= 0, psym
= isyms
;
3498 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3499 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3500 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3501 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3502 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3504 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3505 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
3506 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
3517 get_elf_section_flags (sh_flags
)
3520 static char buff
[32];
3528 flag
= sh_flags
& - sh_flags
;
3533 case SHF_WRITE
: strcat (buff
, "W"); break;
3534 case SHF_ALLOC
: strcat (buff
, "A"); break;
3535 case SHF_EXECINSTR
: strcat (buff
, "X"); break;
3536 case SHF_MERGE
: strcat (buff
, "M"); break;
3537 case SHF_STRINGS
: strcat (buff
, "S"); break;
3538 case SHF_INFO_LINK
: strcat (buff
, "I"); break;
3539 case SHF_LINK_ORDER
: strcat (buff
, "L"); break;
3540 case SHF_OS_NONCONFORMING
: strcat (buff
, "O"); break;
3541 case SHF_GROUP
: strcat (buff
, "G"); break;
3542 case SHF_TLS
: strcat (buff
, "T"); break;
3545 if (flag
& SHF_MASKOS
)
3548 sh_flags
&= ~ SHF_MASKOS
;
3550 else if (flag
& SHF_MASKPROC
)
3553 sh_flags
&= ~ SHF_MASKPROC
;
3565 process_section_headers (file
)
3568 Elf_Internal_Shdr
*section
;
3571 section_headers
= NULL
;
3573 if (elf_header
.e_shnum
== 0)
3576 printf (_("\nThere are no sections in this file.\n"));
3581 if (do_sections
&& !do_header
)
3582 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3583 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3587 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3590 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3593 /* Read in the string table, so that we have names to display. */
3594 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3596 if (section
->sh_size
!= 0)
3598 string_table
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3599 section
->sh_size
, _("string table"));
3601 string_table_length
= section
->sh_size
;
3604 /* Scan the sections for the dynamic symbol table
3605 and dynamic string table and debug sections. */
3606 dynamic_symbols
= NULL
;
3607 dynamic_strings
= NULL
;
3608 dynamic_syminfo
= NULL
;
3609 symtab_shndx_hdr
= NULL
;
3611 for (i
= 0, section
= section_headers
;
3612 i
< elf_header
.e_shnum
;
3615 char *name
= SECTION_NAME (section
);
3617 if (section
->sh_type
== SHT_DYNSYM
)
3619 if (dynamic_symbols
!= NULL
)
3621 error (_("File contains multiple dynamic symbol tables\n"));
3625 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3626 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3628 else if (section
->sh_type
== SHT_STRTAB
3629 && strcmp (name
, ".dynstr") == 0)
3631 if (dynamic_strings
!= NULL
)
3633 error (_("File contains multiple dynamic string tables\n"));
3637 dynamic_strings
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3639 _("dynamic strings"));
3641 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3643 if (symtab_shndx_hdr
!= NULL
)
3645 error (_("File contains multiple symtab shndx tables\n"));
3648 symtab_shndx_hdr
= section
;
3650 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3651 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3652 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3654 && strncmp (name
, ".debug_", 7) == 0)
3659 || (do_debug_info
&& (strcmp (name
, "info") == 0))
3660 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
3661 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
3662 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
3663 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
3664 || (do_debug_frames
&& (strcmp (name
, "frame") == 0))
3665 || (do_debug_macinfo
&& (strcmp (name
, "macinfo") == 0))
3666 || (do_debug_str
&& (strcmp (name
, "str") == 0))
3667 || (do_debug_loc
&& (strcmp (name
, "loc") == 0))
3669 request_dump (i
, DEBUG_DUMP
);
3671 /* linkonce section to be combined with .debug_info at link time. */
3672 else if ((do_debugging
|| do_debug_info
)
3673 && strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
3674 request_dump (i
, DEBUG_DUMP
);
3675 else if (do_debug_frames
&& strcmp (name
, ".eh_frame") == 0)
3676 request_dump (i
, DEBUG_DUMP
);
3682 if (elf_header
.e_shnum
> 1)
3683 printf (_("\nSection Headers:\n"));
3685 printf (_("\nSection Header:\n"));
3689 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3692 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3695 printf (_(" [Nr] Name Type Address Offset\n"));
3696 printf (_(" Size EntSize Flags Link Info Align\n"));
3699 for (i
= 0, section
= section_headers
;
3700 i
< elf_header
.e_shnum
;
3703 printf (" [%2u] %-17.17s %-15.15s ",
3704 SECTION_HEADER_NUM (i
),
3705 SECTION_NAME (section
),
3706 get_section_type_name (section
->sh_type
));
3710 print_vma (section
->sh_addr
, LONG_HEX
);
3712 printf ( " %6.6lx %6.6lx %2.2lx",
3713 (unsigned long) section
->sh_offset
,
3714 (unsigned long) section
->sh_size
,
3715 (unsigned long) section
->sh_entsize
);
3717 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3719 printf ("%2ld %3lx %2ld\n",
3720 (unsigned long) section
->sh_link
,
3721 (unsigned long) section
->sh_info
,
3722 (unsigned long) section
->sh_addralign
);
3726 print_vma (section
->sh_addr
, LONG_HEX
);
3728 if ((long) section
->sh_offset
== section
->sh_offset
)
3729 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
3733 print_vma (section
->sh_offset
, LONG_HEX
);
3736 if ((unsigned long) section
->sh_size
== section
->sh_size
)
3737 printf (" %6.6lx", (unsigned long) section
->sh_size
);
3741 print_vma (section
->sh_size
, LONG_HEX
);
3744 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
3745 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
3749 print_vma (section
->sh_entsize
, LONG_HEX
);
3752 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3754 printf ("%2ld %3lx ",
3755 (unsigned long) section
->sh_link
,
3756 (unsigned long) section
->sh_info
);
3758 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
3759 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
3762 print_vma (section
->sh_addralign
, DEC
);
3769 print_vma (section
->sh_addr
, LONG_HEX
);
3770 if ((long) section
->sh_offset
== section
->sh_offset
)
3771 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
3775 print_vma (section
->sh_offset
, LONG_HEX
);
3778 print_vma (section
->sh_size
, LONG_HEX
);
3780 print_vma (section
->sh_entsize
, LONG_HEX
);
3782 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3784 printf (" %2ld %3lx %ld\n",
3785 (unsigned long) section
->sh_link
,
3786 (unsigned long) section
->sh_info
,
3787 (unsigned long) section
->sh_addralign
);
3791 printf (_("Key to Flags:\n\
3792 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3793 I (info), L (link order), G (group), x (unknown)\n\
3794 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3799 /* Process the reloc section. */
3801 process_relocs (file
)
3804 unsigned long rel_size
;
3805 unsigned long rel_offset
;
3811 if (do_using_dynamic
)
3813 int is_rela
= FALSE
;
3818 if (dynamic_info
[DT_REL
])
3820 rel_offset
= dynamic_info
[DT_REL
];
3821 rel_size
= dynamic_info
[DT_RELSZ
];
3824 else if (dynamic_info
[DT_RELA
])
3826 rel_offset
= dynamic_info
[DT_RELA
];
3827 rel_size
= dynamic_info
[DT_RELASZ
];
3830 else if (dynamic_info
[DT_JMPREL
])
3832 rel_offset
= dynamic_info
[DT_JMPREL
];
3833 rel_size
= dynamic_info
[DT_PLTRELSZ
];
3835 switch (dynamic_info
[DT_PLTREL
])
3852 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3853 rel_offset
, rel_size
);
3855 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
3856 dynamic_symbols
, num_dynamic_syms
, dynamic_strings
,
3860 printf (_("\nThere are no dynamic relocations in this file.\n"));
3864 Elf_Internal_Shdr
*section
;
3868 for (i
= 0, section
= section_headers
;
3869 i
< elf_header
.e_shnum
;
3872 if ( section
->sh_type
!= SHT_RELA
3873 && section
->sh_type
!= SHT_REL
)
3876 rel_offset
= section
->sh_offset
;
3877 rel_size
= section
->sh_size
;
3881 Elf_Internal_Shdr
*strsec
;
3882 Elf_Internal_Sym
*symtab
;
3885 unsigned long nsyms
;
3887 printf (_("\nRelocation section "));
3889 if (string_table
== NULL
)
3890 printf ("%d", section
->sh_name
);
3892 printf (_("'%s'"), SECTION_NAME (section
));
3894 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3895 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
3900 if (section
->sh_link
)
3902 Elf_Internal_Shdr
*symsec
;
3904 symsec
= SECTION_HEADER (section
->sh_link
);
3905 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
3906 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
3911 strsec
= SECTION_HEADER (symsec
->sh_link
);
3913 strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
3917 is_rela
= section
->sh_type
== SHT_RELA
;
3919 dump_relocations (file
, rel_offset
, rel_size
,
3920 symtab
, nsyms
, strtab
, is_rela
);
3932 printf (_("\nThere are no relocations in this file.\n"));
3938 #include "unwind-ia64.h"
3940 /* An absolute address consists of a section and an offset. If the
3941 section is NULL, the offset itself is the address, otherwise, the
3942 address equals to LOAD_ADDRESS(section) + offset. */
3946 unsigned short section
;
3952 struct unw_table_entry
3954 struct absaddr start
;
3956 struct absaddr info
;
3958 *table
; /* Unwind table. */
3959 unsigned long table_len
; /* Length of unwind table. */
3960 unsigned char *info
; /* Unwind info. */
3961 unsigned long info_size
; /* Size of unwind info. */
3962 bfd_vma info_addr
; /* starting address of unwind info. */
3963 bfd_vma seg_base
; /* Starting address of segment. */
3964 Elf_Internal_Sym
*symtab
; /* The symbol table. */
3965 unsigned long nsyms
; /* Number of symbols. */
3966 char *strtab
; /* The string table. */
3967 unsigned long strtab_size
; /* Size of string table. */
3970 static void find_symbol_for_address
3971 PARAMS ((struct unw_aux_info
*, struct absaddr
, const char **, bfd_vma
*));
3972 static void dump_ia64_unwind
3973 PARAMS ((struct unw_aux_info
*));
3974 static int slurp_ia64_unwind_table
3975 PARAMS ((FILE *, struct unw_aux_info
*, Elf_Internal_Shdr
*));
3978 find_symbol_for_address (aux
, addr
, symname
, offset
)
3979 struct unw_aux_info
*aux
;
3980 struct absaddr addr
;
3981 const char **symname
;
3984 bfd_vma dist
= (bfd_vma
) 0x100000;
3985 Elf_Internal_Sym
*sym
, *best
= NULL
;
3988 for (i
= 0, sym
= aux
->symtab
; i
< aux
->nsyms
; ++i
, ++sym
)
3990 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
3991 && sym
->st_name
!= 0
3992 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
3993 && addr
.offset
>= sym
->st_value
3994 && addr
.offset
- sym
->st_value
< dist
)
3997 dist
= addr
.offset
- sym
->st_value
;
4004 *symname
= (best
->st_name
>= aux
->strtab_size
4005 ? "<corrupt>" : aux
->strtab
+ best
->st_name
);
4010 *offset
= addr
.offset
;
4014 dump_ia64_unwind (aux
)
4015 struct unw_aux_info
*aux
;
4018 struct unw_table_entry
*tp
;
4021 addr_size
= is_32bit_elf
? 4 : 8;
4023 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4027 const unsigned char *dp
;
4028 const unsigned char *head
;
4029 const char *procname
;
4031 find_symbol_for_address (aux
, tp
->start
, &procname
, &offset
);
4033 fputs ("\n<", stdout
);
4037 fputs (procname
, stdout
);
4040 printf ("+%lx", (unsigned long) offset
);
4043 fputs (">: [", stdout
);
4044 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4045 fputc ('-', stdout
);
4046 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4047 printf ("], info at +0x%lx\n",
4048 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4050 head
= aux
->info
+ (tp
->info
.offset
- aux
->info_addr
);
4051 stamp
= BYTE_GET8 ((unsigned char *) head
);
4053 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4054 (unsigned) UNW_VER (stamp
),
4055 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4056 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4057 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4058 (unsigned long) (addr_size
* UNW_LENGTH (stamp
)));
4060 if (UNW_VER (stamp
) != 1)
4062 printf ("\tUnknown version.\n");
4067 for (dp
= head
+ 8; dp
< head
+ 8 + addr_size
* UNW_LENGTH (stamp
);)
4068 dp
= unw_decode (dp
, in_body
, & in_body
);
4073 slurp_ia64_unwind_table (file
, aux
, sec
)
4075 struct unw_aux_info
*aux
;
4076 Elf_Internal_Shdr
*sec
;
4078 unsigned long size
, addr_size
, nrelas
, i
;
4079 Elf_Internal_Phdr
*prog_hdrs
, *seg
;
4080 struct unw_table_entry
*tep
;
4081 Elf_Internal_Shdr
*relsec
;
4082 Elf_Internal_Rela
*rela
, *rp
;
4083 unsigned char *table
, *tp
;
4084 Elf_Internal_Sym
*sym
;
4085 const char *relname
;
4088 addr_size
= is_32bit_elf
? 4 : 8;
4090 /* First, find the starting address of the segment that includes
4093 if (elf_header
.e_phnum
)
4095 prog_hdrs
= (Elf_Internal_Phdr
*)
4096 xmalloc (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
4099 result
= get_32bit_program_headers (file
, prog_hdrs
);
4101 result
= get_64bit_program_headers (file
, prog_hdrs
);
4109 for (seg
= prog_hdrs
; seg
< prog_hdrs
+ elf_header
.e_phnum
; ++seg
)
4111 if (seg
->p_type
!= PT_LOAD
)
4114 if (sec
->sh_addr
>= seg
->p_vaddr
4115 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4117 aux
->seg_base
= seg
->p_vaddr
;
4125 /* Second, build the unwind table from the contents of the unwind section: */
4126 size
= sec
->sh_size
;
4127 table
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4128 size
, _("unwind table"));
4132 tep
= aux
->table
= xmalloc (size
/ (3 * addr_size
) * sizeof (aux
->table
[0]));
4133 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * addr_size
, ++tep
)
4135 tep
->start
.section
= SHN_UNDEF
;
4136 tep
->end
.section
= SHN_UNDEF
;
4137 tep
->info
.section
= SHN_UNDEF
;
4140 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4141 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4142 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4146 tep
->start
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 0);
4147 tep
->end
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 8);
4148 tep
->info
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 16);
4150 tep
->start
.offset
+= aux
->seg_base
;
4151 tep
->end
.offset
+= aux
->seg_base
;
4152 tep
->info
.offset
+= aux
->seg_base
;
4156 /* Third, apply any relocations to the unwind table: */
4158 for (relsec
= section_headers
;
4159 relsec
< section_headers
+ elf_header
.e_shnum
;
4162 if (relsec
->sh_type
!= SHT_RELA
4163 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4166 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4170 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4174 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4175 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4177 if (ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4179 warn (_("Skipping unexpected symbol type %u\n"),
4180 ELF32_ST_TYPE (sym
->st_info
));
4186 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4187 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4189 if (ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4191 warn (_("Skipping unexpected symbol type %u\n"),
4192 ELF64_ST_TYPE (sym
->st_info
));
4197 if (strncmp (relname
, "R_IA64_SEGREL", 13) != 0)
4199 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4203 i
= rp
->r_offset
/ (3 * addr_size
);
4205 switch (rp
->r_offset
/addr_size
% 3)
4208 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4209 aux
->table
[i
].start
.offset
+= rp
->r_addend
;
4212 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4213 aux
->table
[i
].end
.offset
+= rp
->r_addend
;
4216 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4217 aux
->table
[i
].info
.offset
+= rp
->r_addend
;
4227 aux
->table_len
= size
/ (3 * addr_size
);
4232 process_unwind (file
)
4235 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4236 unsigned long i
, addr_size
, unwcount
= 0, unwstart
= 0;
4237 struct unw_aux_info aux
;
4242 if (elf_header
.e_machine
!= EM_IA_64
)
4244 printf (_("\nThere are no unwind sections in this file.\n"));
4248 memset (& aux
, 0, sizeof (aux
));
4250 addr_size
= is_32bit_elf
? 4 : 8;
4252 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4254 if (sec
->sh_type
== SHT_SYMTAB
)
4256 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4257 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4259 strsec
= SECTION_HEADER (sec
->sh_link
);
4260 aux
.strtab_size
= strsec
->sh_size
;
4261 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
4262 aux
.strtab_size
, _("string table"));
4264 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4269 printf (_("\nThere are no unwind sections in this file.\n"));
4271 while (unwcount
-- > 0)
4276 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4277 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4278 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4285 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4287 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
,
4290 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
4291 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4292 suffix
= SECTION_NAME (unwsec
) + len
;
4293 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4295 if (strncmp (SECTION_NAME (sec
),
4296 ELF_STRING_ia64_unwind_info_once
, len2
) == 0
4297 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4302 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4303 .IA_64.unwind or BAR -> .IA_64.unwind_info */
4304 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4305 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4307 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
,
4309 suffix
= SECTION_NAME (unwsec
) + len
;
4310 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4312 if (strncmp (SECTION_NAME (sec
),
4313 ELF_STRING_ia64_unwind_info
, len2
) == 0
4314 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4318 if (i
== elf_header
.e_shnum
)
4320 printf (_("\nCould not find unwind info section for "));
4322 if (string_table
== NULL
)
4323 printf ("%d", unwsec
->sh_name
);
4325 printf (_("'%s'"), SECTION_NAME (unwsec
));
4329 aux
.info_size
= sec
->sh_size
;
4330 aux
.info_addr
= sec
->sh_addr
;
4331 aux
.info
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4332 aux
.info_size
, _("unwind info"));
4334 printf (_("\nUnwind section "));
4336 if (string_table
== NULL
)
4337 printf ("%d", unwsec
->sh_name
);
4339 printf (_("'%s'"), SECTION_NAME (unwsec
));
4341 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4342 (unsigned long) unwsec
->sh_offset
,
4343 (unsigned long) (unwsec
->sh_size
/ (3 * addr_size
)));
4345 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4347 if (aux
.table_len
> 0)
4348 dump_ia64_unwind (& aux
);
4351 free ((char *) aux
.table
);
4353 free ((char *) aux
.info
);
4362 free ((char *) aux
.strtab
);
4368 dynamic_segment_mips_val (entry
)
4369 Elf_Internal_Dyn
*entry
;
4371 switch (entry
->d_tag
)
4374 if (entry
->d_un
.d_val
== 0)
4378 static const char * opts
[] =
4380 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
4381 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
4382 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
4383 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
4388 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
4389 if (entry
->d_un
.d_val
& (1 << cnt
))
4391 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
4398 case DT_MIPS_IVERSION
:
4399 if (dynamic_strings
!= NULL
)
4400 printf ("Interface Version: %s\n",
4401 dynamic_strings
+ entry
->d_un
.d_val
);
4403 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4406 case DT_MIPS_TIME_STAMP
:
4411 time_t time
= entry
->d_un
.d_val
;
4412 tmp
= gmtime (&time
);
4413 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
4414 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
4415 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
4416 printf ("Time Stamp: %s\n", timebuf
);
4420 case DT_MIPS_RLD_VERSION
:
4421 case DT_MIPS_LOCAL_GOTNO
:
4422 case DT_MIPS_CONFLICTNO
:
4423 case DT_MIPS_LIBLISTNO
:
4424 case DT_MIPS_SYMTABNO
:
4425 case DT_MIPS_UNREFEXTNO
:
4426 case DT_MIPS_HIPAGENO
:
4427 case DT_MIPS_DELTA_CLASS_NO
:
4428 case DT_MIPS_DELTA_INSTANCE_NO
:
4429 case DT_MIPS_DELTA_RELOC_NO
:
4430 case DT_MIPS_DELTA_SYM_NO
:
4431 case DT_MIPS_DELTA_CLASSSYM_NO
:
4432 case DT_MIPS_COMPACT_SIZE
:
4433 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4437 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
4443 dynamic_segment_parisc_val (entry
)
4444 Elf_Internal_Dyn
*entry
;
4446 switch (entry
->d_tag
)
4448 case DT_HP_DLD_FLAGS
:
4457 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
4458 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
4459 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
4460 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
4461 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
4462 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
4463 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
4464 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
4465 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
4466 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
4467 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" }
4471 bfd_vma val
= entry
->d_un
.d_val
;
4473 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
4474 if (val
& flags
[cnt
].bit
)
4478 fputs (flags
[cnt
].str
, stdout
);
4480 val
^= flags
[cnt
].bit
;
4483 if (val
!= 0 || first
)
4487 print_vma (val
, HEX
);
4493 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4500 dynamic_segment_ia64_val (entry
)
4501 Elf_Internal_Dyn
*entry
;
4503 switch (entry
->d_tag
)
4505 case DT_IA_64_PLT_RESERVE
:
4506 /* First 3 bytes reserved. */
4507 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4509 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
4515 get_32bit_dynamic_segment (file
)
4518 Elf32_External_Dyn
*edyn
;
4519 Elf_Internal_Dyn
*entry
;
4522 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4523 dynamic_size
, _("dynamic segment"));
4527 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4528 how large this .dynamic is now. We can do this even before the byte
4529 swapping since the DT_NULL tag is recognizable. */
4531 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4534 dynamic_segment
= (Elf_Internal_Dyn
*)
4535 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4537 if (dynamic_segment
== NULL
)
4539 error (_("Out of memory\n"));
4544 for (i
= 0, entry
= dynamic_segment
;
4548 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
4549 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
4558 get_64bit_dynamic_segment (file
)
4561 Elf64_External_Dyn
*edyn
;
4562 Elf_Internal_Dyn
*entry
;
4565 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4566 dynamic_size
, _("dynamic segment"));
4570 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4571 how large this .dynamic is now. We can do this even before the byte
4572 swapping since the DT_NULL tag is recognizable. */
4574 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4577 dynamic_segment
= (Elf_Internal_Dyn
*)
4578 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4580 if (dynamic_segment
== NULL
)
4582 error (_("Out of memory\n"));
4587 for (i
= 0, entry
= dynamic_segment
;
4591 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
4592 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
4601 get_dynamic_flags (flags
)
4604 static char buff
[128];
4612 flag
= flags
& - flags
;
4620 case DF_ORIGIN
: strcpy (p
, "ORIGIN"); break;
4621 case DF_SYMBOLIC
: strcpy (p
, "SYMBOLIC"); break;
4622 case DF_TEXTREL
: strcpy (p
, "TEXTREL"); break;
4623 case DF_BIND_NOW
: strcpy (p
, "BIND_NOW"); break;
4624 case DF_STATIC_TLS
: strcpy (p
, "STATIC_TLS"); break;
4625 default: strcpy (p
, "unknown"); break;
4628 p
= strchr (p
, '\0');
4633 /* Parse and display the contents of the dynamic segment. */
4635 process_dynamic_segment (file
)
4638 Elf_Internal_Dyn
*entry
;
4641 if (dynamic_size
== 0)
4644 printf (_("\nThere is no dynamic segment in this file.\n"));
4651 if (! get_32bit_dynamic_segment (file
))
4654 else if (! get_64bit_dynamic_segment (file
))
4657 /* Find the appropriate symbol table. */
4658 if (dynamic_symbols
== NULL
)
4660 for (i
= 0, entry
= dynamic_segment
;
4664 Elf_Internal_Shdr section
;
4666 if (entry
->d_tag
!= DT_SYMTAB
)
4669 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
4671 /* Since we do not know how big the symbol table is,
4672 we default to reading in the entire file (!) and
4673 processing that. This is overkill, I know, but it
4675 section
.sh_offset
= entry
->d_un
.d_val
- loadaddr
;
4677 if (fseek (file
, 0, SEEK_END
))
4678 error (_("Unable to seek to end of file!"));
4680 section
.sh_size
= ftell (file
) - section
.sh_offset
;
4682 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
4684 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
4686 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
4687 if (num_dynamic_syms
< 1)
4689 error (_("Unable to determine the number of symbols to load\n"));
4693 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
4697 /* Similarly find a string table. */
4698 if (dynamic_strings
== NULL
)
4700 for (i
= 0, entry
= dynamic_segment
;
4704 unsigned long offset
;
4707 if (entry
->d_tag
!= DT_STRTAB
)
4710 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
4712 /* Since we do not know how big the string table is,
4713 we default to reading in the entire file (!) and
4714 processing that. This is overkill, I know, but it
4717 offset
= entry
->d_un
.d_val
- loadaddr
;
4718 if (fseek (file
, 0, SEEK_END
))
4719 error (_("Unable to seek to end of file\n"));
4720 str_tab_len
= ftell (file
) - offset
;
4722 if (str_tab_len
< 1)
4725 (_("Unable to determine the length of the dynamic string table\n"));
4729 dynamic_strings
= (char *) get_data (NULL
, file
, offset
, str_tab_len
,
4730 _("dynamic string table"));
4735 /* And find the syminfo section if available. */
4736 if (dynamic_syminfo
== NULL
)
4738 unsigned long syminsz
= 0;
4740 for (i
= 0, entry
= dynamic_segment
;
4744 if (entry
->d_tag
== DT_SYMINENT
)
4746 /* Note: these braces are necessary to avoid a syntax
4747 error from the SunOS4 C compiler. */
4748 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
4750 else if (entry
->d_tag
== DT_SYMINSZ
)
4751 syminsz
= entry
->d_un
.d_val
;
4752 else if (entry
->d_tag
== DT_SYMINFO
)
4753 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
4756 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
4758 Elf_External_Syminfo
*extsyminfo
;
4759 Elf_Internal_Syminfo
*syminfo
;
4761 /* There is a syminfo section. Read the data. */
4762 extsyminfo
= ((Elf_External_Syminfo
*)
4763 get_data (NULL
, file
, dynamic_syminfo_offset
,
4764 syminsz
, _("symbol information")));
4768 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
4769 if (dynamic_syminfo
== NULL
)
4771 error (_("Out of memory\n"));
4775 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
4776 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
4779 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
4780 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
4787 if (do_dynamic
&& dynamic_addr
)
4788 printf (_("\nDynamic segment at offset 0x%lx contains %ld entries:\n"),
4789 dynamic_addr
, (long) dynamic_size
);
4791 printf (_(" Tag Type Name/Value\n"));
4793 for (i
= 0, entry
= dynamic_segment
;
4802 print_vma (entry
->d_tag
, FULL_HEX
);
4803 dtype
= get_dynamic_type (entry
->d_tag
);
4804 printf (" (%s)%*s", dtype
,
4805 ((is_32bit_elf
? 27 : 19)
4806 - (int) strlen (dtype
)),
4810 switch (entry
->d_tag
)
4814 puts (get_dynamic_flags (entry
->d_un
.d_val
));
4824 switch (entry
->d_tag
)
4827 printf (_("Auxiliary library"));
4831 printf (_("Filter library"));
4835 printf (_("Configuration file"));
4839 printf (_("Dependency audit library"));
4843 printf (_("Audit library"));
4847 if (dynamic_strings
)
4848 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
4852 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4861 printf (_("Flags:"));
4863 if (entry
->d_un
.d_val
== 0)
4864 printf (_(" None\n"));
4867 unsigned long int val
= entry
->d_un
.d_val
;
4869 if (val
& DTF_1_PARINIT
)
4871 printf (" PARINIT");
4872 val
^= DTF_1_PARINIT
;
4874 if (val
& DTF_1_CONFEXP
)
4876 printf (" CONFEXP");
4877 val
^= DTF_1_CONFEXP
;
4880 printf (" %lx", val
);
4889 printf (_("Flags:"));
4891 if (entry
->d_un
.d_val
== 0)
4892 printf (_(" None\n"));
4895 unsigned long int val
= entry
->d_un
.d_val
;
4897 if (val
& DF_P1_LAZYLOAD
)
4899 printf (" LAZYLOAD");
4900 val
^= DF_P1_LAZYLOAD
;
4902 if (val
& DF_P1_GROUPPERM
)
4904 printf (" GROUPPERM");
4905 val
^= DF_P1_GROUPPERM
;
4908 printf (" %lx", val
);
4917 printf (_("Flags:"));
4918 if (entry
->d_un
.d_val
== 0)
4919 printf (_(" None\n"));
4922 unsigned long int val
= entry
->d_un
.d_val
;
4929 if (val
& DF_1_GLOBAL
)
4934 if (val
& DF_1_GROUP
)
4939 if (val
& DF_1_NODELETE
)
4941 printf (" NODELETE");
4942 val
^= DF_1_NODELETE
;
4944 if (val
& DF_1_LOADFLTR
)
4946 printf (" LOADFLTR");
4947 val
^= DF_1_LOADFLTR
;
4949 if (val
& DF_1_INITFIRST
)
4951 printf (" INITFIRST");
4952 val
^= DF_1_INITFIRST
;
4954 if (val
& DF_1_NOOPEN
)
4959 if (val
& DF_1_ORIGIN
)
4964 if (val
& DF_1_DIRECT
)
4969 if (val
& DF_1_TRANS
)
4974 if (val
& DF_1_INTERPOSE
)
4976 printf (" INTERPOSE");
4977 val
^= DF_1_INTERPOSE
;
4979 if (val
& DF_1_NODEFLIB
)
4981 printf (" NODEFLIB");
4982 val
^= DF_1_NODEFLIB
;
4984 if (val
& DF_1_NODUMP
)
4989 if (val
& DF_1_CONLFAT
)
4991 printf (" CONLFAT");
4992 val
^= DF_1_CONLFAT
;
4995 printf (" %lx", val
);
5003 puts (get_dynamic_type (entry
->d_un
.d_val
));
5023 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5029 if (dynamic_strings
== NULL
)
5032 name
= dynamic_strings
+ entry
->d_un
.d_val
;
5036 switch (entry
->d_tag
)
5039 printf (_("Shared library: [%s]"), name
);
5041 if (strcmp (name
, program_interpreter
) == 0)
5042 printf (_(" program interpreter"));
5046 printf (_("Library soname: [%s]"), name
);
5050 printf (_("Library rpath: [%s]"), name
);
5054 printf (_("Library runpath: [%s]"), name
);
5058 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5063 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5079 case DT_INIT_ARRAYSZ
:
5080 case DT_FINI_ARRAYSZ
:
5081 case DT_GNU_CONFLICTSZ
:
5082 case DT_GNU_LIBLISTSZ
:
5085 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5086 printf (" (bytes)\n");
5096 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5109 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
5113 name
= dynamic_strings
+ entry
->d_un
.d_val
;
5117 printf (_("Not needed object: [%s]\n"), name
);
5122 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5128 /* The value of this entry is ignored. */
5133 case DT_GNU_PRELINKED
:
5137 time_t time
= entry
->d_un
.d_val
;
5139 tmp
= gmtime (&time
);
5140 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
5141 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5142 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5148 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
5149 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
5154 switch (elf_header
.e_machine
)
5157 case EM_MIPS_RS3_LE
:
5158 dynamic_segment_mips_val (entry
);
5161 dynamic_segment_parisc_val (entry
);
5164 dynamic_segment_ia64_val (entry
);
5167 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5179 get_ver_flags (flags
)
5182 static char buff
[32];
5189 if (flags
& VER_FLG_BASE
)
5190 strcat (buff
, "BASE ");
5192 if (flags
& VER_FLG_WEAK
)
5194 if (flags
& VER_FLG_BASE
)
5195 strcat (buff
, "| ");
5197 strcat (buff
, "WEAK ");
5200 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
5201 strcat (buff
, "| <unknown>");
5206 /* Display the contents of the version sections. */
5208 process_version_sections (file
)
5211 Elf_Internal_Shdr
*section
;
5218 for (i
= 0, section
= section_headers
;
5219 i
< elf_header
.e_shnum
;
5222 switch (section
->sh_type
)
5224 case SHT_GNU_verdef
:
5226 Elf_External_Verdef
*edefs
;
5233 (_("\nVersion definition section '%s' contains %ld entries:\n"),
5234 SECTION_NAME (section
), section
->sh_info
);
5236 printf (_(" Addr: 0x"));
5237 printf_vma (section
->sh_addr
);
5238 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5239 (unsigned long) section
->sh_offset
, section
->sh_link
,
5240 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5242 edefs
= ((Elf_External_Verdef
*)
5243 get_data (NULL
, file
, section
->sh_offset
,
5245 _("version definition section")));
5249 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5252 Elf_External_Verdef
*edef
;
5253 Elf_Internal_Verdef ent
;
5254 Elf_External_Verdaux
*eaux
;
5255 Elf_Internal_Verdaux aux
;
5259 vstart
= ((char *) edefs
) + idx
;
5261 edef
= (Elf_External_Verdef
*) vstart
;
5263 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
5264 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
5265 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
5266 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
5267 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
5268 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
5269 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
5271 printf (_(" %#06x: Rev: %d Flags: %s"),
5272 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
5274 printf (_(" Index: %d Cnt: %d "),
5275 ent
.vd_ndx
, ent
.vd_cnt
);
5277 vstart
+= ent
.vd_aux
;
5279 eaux
= (Elf_External_Verdaux
*) vstart
;
5281 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5282 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5284 if (dynamic_strings
)
5285 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
5287 printf (_("Name index: %ld\n"), aux
.vda_name
);
5289 isum
= idx
+ ent
.vd_aux
;
5291 for (j
= 1; j
< ent
.vd_cnt
; j
++)
5293 isum
+= aux
.vda_next
;
5294 vstart
+= aux
.vda_next
;
5296 eaux
= (Elf_External_Verdaux
*) vstart
;
5298 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5299 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5301 if (dynamic_strings
)
5302 printf (_(" %#06x: Parent %d: %s\n"),
5303 isum
, j
, dynamic_strings
+ aux
.vda_name
);
5305 printf (_(" %#06x: Parent %d, name index: %ld\n"),
5306 isum
, j
, aux
.vda_name
);
5316 case SHT_GNU_verneed
:
5318 Elf_External_Verneed
*eneed
;
5324 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
5325 SECTION_NAME (section
), section
->sh_info
);
5327 printf (_(" Addr: 0x"));
5328 printf_vma (section
->sh_addr
);
5329 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
5330 (unsigned long) section
->sh_offset
, section
->sh_link
,
5331 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5333 eneed
= ((Elf_External_Verneed
*)
5334 get_data (NULL
, file
, section
->sh_offset
,
5335 section
->sh_size
, _("version need section")));
5339 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5341 Elf_External_Verneed
*entry
;
5342 Elf_Internal_Verneed ent
;
5347 vstart
= ((char *) eneed
) + idx
;
5349 entry
= (Elf_External_Verneed
*) vstart
;
5351 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
5352 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
5353 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
5354 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
5355 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
5357 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
5359 if (dynamic_strings
)
5360 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
5362 printf (_(" File: %lx"), ent
.vn_file
);
5364 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
5366 vstart
+= ent
.vn_aux
;
5368 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
5370 Elf_External_Vernaux
*eaux
;
5371 Elf_Internal_Vernaux aux
;
5373 eaux
= (Elf_External_Vernaux
*) vstart
;
5375 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
5376 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
5377 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
5378 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
5379 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
5381 if (dynamic_strings
)
5382 printf (_(" %#06x: Name: %s"),
5383 isum
, dynamic_strings
+ aux
.vna_name
);
5385 printf (_(" %#06x: Name index: %lx"),
5386 isum
, aux
.vna_name
);
5388 printf (_(" Flags: %s Version: %d\n"),
5389 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
5391 isum
+= aux
.vna_next
;
5392 vstart
+= aux
.vna_next
;
5402 case SHT_GNU_versym
:
5404 Elf_Internal_Shdr
*link_section
;
5407 unsigned char *edata
;
5408 unsigned short *data
;
5410 Elf_Internal_Sym
*symbols
;
5411 Elf_Internal_Shdr
*string_sec
;
5413 link_section
= SECTION_HEADER (section
->sh_link
);
5414 total
= section
->sh_size
/ section
->sh_entsize
;
5418 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
5420 string_sec
= SECTION_HEADER (link_section
->sh_link
);
5422 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5423 string_sec
->sh_size
,
5424 _("version string table"));
5428 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
5429 SECTION_NAME (section
), total
);
5431 printf (_(" Addr: "));
5432 printf_vma (section
->sh_addr
);
5433 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5434 (unsigned long) section
->sh_offset
, section
->sh_link
,
5435 SECTION_NAME (link_section
));
5439 get_data (NULL
, file
,
5440 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] - loadaddr
,
5441 total
* sizeof (short), _("version symbol data")));
5448 data
= (unsigned short *) malloc (total
* sizeof (short));
5450 for (cnt
= total
; cnt
--;)
5451 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
5456 for (cnt
= 0; cnt
< total
; cnt
+= 4)
5459 int check_def
, check_need
;
5462 printf (" %03x:", cnt
);
5464 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
5465 switch (data
[cnt
+ j
])
5468 fputs (_(" 0 (*local*) "), stdout
);
5472 fputs (_(" 1 (*global*) "), stdout
);
5476 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
5477 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
5481 if (SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
5484 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
5491 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
5493 Elf_Internal_Verneed ivn
;
5494 unsigned long offset
;
5496 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5501 Elf_Internal_Vernaux ivna
;
5502 Elf_External_Verneed evn
;
5503 Elf_External_Vernaux evna
;
5504 unsigned long a_off
;
5506 get_data (&evn
, file
, offset
, sizeof (evn
),
5509 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5510 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5512 a_off
= offset
+ ivn
.vn_aux
;
5516 get_data (&evna
, file
, a_off
, sizeof (evna
),
5517 _("version need aux (2)"));
5519 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5520 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5522 a_off
+= ivna
.vna_next
;
5524 while (ivna
.vna_other
!= data
[cnt
+ j
]
5525 && ivna
.vna_next
!= 0);
5527 if (ivna
.vna_other
== data
[cnt
+ j
])
5529 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5531 name
= strtab
+ ivna
.vna_name
;
5532 nn
+= printf ("(%s%-*s",
5534 12 - (int) strlen (name
),
5540 offset
+= ivn
.vn_next
;
5542 while (ivn
.vn_next
);
5545 if (check_def
&& data
[cnt
+ j
] != 0x8001
5546 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5548 Elf_Internal_Verdef ivd
;
5549 Elf_External_Verdef evd
;
5550 unsigned long offset
;
5552 offset
= (version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
5557 get_data (&evd
, file
, offset
, sizeof (evd
),
5560 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
5561 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
5563 offset
+= ivd
.vd_next
;
5565 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
5566 && ivd
.vd_next
!= 0);
5568 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
5570 Elf_External_Verdaux evda
;
5571 Elf_Internal_Verdaux ivda
;
5573 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
5575 get_data (&evda
, file
,
5576 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
5577 sizeof (evda
), _("version def aux"));
5579 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
5581 name
= strtab
+ ivda
.vda_name
;
5582 nn
+= printf ("(%s%-*s",
5584 12 - (int) strlen (name
),
5590 printf ("%*c", 18 - nn
, ' ');
5608 printf (_("\nNo version information found in this file.\n"));
5614 get_symbol_binding (binding
)
5615 unsigned int binding
;
5617 static char buff
[32];
5621 case STB_LOCAL
: return "LOCAL";
5622 case STB_GLOBAL
: return "GLOBAL";
5623 case STB_WEAK
: return "WEAK";
5625 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
5626 sprintf (buff
, _("<processor specific>: %d"), binding
);
5627 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
5628 sprintf (buff
, _("<OS specific>: %d"), binding
);
5630 sprintf (buff
, _("<unknown>: %d"), binding
);
5636 get_symbol_type (type
)
5639 static char buff
[32];
5643 case STT_NOTYPE
: return "NOTYPE";
5644 case STT_OBJECT
: return "OBJECT";
5645 case STT_FUNC
: return "FUNC";
5646 case STT_SECTION
: return "SECTION";
5647 case STT_FILE
: return "FILE";
5648 case STT_COMMON
: return "COMMON";
5649 case STT_TLS
: return "TLS";
5651 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
5653 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
5654 return "THUMB_FUNC";
5656 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
5659 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
5660 return "PARISC_MILLI";
5662 sprintf (buff
, _("<processor specific>: %d"), type
);
5664 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
5666 if (elf_header
.e_machine
== EM_PARISC
)
5668 if (type
== STT_HP_OPAQUE
)
5670 if (type
== STT_HP_STUB
)
5674 sprintf (buff
, _("<OS specific>: %d"), type
);
5677 sprintf (buff
, _("<unknown>: %d"), type
);
5683 get_symbol_visibility (visibility
)
5684 unsigned int visibility
;
5688 case STV_DEFAULT
: return "DEFAULT";
5689 case STV_INTERNAL
: return "INTERNAL";
5690 case STV_HIDDEN
: return "HIDDEN";
5691 case STV_PROTECTED
: return "PROTECTED";
5697 get_symbol_index_type (type
)
5700 static char buff
[32];
5704 case SHN_UNDEF
: return "UND";
5705 case SHN_ABS
: return "ABS";
5706 case SHN_COMMON
: return "COM";
5708 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
5709 sprintf (buff
, "PRC[0x%04x]", type
);
5710 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
5711 sprintf (buff
, "OS [0x%04x]", type
);
5712 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
5713 sprintf (buff
, "RSV[0x%04x]", type
);
5715 sprintf (buff
, "%3d", type
);
5723 get_dynamic_data (file
, number
)
5725 unsigned int number
;
5727 unsigned char *e_data
;
5730 e_data
= (unsigned char *) malloc (number
* 4);
5734 error (_("Out of memory\n"));
5738 if (fread (e_data
, 4, number
, file
) != number
)
5740 error (_("Unable to read in dynamic data\n"));
5744 i_data
= (int *) malloc (number
* sizeof (*i_data
));
5748 error (_("Out of memory\n"));
5754 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
5761 /* Dump the symbol table. */
5763 process_symbol_table (file
)
5766 Elf_Internal_Shdr
*section
;
5767 unsigned char nb
[4];
5768 unsigned char nc
[4];
5771 int *buckets
= NULL
;
5774 if (! do_syms
&& !do_histogram
)
5777 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
5780 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
5782 error (_("Unable to seek to start of dynamic information"));
5786 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
5788 error (_("Failed to read in number of buckets\n"));
5792 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
5794 error (_("Failed to read in number of chains\n"));
5798 nbuckets
= byte_get (nb
, 4);
5799 nchains
= byte_get (nc
, 4);
5801 buckets
= get_dynamic_data (file
, nbuckets
);
5802 chains
= get_dynamic_data (file
, nchains
);
5804 if (buckets
== NULL
|| chains
== NULL
)
5809 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
5814 printf (_("\nSymbol table for image:\n"));
5816 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5818 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5820 for (hn
= 0; hn
< nbuckets
; hn
++)
5825 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
5827 Elf_Internal_Sym
*psym
;
5829 psym
= dynamic_symbols
+ si
;
5831 printf (" %3d %3d: ", si
, hn
);
5832 print_vma (psym
->st_value
, LONG_HEX
);
5834 print_vma (psym
->st_size
, DEC_5
);
5836 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5837 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5838 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5839 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
5840 print_symbol (25, dynamic_strings
+ psym
->st_name
);
5845 else if (do_syms
&& !do_using_dynamic
)
5849 for (i
= 0, section
= section_headers
;
5850 i
< elf_header
.e_shnum
;
5855 Elf_Internal_Sym
*symtab
;
5856 Elf_Internal_Sym
*psym
;
5859 if ( section
->sh_type
!= SHT_SYMTAB
5860 && section
->sh_type
!= SHT_DYNSYM
)
5863 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5864 SECTION_NAME (section
),
5865 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
5867 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5869 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5871 symtab
= GET_ELF_SYMBOLS (file
, section
);
5875 if (section
->sh_link
== elf_header
.e_shstrndx
)
5876 strtab
= string_table
;
5879 Elf_Internal_Shdr
*string_sec
;
5881 string_sec
= SECTION_HEADER (section
->sh_link
);
5883 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5884 string_sec
->sh_size
,
5888 for (si
= 0, psym
= symtab
;
5889 si
< section
->sh_size
/ section
->sh_entsize
;
5892 printf ("%6d: ", si
);
5893 print_vma (psym
->st_value
, LONG_HEX
);
5895 print_vma (psym
->st_size
, DEC_5
);
5896 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5897 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5898 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5899 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
5900 print_symbol (25, strtab
+ psym
->st_name
);
5902 if (section
->sh_type
== SHT_DYNSYM
&&
5903 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
5905 unsigned char data
[2];
5906 unsigned short vers_data
;
5907 unsigned long offset
;
5911 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
5914 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
5915 sizeof (data
), _("version data"));
5917 vers_data
= byte_get (data
, 2);
5919 is_nobits
= (SECTION_HEADER (psym
->st_shndx
)->sh_type
5922 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
5924 if ((vers_data
& 0x8000) || vers_data
> 1)
5926 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5927 && (is_nobits
|| ! check_def
))
5929 Elf_External_Verneed evn
;
5930 Elf_Internal_Verneed ivn
;
5931 Elf_Internal_Vernaux ivna
;
5933 /* We must test both. */
5934 offset
= (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5939 unsigned long vna_off
;
5941 get_data (&evn
, file
, offset
, sizeof (evn
),
5944 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5945 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5947 vna_off
= offset
+ ivn
.vn_aux
;
5951 Elf_External_Vernaux evna
;
5953 get_data (&evna
, file
, vna_off
,
5955 _("version need aux (3)"));
5957 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5958 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5959 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5961 vna_off
+= ivna
.vna_next
;
5963 while (ivna
.vna_other
!= vers_data
5964 && ivna
.vna_next
!= 0);
5966 if (ivna
.vna_other
== vers_data
)
5969 offset
+= ivn
.vn_next
;
5971 while (ivn
.vn_next
!= 0);
5973 if (ivna
.vna_other
== vers_data
)
5976 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
5979 else if (! is_nobits
)
5980 error (_("bad dynamic symbol"));
5987 if (vers_data
!= 0x8001
5988 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5990 Elf_Internal_Verdef ivd
;
5991 Elf_Internal_Verdaux ivda
;
5992 Elf_External_Verdaux evda
;
5993 unsigned long offset
;
5996 = (version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
6001 Elf_External_Verdef evd
;
6003 get_data (&evd
, file
, offset
, sizeof (evd
),
6006 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6007 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6008 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6010 offset
+= ivd
.vd_next
;
6012 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
6013 && ivd
.vd_next
!= 0);
6015 offset
-= ivd
.vd_next
;
6016 offset
+= ivd
.vd_aux
;
6018 get_data (&evda
, file
, offset
, sizeof (evda
),
6019 _("version def aux"));
6021 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6023 if (psym
->st_name
!= ivda
.vda_name
)
6024 printf ((vers_data
& 0x8000)
6026 strtab
+ ivda
.vda_name
);
6036 if (strtab
!= string_table
)
6042 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
6044 if (do_histogram
&& buckets
!= NULL
)
6051 int nzero_counts
= 0;
6054 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
6056 printf (_(" Length Number %% of total Coverage\n"));
6058 lengths
= (int *) calloc (nbuckets
, sizeof (int));
6059 if (lengths
== NULL
)
6061 error (_("Out of memory"));
6064 for (hn
= 0; hn
< nbuckets
; ++hn
)
6069 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
6072 if (maxlength
< ++lengths
[hn
])
6077 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
6080 error (_("Out of memory"));
6084 for (hn
= 0; hn
< nbuckets
; ++hn
)
6085 ++counts
[lengths
[hn
]];
6089 printf (" 0 %-10d (%5.1f%%)\n",
6090 counts
[0], (counts
[0] * 100.0) / nbuckets
);
6091 for (si
= 1; si
<= maxlength
; ++si
)
6093 nzero_counts
+= counts
[si
] * si
;
6094 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
6095 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
6096 (nzero_counts
* 100.0) / nsyms
);
6104 if (buckets
!= NULL
)
6114 process_syminfo (file
)
6115 FILE *file ATTRIBUTE_UNUSED
;
6119 if (dynamic_syminfo
== NULL
6121 /* No syminfo, this is ok. */
6124 /* There better should be a dynamic symbol section. */
6125 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
6129 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
6130 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
6132 printf (_(" Num: Name BoundTo Flags\n"));
6133 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
6135 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
6137 printf ("%4d: ", i
);
6138 print_symbol (30, dynamic_strings
+ dynamic_symbols
[i
].st_name
);
6141 switch (dynamic_syminfo
[i
].si_boundto
)
6143 case SYMINFO_BT_SELF
:
6144 fputs ("SELF ", stdout
);
6146 case SYMINFO_BT_PARENT
:
6147 fputs ("PARENT ", stdout
);
6150 if (dynamic_syminfo
[i
].si_boundto
> 0
6151 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
6156 [dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
6160 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
6164 if (flags
& SYMINFO_FLG_DIRECT
)
6166 if (flags
& SYMINFO_FLG_PASSTHRU
)
6167 printf (" PASSTHRU");
6168 if (flags
& SYMINFO_FLG_COPY
)
6170 if (flags
& SYMINFO_FLG_LAZYLOAD
)
6171 printf (" LAZYLOAD");
6179 #ifdef SUPPORT_DISASSEMBLY
6181 disassemble_section (section
, file
)
6182 Elf_Internal_Shdr
*section
;
6185 printf (_("\nAssembly dump of section %s\n"),
6186 SECTION_NAME (section
));
6188 /* XXX -- to be done --- XXX */
6195 dump_section (section
, file
)
6196 Elf_Internal_Shdr
*section
;
6199 bfd_size_type bytes
;
6201 unsigned char *data
;
6202 unsigned char *start
;
6204 bytes
= section
->sh_size
;
6208 printf (_("\nSection '%s' has no data to dump.\n"),
6209 SECTION_NAME (section
));
6213 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
6215 addr
= section
->sh_addr
;
6217 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, bytes
,
6230 lbytes
= (bytes
> 16 ? 16 : bytes
);
6232 printf (" 0x%8.8lx ", (unsigned long) addr
);
6234 switch (elf_header
.e_ident
[EI_DATA
])
6238 for (j
= 15; j
>= 0; j
--)
6241 printf ("%2.2x", data
[j
]);
6251 for (j
= 0; j
< 16; j
++)
6254 printf ("%2.2x", data
[j
]);
6264 for (j
= 0; j
< lbytes
; j
++)
6267 if (k
>= ' ' && k
< 0x80)
6286 static unsigned long int
6287 read_leb128 (data
, length_return
, sign
)
6288 unsigned char *data
;
6292 unsigned long int result
= 0;
6293 unsigned int num_read
= 0;
6302 result
|= (byte
& 0x7f) << shift
;
6307 while (byte
& 0x80);
6309 if (length_return
!= NULL
)
6310 *length_return
= num_read
;
6312 if (sign
&& (shift
< 32) && (byte
& 0x40))
6313 result
|= -1 << shift
;
6318 typedef struct State_Machine_Registers
6320 unsigned long address
;
6323 unsigned int column
;
6327 /* This variable hold the number of the last entry seen
6328 in the File Table. */
6329 unsigned int last_file_entry
;
6332 static SMR state_machine_regs
;
6335 reset_state_machine (is_stmt
)
6338 state_machine_regs
.address
= 0;
6339 state_machine_regs
.file
= 1;
6340 state_machine_regs
.line
= 1;
6341 state_machine_regs
.column
= 0;
6342 state_machine_regs
.is_stmt
= is_stmt
;
6343 state_machine_regs
.basic_block
= 0;
6344 state_machine_regs
.end_sequence
= 0;
6345 state_machine_regs
.last_file_entry
= 0;
6348 /* Handled an extend line op. Returns true if this is the end
6351 process_extended_line_op (data
, is_stmt
, pointer_size
)
6352 unsigned char *data
;
6356 unsigned char op_code
;
6359 unsigned char *name
;
6362 len
= read_leb128 (data
, & bytes_read
, 0);
6367 warn (_("badly formed extended line op encountered!\n"));
6374 printf (_(" Extended opcode %d: "), op_code
);
6378 case DW_LNE_end_sequence
:
6379 printf (_("End of Sequence\n\n"));
6380 reset_state_machine (is_stmt
);
6383 case DW_LNE_set_address
:
6384 adr
= byte_get (data
, pointer_size
);
6385 printf (_("set Address to 0x%lx\n"), adr
);
6386 state_machine_regs
.address
= adr
;
6389 case DW_LNE_define_file
:
6390 printf (_(" define new File Table entry\n"));
6391 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6393 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6395 data
+= strlen ((char *) data
) + 1;
6396 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6398 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6400 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6401 printf (_("%s\n\n"), name
);
6405 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
6412 /* Size of pointers in the .debug_line section. This information is not
6413 really present in that section. It's obtained before dumping the debug
6414 sections by doing some pre-scan of the .debug_info section. */
6415 static int debug_line_pointer_size
= 4;
6418 display_debug_lines (section
, start
, file
)
6419 Elf_Internal_Shdr
*section
;
6420 unsigned char * start
;
6421 FILE *file ATTRIBUTE_UNUSED
;
6423 DWARF2_External_LineInfo
*external
;
6424 DWARF2_Internal_LineInfo info
;
6425 unsigned char *standard_opcodes
;
6426 unsigned char *data
= start
;
6427 unsigned char *end
= start
+ section
->sh_size
;
6428 unsigned char *end_of_sequence
;
6431 printf (_("\nDump of debug contents of section %s:\n\n"),
6432 SECTION_NAME (section
));
6436 external
= (DWARF2_External_LineInfo
*) data
;
6438 /* Check the length of the block. */
6439 info
.li_length
= BYTE_GET (external
->li_length
);
6441 if (info
.li_length
== 0xffffffff)
6443 warn (_("64-bit DWARF line info is not supported yet.\n"));
6447 if (info
.li_length
+ sizeof (external
->li_length
) > section
->sh_size
)
6450 (_("The line info appears to be corrupt - the section is too small\n"));
6454 /* Check its version number. */
6455 info
.li_version
= BYTE_GET (external
->li_version
);
6456 if (info
.li_version
!= 2)
6458 warn (_("Only DWARF version 2 line info is currently supported.\n"));
6462 info
.li_prologue_length
= BYTE_GET (external
->li_prologue_length
);
6463 info
.li_min_insn_length
= BYTE_GET (external
->li_min_insn_length
);
6464 info
.li_default_is_stmt
= BYTE_GET (external
->li_default_is_stmt
);
6465 info
.li_line_base
= BYTE_GET (external
->li_line_base
);
6466 info
.li_line_range
= BYTE_GET (external
->li_line_range
);
6467 info
.li_opcode_base
= BYTE_GET (external
->li_opcode_base
);
6469 /* Sign extend the line base field. */
6470 info
.li_line_base
<<= 24;
6471 info
.li_line_base
>>= 24;
6473 printf (_(" Length: %ld\n"), info
.li_length
);
6474 printf (_(" DWARF Version: %d\n"), info
.li_version
);
6475 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
6476 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
6477 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
6478 printf (_(" Line Base: %d\n"), info
.li_line_base
);
6479 printf (_(" Line Range: %d\n"), info
.li_line_range
);
6480 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
6482 end_of_sequence
= data
+ info
.li_length
+ sizeof (external
->li_length
);
6484 reset_state_machine (info
.li_default_is_stmt
);
6486 /* Display the contents of the Opcodes table. */
6487 standard_opcodes
= data
+ sizeof (*external
);
6489 printf (_("\n Opcodes:\n"));
6491 for (i
= 1; i
< info
.li_opcode_base
; i
++)
6492 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
6494 /* Display the contents of the Directory table. */
6495 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
6498 printf (_("\n The Directory Table is empty.\n"));
6501 printf (_("\n The Directory Table:\n"));
6505 printf (_(" %s\n"), data
);
6507 data
+= strlen ((char *) data
) + 1;
6511 /* Skip the NUL at the end of the table. */
6514 /* Display the contents of the File Name table. */
6516 printf (_("\n The File Name Table is empty.\n"));
6519 printf (_("\n The File Name Table:\n"));
6520 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6524 unsigned char *name
;
6527 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6530 data
+= strlen ((char *) data
) + 1;
6532 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6534 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6536 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6538 printf (_("%s\n"), name
);
6542 /* Skip the NUL at the end of the table. */
6545 /* Now display the statements. */
6546 printf (_("\n Line Number Statements:\n"));
6549 while (data
< end_of_sequence
)
6551 unsigned char op_code
;
6557 if (op_code
>= info
.li_opcode_base
)
6559 op_code
-= info
.li_opcode_base
;
6560 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
6561 state_machine_regs
.address
+= adv
;
6562 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6563 op_code
, adv
, state_machine_regs
.address
);
6564 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
6565 state_machine_regs
.line
+= adv
;
6566 printf (_(" and Line by %d to %d\n"),
6567 adv
, state_machine_regs
.line
);
6569 else switch (op_code
)
6571 case DW_LNS_extended_op
:
6572 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
6573 debug_line_pointer_size
);
6577 printf (_(" Copy\n"));
6580 case DW_LNS_advance_pc
:
6581 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
6583 state_machine_regs
.address
+= adv
;
6584 printf (_(" Advance PC by %d to %lx\n"), adv
,
6585 state_machine_regs
.address
);
6588 case DW_LNS_advance_line
:
6589 adv
= read_leb128 (data
, & bytes_read
, 1);
6591 state_machine_regs
.line
+= adv
;
6592 printf (_(" Advance Line by %d to %d\n"), adv
,
6593 state_machine_regs
.line
);
6596 case DW_LNS_set_file
:
6597 adv
= read_leb128 (data
, & bytes_read
, 0);
6599 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6601 state_machine_regs
.file
= adv
;
6604 case DW_LNS_set_column
:
6605 adv
= read_leb128 (data
, & bytes_read
, 0);
6607 printf (_(" Set column to %d\n"), adv
);
6608 state_machine_regs
.column
= adv
;
6611 case DW_LNS_negate_stmt
:
6612 adv
= state_machine_regs
.is_stmt
;
6614 printf (_(" Set is_stmt to %d\n"), adv
);
6615 state_machine_regs
.is_stmt
= adv
;
6618 case DW_LNS_set_basic_block
:
6619 printf (_(" Set basic block\n"));
6620 state_machine_regs
.basic_block
= 1;
6623 case DW_LNS_const_add_pc
:
6624 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
6625 * info
.li_min_insn_length
);
6626 state_machine_regs
.address
+= adv
;
6627 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
6628 state_machine_regs
.address
);
6631 case DW_LNS_fixed_advance_pc
:
6632 adv
= byte_get (data
, 2);
6634 state_machine_regs
.address
+= adv
;
6635 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6636 adv
, state_machine_regs
.address
);
6639 case DW_LNS_set_prologue_end
:
6640 printf (_(" Set prologue_end to true\n"));
6643 case DW_LNS_set_epilogue_begin
:
6644 printf (_(" Set epilogue_begin to true\n"));
6647 case DW_LNS_set_isa
:
6648 adv
= read_leb128 (data
, & bytes_read
, 0);
6650 printf (_(" Set ISA to %d\n"), adv
);
6654 printf (_(" Unknown opcode %d with operands: "), op_code
);
6657 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
6659 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
6660 i
== 1 ? "" : ", ");
6675 display_debug_pubnames (section
, start
, file
)
6676 Elf_Internal_Shdr
*section
;
6677 unsigned char *start
;
6678 FILE *file ATTRIBUTE_UNUSED
;
6680 DWARF2_External_PubNames
*external
;
6681 DWARF2_Internal_PubNames pubnames
;
6684 end
= start
+ section
->sh_size
;
6686 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6690 unsigned char *data
;
6691 unsigned long offset
;
6693 external
= (DWARF2_External_PubNames
*) start
;
6695 pubnames
.pn_length
= BYTE_GET (external
->pn_length
);
6696 pubnames
.pn_version
= BYTE_GET (external
->pn_version
);
6697 pubnames
.pn_offset
= BYTE_GET (external
->pn_offset
);
6698 pubnames
.pn_size
= BYTE_GET (external
->pn_size
);
6700 data
= start
+ sizeof (*external
);
6701 start
+= pubnames
.pn_length
+ sizeof (external
->pn_length
);
6703 if (pubnames
.pn_length
== 0xffffffff)
6705 warn (_("64-bit DWARF pubnames are not supported yet.\n"));
6709 if (pubnames
.pn_version
!= 2)
6711 static int warned
= 0;
6715 warn (_("Only DWARF 2 pubnames are currently supported\n"));
6722 printf (_(" Length: %ld\n"),
6723 pubnames
.pn_length
);
6724 printf (_(" Version: %d\n"),
6725 pubnames
.pn_version
);
6726 printf (_(" Offset into .debug_info section: %ld\n"),
6727 pubnames
.pn_offset
);
6728 printf (_(" Size of area in .debug_info section: %ld\n"),
6731 printf (_("\n Offset\tName\n"));
6735 offset
= byte_get (data
, 4);
6740 printf (" %ld\t\t%s\n", offset
, data
);
6741 data
+= strlen ((char *) data
) + 1;
6744 while (offset
!= 0);
6757 case DW_TAG_padding
: return "DW_TAG_padding";
6758 case DW_TAG_array_type
: return "DW_TAG_array_type";
6759 case DW_TAG_class_type
: return "DW_TAG_class_type";
6760 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
6761 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
6762 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
6763 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
6764 case DW_TAG_label
: return "DW_TAG_label";
6765 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
6766 case DW_TAG_member
: return "DW_TAG_member";
6767 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
6768 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
6769 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
6770 case DW_TAG_string_type
: return "DW_TAG_string_type";
6771 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
6772 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
6773 case DW_TAG_typedef
: return "DW_TAG_typedef";
6774 case DW_TAG_union_type
: return "DW_TAG_union_type";
6775 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
6776 case DW_TAG_variant
: return "DW_TAG_variant";
6777 case DW_TAG_common_block
: return "DW_TAG_common_block";
6778 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
6779 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
6780 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
6781 case DW_TAG_module
: return "DW_TAG_module";
6782 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
6783 case DW_TAG_set_type
: return "DW_TAG_set_type";
6784 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
6785 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
6786 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
6787 case DW_TAG_base_type
: return "DW_TAG_base_type";
6788 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
6789 case DW_TAG_const_type
: return "DW_TAG_const_type";
6790 case DW_TAG_constant
: return "DW_TAG_constant";
6791 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
6792 case DW_TAG_file_type
: return "DW_TAG_file_type";
6793 case DW_TAG_friend
: return "DW_TAG_friend";
6794 case DW_TAG_namelist
: return "DW_TAG_namelist";
6795 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
6796 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
6797 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
6798 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
6799 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
6800 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
6801 case DW_TAG_try_block
: return "DW_TAG_try_block";
6802 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
6803 case DW_TAG_variable
: return "DW_TAG_variable";
6804 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
6805 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
6806 case DW_TAG_format_label
: return "DW_TAG_format_label";
6807 case DW_TAG_function_template
: return "DW_TAG_function_template";
6808 case DW_TAG_class_template
: return "DW_TAG_class_template";
6809 /* DWARF 2.1 values. */
6810 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
6811 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
6812 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
6813 case DW_TAG_namespace
: return "DW_TAG_namespace";
6814 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
6815 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
6816 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
6817 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
6819 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
6820 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
6821 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
6824 static char buffer
[100];
6826 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
6833 get_AT_name (attribute
)
6834 unsigned long attribute
;
6838 case DW_AT_sibling
: return "DW_AT_sibling";
6839 case DW_AT_location
: return "DW_AT_location";
6840 case DW_AT_name
: return "DW_AT_name";
6841 case DW_AT_ordering
: return "DW_AT_ordering";
6842 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
6843 case DW_AT_byte_size
: return "DW_AT_byte_size";
6844 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
6845 case DW_AT_bit_size
: return "DW_AT_bit_size";
6846 case DW_AT_element_list
: return "DW_AT_element_list";
6847 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
6848 case DW_AT_low_pc
: return "DW_AT_low_pc";
6849 case DW_AT_high_pc
: return "DW_AT_high_pc";
6850 case DW_AT_language
: return "DW_AT_language";
6851 case DW_AT_member
: return "DW_AT_member";
6852 case DW_AT_discr
: return "DW_AT_discr";
6853 case DW_AT_discr_value
: return "DW_AT_discr_value";
6854 case DW_AT_visibility
: return "DW_AT_visibility";
6855 case DW_AT_import
: return "DW_AT_import";
6856 case DW_AT_string_length
: return "DW_AT_string_length";
6857 case DW_AT_common_reference
: return "DW_AT_common_reference";
6858 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
6859 case DW_AT_const_value
: return "DW_AT_const_value";
6860 case DW_AT_containing_type
: return "DW_AT_containing_type";
6861 case DW_AT_default_value
: return "DW_AT_default_value";
6862 case DW_AT_inline
: return "DW_AT_inline";
6863 case DW_AT_is_optional
: return "DW_AT_is_optional";
6864 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
6865 case DW_AT_producer
: return "DW_AT_producer";
6866 case DW_AT_prototyped
: return "DW_AT_prototyped";
6867 case DW_AT_return_addr
: return "DW_AT_return_addr";
6868 case DW_AT_start_scope
: return "DW_AT_start_scope";
6869 case DW_AT_stride_size
: return "DW_AT_stride_size";
6870 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
6871 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
6872 case DW_AT_accessibility
: return "DW_AT_accessibility";
6873 case DW_AT_address_class
: return "DW_AT_address_class";
6874 case DW_AT_artificial
: return "DW_AT_artificial";
6875 case DW_AT_base_types
: return "DW_AT_base_types";
6876 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
6877 case DW_AT_count
: return "DW_AT_count";
6878 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
6879 case DW_AT_decl_column
: return "DW_AT_decl_column";
6880 case DW_AT_decl_file
: return "DW_AT_decl_file";
6881 case DW_AT_decl_line
: return "DW_AT_decl_line";
6882 case DW_AT_declaration
: return "DW_AT_declaration";
6883 case DW_AT_discr_list
: return "DW_AT_discr_list";
6884 case DW_AT_encoding
: return "DW_AT_encoding";
6885 case DW_AT_external
: return "DW_AT_external";
6886 case DW_AT_frame_base
: return "DW_AT_frame_base";
6887 case DW_AT_friend
: return "DW_AT_friend";
6888 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
6889 case DW_AT_macro_info
: return "DW_AT_macro_info";
6890 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
6891 case DW_AT_priority
: return "DW_AT_priority";
6892 case DW_AT_segment
: return "DW_AT_segment";
6893 case DW_AT_specification
: return "DW_AT_specification";
6894 case DW_AT_static_link
: return "DW_AT_static_link";
6895 case DW_AT_type
: return "DW_AT_type";
6896 case DW_AT_use_location
: return "DW_AT_use_location";
6897 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
6898 case DW_AT_virtuality
: return "DW_AT_virtuality";
6899 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
6900 /* DWARF 2.1 values. */
6901 case DW_AT_allocated
: return "DW_AT_allocated";
6902 case DW_AT_associated
: return "DW_AT_associated";
6903 case DW_AT_data_location
: return "DW_AT_data_location";
6904 case DW_AT_stride
: return "DW_AT_stride";
6905 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
6906 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
6907 case DW_AT_extension
: return "DW_AT_extension";
6908 case DW_AT_ranges
: return "DW_AT_ranges";
6909 case DW_AT_trampoline
: return "DW_AT_trampoline";
6910 case DW_AT_call_column
: return "DW_AT_call_column";
6911 case DW_AT_call_file
: return "DW_AT_call_file";
6912 case DW_AT_call_line
: return "DW_AT_call_line";
6913 /* SGI/MIPS extensions. */
6914 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
6915 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
6916 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
6917 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
6918 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
6919 case DW_AT_MIPS_software_pipeline_depth
:
6920 return "DW_AT_MIPS_software_pipeline_depth";
6921 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
6922 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
6923 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
6924 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
6925 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
6926 /* GNU extensions. */
6927 case DW_AT_sf_names
: return "DW_AT_sf_names";
6928 case DW_AT_src_info
: return "DW_AT_src_info";
6929 case DW_AT_mac_info
: return "DW_AT_mac_info";
6930 case DW_AT_src_coords
: return "DW_AT_src_coords";
6931 case DW_AT_body_begin
: return "DW_AT_body_begin";
6932 case DW_AT_body_end
: return "DW_AT_body_end";
6933 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
6934 /* UPC extension. */
6935 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
6938 static char buffer
[100];
6940 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
6947 get_FORM_name (form
)
6952 case DW_FORM_addr
: return "DW_FORM_addr";
6953 case DW_FORM_block2
: return "DW_FORM_block2";
6954 case DW_FORM_block4
: return "DW_FORM_block4";
6955 case DW_FORM_data2
: return "DW_FORM_data2";
6956 case DW_FORM_data4
: return "DW_FORM_data4";
6957 case DW_FORM_data8
: return "DW_FORM_data8";
6958 case DW_FORM_string
: return "DW_FORM_string";
6959 case DW_FORM_block
: return "DW_FORM_block";
6960 case DW_FORM_block1
: return "DW_FORM_block1";
6961 case DW_FORM_data1
: return "DW_FORM_data1";
6962 case DW_FORM_flag
: return "DW_FORM_flag";
6963 case DW_FORM_sdata
: return "DW_FORM_sdata";
6964 case DW_FORM_strp
: return "DW_FORM_strp";
6965 case DW_FORM_udata
: return "DW_FORM_udata";
6966 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
6967 case DW_FORM_ref1
: return "DW_FORM_ref1";
6968 case DW_FORM_ref2
: return "DW_FORM_ref2";
6969 case DW_FORM_ref4
: return "DW_FORM_ref4";
6970 case DW_FORM_ref8
: return "DW_FORM_ref8";
6971 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
6972 case DW_FORM_indirect
: return "DW_FORM_indirect";
6975 static char buffer
[100];
6977 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
6983 /* FIXME: There are better and more effiecint ways to handle
6984 these structures. For now though, I just want something that
6985 is simple to implement. */
6986 typedef struct abbrev_attr
6988 unsigned long attribute
;
6990 struct abbrev_attr
*next
;
6994 typedef struct abbrev_entry
6996 unsigned long entry
;
6999 struct abbrev_attr
*first_attr
;
7000 struct abbrev_attr
*last_attr
;
7001 struct abbrev_entry
*next
;
7005 static abbrev_entry
*first_abbrev
= NULL
;
7006 static abbrev_entry
*last_abbrev
= NULL
;
7011 abbrev_entry
*abbrev
;
7013 for (abbrev
= first_abbrev
; abbrev
;)
7015 abbrev_entry
*next
= abbrev
->next
;
7018 for (attr
= abbrev
->first_attr
; attr
;)
7020 abbrev_attr
*next
= attr
->next
;
7030 last_abbrev
= first_abbrev
= NULL
;
7034 add_abbrev (number
, tag
, children
)
7035 unsigned long number
;
7039 abbrev_entry
*entry
;
7041 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
7047 entry
->entry
= number
;
7049 entry
->children
= children
;
7050 entry
->first_attr
= NULL
;
7051 entry
->last_attr
= NULL
;
7054 if (first_abbrev
== NULL
)
7055 first_abbrev
= entry
;
7057 last_abbrev
->next
= entry
;
7059 last_abbrev
= entry
;
7063 add_abbrev_attr (attribute
, form
)
7064 unsigned long attribute
;
7069 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
7075 attr
->attribute
= attribute
;
7079 if (last_abbrev
->first_attr
== NULL
)
7080 last_abbrev
->first_attr
= attr
;
7082 last_abbrev
->last_attr
->next
= attr
;
7084 last_abbrev
->last_attr
= attr
;
7087 /* Processes the (partial) contents of a .debug_abbrev section.
7088 Returns NULL if the end of the section was encountered.
7089 Returns the address after the last byte read if the end of
7090 an abbreviation set was found. */
7092 static unsigned char *
7093 process_abbrev_section (start
, end
)
7094 unsigned char *start
;
7097 if (first_abbrev
!= NULL
)
7103 unsigned long entry
;
7105 unsigned long attribute
;
7108 entry
= read_leb128 (start
, & bytes_read
, 0);
7109 start
+= bytes_read
;
7111 /* A single zero is supposed to end the section according
7112 to the standard. If there's more, then signal that to
7115 return start
== end
? NULL
: start
;
7117 tag
= read_leb128 (start
, & bytes_read
, 0);
7118 start
+= bytes_read
;
7120 children
= *start
++;
7122 add_abbrev (entry
, tag
, children
);
7128 attribute
= read_leb128 (start
, & bytes_read
, 0);
7129 start
+= bytes_read
;
7131 form
= read_leb128 (start
, & bytes_read
, 0);
7132 start
+= bytes_read
;
7135 add_abbrev_attr (attribute
, form
);
7137 while (attribute
!= 0);
7145 display_debug_macinfo (section
, start
, file
)
7146 Elf_Internal_Shdr
*section
;
7147 unsigned char *start
;
7148 FILE *file ATTRIBUTE_UNUSED
;
7150 unsigned char *end
= start
+ section
->sh_size
;
7151 unsigned char *curr
= start
;
7152 unsigned int bytes_read
;
7153 enum dwarf_macinfo_record_type op
;
7155 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7159 unsigned int lineno
;
7167 case DW_MACINFO_start_file
:
7169 unsigned int filenum
;
7171 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7173 filenum
= read_leb128 (curr
, & bytes_read
, 0);
7176 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno
, filenum
);
7180 case DW_MACINFO_end_file
:
7181 printf (_(" DW_MACINFO_end_file\n"));
7184 case DW_MACINFO_define
:
7185 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7188 curr
+= strlen (string
) + 1;
7189 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno
, string
);
7192 case DW_MACINFO_undef
:
7193 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7196 curr
+= strlen (string
) + 1;
7197 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno
, string
);
7200 case DW_MACINFO_vendor_ext
:
7202 unsigned int constant
;
7204 constant
= read_leb128 (curr
, & bytes_read
, 0);
7207 curr
+= strlen (string
) + 1;
7208 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant
, string
);
7219 display_debug_abbrev (section
, start
, file
)
7220 Elf_Internal_Shdr
*section
;
7221 unsigned char *start
;
7222 FILE *file ATTRIBUTE_UNUSED
;
7224 abbrev_entry
*entry
;
7225 unsigned char *end
= start
+ section
->sh_size
;
7227 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7231 start
= process_abbrev_section (start
, end
);
7233 if (first_abbrev
== NULL
)
7236 printf (_(" Number TAG\n"));
7238 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
7242 printf (_(" %ld %s [%s]\n"),
7244 get_TAG_name (entry
->tag
),
7245 entry
->children
? _("has children") : _("no children"));
7247 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
7249 printf (_(" %-18s %s\n"),
7250 get_AT_name (attr
->attribute
),
7251 get_FORM_name (attr
->form
));
7265 static unsigned char *
7266 display_block (data
, length
)
7267 unsigned char *data
;
7268 unsigned long length
;
7270 printf (_(" %lu byte block: "), length
);
7273 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
7279 decode_location_expression (data
, pointer_size
, length
)
7280 unsigned char * data
;
7281 unsigned int pointer_size
;
7282 unsigned long length
;
7286 unsigned long uvalue
;
7287 unsigned char *end
= data
+ length
;
7296 printf ("DW_OP_addr: %lx",
7297 (unsigned long) byte_get (data
, pointer_size
));
7298 data
+= pointer_size
;
7301 printf ("DW_OP_deref");
7304 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
7307 printf ("DW_OP_const1s: %ld", (long) byte_get (data
++, 1));
7310 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
7314 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
7318 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
7322 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
7326 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
7327 (unsigned long) byte_get (data
+ 4, 4));
7331 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
7332 (long) byte_get (data
+ 4, 4));
7336 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
7340 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
7344 printf ("DW_OP_dup");
7347 printf ("DW_OP_drop");
7350 printf ("DW_OP_over");
7353 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
7356 printf ("DW_OP_swap");
7359 printf ("DW_OP_rot");
7362 printf ("DW_OP_xderef");
7365 printf ("DW_OP_abs");
7368 printf ("DW_OP_and");
7371 printf ("DW_OP_div");
7374 printf ("DW_OP_minus");
7377 printf ("DW_OP_mod");
7380 printf ("DW_OP_mul");
7383 printf ("DW_OP_neg");
7386 printf ("DW_OP_not");
7389 printf ("DW_OP_or");
7392 printf ("DW_OP_plus");
7394 case DW_OP_plus_uconst
:
7395 printf ("DW_OP_plus_uconst: %lu",
7396 read_leb128 (data
, &bytes_read
, 0));
7400 printf ("DW_OP_shl");
7403 printf ("DW_OP_shr");
7406 printf ("DW_OP_shra");
7409 printf ("DW_OP_xor");
7412 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
7416 printf ("DW_OP_eq");
7419 printf ("DW_OP_ge");
7422 printf ("DW_OP_gt");
7425 printf ("DW_OP_le");
7428 printf ("DW_OP_lt");
7431 printf ("DW_OP_ne");
7434 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
7470 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
7505 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
7540 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
7541 read_leb128 (data
, &bytes_read
, 1));
7546 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
7550 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
7554 uvalue
= read_leb128 (data
, &bytes_read
, 0);
7556 printf ("DW_OP_bregx: %lu %ld", uvalue
,
7557 read_leb128 (data
, &bytes_read
, 1));
7561 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
7564 case DW_OP_deref_size
:
7565 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
7567 case DW_OP_xderef_size
:
7568 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
7571 printf ("DW_OP_nop");
7574 /* DWARF 3 extensions. */
7575 case DW_OP_push_object_address
:
7576 printf ("DW_OP_push_object_address");
7579 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2));
7583 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4));
7586 case DW_OP_call_ref
:
7587 printf ("DW_OP_call_ref");
7590 /* GNU extensions. */
7591 case DW_OP_GNU_push_tls_address
:
7592 printf ("DW_OP_GNU_push_tls_address");
7596 if (op
>= DW_OP_lo_user
7597 && op
<= DW_OP_hi_user
)
7598 printf (_("(User defined location op)"));
7600 printf (_("(Unknown location op)"));
7601 /* No way to tell where the next op is, so just bail. */
7605 /* Separate the ops. */
7610 static const char *debug_loc_contents
;
7611 static bfd_vma debug_loc_size
;
7614 load_debug_loc (file
)
7617 Elf_Internal_Shdr
*sec
;
7620 /* If it is already loaded, do nothing. */
7621 if (debug_loc_contents
!= NULL
)
7624 /* Locate the .debug_loc section. */
7625 for (i
= 0, sec
= section_headers
;
7626 i
< elf_header
.e_shnum
;
7628 if (strcmp (SECTION_NAME (sec
), ".debug_loc") == 0)
7631 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7634 debug_loc_size
= sec
->sh_size
;
7636 debug_loc_contents
= ((char *)
7637 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7638 _("debug_loc section data")));
7644 if (debug_loc_contents
== NULL
)
7647 free ((char *) debug_loc_contents
);
7648 debug_loc_contents
= NULL
;
7654 display_debug_loc (section
, start
, file
)
7655 Elf_Internal_Shdr
*section
;
7656 unsigned char *start
;
7657 FILE *file ATTRIBUTE_UNUSED
;
7659 unsigned char *section_end
;
7660 unsigned long bytes
;
7661 unsigned char *section_begin
= start
;
7664 addr
= section
->sh_addr
;
7665 bytes
= section
->sh_size
;
7666 section_end
= start
+ bytes
;
7670 printf (_("\nThe .debug_loc section is empty.\n"));
7674 printf (_("Contents of the .debug_loc section:\n\n"));
7675 printf (_("\n Offset Begin End Expression\n"));
7677 while (start
< section_end
)
7679 unsigned long begin
;
7681 unsigned short length
;
7682 unsigned long offset
;
7684 offset
= start
- section_begin
;
7688 /* Normally, the lists in the debug_loc section are related to a
7689 given compilation unit, and thus, we would use the pointer size
7690 of that compilation unit. However, since we are displaying it
7691 seperately here, we either have to store pointer sizes of all
7692 compilation units, or assume they don't change. We assume,
7693 like the debug_line display, that it doesn't change. */
7694 begin
= byte_get (start
, debug_line_pointer_size
);
7695 start
+= debug_line_pointer_size
;
7696 end
= byte_get (start
, debug_line_pointer_size
);
7697 start
+= debug_line_pointer_size
;
7699 if (begin
== 0 && end
== 0)
7702 /* For now, skip any base address specifiers. */
7703 if (begin
== 0xffffffff)
7709 length
= byte_get (start
, 2);
7712 printf (" %8.8lx %8.8lx %8.8lx (", offset
, begin
, end
);
7713 decode_location_expression (start
, debug_line_pointer_size
, length
);
7723 static const char *debug_str_contents
;
7724 static bfd_vma debug_str_size
;
7727 load_debug_str (file
)
7730 Elf_Internal_Shdr
*sec
;
7733 /* If it is already loaded, do nothing. */
7734 if (debug_str_contents
!= NULL
)
7737 /* Locate the .debug_str section. */
7738 for (i
= 0, sec
= section_headers
;
7739 i
< elf_header
.e_shnum
;
7741 if (strcmp (SECTION_NAME (sec
), ".debug_str") == 0)
7744 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7747 debug_str_size
= sec
->sh_size
;
7749 debug_str_contents
= ((char *)
7750 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7751 _("debug_str section data")));
7757 if (debug_str_contents
== NULL
)
7760 free ((char *) debug_str_contents
);
7761 debug_str_contents
= NULL
;
7766 fetch_indirect_string (offset
)
7767 unsigned long offset
;
7769 if (debug_str_contents
== NULL
)
7770 return _("<no .debug_str section>");
7772 if (offset
> debug_str_size
)
7773 return _("<offset is too big>");
7775 return debug_str_contents
+ offset
;
7779 display_debug_str (section
, start
, file
)
7780 Elf_Internal_Shdr
*section
;
7781 unsigned char *start
;
7782 FILE *file ATTRIBUTE_UNUSED
;
7784 unsigned long bytes
;
7787 addr
= section
->sh_addr
;
7788 bytes
= section
->sh_size
;
7792 printf (_("\nThe .debug_str section is empty.\n"));
7796 printf (_("Contents of the .debug_str section:\n\n"));
7804 lbytes
= (bytes
> 16 ? 16 : bytes
);
7806 printf (" 0x%8.8lx ", (unsigned long) addr
);
7808 for (j
= 0; j
< 16; j
++)
7811 printf ("%2.2x", start
[j
]);
7819 for (j
= 0; j
< lbytes
; j
++)
7822 if (k
>= ' ' && k
< 0x80)
7838 static unsigned char *
7839 read_and_display_attr_value (attribute
, form
, data
, cu_offset
, pointer_size
)
7840 unsigned long attribute
;
7842 unsigned char *data
;
7843 unsigned long cu_offset
;
7844 unsigned long pointer_size
;
7846 unsigned long uvalue
= 0;
7847 unsigned char *block_start
= NULL
;
7855 case DW_FORM_ref_addr
:
7857 uvalue
= byte_get (data
, pointer_size
);
7858 data
+= pointer_size
;
7862 uvalue
= byte_get (data
, /* offset_size */ 4);
7863 data
+= /* offset_size */ 4;
7869 uvalue
= byte_get (data
++, 1);
7874 uvalue
= byte_get (data
, 2);
7880 uvalue
= byte_get (data
, 4);
7885 uvalue
= read_leb128 (data
, & bytes_read
, 1);
7889 case DW_FORM_ref_udata
:
7891 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7895 case DW_FORM_indirect
:
7896 form
= read_leb128 (data
, & bytes_read
, 0);
7898 printf (" %s", get_FORM_name (form
));
7899 return read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
7905 case DW_FORM_ref_addr
:
7906 printf (" <#%lx>", uvalue
);
7912 case DW_FORM_ref_udata
:
7913 printf (" <%lx>", uvalue
+ cu_offset
);
7917 printf (" %#lx", uvalue
);
7925 printf (" %ld", uvalue
);
7930 uvalue
= byte_get (data
, 4);
7931 printf (" %lx", uvalue
);
7932 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
7936 case DW_FORM_string
:
7937 printf (" %s", data
);
7938 data
+= strlen ((char *) data
) + 1;
7942 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7943 block_start
= data
+ bytes_read
;
7944 data
= display_block (block_start
, uvalue
);
7947 case DW_FORM_block1
:
7948 uvalue
= byte_get (data
, 1);
7949 block_start
= data
+ 1;
7950 data
= display_block (block_start
, uvalue
);
7953 case DW_FORM_block2
:
7954 uvalue
= byte_get (data
, 2);
7955 block_start
= data
+ 2;
7956 data
= display_block (block_start
, uvalue
);
7959 case DW_FORM_block4
:
7960 uvalue
= byte_get (data
, 4);
7961 block_start
= data
+ 4;
7962 data
= display_block (block_start
, uvalue
);
7966 printf (_(" (indirect string, offset: 0x%lx): %s"),
7967 uvalue
, fetch_indirect_string (uvalue
));
7970 case DW_FORM_indirect
:
7971 /* Handled above. */
7975 warn (_("Unrecognized form: %d\n"), form
);
7979 /* For some attributes we can display futher information. */
7988 case DW_INL_not_inlined
:
7989 printf (_("(not inlined)"));
7991 case DW_INL_inlined
:
7992 printf (_("(inlined)"));
7994 case DW_INL_declared_not_inlined
:
7995 printf (_("(declared as inline but ignored)"));
7997 case DW_INL_declared_inlined
:
7998 printf (_("(declared as inline and inlined)"));
8001 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
8006 case DW_AT_language
:
8009 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
8010 case DW_LANG_C89
: printf ("(ANSI C)"); break;
8011 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
8012 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
8013 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
8014 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
8015 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
8016 case DW_LANG_Ada83
: printf ("(Ada)"); break;
8017 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
8018 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
8019 /* DWARF 2.1 values. */
8020 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
8021 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
8022 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
8023 /* MIPS extension. */
8024 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
8025 /* UPC extension. */
8026 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
8028 printf ("(Unknown: %lx)", uvalue
);
8033 case DW_AT_encoding
:
8036 case DW_ATE_void
: printf ("(void)"); break;
8037 case DW_ATE_address
: printf ("(machine address)"); break;
8038 case DW_ATE_boolean
: printf ("(boolean)"); break;
8039 case DW_ATE_complex_float
: printf ("(complex float)"); break;
8040 case DW_ATE_float
: printf ("(float)"); break;
8041 case DW_ATE_signed
: printf ("(signed)"); break;
8042 case DW_ATE_signed_char
: printf ("(signed char)"); break;
8043 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
8044 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
8045 /* DWARF 2.1 value. */
8046 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
8048 if (uvalue
>= DW_ATE_lo_user
8049 && uvalue
<= DW_ATE_hi_user
)
8050 printf ("(user defined type)");
8052 printf ("(unknown type)");
8057 case DW_AT_accessibility
:
8060 case DW_ACCESS_public
: printf ("(public)"); break;
8061 case DW_ACCESS_protected
: printf ("(protected)"); break;
8062 case DW_ACCESS_private
: printf ("(private)"); break;
8064 printf ("(unknown accessibility)");
8069 case DW_AT_visibility
:
8072 case DW_VIS_local
: printf ("(local)"); break;
8073 case DW_VIS_exported
: printf ("(exported)"); break;
8074 case DW_VIS_qualified
: printf ("(qualified)"); break;
8075 default: printf ("(unknown visibility)"); break;
8079 case DW_AT_virtuality
:
8082 case DW_VIRTUALITY_none
: printf ("(none)"); break;
8083 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
8084 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
8085 default: printf ("(unknown virtuality)"); break;
8089 case DW_AT_identifier_case
:
8092 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
8093 case DW_ID_up_case
: printf ("(up_case)"); break;
8094 case DW_ID_down_case
: printf ("(down_case)"); break;
8095 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
8096 default: printf ("(unknown case)"); break;
8100 case DW_AT_calling_convention
:
8103 case DW_CC_normal
: printf ("(normal)"); break;
8104 case DW_CC_program
: printf ("(program)"); break;
8105 case DW_CC_nocall
: printf ("(nocall)"); break;
8107 if (uvalue
>= DW_CC_lo_user
8108 && uvalue
<= DW_CC_hi_user
)
8109 printf ("(user defined)");
8111 printf ("(unknown convention)");
8115 case DW_AT_ordering
:
8118 case -1: printf ("(undefined)"); break;
8119 case 0: printf ("(row major)"); break;
8120 case 1: printf ("(column major)"); break;
8124 case DW_AT_frame_base
:
8125 case DW_AT_location
:
8126 case DW_AT_data_member_location
:
8127 case DW_AT_vtable_elem_location
:
8128 case DW_AT_allocated
:
8129 case DW_AT_associated
:
8130 case DW_AT_data_location
:
8132 case DW_AT_upper_bound
:
8133 case DW_AT_lower_bound
:
8137 decode_location_expression (block_start
, pointer_size
, uvalue
);
8140 else if (form
== DW_FORM_data4
)
8143 printf ("location list");
8155 static unsigned char *
8156 read_and_display_attr (attribute
, form
, data
, cu_offset
, pointer_size
)
8157 unsigned long attribute
;
8159 unsigned char *data
;
8160 unsigned long cu_offset
;
8161 unsigned long pointer_size
;
8163 printf (" %-18s:", get_AT_name (attribute
));
8164 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
8171 display_debug_info (section
, start
, file
)
8172 Elf_Internal_Shdr
*section
;
8173 unsigned char *start
;
8176 unsigned char *end
= start
+ section
->sh_size
;
8177 unsigned char *section_begin
= start
;
8179 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8181 load_debug_str (file
);
8182 load_debug_loc (file
);
8186 DWARF2_External_CompUnit
*external
;
8187 DWARF2_Internal_CompUnit compunit
;
8188 Elf_Internal_Shdr
*relsec
;
8189 unsigned char *tags
;
8192 unsigned long cu_offset
;
8194 external
= (DWARF2_External_CompUnit
*) start
;
8196 compunit
.cu_length
= BYTE_GET (external
->cu_length
);
8197 compunit
.cu_version
= BYTE_GET (external
->cu_version
);
8198 compunit
.cu_abbrev_offset
= BYTE_GET (external
->cu_abbrev_offset
);
8199 compunit
.cu_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
8201 if (compunit
.cu_length
== 0xffffffff)
8203 warn (_("64-bit DWARF debug info is not supported yet.\n"));
8207 /* Check for RELA relocations in the
8208 abbrev_offset address, and apply them. */
8209 for (relsec
= section_headers
;
8210 relsec
< section_headers
+ elf_header
.e_shnum
;
8213 unsigned long nrelas
;
8214 Elf_Internal_Rela
*rela
, *rp
;
8215 Elf_Internal_Shdr
*symsec
;
8216 Elf_Internal_Sym
*symtab
;
8217 Elf_Internal_Sym
*sym
;
8219 if (relsec
->sh_type
!= SHT_RELA
8220 || SECTION_HEADER (relsec
->sh_info
) != section
8221 || relsec
->sh_size
== 0)
8224 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8228 symsec
= SECTION_HEADER (relsec
->sh_link
);
8229 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
8231 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8234 != (bfd_vma
) ((unsigned char *) &external
->cu_abbrev_offset
8240 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
8242 if (ELF32_R_SYM (rp
->r_info
) != 0
8243 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8245 warn (_("Skipping unexpected symbol type %u\n"),
8246 ELF32_ST_TYPE (sym
->st_info
));
8252 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
8254 if (ELF64_R_SYM (rp
->r_info
) != 0
8255 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8257 warn (_("Skipping unexpected symbol type %u\n"),
8258 ELF64_ST_TYPE (sym
->st_info
));
8263 compunit
.cu_abbrev_offset
= rp
->r_addend
;
8271 tags
= start
+ sizeof (*external
);
8272 cu_offset
= start
- section_begin
;
8273 start
+= compunit
.cu_length
+ sizeof (external
->cu_length
);
8275 printf (_(" Compilation Unit @ %lx:\n"), cu_offset
);
8276 printf (_(" Length: %ld\n"), compunit
.cu_length
);
8277 printf (_(" Version: %d\n"), compunit
.cu_version
);
8278 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
8279 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
8281 if (compunit
.cu_version
!= 2)
8283 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
8289 /* Read in the abbrevs used by this compilation unit. */
8291 Elf_Internal_Shdr
*sec
;
8292 unsigned char *begin
;
8294 /* Locate the .debug_abbrev section and process it. */
8295 for (i
= 0, sec
= section_headers
;
8296 i
< elf_header
.e_shnum
;
8298 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
8301 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
8303 warn (_("Unable to locate .debug_abbrev section!\n"));
8307 begin
= ((unsigned char *)
8308 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
8309 _("debug_abbrev section data")));
8313 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
8314 begin
+ sec
->sh_size
);
8320 while (tags
< start
)
8323 unsigned long abbrev_number
;
8324 abbrev_entry
*entry
;
8327 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
8330 /* A null DIE marks the end of a list of children. */
8331 if (abbrev_number
== 0)
8337 /* Scan through the abbreviation list until we reach the
8339 for (entry
= first_abbrev
;
8340 entry
&& entry
->entry
!= abbrev_number
;
8341 entry
= entry
->next
)
8346 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8351 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8353 (unsigned long) (tags
- section_begin
- bytes_read
),
8355 get_TAG_name (entry
->tag
));
8357 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
8358 tags
= read_and_display_attr (attr
->attribute
,
8361 compunit
.cu_pointer_size
);
8363 if (entry
->children
)
8377 display_debug_aranges (section
, start
, file
)
8378 Elf_Internal_Shdr
*section
;
8379 unsigned char *start
;
8380 FILE *file ATTRIBUTE_UNUSED
;
8382 unsigned char *end
= start
+ section
->sh_size
;
8384 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8388 DWARF2_External_ARange
*external
;
8389 DWARF2_Internal_ARange arange
;
8390 unsigned char *ranges
;
8391 unsigned long length
;
8392 unsigned long address
;
8395 external
= (DWARF2_External_ARange
*) start
;
8397 arange
.ar_length
= BYTE_GET (external
->ar_length
);
8398 arange
.ar_version
= BYTE_GET (external
->ar_version
);
8399 arange
.ar_info_offset
= BYTE_GET (external
->ar_info_offset
);
8400 arange
.ar_pointer_size
= BYTE_GET (external
->ar_pointer_size
);
8401 arange
.ar_segment_size
= BYTE_GET (external
->ar_segment_size
);
8403 if (arange
.ar_length
== 0xffffffff)
8405 warn (_("64-bit DWARF aranges are not supported yet.\n"));
8409 if (arange
.ar_version
!= 2)
8411 warn (_("Only DWARF 2 aranges are currently supported.\n"));
8415 printf (_(" Length: %ld\n"), arange
.ar_length
);
8416 printf (_(" Version: %d\n"), arange
.ar_version
);
8417 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
8418 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
8419 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
8421 printf (_("\n Address Length\n"));
8423 ranges
= start
+ sizeof (*external
);
8425 /* Must pad to an alignment boundary that is twice the pointer size. */
8426 excess
= sizeof (*external
) % (2 * arange
.ar_pointer_size
);
8428 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
8432 address
= byte_get (ranges
, arange
.ar_pointer_size
);
8434 ranges
+= arange
.ar_pointer_size
;
8436 length
= byte_get (ranges
, arange
.ar_pointer_size
);
8438 ranges
+= arange
.ar_pointer_size
;
8440 /* A pair of zeros marks the end of the list. */
8441 if (address
== 0 && length
== 0)
8444 printf (" %8.8lx %lu\n", address
, length
);
8447 start
+= arange
.ar_length
+ sizeof (external
->ar_length
);
8455 typedef struct Frame_Chunk
8457 struct Frame_Chunk
*next
;
8458 unsigned char *chunk_start
;
8460 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8461 short int *col_type
;
8464 unsigned int code_factor
;
8466 unsigned long pc_begin
;
8467 unsigned long pc_range
;
8471 unsigned char fde_encoding
;
8475 /* A marker for a col_type that means this column was never referenced
8476 in the frame info. */
8477 #define DW_CFA_unreferenced (-1)
8479 static void frame_need_space
PARAMS ((Frame_Chunk
*, int));
8480 static void frame_display_row
PARAMS ((Frame_Chunk
*, int *, int *));
8481 static int size_of_encoded_value
PARAMS ((int));
8484 frame_need_space (fc
, reg
)
8488 int prev
= fc
->ncols
;
8490 if (reg
< fc
->ncols
)
8493 fc
->ncols
= reg
+ 1;
8494 fc
->col_type
= (short int *) xrealloc (fc
->col_type
,
8495 fc
->ncols
* sizeof (short int));
8496 fc
->col_offset
= (int *) xrealloc (fc
->col_offset
,
8497 fc
->ncols
* sizeof (int));
8499 while (prev
< fc
->ncols
)
8501 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8502 fc
->col_offset
[prev
] = 0;
8508 frame_display_row (fc
, need_col_headers
, max_regs
)
8510 int *need_col_headers
;
8516 if (*max_regs
< fc
->ncols
)
8517 *max_regs
= fc
->ncols
;
8519 if (*need_col_headers
)
8521 *need_col_headers
= 0;
8523 printf (" LOC CFA ");
8525 for (r
= 0; r
< *max_regs
; r
++)
8526 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8531 printf ("r%-4d", r
);
8537 printf ("%08lx ", fc
->pc_begin
);
8538 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
8539 printf ("%-8s ", tmp
);
8541 for (r
= 0; r
< fc
->ncols
; r
++)
8543 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8545 switch (fc
->col_type
[r
])
8547 case DW_CFA_undefined
:
8550 case DW_CFA_same_value
:
8554 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8556 case DW_CFA_register
:
8557 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
8560 strcpy (tmp
, "n/a");
8563 printf ("%-5s", tmp
);
8570 size_of_encoded_value (encoding
)
8573 switch (encoding
& 0x7)
8576 case 0: return is_32bit_elf
? 4 : 8;
8583 #define GET(N) byte_get (start, N); start += N
8584 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8585 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8588 display_debug_frames (section
, start
, file
)
8589 Elf_Internal_Shdr
*section
;
8590 unsigned char *start
;
8591 FILE *file ATTRIBUTE_UNUSED
;
8593 unsigned char *end
= start
+ section
->sh_size
;
8594 unsigned char *section_start
= start
;
8595 Frame_Chunk
*chunks
= 0;
8596 Frame_Chunk
*remembered_state
= 0;
8598 int is_eh
= (strcmp (SECTION_NAME (section
), ".eh_frame") == 0);
8601 int addr_size
= is_32bit_elf
? 4 : 8;
8603 printf (_("The section %s contains:\n"), SECTION_NAME (section
));
8607 unsigned char *saved_start
;
8608 unsigned char *block_end
;
8609 unsigned long length
;
8610 unsigned long cie_id
;
8613 int need_col_headers
= 1;
8614 unsigned char *augmentation_data
= NULL
;
8615 unsigned long augmentation_data_len
= 0;
8616 int encoded_ptr_size
= addr_size
;
8618 saved_start
= start
;
8619 length
= byte_get (start
, 4); start
+= 4;
8623 printf ("\n%08lx ZERO terminator\n\n",
8624 (unsigned long)(saved_start
- section_start
));
8628 if (length
== 0xffffffff)
8630 warn (_("64-bit DWARF format frames are not supported yet.\n"));
8634 block_end
= saved_start
+ length
+ 4;
8635 cie_id
= byte_get (start
, 4); start
+= 4;
8637 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
8641 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8642 memset (fc
, 0, sizeof (Frame_Chunk
));
8646 fc
->chunk_start
= saved_start
;
8648 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8649 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8650 frame_need_space (fc
, max_regs
-1);
8654 fc
->augmentation
= start
;
8655 start
= strchr (start
, '\0') + 1;
8657 if (fc
->augmentation
[0] == 'z')
8659 fc
->code_factor
= LEB ();
8660 fc
->data_factor
= SLEB ();
8661 fc
->ra
= byte_get (start
, 1); start
+= 1;
8662 augmentation_data_len
= LEB ();
8663 augmentation_data
= start
;
8664 start
+= augmentation_data_len
;
8666 else if (strcmp (fc
->augmentation
, "eh") == 0)
8669 fc
->code_factor
= LEB ();
8670 fc
->data_factor
= SLEB ();
8671 fc
->ra
= byte_get (start
, 1); start
+= 1;
8675 fc
->code_factor
= LEB ();
8676 fc
->data_factor
= SLEB ();
8677 fc
->ra
= byte_get (start
, 1); start
+= 1;
8681 if (do_debug_frames_interp
)
8682 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8683 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8684 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
8688 printf ("\n%08lx %08lx %08lx CIE\n",
8689 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
8690 printf (" Version: %d\n", version
);
8691 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8692 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8693 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8694 printf (" Return address column: %d\n", fc
->ra
);
8696 if (augmentation_data_len
)
8699 printf (" Augmentation data: ");
8700 for (i
= 0; i
< augmentation_data_len
; ++i
)
8701 printf (" %02x", augmentation_data
[i
]);
8707 if (augmentation_data_len
)
8709 unsigned char *p
, *q
;
8710 p
= fc
->augmentation
+ 1;
8711 q
= augmentation_data
;
8718 q
+= 1 + size_of_encoded_value (*q
);
8720 fc
->fde_encoding
= *q
++;
8726 if (fc
->fde_encoding
)
8727 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8730 frame_need_space (fc
, fc
->ra
);
8734 unsigned char *look_for
;
8735 static Frame_Chunk fde_fc
;
8738 memset (fc
, 0, sizeof (Frame_Chunk
));
8740 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
8742 for (cie
= chunks
; cie
; cie
= cie
->next
)
8743 if (cie
->chunk_start
== look_for
)
8748 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8749 cie_id
, saved_start
);
8752 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8753 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8754 frame_need_space (fc
, max_regs
- 1);
8756 fc
->augmentation
= "";
8757 fc
->fde_encoding
= 0;
8761 fc
->ncols
= cie
->ncols
;
8762 fc
->col_type
= (short int *) xmalloc (fc
->ncols
* sizeof (short int));
8763 fc
->col_offset
= (int *) xmalloc (fc
->ncols
* sizeof (int));
8764 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8765 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8766 fc
->augmentation
= cie
->augmentation
;
8767 fc
->code_factor
= cie
->code_factor
;
8768 fc
->data_factor
= cie
->data_factor
;
8769 fc
->cfa_reg
= cie
->cfa_reg
;
8770 fc
->cfa_offset
= cie
->cfa_offset
;
8772 frame_need_space (fc
, max_regs
-1);
8773 fc
->fde_encoding
= cie
->fde_encoding
;
8776 if (fc
->fde_encoding
)
8777 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8779 fc
->pc_begin
= byte_get (start
, encoded_ptr_size
);
8780 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
8781 fc
->pc_begin
+= section
->sh_addr
+ (start
- section_start
);
8782 start
+= encoded_ptr_size
;
8783 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
8784 start
+= encoded_ptr_size
;
8786 if (cie
->augmentation
[0] == 'z')
8788 augmentation_data_len
= LEB ();
8789 augmentation_data
= start
;
8790 start
+= augmentation_data_len
;
8793 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8794 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8795 (unsigned long)(cie
->chunk_start
- section_start
),
8796 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
8797 if (! do_debug_frames_interp
&& augmentation_data_len
)
8800 printf (" Augmentation data: ");
8801 for (i
= 0; i
< augmentation_data_len
; ++i
)
8802 printf (" %02x", augmentation_data
[i
]);
8808 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8809 about to interpret instructions for the chunk. */
8811 if (do_debug_frames_interp
)
8813 /* Start by making a pass over the chunk, allocating storage
8814 and taking note of what registers are used. */
8815 unsigned char *tmp
= start
;
8817 while (start
< block_end
)
8827 /* Warning: if you add any more cases to this switch, be
8828 sure to add them to the corresponding switch below. */
8831 case DW_CFA_advance_loc
:
8835 frame_need_space (fc
, opa
);
8836 fc
->col_type
[opa
] = DW_CFA_undefined
;
8838 case DW_CFA_restore
:
8839 frame_need_space (fc
, opa
);
8840 fc
->col_type
[opa
] = DW_CFA_undefined
;
8842 case DW_CFA_set_loc
:
8843 start
+= encoded_ptr_size
;
8845 case DW_CFA_advance_loc1
:
8848 case DW_CFA_advance_loc2
:
8851 case DW_CFA_advance_loc4
:
8854 case DW_CFA_offset_extended
:
8855 reg
= LEB (); LEB ();
8856 frame_need_space (fc
, reg
);
8857 fc
->col_type
[reg
] = DW_CFA_undefined
;
8859 case DW_CFA_restore_extended
:
8861 frame_need_space (fc
, reg
);
8862 fc
->col_type
[reg
] = DW_CFA_undefined
;
8864 case DW_CFA_undefined
:
8866 frame_need_space (fc
, reg
);
8867 fc
->col_type
[reg
] = DW_CFA_undefined
;
8869 case DW_CFA_same_value
:
8871 frame_need_space (fc
, reg
);
8872 fc
->col_type
[reg
] = DW_CFA_undefined
;
8874 case DW_CFA_register
:
8875 reg
= LEB (); LEB ();
8876 frame_need_space (fc
, reg
);
8877 fc
->col_type
[reg
] = DW_CFA_undefined
;
8879 case DW_CFA_def_cfa
:
8882 case DW_CFA_def_cfa_register
:
8885 case DW_CFA_def_cfa_offset
:
8888 case DW_CFA_offset_extended_sf
:
8889 reg
= LEB (); SLEB ();
8890 frame_need_space (fc
, reg
);
8891 fc
->col_type
[reg
] = DW_CFA_undefined
;
8893 case DW_CFA_def_cfa_sf
:
8896 case DW_CFA_def_cfa_offset_sf
:
8899 case DW_CFA_GNU_args_size
:
8902 case DW_CFA_GNU_negative_offset_extended
:
8903 reg
= LEB (); LEB ();
8904 frame_need_space (fc
, reg
);
8905 fc
->col_type
[reg
] = DW_CFA_undefined
;
8914 /* Now we know what registers are used, make a second pass over
8915 the chunk, this time actually printing out the info. */
8917 while (start
< block_end
)
8920 unsigned long ul
, reg
, roffs
;
8929 /* Warning: if you add any more cases to this switch, be
8930 sure to add them to the corresponding switch above. */
8933 case DW_CFA_advance_loc
:
8934 if (do_debug_frames_interp
)
8935 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8937 printf (" DW_CFA_advance_loc: %d to %08lx\n",
8938 opa
* fc
->code_factor
,
8939 fc
->pc_begin
+ opa
* fc
->code_factor
);
8940 fc
->pc_begin
+= opa
* fc
->code_factor
;
8945 if (! do_debug_frames_interp
)
8946 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
8947 opa
, roffs
* fc
->data_factor
);
8948 fc
->col_type
[opa
] = DW_CFA_offset
;
8949 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8952 case DW_CFA_restore
:
8953 if (! do_debug_frames_interp
)
8954 printf (" DW_CFA_restore: r%d\n", opa
);
8955 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8956 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8959 case DW_CFA_set_loc
:
8960 vma
= byte_get (start
, encoded_ptr_size
);
8961 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
8962 vma
+= section
->sh_addr
+ (start
- section_start
);
8963 start
+= encoded_ptr_size
;
8964 if (do_debug_frames_interp
)
8965 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8967 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
8971 case DW_CFA_advance_loc1
:
8972 ofs
= byte_get (start
, 1); start
+= 1;
8973 if (do_debug_frames_interp
)
8974 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8976 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
8977 ofs
* fc
->code_factor
,
8978 fc
->pc_begin
+ ofs
* fc
->code_factor
);
8979 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8982 case DW_CFA_advance_loc2
:
8983 ofs
= byte_get (start
, 2); start
+= 2;
8984 if (do_debug_frames_interp
)
8985 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8987 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
8988 ofs
* fc
->code_factor
,
8989 fc
->pc_begin
+ ofs
* fc
->code_factor
);
8990 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8993 case DW_CFA_advance_loc4
:
8994 ofs
= byte_get (start
, 4); start
+= 4;
8995 if (do_debug_frames_interp
)
8996 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8998 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
8999 ofs
* fc
->code_factor
,
9000 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9001 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9004 case DW_CFA_offset_extended
:
9007 if (! do_debug_frames_interp
)
9008 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
9009 reg
, roffs
* fc
->data_factor
);
9010 fc
->col_type
[reg
] = DW_CFA_offset
;
9011 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9014 case DW_CFA_restore_extended
:
9016 if (! do_debug_frames_interp
)
9017 printf (" DW_CFA_restore_extended: r%ld\n", reg
);
9018 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9019 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9022 case DW_CFA_undefined
:
9024 if (! do_debug_frames_interp
)
9025 printf (" DW_CFA_undefined: r%ld\n", reg
);
9026 fc
->col_type
[reg
] = DW_CFA_undefined
;
9027 fc
->col_offset
[reg
] = 0;
9030 case DW_CFA_same_value
:
9032 if (! do_debug_frames_interp
)
9033 printf (" DW_CFA_same_value: r%ld\n", reg
);
9034 fc
->col_type
[reg
] = DW_CFA_same_value
;
9035 fc
->col_offset
[reg
] = 0;
9038 case DW_CFA_register
:
9041 if (! do_debug_frames_interp
)
9042 printf (" DW_CFA_register: r%ld\n", reg
);
9043 fc
->col_type
[reg
] = DW_CFA_register
;
9044 fc
->col_offset
[reg
] = roffs
;
9047 case DW_CFA_remember_state
:
9048 if (! do_debug_frames_interp
)
9049 printf (" DW_CFA_remember_state\n");
9050 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9051 rs
->ncols
= fc
->ncols
;
9052 rs
->col_type
= (short int *) xmalloc (rs
->ncols
* sizeof (short int));
9053 rs
->col_offset
= (int *) xmalloc (rs
->ncols
* sizeof (int));
9054 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
9055 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
9056 rs
->next
= remembered_state
;
9057 remembered_state
= rs
;
9060 case DW_CFA_restore_state
:
9061 if (! do_debug_frames_interp
)
9062 printf (" DW_CFA_restore_state\n");
9063 rs
= remembered_state
;
9064 remembered_state
= rs
->next
;
9065 frame_need_space (fc
, rs
->ncols
-1);
9066 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
9067 memcpy (fc
->col_offset
, rs
->col_offset
, rs
->ncols
* sizeof (int));
9068 free (rs
->col_type
);
9069 free (rs
->col_offset
);
9073 case DW_CFA_def_cfa
:
9074 fc
->cfa_reg
= LEB ();
9075 fc
->cfa_offset
= LEB ();
9076 if (! do_debug_frames_interp
)
9077 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
9078 fc
->cfa_reg
, fc
->cfa_offset
);
9081 case DW_CFA_def_cfa_register
:
9082 fc
->cfa_reg
= LEB ();
9083 if (! do_debug_frames_interp
)
9084 printf (" DW_CFA_def_cfa_reg: r%d\n", fc
->cfa_reg
);
9087 case DW_CFA_def_cfa_offset
:
9088 fc
->cfa_offset
= LEB ();
9089 if (! do_debug_frames_interp
)
9090 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
9094 if (! do_debug_frames_interp
)
9095 printf (" DW_CFA_nop\n");
9098 case DW_CFA_offset_extended_sf
:
9101 frame_need_space (fc
, reg
);
9102 if (! do_debug_frames_interp
)
9103 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
9104 reg
, l
* fc
->data_factor
);
9105 fc
->col_type
[reg
] = DW_CFA_offset
;
9106 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9109 case DW_CFA_def_cfa_sf
:
9110 fc
->cfa_reg
= LEB ();
9111 fc
->cfa_offset
= SLEB ();
9112 if (! do_debug_frames_interp
)
9113 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
9114 fc
->cfa_reg
, fc
->cfa_offset
);
9117 case DW_CFA_def_cfa_offset_sf
:
9118 fc
->cfa_offset
= SLEB ();
9119 if (! do_debug_frames_interp
)
9120 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
9123 case DW_CFA_GNU_window_save
:
9124 if (! do_debug_frames_interp
)
9125 printf (" DW_CFA_GNU_window_save\n");
9128 case DW_CFA_GNU_args_size
:
9130 if (! do_debug_frames_interp
)
9131 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9134 case DW_CFA_GNU_negative_offset_extended
:
9137 frame_need_space (fc
, reg
);
9138 if (! do_debug_frames_interp
)
9139 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
9140 reg
, l
* fc
->data_factor
);
9141 fc
->col_type
[reg
] = DW_CFA_offset
;
9142 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9145 /* FIXME: How do we handle these? */
9146 case DW_CFA_def_cfa_expression
:
9147 fprintf (stderr
, "unsupported DW_CFA_def_cfa_expression\n");
9151 case DW_CFA_expression
:
9152 fprintf (stderr
, "unsupported DW_CFA_expression\n");
9157 fprintf (stderr
, "unsupported or unknown DW_CFA_%d\n", op
);
9162 if (do_debug_frames_interp
)
9163 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9178 display_debug_not_supported (section
, start
, file
)
9179 Elf_Internal_Shdr
*section
;
9180 unsigned char *start ATTRIBUTE_UNUSED
;
9181 FILE *file ATTRIBUTE_UNUSED
;
9183 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9184 SECTION_NAME (section
));
9189 /* Pre-scan the .debug_info section to record the size of address.
9190 When dumping the .debug_line, we use that size information, assuming
9191 that all compilation units have the same address size. */
9193 prescan_debug_info (section
, start
, file
)
9194 Elf_Internal_Shdr
*section ATTRIBUTE_UNUSED
;
9195 unsigned char *start
;
9196 FILE *file ATTRIBUTE_UNUSED
;
9198 DWARF2_External_CompUnit
*external
;
9200 external
= (DWARF2_External_CompUnit
*) start
;
9202 debug_line_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
9206 /* A structure containing the name of a debug section and a pointer
9207 to a function that can decode it. The third field is a prescan
9208 function to be run over the section before displaying any of the
9212 const char *const name
;
9213 int (*display
) PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
9214 int (*prescan
) PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
9218 { ".debug_abbrev", display_debug_abbrev
, NULL
},
9219 { ".debug_aranges", display_debug_aranges
, NULL
},
9220 { ".debug_frame", display_debug_frames
, NULL
},
9221 { ".debug_info", display_debug_info
, prescan_debug_info
},
9222 { ".debug_line", display_debug_lines
, NULL
},
9223 { ".debug_pubnames", display_debug_pubnames
, NULL
},
9224 { ".eh_frame", display_debug_frames
, NULL
},
9225 { ".debug_macinfo", display_debug_macinfo
, NULL
},
9226 { ".debug_str", display_debug_str
, NULL
},
9227 { ".debug_loc", display_debug_loc
, NULL
},
9228 { ".debug_pubtypes", display_debug_not_supported
, NULL
},
9229 { ".debug_ranges", display_debug_not_supported
, NULL
},
9230 { ".debug_static_func", display_debug_not_supported
, NULL
},
9231 { ".debug_static_vars", display_debug_not_supported
, NULL
},
9232 { ".debug_types", display_debug_not_supported
, NULL
},
9233 { ".debug_weaknames", display_debug_not_supported
, NULL
}
9237 display_debug_section (section
, file
)
9238 Elf_Internal_Shdr
*section
;
9241 char *name
= SECTION_NAME (section
);
9242 bfd_size_type length
;
9243 unsigned char *start
;
9246 length
= section
->sh_size
;
9249 printf (_("\nSection '%s' has no debugging data.\n"), name
);
9253 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, length
,
9254 _("debug section data"));
9258 /* See if we know how to display the contents of this section. */
9259 if (strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
9260 name
= ".debug_info";
9262 for (i
= NUM_ELEM (debug_displays
); i
--;)
9263 if (strcmp (debug_displays
[i
].name
, name
) == 0)
9265 debug_displays
[i
].display (section
, start
, file
);
9270 printf (_("Unrecognized debug section: %s\n"), name
);
9274 /* If we loaded in the abbrev section at some point,
9275 we must release it here. */
9282 process_section_contents (file
)
9285 Elf_Internal_Shdr
*section
;
9291 /* Pre-scan the debug sections to find some debug information not
9292 present in some of them. For the .debug_line, we must find out the
9293 size of address (specified in .debug_info and .debug_aranges). */
9294 for (i
= 0, section
= section_headers
;
9295 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9298 char *name
= SECTION_NAME (section
);
9301 if (section
->sh_size
== 0)
9304 /* See if there is some pre-scan operation for this section. */
9305 for (j
= NUM_ELEM (debug_displays
); j
--;)
9306 if (strcmp (debug_displays
[j
].name
, name
) == 0)
9308 if (debug_displays
[j
].prescan
!= NULL
)
9310 bfd_size_type length
;
9311 unsigned char *start
;
9313 length
= section
->sh_size
;
9314 start
= ((unsigned char *)
9315 get_data (NULL
, file
, section
->sh_offset
, length
,
9316 _("debug section data")));
9320 debug_displays
[j
].prescan (section
, start
, file
);
9328 for (i
= 0, section
= section_headers
;
9329 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9332 #ifdef SUPPORT_DISASSEMBLY
9333 if (dump_sects
[i
] & DISASS_DUMP
)
9334 disassemble_section (section
, file
);
9336 if (dump_sects
[i
] & HEX_DUMP
)
9337 dump_section (section
, file
);
9339 if (dump_sects
[i
] & DEBUG_DUMP
)
9340 display_debug_section (section
, file
);
9343 if (i
< num_dump_sects
)
9344 warn (_("Some sections were not dumped because they do not exist!\n"));
9350 process_mips_fpe_exception (mask
)
9356 if (mask
& OEX_FPU_INEX
)
9357 fputs ("INEX", stdout
), first
= 0;
9358 if (mask
& OEX_FPU_UFLO
)
9359 printf ("%sUFLO", first
? "" : "|"), first
= 0;
9360 if (mask
& OEX_FPU_OFLO
)
9361 printf ("%sOFLO", first
? "" : "|"), first
= 0;
9362 if (mask
& OEX_FPU_DIV0
)
9363 printf ("%sDIV0", first
? "" : "|"), first
= 0;
9364 if (mask
& OEX_FPU_INVAL
)
9365 printf ("%sINVAL", first
? "" : "|");
9368 fputs ("0", stdout
);
9372 process_mips_specific (file
)
9375 Elf_Internal_Dyn
*entry
;
9376 size_t liblist_offset
= 0;
9377 size_t liblistno
= 0;
9378 size_t conflictsno
= 0;
9379 size_t options_offset
= 0;
9380 size_t conflicts_offset
= 0;
9382 /* We have a lot of special sections. Thanks SGI! */
9383 if (dynamic_segment
== NULL
)
9384 /* No information available. */
9387 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
9388 switch (entry
->d_tag
)
9390 case DT_MIPS_LIBLIST
:
9391 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
9393 case DT_MIPS_LIBLISTNO
:
9394 liblistno
= entry
->d_un
.d_val
;
9396 case DT_MIPS_OPTIONS
:
9397 options_offset
= entry
->d_un
.d_val
- loadaddr
;
9399 case DT_MIPS_CONFLICT
:
9400 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
9402 case DT_MIPS_CONFLICTNO
:
9403 conflictsno
= entry
->d_un
.d_val
;
9409 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9411 Elf32_External_Lib
*elib
;
9414 elib
= ((Elf32_External_Lib
*)
9415 get_data (NULL
, file
, liblist_offset
,
9416 liblistno
* sizeof (Elf32_External_Lib
),
9420 printf ("\nSection '.liblist' contains %lu entries:\n",
9421 (unsigned long) liblistno
);
9422 fputs (" Library Time Stamp Checksum Version Flags\n",
9425 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9432 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9433 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9434 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9435 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9436 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9438 tmp
= gmtime (&time
);
9439 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9440 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9441 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9443 printf ("%3lu: ", (unsigned long) cnt
);
9444 print_symbol (20, dynamic_strings
+ liblist
.l_name
);
9445 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9448 if (liblist
.l_flags
== 0)
9459 { " EXACT_MATCH", LL_EXACT_MATCH
},
9460 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9461 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9462 { " EXPORTS", LL_EXPORTS
},
9463 { " DELAY_LOAD", LL_DELAY_LOAD
},
9464 { " DELTA", LL_DELTA
}
9466 int flags
= liblist
.l_flags
;
9470 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
9472 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9474 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9475 flags
^= l_flags_vals
[fcnt
].bit
;
9478 printf (" %#x", (unsigned int) flags
);
9488 if (options_offset
!= 0)
9490 Elf_External_Options
*eopt
;
9491 Elf_Internal_Shdr
*sect
= section_headers
;
9492 Elf_Internal_Options
*iopt
;
9493 Elf_Internal_Options
*option
;
9497 /* Find the section header so that we get the size. */
9498 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9501 eopt
= (Elf_External_Options
*) get_data (NULL
, file
, options_offset
,
9502 sect
->sh_size
, _("options"));
9505 iopt
= ((Elf_Internal_Options
*)
9506 malloc ((sect
->sh_size
/ sizeof (eopt
)) * sizeof (*iopt
)));
9509 error (_("Out of memory"));
9516 while (offset
< sect
->sh_size
)
9518 Elf_External_Options
*eoption
;
9520 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9522 option
->kind
= BYTE_GET (eoption
->kind
);
9523 option
->size
= BYTE_GET (eoption
->size
);
9524 option
->section
= BYTE_GET (eoption
->section
);
9525 option
->info
= BYTE_GET (eoption
->info
);
9527 offset
+= option
->size
;
9533 printf (_("\nSection '%s' contains %d entries:\n"),
9534 SECTION_NAME (sect
), cnt
);
9542 switch (option
->kind
)
9545 /* This shouldn't happen. */
9546 printf (" NULL %d %lx", option
->section
, option
->info
);
9549 printf (" REGINFO ");
9550 if (elf_header
.e_machine
== EM_MIPS
)
9553 Elf32_External_RegInfo
*ereg
;
9554 Elf32_RegInfo reginfo
;
9556 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9557 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9558 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9559 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9560 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9561 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9562 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9564 printf ("GPR %08lx GP 0x%lx\n",
9566 (unsigned long) reginfo
.ri_gp_value
);
9567 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9568 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9569 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9574 Elf64_External_RegInfo
*ereg
;
9575 Elf64_Internal_RegInfo reginfo
;
9577 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9578 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9579 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9580 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9581 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9582 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9583 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
9585 printf ("GPR %08lx GP 0x",
9586 reginfo
.ri_gprmask
);
9587 printf_vma (reginfo
.ri_gp_value
);
9590 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9591 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9592 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9596 case ODK_EXCEPTIONS
:
9597 fputs (" EXCEPTIONS fpe_min(", stdout
);
9598 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9599 fputs (") fpe_max(", stdout
);
9600 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9601 fputs (")", stdout
);
9603 if (option
->info
& OEX_PAGE0
)
9604 fputs (" PAGE0", stdout
);
9605 if (option
->info
& OEX_SMM
)
9606 fputs (" SMM", stdout
);
9607 if (option
->info
& OEX_FPDBUG
)
9608 fputs (" FPDBUG", stdout
);
9609 if (option
->info
& OEX_DISMISS
)
9610 fputs (" DISMISS", stdout
);
9613 fputs (" PAD ", stdout
);
9614 if (option
->info
& OPAD_PREFIX
)
9615 fputs (" PREFIX", stdout
);
9616 if (option
->info
& OPAD_POSTFIX
)
9617 fputs (" POSTFIX", stdout
);
9618 if (option
->info
& OPAD_SYMBOL
)
9619 fputs (" SYMBOL", stdout
);
9622 fputs (" HWPATCH ", stdout
);
9623 if (option
->info
& OHW_R4KEOP
)
9624 fputs (" R4KEOP", stdout
);
9625 if (option
->info
& OHW_R8KPFETCH
)
9626 fputs (" R8KPFETCH", stdout
);
9627 if (option
->info
& OHW_R5KEOP
)
9628 fputs (" R5KEOP", stdout
);
9629 if (option
->info
& OHW_R5KCVTL
)
9630 fputs (" R5KCVTL", stdout
);
9633 fputs (" FILL ", stdout
);
9634 /* XXX Print content of info word? */
9637 fputs (" TAGS ", stdout
);
9638 /* XXX Print content of info word? */
9641 fputs (" HWAND ", stdout
);
9642 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9643 fputs (" R4KEOP_CHECKED", stdout
);
9644 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9645 fputs (" R4KEOP_CLEAN", stdout
);
9648 fputs (" HWOR ", stdout
);
9649 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9650 fputs (" R4KEOP_CHECKED", stdout
);
9651 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9652 fputs (" R4KEOP_CLEAN", stdout
);
9655 printf (" GP_GROUP %#06lx self-contained %#06lx",
9656 option
->info
& OGP_GROUP
,
9657 (option
->info
& OGP_SELF
) >> 16);
9660 printf (" IDENT %#06lx self-contained %#06lx",
9661 option
->info
& OGP_GROUP
,
9662 (option
->info
& OGP_SELF
) >> 16);
9665 /* This shouldn't happen. */
9666 printf (" %3d ??? %d %lx",
9667 option
->kind
, option
->section
, option
->info
);
9671 len
= sizeof (*eopt
);
9672 while (len
< option
->size
)
9673 if (((char *) option
)[len
] >= ' '
9674 && ((char *) option
)[len
] < 0x7f)
9675 printf ("%c", ((char *) option
)[len
++]);
9677 printf ("\\%03o", ((char *) option
)[len
++]);
9679 fputs ("\n", stdout
);
9687 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9689 Elf32_Conflict
*iconf
;
9692 if (dynamic_symbols
== NULL
)
9694 error (_("conflict list found without a dynamic symbol table"));
9698 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
9701 error (_("Out of memory"));
9707 Elf32_External_Conflict
*econf32
;
9709 econf32
= ((Elf32_External_Conflict
*)
9710 get_data (NULL
, file
, conflicts_offset
,
9711 conflictsno
* sizeof (*econf32
),
9716 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9717 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9723 Elf64_External_Conflict
*econf64
;
9725 econf64
= ((Elf64_External_Conflict
*)
9726 get_data (NULL
, file
, conflicts_offset
,
9727 conflictsno
* sizeof (*econf64
),
9732 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9733 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9738 printf (_("\nSection '.conflict' contains %ld entries:\n"),
9739 (long) conflictsno
);
9740 puts (_(" Num: Index Value Name"));
9742 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9744 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
9746 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9747 print_vma (psym
->st_value
, FULL_HEX
);
9749 print_symbol (25, dynamic_strings
+ psym
->st_name
);
9760 process_gnu_liblist (file
)
9763 Elf_Internal_Shdr
*section
, *string_sec
;
9764 Elf32_External_Lib
*elib
;
9772 for (i
= 0, section
= section_headers
;
9773 i
< elf_header
.e_shnum
;
9776 switch (section
->sh_type
)
9778 case SHT_GNU_LIBLIST
:
9779 elib
= ((Elf32_External_Lib
*)
9780 get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
9785 string_sec
= SECTION_HEADER (section
->sh_link
);
9787 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
9788 string_sec
->sh_size
,
9789 _("liblist string table"));
9792 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9798 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9799 SECTION_NAME (section
),
9800 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9802 puts (" Library Time Stamp Checksum Version Flags");
9804 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9812 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9813 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9814 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9815 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9816 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9818 tmp
= gmtime (&time
);
9819 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9820 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9821 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9823 printf ("%3lu: ", (unsigned long) cnt
);
9825 printf ("%-20s", strtab
+ liblist
.l_name
);
9827 printf ("%-20.20s", strtab
+ liblist
.l_name
);
9828 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9829 liblist
.l_version
, liblist
.l_flags
);
9840 get_note_type (e_type
)
9843 static char buff
[64];
9847 case NT_PRSTATUS
: return _("NT_PRSTATUS (prstatus structure)");
9848 case NT_FPREGSET
: return _("NT_FPREGSET (floating point registers)");
9849 case NT_PRPSINFO
: return _("NT_PRPSINFO (prpsinfo structure)");
9850 case NT_TASKSTRUCT
: return _("NT_TASKSTRUCT (task structure)");
9851 case NT_PRXFPREG
: return _("NT_PRXFPREG (user_xfpregs structure)");
9852 case NT_PSTATUS
: return _("NT_PSTATUS (pstatus structure)");
9853 case NT_FPREGS
: return _("NT_FPREGS (floating point registers)");
9854 case NT_PSINFO
: return _("NT_PSINFO (psinfo structure)");
9855 case NT_LWPSTATUS
: return _("NT_LWPSTATUS (lwpstatus_t structure)");
9856 case NT_LWPSINFO
: return _("NT_LWPSINFO (lwpsinfo_t structure)");
9857 case NT_WIN32PSTATUS
: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9859 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
9865 get_netbsd_elfcore_note_type (e_type
)
9868 static char buff
[64];
9870 if (e_type
== NT_NETBSDCORE_PROCINFO
)
9872 /* NetBSD core "procinfo" structure. */
9873 return _("NetBSD procinfo structure");
9876 /* As of Jan 2002 there are no other machine-independent notes
9877 defined for NetBSD core files. If the note type is less
9878 than the start of the machine-dependent note types, we don't
9881 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
9883 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
9887 switch (elf_header
.e_machine
)
9889 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9890 and PT_GETFPREGS == mach+2. */
9895 case EM_SPARC32PLUS
:
9899 case NT_NETBSDCORE_FIRSTMACH
+0:
9900 return _("PT_GETREGS (reg structure)");
9901 case NT_NETBSDCORE_FIRSTMACH
+2:
9902 return _("PT_GETFPREGS (fpreg structure)");
9908 /* On all other arch's, PT_GETREGS == mach+1 and
9909 PT_GETFPREGS == mach+3. */
9913 case NT_NETBSDCORE_FIRSTMACH
+1:
9914 return _("PT_GETREGS (reg structure)");
9915 case NT_NETBSDCORE_FIRSTMACH
+3:
9916 return _("PT_GETFPREGS (fpreg structure)");
9922 sprintf (buff
, _("PT_FIRSTMACH+%d"), e_type
- NT_NETBSDCORE_FIRSTMACH
);
9926 /* Note that by the ELF standard, the name field is already null byte
9927 terminated, and namesz includes the terminating null byte.
9928 I.E. the value of namesz for the name "FSF" is 4.
9930 If the value of namesz is zero, there is no name present. */
9932 process_note (pnote
)
9933 Elf_Internal_Note
*pnote
;
9937 if (pnote
->namesz
== 0)
9939 /* If there is no note name, then use the default set of
9940 note type strings. */
9941 nt
= get_note_type (pnote
->type
);
9943 else if (strncmp (pnote
->namedata
, "NetBSD-CORE", 11) == 0)
9945 /* NetBSD-specific core file notes. */
9946 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
9950 /* Don't recognize this note name; just use the default set of
9951 note type strings. */
9952 nt
= get_note_type (pnote
->type
);
9955 printf (" %s\t\t0x%08lx\t%s\n",
9956 pnote
->namesz
? pnote
->namedata
: "(NONE)",
9963 process_corefile_note_segment (file
, offset
, length
)
9968 Elf_External_Note
*pnotes
;
9969 Elf_External_Note
*external
;
9975 pnotes
= (Elf_External_Note
*) get_data (NULL
, file
, offset
, length
,
9982 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9983 (unsigned long) offset
, (unsigned long) length
);
9984 printf (_(" Owner\t\tData size\tDescription\n"));
9986 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
9988 Elf_External_Note
*next
;
9989 Elf_Internal_Note inote
;
9992 inote
.type
= BYTE_GET (external
->type
);
9993 inote
.namesz
= BYTE_GET (external
->namesz
);
9994 inote
.namedata
= external
->name
;
9995 inote
.descsz
= BYTE_GET (external
->descsz
);
9996 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
9997 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
9999 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
10001 if (((char *) next
) > (((char *) pnotes
) + length
))
10003 warn (_("corrupt note found at offset %x into core notes\n"),
10004 ((char *) external
) - ((char *) pnotes
));
10005 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
10006 inote
.type
, inote
.namesz
, inote
.descsz
);
10012 /* Verify that name is null terminated. It appears that at least
10013 one version of Linux (RedHat 6.0) generates corefiles that don't
10014 comply with the ELF spec by failing to include the null byte in
10016 if (inote
.namedata
[inote
.namesz
] != '\0')
10018 temp
= malloc (inote
.namesz
+ 1);
10022 error (_("Out of memory\n"));
10027 strncpy (temp
, inote
.namedata
, inote
.namesz
);
10028 temp
[inote
.namesz
] = 0;
10030 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
10031 inote
.namedata
= temp
;
10034 res
&= process_note (& inote
);
10049 process_corefile_note_segments (file
)
10052 Elf_Internal_Phdr
*program_headers
;
10053 Elf_Internal_Phdr
*segment
;
10057 program_headers
= (Elf_Internal_Phdr
*) malloc
10058 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
10060 if (program_headers
== NULL
)
10062 error (_("Out of memory\n"));
10067 i
= get_32bit_program_headers (file
, program_headers
);
10069 i
= get_64bit_program_headers (file
, program_headers
);
10073 free (program_headers
);
10077 for (i
= 0, segment
= program_headers
;
10078 i
< elf_header
.e_phnum
;
10081 if (segment
->p_type
== PT_NOTE
)
10082 res
&= process_corefile_note_segment (file
,
10083 (bfd_vma
) segment
->p_offset
,
10084 (bfd_vma
) segment
->p_filesz
);
10087 free (program_headers
);
10093 process_corefile_contents (file
)
10096 /* If we have not been asked to display the notes then do nothing. */
10100 /* If file is not a core file then exit. */
10101 if (elf_header
.e_type
!= ET_CORE
)
10104 /* No program headers means no NOTE segment. */
10105 if (elf_header
.e_phnum
== 0)
10107 printf (_("No note segments present in the core file.\n"));
10111 return process_corefile_note_segments (file
);
10115 process_arch_specific (file
)
10121 switch (elf_header
.e_machine
)
10124 case EM_MIPS_RS3_LE
:
10125 return process_mips_specific (file
);
10134 get_file_header (file
)
10137 /* Read in the identity array. */
10138 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
10141 /* Determine how to read the rest of the header. */
10142 switch (elf_header
.e_ident
[EI_DATA
])
10144 default: /* fall through */
10145 case ELFDATANONE
: /* fall through */
10146 case ELFDATA2LSB
: byte_get
= byte_get_little_endian
; break;
10147 case ELFDATA2MSB
: byte_get
= byte_get_big_endian
; break;
10150 /* For now we only support 32 bit and 64 bit ELF files. */
10151 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
10153 /* Read in the rest of the header. */
10156 Elf32_External_Ehdr ehdr32
;
10158 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
10161 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
10162 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
10163 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
10164 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
10165 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
10166 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
10167 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
10168 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
10169 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
10170 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
10171 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
10172 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
10173 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
10177 Elf64_External_Ehdr ehdr64
;
10179 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10180 we will not be able to cope with the 64bit data found in
10181 64 ELF files. Detect this now and abort before we start
10182 overwritting things. */
10183 if (sizeof (bfd_vma
) < 8)
10185 error (_("This instance of readelf has been built without support for a\n\
10186 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10190 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
10193 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
10194 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
10195 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
10196 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
10197 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
10198 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
10199 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
10200 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
10201 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
10202 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
10203 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
10204 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
10205 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
10208 if (elf_header
.e_shoff
)
10210 /* There may be some extensions in the first section header. Don't
10211 bomb if we can't read it. */
10213 get_32bit_section_headers (file
, 1);
10215 get_64bit_section_headers (file
, 1);
10222 process_file (file_name
)
10226 struct stat statbuf
;
10229 if (stat (file_name
, & statbuf
) < 0)
10231 error (_("Cannot stat input file %s.\n"), file_name
);
10235 file
= fopen (file_name
, "rb");
10238 error (_("Input file %s not found.\n"), file_name
);
10242 if (! get_file_header (file
))
10244 error (_("%s: Failed to read file header\n"), file_name
);
10249 /* Initialise per file variables. */
10250 for (i
= NUM_ELEM (version_info
); i
--;)
10251 version_info
[i
] = 0;
10253 for (i
= NUM_ELEM (dynamic_info
); i
--;)
10254 dynamic_info
[i
] = 0;
10256 /* Process the file. */
10258 printf (_("\nFile: %s\n"), file_name
);
10260 if (! process_file_header ())
10266 if (! process_section_headers (file
))
10268 /* Without loaded section headers we
10269 cannot process lots of things. */
10270 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10272 if (! do_using_dynamic
)
10273 do_syms
= do_reloc
= 0;
10276 if (process_program_headers (file
))
10277 process_dynamic_segment (file
);
10279 process_relocs (file
);
10281 process_unwind (file
);
10283 process_symbol_table (file
);
10285 process_syminfo (file
);
10287 process_version_sections (file
);
10289 process_section_contents (file
);
10291 process_corefile_contents (file
);
10293 process_gnu_liblist (file
);
10295 process_arch_specific (file
);
10299 if (section_headers
)
10301 free (section_headers
);
10302 section_headers
= NULL
;
10307 free (string_table
);
10308 string_table
= NULL
;
10309 string_table_length
= 0;
10312 if (dynamic_strings
)
10314 free (dynamic_strings
);
10315 dynamic_strings
= NULL
;
10318 if (dynamic_symbols
)
10320 free (dynamic_symbols
);
10321 dynamic_symbols
= NULL
;
10322 num_dynamic_syms
= 0;
10325 if (dynamic_syminfo
)
10327 free (dynamic_syminfo
);
10328 dynamic_syminfo
= NULL
;
10334 #ifdef SUPPORT_DISASSEMBLY
10335 /* Needed by the i386 disassembler. For extra credit, someone could
10336 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10340 print_address (unsigned int addr
, FILE *outfile
)
10342 fprintf (outfile
,"0x%8.8x", addr
);
10345 /* Needed by the i386 disassembler. */
10347 db_task_printsym (unsigned int addr
)
10349 print_address (addr
, stderr
);
10353 int main
PARAMS ((int, char **));
10361 char *cmdline_dump_sects
= NULL
;
10362 unsigned num_cmdline_dump_sects
= 0;
10364 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10365 setlocale (LC_MESSAGES
, "");
10367 #if defined (HAVE_SETLOCALE)
10368 setlocale (LC_CTYPE
, "");
10370 bindtextdomain (PACKAGE
, LOCALEDIR
);
10371 textdomain (PACKAGE
);
10373 parse_args (argc
, argv
);
10375 if (optind
< (argc
- 1))
10378 /* When processing more than one file remember the dump requests
10379 issued on command line to reset them after each file. */
10380 if (optind
+ 1 < argc
&& dump_sects
!= NULL
)
10382 cmdline_dump_sects
= malloc (num_dump_sects
);
10383 if (cmdline_dump_sects
== NULL
)
10384 error (_("Out of memory allocating dump request table."));
10387 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
10388 num_cmdline_dump_sects
= num_dump_sects
;
10393 while (optind
< argc
)
10395 err
|= process_file (argv
[optind
++]);
10397 /* Reset dump requests. */
10398 if (optind
< argc
&& dump_sects
!= NULL
)
10400 num_dump_sects
= num_cmdline_dump_sects
;
10401 if (num_cmdline_dump_sects
> 0)
10402 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
10406 if (dump_sects
!= NULL
)
10408 if (cmdline_dump_sects
!= NULL
)
10409 free (cmdline_dump_sects
);