1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 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 3 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., 51 Franklin Street - Fifth Floor, 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. */
60 # ifdef HAVE_SYS_PARAM_H
61 # include <sys/param.h>
65 # define PATH_MAX MAXPATHLEN
67 # define PATH_MAX 1024
73 /* Define BFD64 here, even if our default architecture is 32 bit ELF
74 as this will allow us to read in and parse 64bit and 32bit ELF files.
75 Only do this if we believe that the compiler can support a 64 bit
76 data type. For now we only rely on GCC being able to do this. */
84 #include "elf/common.h"
85 #include "elf/external.h"
86 #include "elf/internal.h"
89 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
90 we can obtain the H8 reloc numbers. We need these for the
91 get_reloc_size() function. We include h8.h again after defining
92 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
97 /* Undo the effects of #including reloc-macros.h. */
99 #undef START_RELOC_NUMBERS
103 #undef END_RELOC_NUMBERS
104 #undef _RELOC_MACROS_H
106 /* The following headers use the elf/reloc-macros.h file to
107 automatically generate relocation recognition functions
108 such as elf_mips_reloc_type() */
110 #define RELOC_MACROS_GEN_FUNC
112 #include "elf/alpha.h"
116 #include "elf/bfin.h"
117 #include "elf/cr16.h"
118 #include "elf/cris.h"
120 #include "elf/d10v.h"
121 #include "elf/d30v.h"
123 #include "elf/fr30.h"
126 #include "elf/hppa.h"
127 #include "elf/i386.h"
128 #include "elf/i370.h"
129 #include "elf/i860.h"
130 #include "elf/i960.h"
131 #include "elf/ia64.h"
132 #include "elf/ip2k.h"
133 #include "elf/iq2000.h"
134 #include "elf/m32c.h"
135 #include "elf/m32r.h"
136 #include "elf/m68k.h"
137 #include "elf/m68hc11.h"
138 #include "elf/mcore.h"
140 #include "elf/mips.h"
141 #include "elf/mmix.h"
142 #include "elf/mn10200.h"
143 #include "elf/mn10300.h"
145 #include "elf/msp430.h"
146 #include "elf/or32.h"
149 #include "elf/ppc64.h"
150 #include "elf/s390.h"
151 #include "elf/score.h"
153 #include "elf/sparc.h"
155 #include "elf/v850.h"
157 #include "elf/x86-64.h"
158 #include "elf/xstormy16.h"
159 #include "elf/xtensa.h"
164 #include "libiberty.h"
165 #include "safe-ctype.h"
167 char *program_name
= "readelf";
169 static long archive_file_offset
;
170 static unsigned long archive_file_size
;
171 static unsigned long dynamic_addr
;
172 static bfd_size_type dynamic_size
;
173 static unsigned int dynamic_nent
;
174 static char *dynamic_strings
;
175 static unsigned long dynamic_strings_length
;
176 static char *string_table
;
177 static unsigned long string_table_length
;
178 static unsigned long num_dynamic_syms
;
179 static Elf_Internal_Sym
*dynamic_symbols
;
180 static Elf_Internal_Syminfo
*dynamic_syminfo
;
181 static unsigned long dynamic_syminfo_offset
;
182 static unsigned int dynamic_syminfo_nent
;
183 static char program_interpreter
[PATH_MAX
];
184 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
185 static bfd_vma dynamic_info_DT_GNU_HASH
;
186 static bfd_vma version_info
[16];
187 static Elf_Internal_Ehdr elf_header
;
188 static Elf_Internal_Shdr
*section_headers
;
189 static Elf_Internal_Phdr
*program_headers
;
190 static Elf_Internal_Dyn
*dynamic_section
;
191 static Elf_Internal_Shdr
*symtab_shndx_hdr
;
192 static int show_name
;
193 static int do_dynamic
;
196 static int do_sections
;
197 static int do_section_groups
;
198 static int do_section_details
;
199 static int do_segments
;
200 static int do_unwind
;
201 static int do_using_dynamic
;
202 static int do_header
;
204 static int do_version
;
205 static int do_histogram
;
206 static int do_debugging
;
209 static int do_archive_index
;
210 static int is_32bit_elf
;
214 struct group_list
*next
;
215 unsigned int section_index
;
220 struct group_list
*root
;
221 unsigned int group_index
;
224 static size_t group_count
;
225 static struct group
*section_groups
;
226 static struct group
**section_headers_groups
;
229 /* Flag bits indicating particular types of dump. */
230 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
231 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
232 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
233 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
235 typedef unsigned char dump_type
;
237 /* A linked list of the section names for which dumps were requested. */
238 struct dump_list_entry
242 struct dump_list_entry
*next
;
244 static struct dump_list_entry
*dump_sects_byname
;
246 /* A dynamic array of flags indicating for which sections a dump
247 has been requested via command line switches. */
248 static dump_type
* cmdline_dump_sects
= NULL
;
249 static unsigned int num_cmdline_dump_sects
= 0;
251 /* A dynamic array of flags indicating for which sections a dump of
252 some kind has been requested. It is reset on a per-object file
253 basis and then initialised from the cmdline_dump_sects array,
254 the results of interpreting the -w switch, and the
255 dump_sects_byname list. */
256 static dump_type
* dump_sects
= NULL
;
257 static unsigned int num_dump_sects
= 0;
260 /* How to print a vma value. */
261 typedef enum print_mode
273 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
277 #define SECTION_NAME(X) \
278 ((X) == NULL ? "<none>" \
279 : string_table == NULL ? "<no-name>" \
280 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
281 : string_table + (X)->sh_name))
283 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
285 #define BYTE_GET(field) byte_get (field, sizeof (field))
287 #define GET_ELF_SYMBOLS(file, section) \
288 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
289 : get_64bit_elf_symbols (file, section))
291 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
292 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
293 already been called and verified that the string exists. */
294 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
296 /* This is just a bit of syntatic sugar. */
297 #define streq(a,b) (strcmp ((a), (b)) == 0)
298 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
299 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
302 get_data (void *var
, FILE *file
, long offset
, size_t size
, size_t nmemb
,
307 if (size
== 0 || nmemb
== 0)
310 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
312 error (_("Unable to seek to 0x%lx for %s\n"),
313 archive_file_offset
+ offset
, reason
);
320 /* Check for overflow. */
321 if (nmemb
< (~(size_t) 0 - 1) / size
)
322 /* + 1 so that we can '\0' terminate invalid string table sections. */
323 mvar
= malloc (size
* nmemb
+ 1);
327 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
328 (unsigned long)(size
* nmemb
), reason
);
332 ((char *) mvar
)[size
* nmemb
] = '\0';
335 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
337 error (_("Unable to read in 0x%lx bytes of %s\n"),
338 (unsigned long)(size
* nmemb
), reason
);
348 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
353 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
354 field
[6] = ((value
>> 24) >> 24) & 0xff;
355 field
[5] = ((value
>> 24) >> 16) & 0xff;
356 field
[4] = ((value
>> 24) >> 8) & 0xff;
359 field
[3] = (value
>> 24) & 0xff;
360 field
[2] = (value
>> 16) & 0xff;
363 field
[1] = (value
>> 8) & 0xff;
366 field
[0] = value
& 0xff;
370 error (_("Unhandled data length: %d\n"), size
);
375 #if defined BFD64 && !BFD_HOST_64BIT_LONG && !BFD_HOST_64BIT_LONG_LONG
377 print_dec_vma (bfd_vma vma
, int is_signed
)
383 if (is_signed
&& (bfd_signed_vma
) vma
< 0)
392 *bufp
++ = '0' + vma
% 10;
404 print_hex_vma (bfd_vma vma
)
412 char digit
= '0' + (vma
& 0x0f);
414 digit
+= 'a' - '0' - 10;
427 /* Print a VMA value. */
429 print_vma (bfd_vma vma
, print_mode mode
)
438 return printf ("0x%8.8lx", (unsigned long) vma
);
441 return printf ("%8.8lx", (unsigned long) vma
);
445 return printf ("%5ld", (long) vma
);
449 return printf ("0x%lx", (unsigned long) vma
);
452 return printf ("%lx", (unsigned long) vma
);
455 return printf ("%ld", (unsigned long) vma
);
458 return printf ("%lu", (unsigned long) vma
);
481 #if BFD_HOST_64BIT_LONG
482 return nc
+ printf ("%lx", vma
);
483 #elif BFD_HOST_64BIT_LONG_LONG
485 return nc
+ printf ("%llx", vma
);
487 return nc
+ printf ("%I64x", vma
);
490 return nc
+ print_hex_vma (vma
);
494 #if BFD_HOST_64BIT_LONG
495 return printf ("%ld", vma
);
496 #elif BFD_HOST_64BIT_LONG_LONG
498 return printf ("%lld", vma
);
500 return printf ("%I64d", vma
);
503 return print_dec_vma (vma
, 1);
507 #if BFD_HOST_64BIT_LONG
509 return printf ("%5ld", vma
);
511 return printf ("%#lx", vma
);
512 #elif BFD_HOST_64BIT_LONG_LONG
515 return printf ("%5lld", vma
);
517 return printf ("%#llx", vma
);
520 return printf ("%5I64d", vma
);
522 return printf ("%#I64x", vma
);
526 return printf ("%5ld", _bfd_int64_low (vma
));
528 return print_hex_vma (vma
);
532 #if BFD_HOST_64BIT_LONG
533 return printf ("%lu", vma
);
534 #elif BFD_HOST_64BIT_LONG_LONG
536 return printf ("%llu", vma
);
538 return printf ("%I64u", vma
);
541 return print_dec_vma (vma
, 0);
549 /* Display a symbol on stdout. Handles the display of
550 non-printing characters.
551 If DO_WIDE is not true then format the symbol to be
552 at most WIDTH characters, truncating as necessary.
553 If WIDTH is negative then format the string to be
554 exactly - WIDTH characters, truncating or padding
558 print_symbol (int width
, const char *symbol
)
560 const char * format_string
;
565 format_string
= "%.*s";
566 /* Set the width to a very large value. This simplifies the code below. */
571 format_string
= "%-*.*2s";
572 /* Keep the width positive. This also helps. */
577 format_string
= "%-.*s";
586 /* Look for non-printing symbols inside the symbol's name.
587 This test is triggered in particular by the names generated
588 by the assembler for local labels. */
589 while (ISPRINT (* c
))
599 printf (format_string
, len
, symbol
);
604 if (* c
== 0 || width
== 0)
607 /* Now display the non-printing character, if
608 there is room left in which to dipslay it. */
614 printf ("^%c", *c
+ 0x40);
623 printf ("<0x%.2x>", *c
);
633 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
638 field
[7] = value
& 0xff;
639 field
[6] = (value
>> 8) & 0xff;
640 field
[5] = (value
>> 16) & 0xff;
641 field
[4] = (value
>> 24) & 0xff;
646 field
[3] = value
& 0xff;
647 field
[2] = (value
>> 8) & 0xff;
651 field
[1] = value
& 0xff;
655 field
[0] = value
& 0xff;
659 error (_("Unhandled data length: %d\n"), size
);
664 /* Return a pointer to section NAME, or NULL if no such section exists. */
666 static Elf_Internal_Shdr
*
667 find_section (const char *name
)
671 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
672 if (streq (SECTION_NAME (section_headers
+ i
), name
))
673 return section_headers
+ i
;
678 /* Guess the relocation size commonly used by the specific machines. */
681 guess_is_rela (unsigned int e_machine
)
685 /* Targets that use REL relocations. */
701 /* Targets that use RELA relocations. */
705 case EM_ALTERA_NIOS2
:
732 case EM_CYGNUS_MN10200
:
734 case EM_CYGNUS_MN10300
:
775 warn (_("Don't know about relocations on this machine architecture\n"));
781 slurp_rela_relocs (FILE *file
,
782 unsigned long rel_offset
,
783 unsigned long rel_size
,
784 Elf_Internal_Rela
**relasp
,
785 unsigned long *nrelasp
)
787 Elf_Internal_Rela
*relas
;
788 unsigned long nrelas
;
793 Elf32_External_Rela
*erelas
;
795 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
799 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
801 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
806 error (_("out of memory parsing relocs\n"));
810 for (i
= 0; i
< nrelas
; i
++)
812 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
813 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
814 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
821 Elf64_External_Rela
*erelas
;
823 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
827 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
829 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
834 error (_("out of memory parsing relocs\n"));
838 for (i
= 0; i
< nrelas
; i
++)
840 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
841 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
842 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
853 slurp_rel_relocs (FILE *file
,
854 unsigned long rel_offset
,
855 unsigned long rel_size
,
856 Elf_Internal_Rela
**relsp
,
857 unsigned long *nrelsp
)
859 Elf_Internal_Rela
*rels
;
865 Elf32_External_Rel
*erels
;
867 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
871 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
873 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
878 error (_("out of memory parsing relocs\n"));
882 for (i
= 0; i
< nrels
; i
++)
884 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
885 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
886 rels
[i
].r_addend
= 0;
893 Elf64_External_Rel
*erels
;
895 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
899 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
901 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
906 error (_("out of memory parsing relocs\n"));
910 for (i
= 0; i
< nrels
; i
++)
912 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
913 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
914 rels
[i
].r_addend
= 0;
924 /* Returns the reloc type extracted from the reloc info field. */
927 get_reloc_type (bfd_vma reloc_info
)
930 return ELF32_R_TYPE (reloc_info
);
932 switch (elf_header
.e_machine
)
935 /* Note: We assume that reloc_info has already been adjusted for us. */
936 return ELF64_MIPS_R_TYPE (reloc_info
);
939 return ELF64_R_TYPE_ID (reloc_info
);
942 return ELF64_R_TYPE (reloc_info
);
946 /* Return the symbol index extracted from the reloc info field. */
949 get_reloc_symindex (bfd_vma reloc_info
)
951 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
954 /* Display the contents of the relocation data found at the specified
958 dump_relocations (FILE *file
,
959 unsigned long rel_offset
,
960 unsigned long rel_size
,
961 Elf_Internal_Sym
*symtab
,
964 unsigned long strtablen
,
968 Elf_Internal_Rela
*rels
;
971 if (is_rela
== UNKNOWN
)
972 is_rela
= guess_is_rela (elf_header
.e_machine
);
976 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
981 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
990 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
992 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
997 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
999 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1007 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1009 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1014 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1016 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1020 for (i
= 0; i
< rel_size
; i
++)
1025 bfd_vma symtab_index
;
1028 offset
= rels
[i
].r_offset
;
1029 info
= rels
[i
].r_info
;
1031 /* The #ifdef BFD64 below is to prevent a compile time warning.
1032 We know that if we do not have a 64 bit data type that we
1033 will never execute this code anyway. */
1036 && elf_header
.e_machine
== EM_MIPS
1037 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1039 /* In little-endian objects, r_info isn't really a 64-bit
1040 little-endian value: it has a 32-bit little-endian
1041 symbol index followed by four individual byte fields.
1042 Reorder INFO accordingly. */
1043 info
= (((info
& 0xffffffff) << 32)
1044 | ((info
>> 56) & 0xff)
1045 | ((info
>> 40) & 0xff00)
1046 | ((info
>> 24) & 0xff0000)
1047 | ((info
>> 8) & 0xff000000));
1051 type
= get_reloc_type (info
);
1052 symtab_index
= get_reloc_symindex (info
);
1056 printf ("%8.8lx %8.8lx ",
1057 (unsigned long) offset
& 0xffffffff,
1058 (unsigned long) info
& 0xffffffff);
1062 #if BFD_HOST_64BIT_LONG
1064 ? "%16.16lx %16.16lx "
1065 : "%12.12lx %12.12lx ",
1067 #elif BFD_HOST_64BIT_LONG_LONG
1070 ? "%16.16llx %16.16llx "
1071 : "%12.12llx %12.12llx ",
1075 ? "%16.16I64x %16.16I64x "
1076 : "%12.12I64x %12.12I64x ",
1081 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1082 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1083 _bfd_int64_high (offset
),
1084 _bfd_int64_low (offset
),
1085 _bfd_int64_high (info
),
1086 _bfd_int64_low (info
));
1090 switch (elf_header
.e_machine
)
1097 case EM_CYGNUS_M32R
:
1098 rtype
= elf_m32r_reloc_type (type
);
1103 rtype
= elf_i386_reloc_type (type
);
1108 rtype
= elf_m68hc11_reloc_type (type
);
1112 rtype
= elf_m68k_reloc_type (type
);
1116 rtype
= elf_i960_reloc_type (type
);
1121 rtype
= elf_avr_reloc_type (type
);
1124 case EM_OLD_SPARCV9
:
1125 case EM_SPARC32PLUS
:
1128 rtype
= elf_sparc_reloc_type (type
);
1132 rtype
= elf_spu_reloc_type (type
);
1136 case EM_CYGNUS_V850
:
1137 rtype
= v850_reloc_type (type
);
1141 case EM_CYGNUS_D10V
:
1142 rtype
= elf_d10v_reloc_type (type
);
1146 case EM_CYGNUS_D30V
:
1147 rtype
= elf_d30v_reloc_type (type
);
1151 rtype
= elf_dlx_reloc_type (type
);
1155 rtype
= elf_sh_reloc_type (type
);
1159 case EM_CYGNUS_MN10300
:
1160 rtype
= elf_mn10300_reloc_type (type
);
1164 case EM_CYGNUS_MN10200
:
1165 rtype
= elf_mn10200_reloc_type (type
);
1169 case EM_CYGNUS_FR30
:
1170 rtype
= elf_fr30_reloc_type (type
);
1174 rtype
= elf_frv_reloc_type (type
);
1178 rtype
= elf_mcore_reloc_type (type
);
1182 rtype
= elf_mmix_reloc_type (type
);
1187 rtype
= elf_msp430_reloc_type (type
);
1191 rtype
= elf_ppc_reloc_type (type
);
1195 rtype
= elf_ppc64_reloc_type (type
);
1199 case EM_MIPS_RS3_LE
:
1200 rtype
= elf_mips_reloc_type (type
);
1204 rtype
= elf_alpha_reloc_type (type
);
1208 rtype
= elf_arm_reloc_type (type
);
1212 rtype
= elf_arc_reloc_type (type
);
1216 rtype
= elf_hppa_reloc_type (type
);
1222 rtype
= elf_h8_reloc_type (type
);
1227 rtype
= elf_or32_reloc_type (type
);
1232 rtype
= elf_pj_reloc_type (type
);
1235 rtype
= elf_ia64_reloc_type (type
);
1239 rtype
= elf_cris_reloc_type (type
);
1243 rtype
= elf_i860_reloc_type (type
);
1247 rtype
= elf_x86_64_reloc_type (type
);
1251 rtype
= i370_reloc_type (type
);
1256 rtype
= elf_s390_reloc_type (type
);
1260 rtype
= elf_score_reloc_type (type
);
1264 rtype
= elf_xstormy16_reloc_type (type
);
1268 rtype
= elf_crx_reloc_type (type
);
1272 rtype
= elf_vax_reloc_type (type
);
1277 rtype
= elf_ip2k_reloc_type (type
);
1281 rtype
= elf_iq2000_reloc_type (type
);
1286 rtype
= elf_xtensa_reloc_type (type
);
1291 rtype
= elf_m32c_reloc_type (type
);
1295 rtype
= elf_mt_reloc_type (type
);
1299 rtype
= elf_bfin_reloc_type (type
);
1303 rtype
= elf_mep_reloc_type (type
);
1308 rtype
= elf_cr16_reloc_type (type
);
1313 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1315 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1317 if (elf_header
.e_machine
== EM_ALPHA
1319 && streq (rtype
, "R_ALPHA_LITUSE")
1322 switch (rels
[i
].r_addend
)
1324 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1325 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1326 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1327 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1328 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1329 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1330 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1331 default: rtype
= NULL
;
1334 printf (" (%s)", rtype
);
1338 printf (_("<unknown addend: %lx>"),
1339 (unsigned long) rels
[i
].r_addend
);
1342 else if (symtab_index
)
1344 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1345 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1348 Elf_Internal_Sym
*psym
;
1350 psym
= symtab
+ symtab_index
;
1353 print_vma (psym
->st_value
, LONG_HEX
);
1354 printf (is_32bit_elf
? " " : " ");
1356 if (psym
->st_name
== 0)
1358 const char *sec_name
= "<null>";
1361 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1363 if (psym
->st_shndx
< elf_header
.e_shnum
)
1365 = SECTION_NAME (section_headers
+ psym
->st_shndx
);
1366 else if (psym
->st_shndx
== SHN_ABS
)
1368 else if (psym
->st_shndx
== SHN_COMMON
)
1369 sec_name
= "COMMON";
1370 else if (elf_header
.e_machine
== EM_MIPS
1371 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1372 sec_name
= "SCOMMON";
1373 else if (elf_header
.e_machine
== EM_MIPS
1374 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1375 sec_name
= "SUNDEF";
1376 else if (elf_header
.e_machine
== EM_X86_64
1377 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1378 sec_name
= "LARGE_COMMON";
1379 else if (elf_header
.e_machine
== EM_IA_64
1380 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1381 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1382 sec_name
= "ANSI_COM";
1383 else if (elf_header
.e_machine
== EM_IA_64
1384 && (elf_header
.e_ident
[EI_OSABI
]
1385 == ELFOSABI_OPENVMS
)
1386 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
1387 sec_name
= "VMS_SYMVEC";
1390 sprintf (name_buf
, "<section 0x%x>",
1391 (unsigned int) psym
->st_shndx
);
1392 sec_name
= name_buf
;
1395 print_symbol (22, sec_name
);
1397 else if (strtab
== NULL
)
1398 printf (_("<string table index: %3ld>"), psym
->st_name
);
1399 else if (psym
->st_name
>= strtablen
)
1400 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1402 print_symbol (22, strtab
+ psym
->st_name
);
1405 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1410 printf ("%*c", is_32bit_elf
?
1411 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1412 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1415 if (elf_header
.e_machine
== EM_SPARCV9
1417 && streq (rtype
, "R_SPARC_OLO10"))
1418 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1423 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1425 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (info
);
1426 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (info
);
1427 const char *rtype2
= elf_mips_reloc_type (type2
);
1428 const char *rtype3
= elf_mips_reloc_type (type3
);
1430 printf (" Type2: ");
1433 printf (_("unrecognized: %-7lx"),
1434 (unsigned long) type2
& 0xffffffff);
1436 printf ("%-17.17s", rtype2
);
1438 printf ("\n Type3: ");
1441 printf (_("unrecognized: %-7lx"),
1442 (unsigned long) type3
& 0xffffffff);
1444 printf ("%-17.17s", rtype3
);
1455 get_mips_dynamic_type (unsigned long type
)
1459 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1460 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1461 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1462 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1463 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1464 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1465 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1466 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1467 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1468 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1469 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1470 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1471 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1472 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1473 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1474 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1475 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1476 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1477 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1478 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1479 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1480 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1481 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1482 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1483 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1484 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1485 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1486 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1487 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1488 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1489 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1490 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1491 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1492 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1493 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1494 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1495 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1496 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1497 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1498 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1499 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1500 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1501 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1508 get_sparc64_dynamic_type (unsigned long type
)
1512 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1519 get_ppc_dynamic_type (unsigned long type
)
1523 case DT_PPC_GOT
: return "PPC_GOT";
1530 get_ppc64_dynamic_type (unsigned long type
)
1534 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1535 case DT_PPC64_OPD
: return "PPC64_OPD";
1536 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1543 get_parisc_dynamic_type (unsigned long type
)
1547 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1548 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1549 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1550 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1551 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1552 case DT_HP_PREINIT
: return "HP_PREINIT";
1553 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1554 case DT_HP_NEEDED
: return "HP_NEEDED";
1555 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1556 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1557 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1558 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1559 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1560 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1561 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1562 case DT_HP_FILTERED
: return "HP_FILTERED";
1563 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1564 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1565 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1566 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1567 case DT_PLT
: return "PLT";
1568 case DT_PLT_SIZE
: return "PLT_SIZE";
1569 case DT_DLT
: return "DLT";
1570 case DT_DLT_SIZE
: return "DLT_SIZE";
1577 get_ia64_dynamic_type (unsigned long type
)
1581 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1582 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
1583 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
1584 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
1585 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
1586 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
1587 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
1588 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
1589 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
1590 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
1591 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
1592 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
1593 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
1594 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
1595 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
1596 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
1597 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
1598 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
1599 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
1600 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
1601 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
1602 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
1603 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
1604 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
1605 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
1606 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
1607 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
1608 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
1609 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
1610 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
1611 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
1618 get_alpha_dynamic_type (unsigned long type
)
1622 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1629 get_score_dynamic_type (unsigned long type
)
1633 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1634 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1635 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1636 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1637 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1638 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1646 get_dynamic_type (unsigned long type
)
1648 static char buff
[64];
1652 case DT_NULL
: return "NULL";
1653 case DT_NEEDED
: return "NEEDED";
1654 case DT_PLTRELSZ
: return "PLTRELSZ";
1655 case DT_PLTGOT
: return "PLTGOT";
1656 case DT_HASH
: return "HASH";
1657 case DT_STRTAB
: return "STRTAB";
1658 case DT_SYMTAB
: return "SYMTAB";
1659 case DT_RELA
: return "RELA";
1660 case DT_RELASZ
: return "RELASZ";
1661 case DT_RELAENT
: return "RELAENT";
1662 case DT_STRSZ
: return "STRSZ";
1663 case DT_SYMENT
: return "SYMENT";
1664 case DT_INIT
: return "INIT";
1665 case DT_FINI
: return "FINI";
1666 case DT_SONAME
: return "SONAME";
1667 case DT_RPATH
: return "RPATH";
1668 case DT_SYMBOLIC
: return "SYMBOLIC";
1669 case DT_REL
: return "REL";
1670 case DT_RELSZ
: return "RELSZ";
1671 case DT_RELENT
: return "RELENT";
1672 case DT_PLTREL
: return "PLTREL";
1673 case DT_DEBUG
: return "DEBUG";
1674 case DT_TEXTREL
: return "TEXTREL";
1675 case DT_JMPREL
: return "JMPREL";
1676 case DT_BIND_NOW
: return "BIND_NOW";
1677 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1678 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1679 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1680 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1681 case DT_RUNPATH
: return "RUNPATH";
1682 case DT_FLAGS
: return "FLAGS";
1684 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1685 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1687 case DT_CHECKSUM
: return "CHECKSUM";
1688 case DT_PLTPADSZ
: return "PLTPADSZ";
1689 case DT_MOVEENT
: return "MOVEENT";
1690 case DT_MOVESZ
: return "MOVESZ";
1691 case DT_FEATURE
: return "FEATURE";
1692 case DT_POSFLAG_1
: return "POSFLAG_1";
1693 case DT_SYMINSZ
: return "SYMINSZ";
1694 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1696 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1697 case DT_CONFIG
: return "CONFIG";
1698 case DT_DEPAUDIT
: return "DEPAUDIT";
1699 case DT_AUDIT
: return "AUDIT";
1700 case DT_PLTPAD
: return "PLTPAD";
1701 case DT_MOVETAB
: return "MOVETAB";
1702 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1704 case DT_VERSYM
: return "VERSYM";
1706 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1707 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1708 case DT_RELACOUNT
: return "RELACOUNT";
1709 case DT_RELCOUNT
: return "RELCOUNT";
1710 case DT_FLAGS_1
: return "FLAGS_1";
1711 case DT_VERDEF
: return "VERDEF";
1712 case DT_VERDEFNUM
: return "VERDEFNUM";
1713 case DT_VERNEED
: return "VERNEED";
1714 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1716 case DT_AUXILIARY
: return "AUXILIARY";
1717 case DT_USED
: return "USED";
1718 case DT_FILTER
: return "FILTER";
1720 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1721 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1722 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1723 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1724 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1725 case DT_GNU_HASH
: return "GNU_HASH";
1728 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1732 switch (elf_header
.e_machine
)
1735 case EM_MIPS_RS3_LE
:
1736 result
= get_mips_dynamic_type (type
);
1739 result
= get_sparc64_dynamic_type (type
);
1742 result
= get_ppc_dynamic_type (type
);
1745 result
= get_ppc64_dynamic_type (type
);
1748 result
= get_ia64_dynamic_type (type
);
1751 result
= get_alpha_dynamic_type (type
);
1754 result
= get_score_dynamic_type (type
);
1764 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1766 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1767 || (elf_header
.e_machine
== EM_PARISC
1768 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1772 switch (elf_header
.e_machine
)
1775 result
= get_parisc_dynamic_type (type
);
1778 result
= get_ia64_dynamic_type (type
);
1788 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1792 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1799 get_file_type (unsigned e_type
)
1801 static char buff
[32];
1805 case ET_NONE
: return _("NONE (None)");
1806 case ET_REL
: return _("REL (Relocatable file)");
1807 case ET_EXEC
: return _("EXEC (Executable file)");
1808 case ET_DYN
: return _("DYN (Shared object file)");
1809 case ET_CORE
: return _("CORE (Core file)");
1812 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1813 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1814 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1815 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1817 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1823 get_machine_name (unsigned e_machine
)
1825 static char buff
[64]; /* XXX */
1829 case EM_NONE
: return _("None");
1830 case EM_M32
: return "WE32100";
1831 case EM_SPARC
: return "Sparc";
1832 case EM_SPU
: return "SPU";
1833 case EM_386
: return "Intel 80386";
1834 case EM_68K
: return "MC68000";
1835 case EM_88K
: return "MC88000";
1836 case EM_486
: return "Intel 80486";
1837 case EM_860
: return "Intel 80860";
1838 case EM_MIPS
: return "MIPS R3000";
1839 case EM_S370
: return "IBM System/370";
1840 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1841 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1842 case EM_PARISC
: return "HPPA";
1843 case EM_PPC_OLD
: return "Power PC (old)";
1844 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1845 case EM_960
: return "Intel 90860";
1846 case EM_PPC
: return "PowerPC";
1847 case EM_PPC64
: return "PowerPC64";
1848 case EM_V800
: return "NEC V800";
1849 case EM_FR20
: return "Fujitsu FR20";
1850 case EM_RH32
: return "TRW RH32";
1851 case EM_MCORE
: return "MCORE";
1852 case EM_ARM
: return "ARM";
1853 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1854 case EM_SH
: return "Renesas / SuperH SH";
1855 case EM_SPARCV9
: return "Sparc v9";
1856 case EM_TRICORE
: return "Siemens Tricore";
1857 case EM_ARC
: return "ARC";
1858 case EM_H8_300
: return "Renesas H8/300";
1859 case EM_H8_300H
: return "Renesas H8/300H";
1860 case EM_H8S
: return "Renesas H8S";
1861 case EM_H8_500
: return "Renesas H8/500";
1862 case EM_IA_64
: return "Intel IA-64";
1863 case EM_MIPS_X
: return "Stanford MIPS-X";
1864 case EM_COLDFIRE
: return "Motorola Coldfire";
1865 case EM_68HC12
: return "Motorola M68HC12";
1866 case EM_ALPHA
: return "Alpha";
1867 case EM_CYGNUS_D10V
:
1868 case EM_D10V
: return "d10v";
1869 case EM_CYGNUS_D30V
:
1870 case EM_D30V
: return "d30v";
1871 case EM_CYGNUS_M32R
:
1872 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1873 case EM_CYGNUS_V850
:
1874 case EM_V850
: return "NEC v850";
1875 case EM_CYGNUS_MN10300
:
1876 case EM_MN10300
: return "mn10300";
1877 case EM_CYGNUS_MN10200
:
1878 case EM_MN10200
: return "mn10200";
1879 case EM_CYGNUS_FR30
:
1880 case EM_FR30
: return "Fujitsu FR30";
1881 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1883 case EM_PJ
: return "picoJava";
1884 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1885 case EM_PCP
: return "Siemens PCP";
1886 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1887 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1888 case EM_STARCORE
: return "Motorola Star*Core processor";
1889 case EM_ME16
: return "Toyota ME16 processor";
1890 case EM_ST100
: return "STMicroelectronics ST100 processor";
1891 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1892 case EM_FX66
: return "Siemens FX66 microcontroller";
1893 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1894 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1895 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1896 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1897 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1898 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1899 case EM_SVX
: return "Silicon Graphics SVx";
1900 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1901 case EM_VAX
: return "Digital VAX";
1903 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1904 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1905 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1906 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1907 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1908 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1909 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1910 case EM_PRISM
: return "Vitesse Prism";
1911 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1913 case EM_S390
: return "IBM S/390";
1914 case EM_SCORE
: return "SUNPLUS S+Core";
1915 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1917 case EM_OR32
: return "OpenRISC";
1918 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1919 case EM_DLX
: return "OpenDLX";
1921 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1922 case EM_IQ2000
: return "Vitesse IQ2000";
1924 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1926 case EM_M32C
: return "Renesas M32c";
1927 case EM_MT
: return "Morpho Techologies MT processor";
1928 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1929 case EM_NIOS32
: return "Altera Nios";
1930 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1931 case EM_XC16X
: return "Infineon Technologies xc16x";
1932 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1934 case EM_CR16_OLD
: return "National Semiconductor's CR16";
1936 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
1942 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1947 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1948 e_flags
&= ~ EF_ARM_EABIMASK
;
1950 /* Handle "generic" ARM flags. */
1951 if (e_flags
& EF_ARM_RELEXEC
)
1953 strcat (buf
, ", relocatable executable");
1954 e_flags
&= ~ EF_ARM_RELEXEC
;
1957 if (e_flags
& EF_ARM_HASENTRY
)
1959 strcat (buf
, ", has entry point");
1960 e_flags
&= ~ EF_ARM_HASENTRY
;
1963 /* Now handle EABI specific flags. */
1967 strcat (buf
, ", <unrecognized EABI>");
1972 case EF_ARM_EABI_VER1
:
1973 strcat (buf
, ", Version1 EABI");
1978 /* Process flags one bit at a time. */
1979 flag
= e_flags
& - e_flags
;
1984 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1985 strcat (buf
, ", sorted symbol tables");
1995 case EF_ARM_EABI_VER2
:
1996 strcat (buf
, ", Version2 EABI");
2001 /* Process flags one bit at a time. */
2002 flag
= e_flags
& - e_flags
;
2007 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2008 strcat (buf
, ", sorted symbol tables");
2011 case EF_ARM_DYNSYMSUSESEGIDX
:
2012 strcat (buf
, ", dynamic symbols use segment index");
2015 case EF_ARM_MAPSYMSFIRST
:
2016 strcat (buf
, ", mapping symbols precede others");
2026 case EF_ARM_EABI_VER3
:
2027 strcat (buf
, ", Version3 EABI");
2030 case EF_ARM_EABI_VER4
:
2031 strcat (buf
, ", Version4 EABI");
2034 case EF_ARM_EABI_VER5
:
2035 strcat (buf
, ", Version5 EABI");
2041 /* Process flags one bit at a time. */
2042 flag
= e_flags
& - e_flags
;
2048 strcat (buf
, ", BE8");
2052 strcat (buf
, ", LE8");
2062 case EF_ARM_EABI_UNKNOWN
:
2063 strcat (buf
, ", GNU EABI");
2068 /* Process flags one bit at a time. */
2069 flag
= e_flags
& - e_flags
;
2074 case EF_ARM_INTERWORK
:
2075 strcat (buf
, ", interworking enabled");
2078 case EF_ARM_APCS_26
:
2079 strcat (buf
, ", uses APCS/26");
2082 case EF_ARM_APCS_FLOAT
:
2083 strcat (buf
, ", uses APCS/float");
2087 strcat (buf
, ", position independent");
2091 strcat (buf
, ", 8 bit structure alignment");
2094 case EF_ARM_NEW_ABI
:
2095 strcat (buf
, ", uses new ABI");
2098 case EF_ARM_OLD_ABI
:
2099 strcat (buf
, ", uses old ABI");
2102 case EF_ARM_SOFT_FLOAT
:
2103 strcat (buf
, ", software FP");
2106 case EF_ARM_VFP_FLOAT
:
2107 strcat (buf
, ", VFP");
2110 case EF_ARM_MAVERICK_FLOAT
:
2111 strcat (buf
, ", Maverick FP");
2122 strcat (buf
,", <unknown>");
2126 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
2128 static char buf
[1024];
2140 decode_ARM_machine_flags (e_flags
, buf
);
2144 switch (e_flags
& EF_FRV_CPU_MASK
)
2146 case EF_FRV_CPU_GENERIC
:
2150 strcat (buf
, ", fr???");
2153 case EF_FRV_CPU_FR300
:
2154 strcat (buf
, ", fr300");
2157 case EF_FRV_CPU_FR400
:
2158 strcat (buf
, ", fr400");
2160 case EF_FRV_CPU_FR405
:
2161 strcat (buf
, ", fr405");
2164 case EF_FRV_CPU_FR450
:
2165 strcat (buf
, ", fr450");
2168 case EF_FRV_CPU_FR500
:
2169 strcat (buf
, ", fr500");
2171 case EF_FRV_CPU_FR550
:
2172 strcat (buf
, ", fr550");
2175 case EF_FRV_CPU_SIMPLE
:
2176 strcat (buf
, ", simple");
2178 case EF_FRV_CPU_TOMCAT
:
2179 strcat (buf
, ", tomcat");
2185 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2186 strcat (buf
, ", m68000");
2187 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2188 strcat (buf
, ", cpu32");
2189 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2190 strcat (buf
, ", fido_a");
2193 char const *isa
= _("unknown");
2194 char const *mac
= _("unknown mac");
2195 char const *additional
= NULL
;
2197 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2199 case EF_M68K_CF_ISA_A_NODIV
:
2201 additional
= ", nodiv";
2203 case EF_M68K_CF_ISA_A
:
2206 case EF_M68K_CF_ISA_A_PLUS
:
2209 case EF_M68K_CF_ISA_B_NOUSP
:
2211 additional
= ", nousp";
2213 case EF_M68K_CF_ISA_B
:
2217 strcat (buf
, ", cf, isa ");
2220 strcat (buf
, additional
);
2221 if (e_flags
& EF_M68K_CF_FLOAT
)
2222 strcat (buf
, ", float");
2223 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2228 case EF_M68K_CF_MAC
:
2231 case EF_M68K_CF_EMAC
:
2244 if (e_flags
& EF_PPC_EMB
)
2245 strcat (buf
, ", emb");
2247 if (e_flags
& EF_PPC_RELOCATABLE
)
2248 strcat (buf
, ", relocatable");
2250 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2251 strcat (buf
, ", relocatable-lib");
2255 case EM_CYGNUS_V850
:
2256 switch (e_flags
& EF_V850_ARCH
)
2259 strcat (buf
, ", v850e1");
2262 strcat (buf
, ", v850e");
2265 strcat (buf
, ", v850");
2268 strcat (buf
, ", unknown v850 architecture variant");
2274 case EM_CYGNUS_M32R
:
2275 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2276 strcat (buf
, ", m32r");
2280 case EM_MIPS_RS3_LE
:
2281 if (e_flags
& EF_MIPS_NOREORDER
)
2282 strcat (buf
, ", noreorder");
2284 if (e_flags
& EF_MIPS_PIC
)
2285 strcat (buf
, ", pic");
2287 if (e_flags
& EF_MIPS_CPIC
)
2288 strcat (buf
, ", cpic");
2290 if (e_flags
& EF_MIPS_UCODE
)
2291 strcat (buf
, ", ugen_reserved");
2293 if (e_flags
& EF_MIPS_ABI2
)
2294 strcat (buf
, ", abi2");
2296 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2297 strcat (buf
, ", odk first");
2299 if (e_flags
& EF_MIPS_32BITMODE
)
2300 strcat (buf
, ", 32bitmode");
2302 switch ((e_flags
& EF_MIPS_MACH
))
2304 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2305 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2306 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2307 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2308 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2309 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2310 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2311 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2312 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2313 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2314 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
2315 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
2316 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
2318 /* We simply ignore the field in this case to avoid confusion:
2319 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2322 default: strcat (buf
, ", unknown CPU"); break;
2325 switch ((e_flags
& EF_MIPS_ABI
))
2327 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2328 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2329 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2330 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2332 /* We simply ignore the field in this case to avoid confusion:
2333 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2334 This means it is likely to be an o32 file, but not for
2337 default: strcat (buf
, ", unknown ABI"); break;
2340 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2341 strcat (buf
, ", mdmx");
2343 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2344 strcat (buf
, ", mips16");
2346 switch ((e_flags
& EF_MIPS_ARCH
))
2348 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2349 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2350 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2351 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2352 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2353 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2354 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2355 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2356 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2357 default: strcat (buf
, ", unknown ISA"); break;
2363 switch ((e_flags
& EF_SH_MACH_MASK
))
2365 case EF_SH1
: strcat (buf
, ", sh1"); break;
2366 case EF_SH2
: strcat (buf
, ", sh2"); break;
2367 case EF_SH3
: strcat (buf
, ", sh3"); break;
2368 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2369 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2370 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2371 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2372 case EF_SH4
: strcat (buf
, ", sh4"); break;
2373 case EF_SH5
: strcat (buf
, ", sh5"); break;
2374 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2375 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2376 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2377 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2378 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2379 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2380 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2381 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2382 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2383 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2384 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2385 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2386 default: strcat (buf
, ", unknown ISA"); break;
2392 if (e_flags
& EF_SPARC_32PLUS
)
2393 strcat (buf
, ", v8+");
2395 if (e_flags
& EF_SPARC_SUN_US1
)
2396 strcat (buf
, ", ultrasparcI");
2398 if (e_flags
& EF_SPARC_SUN_US3
)
2399 strcat (buf
, ", ultrasparcIII");
2401 if (e_flags
& EF_SPARC_HAL_R1
)
2402 strcat (buf
, ", halr1");
2404 if (e_flags
& EF_SPARC_LEDATA
)
2405 strcat (buf
, ", ledata");
2407 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2408 strcat (buf
, ", tso");
2410 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2411 strcat (buf
, ", pso");
2413 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2414 strcat (buf
, ", rmo");
2418 switch (e_flags
& EF_PARISC_ARCH
)
2420 case EFA_PARISC_1_0
:
2421 strcpy (buf
, ", PA-RISC 1.0");
2423 case EFA_PARISC_1_1
:
2424 strcpy (buf
, ", PA-RISC 1.1");
2426 case EFA_PARISC_2_0
:
2427 strcpy (buf
, ", PA-RISC 2.0");
2432 if (e_flags
& EF_PARISC_TRAPNIL
)
2433 strcat (buf
, ", trapnil");
2434 if (e_flags
& EF_PARISC_EXT
)
2435 strcat (buf
, ", ext");
2436 if (e_flags
& EF_PARISC_LSB
)
2437 strcat (buf
, ", lsb");
2438 if (e_flags
& EF_PARISC_WIDE
)
2439 strcat (buf
, ", wide");
2440 if (e_flags
& EF_PARISC_NO_KABP
)
2441 strcat (buf
, ", no kabp");
2442 if (e_flags
& EF_PARISC_LAZYSWAP
)
2443 strcat (buf
, ", lazyswap");
2448 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2449 strcat (buf
, ", new calling convention");
2451 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2452 strcat (buf
, ", gnu calling convention");
2456 if ((e_flags
& EF_IA_64_ABI64
))
2457 strcat (buf
, ", 64-bit");
2459 strcat (buf
, ", 32-bit");
2460 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2461 strcat (buf
, ", reduced fp model");
2462 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2463 strcat (buf
, ", no function descriptors, constant gp");
2464 else if ((e_flags
& EF_IA_64_CONS_GP
))
2465 strcat (buf
, ", constant gp");
2466 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2467 strcat (buf
, ", absolute");
2471 if ((e_flags
& EF_VAX_NONPIC
))
2472 strcat (buf
, ", non-PIC");
2473 if ((e_flags
& EF_VAX_DFLOAT
))
2474 strcat (buf
, ", D-Float");
2475 if ((e_flags
& EF_VAX_GFLOAT
))
2476 strcat (buf
, ", G-Float");
2485 get_osabi_name (unsigned int osabi
)
2487 static char buff
[32];
2491 case ELFOSABI_NONE
: return "UNIX - System V";
2492 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2493 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2494 case ELFOSABI_LINUX
: return "UNIX - Linux";
2495 case ELFOSABI_HURD
: return "GNU/Hurd";
2496 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2497 case ELFOSABI_AIX
: return "UNIX - AIX";
2498 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2499 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2500 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2501 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2502 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2503 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2504 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2505 case ELFOSABI_AROS
: return "Amiga Research OS";
2506 case ELFOSABI_STANDALONE
: return _("Standalone App");
2507 case ELFOSABI_ARM
: return "ARM";
2509 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2515 get_arm_segment_type (unsigned long type
)
2529 get_mips_segment_type (unsigned long type
)
2533 case PT_MIPS_REGINFO
:
2535 case PT_MIPS_RTPROC
:
2537 case PT_MIPS_OPTIONS
:
2547 get_parisc_segment_type (unsigned long type
)
2551 case PT_HP_TLS
: return "HP_TLS";
2552 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2553 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2554 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2555 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2556 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2557 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2558 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2559 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2560 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2561 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2562 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2563 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2564 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2565 case PT_HP_STACK
: return "HP_STACK";
2566 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2567 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2568 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2569 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2578 get_ia64_segment_type (unsigned long type
)
2582 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2583 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2584 case PT_HP_TLS
: return "HP_TLS";
2585 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2586 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2587 case PT_IA_64_HP_STACK
: return "HP_STACK";
2596 get_segment_type (unsigned long p_type
)
2598 static char buff
[32];
2602 case PT_NULL
: return "NULL";
2603 case PT_LOAD
: return "LOAD";
2604 case PT_DYNAMIC
: return "DYNAMIC";
2605 case PT_INTERP
: return "INTERP";
2606 case PT_NOTE
: return "NOTE";
2607 case PT_SHLIB
: return "SHLIB";
2608 case PT_PHDR
: return "PHDR";
2609 case PT_TLS
: return "TLS";
2611 case PT_GNU_EH_FRAME
:
2612 return "GNU_EH_FRAME";
2613 case PT_GNU_STACK
: return "GNU_STACK";
2614 case PT_GNU_RELRO
: return "GNU_RELRO";
2617 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2621 switch (elf_header
.e_machine
)
2624 result
= get_arm_segment_type (p_type
);
2627 case EM_MIPS_RS3_LE
:
2628 result
= get_mips_segment_type (p_type
);
2631 result
= get_parisc_segment_type (p_type
);
2634 result
= get_ia64_segment_type (p_type
);
2644 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2646 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2650 switch (elf_header
.e_machine
)
2653 result
= get_parisc_segment_type (p_type
);
2656 result
= get_ia64_segment_type (p_type
);
2666 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2669 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2676 get_mips_section_type_name (unsigned int sh_type
)
2680 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2681 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2682 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2683 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2684 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2685 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2686 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2687 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2688 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2689 case SHT_MIPS_RELD
: return "MIPS_RELD";
2690 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2691 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2692 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2693 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2694 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2695 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2696 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2697 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2698 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2699 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2700 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2701 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2702 case SHT_MIPS_LINE
: return "MIPS_LINE";
2703 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2704 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2705 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2706 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2707 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2708 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2709 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2710 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2711 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2712 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2713 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2714 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2715 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2716 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2717 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2718 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2726 get_parisc_section_type_name (unsigned int sh_type
)
2730 case SHT_PARISC_EXT
: return "PARISC_EXT";
2731 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2732 case SHT_PARISC_DOC
: return "PARISC_DOC";
2733 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2734 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2735 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2736 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2744 get_ia64_section_type_name (unsigned int sh_type
)
2746 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2747 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2748 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2752 case SHT_IA_64_EXT
: return "IA_64_EXT";
2753 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2754 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2755 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
2756 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
2757 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
2758 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
2759 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
2760 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
2761 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
2769 get_x86_64_section_type_name (unsigned int sh_type
)
2773 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2781 get_arm_section_type_name (unsigned int sh_type
)
2787 case SHT_ARM_PREEMPTMAP
:
2788 return "ARM_PREEMPTMAP";
2789 case SHT_ARM_ATTRIBUTES
:
2790 return "ARM_ATTRIBUTES";
2798 get_section_type_name (unsigned int sh_type
)
2800 static char buff
[32];
2804 case SHT_NULL
: return "NULL";
2805 case SHT_PROGBITS
: return "PROGBITS";
2806 case SHT_SYMTAB
: return "SYMTAB";
2807 case SHT_STRTAB
: return "STRTAB";
2808 case SHT_RELA
: return "RELA";
2809 case SHT_HASH
: return "HASH";
2810 case SHT_DYNAMIC
: return "DYNAMIC";
2811 case SHT_NOTE
: return "NOTE";
2812 case SHT_NOBITS
: return "NOBITS";
2813 case SHT_REL
: return "REL";
2814 case SHT_SHLIB
: return "SHLIB";
2815 case SHT_DYNSYM
: return "DYNSYM";
2816 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2817 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2818 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2819 case SHT_GNU_HASH
: return "GNU_HASH";
2820 case SHT_GROUP
: return "GROUP";
2821 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2822 case SHT_GNU_verdef
: return "VERDEF";
2823 case SHT_GNU_verneed
: return "VERNEED";
2824 case SHT_GNU_versym
: return "VERSYM";
2825 case 0x6ffffff0: return "VERSYM";
2826 case 0x6ffffffc: return "VERDEF";
2827 case 0x7ffffffd: return "AUXILIARY";
2828 case 0x7fffffff: return "FILTER";
2829 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2832 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2836 switch (elf_header
.e_machine
)
2839 case EM_MIPS_RS3_LE
:
2840 result
= get_mips_section_type_name (sh_type
);
2843 result
= get_parisc_section_type_name (sh_type
);
2846 result
= get_ia64_section_type_name (sh_type
);
2849 result
= get_x86_64_section_type_name (sh_type
);
2852 result
= get_arm_section_type_name (sh_type
);
2862 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2864 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2868 switch (elf_header
.e_machine
)
2871 result
= get_ia64_section_type_name (sh_type
);
2881 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2883 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2884 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2886 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2892 #define OPTION_DEBUG_DUMP 512
2894 static struct option options
[] =
2896 {"all", no_argument
, 0, 'a'},
2897 {"file-header", no_argument
, 0, 'h'},
2898 {"program-headers", no_argument
, 0, 'l'},
2899 {"headers", no_argument
, 0, 'e'},
2900 {"histogram", no_argument
, 0, 'I'},
2901 {"segments", no_argument
, 0, 'l'},
2902 {"sections", no_argument
, 0, 'S'},
2903 {"section-headers", no_argument
, 0, 'S'},
2904 {"section-groups", no_argument
, 0, 'g'},
2905 {"section-details", no_argument
, 0, 't'},
2906 {"full-section-name",no_argument
, 0, 'N'},
2907 {"symbols", no_argument
, 0, 's'},
2908 {"syms", no_argument
, 0, 's'},
2909 {"relocs", no_argument
, 0, 'r'},
2910 {"notes", no_argument
, 0, 'n'},
2911 {"dynamic", no_argument
, 0, 'd'},
2912 {"arch-specific", no_argument
, 0, 'A'},
2913 {"version-info", no_argument
, 0, 'V'},
2914 {"use-dynamic", no_argument
, 0, 'D'},
2915 {"unwind", no_argument
, 0, 'u'},
2916 {"archive-index", no_argument
, 0, 'c'},
2917 {"hex-dump", required_argument
, 0, 'x'},
2918 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2919 {"string-dump", required_argument
, 0, 'p'},
2920 #ifdef SUPPORT_DISASSEMBLY
2921 {"instruction-dump", required_argument
, 0, 'i'},
2924 {"version", no_argument
, 0, 'v'},
2925 {"wide", no_argument
, 0, 'W'},
2926 {"help", no_argument
, 0, 'H'},
2927 {0, no_argument
, 0, 0}
2931 usage (FILE *stream
)
2933 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2934 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
2935 fprintf (stream
, _(" Options are:\n\
2936 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2937 -h --file-header Display the ELF file header\n\
2938 -l --program-headers Display the program headers\n\
2939 --segments An alias for --program-headers\n\
2940 -S --section-headers Display the sections' header\n\
2941 --sections An alias for --section-headers\n\
2942 -g --section-groups Display the section groups\n\
2943 -t --section-details Display the section details\n\
2944 -e --headers Equivalent to: -h -l -S\n\
2945 -s --syms Display the symbol table\n\
2946 --symbols An alias for --syms\n\
2947 -n --notes Display the core notes (if present)\n\
2948 -r --relocs Display the relocations (if present)\n\
2949 -u --unwind Display the unwind info (if present)\n\
2950 -d --dynamic Display the dynamic section (if present)\n\
2951 -V --version-info Display the version sections (if present)\n\
2952 -A --arch-specific Display architecture specific information (if any).\n\
2953 -c --archive-index Display the symbol/file index in an archive\n\
2954 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2955 -x --hex-dump=<number|name>\n\
2956 Dump the contents of section <number|name> as bytes\n\
2957 -p --string-dump=<number|name>\n\
2958 Dump the contents of section <number|name> as strings\n\
2959 -w[lLiaprmfFsoR] or\n\
2960 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2961 Display the contents of DWARF2 debug sections\n"));
2962 #ifdef SUPPORT_DISASSEMBLY
2963 fprintf (stream
, _("\
2964 -i --instruction-dump=<number|name>\n\
2965 Disassemble the contents of section <number|name>\n"));
2967 fprintf (stream
, _("\
2968 -I --histogram Display histogram of bucket list lengths\n\
2969 -W --wide Allow output width to exceed 80 characters\n\
2970 @<file> Read options from <file>\n\
2971 -H --help Display this information\n\
2972 -v --version Display the version number of readelf\n"));
2974 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2975 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2977 exit (stream
== stdout
? 0 : 1);
2980 /* Record the fact that the user wants the contents of section number
2981 SECTION to be displayed using the method(s) encoded as flags bits
2982 in TYPE. Note, TYPE can be zero if we are creating the array for
2986 request_dump_bynumber (unsigned int section
, dump_type type
)
2988 if (section
>= num_dump_sects
)
2990 dump_type
*new_dump_sects
;
2992 new_dump_sects
= calloc (section
+ 1, sizeof (* dump_sects
));
2994 if (new_dump_sects
== NULL
)
2995 error (_("Out of memory allocating dump request table.\n"));
2998 /* Copy current flag settings. */
2999 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
* sizeof (* dump_sects
));
3003 dump_sects
= new_dump_sects
;
3004 num_dump_sects
= section
+ 1;
3009 dump_sects
[section
] |= type
;
3014 /* Request a dump by section name. */
3017 request_dump_byname (const char *section
, dump_type type
)
3019 struct dump_list_entry
*new_request
;
3021 new_request
= malloc (sizeof (struct dump_list_entry
));
3023 error (_("Out of memory allocating dump request table.\n"));
3025 new_request
->name
= strdup (section
);
3026 if (!new_request
->name
)
3027 error (_("Out of memory allocating dump request table.\n"));
3029 new_request
->type
= type
;
3031 new_request
->next
= dump_sects_byname
;
3032 dump_sects_byname
= new_request
;
3036 parse_args (int argc
, char **argv
)
3043 while ((c
= getopt_long
3044 (argc
, argv
, "ADHINSVWacdeghi:lnp:rstuvw::x:", options
, NULL
)) != EOF
)
3065 do_section_groups
++;
3073 do_section_groups
++;
3078 do_section_details
++;
3123 section
= strtoul (optarg
, & cp
, 0);
3124 if (! *cp
&& section
>= 0)
3125 request_dump_bynumber (section
, HEX_DUMP
);
3127 request_dump_byname (optarg
, HEX_DUMP
);
3131 section
= strtoul (optarg
, & cp
, 0);
3132 if (! *cp
&& section
>= 0)
3133 request_dump_bynumber (section
, STRING_DUMP
);
3135 request_dump_byname (optarg
, STRING_DUMP
);
3143 unsigned int index
= 0;
3147 while (optarg
[index
])
3148 switch (optarg
[index
++])
3155 do_debug_abbrevs
= 1;
3163 do_debug_lines_decoded
= 1;
3167 do_debug_pubnames
= 1;
3171 do_debug_aranges
= 1;
3175 do_debug_ranges
= 1;
3179 do_debug_frames_interp
= 1;
3181 do_debug_frames
= 1;
3185 do_debug_macinfo
= 1;
3197 warn (_("Unrecognized debug option '%s'\n"), optarg
);
3202 case OPTION_DEBUG_DUMP
:
3210 const char * option
;
3213 debug_dump_long_opts
;
3215 debug_dump_long_opts opts_table
[] =
3217 /* Please keep this table alpha- sorted. */
3218 { "Ranges", & do_debug_ranges
},
3219 { "abbrev", & do_debug_abbrevs
},
3220 { "aranges", & do_debug_aranges
},
3221 { "frames", & do_debug_frames
},
3222 { "frames-interp", & do_debug_frames_interp
},
3223 { "info", & do_debug_info
},
3224 { "line", & do_debug_lines
}, /* For backwards compatibility. */
3225 { "rawline", & do_debug_lines
},
3226 { "decodedline", & do_debug_lines_decoded
},
3227 { "loc", & do_debug_loc
},
3228 { "macro", & do_debug_macinfo
},
3229 { "pubnames", & do_debug_pubnames
},
3230 /* This entry is for compatability
3231 with earlier versions of readelf. */
3232 { "ranges", & do_debug_aranges
},
3233 { "str", & do_debug_str
},
3244 debug_dump_long_opts
* entry
;
3246 for (entry
= opts_table
; entry
->option
; entry
++)
3248 size_t len
= strlen (entry
->option
);
3250 if (strneq (p
, entry
->option
, len
)
3251 && (p
[len
] == ',' || p
[len
] == '\0'))
3253 * entry
->variable
= 1;
3255 /* The --debug-dump=frames-interp option also
3256 enables the --debug-dump=frames option. */
3257 if (do_debug_frames_interp
)
3258 do_debug_frames
= 1;
3265 if (entry
->option
== NULL
)
3267 warn (_("Unrecognized debug option '%s'\n"), p
);
3268 p
= strchr (p
, ',');
3278 #ifdef SUPPORT_DISASSEMBLY
3281 section
= strtoul (optarg
, & cp
, 0);
3282 if (! *cp
&& section
>= 0)
3283 request_dump_bynumber (section
, DISASS_DUMP
);
3285 request_dump_byname (optarg
, DISASS_DUMP
);
3288 print_version (program_name
);
3297 /* xgettext:c-format */
3298 error (_("Invalid option '-%c'\n"), c
);
3305 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3306 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3307 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3308 && !do_section_groups
&& !do_archive_index
)
3312 warn (_("Nothing to do.\n"));
3318 get_elf_class (unsigned int elf_class
)
3320 static char buff
[32];
3324 case ELFCLASSNONE
: return _("none");
3325 case ELFCLASS32
: return "ELF32";
3326 case ELFCLASS64
: return "ELF64";
3328 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3334 get_data_encoding (unsigned int encoding
)
3336 static char buff
[32];
3340 case ELFDATANONE
: return _("none");
3341 case ELFDATA2LSB
: return _("2's complement, little endian");
3342 case ELFDATA2MSB
: return _("2's complement, big endian");
3344 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3349 /* Decode the data held in 'elf_header'. */
3352 process_file_header (void)
3354 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3355 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3356 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3357 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3360 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3364 init_dwarf_regnames (elf_header
.e_machine
);
3370 printf (_("ELF Header:\n"));
3371 printf (_(" Magic: "));
3372 for (i
= 0; i
< EI_NIDENT
; i
++)
3373 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3375 printf (_(" Class: %s\n"),
3376 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3377 printf (_(" Data: %s\n"),
3378 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3379 printf (_(" Version: %d %s\n"),
3380 elf_header
.e_ident
[EI_VERSION
],
3381 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3383 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3386 printf (_(" OS/ABI: %s\n"),
3387 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3388 printf (_(" ABI Version: %d\n"),
3389 elf_header
.e_ident
[EI_ABIVERSION
]);
3390 printf (_(" Type: %s\n"),
3391 get_file_type (elf_header
.e_type
));
3392 printf (_(" Machine: %s\n"),
3393 get_machine_name (elf_header
.e_machine
));
3394 printf (_(" Version: 0x%lx\n"),
3395 (unsigned long) elf_header
.e_version
);
3397 printf (_(" Entry point address: "));
3398 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3399 printf (_("\n Start of program headers: "));
3400 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3401 printf (_(" (bytes into file)\n Start of section headers: "));
3402 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3403 printf (_(" (bytes into file)\n"));
3405 printf (_(" Flags: 0x%lx%s\n"),
3406 (unsigned long) elf_header
.e_flags
,
3407 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3408 printf (_(" Size of this header: %ld (bytes)\n"),
3409 (long) elf_header
.e_ehsize
);
3410 printf (_(" Size of program headers: %ld (bytes)\n"),
3411 (long) elf_header
.e_phentsize
);
3412 printf (_(" Number of program headers: %ld\n"),
3413 (long) elf_header
.e_phnum
);
3414 printf (_(" Size of section headers: %ld (bytes)\n"),
3415 (long) elf_header
.e_shentsize
);
3416 printf (_(" Number of section headers: %ld"),
3417 (long) elf_header
.e_shnum
);
3418 if (section_headers
!= NULL
&& elf_header
.e_shnum
== SHN_UNDEF
)
3419 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3420 putc ('\n', stdout
);
3421 printf (_(" Section header string table index: %ld"),
3422 (long) elf_header
.e_shstrndx
);
3423 if (section_headers
!= NULL
3424 && elf_header
.e_shstrndx
== (SHN_XINDEX
& 0xffff))
3425 printf (" (%u)", section_headers
[0].sh_link
);
3426 else if (elf_header
.e_shstrndx
>= elf_header
.e_shnum
)
3427 printf (" <corrupt: out of range>");
3428 putc ('\n', stdout
);
3431 if (section_headers
!= NULL
)
3433 if (elf_header
.e_shnum
== SHN_UNDEF
)
3434 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3435 if (elf_header
.e_shstrndx
== (SHN_XINDEX
& 0xffff))
3436 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3437 else if (elf_header
.e_shstrndx
>= elf_header
.e_shnum
)
3438 elf_header
.e_shstrndx
= SHN_UNDEF
;
3439 free (section_headers
);
3440 section_headers
= NULL
;
3448 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3450 Elf32_External_Phdr
*phdrs
;
3451 Elf32_External_Phdr
*external
;
3452 Elf_Internal_Phdr
*internal
;
3455 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3456 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3457 _("program headers"));
3461 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3462 i
< elf_header
.e_phnum
;
3463 i
++, internal
++, external
++)
3465 internal
->p_type
= BYTE_GET (external
->p_type
);
3466 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3467 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3468 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3469 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3470 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3471 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3472 internal
->p_align
= BYTE_GET (external
->p_align
);
3481 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3483 Elf64_External_Phdr
*phdrs
;
3484 Elf64_External_Phdr
*external
;
3485 Elf_Internal_Phdr
*internal
;
3488 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3489 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3490 _("program headers"));
3494 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3495 i
< elf_header
.e_phnum
;
3496 i
++, internal
++, external
++)
3498 internal
->p_type
= BYTE_GET (external
->p_type
);
3499 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3500 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3501 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3502 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3503 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3504 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3505 internal
->p_align
= BYTE_GET (external
->p_align
);
3513 /* Returns 1 if the program headers were read into `program_headers'. */
3516 get_program_headers (FILE *file
)
3518 Elf_Internal_Phdr
*phdrs
;
3520 /* Check cache of prior read. */
3521 if (program_headers
!= NULL
)
3524 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3528 error (_("Out of memory\n"));
3533 ? get_32bit_program_headers (file
, phdrs
)
3534 : get_64bit_program_headers (file
, phdrs
))
3536 program_headers
= phdrs
;
3544 /* Returns 1 if the program headers were loaded. */
3547 process_program_headers (FILE *file
)
3549 Elf_Internal_Phdr
*segment
;
3552 if (elf_header
.e_phnum
== 0)
3555 printf (_("\nThere are no program headers in this file.\n"));
3559 if (do_segments
&& !do_header
)
3561 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3562 printf (_("Entry point "));
3563 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3564 printf (_("\nThere are %d program headers, starting at offset "),
3565 elf_header
.e_phnum
);
3566 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3570 if (! get_program_headers (file
))
3575 if (elf_header
.e_phnum
> 1)
3576 printf (_("\nProgram Headers:\n"));
3578 printf (_("\nProgram Headers:\n"));
3582 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3585 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3589 (_(" Type Offset VirtAddr PhysAddr\n"));
3591 (_(" FileSiz MemSiz Flags Align\n"));
3598 for (i
= 0, segment
= program_headers
;
3599 i
< elf_header
.e_phnum
;
3604 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3608 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3609 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3610 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3611 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3612 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3614 (segment
->p_flags
& PF_R
? 'R' : ' '),
3615 (segment
->p_flags
& PF_W
? 'W' : ' '),
3616 (segment
->p_flags
& PF_X
? 'E' : ' '));
3617 printf ("%#lx", (unsigned long) segment
->p_align
);
3621 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3622 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3625 print_vma (segment
->p_offset
, FULL_HEX
);
3629 print_vma (segment
->p_vaddr
, FULL_HEX
);
3631 print_vma (segment
->p_paddr
, FULL_HEX
);
3634 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3635 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3638 print_vma (segment
->p_filesz
, FULL_HEX
);
3642 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3643 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3646 print_vma (segment
->p_offset
, FULL_HEX
);
3650 (segment
->p_flags
& PF_R
? 'R' : ' '),
3651 (segment
->p_flags
& PF_W
? 'W' : ' '),
3652 (segment
->p_flags
& PF_X
? 'E' : ' '));
3654 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3655 printf ("%#lx", (unsigned long) segment
->p_align
);
3658 print_vma (segment
->p_align
, PREFIX_HEX
);
3663 print_vma (segment
->p_offset
, FULL_HEX
);
3665 print_vma (segment
->p_vaddr
, FULL_HEX
);
3667 print_vma (segment
->p_paddr
, FULL_HEX
);
3669 print_vma (segment
->p_filesz
, FULL_HEX
);
3671 print_vma (segment
->p_memsz
, FULL_HEX
);
3673 (segment
->p_flags
& PF_R
? 'R' : ' '),
3674 (segment
->p_flags
& PF_W
? 'W' : ' '),
3675 (segment
->p_flags
& PF_X
? 'E' : ' '));
3676 print_vma (segment
->p_align
, HEX
);
3680 switch (segment
->p_type
)
3684 error (_("more than one dynamic segment\n"));
3686 /* By default, assume that the .dynamic section is the first
3687 section in the DYNAMIC segment. */
3688 dynamic_addr
= segment
->p_offset
;
3689 dynamic_size
= segment
->p_filesz
;
3691 /* Try to locate the .dynamic section. If there is
3692 a section header table, we can easily locate it. */
3693 if (section_headers
!= NULL
)
3695 Elf_Internal_Shdr
*sec
;
3697 sec
= find_section (".dynamic");
3698 if (sec
== NULL
|| sec
->sh_size
== 0)
3700 error (_("no .dynamic section in the dynamic segment\n"));
3704 if (sec
->sh_type
== SHT_NOBITS
)
3710 dynamic_addr
= sec
->sh_offset
;
3711 dynamic_size
= sec
->sh_size
;
3713 if (dynamic_addr
< segment
->p_offset
3714 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3715 warn (_("the .dynamic section is not contained"
3716 " within the dynamic segment\n"));
3717 else if (dynamic_addr
> segment
->p_offset
)
3718 warn (_("the .dynamic section is not the first section"
3719 " in the dynamic segment.\n"));
3724 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3726 error (_("Unable to find program interpreter name\n"));
3730 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3732 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3733 error (_("Internal error: failed to create format string to display program interpreter\n"));
3735 program_interpreter
[0] = 0;
3736 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3737 error (_("Unable to read program interpreter name\n"));
3740 printf (_("\n [Requesting program interpreter: %s]"),
3741 program_interpreter
);
3747 putc ('\n', stdout
);
3750 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3752 printf (_("\n Section to Segment mapping:\n"));
3753 printf (_(" Segment Sections...\n"));
3755 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3758 Elf_Internal_Shdr
*section
;
3760 segment
= program_headers
+ i
;
3761 section
= section_headers
+ 1;
3763 printf (" %2.2d ", i
);
3765 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3767 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section
, segment
))
3768 printf ("%s ", SECTION_NAME (section
));
3779 /* Find the file offset corresponding to VMA by using the program headers. */
3782 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3784 Elf_Internal_Phdr
*seg
;
3786 if (! get_program_headers (file
))
3788 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3792 for (seg
= program_headers
;
3793 seg
< program_headers
+ elf_header
.e_phnum
;
3796 if (seg
->p_type
!= PT_LOAD
)
3799 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3800 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3801 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3804 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3811 get_32bit_section_headers (FILE *file
, unsigned int num
)
3813 Elf32_External_Shdr
*shdrs
;
3814 Elf_Internal_Shdr
*internal
;
3817 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3818 elf_header
.e_shentsize
, num
, _("section headers"));
3822 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3824 if (section_headers
== NULL
)
3826 error (_("Out of memory\n"));
3830 for (i
= 0, internal
= section_headers
;
3834 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3835 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3836 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3837 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3838 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3839 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3840 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3841 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3842 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3843 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3852 get_64bit_section_headers (FILE *file
, unsigned int num
)
3854 Elf64_External_Shdr
*shdrs
;
3855 Elf_Internal_Shdr
*internal
;
3858 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3859 elf_header
.e_shentsize
, num
, _("section headers"));
3863 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3865 if (section_headers
== NULL
)
3867 error (_("Out of memory\n"));
3871 for (i
= 0, internal
= section_headers
;
3875 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3876 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3877 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3878 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3879 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3880 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3881 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3882 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3883 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3884 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3892 static Elf_Internal_Sym
*
3893 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3895 unsigned long number
;
3896 Elf32_External_Sym
*esyms
;
3897 Elf_External_Sym_Shndx
*shndx
;
3898 Elf_Internal_Sym
*isyms
;
3899 Elf_Internal_Sym
*psym
;
3902 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3908 if (symtab_shndx_hdr
!= NULL
3909 && (symtab_shndx_hdr
->sh_link
3910 == (unsigned long) (section
- section_headers
)))
3912 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3913 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3921 number
= section
->sh_size
/ section
->sh_entsize
;
3922 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3926 error (_("Out of memory\n"));
3933 for (j
= 0, psym
= isyms
;
3937 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3938 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3939 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3940 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3941 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
3943 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3944 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
3945 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
3946 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3947 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3957 static Elf_Internal_Sym
*
3958 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3960 unsigned long number
;
3961 Elf64_External_Sym
*esyms
;
3962 Elf_External_Sym_Shndx
*shndx
;
3963 Elf_Internal_Sym
*isyms
;
3964 Elf_Internal_Sym
*psym
;
3967 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3973 if (symtab_shndx_hdr
!= NULL
3974 && (symtab_shndx_hdr
->sh_link
3975 == (unsigned long) (section
- section_headers
)))
3977 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3978 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3986 number
= section
->sh_size
/ section
->sh_entsize
;
3987 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3991 error (_("Out of memory\n"));
3998 for (j
= 0, psym
= isyms
;
4002 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
4003 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
4004 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
4005 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
4006 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
4008 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
4009 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
4010 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
4011 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
4012 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
4023 get_elf_section_flags (bfd_vma sh_flags
)
4025 static char buff
[1024];
4027 int field_size
= is_32bit_elf
? 8 : 16;
4028 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
4029 bfd_vma os_flags
= 0;
4030 bfd_vma proc_flags
= 0;
4031 bfd_vma unknown_flags
= 0;
4045 { "LINK ORDER", 10 },
4046 { "OS NONCONF", 10 },
4049 /* IA-64 specific. */
4052 /* IA-64 OpenVMS specific. */
4053 { "VMS_GLOBAL", 10 },
4054 { "VMS_OVERLAID", 12 },
4055 { "VMS_SHARED", 10 },
4056 { "VMS_VECTOR", 10 },
4057 { "VMS_ALLOC_64BIT", 15 },
4058 { "VMS_PROTECTED", 13}
4061 if (do_section_details
)
4063 sprintf (buff
, "[%*.*lx]: ",
4064 field_size
, field_size
, (unsigned long) sh_flags
);
4065 p
+= field_size
+ 4;
4072 flag
= sh_flags
& - sh_flags
;
4075 if (do_section_details
)
4079 case SHF_WRITE
: index
= 0; break;
4080 case SHF_ALLOC
: index
= 1; break;
4081 case SHF_EXECINSTR
: index
= 2; break;
4082 case SHF_MERGE
: index
= 3; break;
4083 case SHF_STRINGS
: index
= 4; break;
4084 case SHF_INFO_LINK
: index
= 5; break;
4085 case SHF_LINK_ORDER
: index
= 6; break;
4086 case SHF_OS_NONCONFORMING
: index
= 7; break;
4087 case SHF_GROUP
: index
= 8; break;
4088 case SHF_TLS
: index
= 9; break;
4092 if (elf_header
.e_machine
== EM_IA_64
)
4094 if (flag
== SHF_IA_64_SHORT
)
4096 else if (flag
== SHF_IA_64_NORECOV
)
4099 else if (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
4102 case SHF_IA_64_VMS_GLOBAL
: index
= 12; break;
4103 case SHF_IA_64_VMS_OVERLAID
: index
= 13; break;
4104 case SHF_IA_64_VMS_SHARED
: index
= 14; break;
4105 case SHF_IA_64_VMS_VECTOR
: index
= 15; break;
4106 case SHF_IA_64_VMS_ALLOC_64BIT
: index
= 16; break;
4107 case SHF_IA_64_VMS_PROTECTED
: index
= 17; break;
4117 if (p
!= buff
+ field_size
+ 4)
4119 if (size
< (10 + 2))
4126 size
-= flags
[index
].len
;
4127 p
= stpcpy (p
, flags
[index
].str
);
4129 else if (flag
& SHF_MASKOS
)
4131 else if (flag
& SHF_MASKPROC
)
4134 unknown_flags
|= flag
;
4140 case SHF_WRITE
: *p
= 'W'; break;
4141 case SHF_ALLOC
: *p
= 'A'; break;
4142 case SHF_EXECINSTR
: *p
= 'X'; break;
4143 case SHF_MERGE
: *p
= 'M'; break;
4144 case SHF_STRINGS
: *p
= 'S'; break;
4145 case SHF_INFO_LINK
: *p
= 'I'; break;
4146 case SHF_LINK_ORDER
: *p
= 'L'; break;
4147 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
4148 case SHF_GROUP
: *p
= 'G'; break;
4149 case SHF_TLS
: *p
= 'T'; break;
4152 if (elf_header
.e_machine
== EM_X86_64
4153 && flag
== SHF_X86_64_LARGE
)
4155 else if (flag
& SHF_MASKOS
)
4158 sh_flags
&= ~ SHF_MASKOS
;
4160 else if (flag
& SHF_MASKPROC
)
4163 sh_flags
&= ~ SHF_MASKPROC
;
4173 if (do_section_details
)
4177 size
-= 5 + field_size
;
4178 if (p
!= buff
+ field_size
+ 4)
4186 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
4187 (unsigned long) os_flags
);
4188 p
+= 5 + field_size
;
4192 size
-= 7 + field_size
;
4193 if (p
!= buff
+ field_size
+ 4)
4201 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
4202 (unsigned long) proc_flags
);
4203 p
+= 7 + field_size
;
4207 size
-= 10 + field_size
;
4208 if (p
!= buff
+ field_size
+ 4)
4216 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
4217 (unsigned long) unknown_flags
);
4218 p
+= 10 + field_size
;
4227 process_section_headers (FILE *file
)
4229 Elf_Internal_Shdr
*section
;
4232 section_headers
= NULL
;
4234 if (elf_header
.e_shnum
== 0)
4237 printf (_("\nThere are no sections in this file.\n"));
4242 if (do_sections
&& !do_header
)
4243 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4244 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4248 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4251 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4254 /* Read in the string table, so that we have names to display. */
4255 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4256 && elf_header
.e_shstrndx
< elf_header
.e_shnum
)
4258 section
= section_headers
+ elf_header
.e_shstrndx
;
4260 if (section
->sh_size
!= 0)
4262 string_table
= get_data (NULL
, file
, section
->sh_offset
,
4263 1, section
->sh_size
, _("string table"));
4265 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4269 /* Scan the sections for the dynamic symbol table
4270 and dynamic string table and debug sections. */
4271 dynamic_symbols
= NULL
;
4272 dynamic_strings
= NULL
;
4273 dynamic_syminfo
= NULL
;
4274 symtab_shndx_hdr
= NULL
;
4276 eh_addr_size
= is_32bit_elf
? 4 : 8;
4277 switch (elf_header
.e_machine
)
4280 case EM_MIPS_RS3_LE
:
4281 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4282 FDE addresses. However, the ABI also has a semi-official ILP32
4283 variant for which the normal FDE address size rules apply.
4285 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4286 section, where XX is the size of longs in bits. Unfortunately,
4287 earlier compilers provided no way of distinguishing ILP32 objects
4288 from LP64 objects, so if there's any doubt, we should assume that
4289 the official LP64 form is being used. */
4290 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4291 && find_section (".gcc_compiled_long32") == NULL
)
4297 switch (elf_header
.e_flags
& EF_H8_MACH
)
4299 case E_H8_MACH_H8300
:
4300 case E_H8_MACH_H8300HN
:
4301 case E_H8_MACH_H8300SN
:
4302 case E_H8_MACH_H8300SXN
:
4305 case E_H8_MACH_H8300H
:
4306 case E_H8_MACH_H8300S
:
4307 case E_H8_MACH_H8300SX
:
4315 switch (elf_header
.e_flags
& EF_M32C_CPU_MASK
)
4317 case EF_M32C_CPU_M16C
:
4324 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4327 size_t expected_entsize \
4328 = is_32bit_elf ? size32 : size64; \
4329 if (section->sh_entsize != expected_entsize) \
4330 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4331 i, (unsigned long int) section->sh_entsize, \
4332 (unsigned long int) expected_entsize); \
4333 section->sh_entsize = expected_entsize; \
4336 #define CHECK_ENTSIZE(section, i, type) \
4337 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4338 sizeof (Elf64_External_##type))
4340 for (i
= 0, section
= section_headers
;
4341 i
< elf_header
.e_shnum
;
4344 char *name
= SECTION_NAME (section
);
4346 if (section
->sh_type
== SHT_DYNSYM
)
4348 if (dynamic_symbols
!= NULL
)
4350 error (_("File contains multiple dynamic symbol tables\n"));
4354 CHECK_ENTSIZE (section
, i
, Sym
);
4355 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4356 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4358 else if (section
->sh_type
== SHT_STRTAB
4359 && streq (name
, ".dynstr"))
4361 if (dynamic_strings
!= NULL
)
4363 error (_("File contains multiple dynamic string tables\n"));
4367 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
4368 1, section
->sh_size
, _("dynamic strings"));
4369 dynamic_strings_length
= section
->sh_size
;
4371 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4373 if (symtab_shndx_hdr
!= NULL
)
4375 error (_("File contains multiple symtab shndx tables\n"));
4378 symtab_shndx_hdr
= section
;
4380 else if (section
->sh_type
== SHT_SYMTAB
)
4381 CHECK_ENTSIZE (section
, i
, Sym
);
4382 else if (section
->sh_type
== SHT_GROUP
)
4383 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4384 else if (section
->sh_type
== SHT_REL
)
4385 CHECK_ENTSIZE (section
, i
, Rel
);
4386 else if (section
->sh_type
== SHT_RELA
)
4387 CHECK_ENTSIZE (section
, i
, Rela
);
4388 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4389 || do_debug_lines
|| do_debug_lines_decoded
|| do_debug_pubnames
4390 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
4391 || do_debug_str
|| do_debug_loc
|| do_debug_ranges
)
4392 && (const_strneq (name
, ".debug_")
4393 || const_strneq (name
, ".zdebug_")))
4396 name
+= sizeof (".zdebug_") - 1;
4398 name
+= sizeof (".debug_") - 1;
4401 || (do_debug_info
&& streq (name
, "info"))
4402 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4403 || ((do_debug_lines
|| do_debug_lines_decoded
)
4404 && streq (name
, "line"))
4405 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4406 || (do_debug_aranges
&& streq (name
, "aranges"))
4407 || (do_debug_ranges
&& streq (name
, "ranges"))
4408 || (do_debug_frames
&& streq (name
, "frame"))
4409 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4410 || (do_debug_str
&& streq (name
, "str"))
4411 || (do_debug_loc
&& streq (name
, "loc"))
4413 request_dump_bynumber (i
, DEBUG_DUMP
);
4415 /* Linkonce section to be combined with .debug_info at link time. */
4416 else if ((do_debugging
|| do_debug_info
)
4417 && const_strneq (name
, ".gnu.linkonce.wi."))
4418 request_dump_bynumber (i
, DEBUG_DUMP
);
4419 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4420 request_dump_bynumber (i
, DEBUG_DUMP
);
4426 if (elf_header
.e_shnum
> 1)
4427 printf (_("\nSection Headers:\n"));
4429 printf (_("\nSection Header:\n"));
4433 if (do_section_details
)
4435 printf (_(" [Nr] Name\n"));
4436 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4440 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4444 if (do_section_details
)
4446 printf (_(" [Nr] Name\n"));
4447 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4451 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4455 if (do_section_details
)
4457 printf (_(" [Nr] Name\n"));
4458 printf (_(" Type Address Offset Link\n"));
4459 printf (_(" Size EntSize Info Align\n"));
4463 printf (_(" [Nr] Name Type Address Offset\n"));
4464 printf (_(" Size EntSize Flags Link Info Align\n"));
4468 if (do_section_details
)
4469 printf (_(" Flags\n"));
4471 for (i
= 0, section
= section_headers
;
4472 i
< elf_header
.e_shnum
;
4475 if (do_section_details
)
4477 printf (" [%2u] %s\n",
4479 SECTION_NAME (section
));
4480 if (is_32bit_elf
|| do_wide
)
4481 printf (" %-15.15s ",
4482 get_section_type_name (section
->sh_type
));
4485 printf (" [%2u] %-17.17s %-15.15s ",
4487 SECTION_NAME (section
),
4488 get_section_type_name (section
->sh_type
));
4492 print_vma (section
->sh_addr
, LONG_HEX
);
4494 printf ( " %6.6lx %6.6lx %2.2lx",
4495 (unsigned long) section
->sh_offset
,
4496 (unsigned long) section
->sh_size
,
4497 (unsigned long) section
->sh_entsize
);
4499 if (do_section_details
)
4500 fputs (" ", stdout
);
4502 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4504 printf ("%2u %3u %2lu\n",
4507 (unsigned long) section
->sh_addralign
);
4511 print_vma (section
->sh_addr
, LONG_HEX
);
4513 if ((long) section
->sh_offset
== section
->sh_offset
)
4514 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4518 print_vma (section
->sh_offset
, LONG_HEX
);
4521 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4522 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4526 print_vma (section
->sh_size
, LONG_HEX
);
4529 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4530 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4534 print_vma (section
->sh_entsize
, LONG_HEX
);
4537 if (do_section_details
)
4538 fputs (" ", stdout
);
4540 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4542 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
4544 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4545 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
4548 print_vma (section
->sh_addralign
, DEC
);
4552 else if (do_section_details
)
4554 printf (" %-15.15s ",
4555 get_section_type_name (section
->sh_type
));
4556 print_vma (section
->sh_addr
, LONG_HEX
);
4557 if ((long) section
->sh_offset
== section
->sh_offset
)
4558 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4562 print_vma (section
->sh_offset
, LONG_HEX
);
4564 printf (" %u\n ", section
->sh_link
);
4565 print_vma (section
->sh_size
, LONG_HEX
);
4567 print_vma (section
->sh_entsize
, LONG_HEX
);
4569 printf (" %-16u %lu\n",
4571 (unsigned long) section
->sh_addralign
);
4576 print_vma (section
->sh_addr
, LONG_HEX
);
4577 if ((long) section
->sh_offset
== section
->sh_offset
)
4578 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4582 print_vma (section
->sh_offset
, LONG_HEX
);
4585 print_vma (section
->sh_size
, LONG_HEX
);
4587 print_vma (section
->sh_entsize
, LONG_HEX
);
4589 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4591 printf (" %2u %3u %lu\n",
4594 (unsigned long) section
->sh_addralign
);
4597 if (do_section_details
)
4598 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4601 if (!do_section_details
)
4602 printf (_("Key to Flags:\n\
4603 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4604 I (info), L (link order), G (group), x (unknown)\n\
4605 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4611 get_group_flags (unsigned int flags
)
4613 static char buff
[32];
4620 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4627 process_section_groups (FILE *file
)
4629 Elf_Internal_Shdr
*section
;
4631 struct group
*group
;
4632 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4633 Elf_Internal_Sym
*symtab
;
4637 /* Don't process section groups unless needed. */
4638 if (!do_unwind
&& !do_section_groups
)
4641 if (elf_header
.e_shnum
== 0)
4643 if (do_section_groups
)
4644 printf (_("\nThere are no sections in this file.\n"));
4649 if (section_headers
== NULL
)
4651 error (_("Section headers are not available!\n"));
4655 section_headers_groups
= calloc (elf_header
.e_shnum
,
4656 sizeof (struct group
*));
4658 if (section_headers_groups
== NULL
)
4660 error (_("Out of memory\n"));
4664 /* Scan the sections for the group section. */
4666 for (i
= 0, section
= section_headers
;
4667 i
< elf_header
.e_shnum
;
4669 if (section
->sh_type
== SHT_GROUP
)
4672 if (group_count
== 0)
4674 if (do_section_groups
)
4675 printf (_("\nThere are no section groups in this file.\n"));
4680 section_groups
= calloc (group_count
, sizeof (struct group
));
4682 if (section_groups
== NULL
)
4684 error (_("Out of memory\n"));
4693 for (i
= 0, section
= section_headers
, group
= section_groups
;
4694 i
< elf_header
.e_shnum
;
4697 if (section
->sh_type
== SHT_GROUP
)
4699 char *name
= SECTION_NAME (section
);
4701 unsigned char *start
, *indices
;
4702 unsigned int entry
, j
, size
;
4703 Elf_Internal_Shdr
*sec
;
4704 Elf_Internal_Sym
*sym
;
4706 /* Get the symbol table. */
4707 if (section
->sh_link
>= elf_header
.e_shnum
4708 || ((sec
= section_headers
+ section
->sh_link
)->sh_type
4711 error (_("Bad sh_link in group section `%s'\n"), name
);
4715 if (symtab_sec
!= sec
)
4720 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4723 sym
= symtab
+ section
->sh_info
;
4725 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4727 if (sym
->st_shndx
== 0
4728 || sym
->st_shndx
>= elf_header
.e_shnum
)
4730 error (_("Bad sh_info in group section `%s'\n"), name
);
4734 group_name
= SECTION_NAME (section_headers
+ sym
->st_shndx
);
4743 /* Get the string table. */
4744 if (symtab_sec
->sh_link
>= elf_header
.e_shnum
)
4753 != (sec
= section_headers
+ symtab_sec
->sh_link
))
4758 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4759 1, strtab_sec
->sh_size
,
4761 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4763 group_name
= sym
->st_name
< strtab_size
4764 ? strtab
+ sym
->st_name
: "<corrupt>";
4767 start
= get_data (NULL
, file
, section
->sh_offset
,
4768 1, section
->sh_size
, _("section data"));
4771 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4772 entry
= byte_get (indices
, 4);
4775 if (do_section_groups
)
4777 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4778 get_group_flags (entry
), i
, name
, group_name
, size
);
4780 printf (_(" [Index] Name\n"));
4783 group
->group_index
= i
;
4785 for (j
= 0; j
< size
; j
++)
4787 struct group_list
*g
;
4789 entry
= byte_get (indices
, 4);
4792 if (entry
>= elf_header
.e_shnum
)
4794 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4795 entry
, i
, elf_header
.e_shnum
- 1);
4799 if (section_headers_groups
[entry
] != NULL
)
4803 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4805 section_headers_groups
[entry
]->group_index
);
4810 /* Intel C/C++ compiler may put section 0 in a
4811 section group. We just warn it the first time
4812 and ignore it afterwards. */
4813 static int warned
= 0;
4816 error (_("section 0 in group section [%5u]\n"),
4817 section_headers_groups
[entry
]->group_index
);
4823 section_headers_groups
[entry
] = group
;
4825 if (do_section_groups
)
4827 sec
= section_headers
+ entry
;
4828 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4831 g
= xmalloc (sizeof (struct group_list
));
4832 g
->section_index
= entry
;
4833 g
->next
= group
->root
;
4857 } dynamic_relocations
[] =
4859 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4860 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4861 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4864 /* Process the reloc section. */
4867 process_relocs (FILE *file
)
4869 unsigned long rel_size
;
4870 unsigned long rel_offset
;
4876 if (do_using_dynamic
)
4880 int has_dynamic_reloc
;
4883 has_dynamic_reloc
= 0;
4885 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4887 is_rela
= dynamic_relocations
[i
].rela
;
4888 name
= dynamic_relocations
[i
].name
;
4889 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4890 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4892 has_dynamic_reloc
|= rel_size
;
4894 if (is_rela
== UNKNOWN
)
4896 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4897 switch (dynamic_info
[DT_PLTREL
])
4911 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4912 name
, rel_offset
, rel_size
);
4914 dump_relocations (file
,
4915 offset_from_vma (file
, rel_offset
, rel_size
),
4917 dynamic_symbols
, num_dynamic_syms
,
4918 dynamic_strings
, dynamic_strings_length
, is_rela
);
4922 if (! has_dynamic_reloc
)
4923 printf (_("\nThere are no dynamic relocations in this file.\n"));
4927 Elf_Internal_Shdr
*section
;
4931 for (i
= 0, section
= section_headers
;
4932 i
< elf_header
.e_shnum
;
4935 if ( section
->sh_type
!= SHT_RELA
4936 && section
->sh_type
!= SHT_REL
)
4939 rel_offset
= section
->sh_offset
;
4940 rel_size
= section
->sh_size
;
4944 Elf_Internal_Shdr
*strsec
;
4947 printf (_("\nRelocation section "));
4949 if (string_table
== NULL
)
4950 printf ("%d", section
->sh_name
);
4952 printf (_("'%s'"), SECTION_NAME (section
));
4954 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4955 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4957 is_rela
= section
->sh_type
== SHT_RELA
;
4959 if (section
->sh_link
!= 0
4960 && section
->sh_link
< elf_header
.e_shnum
)
4962 Elf_Internal_Shdr
*symsec
;
4963 Elf_Internal_Sym
*symtab
;
4964 unsigned long nsyms
;
4965 unsigned long strtablen
= 0;
4966 char *strtab
= NULL
;
4968 symsec
= section_headers
+ section
->sh_link
;
4969 if (symsec
->sh_type
!= SHT_SYMTAB
4970 && symsec
->sh_type
!= SHT_DYNSYM
)
4973 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4974 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4979 if (symsec
->sh_link
!= 0
4980 && symsec
->sh_link
< elf_header
.e_shnum
)
4982 strsec
= section_headers
+ symsec
->sh_link
;
4984 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4987 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4990 dump_relocations (file
, rel_offset
, rel_size
,
4991 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4997 dump_relocations (file
, rel_offset
, rel_size
,
4998 NULL
, 0, NULL
, 0, is_rela
);
5005 printf (_("\nThere are no relocations in this file.\n"));
5011 /* Process the unwind section. */
5013 #include "unwind-ia64.h"
5015 /* An absolute address consists of a section and an offset. If the
5016 section is NULL, the offset itself is the address, otherwise, the
5017 address equals to LOAD_ADDRESS(section) + offset. */
5021 unsigned short section
;
5025 #define ABSADDR(a) \
5027 ? section_headers [(a).section].sh_addr + (a).offset \
5030 struct ia64_unw_aux_info
5032 struct ia64_unw_table_entry
5034 struct absaddr start
;
5036 struct absaddr info
;
5038 *table
; /* Unwind table. */
5039 unsigned long table_len
; /* Length of unwind table. */
5040 unsigned char *info
; /* Unwind info. */
5041 unsigned long info_size
; /* Size of unwind info. */
5042 bfd_vma info_addr
; /* starting address of unwind info. */
5043 bfd_vma seg_base
; /* Starting address of segment. */
5044 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5045 unsigned long nsyms
; /* Number of symbols. */
5046 char *strtab
; /* The string table. */
5047 unsigned long strtab_size
; /* Size of string table. */
5051 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
5052 unsigned long nsyms
,
5054 unsigned long strtab_size
,
5055 struct absaddr addr
,
5056 const char **symname
,
5059 bfd_vma dist
= 0x100000;
5060 Elf_Internal_Sym
*sym
, *best
= NULL
;
5063 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
5065 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
5066 && sym
->st_name
!= 0
5067 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
5068 && addr
.offset
>= sym
->st_value
5069 && addr
.offset
- sym
->st_value
< dist
)
5072 dist
= addr
.offset
- sym
->st_value
;
5079 *symname
= (best
->st_name
>= strtab_size
5080 ? "<corrupt>" : strtab
+ best
->st_name
);
5085 *offset
= addr
.offset
;
5089 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
5091 struct ia64_unw_table_entry
*tp
;
5094 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5098 const unsigned char *dp
;
5099 const unsigned char *head
;
5100 const char *procname
;
5102 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5103 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
5105 fputs ("\n<", stdout
);
5109 fputs (procname
, stdout
);
5112 printf ("+%lx", (unsigned long) offset
);
5115 fputs (">: [", stdout
);
5116 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5117 fputc ('-', stdout
);
5118 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5119 printf ("], info at +0x%lx\n",
5120 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
5122 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
5123 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
5125 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
5126 (unsigned) UNW_VER (stamp
),
5127 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
5128 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
5129 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
5130 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
5132 if (UNW_VER (stamp
) != 1)
5134 printf ("\tUnknown version.\n");
5139 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
5140 dp
= unw_decode (dp
, in_body
, & in_body
);
5145 slurp_ia64_unwind_table (FILE *file
,
5146 struct ia64_unw_aux_info
*aux
,
5147 Elf_Internal_Shdr
*sec
)
5149 unsigned long size
, nrelas
, i
;
5150 Elf_Internal_Phdr
*seg
;
5151 struct ia64_unw_table_entry
*tep
;
5152 Elf_Internal_Shdr
*relsec
;
5153 Elf_Internal_Rela
*rela
, *rp
;
5154 unsigned char *table
, *tp
;
5155 Elf_Internal_Sym
*sym
;
5156 const char *relname
;
5158 /* First, find the starting address of the segment that includes
5161 if (elf_header
.e_phnum
)
5163 if (! get_program_headers (file
))
5166 for (seg
= program_headers
;
5167 seg
< program_headers
+ elf_header
.e_phnum
;
5170 if (seg
->p_type
!= PT_LOAD
)
5173 if (sec
->sh_addr
>= seg
->p_vaddr
5174 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5176 aux
->seg_base
= seg
->p_vaddr
;
5182 /* Second, build the unwind table from the contents of the unwind section: */
5183 size
= sec
->sh_size
;
5184 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5188 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
5190 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
5192 tep
->start
.section
= SHN_UNDEF
;
5193 tep
->end
.section
= SHN_UNDEF
;
5194 tep
->info
.section
= SHN_UNDEF
;
5197 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5198 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5199 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
5203 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
5204 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
5205 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
5207 tep
->start
.offset
+= aux
->seg_base
;
5208 tep
->end
.offset
+= aux
->seg_base
;
5209 tep
->info
.offset
+= aux
->seg_base
;
5213 /* Third, apply any relocations to the unwind table: */
5214 for (relsec
= section_headers
;
5215 relsec
< section_headers
+ elf_header
.e_shnum
;
5218 if (relsec
->sh_type
!= SHT_RELA
5219 || relsec
->sh_info
>= elf_header
.e_shnum
5220 || section_headers
+ relsec
->sh_info
!= sec
)
5223 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5227 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5229 relname
= elf_ia64_reloc_type (get_reloc_type (rp
->r_info
));
5230 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5232 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5234 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5238 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5240 switch (rp
->r_offset
/eh_addr_size
% 3)
5243 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5244 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5247 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5248 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5251 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5252 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5262 aux
->table_len
= size
/ (3 * eh_addr_size
);
5267 ia64_process_unwind (FILE *file
)
5269 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
5270 unsigned long i
, unwcount
= 0, unwstart
= 0;
5271 struct ia64_unw_aux_info aux
;
5273 memset (& aux
, 0, sizeof (aux
));
5275 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5277 if (sec
->sh_type
== SHT_SYMTAB
5278 && sec
->sh_link
< elf_header
.e_shnum
)
5280 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5281 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5283 strsec
= section_headers
+ sec
->sh_link
;
5284 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5285 1, strsec
->sh_size
, _("string table"));
5286 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5288 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5293 printf (_("\nThere are no unwind sections in this file.\n"));
5295 while (unwcount
-- > 0)
5300 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5301 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5302 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5309 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5311 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5313 /* We need to find which section group it is in. */
5314 struct group_list
*g
= section_headers_groups
[i
]->root
;
5316 for (; g
!= NULL
; g
= g
->next
)
5318 sec
= section_headers
+ g
->section_index
;
5320 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5325 i
= elf_header
.e_shnum
;
5327 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5329 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5330 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5331 suffix
= SECTION_NAME (unwsec
) + len
;
5332 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5334 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5335 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5340 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5341 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5342 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5343 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5345 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5346 suffix
= SECTION_NAME (unwsec
) + len
;
5347 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5349 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5350 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5354 if (i
== elf_header
.e_shnum
)
5356 printf (_("\nCould not find unwind info section for "));
5358 if (string_table
== NULL
)
5359 printf ("%d", unwsec
->sh_name
);
5361 printf (_("'%s'"), SECTION_NAME (unwsec
));
5365 aux
.info_size
= sec
->sh_size
;
5366 aux
.info_addr
= sec
->sh_addr
;
5367 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
5370 printf (_("\nUnwind section "));
5372 if (string_table
== NULL
)
5373 printf ("%d", unwsec
->sh_name
);
5375 printf (_("'%s'"), SECTION_NAME (unwsec
));
5377 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5378 (unsigned long) unwsec
->sh_offset
,
5379 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5381 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5383 if (aux
.table_len
> 0)
5384 dump_ia64_unwind (& aux
);
5387 free ((char *) aux
.table
);
5389 free ((char *) aux
.info
);
5398 free ((char *) aux
.strtab
);
5403 struct hppa_unw_aux_info
5405 struct hppa_unw_table_entry
5407 struct absaddr start
;
5409 unsigned int Cannot_unwind
:1; /* 0 */
5410 unsigned int Millicode
:1; /* 1 */
5411 unsigned int Millicode_save_sr0
:1; /* 2 */
5412 unsigned int Region_description
:2; /* 3..4 */
5413 unsigned int reserved1
:1; /* 5 */
5414 unsigned int Entry_SR
:1; /* 6 */
5415 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5416 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5417 unsigned int Args_stored
:1; /* 16 */
5418 unsigned int Variable_Frame
:1; /* 17 */
5419 unsigned int Separate_Package_Body
:1; /* 18 */
5420 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5421 unsigned int Stack_Overflow_Check
:1; /* 20 */
5422 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5423 unsigned int Ada_Region
:1; /* 22 */
5424 unsigned int cxx_info
:1; /* 23 */
5425 unsigned int cxx_try_catch
:1; /* 24 */
5426 unsigned int sched_entry_seq
:1; /* 25 */
5427 unsigned int reserved2
:1; /* 26 */
5428 unsigned int Save_SP
:1; /* 27 */
5429 unsigned int Save_RP
:1; /* 28 */
5430 unsigned int Save_MRP_in_frame
:1; /* 29 */
5431 unsigned int extn_ptr_defined
:1; /* 30 */
5432 unsigned int Cleanup_defined
:1; /* 31 */
5434 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5435 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5436 unsigned int Large_frame
:1; /* 2 */
5437 unsigned int Pseudo_SP_Set
:1; /* 3 */
5438 unsigned int reserved4
:1; /* 4 */
5439 unsigned int Total_frame_size
:27; /* 5..31 */
5441 *table
; /* Unwind table. */
5442 unsigned long table_len
; /* Length of unwind table. */
5443 bfd_vma seg_base
; /* Starting address of segment. */
5444 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5445 unsigned long nsyms
; /* Number of symbols. */
5446 char *strtab
; /* The string table. */
5447 unsigned long strtab_size
; /* Size of string table. */
5451 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5453 struct hppa_unw_table_entry
*tp
;
5455 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5458 const char *procname
;
5460 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5461 aux
->strtab_size
, tp
->start
, &procname
,
5464 fputs ("\n<", stdout
);
5468 fputs (procname
, stdout
);
5471 printf ("+%lx", (unsigned long) offset
);
5474 fputs (">: [", stdout
);
5475 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5476 fputc ('-', stdout
);
5477 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5480 #define PF(_m) if (tp->_m) printf (#_m " ");
5481 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5484 PF(Millicode_save_sr0
);
5485 /* PV(Region_description); */
5491 PF(Separate_Package_Body
);
5492 PF(Frame_Extension_Millicode
);
5493 PF(Stack_Overflow_Check
);
5494 PF(Two_Instruction_SP_Increment
);
5498 PF(sched_entry_seq
);
5501 PF(Save_MRP_in_frame
);
5502 PF(extn_ptr_defined
);
5503 PF(Cleanup_defined
);
5504 PF(MPE_XL_interrupt_marker
);
5505 PF(HP_UX_interrupt_marker
);
5508 PV(Total_frame_size
);
5517 slurp_hppa_unwind_table (FILE *file
,
5518 struct hppa_unw_aux_info
*aux
,
5519 Elf_Internal_Shdr
*sec
)
5521 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5522 Elf_Internal_Phdr
*seg
;
5523 struct hppa_unw_table_entry
*tep
;
5524 Elf_Internal_Shdr
*relsec
;
5525 Elf_Internal_Rela
*rela
, *rp
;
5526 unsigned char *table
, *tp
;
5527 Elf_Internal_Sym
*sym
;
5528 const char *relname
;
5530 /* First, find the starting address of the segment that includes
5533 if (elf_header
.e_phnum
)
5535 if (! get_program_headers (file
))
5538 for (seg
= program_headers
;
5539 seg
< program_headers
+ elf_header
.e_phnum
;
5542 if (seg
->p_type
!= PT_LOAD
)
5545 if (sec
->sh_addr
>= seg
->p_vaddr
5546 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5548 aux
->seg_base
= seg
->p_vaddr
;
5554 /* Second, build the unwind table from the contents of the unwind
5556 size
= sec
->sh_size
;
5557 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5562 nentries
= size
/ unw_ent_size
;
5563 size
= unw_ent_size
* nentries
;
5565 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5567 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5569 unsigned int tmp1
, tmp2
;
5571 tep
->start
.section
= SHN_UNDEF
;
5572 tep
->end
.section
= SHN_UNDEF
;
5574 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5575 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5576 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5577 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5579 tep
->start
.offset
+= aux
->seg_base
;
5580 tep
->end
.offset
+= aux
->seg_base
;
5582 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5583 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5584 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5585 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5586 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5587 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5588 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5589 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5590 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5591 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5592 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5593 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5594 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5595 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5596 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5597 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5598 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5599 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5600 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5601 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5602 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5603 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5604 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5605 tep
->Cleanup_defined
= tmp1
& 0x1;
5607 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5608 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5609 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5610 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5611 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5612 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5616 /* Third, apply any relocations to the unwind table. */
5617 for (relsec
= section_headers
;
5618 relsec
< section_headers
+ elf_header
.e_shnum
;
5621 if (relsec
->sh_type
!= SHT_RELA
5622 || relsec
->sh_info
>= elf_header
.e_shnum
5623 || section_headers
+ relsec
->sh_info
!= sec
)
5626 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5630 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5632 relname
= elf_hppa_reloc_type (get_reloc_type (rp
->r_info
));
5633 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5635 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5636 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5638 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5642 i
= rp
->r_offset
/ unw_ent_size
;
5644 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5647 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5648 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5651 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5652 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5662 aux
->table_len
= nentries
;
5668 hppa_process_unwind (FILE *file
)
5670 struct hppa_unw_aux_info aux
;
5671 Elf_Internal_Shdr
*unwsec
= NULL
;
5672 Elf_Internal_Shdr
*strsec
;
5673 Elf_Internal_Shdr
*sec
;
5676 memset (& aux
, 0, sizeof (aux
));
5678 if (string_table
== NULL
)
5681 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5683 if (sec
->sh_type
== SHT_SYMTAB
5684 && sec
->sh_link
< elf_header
.e_shnum
)
5686 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5687 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5689 strsec
= section_headers
+ sec
->sh_link
;
5690 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5691 1, strsec
->sh_size
, _("string table"));
5692 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5694 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5699 printf (_("\nThere are no unwind sections in this file.\n"));
5701 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5703 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5705 printf (_("\nUnwind section "));
5706 printf (_("'%s'"), SECTION_NAME (sec
));
5708 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5709 (unsigned long) sec
->sh_offset
,
5710 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5712 slurp_hppa_unwind_table (file
, &aux
, sec
);
5713 if (aux
.table_len
> 0)
5714 dump_hppa_unwind (&aux
);
5717 free ((char *) aux
.table
);
5725 free ((char *) aux
.strtab
);
5731 process_unwind (FILE *file
)
5733 struct unwind_handler
{
5735 int (*handler
)(FILE *file
);
5737 { EM_IA_64
, ia64_process_unwind
},
5738 { EM_PARISC
, hppa_process_unwind
},
5746 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5747 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5748 return handlers
[i
].handler (file
);
5750 printf (_("\nThere are no unwind sections in this file.\n"));
5755 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5757 switch (entry
->d_tag
)
5760 if (entry
->d_un
.d_val
== 0)
5764 static const char * opts
[] =
5766 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5767 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5768 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5769 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5774 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
5775 if (entry
->d_un
.d_val
& (1 << cnt
))
5777 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5784 case DT_MIPS_IVERSION
:
5785 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5786 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5788 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5791 case DT_MIPS_TIME_STAMP
:
5796 time_t time
= entry
->d_un
.d_val
;
5797 tmp
= gmtime (&time
);
5798 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5799 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5800 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5801 printf ("Time Stamp: %s\n", timebuf
);
5805 case DT_MIPS_RLD_VERSION
:
5806 case DT_MIPS_LOCAL_GOTNO
:
5807 case DT_MIPS_CONFLICTNO
:
5808 case DT_MIPS_LIBLISTNO
:
5809 case DT_MIPS_SYMTABNO
:
5810 case DT_MIPS_UNREFEXTNO
:
5811 case DT_MIPS_HIPAGENO
:
5812 case DT_MIPS_DELTA_CLASS_NO
:
5813 case DT_MIPS_DELTA_INSTANCE_NO
:
5814 case DT_MIPS_DELTA_RELOC_NO
:
5815 case DT_MIPS_DELTA_SYM_NO
:
5816 case DT_MIPS_DELTA_CLASSSYM_NO
:
5817 case DT_MIPS_COMPACT_SIZE
:
5818 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5822 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5828 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5830 switch (entry
->d_tag
)
5832 case DT_HP_DLD_FLAGS
:
5841 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5842 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5843 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5844 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5845 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5846 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5847 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5848 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5849 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5850 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5851 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5852 { DT_HP_GST
, "HP_GST" },
5853 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5854 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5855 { DT_HP_NODELETE
, "HP_NODELETE" },
5856 { DT_HP_GROUP
, "HP_GROUP" },
5857 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5861 bfd_vma val
= entry
->d_un
.d_val
;
5863 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
5864 if (val
& flags
[cnt
].bit
)
5868 fputs (flags
[cnt
].str
, stdout
);
5870 val
^= flags
[cnt
].bit
;
5873 if (val
!= 0 || first
)
5877 print_vma (val
, HEX
);
5883 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5890 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5892 switch (entry
->d_tag
)
5894 case DT_IA_64_PLT_RESERVE
:
5895 /* First 3 slots reserved. */
5896 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5898 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5902 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5909 get_32bit_dynamic_section (FILE *file
)
5911 Elf32_External_Dyn
*edyn
, *ext
;
5912 Elf_Internal_Dyn
*entry
;
5914 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5915 _("dynamic section"));
5919 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5920 might not have the luxury of section headers. Look for the DT_NULL
5921 terminator to determine the number of entries. */
5922 for (ext
= edyn
, dynamic_nent
= 0;
5923 (char *) ext
< (char *) edyn
+ dynamic_size
;
5927 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5931 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5932 if (dynamic_section
== NULL
)
5934 error (_("Out of memory\n"));
5939 for (ext
= edyn
, entry
= dynamic_section
;
5940 entry
< dynamic_section
+ dynamic_nent
;
5943 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5944 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5953 get_64bit_dynamic_section (FILE *file
)
5955 Elf64_External_Dyn
*edyn
, *ext
;
5956 Elf_Internal_Dyn
*entry
;
5958 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5959 _("dynamic section"));
5963 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5964 might not have the luxury of section headers. Look for the DT_NULL
5965 terminator to determine the number of entries. */
5966 for (ext
= edyn
, dynamic_nent
= 0;
5967 (char *) ext
< (char *) edyn
+ dynamic_size
;
5971 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5975 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5976 if (dynamic_section
== NULL
)
5978 error (_("Out of memory\n"));
5983 for (ext
= edyn
, entry
= dynamic_section
;
5984 entry
< dynamic_section
+ dynamic_nent
;
5987 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5988 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5997 print_dynamic_flags (bfd_vma flags
)
6005 flag
= flags
& - flags
;
6015 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
6016 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
6017 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
6018 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
6019 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
6020 default: fputs ("unknown", stdout
); break;
6026 /* Parse and display the contents of the dynamic section. */
6029 process_dynamic_section (FILE *file
)
6031 Elf_Internal_Dyn
*entry
;
6033 if (dynamic_size
== 0)
6036 printf (_("\nThere is no dynamic section in this file.\n"));
6043 if (! get_32bit_dynamic_section (file
))
6046 else if (! get_64bit_dynamic_section (file
))
6049 /* Find the appropriate symbol table. */
6050 if (dynamic_symbols
== NULL
)
6052 for (entry
= dynamic_section
;
6053 entry
< dynamic_section
+ dynamic_nent
;
6056 Elf_Internal_Shdr section
;
6058 if (entry
->d_tag
!= DT_SYMTAB
)
6061 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
6063 /* Since we do not know how big the symbol table is,
6064 we default to reading in the entire file (!) and
6065 processing that. This is overkill, I know, but it
6067 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
6069 if (archive_file_offset
!= 0)
6070 section
.sh_size
= archive_file_size
- section
.sh_offset
;
6073 if (fseek (file
, 0, SEEK_END
))
6074 error (_("Unable to seek to end of file!\n"));
6076 section
.sh_size
= ftell (file
) - section
.sh_offset
;
6080 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
6082 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
6084 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
6085 if (num_dynamic_syms
< 1)
6087 error (_("Unable to determine the number of symbols to load\n"));
6091 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
6095 /* Similarly find a string table. */
6096 if (dynamic_strings
== NULL
)
6098 for (entry
= dynamic_section
;
6099 entry
< dynamic_section
+ dynamic_nent
;
6102 unsigned long offset
;
6105 if (entry
->d_tag
!= DT_STRTAB
)
6108 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
6110 /* Since we do not know how big the string table is,
6111 we default to reading in the entire file (!) and
6112 processing that. This is overkill, I know, but it
6115 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
6117 if (archive_file_offset
!= 0)
6118 str_tab_len
= archive_file_size
- offset
;
6121 if (fseek (file
, 0, SEEK_END
))
6122 error (_("Unable to seek to end of file\n"));
6123 str_tab_len
= ftell (file
) - offset
;
6126 if (str_tab_len
< 1)
6129 (_("Unable to determine the length of the dynamic string table\n"));
6133 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
6134 _("dynamic string table"));
6135 dynamic_strings_length
= str_tab_len
;
6140 /* And find the syminfo section if available. */
6141 if (dynamic_syminfo
== NULL
)
6143 unsigned long syminsz
= 0;
6145 for (entry
= dynamic_section
;
6146 entry
< dynamic_section
+ dynamic_nent
;
6149 if (entry
->d_tag
== DT_SYMINENT
)
6151 /* Note: these braces are necessary to avoid a syntax
6152 error from the SunOS4 C compiler. */
6153 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
6155 else if (entry
->d_tag
== DT_SYMINSZ
)
6156 syminsz
= entry
->d_un
.d_val
;
6157 else if (entry
->d_tag
== DT_SYMINFO
)
6158 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
6162 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
6164 Elf_External_Syminfo
*extsyminfo
, *extsym
;
6165 Elf_Internal_Syminfo
*syminfo
;
6167 /* There is a syminfo section. Read the data. */
6168 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
6169 syminsz
, _("symbol information"));
6173 dynamic_syminfo
= malloc (syminsz
);
6174 if (dynamic_syminfo
== NULL
)
6176 error (_("Out of memory\n"));
6180 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
6181 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
6182 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
6183 ++syminfo
, ++extsym
)
6185 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
6186 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
6193 if (do_dynamic
&& dynamic_addr
)
6194 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
6195 dynamic_addr
, dynamic_nent
);
6197 printf (_(" Tag Type Name/Value\n"));
6199 for (entry
= dynamic_section
;
6200 entry
< dynamic_section
+ dynamic_nent
;
6208 print_vma (entry
->d_tag
, FULL_HEX
);
6209 dtype
= get_dynamic_type (entry
->d_tag
);
6210 printf (" (%s)%*s", dtype
,
6211 ((is_32bit_elf
? 27 : 19)
6212 - (int) strlen (dtype
)),
6216 switch (entry
->d_tag
)
6220 print_dynamic_flags (entry
->d_un
.d_val
);
6230 switch (entry
->d_tag
)
6233 printf (_("Auxiliary library"));
6237 printf (_("Filter library"));
6241 printf (_("Configuration file"));
6245 printf (_("Dependency audit library"));
6249 printf (_("Audit library"));
6253 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6254 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6258 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6267 printf (_("Flags:"));
6269 if (entry
->d_un
.d_val
== 0)
6270 printf (_(" None\n"));
6273 unsigned long int val
= entry
->d_un
.d_val
;
6275 if (val
& DTF_1_PARINIT
)
6277 printf (" PARINIT");
6278 val
^= DTF_1_PARINIT
;
6280 if (val
& DTF_1_CONFEXP
)
6282 printf (" CONFEXP");
6283 val
^= DTF_1_CONFEXP
;
6286 printf (" %lx", val
);
6295 printf (_("Flags:"));
6297 if (entry
->d_un
.d_val
== 0)
6298 printf (_(" None\n"));
6301 unsigned long int val
= entry
->d_un
.d_val
;
6303 if (val
& DF_P1_LAZYLOAD
)
6305 printf (" LAZYLOAD");
6306 val
^= DF_P1_LAZYLOAD
;
6308 if (val
& DF_P1_GROUPPERM
)
6310 printf (" GROUPPERM");
6311 val
^= DF_P1_GROUPPERM
;
6314 printf (" %lx", val
);
6323 printf (_("Flags:"));
6324 if (entry
->d_un
.d_val
== 0)
6325 printf (_(" None\n"));
6328 unsigned long int val
= entry
->d_un
.d_val
;
6335 if (val
& DF_1_GLOBAL
)
6340 if (val
& DF_1_GROUP
)
6345 if (val
& DF_1_NODELETE
)
6347 printf (" NODELETE");
6348 val
^= DF_1_NODELETE
;
6350 if (val
& DF_1_LOADFLTR
)
6352 printf (" LOADFLTR");
6353 val
^= DF_1_LOADFLTR
;
6355 if (val
& DF_1_INITFIRST
)
6357 printf (" INITFIRST");
6358 val
^= DF_1_INITFIRST
;
6360 if (val
& DF_1_NOOPEN
)
6365 if (val
& DF_1_ORIGIN
)
6370 if (val
& DF_1_DIRECT
)
6375 if (val
& DF_1_TRANS
)
6380 if (val
& DF_1_INTERPOSE
)
6382 printf (" INTERPOSE");
6383 val
^= DF_1_INTERPOSE
;
6385 if (val
& DF_1_NODEFLIB
)
6387 printf (" NODEFLIB");
6388 val
^= DF_1_NODEFLIB
;
6390 if (val
& DF_1_NODUMP
)
6395 if (val
& DF_1_CONLFAT
)
6397 printf (" CONLFAT");
6398 val
^= DF_1_CONLFAT
;
6401 printf (" %lx", val
);
6408 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6410 puts (get_dynamic_type (entry
->d_un
.d_val
));
6430 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6436 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6437 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6443 switch (entry
->d_tag
)
6446 printf (_("Shared library: [%s]"), name
);
6448 if (streq (name
, program_interpreter
))
6449 printf (_(" program interpreter"));
6453 printf (_("Library soname: [%s]"), name
);
6457 printf (_("Library rpath: [%s]"), name
);
6461 printf (_("Library runpath: [%s]"), name
);
6465 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6470 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6483 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6487 case DT_INIT_ARRAYSZ
:
6488 case DT_FINI_ARRAYSZ
:
6489 case DT_GNU_CONFLICTSZ
:
6490 case DT_GNU_LIBLISTSZ
:
6493 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6494 printf (" (bytes)\n");
6504 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6517 if (entry
->d_tag
== DT_USED
6518 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6520 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6524 printf (_("Not needed object: [%s]\n"), name
);
6529 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6535 /* The value of this entry is ignored. */
6540 case DT_GNU_PRELINKED
:
6544 time_t time
= entry
->d_un
.d_val
;
6546 tmp
= gmtime (&time
);
6547 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6548 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6549 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6555 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6558 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6564 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6565 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6570 switch (elf_header
.e_machine
)
6573 case EM_MIPS_RS3_LE
:
6574 dynamic_section_mips_val (entry
);
6577 dynamic_section_parisc_val (entry
);
6580 dynamic_section_ia64_val (entry
);
6583 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6595 get_ver_flags (unsigned int flags
)
6597 static char buff
[32];
6604 if (flags
& VER_FLG_BASE
)
6605 strcat (buff
, "BASE ");
6607 if (flags
& VER_FLG_WEAK
)
6609 if (flags
& VER_FLG_BASE
)
6610 strcat (buff
, "| ");
6612 strcat (buff
, "WEAK ");
6615 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6616 strcat (buff
, "| <unknown>");
6621 /* Display the contents of the version sections. */
6623 process_version_sections (FILE *file
)
6625 Elf_Internal_Shdr
*section
;
6632 for (i
= 0, section
= section_headers
;
6633 i
< elf_header
.e_shnum
;
6636 switch (section
->sh_type
)
6638 case SHT_GNU_verdef
:
6640 Elf_External_Verdef
*edefs
;
6648 (_("\nVersion definition section '%s' contains %u entries:\n"),
6649 SECTION_NAME (section
), section
->sh_info
);
6651 printf (_(" Addr: 0x"));
6652 printf_vma (section
->sh_addr
);
6653 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6654 (unsigned long) section
->sh_offset
, section
->sh_link
,
6655 section
->sh_link
< elf_header
.e_shnum
6656 ? SECTION_NAME (section_headers
+ section
->sh_link
)
6659 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6661 _("version definition section"));
6662 endbuf
= (char *) edefs
+ section
->sh_size
;
6666 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6669 Elf_External_Verdef
*edef
;
6670 Elf_Internal_Verdef ent
;
6671 Elf_External_Verdaux
*eaux
;
6672 Elf_Internal_Verdaux aux
;
6676 vstart
= ((char *) edefs
) + idx
;
6677 if (vstart
+ sizeof (*edef
) > endbuf
)
6680 edef
= (Elf_External_Verdef
*) vstart
;
6682 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6683 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6684 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6685 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6686 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6687 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6688 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6690 printf (_(" %#06x: Rev: %d Flags: %s"),
6691 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6693 printf (_(" Index: %d Cnt: %d "),
6694 ent
.vd_ndx
, ent
.vd_cnt
);
6696 vstart
+= ent
.vd_aux
;
6698 eaux
= (Elf_External_Verdaux
*) vstart
;
6700 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6701 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6703 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6704 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6706 printf (_("Name index: %ld\n"), aux
.vda_name
);
6708 isum
= idx
+ ent
.vd_aux
;
6710 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6712 isum
+= aux
.vda_next
;
6713 vstart
+= aux
.vda_next
;
6715 eaux
= (Elf_External_Verdaux
*) vstart
;
6716 if (vstart
+ sizeof (*eaux
) > endbuf
)
6719 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6720 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6722 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6723 printf (_(" %#06x: Parent %d: %s\n"),
6724 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6726 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6727 isum
, j
, aux
.vda_name
);
6730 printf (_(" Version def aux past end of section\n"));
6734 if (cnt
< section
->sh_info
)
6735 printf (_(" Version definition past end of section\n"));
6741 case SHT_GNU_verneed
:
6743 Elf_External_Verneed
*eneed
;
6750 printf (_("\nVersion needs section '%s' contains %u entries:\n"),
6751 SECTION_NAME (section
), section
->sh_info
);
6753 printf (_(" Addr: 0x"));
6754 printf_vma (section
->sh_addr
);
6755 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6756 (unsigned long) section
->sh_offset
, section
->sh_link
,
6757 section
->sh_link
< elf_header
.e_shnum
6758 ? SECTION_NAME (section_headers
+ section
->sh_link
)
6761 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6763 _("version need section"));
6764 endbuf
= (char *) eneed
+ section
->sh_size
;
6768 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6770 Elf_External_Verneed
*entry
;
6771 Elf_Internal_Verneed ent
;
6776 vstart
= ((char *) eneed
) + idx
;
6777 if (vstart
+ sizeof (*entry
) > endbuf
)
6780 entry
= (Elf_External_Verneed
*) vstart
;
6782 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6783 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6784 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6785 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6786 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6788 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6790 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6791 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6793 printf (_(" File: %lx"), ent
.vn_file
);
6795 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6797 vstart
+= ent
.vn_aux
;
6799 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6801 Elf_External_Vernaux
*eaux
;
6802 Elf_Internal_Vernaux aux
;
6804 if (vstart
+ sizeof (*eaux
) > endbuf
)
6806 eaux
= (Elf_External_Vernaux
*) vstart
;
6808 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6809 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6810 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6811 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6812 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6814 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6815 printf (_(" %#06x: Name: %s"),
6816 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6818 printf (_(" %#06x: Name index: %lx"),
6819 isum
, aux
.vna_name
);
6821 printf (_(" Flags: %s Version: %d\n"),
6822 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6824 isum
+= aux
.vna_next
;
6825 vstart
+= aux
.vna_next
;
6828 printf (_(" Version need aux past end of section\n"));
6832 if (cnt
< section
->sh_info
)
6833 printf (_(" Version need past end of section\n"));
6839 case SHT_GNU_versym
:
6841 Elf_Internal_Shdr
*link_section
;
6844 unsigned char *edata
;
6845 unsigned short *data
;
6847 Elf_Internal_Sym
*symbols
;
6848 Elf_Internal_Shdr
*string_sec
;
6851 if (section
->sh_link
>= elf_header
.e_shnum
)
6854 link_section
= section_headers
+ section
->sh_link
;
6855 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6857 if (link_section
->sh_link
>= elf_header
.e_shnum
)
6862 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6864 string_sec
= section_headers
+ link_section
->sh_link
;
6866 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6867 string_sec
->sh_size
, _("version string table"));
6871 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6872 SECTION_NAME (section
), total
);
6874 printf (_(" Addr: "));
6875 printf_vma (section
->sh_addr
);
6876 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6877 (unsigned long) section
->sh_offset
, section
->sh_link
,
6878 SECTION_NAME (link_section
));
6880 off
= offset_from_vma (file
,
6881 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6882 total
* sizeof (short));
6883 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6884 _("version symbol data"));
6891 data
= cmalloc (total
, sizeof (short));
6893 for (cnt
= total
; cnt
--;)
6894 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6899 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6902 int check_def
, check_need
;
6905 printf (" %03x:", cnt
);
6907 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6908 switch (data
[cnt
+ j
])
6911 fputs (_(" 0 (*local*) "), stdout
);
6915 fputs (_(" 1 (*global*) "), stdout
);
6919 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6920 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6924 if (symbols
[cnt
+ j
].st_shndx
>= elf_header
.e_shnum
6925 || section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
6928 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6935 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6937 Elf_Internal_Verneed ivn
;
6938 unsigned long offset
;
6940 offset
= offset_from_vma
6941 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6942 sizeof (Elf_External_Verneed
));
6946 Elf_Internal_Vernaux ivna
;
6947 Elf_External_Verneed evn
;
6948 Elf_External_Vernaux evna
;
6949 unsigned long a_off
;
6951 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6954 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6955 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6957 a_off
= offset
+ ivn
.vn_aux
;
6961 get_data (&evna
, file
, a_off
, sizeof (evna
),
6962 1, _("version need aux (2)"));
6964 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6965 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6967 a_off
+= ivna
.vna_next
;
6969 while (ivna
.vna_other
!= data
[cnt
+ j
]
6970 && ivna
.vna_next
!= 0);
6972 if (ivna
.vna_other
== data
[cnt
+ j
])
6974 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6976 if (ivna
.vna_name
>= string_sec
->sh_size
)
6977 name
= _("*invalid*");
6979 name
= strtab
+ ivna
.vna_name
;
6980 nn
+= printf ("(%s%-*s",
6982 12 - (int) strlen (name
),
6988 offset
+= ivn
.vn_next
;
6990 while (ivn
.vn_next
);
6993 if (check_def
&& data
[cnt
+ j
] != 0x8001
6994 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6996 Elf_Internal_Verdef ivd
;
6997 Elf_External_Verdef evd
;
6998 unsigned long offset
;
7000 offset
= offset_from_vma
7001 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7006 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
7009 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7010 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7012 offset
+= ivd
.vd_next
;
7014 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
7015 && ivd
.vd_next
!= 0);
7017 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
7019 Elf_External_Verdaux evda
;
7020 Elf_Internal_Verdaux ivda
;
7022 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7024 get_data (&evda
, file
,
7025 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
7027 _("version def aux"));
7029 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7031 if (ivda
.vda_name
>= string_sec
->sh_size
)
7032 name
= _("*invalid*");
7034 name
= strtab
+ ivda
.vda_name
;
7035 nn
+= printf ("(%s%-*s",
7037 12 - (int) strlen (name
),
7043 printf ("%*c", 18 - nn
, ' ');
7061 printf (_("\nNo version information found in this file.\n"));
7067 get_symbol_binding (unsigned int binding
)
7069 static char buff
[32];
7073 case STB_LOCAL
: return "LOCAL";
7074 case STB_GLOBAL
: return "GLOBAL";
7075 case STB_WEAK
: return "WEAK";
7077 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
7078 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
7080 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
7081 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
7083 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
7089 get_symbol_type (unsigned int type
)
7091 static char buff
[32];
7095 case STT_NOTYPE
: return "NOTYPE";
7096 case STT_OBJECT
: return "OBJECT";
7097 case STT_FUNC
: return "FUNC";
7098 case STT_SECTION
: return "SECTION";
7099 case STT_FILE
: return "FILE";
7100 case STT_COMMON
: return "COMMON";
7101 case STT_TLS
: return "TLS";
7102 case STT_RELC
: return "RELC";
7103 case STT_SRELC
: return "SRELC";
7105 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
7107 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
7108 return "THUMB_FUNC";
7110 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
7113 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
7114 return "PARISC_MILLI";
7116 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
7118 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
7120 if (elf_header
.e_machine
== EM_PARISC
)
7122 if (type
== STT_HP_OPAQUE
)
7124 if (type
== STT_HP_STUB
)
7128 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
7131 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
7137 get_symbol_visibility (unsigned int visibility
)
7141 case STV_DEFAULT
: return "DEFAULT";
7142 case STV_INTERNAL
: return "INTERNAL";
7143 case STV_HIDDEN
: return "HIDDEN";
7144 case STV_PROTECTED
: return "PROTECTED";
7150 get_mips_symbol_other (unsigned int other
)
7154 case STO_OPTIONAL
: return "OPTIONAL";
7155 case STO_MIPS16
: return "MIPS16";
7156 default: return NULL
;
7161 get_symbol_other (unsigned int other
)
7163 const char * result
= NULL
;
7164 static char buff
[32];
7169 switch (elf_header
.e_machine
)
7172 result
= get_mips_symbol_other (other
);
7180 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
7185 get_symbol_index_type (unsigned int type
)
7187 static char buff
[32];
7191 case SHN_UNDEF
: return "UND";
7192 case SHN_ABS
: return "ABS";
7193 case SHN_COMMON
: return "COM";
7195 if (type
== SHN_IA_64_ANSI_COMMON
7196 && elf_header
.e_machine
== EM_IA_64
7197 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
7199 else if (elf_header
.e_machine
== EM_X86_64
7200 && type
== SHN_X86_64_LCOMMON
)
7202 else if (type
== SHN_MIPS_SCOMMON
7203 && elf_header
.e_machine
== EM_MIPS
)
7205 else if (type
== SHN_MIPS_SUNDEFINED
7206 && elf_header
.e_machine
== EM_MIPS
)
7208 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
7209 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
7210 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
7211 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
7212 else if (type
>= SHN_LORESERVE
)
7213 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
7215 sprintf (buff
, "%3d", type
);
7223 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
7225 unsigned char *e_data
;
7228 e_data
= cmalloc (number
, ent_size
);
7232 error (_("Out of memory\n"));
7236 if (fread (e_data
, ent_size
, number
, file
) != number
)
7238 error (_("Unable to read in dynamic data\n"));
7242 i_data
= cmalloc (number
, sizeof (*i_data
));
7246 error (_("Out of memory\n"));
7252 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7260 print_dynamic_symbol (bfd_vma si
, unsigned long hn
)
7262 Elf_Internal_Sym
*psym
;
7265 psym
= dynamic_symbols
+ si
;
7267 n
= print_vma (si
, DEC_5
);
7269 fputs (" " + n
, stdout
);
7270 printf (" %3lu: ", hn
);
7271 print_vma (psym
->st_value
, LONG_HEX
);
7273 print_vma (psym
->st_size
, DEC_5
);
7275 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7276 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7277 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7278 /* Check to see if any other bits in the st_other field are set.
7279 Note - displaying this information disrupts the layout of the
7280 table being generated, but for the moment this case is very
7282 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7283 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7284 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7285 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7286 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7288 printf (" <corrupt: %14ld>", psym
->st_name
);
7292 /* Dump the symbol table. */
7294 process_symbol_table (FILE *file
)
7296 Elf_Internal_Shdr
*section
;
7297 bfd_vma nbuckets
= 0;
7298 bfd_vma nchains
= 0;
7299 bfd_vma
*buckets
= NULL
;
7300 bfd_vma
*chains
= NULL
;
7301 bfd_vma ngnubuckets
= 0;
7302 bfd_vma
*gnubuckets
= NULL
;
7303 bfd_vma
*gnuchains
= NULL
;
7304 bfd_vma gnusymidx
= 0;
7306 if (! do_syms
&& !do_histogram
)
7309 if (dynamic_info
[DT_HASH
]
7311 || (do_using_dynamic
&& dynamic_strings
!= NULL
)))
7313 unsigned char nb
[8];
7314 unsigned char nc
[8];
7315 int hash_ent_size
= 4;
7317 if ((elf_header
.e_machine
== EM_ALPHA
7318 || elf_header
.e_machine
== EM_S390
7319 || elf_header
.e_machine
== EM_S390_OLD
)
7320 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7324 (archive_file_offset
7325 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7326 sizeof nb
+ sizeof nc
)),
7329 error (_("Unable to seek to start of dynamic information\n"));
7333 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7335 error (_("Failed to read in number of buckets\n"));
7339 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7341 error (_("Failed to read in number of chains\n"));
7345 nbuckets
= byte_get (nb
, hash_ent_size
);
7346 nchains
= byte_get (nc
, hash_ent_size
);
7348 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7349 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7351 if (buckets
== NULL
|| chains
== NULL
)
7355 if (dynamic_info_DT_GNU_HASH
7357 || (do_using_dynamic
&& dynamic_strings
!= NULL
)))
7359 unsigned char nb
[16];
7360 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
7361 bfd_vma buckets_vma
;
7364 (archive_file_offset
7365 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7369 error (_("Unable to seek to start of dynamic information\n"));
7373 if (fread (nb
, 16, 1, file
) != 1)
7375 error (_("Failed to read in number of buckets\n"));
7379 ngnubuckets
= byte_get (nb
, 4);
7380 gnusymidx
= byte_get (nb
+ 4, 4);
7381 bitmaskwords
= byte_get (nb
+ 8, 4);
7382 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7384 buckets_vma
+= bitmaskwords
* 4;
7386 buckets_vma
+= bitmaskwords
* 8;
7389 (archive_file_offset
7390 + offset_from_vma (file
, buckets_vma
, 4)),
7393 error (_("Unable to seek to start of dynamic information\n"));
7397 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7399 if (gnubuckets
== NULL
)
7402 for (i
= 0; i
< ngnubuckets
; i
++)
7403 if (gnubuckets
[i
] != 0)
7405 if (gnubuckets
[i
] < gnusymidx
)
7408 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7409 maxchain
= gnubuckets
[i
];
7412 if (maxchain
== 0xffffffff)
7415 maxchain
-= gnusymidx
;
7418 (archive_file_offset
7419 + offset_from_vma (file
, buckets_vma
7420 + 4 * (ngnubuckets
+ maxchain
), 4)),
7423 error (_("Unable to seek to start of dynamic information\n"));
7429 if (fread (nb
, 4, 1, file
) != 1)
7431 error (_("Failed to determine last chain length\n"));
7435 if (maxchain
+ 1 == 0)
7440 while ((byte_get (nb
, 4) & 1) == 0);
7443 (archive_file_offset
7444 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7447 error (_("Unable to seek to start of dynamic information\n"));
7451 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7453 if (gnuchains
== NULL
)
7457 if ((dynamic_info
[DT_HASH
] || dynamic_info_DT_GNU_HASH
)
7460 && dynamic_strings
!= NULL
)
7464 if (dynamic_info
[DT_HASH
])
7468 printf (_("\nSymbol table for image:\n"));
7470 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7472 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7474 for (hn
= 0; hn
< nbuckets
; hn
++)
7479 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7480 print_dynamic_symbol (si
, hn
);
7484 if (dynamic_info_DT_GNU_HASH
)
7486 printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
7488 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7490 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7492 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7493 if (gnubuckets
[hn
] != 0)
7495 bfd_vma si
= gnubuckets
[hn
];
7496 bfd_vma off
= si
- gnusymidx
;
7500 print_dynamic_symbol (si
, hn
);
7503 while ((gnuchains
[off
++] & 1) == 0);
7507 else if (do_syms
&& !do_using_dynamic
)
7511 for (i
= 0, section
= section_headers
;
7512 i
< elf_header
.e_shnum
;
7516 char *strtab
= NULL
;
7517 unsigned long int strtab_size
= 0;
7518 Elf_Internal_Sym
*symtab
;
7519 Elf_Internal_Sym
*psym
;
7522 if ( section
->sh_type
!= SHT_SYMTAB
7523 && section
->sh_type
!= SHT_DYNSYM
)
7526 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7527 SECTION_NAME (section
),
7528 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7530 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7532 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7534 symtab
= GET_ELF_SYMBOLS (file
, section
);
7538 if (section
->sh_link
== elf_header
.e_shstrndx
)
7540 strtab
= string_table
;
7541 strtab_size
= string_table_length
;
7543 else if (section
->sh_link
< elf_header
.e_shnum
)
7545 Elf_Internal_Shdr
*string_sec
;
7547 string_sec
= section_headers
+ section
->sh_link
;
7549 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
7550 1, string_sec
->sh_size
, _("string table"));
7551 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7554 for (si
= 0, psym
= symtab
;
7555 si
< section
->sh_size
/ section
->sh_entsize
;
7558 printf ("%6d: ", si
);
7559 print_vma (psym
->st_value
, LONG_HEX
);
7561 print_vma (psym
->st_size
, DEC_5
);
7562 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7563 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7564 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7565 /* Check to see if any other bits in the st_other field are set.
7566 Note - displaying this information disrupts the layout of the
7567 table being generated, but for the moment this case is very rare. */
7568 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7569 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7570 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7571 print_symbol (25, psym
->st_name
< strtab_size
7572 ? strtab
+ psym
->st_name
: "<corrupt>");
7574 if (section
->sh_type
== SHT_DYNSYM
&&
7575 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7577 unsigned char data
[2];
7578 unsigned short vers_data
;
7579 unsigned long offset
;
7583 offset
= offset_from_vma
7584 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7585 sizeof data
+ si
* sizeof (vers_data
));
7587 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7588 sizeof (data
), 1, _("version data"));
7590 vers_data
= byte_get (data
, 2);
7592 is_nobits
= (psym
->st_shndx
< elf_header
.e_shnum
7593 && section_headers
[psym
->st_shndx
].sh_type
7596 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7598 if ((vers_data
& 0x8000) || vers_data
> 1)
7600 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7601 && (is_nobits
|| ! check_def
))
7603 Elf_External_Verneed evn
;
7604 Elf_Internal_Verneed ivn
;
7605 Elf_Internal_Vernaux ivna
;
7607 /* We must test both. */
7608 offset
= offset_from_vma
7609 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7614 unsigned long vna_off
;
7616 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7619 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7620 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7622 vna_off
= offset
+ ivn
.vn_aux
;
7626 Elf_External_Vernaux evna
;
7628 get_data (&evna
, file
, vna_off
,
7630 _("version need aux (3)"));
7632 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7633 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7634 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7636 vna_off
+= ivna
.vna_next
;
7638 while (ivna
.vna_other
!= vers_data
7639 && ivna
.vna_next
!= 0);
7641 if (ivna
.vna_other
== vers_data
)
7644 offset
+= ivn
.vn_next
;
7646 while (ivn
.vn_next
!= 0);
7648 if (ivna
.vna_other
== vers_data
)
7651 ivna
.vna_name
< strtab_size
7652 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7656 else if (! is_nobits
)
7657 error (_("bad dynamic symbol\n"));
7664 if (vers_data
!= 0x8001
7665 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7667 Elf_Internal_Verdef ivd
;
7668 Elf_Internal_Verdaux ivda
;
7669 Elf_External_Verdaux evda
;
7670 unsigned long offset
;
7672 offset
= offset_from_vma
7674 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7675 sizeof (Elf_External_Verdef
));
7679 Elf_External_Verdef evd
;
7681 get_data (&evd
, file
, offset
, sizeof (evd
),
7682 1, _("version def"));
7684 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7685 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7686 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7688 offset
+= ivd
.vd_next
;
7690 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7691 && ivd
.vd_next
!= 0);
7693 offset
-= ivd
.vd_next
;
7694 offset
+= ivd
.vd_aux
;
7696 get_data (&evda
, file
, offset
, sizeof (evda
),
7697 1, _("version def aux"));
7699 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7701 if (psym
->st_name
!= ivda
.vda_name
)
7702 printf ((vers_data
& 0x8000)
7704 ivda
.vda_name
< strtab_size
7705 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7715 if (strtab
!= string_table
)
7721 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7723 if (do_histogram
&& buckets
!= NULL
)
7725 unsigned long *lengths
;
7726 unsigned long *counts
;
7729 unsigned long maxlength
= 0;
7730 unsigned long nzero_counts
= 0;
7731 unsigned long nsyms
= 0;
7733 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7734 (unsigned long) nbuckets
);
7735 printf (_(" Length Number %% of total Coverage\n"));
7737 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7738 if (lengths
== NULL
)
7740 error (_("Out of memory\n"));
7743 for (hn
= 0; hn
< nbuckets
; ++hn
)
7745 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7748 if (maxlength
< ++lengths
[hn
])
7753 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7756 error (_("Out of memory\n"));
7760 for (hn
= 0; hn
< nbuckets
; ++hn
)
7761 ++counts
[lengths
[hn
]];
7766 printf (" 0 %-10lu (%5.1f%%)\n",
7767 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7768 for (i
= 1; i
<= maxlength
; ++i
)
7770 nzero_counts
+= counts
[i
] * i
;
7771 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7772 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7773 (nzero_counts
* 100.0) / nsyms
);
7781 if (buckets
!= NULL
)
7787 if (do_histogram
&& dynamic_info_DT_GNU_HASH
)
7789 unsigned long *lengths
;
7790 unsigned long *counts
;
7792 unsigned long maxlength
= 0;
7793 unsigned long nzero_counts
= 0;
7794 unsigned long nsyms
= 0;
7796 lengths
= calloc (ngnubuckets
, sizeof (*lengths
));
7797 if (lengths
== NULL
)
7799 error (_("Out of memory\n"));
7803 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7804 (unsigned long) ngnubuckets
);
7805 printf (_(" Length Number %% of total Coverage\n"));
7807 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7808 if (gnubuckets
[hn
] != 0)
7810 bfd_vma off
, length
= 1;
7812 for (off
= gnubuckets
[hn
] - gnusymidx
;
7813 (gnuchains
[off
] & 1) == 0; ++off
)
7815 lengths
[hn
] = length
;
7816 if (length
> maxlength
)
7821 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7824 error (_("Out of memory\n"));
7828 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7829 ++counts
[lengths
[hn
]];
7831 if (ngnubuckets
> 0)
7834 printf (" 0 %-10lu (%5.1f%%)\n",
7835 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7836 for (j
= 1; j
<= maxlength
; ++j
)
7838 nzero_counts
+= counts
[j
] * j
;
7839 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7840 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7841 (nzero_counts
* 100.0) / nsyms
);
7855 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7859 if (dynamic_syminfo
== NULL
7861 /* No syminfo, this is ok. */
7864 /* There better should be a dynamic symbol section. */
7865 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7869 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7870 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7872 printf (_(" Num: Name BoundTo Flags\n"));
7873 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7875 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7877 printf ("%4d: ", i
);
7878 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7879 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7881 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7884 switch (dynamic_syminfo
[i
].si_boundto
)
7886 case SYMINFO_BT_SELF
:
7887 fputs ("SELF ", stdout
);
7889 case SYMINFO_BT_PARENT
:
7890 fputs ("PARENT ", stdout
);
7893 if (dynamic_syminfo
[i
].si_boundto
> 0
7894 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7895 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7897 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7901 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7905 if (flags
& SYMINFO_FLG_DIRECT
)
7907 if (flags
& SYMINFO_FLG_PASSTHRU
)
7908 printf (" PASSTHRU");
7909 if (flags
& SYMINFO_FLG_COPY
)
7911 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7912 printf (" LAZYLOAD");
7920 #ifdef SUPPORT_DISASSEMBLY
7922 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7924 printf (_("\nAssembly dump of section %s\n"),
7925 SECTION_NAME (section
));
7927 /* XXX -- to be done --- XXX */
7934 dump_section_as_strings (Elf_Internal_Shdr
*section
, FILE *file
)
7936 Elf_Internal_Shdr
*relsec
;
7937 bfd_size_type num_bytes
;
7942 char *name
= SECTION_NAME (section
);
7943 bfd_boolean some_strings_shown
;
7945 num_bytes
= section
->sh_size
;
7947 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7949 printf (_("\nSection '%s' has no data to dump.\n"), name
);
7953 addr
= section
->sh_addr
;
7955 start
= get_data (NULL
, file
, section
->sh_offset
, 1, num_bytes
,
7960 printf (_("\nString dump of section '%s':\n"), name
);
7962 /* If the section being dumped has relocations against it the user might
7963 be expecting these relocations to have been applied. Check for this
7964 case and issue a warning message in order to avoid confusion.
7965 FIXME: Maybe we ought to have an option that dumps a section with
7967 for (relsec
= section_headers
;
7968 relsec
< section_headers
+ elf_header
.e_shnum
;
7971 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
7972 || relsec
->sh_info
>= elf_header
.e_shnum
7973 || section_headers
+ relsec
->sh_info
!= section
7974 || relsec
->sh_size
== 0
7975 || relsec
->sh_link
>= elf_header
.e_shnum
)
7978 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
7983 end
= start
+ num_bytes
;
7984 some_strings_shown
= FALSE
;
7988 while (!ISPRINT (* data
))
7995 printf (" [%6tx] %s\n", data
- start
, data
);
7997 printf (" [%6Ix] %s\n", (size_t) (data
- start
), data
);
7999 data
+= strlen (data
);
8000 some_strings_shown
= TRUE
;
8004 if (! some_strings_shown
)
8005 printf (_(" No strings found in this section."));
8015 dump_section_as_bytes (Elf_Internal_Shdr
*section
, FILE *file
)
8017 Elf_Internal_Shdr
*relsec
;
8018 bfd_size_type bytes
;
8020 unsigned char *data
;
8021 unsigned char *start
;
8023 bytes
= section
->sh_size
;
8025 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
8027 printf (_("\nSection '%s' has no data to dump.\n"),
8028 SECTION_NAME (section
));
8032 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
8034 addr
= section
->sh_addr
;
8036 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
8041 /* If the section being dumped has relocations against it the user might
8042 be expecting these relocations to have been applied. Check for this
8043 case and issue a warning message in order to avoid confusion.
8044 FIXME: Maybe we ought to have an option that dumps a section with
8046 for (relsec
= section_headers
;
8047 relsec
< section_headers
+ elf_header
.e_shnum
;
8050 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8051 || relsec
->sh_info
>= elf_header
.e_shnum
8052 || section_headers
+ relsec
->sh_info
!= section
8053 || relsec
->sh_size
== 0
8054 || relsec
->sh_link
>= elf_header
.e_shnum
)
8057 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
8069 lbytes
= (bytes
> 16 ? 16 : bytes
);
8071 printf (" 0x%8.8lx ", (unsigned long) addr
);
8073 for (j
= 0; j
< 16; j
++)
8076 printf ("%2.2x", data
[j
]);
8084 for (j
= 0; j
< lbytes
; j
++)
8087 if (k
>= ' ' && k
< 0x7f)
8106 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
8107 DWARF debug sections. This is a target specific test. Note - we do not
8108 go through the whole including-target-headers-multiple-times route, (as
8109 we have already done with <elf/h8.h>) because this would become very
8110 messy and even then this function would have to contain target specific
8111 information (the names of the relocs instead of their numeric values).
8112 FIXME: This is not the correct way to solve this problem. The proper way
8113 is to have target specific reloc sizing and typing functions created by
8114 the reloc-macros.h header, in the same way that it already creates the
8115 reloc naming functions. */
8118 is_32bit_abs_reloc (unsigned int reloc_type
)
8120 switch (elf_header
.e_machine
)
8124 return reloc_type
== 1; /* R_386_32. */
8126 return reloc_type
== 1; /* R_68K_32. */
8128 return reloc_type
== 1; /* R_860_32. */
8130 return reloc_type
== 1; /* XXX Is this right ? */
8132 return reloc_type
== 1; /* R_ARC_32. */
8134 return reloc_type
== 2; /* R_ARM_ABS32 */
8137 return reloc_type
== 1;
8139 return reloc_type
== 0x12; /* R_byte4_data. */
8141 return reloc_type
== 3; /* R_CRIS_32. */
8144 return reloc_type
== 3; /* R_CR16_NUM32. */
8146 return reloc_type
== 15; /* R_CRX_NUM32. */
8148 return reloc_type
== 1;
8149 case EM_CYGNUS_D10V
:
8151 return reloc_type
== 6; /* R_D10V_32. */
8152 case EM_CYGNUS_D30V
:
8154 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
8156 return reloc_type
== 3; /* R_DLX_RELOC_32. */
8157 case EM_CYGNUS_FR30
:
8159 return reloc_type
== 3; /* R_FR30_32. */
8163 return reloc_type
== 1; /* R_H8_DIR32. */
8165 return reloc_type
== 0x65; /* R_IA64_SECREL32LSB. */
8168 return reloc_type
== 2; /* R_IP2K_32. */
8170 return reloc_type
== 2; /* R_IQ2000_32. */
8173 return reloc_type
== 3; /* R_M32C_32. */
8175 return reloc_type
== 34; /* R_M32R_32_RELA. */
8177 return reloc_type
== 1; /* R_MCORE_ADDR32. */
8179 return reloc_type
== 4; /* R_MEP_32. */
8181 return reloc_type
== 2; /* R_MIPS_32. */
8183 return reloc_type
== 4; /* R_MMIX_32. */
8184 case EM_CYGNUS_MN10200
:
8186 return reloc_type
== 1; /* R_MN10200_32. */
8187 case EM_CYGNUS_MN10300
:
8189 return reloc_type
== 1; /* R_MN10300_32. */
8192 return reloc_type
== 1; /* R_MSP43_32. */
8194 return reloc_type
== 2; /* R_MT_32. */
8195 case EM_ALTERA_NIOS2
:
8197 return reloc_type
== 1; /* R_NIOS_32. */
8200 return reloc_type
== 1; /* R_OR32_32. */
8202 return reloc_type
== 1; /* R_PARISC_DIR32. */
8205 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
8207 return reloc_type
== 1; /* R_PPC64_ADDR32. */
8209 return reloc_type
== 1; /* R_PPC_ADDR32. */
8211 return reloc_type
== 1; /* R_I370_ADDR31. */
8214 return reloc_type
== 4; /* R_S390_32. */
8216 return reloc_type
== 8; /* R_SCORE_ABS32. */
8218 return reloc_type
== 1; /* R_SH_DIR32. */
8219 case EM_SPARC32PLUS
:
8222 return reloc_type
== 3 /* R_SPARC_32. */
8223 || reloc_type
== 23; /* R_SPARC_UA32. */
8225 return reloc_type
== 6; /* R_SPU_ADDR32 */
8226 case EM_CYGNUS_V850
:
8228 return reloc_type
== 6; /* R_V850_ABS32. */
8230 return reloc_type
== 1; /* R_VAX_32. */
8232 return reloc_type
== 10; /* R_X86_64_32. */
8234 return reloc_type
== 1; /* R_XSTROMY16_32. */
8237 return reloc_type
== 1; /* R_XTENSA_32. */
8240 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
8241 elf_header
.e_machine
);
8246 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8247 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
8250 is_32bit_pcrel_reloc (unsigned int reloc_type
)
8252 switch (elf_header
.e_machine
)
8256 return reloc_type
== 2; /* R_386_PC32. */
8258 return reloc_type
== 4; /* R_68K_PC32. */
8260 return reloc_type
== 10; /* R_ALPHA_SREL32. */
8262 return reloc_type
== 3; /* R_ARM_REL32 */
8264 return reloc_type
== 0; /* R_PARISC_NONE. *//* FIXME: This reloc is generated, but it may be a bug. */
8266 return reloc_type
== 26; /* R_PPC_REL32. */
8268 return reloc_type
== 26; /* R_PPC64_REL32. */
8271 return reloc_type
== 5; /* R_390_PC32. */
8273 return reloc_type
== 2; /* R_SH_REL32. */
8274 case EM_SPARC32PLUS
:
8277 return reloc_type
== 6; /* R_SPARC_DISP32. */
8279 return reloc_type
== 13; /* R_SPU_REL32. */
8281 return reloc_type
== 2; /* R_X86_64_PC32. */
8284 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
8286 /* Do not abort or issue an error message here. Not all targets use
8287 pc-relative 32-bit relocs in their DWARF debug information and we
8288 have already tested for target coverage in is_32bit_abs_reloc. A
8289 more helpful warning message will be generated by
8290 debug_apply_relocations anyway, so just return. */
8295 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8296 a 64-bit absolute RELA relocation used in DWARF debug sections. */
8299 is_64bit_abs_reloc (unsigned int reloc_type
)
8301 switch (elf_header
.e_machine
)
8304 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
8306 return reloc_type
== 0x27; /* R_IA64_DIR64LSB. */
8308 return reloc_type
== 80; /* R_PARISC_DIR64. */
8310 return reloc_type
== 38; /* R_PPC64_ADDR64. */
8311 case EM_SPARC32PLUS
:
8314 return reloc_type
== 54; /* R_SPARC_UA64. */
8316 return reloc_type
== 1; /* R_X86_64_64. */
8319 return reloc_type
== 22; /* R_S390_64 */
8325 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8326 a 16-bit absolute RELA relocation used in DWARF debug sections. */
8329 is_16bit_abs_reloc (unsigned int reloc_type
)
8331 switch (elf_header
.e_machine
)
8335 return reloc_type
== 4; /* R_AVR_16. */
8336 case EM_CYGNUS_D10V
:
8338 return reloc_type
== 3; /* R_D10V_16. */
8342 return reloc_type
== R_H8_DIR16
;
8345 return reloc_type
== 1; /* R_IP2K_16. */
8348 return reloc_type
== 1; /* R_M32C_16 */
8351 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
8352 case EM_ALTERA_NIOS2
:
8354 return reloc_type
== 9; /* R_NIOS_16. */
8360 /* Uncompresses a section that was compressed using zlib, in place.
8361 * This is a copy of bfd_uncompress_section_contents, in bfd/compress.c */
8364 uncompress_section_contents (unsigned char **buffer
, dwarf_size_type
*size
)
8367 /* These are just to quiet gcc. */
8372 dwarf_size_type compressed_size
= *size
;
8373 unsigned char* compressed_buffer
= *buffer
;
8374 dwarf_size_type uncompressed_size
;
8375 unsigned char* uncompressed_buffer
;
8378 dwarf_size_type header_size
= 12;
8380 /* Read the zlib header. In this case, it should be "ZLIB" followed
8381 by the uncompressed section size, 8 bytes in big-endian order. */
8382 if (compressed_size
< header_size
8383 || ! streq ((char*) compressed_buffer
, "ZLIB"))
8385 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
8386 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
8387 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
8388 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
8389 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
8390 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
8391 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
8392 uncompressed_size
+= compressed_buffer
[11];
8394 /* It is possible the section consists of several compressed
8395 buffers concatenated together, so we uncompress in a loop. */
8399 strm
.avail_in
= compressed_size
- header_size
;
8400 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
8401 strm
.avail_out
= uncompressed_size
;
8402 uncompressed_buffer
= xmalloc (uncompressed_size
);
8404 rc
= inflateInit (&strm
);
8405 while (strm
.avail_in
> 0)
8409 strm
.next_out
= ((Bytef
*) uncompressed_buffer
8410 + (uncompressed_size
- strm
.avail_out
));
8411 rc
= inflate (&strm
, Z_FINISH
);
8412 if (rc
!= Z_STREAM_END
)
8414 rc
= inflateReset (&strm
);
8416 rc
= inflateEnd (&strm
);
8418 || strm
.avail_out
!= 0)
8421 free (compressed_buffer
);
8422 *buffer
= uncompressed_buffer
;
8423 *size
= uncompressed_size
;
8427 free (uncompressed_buffer
);
8429 #endif /* HAVE_ZLIB_H */
8432 /* Apply relocations to a debug section. */
8435 debug_apply_relocations (void *file
,
8436 Elf_Internal_Shdr
*section
,
8437 unsigned char *start
)
8439 Elf_Internal_Shdr
*relsec
;
8440 unsigned char *end
= start
+ section
->sh_size
;
8442 if (elf_header
.e_type
!= ET_REL
)
8445 /* Find the reloc section associated with the debug section. */
8446 for (relsec
= section_headers
;
8447 relsec
< section_headers
+ elf_header
.e_shnum
;
8450 bfd_boolean is_rela
;
8451 unsigned long num_relocs
;
8452 Elf_Internal_Rela
*relocs
, *rp
;
8453 Elf_Internal_Shdr
*symsec
;
8454 Elf_Internal_Sym
*symtab
;
8455 Elf_Internal_Sym
*sym
;
8457 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8458 || relsec
->sh_info
>= elf_header
.e_shnum
8459 || section_headers
+ relsec
->sh_info
!= section
8460 || relsec
->sh_size
== 0
8461 || relsec
->sh_link
>= elf_header
.e_shnum
)
8464 is_rela
= relsec
->sh_type
== SHT_RELA
;
8468 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8469 & relocs
, & num_relocs
))
8474 if (!slurp_rel_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8475 & relocs
, & num_relocs
))
8479 /* SH uses RELA but uses in place value instead of the addend field. */
8480 if (elf_header
.e_machine
== EM_SH
)
8483 symsec
= section_headers
+ relsec
->sh_link
;
8484 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
8486 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
8489 unsigned int reloc_type
;
8490 unsigned int reloc_size
;
8491 unsigned char * loc
;
8493 /* In MIPS little-endian objects, r_info isn't really a
8494 64-bit little-endian value: it has a 32-bit little-endian
8495 symbol index followed by four individual byte fields.
8496 Reorder INFO accordingly. */
8498 && elf_header
.e_machine
== EM_MIPS
8499 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
8500 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
8501 | ((rp
->r_info
>> 56) & 0xff)
8502 | ((rp
->r_info
>> 40) & 0xff00)
8503 | ((rp
->r_info
>> 24) & 0xff0000)
8504 | ((rp
->r_info
>> 8) & 0xff000000));
8506 reloc_type
= get_reloc_type (rp
->r_info
);
8508 if (is_32bit_abs_reloc (reloc_type
)
8509 || is_32bit_pcrel_reloc (reloc_type
))
8511 else if (is_64bit_abs_reloc (reloc_type
))
8513 else if (is_16bit_abs_reloc (reloc_type
))
8517 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
8518 reloc_type
, SECTION_NAME (section
));
8522 loc
= start
+ rp
->r_offset
;
8523 if ((loc
+ reloc_size
) > end
)
8525 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
8526 (unsigned long) rp
->r_offset
,
8527 SECTION_NAME (section
));
8531 sym
= symtab
+ get_reloc_symindex (rp
->r_info
);
8533 /* If the reloc has a symbol associated with it,
8534 make sure that it is of an appropriate type. */
8536 && ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
8537 /* Relocations against symbols without type can happen.
8538 Gcc -feliminate-dwarf2-dups may generate symbols
8539 without type for debug info. */
8540 && ELF_ST_TYPE (sym
->st_info
) != STT_NOTYPE
8541 /* Relocations against object symbols can happen,
8542 eg when referencing a global array. For an
8543 example of this see the _clz.o binary in libgcc.a. */
8544 && ELF_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
8546 warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
8547 get_symbol_type (ELF_ST_TYPE (sym
->st_info
)),
8548 (long int)(rp
- relocs
),
8549 SECTION_NAME (relsec
));
8553 addend
= is_rela
? rp
->r_addend
: byte_get (loc
, reloc_size
);
8555 if (is_32bit_pcrel_reloc (reloc_type
))
8556 byte_put (loc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
8559 byte_put (loc
, addend
+ sym
->st_value
, reloc_size
);
8569 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
8571 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
8572 Elf_Internal_Shdr
*sec
;
8574 int section_is_compressed
;
8576 /* If it is already loaded, do nothing. */
8577 if (section
->start
!= NULL
)
8580 /* Locate the debug section. */
8581 sec
= find_section (section
->uncompressed_name
);
8583 section
->name
= section
->uncompressed_name
;
8586 sec
= find_section (section
->compressed_name
);
8588 section
->name
= section
->compressed_name
;
8592 section_is_compressed
= section
->name
== section
->compressed_name
;
8594 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
8595 section
->address
= sec
->sh_addr
;
8596 section
->size
= sec
->sh_size
;
8597 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
8599 if (section
->start
== NULL
)
8602 if (section_is_compressed
)
8603 if (! uncompress_section_contents (§ion
->start
, §ion
->size
))
8606 if (debug_displays
[debug
].relocate
)
8607 debug_apply_relocations (file
, sec
, section
->start
);
8613 free_debug_section (enum dwarf_section_display_enum debug
)
8615 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
8617 if (section
->start
== NULL
)
8620 free ((char *) section
->start
);
8621 section
->start
= NULL
;
8622 section
->address
= 0;
8627 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
8629 char *name
= SECTION_NAME (section
);
8630 bfd_size_type length
;
8632 enum dwarf_section_display_enum i
;
8634 length
= section
->sh_size
;
8637 printf (_("\nSection '%s' has no debugging data.\n"), name
);
8641 if (const_strneq (name
, ".gnu.linkonce.wi."))
8642 name
= ".debug_info";
8644 /* See if we know how to display the contents of this section. */
8645 for (i
= 0; i
< max
; i
++)
8646 if (streq (debug_displays
[i
].section
.uncompressed_name
, name
)
8647 || streq (debug_displays
[i
].section
.compressed_name
, name
))
8649 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
8651 if (load_debug_section (i
, file
))
8653 result
&= debug_displays
[i
].display (sec
, file
);
8655 if (i
!= info
&& i
!= abbrev
)
8656 free_debug_section (i
);
8664 printf (_("Unrecognized debug section: %s\n"), name
);
8671 /* Set DUMP_SECTS for all sections where dumps were requested
8672 based on section name. */
8675 initialise_dumps_byname (void)
8677 struct dump_list_entry
*cur
;
8679 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
8684 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
8685 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
8687 request_dump_bynumber (i
, cur
->type
);
8692 warn (_("Section '%s' was not dumped because it does not exist!\n"),
8698 process_section_contents (FILE *file
)
8700 Elf_Internal_Shdr
*section
;
8706 initialise_dumps_byname ();
8708 for (i
= 0, section
= section_headers
;
8709 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8712 #ifdef SUPPORT_DISASSEMBLY
8713 if (dump_sects
[i
] & DISASS_DUMP
)
8714 disassemble_section (section
, file
);
8716 if (dump_sects
[i
] & HEX_DUMP
)
8717 dump_section_as_bytes (section
, file
);
8719 if (dump_sects
[i
] & DEBUG_DUMP
)
8720 display_debug_section (section
, file
);
8722 if (dump_sects
[i
] & STRING_DUMP
)
8723 dump_section_as_strings (section
, file
);
8726 /* Check to see if the user requested a
8727 dump of a section that does not exist. */
8728 while (i
++ < num_dump_sects
)
8730 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
8734 process_mips_fpe_exception (int mask
)
8739 if (mask
& OEX_FPU_INEX
)
8740 fputs ("INEX", stdout
), first
= 0;
8741 if (mask
& OEX_FPU_UFLO
)
8742 printf ("%sUFLO", first
? "" : "|"), first
= 0;
8743 if (mask
& OEX_FPU_OFLO
)
8744 printf ("%sOFLO", first
? "" : "|"), first
= 0;
8745 if (mask
& OEX_FPU_DIV0
)
8746 printf ("%sDIV0", first
? "" : "|"), first
= 0;
8747 if (mask
& OEX_FPU_INVAL
)
8748 printf ("%sINVAL", first
? "" : "|");
8751 fputs ("0", stdout
);
8754 /* ARM EABI attributes section. */
8759 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8762 } arm_attr_public_tag
;
8764 static const char *arm_attr_tag_CPU_arch
[] =
8765 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8767 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8768 static const char *arm_attr_tag_THUMB_ISA_use
[] =
8769 {"No", "Thumb-1", "Thumb-2"};
8770 static const char *arm_attr_tag_VFP_arch
[] =
8771 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16"};
8772 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
8773 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
8774 static const char *arm_attr_tag_ABI_PCS_config
[] =
8775 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8776 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8777 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
8778 {"V6", "SB", "TLS", "Unused"};
8779 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
8780 {"Absolute", "PC-relative", "SB-relative", "None"};
8781 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
8782 {"Absolute", "PC-relative", "None"};
8783 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
8784 {"None", "direct", "GOT-indirect"};
8785 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
8786 {"None", "??? 1", "2", "??? 3", "4"};
8787 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8788 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
8789 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8790 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8791 static const char *arm_attr_tag_ABI_FP_number_model
[] =
8792 {"Unused", "Finite", "RTABI", "IEEE 754"};
8793 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8794 static const char *arm_attr_tag_ABI_align8_preserved
[] =
8795 {"No", "Yes, except leaf SP", "Yes"};
8796 static const char *arm_attr_tag_ABI_enum_size
[] =
8797 {"Unused", "small", "int", "forced to int"};
8798 static const char *arm_attr_tag_ABI_HardFP_use
[] =
8799 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8800 static const char *arm_attr_tag_ABI_VFP_args
[] =
8801 {"AAPCS", "VFP registers", "custom"};
8802 static const char *arm_attr_tag_ABI_WMMX_args
[] =
8803 {"AAPCS", "WMMX registers", "custom"};
8804 static const char *arm_attr_tag_ABI_optimization_goals
[] =
8805 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8806 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8807 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
8808 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8809 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8811 #define LOOKUP(id, name) \
8812 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8813 static arm_attr_public_tag arm_attr_public_tags
[] =
8815 {4, "CPU_raw_name", 1, NULL
},
8816 {5, "CPU_name", 1, NULL
},
8817 LOOKUP(6, CPU_arch
),
8818 {7, "CPU_arch_profile", 0, NULL
},
8819 LOOKUP(8, ARM_ISA_use
),
8820 LOOKUP(9, THUMB_ISA_use
),
8821 LOOKUP(10, VFP_arch
),
8822 LOOKUP(11, WMMX_arch
),
8823 LOOKUP(12, NEON_arch
),
8824 LOOKUP(13, ABI_PCS_config
),
8825 LOOKUP(14, ABI_PCS_R9_use
),
8826 LOOKUP(15, ABI_PCS_RW_data
),
8827 LOOKUP(16, ABI_PCS_RO_DATA
),
8828 LOOKUP(17, ABI_PCS_GOT_use
),
8829 LOOKUP(18, ABI_PCS_wchar_t
),
8830 LOOKUP(19, ABI_FP_rounding
),
8831 LOOKUP(20, ABI_FP_denormal
),
8832 LOOKUP(21, ABI_FP_exceptions
),
8833 LOOKUP(22, ABI_FP_user_exceptions
),
8834 LOOKUP(23, ABI_FP_number_model
),
8835 LOOKUP(24, ABI_align8_needed
),
8836 LOOKUP(25, ABI_align8_preserved
),
8837 LOOKUP(26, ABI_enum_size
),
8838 LOOKUP(27, ABI_HardFP_use
),
8839 LOOKUP(28, ABI_VFP_args
),
8840 LOOKUP(29, ABI_WMMX_args
),
8841 LOOKUP(30, ABI_optimization_goals
),
8842 LOOKUP(31, ABI_FP_optimization_goals
),
8843 {32, "compatibility", 0, NULL
}
8847 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8850 read_uleb128 (unsigned char *p
, unsigned int *plen
)
8864 val
|= ((unsigned int)c
& 0x7f) << shift
;
8873 static unsigned char *
8874 display_arm_attribute (unsigned char *p
)
8879 arm_attr_public_tag
*attr
;
8883 tag
= read_uleb128 (p
, &len
);
8886 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
8888 if (arm_attr_public_tags
[i
].tag
== tag
)
8890 attr
= &arm_attr_public_tags
[i
];
8897 printf (" Tag_%s: ", attr
->name
);
8903 case 7: /* Tag_CPU_arch_profile. */
8904 val
= read_uleb128 (p
, &len
);
8908 case 0: printf ("None\n"); break;
8909 case 'A': printf ("Application\n"); break;
8910 case 'R': printf ("Realtime\n"); break;
8911 case 'M': printf ("Microcontroller\n"); break;
8912 default: printf ("??? (%d)\n", val
); break;
8916 case 32: /* Tag_compatibility. */
8917 val
= read_uleb128 (p
, &len
);
8919 printf ("flag = %d, vendor = %s\n", val
, p
);
8920 p
+= strlen((char *)p
) + 1;
8934 assert (attr
->type
& 0x80);
8935 val
= read_uleb128 (p
, &len
);
8937 type
= attr
->type
& 0x7f;
8939 printf ("??? (%d)\n", val
);
8941 printf ("%s\n", attr
->table
[val
]);
8948 type
= 1; /* String. */
8950 type
= 2; /* uleb128. */
8951 printf (" Tag_unknown_%d: ", tag
);
8956 printf ("\"%s\"\n", p
);
8957 p
+= strlen((char *)p
) + 1;
8961 val
= read_uleb128 (p
, &len
);
8963 printf ("%d (0x%x)\n", val
, val
);
8969 static unsigned char *
8970 display_gnu_attribute (unsigned char * p
,
8971 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8978 tag
= read_uleb128 (p
, &len
);
8981 /* Tag_compatibility is the only generic GNU attribute defined at
8985 val
= read_uleb128 (p
, &len
);
8987 printf ("flag = %d, vendor = %s\n", val
, p
);
8988 p
+= strlen ((char *) p
) + 1;
8992 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
8993 return display_proc_gnu_attribute (p
, tag
);
8996 type
= 1; /* String. */
8998 type
= 2; /* uleb128. */
8999 printf (" Tag_unknown_%d: ", tag
);
9003 printf ("\"%s\"\n", p
);
9004 p
+= strlen ((char *) p
) + 1;
9008 val
= read_uleb128 (p
, &len
);
9010 printf ("%d (0x%x)\n", val
, val
);
9016 static unsigned char *
9017 display_power_gnu_attribute (unsigned char *p
, int tag
)
9023 if (tag
== Tag_GNU_Power_ABI_FP
)
9025 val
= read_uleb128 (p
, &len
);
9027 printf (" Tag_GNU_Power_ABI_FP: ");
9032 printf ("Hard or soft float\n");
9035 printf ("Hard float\n");
9038 printf ("Soft float\n");
9041 printf ("??? (%d)\n", val
);
9047 if (tag
== Tag_GNU_Power_ABI_Vector
)
9049 val
= read_uleb128 (p
, &len
);
9051 printf (" Tag_GNU_Power_ABI_Vector: ");
9058 printf ("Generic\n");
9061 printf ("AltiVec\n");
9067 printf ("??? (%d)\n", val
);
9074 type
= 1; /* String. */
9076 type
= 2; /* uleb128. */
9077 printf (" Tag_unknown_%d: ", tag
);
9081 printf ("\"%s\"\n", p
);
9082 p
+= strlen ((char *) p
) + 1;
9086 val
= read_uleb128 (p
, &len
);
9088 printf ("%d (0x%x)\n", val
, val
);
9094 static unsigned char *
9095 display_mips_gnu_attribute (unsigned char *p
, int tag
)
9101 if (tag
== Tag_GNU_MIPS_ABI_FP
)
9103 val
= read_uleb128 (p
, &len
);
9105 printf (" Tag_GNU_MIPS_ABI_FP: ");
9110 printf ("Hard or soft float\n");
9113 printf ("Hard float (-mdouble-float)\n");
9116 printf ("Hard float (-msingle-float)\n");
9119 printf ("Soft float\n");
9122 printf ("64-bit float (-mips32r2 -mfp64)\n");
9125 printf ("??? (%d)\n", val
);
9132 type
= 1; /* String. */
9134 type
= 2; /* uleb128. */
9135 printf (" Tag_unknown_%d: ", tag
);
9139 printf ("\"%s\"\n", p
);
9140 p
+= strlen ((char *) p
) + 1;
9144 val
= read_uleb128 (p
, &len
);
9146 printf ("%d (0x%x)\n", val
, val
);
9153 process_attributes (FILE * file
,
9154 const char * public_name
,
9155 unsigned int proc_type
,
9156 unsigned char * (* display_pub_attribute
) (unsigned char *),
9157 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
9159 Elf_Internal_Shdr
*sect
;
9160 unsigned char *contents
;
9163 bfd_vma section_len
;
9167 /* Find the section header so that we get the size. */
9168 for (i
= 0, sect
= section_headers
;
9169 i
< elf_header
.e_shnum
;
9172 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
9175 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
9177 if (contents
== NULL
)
9183 len
= sect
->sh_size
- 1;
9189 bfd_boolean public_section
;
9190 bfd_boolean gnu_section
;
9192 section_len
= byte_get (p
, 4);
9195 if (section_len
> len
)
9197 printf (_("ERROR: Bad section length (%d > %d)\n"),
9198 (int) section_len
, (int) len
);
9203 printf ("Attribute Section: %s\n", p
);
9205 if (public_name
&& streq ((char *) p
, public_name
))
9206 public_section
= TRUE
;
9208 public_section
= FALSE
;
9210 if (streq ((char *) p
, "gnu"))
9213 gnu_section
= FALSE
;
9215 namelen
= strlen ((char *) p
) + 1;
9217 section_len
-= namelen
+ 4;
9219 while (section_len
> 0)
9225 size
= byte_get (p
, 4);
9226 if (size
> section_len
)
9228 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
9229 (int) size
, (int) section_len
);
9233 section_len
-= size
;
9240 printf ("File Attributes\n");
9243 printf ("Section Attributes:");
9246 printf ("Symbol Attributes:");
9252 val
= read_uleb128 (p
, &i
);
9256 printf (" %d", val
);
9261 printf ("Unknown tag: %d\n", tag
);
9262 public_section
= FALSE
;
9269 p
= display_pub_attribute (p
);
9271 else if (gnu_section
)
9274 p
= display_gnu_attribute (p
,
9275 display_proc_gnu_attribute
);
9279 /* ??? Do something sensible, like dump hex. */
9280 printf (" Unknown section contexts\n");
9287 printf (_("Unknown format '%c'\n"), *p
);
9295 process_arm_specific (FILE *file
)
9297 return process_attributes (file
, "aeabi", SHT_ARM_ATTRIBUTES
,
9298 display_arm_attribute
, NULL
);
9302 process_power_specific (FILE *file
)
9304 return process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
9305 display_power_gnu_attribute
);
9308 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
9309 Print the Address, Access and Initial fields of an entry at VMA ADDR
9310 and return the VMA of the next entry. */
9313 print_mips_got_entry (unsigned char *data
, bfd_vma pltgot
, bfd_vma addr
)
9316 print_vma (addr
, LONG_HEX
);
9318 if (addr
< pltgot
+ 0xfff0)
9319 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
9321 printf ("%10s", "");
9324 printf ("%*s", is_32bit_elf
? 8 : 16, "<unknown>");
9329 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
9330 print_vma (entry
, LONG_HEX
);
9332 return addr
+ (is_32bit_elf
? 4 : 8);
9336 process_mips_specific (FILE *file
)
9338 Elf_Internal_Dyn
*entry
;
9339 size_t liblist_offset
= 0;
9340 size_t liblistno
= 0;
9341 size_t conflictsno
= 0;
9342 size_t options_offset
= 0;
9343 size_t conflicts_offset
= 0;
9345 bfd_vma local_gotno
= 0;
9347 bfd_vma symtabno
= 0;
9349 process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
9350 display_mips_gnu_attribute
);
9352 /* We have a lot of special sections. Thanks SGI! */
9353 if (dynamic_section
== NULL
)
9354 /* No information available. */
9357 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
9358 switch (entry
->d_tag
)
9360 case DT_MIPS_LIBLIST
:
9362 = offset_from_vma (file
, entry
->d_un
.d_val
,
9363 liblistno
* sizeof (Elf32_External_Lib
));
9365 case DT_MIPS_LIBLISTNO
:
9366 liblistno
= entry
->d_un
.d_val
;
9368 case DT_MIPS_OPTIONS
:
9369 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
9371 case DT_MIPS_CONFLICT
:
9373 = offset_from_vma (file
, entry
->d_un
.d_val
,
9374 conflictsno
* sizeof (Elf32_External_Conflict
));
9376 case DT_MIPS_CONFLICTNO
:
9377 conflictsno
= entry
->d_un
.d_val
;
9380 pltgot
= entry
->d_un
.d_val
;
9381 case DT_MIPS_LOCAL_GOTNO
:
9382 local_gotno
= entry
->d_un
.d_val
;
9384 case DT_MIPS_GOTSYM
:
9385 gotsym
= entry
->d_un
.d_val
;
9387 case DT_MIPS_SYMTABNO
:
9388 symtabno
= entry
->d_un
.d_val
;
9394 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9396 Elf32_External_Lib
*elib
;
9399 elib
= get_data (NULL
, file
, liblist_offset
,
9400 liblistno
, sizeof (Elf32_External_Lib
),
9404 printf ("\nSection '.liblist' contains %lu entries:\n",
9405 (unsigned long) liblistno
);
9406 fputs (" Library Time Stamp Checksum Version Flags\n",
9409 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9416 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9417 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9418 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9419 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9420 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9422 tmp
= gmtime (&time
);
9423 snprintf (timebuf
, sizeof (timebuf
),
9424 "%04u-%02u-%02uT%02u:%02u:%02u",
9425 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9426 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9428 printf ("%3lu: ", (unsigned long) cnt
);
9429 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
9430 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
9432 printf ("<corrupt: %9ld>", liblist
.l_name
);
9433 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9436 if (liblist
.l_flags
== 0)
9447 { " EXACT_MATCH", LL_EXACT_MATCH
},
9448 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9449 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9450 { " EXPORTS", LL_EXPORTS
},
9451 { " DELAY_LOAD", LL_DELAY_LOAD
},
9452 { " DELTA", LL_DELTA
}
9454 int flags
= liblist
.l_flags
;
9457 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
9458 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9460 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9461 flags
^= l_flags_vals
[fcnt
].bit
;
9464 printf (" %#x", (unsigned int) flags
);
9474 if (options_offset
!= 0)
9476 Elf_External_Options
*eopt
;
9477 Elf_Internal_Shdr
*sect
= section_headers
;
9478 Elf_Internal_Options
*iopt
;
9479 Elf_Internal_Options
*option
;
9483 /* Find the section header so that we get the size. */
9484 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9487 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
9491 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
9494 error (_("Out of memory\n"));
9501 while (offset
< sect
->sh_size
)
9503 Elf_External_Options
*eoption
;
9505 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9507 option
->kind
= BYTE_GET (eoption
->kind
);
9508 option
->size
= BYTE_GET (eoption
->size
);
9509 option
->section
= BYTE_GET (eoption
->section
);
9510 option
->info
= BYTE_GET (eoption
->info
);
9512 offset
+= option
->size
;
9518 printf (_("\nSection '%s' contains %d entries:\n"),
9519 SECTION_NAME (sect
), cnt
);
9527 switch (option
->kind
)
9530 /* This shouldn't happen. */
9531 printf (" NULL %d %lx", option
->section
, option
->info
);
9534 printf (" REGINFO ");
9535 if (elf_header
.e_machine
== EM_MIPS
)
9538 Elf32_External_RegInfo
*ereg
;
9539 Elf32_RegInfo reginfo
;
9541 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9542 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9543 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9544 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9545 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9546 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9547 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9549 printf ("GPR %08lx GP 0x%lx\n",
9551 (unsigned long) reginfo
.ri_gp_value
);
9552 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9553 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9554 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9559 Elf64_External_RegInfo
*ereg
;
9560 Elf64_Internal_RegInfo reginfo
;
9562 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9563 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9564 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9565 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9566 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9567 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9568 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9570 printf ("GPR %08lx GP 0x",
9571 reginfo
.ri_gprmask
);
9572 printf_vma (reginfo
.ri_gp_value
);
9575 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9576 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9577 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9581 case ODK_EXCEPTIONS
:
9582 fputs (" EXCEPTIONS fpe_min(", stdout
);
9583 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9584 fputs (") fpe_max(", stdout
);
9585 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9586 fputs (")", stdout
);
9588 if (option
->info
& OEX_PAGE0
)
9589 fputs (" PAGE0", stdout
);
9590 if (option
->info
& OEX_SMM
)
9591 fputs (" SMM", stdout
);
9592 if (option
->info
& OEX_FPDBUG
)
9593 fputs (" FPDBUG", stdout
);
9594 if (option
->info
& OEX_DISMISS
)
9595 fputs (" DISMISS", stdout
);
9598 fputs (" PAD ", stdout
);
9599 if (option
->info
& OPAD_PREFIX
)
9600 fputs (" PREFIX", stdout
);
9601 if (option
->info
& OPAD_POSTFIX
)
9602 fputs (" POSTFIX", stdout
);
9603 if (option
->info
& OPAD_SYMBOL
)
9604 fputs (" SYMBOL", stdout
);
9607 fputs (" HWPATCH ", stdout
);
9608 if (option
->info
& OHW_R4KEOP
)
9609 fputs (" R4KEOP", stdout
);
9610 if (option
->info
& OHW_R8KPFETCH
)
9611 fputs (" R8KPFETCH", stdout
);
9612 if (option
->info
& OHW_R5KEOP
)
9613 fputs (" R5KEOP", stdout
);
9614 if (option
->info
& OHW_R5KCVTL
)
9615 fputs (" R5KCVTL", stdout
);
9618 fputs (" FILL ", stdout
);
9619 /* XXX Print content of info word? */
9622 fputs (" TAGS ", stdout
);
9623 /* XXX Print content of info word? */
9626 fputs (" HWAND ", stdout
);
9627 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9628 fputs (" R4KEOP_CHECKED", stdout
);
9629 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9630 fputs (" R4KEOP_CLEAN", stdout
);
9633 fputs (" HWOR ", stdout
);
9634 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9635 fputs (" R4KEOP_CHECKED", stdout
);
9636 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9637 fputs (" R4KEOP_CLEAN", stdout
);
9640 printf (" GP_GROUP %#06lx self-contained %#06lx",
9641 option
->info
& OGP_GROUP
,
9642 (option
->info
& OGP_SELF
) >> 16);
9645 printf (" IDENT %#06lx self-contained %#06lx",
9646 option
->info
& OGP_GROUP
,
9647 (option
->info
& OGP_SELF
) >> 16);
9650 /* This shouldn't happen. */
9651 printf (" %3d ??? %d %lx",
9652 option
->kind
, option
->section
, option
->info
);
9656 len
= sizeof (*eopt
);
9657 while (len
< option
->size
)
9658 if (((char *) option
)[len
] >= ' '
9659 && ((char *) option
)[len
] < 0x7f)
9660 printf ("%c", ((char *) option
)[len
++]);
9662 printf ("\\%03o", ((char *) option
)[len
++]);
9664 fputs ("\n", stdout
);
9672 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9674 Elf32_Conflict
*iconf
;
9677 if (dynamic_symbols
== NULL
)
9679 error (_("conflict list found without a dynamic symbol table\n"));
9683 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
9686 error (_("Out of memory\n"));
9692 Elf32_External_Conflict
*econf32
;
9694 econf32
= get_data (NULL
, file
, conflicts_offset
,
9695 conflictsno
, sizeof (*econf32
), _("conflict"));
9699 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9700 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9706 Elf64_External_Conflict
*econf64
;
9708 econf64
= get_data (NULL
, file
, conflicts_offset
,
9709 conflictsno
, sizeof (*econf64
), _("conflict"));
9713 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9714 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9719 printf (_("\nSection '.conflict' contains %lu entries:\n"),
9720 (unsigned long) conflictsno
);
9721 puts (_(" Num: Index Value Name"));
9723 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9725 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
9727 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9728 print_vma (psym
->st_value
, FULL_HEX
);
9730 if (VALID_DYNAMIC_NAME (psym
->st_name
))
9731 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
9733 printf ("<corrupt: %14ld>", psym
->st_name
);
9740 if (pltgot
!= 0 && local_gotno
!= 0)
9742 bfd_vma entry
, local_end
, global_end
;
9744 unsigned char *data
;
9748 addr_size
= (is_32bit_elf
? 4 : 8);
9749 local_end
= pltgot
+ local_gotno
* addr_size
;
9750 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
9752 offset
= offset_from_vma (file
, pltgot
, global_end
- pltgot
);
9753 data
= get_data (NULL
, file
, offset
, global_end
- pltgot
, 1, _("GOT"));
9754 printf (_("\nPrimary GOT:\n"));
9755 printf (_(" Canonical gp value: "));
9756 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
9759 printf (_(" Reserved entries:\n"));
9760 printf (_(" %*s %10s %*s Purpose\n"),
9761 addr_size
* 2, "Address", "Access",
9762 addr_size
* 2, "Initial");
9763 entry
= print_mips_got_entry (data
, pltgot
, entry
);
9764 printf (" Lazy resolver\n");
9766 && (byte_get (data
+ entry
- pltgot
, addr_size
)
9767 >> (addr_size
* 8 - 1)) != 0)
9769 entry
= print_mips_got_entry (data
, pltgot
, entry
);
9770 printf (" Module pointer (GNU extension)\n");
9774 if (entry
< local_end
)
9776 printf (_(" Local entries:\n"));
9777 printf (_(" %*s %10s %*s\n"),
9778 addr_size
* 2, "Address", "Access",
9779 addr_size
* 2, "Initial");
9780 while (entry
< local_end
)
9782 entry
= print_mips_got_entry (data
, pltgot
, entry
);
9788 if (gotsym
< symtabno
)
9792 printf (_(" Global entries:\n"));
9793 printf (_(" %*s %10s %*s %*s %-7s %3s %s\n"),
9794 addr_size
* 2, "Address", "Access",
9795 addr_size
* 2, "Initial",
9796 addr_size
* 2, "Sym.Val.", "Type", "Ndx", "Name");
9797 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
9798 for (i
= gotsym
; i
< symtabno
; i
++)
9800 Elf_Internal_Sym
*psym
;
9802 psym
= dynamic_symbols
+ i
;
9803 entry
= print_mips_got_entry (data
, pltgot
, entry
);
9805 print_vma (psym
->st_value
, LONG_HEX
);
9806 printf (" %-7s %3s ",
9807 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
9808 get_symbol_index_type (psym
->st_shndx
));
9809 if (VALID_DYNAMIC_NAME (psym
->st_name
))
9810 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
9812 printf ("<corrupt: %14ld>", psym
->st_name
);
9826 process_gnu_liblist (FILE *file
)
9828 Elf_Internal_Shdr
*section
, *string_sec
;
9829 Elf32_External_Lib
*elib
;
9838 for (i
= 0, section
= section_headers
;
9839 i
< elf_header
.e_shnum
;
9842 switch (section
->sh_type
)
9844 case SHT_GNU_LIBLIST
:
9845 if (section
->sh_link
>= elf_header
.e_shnum
)
9848 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
9853 string_sec
= section_headers
+ section
->sh_link
;
9855 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
9856 string_sec
->sh_size
, _("liblist string table"));
9857 strtab_size
= string_sec
->sh_size
;
9860 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9866 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9867 SECTION_NAME (section
),
9868 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9870 puts (" Library Time Stamp Checksum Version Flags");
9872 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9880 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9881 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9882 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9883 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9884 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9886 tmp
= gmtime (&time
);
9887 snprintf (timebuf
, sizeof (timebuf
),
9888 "%04u-%02u-%02uT%02u:%02u:%02u",
9889 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9890 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9892 printf ("%3lu: ", (unsigned long) cnt
);
9894 printf ("%-20s", liblist
.l_name
< strtab_size
9895 ? strtab
+ liblist
.l_name
: "<corrupt>");
9897 printf ("%-20.20s", liblist
.l_name
< strtab_size
9898 ? strtab
+ liblist
.l_name
: "<corrupt>");
9899 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9900 liblist
.l_version
, liblist
.l_flags
);
9911 get_note_type (unsigned e_type
)
9913 static char buff
[64];
9915 if (elf_header
.e_type
== ET_CORE
)
9919 return _("NT_AUXV (auxiliary vector)");
9921 return _("NT_PRSTATUS (prstatus structure)");
9923 return _("NT_FPREGSET (floating point registers)");
9925 return _("NT_PRPSINFO (prpsinfo structure)");
9927 return _("NT_TASKSTRUCT (task structure)");
9929 return _("NT_PRXFPREG (user_xfpregs structure)");
9931 return _("NT_PPC_VMX (ppc Altivec registers)");
9933 return _("NT_PSTATUS (pstatus structure)");
9935 return _("NT_FPREGS (floating point registers)");
9937 return _("NT_PSINFO (psinfo structure)");
9939 return _("NT_LWPSTATUS (lwpstatus_t structure)");
9941 return _("NT_LWPSINFO (lwpsinfo_t structure)");
9942 case NT_WIN32PSTATUS
:
9943 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9951 return _("NT_VERSION (version)");
9953 return _("NT_ARCH (architecture)");
9958 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9963 get_gnu_elf_note_type (unsigned e_type
)
9965 static char buff
[64];
9969 case NT_GNU_ABI_TAG
:
9970 return _("NT_GNU_ABI_TAG (ABI version tag)");
9972 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
9973 case NT_GNU_BUILD_ID
:
9974 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
9975 case NT_GNU_GOLD_VERSION
:
9976 return _("NT_GNU_GOLD_VERSION (gold version)");
9981 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9986 get_netbsd_elfcore_note_type (unsigned e_type
)
9988 static char buff
[64];
9990 if (e_type
== NT_NETBSDCORE_PROCINFO
)
9992 /* NetBSD core "procinfo" structure. */
9993 return _("NetBSD procinfo structure");
9996 /* As of Jan 2002 there are no other machine-independent notes
9997 defined for NetBSD core files. If the note type is less
9998 than the start of the machine-dependent note types, we don't
10001 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
10003 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
10007 switch (elf_header
.e_machine
)
10009 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
10010 and PT_GETFPREGS == mach+2. */
10015 case EM_SPARC32PLUS
:
10019 case NT_NETBSDCORE_FIRSTMACH
+0:
10020 return _("PT_GETREGS (reg structure)");
10021 case NT_NETBSDCORE_FIRSTMACH
+2:
10022 return _("PT_GETFPREGS (fpreg structure)");
10028 /* On all other arch's, PT_GETREGS == mach+1 and
10029 PT_GETFPREGS == mach+3. */
10033 case NT_NETBSDCORE_FIRSTMACH
+1:
10034 return _("PT_GETREGS (reg structure)");
10035 case NT_NETBSDCORE_FIRSTMACH
+3:
10036 return _("PT_GETFPREGS (fpreg structure)");
10042 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
10043 e_type
- NT_NETBSDCORE_FIRSTMACH
);
10047 /* Note that by the ELF standard, the name field is already null byte
10048 terminated, and namesz includes the terminating null byte.
10049 I.E. the value of namesz for the name "FSF" is 4.
10051 If the value of namesz is zero, there is no name present. */
10053 process_note (Elf_Internal_Note
*pnote
)
10055 const char *name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
10058 if (pnote
->namesz
== 0)
10059 /* If there is no note name, then use the default set of
10060 note type strings. */
10061 nt
= get_note_type (pnote
->type
);
10063 else if (const_strneq (pnote
->namedata
, "GNU"))
10064 /* GNU-specific object file notes. */
10065 nt
= get_gnu_elf_note_type (pnote
->type
);
10067 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
10068 /* NetBSD-specific core file notes. */
10069 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
10071 else if (strneq (pnote
->namedata
, "SPU/", 4))
10073 /* SPU-specific core file notes. */
10074 nt
= pnote
->namedata
+ 4;
10079 /* Don't recognize this note name; just use the default set of
10080 note type strings. */
10081 nt
= get_note_type (pnote
->type
);
10083 printf (" %s\t\t0x%08lx\t%s\n", name
, pnote
->descsz
, nt
);
10089 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
10091 Elf_External_Note
*pnotes
;
10092 Elf_External_Note
*external
;
10098 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
10104 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
10105 (unsigned long) offset
, (unsigned long) length
);
10106 printf (_(" Owner\t\tData size\tDescription\n"));
10108 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
10110 Elf_External_Note
*next
;
10111 Elf_Internal_Note inote
;
10114 inote
.type
= BYTE_GET (external
->type
);
10115 inote
.namesz
= BYTE_GET (external
->namesz
);
10116 inote
.namedata
= external
->name
;
10117 inote
.descsz
= BYTE_GET (external
->descsz
);
10118 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
10119 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
10121 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
10123 if (((char *) next
) > (((char *) pnotes
) + length
))
10125 warn (_("corrupt note found at offset %lx into core notes\n"),
10126 (long)((char *)external
- (char *)pnotes
));
10127 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
10128 inote
.type
, inote
.namesz
, inote
.descsz
);
10134 /* Verify that name is null terminated. It appears that at least
10135 one version of Linux (RedHat 6.0) generates corefiles that don't
10136 comply with the ELF spec by failing to include the null byte in
10138 if (inote
.namedata
[inote
.namesz
] != '\0')
10140 temp
= malloc (inote
.namesz
+ 1);
10144 error (_("Out of memory\n"));
10149 strncpy (temp
, inote
.namedata
, inote
.namesz
);
10150 temp
[inote
.namesz
] = 0;
10152 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
10153 inote
.namedata
= temp
;
10156 res
&= process_note (& inote
);
10171 process_corefile_note_segments (FILE *file
)
10173 Elf_Internal_Phdr
*segment
;
10177 if (! get_program_headers (file
))
10180 for (i
= 0, segment
= program_headers
;
10181 i
< elf_header
.e_phnum
;
10184 if (segment
->p_type
== PT_NOTE
)
10185 res
&= process_corefile_note_segment (file
,
10186 (bfd_vma
) segment
->p_offset
,
10187 (bfd_vma
) segment
->p_filesz
);
10194 process_note_sections (FILE *file
)
10196 Elf_Internal_Shdr
*section
;
10200 for (i
= 0, section
= section_headers
;
10201 i
< elf_header
.e_shnum
;
10203 if (section
->sh_type
== SHT_NOTE
)
10204 res
&= process_corefile_note_segment (file
,
10205 (bfd_vma
) section
->sh_offset
,
10206 (bfd_vma
) section
->sh_size
);
10212 process_notes (FILE *file
)
10214 /* If we have not been asked to display the notes then do nothing. */
10218 if (elf_header
.e_type
!= ET_CORE
)
10219 return process_note_sections (file
);
10221 /* No program headers means no NOTE segment. */
10222 if (elf_header
.e_phnum
> 0)
10223 return process_corefile_note_segments (file
);
10225 printf (_("No note segments present in the core file.\n"));
10230 process_arch_specific (FILE *file
)
10235 switch (elf_header
.e_machine
)
10238 return process_arm_specific (file
);
10240 case EM_MIPS_RS3_LE
:
10241 return process_mips_specific (file
);
10244 return process_power_specific (file
);
10253 get_file_header (FILE *file
)
10255 /* Read in the identity array. */
10256 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
10259 /* Determine how to read the rest of the header. */
10260 switch (elf_header
.e_ident
[EI_DATA
])
10262 default: /* fall through */
10263 case ELFDATANONE
: /* fall through */
10265 byte_get
= byte_get_little_endian
;
10266 byte_put
= byte_put_little_endian
;
10269 byte_get
= byte_get_big_endian
;
10270 byte_put
= byte_put_big_endian
;
10274 /* For now we only support 32 bit and 64 bit ELF files. */
10275 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
10277 /* Read in the rest of the header. */
10280 Elf32_External_Ehdr ehdr32
;
10282 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
10285 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
10286 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
10287 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
10288 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
10289 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
10290 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
10291 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
10292 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
10293 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
10294 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
10295 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
10296 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
10297 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
10301 Elf64_External_Ehdr ehdr64
;
10303 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10304 we will not be able to cope with the 64bit data found in
10305 64 ELF files. Detect this now and abort before we start
10306 overwriting things. */
10307 if (sizeof (bfd_vma
) < 8)
10309 error (_("This instance of readelf has been built without support for a\n\
10310 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10314 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
10317 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
10318 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
10319 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
10320 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
10321 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
10322 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
10323 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
10324 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
10325 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
10326 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
10327 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
10328 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
10329 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
10332 if (elf_header
.e_shoff
)
10334 /* There may be some extensions in the first section header. Don't
10335 bomb if we can't read it. */
10337 get_32bit_section_headers (file
, 1);
10339 get_64bit_section_headers (file
, 1);
10345 /* Process one ELF object file according to the command line options.
10346 This file may actually be stored in an archive. The file is
10347 positioned at the start of the ELF object. */
10350 process_object (char *file_name
, FILE *file
)
10354 if (! get_file_header (file
))
10356 error (_("%s: Failed to read file header\n"), file_name
);
10360 /* Initialise per file variables. */
10361 for (i
= ARRAY_SIZE (version_info
); i
--;)
10362 version_info
[i
] = 0;
10364 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
10365 dynamic_info
[i
] = 0;
10367 /* Process the file. */
10369 printf (_("\nFile: %s\n"), file_name
);
10371 /* Initialise the dump_sects array from the cmdline_dump_sects array.
10372 Note we do this even if cmdline_dump_sects is empty because we
10373 must make sure that the dump_sets array is zeroed out before each
10374 object file is processed. */
10375 if (num_dump_sects
> num_cmdline_dump_sects
)
10376 memset (dump_sects
, 0, num_dump_sects
* sizeof (* dump_sects
));
10378 if (num_cmdline_dump_sects
> 0)
10380 if (num_dump_sects
== 0)
10381 /* A sneaky way of allocating the dump_sects array. */
10382 request_dump_bynumber (num_cmdline_dump_sects
, 0);
10384 assert (num_dump_sects
>= num_cmdline_dump_sects
);
10385 memcpy (dump_sects
, cmdline_dump_sects
,
10386 num_cmdline_dump_sects
* sizeof (* dump_sects
));
10389 if (! process_file_header ())
10392 if (! process_section_headers (file
))
10394 /* Without loaded section headers we cannot process lots of
10396 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10398 if (! do_using_dynamic
)
10399 do_syms
= do_reloc
= 0;
10402 if (! process_section_groups (file
))
10404 /* Without loaded section groups we cannot process unwind. */
10408 if (process_program_headers (file
))
10409 process_dynamic_section (file
);
10411 process_relocs (file
);
10413 process_unwind (file
);
10415 process_symbol_table (file
);
10417 process_syminfo (file
);
10419 process_version_sections (file
);
10421 process_section_contents (file
);
10423 process_notes (file
);
10425 process_gnu_liblist (file
);
10427 process_arch_specific (file
);
10429 if (program_headers
)
10431 free (program_headers
);
10432 program_headers
= NULL
;
10435 if (section_headers
)
10437 free (section_headers
);
10438 section_headers
= NULL
;
10443 free (string_table
);
10444 string_table
= NULL
;
10445 string_table_length
= 0;
10448 if (dynamic_strings
)
10450 free (dynamic_strings
);
10451 dynamic_strings
= NULL
;
10452 dynamic_strings_length
= 0;
10455 if (dynamic_symbols
)
10457 free (dynamic_symbols
);
10458 dynamic_symbols
= NULL
;
10459 num_dynamic_syms
= 0;
10462 if (dynamic_syminfo
)
10464 free (dynamic_syminfo
);
10465 dynamic_syminfo
= NULL
;
10468 if (section_headers_groups
)
10470 free (section_headers_groups
);
10471 section_headers_groups
= NULL
;
10474 if (section_groups
)
10476 struct group_list
*g
, *next
;
10478 for (i
= 0; i
< group_count
; i
++)
10480 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
10487 free (section_groups
);
10488 section_groups
= NULL
;
10491 free_debug_memory ();
10496 /* Process an ELF archive.
10497 On entry the file is positioned just after the ARMAG string. */
10500 process_archive (char *file_name
, FILE *file
)
10502 struct ar_hdr arhdr
;
10504 unsigned long size
;
10505 unsigned long index_num
= 0;
10506 unsigned long *index_array
= NULL
;
10507 char *sym_table
= NULL
;
10508 unsigned long sym_size
= 0;
10509 char *longnames
= NULL
;
10510 unsigned long longnames_size
= 0;
10511 size_t file_name_size
;
10516 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
10517 if (got
!= sizeof arhdr
)
10522 error (_("%s: failed to read archive header\n"), file_name
);
10526 /* See if this is the archive symbol table. */
10527 if (const_strneq (arhdr
.ar_name
, "/ ")
10528 || const_strneq (arhdr
.ar_name
, "/SYM64/ "))
10530 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
10531 size
= size
+ (size
& 1);
10533 if (do_archive_index
)
10536 /* A buffer used to hold numbers read in from an archive index.
10537 These are always 4 bytes long and stored in big-endian format. */
10538 #define SIZEOF_AR_INDEX_NUMBERS 4
10539 unsigned char integer_buffer
[SIZEOF_AR_INDEX_NUMBERS
];
10540 unsigned char * index_buffer
;
10542 /* Check the size of the archive index. */
10543 if (size
< SIZEOF_AR_INDEX_NUMBERS
)
10545 error (_("%s: the archive index is empty\n"), file_name
);
10549 /* Read the numer of entries in the archive index. */
10550 got
= fread (integer_buffer
, 1, sizeof integer_buffer
, file
);
10551 if (got
!= sizeof (integer_buffer
))
10553 error (_("%s: failed to read archive index\n"), file_name
);
10556 index_num
= byte_get_big_endian (integer_buffer
, sizeof integer_buffer
);
10557 size
-= SIZEOF_AR_INDEX_NUMBERS
;
10559 /* Read in the archive index. */
10560 if (size
< index_num
* SIZEOF_AR_INDEX_NUMBERS
)
10562 error (_("%s: the archive index is supposed to have %ld entries, but the size in the header is too small\n"),
10563 file_name
, index_num
);
10566 index_buffer
= malloc (index_num
* SIZEOF_AR_INDEX_NUMBERS
);
10567 if (index_buffer
== NULL
)
10569 error (_("Out of memory whilst trying to read archive symbol index\n"));
10572 got
= fread (index_buffer
, SIZEOF_AR_INDEX_NUMBERS
, index_num
, file
);
10573 if (got
!= index_num
)
10575 free (index_buffer
);
10576 error (_("%s: failed to read archive index\n"), file_name
);
10580 size
-= index_num
* SIZEOF_AR_INDEX_NUMBERS
;
10582 /* Convert the index numbers into the host's numeric format. */
10583 index_array
= malloc (index_num
* sizeof (* index_array
));
10584 if (index_array
== NULL
)
10586 free (index_buffer
);
10587 error (_("Out of memory whilst trying to convert the archive symbol index\n"));
10591 for (i
= 0; i
< index_num
; i
++)
10592 index_array
[i
] = byte_get_big_endian ((unsigned char *)(index_buffer
+ (i
* SIZEOF_AR_INDEX_NUMBERS
)),
10593 SIZEOF_AR_INDEX_NUMBERS
);
10594 free (index_buffer
);
10596 /* The remaining space in the header is taken up by the symbol table. */
10599 error (_("%s: the archive has an index but no symbols\n"), file_name
);
10603 sym_table
= malloc (size
);
10605 if (sym_table
== NULL
)
10607 error (_("Out of memory whilst trying to read archive index symbol table\n"));
10611 got
= fread (sym_table
, 1, size
, file
);
10614 error (_("%s: failed to read archive index symbol table\n"), file_name
);
10621 if (fseek (file
, size
, SEEK_CUR
) != 0)
10623 error (_("%s: failed to skip archive symbol table\n"), file_name
);
10628 got
= fread (& arhdr
, 1, sizeof arhdr
, file
);
10629 if (got
!= sizeof arhdr
)
10637 error (_("%s: failed to read archive header following archive index\n"), file_name
);
10642 else if (do_archive_index
)
10643 printf (_("%s has no archive index\n"), file_name
);
10645 if (const_strneq (arhdr
.ar_name
, "// "))
10647 /* This is the archive string table holding long member
10650 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
10651 longnames
= malloc (longnames_size
);
10652 if (longnames
== NULL
)
10654 error (_("Out of memory reading long symbol names in archive\n"));
10659 if (fread (longnames
, longnames_size
, 1, file
) != 1)
10662 error (_("%s: failed to read long symbol name string table\n"), file_name
);
10667 if ((longnames_size
& 1) != 0)
10670 got
= fread (& arhdr
, 1, sizeof arhdr
, file
);
10671 if (got
!= sizeof arhdr
)
10677 error (_("%s: failed to read archive header following long symbol names\n"), file_name
);
10684 if (do_archive_index
)
10686 if (sym_table
== NULL
)
10687 error (_("%s: unable to dump the index as none was found\n"), file_name
);
10690 unsigned int i
, j
, k
, l
;
10692 unsigned long current_pos
;
10694 printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
10695 file_name
, index_num
, sym_size
);
10696 current_pos
= ftell (file
);
10698 for (i
= l
= 0; i
< index_num
; i
++)
10700 if ((i
== 0) || ((i
> 0) && (index_array
[i
] != index_array
[i
- 1])))
10702 if (fseek (file
, index_array
[i
], SEEK_SET
) != 0)
10704 error (_("%s: failed to seek to next file name\n"), file_name
);
10708 got
= fread (elf_name
, 1, 16, file
);
10711 error (_("%s: failed to read file name\n"), file_name
);
10716 if (elf_name
[0] == '/')
10718 /* We have a long name. */
10719 k
= j
= strtoul (elf_name
+ 1, NULL
, 10);
10720 while ((j
< longnames_size
) && (longnames
[j
] != '/'))
10722 longnames
[j
] = '\0';
10723 printf (_("Binary %s contains:\n"), longnames
+ k
);
10724 longnames
[j
] = '/';
10729 while ((elf_name
[j
] != '/') && (j
< 16))
10731 elf_name
[j
] = '\0';
10732 printf(_("Binary %s contains:\n"), elf_name
);
10737 error (_("%s: end of the symbol table reached before the end of the index\n"),
10741 printf ("\t%s\n", sym_table
+ l
);
10742 l
+= strlen (sym_table
+ l
) + 1;
10746 error (_("%s: symbols remain in the index symbol table, but without corresponding entries in the index table\n"),
10749 free (index_array
);
10750 index_array
= NULL
;
10753 if (fseek (file
, current_pos
, SEEK_SET
) != 0)
10755 error (_("%s: failed to seek back to start of object files in the archive\n"), file_name
);
10760 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
10761 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
10762 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
10763 && !do_section_groups
)
10764 return 0; /* Archive index only. */
10767 file_name_size
= strlen (file_name
);
10776 if (arhdr
.ar_name
[0] == '/')
10780 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
10781 if (off
>= longnames_size
)
10783 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
10788 name
= longnames
+ off
;
10789 nameend
= memchr (name
, '/', longnames_size
- off
);
10793 name
= arhdr
.ar_name
;
10794 nameend
= memchr (name
, '/', 16);
10797 if (nameend
== NULL
)
10799 error (_("%s: bad archive file name\n"), file_name
);
10804 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
10805 if (namealc
== NULL
)
10807 error (_("Out of memory\n"));
10812 memcpy (namealc
, file_name
, file_name_size
);
10813 namealc
[file_name_size
] = '(';
10814 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
10815 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
10816 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
10818 archive_file_offset
= ftell (file
);
10819 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
10821 ret
|= process_object (namealc
, file
);
10826 (archive_file_offset
10827 + archive_file_size
10828 + (archive_file_size
& 1)),
10831 error (_("%s: failed to seek to next archive header\n"), file_name
);
10836 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
10837 if (got
!= sizeof arhdr
)
10842 error (_("%s: failed to read archive header\n"), file_name
);
10849 if (index_array
!= NULL
)
10850 free (index_array
);
10851 if (sym_table
!= NULL
)
10853 if (longnames
!= NULL
)
10860 process_file (char *file_name
)
10863 struct stat statbuf
;
10864 char armag
[SARMAG
];
10867 if (stat (file_name
, &statbuf
) < 0)
10869 if (errno
== ENOENT
)
10870 error (_("'%s': No such file\n"), file_name
);
10872 error (_("Could not locate '%s'. System error message: %s\n"),
10873 file_name
, strerror (errno
));
10877 if (! S_ISREG (statbuf
.st_mode
))
10879 error (_("'%s' is not an ordinary file\n"), file_name
);
10883 file
= fopen (file_name
, "rb");
10886 error (_("Input file '%s' is not readable.\n"), file_name
);
10890 if (fread (armag
, SARMAG
, 1, file
) != 1)
10892 error (_("%s: Failed to read file's magic number\n"), file_name
);
10897 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
10898 ret
= process_archive (file_name
, file
);
10901 if (do_archive_index
)
10902 error (_("File %s is not an archive so its index cannot be displayed.\n"),
10906 archive_file_size
= archive_file_offset
= 0;
10907 ret
= process_object (file_name
, file
);
10915 #ifdef SUPPORT_DISASSEMBLY
10916 /* Needed by the i386 disassembler. For extra credit, someone could
10917 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10921 print_address (unsigned int addr
, FILE *outfile
)
10923 fprintf (outfile
,"0x%8.8x", addr
);
10926 /* Needed by the i386 disassembler. */
10928 db_task_printsym (unsigned int addr
)
10930 print_address (addr
, stderr
);
10935 main (int argc
, char **argv
)
10939 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10940 setlocale (LC_MESSAGES
, "");
10942 #if defined (HAVE_SETLOCALE)
10943 setlocale (LC_CTYPE
, "");
10945 bindtextdomain (PACKAGE
, LOCALEDIR
);
10946 textdomain (PACKAGE
);
10948 expandargv (&argc
, &argv
);
10950 parse_args (argc
, argv
);
10952 if (num_dump_sects
> 0)
10954 /* Make a copy of the dump_sects array. */
10955 cmdline_dump_sects
= malloc (num_dump_sects
* sizeof (* dump_sects
));
10956 if (cmdline_dump_sects
== NULL
)
10957 error (_("Out of memory allocating dump request table.\n"));
10960 memcpy (cmdline_dump_sects
, dump_sects
,
10961 num_dump_sects
* sizeof (* dump_sects
));
10962 num_cmdline_dump_sects
= num_dump_sects
;
10966 if (optind
< (argc
- 1))
10970 while (optind
< argc
)
10971 err
|= process_file (argv
[optind
++]);
10973 if (dump_sects
!= NULL
)
10975 if (cmdline_dump_sects
!= NULL
)
10976 free (cmdline_dump_sects
);