1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 /* The difference between readelf and objdump:
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
45 #include <sys/types.h>
51 /* Define BFD64 here, even if our default architecture is 32 bit ELF
52 as this will allow us to read in and parse 64bit and 32bit ELF files.
53 Only do this if we believe that the compiler can support a 64 bit
54 data type. For now we only rely on GCC being able to do this. */
60 #include "elf/common.h"
61 #include "elf/external.h"
62 #include "elf/internal.h"
63 #include "elf/dwarf2.h"
65 /* The following headers use the elf/reloc-macros.h file to
66 automatically generate relocation recognition functions
67 such as elf_mips_reloc_type() */
69 #define RELOC_MACROS_GEN_FUNC
71 #include "elf/alpha.h"
91 #include "elf/m68hc11.h"
92 #include "elf/mcore.h"
95 #include "elf/mn10200.h"
96 #include "elf/mn10300.h"
97 #include "elf/msp430.h"
101 #include "elf/ppc64.h"
102 #include "elf/s390.h"
104 #include "elf/sparc.h"
105 #include "elf/v850.h"
107 #include "elf/x86-64.h"
108 #include "elf/xstormy16.h"
110 #include "elf/iq2000.h"
111 #include "elf/xtensa.h"
117 #include "libiberty.h"
119 char *program_name
= "readelf";
120 long archive_file_offset
;
121 unsigned long archive_file_size
;
122 unsigned long dynamic_addr
;
123 bfd_size_type dynamic_size
;
124 unsigned int dynamic_nent
;
125 char *dynamic_strings
;
126 unsigned long dynamic_strings_length
;
128 unsigned long string_table_length
;
129 unsigned long num_dynamic_syms
;
130 Elf_Internal_Sym
*dynamic_symbols
;
131 Elf_Internal_Syminfo
*dynamic_syminfo
;
132 unsigned long dynamic_syminfo_offset
;
133 unsigned int dynamic_syminfo_nent
;
134 char program_interpreter
[64];
135 bfd_vma dynamic_info
[DT_JMPREL
+ 1];
136 bfd_vma version_info
[16];
137 Elf_Internal_Ehdr elf_header
;
138 Elf_Internal_Shdr
*section_headers
;
139 Elf_Internal_Phdr
*program_headers
;
140 Elf_Internal_Dyn
*dynamic_section
;
141 Elf_Internal_Shdr
*symtab_shndx_hdr
;
147 int do_section_groups
;
150 int do_using_dynamic
;
158 int do_debug_abbrevs
;
160 int do_debug_pubnames
;
161 int do_debug_aranges
;
164 int do_debug_frames_interp
;
165 int do_debug_macinfo
;
172 int need_base_address
;
176 struct group_list
*next
;
177 unsigned int section_index
;
182 struct group_list
*root
;
183 unsigned int group_index
;
186 struct group
*section_groups
;
187 size_t group_count
= 0;
189 struct group
**section_headers_groups
;
191 /* A dynamic array of flags indicating for which sections a hex dump
192 has been requested (via the -x switch) and/or a disassembly dump
193 (via the -i switch). */
194 char *cmdline_dump_sects
= NULL
;
195 unsigned num_cmdline_dump_sects
= 0;
197 /* A dynamic array of flags indicating for which sections a dump of
198 some kind has been requested. It is reset on a per-object file
199 basis and then initialised from the cmdline_dump_sects array and
200 the results of interpreting the -w switch. */
201 char *dump_sects
= NULL
;
202 unsigned int num_dump_sects
= 0;
204 #define HEX_DUMP (1 << 0)
205 #define DISASS_DUMP (1 << 1)
206 #define DEBUG_DUMP (1 << 2)
208 /* How to rpint a vma value. */
209 typedef enum print_mode
221 static bfd_vma (*byte_get
) (unsigned char *, int);
222 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
226 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
227 ((X)->sh_name >= string_table_length \
228 ? "<corrupt>" : string_table + (X)->sh_name))
230 /* Given st_shndx I, map to section_headers index. */
231 #define SECTION_HEADER_INDEX(I) \
232 ((I) < SHN_LORESERVE \
234 : ((I) <= SHN_HIRESERVE \
236 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
238 /* Reverse of the above. */
239 #define SECTION_HEADER_NUM(N) \
240 ((N) < SHN_LORESERVE \
242 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
244 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
246 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
248 #define BYTE_GET(field) byte_get (field, sizeof (field))
250 /* If we can support a 64 bit data type then BFD64 should be defined
251 and sizeof (bfd_vma) == 8. In this case when translating from an
252 external 8 byte field to an internal field, we can assume that the
253 internal field is also 8 bytes wide and so we can extract all the data.
254 If, however, BFD64 is not defined, then we must assume that the
255 internal data structure only has 4 byte wide fields that are the
256 equivalent of the 8 byte wide external counterparts, and so we must
257 truncate the data. */
259 #define BYTE_GET8(field) byte_get (field, -8)
261 #define BYTE_GET8(field) byte_get (field, 8)
264 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
266 #define GET_ELF_SYMBOLS(file, section) \
267 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
268 : get_64bit_elf_symbols (file, section))
270 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
271 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
272 already been called and verified that the string exists. */
273 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
275 /* This is just a bit of syntatic sugar. */
276 #define streq(a,b) (strcmp ((a), (b)) == 0)
277 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
280 error (const char *message
, ...)
284 va_start (args
, message
);
285 fprintf (stderr
, _("%s: Error: "), program_name
);
286 vfprintf (stderr
, message
, args
);
291 warn (const char *message
, ...)
295 va_start (args
, message
);
296 fprintf (stderr
, _("%s: Warning: "), program_name
);
297 vfprintf (stderr
, message
, args
);
302 get_data (void *var
, FILE *file
, long offset
, size_t size
, const char *reason
)
309 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
311 error (_("Unable to seek to 0x%x for %s\n"),
312 archive_file_offset
+ offset
, reason
);
319 mvar
= malloc (size
);
323 error (_("Out of memory allocating 0x%x bytes for %s\n"),
329 if (fread (mvar
, size
, 1, file
) != 1)
331 error (_("Unable to read in 0x%x bytes of %s\n"), size
, reason
);
341 byte_get_little_endian (unsigned char *field
, int size
)
349 return ((unsigned int) (field
[0]))
350 | (((unsigned int) (field
[1])) << 8);
354 /* We want to extract data from an 8 byte wide field and
355 place it into a 4 byte wide field. Since this is a little
356 endian source we can just use the 4 byte extraction code. */
360 return ((unsigned long) (field
[0]))
361 | (((unsigned long) (field
[1])) << 8)
362 | (((unsigned long) (field
[2])) << 16)
363 | (((unsigned long) (field
[3])) << 24);
368 /* This is a special case, generated by the BYTE_GET8 macro.
369 It means that we are loading an 8 byte value from a field
370 in an external structure into an 8 byte value in a field
371 in an internal structure. */
372 return ((bfd_vma
) (field
[0]))
373 | (((bfd_vma
) (field
[1])) << 8)
374 | (((bfd_vma
) (field
[2])) << 16)
375 | (((bfd_vma
) (field
[3])) << 24)
376 | (((bfd_vma
) (field
[4])) << 32)
377 | (((bfd_vma
) (field
[5])) << 40)
378 | (((bfd_vma
) (field
[6])) << 48)
379 | (((bfd_vma
) (field
[7])) << 56);
382 error (_("Unhandled data length: %d\n"), size
);
388 byte_get_signed (unsigned char *field
, int size
)
390 bfd_vma x
= byte_get (field
, size
);
395 return (x
^ 0x80) - 0x80;
397 return (x
^ 0x8000) - 0x8000;
399 return (x
^ 0x80000000) - 0x80000000;
409 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
414 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
415 field
[6] = ((value
>> 24) >> 24) & 0xff;
416 field
[5] = ((value
>> 24) >> 16) & 0xff;
417 field
[4] = ((value
>> 24) >> 8) & 0xff;
420 field
[3] = (value
>> 24) & 0xff;
421 field
[2] = (value
>> 16) & 0xff;
424 field
[1] = (value
>> 8) & 0xff;
427 field
[0] = value
& 0xff;
431 error (_("Unhandled data length: %d\n"), size
);
436 /* Print a VMA value. */
438 print_vma (bfd_vma vma
, print_mode mode
)
450 printf ("%8.8lx", (unsigned long) vma
);
456 printf ("%5ld", (long) vma
);
464 printf ("%lx", (unsigned long) vma
);
468 printf ("%ld", (unsigned long) vma
);
472 printf ("%lu", (unsigned long) vma
);
494 #if BFD_HOST_64BIT_LONG
497 if (_bfd_int64_high (vma
))
498 printf ("%lx%8.8lx", _bfd_int64_high (vma
), _bfd_int64_low (vma
));
500 printf ("%lx", _bfd_int64_low (vma
));
505 #if BFD_HOST_64BIT_LONG
508 if (_bfd_int64_high (vma
))
510 printf ("++%ld", _bfd_int64_low (vma
));
512 printf ("%ld", _bfd_int64_low (vma
));
517 #if BFD_HOST_64BIT_LONG
519 printf ("%5ld", vma
);
521 printf ("%#lx", vma
);
523 if (_bfd_int64_high (vma
))
525 printf ("++%ld", _bfd_int64_low (vma
));
526 else if (vma
<= 99999)
527 printf ("%5ld", _bfd_int64_low (vma
));
529 printf ("%#lx", _bfd_int64_low (vma
));
534 #if BFD_HOST_64BIT_LONG
537 if (_bfd_int64_high (vma
))
539 printf ("++%lu", _bfd_int64_low (vma
));
541 printf ("%lu", _bfd_int64_low (vma
));
549 /* Display a symbol on stdout. If do_wide is not true then
550 format the symbol to be at most WIDTH characters,
551 truncating as necessary. If WIDTH is negative then
552 format the string to be exactly - WIDTH characters,
553 truncating or padding as necessary. */
556 print_symbol (int width
, const char *symbol
)
559 printf ("%s", symbol
);
561 printf ("%-*.*s", width
, width
, symbol
);
563 printf ("%-.*s", width
, symbol
);
567 byte_get_big_endian (unsigned char *field
, int size
)
575 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
578 return ((unsigned long) (field
[3]))
579 | (((unsigned long) (field
[2])) << 8)
580 | (((unsigned long) (field
[1])) << 16)
581 | (((unsigned long) (field
[0])) << 24);
585 /* Although we are extracing data from an 8 byte wide field,
586 we are returning only 4 bytes of data. */
587 return ((unsigned long) (field
[7]))
588 | (((unsigned long) (field
[6])) << 8)
589 | (((unsigned long) (field
[5])) << 16)
590 | (((unsigned long) (field
[4])) << 24);
594 /* This is a special case, generated by the BYTE_GET8 macro.
595 It means that we are loading an 8 byte value from a field
596 in an external structure into an 8 byte value in a field
597 in an internal structure. */
598 return ((bfd_vma
) (field
[7]))
599 | (((bfd_vma
) (field
[6])) << 8)
600 | (((bfd_vma
) (field
[5])) << 16)
601 | (((bfd_vma
) (field
[4])) << 24)
602 | (((bfd_vma
) (field
[3])) << 32)
603 | (((bfd_vma
) (field
[2])) << 40)
604 | (((bfd_vma
) (field
[1])) << 48)
605 | (((bfd_vma
) (field
[0])) << 56);
609 error (_("Unhandled data length: %d\n"), size
);
615 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
620 field
[7] = value
& 0xff;
621 field
[6] = (value
>> 8) & 0xff;
622 field
[5] = (value
>> 16) & 0xff;
623 field
[4] = (value
>> 24) & 0xff;
628 field
[3] = value
& 0xff;
629 field
[2] = (value
>> 8) & 0xff;
633 field
[1] = value
& 0xff;
637 field
[0] = value
& 0xff;
641 error (_("Unhandled data length: %d\n"), size
);
646 /* Guess the relocation size commonly used by the specific machines. */
649 guess_is_rela (unsigned long e_machine
)
653 /* Targets that use REL relocations. */
668 /* Targets that use RELA relocations. */
683 case EM_CYGNUS_MN10200
:
685 case EM_CYGNUS_MN10300
:
732 warn (_("Don't know about relocations on this machine architecture\n"));
738 slurp_rela_relocs (FILE *file
,
739 unsigned long rel_offset
,
740 unsigned long rel_size
,
741 Elf_Internal_Rela
**relasp
,
742 unsigned long *nrelasp
)
744 Elf_Internal_Rela
*relas
;
745 unsigned long nrelas
;
750 Elf32_External_Rela
*erelas
;
752 erelas
= get_data (NULL
, file
, rel_offset
, rel_size
, _("relocs"));
756 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
758 relas
= malloc (nrelas
* sizeof (Elf_Internal_Rela
));
762 error (_("out of memory parsing relocs"));
766 for (i
= 0; i
< nrelas
; i
++)
768 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
769 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
770 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
777 Elf64_External_Rela
*erelas
;
779 erelas
= get_data (NULL
, file
, rel_offset
, rel_size
, _("relocs"));
783 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
785 relas
= malloc (nrelas
* sizeof (Elf_Internal_Rela
));
789 error (_("out of memory parsing relocs"));
793 for (i
= 0; i
< nrelas
; i
++)
795 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
796 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
797 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
808 slurp_rel_relocs (FILE *file
,
809 unsigned long rel_offset
,
810 unsigned long rel_size
,
811 Elf_Internal_Rela
**relsp
,
812 unsigned long *nrelsp
)
814 Elf_Internal_Rela
*rels
;
820 Elf32_External_Rel
*erels
;
822 erels
= get_data (NULL
, file
, rel_offset
, rel_size
, _("relocs"));
826 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
828 rels
= malloc (nrels
* sizeof (Elf_Internal_Rela
));
832 error (_("out of memory parsing relocs"));
836 for (i
= 0; i
< nrels
; i
++)
838 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
839 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
840 rels
[i
].r_addend
= 0;
847 Elf64_External_Rel
*erels
;
849 erels
= get_data (NULL
, file
, rel_offset
, rel_size
, _("relocs"));
853 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
855 rels
= malloc (nrels
* sizeof (Elf_Internal_Rela
));
859 error (_("out of memory parsing relocs"));
863 for (i
= 0; i
< nrels
; i
++)
865 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
866 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
867 rels
[i
].r_addend
= 0;
877 /* Display the contents of the relocation data found at the specified
881 dump_relocations (FILE *file
,
882 unsigned long rel_offset
,
883 unsigned long rel_size
,
884 Elf_Internal_Sym
*symtab
,
887 unsigned long strtablen
,
891 Elf_Internal_Rela
*rels
;
894 if (is_rela
== UNKNOWN
)
895 is_rela
= guess_is_rela (elf_header
.e_machine
);
899 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
904 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
913 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
915 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
920 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
922 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
930 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
932 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
937 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
939 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
943 for (i
= 0; i
< rel_size
; i
++)
946 const char *rtype2
= NULL
;
947 const char *rtype3
= NULL
;
950 bfd_vma symtab_index
;
955 offset
= rels
[i
].r_offset
;
956 info
= rels
[i
].r_info
;
960 type
= ELF32_R_TYPE (info
);
961 symtab_index
= ELF32_R_SYM (info
);
965 /* The #ifdef BFD64 below is to prevent a compile time warning.
966 We know that if we do not have a 64 bit data type that we
967 will never execute this code anyway. */
969 if (elf_header
.e_machine
== EM_MIPS
)
971 /* In little-endian objects, r_info isn't really a 64-bit
972 little-endian value: it has a 32-bit little-endian
973 symbol index followed by four individual byte fields.
974 Reorder INFO accordingly. */
975 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
976 info
= (((info
& 0xffffffff) << 32)
977 | ((info
>> 56) & 0xff)
978 | ((info
>> 40) & 0xff00)
979 | ((info
>> 24) & 0xff0000)
980 | ((info
>> 8) & 0xff000000));
981 type
= ELF64_MIPS_R_TYPE (info
);
982 type2
= ELF64_MIPS_R_TYPE2 (info
);
983 type3
= ELF64_MIPS_R_TYPE3 (info
);
985 else if (elf_header
.e_machine
== EM_SPARCV9
)
986 type
= ELF64_R_TYPE_ID (info
);
988 type
= ELF64_R_TYPE (info
);
990 symtab_index
= ELF64_R_SYM (info
);
996 #ifdef _bfd_int64_low
997 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
999 printf ("%8.8lx %8.8lx ", offset
, info
);
1004 #ifdef _bfd_int64_low
1006 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1007 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1008 _bfd_int64_high (offset
),
1009 _bfd_int64_low (offset
),
1010 _bfd_int64_high (info
),
1011 _bfd_int64_low (info
));
1014 ? "%16.16lx %16.16lx "
1015 : "%12.12lx %12.12lx ",
1020 switch (elf_header
.e_machine
)
1027 case EM_CYGNUS_M32R
:
1028 rtype
= elf_m32r_reloc_type (type
);
1033 rtype
= elf_i386_reloc_type (type
);
1038 rtype
= elf_m68hc11_reloc_type (type
);
1042 rtype
= elf_m68k_reloc_type (type
);
1046 rtype
= elf_i960_reloc_type (type
);
1051 rtype
= elf_avr_reloc_type (type
);
1054 case EM_OLD_SPARCV9
:
1055 case EM_SPARC32PLUS
:
1058 rtype
= elf_sparc_reloc_type (type
);
1062 case EM_CYGNUS_V850
:
1063 rtype
= v850_reloc_type (type
);
1067 case EM_CYGNUS_D10V
:
1068 rtype
= elf_d10v_reloc_type (type
);
1072 case EM_CYGNUS_D30V
:
1073 rtype
= elf_d30v_reloc_type (type
);
1077 rtype
= elf_dlx_reloc_type (type
);
1081 rtype
= elf_sh_reloc_type (type
);
1085 case EM_CYGNUS_MN10300
:
1086 rtype
= elf_mn10300_reloc_type (type
);
1090 case EM_CYGNUS_MN10200
:
1091 rtype
= elf_mn10200_reloc_type (type
);
1095 case EM_CYGNUS_FR30
:
1096 rtype
= elf_fr30_reloc_type (type
);
1100 rtype
= elf_frv_reloc_type (type
);
1104 rtype
= elf_mcore_reloc_type (type
);
1108 rtype
= elf_mmix_reloc_type (type
);
1113 rtype
= elf_msp430_reloc_type (type
);
1117 rtype
= elf_ppc_reloc_type (type
);
1121 rtype
= elf_ppc64_reloc_type (type
);
1125 case EM_MIPS_RS3_LE
:
1126 rtype
= elf_mips_reloc_type (type
);
1129 rtype2
= elf_mips_reloc_type (type2
);
1130 rtype3
= elf_mips_reloc_type (type3
);
1135 rtype
= elf_alpha_reloc_type (type
);
1139 rtype
= elf_arm_reloc_type (type
);
1143 rtype
= elf_arc_reloc_type (type
);
1147 rtype
= elf_hppa_reloc_type (type
);
1153 rtype
= elf_h8_reloc_type (type
);
1158 rtype
= elf_or32_reloc_type (type
);
1163 rtype
= elf_pj_reloc_type (type
);
1166 rtype
= elf_ia64_reloc_type (type
);
1170 rtype
= elf_cris_reloc_type (type
);
1174 rtype
= elf_i860_reloc_type (type
);
1178 rtype
= elf_x86_64_reloc_type (type
);
1182 rtype
= i370_reloc_type (type
);
1187 rtype
= elf_s390_reloc_type (type
);
1191 rtype
= elf_xstormy16_reloc_type (type
);
1195 rtype
= elf_crx_reloc_type (type
);
1199 rtype
= elf_vax_reloc_type (type
);
1204 rtype
= elf_ip2k_reloc_type (type
);
1208 rtype
= elf_iq2000_reloc_type (type
);
1213 rtype
= elf_xtensa_reloc_type (type
);
1218 #ifdef _bfd_int64_low
1219 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1221 printf (_("unrecognized: %-7lx"), type
);
1224 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1228 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1229 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1232 Elf_Internal_Sym
*psym
;
1234 psym
= symtab
+ symtab_index
;
1237 print_vma (psym
->st_value
, LONG_HEX
);
1238 printf (is_32bit_elf
? " " : " ");
1240 if (psym
->st_name
== 0)
1242 const char *sec_name
= "<null>";
1245 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1247 bfd_vma sec_index
= (bfd_vma
) -1;
1249 if (psym
->st_shndx
< SHN_LORESERVE
)
1250 sec_index
= psym
->st_shndx
;
1251 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1252 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1255 if (sec_index
!= (bfd_vma
) -1)
1256 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1257 else if (psym
->st_shndx
== SHN_ABS
)
1259 else if (psym
->st_shndx
== SHN_COMMON
)
1260 sec_name
= "COMMON";
1261 else if (elf_header
.e_machine
== EM_IA_64
1262 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1263 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1264 sec_name
= "ANSI_COM";
1267 sprintf (name_buf
, "<section 0x%x>",
1268 (unsigned int) psym
->st_shndx
);
1269 sec_name
= name_buf
;
1272 print_symbol (22, sec_name
);
1274 else if (strtab
== NULL
)
1275 printf (_("<string table index: %3ld>"), psym
->st_name
);
1276 else if (psym
->st_name
> strtablen
)
1277 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1279 print_symbol (22, strtab
+ psym
->st_name
);
1282 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1287 printf ("%*c", is_32bit_elf
?
1288 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1289 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1292 if (elf_header
.e_machine
== EM_SPARCV9
1293 && streq (rtype
, "R_SPARC_OLO10"))
1294 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1298 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1300 printf (" Type2: ");
1303 #ifdef _bfd_int64_low
1304 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1306 printf (_("unrecognized: %-7lx"), type2
);
1309 printf ("%-17.17s", rtype2
);
1311 printf ("\n Type3: ");
1314 #ifdef _bfd_int64_low
1315 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1317 printf (_("unrecognized: %-7lx"), type3
);
1320 printf ("%-17.17s", rtype3
);
1332 get_mips_dynamic_type (unsigned long type
)
1336 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1337 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1338 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1339 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1340 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1341 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1342 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1343 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1344 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1345 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1346 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1347 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1348 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1349 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1350 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1351 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1352 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1353 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1354 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1355 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1356 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1357 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1358 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1359 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1360 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1361 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1362 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1363 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1364 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1365 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1366 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1367 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1368 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1369 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1370 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1371 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1372 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1373 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1374 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1375 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1376 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1377 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1378 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1385 get_sparc64_dynamic_type (unsigned long type
)
1389 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1396 get_ppc64_dynamic_type (unsigned long type
)
1400 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1401 case DT_PPC64_OPD
: return "PPC64_OPD";
1402 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1409 get_parisc_dynamic_type (unsigned long type
)
1413 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1414 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1415 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1416 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1417 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1418 case DT_HP_PREINIT
: return "HP_PREINIT";
1419 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1420 case DT_HP_NEEDED
: return "HP_NEEDED";
1421 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1422 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1423 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1424 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1425 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1432 get_ia64_dynamic_type (unsigned long type
)
1436 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1443 get_dynamic_type (unsigned long type
)
1445 static char buff
[32];
1449 case DT_NULL
: return "NULL";
1450 case DT_NEEDED
: return "NEEDED";
1451 case DT_PLTRELSZ
: return "PLTRELSZ";
1452 case DT_PLTGOT
: return "PLTGOT";
1453 case DT_HASH
: return "HASH";
1454 case DT_STRTAB
: return "STRTAB";
1455 case DT_SYMTAB
: return "SYMTAB";
1456 case DT_RELA
: return "RELA";
1457 case DT_RELASZ
: return "RELASZ";
1458 case DT_RELAENT
: return "RELAENT";
1459 case DT_STRSZ
: return "STRSZ";
1460 case DT_SYMENT
: return "SYMENT";
1461 case DT_INIT
: return "INIT";
1462 case DT_FINI
: return "FINI";
1463 case DT_SONAME
: return "SONAME";
1464 case DT_RPATH
: return "RPATH";
1465 case DT_SYMBOLIC
: return "SYMBOLIC";
1466 case DT_REL
: return "REL";
1467 case DT_RELSZ
: return "RELSZ";
1468 case DT_RELENT
: return "RELENT";
1469 case DT_PLTREL
: return "PLTREL";
1470 case DT_DEBUG
: return "DEBUG";
1471 case DT_TEXTREL
: return "TEXTREL";
1472 case DT_JMPREL
: return "JMPREL";
1473 case DT_BIND_NOW
: return "BIND_NOW";
1474 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1475 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1476 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1477 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1478 case DT_RUNPATH
: return "RUNPATH";
1479 case DT_FLAGS
: return "FLAGS";
1481 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1482 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1484 case DT_CHECKSUM
: return "CHECKSUM";
1485 case DT_PLTPADSZ
: return "PLTPADSZ";
1486 case DT_MOVEENT
: return "MOVEENT";
1487 case DT_MOVESZ
: return "MOVESZ";
1488 case DT_FEATURE
: return "FEATURE";
1489 case DT_POSFLAG_1
: return "POSFLAG_1";
1490 case DT_SYMINSZ
: return "SYMINSZ";
1491 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1493 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1494 case DT_CONFIG
: return "CONFIG";
1495 case DT_DEPAUDIT
: return "DEPAUDIT";
1496 case DT_AUDIT
: return "AUDIT";
1497 case DT_PLTPAD
: return "PLTPAD";
1498 case DT_MOVETAB
: return "MOVETAB";
1499 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1501 case DT_VERSYM
: return "VERSYM";
1503 case DT_RELACOUNT
: return "RELACOUNT";
1504 case DT_RELCOUNT
: return "RELCOUNT";
1505 case DT_FLAGS_1
: return "FLAGS_1";
1506 case DT_VERDEF
: return "VERDEF";
1507 case DT_VERDEFNUM
: return "VERDEFNUM";
1508 case DT_VERNEED
: return "VERNEED";
1509 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1511 case DT_AUXILIARY
: return "AUXILIARY";
1512 case DT_USED
: return "USED";
1513 case DT_FILTER
: return "FILTER";
1515 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1516 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1517 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1518 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1519 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1522 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1526 switch (elf_header
.e_machine
)
1529 case EM_MIPS_RS3_LE
:
1530 result
= get_mips_dynamic_type (type
);
1533 result
= get_sparc64_dynamic_type (type
);
1536 result
= get_ppc64_dynamic_type (type
);
1539 result
= get_ia64_dynamic_type (type
);
1549 sprintf (buff
, _("Processor Specific: %lx"), type
);
1551 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1555 switch (elf_header
.e_machine
)
1558 result
= get_parisc_dynamic_type (type
);
1568 sprintf (buff
, _("Operating System specific: %lx"), type
);
1571 sprintf (buff
, _("<unknown>: %lx"), type
);
1578 get_file_type (unsigned e_type
)
1580 static char buff
[32];
1584 case ET_NONE
: return _("NONE (None)");
1585 case ET_REL
: return _("REL (Relocatable file)");
1586 case ET_EXEC
: return _("EXEC (Executable file)");
1587 case ET_DYN
: return _("DYN (Shared object file)");
1588 case ET_CORE
: return _("CORE (Core file)");
1591 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1592 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
1593 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1594 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
1596 sprintf (buff
, _("<unknown>: %x"), e_type
);
1602 get_machine_name (unsigned e_machine
)
1604 static char buff
[64]; /* XXX */
1608 case EM_NONE
: return _("None");
1609 case EM_M32
: return "WE32100";
1610 case EM_SPARC
: return "Sparc";
1611 case EM_386
: return "Intel 80386";
1612 case EM_68K
: return "MC68000";
1613 case EM_88K
: return "MC88000";
1614 case EM_486
: return "Intel 80486";
1615 case EM_860
: return "Intel 80860";
1616 case EM_MIPS
: return "MIPS R3000";
1617 case EM_S370
: return "IBM System/370";
1618 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1619 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1620 case EM_PARISC
: return "HPPA";
1621 case EM_PPC_OLD
: return "Power PC (old)";
1622 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1623 case EM_960
: return "Intel 90860";
1624 case EM_PPC
: return "PowerPC";
1625 case EM_PPC64
: return "PowerPC64";
1626 case EM_V800
: return "NEC V800";
1627 case EM_FR20
: return "Fujitsu FR20";
1628 case EM_RH32
: return "TRW RH32";
1629 case EM_MCORE
: return "MCORE";
1630 case EM_ARM
: return "ARM";
1631 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1632 case EM_SH
: return "Renesas / SuperH SH";
1633 case EM_SPARCV9
: return "Sparc v9";
1634 case EM_TRICORE
: return "Siemens Tricore";
1635 case EM_ARC
: return "ARC";
1636 case EM_H8_300
: return "Renesas H8/300";
1637 case EM_H8_300H
: return "Renesas H8/300H";
1638 case EM_H8S
: return "Renesas H8S";
1639 case EM_H8_500
: return "Renesas H8/500";
1640 case EM_IA_64
: return "Intel IA-64";
1641 case EM_MIPS_X
: return "Stanford MIPS-X";
1642 case EM_COLDFIRE
: return "Motorola Coldfire";
1643 case EM_68HC12
: return "Motorola M68HC12";
1644 case EM_ALPHA
: return "Alpha";
1645 case EM_CYGNUS_D10V
:
1646 case EM_D10V
: return "d10v";
1647 case EM_CYGNUS_D30V
:
1648 case EM_D30V
: return "d30v";
1649 case EM_CYGNUS_M32R
:
1650 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1651 case EM_CYGNUS_V850
:
1652 case EM_V850
: return "NEC v850";
1653 case EM_CYGNUS_MN10300
:
1654 case EM_MN10300
: return "mn10300";
1655 case EM_CYGNUS_MN10200
:
1656 case EM_MN10200
: return "mn10200";
1657 case EM_CYGNUS_FR30
:
1658 case EM_FR30
: return "Fujitsu FR30";
1659 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1661 case EM_PJ
: return "picoJava";
1662 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1663 case EM_PCP
: return "Siemens PCP";
1664 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1665 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1666 case EM_STARCORE
: return "Motorola Star*Core processor";
1667 case EM_ME16
: return "Toyota ME16 processor";
1668 case EM_ST100
: return "STMicroelectronics ST100 processor";
1669 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1670 case EM_FX66
: return "Siemens FX66 microcontroller";
1671 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1672 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1673 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1674 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1675 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1676 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1677 case EM_SVX
: return "Silicon Graphics SVx";
1678 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1679 case EM_VAX
: return "Digital VAX";
1681 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1682 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1683 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1684 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1685 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1686 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1687 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1688 case EM_PRISM
: return "Vitesse Prism";
1689 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1691 case EM_S390
: return "IBM S/390";
1692 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1694 case EM_OR32
: return "OpenRISC";
1695 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1696 case EM_DLX
: return "OpenDLX";
1698 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1699 case EM_IQ2000
: return "Vitesse IQ2000";
1701 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1703 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1709 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1714 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1715 e_flags
&= ~ EF_ARM_EABIMASK
;
1717 /* Handle "generic" ARM flags. */
1718 if (e_flags
& EF_ARM_RELEXEC
)
1720 strcat (buf
, ", relocatable executable");
1721 e_flags
&= ~ EF_ARM_RELEXEC
;
1724 if (e_flags
& EF_ARM_HASENTRY
)
1726 strcat (buf
, ", has entry point");
1727 e_flags
&= ~ EF_ARM_HASENTRY
;
1730 /* Now handle EABI specific flags. */
1734 strcat (buf
, ", <unrecognized EABI>");
1739 case EF_ARM_EABI_VER1
:
1740 strcat (buf
, ", Version1 EABI");
1745 /* Process flags one bit at a time. */
1746 flag
= e_flags
& - e_flags
;
1751 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1752 strcat (buf
, ", sorted symbol tables");
1762 case EF_ARM_EABI_VER2
:
1763 strcat (buf
, ", Version2 EABI");
1768 /* Process flags one bit at a time. */
1769 flag
= e_flags
& - e_flags
;
1774 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1775 strcat (buf
, ", sorted symbol tables");
1778 case EF_ARM_DYNSYMSUSESEGIDX
:
1779 strcat (buf
, ", dynamic symbols use segment index");
1782 case EF_ARM_MAPSYMSFIRST
:
1783 strcat (buf
, ", mapping symbols precede others");
1793 case EF_ARM_EABI_VER3
:
1794 strcat (buf
, ", Version3 EABI");
1797 case EF_ARM_EABI_VER4
:
1798 strcat (buf
, ", Version4 EABI");
1803 /* Process flags one bit at a time. */
1804 flag
= e_flags
& - e_flags
;
1810 strcat (buf
, ", BE8");
1814 strcat (buf
, ", LE8");
1824 case EF_ARM_EABI_UNKNOWN
:
1825 strcat (buf
, ", GNU EABI");
1830 /* Process flags one bit at a time. */
1831 flag
= e_flags
& - e_flags
;
1836 case EF_ARM_INTERWORK
:
1837 strcat (buf
, ", interworking enabled");
1840 case EF_ARM_APCS_26
:
1841 strcat (buf
, ", uses APCS/26");
1844 case EF_ARM_APCS_FLOAT
:
1845 strcat (buf
, ", uses APCS/float");
1849 strcat (buf
, ", position independent");
1853 strcat (buf
, ", 8 bit structure alignment");
1856 case EF_ARM_NEW_ABI
:
1857 strcat (buf
, ", uses new ABI");
1860 case EF_ARM_OLD_ABI
:
1861 strcat (buf
, ", uses old ABI");
1864 case EF_ARM_SOFT_FLOAT
:
1865 strcat (buf
, ", software FP");
1868 case EF_ARM_VFP_FLOAT
:
1869 strcat (buf
, ", VFP");
1872 case EF_ARM_MAVERICK_FLOAT
:
1873 strcat (buf
, ", Maverick FP");
1884 strcat (buf
,", <unknown>");
1888 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1890 static char buf
[1024];
1902 decode_ARM_machine_flags (e_flags
, buf
);
1906 switch (e_flags
& EF_FRV_CPU_MASK
)
1908 case EF_FRV_CPU_GENERIC
:
1912 strcat (buf
, ", fr???");
1915 case EF_FRV_CPU_FR300
:
1916 strcat (buf
, ", fr300");
1919 case EF_FRV_CPU_FR400
:
1920 strcat (buf
, ", fr400");
1922 case EF_FRV_CPU_FR405
:
1923 strcat (buf
, ", fr405");
1926 case EF_FRV_CPU_FR450
:
1927 strcat (buf
, ", fr450");
1930 case EF_FRV_CPU_FR500
:
1931 strcat (buf
, ", fr500");
1933 case EF_FRV_CPU_FR550
:
1934 strcat (buf
, ", fr550");
1937 case EF_FRV_CPU_SIMPLE
:
1938 strcat (buf
, ", simple");
1940 case EF_FRV_CPU_TOMCAT
:
1941 strcat (buf
, ", tomcat");
1947 if (e_flags
& EF_CPU32
)
1948 strcat (buf
, ", cpu32");
1949 if (e_flags
& EF_M68000
)
1950 strcat (buf
, ", m68000");
1954 if (e_flags
& EF_PPC_EMB
)
1955 strcat (buf
, ", emb");
1957 if (e_flags
& EF_PPC_RELOCATABLE
)
1958 strcat (buf
, ", relocatable");
1960 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1961 strcat (buf
, ", relocatable-lib");
1965 case EM_CYGNUS_V850
:
1966 switch (e_flags
& EF_V850_ARCH
)
1969 strcat (buf
, ", v850e1");
1972 strcat (buf
, ", v850e");
1975 strcat (buf
, ", v850");
1978 strcat (buf
, ", unknown v850 architecture variant");
1984 case EM_CYGNUS_M32R
:
1985 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1986 strcat (buf
, ", m32r");
1991 case EM_MIPS_RS3_LE
:
1992 if (e_flags
& EF_MIPS_NOREORDER
)
1993 strcat (buf
, ", noreorder");
1995 if (e_flags
& EF_MIPS_PIC
)
1996 strcat (buf
, ", pic");
1998 if (e_flags
& EF_MIPS_CPIC
)
1999 strcat (buf
, ", cpic");
2001 if (e_flags
& EF_MIPS_UCODE
)
2002 strcat (buf
, ", ugen_reserved");
2004 if (e_flags
& EF_MIPS_ABI2
)
2005 strcat (buf
, ", abi2");
2007 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2008 strcat (buf
, ", odk first");
2010 if (e_flags
& EF_MIPS_32BITMODE
)
2011 strcat (buf
, ", 32bitmode");
2013 switch ((e_flags
& EF_MIPS_MACH
))
2015 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2016 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2017 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2018 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2019 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2020 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2021 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2022 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2023 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2024 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2026 /* We simply ignore the field in this case to avoid confusion:
2027 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2030 default: strcat (buf
, ", unknown CPU"); break;
2033 switch ((e_flags
& EF_MIPS_ABI
))
2035 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2036 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2037 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2038 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2040 /* We simply ignore the field in this case to avoid confusion:
2041 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2042 This means it is likely to be an o32 file, but not for
2045 default: strcat (buf
, ", unknown ABI"); break;
2048 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2049 strcat (buf
, ", mdmx");
2051 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2052 strcat (buf
, ", mips16");
2054 switch ((e_flags
& EF_MIPS_ARCH
))
2056 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2057 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2058 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2059 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2060 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2061 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2062 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2063 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2064 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2065 default: strcat (buf
, ", unknown ISA"); break;
2071 switch ((e_flags
& EF_SH_MACH_MASK
))
2073 case EF_SH1
: strcat (buf
, ", sh1"); break;
2074 case EF_SH2
: strcat (buf
, ", sh2"); break;
2075 case EF_SH3
: strcat (buf
, ", sh3"); break;
2076 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2077 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2078 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2079 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2080 case EF_SH4
: strcat (buf
, ", sh4"); break;
2081 case EF_SH5
: strcat (buf
, ", sh5"); break;
2082 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2083 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2084 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2085 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2086 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2087 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2088 default: strcat (buf
, ", unknown ISA"); break;
2094 if (e_flags
& EF_SPARC_32PLUS
)
2095 strcat (buf
, ", v8+");
2097 if (e_flags
& EF_SPARC_SUN_US1
)
2098 strcat (buf
, ", ultrasparcI");
2100 if (e_flags
& EF_SPARC_SUN_US3
)
2101 strcat (buf
, ", ultrasparcIII");
2103 if (e_flags
& EF_SPARC_HAL_R1
)
2104 strcat (buf
, ", halr1");
2106 if (e_flags
& EF_SPARC_LEDATA
)
2107 strcat (buf
, ", ledata");
2109 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2110 strcat (buf
, ", tso");
2112 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2113 strcat (buf
, ", pso");
2115 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2116 strcat (buf
, ", rmo");
2120 switch (e_flags
& EF_PARISC_ARCH
)
2122 case EFA_PARISC_1_0
:
2123 strcpy (buf
, ", PA-RISC 1.0");
2125 case EFA_PARISC_1_1
:
2126 strcpy (buf
, ", PA-RISC 1.1");
2128 case EFA_PARISC_2_0
:
2129 strcpy (buf
, ", PA-RISC 2.0");
2134 if (e_flags
& EF_PARISC_TRAPNIL
)
2135 strcat (buf
, ", trapnil");
2136 if (e_flags
& EF_PARISC_EXT
)
2137 strcat (buf
, ", ext");
2138 if (e_flags
& EF_PARISC_LSB
)
2139 strcat (buf
, ", lsb");
2140 if (e_flags
& EF_PARISC_WIDE
)
2141 strcat (buf
, ", wide");
2142 if (e_flags
& EF_PARISC_NO_KABP
)
2143 strcat (buf
, ", no kabp");
2144 if (e_flags
& EF_PARISC_LAZYSWAP
)
2145 strcat (buf
, ", lazyswap");
2150 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2151 strcat (buf
, ", new calling convention");
2153 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2154 strcat (buf
, ", gnu calling convention");
2158 if ((e_flags
& EF_IA_64_ABI64
))
2159 strcat (buf
, ", 64-bit");
2161 strcat (buf
, ", 32-bit");
2162 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2163 strcat (buf
, ", reduced fp model");
2164 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2165 strcat (buf
, ", no function descriptors, constant gp");
2166 else if ((e_flags
& EF_IA_64_CONS_GP
))
2167 strcat (buf
, ", constant gp");
2168 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2169 strcat (buf
, ", absolute");
2173 if ((e_flags
& EF_VAX_NONPIC
))
2174 strcat (buf
, ", non-PIC");
2175 if ((e_flags
& EF_VAX_DFLOAT
))
2176 strcat (buf
, ", D-Float");
2177 if ((e_flags
& EF_VAX_GFLOAT
))
2178 strcat (buf
, ", G-Float");
2187 get_osabi_name (unsigned int osabi
)
2189 static char buff
[32];
2193 case ELFOSABI_NONE
: return "UNIX - System V";
2194 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2195 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2196 case ELFOSABI_LINUX
: return "UNIX - Linux";
2197 case ELFOSABI_HURD
: return "GNU/Hurd";
2198 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2199 case ELFOSABI_AIX
: return "UNIX - AIX";
2200 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2201 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2202 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2203 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2204 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2205 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2206 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2207 case ELFOSABI_AROS
: return "Amiga Research OS";
2208 case ELFOSABI_STANDALONE
: return _("Standalone App");
2209 case ELFOSABI_ARM
: return "ARM";
2211 sprintf (buff
, _("<unknown: %x>"), osabi
);
2217 get_mips_segment_type (unsigned long type
)
2221 case PT_MIPS_REGINFO
:
2223 case PT_MIPS_RTPROC
:
2225 case PT_MIPS_OPTIONS
:
2235 get_parisc_segment_type (unsigned long type
)
2239 case PT_HP_TLS
: return "HP_TLS";
2240 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2241 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2242 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2243 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2244 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2245 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2246 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2247 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2248 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2249 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2250 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2251 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2252 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2261 get_ia64_segment_type (unsigned long type
)
2265 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2266 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2267 case PT_HP_TLS
: return "HP_TLS";
2268 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2269 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2270 case PT_IA_64_HP_STACK
: return "HP_STACK";
2279 get_segment_type (unsigned long p_type
)
2281 static char buff
[32];
2285 case PT_NULL
: return "NULL";
2286 case PT_LOAD
: return "LOAD";
2287 case PT_DYNAMIC
: return "DYNAMIC";
2288 case PT_INTERP
: return "INTERP";
2289 case PT_NOTE
: return "NOTE";
2290 case PT_SHLIB
: return "SHLIB";
2291 case PT_PHDR
: return "PHDR";
2292 case PT_TLS
: return "TLS";
2294 case PT_GNU_EH_FRAME
:
2295 return "GNU_EH_FRAME";
2296 case PT_GNU_STACK
: return "GNU_STACK";
2297 case PT_GNU_RELRO
: return "GNU_RELRO";
2300 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2304 switch (elf_header
.e_machine
)
2307 case EM_MIPS_RS3_LE
:
2308 result
= get_mips_segment_type (p_type
);
2311 result
= get_parisc_segment_type (p_type
);
2314 result
= get_ia64_segment_type (p_type
);
2324 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2326 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2330 switch (elf_header
.e_machine
)
2333 result
= get_parisc_segment_type (p_type
);
2336 result
= get_ia64_segment_type (p_type
);
2346 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2349 sprintf (buff
, _("<unknown>: %lx"), p_type
);
2356 get_mips_section_type_name (unsigned int sh_type
)
2360 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2361 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2362 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2363 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2364 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2365 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2366 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2367 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2368 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2369 case SHT_MIPS_RELD
: return "MIPS_RELD";
2370 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2371 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2372 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2373 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2374 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2375 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2376 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2377 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2378 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2379 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2380 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2381 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2382 case SHT_MIPS_LINE
: return "MIPS_LINE";
2383 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2384 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2385 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2386 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2387 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2388 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2389 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2390 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2391 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2392 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2393 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2394 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2395 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2396 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2397 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2398 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2406 get_parisc_section_type_name (unsigned int sh_type
)
2410 case SHT_PARISC_EXT
: return "PARISC_EXT";
2411 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2412 case SHT_PARISC_DOC
: return "PARISC_DOC";
2420 get_ia64_section_type_name (unsigned int sh_type
)
2422 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2423 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2424 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2428 case SHT_IA_64_EXT
: return "IA_64_EXT";
2429 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2430 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2438 get_x86_64_section_type_name (unsigned int sh_type
)
2442 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2450 get_arm_section_type_name (unsigned int sh_type
)
2463 get_section_type_name (unsigned int sh_type
)
2465 static char buff
[32];
2469 case SHT_NULL
: return "NULL";
2470 case SHT_PROGBITS
: return "PROGBITS";
2471 case SHT_SYMTAB
: return "SYMTAB";
2472 case SHT_STRTAB
: return "STRTAB";
2473 case SHT_RELA
: return "RELA";
2474 case SHT_HASH
: return "HASH";
2475 case SHT_DYNAMIC
: return "DYNAMIC";
2476 case SHT_NOTE
: return "NOTE";
2477 case SHT_NOBITS
: return "NOBITS";
2478 case SHT_REL
: return "REL";
2479 case SHT_SHLIB
: return "SHLIB";
2480 case SHT_DYNSYM
: return "DYNSYM";
2481 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2482 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2483 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2484 case SHT_GROUP
: return "GROUP";
2485 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2486 case SHT_GNU_verdef
: return "VERDEF";
2487 case SHT_GNU_verneed
: return "VERNEED";
2488 case SHT_GNU_versym
: return "VERSYM";
2489 case 0x6ffffff0: return "VERSYM";
2490 case 0x6ffffffc: return "VERDEF";
2491 case 0x7ffffffd: return "AUXILIARY";
2492 case 0x7fffffff: return "FILTER";
2493 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2496 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2500 switch (elf_header
.e_machine
)
2503 case EM_MIPS_RS3_LE
:
2504 result
= get_mips_section_type_name (sh_type
);
2507 result
= get_parisc_section_type_name (sh_type
);
2510 result
= get_ia64_section_type_name (sh_type
);
2513 result
= get_x86_64_section_type_name (sh_type
);
2516 result
= get_arm_section_type_name (sh_type
);
2526 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2528 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2529 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2530 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2531 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2533 sprintf (buff
, _("<unknown>: %x"), sh_type
);
2539 #define OPTION_DEBUG_DUMP 512
2541 struct option options
[] =
2543 {"all", no_argument
, 0, 'a'},
2544 {"file-header", no_argument
, 0, 'h'},
2545 {"program-headers", no_argument
, 0, 'l'},
2546 {"headers", no_argument
, 0, 'e'},
2547 {"histogram", no_argument
, 0, 'I'},
2548 {"segments", no_argument
, 0, 'l'},
2549 {"sections", no_argument
, 0, 'S'},
2550 {"section-headers", no_argument
, 0, 'S'},
2551 {"section-groups", no_argument
, 0, 'g'},
2552 {"symbols", no_argument
, 0, 's'},
2553 {"syms", no_argument
, 0, 's'},
2554 {"relocs", no_argument
, 0, 'r'},
2555 {"notes", no_argument
, 0, 'n'},
2556 {"dynamic", no_argument
, 0, 'd'},
2557 {"arch-specific", no_argument
, 0, 'A'},
2558 {"version-info", no_argument
, 0, 'V'},
2559 {"use-dynamic", no_argument
, 0, 'D'},
2560 {"hex-dump", required_argument
, 0, 'x'},
2561 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2562 {"unwind", no_argument
, 0, 'u'},
2563 #ifdef SUPPORT_DISASSEMBLY
2564 {"instruction-dump", required_argument
, 0, 'i'},
2567 {"version", no_argument
, 0, 'v'},
2568 {"wide", no_argument
, 0, 'W'},
2569 {"help", no_argument
, 0, 'H'},
2570 {0, no_argument
, 0, 0}
2576 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2577 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2578 fprintf (stdout
, _(" Options are:\n\
2579 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2580 -h --file-header Display the ELF file header\n\
2581 -l --program-headers Display the program headers\n\
2582 --segments An alias for --program-headers\n\
2583 -S --section-headers Display the sections' header\n\
2584 --sections An alias for --section-headers\n\
2585 -g --section-groups Display the section groups\n\
2586 -e --headers Equivalent to: -h -l -S\n\
2587 -s --syms Display the symbol table\n\
2588 --symbols An alias for --syms\n\
2589 -n --notes Display the core notes (if present)\n\
2590 -r --relocs Display the relocations (if present)\n\
2591 -u --unwind Display the unwind info (if present)\n\
2592 -d --dynamic Display the dynamic section (if present)\n\
2593 -V --version-info Display the version sections (if present)\n\
2594 -A --arch-specific Display architecture specific information (if any).\n\
2595 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2596 -x --hex-dump=<number> Dump the contents of section <number>\n\
2597 -w[liaprmfFsoR] or\n\
2598 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2599 Display the contents of DWARF2 debug sections\n"));
2600 #ifdef SUPPORT_DISASSEMBLY
2601 fprintf (stdout
, _("\
2602 -i --instruction-dump=<number>\n\
2603 Disassemble the contents of section <number>\n"));
2605 fprintf (stdout
, _("\
2606 -I --histogram Display histogram of bucket list lengths\n\
2607 -W --wide Allow output width to exceed 80 characters\n\
2608 -H --help Display this information\n\
2609 -v --version Display the version number of readelf\n"));
2610 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2615 /* Record the fact that the user wants the contents of section number
2616 SECTION to be displayed using the method(s) encoded as flags bits
2617 in TYPE. Note, TYPE can be zero if we are creating the array for
2621 request_dump (unsigned int section
, int type
)
2623 if (section
>= num_dump_sects
)
2625 char *new_dump_sects
;
2627 new_dump_sects
= calloc (section
+ 1, 1);
2629 if (new_dump_sects
== NULL
)
2630 error (_("Out of memory allocating dump request table."));
2633 /* Copy current flag settings. */
2634 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2638 dump_sects
= new_dump_sects
;
2639 num_dump_sects
= section
+ 1;
2644 dump_sects
[section
] |= type
;
2650 parse_args (int argc
, char **argv
)
2657 while ((c
= getopt_long
2658 (argc
, argv
, "ersuahnldSDAIgw::x:i:vVWH", options
, NULL
)) != EOF
)
2679 do_section_groups
++;
2687 do_section_groups
++;
2729 section
= strtoul (optarg
, & cp
, 0);
2730 if (! *cp
&& section
>= 0)
2732 request_dump (section
, HEX_DUMP
);
2742 unsigned int index
= 0;
2746 while (optarg
[index
])
2747 switch (optarg
[index
++])
2756 do_debug_abbrevs
= 1;
2766 do_debug_pubnames
= 1;
2770 do_debug_aranges
= 1;
2774 do_debug_ranges
= 1;
2778 do_debug_frames_interp
= 1;
2780 do_debug_frames
= 1;
2785 do_debug_macinfo
= 1;
2799 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2804 case OPTION_DEBUG_DUMP
:
2812 const char * option
;
2815 debug_dump_long_opts
;
2817 debug_dump_long_opts opts_table
[] =
2819 /* Please keep this table alpha- sorted. */
2820 { "Ranges", & do_debug_ranges
},
2821 { "abbrev", & do_debug_abbrevs
},
2822 { "aranges", & do_debug_aranges
},
2823 { "frames", & do_debug_frames
},
2824 { "frames-interp", & do_debug_frames_interp
},
2825 { "info", & do_debug_info
},
2826 { "line", & do_debug_lines
},
2827 { "loc", & do_debug_loc
},
2828 { "macro", & do_debug_macinfo
},
2829 { "pubnames", & do_debug_pubnames
},
2830 /* This entry is for compatability
2831 with earlier versions of readelf. */
2832 { "ranges", & do_debug_aranges
},
2833 { "str", & do_debug_str
},
2844 debug_dump_long_opts
* entry
;
2846 for (entry
= opts_table
; entry
->option
; entry
++)
2848 size_t len
= strlen (entry
->option
);
2850 if (strneq (p
, entry
->option
, len
)
2851 && (p
[len
] == ',' || p
[len
] == '\0'))
2853 * entry
->variable
= 1;
2855 /* The --debug-dump=frames-interp option also
2856 enables the --debug-dump=frames option. */
2857 if (do_debug_frames_interp
)
2858 do_debug_frames
= 1;
2865 if (entry
->option
== NULL
)
2867 warn (_("Unrecognized debug option '%s'\n"), p
);
2868 p
= strchr (p
, ',');
2878 #ifdef SUPPORT_DISASSEMBLY
2881 section
= strtoul (optarg
, & cp
, 0);
2882 if (! *cp
&& section
>= 0)
2884 request_dump (section
, DISASS_DUMP
);
2890 print_version (program_name
);
2900 /* xgettext:c-format */
2901 error (_("Invalid option '-%c'\n"), c
);
2908 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2909 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2910 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
2911 && !do_section_groups
)
2915 warn (_("Nothing to do.\n"));
2921 get_elf_class (unsigned int elf_class
)
2923 static char buff
[32];
2927 case ELFCLASSNONE
: return _("none");
2928 case ELFCLASS32
: return "ELF32";
2929 case ELFCLASS64
: return "ELF64";
2931 sprintf (buff
, _("<unknown: %x>"), elf_class
);
2937 get_data_encoding (unsigned int encoding
)
2939 static char buff
[32];
2943 case ELFDATANONE
: return _("none");
2944 case ELFDATA2LSB
: return _("2's complement, little endian");
2945 case ELFDATA2MSB
: return _("2's complement, big endian");
2947 sprintf (buff
, _("<unknown: %x>"), encoding
);
2952 /* Decode the data held in 'elf_header'. */
2955 process_file_header (void)
2957 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2958 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2959 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2960 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2963 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2971 printf (_("ELF Header:\n"));
2972 printf (_(" Magic: "));
2973 for (i
= 0; i
< EI_NIDENT
; i
++)
2974 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2976 printf (_(" Class: %s\n"),
2977 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2978 printf (_(" Data: %s\n"),
2979 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2980 printf (_(" Version: %d %s\n"),
2981 elf_header
.e_ident
[EI_VERSION
],
2982 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
2984 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
2987 printf (_(" OS/ABI: %s\n"),
2988 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
2989 printf (_(" ABI Version: %d\n"),
2990 elf_header
.e_ident
[EI_ABIVERSION
]);
2991 printf (_(" Type: %s\n"),
2992 get_file_type (elf_header
.e_type
));
2993 printf (_(" Machine: %s\n"),
2994 get_machine_name (elf_header
.e_machine
));
2995 printf (_(" Version: 0x%lx\n"),
2996 (unsigned long) elf_header
.e_version
);
2998 printf (_(" Entry point address: "));
2999 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3000 printf (_("\n Start of program headers: "));
3001 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3002 printf (_(" (bytes into file)\n Start of section headers: "));
3003 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3004 printf (_(" (bytes into file)\n"));
3006 printf (_(" Flags: 0x%lx%s\n"),
3007 (unsigned long) elf_header
.e_flags
,
3008 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3009 printf (_(" Size of this header: %ld (bytes)\n"),
3010 (long) elf_header
.e_ehsize
);
3011 printf (_(" Size of program headers: %ld (bytes)\n"),
3012 (long) elf_header
.e_phentsize
);
3013 printf (_(" Number of program headers: %ld\n"),
3014 (long) elf_header
.e_phnum
);
3015 printf (_(" Size of section headers: %ld (bytes)\n"),
3016 (long) elf_header
.e_shentsize
);
3017 printf (_(" Number of section headers: %ld"),
3018 (long) elf_header
.e_shnum
);
3019 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3020 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3021 putc ('\n', stdout
);
3022 printf (_(" Section header string table index: %ld"),
3023 (long) elf_header
.e_shstrndx
);
3024 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3025 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3026 putc ('\n', stdout
);
3029 if (section_headers
!= NULL
)
3031 if (elf_header
.e_shnum
== 0)
3032 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3033 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3034 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3035 free (section_headers
);
3036 section_headers
= NULL
;
3044 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3046 Elf32_External_Phdr
*phdrs
;
3047 Elf32_External_Phdr
*external
;
3048 Elf_Internal_Phdr
*internal
;
3051 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3052 elf_header
.e_phentsize
* elf_header
.e_phnum
,
3053 _("program headers"));
3057 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3058 i
< elf_header
.e_phnum
;
3059 i
++, internal
++, external
++)
3061 internal
->p_type
= BYTE_GET (external
->p_type
);
3062 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3063 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3064 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3065 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3066 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3067 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3068 internal
->p_align
= BYTE_GET (external
->p_align
);
3077 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3079 Elf64_External_Phdr
*phdrs
;
3080 Elf64_External_Phdr
*external
;
3081 Elf_Internal_Phdr
*internal
;
3084 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3085 elf_header
.e_phentsize
* elf_header
.e_phnum
,
3086 _("program headers"));
3090 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3091 i
< elf_header
.e_phnum
;
3092 i
++, internal
++, external
++)
3094 internal
->p_type
= BYTE_GET (external
->p_type
);
3095 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3096 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
3097 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
3098 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
3099 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
3100 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
3101 internal
->p_align
= BYTE_GET8 (external
->p_align
);
3109 /* Returns 1 if the program headers were read into `program_headers'. */
3112 get_program_headers (FILE *file
)
3114 Elf_Internal_Phdr
*phdrs
;
3116 /* Check cache of prior read. */
3117 if (program_headers
!= NULL
)
3120 phdrs
= malloc (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
3124 error (_("Out of memory\n"));
3129 ? get_32bit_program_headers (file
, phdrs
)
3130 : get_64bit_program_headers (file
, phdrs
))
3132 program_headers
= phdrs
;
3140 /* Returns 1 if the program headers were loaded. */
3143 process_program_headers (FILE *file
)
3145 Elf_Internal_Phdr
*segment
;
3148 if (elf_header
.e_phnum
== 0)
3151 printf (_("\nThere are no program headers in this file.\n"));
3155 if (do_segments
&& !do_header
)
3157 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3158 printf (_("Entry point "));
3159 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3160 printf (_("\nThere are %d program headers, starting at offset "),
3161 elf_header
.e_phnum
);
3162 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3166 if (! get_program_headers (file
))
3171 if (elf_header
.e_phnum
> 1)
3172 printf (_("\nProgram Headers:\n"));
3174 printf (_("\nProgram Headers:\n"));
3178 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3181 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3185 (_(" Type Offset VirtAddr PhysAddr\n"));
3187 (_(" FileSiz MemSiz Flags Align\n"));
3194 for (i
= 0, segment
= program_headers
;
3195 i
< elf_header
.e_phnum
;
3200 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3204 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3205 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3206 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3207 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3208 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3210 (segment
->p_flags
& PF_R
? 'R' : ' '),
3211 (segment
->p_flags
& PF_W
? 'W' : ' '),
3212 (segment
->p_flags
& PF_X
? 'E' : ' '));
3213 printf ("%#lx", (unsigned long) segment
->p_align
);
3217 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3218 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3221 print_vma (segment
->p_offset
, FULL_HEX
);
3225 print_vma (segment
->p_vaddr
, FULL_HEX
);
3227 print_vma (segment
->p_paddr
, FULL_HEX
);
3230 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3231 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3234 print_vma (segment
->p_filesz
, FULL_HEX
);
3238 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3239 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3242 print_vma (segment
->p_offset
, FULL_HEX
);
3246 (segment
->p_flags
& PF_R
? 'R' : ' '),
3247 (segment
->p_flags
& PF_W
? 'W' : ' '),
3248 (segment
->p_flags
& PF_X
? 'E' : ' '));
3250 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3251 printf ("%#lx", (unsigned long) segment
->p_align
);
3254 print_vma (segment
->p_align
, PREFIX_HEX
);
3259 print_vma (segment
->p_offset
, FULL_HEX
);
3261 print_vma (segment
->p_vaddr
, FULL_HEX
);
3263 print_vma (segment
->p_paddr
, FULL_HEX
);
3265 print_vma (segment
->p_filesz
, FULL_HEX
);
3267 print_vma (segment
->p_memsz
, FULL_HEX
);
3269 (segment
->p_flags
& PF_R
? 'R' : ' '),
3270 (segment
->p_flags
& PF_W
? 'W' : ' '),
3271 (segment
->p_flags
& PF_X
? 'E' : ' '));
3272 print_vma (segment
->p_align
, HEX
);
3276 switch (segment
->p_type
)
3280 error (_("more than one dynamic segment\n"));
3282 /* Try to locate the .dynamic section. If there is
3283 a section header table, we can easily locate it. */
3284 if (section_headers
!= NULL
)
3286 Elf_Internal_Shdr
*sec
;
3289 for (j
= 0, sec
= section_headers
;
3290 j
< elf_header
.e_shnum
;
3292 if (streq (SECTION_NAME (sec
), ".dynamic"))
3295 if (j
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
3297 error (_("no .dynamic section in the dynamic segment"));
3301 dynamic_addr
= sec
->sh_offset
;
3302 dynamic_size
= sec
->sh_size
;
3304 if (dynamic_addr
< segment
->p_offset
3305 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3306 warn (_("the .dynamic section is not contained within the dynamic segment"));
3307 else if (dynamic_addr
> segment
->p_offset
)
3308 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3312 /* Otherwise, we can only assume that the .dynamic
3313 section is the first section in the DYNAMIC segment. */
3314 dynamic_addr
= segment
->p_offset
;
3315 dynamic_size
= segment
->p_filesz
;
3320 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3322 error (_("Unable to find program interpreter name\n"));
3325 program_interpreter
[0] = 0;
3326 fscanf (file
, "%63s", program_interpreter
);
3329 printf (_("\n [Requesting program interpreter: %s]"),
3330 program_interpreter
);
3336 putc ('\n', stdout
);
3339 if (do_segments
&& section_headers
!= NULL
)
3341 printf (_("\n Section to Segment mapping:\n"));
3342 printf (_(" Segment Sections...\n"));
3344 assert (string_table
!= NULL
);
3346 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3349 Elf_Internal_Shdr
*section
;
3351 segment
= program_headers
+ i
;
3352 section
= section_headers
;
3354 printf (" %2.2d ", i
);
3356 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3358 if (section
->sh_size
> 0
3359 /* Compare allocated sections by VMA, unallocated
3360 sections by file offset. */
3361 && (section
->sh_flags
& SHF_ALLOC
3362 ? (section
->sh_addr
>= segment
->p_vaddr
3363 && section
->sh_addr
+ section
->sh_size
3364 <= segment
->p_vaddr
+ segment
->p_memsz
)
3365 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3366 && (section
->sh_offset
+ section
->sh_size
3367 <= segment
->p_offset
+ segment
->p_filesz
)))
3368 /* .tbss is special. It doesn't contribute memory space
3369 to normal segments. */
3370 && (!((section
->sh_flags
& SHF_TLS
) != 0
3371 && section
->sh_type
== SHT_NOBITS
)
3372 || segment
->p_type
== PT_TLS
))
3373 printf ("%s ", SECTION_NAME (section
));
3384 /* Find the file offset corresponding to VMA by using the program headers. */
3387 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3389 Elf_Internal_Phdr
*seg
;
3391 if (! get_program_headers (file
))
3393 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3397 for (seg
= program_headers
;
3398 seg
< program_headers
+ elf_header
.e_phnum
;
3401 if (seg
->p_type
!= PT_LOAD
)
3404 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3405 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3406 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3409 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3416 get_32bit_section_headers (FILE *file
, unsigned int num
)
3418 Elf32_External_Shdr
*shdrs
;
3419 Elf_Internal_Shdr
*internal
;
3422 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3423 elf_header
.e_shentsize
* num
, _("section headers"));
3427 section_headers
= malloc (num
* sizeof (Elf_Internal_Shdr
));
3429 if (section_headers
== NULL
)
3431 error (_("Out of memory\n"));
3435 for (i
= 0, internal
= section_headers
;
3439 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3440 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3441 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3442 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3443 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3444 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3445 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3446 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3447 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3448 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3457 get_64bit_section_headers (FILE *file
, unsigned int num
)
3459 Elf64_External_Shdr
*shdrs
;
3460 Elf_Internal_Shdr
*internal
;
3463 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3464 elf_header
.e_shentsize
* num
, _("section headers"));
3468 section_headers
= malloc (num
* sizeof (Elf_Internal_Shdr
));
3470 if (section_headers
== NULL
)
3472 error (_("Out of memory\n"));
3476 for (i
= 0, internal
= section_headers
;
3480 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3481 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3482 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
3483 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
3484 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
3485 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
3486 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3487 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3488 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3489 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3497 static Elf_Internal_Sym
*
3498 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3500 unsigned long number
;
3501 Elf32_External_Sym
*esyms
;
3502 Elf_External_Sym_Shndx
*shndx
;
3503 Elf_Internal_Sym
*isyms
;
3504 Elf_Internal_Sym
*psym
;
3507 esyms
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
3513 if (symtab_shndx_hdr
!= NULL
3514 && (symtab_shndx_hdr
->sh_link
3515 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3517 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3518 symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3526 number
= section
->sh_size
/ section
->sh_entsize
;
3527 isyms
= malloc (number
* sizeof (Elf_Internal_Sym
));
3531 error (_("Out of memory\n"));
3538 for (j
= 0, psym
= isyms
;
3542 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3543 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3544 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3545 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3546 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3548 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3549 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3550 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3560 static Elf_Internal_Sym
*
3561 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3563 unsigned long number
;
3564 Elf64_External_Sym
*esyms
;
3565 Elf_External_Sym_Shndx
*shndx
;
3566 Elf_Internal_Sym
*isyms
;
3567 Elf_Internal_Sym
*psym
;
3570 esyms
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
3576 if (symtab_shndx_hdr
!= NULL
3577 && (symtab_shndx_hdr
->sh_link
3578 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3580 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3581 symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3589 number
= section
->sh_size
/ section
->sh_entsize
;
3590 isyms
= malloc (number
* sizeof (Elf_Internal_Sym
));
3594 error (_("Out of memory\n"));
3601 for (j
= 0, psym
= isyms
;
3605 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3606 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3607 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3608 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3609 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3611 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3612 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
3613 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
3624 get_elf_section_flags (bfd_vma sh_flags
)
3626 static char buff
[32];
3634 flag
= sh_flags
& - sh_flags
;
3639 case SHF_WRITE
: strcat (buff
, "W"); break;
3640 case SHF_ALLOC
: strcat (buff
, "A"); break;
3641 case SHF_EXECINSTR
: strcat (buff
, "X"); break;
3642 case SHF_MERGE
: strcat (buff
, "M"); break;
3643 case SHF_STRINGS
: strcat (buff
, "S"); break;
3644 case SHF_INFO_LINK
: strcat (buff
, "I"); break;
3645 case SHF_LINK_ORDER
: strcat (buff
, "L"); break;
3646 case SHF_OS_NONCONFORMING
: strcat (buff
, "O"); break;
3647 case SHF_GROUP
: strcat (buff
, "G"); break;
3648 case SHF_TLS
: strcat (buff
, "T"); break;
3651 if (flag
& SHF_MASKOS
)
3654 sh_flags
&= ~ SHF_MASKOS
;
3656 else if (flag
& SHF_MASKPROC
)
3659 sh_flags
&= ~ SHF_MASKPROC
;
3671 process_section_headers (FILE *file
)
3673 Elf_Internal_Shdr
*section
;
3676 section_headers
= NULL
;
3678 if (elf_header
.e_shnum
== 0)
3681 printf (_("\nThere are no sections in this file.\n"));
3686 if (do_sections
&& !do_header
)
3687 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3688 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3692 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3695 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3698 /* Read in the string table, so that we have names to display. */
3699 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3701 if (section
->sh_size
!= 0)
3703 string_table
= get_data (NULL
, file
, section
->sh_offset
,
3704 section
->sh_size
, _("string table"));
3706 if (string_table
== NULL
)
3709 string_table_length
= section
->sh_size
;
3712 /* Scan the sections for the dynamic symbol table
3713 and dynamic string table and debug sections. */
3714 dynamic_symbols
= NULL
;
3715 dynamic_strings
= NULL
;
3716 dynamic_syminfo
= NULL
;
3717 symtab_shndx_hdr
= NULL
;
3719 for (i
= 0, section
= section_headers
;
3720 i
< elf_header
.e_shnum
;
3723 char *name
= SECTION_NAME (section
);
3725 if (section
->sh_type
== SHT_DYNSYM
)
3727 if (dynamic_symbols
!= NULL
)
3729 error (_("File contains multiple dynamic symbol tables\n"));
3733 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3734 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3736 else if (section
->sh_type
== SHT_STRTAB
3737 && streq (name
, ".dynstr"))
3739 if (dynamic_strings
!= NULL
)
3741 error (_("File contains multiple dynamic string tables\n"));
3745 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
3746 section
->sh_size
, _("dynamic strings"));
3747 dynamic_strings_length
= section
->sh_size
;
3749 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3751 if (symtab_shndx_hdr
!= NULL
)
3753 error (_("File contains multiple symtab shndx tables\n"));
3756 symtab_shndx_hdr
= section
;
3758 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3759 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3760 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3761 || do_debug_loc
|| do_debug_ranges
)
3762 && strneq (name
, ".debug_", 7))
3767 || (do_debug_info
&& streq (name
, "info"))
3768 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
3769 || (do_debug_lines
&& streq (name
, "line"))
3770 || (do_debug_pubnames
&& streq (name
, "pubnames"))
3771 || (do_debug_aranges
&& streq (name
, "aranges"))
3772 || (do_debug_ranges
&& streq (name
, "ranges"))
3773 || (do_debug_frames
&& streq (name
, "frame"))
3774 || (do_debug_macinfo
&& streq (name
, "macinfo"))
3775 || (do_debug_str
&& streq (name
, "str"))
3776 || (do_debug_loc
&& streq (name
, "loc"))
3778 request_dump (i
, DEBUG_DUMP
);
3780 /* linkonce section to be combined with .debug_info at link time. */
3781 else if ((do_debugging
|| do_debug_info
)
3782 && strneq (name
, ".gnu.linkonce.wi.", 17))
3783 request_dump (i
, DEBUG_DUMP
);
3784 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
3785 request_dump (i
, DEBUG_DUMP
);
3791 if (elf_header
.e_shnum
> 1)
3792 printf (_("\nSection Headers:\n"));
3794 printf (_("\nSection Header:\n"));
3798 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3801 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3804 printf (_(" [Nr] Name Type Address Offset\n"));
3805 printf (_(" Size EntSize Flags Link Info Align\n"));
3808 for (i
= 0, section
= section_headers
;
3809 i
< elf_header
.e_shnum
;
3812 printf (" [%2u] %-17.17s %-15.15s ",
3813 SECTION_HEADER_NUM (i
),
3814 SECTION_NAME (section
),
3815 get_section_type_name (section
->sh_type
));
3819 print_vma (section
->sh_addr
, LONG_HEX
);
3821 printf ( " %6.6lx %6.6lx %2.2lx",
3822 (unsigned long) section
->sh_offset
,
3823 (unsigned long) section
->sh_size
,
3824 (unsigned long) section
->sh_entsize
);
3826 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3828 printf ("%2ld %3lu %2ld\n",
3829 (unsigned long) section
->sh_link
,
3830 (unsigned long) section
->sh_info
,
3831 (unsigned long) section
->sh_addralign
);
3835 print_vma (section
->sh_addr
, LONG_HEX
);
3837 if ((long) section
->sh_offset
== section
->sh_offset
)
3838 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
3842 print_vma (section
->sh_offset
, LONG_HEX
);
3845 if ((unsigned long) section
->sh_size
== section
->sh_size
)
3846 printf (" %6.6lx", (unsigned long) section
->sh_size
);
3850 print_vma (section
->sh_size
, LONG_HEX
);
3853 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
3854 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
3858 print_vma (section
->sh_entsize
, LONG_HEX
);
3861 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3863 printf ("%2ld %3lu ",
3864 (unsigned long) section
->sh_link
,
3865 (unsigned long) section
->sh_info
);
3867 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
3868 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
3871 print_vma (section
->sh_addralign
, DEC
);
3878 print_vma (section
->sh_addr
, LONG_HEX
);
3879 if ((long) section
->sh_offset
== section
->sh_offset
)
3880 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
3884 print_vma (section
->sh_offset
, LONG_HEX
);
3887 print_vma (section
->sh_size
, LONG_HEX
);
3889 print_vma (section
->sh_entsize
, LONG_HEX
);
3891 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3893 printf (" %2ld %3lu %ld\n",
3894 (unsigned long) section
->sh_link
,
3895 (unsigned long) section
->sh_info
,
3896 (unsigned long) section
->sh_addralign
);
3900 printf (_("Key to Flags:\n\
3901 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3902 I (info), L (link order), G (group), x (unknown)\n\
3903 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3909 get_group_flags (unsigned int flags
)
3911 static char buff
[32];
3918 sprintf (buff
, _("[<unknown>: 0x%x]"), flags
);
3925 process_section_groups (FILE *file
)
3927 Elf_Internal_Shdr
*section
;
3929 struct group
*group
;
3931 if (elf_header
.e_shnum
== 0)
3933 if (do_section_groups
)
3934 printf (_("\nThere are no section groups in this file.\n"));
3939 if (section_headers
== NULL
)
3941 error (_("Section headers are not available!\n"));
3945 section_headers_groups
= calloc (elf_header
.e_shnum
,
3946 sizeof (struct group
*));
3948 if (section_headers_groups
== NULL
)
3950 error (_("Out of memory\n"));
3954 /* Scan the sections for the group section. */
3955 for (i
= 0, section
= section_headers
;
3956 i
< elf_header
.e_shnum
;
3958 if (section
->sh_type
== SHT_GROUP
)
3961 section_groups
= calloc (group_count
, sizeof (struct group
));
3963 if (section_groups
== NULL
)
3965 error (_("Out of memory\n"));
3969 for (i
= 0, section
= section_headers
, group
= section_groups
;
3970 i
< elf_header
.e_shnum
;
3973 if (section
->sh_type
== SHT_GROUP
)
3975 char *name
= SECTION_NAME (section
);
3976 char *group_name
, *strtab
, *start
, *indices
;
3977 unsigned int entry
, j
, size
;
3978 Elf_Internal_Sym
*sym
;
3979 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
, *sec
;
3980 Elf_Internal_Sym
*symtab
;
3982 /* Get the symbol table. */
3983 symtab_sec
= SECTION_HEADER (section
->sh_link
);
3984 if (symtab_sec
->sh_type
!= SHT_SYMTAB
)
3986 error (_("Bad sh_link in group section `%s'\n"), name
);
3989 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
3991 sym
= symtab
+ section
->sh_info
;
3993 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3995 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
3998 error (_("Bad sh_info in group section `%s'\n"), name
);
4002 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4007 /* Get the string table. */
4008 strtab_sec
= SECTION_HEADER (symtab_sec
->sh_link
);
4009 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4010 strtab_sec
->sh_size
,
4013 group_name
= strtab
+ sym
->st_name
;
4016 start
= get_data (NULL
, file
, section
->sh_offset
,
4017 section
->sh_size
, _("section data"));
4020 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4021 entry
= byte_get (indices
, 4);
4024 if (do_section_groups
)
4026 printf ("\n%s group section `%s' [%s] contains %u sections:\n",
4027 get_group_flags (entry
), name
, group_name
, size
);
4029 printf (_(" [Index] Name\n"));
4032 group
->group_index
= i
;
4034 for (j
= 0; j
< size
; j
++)
4036 struct group_list
*g
;
4038 entry
= byte_get (indices
, 4);
4041 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4044 error (_("section [%5u] already in group section [%5u]\n"),
4045 entry
, section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4049 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4052 if (do_section_groups
)
4054 sec
= SECTION_HEADER (entry
);
4055 printf (" [%5u] %s\n",
4056 entry
, SECTION_NAME (sec
));
4059 g
= xmalloc (sizeof (struct group_list
));
4060 g
->section_index
= entry
;
4061 g
->next
= group
->root
;
4085 } dynamic_relocations
[] =
4087 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4088 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4089 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4092 /* Process the reloc section. */
4095 process_relocs (FILE *file
)
4097 unsigned long rel_size
;
4098 unsigned long rel_offset
;
4104 if (do_using_dynamic
)
4108 int has_dynamic_reloc
;
4111 has_dynamic_reloc
= 0;
4113 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4115 is_rela
= dynamic_relocations
[i
].rela
;
4116 name
= dynamic_relocations
[i
].name
;
4117 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4118 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4120 has_dynamic_reloc
|= rel_size
;
4122 if (is_rela
== UNKNOWN
)
4124 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4125 switch (dynamic_info
[DT_PLTREL
])
4139 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4140 name
, rel_offset
, rel_size
);
4142 dump_relocations (file
,
4143 offset_from_vma (file
, rel_offset
, rel_size
),
4145 dynamic_symbols
, num_dynamic_syms
,
4146 dynamic_strings
, dynamic_strings_length
, is_rela
);
4150 if (! has_dynamic_reloc
)
4151 printf (_("\nThere are no dynamic relocations in this file.\n"));
4155 Elf_Internal_Shdr
*section
;
4159 for (i
= 0, section
= section_headers
;
4160 i
< elf_header
.e_shnum
;
4163 if ( section
->sh_type
!= SHT_RELA
4164 && section
->sh_type
!= SHT_REL
)
4167 rel_offset
= section
->sh_offset
;
4168 rel_size
= section
->sh_size
;
4172 Elf_Internal_Shdr
*strsec
;
4175 printf (_("\nRelocation section "));
4177 if (string_table
== NULL
)
4178 printf ("%d", section
->sh_name
);
4180 printf (_("'%s'"), SECTION_NAME (section
));
4182 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4183 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4185 is_rela
= section
->sh_type
== SHT_RELA
;
4187 if (section
->sh_link
)
4189 Elf_Internal_Shdr
*symsec
;
4190 Elf_Internal_Sym
*symtab
;
4191 unsigned long nsyms
;
4192 unsigned long strtablen
;
4193 char *strtab
= NULL
;
4195 symsec
= SECTION_HEADER (section
->sh_link
);
4196 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4197 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4202 strsec
= SECTION_HEADER (symsec
->sh_link
);
4204 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4205 strsec
->sh_size
, _("string table"));
4206 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4208 dump_relocations (file
, rel_offset
, rel_size
,
4209 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4215 dump_relocations (file
, rel_offset
, rel_size
,
4216 NULL
, 0, NULL
, 0, is_rela
);
4223 printf (_("\nThere are no relocations in this file.\n"));
4229 /* Process the unwind section. */
4231 #include "unwind-ia64.h"
4233 /* An absolute address consists of a section and an offset. If the
4234 section is NULL, the offset itself is the address, otherwise, the
4235 address equals to LOAD_ADDRESS(section) + offset. */
4239 unsigned short section
;
4243 struct ia64_unw_aux_info
4245 struct ia64_unw_table_entry
4247 struct absaddr start
;
4249 struct absaddr info
;
4251 *table
; /* Unwind table. */
4252 unsigned long table_len
; /* Length of unwind table. */
4253 unsigned char *info
; /* Unwind info. */
4254 unsigned long info_size
; /* Size of unwind info. */
4255 bfd_vma info_addr
; /* starting address of unwind info. */
4256 bfd_vma seg_base
; /* Starting address of segment. */
4257 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4258 unsigned long nsyms
; /* Number of symbols. */
4259 char *strtab
; /* The string table. */
4260 unsigned long strtab_size
; /* Size of string table. */
4264 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4265 unsigned long nsyms
,
4267 unsigned long strtab_size
,
4268 struct absaddr addr
,
4269 const char **symname
,
4272 bfd_vma dist
= 0x100000;
4273 Elf_Internal_Sym
*sym
, *best
= NULL
;
4276 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4278 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4279 && sym
->st_name
!= 0
4280 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4281 && addr
.offset
>= sym
->st_value
4282 && addr
.offset
- sym
->st_value
< dist
)
4285 dist
= addr
.offset
- sym
->st_value
;
4292 *symname
= (best
->st_name
>= strtab_size
4293 ? "<corrupt>" : strtab
+ best
->st_name
);
4298 *offset
= addr
.offset
;
4302 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4305 struct ia64_unw_table_entry
*tp
;
4308 addr_size
= is_32bit_elf
? 4 : 8;
4310 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4314 const unsigned char *dp
;
4315 const unsigned char *head
;
4316 const char *procname
;
4318 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4319 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4321 fputs ("\n<", stdout
);
4325 fputs (procname
, stdout
);
4328 printf ("+%lx", (unsigned long) offset
);
4331 fputs (">: [", stdout
);
4332 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4333 fputc ('-', stdout
);
4334 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4335 printf ("], info at +0x%lx\n",
4336 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4338 head
= aux
->info
+ (tp
->info
.offset
- aux
->info_addr
);
4339 stamp
= BYTE_GET8 ((unsigned char *) head
);
4341 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4342 (unsigned) UNW_VER (stamp
),
4343 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4344 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4345 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4346 (unsigned long) (addr_size
* UNW_LENGTH (stamp
)));
4348 if (UNW_VER (stamp
) != 1)
4350 printf ("\tUnknown version.\n");
4355 for (dp
= head
+ 8; dp
< head
+ 8 + addr_size
* UNW_LENGTH (stamp
);)
4356 dp
= unw_decode (dp
, in_body
, & in_body
);
4361 slurp_ia64_unwind_table (FILE *file
,
4362 struct ia64_unw_aux_info
*aux
,
4363 Elf_Internal_Shdr
*sec
)
4365 unsigned long size
, addr_size
, nrelas
, i
;
4366 Elf_Internal_Phdr
*seg
;
4367 struct ia64_unw_table_entry
*tep
;
4368 Elf_Internal_Shdr
*relsec
;
4369 Elf_Internal_Rela
*rela
, *rp
;
4370 unsigned char *table
, *tp
;
4371 Elf_Internal_Sym
*sym
;
4372 const char *relname
;
4374 addr_size
= is_32bit_elf
? 4 : 8;
4376 /* First, find the starting address of the segment that includes
4379 if (elf_header
.e_phnum
)
4381 if (! get_program_headers (file
))
4384 for (seg
= program_headers
;
4385 seg
< program_headers
+ elf_header
.e_phnum
;
4388 if (seg
->p_type
!= PT_LOAD
)
4391 if (sec
->sh_addr
>= seg
->p_vaddr
4392 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4394 aux
->seg_base
= seg
->p_vaddr
;
4400 /* Second, build the unwind table from the contents of the unwind section: */
4401 size
= sec
->sh_size
;
4402 table
= get_data (NULL
, file
, sec
->sh_offset
, size
, _("unwind table"));
4406 tep
= aux
->table
= xmalloc (size
/ (3 * addr_size
) * sizeof (aux
->table
[0]));
4407 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * addr_size
, ++tep
)
4409 tep
->start
.section
= SHN_UNDEF
;
4410 tep
->end
.section
= SHN_UNDEF
;
4411 tep
->info
.section
= SHN_UNDEF
;
4414 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4415 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4416 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4420 tep
->start
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 0);
4421 tep
->end
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 8);
4422 tep
->info
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 16);
4424 tep
->start
.offset
+= aux
->seg_base
;
4425 tep
->end
.offset
+= aux
->seg_base
;
4426 tep
->info
.offset
+= aux
->seg_base
;
4430 /* Third, apply any relocations to the unwind table: */
4432 for (relsec
= section_headers
;
4433 relsec
< section_headers
+ elf_header
.e_shnum
;
4436 if (relsec
->sh_type
!= SHT_RELA
4437 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4440 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4444 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4448 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4449 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4453 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4454 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4457 if (! strneq (relname
, "R_IA64_SEGREL", 13))
4459 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4463 i
= rp
->r_offset
/ (3 * addr_size
);
4465 switch (rp
->r_offset
/addr_size
% 3)
4468 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4469 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
4472 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4473 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
4476 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4477 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
4487 aux
->table_len
= size
/ (3 * addr_size
);
4492 ia64_process_unwind (FILE *file
)
4494 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4495 unsigned long i
, addr_size
, unwcount
= 0, unwstart
= 0;
4496 struct ia64_unw_aux_info aux
;
4498 memset (& aux
, 0, sizeof (aux
));
4500 addr_size
= is_32bit_elf
? 4 : 8;
4502 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4504 if (sec
->sh_type
== SHT_SYMTAB
)
4506 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4507 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4509 strsec
= SECTION_HEADER (sec
->sh_link
);
4510 aux
.strtab_size
= strsec
->sh_size
;
4511 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4512 aux
.strtab_size
, _("string table"));
4514 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4519 printf (_("\nThere are no unwind sections in this file.\n"));
4521 while (unwcount
-- > 0)
4526 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4527 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4528 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4535 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4537 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
4539 /* We need to find which section group it is in. */
4540 struct group_list
*g
= section_headers_groups
[i
]->root
;
4542 for (; g
!= NULL
; g
= g
->next
)
4544 sec
= SECTION_HEADER (g
->section_index
);
4546 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
4551 i
= elf_header
.e_shnum
;
4553 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
4555 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
4556 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4557 suffix
= SECTION_NAME (unwsec
) + len
;
4558 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4560 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
4561 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4566 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4567 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
4568 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4569 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4571 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
4572 suffix
= SECTION_NAME (unwsec
) + len
;
4573 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4575 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
4576 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4580 if (i
== elf_header
.e_shnum
)
4582 printf (_("\nCould not find unwind info section for "));
4584 if (string_table
== NULL
)
4585 printf ("%d", unwsec
->sh_name
);
4587 printf (_("'%s'"), SECTION_NAME (unwsec
));
4591 aux
.info_size
= sec
->sh_size
;
4592 aux
.info_addr
= sec
->sh_addr
;
4593 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, aux
.info_size
,
4596 printf (_("\nUnwind section "));
4598 if (string_table
== NULL
)
4599 printf ("%d", unwsec
->sh_name
);
4601 printf (_("'%s'"), SECTION_NAME (unwsec
));
4603 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4604 (unsigned long) unwsec
->sh_offset
,
4605 (unsigned long) (unwsec
->sh_size
/ (3 * addr_size
)));
4607 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4609 if (aux
.table_len
> 0)
4610 dump_ia64_unwind (& aux
);
4613 free ((char *) aux
.table
);
4615 free ((char *) aux
.info
);
4624 free ((char *) aux
.strtab
);
4629 struct hppa_unw_aux_info
4631 struct hppa_unw_table_entry
4633 struct absaddr start
;
4635 unsigned int Cannot_unwind
:1; /* 0 */
4636 unsigned int Millicode
:1; /* 1 */
4637 unsigned int Millicode_save_sr0
:1; /* 2 */
4638 unsigned int Region_description
:2; /* 3..4 */
4639 unsigned int reserved1
:1; /* 5 */
4640 unsigned int Entry_SR
:1; /* 6 */
4641 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
4642 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
4643 unsigned int Args_stored
:1; /* 16 */
4644 unsigned int Variable_Frame
:1; /* 17 */
4645 unsigned int Separate_Package_Body
:1; /* 18 */
4646 unsigned int Frame_Extension_Millicode
:1; /* 19 */
4647 unsigned int Stack_Overflow_Check
:1; /* 20 */
4648 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
4649 unsigned int Ada_Region
:1; /* 22 */
4650 unsigned int cxx_info
:1; /* 23 */
4651 unsigned int cxx_try_catch
:1; /* 24 */
4652 unsigned int sched_entry_seq
:1; /* 25 */
4653 unsigned int reserved2
:1; /* 26 */
4654 unsigned int Save_SP
:1; /* 27 */
4655 unsigned int Save_RP
:1; /* 28 */
4656 unsigned int Save_MRP_in_frame
:1; /* 29 */
4657 unsigned int extn_ptr_defined
:1; /* 30 */
4658 unsigned int Cleanup_defined
:1; /* 31 */
4660 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
4661 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
4662 unsigned int Large_frame
:1; /* 2 */
4663 unsigned int Pseudo_SP_Set
:1; /* 3 */
4664 unsigned int reserved4
:1; /* 4 */
4665 unsigned int Total_frame_size
:27; /* 5..31 */
4667 *table
; /* Unwind table. */
4668 unsigned long table_len
; /* Length of unwind table. */
4669 bfd_vma seg_base
; /* Starting address of segment. */
4670 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4671 unsigned long nsyms
; /* Number of symbols. */
4672 char *strtab
; /* The string table. */
4673 unsigned long strtab_size
; /* Size of string table. */
4677 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
4680 struct hppa_unw_table_entry
*tp
;
4682 addr_size
= is_32bit_elf
? 4 : 8;
4683 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4686 const char *procname
;
4688 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4689 aux
->strtab_size
, tp
->start
, &procname
,
4692 fputs ("\n<", stdout
);
4696 fputs (procname
, stdout
);
4699 printf ("+%lx", (unsigned long) offset
);
4702 fputs (">: [", stdout
);
4703 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4704 fputc ('-', stdout
);
4705 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4708 #define PF(_m) if (tp->_m) printf (#_m " ");
4709 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
4712 PF(Millicode_save_sr0
);
4713 /* PV(Region_description); */
4719 PF(Separate_Package_Body
);
4720 PF(Frame_Extension_Millicode
);
4721 PF(Stack_Overflow_Check
);
4722 PF(Two_Instruction_SP_Increment
);
4726 PF(sched_entry_seq
);
4729 PF(Save_MRP_in_frame
);
4730 PF(extn_ptr_defined
);
4731 PF(Cleanup_defined
);
4732 PF(MPE_XL_interrupt_marker
);
4733 PF(HP_UX_interrupt_marker
);
4736 PV(Total_frame_size
);
4745 slurp_hppa_unwind_table (FILE *file
,
4746 struct hppa_unw_aux_info
*aux
,
4747 Elf_Internal_Shdr
*sec
)
4749 unsigned long size
, unw_ent_size
, addr_size
, nrelas
, i
;
4750 Elf_Internal_Phdr
*seg
;
4751 struct hppa_unw_table_entry
*tep
;
4752 Elf_Internal_Shdr
*relsec
;
4753 Elf_Internal_Rela
*rela
, *rp
;
4754 unsigned char *table
, *tp
;
4755 Elf_Internal_Sym
*sym
;
4756 const char *relname
;
4758 addr_size
= is_32bit_elf
? 4 : 8;
4760 /* First, find the starting address of the segment that includes
4763 if (elf_header
.e_phnum
)
4765 if (! get_program_headers (file
))
4768 for (seg
= program_headers
;
4769 seg
< program_headers
+ elf_header
.e_phnum
;
4772 if (seg
->p_type
!= PT_LOAD
)
4775 if (sec
->sh_addr
>= seg
->p_vaddr
4776 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4778 aux
->seg_base
= seg
->p_vaddr
;
4784 /* Second, build the unwind table from the contents of the unwind
4786 size
= sec
->sh_size
;
4787 table
= get_data (NULL
, file
, sec
->sh_offset
, size
, _("unwind table"));
4791 unw_ent_size
= 2 * addr_size
+ 8;
4793 tep
= aux
->table
= xmalloc (size
/ unw_ent_size
* sizeof (aux
->table
[0]));
4795 for (tp
= table
; tp
< table
+ size
; tp
+= (2 * addr_size
+ 8), ++tep
)
4797 unsigned int tmp1
, tmp2
;
4799 tep
->start
.section
= SHN_UNDEF
;
4800 tep
->end
.section
= SHN_UNDEF
;
4804 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4805 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4806 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
4807 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
4811 tep
->start
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 0);
4812 tep
->end
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 8);
4813 tmp1
= byte_get ((unsigned char *) tp
+ 16, 4);
4814 tmp2
= byte_get ((unsigned char *) tp
+ 20, 4);
4817 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
4818 tep
->Millicode
= (tmp1
>> 30) & 0x1;
4819 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
4820 tep
->Region_description
= (tmp1
>> 27) & 0x3;
4821 tep
->reserved1
= (tmp1
>> 26) & 0x1;
4822 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
4823 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
4824 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
4825 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
4826 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
4827 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
4828 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
4829 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
4830 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
4831 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
4832 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
4833 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
4834 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
4835 tep
->reserved2
= (tmp1
>> 5) & 0x1;
4836 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
4837 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
4838 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
4839 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
4840 tep
->Cleanup_defined
= tmp1
& 0x1;
4842 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
4843 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
4844 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
4845 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
4846 tep
->reserved4
= (tmp2
>> 27) & 0x1;
4847 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
4849 tep
->start
.offset
+= aux
->seg_base
;
4850 tep
->end
.offset
+= aux
->seg_base
;
4854 /* Third, apply any relocations to the unwind table. */
4856 for (relsec
= section_headers
;
4857 relsec
< section_headers
+ elf_header
.e_shnum
;
4860 if (relsec
->sh_type
!= SHT_RELA
4861 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4864 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4868 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4872 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4873 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4877 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4878 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4881 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
4882 if (strncmp (relname
, "R_PARISC_SEGREL", 15) != 0)
4884 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4888 i
= rp
->r_offset
/ unw_ent_size
;
4890 switch ((rp
->r_offset
% unw_ent_size
) / addr_size
)
4893 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4894 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
4897 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4898 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
4908 aux
->table_len
= size
/ unw_ent_size
;
4914 hppa_process_unwind (FILE *file
)
4916 struct hppa_unw_aux_info aux
;
4917 Elf_Internal_Shdr
*unwsec
= NULL
;
4918 Elf_Internal_Shdr
*strsec
;
4919 Elf_Internal_Shdr
*sec
;
4920 unsigned long addr_size
;
4923 memset (& aux
, 0, sizeof (aux
));
4925 assert (string_table
!= NULL
);
4926 addr_size
= is_32bit_elf
? 4 : 8;
4928 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4930 if (sec
->sh_type
== SHT_SYMTAB
)
4932 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4933 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4935 strsec
= SECTION_HEADER (sec
->sh_link
);
4936 aux
.strtab_size
= strsec
->sh_size
;
4937 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4938 aux
.strtab_size
, _("string table"));
4940 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
4945 printf (_("\nThere are no unwind sections in this file.\n"));
4947 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4949 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
4951 printf (_("\nUnwind section "));
4952 printf (_("'%s'"), SECTION_NAME (sec
));
4954 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4955 (unsigned long) sec
->sh_offset
,
4956 (unsigned long) (sec
->sh_size
/ (2 * addr_size
+ 8)));
4958 slurp_hppa_unwind_table (file
, &aux
, sec
);
4959 if (aux
.table_len
> 0)
4960 dump_hppa_unwind (&aux
);
4963 free ((char *) aux
.table
);
4971 free ((char *) aux
.strtab
);
4977 process_unwind (FILE *file
)
4979 struct unwind_handler
{
4981 int (*handler
)(FILE *file
);
4983 { EM_IA_64
, ia64_process_unwind
},
4984 { EM_PARISC
, hppa_process_unwind
},
4992 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
4993 if (elf_header
.e_machine
== handlers
[i
].machtype
)
4994 return handlers
[i
].handler (file
);
4996 printf (_("\nThere are no unwind sections in this file.\n"));
5001 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5003 switch (entry
->d_tag
)
5006 if (entry
->d_un
.d_val
== 0)
5010 static const char * opts
[] =
5012 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5013 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5014 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5015 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5020 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
5021 if (entry
->d_un
.d_val
& (1 << cnt
))
5023 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5030 case DT_MIPS_IVERSION
:
5031 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5032 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5034 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5037 case DT_MIPS_TIME_STAMP
:
5042 time_t time
= entry
->d_un
.d_val
;
5043 tmp
= gmtime (&time
);
5044 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
5045 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5046 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5047 printf ("Time Stamp: %s\n", timebuf
);
5051 case DT_MIPS_RLD_VERSION
:
5052 case DT_MIPS_LOCAL_GOTNO
:
5053 case DT_MIPS_CONFLICTNO
:
5054 case DT_MIPS_LIBLISTNO
:
5055 case DT_MIPS_SYMTABNO
:
5056 case DT_MIPS_UNREFEXTNO
:
5057 case DT_MIPS_HIPAGENO
:
5058 case DT_MIPS_DELTA_CLASS_NO
:
5059 case DT_MIPS_DELTA_INSTANCE_NO
:
5060 case DT_MIPS_DELTA_RELOC_NO
:
5061 case DT_MIPS_DELTA_SYM_NO
:
5062 case DT_MIPS_DELTA_CLASSSYM_NO
:
5063 case DT_MIPS_COMPACT_SIZE
:
5064 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5068 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5074 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5076 switch (entry
->d_tag
)
5078 case DT_HP_DLD_FLAGS
:
5087 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5088 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5089 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5090 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5091 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5092 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5093 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5094 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5095 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5096 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5097 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" }
5101 bfd_vma val
= entry
->d_un
.d_val
;
5103 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
5104 if (val
& flags
[cnt
].bit
)
5108 fputs (flags
[cnt
].str
, stdout
);
5110 val
^= flags
[cnt
].bit
;
5113 if (val
!= 0 || first
)
5117 print_vma (val
, HEX
);
5123 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5130 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5132 switch (entry
->d_tag
)
5134 case DT_IA_64_PLT_RESERVE
:
5135 /* First 3 slots reserved. */
5136 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5138 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5142 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5149 get_32bit_dynamic_section (FILE *file
)
5151 Elf32_External_Dyn
*edyn
, *ext
;
5152 Elf_Internal_Dyn
*entry
;
5154 edyn
= get_data (NULL
, file
, dynamic_addr
, dynamic_size
,
5155 _("dynamic section"));
5159 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5160 might not have the luxury of section headers. Look for the DT_NULL
5161 terminator to determine the number of entries. */
5162 for (ext
= edyn
, dynamic_nent
= 0;
5163 (char *) ext
< (char *) edyn
+ dynamic_size
;
5167 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5171 dynamic_section
= malloc (dynamic_nent
* sizeof (*entry
));
5172 if (dynamic_section
== NULL
)
5174 error (_("Out of memory\n"));
5179 for (ext
= edyn
, entry
= dynamic_section
;
5180 entry
< dynamic_section
+ dynamic_nent
;
5183 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5184 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5193 get_64bit_dynamic_section (FILE *file
)
5195 Elf64_External_Dyn
*edyn
, *ext
;
5196 Elf_Internal_Dyn
*entry
;
5198 edyn
= get_data (NULL
, file
, dynamic_addr
, dynamic_size
,
5199 _("dynamic section"));
5203 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5204 might not have the luxury of section headers. Look for the DT_NULL
5205 terminator to determine the number of entries. */
5206 for (ext
= edyn
, dynamic_nent
= 0;
5207 (char *) ext
< (char *) edyn
+ dynamic_size
;
5211 if (BYTE_GET8 (ext
->d_tag
) == DT_NULL
)
5215 dynamic_section
= malloc (dynamic_nent
* sizeof (*entry
));
5216 if (dynamic_section
== NULL
)
5218 error (_("Out of memory\n"));
5223 for (ext
= edyn
, entry
= dynamic_section
;
5224 entry
< dynamic_section
+ dynamic_nent
;
5227 entry
->d_tag
= BYTE_GET8 (ext
->d_tag
);
5228 entry
->d_un
.d_val
= BYTE_GET8 (ext
->d_un
.d_val
);
5237 get_dynamic_flags (bfd_vma flags
)
5239 static char buff
[128];
5247 flag
= flags
& - flags
;
5255 case DF_ORIGIN
: strcpy (p
, "ORIGIN"); break;
5256 case DF_SYMBOLIC
: strcpy (p
, "SYMBOLIC"); break;
5257 case DF_TEXTREL
: strcpy (p
, "TEXTREL"); break;
5258 case DF_BIND_NOW
: strcpy (p
, "BIND_NOW"); break;
5259 case DF_STATIC_TLS
: strcpy (p
, "STATIC_TLS"); break;
5260 default: strcpy (p
, "unknown"); break;
5263 p
= strchr (p
, '\0');
5268 /* Parse and display the contents of the dynamic section. */
5271 process_dynamic_section (FILE *file
)
5273 Elf_Internal_Dyn
*entry
;
5275 if (dynamic_size
== 0)
5278 printf (_("\nThere is no dynamic section in this file.\n"));
5285 if (! get_32bit_dynamic_section (file
))
5288 else if (! get_64bit_dynamic_section (file
))
5291 /* Find the appropriate symbol table. */
5292 if (dynamic_symbols
== NULL
)
5294 for (entry
= dynamic_section
;
5295 entry
< dynamic_section
+ dynamic_nent
;
5298 Elf_Internal_Shdr section
;
5300 if (entry
->d_tag
!= DT_SYMTAB
)
5303 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5305 /* Since we do not know how big the symbol table is,
5306 we default to reading in the entire file (!) and
5307 processing that. This is overkill, I know, but it
5309 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5311 if (archive_file_offset
!= 0)
5312 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5315 if (fseek (file
, 0, SEEK_END
))
5316 error (_("Unable to seek to end of file!"));
5318 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5322 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5324 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5326 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5327 if (num_dynamic_syms
< 1)
5329 error (_("Unable to determine the number of symbols to load\n"));
5333 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5337 /* Similarly find a string table. */
5338 if (dynamic_strings
== NULL
)
5340 for (entry
= dynamic_section
;
5341 entry
< dynamic_section
+ dynamic_nent
;
5344 unsigned long offset
;
5347 if (entry
->d_tag
!= DT_STRTAB
)
5350 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5352 /* Since we do not know how big the string table is,
5353 we default to reading in the entire file (!) and
5354 processing that. This is overkill, I know, but it
5357 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5359 if (archive_file_offset
!= 0)
5360 str_tab_len
= archive_file_size
- offset
;
5363 if (fseek (file
, 0, SEEK_END
))
5364 error (_("Unable to seek to end of file\n"));
5365 str_tab_len
= ftell (file
) - offset
;
5368 if (str_tab_len
< 1)
5371 (_("Unable to determine the length of the dynamic string table\n"));
5375 dynamic_strings
= get_data (NULL
, file
, offset
, str_tab_len
,
5376 _("dynamic string table"));
5377 dynamic_strings_length
= str_tab_len
;
5382 /* And find the syminfo section if available. */
5383 if (dynamic_syminfo
== NULL
)
5385 unsigned long syminsz
= 0;
5387 for (entry
= dynamic_section
;
5388 entry
< dynamic_section
+ dynamic_nent
;
5391 if (entry
->d_tag
== DT_SYMINENT
)
5393 /* Note: these braces are necessary to avoid a syntax
5394 error from the SunOS4 C compiler. */
5395 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5397 else if (entry
->d_tag
== DT_SYMINSZ
)
5398 syminsz
= entry
->d_un
.d_val
;
5399 else if (entry
->d_tag
== DT_SYMINFO
)
5400 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5404 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5406 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5407 Elf_Internal_Syminfo
*syminfo
;
5409 /* There is a syminfo section. Read the data. */
5410 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, syminsz
,
5411 _("symbol information"));
5415 dynamic_syminfo
= malloc (syminsz
);
5416 if (dynamic_syminfo
== NULL
)
5418 error (_("Out of memory\n"));
5422 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5423 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5424 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5425 ++syminfo
, ++extsym
)
5427 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5428 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5435 if (do_dynamic
&& dynamic_addr
)
5436 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5437 dynamic_addr
, dynamic_nent
);
5439 printf (_(" Tag Type Name/Value\n"));
5441 for (entry
= dynamic_section
;
5442 entry
< dynamic_section
+ dynamic_nent
;
5450 print_vma (entry
->d_tag
, FULL_HEX
);
5451 dtype
= get_dynamic_type (entry
->d_tag
);
5452 printf (" (%s)%*s", dtype
,
5453 ((is_32bit_elf
? 27 : 19)
5454 - (int) strlen (dtype
)),
5458 switch (entry
->d_tag
)
5462 puts (get_dynamic_flags (entry
->d_un
.d_val
));
5472 switch (entry
->d_tag
)
5475 printf (_("Auxiliary library"));
5479 printf (_("Filter library"));
5483 printf (_("Configuration file"));
5487 printf (_("Dependency audit library"));
5491 printf (_("Audit library"));
5495 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5496 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5500 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5509 printf (_("Flags:"));
5511 if (entry
->d_un
.d_val
== 0)
5512 printf (_(" None\n"));
5515 unsigned long int val
= entry
->d_un
.d_val
;
5517 if (val
& DTF_1_PARINIT
)
5519 printf (" PARINIT");
5520 val
^= DTF_1_PARINIT
;
5522 if (val
& DTF_1_CONFEXP
)
5524 printf (" CONFEXP");
5525 val
^= DTF_1_CONFEXP
;
5528 printf (" %lx", val
);
5537 printf (_("Flags:"));
5539 if (entry
->d_un
.d_val
== 0)
5540 printf (_(" None\n"));
5543 unsigned long int val
= entry
->d_un
.d_val
;
5545 if (val
& DF_P1_LAZYLOAD
)
5547 printf (" LAZYLOAD");
5548 val
^= DF_P1_LAZYLOAD
;
5550 if (val
& DF_P1_GROUPPERM
)
5552 printf (" GROUPPERM");
5553 val
^= DF_P1_GROUPPERM
;
5556 printf (" %lx", val
);
5565 printf (_("Flags:"));
5566 if (entry
->d_un
.d_val
== 0)
5567 printf (_(" None\n"));
5570 unsigned long int val
= entry
->d_un
.d_val
;
5577 if (val
& DF_1_GLOBAL
)
5582 if (val
& DF_1_GROUP
)
5587 if (val
& DF_1_NODELETE
)
5589 printf (" NODELETE");
5590 val
^= DF_1_NODELETE
;
5592 if (val
& DF_1_LOADFLTR
)
5594 printf (" LOADFLTR");
5595 val
^= DF_1_LOADFLTR
;
5597 if (val
& DF_1_INITFIRST
)
5599 printf (" INITFIRST");
5600 val
^= DF_1_INITFIRST
;
5602 if (val
& DF_1_NOOPEN
)
5607 if (val
& DF_1_ORIGIN
)
5612 if (val
& DF_1_DIRECT
)
5617 if (val
& DF_1_TRANS
)
5622 if (val
& DF_1_INTERPOSE
)
5624 printf (" INTERPOSE");
5625 val
^= DF_1_INTERPOSE
;
5627 if (val
& DF_1_NODEFLIB
)
5629 printf (" NODEFLIB");
5630 val
^= DF_1_NODEFLIB
;
5632 if (val
& DF_1_NODUMP
)
5637 if (val
& DF_1_CONLFAT
)
5639 printf (" CONLFAT");
5640 val
^= DF_1_CONLFAT
;
5643 printf (" %lx", val
);
5650 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5652 puts (get_dynamic_type (entry
->d_un
.d_val
));
5672 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5678 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5679 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
5685 switch (entry
->d_tag
)
5688 printf (_("Shared library: [%s]"), name
);
5690 if (streq (name
, program_interpreter
))
5691 printf (_(" program interpreter"));
5695 printf (_("Library soname: [%s]"), name
);
5699 printf (_("Library rpath: [%s]"), name
);
5703 printf (_("Library runpath: [%s]"), name
);
5707 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5712 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5725 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5729 case DT_INIT_ARRAYSZ
:
5730 case DT_FINI_ARRAYSZ
:
5731 case DT_GNU_CONFLICTSZ
:
5732 case DT_GNU_LIBLISTSZ
:
5735 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5736 printf (" (bytes)\n");
5746 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5759 if (entry
->d_tag
== DT_USED
5760 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5762 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
5766 printf (_("Not needed object: [%s]\n"), name
);
5771 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5777 /* The value of this entry is ignored. */
5782 case DT_GNU_PRELINKED
:
5786 time_t time
= entry
->d_un
.d_val
;
5788 tmp
= gmtime (&time
);
5789 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
5790 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5791 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5797 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
5798 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
5803 switch (elf_header
.e_machine
)
5806 case EM_MIPS_RS3_LE
:
5807 dynamic_section_mips_val (entry
);
5810 dynamic_section_parisc_val (entry
);
5813 dynamic_section_ia64_val (entry
);
5816 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5828 get_ver_flags (unsigned int flags
)
5830 static char buff
[32];
5837 if (flags
& VER_FLG_BASE
)
5838 strcat (buff
, "BASE ");
5840 if (flags
& VER_FLG_WEAK
)
5842 if (flags
& VER_FLG_BASE
)
5843 strcat (buff
, "| ");
5845 strcat (buff
, "WEAK ");
5848 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
5849 strcat (buff
, "| <unknown>");
5854 /* Display the contents of the version sections. */
5856 process_version_sections (FILE *file
)
5858 Elf_Internal_Shdr
*section
;
5865 for (i
= 0, section
= section_headers
;
5866 i
< elf_header
.e_shnum
;
5869 switch (section
->sh_type
)
5871 case SHT_GNU_verdef
:
5873 Elf_External_Verdef
*edefs
;
5880 (_("\nVersion definition section '%s' contains %ld entries:\n"),
5881 SECTION_NAME (section
), section
->sh_info
);
5883 printf (_(" Addr: 0x"));
5884 printf_vma (section
->sh_addr
);
5885 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5886 (unsigned long) section
->sh_offset
, section
->sh_link
,
5887 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5889 edefs
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
5890 _("version definition section"));
5894 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5897 Elf_External_Verdef
*edef
;
5898 Elf_Internal_Verdef ent
;
5899 Elf_External_Verdaux
*eaux
;
5900 Elf_Internal_Verdaux aux
;
5904 vstart
= ((char *) edefs
) + idx
;
5906 edef
= (Elf_External_Verdef
*) vstart
;
5908 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
5909 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
5910 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
5911 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
5912 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
5913 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
5914 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
5916 printf (_(" %#06x: Rev: %d Flags: %s"),
5917 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
5919 printf (_(" Index: %d Cnt: %d "),
5920 ent
.vd_ndx
, ent
.vd_cnt
);
5922 vstart
+= ent
.vd_aux
;
5924 eaux
= (Elf_External_Verdaux
*) vstart
;
5926 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5927 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5929 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
5930 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
5932 printf (_("Name index: %ld\n"), aux
.vda_name
);
5934 isum
= idx
+ ent
.vd_aux
;
5936 for (j
= 1; j
< ent
.vd_cnt
; j
++)
5938 isum
+= aux
.vda_next
;
5939 vstart
+= aux
.vda_next
;
5941 eaux
= (Elf_External_Verdaux
*) vstart
;
5943 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5944 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5946 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
5947 printf (_(" %#06x: Parent %d: %s\n"),
5948 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
5950 printf (_(" %#06x: Parent %d, name index: %ld\n"),
5951 isum
, j
, aux
.vda_name
);
5961 case SHT_GNU_verneed
:
5963 Elf_External_Verneed
*eneed
;
5969 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
5970 SECTION_NAME (section
), section
->sh_info
);
5972 printf (_(" Addr: 0x"));
5973 printf_vma (section
->sh_addr
);
5974 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
5975 (unsigned long) section
->sh_offset
, section
->sh_link
,
5976 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5978 eneed
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
5979 _("version need section"));
5983 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5985 Elf_External_Verneed
*entry
;
5986 Elf_Internal_Verneed ent
;
5991 vstart
= ((char *) eneed
) + idx
;
5993 entry
= (Elf_External_Verneed
*) vstart
;
5995 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
5996 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
5997 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
5998 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
5999 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6001 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6003 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6004 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6006 printf (_(" File: %lx"), ent
.vn_file
);
6008 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6010 vstart
+= ent
.vn_aux
;
6012 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6014 Elf_External_Vernaux
*eaux
;
6015 Elf_Internal_Vernaux aux
;
6017 eaux
= (Elf_External_Vernaux
*) vstart
;
6019 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6020 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6021 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6022 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6023 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6025 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6026 printf (_(" %#06x: Name: %s"),
6027 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6029 printf (_(" %#06x: Name index: %lx"),
6030 isum
, aux
.vna_name
);
6032 printf (_(" Flags: %s Version: %d\n"),
6033 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6035 isum
+= aux
.vna_next
;
6036 vstart
+= aux
.vna_next
;
6046 case SHT_GNU_versym
:
6048 Elf_Internal_Shdr
*link_section
;
6051 unsigned char *edata
;
6052 unsigned short *data
;
6054 Elf_Internal_Sym
*symbols
;
6055 Elf_Internal_Shdr
*string_sec
;
6058 link_section
= SECTION_HEADER (section
->sh_link
);
6059 total
= section
->sh_size
/ section
->sh_entsize
;
6063 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6065 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6067 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
6068 string_sec
->sh_size
, _("version string table"));
6072 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6073 SECTION_NAME (section
), total
);
6075 printf (_(" Addr: "));
6076 printf_vma (section
->sh_addr
);
6077 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6078 (unsigned long) section
->sh_offset
, section
->sh_link
,
6079 SECTION_NAME (link_section
));
6081 off
= offset_from_vma (file
,
6082 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6083 total
* sizeof (short));
6084 edata
= get_data (NULL
, file
, off
, total
* sizeof (short),
6085 _("version symbol data"));
6092 data
= malloc (total
* sizeof (short));
6094 for (cnt
= total
; cnt
--;)
6095 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6100 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6103 int check_def
, check_need
;
6106 printf (" %03x:", cnt
);
6108 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6109 switch (data
[cnt
+ j
])
6112 fputs (_(" 0 (*local*) "), stdout
);
6116 fputs (_(" 1 (*global*) "), stdout
);
6120 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6121 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6125 if (SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6128 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6135 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6137 Elf_Internal_Verneed ivn
;
6138 unsigned long offset
;
6140 offset
= offset_from_vma
6141 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6142 sizeof (Elf_External_Verneed
));
6146 Elf_Internal_Vernaux ivna
;
6147 Elf_External_Verneed evn
;
6148 Elf_External_Vernaux evna
;
6149 unsigned long a_off
;
6151 get_data (&evn
, file
, offset
, sizeof (evn
),
6154 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6155 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6157 a_off
= offset
+ ivn
.vn_aux
;
6161 get_data (&evna
, file
, a_off
, sizeof (evna
),
6162 _("version need aux (2)"));
6164 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6165 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6167 a_off
+= ivna
.vna_next
;
6169 while (ivna
.vna_other
!= data
[cnt
+ j
]
6170 && ivna
.vna_next
!= 0);
6172 if (ivna
.vna_other
== data
[cnt
+ j
])
6174 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6176 name
= strtab
+ ivna
.vna_name
;
6177 nn
+= printf ("(%s%-*s",
6179 12 - (int) strlen (name
),
6185 offset
+= ivn
.vn_next
;
6187 while (ivn
.vn_next
);
6190 if (check_def
&& data
[cnt
+ j
] != 0x8001
6191 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6193 Elf_Internal_Verdef ivd
;
6194 Elf_External_Verdef evd
;
6195 unsigned long offset
;
6197 offset
= offset_from_vma
6198 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6203 get_data (&evd
, file
, offset
, sizeof (evd
),
6206 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6207 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6209 offset
+= ivd
.vd_next
;
6211 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6212 && ivd
.vd_next
!= 0);
6214 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6216 Elf_External_Verdaux evda
;
6217 Elf_Internal_Verdaux ivda
;
6219 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6221 get_data (&evda
, file
,
6222 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6223 sizeof (evda
), _("version def aux"));
6225 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6227 name
= strtab
+ ivda
.vda_name
;
6228 nn
+= printf ("(%s%-*s",
6230 12 - (int) strlen (name
),
6236 printf ("%*c", 18 - nn
, ' ');
6254 printf (_("\nNo version information found in this file.\n"));
6260 get_symbol_binding (unsigned int binding
)
6262 static char buff
[32];
6266 case STB_LOCAL
: return "LOCAL";
6267 case STB_GLOBAL
: return "GLOBAL";
6268 case STB_WEAK
: return "WEAK";
6270 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6271 sprintf (buff
, _("<processor specific>: %d"), binding
);
6272 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6273 sprintf (buff
, _("<OS specific>: %d"), binding
);
6275 sprintf (buff
, _("<unknown>: %d"), binding
);
6281 get_symbol_type (unsigned int type
)
6283 static char buff
[32];
6287 case STT_NOTYPE
: return "NOTYPE";
6288 case STT_OBJECT
: return "OBJECT";
6289 case STT_FUNC
: return "FUNC";
6290 case STT_SECTION
: return "SECTION";
6291 case STT_FILE
: return "FILE";
6292 case STT_COMMON
: return "COMMON";
6293 case STT_TLS
: return "TLS";
6295 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6297 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6298 return "THUMB_FUNC";
6300 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6303 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6304 return "PARISC_MILLI";
6306 sprintf (buff
, _("<processor specific>: %d"), type
);
6308 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6310 if (elf_header
.e_machine
== EM_PARISC
)
6312 if (type
== STT_HP_OPAQUE
)
6314 if (type
== STT_HP_STUB
)
6318 sprintf (buff
, _("<OS specific>: %d"), type
);
6321 sprintf (buff
, _("<unknown>: %d"), type
);
6327 get_symbol_visibility (unsigned int visibility
)
6331 case STV_DEFAULT
: return "DEFAULT";
6332 case STV_INTERNAL
: return "INTERNAL";
6333 case STV_HIDDEN
: return "HIDDEN";
6334 case STV_PROTECTED
: return "PROTECTED";
6340 get_symbol_index_type (unsigned int type
)
6342 static char buff
[32];
6346 case SHN_UNDEF
: return "UND";
6347 case SHN_ABS
: return "ABS";
6348 case SHN_COMMON
: return "COM";
6350 if (type
== SHN_IA_64_ANSI_COMMON
6351 && elf_header
.e_machine
== EM_IA_64
6352 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6354 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6355 sprintf (buff
, "PRC[0x%04x]", type
);
6356 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6357 sprintf (buff
, "OS [0x%04x]", type
);
6358 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6359 sprintf (buff
, "RSV[0x%04x]", type
);
6361 sprintf (buff
, "%3d", type
);
6369 get_dynamic_data (FILE *file
, unsigned int number
)
6371 unsigned char *e_data
;
6374 e_data
= malloc (number
* 4);
6378 error (_("Out of memory\n"));
6382 if (fread (e_data
, 4, number
, file
) != number
)
6384 error (_("Unable to read in dynamic data\n"));
6388 i_data
= malloc (number
* sizeof (*i_data
));
6392 error (_("Out of memory\n"));
6398 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
6405 /* Dump the symbol table. */
6407 process_symbol_table (FILE *file
)
6409 Elf_Internal_Shdr
*section
;
6410 unsigned char nb
[4];
6411 unsigned char nc
[4];
6414 int *buckets
= NULL
;
6417 if (! do_syms
&& !do_histogram
)
6420 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
6424 (archive_file_offset
6425 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
6426 sizeof nb
+ sizeof nc
)),
6429 error (_("Unable to seek to start of dynamic information"));
6433 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
6435 error (_("Failed to read in number of buckets\n"));
6439 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
6441 error (_("Failed to read in number of chains\n"));
6445 nbuckets
= byte_get (nb
, 4);
6446 nchains
= byte_get (nc
, 4);
6448 buckets
= get_dynamic_data (file
, nbuckets
);
6449 chains
= get_dynamic_data (file
, nchains
);
6451 if (buckets
== NULL
|| chains
== NULL
)
6456 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
6461 printf (_("\nSymbol table for image:\n"));
6463 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6465 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6467 for (hn
= 0; hn
< nbuckets
; hn
++)
6472 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
6474 Elf_Internal_Sym
*psym
;
6476 psym
= dynamic_symbols
+ si
;
6478 printf (" %3d %3d: ", si
, hn
);
6479 print_vma (psym
->st_value
, LONG_HEX
);
6481 print_vma (psym
->st_size
, DEC_5
);
6483 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6484 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6485 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6486 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
6487 if (VALID_DYNAMIC_NAME (psym
->st_name
))
6488 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
6490 printf (" <corrupt: %14ld>", psym
->st_name
);
6495 else if (do_syms
&& !do_using_dynamic
)
6499 for (i
= 0, section
= section_headers
;
6500 i
< elf_header
.e_shnum
;
6505 Elf_Internal_Sym
*symtab
;
6506 Elf_Internal_Sym
*psym
;
6509 if ( section
->sh_type
!= SHT_SYMTAB
6510 && section
->sh_type
!= SHT_DYNSYM
)
6513 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
6514 SECTION_NAME (section
),
6515 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
6517 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6519 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6521 symtab
= GET_ELF_SYMBOLS (file
, section
);
6525 if (section
->sh_link
== elf_header
.e_shstrndx
)
6526 strtab
= string_table
;
6529 Elf_Internal_Shdr
*string_sec
;
6531 string_sec
= SECTION_HEADER (section
->sh_link
);
6533 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
6534 string_sec
->sh_size
, _("string table"));
6537 for (si
= 0, psym
= symtab
;
6538 si
< section
->sh_size
/ section
->sh_entsize
;
6541 printf ("%6d: ", si
);
6542 print_vma (psym
->st_value
, LONG_HEX
);
6544 print_vma (psym
->st_size
, DEC_5
);
6545 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6546 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6547 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6548 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
6549 print_symbol (25, strtab
+ psym
->st_name
);
6551 if (section
->sh_type
== SHT_DYNSYM
&&
6552 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
6554 unsigned char data
[2];
6555 unsigned short vers_data
;
6556 unsigned long offset
;
6560 offset
= offset_from_vma
6561 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6562 sizeof data
+ si
* sizeof (vers_data
));
6564 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
6565 sizeof (data
), _("version data"));
6567 vers_data
= byte_get (data
, 2);
6569 is_nobits
= (SECTION_HEADER (psym
->st_shndx
)->sh_type
6572 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
6574 if ((vers_data
& 0x8000) || vers_data
> 1)
6576 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
6577 && (is_nobits
|| ! check_def
))
6579 Elf_External_Verneed evn
;
6580 Elf_Internal_Verneed ivn
;
6581 Elf_Internal_Vernaux ivna
;
6583 /* We must test both. */
6584 offset
= offset_from_vma
6585 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6590 unsigned long vna_off
;
6592 get_data (&evn
, file
, offset
, sizeof (evn
),
6595 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6596 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6598 vna_off
= offset
+ ivn
.vn_aux
;
6602 Elf_External_Vernaux evna
;
6604 get_data (&evna
, file
, vna_off
,
6606 _("version need aux (3)"));
6608 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6609 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6610 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6612 vna_off
+= ivna
.vna_next
;
6614 while (ivna
.vna_other
!= vers_data
6615 && ivna
.vna_next
!= 0);
6617 if (ivna
.vna_other
== vers_data
)
6620 offset
+= ivn
.vn_next
;
6622 while (ivn
.vn_next
!= 0);
6624 if (ivna
.vna_other
== vers_data
)
6627 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
6630 else if (! is_nobits
)
6631 error (_("bad dynamic symbol"));
6638 if (vers_data
!= 0x8001
6639 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6641 Elf_Internal_Verdef ivd
;
6642 Elf_Internal_Verdaux ivda
;
6643 Elf_External_Verdaux evda
;
6644 unsigned long offset
;
6646 offset
= offset_from_vma
6648 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6649 sizeof (Elf_External_Verdef
));
6653 Elf_External_Verdef evd
;
6655 get_data (&evd
, file
, offset
, sizeof (evd
),
6658 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6659 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6660 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6662 offset
+= ivd
.vd_next
;
6664 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
6665 && ivd
.vd_next
!= 0);
6667 offset
-= ivd
.vd_next
;
6668 offset
+= ivd
.vd_aux
;
6670 get_data (&evda
, file
, offset
, sizeof (evda
),
6671 _("version def aux"));
6673 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6675 if (psym
->st_name
!= ivda
.vda_name
)
6676 printf ((vers_data
& 0x8000)
6678 strtab
+ ivda
.vda_name
);
6688 if (strtab
!= string_table
)
6694 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
6696 if (do_histogram
&& buckets
!= NULL
)
6703 int nzero_counts
= 0;
6706 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
6708 printf (_(" Length Number %% of total Coverage\n"));
6710 lengths
= calloc (nbuckets
, sizeof (int));
6711 if (lengths
== NULL
)
6713 error (_("Out of memory"));
6716 for (hn
= 0; hn
< nbuckets
; ++hn
)
6721 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
6724 if (maxlength
< ++lengths
[hn
])
6729 counts
= calloc (maxlength
+ 1, sizeof (int));
6732 error (_("Out of memory"));
6736 for (hn
= 0; hn
< nbuckets
; ++hn
)
6737 ++counts
[lengths
[hn
]];
6741 printf (" 0 %-10d (%5.1f%%)\n",
6742 counts
[0], (counts
[0] * 100.0) / nbuckets
);
6743 for (si
= 1; si
<= maxlength
; ++si
)
6745 nzero_counts
+= counts
[si
] * si
;
6746 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
6747 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
6748 (nzero_counts
* 100.0) / nsyms
);
6756 if (buckets
!= NULL
)
6766 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
6770 if (dynamic_syminfo
== NULL
6772 /* No syminfo, this is ok. */
6775 /* There better should be a dynamic symbol section. */
6776 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
6780 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
6781 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
6783 printf (_(" Num: Name BoundTo Flags\n"));
6784 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
6786 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
6788 printf ("%4d: ", i
);
6789 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
6790 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
6792 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
6795 switch (dynamic_syminfo
[i
].si_boundto
)
6797 case SYMINFO_BT_SELF
:
6798 fputs ("SELF ", stdout
);
6800 case SYMINFO_BT_PARENT
:
6801 fputs ("PARENT ", stdout
);
6804 if (dynamic_syminfo
[i
].si_boundto
> 0
6805 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
6806 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
6808 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
6812 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
6816 if (flags
& SYMINFO_FLG_DIRECT
)
6818 if (flags
& SYMINFO_FLG_PASSTHRU
)
6819 printf (" PASSTHRU");
6820 if (flags
& SYMINFO_FLG_COPY
)
6822 if (flags
& SYMINFO_FLG_LAZYLOAD
)
6823 printf (" LAZYLOAD");
6831 #ifdef SUPPORT_DISASSEMBLY
6833 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
6835 printf (_("\nAssembly dump of section %s\n"),
6836 SECTION_NAME (section
));
6838 /* XXX -- to be done --- XXX */
6845 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
6847 bfd_size_type bytes
;
6849 unsigned char *data
;
6850 unsigned char *start
;
6852 bytes
= section
->sh_size
;
6854 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
6856 printf (_("\nSection '%s' has no data to dump.\n"),
6857 SECTION_NAME (section
));
6861 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
6863 addr
= section
->sh_addr
;
6865 start
= get_data (NULL
, file
, section
->sh_offset
, bytes
, _("section data"));
6877 lbytes
= (bytes
> 16 ? 16 : bytes
);
6879 printf (" 0x%8.8lx ", (unsigned long) addr
);
6881 switch (elf_header
.e_ident
[EI_DATA
])
6885 for (j
= 15; j
>= 0; j
--)
6888 printf ("%2.2x", data
[j
]);
6898 for (j
= 0; j
< 16; j
++)
6901 printf ("%2.2x", data
[j
]);
6911 for (j
= 0; j
< lbytes
; j
++)
6914 if (k
>= ' ' && k
< 0x7f)
6933 static unsigned long int
6934 read_leb128 (unsigned char *data
, int *length_return
, int sign
)
6936 unsigned long int result
= 0;
6937 unsigned int num_read
= 0;
6938 unsigned int shift
= 0;
6946 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
6951 while (byte
& 0x80);
6953 if (length_return
!= NULL
)
6954 *length_return
= num_read
;
6956 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6957 result
|= -1L << shift
;
6962 typedef struct State_Machine_Registers
6964 unsigned long address
;
6967 unsigned int column
;
6971 /* This variable hold the number of the last entry seen
6972 in the File Table. */
6973 unsigned int last_file_entry
;
6976 static SMR state_machine_regs
;
6979 reset_state_machine (int is_stmt
)
6981 state_machine_regs
.address
= 0;
6982 state_machine_regs
.file
= 1;
6983 state_machine_regs
.line
= 1;
6984 state_machine_regs
.column
= 0;
6985 state_machine_regs
.is_stmt
= is_stmt
;
6986 state_machine_regs
.basic_block
= 0;
6987 state_machine_regs
.end_sequence
= 0;
6988 state_machine_regs
.last_file_entry
= 0;
6991 /* Handled an extend line op. Returns true if this is the end
6995 process_extended_line_op (unsigned char *data
, int is_stmt
, int pointer_size
)
6997 unsigned char op_code
;
7000 unsigned char *name
;
7003 len
= read_leb128 (data
, & bytes_read
, 0);
7008 warn (_("badly formed extended line op encountered!\n"));
7015 printf (_(" Extended opcode %d: "), op_code
);
7019 case DW_LNE_end_sequence
:
7020 printf (_("End of Sequence\n\n"));
7021 reset_state_machine (is_stmt
);
7024 case DW_LNE_set_address
:
7025 adr
= byte_get (data
, pointer_size
);
7026 printf (_("set Address to 0x%lx\n"), adr
);
7027 state_machine_regs
.address
= adr
;
7030 case DW_LNE_define_file
:
7031 printf (_(" define new File Table entry\n"));
7032 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
7034 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
7036 data
+= strlen ((char *) data
) + 1;
7037 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
7039 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
7041 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
7042 printf (_("%s\n\n"), name
);
7046 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
7053 /* Finds section NAME inside FILE and returns a
7054 pointer to it, or NULL upon failure. */
7056 static Elf_Internal_Shdr
*
7057 find_section (const char * name
)
7059 Elf_Internal_Shdr
*sec
;
7062 for (i
= elf_header
.e_shnum
, sec
= section_headers
+ i
- 1;
7064 if (streq (SECTION_NAME (sec
), name
))
7067 if (i
&& sec
&& sec
->sh_size
!= 0)
7073 static const char *debug_str_contents
;
7074 static bfd_vma debug_str_size
;
7077 load_debug_str (FILE *file
)
7079 Elf_Internal_Shdr
*sec
;
7081 /* If it is already loaded, do nothing. */
7082 if (debug_str_contents
!= NULL
)
7085 /* Locate the .debug_str section. */
7086 sec
= find_section (".debug_str");
7090 debug_str_size
= sec
->sh_size
;
7092 debug_str_contents
= get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7093 _("debug_str section data"));
7097 free_debug_str (void)
7099 if (debug_str_contents
== NULL
)
7102 free ((char *) debug_str_contents
);
7103 debug_str_contents
= NULL
;
7108 fetch_indirect_string (unsigned long offset
)
7110 if (debug_str_contents
== NULL
)
7111 return _("<no .debug_str section>");
7113 if (offset
> debug_str_size
)
7114 return _("<offset is too big>");
7116 return debug_str_contents
+ offset
;
7119 static const char *debug_loc_contents
;
7120 static bfd_vma debug_loc_size
;
7123 load_debug_loc (FILE *file
)
7125 Elf_Internal_Shdr
*sec
;
7127 /* If it is already loaded, do nothing. */
7128 if (debug_loc_contents
!= NULL
)
7131 /* Locate the .debug_loc section. */
7132 sec
= find_section (".debug_loc");
7136 debug_loc_size
= sec
->sh_size
;
7138 debug_loc_contents
= get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7139 _("debug_loc section data"));
7143 free_debug_loc (void)
7145 if (debug_loc_contents
== NULL
)
7148 free ((char *) debug_loc_contents
);
7149 debug_loc_contents
= NULL
;
7153 static const char * debug_range_contents
;
7154 static unsigned long debug_range_size
;
7157 load_debug_range (FILE *file
)
7159 Elf_Internal_Shdr
*sec
;
7161 /* If it is already loaded, do nothing. */
7162 if (debug_range_contents
!= NULL
)
7165 /* Locate the .debug_str section. */
7166 sec
= find_section (".debug_ranges");
7170 debug_range_size
= sec
->sh_size
;
7172 debug_range_contents
= get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7173 _("debug_range section data"));
7177 free_debug_range (void)
7179 if (debug_range_contents
== NULL
)
7182 free ((char *) debug_range_contents
);
7183 debug_range_contents
= NULL
;
7184 debug_range_size
= 0;
7187 /* Apply addends of RELA relocations. */
7190 debug_apply_rela_addends (FILE *file
,
7191 Elf_Internal_Shdr
*section
,
7193 unsigned char *sec_data
,
7194 unsigned char *start
,
7197 Elf_Internal_Shdr
*relsec
;
7199 if (end
- start
< reloc_size
)
7202 for (relsec
= section_headers
;
7203 relsec
< section_headers
+ elf_header
.e_shnum
;
7206 unsigned long nrelas
;
7207 Elf_Internal_Rela
*rela
, *rp
;
7208 Elf_Internal_Shdr
*symsec
;
7209 Elf_Internal_Sym
*symtab
;
7210 Elf_Internal_Sym
*sym
;
7212 if (relsec
->sh_type
!= SHT_RELA
7213 || SECTION_HEADER (relsec
->sh_info
) != section
7214 || relsec
->sh_size
== 0)
7217 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7221 symsec
= SECTION_HEADER (relsec
->sh_link
);
7222 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7224 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7228 if (rp
->r_offset
>= (bfd_vma
) (start
- sec_data
)
7229 && rp
->r_offset
< (bfd_vma
) (end
- sec_data
) - reloc_size
)
7230 loc
= sec_data
+ rp
->r_offset
;
7236 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7238 if (ELF32_R_SYM (rp
->r_info
) != 0
7239 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7240 /* Relocations against object symbols can happen,
7241 eg when referencing a global array. For an
7242 example of this see the _clz.o binary in libgcc.a. */
7243 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7245 warn (_("%s: skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7246 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7247 SECTION_NAME (section
));
7253 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7255 if (ELF64_R_SYM (rp
->r_info
) != 0
7256 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7257 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7259 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7260 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7261 SECTION_NAME (section
));
7266 byte_put (loc
, rp
->r_addend
, reloc_size
);
7276 /* FIXME: There are better and more efficient ways to handle
7277 these structures. For now though, I just want something that
7278 is simple to implement. */
7279 typedef struct abbrev_attr
7281 unsigned long attribute
;
7283 struct abbrev_attr
*next
;
7287 typedef struct abbrev_entry
7289 unsigned long entry
;
7292 struct abbrev_attr
*first_attr
;
7293 struct abbrev_attr
*last_attr
;
7294 struct abbrev_entry
*next
;
7298 static abbrev_entry
*first_abbrev
= NULL
;
7299 static abbrev_entry
*last_abbrev
= NULL
;
7304 abbrev_entry
*abbrev
;
7306 for (abbrev
= first_abbrev
; abbrev
;)
7308 abbrev_entry
*next
= abbrev
->next
;
7311 for (attr
= abbrev
->first_attr
; attr
;)
7313 abbrev_attr
*next
= attr
->next
;
7323 last_abbrev
= first_abbrev
= NULL
;
7327 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
7329 abbrev_entry
*entry
;
7331 entry
= malloc (sizeof (*entry
));
7337 entry
->entry
= number
;
7339 entry
->children
= children
;
7340 entry
->first_attr
= NULL
;
7341 entry
->last_attr
= NULL
;
7344 if (first_abbrev
== NULL
)
7345 first_abbrev
= entry
;
7347 last_abbrev
->next
= entry
;
7349 last_abbrev
= entry
;
7353 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
7357 attr
= malloc (sizeof (*attr
));
7363 attr
->attribute
= attribute
;
7367 if (last_abbrev
->first_attr
== NULL
)
7368 last_abbrev
->first_attr
= attr
;
7370 last_abbrev
->last_attr
->next
= attr
;
7372 last_abbrev
->last_attr
= attr
;
7375 /* Processes the (partial) contents of a .debug_abbrev section.
7376 Returns NULL if the end of the section was encountered.
7377 Returns the address after the last byte read if the end of
7378 an abbreviation set was found. */
7380 static unsigned char *
7381 process_abbrev_section (unsigned char *start
, unsigned char *end
)
7383 if (first_abbrev
!= NULL
)
7389 unsigned long entry
;
7391 unsigned long attribute
;
7394 entry
= read_leb128 (start
, & bytes_read
, 0);
7395 start
+= bytes_read
;
7397 /* A single zero is supposed to end the section according
7398 to the standard. If there's more, then signal that to
7401 return start
== end
? NULL
: start
;
7403 tag
= read_leb128 (start
, & bytes_read
, 0);
7404 start
+= bytes_read
;
7406 children
= *start
++;
7408 add_abbrev (entry
, tag
, children
);
7414 attribute
= read_leb128 (start
, & bytes_read
, 0);
7415 start
+= bytes_read
;
7417 form
= read_leb128 (start
, & bytes_read
, 0);
7418 start
+= bytes_read
;
7421 add_abbrev_attr (attribute
, form
);
7423 while (attribute
!= 0);
7430 get_TAG_name (unsigned long tag
)
7434 case DW_TAG_padding
: return "DW_TAG_padding";
7435 case DW_TAG_array_type
: return "DW_TAG_array_type";
7436 case DW_TAG_class_type
: return "DW_TAG_class_type";
7437 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
7438 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
7439 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
7440 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
7441 case DW_TAG_label
: return "DW_TAG_label";
7442 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
7443 case DW_TAG_member
: return "DW_TAG_member";
7444 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
7445 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
7446 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
7447 case DW_TAG_string_type
: return "DW_TAG_string_type";
7448 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
7449 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
7450 case DW_TAG_typedef
: return "DW_TAG_typedef";
7451 case DW_TAG_union_type
: return "DW_TAG_union_type";
7452 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
7453 case DW_TAG_variant
: return "DW_TAG_variant";
7454 case DW_TAG_common_block
: return "DW_TAG_common_block";
7455 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
7456 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
7457 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
7458 case DW_TAG_module
: return "DW_TAG_module";
7459 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
7460 case DW_TAG_set_type
: return "DW_TAG_set_type";
7461 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
7462 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
7463 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
7464 case DW_TAG_base_type
: return "DW_TAG_base_type";
7465 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
7466 case DW_TAG_const_type
: return "DW_TAG_const_type";
7467 case DW_TAG_constant
: return "DW_TAG_constant";
7468 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
7469 case DW_TAG_file_type
: return "DW_TAG_file_type";
7470 case DW_TAG_friend
: return "DW_TAG_friend";
7471 case DW_TAG_namelist
: return "DW_TAG_namelist";
7472 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
7473 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
7474 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
7475 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
7476 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
7477 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
7478 case DW_TAG_try_block
: return "DW_TAG_try_block";
7479 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
7480 case DW_TAG_variable
: return "DW_TAG_variable";
7481 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
7482 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
7483 case DW_TAG_format_label
: return "DW_TAG_format_label";
7484 case DW_TAG_function_template
: return "DW_TAG_function_template";
7485 case DW_TAG_class_template
: return "DW_TAG_class_template";
7486 /* DWARF 2.1 values. */
7487 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
7488 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
7489 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
7490 case DW_TAG_namespace
: return "DW_TAG_namespace";
7491 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
7492 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
7493 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
7494 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
7496 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
7497 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
7498 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
7501 static char buffer
[100];
7503 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
7510 get_FORM_name (unsigned long form
)
7514 case DW_FORM_addr
: return "DW_FORM_addr";
7515 case DW_FORM_block2
: return "DW_FORM_block2";
7516 case DW_FORM_block4
: return "DW_FORM_block4";
7517 case DW_FORM_data2
: return "DW_FORM_data2";
7518 case DW_FORM_data4
: return "DW_FORM_data4";
7519 case DW_FORM_data8
: return "DW_FORM_data8";
7520 case DW_FORM_string
: return "DW_FORM_string";
7521 case DW_FORM_block
: return "DW_FORM_block";
7522 case DW_FORM_block1
: return "DW_FORM_block1";
7523 case DW_FORM_data1
: return "DW_FORM_data1";
7524 case DW_FORM_flag
: return "DW_FORM_flag";
7525 case DW_FORM_sdata
: return "DW_FORM_sdata";
7526 case DW_FORM_strp
: return "DW_FORM_strp";
7527 case DW_FORM_udata
: return "DW_FORM_udata";
7528 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
7529 case DW_FORM_ref1
: return "DW_FORM_ref1";
7530 case DW_FORM_ref2
: return "DW_FORM_ref2";
7531 case DW_FORM_ref4
: return "DW_FORM_ref4";
7532 case DW_FORM_ref8
: return "DW_FORM_ref8";
7533 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
7534 case DW_FORM_indirect
: return "DW_FORM_indirect";
7537 static char buffer
[100];
7539 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
7545 static unsigned char *
7546 display_block (unsigned char *data
, unsigned long length
)
7548 printf (_(" %lu byte block: "), length
);
7551 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
7557 decode_location_expression (unsigned char * data
,
7558 unsigned int pointer_size
,
7559 unsigned long length
,
7560 unsigned long cu_offset
)
7564 unsigned long uvalue
;
7565 unsigned char *end
= data
+ length
;
7566 int need_frame_base
= 0;
7575 printf ("DW_OP_addr: %lx",
7576 (unsigned long) byte_get (data
, pointer_size
));
7577 data
+= pointer_size
;
7580 printf ("DW_OP_deref");
7583 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
7586 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
7589 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
7593 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
7597 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
7601 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
7605 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
7606 (unsigned long) byte_get (data
+ 4, 4));
7610 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
7611 (long) byte_get (data
+ 4, 4));
7615 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
7619 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
7623 printf ("DW_OP_dup");
7626 printf ("DW_OP_drop");
7629 printf ("DW_OP_over");
7632 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
7635 printf ("DW_OP_swap");
7638 printf ("DW_OP_rot");
7641 printf ("DW_OP_xderef");
7644 printf ("DW_OP_abs");
7647 printf ("DW_OP_and");
7650 printf ("DW_OP_div");
7653 printf ("DW_OP_minus");
7656 printf ("DW_OP_mod");
7659 printf ("DW_OP_mul");
7662 printf ("DW_OP_neg");
7665 printf ("DW_OP_not");
7668 printf ("DW_OP_or");
7671 printf ("DW_OP_plus");
7673 case DW_OP_plus_uconst
:
7674 printf ("DW_OP_plus_uconst: %lu",
7675 read_leb128 (data
, &bytes_read
, 0));
7679 printf ("DW_OP_shl");
7682 printf ("DW_OP_shr");
7685 printf ("DW_OP_shra");
7688 printf ("DW_OP_xor");
7691 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
7695 printf ("DW_OP_eq");
7698 printf ("DW_OP_ge");
7701 printf ("DW_OP_gt");
7704 printf ("DW_OP_le");
7707 printf ("DW_OP_lt");
7710 printf ("DW_OP_ne");
7713 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
7749 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
7784 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
7819 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
7820 read_leb128 (data
, &bytes_read
, 1));
7825 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
7829 need_frame_base
= 1;
7830 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
7834 uvalue
= read_leb128 (data
, &bytes_read
, 0);
7836 printf ("DW_OP_bregx: %lu %ld", uvalue
,
7837 read_leb128 (data
, &bytes_read
, 1));
7841 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
7844 case DW_OP_deref_size
:
7845 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
7847 case DW_OP_xderef_size
:
7848 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
7851 printf ("DW_OP_nop");
7854 /* DWARF 3 extensions. */
7855 case DW_OP_push_object_address
:
7856 printf ("DW_OP_push_object_address");
7859 /* XXX: Strictly speaking for 64-bit DWARF3 files
7860 this ought to be an 8-byte wide computation. */
7861 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2) + cu_offset
);
7865 /* XXX: Strictly speaking for 64-bit DWARF3 files
7866 this ought to be an 8-byte wide computation. */
7867 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
7870 case DW_OP_call_ref
:
7871 printf ("DW_OP_call_ref");
7874 /* GNU extensions. */
7875 case DW_OP_GNU_push_tls_address
:
7876 printf ("DW_OP_GNU_push_tls_address");
7880 if (op
>= DW_OP_lo_user
7881 && op
<= DW_OP_hi_user
)
7882 printf (_("(User defined location op)"));
7884 printf (_("(Unknown location op)"));
7885 /* No way to tell where the next op is, so just bail. */
7886 return need_frame_base
;
7889 /* Separate the ops. */
7894 return need_frame_base
;
7897 /* This structure records the information that
7898 we extract from the.debug_info section. */
7901 unsigned int pointer_size
;
7902 unsigned long cu_offset
;
7903 unsigned long base_address
;
7904 /* This is an array of offsets to the location list table. */
7905 unsigned long *loc_offsets
;
7906 int *have_frame_base
;
7907 unsigned int num_loc_offsets
;
7908 unsigned int max_loc_offsets
;
7909 unsigned long *range_lists
;
7910 unsigned int num_range_lists
;
7911 unsigned int max_range_lists
;
7915 static debug_info
* debug_information
= NULL
;
7916 static unsigned int num_debug_info_entries
= 0;
7917 static unsigned int last_pointer_size
= 0;
7918 static int warned_about_missing_comp_units
= FALSE
;
7920 static unsigned char *
7921 read_and_display_attr_value (unsigned long attribute
,
7923 unsigned char *data
,
7924 unsigned long cu_offset
,
7925 unsigned long pointer_size
,
7926 unsigned long offset_size
,
7928 debug_info
*debug_info_p
,
7931 unsigned long uvalue
= 0;
7932 unsigned char *block_start
= NULL
;
7940 case DW_FORM_ref_addr
:
7941 if (dwarf_version
== 2)
7943 uvalue
= byte_get (data
, pointer_size
);
7944 data
+= pointer_size
;
7946 else if (dwarf_version
== 3)
7948 uvalue
= byte_get (data
, offset_size
);
7949 data
+= offset_size
;
7953 error (_("Internal error: DWARF version is not 2 or 3.\n"));
7958 uvalue
= byte_get (data
, pointer_size
);
7959 data
+= pointer_size
;
7963 uvalue
= byte_get (data
, offset_size
);
7964 data
+= offset_size
;
7970 uvalue
= byte_get (data
++, 1);
7975 uvalue
= byte_get (data
, 2);
7981 uvalue
= byte_get (data
, 4);
7986 uvalue
= read_leb128 (data
, & bytes_read
, 1);
7990 case DW_FORM_ref_udata
:
7992 uvalue
= read_leb128 (data
, & bytes_read
, 0);
7996 case DW_FORM_indirect
:
7997 form
= read_leb128 (data
, & bytes_read
, 0);
8000 printf (" %s", get_FORM_name (form
));
8001 return read_and_display_attr_value (attribute
, form
, data
,
8002 cu_offset
, pointer_size
,
8003 offset_size
, dwarf_version
,
8004 debug_info_p
, do_loc
);
8009 case DW_FORM_ref_addr
:
8011 printf (" <#%lx>", uvalue
);
8017 case DW_FORM_ref_udata
:
8019 printf (" <%lx>", uvalue
+ cu_offset
);
8025 printf (" %#lx", uvalue
);
8034 printf (" %ld", uvalue
);
8041 uvalue
= byte_get (data
, 4);
8042 printf (" %lx", uvalue
);
8043 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
8045 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
8046 && num_debug_info_entries
== 0)
8048 if (sizeof (uvalue
) == 8)
8049 uvalue
= byte_get (data
, 8);
8051 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
8056 case DW_FORM_string
:
8058 printf (" %s", data
);
8059 data
+= strlen ((char *) data
) + 1;
8063 uvalue
= read_leb128 (data
, & bytes_read
, 0);
8064 block_start
= data
+ bytes_read
;
8066 data
= block_start
+ uvalue
;
8068 data
= display_block (block_start
, uvalue
);
8071 case DW_FORM_block1
:
8072 uvalue
= byte_get (data
, 1);
8073 block_start
= data
+ 1;
8075 data
= block_start
+ uvalue
;
8077 data
= display_block (block_start
, uvalue
);
8080 case DW_FORM_block2
:
8081 uvalue
= byte_get (data
, 2);
8082 block_start
= data
+ 2;
8084 data
= block_start
+ uvalue
;
8086 data
= display_block (block_start
, uvalue
);
8089 case DW_FORM_block4
:
8090 uvalue
= byte_get (data
, 4);
8091 block_start
= data
+ 4;
8093 data
= block_start
+ uvalue
;
8095 data
= display_block (block_start
, uvalue
);
8100 printf (_(" (indirect string, offset: 0x%lx): %s"),
8101 uvalue
, fetch_indirect_string (uvalue
));
8104 case DW_FORM_indirect
:
8105 /* Handled above. */
8109 warn (_("Unrecognized form: %d\n"), form
);
8113 /* For some attributes we can display further information. */
8114 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
8115 && num_debug_info_entries
== 0)
8119 case DW_AT_frame_base
:
8120 have_frame_base
= 1;
8121 case DW_AT_location
:
8122 case DW_AT_data_member_location
:
8123 case DW_AT_vtable_elem_location
:
8124 case DW_AT_allocated
:
8125 case DW_AT_associated
:
8126 case DW_AT_data_location
:
8128 case DW_AT_upper_bound
:
8129 case DW_AT_lower_bound
:
8130 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
8132 /* Process location list. */
8133 unsigned int max
= debug_info_p
->max_loc_offsets
;
8134 unsigned int num
= debug_info_p
->num_loc_offsets
;
8136 if (max
== 0 || num
>= max
)
8139 debug_info_p
->loc_offsets
8140 = xrealloc (debug_info_p
->loc_offsets
,
8141 max
* sizeof (*debug_info_p
->loc_offsets
));
8142 debug_info_p
->have_frame_base
8143 = xrealloc (debug_info_p
->have_frame_base
,
8144 max
* sizeof (*debug_info_p
->have_frame_base
));
8145 debug_info_p
->max_loc_offsets
= max
;
8147 debug_info_p
->loc_offsets
[num
] = uvalue
;
8148 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
8149 debug_info_p
->num_loc_offsets
++;
8154 if (need_base_address
)
8155 debug_info_p
->base_address
= uvalue
;
8159 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
8161 /* Process range list. */
8162 unsigned int max
= debug_info_p
->max_range_lists
;
8163 unsigned int num
= debug_info_p
->num_range_lists
;
8165 if (max
== 0 || num
>= max
)
8168 debug_info_p
->range_lists
8169 = xrealloc (debug_info_p
->range_lists
,
8170 max
* sizeof (*debug_info_p
->range_lists
));
8171 debug_info_p
->max_range_lists
= max
;
8173 debug_info_p
->range_lists
[num
] = uvalue
;
8174 debug_info_p
->num_range_lists
++;
8193 case DW_INL_not_inlined
:
8194 printf (_("(not inlined)"));
8196 case DW_INL_inlined
:
8197 printf (_("(inlined)"));
8199 case DW_INL_declared_not_inlined
:
8200 printf (_("(declared as inline but ignored)"));
8202 case DW_INL_declared_inlined
:
8203 printf (_("(declared as inline and inlined)"));
8206 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
8211 case DW_AT_language
:
8214 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
8215 case DW_LANG_C89
: printf ("(ANSI C)"); break;
8216 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
8217 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
8218 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
8219 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
8220 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
8221 case DW_LANG_Ada83
: printf ("(Ada)"); break;
8222 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
8223 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
8224 /* DWARF 2.1 values. */
8225 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
8226 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
8227 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
8228 /* MIPS extension. */
8229 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
8230 /* UPC extension. */
8231 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
8233 printf ("(Unknown: %lx)", uvalue
);
8238 case DW_AT_encoding
:
8241 case DW_ATE_void
: printf ("(void)"); break;
8242 case DW_ATE_address
: printf ("(machine address)"); break;
8243 case DW_ATE_boolean
: printf ("(boolean)"); break;
8244 case DW_ATE_complex_float
: printf ("(complex float)"); break;
8245 case DW_ATE_float
: printf ("(float)"); break;
8246 case DW_ATE_signed
: printf ("(signed)"); break;
8247 case DW_ATE_signed_char
: printf ("(signed char)"); break;
8248 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
8249 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
8250 /* DWARF 2.1 value. */
8251 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
8253 if (uvalue
>= DW_ATE_lo_user
8254 && uvalue
<= DW_ATE_hi_user
)
8255 printf ("(user defined type)");
8257 printf ("(unknown type)");
8262 case DW_AT_accessibility
:
8265 case DW_ACCESS_public
: printf ("(public)"); break;
8266 case DW_ACCESS_protected
: printf ("(protected)"); break;
8267 case DW_ACCESS_private
: printf ("(private)"); break;
8269 printf ("(unknown accessibility)");
8274 case DW_AT_visibility
:
8277 case DW_VIS_local
: printf ("(local)"); break;
8278 case DW_VIS_exported
: printf ("(exported)"); break;
8279 case DW_VIS_qualified
: printf ("(qualified)"); break;
8280 default: printf ("(unknown visibility)"); break;
8284 case DW_AT_virtuality
:
8287 case DW_VIRTUALITY_none
: printf ("(none)"); break;
8288 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
8289 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
8290 default: printf ("(unknown virtuality)"); break;
8294 case DW_AT_identifier_case
:
8297 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
8298 case DW_ID_up_case
: printf ("(up_case)"); break;
8299 case DW_ID_down_case
: printf ("(down_case)"); break;
8300 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
8301 default: printf ("(unknown case)"); break;
8305 case DW_AT_calling_convention
:
8308 case DW_CC_normal
: printf ("(normal)"); break;
8309 case DW_CC_program
: printf ("(program)"); break;
8310 case DW_CC_nocall
: printf ("(nocall)"); break;
8312 if (uvalue
>= DW_CC_lo_user
8313 && uvalue
<= DW_CC_hi_user
)
8314 printf ("(user defined)");
8316 printf ("(unknown convention)");
8320 case DW_AT_ordering
:
8323 case -1: printf ("(undefined)"); break;
8324 case 0: printf ("(row major)"); break;
8325 case 1: printf ("(column major)"); break;
8329 case DW_AT_frame_base
:
8330 have_frame_base
= 1;
8331 case DW_AT_location
:
8332 case DW_AT_data_member_location
:
8333 case DW_AT_vtable_elem_location
:
8334 case DW_AT_allocated
:
8335 case DW_AT_associated
:
8336 case DW_AT_data_location
:
8338 case DW_AT_upper_bound
:
8339 case DW_AT_lower_bound
:
8342 int need_frame_base
;
8345 need_frame_base
= decode_location_expression (block_start
,
8350 if (need_frame_base
&& !have_frame_base
)
8351 printf (_(" [without DW_AT_frame_base]"));
8353 else if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
8354 printf (_("(location list)"));
8366 get_AT_name (unsigned long attribute
)
8370 case DW_AT_sibling
: return "DW_AT_sibling";
8371 case DW_AT_location
: return "DW_AT_location";
8372 case DW_AT_name
: return "DW_AT_name";
8373 case DW_AT_ordering
: return "DW_AT_ordering";
8374 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
8375 case DW_AT_byte_size
: return "DW_AT_byte_size";
8376 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
8377 case DW_AT_bit_size
: return "DW_AT_bit_size";
8378 case DW_AT_element_list
: return "DW_AT_element_list";
8379 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
8380 case DW_AT_low_pc
: return "DW_AT_low_pc";
8381 case DW_AT_high_pc
: return "DW_AT_high_pc";
8382 case DW_AT_language
: return "DW_AT_language";
8383 case DW_AT_member
: return "DW_AT_member";
8384 case DW_AT_discr
: return "DW_AT_discr";
8385 case DW_AT_discr_value
: return "DW_AT_discr_value";
8386 case DW_AT_visibility
: return "DW_AT_visibility";
8387 case DW_AT_import
: return "DW_AT_import";
8388 case DW_AT_string_length
: return "DW_AT_string_length";
8389 case DW_AT_common_reference
: return "DW_AT_common_reference";
8390 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
8391 case DW_AT_const_value
: return "DW_AT_const_value";
8392 case DW_AT_containing_type
: return "DW_AT_containing_type";
8393 case DW_AT_default_value
: return "DW_AT_default_value";
8394 case DW_AT_inline
: return "DW_AT_inline";
8395 case DW_AT_is_optional
: return "DW_AT_is_optional";
8396 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
8397 case DW_AT_producer
: return "DW_AT_producer";
8398 case DW_AT_prototyped
: return "DW_AT_prototyped";
8399 case DW_AT_return_addr
: return "DW_AT_return_addr";
8400 case DW_AT_start_scope
: return "DW_AT_start_scope";
8401 case DW_AT_stride_size
: return "DW_AT_stride_size";
8402 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
8403 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
8404 case DW_AT_accessibility
: return "DW_AT_accessibility";
8405 case DW_AT_address_class
: return "DW_AT_address_class";
8406 case DW_AT_artificial
: return "DW_AT_artificial";
8407 case DW_AT_base_types
: return "DW_AT_base_types";
8408 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
8409 case DW_AT_count
: return "DW_AT_count";
8410 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
8411 case DW_AT_decl_column
: return "DW_AT_decl_column";
8412 case DW_AT_decl_file
: return "DW_AT_decl_file";
8413 case DW_AT_decl_line
: return "DW_AT_decl_line";
8414 case DW_AT_declaration
: return "DW_AT_declaration";
8415 case DW_AT_discr_list
: return "DW_AT_discr_list";
8416 case DW_AT_encoding
: return "DW_AT_encoding";
8417 case DW_AT_external
: return "DW_AT_external";
8418 case DW_AT_frame_base
: return "DW_AT_frame_base";
8419 case DW_AT_friend
: return "DW_AT_friend";
8420 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
8421 case DW_AT_macro_info
: return "DW_AT_macro_info";
8422 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
8423 case DW_AT_priority
: return "DW_AT_priority";
8424 case DW_AT_segment
: return "DW_AT_segment";
8425 case DW_AT_specification
: return "DW_AT_specification";
8426 case DW_AT_static_link
: return "DW_AT_static_link";
8427 case DW_AT_type
: return "DW_AT_type";
8428 case DW_AT_use_location
: return "DW_AT_use_location";
8429 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
8430 case DW_AT_virtuality
: return "DW_AT_virtuality";
8431 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
8432 /* DWARF 2.1 values. */
8433 case DW_AT_allocated
: return "DW_AT_allocated";
8434 case DW_AT_associated
: return "DW_AT_associated";
8435 case DW_AT_data_location
: return "DW_AT_data_location";
8436 case DW_AT_stride
: return "DW_AT_stride";
8437 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
8438 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
8439 case DW_AT_extension
: return "DW_AT_extension";
8440 case DW_AT_ranges
: return "DW_AT_ranges";
8441 case DW_AT_trampoline
: return "DW_AT_trampoline";
8442 case DW_AT_call_column
: return "DW_AT_call_column";
8443 case DW_AT_call_file
: return "DW_AT_call_file";
8444 case DW_AT_call_line
: return "DW_AT_call_line";
8445 /* SGI/MIPS extensions. */
8446 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
8447 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
8448 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
8449 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
8450 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
8451 case DW_AT_MIPS_software_pipeline_depth
:
8452 return "DW_AT_MIPS_software_pipeline_depth";
8453 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
8454 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
8455 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
8456 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
8457 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
8458 /* GNU extensions. */
8459 case DW_AT_sf_names
: return "DW_AT_sf_names";
8460 case DW_AT_src_info
: return "DW_AT_src_info";
8461 case DW_AT_mac_info
: return "DW_AT_mac_info";
8462 case DW_AT_src_coords
: return "DW_AT_src_coords";
8463 case DW_AT_body_begin
: return "DW_AT_body_begin";
8464 case DW_AT_body_end
: return "DW_AT_body_end";
8465 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
8466 /* UPC extension. */
8467 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
8470 static char buffer
[100];
8472 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
8478 static unsigned char *
8479 read_and_display_attr (unsigned long attribute
,
8481 unsigned char *data
,
8482 unsigned long cu_offset
,
8483 unsigned long pointer_size
,
8484 unsigned long offset_size
,
8486 debug_info
*debug_info_p
,
8490 printf (" %-18s:", get_AT_name (attribute
));
8491 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
8492 pointer_size
, offset_size
,
8493 dwarf_version
, debug_info_p
,
8501 /* Process the contents of a .debug_info section. If do_loc is non-zero
8502 then we are scanning for location lists and we do not want to display
8503 anything to the user. */
8506 process_debug_info (Elf_Internal_Shdr
*section
, unsigned char *start
,
8507 FILE *file
, int do_loc
)
8509 unsigned char *end
= start
+ section
->sh_size
;
8510 unsigned char *section_begin
;
8512 unsigned int num_units
= 0;
8514 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
8515 && num_debug_info_entries
== 0)
8517 unsigned long length
;
8519 /* First scan the section to get the number of comp units. */
8520 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
8523 /* Read the first 4 bytes. For a 32-bit DWARF section, this
8524 will be the length. For a 64-bit DWARF section, it'll be
8525 the escape code 0xffffffff followed by an 8 byte length. */
8526 length
= byte_get (section_begin
, 4);
8528 if (length
== 0xffffffff)
8530 length
= byte_get (section_begin
+ 4, 8);
8531 section_begin
+= length
+ 12;
8534 section_begin
+= length
+ 4;
8539 error (_("No comp units in .debug_info section ?"));
8543 /* Then allocate an array to hold the information. */
8544 debug_information
= malloc (num_units
*
8545 sizeof (* debug_information
));
8546 if (debug_information
== NULL
)
8548 error (_("Not enough memory for a debug info array of %u entries"),
8556 printf (_("The section %s contains:\n\n"),
8557 SECTION_NAME (section
));
8559 load_debug_str (file
);
8560 load_debug_loc (file
);
8561 load_debug_range (file
);
8564 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
8566 DWARF2_Internal_CompUnit compunit
;
8567 unsigned char *hdrptr
;
8568 unsigned char *cu_abbrev_offset_ptr
;
8569 unsigned char *tags
;
8571 unsigned long cu_offset
;
8573 int initial_length_size
;
8577 compunit
.cu_length
= byte_get (hdrptr
, 4);
8580 if (compunit
.cu_length
== 0xffffffff)
8582 compunit
.cu_length
= byte_get (hdrptr
, 8);
8585 initial_length_size
= 12;
8590 initial_length_size
= 4;
8593 compunit
.cu_version
= byte_get (hdrptr
, 2);
8596 cu_offset
= start
- section_begin
;
8597 start
+= compunit
.cu_length
+ initial_length_size
;
8599 if (elf_header
.e_type
== ET_REL
8600 && !debug_apply_rela_addends (file
, section
, offset_size
,
8601 section_begin
, hdrptr
, start
))
8604 cu_abbrev_offset_ptr
= hdrptr
;
8605 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
8606 hdrptr
+= offset_size
;
8608 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
8610 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
8611 && num_debug_info_entries
== 0)
8613 debug_information
[unit
].cu_offset
= cu_offset
;
8614 debug_information
[unit
].pointer_size
8615 = compunit
.cu_pointer_size
;
8616 debug_information
[unit
].base_address
= 0;
8617 debug_information
[unit
].loc_offsets
= NULL
;
8618 debug_information
[unit
].have_frame_base
= NULL
;
8619 debug_information
[unit
].max_loc_offsets
= 0;
8620 debug_information
[unit
].num_loc_offsets
= 0;
8621 debug_information
[unit
].range_lists
= NULL
;
8622 debug_information
[unit
].max_range_lists
= 0;
8623 debug_information
[unit
].num_range_lists
= 0;
8630 printf (_(" Compilation Unit @ %lx:\n"), cu_offset
);
8631 printf (_(" Length: %ld\n"), compunit
.cu_length
);
8632 printf (_(" Version: %d\n"), compunit
.cu_version
);
8633 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
8634 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
8637 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
8639 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
8645 /* Read in the abbrevs used by this compilation unit. */
8647 Elf_Internal_Shdr
*sec
;
8648 unsigned char *begin
;
8650 /* Locate the .debug_abbrev section and process it. */
8651 sec
= find_section (".debug_abbrev");
8654 warn (_("Unable to locate .debug_abbrev section!\n"));
8658 begin
= get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
8659 _("debug_abbrev section data"));
8663 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
8664 begin
+ sec
->sh_size
);
8670 while (tags
< start
)
8673 unsigned long abbrev_number
;
8674 abbrev_entry
*entry
;
8677 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
8680 /* A null DIE marks the end of a list of children. */
8681 if (abbrev_number
== 0)
8687 /* Scan through the abbreviation list until we reach the
8689 for (entry
= first_abbrev
;
8690 entry
&& entry
->entry
!= abbrev_number
;
8691 entry
= entry
->next
)
8696 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8702 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8704 (unsigned long) (tags
- section_begin
8707 get_TAG_name (entry
->tag
));
8712 need_base_address
= 0;
8714 case DW_TAG_compile_unit
:
8715 need_base_address
= 1;
8717 case DW_TAG_entry_point
:
8718 case DW_TAG_inlined_subroutine
:
8719 case DW_TAG_subprogram
:
8720 need_base_address
= 0;
8721 /* Assuming that there is no DW_AT_frame_base. */
8722 have_frame_base
= 0;
8726 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
8727 tags
= read_and_display_attr (attr
->attribute
,
8730 compunit
.cu_pointer_size
,
8732 compunit
.cu_version
,
8733 &debug_information
[unit
],
8736 if (entry
->children
)
8741 /* Set num_debug_info_entries here so that it can be used to check if
8742 we need to proecess .debug_loc and .debug_ranges sections. */
8743 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
8744 && num_debug_info_entries
== 0)
8745 num_debug_info_entries
= num_units
;
8749 free_debug_range ();
8759 /* Retrieve the pointer size associated with the given compilation unit.
8760 Optionally the offset of this unit into the .debug_info section is
8761 also retutned. If there is no .debug_info section then an error
8762 message is issued and 0 is returned. If the requested comp unit has
8763 not been defined in the .debug_info section then a warning message
8764 is issued and the last know pointer size is returned. This message
8765 is only issued once per section dumped per file dumped. */
8768 get_pointer_size_and_offset_of_comp_unit (unsigned int comp_unit
,
8769 const char * section_name
,
8770 unsigned long * offset_return
)
8772 unsigned long offset
= 0;
8774 if (num_debug_info_entries
== 0)
8775 error (_("%s section needs a populated .debug_info section\n"),
8778 else if (comp_unit
>= num_debug_info_entries
)
8780 if (!warned_about_missing_comp_units
)
8782 warn (_("%s section has more comp units than .debug_info section\n"),
8784 warn (_("assuming that the pointer size is %d, from the last comp unit in .debug_info\n\n"),
8786 warned_about_missing_comp_units
= TRUE
;
8791 last_pointer_size
= debug_information
[comp_unit
].pointer_size
;
8792 offset
= debug_information
[comp_unit
].cu_offset
;
8795 if (offset_return
!= NULL
)
8796 * offset_return
= offset
;
8798 return last_pointer_size
;
8801 /* Locate and scan the .debug_info section in the file and record the pointer
8802 sizes and offsets for the compilation units in it. Usually an executable
8803 will have just one pointer size, but this is not guaranteed, and so we try
8804 not to make any assumptions. Returns zero upon failure, or the number of
8805 compilation units upon success. */
8808 get_debug_info (FILE * file
)
8810 Elf_Internal_Shdr
* section
;
8811 unsigned char * start
;
8814 /* Reset the last pointer size so that we can issue correct error
8815 messages if we are displaying the contents of more than one section. */
8816 last_pointer_size
= 0;
8817 warned_about_missing_comp_units
= FALSE
;
8819 /* If we already have the information there is nothing else to do. */
8820 if (num_debug_info_entries
> 0)
8821 return num_debug_info_entries
;
8823 section
= find_section (".debug_info");
8824 if (section
== NULL
)
8827 start
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
8828 _("extracting information from .debug_info section"));
8832 ret
= process_debug_info (section
, start
, file
, 1);
8835 return ret
? num_debug_info_entries
: 0;
8839 display_debug_lines (Elf_Internal_Shdr
*section
,
8840 unsigned char *start
, FILE *file
)
8842 unsigned char *data
= start
;
8843 unsigned char *end
= start
+ section
->sh_size
;
8844 unsigned int comp_unit
= 0;
8846 printf (_("\nDump of debug contents of section %s:\n\n"),
8847 SECTION_NAME (section
));
8849 get_debug_info (file
);
8853 DWARF2_Internal_LineInfo info
;
8854 unsigned char *standard_opcodes
;
8855 unsigned char *end_of_sequence
;
8856 unsigned char *hdrptr
;
8857 unsigned int pointer_size
;
8858 int initial_length_size
;
8864 /* Check the length of the block. */
8865 info
.li_length
= byte_get (hdrptr
, 4);
8868 if (info
.li_length
== 0xffffffff)
8870 /* This section is 64-bit DWARF 3. */
8871 info
.li_length
= byte_get (hdrptr
, 8);
8874 initial_length_size
= 12;
8879 initial_length_size
= 4;
8882 if (info
.li_length
+ initial_length_size
> section
->sh_size
)
8885 (_("The line info appears to be corrupt - the section is too small\n"));
8889 /* Check its version number. */
8890 info
.li_version
= byte_get (hdrptr
, 2);
8892 if (info
.li_version
!= 2 && info
.li_version
!= 3)
8894 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
8898 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
8899 hdrptr
+= offset_size
;
8900 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
8902 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
8904 info
.li_line_base
= byte_get (hdrptr
, 1);
8906 info
.li_line_range
= byte_get (hdrptr
, 1);
8908 info
.li_opcode_base
= byte_get (hdrptr
, 1);
8911 /* Sign extend the line base field. */
8912 info
.li_line_base
<<= 24;
8913 info
.li_line_base
>>= 24;
8915 /* Get the pointer size from the comp unit associated
8916 with this block of line number information. */
8917 pointer_size
= get_pointer_size_and_offset_of_comp_unit
8918 (comp_unit
, ".debug_lines", NULL
);
8921 printf (_(" Length: %ld\n"), info
.li_length
);
8922 printf (_(" DWARF Version: %d\n"), info
.li_version
);
8923 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
8924 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
8925 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
8926 printf (_(" Line Base: %d\n"), info
.li_line_base
);
8927 printf (_(" Line Range: %d\n"), info
.li_line_range
);
8928 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
8929 printf (_(" (Pointer size: %u)\n"), pointer_size
);
8931 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
8933 reset_state_machine (info
.li_default_is_stmt
);
8935 /* Display the contents of the Opcodes table. */
8936 standard_opcodes
= hdrptr
;
8938 printf (_("\n Opcodes:\n"));
8940 for (i
= 1; i
< info
.li_opcode_base
; i
++)
8941 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
8943 /* Display the contents of the Directory table. */
8944 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
8947 printf (_("\n The Directory Table is empty.\n"));
8950 printf (_("\n The Directory Table:\n"));
8954 printf (_(" %s\n"), data
);
8956 data
+= strlen ((char *) data
) + 1;
8960 /* Skip the NUL at the end of the table. */
8963 /* Display the contents of the File Name table. */
8965 printf (_("\n The File Name Table is empty.\n"));
8968 printf (_("\n The File Name Table:\n"));
8969 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
8973 unsigned char *name
;
8976 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
8979 data
+= strlen ((char *) data
) + 1;
8981 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
8983 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
8985 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
8987 printf (_("%s\n"), name
);
8991 /* Skip the NUL at the end of the table. */
8994 /* Now display the statements. */
8995 printf (_("\n Line Number Statements:\n"));
8997 while (data
< end_of_sequence
)
8999 unsigned char op_code
;
9005 if (op_code
>= info
.li_opcode_base
)
9007 op_code
-= info
.li_opcode_base
;
9008 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
9009 state_machine_regs
.address
+= adv
;
9010 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
9011 op_code
, adv
, state_machine_regs
.address
);
9012 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
9013 state_machine_regs
.line
+= adv
;
9014 printf (_(" and Line by %d to %d\n"),
9015 adv
, state_machine_regs
.line
);
9017 else switch (op_code
)
9019 case DW_LNS_extended_op
:
9020 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
9025 printf (_(" Copy\n"));
9028 case DW_LNS_advance_pc
:
9029 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
9031 state_machine_regs
.address
+= adv
;
9032 printf (_(" Advance PC by %d to %lx\n"), adv
,
9033 state_machine_regs
.address
);
9036 case DW_LNS_advance_line
:
9037 adv
= read_leb128 (data
, & bytes_read
, 1);
9039 state_machine_regs
.line
+= adv
;
9040 printf (_(" Advance Line by %d to %d\n"), adv
,
9041 state_machine_regs
.line
);
9044 case DW_LNS_set_file
:
9045 adv
= read_leb128 (data
, & bytes_read
, 0);
9047 printf (_(" Set File Name to entry %d in the File Name Table\n"),
9049 state_machine_regs
.file
= adv
;
9052 case DW_LNS_set_column
:
9053 adv
= read_leb128 (data
, & bytes_read
, 0);
9055 printf (_(" Set column to %d\n"), adv
);
9056 state_machine_regs
.column
= adv
;
9059 case DW_LNS_negate_stmt
:
9060 adv
= state_machine_regs
.is_stmt
;
9062 printf (_(" Set is_stmt to %d\n"), adv
);
9063 state_machine_regs
.is_stmt
= adv
;
9066 case DW_LNS_set_basic_block
:
9067 printf (_(" Set basic block\n"));
9068 state_machine_regs
.basic_block
= 1;
9071 case DW_LNS_const_add_pc
:
9072 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
9073 * info
.li_min_insn_length
);
9074 state_machine_regs
.address
+= adv
;
9075 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
9076 state_machine_regs
.address
);
9079 case DW_LNS_fixed_advance_pc
:
9080 adv
= byte_get (data
, 2);
9082 state_machine_regs
.address
+= adv
;
9083 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
9084 adv
, state_machine_regs
.address
);
9087 case DW_LNS_set_prologue_end
:
9088 printf (_(" Set prologue_end to true\n"));
9091 case DW_LNS_set_epilogue_begin
:
9092 printf (_(" Set epilogue_begin to true\n"));
9095 case DW_LNS_set_isa
:
9096 adv
= read_leb128 (data
, & bytes_read
, 0);
9098 printf (_(" Set ISA to %d\n"), adv
);
9102 printf (_(" Unknown opcode %d with operands: "), op_code
);
9104 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
9106 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
9107 i
== 1 ? "" : ", ");
9121 display_debug_pubnames (Elf_Internal_Shdr
*section
,
9122 unsigned char *start
,
9123 FILE *file ATTRIBUTE_UNUSED
)
9125 DWARF2_Internal_PubNames pubnames
;
9128 end
= start
+ section
->sh_size
;
9130 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
9134 unsigned char *data
;
9135 unsigned long offset
;
9136 int offset_size
, initial_length_size
;
9140 pubnames
.pn_length
= byte_get (data
, 4);
9142 if (pubnames
.pn_length
== 0xffffffff)
9144 pubnames
.pn_length
= byte_get (data
, 8);
9147 initial_length_size
= 12;
9152 initial_length_size
= 4;
9155 pubnames
.pn_version
= byte_get (data
, 2);
9157 pubnames
.pn_offset
= byte_get (data
, offset_size
);
9158 data
+= offset_size
;
9159 pubnames
.pn_size
= byte_get (data
, offset_size
);
9160 data
+= offset_size
;
9162 start
+= pubnames
.pn_length
+ initial_length_size
;
9164 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
9166 static int warned
= 0;
9170 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
9177 printf (_(" Length: %ld\n"),
9178 pubnames
.pn_length
);
9179 printf (_(" Version: %d\n"),
9180 pubnames
.pn_version
);
9181 printf (_(" Offset into .debug_info section: %ld\n"),
9182 pubnames
.pn_offset
);
9183 printf (_(" Size of area in .debug_info section: %ld\n"),
9186 printf (_("\n Offset\tName\n"));
9190 offset
= byte_get (data
, offset_size
);
9194 data
+= offset_size
;
9195 printf (" %-6ld\t\t%s\n", offset
, data
);
9196 data
+= strlen ((char *) data
) + 1;
9199 while (offset
!= 0);
9207 display_debug_macinfo (Elf_Internal_Shdr
*section
,
9208 unsigned char *start
,
9209 FILE *file ATTRIBUTE_UNUSED
)
9211 unsigned char *end
= start
+ section
->sh_size
;
9212 unsigned char *curr
= start
;
9213 unsigned int bytes_read
;
9214 enum dwarf_macinfo_record_type op
;
9216 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
9220 unsigned int lineno
;
9228 case DW_MACINFO_start_file
:
9230 unsigned int filenum
;
9232 lineno
= read_leb128 (curr
, & bytes_read
, 0);
9234 filenum
= read_leb128 (curr
, & bytes_read
, 0);
9237 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
9242 case DW_MACINFO_end_file
:
9243 printf (_(" DW_MACINFO_end_file\n"));
9246 case DW_MACINFO_define
:
9247 lineno
= read_leb128 (curr
, & bytes_read
, 0);
9250 curr
+= strlen (string
) + 1;
9251 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
9255 case DW_MACINFO_undef
:
9256 lineno
= read_leb128 (curr
, & bytes_read
, 0);
9259 curr
+= strlen (string
) + 1;
9260 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
9264 case DW_MACINFO_vendor_ext
:
9266 unsigned int constant
;
9268 constant
= read_leb128 (curr
, & bytes_read
, 0);
9271 curr
+= strlen (string
) + 1;
9272 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
9284 display_debug_abbrev (Elf_Internal_Shdr
*section
,
9285 unsigned char *start
,
9286 FILE *file ATTRIBUTE_UNUSED
)
9288 abbrev_entry
*entry
;
9289 unsigned char *end
= start
+ section
->sh_size
;
9291 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
9295 start
= process_abbrev_section (start
, end
);
9297 if (first_abbrev
== NULL
)
9300 printf (_(" Number TAG\n"));
9302 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
9306 printf (_(" %ld %s [%s]\n"),
9308 get_TAG_name (entry
->tag
),
9309 entry
->children
? _("has children") : _("no children"));
9311 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
9312 printf (_(" %-18s %s\n"),
9313 get_AT_name (attr
->attribute
),
9314 get_FORM_name (attr
->form
));
9327 display_debug_loc (Elf_Internal_Shdr
*section
,
9328 unsigned char *start
, FILE *file
)
9330 unsigned char *section_end
;
9331 unsigned long bytes
;
9332 unsigned char *section_begin
= start
;
9333 unsigned int num_loc_list
= 0;
9334 unsigned long last_offset
= 0;
9335 unsigned int first
= 0;
9338 int seen_first_offset
= 0;
9339 int use_debug_info
= 1;
9340 unsigned char *next
;
9342 bytes
= section
->sh_size
;
9343 section_end
= start
+ bytes
;
9347 printf (_("\nThe .debug_loc section is empty.\n"));
9351 get_debug_info (file
);
9353 /* Check the order of location list in .debug_info section. If
9354 offsets of location lists are in the ascending order, we can
9355 use `debug_information' directly. */
9356 for (i
= 0; i
< num_debug_info_entries
; i
++)
9360 num
= debug_information
[i
].num_loc_offsets
;
9361 num_loc_list
+= num
;
9363 /* Check if we can use `debug_information' directly. */
9364 if (use_debug_info
&& num
!= 0)
9366 if (!seen_first_offset
)
9368 /* This is the first location list. */
9369 last_offset
= debug_information
[i
].loc_offsets
[0];
9371 seen_first_offset
= 1;
9377 for (; j
< num
; j
++)
9380 debug_information
[i
].loc_offsets
[j
])
9385 last_offset
= debug_information
[i
].loc_offsets
[j
];
9390 if (!use_debug_info
)
9391 /* FIXME: Should we handle this case? */
9392 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
9394 if (!seen_first_offset
)
9395 error (_("No location lists in .debug_info section!\n"));
9397 if (debug_information
[first
].loc_offsets
[0] != 0)
9398 warn (_("Location lists in .debug_loc section start at 0x%lx\n"),
9399 debug_information
[first
].loc_offsets
[0]);
9401 printf (_("Contents of the .debug_loc section:\n\n"));
9402 printf (_(" Offset Begin End Expression\n"));
9404 seen_first_offset
= 0;
9405 for (i
= first
; i
< num_debug_info_entries
; i
++)
9407 unsigned long begin
;
9409 unsigned short length
;
9410 unsigned long offset
;
9411 unsigned int pointer_size
;
9412 unsigned long cu_offset
;
9413 unsigned long base_address
;
9414 int need_frame_base
;
9417 pointer_size
= debug_information
[i
].pointer_size
;
9418 cu_offset
= debug_information
[i
].cu_offset
;
9420 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
9422 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
9423 offset
= debug_information
[i
].loc_offsets
[j
];
9424 next
= section_begin
+ offset
;
9425 base_address
= debug_information
[i
].base_address
;
9427 if (!seen_first_offset
)
9428 seen_first_offset
= 1;
9432 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
9433 start
- section_begin
, next
- section_begin
);
9434 else if (start
> next
)
9435 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
9436 start
- section_begin
, next
- section_begin
);
9442 begin
= byte_get (start
, pointer_size
);
9443 start
+= pointer_size
;
9444 end
= byte_get (start
, pointer_size
);
9445 start
+= pointer_size
;
9447 if (begin
== 0 && end
== 0)
9450 /* Check base address specifiers. */
9451 if (begin
== -1UL && end
!= -1UL)
9454 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
9455 offset
, begin
, end
);
9459 length
= byte_get (start
, 2);
9462 printf (" %8.8lx %8.8lx %8.8lx (",
9463 offset
, begin
+ base_address
, end
+ base_address
);
9464 need_frame_base
= decode_location_expression (start
,
9470 if (need_frame_base
&& !has_frame_base
)
9471 printf (_(" [without DW_AT_frame_base]"));
9474 fputs (_(" (start == end)"), stdout
);
9475 else if (begin
> end
)
9476 fputs (_(" (start > end)"), stdout
);
9483 fputs (_(" <End of list>\n"), stdout
);
9490 display_debug_str (Elf_Internal_Shdr
*section
,
9491 unsigned char *start
,
9492 FILE *file ATTRIBUTE_UNUSED
)
9494 unsigned long bytes
;
9497 addr
= section
->sh_addr
;
9498 bytes
= section
->sh_size
;
9502 printf (_("\nThe .debug_str section is empty.\n"));
9506 printf (_("Contents of the .debug_str section:\n\n"));
9514 lbytes
= (bytes
> 16 ? 16 : bytes
);
9516 printf (" 0x%8.8lx ", (unsigned long) addr
);
9518 for (j
= 0; j
< 16; j
++)
9521 printf ("%2.2x", start
[j
]);
9529 for (j
= 0; j
< lbytes
; j
++)
9532 if (k
>= ' ' && k
< 0x80)
9552 display_debug_info (Elf_Internal_Shdr
* section
,
9553 unsigned char * start
, FILE * file
)
9555 return process_debug_info (section
, start
, file
, 0);
9560 display_debug_aranges (Elf_Internal_Shdr
*section
,
9561 unsigned char *start
,
9562 FILE *file ATTRIBUTE_UNUSED
)
9564 unsigned char *end
= start
+ section
->sh_size
;
9566 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
9570 unsigned char *hdrptr
;
9571 DWARF2_Internal_ARange arange
;
9572 unsigned char *ranges
;
9573 unsigned long length
;
9574 unsigned long address
;
9577 int initial_length_size
;
9581 arange
.ar_length
= byte_get (hdrptr
, 4);
9584 if (arange
.ar_length
== 0xffffffff)
9586 arange
.ar_length
= byte_get (hdrptr
, 8);
9589 initial_length_size
= 12;
9594 initial_length_size
= 4;
9597 arange
.ar_version
= byte_get (hdrptr
, 2);
9600 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
9601 hdrptr
+= offset_size
;
9603 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
9606 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
9609 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
9611 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
9615 printf (_(" Length: %ld\n"), arange
.ar_length
);
9616 printf (_(" Version: %d\n"), arange
.ar_version
);
9617 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
9618 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
9619 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
9621 printf (_("\n Address Length\n"));
9625 /* Must pad to an alignment boundary that is twice the pointer size. */
9626 excess
= (hdrptr
- start
) % (2 * arange
.ar_pointer_size
);
9628 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
9632 address
= byte_get (ranges
, arange
.ar_pointer_size
);
9634 ranges
+= arange
.ar_pointer_size
;
9636 length
= byte_get (ranges
, arange
.ar_pointer_size
);
9638 ranges
+= arange
.ar_pointer_size
;
9640 /* A pair of zeros marks the end of the list. */
9641 if (address
== 0 && length
== 0)
9644 printf (" %8.8lx %lu\n", address
, length
);
9647 start
+= arange
.ar_length
+ initial_length_size
;
9656 display_debug_ranges (Elf_Internal_Shdr
*section
,
9657 unsigned char *start
,
9658 FILE *file ATTRIBUTE_UNUSED
)
9660 unsigned char *section_end
;
9661 unsigned long bytes
;
9662 unsigned char *section_begin
= start
;
9663 unsigned int num_range_list
= 0;
9664 unsigned long last_offset
= 0;
9665 unsigned int first
= 0;
9668 int seen_first_offset
= 0;
9669 int use_debug_info
= 1;
9670 unsigned char *next
;
9672 bytes
= section
->sh_size
;
9673 section_end
= start
+ bytes
;
9677 printf (_("\nThe .debug_ranges section is empty.\n"));
9681 get_debug_info (file
);
9683 /* Check the order of range list in .debug_info section. If
9684 offsets of range lists are in the ascending order, we can
9685 use `debug_information' directly. */
9686 for (i
= 0; i
< num_debug_info_entries
; i
++)
9690 num
= debug_information
[i
].num_range_lists
;
9691 num_range_list
+= num
;
9693 /* Check if we can use `debug_information' directly. */
9694 if (use_debug_info
&& num
!= 0)
9696 if (!seen_first_offset
)
9698 /* This is the first range list. */
9699 last_offset
= debug_information
[i
].range_lists
[0];
9701 seen_first_offset
= 1;
9707 for (; j
< num
; j
++)
9710 debug_information
[i
].range_lists
[j
])
9715 last_offset
= debug_information
[i
].range_lists
[j
];
9720 if (!use_debug_info
)
9721 /* FIXME: Should we handle this case? */
9722 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
9724 if (!seen_first_offset
)
9725 error (_("No range lists in .debug_info section!\n"));
9727 if (debug_information
[first
].range_lists
[0] != 0)
9728 warn (_("Range lists in .debug_ranges section start at 0x%lx\n"),
9729 debug_information
[first
].range_lists
[0]);
9731 printf (_("Contents of the .debug_ranges section:\n\n"));
9732 printf (_(" Offset Begin End\n"));
9734 seen_first_offset
= 0;
9735 for (i
= first
; i
< num_debug_info_entries
; i
++)
9737 unsigned long begin
;
9739 unsigned long offset
;
9740 unsigned int pointer_size
;
9741 unsigned long base_address
;
9743 pointer_size
= debug_information
[i
].pointer_size
;
9745 for (j
= 0; j
< debug_information
[i
].num_range_lists
; j
++)
9747 offset
= debug_information
[i
].range_lists
[j
];
9748 next
= section_begin
+ offset
;
9749 base_address
= debug_information
[i
].base_address
;
9751 if (!seen_first_offset
)
9752 seen_first_offset
= 1;
9756 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_ranges section.\n"),
9757 start
- section_begin
, next
- section_begin
);
9758 else if (start
> next
)
9759 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_ranges section.\n"),
9760 start
- section_begin
, next
- section_begin
);
9766 begin
= byte_get (start
, pointer_size
);
9767 start
+= pointer_size
;
9768 end
= byte_get (start
, pointer_size
);
9769 start
+= pointer_size
;
9771 if (begin
== 0 && end
== 0)
9774 /* Check base address specifiers. */
9775 if (begin
== -1UL && end
!= -1UL)
9778 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
9779 offset
, begin
, end
);
9783 printf (" %8.8lx %8.8lx %8.8lx",
9784 offset
, begin
+ base_address
, end
+ base_address
);
9787 fputs (_(" (start == end)"), stdout
);
9788 else if (begin
> end
)
9789 fputs (_(" (start > end)"), stdout
);
9793 fputs (_(" <End of list>\n"), stdout
);
9800 typedef struct Frame_Chunk
9802 struct Frame_Chunk
*next
;
9803 unsigned char *chunk_start
;
9805 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
9806 short int *col_type
;
9809 unsigned int code_factor
;
9811 unsigned long pc_begin
;
9812 unsigned long pc_range
;
9816 unsigned char fde_encoding
;
9817 unsigned char cfa_exp
;
9821 /* A marker for a col_type that means this column was never referenced
9822 in the frame info. */
9823 #define DW_CFA_unreferenced (-1)
9826 frame_need_space (Frame_Chunk
*fc
, int reg
)
9828 int prev
= fc
->ncols
;
9830 if (reg
< fc
->ncols
)
9833 fc
->ncols
= reg
+ 1;
9834 fc
->col_type
= xrealloc (fc
->col_type
, fc
->ncols
* sizeof (short int));
9835 fc
->col_offset
= xrealloc (fc
->col_offset
, fc
->ncols
* sizeof (int));
9837 while (prev
< fc
->ncols
)
9839 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
9840 fc
->col_offset
[prev
] = 0;
9846 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
9851 if (*max_regs
< fc
->ncols
)
9852 *max_regs
= fc
->ncols
;
9854 if (*need_col_headers
)
9856 *need_col_headers
= 0;
9858 printf (" LOC CFA ");
9860 for (r
= 0; r
< *max_regs
; r
++)
9861 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9866 printf ("r%-4d", r
);
9872 printf ("%08lx ", fc
->pc_begin
);
9874 strcpy (tmp
, "exp");
9876 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
9877 printf ("%-8s ", tmp
);
9879 for (r
= 0; r
< fc
->ncols
; r
++)
9881 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9883 switch (fc
->col_type
[r
])
9885 case DW_CFA_undefined
:
9888 case DW_CFA_same_value
:
9892 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
9894 case DW_CFA_register
:
9895 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
9897 case DW_CFA_expression
:
9898 strcpy (tmp
, "exp");
9901 strcpy (tmp
, "n/a");
9904 printf ("%-5s", tmp
);
9911 size_of_encoded_value (int encoding
)
9913 switch (encoding
& 0x7)
9916 case 0: return is_32bit_elf
? 4 : 8;
9924 get_encoded_value (unsigned char *data
, int encoding
)
9926 int size
= size_of_encoded_value (encoding
);
9927 if (encoding
& DW_EH_PE_signed
)
9928 return byte_get_signed (data
, size
);
9930 return byte_get (data
, size
);
9933 #define GET(N) byte_get (start, N); start += N
9934 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
9935 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
9938 display_debug_frames (Elf_Internal_Shdr
*section
,
9939 unsigned char *start
,
9940 FILE *file ATTRIBUTE_UNUSED
)
9942 unsigned char *end
= start
+ section
->sh_size
;
9943 unsigned char *section_start
= start
;
9944 Frame_Chunk
*chunks
= 0;
9945 Frame_Chunk
*remembered_state
= 0;
9947 int is_eh
= streq (SECTION_NAME (section
), ".eh_frame");
9950 int addr_size
= is_32bit_elf
? 4 : 8;
9952 printf (_("The section %s contains:\n"), SECTION_NAME (section
));
9956 unsigned char *saved_start
;
9957 unsigned char *block_end
;
9958 unsigned long length
;
9959 unsigned long cie_id
;
9962 int need_col_headers
= 1;
9963 unsigned char *augmentation_data
= NULL
;
9964 unsigned long augmentation_data_len
= 0;
9965 int encoded_ptr_size
= addr_size
;
9967 int initial_length_size
;
9969 saved_start
= start
;
9970 length
= byte_get (start
, 4); start
+= 4;
9974 printf ("\n%08lx ZERO terminator\n\n",
9975 (unsigned long)(saved_start
- section_start
));
9979 if (length
== 0xffffffff)
9981 length
= byte_get (start
, 8);
9984 initial_length_size
= 12;
9989 initial_length_size
= 4;
9992 block_end
= saved_start
+ length
+ initial_length_size
;
9993 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
9995 if (elf_header
.e_type
== ET_REL
9996 && !debug_apply_rela_addends (file
, section
, offset_size
,
9997 section_start
, start
, block_end
))
10000 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
10004 fc
= xmalloc (sizeof (Frame_Chunk
));
10005 memset (fc
, 0, sizeof (Frame_Chunk
));
10009 fc
->chunk_start
= saved_start
;
10011 fc
->col_type
= xmalloc (sizeof (short int));
10012 fc
->col_offset
= xmalloc (sizeof (int));
10013 frame_need_space (fc
, max_regs
-1);
10015 version
= *start
++;
10017 fc
->augmentation
= start
;
10018 start
= strchr (start
, '\0') + 1;
10020 if (fc
->augmentation
[0] == 'z')
10022 fc
->code_factor
= LEB ();
10023 fc
->data_factor
= SLEB ();
10032 augmentation_data_len
= LEB ();
10033 augmentation_data
= start
;
10034 start
+= augmentation_data_len
;
10036 else if (streq (fc
->augmentation
, "eh"))
10038 start
+= addr_size
;
10039 fc
->code_factor
= LEB ();
10040 fc
->data_factor
= SLEB ();
10052 fc
->code_factor
= LEB ();
10053 fc
->data_factor
= SLEB ();
10065 if (do_debug_frames_interp
)
10066 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
10067 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
10068 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
10072 printf ("\n%08lx %08lx %08lx CIE\n",
10073 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
10074 printf (" Version: %d\n", version
);
10075 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
10076 printf (" Code alignment factor: %u\n", fc
->code_factor
);
10077 printf (" Data alignment factor: %d\n", fc
->data_factor
);
10078 printf (" Return address column: %d\n", fc
->ra
);
10080 if (augmentation_data_len
)
10083 printf (" Augmentation data: ");
10084 for (i
= 0; i
< augmentation_data_len
; ++i
)
10085 printf (" %02x", augmentation_data
[i
]);
10091 if (augmentation_data_len
)
10093 unsigned char *p
, *q
;
10094 p
= fc
->augmentation
+ 1;
10095 q
= augmentation_data
;
10101 else if (*p
== 'P')
10102 q
+= 1 + size_of_encoded_value (*q
);
10103 else if (*p
== 'R')
10104 fc
->fde_encoding
= *q
++;
10110 if (fc
->fde_encoding
)
10111 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
10114 frame_need_space (fc
, fc
->ra
);
10118 unsigned char *look_for
;
10119 static Frame_Chunk fde_fc
;
10122 memset (fc
, 0, sizeof (Frame_Chunk
));
10124 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
10126 for (cie
= chunks
; cie
; cie
= cie
->next
)
10127 if (cie
->chunk_start
== look_for
)
10132 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
10133 cie_id
, saved_start
);
10136 fc
->col_type
= xmalloc (sizeof (short int));
10137 fc
->col_offset
= xmalloc (sizeof (int));
10138 frame_need_space (fc
, max_regs
- 1);
10140 fc
->augmentation
= "";
10141 fc
->fde_encoding
= 0;
10145 fc
->ncols
= cie
->ncols
;
10146 fc
->col_type
= xmalloc (fc
->ncols
* sizeof (short int));
10147 fc
->col_offset
= xmalloc (fc
->ncols
* sizeof (int));
10148 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
10149 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
10150 fc
->augmentation
= cie
->augmentation
;
10151 fc
->code_factor
= cie
->code_factor
;
10152 fc
->data_factor
= cie
->data_factor
;
10153 fc
->cfa_reg
= cie
->cfa_reg
;
10154 fc
->cfa_offset
= cie
->cfa_offset
;
10156 frame_need_space (fc
, max_regs
-1);
10157 fc
->fde_encoding
= cie
->fde_encoding
;
10160 if (fc
->fde_encoding
)
10161 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
10163 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
10164 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
10165 /* Don't adjust for ET_REL since there's invariably a pcrel
10166 reloc here, which we haven't applied. */
10167 && elf_header
.e_type
!= ET_REL
)
10168 fc
->pc_begin
+= section
->sh_addr
+ (start
- section_start
);
10169 start
+= encoded_ptr_size
;
10170 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
10171 start
+= encoded_ptr_size
;
10173 if (cie
->augmentation
[0] == 'z')
10175 augmentation_data_len
= LEB ();
10176 augmentation_data
= start
;
10177 start
+= augmentation_data_len
;
10180 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
10181 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
10182 (unsigned long)(cie
->chunk_start
- section_start
),
10183 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
10184 if (! do_debug_frames_interp
&& augmentation_data_len
)
10188 printf (" Augmentation data: ");
10189 for (i
= 0; i
< augmentation_data_len
; ++i
)
10190 printf (" %02x", augmentation_data
[i
]);
10196 /* At this point, fc is the current chunk, cie (if any) is set, and
10197 we're about to interpret instructions for the chunk. */
10198 /* ??? At present we need to do this always, since this sizes the
10199 fc->col_type and fc->col_offset arrays, which we write into always.
10200 We should probably split the interpreted and non-interpreted bits
10201 into two different routines, since there's so much that doesn't
10202 really overlap between them. */
10203 if (1 || do_debug_frames_interp
)
10205 /* Start by making a pass over the chunk, allocating storage
10206 and taking note of what registers are used. */
10207 unsigned char *tmp
= start
;
10209 while (start
< block_end
)
10212 unsigned long reg
, tmp
;
10219 /* Warning: if you add any more cases to this switch, be
10220 sure to add them to the corresponding switch below. */
10223 case DW_CFA_advance_loc
:
10225 case DW_CFA_offset
:
10227 frame_need_space (fc
, opa
);
10228 fc
->col_type
[opa
] = DW_CFA_undefined
;
10230 case DW_CFA_restore
:
10231 frame_need_space (fc
, opa
);
10232 fc
->col_type
[opa
] = DW_CFA_undefined
;
10234 case DW_CFA_set_loc
:
10235 start
+= encoded_ptr_size
;
10237 case DW_CFA_advance_loc1
:
10240 case DW_CFA_advance_loc2
:
10243 case DW_CFA_advance_loc4
:
10246 case DW_CFA_offset_extended
:
10247 reg
= LEB (); LEB ();
10248 frame_need_space (fc
, reg
);
10249 fc
->col_type
[reg
] = DW_CFA_undefined
;
10251 case DW_CFA_restore_extended
:
10253 frame_need_space (fc
, reg
);
10254 fc
->col_type
[reg
] = DW_CFA_undefined
;
10256 case DW_CFA_undefined
:
10258 frame_need_space (fc
, reg
);
10259 fc
->col_type
[reg
] = DW_CFA_undefined
;
10261 case DW_CFA_same_value
:
10263 frame_need_space (fc
, reg
);
10264 fc
->col_type
[reg
] = DW_CFA_undefined
;
10266 case DW_CFA_register
:
10267 reg
= LEB (); LEB ();
10268 frame_need_space (fc
, reg
);
10269 fc
->col_type
[reg
] = DW_CFA_undefined
;
10271 case DW_CFA_def_cfa
:
10274 case DW_CFA_def_cfa_register
:
10277 case DW_CFA_def_cfa_offset
:
10280 case DW_CFA_def_cfa_expression
:
10284 case DW_CFA_expression
:
10288 frame_need_space (fc
, reg
);
10289 fc
->col_type
[reg
] = DW_CFA_undefined
;
10291 case DW_CFA_offset_extended_sf
:
10292 reg
= LEB (); SLEB ();
10293 frame_need_space (fc
, reg
);
10294 fc
->col_type
[reg
] = DW_CFA_undefined
;
10296 case DW_CFA_def_cfa_sf
:
10299 case DW_CFA_def_cfa_offset_sf
:
10302 case DW_CFA_MIPS_advance_loc8
:
10305 case DW_CFA_GNU_args_size
:
10308 case DW_CFA_GNU_negative_offset_extended
:
10309 reg
= LEB (); LEB ();
10310 frame_need_space (fc
, reg
);
10311 fc
->col_type
[reg
] = DW_CFA_undefined
;
10320 /* Now we know what registers are used, make a second pass over
10321 the chunk, this time actually printing out the info. */
10323 while (start
< block_end
)
10326 unsigned long ul
, reg
, roffs
;
10335 /* Warning: if you add any more cases to this switch, be
10336 sure to add them to the corresponding switch above. */
10339 case DW_CFA_advance_loc
:
10340 if (do_debug_frames_interp
)
10341 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10343 printf (" DW_CFA_advance_loc: %d to %08lx\n",
10344 opa
* fc
->code_factor
,
10345 fc
->pc_begin
+ opa
* fc
->code_factor
);
10346 fc
->pc_begin
+= opa
* fc
->code_factor
;
10349 case DW_CFA_offset
:
10351 if (! do_debug_frames_interp
)
10352 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
10353 opa
, roffs
* fc
->data_factor
);
10354 fc
->col_type
[opa
] = DW_CFA_offset
;
10355 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
10358 case DW_CFA_restore
:
10359 if (! do_debug_frames_interp
)
10360 printf (" DW_CFA_restore: r%d\n", opa
);
10361 fc
->col_type
[opa
] = cie
->col_type
[opa
];
10362 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
10365 case DW_CFA_set_loc
:
10366 vma
= get_encoded_value (start
, fc
->fde_encoding
);
10367 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
10368 && elf_header
.e_type
!= ET_REL
)
10369 vma
+= section
->sh_addr
+ (start
- section_start
);
10370 start
+= encoded_ptr_size
;
10371 if (do_debug_frames_interp
)
10372 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10374 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
10375 fc
->pc_begin
= vma
;
10378 case DW_CFA_advance_loc1
:
10379 ofs
= byte_get (start
, 1); start
+= 1;
10380 if (do_debug_frames_interp
)
10381 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10383 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
10384 ofs
* fc
->code_factor
,
10385 fc
->pc_begin
+ ofs
* fc
->code_factor
);
10386 fc
->pc_begin
+= ofs
* fc
->code_factor
;
10389 case DW_CFA_advance_loc2
:
10390 ofs
= byte_get (start
, 2); start
+= 2;
10391 if (do_debug_frames_interp
)
10392 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10394 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
10395 ofs
* fc
->code_factor
,
10396 fc
->pc_begin
+ ofs
* fc
->code_factor
);
10397 fc
->pc_begin
+= ofs
* fc
->code_factor
;
10400 case DW_CFA_advance_loc4
:
10401 ofs
= byte_get (start
, 4); start
+= 4;
10402 if (do_debug_frames_interp
)
10403 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10405 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
10406 ofs
* fc
->code_factor
,
10407 fc
->pc_begin
+ ofs
* fc
->code_factor
);
10408 fc
->pc_begin
+= ofs
* fc
->code_factor
;
10411 case DW_CFA_offset_extended
:
10414 if (! do_debug_frames_interp
)
10415 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
10416 reg
, roffs
* fc
->data_factor
);
10417 fc
->col_type
[reg
] = DW_CFA_offset
;
10418 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
10421 case DW_CFA_restore_extended
:
10423 if (! do_debug_frames_interp
)
10424 printf (" DW_CFA_restore_extended: r%ld\n", reg
);
10425 fc
->col_type
[reg
] = cie
->col_type
[reg
];
10426 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
10429 case DW_CFA_undefined
:
10431 if (! do_debug_frames_interp
)
10432 printf (" DW_CFA_undefined: r%ld\n", reg
);
10433 fc
->col_type
[reg
] = DW_CFA_undefined
;
10434 fc
->col_offset
[reg
] = 0;
10437 case DW_CFA_same_value
:
10439 if (! do_debug_frames_interp
)
10440 printf (" DW_CFA_same_value: r%ld\n", reg
);
10441 fc
->col_type
[reg
] = DW_CFA_same_value
;
10442 fc
->col_offset
[reg
] = 0;
10445 case DW_CFA_register
:
10448 if (! do_debug_frames_interp
)
10449 printf (" DW_CFA_register: r%ld in r%ld\n", reg
, roffs
);
10450 fc
->col_type
[reg
] = DW_CFA_register
;
10451 fc
->col_offset
[reg
] = roffs
;
10454 case DW_CFA_remember_state
:
10455 if (! do_debug_frames_interp
)
10456 printf (" DW_CFA_remember_state\n");
10457 rs
= xmalloc (sizeof (Frame_Chunk
));
10458 rs
->ncols
= fc
->ncols
;
10459 rs
->col_type
= xmalloc (rs
->ncols
* sizeof (short int));
10460 rs
->col_offset
= xmalloc (rs
->ncols
* sizeof (int));
10461 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
10462 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
10463 rs
->next
= remembered_state
;
10464 remembered_state
= rs
;
10467 case DW_CFA_restore_state
:
10468 if (! do_debug_frames_interp
)
10469 printf (" DW_CFA_restore_state\n");
10470 rs
= remembered_state
;
10473 remembered_state
= rs
->next
;
10474 frame_need_space (fc
, rs
->ncols
-1);
10475 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
10476 memcpy (fc
->col_offset
, rs
->col_offset
,
10477 rs
->ncols
* sizeof (int));
10478 free (rs
->col_type
);
10479 free (rs
->col_offset
);
10482 else if (do_debug_frames_interp
)
10483 printf ("Mismatched DW_CFA_restore_state\n");
10486 case DW_CFA_def_cfa
:
10487 fc
->cfa_reg
= LEB ();
10488 fc
->cfa_offset
= LEB ();
10490 if (! do_debug_frames_interp
)
10491 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
10492 fc
->cfa_reg
, fc
->cfa_offset
);
10495 case DW_CFA_def_cfa_register
:
10496 fc
->cfa_reg
= LEB ();
10498 if (! do_debug_frames_interp
)
10499 printf (" DW_CFA_def_cfa_reg: r%d\n", fc
->cfa_reg
);
10502 case DW_CFA_def_cfa_offset
:
10503 fc
->cfa_offset
= LEB ();
10504 if (! do_debug_frames_interp
)
10505 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
10509 if (! do_debug_frames_interp
)
10510 printf (" DW_CFA_nop\n");
10513 case DW_CFA_def_cfa_expression
:
10515 if (! do_debug_frames_interp
)
10517 printf (" DW_CFA_def_cfa_expression (");
10518 decode_location_expression (start
, addr_size
, ul
, 0);
10525 case DW_CFA_expression
:
10528 if (! do_debug_frames_interp
)
10530 printf (" DW_CFA_expression: r%ld (", reg
);
10531 decode_location_expression (start
, addr_size
, ul
, 0);
10534 fc
->col_type
[reg
] = DW_CFA_expression
;
10538 case DW_CFA_offset_extended_sf
:
10541 frame_need_space (fc
, reg
);
10542 if (! do_debug_frames_interp
)
10543 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
10544 reg
, l
* fc
->data_factor
);
10545 fc
->col_type
[reg
] = DW_CFA_offset
;
10546 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
10549 case DW_CFA_def_cfa_sf
:
10550 fc
->cfa_reg
= LEB ();
10551 fc
->cfa_offset
= SLEB ();
10553 if (! do_debug_frames_interp
)
10554 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
10555 fc
->cfa_reg
, fc
->cfa_offset
);
10558 case DW_CFA_def_cfa_offset_sf
:
10559 fc
->cfa_offset
= SLEB ();
10560 if (! do_debug_frames_interp
)
10561 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
10564 case DW_CFA_MIPS_advance_loc8
:
10565 ofs
= byte_get (start
, 8); start
+= 8;
10566 if (do_debug_frames_interp
)
10567 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10569 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
10570 ofs
* fc
->code_factor
,
10571 fc
->pc_begin
+ ofs
* fc
->code_factor
);
10572 fc
->pc_begin
+= ofs
* fc
->code_factor
;
10575 case DW_CFA_GNU_window_save
:
10576 if (! do_debug_frames_interp
)
10577 printf (" DW_CFA_GNU_window_save\n");
10580 case DW_CFA_GNU_args_size
:
10582 if (! do_debug_frames_interp
)
10583 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
10586 case DW_CFA_GNU_negative_offset_extended
:
10589 frame_need_space (fc
, reg
);
10590 if (! do_debug_frames_interp
)
10591 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
10592 reg
, l
* fc
->data_factor
);
10593 fc
->col_type
[reg
] = DW_CFA_offset
;
10594 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
10598 warn (_("unsupported or unknown DW_CFA_%d\n"), op
);
10603 if (do_debug_frames_interp
)
10604 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10619 display_debug_not_supported (Elf_Internal_Shdr
*section
,
10620 unsigned char *start ATTRIBUTE_UNUSED
,
10621 FILE *file ATTRIBUTE_UNUSED
)
10623 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10624 SECTION_NAME (section
));
10629 /* A structure containing the name of a debug section
10630 and a pointer to a function that can decode it. */
10633 const char *const name
;
10634 int (*display
) (Elf_Internal_Shdr
*, unsigned char *, FILE *);
10638 { ".debug_abbrev", display_debug_abbrev
},
10639 { ".debug_aranges", display_debug_aranges
},
10640 { ".debug_frame", display_debug_frames
},
10641 { ".debug_info", display_debug_info
},
10642 { ".debug_line", display_debug_lines
},
10643 { ".debug_pubnames", display_debug_pubnames
},
10644 { ".eh_frame", display_debug_frames
},
10645 { ".debug_macinfo", display_debug_macinfo
},
10646 { ".debug_str", display_debug_str
},
10647 { ".debug_loc", display_debug_loc
},
10648 { ".debug_pubtypes", display_debug_pubnames
},
10649 { ".debug_ranges", display_debug_ranges
},
10650 { ".debug_static_func", display_debug_not_supported
},
10651 { ".debug_static_vars", display_debug_not_supported
},
10652 { ".debug_types", display_debug_not_supported
},
10653 { ".debug_weaknames", display_debug_not_supported
}
10657 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
10659 char *name
= SECTION_NAME (section
);
10660 bfd_size_type length
;
10664 length
= section
->sh_size
;
10667 printf (_("\nSection '%s' has no debugging data.\n"), name
);
10671 if (strneq (name
, ".gnu.linkonce.wi.", 17))
10672 name
= ".debug_info";
10674 /* See if we know how to display the contents of this section. */
10675 for (i
= NUM_ELEM (debug_displays
); i
--;)
10676 if (streq (debug_displays
[i
].name
, name
))
10678 unsigned char *start
;
10680 start
= get_data (NULL
, file
, section
->sh_offset
, length
,
10681 _("debug section data"));
10688 result
&= debug_displays
[i
].display (section
, start
, file
);
10691 /* If we loaded in the abbrev section
10692 at some point, we must release it here. */
10700 printf (_("Unrecognized debug section: %s\n"), name
);
10708 process_section_contents (FILE *file
)
10710 Elf_Internal_Shdr
*section
;
10716 for (i
= 0, section
= section_headers
;
10717 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
10720 #ifdef SUPPORT_DISASSEMBLY
10721 if (dump_sects
[i
] & DISASS_DUMP
)
10722 disassemble_section (section
, file
);
10724 if (dump_sects
[i
] & HEX_DUMP
)
10725 dump_section (section
, file
);
10727 if (dump_sects
[i
] & DEBUG_DUMP
)
10728 display_debug_section (section
, file
);
10731 /* Check to see if the user requested a
10732 dump of a section that does not exist. */
10733 while (i
++ < num_dump_sects
)
10735 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
10739 process_mips_fpe_exception (int mask
)
10744 if (mask
& OEX_FPU_INEX
)
10745 fputs ("INEX", stdout
), first
= 0;
10746 if (mask
& OEX_FPU_UFLO
)
10747 printf ("%sUFLO", first
? "" : "|"), first
= 0;
10748 if (mask
& OEX_FPU_OFLO
)
10749 printf ("%sOFLO", first
? "" : "|"), first
= 0;
10750 if (mask
& OEX_FPU_DIV0
)
10751 printf ("%sDIV0", first
? "" : "|"), first
= 0;
10752 if (mask
& OEX_FPU_INVAL
)
10753 printf ("%sINVAL", first
? "" : "|");
10756 fputs ("0", stdout
);
10760 process_mips_specific (FILE *file
)
10762 Elf_Internal_Dyn
*entry
;
10763 size_t liblist_offset
= 0;
10764 size_t liblistno
= 0;
10765 size_t conflictsno
= 0;
10766 size_t options_offset
= 0;
10767 size_t conflicts_offset
= 0;
10769 /* We have a lot of special sections. Thanks SGI! */
10770 if (dynamic_section
== NULL
)
10771 /* No information available. */
10774 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
10775 switch (entry
->d_tag
)
10777 case DT_MIPS_LIBLIST
:
10779 = offset_from_vma (file
, entry
->d_un
.d_val
,
10780 liblistno
* sizeof (Elf32_External_Lib
));
10782 case DT_MIPS_LIBLISTNO
:
10783 liblistno
= entry
->d_un
.d_val
;
10785 case DT_MIPS_OPTIONS
:
10786 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
10788 case DT_MIPS_CONFLICT
:
10790 = offset_from_vma (file
, entry
->d_un
.d_val
,
10791 conflictsno
* sizeof (Elf32_External_Conflict
));
10793 case DT_MIPS_CONFLICTNO
:
10794 conflictsno
= entry
->d_un
.d_val
;
10800 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
10802 Elf32_External_Lib
*elib
;
10805 elib
= get_data (NULL
, file
, liblist_offset
,
10806 liblistno
* sizeof (Elf32_External_Lib
),
10810 printf ("\nSection '.liblist' contains %lu entries:\n",
10811 (unsigned long) liblistno
);
10812 fputs (" Library Time Stamp Checksum Version Flags\n",
10815 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
10822 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
10823 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
10824 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
10825 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
10826 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
10828 tmp
= gmtime (&time
);
10829 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
10830 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10831 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10833 printf ("%3lu: ", (unsigned long) cnt
);
10834 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
10835 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
10837 printf ("<corrupt: %9ld>", liblist
.l_name
);
10838 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
10839 liblist
.l_version
);
10841 if (liblist
.l_flags
== 0)
10845 static const struct
10852 { " EXACT_MATCH", LL_EXACT_MATCH
},
10853 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
10854 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
10855 { " EXPORTS", LL_EXPORTS
},
10856 { " DELAY_LOAD", LL_DELAY_LOAD
},
10857 { " DELTA", LL_DELTA
}
10859 int flags
= liblist
.l_flags
;
10863 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
10865 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
10867 fputs (l_flags_vals
[fcnt
].name
, stdout
);
10868 flags
^= l_flags_vals
[fcnt
].bit
;
10871 printf (" %#x", (unsigned int) flags
);
10881 if (options_offset
!= 0)
10883 Elf_External_Options
*eopt
;
10884 Elf_Internal_Shdr
*sect
= section_headers
;
10885 Elf_Internal_Options
*iopt
;
10886 Elf_Internal_Options
*option
;
10890 /* Find the section header so that we get the size. */
10891 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
10894 eopt
= get_data (NULL
, file
, options_offset
, sect
->sh_size
,
10898 iopt
= malloc ((sect
->sh_size
/ sizeof (eopt
)) * sizeof (*iopt
));
10901 error (_("Out of memory"));
10908 while (offset
< sect
->sh_size
)
10910 Elf_External_Options
*eoption
;
10912 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
10914 option
->kind
= BYTE_GET (eoption
->kind
);
10915 option
->size
= BYTE_GET (eoption
->size
);
10916 option
->section
= BYTE_GET (eoption
->section
);
10917 option
->info
= BYTE_GET (eoption
->info
);
10919 offset
+= option
->size
;
10925 printf (_("\nSection '%s' contains %d entries:\n"),
10926 SECTION_NAME (sect
), cnt
);
10934 switch (option
->kind
)
10937 /* This shouldn't happen. */
10938 printf (" NULL %d %lx", option
->section
, option
->info
);
10941 printf (" REGINFO ");
10942 if (elf_header
.e_machine
== EM_MIPS
)
10945 Elf32_External_RegInfo
*ereg
;
10946 Elf32_RegInfo reginfo
;
10948 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
10949 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
10950 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
10951 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
10952 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
10953 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
10954 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
10956 printf ("GPR %08lx GP 0x%lx\n",
10957 reginfo
.ri_gprmask
,
10958 (unsigned long) reginfo
.ri_gp_value
);
10959 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
10960 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
10961 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
10966 Elf64_External_RegInfo
*ereg
;
10967 Elf64_Internal_RegInfo reginfo
;
10969 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
10970 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
10971 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
10972 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
10973 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
10974 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
10975 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
10977 printf ("GPR %08lx GP 0x",
10978 reginfo
.ri_gprmask
);
10979 printf_vma (reginfo
.ri_gp_value
);
10982 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
10983 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
10984 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
10988 case ODK_EXCEPTIONS
:
10989 fputs (" EXCEPTIONS fpe_min(", stdout
);
10990 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
10991 fputs (") fpe_max(", stdout
);
10992 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
10993 fputs (")", stdout
);
10995 if (option
->info
& OEX_PAGE0
)
10996 fputs (" PAGE0", stdout
);
10997 if (option
->info
& OEX_SMM
)
10998 fputs (" SMM", stdout
);
10999 if (option
->info
& OEX_FPDBUG
)
11000 fputs (" FPDBUG", stdout
);
11001 if (option
->info
& OEX_DISMISS
)
11002 fputs (" DISMISS", stdout
);
11005 fputs (" PAD ", stdout
);
11006 if (option
->info
& OPAD_PREFIX
)
11007 fputs (" PREFIX", stdout
);
11008 if (option
->info
& OPAD_POSTFIX
)
11009 fputs (" POSTFIX", stdout
);
11010 if (option
->info
& OPAD_SYMBOL
)
11011 fputs (" SYMBOL", stdout
);
11014 fputs (" HWPATCH ", stdout
);
11015 if (option
->info
& OHW_R4KEOP
)
11016 fputs (" R4KEOP", stdout
);
11017 if (option
->info
& OHW_R8KPFETCH
)
11018 fputs (" R8KPFETCH", stdout
);
11019 if (option
->info
& OHW_R5KEOP
)
11020 fputs (" R5KEOP", stdout
);
11021 if (option
->info
& OHW_R5KCVTL
)
11022 fputs (" R5KCVTL", stdout
);
11025 fputs (" FILL ", stdout
);
11026 /* XXX Print content of info word? */
11029 fputs (" TAGS ", stdout
);
11030 /* XXX Print content of info word? */
11033 fputs (" HWAND ", stdout
);
11034 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
11035 fputs (" R4KEOP_CHECKED", stdout
);
11036 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
11037 fputs (" R4KEOP_CLEAN", stdout
);
11040 fputs (" HWOR ", stdout
);
11041 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
11042 fputs (" R4KEOP_CHECKED", stdout
);
11043 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
11044 fputs (" R4KEOP_CLEAN", stdout
);
11047 printf (" GP_GROUP %#06lx self-contained %#06lx",
11048 option
->info
& OGP_GROUP
,
11049 (option
->info
& OGP_SELF
) >> 16);
11052 printf (" IDENT %#06lx self-contained %#06lx",
11053 option
->info
& OGP_GROUP
,
11054 (option
->info
& OGP_SELF
) >> 16);
11057 /* This shouldn't happen. */
11058 printf (" %3d ??? %d %lx",
11059 option
->kind
, option
->section
, option
->info
);
11063 len
= sizeof (*eopt
);
11064 while (len
< option
->size
)
11065 if (((char *) option
)[len
] >= ' '
11066 && ((char *) option
)[len
] < 0x7f)
11067 printf ("%c", ((char *) option
)[len
++]);
11069 printf ("\\%03o", ((char *) option
)[len
++]);
11071 fputs ("\n", stdout
);
11079 if (conflicts_offset
!= 0 && conflictsno
!= 0)
11081 Elf32_Conflict
*iconf
;
11084 if (dynamic_symbols
== NULL
)
11086 error (_("conflict list found without a dynamic symbol table"));
11090 iconf
= malloc (conflictsno
* sizeof (*iconf
));
11093 error (_("Out of memory"));
11099 Elf32_External_Conflict
*econf32
;
11101 econf32
= get_data (NULL
, file
, conflicts_offset
,
11102 conflictsno
* sizeof (*econf32
), _("conflict"));
11106 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
11107 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
11113 Elf64_External_Conflict
*econf64
;
11115 econf64
= get_data (NULL
, file
, conflicts_offset
,
11116 conflictsno
* sizeof (*econf64
), _("conflict"));
11120 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
11121 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
11126 printf (_("\nSection '.conflict' contains %lu entries:\n"),
11127 (unsigned long) conflictsno
);
11128 puts (_(" Num: Index Value Name"));
11130 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
11132 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
11134 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
11135 print_vma (psym
->st_value
, FULL_HEX
);
11137 if (VALID_DYNAMIC_NAME (psym
->st_name
))
11138 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
11140 printf ("<corrupt: %14ld>", psym
->st_name
);
11151 process_gnu_liblist (FILE *file
)
11153 Elf_Internal_Shdr
*section
, *string_sec
;
11154 Elf32_External_Lib
*elib
;
11162 for (i
= 0, section
= section_headers
;
11163 i
< elf_header
.e_shnum
;
11166 switch (section
->sh_type
)
11168 case SHT_GNU_LIBLIST
:
11169 elib
= get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
11174 string_sec
= SECTION_HEADER (section
->sh_link
);
11176 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
11177 string_sec
->sh_size
, _("liblist string table"));
11180 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
11186 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
11187 SECTION_NAME (section
),
11188 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
11190 puts (" Library Time Stamp Checksum Version Flags");
11192 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
11200 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
11201 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
11202 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
11203 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
11204 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
11206 tmp
= gmtime (&time
);
11207 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
11208 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
11209 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
11211 printf ("%3lu: ", (unsigned long) cnt
);
11213 printf ("%-20s", strtab
+ liblist
.l_name
);
11215 printf ("%-20.20s", strtab
+ liblist
.l_name
);
11216 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
11217 liblist
.l_version
, liblist
.l_flags
);
11227 static const char *
11228 get_note_type (unsigned e_type
)
11230 static char buff
[64];
11232 if (elf_header
.e_type
== ET_CORE
)
11236 return _("NT_AUXV (auxiliary vector)");
11238 return _("NT_PRSTATUS (prstatus structure)");
11240 return _("NT_FPREGSET (floating point registers)");
11242 return _("NT_PRPSINFO (prpsinfo structure)");
11243 case NT_TASKSTRUCT
:
11244 return _("NT_TASKSTRUCT (task structure)");
11246 return _("NT_PRXFPREG (user_xfpregs structure)");
11248 return _("NT_PSTATUS (pstatus structure)");
11250 return _("NT_FPREGS (floating point registers)");
11252 return _("NT_PSINFO (psinfo structure)");
11254 return _("NT_LWPSTATUS (lwpstatus_t structure)");
11256 return _("NT_LWPSINFO (lwpsinfo_t structure)");
11257 case NT_WIN32PSTATUS
:
11258 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
11266 return _("NT_VERSION (version)");
11268 return _("NT_ARCH (architecture)");
11273 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
11277 static const char *
11278 get_netbsd_elfcore_note_type (unsigned e_type
)
11280 static char buff
[64];
11282 if (e_type
== NT_NETBSDCORE_PROCINFO
)
11284 /* NetBSD core "procinfo" structure. */
11285 return _("NetBSD procinfo structure");
11288 /* As of Jan 2002 there are no other machine-independent notes
11289 defined for NetBSD core files. If the note type is less
11290 than the start of the machine-dependent note types, we don't
11293 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
11295 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
11299 switch (elf_header
.e_machine
)
11301 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
11302 and PT_GETFPREGS == mach+2. */
11307 case EM_SPARC32PLUS
:
11311 case NT_NETBSDCORE_FIRSTMACH
+0:
11312 return _("PT_GETREGS (reg structure)");
11313 case NT_NETBSDCORE_FIRSTMACH
+2:
11314 return _("PT_GETFPREGS (fpreg structure)");
11320 /* On all other arch's, PT_GETREGS == mach+1 and
11321 PT_GETFPREGS == mach+3. */
11325 case NT_NETBSDCORE_FIRSTMACH
+1:
11326 return _("PT_GETREGS (reg structure)");
11327 case NT_NETBSDCORE_FIRSTMACH
+3:
11328 return _("PT_GETFPREGS (fpreg structure)");
11334 sprintf (buff
, _("PT_FIRSTMACH+%d"), e_type
- NT_NETBSDCORE_FIRSTMACH
);
11338 /* Note that by the ELF standard, the name field is already null byte
11339 terminated, and namesz includes the terminating null byte.
11340 I.E. the value of namesz for the name "FSF" is 4.
11342 If the value of namesz is zero, there is no name present. */
11344 process_note (Elf_Internal_Note
*pnote
)
11348 if (pnote
->namesz
== 0)
11349 /* If there is no note name, then use the default set of
11350 note type strings. */
11351 nt
= get_note_type (pnote
->type
);
11353 else if (strneq (pnote
->namedata
, "NetBSD-CORE", 11))
11354 /* NetBSD-specific core file notes. */
11355 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
11358 /* Don't recognize this note name; just use the default set of
11359 note type strings. */
11360 nt
= get_note_type (pnote
->type
);
11362 printf (" %s\t\t0x%08lx\t%s\n",
11363 pnote
->namesz
? pnote
->namedata
: "(NONE)",
11364 pnote
->descsz
, nt
);
11370 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
11372 Elf_External_Note
*pnotes
;
11373 Elf_External_Note
*external
;
11379 pnotes
= get_data (NULL
, file
, offset
, length
, _("notes"));
11385 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
11386 (unsigned long) offset
, (unsigned long) length
);
11387 printf (_(" Owner\t\tData size\tDescription\n"));
11389 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
11391 Elf_External_Note
*next
;
11392 Elf_Internal_Note inote
;
11395 inote
.type
= BYTE_GET (external
->type
);
11396 inote
.namesz
= BYTE_GET (external
->namesz
);
11397 inote
.namedata
= external
->name
;
11398 inote
.descsz
= BYTE_GET (external
->descsz
);
11399 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
11400 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
11402 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
11404 if (((char *) next
) > (((char *) pnotes
) + length
))
11406 warn (_("corrupt note found at offset %x into core notes\n"),
11407 ((char *) external
) - ((char *) pnotes
));
11408 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
11409 inote
.type
, inote
.namesz
, inote
.descsz
);
11415 /* Verify that name is null terminated. It appears that at least
11416 one version of Linux (RedHat 6.0) generates corefiles that don't
11417 comply with the ELF spec by failing to include the null byte in
11419 if (inote
.namedata
[inote
.namesz
] != '\0')
11421 temp
= malloc (inote
.namesz
+ 1);
11425 error (_("Out of memory\n"));
11430 strncpy (temp
, inote
.namedata
, inote
.namesz
);
11431 temp
[inote
.namesz
] = 0;
11433 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
11434 inote
.namedata
= temp
;
11437 res
&= process_note (& inote
);
11452 process_corefile_note_segments (FILE *file
)
11454 Elf_Internal_Phdr
*segment
;
11458 if (! get_program_headers (file
))
11461 for (i
= 0, segment
= program_headers
;
11462 i
< elf_header
.e_phnum
;
11465 if (segment
->p_type
== PT_NOTE
)
11466 res
&= process_corefile_note_segment (file
,
11467 (bfd_vma
) segment
->p_offset
,
11468 (bfd_vma
) segment
->p_filesz
);
11475 process_note_sections (FILE *file
)
11477 Elf_Internal_Shdr
*section
;
11481 for (i
= 0, section
= section_headers
;
11482 i
< elf_header
.e_shnum
;
11484 if (section
->sh_type
== SHT_NOTE
)
11485 res
&= process_corefile_note_segment (file
,
11486 (bfd_vma
) section
->sh_offset
,
11487 (bfd_vma
) section
->sh_size
);
11493 process_notes (FILE *file
)
11495 /* If we have not been asked to display the notes then do nothing. */
11499 if (elf_header
.e_type
!= ET_CORE
)
11500 return process_note_sections (file
);
11502 /* No program headers means no NOTE segment. */
11503 if (elf_header
.e_phnum
> 0)
11504 return process_corefile_note_segments (file
);
11506 printf (_("No note segments present in the core file.\n"));
11511 process_arch_specific (FILE *file
)
11516 switch (elf_header
.e_machine
)
11519 case EM_MIPS_RS3_LE
:
11520 return process_mips_specific (file
);
11529 get_file_header (FILE *file
)
11531 /* Read in the identity array. */
11532 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
11535 /* Determine how to read the rest of the header. */
11536 switch (elf_header
.e_ident
[EI_DATA
])
11538 default: /* fall through */
11539 case ELFDATANONE
: /* fall through */
11541 byte_get
= byte_get_little_endian
;
11542 byte_put
= byte_put_little_endian
;
11545 byte_get
= byte_get_big_endian
;
11546 byte_put
= byte_put_big_endian
;
11550 /* For now we only support 32 bit and 64 bit ELF files. */
11551 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
11553 /* Read in the rest of the header. */
11556 Elf32_External_Ehdr ehdr32
;
11558 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
11561 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
11562 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
11563 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
11564 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
11565 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
11566 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
11567 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
11568 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
11569 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
11570 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
11571 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
11572 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
11573 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
11577 Elf64_External_Ehdr ehdr64
;
11579 /* If we have been compiled with sizeof (bfd_vma) == 4, then
11580 we will not be able to cope with the 64bit data found in
11581 64 ELF files. Detect this now and abort before we start
11582 overwriting things. */
11583 if (sizeof (bfd_vma
) < 8)
11585 error (_("This instance of readelf has been built without support for a\n\
11586 64 bit data type and so it cannot read 64 bit ELF files.\n"));
11590 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
11593 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
11594 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
11595 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
11596 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
11597 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
11598 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
11599 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
11600 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
11601 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
11602 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
11603 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
11604 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
11605 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
11608 if (elf_header
.e_shoff
)
11610 /* There may be some extensions in the first section header. Don't
11611 bomb if we can't read it. */
11613 get_32bit_section_headers (file
, 1);
11615 get_64bit_section_headers (file
, 1);
11621 /* Process one ELF object file according to the command line options.
11622 This file may actually be stored in an archive. The file is
11623 positioned at the start of the ELF object. */
11626 process_object (char *file_name
, FILE *file
)
11630 if (! get_file_header (file
))
11632 error (_("%s: Failed to read file header\n"), file_name
);
11636 /* Initialise per file variables. */
11637 for (i
= NUM_ELEM (version_info
); i
--;)
11638 version_info
[i
] = 0;
11640 for (i
= NUM_ELEM (dynamic_info
); i
--;)
11641 dynamic_info
[i
] = 0;
11643 /* Process the file. */
11645 printf (_("\nFile: %s\n"), file_name
);
11647 /* Initialise the dump_sects array from the cmdline_dump_sects array.
11648 Note we do this even if cmdline_dump_sects is empty because we
11649 must make sure that the dump_sets array is zeroed out before each
11650 object file is processed. */
11651 if (num_dump_sects
> num_cmdline_dump_sects
)
11652 memset (dump_sects
, 0, num_dump_sects
);
11654 if (num_cmdline_dump_sects
> 0)
11656 if (num_dump_sects
== 0)
11657 /* A sneaky way of allocating the dump_sects array. */
11658 request_dump (num_cmdline_dump_sects
, 0);
11660 assert (num_dump_sects
>= num_cmdline_dump_sects
);
11661 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
11664 if (! process_file_header ())
11667 if (! process_section_headers (file
)
11668 || ! process_section_groups (file
))
11670 /* Without loaded section headers and section groups we
11671 cannot process lots of things. */
11672 do_unwind
= do_version
= do_dump
= do_arch
= 0;
11674 if (! do_using_dynamic
)
11675 do_syms
= do_reloc
= 0;
11678 if (process_program_headers (file
))
11679 process_dynamic_section (file
);
11681 process_relocs (file
);
11683 process_unwind (file
);
11685 process_symbol_table (file
);
11687 process_syminfo (file
);
11689 process_version_sections (file
);
11691 process_section_contents (file
);
11693 process_notes (file
);
11695 process_gnu_liblist (file
);
11697 process_arch_specific (file
);
11699 if (program_headers
)
11701 free (program_headers
);
11702 program_headers
= NULL
;
11705 if (section_headers
)
11707 free (section_headers
);
11708 section_headers
= NULL
;
11713 free (string_table
);
11714 string_table
= NULL
;
11715 string_table_length
= 0;
11718 if (dynamic_strings
)
11720 free (dynamic_strings
);
11721 dynamic_strings
= NULL
;
11722 dynamic_strings_length
= 0;
11725 if (dynamic_symbols
)
11727 free (dynamic_symbols
);
11728 dynamic_symbols
= NULL
;
11729 num_dynamic_syms
= 0;
11732 if (dynamic_syminfo
)
11734 free (dynamic_syminfo
);
11735 dynamic_syminfo
= NULL
;
11738 if (section_headers_groups
)
11740 free (section_headers_groups
);
11741 section_headers_groups
= NULL
;
11744 if (section_groups
)
11746 struct group_list
*g
, *next
;
11748 for (i
= 0; i
< group_count
; i
++)
11750 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
11757 free (section_groups
);
11758 section_groups
= NULL
;
11761 if (debug_information
)
11763 for (i
= 0; i
< num_debug_info_entries
; i
++)
11765 if (!debug_information
[i
].max_loc_offsets
)
11767 free (debug_information
[i
].loc_offsets
);
11768 free (debug_information
[i
].have_frame_base
);
11770 if (!debug_information
[i
].max_range_lists
)
11771 free (debug_information
[i
].range_lists
);
11773 free (debug_information
);
11774 debug_information
= NULL
;
11775 num_debug_info_entries
= 0;
11781 /* Process an ELF archive. The file is positioned just after the
11785 process_archive (char *file_name
, FILE *file
)
11787 struct ar_hdr arhdr
;
11789 unsigned long size
;
11790 char *longnames
= NULL
;
11791 unsigned long longnames_size
= 0;
11792 size_t file_name_size
;
11797 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
11798 if (got
!= sizeof arhdr
)
11803 error (_("%s: failed to read archive header\n"), file_name
);
11807 if (memcmp (arhdr
.ar_name
, "/ ", 16) == 0)
11809 /* This is the archive symbol table. Skip it.
11810 FIXME: We should have an option to dump it. */
11811 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
11812 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
11814 error (_("%s: failed to skip archive symbol table\n"), file_name
);
11818 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
11819 if (got
!= sizeof arhdr
)
11824 error (_("%s: failed to read archive header\n"), file_name
);
11829 if (memcmp (arhdr
.ar_name
, "// ", 16) == 0)
11831 /* This is the archive string table holding long member
11834 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
11836 longnames
= malloc (longnames_size
);
11837 if (longnames
== NULL
)
11839 error (_("Out of memory\n"));
11843 if (fread (longnames
, longnames_size
, 1, file
) != 1)
11846 error (_("%s: failed to read string table\n"), file_name
);
11850 if ((longnames_size
& 1) != 0)
11853 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
11854 if (got
!= sizeof arhdr
)
11861 error (_("%s: failed to read archive header\n"), file_name
);
11866 file_name_size
= strlen (file_name
);
11875 if (arhdr
.ar_name
[0] == '/')
11879 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
11880 if (off
>= longnames_size
)
11882 error (_("%s: invalid archive string table offset %lu\n"), off
);
11887 name
= longnames
+ off
;
11888 nameend
= memchr (name
, '/', longnames_size
- off
);
11892 name
= arhdr
.ar_name
;
11893 nameend
= memchr (name
, '/', 16);
11896 if (nameend
== NULL
)
11898 error (_("%s: bad archive file name\n"));
11903 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
11904 if (namealc
== NULL
)
11906 error (_("Out of memory\n"));
11911 memcpy (namealc
, file_name
, file_name_size
);
11912 namealc
[file_name_size
] = '(';
11913 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
11914 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
11915 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
11917 archive_file_offset
= ftell (file
);
11918 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
11920 ret
|= process_object (namealc
, file
);
11925 (archive_file_offset
11926 + archive_file_size
11927 + (archive_file_size
& 1)),
11930 error (_("%s: failed to seek to next archive header\n"), file_name
);
11935 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
11936 if (got
!= sizeof arhdr
)
11941 error (_("%s: failed to read archive header\n"), file_name
);
11947 if (longnames
!= 0)
11954 process_file (char *file_name
)
11957 struct stat statbuf
;
11958 char armag
[SARMAG
];
11961 if (stat (file_name
, &statbuf
) < 0)
11963 if (errno
== ENOENT
)
11964 error (_("'%s': No such file\n"), file_name
);
11966 error (_("Could not locate '%s'. System error message: %s\n"),
11967 file_name
, strerror (errno
));
11971 if (! S_ISREG (statbuf
.st_mode
))
11973 error (_("'%s' is not an ordinary file\n"), file_name
);
11977 file
= fopen (file_name
, "rb");
11980 error (_("Input file '%s' is not readable.\n"), file_name
);
11984 if (fread (armag
, SARMAG
, 1, file
) != 1)
11986 error (_("%s: Failed to read file header\n"), file_name
);
11991 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
11992 ret
= process_archive (file_name
, file
);
11996 archive_file_size
= archive_file_offset
= 0;
11997 ret
= process_object (file_name
, file
);
12005 #ifdef SUPPORT_DISASSEMBLY
12006 /* Needed by the i386 disassembler. For extra credit, someone could
12007 fix this so that we insert symbolic addresses here, esp for GOT/PLT
12011 print_address (unsigned int addr
, FILE *outfile
)
12013 fprintf (outfile
,"0x%8.8x", addr
);
12016 /* Needed by the i386 disassembler. */
12018 db_task_printsym (unsigned int addr
)
12020 print_address (addr
, stderr
);
12025 main (int argc
, char **argv
)
12029 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
12030 setlocale (LC_MESSAGES
, "");
12032 #if defined (HAVE_SETLOCALE)
12033 setlocale (LC_CTYPE
, "");
12035 bindtextdomain (PACKAGE
, LOCALEDIR
);
12036 textdomain (PACKAGE
);
12038 parse_args (argc
, argv
);
12040 if (num_dump_sects
> 0)
12042 /* Make a copy of the dump_sects array. */
12043 cmdline_dump_sects
= malloc (num_dump_sects
);
12044 if (cmdline_dump_sects
== NULL
)
12045 error (_("Out of memory allocating dump request table."));
12048 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
12049 num_cmdline_dump_sects
= num_dump_sects
;
12053 if (optind
< (argc
- 1))
12057 while (optind
< argc
)
12058 err
|= process_file (argv
[optind
++]);
12060 if (dump_sects
!= NULL
)
12062 if (cmdline_dump_sects
!= NULL
)
12063 free (cmdline_dump_sects
);