1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include <sys/types.h>
32 /* Define BFD64 here, even if our default architecture is 32 bit ELF
33 as this will allow us to read in and parse 64bit and 32bit ELF files.
34 Only do this if we believe that the compiler can support a 64 bit
35 data type. For now we only rely on GCC being able to do this. */
41 #include "elf/common.h"
42 #include "elf/external.h"
43 #include "elf/internal.h"
44 #include "elf/dwarf2.h"
46 /* The following headers use the elf/reloc-macros.h file to
47 automatically generate relocation recognition functions
48 such as elf_mips_reloc_type() */
50 #define RELOC_MACROS_GEN_FUNC
52 #include "elf/alpha.h"
72 #include "elf/m68hc11.h"
73 #include "elf/mcore.h"
76 #include "elf/mn10200.h"
77 #include "elf/mn10300.h"
78 #include "elf/msp430.h"
82 #include "elf/ppc64.h"
85 #include "elf/sparc.h"
88 #include "elf/x86-64.h"
89 #include "elf/xstormy16.h"
90 #include "elf/iq2000.h"
91 #include "elf/xtensa.h"
95 #include "libiberty.h"
97 char *program_name
= "readelf";
98 unsigned long dynamic_addr
;
99 bfd_size_type dynamic_size
;
100 char *dynamic_strings
;
102 unsigned long string_table_length
;
103 unsigned long num_dynamic_syms
;
104 Elf_Internal_Sym
*dynamic_symbols
;
105 Elf_Internal_Syminfo
*dynamic_syminfo
;
106 unsigned long dynamic_syminfo_offset
;
107 unsigned int dynamic_syminfo_nent
;
108 char program_interpreter
[64];
109 bfd_vma dynamic_info
[DT_JMPREL
+ 1];
110 bfd_vma version_info
[16];
111 Elf_Internal_Ehdr elf_header
;
112 Elf_Internal_Shdr
*section_headers
;
113 Elf_Internal_Phdr
*program_headers
;
114 Elf_Internal_Dyn
*dynamic_segment
;
115 Elf_Internal_Shdr
*symtab_shndx_hdr
;
123 int do_using_dynamic
;
131 int do_debug_abbrevs
;
133 int do_debug_pubnames
;
134 int do_debug_aranges
;
136 int do_debug_frames_interp
;
137 int do_debug_macinfo
;
144 /* A dynamic array of flags indicating which sections require dumping. */
145 char *dump_sects
= NULL
;
146 unsigned int num_dump_sects
= 0;
148 #define HEX_DUMP (1 << 0)
149 #define DISASS_DUMP (1 << 1)
150 #define DEBUG_DUMP (1 << 2)
152 /* How to rpint a vma value. */
153 typedef enum print_mode
165 static bfd_vma (*byte_get
) (unsigned char *, int);
166 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
168 typedef int Elf32_Word
;
172 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
173 ((X)->sh_name >= string_table_length \
174 ? "<corrupt>" : string_table + (X)->sh_name))
176 /* Given st_shndx I, map to section_headers index. */
177 #define SECTION_HEADER_INDEX(I) \
178 ((I) < SHN_LORESERVE \
180 : ((I) <= SHN_HIRESERVE \
182 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
184 /* Reverse of the above. */
185 #define SECTION_HEADER_NUM(N) \
186 ((N) < SHN_LORESERVE \
188 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
190 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
192 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
194 #define BYTE_GET(field) byte_get (field, sizeof (field))
196 /* If we can support a 64 bit data type then BFD64 should be defined
197 and sizeof (bfd_vma) == 8. In this case when translating from an
198 external 8 byte field to an internal field, we can assume that the
199 internal field is also 8 bytes wide and so we can extract all the data.
200 If, however, BFD64 is not defined, then we must assume that the
201 internal data structure only has 4 byte wide fields that are the
202 equivalent of the 8 byte wide external counterparts, and so we must
203 truncate the data. */
205 #define BYTE_GET8(field) byte_get (field, -8)
207 #define BYTE_GET8(field) byte_get (field, 8)
210 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
212 #define GET_ELF_SYMBOLS(file, section) \
213 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
214 : get_64bit_elf_symbols (file, section))
218 error (const char *message
, ...)
222 va_start (args
, message
);
223 fprintf (stderr
, _("%s: Error: "), program_name
);
224 vfprintf (stderr
, message
, args
);
229 warn (const char *message
, ...)
233 va_start (args
, message
);
234 fprintf (stderr
, _("%s: Warning: "), program_name
);
235 vfprintf (stderr
, message
, args
);
240 get_data (void *var
, FILE *file
, long offset
, size_t size
, const char *reason
)
247 if (fseek (file
, offset
, SEEK_SET
))
249 error (_("Unable to seek to 0x%x for %s\n"), offset
, reason
);
256 mvar
= malloc (size
);
260 error (_("Out of memory allocating 0x%x bytes for %s\n"),
266 if (fread (mvar
, size
, 1, file
) != 1)
268 error (_("Unable to read in 0x%x bytes of %s\n"), size
, reason
);
278 byte_get_little_endian (unsigned char *field
, int size
)
286 return ((unsigned int) (field
[0]))
287 | (((unsigned int) (field
[1])) << 8);
291 /* We want to extract data from an 8 byte wide field and
292 place it into a 4 byte wide field. Since this is a little
293 endian source we can just use the 4 byte extraction code. */
297 return ((unsigned long) (field
[0]))
298 | (((unsigned long) (field
[1])) << 8)
299 | (((unsigned long) (field
[2])) << 16)
300 | (((unsigned long) (field
[3])) << 24);
305 /* This is a special case, generated by the BYTE_GET8 macro.
306 It means that we are loading an 8 byte value from a field
307 in an external structure into an 8 byte value in a field
308 in an internal strcuture. */
309 return ((bfd_vma
) (field
[0]))
310 | (((bfd_vma
) (field
[1])) << 8)
311 | (((bfd_vma
) (field
[2])) << 16)
312 | (((bfd_vma
) (field
[3])) << 24)
313 | (((bfd_vma
) (field
[4])) << 32)
314 | (((bfd_vma
) (field
[5])) << 40)
315 | (((bfd_vma
) (field
[6])) << 48)
316 | (((bfd_vma
) (field
[7])) << 56);
319 error (_("Unhandled data length: %d\n"), size
);
325 byte_get_signed (unsigned char *field
, int size
)
327 bfd_vma x
= byte_get (field
, size
);
332 return (x
^ 0x80) - 0x80;
334 return (x
^ 0x8000) - 0x8000;
336 return (x
^ 0x80000000) - 0x80000000;
346 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
351 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
352 field
[6] = ((value
>> 24) >> 24) & 0xff;
353 field
[5] = ((value
>> 24) >> 16) & 0xff;
354 field
[4] = ((value
>> 24) >> 8) & 0xff;
357 field
[3] = (value
>> 24) & 0xff;
358 field
[2] = (value
>> 16) & 0xff;
361 field
[1] = (value
>> 8) & 0xff;
364 field
[0] = value
& 0xff;
368 error (_("Unhandled data length: %d\n"), size
);
373 /* Print a VMA value. */
375 print_vma (bfd_vma vma
, print_mode mode
)
387 printf ("%8.8lx", (unsigned long) vma
);
393 printf ("%5ld", (long) vma
);
401 printf ("%lx", (unsigned long) vma
);
405 printf ("%ld", (unsigned long) vma
);
409 printf ("%lu", (unsigned long) vma
);
431 #if BFD_HOST_64BIT_LONG
434 if (_bfd_int64_high (vma
))
435 printf ("%lx%8.8lx", _bfd_int64_high (vma
), _bfd_int64_low (vma
));
437 printf ("%lx", _bfd_int64_low (vma
));
442 #if BFD_HOST_64BIT_LONG
445 if (_bfd_int64_high (vma
))
447 printf ("++%ld", _bfd_int64_low (vma
));
449 printf ("%ld", _bfd_int64_low (vma
));
454 #if BFD_HOST_64BIT_LONG
456 printf ("%5ld", vma
);
458 printf ("%#lx", vma
);
460 if (_bfd_int64_high (vma
))
462 printf ("++%ld", _bfd_int64_low (vma
));
463 else if (vma
<= 99999)
464 printf ("%5ld", _bfd_int64_low (vma
));
466 printf ("%#lx", _bfd_int64_low (vma
));
471 #if BFD_HOST_64BIT_LONG
474 if (_bfd_int64_high (vma
))
476 printf ("++%lu", _bfd_int64_low (vma
));
478 printf ("%lu", _bfd_int64_low (vma
));
486 /* Display a symbol on stdout. If do_wide is not true then
487 format the symbol to be at most WIDTH characters,
488 truncating as necessary. If WIDTH is negative then
489 format the string to be exactly - WIDTH characters,
490 truncating or padding as necessary. */
493 print_symbol (int width
, const char *symbol
)
496 printf ("%s", symbol
);
498 printf ("%-*.*s", width
, width
, symbol
);
500 printf ("%-.*s", width
, symbol
);
504 byte_get_big_endian (unsigned char *field
, int size
)
512 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
515 return ((unsigned long) (field
[3]))
516 | (((unsigned long) (field
[2])) << 8)
517 | (((unsigned long) (field
[1])) << 16)
518 | (((unsigned long) (field
[0])) << 24);
522 /* Although we are extracing data from an 8 byte wide field, we
523 are returning only 4 bytes of data. */
524 return ((unsigned long) (field
[7]))
525 | (((unsigned long) (field
[6])) << 8)
526 | (((unsigned long) (field
[5])) << 16)
527 | (((unsigned long) (field
[4])) << 24);
531 /* This is a special case, generated by the BYTE_GET8 macro.
532 It means that we are loading an 8 byte value from a field
533 in an external structure into an 8 byte value in a field
534 in an internal strcuture. */
535 return ((bfd_vma
) (field
[7]))
536 | (((bfd_vma
) (field
[6])) << 8)
537 | (((bfd_vma
) (field
[5])) << 16)
538 | (((bfd_vma
) (field
[4])) << 24)
539 | (((bfd_vma
) (field
[3])) << 32)
540 | (((bfd_vma
) (field
[2])) << 40)
541 | (((bfd_vma
) (field
[1])) << 48)
542 | (((bfd_vma
) (field
[0])) << 56);
546 error (_("Unhandled data length: %d\n"), size
);
552 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
557 field
[7] = value
& 0xff;
558 field
[6] = (value
>> 8) & 0xff;
559 field
[5] = (value
>> 16) & 0xff;
560 field
[4] = (value
>> 24) & 0xff;
565 field
[3] = value
& 0xff;
566 field
[2] = (value
>> 8) & 0xff;
570 field
[1] = value
& 0xff;
574 field
[0] = value
& 0xff;
578 error (_("Unhandled data length: %d\n"), size
);
583 /* Guess the relocation size commonly used by the specific machines. */
586 guess_is_rela (unsigned long e_machine
)
590 /* Targets that use REL relocations. */
606 /* Targets that use RELA relocations. */
621 case EM_CYGNUS_MN10200
:
623 case EM_CYGNUS_MN10300
:
668 warn (_("Don't know about relocations on this machine architecture\n"));
674 slurp_rela_relocs (FILE *file
,
675 unsigned long rel_offset
,
676 unsigned long rel_size
,
677 Elf_Internal_Rela
**relasp
,
678 unsigned long *nrelasp
)
680 Elf_Internal_Rela
*relas
;
681 unsigned long nrelas
;
686 Elf32_External_Rela
*erelas
;
688 erelas
= get_data (NULL
, file
, rel_offset
, rel_size
, _("relocs"));
692 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
694 relas
= malloc (nrelas
* sizeof (Elf_Internal_Rela
));
698 error(_("out of memory parsing relocs"));
702 for (i
= 0; i
< nrelas
; i
++)
704 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
705 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
706 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
713 Elf64_External_Rela
*erelas
;
715 erelas
= get_data (NULL
, file
, rel_offset
, rel_size
, _("relocs"));
719 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
721 relas
= malloc (nrelas
* sizeof (Elf_Internal_Rela
));
725 error(_("out of memory parsing relocs"));
729 for (i
= 0; i
< nrelas
; i
++)
731 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
732 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
733 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
744 slurp_rel_relocs (FILE *file
,
745 unsigned long rel_offset
,
746 unsigned long rel_size
,
747 Elf_Internal_Rela
**relsp
,
748 unsigned long *nrelsp
)
750 Elf_Internal_Rela
*rels
;
756 Elf32_External_Rel
*erels
;
758 erels
= get_data (NULL
, file
, rel_offset
, rel_size
, _("relocs"));
762 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
764 rels
= malloc (nrels
* sizeof (Elf_Internal_Rela
));
768 error(_("out of memory parsing relocs"));
772 for (i
= 0; i
< nrels
; i
++)
774 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
775 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
776 rels
[i
].r_addend
= 0;
783 Elf64_External_Rel
*erels
;
785 erels
= get_data (NULL
, file
, rel_offset
, rel_size
, _("relocs"));
789 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
791 rels
= malloc (nrels
* sizeof (Elf_Internal_Rela
));
795 error(_("out of memory parsing relocs"));
799 for (i
= 0; i
< nrels
; i
++)
801 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
802 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
803 rels
[i
].r_addend
= 0;
813 /* Display the contents of the relocation data found at the specified
817 dump_relocations (FILE *file
,
818 unsigned long rel_offset
,
819 unsigned long rel_size
,
820 Elf_Internal_Sym
*symtab
,
826 Elf_Internal_Rela
*rels
;
829 if (is_rela
== UNKNOWN
)
830 is_rela
= guess_is_rela (elf_header
.e_machine
);
834 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
839 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
848 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
850 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
855 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
857 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
865 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
867 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
872 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
874 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
878 for (i
= 0; i
< rel_size
; i
++)
881 const char *rtype2
= NULL
;
882 const char *rtype3
= NULL
;
885 bfd_vma symtab_index
;
890 offset
= rels
[i
].r_offset
;
891 info
= rels
[i
].r_info
;
895 type
= ELF32_R_TYPE (info
);
896 symtab_index
= ELF32_R_SYM (info
);
900 /* The #ifdef BFD64 below is to prevent a compile time warning.
901 We know that if we do not have a 64 bit data type that we
902 will never execute this code anyway. */
904 if (elf_header
.e_machine
== EM_MIPS
)
906 /* In little-endian objects, r_info isn't really a 64-bit
907 little-endian value: it has a 32-bit little-endian
908 symbol index followed by four individual byte fields.
909 Reorder INFO accordingly. */
910 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
911 info
= (((info
& 0xffffffff) << 32)
912 | ((info
>> 56) & 0xff)
913 | ((info
>> 40) & 0xff00)
914 | ((info
>> 24) & 0xff0000)
915 | ((info
>> 8) & 0xff000000));
916 type
= ELF64_MIPS_R_TYPE (info
);
917 type2
= ELF64_MIPS_R_TYPE2 (info
);
918 type3
= ELF64_MIPS_R_TYPE3 (info
);
920 else if (elf_header
.e_machine
== EM_SPARCV9
)
921 type
= ELF64_R_TYPE_ID (info
);
923 type
= ELF64_R_TYPE (info
);
925 symtab_index
= ELF64_R_SYM (info
);
931 #ifdef _bfd_int64_low
932 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
934 printf ("%8.8lx %8.8lx ", offset
, info
);
939 #ifdef _bfd_int64_low
941 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
942 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
943 _bfd_int64_high (offset
),
944 _bfd_int64_low (offset
),
945 _bfd_int64_high (info
),
946 _bfd_int64_low (info
));
949 ? "%16.16lx %16.16lx "
950 : "%12.12lx %12.12lx ",
955 switch (elf_header
.e_machine
)
963 rtype
= elf_m32r_reloc_type (type
);
968 rtype
= elf_i386_reloc_type (type
);
973 rtype
= elf_m68hc11_reloc_type (type
);
977 rtype
= elf_m68k_reloc_type (type
);
981 rtype
= elf_i960_reloc_type (type
);
986 rtype
= elf_avr_reloc_type (type
);
993 rtype
= elf_sparc_reloc_type (type
);
998 rtype
= v850_reloc_type (type
);
1002 case EM_CYGNUS_D10V
:
1003 rtype
= elf_d10v_reloc_type (type
);
1007 case EM_CYGNUS_D30V
:
1008 rtype
= elf_d30v_reloc_type (type
);
1012 rtype
= elf_dlx_reloc_type (type
);
1016 rtype
= elf_sh_reloc_type (type
);
1020 case EM_CYGNUS_MN10300
:
1021 rtype
= elf_mn10300_reloc_type (type
);
1025 case EM_CYGNUS_MN10200
:
1026 rtype
= elf_mn10200_reloc_type (type
);
1030 case EM_CYGNUS_FR30
:
1031 rtype
= elf_fr30_reloc_type (type
);
1035 rtype
= elf_frv_reloc_type (type
);
1039 rtype
= elf_mcore_reloc_type (type
);
1043 rtype
= elf_mmix_reloc_type (type
);
1048 rtype
= elf_msp430_reloc_type (type
);
1052 rtype
= elf_ppc_reloc_type (type
);
1056 rtype
= elf_ppc64_reloc_type (type
);
1060 case EM_MIPS_RS3_LE
:
1061 rtype
= elf_mips_reloc_type (type
);
1064 rtype2
= elf_mips_reloc_type (type2
);
1065 rtype3
= elf_mips_reloc_type (type3
);
1070 rtype
= elf_alpha_reloc_type (type
);
1074 rtype
= elf_arm_reloc_type (type
);
1078 rtype
= elf_arc_reloc_type (type
);
1082 rtype
= elf_hppa_reloc_type (type
);
1088 rtype
= elf_h8_reloc_type (type
);
1093 rtype
= elf_or32_reloc_type (type
);
1098 rtype
= elf_pj_reloc_type (type
);
1101 rtype
= elf_ia64_reloc_type (type
);
1105 rtype
= elf_cris_reloc_type (type
);
1109 rtype
= elf_i860_reloc_type (type
);
1113 rtype
= elf_x86_64_reloc_type (type
);
1117 rtype
= i370_reloc_type (type
);
1122 rtype
= elf_s390_reloc_type (type
);
1126 rtype
= elf_xstormy16_reloc_type (type
);
1130 rtype
= elf_vax_reloc_type (type
);
1135 rtype
= elf_ip2k_reloc_type (type
);
1139 rtype
= elf_iq2000_reloc_type (type
);
1144 rtype
= elf_xtensa_reloc_type (type
);
1149 #ifdef _bfd_int64_low
1150 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1152 printf (_("unrecognized: %-7lx"), type
);
1155 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1159 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1160 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1163 Elf_Internal_Sym
*psym
;
1165 psym
= symtab
+ symtab_index
;
1168 print_vma (psym
->st_value
, LONG_HEX
);
1169 printf (is_32bit_elf
? " " : " ");
1171 if (psym
->st_name
== 0)
1173 const char *sec_name
= "<null>";
1176 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1178 bfd_vma sec_index
= (bfd_vma
) -1;
1180 if (psym
->st_shndx
< SHN_LORESERVE
)
1181 sec_index
= psym
->st_shndx
;
1182 else if (psym
->st_shndx
> SHN_LORESERVE
)
1183 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1186 if (sec_index
!= (bfd_vma
) -1)
1187 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1188 else if (psym
->st_shndx
== SHN_ABS
)
1190 else if (psym
->st_shndx
== SHN_COMMON
)
1191 sec_name
= "COMMON";
1194 sprintf (name_buf
, "<section 0x%x>",
1195 (unsigned int) psym
->st_shndx
);
1196 sec_name
= name_buf
;
1199 print_symbol (22, sec_name
);
1201 else if (strtab
== NULL
)
1202 printf (_("<string table index %3ld>"), psym
->st_name
);
1204 print_symbol (22, strtab
+ psym
->st_name
);
1207 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1212 printf ("%*c", is_32bit_elf
? (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1213 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1216 if (elf_header
.e_machine
== EM_SPARCV9
1217 && !strcmp (rtype
, "R_SPARC_OLO10"))
1218 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1222 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1224 printf (" Type2: ");
1227 #ifdef _bfd_int64_low
1228 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1230 printf (_("unrecognized: %-7lx"), type2
);
1233 printf ("%-17.17s", rtype2
);
1235 printf("\n Type3: ");
1238 #ifdef _bfd_int64_low
1239 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1241 printf (_("unrecognized: %-7lx"), type3
);
1244 printf ("%-17.17s", rtype3
);
1256 get_mips_dynamic_type (unsigned long type
)
1260 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1261 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1262 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1263 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1264 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1265 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1266 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1267 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1268 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1269 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1270 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1271 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1272 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1273 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1274 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1275 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1276 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1277 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1278 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1279 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1280 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1281 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1282 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1283 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1284 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1285 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1286 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1287 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1288 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1289 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1290 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1291 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1292 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1293 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1294 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1295 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1296 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1297 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1298 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1299 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1300 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1301 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1302 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1309 get_sparc64_dynamic_type (unsigned long type
)
1313 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1320 get_ppc64_dynamic_type (unsigned long type
)
1324 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1325 case DT_PPC64_OPD
: return "PPC64_OPD";
1326 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1333 get_parisc_dynamic_type (unsigned long type
)
1337 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1338 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1339 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1340 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1341 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1342 case DT_HP_PREINIT
: return "HP_PREINIT";
1343 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1344 case DT_HP_NEEDED
: return "HP_NEEDED";
1345 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1346 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1347 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1348 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1349 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1356 get_ia64_dynamic_type (unsigned long type
)
1360 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1367 get_dynamic_type (unsigned long type
)
1369 static char buff
[32];
1373 case DT_NULL
: return "NULL";
1374 case DT_NEEDED
: return "NEEDED";
1375 case DT_PLTRELSZ
: return "PLTRELSZ";
1376 case DT_PLTGOT
: return "PLTGOT";
1377 case DT_HASH
: return "HASH";
1378 case DT_STRTAB
: return "STRTAB";
1379 case DT_SYMTAB
: return "SYMTAB";
1380 case DT_RELA
: return "RELA";
1381 case DT_RELASZ
: return "RELASZ";
1382 case DT_RELAENT
: return "RELAENT";
1383 case DT_STRSZ
: return "STRSZ";
1384 case DT_SYMENT
: return "SYMENT";
1385 case DT_INIT
: return "INIT";
1386 case DT_FINI
: return "FINI";
1387 case DT_SONAME
: return "SONAME";
1388 case DT_RPATH
: return "RPATH";
1389 case DT_SYMBOLIC
: return "SYMBOLIC";
1390 case DT_REL
: return "REL";
1391 case DT_RELSZ
: return "RELSZ";
1392 case DT_RELENT
: return "RELENT";
1393 case DT_PLTREL
: return "PLTREL";
1394 case DT_DEBUG
: return "DEBUG";
1395 case DT_TEXTREL
: return "TEXTREL";
1396 case DT_JMPREL
: return "JMPREL";
1397 case DT_BIND_NOW
: return "BIND_NOW";
1398 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1399 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1400 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1401 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1402 case DT_RUNPATH
: return "RUNPATH";
1403 case DT_FLAGS
: return "FLAGS";
1405 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1406 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1408 case DT_CHECKSUM
: return "CHECKSUM";
1409 case DT_PLTPADSZ
: return "PLTPADSZ";
1410 case DT_MOVEENT
: return "MOVEENT";
1411 case DT_MOVESZ
: return "MOVESZ";
1412 case DT_FEATURE
: return "FEATURE";
1413 case DT_POSFLAG_1
: return "POSFLAG_1";
1414 case DT_SYMINSZ
: return "SYMINSZ";
1415 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1417 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1418 case DT_CONFIG
: return "CONFIG";
1419 case DT_DEPAUDIT
: return "DEPAUDIT";
1420 case DT_AUDIT
: return "AUDIT";
1421 case DT_PLTPAD
: return "PLTPAD";
1422 case DT_MOVETAB
: return "MOVETAB";
1423 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1425 case DT_VERSYM
: return "VERSYM";
1427 case DT_RELACOUNT
: return "RELACOUNT";
1428 case DT_RELCOUNT
: return "RELCOUNT";
1429 case DT_FLAGS_1
: return "FLAGS_1";
1430 case DT_VERDEF
: return "VERDEF";
1431 case DT_VERDEFNUM
: return "VERDEFNUM";
1432 case DT_VERNEED
: return "VERNEED";
1433 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1435 case DT_AUXILIARY
: return "AUXILIARY";
1436 case DT_USED
: return "USED";
1437 case DT_FILTER
: return "FILTER";
1439 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1440 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1441 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1442 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1443 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1446 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1450 switch (elf_header
.e_machine
)
1453 case EM_MIPS_RS3_LE
:
1454 result
= get_mips_dynamic_type (type
);
1457 result
= get_sparc64_dynamic_type (type
);
1460 result
= get_ppc64_dynamic_type (type
);
1463 result
= get_ia64_dynamic_type (type
);
1473 sprintf (buff
, _("Processor Specific: %lx"), type
);
1475 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1479 switch (elf_header
.e_machine
)
1482 result
= get_parisc_dynamic_type (type
);
1492 sprintf (buff
, _("Operating System specific: %lx"), type
);
1495 sprintf (buff
, _("<unknown>: %lx"), type
);
1502 get_file_type (unsigned e_type
)
1504 static char buff
[32];
1508 case ET_NONE
: return _("NONE (None)");
1509 case ET_REL
: return _("REL (Relocatable file)");
1510 case ET_EXEC
: return _("EXEC (Executable file)");
1511 case ET_DYN
: return _("DYN (Shared object file)");
1512 case ET_CORE
: return _("CORE (Core file)");
1515 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1516 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
1517 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1518 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
1520 sprintf (buff
, _("<unknown>: %x"), e_type
);
1526 get_machine_name (unsigned e_machine
)
1528 static char buff
[64]; /* XXX */
1532 case EM_NONE
: return _("None");
1533 case EM_M32
: return "WE32100";
1534 case EM_SPARC
: return "Sparc";
1535 case EM_386
: return "Intel 80386";
1536 case EM_68K
: return "MC68000";
1537 case EM_88K
: return "MC88000";
1538 case EM_486
: return "Intel 80486";
1539 case EM_860
: return "Intel 80860";
1540 case EM_MIPS
: return "MIPS R3000";
1541 case EM_S370
: return "IBM System/370";
1542 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1543 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1544 case EM_PARISC
: return "HPPA";
1545 case EM_PPC_OLD
: return "Power PC (old)";
1546 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1547 case EM_960
: return "Intel 90860";
1548 case EM_PPC
: return "PowerPC";
1549 case EM_PPC64
: return "PowerPC64";
1550 case EM_V800
: return "NEC V800";
1551 case EM_FR20
: return "Fujitsu FR20";
1552 case EM_RH32
: return "TRW RH32";
1553 case EM_MCORE
: return "MCORE";
1554 case EM_ARM
: return "ARM";
1555 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1556 case EM_SH
: return "Renesas / SuperH SH";
1557 case EM_SPARCV9
: return "Sparc v9";
1558 case EM_TRICORE
: return "Siemens Tricore";
1559 case EM_ARC
: return "ARC";
1560 case EM_H8_300
: return "Renesas H8/300";
1561 case EM_H8_300H
: return "Renesas H8/300H";
1562 case EM_H8S
: return "Renesas H8S";
1563 case EM_H8_500
: return "Renesas H8/500";
1564 case EM_IA_64
: return "Intel IA-64";
1565 case EM_MIPS_X
: return "Stanford MIPS-X";
1566 case EM_COLDFIRE
: return "Motorola Coldfire";
1567 case EM_68HC12
: return "Motorola M68HC12";
1568 case EM_ALPHA
: return "Alpha";
1569 case EM_CYGNUS_D10V
:
1570 case EM_D10V
: return "d10v";
1571 case EM_CYGNUS_D30V
:
1572 case EM_D30V
: return "d30v";
1573 case EM_CYGNUS_M32R
:
1574 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1575 case EM_CYGNUS_V850
:
1576 case EM_V850
: return "NEC v850";
1577 case EM_CYGNUS_MN10300
:
1578 case EM_MN10300
: return "mn10300";
1579 case EM_CYGNUS_MN10200
:
1580 case EM_MN10200
: return "mn10200";
1581 case EM_CYGNUS_FR30
:
1582 case EM_FR30
: return "Fujitsu FR30";
1583 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1585 case EM_PJ
: return "picoJava";
1586 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1587 case EM_PCP
: return "Siemens PCP";
1588 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1589 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1590 case EM_STARCORE
: return "Motorola Star*Core processor";
1591 case EM_ME16
: return "Toyota ME16 processor";
1592 case EM_ST100
: return "STMicroelectronics ST100 processor";
1593 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1594 case EM_FX66
: return "Siemens FX66 microcontroller";
1595 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1596 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1597 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1598 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1599 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1600 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1601 case EM_SVX
: return "Silicon Graphics SVx";
1602 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1603 case EM_VAX
: return "Digital VAX";
1605 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1606 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1607 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1608 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1609 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1610 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1611 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1612 case EM_PRISM
: return "Vitesse Prism";
1613 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1615 case EM_S390
: return "IBM S/390";
1616 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1618 case EM_OR32
: return "OpenRISC";
1619 case EM_DLX
: return "OpenDLX";
1621 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1622 case EM_IQ2000
: return "Vitesse IQ2000";
1624 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1626 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1632 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1637 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1638 e_flags
&= ~ EF_ARM_EABIMASK
;
1640 /* Handle "generic" ARM flags. */
1641 if (e_flags
& EF_ARM_RELEXEC
)
1643 strcat (buf
, ", relocatable executable");
1644 e_flags
&= ~ EF_ARM_RELEXEC
;
1647 if (e_flags
& EF_ARM_HASENTRY
)
1649 strcat (buf
, ", has entry point");
1650 e_flags
&= ~ EF_ARM_HASENTRY
;
1653 /* Now handle EABI specific flags. */
1657 strcat (buf
, ", <unrecognized EABI>");
1662 case EF_ARM_EABI_VER1
:
1663 strcat (buf
, ", Version1 EABI");
1668 /* Process flags one bit at a time. */
1669 flag
= e_flags
& - e_flags
;
1674 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1675 strcat (buf
, ", sorted symbol tables");
1685 case EF_ARM_EABI_VER2
:
1686 strcat (buf
, ", Version2 EABI");
1691 /* Process flags one bit at a time. */
1692 flag
= e_flags
& - e_flags
;
1697 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1698 strcat (buf
, ", sorted symbol tables");
1701 case EF_ARM_DYNSYMSUSESEGIDX
:
1702 strcat (buf
, ", dynamic symbols use segment index");
1705 case EF_ARM_MAPSYMSFIRST
:
1706 strcat (buf
, ", mapping symbols precede others");
1716 case EF_ARM_EABI_UNKNOWN
:
1717 strcat (buf
, ", GNU EABI");
1722 /* Process flags one bit at a time. */
1723 flag
= e_flags
& - e_flags
;
1728 case EF_ARM_INTERWORK
:
1729 strcat (buf
, ", interworking enabled");
1732 case EF_ARM_APCS_26
:
1733 strcat (buf
, ", uses APCS/26");
1736 case EF_ARM_APCS_FLOAT
:
1737 strcat (buf
, ", uses APCS/float");
1741 strcat (buf
, ", position independent");
1745 strcat (buf
, ", 8 bit structure alignment");
1748 case EF_ARM_NEW_ABI
:
1749 strcat (buf
, ", uses new ABI");
1752 case EF_ARM_OLD_ABI
:
1753 strcat (buf
, ", uses old ABI");
1756 case EF_ARM_SOFT_FLOAT
:
1757 strcat (buf
, ", software FP");
1760 case EF_ARM_MAVERICK_FLOAT
:
1761 strcat (buf
, ", Maverick FP");
1772 strcat (buf
,", <unknown>");
1776 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1778 static char buf
[1024];
1790 decode_ARM_machine_flags (e_flags
, buf
);
1794 if (e_flags
& EF_CPU32
)
1795 strcat (buf
, ", cpu32");
1796 if (e_flags
& EF_M68000
)
1797 strcat (buf
, ", m68000");
1801 if (e_flags
& EF_PPC_EMB
)
1802 strcat (buf
, ", emb");
1804 if (e_flags
& EF_PPC_RELOCATABLE
)
1805 strcat (buf
, ", relocatable");
1807 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1808 strcat (buf
, ", relocatable-lib");
1812 case EM_CYGNUS_V850
:
1813 switch (e_flags
& EF_V850_ARCH
)
1816 strcat (buf
, ", v850e");
1819 strcat (buf
, ", v850");
1822 strcat (buf
, ", unknown v850 architecture variant");
1828 case EM_CYGNUS_M32R
:
1829 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1830 strcat (buf
, ", m32r");
1835 case EM_MIPS_RS3_LE
:
1836 if (e_flags
& EF_MIPS_NOREORDER
)
1837 strcat (buf
, ", noreorder");
1839 if (e_flags
& EF_MIPS_PIC
)
1840 strcat (buf
, ", pic");
1842 if (e_flags
& EF_MIPS_CPIC
)
1843 strcat (buf
, ", cpic");
1845 if (e_flags
& EF_MIPS_UCODE
)
1846 strcat (buf
, ", ugen_reserved");
1848 if (e_flags
& EF_MIPS_ABI2
)
1849 strcat (buf
, ", abi2");
1851 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
1852 strcat (buf
, ", odk first");
1854 if (e_flags
& EF_MIPS_32BITMODE
)
1855 strcat (buf
, ", 32bitmode");
1857 switch ((e_flags
& EF_MIPS_MACH
))
1859 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
1860 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
1861 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
1862 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
1863 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
1864 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
1865 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
1866 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
1867 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
1869 /* We simply ignore the field in this case to avoid confusion:
1870 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
1873 default: strcat (buf
, ", unknown CPU"); break;
1876 switch ((e_flags
& EF_MIPS_ABI
))
1878 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
1879 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
1880 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
1881 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
1883 /* We simply ignore the field in this case to avoid confusion:
1884 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
1885 This means it is likely to be an o32 file, but not for
1888 default: strcat (buf
, ", unknown ABI"); break;
1891 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
1892 strcat (buf
, ", mdmx");
1894 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
1895 strcat (buf
, ", mips16");
1897 switch ((e_flags
& EF_MIPS_ARCH
))
1899 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
1900 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
1901 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
1902 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
1903 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
1904 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
1905 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
1906 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
1907 default: strcat (buf
, ", unknown ISA"); break;
1913 if (e_flags
& EF_SPARC_32PLUS
)
1914 strcat (buf
, ", v8+");
1916 if (e_flags
& EF_SPARC_SUN_US1
)
1917 strcat (buf
, ", ultrasparcI");
1919 if (e_flags
& EF_SPARC_SUN_US3
)
1920 strcat (buf
, ", ultrasparcIII");
1922 if (e_flags
& EF_SPARC_HAL_R1
)
1923 strcat (buf
, ", halr1");
1925 if (e_flags
& EF_SPARC_LEDATA
)
1926 strcat (buf
, ", ledata");
1928 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
1929 strcat (buf
, ", tso");
1931 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
1932 strcat (buf
, ", pso");
1934 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
1935 strcat (buf
, ", rmo");
1939 switch (e_flags
& EF_PARISC_ARCH
)
1941 case EFA_PARISC_1_0
:
1942 strcpy (buf
, ", PA-RISC 1.0");
1944 case EFA_PARISC_1_1
:
1945 strcpy (buf
, ", PA-RISC 1.1");
1947 case EFA_PARISC_2_0
:
1948 strcpy (buf
, ", PA-RISC 2.0");
1953 if (e_flags
& EF_PARISC_TRAPNIL
)
1954 strcat (buf
, ", trapnil");
1955 if (e_flags
& EF_PARISC_EXT
)
1956 strcat (buf
, ", ext");
1957 if (e_flags
& EF_PARISC_LSB
)
1958 strcat (buf
, ", lsb");
1959 if (e_flags
& EF_PARISC_WIDE
)
1960 strcat (buf
, ", wide");
1961 if (e_flags
& EF_PARISC_NO_KABP
)
1962 strcat (buf
, ", no kabp");
1963 if (e_flags
& EF_PARISC_LAZYSWAP
)
1964 strcat (buf
, ", lazyswap");
1969 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
1970 strcat (buf
, ", new calling convention");
1972 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
1973 strcat (buf
, ", gnu calling convention");
1977 if ((e_flags
& EF_IA_64_ABI64
))
1978 strcat (buf
, ", 64-bit");
1980 strcat (buf
, ", 32-bit");
1981 if ((e_flags
& EF_IA_64_REDUCEDFP
))
1982 strcat (buf
, ", reduced fp model");
1983 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
1984 strcat (buf
, ", no function descriptors, constant gp");
1985 else if ((e_flags
& EF_IA_64_CONS_GP
))
1986 strcat (buf
, ", constant gp");
1987 if ((e_flags
& EF_IA_64_ABSOLUTE
))
1988 strcat (buf
, ", absolute");
1992 if ((e_flags
& EF_VAX_NONPIC
))
1993 strcat (buf
, ", non-PIC");
1994 if ((e_flags
& EF_VAX_DFLOAT
))
1995 strcat (buf
, ", D-Float");
1996 if ((e_flags
& EF_VAX_GFLOAT
))
1997 strcat (buf
, ", G-Float");
2006 get_osabi_name (unsigned int osabi
)
2008 static char buff
[32];
2012 case ELFOSABI_NONE
: return "UNIX - System V";
2013 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2014 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2015 case ELFOSABI_LINUX
: return "UNIX - Linux";
2016 case ELFOSABI_HURD
: return "GNU/Hurd";
2017 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2018 case ELFOSABI_AIX
: return "UNIX - AIX";
2019 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2020 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2021 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2022 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2023 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2024 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2025 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2026 case ELFOSABI_AROS
: return "Amiga Research OS";
2027 case ELFOSABI_STANDALONE
: return _("Standalone App");
2028 case ELFOSABI_ARM
: return "ARM";
2030 sprintf (buff
, _("<unknown: %x>"), osabi
);
2036 get_mips_segment_type (unsigned long type
)
2040 case PT_MIPS_REGINFO
:
2042 case PT_MIPS_RTPROC
:
2044 case PT_MIPS_OPTIONS
:
2054 get_parisc_segment_type (unsigned long type
)
2058 case PT_HP_TLS
: return "HP_TLS";
2059 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2060 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2061 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2062 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2063 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2064 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2065 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2066 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2067 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2068 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2069 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2070 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2071 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2080 get_ia64_segment_type (unsigned long type
)
2084 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2085 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2086 case PT_HP_TLS
: return "HP_TLS";
2087 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2088 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2089 case PT_IA_64_HP_STACK
: return "HP_STACK";
2098 get_segment_type (unsigned long p_type
)
2100 static char buff
[32];
2104 case PT_NULL
: return "NULL";
2105 case PT_LOAD
: return "LOAD";
2106 case PT_DYNAMIC
: return "DYNAMIC";
2107 case PT_INTERP
: return "INTERP";
2108 case PT_NOTE
: return "NOTE";
2109 case PT_SHLIB
: return "SHLIB";
2110 case PT_PHDR
: return "PHDR";
2111 case PT_TLS
: return "TLS";
2113 case PT_GNU_EH_FRAME
:
2114 return "GNU_EH_FRAME";
2115 case PT_GNU_STACK
: return "STACK";
2118 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2122 switch (elf_header
.e_machine
)
2125 case EM_MIPS_RS3_LE
:
2126 result
= get_mips_segment_type (p_type
);
2129 result
= get_parisc_segment_type (p_type
);
2132 result
= get_ia64_segment_type (p_type
);
2142 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2144 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2148 switch (elf_header
.e_machine
)
2151 result
= get_parisc_segment_type (p_type
);
2154 result
= get_ia64_segment_type (p_type
);
2164 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2167 sprintf (buff
, _("<unknown>: %lx"), p_type
);
2174 get_mips_section_type_name (unsigned int sh_type
)
2178 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2179 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2180 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2181 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2182 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2183 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2184 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2185 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2186 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2187 case SHT_MIPS_RELD
: return "MIPS_RELD";
2188 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2189 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2190 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2191 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2192 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2193 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2194 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2195 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2196 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2197 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2198 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2199 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2200 case SHT_MIPS_LINE
: return "MIPS_LINE";
2201 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2202 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2203 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2204 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2205 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2206 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2207 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2208 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2209 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2210 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2211 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2212 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2213 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2214 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2215 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2216 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2224 get_parisc_section_type_name (unsigned int sh_type
)
2228 case SHT_PARISC_EXT
: return "PARISC_EXT";
2229 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2230 case SHT_PARISC_DOC
: return "PARISC_DOC";
2238 get_ia64_section_type_name (unsigned int sh_type
)
2240 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2241 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2242 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2246 case SHT_IA_64_EXT
: return "IA_64_EXT";
2247 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2248 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2256 get_section_type_name (unsigned int sh_type
)
2258 static char buff
[32];
2262 case SHT_NULL
: return "NULL";
2263 case SHT_PROGBITS
: return "PROGBITS";
2264 case SHT_SYMTAB
: return "SYMTAB";
2265 case SHT_STRTAB
: return "STRTAB";
2266 case SHT_RELA
: return "RELA";
2267 case SHT_HASH
: return "HASH";
2268 case SHT_DYNAMIC
: return "DYNAMIC";
2269 case SHT_NOTE
: return "NOTE";
2270 case SHT_NOBITS
: return "NOBITS";
2271 case SHT_REL
: return "REL";
2272 case SHT_SHLIB
: return "SHLIB";
2273 case SHT_DYNSYM
: return "DYNSYM";
2274 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2275 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2276 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2277 case SHT_GROUP
: return "GROUP";
2278 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2279 case SHT_GNU_verdef
: return "VERDEF";
2280 case SHT_GNU_verneed
: return "VERNEED";
2281 case SHT_GNU_versym
: return "VERSYM";
2282 case 0x6ffffff0: return "VERSYM";
2283 case 0x6ffffffc: return "VERDEF";
2284 case 0x7ffffffd: return "AUXILIARY";
2285 case 0x7fffffff: return "FILTER";
2286 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2289 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2293 switch (elf_header
.e_machine
)
2296 case EM_MIPS_RS3_LE
:
2297 result
= get_mips_section_type_name (sh_type
);
2300 result
= get_parisc_section_type_name (sh_type
);
2303 result
= get_ia64_section_type_name (sh_type
);
2313 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2315 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2316 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2317 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2318 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2320 sprintf (buff
, _("<unknown>: %x"), sh_type
);
2326 #define OPTION_DEBUG_DUMP 512
2328 struct option options
[] =
2330 {"all", no_argument
, 0, 'a'},
2331 {"file-header", no_argument
, 0, 'h'},
2332 {"program-headers", no_argument
, 0, 'l'},
2333 {"headers", no_argument
, 0, 'e'},
2334 {"histogram", no_argument
, 0, 'I'},
2335 {"segments", no_argument
, 0, 'l'},
2336 {"sections", no_argument
, 0, 'S'},
2337 {"section-headers", no_argument
, 0, 'S'},
2338 {"symbols", no_argument
, 0, 's'},
2339 {"syms", no_argument
, 0, 's'},
2340 {"relocs", no_argument
, 0, 'r'},
2341 {"notes", no_argument
, 0, 'n'},
2342 {"dynamic", no_argument
, 0, 'd'},
2343 {"arch-specific", no_argument
, 0, 'A'},
2344 {"version-info", no_argument
, 0, 'V'},
2345 {"use-dynamic", no_argument
, 0, 'D'},
2346 {"hex-dump", required_argument
, 0, 'x'},
2347 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2348 {"unwind", no_argument
, 0, 'u'},
2349 #ifdef SUPPORT_DISASSEMBLY
2350 {"instruction-dump", required_argument
, 0, 'i'},
2353 {"version", no_argument
, 0, 'v'},
2354 {"wide", no_argument
, 0, 'W'},
2355 {"help", no_argument
, 0, 'H'},
2356 {0, no_argument
, 0, 0}
2362 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2363 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2364 fprintf (stdout
, _(" Options are:\n\
2365 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2366 -h --file-header Display the ELF file header\n\
2367 -l --program-headers Display the program headers\n\
2368 --segments An alias for --program-headers\n\
2369 -S --section-headers Display the sections' header\n\
2370 --sections An alias for --section-headers\n\
2371 -e --headers Equivalent to: -h -l -S\n\
2372 -s --syms Display the symbol table\n\
2373 --symbols An alias for --syms\n\
2374 -n --notes Display the core notes (if present)\n\
2375 -r --relocs Display the relocations (if present)\n\
2376 -u --unwind Display the unwind info (if present)\n\
2377 -d --dynamic Display the dynamic segment (if present)\n\
2378 -V --version-info Display the version sections (if present)\n\
2379 -A --arch-specific Display architecture specific information (if any).\n\
2380 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2381 -x --hex-dump=<number> Dump the contents of section <number>\n\
2382 -w[liaprmfFso] or\n\
2383 --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
2384 Display the contents of DWARF2 debug sections\n"));
2385 #ifdef SUPPORT_DISASSEMBLY
2386 fprintf (stdout
, _("\
2387 -i --instruction-dump=<number>\n\
2388 Disassemble the contents of section <number>\n"));
2390 fprintf (stdout
, _("\
2391 -I --histogram Display histogram of bucket list lengths\n\
2392 -W --wide Allow output width to exceed 80 characters\n\
2393 -H --help Display this information\n\
2394 -v --version Display the version number of readelf\n"));
2395 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2401 request_dump (unsigned int section
, int type
)
2403 if (section
>= num_dump_sects
)
2405 char *new_dump_sects
;
2407 new_dump_sects
= calloc (section
+ 1, 1);
2409 if (new_dump_sects
== NULL
)
2410 error (_("Out of memory allocating dump request table."));
2413 /* Copy current flag settings. */
2414 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2418 dump_sects
= new_dump_sects
;
2419 num_dump_sects
= section
+ 1;
2424 dump_sects
[section
] |= type
;
2430 parse_args (int argc
, char **argv
)
2437 while ((c
= getopt_long
2438 (argc
, argv
, "ersuahnldSDAIw::x:i:vVWH", options
, NULL
)) != EOF
)
2505 section
= strtoul (optarg
, & cp
, 0);
2506 if (! *cp
&& section
>= 0)
2508 request_dump (section
, HEX_DUMP
);
2518 unsigned int index
= 0;
2522 while (optarg
[index
])
2523 switch (optarg
[index
++])
2532 do_debug_abbrevs
= 1;
2542 do_debug_pubnames
= 1;
2547 do_debug_aranges
= 1;
2551 do_debug_frames_interp
= 1;
2553 do_debug_frames
= 1;
2558 do_debug_macinfo
= 1;
2572 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2577 case OPTION_DEBUG_DUMP
:
2583 static const char *debug_dump_opt
[]
2584 = { "line", "info", "abbrev", "pubnames", "ranges",
2585 "macro", "frames", "frames-interp", "str", "loc", NULL
};
2594 for (index
= 0; debug_dump_opt
[index
]; index
++)
2596 size_t len
= strlen (debug_dump_opt
[index
]);
2598 if (strncmp (p
, debug_dump_opt
[index
], len
) == 0
2599 && (p
[len
] == ',' || p
[len
] == '\0'))
2608 do_debug_abbrevs
= 1;
2619 do_debug_pubnames
= 1;
2623 do_debug_aranges
= 1;
2628 do_debug_frames_interp
= 1;
2629 do_debug_frames
= 1;
2633 do_debug_macinfo
= 1;
2646 if (debug_dump_opt
[index
] == NULL
)
2648 warn (_("Unrecognized debug option '%s'\n"), p
);
2649 p
= strchr (p
, ',');
2659 #ifdef SUPPORT_DISASSEMBLY
2662 section
= strtoul (optarg
, & cp
, 0);
2663 if (! *cp
&& section
>= 0)
2665 request_dump (section
, DISASS_DUMP
);
2671 print_version (program_name
);
2681 /* xgettext:c-format */
2682 error (_("Invalid option '-%c'\n"), c
);
2689 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2690 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2691 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
)
2695 warn (_("Nothing to do.\n"));
2701 get_elf_class (unsigned int elf_class
)
2703 static char buff
[32];
2707 case ELFCLASSNONE
: return _("none");
2708 case ELFCLASS32
: return "ELF32";
2709 case ELFCLASS64
: return "ELF64";
2711 sprintf (buff
, _("<unknown: %x>"), elf_class
);
2717 get_data_encoding (unsigned int encoding
)
2719 static char buff
[32];
2723 case ELFDATANONE
: return _("none");
2724 case ELFDATA2LSB
: return _("2's complement, little endian");
2725 case ELFDATA2MSB
: return _("2's complement, big endian");
2727 sprintf (buff
, _("<unknown: %x>"), encoding
);
2732 /* Decode the data held in 'elf_header'. */
2735 process_file_header (void)
2737 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2738 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2739 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2740 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2743 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2751 printf (_("ELF Header:\n"));
2752 printf (_(" Magic: "));
2753 for (i
= 0; i
< EI_NIDENT
; i
++)
2754 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2756 printf (_(" Class: %s\n"),
2757 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2758 printf (_(" Data: %s\n"),
2759 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2760 printf (_(" Version: %d %s\n"),
2761 elf_header
.e_ident
[EI_VERSION
],
2762 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
2764 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
2767 printf (_(" OS/ABI: %s\n"),
2768 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
2769 printf (_(" ABI Version: %d\n"),
2770 elf_header
.e_ident
[EI_ABIVERSION
]);
2771 printf (_(" Type: %s\n"),
2772 get_file_type (elf_header
.e_type
));
2773 printf (_(" Machine: %s\n"),
2774 get_machine_name (elf_header
.e_machine
));
2775 printf (_(" Version: 0x%lx\n"),
2776 (unsigned long) elf_header
.e_version
);
2778 printf (_(" Entry point address: "));
2779 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2780 printf (_("\n Start of program headers: "));
2781 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2782 printf (_(" (bytes into file)\n Start of section headers: "));
2783 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
2784 printf (_(" (bytes into file)\n"));
2786 printf (_(" Flags: 0x%lx%s\n"),
2787 (unsigned long) elf_header
.e_flags
,
2788 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
2789 printf (_(" Size of this header: %ld (bytes)\n"),
2790 (long) elf_header
.e_ehsize
);
2791 printf (_(" Size of program headers: %ld (bytes)\n"),
2792 (long) elf_header
.e_phentsize
);
2793 printf (_(" Number of program headers: %ld\n"),
2794 (long) elf_header
.e_phnum
);
2795 printf (_(" Size of section headers: %ld (bytes)\n"),
2796 (long) elf_header
.e_shentsize
);
2797 printf (_(" Number of section headers: %ld"),
2798 (long) elf_header
.e_shnum
);
2799 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
2800 printf (" (%ld)", (long) section_headers
[0].sh_size
);
2801 putc ('\n', stdout
);
2802 printf (_(" Section header string table index: %ld"),
2803 (long) elf_header
.e_shstrndx
);
2804 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
2805 printf (" (%ld)", (long) section_headers
[0].sh_link
);
2806 putc ('\n', stdout
);
2809 if (section_headers
!= NULL
)
2811 if (elf_header
.e_shnum
== 0)
2812 elf_header
.e_shnum
= section_headers
[0].sh_size
;
2813 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
2814 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
2815 free (section_headers
);
2816 section_headers
= NULL
;
2824 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
2826 Elf32_External_Phdr
*phdrs
;
2827 Elf32_External_Phdr
*external
;
2828 Elf_Internal_Phdr
*internal
;
2831 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
2832 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2833 _("program headers"));
2837 for (i
= 0, internal
= program_headers
, external
= phdrs
;
2838 i
< elf_header
.e_phnum
;
2839 i
++, internal
++, external
++)
2841 internal
->p_type
= BYTE_GET (external
->p_type
);
2842 internal
->p_offset
= BYTE_GET (external
->p_offset
);
2843 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
2844 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
2845 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
2846 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
2847 internal
->p_flags
= BYTE_GET (external
->p_flags
);
2848 internal
->p_align
= BYTE_GET (external
->p_align
);
2857 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
2859 Elf64_External_Phdr
*phdrs
;
2860 Elf64_External_Phdr
*external
;
2861 Elf_Internal_Phdr
*internal
;
2864 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
2865 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2866 _("program headers"));
2870 for (i
= 0, internal
= program_headers
, external
= phdrs
;
2871 i
< elf_header
.e_phnum
;
2872 i
++, internal
++, external
++)
2874 internal
->p_type
= BYTE_GET (external
->p_type
);
2875 internal
->p_flags
= BYTE_GET (external
->p_flags
);
2876 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
2877 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
2878 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
2879 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
2880 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
2881 internal
->p_align
= BYTE_GET8 (external
->p_align
);
2889 /* Returns 1 if the program headers were read into `program_headers'. */
2892 get_program_headers (FILE *file
)
2894 Elf_Internal_Phdr
*phdrs
;
2896 /* Check cache of prior read. */
2897 if (program_headers
!= NULL
)
2900 phdrs
= malloc (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
2904 error (_("Out of memory\n"));
2909 ? get_32bit_program_headers (file
, phdrs
)
2910 : get_64bit_program_headers (file
, phdrs
))
2912 program_headers
= phdrs
;
2920 /* Returns 1 if the program headers were loaded. */
2923 process_program_headers (FILE *file
)
2925 Elf_Internal_Phdr
*segment
;
2928 if (elf_header
.e_phnum
== 0)
2931 printf (_("\nThere are no program headers in this file.\n"));
2935 if (do_segments
&& !do_header
)
2937 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
2938 printf (_("Entry point "));
2939 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2940 printf (_("\nThere are %d program headers, starting at offset "),
2941 elf_header
.e_phnum
);
2942 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2946 if (! get_program_headers (file
))
2951 if (elf_header
.e_phnum
> 1)
2952 printf (_("\nProgram Headers:\n"));
2954 printf (_("\nProgram Headers:\n"));
2958 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2961 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2965 (_(" Type Offset VirtAddr PhysAddr\n"));
2967 (_(" FileSiz MemSiz Flags Align\n"));
2974 for (i
= 0, segment
= program_headers
;
2975 i
< elf_header
.e_phnum
;
2980 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
2984 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
2985 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
2986 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
2987 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
2988 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
2990 (segment
->p_flags
& PF_R
? 'R' : ' '),
2991 (segment
->p_flags
& PF_W
? 'W' : ' '),
2992 (segment
->p_flags
& PF_X
? 'E' : ' '));
2993 printf ("%#lx", (unsigned long) segment
->p_align
);
2997 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
2998 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3001 print_vma (segment
->p_offset
, FULL_HEX
);
3005 print_vma (segment
->p_vaddr
, FULL_HEX
);
3007 print_vma (segment
->p_paddr
, FULL_HEX
);
3010 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3011 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3014 print_vma (segment
->p_filesz
, FULL_HEX
);
3018 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3019 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3022 print_vma (segment
->p_offset
, FULL_HEX
);
3026 (segment
->p_flags
& PF_R
? 'R' : ' '),
3027 (segment
->p_flags
& PF_W
? 'W' : ' '),
3028 (segment
->p_flags
& PF_X
? 'E' : ' '));
3030 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3031 printf ("%#lx", (unsigned long) segment
->p_align
);
3034 print_vma (segment
->p_align
, PREFIX_HEX
);
3039 print_vma (segment
->p_offset
, FULL_HEX
);
3041 print_vma (segment
->p_vaddr
, FULL_HEX
);
3043 print_vma (segment
->p_paddr
, FULL_HEX
);
3045 print_vma (segment
->p_filesz
, FULL_HEX
);
3047 print_vma (segment
->p_memsz
, FULL_HEX
);
3049 (segment
->p_flags
& PF_R
? 'R' : ' '),
3050 (segment
->p_flags
& PF_W
? 'W' : ' '),
3051 (segment
->p_flags
& PF_X
? 'E' : ' '));
3052 print_vma (segment
->p_align
, HEX
);
3056 switch (segment
->p_type
)
3060 error (_("more than one dynamic segment\n"));
3062 dynamic_addr
= segment
->p_offset
;
3063 dynamic_size
= segment
->p_filesz
;
3067 if (fseek (file
, (long) segment
->p_offset
, SEEK_SET
))
3068 error (_("Unable to find program interpreter name\n"));
3071 program_interpreter
[0] = 0;
3072 fscanf (file
, "%63s", program_interpreter
);
3075 printf (_("\n [Requesting program interpreter: %s]"),
3076 program_interpreter
);
3082 putc ('\n', stdout
);
3085 if (do_segments
&& section_headers
!= NULL
)
3087 printf (_("\n Section to Segment mapping:\n"));
3088 printf (_(" Segment Sections...\n"));
3090 assert (string_table
!= NULL
);
3092 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3095 Elf_Internal_Shdr
*section
;
3097 segment
= program_headers
+ i
;
3098 section
= section_headers
;
3100 printf (" %2.2d ", i
);
3102 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3104 if (section
->sh_size
> 0
3105 /* Compare allocated sections by VMA, unallocated
3106 sections by file offset. */
3107 && (section
->sh_flags
& SHF_ALLOC
3108 ? (section
->sh_addr
>= segment
->p_vaddr
3109 && section
->sh_addr
+ section
->sh_size
3110 <= segment
->p_vaddr
+ segment
->p_memsz
)
3111 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3112 && (section
->sh_offset
+ section
->sh_size
3113 <= segment
->p_offset
+ segment
->p_filesz
))))
3114 printf ("%s ", SECTION_NAME (section
));
3125 /* Find the file offset corresponding to VMA by using the program headers. */
3128 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3130 Elf_Internal_Phdr
*seg
;
3132 if (! get_program_headers (file
))
3134 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3138 for (seg
= program_headers
;
3139 seg
< program_headers
+ elf_header
.e_phnum
;
3142 if (seg
->p_type
!= PT_LOAD
)
3145 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3146 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3147 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3150 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3157 get_32bit_section_headers (FILE *file
, unsigned int num
)
3159 Elf32_External_Shdr
*shdrs
;
3160 Elf_Internal_Shdr
*internal
;
3163 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3164 elf_header
.e_shentsize
* num
, _("section headers"));
3168 section_headers
= malloc (num
* sizeof (Elf_Internal_Shdr
));
3170 if (section_headers
== NULL
)
3172 error (_("Out of memory\n"));
3176 for (i
= 0, internal
= section_headers
;
3180 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3181 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3182 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3183 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3184 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3185 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3186 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3187 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3188 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3189 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3198 get_64bit_section_headers (FILE *file
, unsigned int num
)
3200 Elf64_External_Shdr
*shdrs
;
3201 Elf_Internal_Shdr
*internal
;
3204 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3205 elf_header
.e_shentsize
* num
, _("section headers"));
3209 section_headers
= malloc (num
* sizeof (Elf_Internal_Shdr
));
3211 if (section_headers
== NULL
)
3213 error (_("Out of memory\n"));
3217 for (i
= 0, internal
= section_headers
;
3221 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3222 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3223 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
3224 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
3225 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
3226 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
3227 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3228 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3229 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3230 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3238 static Elf_Internal_Sym
*
3239 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3241 unsigned long number
;
3242 Elf32_External_Sym
*esyms
;
3243 Elf_External_Sym_Shndx
*shndx
;
3244 Elf_Internal_Sym
*isyms
;
3245 Elf_Internal_Sym
*psym
;
3248 esyms
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
3254 if (symtab_shndx_hdr
!= NULL
3255 && (symtab_shndx_hdr
->sh_link
3256 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3258 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3259 symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3267 number
= section
->sh_size
/ section
->sh_entsize
;
3268 isyms
= malloc (number
* sizeof (Elf_Internal_Sym
));
3272 error (_("Out of memory\n"));
3279 for (j
= 0, psym
= isyms
;
3283 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3284 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3285 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3286 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3287 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3289 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3290 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3291 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3301 static Elf_Internal_Sym
*
3302 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3304 unsigned long number
;
3305 Elf64_External_Sym
*esyms
;
3306 Elf_External_Sym_Shndx
*shndx
;
3307 Elf_Internal_Sym
*isyms
;
3308 Elf_Internal_Sym
*psym
;
3311 esyms
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
3317 if (symtab_shndx_hdr
!= NULL
3318 && (symtab_shndx_hdr
->sh_link
3319 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3321 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3322 symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3330 number
= section
->sh_size
/ section
->sh_entsize
;
3331 isyms
= malloc (number
* sizeof (Elf_Internal_Sym
));
3335 error (_("Out of memory\n"));
3342 for (j
= 0, psym
= isyms
;
3346 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3347 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3348 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3349 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3350 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3352 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3353 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
3354 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
3365 get_elf_section_flags (bfd_vma sh_flags
)
3367 static char buff
[32];
3375 flag
= sh_flags
& - sh_flags
;
3380 case SHF_WRITE
: strcat (buff
, "W"); break;
3381 case SHF_ALLOC
: strcat (buff
, "A"); break;
3382 case SHF_EXECINSTR
: strcat (buff
, "X"); break;
3383 case SHF_MERGE
: strcat (buff
, "M"); break;
3384 case SHF_STRINGS
: strcat (buff
, "S"); break;
3385 case SHF_INFO_LINK
: strcat (buff
, "I"); break;
3386 case SHF_LINK_ORDER
: strcat (buff
, "L"); break;
3387 case SHF_OS_NONCONFORMING
: strcat (buff
, "O"); break;
3388 case SHF_GROUP
: strcat (buff
, "G"); break;
3389 case SHF_TLS
: strcat (buff
, "T"); break;
3392 if (flag
& SHF_MASKOS
)
3395 sh_flags
&= ~ SHF_MASKOS
;
3397 else if (flag
& SHF_MASKPROC
)
3400 sh_flags
&= ~ SHF_MASKPROC
;
3412 process_section_headers (FILE *file
)
3414 Elf_Internal_Shdr
*section
;
3417 section_headers
= NULL
;
3419 if (elf_header
.e_shnum
== 0)
3422 printf (_("\nThere are no sections in this file.\n"));
3427 if (do_sections
&& !do_header
)
3428 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3429 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3433 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3436 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3439 /* Read in the string table, so that we have names to display. */
3440 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3442 if (section
->sh_size
!= 0)
3444 string_table
= get_data (NULL
, file
, section
->sh_offset
,
3445 section
->sh_size
, _("string table"));
3447 if (string_table
== NULL
)
3450 string_table_length
= section
->sh_size
;
3453 /* Scan the sections for the dynamic symbol table
3454 and dynamic string table and debug sections. */
3455 dynamic_symbols
= NULL
;
3456 dynamic_strings
= NULL
;
3457 dynamic_syminfo
= NULL
;
3458 symtab_shndx_hdr
= NULL
;
3460 for (i
= 0, section
= section_headers
;
3461 i
< elf_header
.e_shnum
;
3464 char *name
= SECTION_NAME (section
);
3466 if (section
->sh_type
== SHT_DYNSYM
)
3468 if (dynamic_symbols
!= NULL
)
3470 error (_("File contains multiple dynamic symbol tables\n"));
3474 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3475 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3477 else if (section
->sh_type
== SHT_STRTAB
3478 && strcmp (name
, ".dynstr") == 0)
3480 if (dynamic_strings
!= NULL
)
3482 error (_("File contains multiple dynamic string tables\n"));
3486 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
3487 section
->sh_size
, _("dynamic strings"));
3489 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3491 if (symtab_shndx_hdr
!= NULL
)
3493 error (_("File contains multiple symtab shndx tables\n"));
3496 symtab_shndx_hdr
= section
;
3498 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3499 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3500 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3502 && strncmp (name
, ".debug_", 7) == 0)
3507 || (do_debug_info
&& (strcmp (name
, "info") == 0))
3508 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
3509 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
3510 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
3511 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
3512 || (do_debug_frames
&& (strcmp (name
, "frame") == 0))
3513 || (do_debug_macinfo
&& (strcmp (name
, "macinfo") == 0))
3514 || (do_debug_str
&& (strcmp (name
, "str") == 0))
3515 || (do_debug_loc
&& (strcmp (name
, "loc") == 0))
3517 request_dump (i
, DEBUG_DUMP
);
3519 /* linkonce section to be combined with .debug_info at link time. */
3520 else if ((do_debugging
|| do_debug_info
)
3521 && strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
3522 request_dump (i
, DEBUG_DUMP
);
3523 else if (do_debug_frames
&& strcmp (name
, ".eh_frame") == 0)
3524 request_dump (i
, DEBUG_DUMP
);
3530 if (elf_header
.e_shnum
> 1)
3531 printf (_("\nSection Headers:\n"));
3533 printf (_("\nSection Header:\n"));
3537 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3540 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3543 printf (_(" [Nr] Name Type Address Offset\n"));
3544 printf (_(" Size EntSize Flags Link Info Align\n"));
3547 for (i
= 0, section
= section_headers
;
3548 i
< elf_header
.e_shnum
;
3551 printf (" [%2u] %-17.17s %-15.15s ",
3552 SECTION_HEADER_NUM (i
),
3553 SECTION_NAME (section
),
3554 get_section_type_name (section
->sh_type
));
3558 print_vma (section
->sh_addr
, LONG_HEX
);
3560 printf ( " %6.6lx %6.6lx %2.2lx",
3561 (unsigned long) section
->sh_offset
,
3562 (unsigned long) section
->sh_size
,
3563 (unsigned long) section
->sh_entsize
);
3565 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3567 printf ("%2ld %3lx %2ld\n",
3568 (unsigned long) section
->sh_link
,
3569 (unsigned long) section
->sh_info
,
3570 (unsigned long) section
->sh_addralign
);
3574 print_vma (section
->sh_addr
, LONG_HEX
);
3576 if ((long) section
->sh_offset
== section
->sh_offset
)
3577 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
3581 print_vma (section
->sh_offset
, LONG_HEX
);
3584 if ((unsigned long) section
->sh_size
== section
->sh_size
)
3585 printf (" %6.6lx", (unsigned long) section
->sh_size
);
3589 print_vma (section
->sh_size
, LONG_HEX
);
3592 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
3593 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
3597 print_vma (section
->sh_entsize
, LONG_HEX
);
3600 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3602 printf ("%2ld %3lx ",
3603 (unsigned long) section
->sh_link
,
3604 (unsigned long) section
->sh_info
);
3606 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
3607 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
3610 print_vma (section
->sh_addralign
, DEC
);
3617 print_vma (section
->sh_addr
, LONG_HEX
);
3618 if ((long) section
->sh_offset
== section
->sh_offset
)
3619 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
3623 print_vma (section
->sh_offset
, LONG_HEX
);
3626 print_vma (section
->sh_size
, LONG_HEX
);
3628 print_vma (section
->sh_entsize
, LONG_HEX
);
3630 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3632 printf (" %2ld %3lx %ld\n",
3633 (unsigned long) section
->sh_link
,
3634 (unsigned long) section
->sh_info
,
3635 (unsigned long) section
->sh_addralign
);
3639 printf (_("Key to Flags:\n\
3640 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3641 I (info), L (link order), G (group), x (unknown)\n\
3642 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3653 } dynamic_relocations
[] =
3655 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
3656 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
3657 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
3660 /* Process the reloc section. */
3662 process_relocs (FILE *file
)
3664 unsigned long rel_size
;
3665 unsigned long rel_offset
;
3671 if (do_using_dynamic
)
3675 int has_dynamic_reloc
;
3678 has_dynamic_reloc
= 0;
3680 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
3682 is_rela
= dynamic_relocations
[i
].rela
;
3683 name
= dynamic_relocations
[i
].name
;
3684 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
3685 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
3687 has_dynamic_reloc
|= rel_size
;
3689 if (is_rela
== UNKNOWN
)
3691 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
3692 switch (dynamic_info
[DT_PLTREL
])
3706 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
3707 name
, rel_offset
, rel_size
);
3709 dump_relocations (file
,
3710 offset_from_vma (file
, rel_offset
, rel_size
),
3712 dynamic_symbols
, num_dynamic_syms
,
3713 dynamic_strings
, is_rela
);
3717 if (! has_dynamic_reloc
)
3718 printf (_("\nThere are no dynamic relocations in this file.\n"));
3722 Elf_Internal_Shdr
*section
;
3726 for (i
= 0, section
= section_headers
;
3727 i
< elf_header
.e_shnum
;
3730 if ( section
->sh_type
!= SHT_RELA
3731 && section
->sh_type
!= SHT_REL
)
3734 rel_offset
= section
->sh_offset
;
3735 rel_size
= section
->sh_size
;
3739 Elf_Internal_Shdr
*strsec
;
3740 Elf_Internal_Sym
*symtab
;
3743 unsigned long nsyms
;
3745 printf (_("\nRelocation section "));
3747 if (string_table
== NULL
)
3748 printf ("%d", section
->sh_name
);
3750 printf (_("'%s'"), SECTION_NAME (section
));
3752 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3753 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
3758 if (section
->sh_link
)
3760 Elf_Internal_Shdr
*symsec
;
3762 symsec
= SECTION_HEADER (section
->sh_link
);
3763 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
3764 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
3769 strsec
= SECTION_HEADER (symsec
->sh_link
);
3771 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
3772 strsec
->sh_size
, _("string table"));
3774 is_rela
= section
->sh_type
== SHT_RELA
;
3776 dump_relocations (file
, rel_offset
, rel_size
,
3777 symtab
, nsyms
, strtab
, is_rela
);
3789 printf (_("\nThere are no relocations in this file.\n"));
3795 #include "unwind-ia64.h"
3797 /* An absolute address consists of a section and an offset. If the
3798 section is NULL, the offset itself is the address, otherwise, the
3799 address equals to LOAD_ADDRESS(section) + offset. */
3803 unsigned short section
;
3809 struct unw_table_entry
3811 struct absaddr start
;
3813 struct absaddr info
;
3815 *table
; /* Unwind table. */
3816 unsigned long table_len
; /* Length of unwind table. */
3817 unsigned char *info
; /* Unwind info. */
3818 unsigned long info_size
; /* Size of unwind info. */
3819 bfd_vma info_addr
; /* starting address of unwind info. */
3820 bfd_vma seg_base
; /* Starting address of segment. */
3821 Elf_Internal_Sym
*symtab
; /* The symbol table. */
3822 unsigned long nsyms
; /* Number of symbols. */
3823 char *strtab
; /* The string table. */
3824 unsigned long strtab_size
; /* Size of string table. */
3828 find_symbol_for_address (struct unw_aux_info
*aux
,
3829 struct absaddr addr
,
3830 const char **symname
,
3833 bfd_vma dist
= 0x100000;
3834 Elf_Internal_Sym
*sym
, *best
= NULL
;
3837 for (i
= 0, sym
= aux
->symtab
; i
< aux
->nsyms
; ++i
, ++sym
)
3839 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
3840 && sym
->st_name
!= 0
3841 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
3842 && addr
.offset
>= sym
->st_value
3843 && addr
.offset
- sym
->st_value
< dist
)
3846 dist
= addr
.offset
- sym
->st_value
;
3853 *symname
= (best
->st_name
>= aux
->strtab_size
3854 ? "<corrupt>" : aux
->strtab
+ best
->st_name
);
3859 *offset
= addr
.offset
;
3863 dump_ia64_unwind (struct unw_aux_info
*aux
)
3866 struct unw_table_entry
*tp
;
3869 addr_size
= is_32bit_elf
? 4 : 8;
3871 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
3875 const unsigned char *dp
;
3876 const unsigned char *head
;
3877 const char *procname
;
3879 find_symbol_for_address (aux
, tp
->start
, &procname
, &offset
);
3881 fputs ("\n<", stdout
);
3885 fputs (procname
, stdout
);
3888 printf ("+%lx", (unsigned long) offset
);
3891 fputs (">: [", stdout
);
3892 print_vma (tp
->start
.offset
, PREFIX_HEX
);
3893 fputc ('-', stdout
);
3894 print_vma (tp
->end
.offset
, PREFIX_HEX
);
3895 printf ("], info at +0x%lx\n",
3896 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
3898 head
= aux
->info
+ (tp
->info
.offset
- aux
->info_addr
);
3899 stamp
= BYTE_GET8 ((unsigned char *) head
);
3901 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
3902 (unsigned) UNW_VER (stamp
),
3903 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
3904 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
3905 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
3906 (unsigned long) (addr_size
* UNW_LENGTH (stamp
)));
3908 if (UNW_VER (stamp
) != 1)
3910 printf ("\tUnknown version.\n");
3915 for (dp
= head
+ 8; dp
< head
+ 8 + addr_size
* UNW_LENGTH (stamp
);)
3916 dp
= unw_decode (dp
, in_body
, & in_body
);
3921 slurp_ia64_unwind_table (FILE *file
,
3922 struct unw_aux_info
*aux
,
3923 Elf_Internal_Shdr
*sec
)
3925 unsigned long size
, addr_size
, nrelas
, i
;
3926 Elf_Internal_Phdr
*seg
;
3927 struct unw_table_entry
*tep
;
3928 Elf_Internal_Shdr
*relsec
;
3929 Elf_Internal_Rela
*rela
, *rp
;
3930 unsigned char *table
, *tp
;
3931 Elf_Internal_Sym
*sym
;
3932 const char *relname
;
3934 addr_size
= is_32bit_elf
? 4 : 8;
3936 /* First, find the starting address of the segment that includes
3939 if (elf_header
.e_phnum
)
3941 if (! get_program_headers (file
))
3944 for (seg
= program_headers
;
3945 seg
< program_headers
+ elf_header
.e_phnum
;
3948 if (seg
->p_type
!= PT_LOAD
)
3951 if (sec
->sh_addr
>= seg
->p_vaddr
3952 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
3954 aux
->seg_base
= seg
->p_vaddr
;
3960 /* Second, build the unwind table from the contents of the unwind section: */
3961 size
= sec
->sh_size
;
3962 table
= get_data (NULL
, file
, sec
->sh_offset
, size
, _("unwind table"));
3966 tep
= aux
->table
= xmalloc (size
/ (3 * addr_size
) * sizeof (aux
->table
[0]));
3967 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * addr_size
, ++tep
)
3969 tep
->start
.section
= SHN_UNDEF
;
3970 tep
->end
.section
= SHN_UNDEF
;
3971 tep
->info
.section
= SHN_UNDEF
;
3974 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
3975 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
3976 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
3980 tep
->start
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 0);
3981 tep
->end
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 8);
3982 tep
->info
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 16);
3984 tep
->start
.offset
+= aux
->seg_base
;
3985 tep
->end
.offset
+= aux
->seg_base
;
3986 tep
->info
.offset
+= aux
->seg_base
;
3990 /* Third, apply any relocations to the unwind table: */
3992 for (relsec
= section_headers
;
3993 relsec
< section_headers
+ elf_header
.e_shnum
;
3996 if (relsec
->sh_type
!= SHT_RELA
3997 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4000 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4004 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4008 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4009 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4011 if (ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4013 warn (_("Skipping unexpected symbol type %u\n"),
4014 ELF32_ST_TYPE (sym
->st_info
));
4020 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4021 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4023 if (ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4025 warn (_("Skipping unexpected symbol type %u\n"),
4026 ELF64_ST_TYPE (sym
->st_info
));
4031 if (strncmp (relname
, "R_IA64_SEGREL", 13) != 0)
4033 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4037 i
= rp
->r_offset
/ (3 * addr_size
);
4039 switch (rp
->r_offset
/addr_size
% 3)
4042 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4043 aux
->table
[i
].start
.offset
+= rp
->r_addend
;
4046 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4047 aux
->table
[i
].end
.offset
+= rp
->r_addend
;
4050 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4051 aux
->table
[i
].info
.offset
+= rp
->r_addend
;
4061 aux
->table_len
= size
/ (3 * addr_size
);
4066 process_unwind (FILE *file
)
4068 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4069 unsigned long i
, addr_size
, unwcount
= 0, unwstart
= 0;
4070 struct unw_aux_info aux
;
4075 if (elf_header
.e_machine
!= EM_IA_64
)
4077 printf (_("\nThere are no unwind sections in this file.\n"));
4081 memset (& aux
, 0, sizeof (aux
));
4083 addr_size
= is_32bit_elf
? 4 : 8;
4085 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4087 if (sec
->sh_type
== SHT_SYMTAB
)
4089 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4090 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4092 strsec
= SECTION_HEADER (sec
->sh_link
);
4093 aux
.strtab_size
= strsec
->sh_size
;
4094 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4095 aux
.strtab_size
, _("string table"));
4097 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4102 printf (_("\nThere are no unwind sections in this file.\n"));
4104 while (unwcount
-- > 0)
4109 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4110 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4111 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4118 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4120 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
,
4123 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
4124 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4125 suffix
= SECTION_NAME (unwsec
) + len
;
4126 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4128 if (strncmp (SECTION_NAME (sec
),
4129 ELF_STRING_ia64_unwind_info_once
, len2
) == 0
4130 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4135 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4136 .IA_64.unwind or BAR -> .IA_64.unwind_info */
4137 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4138 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4140 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
,
4142 suffix
= SECTION_NAME (unwsec
) + len
;
4143 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4145 if (strncmp (SECTION_NAME (sec
),
4146 ELF_STRING_ia64_unwind_info
, len2
) == 0
4147 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4151 if (i
== elf_header
.e_shnum
)
4153 printf (_("\nCould not find unwind info section for "));
4155 if (string_table
== NULL
)
4156 printf ("%d", unwsec
->sh_name
);
4158 printf (_("'%s'"), SECTION_NAME (unwsec
));
4162 aux
.info_size
= sec
->sh_size
;
4163 aux
.info_addr
= sec
->sh_addr
;
4164 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, aux
.info_size
,
4167 printf (_("\nUnwind section "));
4169 if (string_table
== NULL
)
4170 printf ("%d", unwsec
->sh_name
);
4172 printf (_("'%s'"), SECTION_NAME (unwsec
));
4174 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4175 (unsigned long) unwsec
->sh_offset
,
4176 (unsigned long) (unwsec
->sh_size
/ (3 * addr_size
)));
4178 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4180 if (aux
.table_len
> 0)
4181 dump_ia64_unwind (& aux
);
4184 free ((char *) aux
.table
);
4186 free ((char *) aux
.info
);
4195 free ((char *) aux
.strtab
);
4201 dynamic_segment_mips_val (Elf_Internal_Dyn
*entry
)
4203 switch (entry
->d_tag
)
4206 if (entry
->d_un
.d_val
== 0)
4210 static const char * opts
[] =
4212 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
4213 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
4214 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
4215 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
4220 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
4221 if (entry
->d_un
.d_val
& (1 << cnt
))
4223 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
4230 case DT_MIPS_IVERSION
:
4231 if (dynamic_strings
!= NULL
)
4232 printf ("Interface Version: %s\n",
4233 dynamic_strings
+ entry
->d_un
.d_val
);
4235 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4238 case DT_MIPS_TIME_STAMP
:
4243 time_t time
= entry
->d_un
.d_val
;
4244 tmp
= gmtime (&time
);
4245 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
4246 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
4247 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
4248 printf ("Time Stamp: %s\n", timebuf
);
4252 case DT_MIPS_RLD_VERSION
:
4253 case DT_MIPS_LOCAL_GOTNO
:
4254 case DT_MIPS_CONFLICTNO
:
4255 case DT_MIPS_LIBLISTNO
:
4256 case DT_MIPS_SYMTABNO
:
4257 case DT_MIPS_UNREFEXTNO
:
4258 case DT_MIPS_HIPAGENO
:
4259 case DT_MIPS_DELTA_CLASS_NO
:
4260 case DT_MIPS_DELTA_INSTANCE_NO
:
4261 case DT_MIPS_DELTA_RELOC_NO
:
4262 case DT_MIPS_DELTA_SYM_NO
:
4263 case DT_MIPS_DELTA_CLASSSYM_NO
:
4264 case DT_MIPS_COMPACT_SIZE
:
4265 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4269 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
4275 dynamic_segment_parisc_val (Elf_Internal_Dyn
*entry
)
4277 switch (entry
->d_tag
)
4279 case DT_HP_DLD_FLAGS
:
4288 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
4289 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
4290 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
4291 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
4292 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
4293 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
4294 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
4295 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
4296 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
4297 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
4298 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" }
4302 bfd_vma val
= entry
->d_un
.d_val
;
4304 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
4305 if (val
& flags
[cnt
].bit
)
4309 fputs (flags
[cnt
].str
, stdout
);
4311 val
^= flags
[cnt
].bit
;
4314 if (val
!= 0 || first
)
4318 print_vma (val
, HEX
);
4324 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4331 dynamic_segment_ia64_val (Elf_Internal_Dyn
*entry
)
4333 switch (entry
->d_tag
)
4335 case DT_IA_64_PLT_RESERVE
:
4336 /* First 3 slots reserved. */
4337 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4339 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
4343 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4350 get_32bit_dynamic_segment (FILE *file
)
4352 Elf32_External_Dyn
*edyn
;
4353 Elf_Internal_Dyn
*entry
;
4356 edyn
= get_data (NULL
, file
, dynamic_addr
, dynamic_size
,
4357 _("dynamic segment"));
4361 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4362 how large this .dynamic is now. We can do this even before the byte
4363 swapping since the DT_NULL tag is recognizable. */
4365 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4368 dynamic_segment
= malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4370 if (dynamic_segment
== NULL
)
4372 error (_("Out of memory\n"));
4377 for (i
= 0, entry
= dynamic_segment
;
4381 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
4382 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
4391 get_64bit_dynamic_segment (FILE *file
)
4393 Elf64_External_Dyn
*edyn
;
4394 Elf_Internal_Dyn
*entry
;
4397 edyn
= get_data (NULL
, file
, dynamic_addr
, dynamic_size
,
4398 _("dynamic segment"));
4402 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4403 how large this .dynamic is now. We can do this even before the byte
4404 swapping since the DT_NULL tag is recognizable. */
4406 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4409 dynamic_segment
= malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4411 if (dynamic_segment
== NULL
)
4413 error (_("Out of memory\n"));
4418 for (i
= 0, entry
= dynamic_segment
;
4422 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
4423 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
4432 get_dynamic_flags (bfd_vma flags
)
4434 static char buff
[128];
4442 flag
= flags
& - flags
;
4450 case DF_ORIGIN
: strcpy (p
, "ORIGIN"); break;
4451 case DF_SYMBOLIC
: strcpy (p
, "SYMBOLIC"); break;
4452 case DF_TEXTREL
: strcpy (p
, "TEXTREL"); break;
4453 case DF_BIND_NOW
: strcpy (p
, "BIND_NOW"); break;
4454 case DF_STATIC_TLS
: strcpy (p
, "STATIC_TLS"); break;
4455 default: strcpy (p
, "unknown"); break;
4458 p
= strchr (p
, '\0');
4463 /* Parse and display the contents of the dynamic segment. */
4465 process_dynamic_segment (FILE *file
)
4467 Elf_Internal_Dyn
*entry
;
4470 if (dynamic_size
== 0)
4473 printf (_("\nThere is no dynamic segment in this file.\n"));
4480 if (! get_32bit_dynamic_segment (file
))
4483 else if (! get_64bit_dynamic_segment (file
))
4486 /* Find the appropriate symbol table. */
4487 if (dynamic_symbols
== NULL
)
4489 for (i
= 0, entry
= dynamic_segment
;
4493 Elf_Internal_Shdr section
;
4495 if (entry
->d_tag
!= DT_SYMTAB
)
4498 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
4500 /* Since we do not know how big the symbol table is,
4501 we default to reading in the entire file (!) and
4502 processing that. This is overkill, I know, but it
4504 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
4506 if (fseek (file
, 0, SEEK_END
))
4507 error (_("Unable to seek to end of file!"));
4509 section
.sh_size
= ftell (file
) - section
.sh_offset
;
4511 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
4513 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
4515 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
4516 if (num_dynamic_syms
< 1)
4518 error (_("Unable to determine the number of symbols to load\n"));
4522 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
4526 /* Similarly find a string table. */
4527 if (dynamic_strings
== NULL
)
4529 for (i
= 0, entry
= dynamic_segment
;
4533 unsigned long offset
;
4536 if (entry
->d_tag
!= DT_STRTAB
)
4539 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
4541 /* Since we do not know how big the string table is,
4542 we default to reading in the entire file (!) and
4543 processing that. This is overkill, I know, but it
4546 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
4547 if (fseek (file
, 0, SEEK_END
))
4548 error (_("Unable to seek to end of file\n"));
4549 str_tab_len
= ftell (file
) - offset
;
4551 if (str_tab_len
< 1)
4554 (_("Unable to determine the length of the dynamic string table\n"));
4558 dynamic_strings
= get_data (NULL
, file
, offset
, str_tab_len
,
4559 _("dynamic string table"));
4564 /* And find the syminfo section if available. */
4565 if (dynamic_syminfo
== NULL
)
4567 unsigned long syminsz
= 0;
4569 for (i
= 0, entry
= dynamic_segment
;
4573 if (entry
->d_tag
== DT_SYMINENT
)
4575 /* Note: these braces are necessary to avoid a syntax
4576 error from the SunOS4 C compiler. */
4577 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
4579 else if (entry
->d_tag
== DT_SYMINSZ
)
4580 syminsz
= entry
->d_un
.d_val
;
4581 else if (entry
->d_tag
== DT_SYMINFO
)
4582 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
4586 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
4588 Elf_External_Syminfo
*extsyminfo
;
4589 Elf_Internal_Syminfo
*syminfo
;
4591 /* There is a syminfo section. Read the data. */
4592 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, syminsz
,
4593 _("symbol information"));
4597 dynamic_syminfo
= malloc (syminsz
);
4598 if (dynamic_syminfo
== NULL
)
4600 error (_("Out of memory\n"));
4604 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
4605 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
4608 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
4609 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
4616 if (do_dynamic
&& dynamic_addr
)
4617 printf (_("\nDynamic segment at offset 0x%lx contains %ld entries:\n"),
4618 dynamic_addr
, (long) dynamic_size
);
4620 printf (_(" Tag Type Name/Value\n"));
4622 for (i
= 0, entry
= dynamic_segment
;
4631 print_vma (entry
->d_tag
, FULL_HEX
);
4632 dtype
= get_dynamic_type (entry
->d_tag
);
4633 printf (" (%s)%*s", dtype
,
4634 ((is_32bit_elf
? 27 : 19)
4635 - (int) strlen (dtype
)),
4639 switch (entry
->d_tag
)
4643 puts (get_dynamic_flags (entry
->d_un
.d_val
));
4653 switch (entry
->d_tag
)
4656 printf (_("Auxiliary library"));
4660 printf (_("Filter library"));
4664 printf (_("Configuration file"));
4668 printf (_("Dependency audit library"));
4672 printf (_("Audit library"));
4676 if (dynamic_strings
)
4677 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
4681 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4690 printf (_("Flags:"));
4692 if (entry
->d_un
.d_val
== 0)
4693 printf (_(" None\n"));
4696 unsigned long int val
= entry
->d_un
.d_val
;
4698 if (val
& DTF_1_PARINIT
)
4700 printf (" PARINIT");
4701 val
^= DTF_1_PARINIT
;
4703 if (val
& DTF_1_CONFEXP
)
4705 printf (" CONFEXP");
4706 val
^= DTF_1_CONFEXP
;
4709 printf (" %lx", val
);
4718 printf (_("Flags:"));
4720 if (entry
->d_un
.d_val
== 0)
4721 printf (_(" None\n"));
4724 unsigned long int val
= entry
->d_un
.d_val
;
4726 if (val
& DF_P1_LAZYLOAD
)
4728 printf (" LAZYLOAD");
4729 val
^= DF_P1_LAZYLOAD
;
4731 if (val
& DF_P1_GROUPPERM
)
4733 printf (" GROUPPERM");
4734 val
^= DF_P1_GROUPPERM
;
4737 printf (" %lx", val
);
4746 printf (_("Flags:"));
4747 if (entry
->d_un
.d_val
== 0)
4748 printf (_(" None\n"));
4751 unsigned long int val
= entry
->d_un
.d_val
;
4758 if (val
& DF_1_GLOBAL
)
4763 if (val
& DF_1_GROUP
)
4768 if (val
& DF_1_NODELETE
)
4770 printf (" NODELETE");
4771 val
^= DF_1_NODELETE
;
4773 if (val
& DF_1_LOADFLTR
)
4775 printf (" LOADFLTR");
4776 val
^= DF_1_LOADFLTR
;
4778 if (val
& DF_1_INITFIRST
)
4780 printf (" INITFIRST");
4781 val
^= DF_1_INITFIRST
;
4783 if (val
& DF_1_NOOPEN
)
4788 if (val
& DF_1_ORIGIN
)
4793 if (val
& DF_1_DIRECT
)
4798 if (val
& DF_1_TRANS
)
4803 if (val
& DF_1_INTERPOSE
)
4805 printf (" INTERPOSE");
4806 val
^= DF_1_INTERPOSE
;
4808 if (val
& DF_1_NODEFLIB
)
4810 printf (" NODEFLIB");
4811 val
^= DF_1_NODEFLIB
;
4813 if (val
& DF_1_NODUMP
)
4818 if (val
& DF_1_CONLFAT
)
4820 printf (" CONLFAT");
4821 val
^= DF_1_CONLFAT
;
4824 printf (" %lx", val
);
4831 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
4833 puts (get_dynamic_type (entry
->d_un
.d_val
));
4853 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
4859 if (dynamic_strings
== NULL
)
4862 name
= dynamic_strings
+ entry
->d_un
.d_val
;
4866 switch (entry
->d_tag
)
4869 printf (_("Shared library: [%s]"), name
);
4871 if (strcmp (name
, program_interpreter
) == 0)
4872 printf (_(" program interpreter"));
4876 printf (_("Library soname: [%s]"), name
);
4880 printf (_("Library rpath: [%s]"), name
);
4884 printf (_("Library runpath: [%s]"), name
);
4888 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4893 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4906 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
4910 case DT_INIT_ARRAYSZ
:
4911 case DT_FINI_ARRAYSZ
:
4912 case DT_GNU_CONFLICTSZ
:
4913 case DT_GNU_LIBLISTSZ
:
4916 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
4917 printf (" (bytes)\n");
4927 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
4940 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
4944 name
= dynamic_strings
+ entry
->d_un
.d_val
;
4948 printf (_("Not needed object: [%s]\n"), name
);
4953 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4959 /* The value of this entry is ignored. */
4964 case DT_GNU_PRELINKED
:
4968 time_t time
= entry
->d_un
.d_val
;
4970 tmp
= gmtime (&time
);
4971 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
4972 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
4973 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
4979 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
4980 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
4985 switch (elf_header
.e_machine
)
4988 case EM_MIPS_RS3_LE
:
4989 dynamic_segment_mips_val (entry
);
4992 dynamic_segment_parisc_val (entry
);
4995 dynamic_segment_ia64_val (entry
);
4998 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5010 get_ver_flags (unsigned int flags
)
5012 static char buff
[32];
5019 if (flags
& VER_FLG_BASE
)
5020 strcat (buff
, "BASE ");
5022 if (flags
& VER_FLG_WEAK
)
5024 if (flags
& VER_FLG_BASE
)
5025 strcat (buff
, "| ");
5027 strcat (buff
, "WEAK ");
5030 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
5031 strcat (buff
, "| <unknown>");
5036 /* Display the contents of the version sections. */
5038 process_version_sections (FILE *file
)
5040 Elf_Internal_Shdr
*section
;
5047 for (i
= 0, section
= section_headers
;
5048 i
< elf_header
.e_shnum
;
5051 switch (section
->sh_type
)
5053 case SHT_GNU_verdef
:
5055 Elf_External_Verdef
*edefs
;
5062 (_("\nVersion definition section '%s' contains %ld entries:\n"),
5063 SECTION_NAME (section
), section
->sh_info
);
5065 printf (_(" Addr: 0x"));
5066 printf_vma (section
->sh_addr
);
5067 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5068 (unsigned long) section
->sh_offset
, section
->sh_link
,
5069 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5071 edefs
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
5072 _("version definition section"));
5076 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5079 Elf_External_Verdef
*edef
;
5080 Elf_Internal_Verdef ent
;
5081 Elf_External_Verdaux
*eaux
;
5082 Elf_Internal_Verdaux aux
;
5086 vstart
= ((char *) edefs
) + idx
;
5088 edef
= (Elf_External_Verdef
*) vstart
;
5090 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
5091 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
5092 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
5093 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
5094 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
5095 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
5096 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
5098 printf (_(" %#06x: Rev: %d Flags: %s"),
5099 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
5101 printf (_(" Index: %d Cnt: %d "),
5102 ent
.vd_ndx
, ent
.vd_cnt
);
5104 vstart
+= ent
.vd_aux
;
5106 eaux
= (Elf_External_Verdaux
*) vstart
;
5108 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5109 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5111 if (dynamic_strings
)
5112 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
5114 printf (_("Name index: %ld\n"), aux
.vda_name
);
5116 isum
= idx
+ ent
.vd_aux
;
5118 for (j
= 1; j
< ent
.vd_cnt
; j
++)
5120 isum
+= aux
.vda_next
;
5121 vstart
+= aux
.vda_next
;
5123 eaux
= (Elf_External_Verdaux
*) vstart
;
5125 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5126 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5128 if (dynamic_strings
)
5129 printf (_(" %#06x: Parent %d: %s\n"),
5130 isum
, j
, dynamic_strings
+ aux
.vda_name
);
5132 printf (_(" %#06x: Parent %d, name index: %ld\n"),
5133 isum
, j
, aux
.vda_name
);
5143 case SHT_GNU_verneed
:
5145 Elf_External_Verneed
*eneed
;
5151 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
5152 SECTION_NAME (section
), section
->sh_info
);
5154 printf (_(" Addr: 0x"));
5155 printf_vma (section
->sh_addr
);
5156 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
5157 (unsigned long) section
->sh_offset
, section
->sh_link
,
5158 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5160 eneed
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
5161 _("version need section"));
5165 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5167 Elf_External_Verneed
*entry
;
5168 Elf_Internal_Verneed ent
;
5173 vstart
= ((char *) eneed
) + idx
;
5175 entry
= (Elf_External_Verneed
*) vstart
;
5177 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
5178 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
5179 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
5180 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
5181 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
5183 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
5185 if (dynamic_strings
)
5186 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
5188 printf (_(" File: %lx"), ent
.vn_file
);
5190 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
5192 vstart
+= ent
.vn_aux
;
5194 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
5196 Elf_External_Vernaux
*eaux
;
5197 Elf_Internal_Vernaux aux
;
5199 eaux
= (Elf_External_Vernaux
*) vstart
;
5201 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
5202 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
5203 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
5204 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
5205 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
5207 if (dynamic_strings
)
5208 printf (_(" %#06x: Name: %s"),
5209 isum
, dynamic_strings
+ aux
.vna_name
);
5211 printf (_(" %#06x: Name index: %lx"),
5212 isum
, aux
.vna_name
);
5214 printf (_(" Flags: %s Version: %d\n"),
5215 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
5217 isum
+= aux
.vna_next
;
5218 vstart
+= aux
.vna_next
;
5228 case SHT_GNU_versym
:
5230 Elf_Internal_Shdr
*link_section
;
5233 unsigned char *edata
;
5234 unsigned short *data
;
5236 Elf_Internal_Sym
*symbols
;
5237 Elf_Internal_Shdr
*string_sec
;
5240 link_section
= SECTION_HEADER (section
->sh_link
);
5241 total
= section
->sh_size
/ section
->sh_entsize
;
5245 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
5247 string_sec
= SECTION_HEADER (link_section
->sh_link
);
5249 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
5250 string_sec
->sh_size
, _("version string table"));
5254 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
5255 SECTION_NAME (section
), total
);
5257 printf (_(" Addr: "));
5258 printf_vma (section
->sh_addr
);
5259 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5260 (unsigned long) section
->sh_offset
, section
->sh_link
,
5261 SECTION_NAME (link_section
));
5263 off
= offset_from_vma (file
,
5264 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
5265 total
* sizeof (short));
5266 edata
= get_data (NULL
, file
, off
, total
* sizeof (short),
5267 _("version symbol data"));
5274 data
= malloc (total
* sizeof (short));
5276 for (cnt
= total
; cnt
--;)
5277 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
5282 for (cnt
= 0; cnt
< total
; cnt
+= 4)
5285 int check_def
, check_need
;
5288 printf (" %03x:", cnt
);
5290 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
5291 switch (data
[cnt
+ j
])
5294 fputs (_(" 0 (*local*) "), stdout
);
5298 fputs (_(" 1 (*global*) "), stdout
);
5302 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
5303 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
5307 if (SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
5310 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
5317 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
5319 Elf_Internal_Verneed ivn
;
5320 unsigned long offset
;
5322 offset
= offset_from_vma
5323 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
5324 sizeof (Elf_External_Verneed
));
5328 Elf_Internal_Vernaux ivna
;
5329 Elf_External_Verneed evn
;
5330 Elf_External_Vernaux evna
;
5331 unsigned long a_off
;
5333 get_data (&evn
, file
, offset
, sizeof (evn
),
5336 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5337 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5339 a_off
= offset
+ ivn
.vn_aux
;
5343 get_data (&evna
, file
, a_off
, sizeof (evna
),
5344 _("version need aux (2)"));
5346 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5347 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5349 a_off
+= ivna
.vna_next
;
5351 while (ivna
.vna_other
!= data
[cnt
+ j
]
5352 && ivna
.vna_next
!= 0);
5354 if (ivna
.vna_other
== data
[cnt
+ j
])
5356 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5358 name
= strtab
+ ivna
.vna_name
;
5359 nn
+= printf ("(%s%-*s",
5361 12 - (int) strlen (name
),
5367 offset
+= ivn
.vn_next
;
5369 while (ivn
.vn_next
);
5372 if (check_def
&& data
[cnt
+ j
] != 0x8001
5373 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5375 Elf_Internal_Verdef ivd
;
5376 Elf_External_Verdef evd
;
5377 unsigned long offset
;
5379 offset
= offset_from_vma
5380 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
5385 get_data (&evd
, file
, offset
, sizeof (evd
),
5388 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
5389 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
5391 offset
+= ivd
.vd_next
;
5393 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
5394 && ivd
.vd_next
!= 0);
5396 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
5398 Elf_External_Verdaux evda
;
5399 Elf_Internal_Verdaux ivda
;
5401 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
5403 get_data (&evda
, file
,
5404 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
5405 sizeof (evda
), _("version def aux"));
5407 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
5409 name
= strtab
+ ivda
.vda_name
;
5410 nn
+= printf ("(%s%-*s",
5412 12 - (int) strlen (name
),
5418 printf ("%*c", 18 - nn
, ' ');
5436 printf (_("\nNo version information found in this file.\n"));
5442 get_symbol_binding (unsigned int binding
)
5444 static char buff
[32];
5448 case STB_LOCAL
: return "LOCAL";
5449 case STB_GLOBAL
: return "GLOBAL";
5450 case STB_WEAK
: return "WEAK";
5452 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
5453 sprintf (buff
, _("<processor specific>: %d"), binding
);
5454 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
5455 sprintf (buff
, _("<OS specific>: %d"), binding
);
5457 sprintf (buff
, _("<unknown>: %d"), binding
);
5463 get_symbol_type (unsigned int type
)
5465 static char buff
[32];
5469 case STT_NOTYPE
: return "NOTYPE";
5470 case STT_OBJECT
: return "OBJECT";
5471 case STT_FUNC
: return "FUNC";
5472 case STT_SECTION
: return "SECTION";
5473 case STT_FILE
: return "FILE";
5474 case STT_COMMON
: return "COMMON";
5475 case STT_TLS
: return "TLS";
5477 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
5479 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
5480 return "THUMB_FUNC";
5482 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
5485 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
5486 return "PARISC_MILLI";
5488 sprintf (buff
, _("<processor specific>: %d"), type
);
5490 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
5492 if (elf_header
.e_machine
== EM_PARISC
)
5494 if (type
== STT_HP_OPAQUE
)
5496 if (type
== STT_HP_STUB
)
5500 sprintf (buff
, _("<OS specific>: %d"), type
);
5503 sprintf (buff
, _("<unknown>: %d"), type
);
5509 get_symbol_visibility (unsigned int visibility
)
5513 case STV_DEFAULT
: return "DEFAULT";
5514 case STV_INTERNAL
: return "INTERNAL";
5515 case STV_HIDDEN
: return "HIDDEN";
5516 case STV_PROTECTED
: return "PROTECTED";
5522 get_symbol_index_type (unsigned int type
)
5524 static char buff
[32];
5528 case SHN_UNDEF
: return "UND";
5529 case SHN_ABS
: return "ABS";
5530 case SHN_COMMON
: return "COM";
5532 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
5533 sprintf (buff
, "PRC[0x%04x]", type
);
5534 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
5535 sprintf (buff
, "OS [0x%04x]", type
);
5536 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
5537 sprintf (buff
, "RSV[0x%04x]", type
);
5539 sprintf (buff
, "%3d", type
);
5547 get_dynamic_data (FILE *file
, unsigned int number
)
5549 unsigned char *e_data
;
5552 e_data
= malloc (number
* 4);
5556 error (_("Out of memory\n"));
5560 if (fread (e_data
, 4, number
, file
) != number
)
5562 error (_("Unable to read in dynamic data\n"));
5566 i_data
= malloc (number
* sizeof (*i_data
));
5570 error (_("Out of memory\n"));
5576 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
5583 /* Dump the symbol table. */
5585 process_symbol_table (FILE *file
)
5587 Elf_Internal_Shdr
*section
;
5588 unsigned char nb
[4];
5589 unsigned char nc
[4];
5592 int *buckets
= NULL
;
5595 if (! do_syms
&& !do_histogram
)
5598 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
5601 if (fseek (file
, offset_from_vma (file
, dynamic_info
[DT_HASH
],
5602 sizeof nb
+ sizeof nc
),
5605 error (_("Unable to seek to start of dynamic information"));
5609 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
5611 error (_("Failed to read in number of buckets\n"));
5615 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
5617 error (_("Failed to read in number of chains\n"));
5621 nbuckets
= byte_get (nb
, 4);
5622 nchains
= byte_get (nc
, 4);
5624 buckets
= get_dynamic_data (file
, nbuckets
);
5625 chains
= get_dynamic_data (file
, nchains
);
5627 if (buckets
== NULL
|| chains
== NULL
)
5632 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
5637 printf (_("\nSymbol table for image:\n"));
5639 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5641 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5643 for (hn
= 0; hn
< nbuckets
; hn
++)
5648 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
5650 Elf_Internal_Sym
*psym
;
5652 psym
= dynamic_symbols
+ si
;
5654 printf (" %3d %3d: ", si
, hn
);
5655 print_vma (psym
->st_value
, LONG_HEX
);
5657 print_vma (psym
->st_size
, DEC_5
);
5659 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5660 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5661 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5662 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
5663 print_symbol (25, dynamic_strings
+ psym
->st_name
);
5668 else if (do_syms
&& !do_using_dynamic
)
5672 for (i
= 0, section
= section_headers
;
5673 i
< elf_header
.e_shnum
;
5678 Elf_Internal_Sym
*symtab
;
5679 Elf_Internal_Sym
*psym
;
5682 if ( section
->sh_type
!= SHT_SYMTAB
5683 && section
->sh_type
!= SHT_DYNSYM
)
5686 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5687 SECTION_NAME (section
),
5688 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
5690 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5692 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5694 symtab
= GET_ELF_SYMBOLS (file
, section
);
5698 if (section
->sh_link
== elf_header
.e_shstrndx
)
5699 strtab
= string_table
;
5702 Elf_Internal_Shdr
*string_sec
;
5704 string_sec
= SECTION_HEADER (section
->sh_link
);
5706 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
5707 string_sec
->sh_size
, _("string table"));
5710 for (si
= 0, psym
= symtab
;
5711 si
< section
->sh_size
/ section
->sh_entsize
;
5714 printf ("%6d: ", si
);
5715 print_vma (psym
->st_value
, LONG_HEX
);
5717 print_vma (psym
->st_size
, DEC_5
);
5718 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5719 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5720 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5721 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
5722 print_symbol (25, strtab
+ psym
->st_name
);
5724 if (section
->sh_type
== SHT_DYNSYM
&&
5725 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
5727 unsigned char data
[2];
5728 unsigned short vers_data
;
5729 unsigned long offset
;
5733 offset
= offset_from_vma
5734 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
5735 sizeof data
+ si
* sizeof (vers_data
));
5737 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
5738 sizeof (data
), _("version data"));
5740 vers_data
= byte_get (data
, 2);
5742 is_nobits
= (SECTION_HEADER (psym
->st_shndx
)->sh_type
5745 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
5747 if ((vers_data
& 0x8000) || vers_data
> 1)
5749 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5750 && (is_nobits
|| ! check_def
))
5752 Elf_External_Verneed evn
;
5753 Elf_Internal_Verneed ivn
;
5754 Elf_Internal_Vernaux ivna
;
5756 /* We must test both. */
5757 offset
= offset_from_vma
5758 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
5763 unsigned long vna_off
;
5765 get_data (&evn
, file
, offset
, sizeof (evn
),
5768 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5769 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5771 vna_off
= offset
+ ivn
.vn_aux
;
5775 Elf_External_Vernaux evna
;
5777 get_data (&evna
, file
, vna_off
,
5779 _("version need aux (3)"));
5781 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5782 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5783 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5785 vna_off
+= ivna
.vna_next
;
5787 while (ivna
.vna_other
!= vers_data
5788 && ivna
.vna_next
!= 0);
5790 if (ivna
.vna_other
== vers_data
)
5793 offset
+= ivn
.vn_next
;
5795 while (ivn
.vn_next
!= 0);
5797 if (ivna
.vna_other
== vers_data
)
5800 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
5803 else if (! is_nobits
)
5804 error (_("bad dynamic symbol"));
5811 if (vers_data
!= 0x8001
5812 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5814 Elf_Internal_Verdef ivd
;
5815 Elf_Internal_Verdaux ivda
;
5816 Elf_External_Verdaux evda
;
5817 unsigned long offset
;
5819 offset
= offset_from_vma
5821 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
5822 sizeof (Elf_External_Verdef
));
5826 Elf_External_Verdef evd
;
5828 get_data (&evd
, file
, offset
, sizeof (evd
),
5831 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
5832 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
5833 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
5835 offset
+= ivd
.vd_next
;
5837 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
5838 && ivd
.vd_next
!= 0);
5840 offset
-= ivd
.vd_next
;
5841 offset
+= ivd
.vd_aux
;
5843 get_data (&evda
, file
, offset
, sizeof (evda
),
5844 _("version def aux"));
5846 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
5848 if (psym
->st_name
!= ivda
.vda_name
)
5849 printf ((vers_data
& 0x8000)
5851 strtab
+ ivda
.vda_name
);
5861 if (strtab
!= string_table
)
5867 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5869 if (do_histogram
&& buckets
!= NULL
)
5876 int nzero_counts
= 0;
5879 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5881 printf (_(" Length Number %% of total Coverage\n"));
5883 lengths
= calloc (nbuckets
, sizeof (int));
5884 if (lengths
== NULL
)
5886 error (_("Out of memory"));
5889 for (hn
= 0; hn
< nbuckets
; ++hn
)
5894 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
5897 if (maxlength
< ++lengths
[hn
])
5902 counts
= calloc (maxlength
+ 1, sizeof (int));
5905 error (_("Out of memory"));
5909 for (hn
= 0; hn
< nbuckets
; ++hn
)
5910 ++counts
[lengths
[hn
]];
5914 printf (" 0 %-10d (%5.1f%%)\n",
5915 counts
[0], (counts
[0] * 100.0) / nbuckets
);
5916 for (si
= 1; si
<= maxlength
; ++si
)
5918 nzero_counts
+= counts
[si
] * si
;
5919 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5920 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
5921 (nzero_counts
* 100.0) / nsyms
);
5929 if (buckets
!= NULL
)
5939 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
5943 if (dynamic_syminfo
== NULL
5945 /* No syminfo, this is ok. */
5948 /* There better should be a dynamic symbol section. */
5949 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
5953 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5954 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
5956 printf (_(" Num: Name BoundTo Flags\n"));
5957 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
5959 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
5961 printf ("%4d: ", i
);
5962 print_symbol (30, dynamic_strings
+ dynamic_symbols
[i
].st_name
);
5965 switch (dynamic_syminfo
[i
].si_boundto
)
5967 case SYMINFO_BT_SELF
:
5968 fputs ("SELF ", stdout
);
5970 case SYMINFO_BT_PARENT
:
5971 fputs ("PARENT ", stdout
);
5974 if (dynamic_syminfo
[i
].si_boundto
> 0
5975 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
5980 [dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
5984 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
5988 if (flags
& SYMINFO_FLG_DIRECT
)
5990 if (flags
& SYMINFO_FLG_PASSTHRU
)
5991 printf (" PASSTHRU");
5992 if (flags
& SYMINFO_FLG_COPY
)
5994 if (flags
& SYMINFO_FLG_LAZYLOAD
)
5995 printf (" LAZYLOAD");
6003 #ifdef SUPPORT_DISASSEMBLY
6005 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
6007 printf (_("\nAssembly dump of section %s\n"),
6008 SECTION_NAME (section
));
6010 /* XXX -- to be done --- XXX */
6017 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
6019 bfd_size_type bytes
;
6021 unsigned char *data
;
6022 unsigned char *start
;
6024 bytes
= section
->sh_size
;
6028 printf (_("\nSection '%s' has no data to dump.\n"),
6029 SECTION_NAME (section
));
6033 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
6035 addr
= section
->sh_addr
;
6037 start
= get_data (NULL
, file
, section
->sh_offset
, bytes
, _("section data"));
6049 lbytes
= (bytes
> 16 ? 16 : bytes
);
6051 printf (" 0x%8.8lx ", (unsigned long) addr
);
6053 switch (elf_header
.e_ident
[EI_DATA
])
6057 for (j
= 15; j
>= 0; j
--)
6060 printf ("%2.2x", data
[j
]);
6070 for (j
= 0; j
< 16; j
++)
6073 printf ("%2.2x", data
[j
]);
6083 for (j
= 0; j
< lbytes
; j
++)
6086 if (k
>= ' ' && k
< 0x80)
6105 static unsigned long int
6106 read_leb128 (unsigned char *data
, int *length_return
, int sign
)
6108 unsigned long int result
= 0;
6109 unsigned int num_read
= 0;
6118 result
|= (byte
& 0x7f) << shift
;
6123 while (byte
& 0x80);
6125 if (length_return
!= NULL
)
6126 *length_return
= num_read
;
6128 if (sign
&& (shift
< 32) && (byte
& 0x40))
6129 result
|= -1 << shift
;
6134 typedef struct State_Machine_Registers
6136 unsigned long address
;
6139 unsigned int column
;
6143 /* This variable hold the number of the last entry seen
6144 in the File Table. */
6145 unsigned int last_file_entry
;
6148 static SMR state_machine_regs
;
6151 reset_state_machine (int is_stmt
)
6153 state_machine_regs
.address
= 0;
6154 state_machine_regs
.file
= 1;
6155 state_machine_regs
.line
= 1;
6156 state_machine_regs
.column
= 0;
6157 state_machine_regs
.is_stmt
= is_stmt
;
6158 state_machine_regs
.basic_block
= 0;
6159 state_machine_regs
.end_sequence
= 0;
6160 state_machine_regs
.last_file_entry
= 0;
6163 /* Handled an extend line op. Returns true if this is the end
6166 process_extended_line_op (unsigned char *data
, int is_stmt
, int pointer_size
)
6168 unsigned char op_code
;
6171 unsigned char *name
;
6174 len
= read_leb128 (data
, & bytes_read
, 0);
6179 warn (_("badly formed extended line op encountered!\n"));
6186 printf (_(" Extended opcode %d: "), op_code
);
6190 case DW_LNE_end_sequence
:
6191 printf (_("End of Sequence\n\n"));
6192 reset_state_machine (is_stmt
);
6195 case DW_LNE_set_address
:
6196 adr
= byte_get (data
, pointer_size
);
6197 printf (_("set Address to 0x%lx\n"), adr
);
6198 state_machine_regs
.address
= adr
;
6201 case DW_LNE_define_file
:
6202 printf (_(" define new File Table entry\n"));
6203 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6205 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6207 data
+= strlen ((char *) data
) + 1;
6208 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6210 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6212 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6213 printf (_("%s\n\n"), name
);
6217 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
6224 /* Size of pointers in the .debug_line section. This information is not
6225 really present in that section. It's obtained before dumping the debug
6226 sections by doing some pre-scan of the .debug_info section. */
6227 static int debug_line_pointer_size
= 4;
6230 display_debug_lines (Elf_Internal_Shdr
*section
,
6231 unsigned char * start
,
6232 FILE *file ATTRIBUTE_UNUSED
)
6234 unsigned char *hdrptr
;
6235 DWARF2_Internal_LineInfo info
;
6236 unsigned char *standard_opcodes
;
6237 unsigned char *data
= start
;
6238 unsigned char *end
= start
+ section
->sh_size
;
6239 unsigned char *end_of_sequence
;
6242 int initial_length_size
;
6244 printf (_("\nDump of debug contents of section %s:\n\n"),
6245 SECTION_NAME (section
));
6251 /* Check the length of the block. */
6252 info
.li_length
= byte_get (hdrptr
, 4);
6255 if (info
.li_length
== 0xffffffff)
6257 /* This section is 64-bit DWARF 3. */
6258 info
.li_length
= byte_get (hdrptr
, 8);
6261 initial_length_size
= 12;
6266 initial_length_size
= 4;
6269 if (info
.li_length
+ initial_length_size
> section
->sh_size
)
6272 (_("The line info appears to be corrupt - the section is too small\n"));
6276 /* Check its version number. */
6277 info
.li_version
= byte_get (hdrptr
, 2);
6279 if (info
.li_version
!= 2 && info
.li_version
!= 3)
6281 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
6285 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
6286 hdrptr
+= offset_size
;
6287 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
6289 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
6291 info
.li_line_base
= byte_get (hdrptr
, 1);
6293 info
.li_line_range
= byte_get (hdrptr
, 1);
6295 info
.li_opcode_base
= byte_get (hdrptr
, 1);
6298 /* Sign extend the line base field. */
6299 info
.li_line_base
<<= 24;
6300 info
.li_line_base
>>= 24;
6302 printf (_(" Length: %ld\n"), info
.li_length
);
6303 printf (_(" DWARF Version: %d\n"), info
.li_version
);
6304 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
6305 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
6306 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
6307 printf (_(" Line Base: %d\n"), info
.li_line_base
);
6308 printf (_(" Line Range: %d\n"), info
.li_line_range
);
6309 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
6311 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
6313 reset_state_machine (info
.li_default_is_stmt
);
6315 /* Display the contents of the Opcodes table. */
6316 standard_opcodes
= hdrptr
;
6318 printf (_("\n Opcodes:\n"));
6320 for (i
= 1; i
< info
.li_opcode_base
; i
++)
6321 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
6323 /* Display the contents of the Directory table. */
6324 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
6327 printf (_("\n The Directory Table is empty.\n"));
6330 printf (_("\n The Directory Table:\n"));
6334 printf (_(" %s\n"), data
);
6336 data
+= strlen ((char *) data
) + 1;
6340 /* Skip the NUL at the end of the table. */
6343 /* Display the contents of the File Name table. */
6345 printf (_("\n The File Name Table is empty.\n"));
6348 printf (_("\n The File Name Table:\n"));
6349 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6353 unsigned char *name
;
6356 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6359 data
+= strlen ((char *) data
) + 1;
6361 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6363 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6365 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6367 printf (_("%s\n"), name
);
6371 /* Skip the NUL at the end of the table. */
6374 /* Now display the statements. */
6375 printf (_("\n Line Number Statements:\n"));
6378 while (data
< end_of_sequence
)
6380 unsigned char op_code
;
6386 if (op_code
>= info
.li_opcode_base
)
6388 op_code
-= info
.li_opcode_base
;
6389 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
6390 state_machine_regs
.address
+= adv
;
6391 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6392 op_code
, adv
, state_machine_regs
.address
);
6393 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
6394 state_machine_regs
.line
+= adv
;
6395 printf (_(" and Line by %d to %d\n"),
6396 adv
, state_machine_regs
.line
);
6398 else switch (op_code
)
6400 case DW_LNS_extended_op
:
6401 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
6402 debug_line_pointer_size
);
6406 printf (_(" Copy\n"));
6409 case DW_LNS_advance_pc
:
6410 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
6412 state_machine_regs
.address
+= adv
;
6413 printf (_(" Advance PC by %d to %lx\n"), adv
,
6414 state_machine_regs
.address
);
6417 case DW_LNS_advance_line
:
6418 adv
= read_leb128 (data
, & bytes_read
, 1);
6420 state_machine_regs
.line
+= adv
;
6421 printf (_(" Advance Line by %d to %d\n"), adv
,
6422 state_machine_regs
.line
);
6425 case DW_LNS_set_file
:
6426 adv
= read_leb128 (data
, & bytes_read
, 0);
6428 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6430 state_machine_regs
.file
= adv
;
6433 case DW_LNS_set_column
:
6434 adv
= read_leb128 (data
, & bytes_read
, 0);
6436 printf (_(" Set column to %d\n"), adv
);
6437 state_machine_regs
.column
= adv
;
6440 case DW_LNS_negate_stmt
:
6441 adv
= state_machine_regs
.is_stmt
;
6443 printf (_(" Set is_stmt to %d\n"), adv
);
6444 state_machine_regs
.is_stmt
= adv
;
6447 case DW_LNS_set_basic_block
:
6448 printf (_(" Set basic block\n"));
6449 state_machine_regs
.basic_block
= 1;
6452 case DW_LNS_const_add_pc
:
6453 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
6454 * info
.li_min_insn_length
);
6455 state_machine_regs
.address
+= adv
;
6456 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
6457 state_machine_regs
.address
);
6460 case DW_LNS_fixed_advance_pc
:
6461 adv
= byte_get (data
, 2);
6463 state_machine_regs
.address
+= adv
;
6464 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6465 adv
, state_machine_regs
.address
);
6468 case DW_LNS_set_prologue_end
:
6469 printf (_(" Set prologue_end to true\n"));
6472 case DW_LNS_set_epilogue_begin
:
6473 printf (_(" Set epilogue_begin to true\n"));
6476 case DW_LNS_set_isa
:
6477 adv
= read_leb128 (data
, & bytes_read
, 0);
6479 printf (_(" Set ISA to %d\n"), adv
);
6483 printf (_(" Unknown opcode %d with operands: "), op_code
);
6486 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
6488 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
6489 i
== 1 ? "" : ", ");
6504 display_debug_pubnames (Elf_Internal_Shdr
*section
,
6505 unsigned char *start
,
6506 FILE *file ATTRIBUTE_UNUSED
)
6508 DWARF2_Internal_PubNames pubnames
;
6511 end
= start
+ section
->sh_size
;
6513 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6517 unsigned char *data
;
6518 unsigned long offset
;
6519 int offset_size
, initial_length_size
;
6523 pubnames
.pn_length
= byte_get (data
, 4);
6525 if (pubnames
.pn_length
== 0xffffffff)
6527 pubnames
.pn_length
= byte_get (data
, 8);
6530 initial_length_size
= 12;
6535 initial_length_size
= 4;
6538 pubnames
.pn_version
= byte_get (data
, 2);
6540 pubnames
.pn_offset
= byte_get (data
, offset_size
);
6541 data
+= offset_size
;
6542 pubnames
.pn_size
= byte_get (data
, offset_size
);
6543 data
+= offset_size
;
6545 start
+= pubnames
.pn_length
+ initial_length_size
;
6547 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
6549 static int warned
= 0;
6553 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6560 printf (_(" Length: %ld\n"),
6561 pubnames
.pn_length
);
6562 printf (_(" Version: %d\n"),
6563 pubnames
.pn_version
);
6564 printf (_(" Offset into .debug_info section: %ld\n"),
6565 pubnames
.pn_offset
);
6566 printf (_(" Size of area in .debug_info section: %ld\n"),
6569 printf (_("\n Offset\tName\n"));
6573 offset
= byte_get (data
, offset_size
);
6577 data
+= offset_size
;
6578 printf (" %ld\t\t%s\n", offset
, data
);
6579 data
+= strlen ((char *) data
) + 1;
6582 while (offset
!= 0);
6590 get_TAG_name (unsigned long tag
)
6594 case DW_TAG_padding
: return "DW_TAG_padding";
6595 case DW_TAG_array_type
: return "DW_TAG_array_type";
6596 case DW_TAG_class_type
: return "DW_TAG_class_type";
6597 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
6598 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
6599 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
6600 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
6601 case DW_TAG_label
: return "DW_TAG_label";
6602 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
6603 case DW_TAG_member
: return "DW_TAG_member";
6604 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
6605 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
6606 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
6607 case DW_TAG_string_type
: return "DW_TAG_string_type";
6608 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
6609 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
6610 case DW_TAG_typedef
: return "DW_TAG_typedef";
6611 case DW_TAG_union_type
: return "DW_TAG_union_type";
6612 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
6613 case DW_TAG_variant
: return "DW_TAG_variant";
6614 case DW_TAG_common_block
: return "DW_TAG_common_block";
6615 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
6616 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
6617 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
6618 case DW_TAG_module
: return "DW_TAG_module";
6619 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
6620 case DW_TAG_set_type
: return "DW_TAG_set_type";
6621 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
6622 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
6623 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
6624 case DW_TAG_base_type
: return "DW_TAG_base_type";
6625 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
6626 case DW_TAG_const_type
: return "DW_TAG_const_type";
6627 case DW_TAG_constant
: return "DW_TAG_constant";
6628 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
6629 case DW_TAG_file_type
: return "DW_TAG_file_type";
6630 case DW_TAG_friend
: return "DW_TAG_friend";
6631 case DW_TAG_namelist
: return "DW_TAG_namelist";
6632 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
6633 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
6634 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
6635 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
6636 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
6637 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
6638 case DW_TAG_try_block
: return "DW_TAG_try_block";
6639 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
6640 case DW_TAG_variable
: return "DW_TAG_variable";
6641 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
6642 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
6643 case DW_TAG_format_label
: return "DW_TAG_format_label";
6644 case DW_TAG_function_template
: return "DW_TAG_function_template";
6645 case DW_TAG_class_template
: return "DW_TAG_class_template";
6646 /* DWARF 2.1 values. */
6647 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
6648 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
6649 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
6650 case DW_TAG_namespace
: return "DW_TAG_namespace";
6651 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
6652 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
6653 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
6654 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
6656 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
6657 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
6658 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
6661 static char buffer
[100];
6663 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
6670 get_AT_name (unsigned long attribute
)
6674 case DW_AT_sibling
: return "DW_AT_sibling";
6675 case DW_AT_location
: return "DW_AT_location";
6676 case DW_AT_name
: return "DW_AT_name";
6677 case DW_AT_ordering
: return "DW_AT_ordering";
6678 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
6679 case DW_AT_byte_size
: return "DW_AT_byte_size";
6680 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
6681 case DW_AT_bit_size
: return "DW_AT_bit_size";
6682 case DW_AT_element_list
: return "DW_AT_element_list";
6683 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
6684 case DW_AT_low_pc
: return "DW_AT_low_pc";
6685 case DW_AT_high_pc
: return "DW_AT_high_pc";
6686 case DW_AT_language
: return "DW_AT_language";
6687 case DW_AT_member
: return "DW_AT_member";
6688 case DW_AT_discr
: return "DW_AT_discr";
6689 case DW_AT_discr_value
: return "DW_AT_discr_value";
6690 case DW_AT_visibility
: return "DW_AT_visibility";
6691 case DW_AT_import
: return "DW_AT_import";
6692 case DW_AT_string_length
: return "DW_AT_string_length";
6693 case DW_AT_common_reference
: return "DW_AT_common_reference";
6694 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
6695 case DW_AT_const_value
: return "DW_AT_const_value";
6696 case DW_AT_containing_type
: return "DW_AT_containing_type";
6697 case DW_AT_default_value
: return "DW_AT_default_value";
6698 case DW_AT_inline
: return "DW_AT_inline";
6699 case DW_AT_is_optional
: return "DW_AT_is_optional";
6700 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
6701 case DW_AT_producer
: return "DW_AT_producer";
6702 case DW_AT_prototyped
: return "DW_AT_prototyped";
6703 case DW_AT_return_addr
: return "DW_AT_return_addr";
6704 case DW_AT_start_scope
: return "DW_AT_start_scope";
6705 case DW_AT_stride_size
: return "DW_AT_stride_size";
6706 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
6707 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
6708 case DW_AT_accessibility
: return "DW_AT_accessibility";
6709 case DW_AT_address_class
: return "DW_AT_address_class";
6710 case DW_AT_artificial
: return "DW_AT_artificial";
6711 case DW_AT_base_types
: return "DW_AT_base_types";
6712 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
6713 case DW_AT_count
: return "DW_AT_count";
6714 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
6715 case DW_AT_decl_column
: return "DW_AT_decl_column";
6716 case DW_AT_decl_file
: return "DW_AT_decl_file";
6717 case DW_AT_decl_line
: return "DW_AT_decl_line";
6718 case DW_AT_declaration
: return "DW_AT_declaration";
6719 case DW_AT_discr_list
: return "DW_AT_discr_list";
6720 case DW_AT_encoding
: return "DW_AT_encoding";
6721 case DW_AT_external
: return "DW_AT_external";
6722 case DW_AT_frame_base
: return "DW_AT_frame_base";
6723 case DW_AT_friend
: return "DW_AT_friend";
6724 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
6725 case DW_AT_macro_info
: return "DW_AT_macro_info";
6726 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
6727 case DW_AT_priority
: return "DW_AT_priority";
6728 case DW_AT_segment
: return "DW_AT_segment";
6729 case DW_AT_specification
: return "DW_AT_specification";
6730 case DW_AT_static_link
: return "DW_AT_static_link";
6731 case DW_AT_type
: return "DW_AT_type";
6732 case DW_AT_use_location
: return "DW_AT_use_location";
6733 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
6734 case DW_AT_virtuality
: return "DW_AT_virtuality";
6735 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
6736 /* DWARF 2.1 values. */
6737 case DW_AT_allocated
: return "DW_AT_allocated";
6738 case DW_AT_associated
: return "DW_AT_associated";
6739 case DW_AT_data_location
: return "DW_AT_data_location";
6740 case DW_AT_stride
: return "DW_AT_stride";
6741 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
6742 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
6743 case DW_AT_extension
: return "DW_AT_extension";
6744 case DW_AT_ranges
: return "DW_AT_ranges";
6745 case DW_AT_trampoline
: return "DW_AT_trampoline";
6746 case DW_AT_call_column
: return "DW_AT_call_column";
6747 case DW_AT_call_file
: return "DW_AT_call_file";
6748 case DW_AT_call_line
: return "DW_AT_call_line";
6749 /* SGI/MIPS extensions. */
6750 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
6751 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
6752 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
6753 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
6754 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
6755 case DW_AT_MIPS_software_pipeline_depth
:
6756 return "DW_AT_MIPS_software_pipeline_depth";
6757 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
6758 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
6759 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
6760 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
6761 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
6762 /* GNU extensions. */
6763 case DW_AT_sf_names
: return "DW_AT_sf_names";
6764 case DW_AT_src_info
: return "DW_AT_src_info";
6765 case DW_AT_mac_info
: return "DW_AT_mac_info";
6766 case DW_AT_src_coords
: return "DW_AT_src_coords";
6767 case DW_AT_body_begin
: return "DW_AT_body_begin";
6768 case DW_AT_body_end
: return "DW_AT_body_end";
6769 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
6770 /* UPC extension. */
6771 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
6774 static char buffer
[100];
6776 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
6783 get_FORM_name (unsigned long form
)
6787 case DW_FORM_addr
: return "DW_FORM_addr";
6788 case DW_FORM_block2
: return "DW_FORM_block2";
6789 case DW_FORM_block4
: return "DW_FORM_block4";
6790 case DW_FORM_data2
: return "DW_FORM_data2";
6791 case DW_FORM_data4
: return "DW_FORM_data4";
6792 case DW_FORM_data8
: return "DW_FORM_data8";
6793 case DW_FORM_string
: return "DW_FORM_string";
6794 case DW_FORM_block
: return "DW_FORM_block";
6795 case DW_FORM_block1
: return "DW_FORM_block1";
6796 case DW_FORM_data1
: return "DW_FORM_data1";
6797 case DW_FORM_flag
: return "DW_FORM_flag";
6798 case DW_FORM_sdata
: return "DW_FORM_sdata";
6799 case DW_FORM_strp
: return "DW_FORM_strp";
6800 case DW_FORM_udata
: return "DW_FORM_udata";
6801 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
6802 case DW_FORM_ref1
: return "DW_FORM_ref1";
6803 case DW_FORM_ref2
: return "DW_FORM_ref2";
6804 case DW_FORM_ref4
: return "DW_FORM_ref4";
6805 case DW_FORM_ref8
: return "DW_FORM_ref8";
6806 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
6807 case DW_FORM_indirect
: return "DW_FORM_indirect";
6810 static char buffer
[100];
6812 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
6818 /* FIXME: There are better and more effiecint ways to handle
6819 these structures. For now though, I just want something that
6820 is simple to implement. */
6821 typedef struct abbrev_attr
6823 unsigned long attribute
;
6825 struct abbrev_attr
*next
;
6829 typedef struct abbrev_entry
6831 unsigned long entry
;
6834 struct abbrev_attr
*first_attr
;
6835 struct abbrev_attr
*last_attr
;
6836 struct abbrev_entry
*next
;
6840 static abbrev_entry
*first_abbrev
= NULL
;
6841 static abbrev_entry
*last_abbrev
= NULL
;
6846 abbrev_entry
*abbrev
;
6848 for (abbrev
= first_abbrev
; abbrev
;)
6850 abbrev_entry
*next
= abbrev
->next
;
6853 for (attr
= abbrev
->first_attr
; attr
;)
6855 abbrev_attr
*next
= attr
->next
;
6865 last_abbrev
= first_abbrev
= NULL
;
6869 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
6871 abbrev_entry
*entry
;
6873 entry
= malloc (sizeof (*entry
));
6879 entry
->entry
= number
;
6881 entry
->children
= children
;
6882 entry
->first_attr
= NULL
;
6883 entry
->last_attr
= NULL
;
6886 if (first_abbrev
== NULL
)
6887 first_abbrev
= entry
;
6889 last_abbrev
->next
= entry
;
6891 last_abbrev
= entry
;
6895 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
6899 attr
= malloc (sizeof (*attr
));
6905 attr
->attribute
= attribute
;
6909 if (last_abbrev
->first_attr
== NULL
)
6910 last_abbrev
->first_attr
= attr
;
6912 last_abbrev
->last_attr
->next
= attr
;
6914 last_abbrev
->last_attr
= attr
;
6917 /* Processes the (partial) contents of a .debug_abbrev section.
6918 Returns NULL if the end of the section was encountered.
6919 Returns the address after the last byte read if the end of
6920 an abbreviation set was found. */
6922 static unsigned char *
6923 process_abbrev_section (unsigned char *start
, unsigned char *end
)
6925 if (first_abbrev
!= NULL
)
6931 unsigned long entry
;
6933 unsigned long attribute
;
6936 entry
= read_leb128 (start
, & bytes_read
, 0);
6937 start
+= bytes_read
;
6939 /* A single zero is supposed to end the section according
6940 to the standard. If there's more, then signal that to
6943 return start
== end
? NULL
: start
;
6945 tag
= read_leb128 (start
, & bytes_read
, 0);
6946 start
+= bytes_read
;
6948 children
= *start
++;
6950 add_abbrev (entry
, tag
, children
);
6956 attribute
= read_leb128 (start
, & bytes_read
, 0);
6957 start
+= bytes_read
;
6959 form
= read_leb128 (start
, & bytes_read
, 0);
6960 start
+= bytes_read
;
6963 add_abbrev_attr (attribute
, form
);
6965 while (attribute
!= 0);
6973 display_debug_macinfo (Elf_Internal_Shdr
*section
,
6974 unsigned char *start
,
6975 FILE *file ATTRIBUTE_UNUSED
)
6977 unsigned char *end
= start
+ section
->sh_size
;
6978 unsigned char *curr
= start
;
6979 unsigned int bytes_read
;
6980 enum dwarf_macinfo_record_type op
;
6982 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6986 unsigned int lineno
;
6994 case DW_MACINFO_start_file
:
6996 unsigned int filenum
;
6998 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7000 filenum
= read_leb128 (curr
, & bytes_read
, 0);
7003 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno
, filenum
);
7007 case DW_MACINFO_end_file
:
7008 printf (_(" DW_MACINFO_end_file\n"));
7011 case DW_MACINFO_define
:
7012 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7015 curr
+= strlen (string
) + 1;
7016 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno
, string
);
7019 case DW_MACINFO_undef
:
7020 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7023 curr
+= strlen (string
) + 1;
7024 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno
, string
);
7027 case DW_MACINFO_vendor_ext
:
7029 unsigned int constant
;
7031 constant
= read_leb128 (curr
, & bytes_read
, 0);
7034 curr
+= strlen (string
) + 1;
7035 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant
, string
);
7046 display_debug_abbrev (Elf_Internal_Shdr
*section
,
7047 unsigned char *start
,
7048 FILE *file ATTRIBUTE_UNUSED
)
7050 abbrev_entry
*entry
;
7051 unsigned char *end
= start
+ section
->sh_size
;
7053 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7057 start
= process_abbrev_section (start
, end
);
7059 if (first_abbrev
== NULL
)
7062 printf (_(" Number TAG\n"));
7064 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
7068 printf (_(" %ld %s [%s]\n"),
7070 get_TAG_name (entry
->tag
),
7071 entry
->children
? _("has children") : _("no children"));
7073 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
7075 printf (_(" %-18s %s\n"),
7076 get_AT_name (attr
->attribute
),
7077 get_FORM_name (attr
->form
));
7091 static unsigned char *
7092 display_block (unsigned char *data
, unsigned long length
)
7094 printf (_(" %lu byte block: "), length
);
7097 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
7103 decode_location_expression (unsigned char * data
,
7104 unsigned int pointer_size
,
7105 unsigned long length
)
7109 unsigned long uvalue
;
7110 unsigned char *end
= data
+ length
;
7119 printf ("DW_OP_addr: %lx",
7120 (unsigned long) byte_get (data
, pointer_size
));
7121 data
+= pointer_size
;
7124 printf ("DW_OP_deref");
7127 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
7130 printf ("DW_OP_const1s: %ld", (long) byte_get (data
++, 1));
7133 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
7137 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
7141 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
7145 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
7149 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
7150 (unsigned long) byte_get (data
+ 4, 4));
7154 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
7155 (long) byte_get (data
+ 4, 4));
7159 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
7163 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
7167 printf ("DW_OP_dup");
7170 printf ("DW_OP_drop");
7173 printf ("DW_OP_over");
7176 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
7179 printf ("DW_OP_swap");
7182 printf ("DW_OP_rot");
7185 printf ("DW_OP_xderef");
7188 printf ("DW_OP_abs");
7191 printf ("DW_OP_and");
7194 printf ("DW_OP_div");
7197 printf ("DW_OP_minus");
7200 printf ("DW_OP_mod");
7203 printf ("DW_OP_mul");
7206 printf ("DW_OP_neg");
7209 printf ("DW_OP_not");
7212 printf ("DW_OP_or");
7215 printf ("DW_OP_plus");
7217 case DW_OP_plus_uconst
:
7218 printf ("DW_OP_plus_uconst: %lu",
7219 read_leb128 (data
, &bytes_read
, 0));
7223 printf ("DW_OP_shl");
7226 printf ("DW_OP_shr");
7229 printf ("DW_OP_shra");
7232 printf ("DW_OP_xor");
7235 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
7239 printf ("DW_OP_eq");
7242 printf ("DW_OP_ge");
7245 printf ("DW_OP_gt");
7248 printf ("DW_OP_le");
7251 printf ("DW_OP_lt");
7254 printf ("DW_OP_ne");
7257 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
7293 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
7328 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
7363 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
7364 read_leb128 (data
, &bytes_read
, 1));
7369 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
7373 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
7377 uvalue
= read_leb128 (data
, &bytes_read
, 0);
7379 printf ("DW_OP_bregx: %lu %ld", uvalue
,
7380 read_leb128 (data
, &bytes_read
, 1));
7384 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
7387 case DW_OP_deref_size
:
7388 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
7390 case DW_OP_xderef_size
:
7391 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
7394 printf ("DW_OP_nop");
7397 /* DWARF 3 extensions. */
7398 case DW_OP_push_object_address
:
7399 printf ("DW_OP_push_object_address");
7402 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2));
7406 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4));
7409 case DW_OP_call_ref
:
7410 printf ("DW_OP_call_ref");
7413 /* GNU extensions. */
7414 case DW_OP_GNU_push_tls_address
:
7415 printf ("DW_OP_GNU_push_tls_address");
7419 if (op
>= DW_OP_lo_user
7420 && op
<= DW_OP_hi_user
)
7421 printf (_("(User defined location op)"));
7423 printf (_("(Unknown location op)"));
7424 /* No way to tell where the next op is, so just bail. */
7428 /* Separate the ops. */
7434 static const char *debug_loc_contents
;
7435 static bfd_vma debug_loc_size
;
7438 load_debug_loc (FILE *file
)
7440 Elf_Internal_Shdr
*sec
;
7443 /* If it is already loaded, do nothing. */
7444 if (debug_loc_contents
!= NULL
)
7447 /* Locate the .debug_loc section. */
7448 for (i
= 0, sec
= section_headers
;
7449 i
< elf_header
.e_shnum
;
7451 if (strcmp (SECTION_NAME (sec
), ".debug_loc") == 0)
7454 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7457 debug_loc_size
= sec
->sh_size
;
7459 debug_loc_contents
= get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7460 _("debug_loc section data"));
7464 free_debug_loc (void)
7466 if (debug_loc_contents
== NULL
)
7469 free ((char *) debug_loc_contents
);
7470 debug_loc_contents
= NULL
;
7476 display_debug_loc (Elf_Internal_Shdr
*section
,
7477 unsigned char *start
,
7478 FILE *file ATTRIBUTE_UNUSED
)
7480 unsigned char *section_end
;
7481 unsigned long bytes
;
7482 unsigned char *section_begin
= start
;
7485 addr
= section
->sh_addr
;
7486 bytes
= section
->sh_size
;
7487 section_end
= start
+ bytes
;
7491 printf (_("\nThe .debug_loc section is empty.\n"));
7495 printf (_("Contents of the .debug_loc section:\n\n"));
7496 printf (_("\n Offset Begin End Expression\n"));
7498 while (start
< section_end
)
7500 unsigned long begin
;
7502 unsigned short length
;
7503 unsigned long offset
;
7505 offset
= start
- section_begin
;
7509 /* Normally, the lists in the debug_loc section are related to a
7510 given compilation unit, and thus, we would use the pointer size
7511 of that compilation unit. However, since we are displaying it
7512 seperately here, we either have to store pointer sizes of all
7513 compilation units, or assume they don't change. We assume,
7514 like the debug_line display, that it doesn't change. */
7515 begin
= byte_get (start
, debug_line_pointer_size
);
7516 start
+= debug_line_pointer_size
;
7517 end
= byte_get (start
, debug_line_pointer_size
);
7518 start
+= debug_line_pointer_size
;
7520 if (begin
== 0 && end
== 0)
7523 /* For now, skip any base address specifiers. */
7524 if (begin
== 0xffffffff)
7530 length
= byte_get (start
, 2);
7533 printf (" %8.8lx %8.8lx %8.8lx (", offset
, begin
, end
);
7534 decode_location_expression (start
, debug_line_pointer_size
, length
);
7544 static const char *debug_str_contents
;
7545 static bfd_vma debug_str_size
;
7548 load_debug_str (FILE *file
)
7550 Elf_Internal_Shdr
*sec
;
7553 /* If it is already loaded, do nothing. */
7554 if (debug_str_contents
!= NULL
)
7557 /* Locate the .debug_str section. */
7558 for (i
= 0, sec
= section_headers
;
7559 i
< elf_header
.e_shnum
;
7561 if (strcmp (SECTION_NAME (sec
), ".debug_str") == 0)
7564 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7567 debug_str_size
= sec
->sh_size
;
7569 debug_str_contents
= get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7570 _("debug_str section data"));
7574 free_debug_str (void)
7576 if (debug_str_contents
== NULL
)
7579 free ((char *) debug_str_contents
);
7580 debug_str_contents
= NULL
;
7585 fetch_indirect_string (unsigned long offset
)
7587 if (debug_str_contents
== NULL
)
7588 return _("<no .debug_str section>");
7590 if (offset
> debug_str_size
)
7591 return _("<offset is too big>");
7593 return debug_str_contents
+ offset
;
7597 display_debug_str (Elf_Internal_Shdr
*section
,
7598 unsigned char *start
,
7599 FILE *file ATTRIBUTE_UNUSED
)
7601 unsigned long bytes
;
7604 addr
= section
->sh_addr
;
7605 bytes
= section
->sh_size
;
7609 printf (_("\nThe .debug_str section is empty.\n"));
7613 printf (_("Contents of the .debug_str section:\n\n"));
7621 lbytes
= (bytes
> 16 ? 16 : bytes
);
7623 printf (" 0x%8.8lx ", (unsigned long) addr
);
7625 for (j
= 0; j
< 16; j
++)
7628 printf ("%2.2x", start
[j
]);
7636 for (j
= 0; j
< lbytes
; j
++)
7639 if (k
>= ' ' && k
< 0x80)
7655 static unsigned char *
7656 read_and_display_attr_value (unsigned long attribute
,
7658 unsigned char *data
,
7659 unsigned long cu_offset
,
7660 unsigned long pointer_size
,
7661 unsigned long offset_size
,
7664 unsigned long uvalue
= 0;
7665 unsigned char *block_start
= NULL
;
7673 case DW_FORM_ref_addr
:
7674 if (dwarf_version
== 2)
7676 uvalue
= byte_get (data
, pointer_size
);
7677 data
+= pointer_size
;
7679 else if (dwarf_version
== 3)
7681 uvalue
= byte_get (data
, offset_size
);
7682 data
+= offset_size
;
7686 error (_("Internal error: DWARF version is not 2 or 3.\n"));
7691 uvalue
= byte_get (data
, pointer_size
);
7692 data
+= pointer_size
;
7696 uvalue
= byte_get (data
, offset_size
);
7697 data
+= offset_size
;
7703 uvalue
= byte_get (data
++, 1);
7708 uvalue
= byte_get (data
, 2);
7714 uvalue
= byte_get (data
, 4);
7719 uvalue
= read_leb128 (data
, & bytes_read
, 1);
7723 case DW_FORM_ref_udata
:
7725 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7729 case DW_FORM_indirect
:
7730 form
= read_leb128 (data
, & bytes_read
, 0);
7732 printf (" %s", get_FORM_name (form
));
7733 return read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
7734 pointer_size
, offset_size
,
7740 case DW_FORM_ref_addr
:
7741 printf (" <#%lx>", uvalue
);
7747 case DW_FORM_ref_udata
:
7748 printf (" <%lx>", uvalue
+ cu_offset
);
7752 printf (" %#lx", uvalue
);
7760 printf (" %ld", uvalue
);
7765 uvalue
= byte_get (data
, 4);
7766 printf (" %lx", uvalue
);
7767 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
7771 case DW_FORM_string
:
7772 printf (" %s", data
);
7773 data
+= strlen ((char *) data
) + 1;
7777 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7778 block_start
= data
+ bytes_read
;
7779 data
= display_block (block_start
, uvalue
);
7782 case DW_FORM_block1
:
7783 uvalue
= byte_get (data
, 1);
7784 block_start
= data
+ 1;
7785 data
= display_block (block_start
, uvalue
);
7788 case DW_FORM_block2
:
7789 uvalue
= byte_get (data
, 2);
7790 block_start
= data
+ 2;
7791 data
= display_block (block_start
, uvalue
);
7794 case DW_FORM_block4
:
7795 uvalue
= byte_get (data
, 4);
7796 block_start
= data
+ 4;
7797 data
= display_block (block_start
, uvalue
);
7801 printf (_(" (indirect string, offset: 0x%lx): %s"),
7802 uvalue
, fetch_indirect_string (uvalue
));
7805 case DW_FORM_indirect
:
7806 /* Handled above. */
7810 warn (_("Unrecognized form: %d\n"), form
);
7814 /* For some attributes we can display futher information. */
7823 case DW_INL_not_inlined
:
7824 printf (_("(not inlined)"));
7826 case DW_INL_inlined
:
7827 printf (_("(inlined)"));
7829 case DW_INL_declared_not_inlined
:
7830 printf (_("(declared as inline but ignored)"));
7832 case DW_INL_declared_inlined
:
7833 printf (_("(declared as inline and inlined)"));
7836 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
7841 case DW_AT_language
:
7844 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
7845 case DW_LANG_C89
: printf ("(ANSI C)"); break;
7846 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
7847 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
7848 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
7849 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
7850 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
7851 case DW_LANG_Ada83
: printf ("(Ada)"); break;
7852 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
7853 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
7854 /* DWARF 2.1 values. */
7855 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
7856 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
7857 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
7858 /* MIPS extension. */
7859 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
7860 /* UPC extension. */
7861 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
7863 printf ("(Unknown: %lx)", uvalue
);
7868 case DW_AT_encoding
:
7871 case DW_ATE_void
: printf ("(void)"); break;
7872 case DW_ATE_address
: printf ("(machine address)"); break;
7873 case DW_ATE_boolean
: printf ("(boolean)"); break;
7874 case DW_ATE_complex_float
: printf ("(complex float)"); break;
7875 case DW_ATE_float
: printf ("(float)"); break;
7876 case DW_ATE_signed
: printf ("(signed)"); break;
7877 case DW_ATE_signed_char
: printf ("(signed char)"); break;
7878 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
7879 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
7880 /* DWARF 2.1 value. */
7881 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
7883 if (uvalue
>= DW_ATE_lo_user
7884 && uvalue
<= DW_ATE_hi_user
)
7885 printf ("(user defined type)");
7887 printf ("(unknown type)");
7892 case DW_AT_accessibility
:
7895 case DW_ACCESS_public
: printf ("(public)"); break;
7896 case DW_ACCESS_protected
: printf ("(protected)"); break;
7897 case DW_ACCESS_private
: printf ("(private)"); break;
7899 printf ("(unknown accessibility)");
7904 case DW_AT_visibility
:
7907 case DW_VIS_local
: printf ("(local)"); break;
7908 case DW_VIS_exported
: printf ("(exported)"); break;
7909 case DW_VIS_qualified
: printf ("(qualified)"); break;
7910 default: printf ("(unknown visibility)"); break;
7914 case DW_AT_virtuality
:
7917 case DW_VIRTUALITY_none
: printf ("(none)"); break;
7918 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
7919 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
7920 default: printf ("(unknown virtuality)"); break;
7924 case DW_AT_identifier_case
:
7927 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
7928 case DW_ID_up_case
: printf ("(up_case)"); break;
7929 case DW_ID_down_case
: printf ("(down_case)"); break;
7930 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
7931 default: printf ("(unknown case)"); break;
7935 case DW_AT_calling_convention
:
7938 case DW_CC_normal
: printf ("(normal)"); break;
7939 case DW_CC_program
: printf ("(program)"); break;
7940 case DW_CC_nocall
: printf ("(nocall)"); break;
7942 if (uvalue
>= DW_CC_lo_user
7943 && uvalue
<= DW_CC_hi_user
)
7944 printf ("(user defined)");
7946 printf ("(unknown convention)");
7950 case DW_AT_ordering
:
7953 case -1: printf ("(undefined)"); break;
7954 case 0: printf ("(row major)"); break;
7955 case 1: printf ("(column major)"); break;
7959 case DW_AT_frame_base
:
7960 case DW_AT_location
:
7961 case DW_AT_data_member_location
:
7962 case DW_AT_vtable_elem_location
:
7963 case DW_AT_allocated
:
7964 case DW_AT_associated
:
7965 case DW_AT_data_location
:
7967 case DW_AT_upper_bound
:
7968 case DW_AT_lower_bound
:
7972 decode_location_expression (block_start
, pointer_size
, uvalue
);
7975 else if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
7978 printf ("location list");
7990 static unsigned char *
7991 read_and_display_attr (unsigned long attribute
,
7993 unsigned char *data
,
7994 unsigned long cu_offset
,
7995 unsigned long pointer_size
,
7996 unsigned long offset_size
,
7999 printf (" %-18s:", get_AT_name (attribute
));
8000 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
8001 pointer_size
, offset_size
, dwarf_version
);
8007 display_debug_info (Elf_Internal_Shdr
*section
,
8008 unsigned char *start
,
8011 unsigned char *end
= start
+ section
->sh_size
;
8012 unsigned char *section_begin
= start
;
8014 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8016 load_debug_str (file
);
8017 load_debug_loc (file
);
8021 DWARF2_Internal_CompUnit compunit
;
8022 Elf_Internal_Shdr
*relsec
;
8023 unsigned char *hdrptr
;
8024 unsigned char *cu_abbrev_offset_ptr
;
8025 unsigned char *tags
;
8028 unsigned long cu_offset
;
8030 int initial_length_size
;
8034 compunit
.cu_length
= byte_get (hdrptr
, 4);
8037 if (compunit
.cu_length
== 0xffffffff)
8039 compunit
.cu_length
= byte_get (hdrptr
, 8);
8042 initial_length_size
= 12;
8047 initial_length_size
= 4;
8050 compunit
.cu_version
= byte_get (hdrptr
, 2);
8053 /* Apply addends of RELA relocations. */
8054 for (relsec
= section_headers
;
8055 relsec
< section_headers
+ elf_header
.e_shnum
;
8058 unsigned long nrelas
;
8059 Elf_Internal_Rela
*rela
, *rp
;
8060 Elf_Internal_Shdr
*symsec
;
8061 Elf_Internal_Sym
*symtab
;
8062 Elf_Internal_Sym
*sym
;
8064 if (relsec
->sh_type
!= SHT_RELA
8065 || SECTION_HEADER (relsec
->sh_info
) != section
8066 || relsec
->sh_size
== 0)
8069 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8073 symsec
= SECTION_HEADER (relsec
->sh_link
);
8074 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
8076 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8080 if (rp
->r_offset
>= (bfd_vma
) (hdrptr
- section_begin
)
8081 && section
->sh_size
> (bfd_vma
) offset_size
8082 && rp
->r_offset
<= section
->sh_size
- offset_size
)
8083 loc
= section_begin
+ rp
->r_offset
;
8089 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
8091 if (ELF32_R_SYM (rp
->r_info
) != 0
8092 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8094 warn (_("Skipping unexpected symbol type %u\n"),
8095 ELF32_ST_TYPE (sym
->st_info
));
8101 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
8103 if (ELF64_R_SYM (rp
->r_info
) != 0
8104 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8106 warn (_("Skipping unexpected symbol type %u\n"),
8107 ELF64_ST_TYPE (sym
->st_info
));
8112 byte_put (loc
, rp
->r_addend
, offset_size
);
8119 cu_abbrev_offset_ptr
= hdrptr
;
8120 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
8121 hdrptr
+= offset_size
;
8123 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
8127 cu_offset
= start
- section_begin
;
8128 start
+= compunit
.cu_length
+ initial_length_size
;
8130 printf (_(" Compilation Unit @ %lx:\n"), cu_offset
);
8131 printf (_(" Length: %ld\n"), compunit
.cu_length
);
8132 printf (_(" Version: %d\n"), compunit
.cu_version
);
8133 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
8134 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
8136 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
8138 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
8144 /* Read in the abbrevs used by this compilation unit. */
8146 Elf_Internal_Shdr
*sec
;
8147 unsigned char *begin
;
8149 /* Locate the .debug_abbrev section and process it. */
8150 for (i
= 0, sec
= section_headers
;
8151 i
< elf_header
.e_shnum
;
8153 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
8156 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
8158 warn (_("Unable to locate .debug_abbrev section!\n"));
8162 begin
= get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
8163 _("debug_abbrev section data"));
8167 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
8168 begin
+ sec
->sh_size
);
8174 while (tags
< start
)
8177 unsigned long abbrev_number
;
8178 abbrev_entry
*entry
;
8181 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
8184 /* A null DIE marks the end of a list of children. */
8185 if (abbrev_number
== 0)
8191 /* Scan through the abbreviation list until we reach the
8193 for (entry
= first_abbrev
;
8194 entry
&& entry
->entry
!= abbrev_number
;
8195 entry
= entry
->next
)
8200 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8205 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8207 (unsigned long) (tags
- section_begin
- bytes_read
),
8209 get_TAG_name (entry
->tag
));
8211 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
8212 tags
= read_and_display_attr (attr
->attribute
,
8215 compunit
.cu_pointer_size
,
8217 compunit
.cu_version
);
8219 if (entry
->children
)
8233 display_debug_aranges (Elf_Internal_Shdr
*section
,
8234 unsigned char *start
,
8235 FILE *file ATTRIBUTE_UNUSED
)
8237 unsigned char *end
= start
+ section
->sh_size
;
8239 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8243 unsigned char *hdrptr
;
8244 DWARF2_Internal_ARange arange
;
8245 unsigned char *ranges
;
8246 unsigned long length
;
8247 unsigned long address
;
8250 int initial_length_size
;
8254 arange
.ar_length
= byte_get (hdrptr
, 4);
8257 if (arange
.ar_length
== 0xffffffff)
8259 arange
.ar_length
= byte_get (hdrptr
, 8);
8262 initial_length_size
= 12;
8267 initial_length_size
= 4;
8270 arange
.ar_version
= byte_get (hdrptr
, 2);
8273 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
8274 hdrptr
+= offset_size
;
8276 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
8279 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
8282 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
8284 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
8288 printf (_(" Length: %ld\n"), arange
.ar_length
);
8289 printf (_(" Version: %d\n"), arange
.ar_version
);
8290 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
8291 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
8292 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
8294 printf (_("\n Address Length\n"));
8298 /* Must pad to an alignment boundary that is twice the pointer size. */
8299 excess
= (hdrptr
- start
) % (2 * arange
.ar_pointer_size
);
8301 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
8305 address
= byte_get (ranges
, arange
.ar_pointer_size
);
8307 ranges
+= arange
.ar_pointer_size
;
8309 length
= byte_get (ranges
, arange
.ar_pointer_size
);
8311 ranges
+= arange
.ar_pointer_size
;
8313 /* A pair of zeros marks the end of the list. */
8314 if (address
== 0 && length
== 0)
8317 printf (" %8.8lx %lu\n", address
, length
);
8320 start
+= arange
.ar_length
+ initial_length_size
;
8328 typedef struct Frame_Chunk
8330 struct Frame_Chunk
*next
;
8331 unsigned char *chunk_start
;
8333 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8334 short int *col_type
;
8337 unsigned int code_factor
;
8339 unsigned long pc_begin
;
8340 unsigned long pc_range
;
8344 unsigned char fde_encoding
;
8345 unsigned char cfa_exp
;
8349 /* A marker for a col_type that means this column was never referenced
8350 in the frame info. */
8351 #define DW_CFA_unreferenced (-1)
8354 frame_need_space (Frame_Chunk
*fc
, int reg
)
8356 int prev
= fc
->ncols
;
8358 if (reg
< fc
->ncols
)
8361 fc
->ncols
= reg
+ 1;
8362 fc
->col_type
= xrealloc (fc
->col_type
, fc
->ncols
* sizeof (short int));
8363 fc
->col_offset
= xrealloc (fc
->col_offset
, fc
->ncols
* sizeof (int));
8365 while (prev
< fc
->ncols
)
8367 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8368 fc
->col_offset
[prev
] = 0;
8374 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
8379 if (*max_regs
< fc
->ncols
)
8380 *max_regs
= fc
->ncols
;
8382 if (*need_col_headers
)
8384 *need_col_headers
= 0;
8386 printf (" LOC CFA ");
8388 for (r
= 0; r
< *max_regs
; r
++)
8389 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8394 printf ("r%-4d", r
);
8400 printf ("%08lx ", fc
->pc_begin
);
8402 strcpy (tmp
, "exp");
8404 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
8405 printf ("%-8s ", tmp
);
8407 for (r
= 0; r
< fc
->ncols
; r
++)
8409 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8411 switch (fc
->col_type
[r
])
8413 case DW_CFA_undefined
:
8416 case DW_CFA_same_value
:
8420 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8422 case DW_CFA_register
:
8423 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
8425 case DW_CFA_expression
:
8426 strcpy (tmp
, "exp");
8429 strcpy (tmp
, "n/a");
8432 printf ("%-5s", tmp
);
8439 size_of_encoded_value (int encoding
)
8441 switch (encoding
& 0x7)
8444 case 0: return is_32bit_elf
? 4 : 8;
8452 get_encoded_value (unsigned char *data
, int encoding
)
8454 int size
= size_of_encoded_value (encoding
);
8455 if (encoding
& DW_EH_PE_signed
)
8456 return byte_get_signed (data
, size
);
8458 return byte_get (data
, size
);
8461 #define GET(N) byte_get (start, N); start += N
8462 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8463 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8466 display_debug_frames (Elf_Internal_Shdr
*section
,
8467 unsigned char *start
,
8468 FILE *file ATTRIBUTE_UNUSED
)
8470 unsigned char *end
= start
+ section
->sh_size
;
8471 unsigned char *section_start
= start
;
8472 Frame_Chunk
*chunks
= 0;
8473 Frame_Chunk
*remembered_state
= 0;
8475 int is_eh
= (strcmp (SECTION_NAME (section
), ".eh_frame") == 0);
8478 int addr_size
= is_32bit_elf
? 4 : 8;
8480 printf (_("The section %s contains:\n"), SECTION_NAME (section
));
8484 unsigned char *saved_start
;
8485 unsigned char *block_end
;
8486 unsigned long length
;
8487 unsigned long cie_id
;
8490 int need_col_headers
= 1;
8491 unsigned char *augmentation_data
= NULL
;
8492 unsigned long augmentation_data_len
= 0;
8493 int encoded_ptr_size
= addr_size
;
8495 int initial_length_size
;
8497 saved_start
= start
;
8498 length
= byte_get (start
, 4); start
+= 4;
8502 printf ("\n%08lx ZERO terminator\n\n",
8503 (unsigned long)(saved_start
- section_start
));
8507 if (length
== 0xffffffff)
8509 length
= byte_get (start
, 8);
8512 initial_length_size
= 12;
8517 initial_length_size
= 4;
8520 block_end
= saved_start
+ length
+ initial_length_size
;
8521 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
8523 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
8527 fc
= xmalloc (sizeof (Frame_Chunk
));
8528 memset (fc
, 0, sizeof (Frame_Chunk
));
8532 fc
->chunk_start
= saved_start
;
8534 fc
->col_type
= xmalloc (sizeof (short int));
8535 fc
->col_offset
= xmalloc (sizeof (int));
8536 frame_need_space (fc
, max_regs
-1);
8540 fc
->augmentation
= start
;
8541 start
= strchr (start
, '\0') + 1;
8543 if (fc
->augmentation
[0] == 'z')
8545 fc
->code_factor
= LEB ();
8546 fc
->data_factor
= SLEB ();
8547 fc
->ra
= byte_get (start
, 1); start
+= 1;
8548 augmentation_data_len
= LEB ();
8549 augmentation_data
= start
;
8550 start
+= augmentation_data_len
;
8552 else if (strcmp (fc
->augmentation
, "eh") == 0)
8555 fc
->code_factor
= LEB ();
8556 fc
->data_factor
= SLEB ();
8557 fc
->ra
= byte_get (start
, 1); start
+= 1;
8561 fc
->code_factor
= LEB ();
8562 fc
->data_factor
= SLEB ();
8563 fc
->ra
= byte_get (start
, 1); start
+= 1;
8567 if (do_debug_frames_interp
)
8568 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8569 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8570 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
8574 printf ("\n%08lx %08lx %08lx CIE\n",
8575 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
8576 printf (" Version: %d\n", version
);
8577 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8578 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8579 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8580 printf (" Return address column: %d\n", fc
->ra
);
8582 if (augmentation_data_len
)
8585 printf (" Augmentation data: ");
8586 for (i
= 0; i
< augmentation_data_len
; ++i
)
8587 printf (" %02x", augmentation_data
[i
]);
8593 if (augmentation_data_len
)
8595 unsigned char *p
, *q
;
8596 p
= fc
->augmentation
+ 1;
8597 q
= augmentation_data
;
8604 q
+= 1 + size_of_encoded_value (*q
);
8606 fc
->fde_encoding
= *q
++;
8612 if (fc
->fde_encoding
)
8613 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8616 frame_need_space (fc
, fc
->ra
);
8620 unsigned char *look_for
;
8621 static Frame_Chunk fde_fc
;
8624 memset (fc
, 0, sizeof (Frame_Chunk
));
8626 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
8628 for (cie
= chunks
; cie
; cie
= cie
->next
)
8629 if (cie
->chunk_start
== look_for
)
8634 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8635 cie_id
, saved_start
);
8638 fc
->col_type
= xmalloc (sizeof (short int));
8639 fc
->col_offset
= xmalloc (sizeof (int));
8640 frame_need_space (fc
, max_regs
- 1);
8642 fc
->augmentation
= "";
8643 fc
->fde_encoding
= 0;
8647 fc
->ncols
= cie
->ncols
;
8648 fc
->col_type
= xmalloc (fc
->ncols
* sizeof (short int));
8649 fc
->col_offset
= xmalloc (fc
->ncols
* sizeof (int));
8650 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8651 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8652 fc
->augmentation
= cie
->augmentation
;
8653 fc
->code_factor
= cie
->code_factor
;
8654 fc
->data_factor
= cie
->data_factor
;
8655 fc
->cfa_reg
= cie
->cfa_reg
;
8656 fc
->cfa_offset
= cie
->cfa_offset
;
8658 frame_need_space (fc
, max_regs
-1);
8659 fc
->fde_encoding
= cie
->fde_encoding
;
8662 if (fc
->fde_encoding
)
8663 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8665 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
8666 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
8667 fc
->pc_begin
+= section
->sh_addr
+ (start
- section_start
);
8668 start
+= encoded_ptr_size
;
8669 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
8670 start
+= encoded_ptr_size
;
8672 if (cie
->augmentation
[0] == 'z')
8674 augmentation_data_len
= LEB ();
8675 augmentation_data
= start
;
8676 start
+= augmentation_data_len
;
8679 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8680 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8681 (unsigned long)(cie
->chunk_start
- section_start
),
8682 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
8683 if (! do_debug_frames_interp
&& augmentation_data_len
)
8686 printf (" Augmentation data: ");
8687 for (i
= 0; i
< augmentation_data_len
; ++i
)
8688 printf (" %02x", augmentation_data
[i
]);
8694 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8695 about to interpret instructions for the chunk. */
8696 /* ??? At present we need to do this always, since this sizes the
8697 fc->col_type and fc->col_offset arrays, which we write into always.
8698 We should probably split the interpreted and non-interpreted bits
8699 into two different routines, since there's so much that doesn't
8700 really overlap between them. */
8701 if (1 || do_debug_frames_interp
)
8703 /* Start by making a pass over the chunk, allocating storage
8704 and taking note of what registers are used. */
8705 unsigned char *tmp
= start
;
8707 while (start
< block_end
)
8710 unsigned long reg
, tmp
;
8717 /* Warning: if you add any more cases to this switch, be
8718 sure to add them to the corresponding switch below. */
8721 case DW_CFA_advance_loc
:
8725 frame_need_space (fc
, opa
);
8726 fc
->col_type
[opa
] = DW_CFA_undefined
;
8728 case DW_CFA_restore
:
8729 frame_need_space (fc
, opa
);
8730 fc
->col_type
[opa
] = DW_CFA_undefined
;
8732 case DW_CFA_set_loc
:
8733 start
+= encoded_ptr_size
;
8735 case DW_CFA_advance_loc1
:
8738 case DW_CFA_advance_loc2
:
8741 case DW_CFA_advance_loc4
:
8744 case DW_CFA_offset_extended
:
8745 reg
= LEB (); LEB ();
8746 frame_need_space (fc
, reg
);
8747 fc
->col_type
[reg
] = DW_CFA_undefined
;
8749 case DW_CFA_restore_extended
:
8751 frame_need_space (fc
, reg
);
8752 fc
->col_type
[reg
] = DW_CFA_undefined
;
8754 case DW_CFA_undefined
:
8756 frame_need_space (fc
, reg
);
8757 fc
->col_type
[reg
] = DW_CFA_undefined
;
8759 case DW_CFA_same_value
:
8761 frame_need_space (fc
, reg
);
8762 fc
->col_type
[reg
] = DW_CFA_undefined
;
8764 case DW_CFA_register
:
8765 reg
= LEB (); LEB ();
8766 frame_need_space (fc
, reg
);
8767 fc
->col_type
[reg
] = DW_CFA_undefined
;
8769 case DW_CFA_def_cfa
:
8772 case DW_CFA_def_cfa_register
:
8775 case DW_CFA_def_cfa_offset
:
8778 case DW_CFA_def_cfa_expression
:
8782 case DW_CFA_expression
:
8786 frame_need_space (fc
, reg
);
8787 fc
->col_type
[reg
] = DW_CFA_undefined
;
8789 case DW_CFA_offset_extended_sf
:
8790 reg
= LEB (); SLEB ();
8791 frame_need_space (fc
, reg
);
8792 fc
->col_type
[reg
] = DW_CFA_undefined
;
8794 case DW_CFA_def_cfa_sf
:
8797 case DW_CFA_def_cfa_offset_sf
:
8800 case DW_CFA_MIPS_advance_loc8
:
8803 case DW_CFA_GNU_args_size
:
8806 case DW_CFA_GNU_negative_offset_extended
:
8807 reg
= LEB (); LEB ();
8808 frame_need_space (fc
, reg
);
8809 fc
->col_type
[reg
] = DW_CFA_undefined
;
8818 /* Now we know what registers are used, make a second pass over
8819 the chunk, this time actually printing out the info. */
8821 while (start
< block_end
)
8824 unsigned long ul
, reg
, roffs
;
8833 /* Warning: if you add any more cases to this switch, be
8834 sure to add them to the corresponding switch above. */
8837 case DW_CFA_advance_loc
:
8838 if (do_debug_frames_interp
)
8839 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8841 printf (" DW_CFA_advance_loc: %d to %08lx\n",
8842 opa
* fc
->code_factor
,
8843 fc
->pc_begin
+ opa
* fc
->code_factor
);
8844 fc
->pc_begin
+= opa
* fc
->code_factor
;
8849 if (! do_debug_frames_interp
)
8850 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
8851 opa
, roffs
* fc
->data_factor
);
8852 fc
->col_type
[opa
] = DW_CFA_offset
;
8853 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8856 case DW_CFA_restore
:
8857 if (! do_debug_frames_interp
)
8858 printf (" DW_CFA_restore: r%d\n", opa
);
8859 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8860 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8863 case DW_CFA_set_loc
:
8864 vma
= get_encoded_value (start
, fc
->fde_encoding
);
8865 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
8866 vma
+= section
->sh_addr
+ (start
- section_start
);
8867 start
+= encoded_ptr_size
;
8868 if (do_debug_frames_interp
)
8869 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8871 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
8875 case DW_CFA_advance_loc1
:
8876 ofs
= byte_get (start
, 1); start
+= 1;
8877 if (do_debug_frames_interp
)
8878 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8880 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
8881 ofs
* fc
->code_factor
,
8882 fc
->pc_begin
+ ofs
* fc
->code_factor
);
8883 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8886 case DW_CFA_advance_loc2
:
8887 ofs
= byte_get (start
, 2); start
+= 2;
8888 if (do_debug_frames_interp
)
8889 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8891 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
8892 ofs
* fc
->code_factor
,
8893 fc
->pc_begin
+ ofs
* fc
->code_factor
);
8894 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8897 case DW_CFA_advance_loc4
:
8898 ofs
= byte_get (start
, 4); start
+= 4;
8899 if (do_debug_frames_interp
)
8900 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8902 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
8903 ofs
* fc
->code_factor
,
8904 fc
->pc_begin
+ ofs
* fc
->code_factor
);
8905 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8908 case DW_CFA_offset_extended
:
8911 if (! do_debug_frames_interp
)
8912 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
8913 reg
, roffs
* fc
->data_factor
);
8914 fc
->col_type
[reg
] = DW_CFA_offset
;
8915 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8918 case DW_CFA_restore_extended
:
8920 if (! do_debug_frames_interp
)
8921 printf (" DW_CFA_restore_extended: r%ld\n", reg
);
8922 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8923 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8926 case DW_CFA_undefined
:
8928 if (! do_debug_frames_interp
)
8929 printf (" DW_CFA_undefined: r%ld\n", reg
);
8930 fc
->col_type
[reg
] = DW_CFA_undefined
;
8931 fc
->col_offset
[reg
] = 0;
8934 case DW_CFA_same_value
:
8936 if (! do_debug_frames_interp
)
8937 printf (" DW_CFA_same_value: r%ld\n", reg
);
8938 fc
->col_type
[reg
] = DW_CFA_same_value
;
8939 fc
->col_offset
[reg
] = 0;
8942 case DW_CFA_register
:
8945 if (! do_debug_frames_interp
)
8946 printf (" DW_CFA_register: r%ld in r%ld\n", reg
, roffs
);
8947 fc
->col_type
[reg
] = DW_CFA_register
;
8948 fc
->col_offset
[reg
] = roffs
;
8951 case DW_CFA_remember_state
:
8952 if (! do_debug_frames_interp
)
8953 printf (" DW_CFA_remember_state\n");
8954 rs
= xmalloc (sizeof (Frame_Chunk
));
8955 rs
->ncols
= fc
->ncols
;
8956 rs
->col_type
= xmalloc (rs
->ncols
* sizeof (short int));
8957 rs
->col_offset
= xmalloc (rs
->ncols
* sizeof (int));
8958 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
8959 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
8960 rs
->next
= remembered_state
;
8961 remembered_state
= rs
;
8964 case DW_CFA_restore_state
:
8965 if (! do_debug_frames_interp
)
8966 printf (" DW_CFA_restore_state\n");
8967 rs
= remembered_state
;
8968 remembered_state
= rs
->next
;
8969 frame_need_space (fc
, rs
->ncols
-1);
8970 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
8971 memcpy (fc
->col_offset
, rs
->col_offset
, rs
->ncols
* sizeof (int));
8972 free (rs
->col_type
);
8973 free (rs
->col_offset
);
8977 case DW_CFA_def_cfa
:
8978 fc
->cfa_reg
= LEB ();
8979 fc
->cfa_offset
= LEB ();
8981 if (! do_debug_frames_interp
)
8982 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
8983 fc
->cfa_reg
, fc
->cfa_offset
);
8986 case DW_CFA_def_cfa_register
:
8987 fc
->cfa_reg
= LEB ();
8989 if (! do_debug_frames_interp
)
8990 printf (" DW_CFA_def_cfa_reg: r%d\n", fc
->cfa_reg
);
8993 case DW_CFA_def_cfa_offset
:
8994 fc
->cfa_offset
= LEB ();
8995 if (! do_debug_frames_interp
)
8996 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
9000 if (! do_debug_frames_interp
)
9001 printf (" DW_CFA_nop\n");
9004 case DW_CFA_def_cfa_expression
:
9006 if (! do_debug_frames_interp
)
9008 printf (" DW_CFA_def_cfa_expression (");
9009 decode_location_expression (start
, addr_size
, ul
);
9016 case DW_CFA_expression
:
9019 if (! do_debug_frames_interp
)
9021 printf (" DW_CFA_expression: r%ld (", reg
);
9022 decode_location_expression (start
, addr_size
, ul
);
9025 fc
->col_type
[reg
] = DW_CFA_expression
;
9029 case DW_CFA_offset_extended_sf
:
9032 frame_need_space (fc
, reg
);
9033 if (! do_debug_frames_interp
)
9034 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
9035 reg
, l
* fc
->data_factor
);
9036 fc
->col_type
[reg
] = DW_CFA_offset
;
9037 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9040 case DW_CFA_def_cfa_sf
:
9041 fc
->cfa_reg
= LEB ();
9042 fc
->cfa_offset
= SLEB ();
9044 if (! do_debug_frames_interp
)
9045 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
9046 fc
->cfa_reg
, fc
->cfa_offset
);
9049 case DW_CFA_def_cfa_offset_sf
:
9050 fc
->cfa_offset
= SLEB ();
9051 if (! do_debug_frames_interp
)
9052 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
9055 case DW_CFA_MIPS_advance_loc8
:
9056 ofs
= byte_get (start
, 8); start
+= 8;
9057 if (do_debug_frames_interp
)
9058 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9060 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
9061 ofs
* fc
->code_factor
,
9062 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9063 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9066 case DW_CFA_GNU_window_save
:
9067 if (! do_debug_frames_interp
)
9068 printf (" DW_CFA_GNU_window_save\n");
9071 case DW_CFA_GNU_args_size
:
9073 if (! do_debug_frames_interp
)
9074 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9077 case DW_CFA_GNU_negative_offset_extended
:
9080 frame_need_space (fc
, reg
);
9081 if (! do_debug_frames_interp
)
9082 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
9083 reg
, l
* fc
->data_factor
);
9084 fc
->col_type
[reg
] = DW_CFA_offset
;
9085 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9089 fprintf (stderr
, "unsupported or unknown DW_CFA_%d\n", op
);
9094 if (do_debug_frames_interp
)
9095 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9110 display_debug_not_supported (Elf_Internal_Shdr
*section
,
9111 unsigned char *start ATTRIBUTE_UNUSED
,
9112 FILE *file ATTRIBUTE_UNUSED
)
9114 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9115 SECTION_NAME (section
));
9120 /* Pre-scan the .debug_info section to record the size of address.
9121 When dumping the .debug_line, we use that size information, assuming
9122 that all compilation units have the same address size. */
9124 prescan_debug_info (Elf_Internal_Shdr
*section ATTRIBUTE_UNUSED
,
9125 unsigned char *start
,
9126 FILE *file ATTRIBUTE_UNUSED
)
9128 unsigned long length
;
9130 /* Read the first 4 bytes. For a 32-bit DWARF section, this will
9131 be the length. For a 64-bit DWARF section, it'll be the escape
9132 code 0xffffffff followed by an 8 byte length. For the purposes
9133 of this prescan, we don't care about the actual length, but the
9134 presence of the escape bytes does affect the location of the byte
9135 which describes the address size. */
9136 length
= byte_get (start
, 4);
9138 if (length
== 0xffffffff)
9140 /* For 64-bit DWARF, the 1-byte address_size field is 22 bytes
9141 from the start of the section. This is computed as follows:
9143 unit_length: 12 bytes
9145 debug_abbrev_offset: 8 bytes
9146 -----------------------------
9149 debug_line_pointer_size
= byte_get (start
+ 22, 1);
9153 /* For 32-bit DWARF, the 1-byte address_size field is 10 bytes from
9154 the start of the section:
9155 unit_length: 4 bytes
9157 debug_abbrev_offset: 4 bytes
9158 -----------------------------
9161 debug_line_pointer_size
= byte_get (start
+ 10, 1);
9166 /* A structure containing the name of a debug section and a pointer
9167 to a function that can decode it. The third field is a prescan
9168 function to be run over the section before displaying any of the
9172 const char *const name
;
9173 int (*display
) (Elf_Internal_Shdr
*, unsigned char *, FILE *);
9174 int (*prescan
) (Elf_Internal_Shdr
*, unsigned char *, FILE *);
9178 { ".debug_abbrev", display_debug_abbrev
, NULL
},
9179 { ".debug_aranges", display_debug_aranges
, NULL
},
9180 { ".debug_frame", display_debug_frames
, NULL
},
9181 { ".debug_info", display_debug_info
, prescan_debug_info
},
9182 { ".debug_line", display_debug_lines
, NULL
},
9183 { ".debug_pubnames", display_debug_pubnames
, NULL
},
9184 { ".eh_frame", display_debug_frames
, NULL
},
9185 { ".debug_macinfo", display_debug_macinfo
, NULL
},
9186 { ".debug_str", display_debug_str
, NULL
},
9187 { ".debug_loc", display_debug_loc
, NULL
},
9188 { ".debug_pubtypes", display_debug_not_supported
, NULL
},
9189 { ".debug_ranges", display_debug_not_supported
, NULL
},
9190 { ".debug_static_func", display_debug_not_supported
, NULL
},
9191 { ".debug_static_vars", display_debug_not_supported
, NULL
},
9192 { ".debug_types", display_debug_not_supported
, NULL
},
9193 { ".debug_weaknames", display_debug_not_supported
, NULL
}
9197 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
9199 char *name
= SECTION_NAME (section
);
9200 bfd_size_type length
;
9201 unsigned char *start
;
9204 length
= section
->sh_size
;
9207 printf (_("\nSection '%s' has no debugging data.\n"), name
);
9211 start
= get_data (NULL
, file
, section
->sh_offset
, length
,
9212 _("debug section data"));
9216 /* See if we know how to display the contents of this section. */
9217 if (strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
9218 name
= ".debug_info";
9220 for (i
= NUM_ELEM (debug_displays
); i
--;)
9221 if (strcmp (debug_displays
[i
].name
, name
) == 0)
9223 debug_displays
[i
].display (section
, start
, file
);
9228 printf (_("Unrecognized debug section: %s\n"), name
);
9232 /* If we loaded in the abbrev section at some point,
9233 we must release it here. */
9240 process_section_contents (FILE *file
)
9242 Elf_Internal_Shdr
*section
;
9248 /* Pre-scan the debug sections to find some debug information not
9249 present in some of them. For the .debug_line, we must find out the
9250 size of address (specified in .debug_info and .debug_aranges). */
9251 for (i
= 0, section
= section_headers
;
9252 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9255 char *name
= SECTION_NAME (section
);
9258 if (section
->sh_size
== 0)
9261 /* See if there is some pre-scan operation for this section. */
9262 for (j
= NUM_ELEM (debug_displays
); j
--;)
9263 if (strcmp (debug_displays
[j
].name
, name
) == 0)
9265 if (debug_displays
[j
].prescan
!= NULL
)
9267 bfd_size_type length
;
9268 unsigned char *start
;
9270 length
= section
->sh_size
;
9271 start
= get_data (NULL
, file
, section
->sh_offset
, length
,
9272 _("debug section data"));
9276 debug_displays
[j
].prescan (section
, start
, file
);
9284 for (i
= 0, section
= section_headers
;
9285 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9288 #ifdef SUPPORT_DISASSEMBLY
9289 if (dump_sects
[i
] & DISASS_DUMP
)
9290 disassemble_section (section
, file
);
9292 if (dump_sects
[i
] & HEX_DUMP
)
9293 dump_section (section
, file
);
9295 if (dump_sects
[i
] & DEBUG_DUMP
)
9296 display_debug_section (section
, file
);
9299 if (i
< num_dump_sects
)
9300 warn (_("Some sections were not dumped because they do not exist!\n"));
9306 process_mips_fpe_exception (int mask
)
9311 if (mask
& OEX_FPU_INEX
)
9312 fputs ("INEX", stdout
), first
= 0;
9313 if (mask
& OEX_FPU_UFLO
)
9314 printf ("%sUFLO", first
? "" : "|"), first
= 0;
9315 if (mask
& OEX_FPU_OFLO
)
9316 printf ("%sOFLO", first
? "" : "|"), first
= 0;
9317 if (mask
& OEX_FPU_DIV0
)
9318 printf ("%sDIV0", first
? "" : "|"), first
= 0;
9319 if (mask
& OEX_FPU_INVAL
)
9320 printf ("%sINVAL", first
? "" : "|");
9323 fputs ("0", stdout
);
9327 process_mips_specific (FILE *file
)
9329 Elf_Internal_Dyn
*entry
;
9330 size_t liblist_offset
= 0;
9331 size_t liblistno
= 0;
9332 size_t conflictsno
= 0;
9333 size_t options_offset
= 0;
9334 size_t conflicts_offset
= 0;
9336 /* We have a lot of special sections. Thanks SGI! */
9337 if (dynamic_segment
== NULL
)
9338 /* No information available. */
9341 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
9342 switch (entry
->d_tag
)
9344 case DT_MIPS_LIBLIST
:
9346 = offset_from_vma (file
, entry
->d_un
.d_val
,
9347 liblistno
* sizeof (Elf32_External_Lib
));
9349 case DT_MIPS_LIBLISTNO
:
9350 liblistno
= entry
->d_un
.d_val
;
9352 case DT_MIPS_OPTIONS
:
9353 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
9355 case DT_MIPS_CONFLICT
:
9357 = offset_from_vma (file
, entry
->d_un
.d_val
,
9358 conflictsno
* sizeof (Elf32_External_Conflict
));
9360 case DT_MIPS_CONFLICTNO
:
9361 conflictsno
= entry
->d_un
.d_val
;
9367 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9369 Elf32_External_Lib
*elib
;
9372 elib
= get_data (NULL
, file
, liblist_offset
,
9373 liblistno
* sizeof (Elf32_External_Lib
),
9377 printf ("\nSection '.liblist' contains %lu entries:\n",
9378 (unsigned long) liblistno
);
9379 fputs (" Library Time Stamp Checksum Version Flags\n",
9382 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9389 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9390 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9391 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9392 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9393 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9395 tmp
= gmtime (&time
);
9396 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9397 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9398 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9400 printf ("%3lu: ", (unsigned long) cnt
);
9401 print_symbol (20, dynamic_strings
+ liblist
.l_name
);
9402 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9405 if (liblist
.l_flags
== 0)
9416 { " EXACT_MATCH", LL_EXACT_MATCH
},
9417 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9418 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9419 { " EXPORTS", LL_EXPORTS
},
9420 { " DELAY_LOAD", LL_DELAY_LOAD
},
9421 { " DELTA", LL_DELTA
}
9423 int flags
= liblist
.l_flags
;
9427 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
9429 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9431 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9432 flags
^= l_flags_vals
[fcnt
].bit
;
9435 printf (" %#x", (unsigned int) flags
);
9445 if (options_offset
!= 0)
9447 Elf_External_Options
*eopt
;
9448 Elf_Internal_Shdr
*sect
= section_headers
;
9449 Elf_Internal_Options
*iopt
;
9450 Elf_Internal_Options
*option
;
9454 /* Find the section header so that we get the size. */
9455 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9458 eopt
= get_data (NULL
, file
, options_offset
, sect
->sh_size
,
9462 iopt
= malloc ((sect
->sh_size
/ sizeof (eopt
)) * sizeof (*iopt
));
9465 error (_("Out of memory"));
9472 while (offset
< sect
->sh_size
)
9474 Elf_External_Options
*eoption
;
9476 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9478 option
->kind
= BYTE_GET (eoption
->kind
);
9479 option
->size
= BYTE_GET (eoption
->size
);
9480 option
->section
= BYTE_GET (eoption
->section
);
9481 option
->info
= BYTE_GET (eoption
->info
);
9483 offset
+= option
->size
;
9489 printf (_("\nSection '%s' contains %d entries:\n"),
9490 SECTION_NAME (sect
), cnt
);
9498 switch (option
->kind
)
9501 /* This shouldn't happen. */
9502 printf (" NULL %d %lx", option
->section
, option
->info
);
9505 printf (" REGINFO ");
9506 if (elf_header
.e_machine
== EM_MIPS
)
9509 Elf32_External_RegInfo
*ereg
;
9510 Elf32_RegInfo reginfo
;
9512 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9513 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9514 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9515 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9516 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9517 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9518 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9520 printf ("GPR %08lx GP 0x%lx\n",
9522 (unsigned long) reginfo
.ri_gp_value
);
9523 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9524 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9525 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9530 Elf64_External_RegInfo
*ereg
;
9531 Elf64_Internal_RegInfo reginfo
;
9533 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9534 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9535 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9536 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9537 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9538 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9539 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
9541 printf ("GPR %08lx GP 0x",
9542 reginfo
.ri_gprmask
);
9543 printf_vma (reginfo
.ri_gp_value
);
9546 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9547 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9548 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9552 case ODK_EXCEPTIONS
:
9553 fputs (" EXCEPTIONS fpe_min(", stdout
);
9554 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9555 fputs (") fpe_max(", stdout
);
9556 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9557 fputs (")", stdout
);
9559 if (option
->info
& OEX_PAGE0
)
9560 fputs (" PAGE0", stdout
);
9561 if (option
->info
& OEX_SMM
)
9562 fputs (" SMM", stdout
);
9563 if (option
->info
& OEX_FPDBUG
)
9564 fputs (" FPDBUG", stdout
);
9565 if (option
->info
& OEX_DISMISS
)
9566 fputs (" DISMISS", stdout
);
9569 fputs (" PAD ", stdout
);
9570 if (option
->info
& OPAD_PREFIX
)
9571 fputs (" PREFIX", stdout
);
9572 if (option
->info
& OPAD_POSTFIX
)
9573 fputs (" POSTFIX", stdout
);
9574 if (option
->info
& OPAD_SYMBOL
)
9575 fputs (" SYMBOL", stdout
);
9578 fputs (" HWPATCH ", stdout
);
9579 if (option
->info
& OHW_R4KEOP
)
9580 fputs (" R4KEOP", stdout
);
9581 if (option
->info
& OHW_R8KPFETCH
)
9582 fputs (" R8KPFETCH", stdout
);
9583 if (option
->info
& OHW_R5KEOP
)
9584 fputs (" R5KEOP", stdout
);
9585 if (option
->info
& OHW_R5KCVTL
)
9586 fputs (" R5KCVTL", stdout
);
9589 fputs (" FILL ", stdout
);
9590 /* XXX Print content of info word? */
9593 fputs (" TAGS ", stdout
);
9594 /* XXX Print content of info word? */
9597 fputs (" HWAND ", stdout
);
9598 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9599 fputs (" R4KEOP_CHECKED", stdout
);
9600 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9601 fputs (" R4KEOP_CLEAN", stdout
);
9604 fputs (" HWOR ", stdout
);
9605 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9606 fputs (" R4KEOP_CHECKED", stdout
);
9607 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9608 fputs (" R4KEOP_CLEAN", stdout
);
9611 printf (" GP_GROUP %#06lx self-contained %#06lx",
9612 option
->info
& OGP_GROUP
,
9613 (option
->info
& OGP_SELF
) >> 16);
9616 printf (" IDENT %#06lx self-contained %#06lx",
9617 option
->info
& OGP_GROUP
,
9618 (option
->info
& OGP_SELF
) >> 16);
9621 /* This shouldn't happen. */
9622 printf (" %3d ??? %d %lx",
9623 option
->kind
, option
->section
, option
->info
);
9627 len
= sizeof (*eopt
);
9628 while (len
< option
->size
)
9629 if (((char *) option
)[len
] >= ' '
9630 && ((char *) option
)[len
] < 0x7f)
9631 printf ("%c", ((char *) option
)[len
++]);
9633 printf ("\\%03o", ((char *) option
)[len
++]);
9635 fputs ("\n", stdout
);
9643 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9645 Elf32_Conflict
*iconf
;
9648 if (dynamic_symbols
== NULL
)
9650 error (_("conflict list found without a dynamic symbol table"));
9654 iconf
= malloc (conflictsno
* sizeof (*iconf
));
9657 error (_("Out of memory"));
9663 Elf32_External_Conflict
*econf32
;
9665 econf32
= get_data (NULL
, file
, conflicts_offset
,
9666 conflictsno
* sizeof (*econf32
), _("conflict"));
9670 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9671 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9677 Elf64_External_Conflict
*econf64
;
9679 econf64
= get_data (NULL
, file
, conflicts_offset
,
9680 conflictsno
* sizeof (*econf64
), _("conflict"));
9684 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9685 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9690 printf (_("\nSection '.conflict' contains %ld entries:\n"),
9691 (long) conflictsno
);
9692 puts (_(" Num: Index Value Name"));
9694 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9696 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
9698 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9699 print_vma (psym
->st_value
, FULL_HEX
);
9701 print_symbol (25, dynamic_strings
+ psym
->st_name
);
9712 process_gnu_liblist (FILE *file
)
9714 Elf_Internal_Shdr
*section
, *string_sec
;
9715 Elf32_External_Lib
*elib
;
9723 for (i
= 0, section
= section_headers
;
9724 i
< elf_header
.e_shnum
;
9727 switch (section
->sh_type
)
9729 case SHT_GNU_LIBLIST
:
9730 elib
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
9735 string_sec
= SECTION_HEADER (section
->sh_link
);
9737 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
9738 string_sec
->sh_size
, _("liblist string table"));
9741 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9747 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9748 SECTION_NAME (section
),
9749 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9751 puts (" Library Time Stamp Checksum Version Flags");
9753 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9761 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9762 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9763 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9764 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9765 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9767 tmp
= gmtime (&time
);
9768 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9769 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9770 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9772 printf ("%3lu: ", (unsigned long) cnt
);
9774 printf ("%-20s", strtab
+ liblist
.l_name
);
9776 printf ("%-20.20s", strtab
+ liblist
.l_name
);
9777 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9778 liblist
.l_version
, liblist
.l_flags
);
9789 get_note_type (unsigned e_type
)
9791 static char buff
[64];
9795 case NT_PRSTATUS
: return _("NT_PRSTATUS (prstatus structure)");
9796 case NT_FPREGSET
: return _("NT_FPREGSET (floating point registers)");
9797 case NT_PRPSINFO
: return _("NT_PRPSINFO (prpsinfo structure)");
9798 case NT_TASKSTRUCT
: return _("NT_TASKSTRUCT (task structure)");
9799 case NT_PRXFPREG
: return _("NT_PRXFPREG (user_xfpregs structure)");
9800 case NT_PSTATUS
: return _("NT_PSTATUS (pstatus structure)");
9801 case NT_FPREGS
: return _("NT_FPREGS (floating point registers)");
9802 case NT_PSINFO
: return _("NT_PSINFO (psinfo structure)");
9803 case NT_LWPSTATUS
: return _("NT_LWPSTATUS (lwpstatus_t structure)");
9804 case NT_LWPSINFO
: return _("NT_LWPSINFO (lwpsinfo_t structure)");
9805 case NT_WIN32PSTATUS
: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9807 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
9813 get_netbsd_elfcore_note_type (unsigned e_type
)
9815 static char buff
[64];
9817 if (e_type
== NT_NETBSDCORE_PROCINFO
)
9819 /* NetBSD core "procinfo" structure. */
9820 return _("NetBSD procinfo structure");
9823 /* As of Jan 2002 there are no other machine-independent notes
9824 defined for NetBSD core files. If the note type is less
9825 than the start of the machine-dependent note types, we don't
9828 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
9830 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
9834 switch (elf_header
.e_machine
)
9836 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9837 and PT_GETFPREGS == mach+2. */
9842 case EM_SPARC32PLUS
:
9846 case NT_NETBSDCORE_FIRSTMACH
+0:
9847 return _("PT_GETREGS (reg structure)");
9848 case NT_NETBSDCORE_FIRSTMACH
+2:
9849 return _("PT_GETFPREGS (fpreg structure)");
9855 /* On all other arch's, PT_GETREGS == mach+1 and
9856 PT_GETFPREGS == mach+3. */
9860 case NT_NETBSDCORE_FIRSTMACH
+1:
9861 return _("PT_GETREGS (reg structure)");
9862 case NT_NETBSDCORE_FIRSTMACH
+3:
9863 return _("PT_GETFPREGS (fpreg structure)");
9869 sprintf (buff
, _("PT_FIRSTMACH+%d"), e_type
- NT_NETBSDCORE_FIRSTMACH
);
9873 /* Note that by the ELF standard, the name field is already null byte
9874 terminated, and namesz includes the terminating null byte.
9875 I.E. the value of namesz for the name "FSF" is 4.
9877 If the value of namesz is zero, there is no name present. */
9879 process_note (Elf_Internal_Note
*pnote
)
9883 if (pnote
->namesz
== 0)
9885 /* If there is no note name, then use the default set of
9886 note type strings. */
9887 nt
= get_note_type (pnote
->type
);
9889 else if (strncmp (pnote
->namedata
, "NetBSD-CORE", 11) == 0)
9891 /* NetBSD-specific core file notes. */
9892 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
9896 /* Don't recognize this note name; just use the default set of
9897 note type strings. */
9898 nt
= get_note_type (pnote
->type
);
9901 printf (" %s\t\t0x%08lx\t%s\n",
9902 pnote
->namesz
? pnote
->namedata
: "(NONE)",
9909 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
9911 Elf_External_Note
*pnotes
;
9912 Elf_External_Note
*external
;
9918 pnotes
= get_data (NULL
, file
, offset
, length
, _("notes"));
9924 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9925 (unsigned long) offset
, (unsigned long) length
);
9926 printf (_(" Owner\t\tData size\tDescription\n"));
9928 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
9930 Elf_External_Note
*next
;
9931 Elf_Internal_Note inote
;
9934 inote
.type
= BYTE_GET (external
->type
);
9935 inote
.namesz
= BYTE_GET (external
->namesz
);
9936 inote
.namedata
= external
->name
;
9937 inote
.descsz
= BYTE_GET (external
->descsz
);
9938 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
9939 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
9941 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
9943 if (((char *) next
) > (((char *) pnotes
) + length
))
9945 warn (_("corrupt note found at offset %x into core notes\n"),
9946 ((char *) external
) - ((char *) pnotes
));
9947 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
9948 inote
.type
, inote
.namesz
, inote
.descsz
);
9954 /* Verify that name is null terminated. It appears that at least
9955 one version of Linux (RedHat 6.0) generates corefiles that don't
9956 comply with the ELF spec by failing to include the null byte in
9958 if (inote
.namedata
[inote
.namesz
] != '\0')
9960 temp
= malloc (inote
.namesz
+ 1);
9964 error (_("Out of memory\n"));
9969 strncpy (temp
, inote
.namedata
, inote
.namesz
);
9970 temp
[inote
.namesz
] = 0;
9972 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9973 inote
.namedata
= temp
;
9976 res
&= process_note (& inote
);
9991 process_corefile_note_segments (FILE *file
)
9993 Elf_Internal_Phdr
*segment
;
9997 if (! get_program_headers (file
))
10000 for (i
= 0, segment
= program_headers
;
10001 i
< elf_header
.e_phnum
;
10004 if (segment
->p_type
== PT_NOTE
)
10005 res
&= process_corefile_note_segment (file
,
10006 (bfd_vma
) segment
->p_offset
,
10007 (bfd_vma
) segment
->p_filesz
);
10014 process_corefile_contents (FILE *file
)
10016 /* If we have not been asked to display the notes then do nothing. */
10020 /* If file is not a core file then exit. */
10021 if (elf_header
.e_type
!= ET_CORE
)
10024 /* No program headers means no NOTE segment. */
10025 if (elf_header
.e_phnum
== 0)
10027 printf (_("No note segments present in the core file.\n"));
10031 return process_corefile_note_segments (file
);
10035 process_arch_specific (FILE *file
)
10040 switch (elf_header
.e_machine
)
10043 case EM_MIPS_RS3_LE
:
10044 return process_mips_specific (file
);
10053 get_file_header (FILE *file
)
10055 /* Read in the identity array. */
10056 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
10059 /* Determine how to read the rest of the header. */
10060 switch (elf_header
.e_ident
[EI_DATA
])
10062 default: /* fall through */
10063 case ELFDATANONE
: /* fall through */
10065 byte_get
= byte_get_little_endian
;
10066 byte_put
= byte_put_little_endian
;
10069 byte_get
= byte_get_big_endian
;
10070 byte_put
= byte_put_big_endian
;
10074 /* For now we only support 32 bit and 64 bit ELF files. */
10075 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
10077 /* Read in the rest of the header. */
10080 Elf32_External_Ehdr ehdr32
;
10082 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
10085 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
10086 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
10087 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
10088 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
10089 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
10090 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
10091 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
10092 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
10093 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
10094 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
10095 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
10096 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
10097 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
10101 Elf64_External_Ehdr ehdr64
;
10103 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10104 we will not be able to cope with the 64bit data found in
10105 64 ELF files. Detect this now and abort before we start
10106 overwritting things. */
10107 if (sizeof (bfd_vma
) < 8)
10109 error (_("This instance of readelf has been built without support for a\n\
10110 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10114 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
10117 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
10118 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
10119 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
10120 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
10121 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
10122 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
10123 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
10124 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
10125 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
10126 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
10127 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
10128 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
10129 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
10132 if (elf_header
.e_shoff
)
10134 /* There may be some extensions in the first section header. Don't
10135 bomb if we can't read it. */
10137 get_32bit_section_headers (file
, 1);
10139 get_64bit_section_headers (file
, 1);
10146 process_file (char *file_name
)
10149 struct stat statbuf
;
10152 if (stat (file_name
, & statbuf
) < 0)
10154 error (_("Cannot stat input file %s.\n"), file_name
);
10158 file
= fopen (file_name
, "rb");
10161 error (_("Input file %s not found.\n"), file_name
);
10165 if (! get_file_header (file
))
10167 error (_("%s: Failed to read file header\n"), file_name
);
10172 /* Initialise per file variables. */
10173 for (i
= NUM_ELEM (version_info
); i
--;)
10174 version_info
[i
] = 0;
10176 for (i
= NUM_ELEM (dynamic_info
); i
--;)
10177 dynamic_info
[i
] = 0;
10179 /* Process the file. */
10181 printf (_("\nFile: %s\n"), file_name
);
10183 if (! process_file_header ())
10189 if (! process_section_headers (file
))
10191 /* Without loaded section headers we
10192 cannot process lots of things. */
10193 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10195 if (! do_using_dynamic
)
10196 do_syms
= do_reloc
= 0;
10199 if (process_program_headers (file
))
10200 process_dynamic_segment (file
);
10202 process_relocs (file
);
10204 process_unwind (file
);
10206 process_symbol_table (file
);
10208 process_syminfo (file
);
10210 process_version_sections (file
);
10212 process_section_contents (file
);
10214 process_corefile_contents (file
);
10216 process_gnu_liblist (file
);
10218 process_arch_specific (file
);
10222 if (program_headers
)
10224 free (program_headers
);
10225 program_headers
= NULL
;
10228 if (section_headers
)
10230 free (section_headers
);
10231 section_headers
= NULL
;
10236 free (string_table
);
10237 string_table
= NULL
;
10238 string_table_length
= 0;
10241 if (dynamic_strings
)
10243 free (dynamic_strings
);
10244 dynamic_strings
= NULL
;
10247 if (dynamic_symbols
)
10249 free (dynamic_symbols
);
10250 dynamic_symbols
= NULL
;
10251 num_dynamic_syms
= 0;
10254 if (dynamic_syminfo
)
10256 free (dynamic_syminfo
);
10257 dynamic_syminfo
= NULL
;
10263 #ifdef SUPPORT_DISASSEMBLY
10264 /* Needed by the i386 disassembler. For extra credit, someone could
10265 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10269 print_address (unsigned int addr
, FILE *outfile
)
10271 fprintf (outfile
,"0x%8.8x", addr
);
10274 /* Needed by the i386 disassembler. */
10276 db_task_printsym (unsigned int addr
)
10278 print_address (addr
, stderr
);
10283 main (int argc
, char **argv
)
10286 char *cmdline_dump_sects
= NULL
;
10287 unsigned num_cmdline_dump_sects
= 0;
10289 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10290 setlocale (LC_MESSAGES
, "");
10292 #if defined (HAVE_SETLOCALE)
10293 setlocale (LC_CTYPE
, "");
10295 bindtextdomain (PACKAGE
, LOCALEDIR
);
10296 textdomain (PACKAGE
);
10298 parse_args (argc
, argv
);
10300 if (optind
< (argc
- 1))
10303 /* When processing more than one file remember the dump requests
10304 issued on command line to reset them after each file. */
10305 if (optind
+ 1 < argc
&& dump_sects
!= NULL
)
10307 cmdline_dump_sects
= malloc (num_dump_sects
);
10308 if (cmdline_dump_sects
== NULL
)
10309 error (_("Out of memory allocating dump request table."));
10312 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
10313 num_cmdline_dump_sects
= num_dump_sects
;
10318 while (optind
< argc
)
10320 err
|= process_file (argv
[optind
++]);
10322 /* Reset dump requests. */
10323 if (optind
< argc
&& dump_sects
!= NULL
)
10325 num_dump_sects
= num_cmdline_dump_sects
;
10326 if (num_cmdline_dump_sects
> 0)
10327 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
10331 if (dump_sects
!= NULL
)
10333 if (cmdline_dump_sects
!= NULL
)
10334 free (cmdline_dump_sects
);