1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 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. */
45 #include <sys/types.h>
51 /* Define BFD64 here, even if our default architecture is 32 bit ELF
52 as this will allow us to read in and parse 64bit and 32bit ELF files.
53 Only do this if we believe that the compiler can support a 64 bit
54 data type. For now we only rely on GCC being able to do this. */
60 #include "elf/common.h"
61 #include "elf/external.h"
62 #include "elf/internal.h"
64 /* The following headers use the elf/reloc-macros.h file to
65 automatically generate relocation recognition functions
66 such as elf_mips_reloc_type() */
68 #define RELOC_MACROS_GEN_FUNC
70 #include "elf/alpha.h"
92 #include "elf/m68hc11.h"
93 #include "elf/mcore.h"
96 #include "elf/mn10200.h"
97 #include "elf/mn10300.h"
99 #include "elf/msp430.h"
100 #include "elf/or32.h"
103 #include "elf/ppc64.h"
104 #include "elf/s390.h"
106 #include "elf/sparc.h"
107 #include "elf/v850.h"
109 #include "elf/x86-64.h"
110 #include "elf/xstormy16.h"
112 #include "elf/iq2000.h"
113 #include "elf/xtensa.h"
119 #include "libiberty.h"
121 char *program_name
= "readelf";
122 static long archive_file_offset
;
123 static unsigned long archive_file_size
;
124 static unsigned long dynamic_addr
;
125 static bfd_size_type dynamic_size
;
126 static unsigned int dynamic_nent
;
127 static char *dynamic_strings
;
128 static unsigned long dynamic_strings_length
;
129 static char *string_table
;
130 static unsigned long string_table_length
;
131 static unsigned long num_dynamic_syms
;
132 static Elf_Internal_Sym
*dynamic_symbols
;
133 static Elf_Internal_Syminfo
*dynamic_syminfo
;
134 static unsigned long dynamic_syminfo_offset
;
135 static unsigned int dynamic_syminfo_nent
;
136 static char program_interpreter
[64];
137 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
138 static bfd_vma version_info
[16];
139 static Elf_Internal_Ehdr elf_header
;
140 static Elf_Internal_Shdr
*section_headers
;
141 static Elf_Internal_Phdr
*program_headers
;
142 static Elf_Internal_Dyn
*dynamic_section
;
143 static Elf_Internal_Shdr
*symtab_shndx_hdr
;
144 static int show_name
;
145 static int do_dynamic
;
148 static int do_sections
;
149 static int do_section_groups
;
150 static int do_section_details
;
151 static int do_segments
;
152 static int do_unwind
;
153 static int do_using_dynamic
;
154 static int do_header
;
156 static int do_version
;
158 static int do_histogram
;
159 static int do_debugging
;
162 static int is_32bit_elf
;
166 struct group_list
*next
;
167 unsigned int section_index
;
172 struct group_list
*root
;
173 unsigned int group_index
;
176 static size_t group_count
;
177 static struct group
*section_groups
;
178 static struct group
**section_headers_groups
;
180 /* A linked list of the section names for which dumps were requested
182 struct dump_list_entry
186 struct dump_list_entry
*next
;
188 static struct dump_list_entry
*dump_sects_byname
;
190 /* A dynamic array of flags indicating for which sections a hex dump
191 has been requested (via the -x switch) and/or a disassembly dump
192 (via the -i switch). */
193 char *cmdline_dump_sects
= NULL
;
194 unsigned num_cmdline_dump_sects
= 0;
196 /* A dynamic array of flags indicating for which sections a dump of
197 some kind has been requested. It is reset on a per-object file
198 basis and then initialised from the cmdline_dump_sects array,
199 the results of interpreting the -w switch, and the
200 dump_sects_byname list. */
201 char *dump_sects
= NULL
;
202 unsigned int num_dump_sects
= 0;
204 #define HEX_DUMP (1 << 0)
205 #define DISASS_DUMP (1 << 1)
206 #define DEBUG_DUMP (1 << 2)
208 /* How to print a vma value. */
209 typedef enum print_mode
221 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
225 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
226 ((X)->sh_name >= string_table_length \
227 ? "<corrupt>" : string_table + (X)->sh_name))
229 /* Given st_shndx I, map to section_headers index. */
230 #define SECTION_HEADER_INDEX(I) \
231 ((I) < SHN_LORESERVE \
233 : ((I) <= SHN_HIRESERVE \
235 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
237 /* Reverse of the above. */
238 #define SECTION_HEADER_NUM(N) \
239 ((N) < SHN_LORESERVE \
241 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
243 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
245 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
247 #define BYTE_GET(field) byte_get (field, sizeof (field))
249 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
251 #define GET_ELF_SYMBOLS(file, section) \
252 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
253 : get_64bit_elf_symbols (file, section))
255 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
256 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
257 already been called and verified that the string exists. */
258 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
260 /* This is just a bit of syntatic sugar. */
261 #define streq(a,b) (strcmp ((a), (b)) == 0)
262 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
265 get_data (void *var
, FILE *file
, long offset
, size_t size
, size_t nmemb
,
270 if (size
== 0 || nmemb
== 0)
273 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
275 error (_("Unable to seek to 0x%lx for %s\n"),
276 archive_file_offset
+ offset
, reason
);
283 /* Check for overflow. */
284 if (nmemb
< (~(size_t) 0 - 1) / size
)
285 /* + 1 so that we can '\0' terminate invalid string table sections. */
286 mvar
= malloc (size
* nmemb
+ 1);
290 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
291 (unsigned long)(size
* nmemb
), reason
);
295 ((char *) mvar
)[size
* nmemb
] = '\0';
298 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
300 error (_("Unable to read in 0x%lx bytes of %s\n"),
301 (unsigned long)(size
* nmemb
), reason
);
311 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
316 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
317 field
[6] = ((value
>> 24) >> 24) & 0xff;
318 field
[5] = ((value
>> 24) >> 16) & 0xff;
319 field
[4] = ((value
>> 24) >> 8) & 0xff;
322 field
[3] = (value
>> 24) & 0xff;
323 field
[2] = (value
>> 16) & 0xff;
326 field
[1] = (value
>> 8) & 0xff;
329 field
[0] = value
& 0xff;
333 error (_("Unhandled data length: %d\n"), size
);
338 #if defined BFD64 && !BFD_HOST_64BIT_LONG
340 print_dec_vma (bfd_vma vma
, int is_signed
)
346 if (is_signed
&& (bfd_signed_vma
) vma
< 0)
355 *bufp
++ = '0' + vma
% 10;
367 print_hex_vma (bfd_vma vma
)
375 char digit
= '0' + (vma
& 0x0f);
377 digit
+= 'a' - '0' - 10;
390 /* Print a VMA value. */
392 print_vma (bfd_vma vma
, print_mode mode
)
401 return printf ("0x%8.8lx", (unsigned long) vma
);
404 return printf ("%8.8lx", (unsigned long) vma
);
408 return printf ("%5ld", (long) vma
);
412 return printf ("0x%lx", (unsigned long) vma
);
415 return printf ("%lx", (unsigned long) vma
);
418 return printf ("%ld", (unsigned long) vma
);
421 return printf ("%lu", (unsigned long) vma
);
444 #if BFD_HOST_64BIT_LONG
445 return nc
+ printf ("%lx", vma
);
447 return nc
+ print_hex_vma (vma
);
451 #if BFD_HOST_64BIT_LONG
452 return printf ("%ld", vma
);
454 return print_dec_vma (vma
, 1);
458 #if BFD_HOST_64BIT_LONG
460 return printf ("%5ld", vma
);
462 return printf ("%#lx", vma
);
465 return printf ("%5ld", _bfd_int64_low (vma
));
467 return print_hex_vma (vma
);
471 #if BFD_HOST_64BIT_LONG
472 return printf ("%lu", vma
);
474 return print_dec_vma (vma
, 0);
482 /* Display a symbol on stdout. If do_wide is not true then
483 format the symbol to be at most WIDTH characters,
484 truncating as necessary. If WIDTH is negative then
485 format the string to be exactly - WIDTH characters,
486 truncating or padding as necessary. */
489 print_symbol (int width
, const char *symbol
)
492 printf ("%s", symbol
);
494 printf ("%-*.*s", width
, width
, symbol
);
496 printf ("%-.*s", width
, symbol
);
500 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
505 field
[7] = value
& 0xff;
506 field
[6] = (value
>> 8) & 0xff;
507 field
[5] = (value
>> 16) & 0xff;
508 field
[4] = (value
>> 24) & 0xff;
513 field
[3] = value
& 0xff;
514 field
[2] = (value
>> 8) & 0xff;
518 field
[1] = value
& 0xff;
522 field
[0] = value
& 0xff;
526 error (_("Unhandled data length: %d\n"), size
);
531 /* Return a pointer to section NAME, or NULL if no such section exists. */
533 static Elf_Internal_Shdr
*
534 find_section (const char *name
)
538 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
539 if (streq (SECTION_NAME (section_headers
+ i
), name
))
540 return section_headers
+ i
;
545 /* Guess the relocation size commonly used by the specific machines. */
548 guess_is_rela (unsigned long e_machine
)
552 /* Targets that use REL relocations. */
567 /* Targets that use RELA relocations. */
582 case EM_CYGNUS_MN10200
:
584 case EM_CYGNUS_MN10300
:
615 case EM_ALTERA_NIOS2
:
636 warn (_("Don't know about relocations on this machine architecture\n"));
642 slurp_rela_relocs (FILE *file
,
643 unsigned long rel_offset
,
644 unsigned long rel_size
,
645 Elf_Internal_Rela
**relasp
,
646 unsigned long *nrelasp
)
648 Elf_Internal_Rela
*relas
;
649 unsigned long nrelas
;
654 Elf32_External_Rela
*erelas
;
656 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
660 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
662 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
667 error (_("out of memory parsing relocs"));
671 for (i
= 0; i
< nrelas
; i
++)
673 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
674 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
675 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
682 Elf64_External_Rela
*erelas
;
684 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
688 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
690 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
695 error (_("out of memory parsing relocs"));
699 for (i
= 0; i
< nrelas
; i
++)
701 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
702 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
703 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
714 slurp_rel_relocs (FILE *file
,
715 unsigned long rel_offset
,
716 unsigned long rel_size
,
717 Elf_Internal_Rela
**relsp
,
718 unsigned long *nrelsp
)
720 Elf_Internal_Rela
*rels
;
726 Elf32_External_Rel
*erels
;
728 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
732 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
734 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
739 error (_("out of memory parsing relocs"));
743 for (i
= 0; i
< nrels
; i
++)
745 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
746 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
747 rels
[i
].r_addend
= 0;
754 Elf64_External_Rel
*erels
;
756 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
760 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
762 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
767 error (_("out of memory parsing relocs"));
771 for (i
= 0; i
< nrels
; i
++)
773 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
774 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
775 rels
[i
].r_addend
= 0;
785 /* Display the contents of the relocation data found at the specified
789 dump_relocations (FILE *file
,
790 unsigned long rel_offset
,
791 unsigned long rel_size
,
792 Elf_Internal_Sym
*symtab
,
795 unsigned long strtablen
,
799 Elf_Internal_Rela
*rels
;
802 if (is_rela
== UNKNOWN
)
803 is_rela
= guess_is_rela (elf_header
.e_machine
);
807 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
812 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
821 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
823 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
828 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
830 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
838 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
840 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
845 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
847 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
851 for (i
= 0; i
< rel_size
; i
++)
854 const char *rtype2
= NULL
;
855 const char *rtype3
= NULL
;
858 bfd_vma symtab_index
;
863 offset
= rels
[i
].r_offset
;
864 info
= rels
[i
].r_info
;
868 type
= ELF32_R_TYPE (info
);
869 symtab_index
= ELF32_R_SYM (info
);
873 /* The #ifdef BFD64 below is to prevent a compile time warning.
874 We know that if we do not have a 64 bit data type that we
875 will never execute this code anyway. */
877 if (elf_header
.e_machine
== EM_MIPS
)
879 /* In little-endian objects, r_info isn't really a 64-bit
880 little-endian value: it has a 32-bit little-endian
881 symbol index followed by four individual byte fields.
882 Reorder INFO accordingly. */
883 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
884 info
= (((info
& 0xffffffff) << 32)
885 | ((info
>> 56) & 0xff)
886 | ((info
>> 40) & 0xff00)
887 | ((info
>> 24) & 0xff0000)
888 | ((info
>> 8) & 0xff000000));
889 type
= ELF64_MIPS_R_TYPE (info
);
890 type2
= ELF64_MIPS_R_TYPE2 (info
);
891 type3
= ELF64_MIPS_R_TYPE3 (info
);
893 else if (elf_header
.e_machine
== EM_SPARCV9
)
894 type
= ELF64_R_TYPE_ID (info
);
896 type
= ELF64_R_TYPE (info
);
898 symtab_index
= ELF64_R_SYM (info
);
904 #ifdef _bfd_int64_low
905 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
907 printf ("%8.8lx %8.8lx ", offset
, info
);
912 #ifdef _bfd_int64_low
914 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
915 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
916 _bfd_int64_high (offset
),
917 _bfd_int64_low (offset
),
918 _bfd_int64_high (info
),
919 _bfd_int64_low (info
));
922 ? "%16.16lx %16.16lx "
923 : "%12.12lx %12.12lx ",
928 switch (elf_header
.e_machine
)
936 rtype
= elf_m32r_reloc_type (type
);
941 rtype
= elf_i386_reloc_type (type
);
946 rtype
= elf_m68hc11_reloc_type (type
);
950 rtype
= elf_m68k_reloc_type (type
);
954 rtype
= elf_i960_reloc_type (type
);
959 rtype
= elf_avr_reloc_type (type
);
966 rtype
= elf_sparc_reloc_type (type
);
971 rtype
= v850_reloc_type (type
);
976 rtype
= elf_d10v_reloc_type (type
);
981 rtype
= elf_d30v_reloc_type (type
);
985 rtype
= elf_dlx_reloc_type (type
);
989 rtype
= elf_sh_reloc_type (type
);
993 case EM_CYGNUS_MN10300
:
994 rtype
= elf_mn10300_reloc_type (type
);
998 case EM_CYGNUS_MN10200
:
999 rtype
= elf_mn10200_reloc_type (type
);
1003 case EM_CYGNUS_FR30
:
1004 rtype
= elf_fr30_reloc_type (type
);
1008 rtype
= elf_frv_reloc_type (type
);
1012 rtype
= elf_mcore_reloc_type (type
);
1016 rtype
= elf_mmix_reloc_type (type
);
1021 rtype
= elf_msp430_reloc_type (type
);
1025 rtype
= elf_ppc_reloc_type (type
);
1029 rtype
= elf_ppc64_reloc_type (type
);
1033 case EM_MIPS_RS3_LE
:
1034 rtype
= elf_mips_reloc_type (type
);
1037 rtype2
= elf_mips_reloc_type (type2
);
1038 rtype3
= elf_mips_reloc_type (type3
);
1043 rtype
= elf_alpha_reloc_type (type
);
1047 rtype
= elf_arm_reloc_type (type
);
1051 rtype
= elf_arc_reloc_type (type
);
1055 rtype
= elf_hppa_reloc_type (type
);
1061 rtype
= elf_h8_reloc_type (type
);
1066 rtype
= elf_or32_reloc_type (type
);
1071 rtype
= elf_pj_reloc_type (type
);
1074 rtype
= elf_ia64_reloc_type (type
);
1078 rtype
= elf_cris_reloc_type (type
);
1082 rtype
= elf_i860_reloc_type (type
);
1086 rtype
= elf_x86_64_reloc_type (type
);
1090 rtype
= i370_reloc_type (type
);
1095 rtype
= elf_s390_reloc_type (type
);
1099 rtype
= elf_xstormy16_reloc_type (type
);
1103 rtype
= elf_crx_reloc_type (type
);
1107 rtype
= elf_vax_reloc_type (type
);
1112 rtype
= elf_ip2k_reloc_type (type
);
1116 rtype
= elf_iq2000_reloc_type (type
);
1121 rtype
= elf_xtensa_reloc_type (type
);
1125 rtype
= elf_m32c_reloc_type (type
);
1129 rtype
= elf_mt_reloc_type (type
);
1133 rtype
= elf_bfin_reloc_type (type
);
1139 #ifdef _bfd_int64_low
1140 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1142 printf (_("unrecognized: %-7lx"), type
);
1145 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1147 if (elf_header
.e_machine
== EM_ALPHA
1148 && streq (rtype
, "R_ALPHA_LITUSE")
1151 switch (rels
[i
].r_addend
)
1153 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1154 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1155 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1156 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1157 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1158 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1159 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1160 default: rtype
= NULL
;
1163 printf (" (%s)", rtype
);
1167 printf (_("<unknown addend: %lx>"),
1168 (unsigned long) rels
[i
].r_addend
);
1171 else if (symtab_index
)
1173 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1174 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1177 Elf_Internal_Sym
*psym
;
1179 psym
= symtab
+ symtab_index
;
1182 print_vma (psym
->st_value
, LONG_HEX
);
1183 printf (is_32bit_elf
? " " : " ");
1185 if (psym
->st_name
== 0)
1187 const char *sec_name
= "<null>";
1190 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1192 bfd_vma sec_index
= (bfd_vma
) -1;
1194 if (psym
->st_shndx
< SHN_LORESERVE
)
1195 sec_index
= psym
->st_shndx
;
1196 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1197 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1200 if (sec_index
!= (bfd_vma
) -1)
1201 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1202 else if (psym
->st_shndx
== SHN_ABS
)
1204 else if (psym
->st_shndx
== SHN_COMMON
)
1205 sec_name
= "COMMON";
1206 else if (elf_header
.e_machine
== EM_X86_64
1207 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1208 sec_name
= "LARGE_COMMON";
1209 else if (elf_header
.e_machine
== EM_IA_64
1210 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1211 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1212 sec_name
= "ANSI_COM";
1215 sprintf (name_buf
, "<section 0x%x>",
1216 (unsigned int) psym
->st_shndx
);
1217 sec_name
= name_buf
;
1220 print_symbol (22, sec_name
);
1222 else if (strtab
== NULL
)
1223 printf (_("<string table index: %3ld>"), psym
->st_name
);
1224 else if (psym
->st_name
>= strtablen
)
1225 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1227 print_symbol (22, strtab
+ psym
->st_name
);
1230 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1235 printf ("%*c", is_32bit_elf
?
1236 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1237 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1240 if (elf_header
.e_machine
== EM_SPARCV9
&& streq (rtype
, "R_SPARC_OLO10"))
1241 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1245 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1247 printf (" Type2: ");
1250 #ifdef _bfd_int64_low
1251 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1253 printf (_("unrecognized: %-7lx"), type2
);
1256 printf ("%-17.17s", rtype2
);
1258 printf ("\n Type3: ");
1261 #ifdef _bfd_int64_low
1262 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1264 printf (_("unrecognized: %-7lx"), type3
);
1267 printf ("%-17.17s", rtype3
);
1279 get_mips_dynamic_type (unsigned long type
)
1283 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1284 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1285 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1286 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1287 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1288 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1289 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1290 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1291 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1292 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1293 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1294 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1295 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1296 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1297 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1298 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1299 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1300 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1301 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1302 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1303 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1304 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1305 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1306 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1307 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1308 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1309 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1310 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1311 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1312 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1313 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1314 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1315 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1316 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1317 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1318 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1319 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1320 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1321 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1322 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1323 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1324 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1325 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1332 get_sparc64_dynamic_type (unsigned long type
)
1336 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1343 get_ppc_dynamic_type (unsigned long type
)
1347 case DT_PPC_GOT
: return "PPC_GOT";
1354 get_ppc64_dynamic_type (unsigned long type
)
1358 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1359 case DT_PPC64_OPD
: return "PPC64_OPD";
1360 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1367 get_parisc_dynamic_type (unsigned long type
)
1371 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1372 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1373 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1374 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1375 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1376 case DT_HP_PREINIT
: return "HP_PREINIT";
1377 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1378 case DT_HP_NEEDED
: return "HP_NEEDED";
1379 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1380 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1381 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1382 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1383 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1384 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1385 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1386 case DT_HP_FILTERED
: return "HP_FILTERED";
1387 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1388 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1389 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1390 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1391 case DT_PLT
: return "PLT";
1392 case DT_PLT_SIZE
: return "PLT_SIZE";
1393 case DT_DLT
: return "DLT";
1394 case DT_DLT_SIZE
: return "DLT_SIZE";
1401 get_ia64_dynamic_type (unsigned long type
)
1405 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1412 get_alpha_dynamic_type (unsigned long type
)
1416 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1423 get_dynamic_type (unsigned long type
)
1425 static char buff
[64];
1429 case DT_NULL
: return "NULL";
1430 case DT_NEEDED
: return "NEEDED";
1431 case DT_PLTRELSZ
: return "PLTRELSZ";
1432 case DT_PLTGOT
: return "PLTGOT";
1433 case DT_HASH
: return "HASH";
1434 case DT_STRTAB
: return "STRTAB";
1435 case DT_SYMTAB
: return "SYMTAB";
1436 case DT_RELA
: return "RELA";
1437 case DT_RELASZ
: return "RELASZ";
1438 case DT_RELAENT
: return "RELAENT";
1439 case DT_STRSZ
: return "STRSZ";
1440 case DT_SYMENT
: return "SYMENT";
1441 case DT_INIT
: return "INIT";
1442 case DT_FINI
: return "FINI";
1443 case DT_SONAME
: return "SONAME";
1444 case DT_RPATH
: return "RPATH";
1445 case DT_SYMBOLIC
: return "SYMBOLIC";
1446 case DT_REL
: return "REL";
1447 case DT_RELSZ
: return "RELSZ";
1448 case DT_RELENT
: return "RELENT";
1449 case DT_PLTREL
: return "PLTREL";
1450 case DT_DEBUG
: return "DEBUG";
1451 case DT_TEXTREL
: return "TEXTREL";
1452 case DT_JMPREL
: return "JMPREL";
1453 case DT_BIND_NOW
: return "BIND_NOW";
1454 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1455 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1456 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1457 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1458 case DT_RUNPATH
: return "RUNPATH";
1459 case DT_FLAGS
: return "FLAGS";
1461 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1462 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1464 case DT_CHECKSUM
: return "CHECKSUM";
1465 case DT_PLTPADSZ
: return "PLTPADSZ";
1466 case DT_MOVEENT
: return "MOVEENT";
1467 case DT_MOVESZ
: return "MOVESZ";
1468 case DT_FEATURE
: return "FEATURE";
1469 case DT_POSFLAG_1
: return "POSFLAG_1";
1470 case DT_SYMINSZ
: return "SYMINSZ";
1471 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1473 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1474 case DT_CONFIG
: return "CONFIG";
1475 case DT_DEPAUDIT
: return "DEPAUDIT";
1476 case DT_AUDIT
: return "AUDIT";
1477 case DT_PLTPAD
: return "PLTPAD";
1478 case DT_MOVETAB
: return "MOVETAB";
1479 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1481 case DT_VERSYM
: return "VERSYM";
1483 case DT_RELACOUNT
: return "RELACOUNT";
1484 case DT_RELCOUNT
: return "RELCOUNT";
1485 case DT_FLAGS_1
: return "FLAGS_1";
1486 case DT_VERDEF
: return "VERDEF";
1487 case DT_VERDEFNUM
: return "VERDEFNUM";
1488 case DT_VERNEED
: return "VERNEED";
1489 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1491 case DT_AUXILIARY
: return "AUXILIARY";
1492 case DT_USED
: return "USED";
1493 case DT_FILTER
: return "FILTER";
1495 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1496 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1497 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1498 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1499 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1502 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1506 switch (elf_header
.e_machine
)
1509 case EM_MIPS_RS3_LE
:
1510 result
= get_mips_dynamic_type (type
);
1513 result
= get_sparc64_dynamic_type (type
);
1516 result
= get_ppc_dynamic_type (type
);
1519 result
= get_ppc64_dynamic_type (type
);
1522 result
= get_ia64_dynamic_type (type
);
1525 result
= get_alpha_dynamic_type (type
);
1535 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1537 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1538 || (elf_header
.e_machine
== EM_PARISC
1539 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1543 switch (elf_header
.e_machine
)
1546 result
= get_parisc_dynamic_type (type
);
1556 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1560 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1567 get_file_type (unsigned e_type
)
1569 static char buff
[32];
1573 case ET_NONE
: return _("NONE (None)");
1574 case ET_REL
: return _("REL (Relocatable file)");
1575 case ET_EXEC
: return _("EXEC (Executable file)");
1576 case ET_DYN
: return _("DYN (Shared object file)");
1577 case ET_CORE
: return _("CORE (Core file)");
1580 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1581 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1582 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1583 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1585 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1591 get_machine_name (unsigned e_machine
)
1593 static char buff
[64]; /* XXX */
1597 case EM_NONE
: return _("None");
1598 case EM_M32
: return "WE32100";
1599 case EM_SPARC
: return "Sparc";
1600 case EM_386
: return "Intel 80386";
1601 case EM_68K
: return "MC68000";
1602 case EM_88K
: return "MC88000";
1603 case EM_486
: return "Intel 80486";
1604 case EM_860
: return "Intel 80860";
1605 case EM_MIPS
: return "MIPS R3000";
1606 case EM_S370
: return "IBM System/370";
1607 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1608 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1609 case EM_PARISC
: return "HPPA";
1610 case EM_PPC_OLD
: return "Power PC (old)";
1611 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1612 case EM_960
: return "Intel 90860";
1613 case EM_PPC
: return "PowerPC";
1614 case EM_PPC64
: return "PowerPC64";
1615 case EM_V800
: return "NEC V800";
1616 case EM_FR20
: return "Fujitsu FR20";
1617 case EM_RH32
: return "TRW RH32";
1618 case EM_MCORE
: return "MCORE";
1619 case EM_ARM
: return "ARM";
1620 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1621 case EM_SH
: return "Renesas / SuperH SH";
1622 case EM_SPARCV9
: return "Sparc v9";
1623 case EM_TRICORE
: return "Siemens Tricore";
1624 case EM_ARC
: return "ARC";
1625 case EM_H8_300
: return "Renesas H8/300";
1626 case EM_H8_300H
: return "Renesas H8/300H";
1627 case EM_H8S
: return "Renesas H8S";
1628 case EM_H8_500
: return "Renesas H8/500";
1629 case EM_IA_64
: return "Intel IA-64";
1630 case EM_MIPS_X
: return "Stanford MIPS-X";
1631 case EM_COLDFIRE
: return "Motorola Coldfire";
1632 case EM_68HC12
: return "Motorola M68HC12";
1633 case EM_ALPHA
: return "Alpha";
1634 case EM_CYGNUS_D10V
:
1635 case EM_D10V
: return "d10v";
1636 case EM_CYGNUS_D30V
:
1637 case EM_D30V
: return "d30v";
1638 case EM_CYGNUS_M32R
:
1639 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1640 case EM_CYGNUS_V850
:
1641 case EM_V850
: return "NEC v850";
1642 case EM_CYGNUS_MN10300
:
1643 case EM_MN10300
: return "mn10300";
1644 case EM_CYGNUS_MN10200
:
1645 case EM_MN10200
: return "mn10200";
1646 case EM_CYGNUS_FR30
:
1647 case EM_FR30
: return "Fujitsu FR30";
1648 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1650 case EM_PJ
: return "picoJava";
1651 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1652 case EM_PCP
: return "Siemens PCP";
1653 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1654 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1655 case EM_STARCORE
: return "Motorola Star*Core processor";
1656 case EM_ME16
: return "Toyota ME16 processor";
1657 case EM_ST100
: return "STMicroelectronics ST100 processor";
1658 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1659 case EM_FX66
: return "Siemens FX66 microcontroller";
1660 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1661 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1662 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1663 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1664 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1665 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1666 case EM_SVX
: return "Silicon Graphics SVx";
1667 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1668 case EM_VAX
: return "Digital VAX";
1670 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1671 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1672 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1673 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1674 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1675 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1676 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1677 case EM_PRISM
: return "Vitesse Prism";
1678 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1680 case EM_S390
: return "IBM S/390";
1681 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1683 case EM_OR32
: return "OpenRISC";
1684 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1685 case EM_DLX
: return "OpenDLX";
1687 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1688 case EM_IQ2000
: return "Vitesse IQ2000";
1690 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1691 case EM_M32C
: return "Renesas M32c";
1692 case EM_MT
: return "Morpho Techologies MT processor";
1693 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1694 case EM_NIOS32
: return "Altera Nios";
1695 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1697 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_machine
);
1703 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1708 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1709 e_flags
&= ~ EF_ARM_EABIMASK
;
1711 /* Handle "generic" ARM flags. */
1712 if (e_flags
& EF_ARM_RELEXEC
)
1714 strcat (buf
, ", relocatable executable");
1715 e_flags
&= ~ EF_ARM_RELEXEC
;
1718 if (e_flags
& EF_ARM_HASENTRY
)
1720 strcat (buf
, ", has entry point");
1721 e_flags
&= ~ EF_ARM_HASENTRY
;
1724 /* Now handle EABI specific flags. */
1728 strcat (buf
, ", <unrecognized EABI>");
1733 case EF_ARM_EABI_VER1
:
1734 strcat (buf
, ", Version1 EABI");
1739 /* Process flags one bit at a time. */
1740 flag
= e_flags
& - e_flags
;
1745 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1746 strcat (buf
, ", sorted symbol tables");
1756 case EF_ARM_EABI_VER2
:
1757 strcat (buf
, ", Version2 EABI");
1762 /* Process flags one bit at a time. */
1763 flag
= e_flags
& - e_flags
;
1768 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1769 strcat (buf
, ", sorted symbol tables");
1772 case EF_ARM_DYNSYMSUSESEGIDX
:
1773 strcat (buf
, ", dynamic symbols use segment index");
1776 case EF_ARM_MAPSYMSFIRST
:
1777 strcat (buf
, ", mapping symbols precede others");
1787 case EF_ARM_EABI_VER3
:
1788 strcat (buf
, ", Version3 EABI");
1791 case EF_ARM_EABI_VER4
:
1792 strcat (buf
, ", Version4 EABI");
1797 /* Process flags one bit at a time. */
1798 flag
= e_flags
& - e_flags
;
1804 strcat (buf
, ", BE8");
1808 strcat (buf
, ", LE8");
1818 case EF_ARM_EABI_UNKNOWN
:
1819 strcat (buf
, ", GNU EABI");
1824 /* Process flags one bit at a time. */
1825 flag
= e_flags
& - e_flags
;
1830 case EF_ARM_INTERWORK
:
1831 strcat (buf
, ", interworking enabled");
1834 case EF_ARM_APCS_26
:
1835 strcat (buf
, ", uses APCS/26");
1838 case EF_ARM_APCS_FLOAT
:
1839 strcat (buf
, ", uses APCS/float");
1843 strcat (buf
, ", position independent");
1847 strcat (buf
, ", 8 bit structure alignment");
1850 case EF_ARM_NEW_ABI
:
1851 strcat (buf
, ", uses new ABI");
1854 case EF_ARM_OLD_ABI
:
1855 strcat (buf
, ", uses old ABI");
1858 case EF_ARM_SOFT_FLOAT
:
1859 strcat (buf
, ", software FP");
1862 case EF_ARM_VFP_FLOAT
:
1863 strcat (buf
, ", VFP");
1866 case EF_ARM_MAVERICK_FLOAT
:
1867 strcat (buf
, ", Maverick FP");
1878 strcat (buf
,", <unknown>");
1882 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1884 static char buf
[1024];
1896 decode_ARM_machine_flags (e_flags
, buf
);
1900 switch (e_flags
& EF_FRV_CPU_MASK
)
1902 case EF_FRV_CPU_GENERIC
:
1906 strcat (buf
, ", fr???");
1909 case EF_FRV_CPU_FR300
:
1910 strcat (buf
, ", fr300");
1913 case EF_FRV_CPU_FR400
:
1914 strcat (buf
, ", fr400");
1916 case EF_FRV_CPU_FR405
:
1917 strcat (buf
, ", fr405");
1920 case EF_FRV_CPU_FR450
:
1921 strcat (buf
, ", fr450");
1924 case EF_FRV_CPU_FR500
:
1925 strcat (buf
, ", fr500");
1927 case EF_FRV_CPU_FR550
:
1928 strcat (buf
, ", fr550");
1931 case EF_FRV_CPU_SIMPLE
:
1932 strcat (buf
, ", simple");
1934 case EF_FRV_CPU_TOMCAT
:
1935 strcat (buf
, ", tomcat");
1941 if (e_flags
& EF_CPU32
)
1942 strcat (buf
, ", cpu32");
1943 if (e_flags
& EF_M68000
)
1944 strcat (buf
, ", m68000");
1948 if (e_flags
& EF_PPC_EMB
)
1949 strcat (buf
, ", emb");
1951 if (e_flags
& EF_PPC_RELOCATABLE
)
1952 strcat (buf
, ", relocatable");
1954 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1955 strcat (buf
, ", relocatable-lib");
1959 case EM_CYGNUS_V850
:
1960 switch (e_flags
& EF_V850_ARCH
)
1963 strcat (buf
, ", v850e1");
1966 strcat (buf
, ", v850e");
1969 strcat (buf
, ", v850");
1972 strcat (buf
, ", unknown v850 architecture variant");
1978 case EM_CYGNUS_M32R
:
1979 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1980 strcat (buf
, ", m32r");
1985 case EM_MIPS_RS3_LE
:
1986 if (e_flags
& EF_MIPS_NOREORDER
)
1987 strcat (buf
, ", noreorder");
1989 if (e_flags
& EF_MIPS_PIC
)
1990 strcat (buf
, ", pic");
1992 if (e_flags
& EF_MIPS_CPIC
)
1993 strcat (buf
, ", cpic");
1995 if (e_flags
& EF_MIPS_UCODE
)
1996 strcat (buf
, ", ugen_reserved");
1998 if (e_flags
& EF_MIPS_ABI2
)
1999 strcat (buf
, ", abi2");
2001 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2002 strcat (buf
, ", odk first");
2004 if (e_flags
& EF_MIPS_32BITMODE
)
2005 strcat (buf
, ", 32bitmode");
2007 switch ((e_flags
& EF_MIPS_MACH
))
2009 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2010 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2011 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2012 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2013 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2014 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2015 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2016 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2017 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2018 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2020 /* We simply ignore the field in this case to avoid confusion:
2021 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2024 default: strcat (buf
, ", unknown CPU"); break;
2027 switch ((e_flags
& EF_MIPS_ABI
))
2029 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2030 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2031 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2032 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2034 /* We simply ignore the field in this case to avoid confusion:
2035 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2036 This means it is likely to be an o32 file, but not for
2039 default: strcat (buf
, ", unknown ABI"); break;
2042 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2043 strcat (buf
, ", mdmx");
2045 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2046 strcat (buf
, ", mips16");
2048 switch ((e_flags
& EF_MIPS_ARCH
))
2050 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2051 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2052 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2053 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2054 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2055 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2056 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2057 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2058 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2059 default: strcat (buf
, ", unknown ISA"); break;
2065 switch ((e_flags
& EF_SH_MACH_MASK
))
2067 case EF_SH1
: strcat (buf
, ", sh1"); break;
2068 case EF_SH2
: strcat (buf
, ", sh2"); break;
2069 case EF_SH3
: strcat (buf
, ", sh3"); break;
2070 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2071 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2072 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2073 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2074 case EF_SH4
: strcat (buf
, ", sh4"); break;
2075 case EF_SH5
: strcat (buf
, ", sh5"); break;
2076 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2077 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2078 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2079 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2080 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2081 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2082 default: strcat (buf
, ", unknown ISA"); break;
2088 if (e_flags
& EF_SPARC_32PLUS
)
2089 strcat (buf
, ", v8+");
2091 if (e_flags
& EF_SPARC_SUN_US1
)
2092 strcat (buf
, ", ultrasparcI");
2094 if (e_flags
& EF_SPARC_SUN_US3
)
2095 strcat (buf
, ", ultrasparcIII");
2097 if (e_flags
& EF_SPARC_HAL_R1
)
2098 strcat (buf
, ", halr1");
2100 if (e_flags
& EF_SPARC_LEDATA
)
2101 strcat (buf
, ", ledata");
2103 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2104 strcat (buf
, ", tso");
2106 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2107 strcat (buf
, ", pso");
2109 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2110 strcat (buf
, ", rmo");
2114 switch (e_flags
& EF_PARISC_ARCH
)
2116 case EFA_PARISC_1_0
:
2117 strcpy (buf
, ", PA-RISC 1.0");
2119 case EFA_PARISC_1_1
:
2120 strcpy (buf
, ", PA-RISC 1.1");
2122 case EFA_PARISC_2_0
:
2123 strcpy (buf
, ", PA-RISC 2.0");
2128 if (e_flags
& EF_PARISC_TRAPNIL
)
2129 strcat (buf
, ", trapnil");
2130 if (e_flags
& EF_PARISC_EXT
)
2131 strcat (buf
, ", ext");
2132 if (e_flags
& EF_PARISC_LSB
)
2133 strcat (buf
, ", lsb");
2134 if (e_flags
& EF_PARISC_WIDE
)
2135 strcat (buf
, ", wide");
2136 if (e_flags
& EF_PARISC_NO_KABP
)
2137 strcat (buf
, ", no kabp");
2138 if (e_flags
& EF_PARISC_LAZYSWAP
)
2139 strcat (buf
, ", lazyswap");
2144 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2145 strcat (buf
, ", new calling convention");
2147 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2148 strcat (buf
, ", gnu calling convention");
2152 if ((e_flags
& EF_IA_64_ABI64
))
2153 strcat (buf
, ", 64-bit");
2155 strcat (buf
, ", 32-bit");
2156 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2157 strcat (buf
, ", reduced fp model");
2158 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2159 strcat (buf
, ", no function descriptors, constant gp");
2160 else if ((e_flags
& EF_IA_64_CONS_GP
))
2161 strcat (buf
, ", constant gp");
2162 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2163 strcat (buf
, ", absolute");
2167 if ((e_flags
& EF_VAX_NONPIC
))
2168 strcat (buf
, ", non-PIC");
2169 if ((e_flags
& EF_VAX_DFLOAT
))
2170 strcat (buf
, ", D-Float");
2171 if ((e_flags
& EF_VAX_GFLOAT
))
2172 strcat (buf
, ", G-Float");
2181 get_osabi_name (unsigned int osabi
)
2183 static char buff
[32];
2187 case ELFOSABI_NONE
: return "UNIX - System V";
2188 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2189 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2190 case ELFOSABI_LINUX
: return "UNIX - Linux";
2191 case ELFOSABI_HURD
: return "GNU/Hurd";
2192 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2193 case ELFOSABI_AIX
: return "UNIX - AIX";
2194 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2195 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2196 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2197 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2198 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2199 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2200 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2201 case ELFOSABI_AROS
: return "Amiga Research OS";
2202 case ELFOSABI_STANDALONE
: return _("Standalone App");
2203 case ELFOSABI_ARM
: return "ARM";
2205 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2211 get_arm_segment_type (unsigned long type
)
2225 get_mips_segment_type (unsigned long type
)
2229 case PT_MIPS_REGINFO
:
2231 case PT_MIPS_RTPROC
:
2233 case PT_MIPS_OPTIONS
:
2243 get_parisc_segment_type (unsigned long type
)
2247 case PT_HP_TLS
: return "HP_TLS";
2248 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2249 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2250 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2251 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2252 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2253 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2254 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2255 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2256 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2257 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2258 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2259 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2260 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2261 case PT_HP_STACK
: return "HP_STACK";
2262 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2263 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2264 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2265 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2274 get_ia64_segment_type (unsigned long type
)
2278 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2279 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2280 case PT_HP_TLS
: return "HP_TLS";
2281 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2282 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2283 case PT_IA_64_HP_STACK
: return "HP_STACK";
2292 get_segment_type (unsigned long p_type
)
2294 static char buff
[32];
2298 case PT_NULL
: return "NULL";
2299 case PT_LOAD
: return "LOAD";
2300 case PT_DYNAMIC
: return "DYNAMIC";
2301 case PT_INTERP
: return "INTERP";
2302 case PT_NOTE
: return "NOTE";
2303 case PT_SHLIB
: return "SHLIB";
2304 case PT_PHDR
: return "PHDR";
2305 case PT_TLS
: return "TLS";
2307 case PT_GNU_EH_FRAME
:
2308 return "GNU_EH_FRAME";
2309 case PT_GNU_STACK
: return "GNU_STACK";
2310 case PT_GNU_RELRO
: return "GNU_RELRO";
2313 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2317 switch (elf_header
.e_machine
)
2320 result
= get_arm_segment_type (p_type
);
2323 case EM_MIPS_RS3_LE
:
2324 result
= get_mips_segment_type (p_type
);
2327 result
= get_parisc_segment_type (p_type
);
2330 result
= get_ia64_segment_type (p_type
);
2340 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2342 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2346 switch (elf_header
.e_machine
)
2349 result
= get_parisc_segment_type (p_type
);
2352 result
= get_ia64_segment_type (p_type
);
2362 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2365 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2372 get_mips_section_type_name (unsigned int sh_type
)
2376 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2377 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2378 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2379 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2380 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2381 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2382 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2383 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2384 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2385 case SHT_MIPS_RELD
: return "MIPS_RELD";
2386 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2387 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2388 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2389 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2390 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2391 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2392 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2393 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2394 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2395 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2396 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2397 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2398 case SHT_MIPS_LINE
: return "MIPS_LINE";
2399 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2400 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2401 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2402 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2403 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2404 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2405 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2406 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2407 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2408 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2409 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2410 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2411 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2412 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2413 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2414 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2422 get_parisc_section_type_name (unsigned int sh_type
)
2426 case SHT_PARISC_EXT
: return "PARISC_EXT";
2427 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2428 case SHT_PARISC_DOC
: return "PARISC_DOC";
2429 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2430 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2431 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2432 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2440 get_ia64_section_type_name (unsigned int sh_type
)
2442 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2443 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2444 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2448 case SHT_IA_64_EXT
: return "IA_64_EXT";
2449 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2450 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2458 get_x86_64_section_type_name (unsigned int sh_type
)
2462 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2470 get_arm_section_type_name (unsigned int sh_type
)
2476 case SHT_ARM_PREEMPTMAP
:
2477 return "ARM_PREEMPTMAP";
2478 case SHT_ARM_ATTRIBUTES
:
2479 return "ARM_ATTRIBUTES";
2487 get_section_type_name (unsigned int sh_type
)
2489 static char buff
[32];
2493 case SHT_NULL
: return "NULL";
2494 case SHT_PROGBITS
: return "PROGBITS";
2495 case SHT_SYMTAB
: return "SYMTAB";
2496 case SHT_STRTAB
: return "STRTAB";
2497 case SHT_RELA
: return "RELA";
2498 case SHT_HASH
: return "HASH";
2499 case SHT_DYNAMIC
: return "DYNAMIC";
2500 case SHT_NOTE
: return "NOTE";
2501 case SHT_NOBITS
: return "NOBITS";
2502 case SHT_REL
: return "REL";
2503 case SHT_SHLIB
: return "SHLIB";
2504 case SHT_DYNSYM
: return "DYNSYM";
2505 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2506 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2507 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2508 case SHT_GROUP
: return "GROUP";
2509 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2510 case SHT_GNU_verdef
: return "VERDEF";
2511 case SHT_GNU_verneed
: return "VERNEED";
2512 case SHT_GNU_versym
: return "VERSYM";
2513 case 0x6ffffff0: return "VERSYM";
2514 case 0x6ffffffc: return "VERDEF";
2515 case 0x7ffffffd: return "AUXILIARY";
2516 case 0x7fffffff: return "FILTER";
2517 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2520 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2524 switch (elf_header
.e_machine
)
2527 case EM_MIPS_RS3_LE
:
2528 result
= get_mips_section_type_name (sh_type
);
2531 result
= get_parisc_section_type_name (sh_type
);
2534 result
= get_ia64_section_type_name (sh_type
);
2537 result
= get_x86_64_section_type_name (sh_type
);
2540 result
= get_arm_section_type_name (sh_type
);
2550 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2552 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2553 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2554 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2555 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2557 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2563 #define OPTION_DEBUG_DUMP 512
2565 static struct option options
[] =
2567 {"all", no_argument
, 0, 'a'},
2568 {"file-header", no_argument
, 0, 'h'},
2569 {"program-headers", no_argument
, 0, 'l'},
2570 {"headers", no_argument
, 0, 'e'},
2571 {"histogram", no_argument
, 0, 'I'},
2572 {"segments", no_argument
, 0, 'l'},
2573 {"sections", no_argument
, 0, 'S'},
2574 {"section-headers", no_argument
, 0, 'S'},
2575 {"section-groups", no_argument
, 0, 'g'},
2576 {"section-details", no_argument
, 0, 't'},
2577 {"full-section-name",no_argument
, 0, 'N'},
2578 {"symbols", no_argument
, 0, 's'},
2579 {"syms", no_argument
, 0, 's'},
2580 {"relocs", no_argument
, 0, 'r'},
2581 {"notes", no_argument
, 0, 'n'},
2582 {"dynamic", no_argument
, 0, 'd'},
2583 {"arch-specific", no_argument
, 0, 'A'},
2584 {"version-info", no_argument
, 0, 'V'},
2585 {"use-dynamic", no_argument
, 0, 'D'},
2586 {"hex-dump", required_argument
, 0, 'x'},
2587 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2588 {"unwind", no_argument
, 0, 'u'},
2589 #ifdef SUPPORT_DISASSEMBLY
2590 {"instruction-dump", required_argument
, 0, 'i'},
2593 {"version", no_argument
, 0, 'v'},
2594 {"wide", no_argument
, 0, 'W'},
2595 {"help", no_argument
, 0, 'H'},
2596 {0, no_argument
, 0, 0}
2602 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2603 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2604 fprintf (stdout
, _(" Options are:\n\
2605 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2606 -h --file-header Display the ELF file header\n\
2607 -l --program-headers Display the program headers\n\
2608 --segments An alias for --program-headers\n\
2609 -S --section-headers Display the sections' header\n\
2610 --sections An alias for --section-headers\n\
2611 -g --section-groups Display the section groups\n\
2612 -t --section-details Display the section details\n\
2613 -e --headers Equivalent to: -h -l -S\n\
2614 -s --syms Display the symbol table\n\
2615 --symbols An alias for --syms\n\
2616 -n --notes Display the core notes (if present)\n\
2617 -r --relocs Display the relocations (if present)\n\
2618 -u --unwind Display the unwind info (if present)\n\
2619 -d --dynamic Display the dynamic section (if present)\n\
2620 -V --version-info Display the version sections (if present)\n\
2621 -A --arch-specific Display architecture specific information (if any).\n\
2622 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2623 -x --hex-dump=<number> Dump the contents of section <number>\n\
2624 -w[liaprmfFsoR] or\n\
2625 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2626 Display the contents of DWARF2 debug sections\n"));
2627 #ifdef SUPPORT_DISASSEMBLY
2628 fprintf (stdout
, _("\
2629 -i --instruction-dump=<number>\n\
2630 Disassemble the contents of section <number>\n"));
2632 fprintf (stdout
, _("\
2633 -I --histogram Display histogram of bucket list lengths\n\
2634 -W --wide Allow output width to exceed 80 characters\n\
2635 @<file> Read options from <file>\n\
2636 -H --help Display this information\n\
2637 -v --version Display the version number of readelf\n"));
2638 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2643 /* Record the fact that the user wants the contents of section number
2644 SECTION to be displayed using the method(s) encoded as flags bits
2645 in TYPE. Note, TYPE can be zero if we are creating the array for
2649 request_dump (unsigned int section
, int type
)
2651 if (section
>= num_dump_sects
)
2653 char *new_dump_sects
;
2655 new_dump_sects
= calloc (section
+ 1, 1);
2657 if (new_dump_sects
== NULL
)
2658 error (_("Out of memory allocating dump request table."));
2661 /* Copy current flag settings. */
2662 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2666 dump_sects
= new_dump_sects
;
2667 num_dump_sects
= section
+ 1;
2672 dump_sects
[section
] |= type
;
2677 /* Request a dump by section name. */
2680 request_dump_byname (const char *section
, int type
)
2682 struct dump_list_entry
*new_request
;
2684 new_request
= malloc (sizeof (struct dump_list_entry
));
2686 error (_("Out of memory allocating dump request table."));
2688 new_request
->name
= strdup (section
);
2689 if (!new_request
->name
)
2690 error (_("Out of memory allocating dump request table."));
2692 new_request
->type
= type
;
2694 new_request
->next
= dump_sects_byname
;
2695 dump_sects_byname
= new_request
;
2699 parse_args (int argc
, char **argv
)
2706 while ((c
= getopt_long
2707 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWH", options
, NULL
)) != EOF
)
2728 do_section_groups
++;
2736 do_section_groups
++;
2741 do_section_details
++;
2783 section
= strtoul (optarg
, & cp
, 0);
2784 if (! *cp
&& section
>= 0)
2785 request_dump (section
, HEX_DUMP
);
2787 request_dump_byname (optarg
, HEX_DUMP
);
2795 unsigned int index
= 0;
2799 while (optarg
[index
])
2800 switch (optarg
[index
++])
2809 do_debug_abbrevs
= 1;
2819 do_debug_pubnames
= 1;
2823 do_debug_aranges
= 1;
2827 do_debug_ranges
= 1;
2831 do_debug_frames_interp
= 1;
2833 do_debug_frames
= 1;
2838 do_debug_macinfo
= 1;
2852 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2857 case OPTION_DEBUG_DUMP
:
2865 const char * option
;
2868 debug_dump_long_opts
;
2870 debug_dump_long_opts opts_table
[] =
2872 /* Please keep this table alpha- sorted. */
2873 { "Ranges", & do_debug_ranges
},
2874 { "abbrev", & do_debug_abbrevs
},
2875 { "aranges", & do_debug_aranges
},
2876 { "frames", & do_debug_frames
},
2877 { "frames-interp", & do_debug_frames_interp
},
2878 { "info", & do_debug_info
},
2879 { "line", & do_debug_lines
},
2880 { "loc", & do_debug_loc
},
2881 { "macro", & do_debug_macinfo
},
2882 { "pubnames", & do_debug_pubnames
},
2883 /* This entry is for compatability
2884 with earlier versions of readelf. */
2885 { "ranges", & do_debug_aranges
},
2886 { "str", & do_debug_str
},
2897 debug_dump_long_opts
* entry
;
2899 for (entry
= opts_table
; entry
->option
; entry
++)
2901 size_t len
= strlen (entry
->option
);
2903 if (strneq (p
, entry
->option
, len
)
2904 && (p
[len
] == ',' || p
[len
] == '\0'))
2906 * entry
->variable
= 1;
2908 /* The --debug-dump=frames-interp option also
2909 enables the --debug-dump=frames option. */
2910 if (do_debug_frames_interp
)
2911 do_debug_frames
= 1;
2918 if (entry
->option
== NULL
)
2920 warn (_("Unrecognized debug option '%s'\n"), p
);
2921 p
= strchr (p
, ',');
2931 #ifdef SUPPORT_DISASSEMBLY
2934 section
= strtoul (optarg
, & cp
, 0);
2935 if (! *cp
&& section
>= 0)
2937 request_dump (section
, DISASS_DUMP
);
2943 print_version (program_name
);
2952 #ifdef SUPPORT_DISASSEMBLY
2955 /* xgettext:c-format */
2956 error (_("Invalid option '-%c'\n"), c
);
2963 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2964 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2965 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
2966 && !do_section_groups
)
2970 warn (_("Nothing to do.\n"));
2976 get_elf_class (unsigned int elf_class
)
2978 static char buff
[32];
2982 case ELFCLASSNONE
: return _("none");
2983 case ELFCLASS32
: return "ELF32";
2984 case ELFCLASS64
: return "ELF64";
2986 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
2992 get_data_encoding (unsigned int encoding
)
2994 static char buff
[32];
2998 case ELFDATANONE
: return _("none");
2999 case ELFDATA2LSB
: return _("2's complement, little endian");
3000 case ELFDATA2MSB
: return _("2's complement, big endian");
3002 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3007 /* Decode the data held in 'elf_header'. */
3010 process_file_header (void)
3012 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3013 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3014 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3015 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3018 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3026 printf (_("ELF Header:\n"));
3027 printf (_(" Magic: "));
3028 for (i
= 0; i
< EI_NIDENT
; i
++)
3029 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3031 printf (_(" Class: %s\n"),
3032 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3033 printf (_(" Data: %s\n"),
3034 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3035 printf (_(" Version: %d %s\n"),
3036 elf_header
.e_ident
[EI_VERSION
],
3037 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3039 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3042 printf (_(" OS/ABI: %s\n"),
3043 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3044 printf (_(" ABI Version: %d\n"),
3045 elf_header
.e_ident
[EI_ABIVERSION
]);
3046 printf (_(" Type: %s\n"),
3047 get_file_type (elf_header
.e_type
));
3048 printf (_(" Machine: %s\n"),
3049 get_machine_name (elf_header
.e_machine
));
3050 printf (_(" Version: 0x%lx\n"),
3051 (unsigned long) elf_header
.e_version
);
3053 printf (_(" Entry point address: "));
3054 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3055 printf (_("\n Start of program headers: "));
3056 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3057 printf (_(" (bytes into file)\n Start of section headers: "));
3058 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3059 printf (_(" (bytes into file)\n"));
3061 printf (_(" Flags: 0x%lx%s\n"),
3062 (unsigned long) elf_header
.e_flags
,
3063 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3064 printf (_(" Size of this header: %ld (bytes)\n"),
3065 (long) elf_header
.e_ehsize
);
3066 printf (_(" Size of program headers: %ld (bytes)\n"),
3067 (long) elf_header
.e_phentsize
);
3068 printf (_(" Number of program headers: %ld\n"),
3069 (long) elf_header
.e_phnum
);
3070 printf (_(" Size of section headers: %ld (bytes)\n"),
3071 (long) elf_header
.e_shentsize
);
3072 printf (_(" Number of section headers: %ld"),
3073 (long) elf_header
.e_shnum
);
3074 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3075 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3076 putc ('\n', stdout
);
3077 printf (_(" Section header string table index: %ld"),
3078 (long) elf_header
.e_shstrndx
);
3079 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3080 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3081 putc ('\n', stdout
);
3084 if (section_headers
!= NULL
)
3086 if (elf_header
.e_shnum
== 0)
3087 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3088 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3089 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3090 free (section_headers
);
3091 section_headers
= NULL
;
3099 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3101 Elf32_External_Phdr
*phdrs
;
3102 Elf32_External_Phdr
*external
;
3103 Elf_Internal_Phdr
*internal
;
3106 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3107 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3108 _("program headers"));
3112 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3113 i
< elf_header
.e_phnum
;
3114 i
++, internal
++, external
++)
3116 internal
->p_type
= BYTE_GET (external
->p_type
);
3117 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3118 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3119 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3120 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3121 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3122 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3123 internal
->p_align
= BYTE_GET (external
->p_align
);
3132 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3134 Elf64_External_Phdr
*phdrs
;
3135 Elf64_External_Phdr
*external
;
3136 Elf_Internal_Phdr
*internal
;
3139 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3140 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3141 _("program headers"));
3145 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3146 i
< elf_header
.e_phnum
;
3147 i
++, internal
++, external
++)
3149 internal
->p_type
= BYTE_GET (external
->p_type
);
3150 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3151 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3152 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3153 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3154 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3155 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3156 internal
->p_align
= BYTE_GET (external
->p_align
);
3164 /* Returns 1 if the program headers were read into `program_headers'. */
3167 get_program_headers (FILE *file
)
3169 Elf_Internal_Phdr
*phdrs
;
3171 /* Check cache of prior read. */
3172 if (program_headers
!= NULL
)
3175 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3179 error (_("Out of memory\n"));
3184 ? get_32bit_program_headers (file
, phdrs
)
3185 : get_64bit_program_headers (file
, phdrs
))
3187 program_headers
= phdrs
;
3195 /* Returns 1 if the program headers were loaded. */
3198 process_program_headers (FILE *file
)
3200 Elf_Internal_Phdr
*segment
;
3203 if (elf_header
.e_phnum
== 0)
3206 printf (_("\nThere are no program headers in this file.\n"));
3210 if (do_segments
&& !do_header
)
3212 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3213 printf (_("Entry point "));
3214 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3215 printf (_("\nThere are %d program headers, starting at offset "),
3216 elf_header
.e_phnum
);
3217 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3221 if (! get_program_headers (file
))
3226 if (elf_header
.e_phnum
> 1)
3227 printf (_("\nProgram Headers:\n"));
3229 printf (_("\nProgram Headers:\n"));
3233 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3236 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3240 (_(" Type Offset VirtAddr PhysAddr\n"));
3242 (_(" FileSiz MemSiz Flags Align\n"));
3249 for (i
= 0, segment
= program_headers
;
3250 i
< elf_header
.e_phnum
;
3255 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3259 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3260 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3261 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3262 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3263 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3265 (segment
->p_flags
& PF_R
? 'R' : ' '),
3266 (segment
->p_flags
& PF_W
? 'W' : ' '),
3267 (segment
->p_flags
& PF_X
? 'E' : ' '));
3268 printf ("%#lx", (unsigned long) segment
->p_align
);
3272 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3273 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3276 print_vma (segment
->p_offset
, FULL_HEX
);
3280 print_vma (segment
->p_vaddr
, FULL_HEX
);
3282 print_vma (segment
->p_paddr
, FULL_HEX
);
3285 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3286 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3289 print_vma (segment
->p_filesz
, FULL_HEX
);
3293 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3294 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3297 print_vma (segment
->p_offset
, FULL_HEX
);
3301 (segment
->p_flags
& PF_R
? 'R' : ' '),
3302 (segment
->p_flags
& PF_W
? 'W' : ' '),
3303 (segment
->p_flags
& PF_X
? 'E' : ' '));
3305 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3306 printf ("%#lx", (unsigned long) segment
->p_align
);
3309 print_vma (segment
->p_align
, PREFIX_HEX
);
3314 print_vma (segment
->p_offset
, FULL_HEX
);
3316 print_vma (segment
->p_vaddr
, FULL_HEX
);
3318 print_vma (segment
->p_paddr
, FULL_HEX
);
3320 print_vma (segment
->p_filesz
, FULL_HEX
);
3322 print_vma (segment
->p_memsz
, FULL_HEX
);
3324 (segment
->p_flags
& PF_R
? 'R' : ' '),
3325 (segment
->p_flags
& PF_W
? 'W' : ' '),
3326 (segment
->p_flags
& PF_X
? 'E' : ' '));
3327 print_vma (segment
->p_align
, HEX
);
3331 switch (segment
->p_type
)
3335 error (_("more than one dynamic segment\n"));
3337 /* Try to locate the .dynamic section. If there is
3338 a section header table, we can easily locate it. */
3339 if (section_headers
!= NULL
)
3341 Elf_Internal_Shdr
*sec
;
3343 sec
= find_section (".dynamic");
3344 if (sec
== NULL
|| sec
->sh_size
== 0)
3346 error (_("no .dynamic section in the dynamic segment"));
3350 dynamic_addr
= sec
->sh_offset
;
3351 dynamic_size
= sec
->sh_size
;
3353 if (dynamic_addr
< segment
->p_offset
3354 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3355 warn (_("the .dynamic section is not contained within the dynamic segment"));
3356 else if (dynamic_addr
> segment
->p_offset
)
3357 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3361 /* Otherwise, we can only assume that the .dynamic
3362 section is the first section in the DYNAMIC segment. */
3363 dynamic_addr
= segment
->p_offset
;
3364 dynamic_size
= segment
->p_filesz
;
3369 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3371 error (_("Unable to find program interpreter name\n"));
3374 program_interpreter
[0] = 0;
3375 fscanf (file
, "%63s", program_interpreter
);
3378 printf (_("\n [Requesting program interpreter: %s]"),
3379 program_interpreter
);
3385 putc ('\n', stdout
);
3388 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3390 printf (_("\n Section to Segment mapping:\n"));
3391 printf (_(" Segment Sections...\n"));
3393 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3396 Elf_Internal_Shdr
*section
;
3398 segment
= program_headers
+ i
;
3399 section
= section_headers
;
3401 printf (" %2.2d ", i
);
3403 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3405 if (section
->sh_size
> 0
3406 /* Compare allocated sections by VMA, unallocated
3407 sections by file offset. */
3408 && (section
->sh_flags
& SHF_ALLOC
3409 ? (section
->sh_addr
>= segment
->p_vaddr
3410 && section
->sh_addr
+ section
->sh_size
3411 <= segment
->p_vaddr
+ segment
->p_memsz
)
3412 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3413 && (section
->sh_offset
+ section
->sh_size
3414 <= segment
->p_offset
+ segment
->p_filesz
)))
3415 /* .tbss is special. It doesn't contribute memory space
3416 to normal segments. */
3417 && (!((section
->sh_flags
& SHF_TLS
) != 0
3418 && section
->sh_type
== SHT_NOBITS
)
3419 || segment
->p_type
== PT_TLS
))
3420 printf ("%s ", SECTION_NAME (section
));
3431 /* Find the file offset corresponding to VMA by using the program headers. */
3434 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3436 Elf_Internal_Phdr
*seg
;
3438 if (! get_program_headers (file
))
3440 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3444 for (seg
= program_headers
;
3445 seg
< program_headers
+ elf_header
.e_phnum
;
3448 if (seg
->p_type
!= PT_LOAD
)
3451 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3452 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3453 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3456 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3463 get_32bit_section_headers (FILE *file
, unsigned int num
)
3465 Elf32_External_Shdr
*shdrs
;
3466 Elf_Internal_Shdr
*internal
;
3469 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3470 elf_header
.e_shentsize
, num
, _("section headers"));
3474 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3476 if (section_headers
== NULL
)
3478 error (_("Out of memory\n"));
3482 for (i
= 0, internal
= section_headers
;
3486 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3487 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3488 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3489 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3490 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3491 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3492 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3493 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3494 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3495 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3504 get_64bit_section_headers (FILE *file
, unsigned int num
)
3506 Elf64_External_Shdr
*shdrs
;
3507 Elf_Internal_Shdr
*internal
;
3510 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3511 elf_header
.e_shentsize
, num
, _("section headers"));
3515 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3517 if (section_headers
== NULL
)
3519 error (_("Out of memory\n"));
3523 for (i
= 0, internal
= section_headers
;
3527 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3528 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3529 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3530 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3531 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3532 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3533 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3534 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3535 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3536 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3544 static Elf_Internal_Sym
*
3545 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3547 unsigned long number
;
3548 Elf32_External_Sym
*esyms
;
3549 Elf_External_Sym_Shndx
*shndx
;
3550 Elf_Internal_Sym
*isyms
;
3551 Elf_Internal_Sym
*psym
;
3554 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3560 if (symtab_shndx_hdr
!= NULL
3561 && (symtab_shndx_hdr
->sh_link
3562 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3564 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3565 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3573 number
= section
->sh_size
/ section
->sh_entsize
;
3574 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3578 error (_("Out of memory\n"));
3585 for (j
= 0, psym
= isyms
;
3589 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3590 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3591 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3592 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3593 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3595 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3596 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3597 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3607 static Elf_Internal_Sym
*
3608 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3610 unsigned long number
;
3611 Elf64_External_Sym
*esyms
;
3612 Elf_External_Sym_Shndx
*shndx
;
3613 Elf_Internal_Sym
*isyms
;
3614 Elf_Internal_Sym
*psym
;
3617 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3623 if (symtab_shndx_hdr
!= NULL
3624 && (symtab_shndx_hdr
->sh_link
3625 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3627 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3628 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3636 number
= section
->sh_size
/ section
->sh_entsize
;
3637 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3641 error (_("Out of memory\n"));
3648 for (j
= 0, psym
= isyms
;
3652 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3653 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3654 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3655 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3656 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3658 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3659 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3660 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3671 get_elf_section_flags (bfd_vma sh_flags
)
3673 static char buff
[1024];
3675 int field_size
= is_32bit_elf
? 8 : 16;
3676 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3677 bfd_vma os_flags
= 0;
3678 bfd_vma proc_flags
= 0;
3679 bfd_vma unknown_flags
= 0;
3693 { "LINK ORDER", 10 },
3694 { "OS NONCONF", 10 },
3699 if (do_section_details
)
3701 sprintf (buff
, "[%*.*lx]: ",
3702 field_size
, field_size
, (unsigned long) sh_flags
);
3703 p
+= field_size
+ 4;
3710 flag
= sh_flags
& - sh_flags
;
3713 if (do_section_details
)
3717 case SHF_WRITE
: index
= 0; break;
3718 case SHF_ALLOC
: index
= 1; break;
3719 case SHF_EXECINSTR
: index
= 2; break;
3720 case SHF_MERGE
: index
= 3; break;
3721 case SHF_STRINGS
: index
= 4; break;
3722 case SHF_INFO_LINK
: index
= 5; break;
3723 case SHF_LINK_ORDER
: index
= 6; break;
3724 case SHF_OS_NONCONFORMING
: index
= 7; break;
3725 case SHF_GROUP
: index
= 8; break;
3726 case SHF_TLS
: index
= 9; break;
3735 if (p
!= buff
+ field_size
+ 4)
3737 if (size
< (10 + 2))
3744 size
-= flags
[index
].len
;
3745 p
= stpcpy (p
, flags
[index
].str
);
3747 else if (flag
& SHF_MASKOS
)
3749 else if (flag
& SHF_MASKPROC
)
3752 unknown_flags
|= flag
;
3758 case SHF_WRITE
: *p
= 'W'; break;
3759 case SHF_ALLOC
: *p
= 'A'; break;
3760 case SHF_EXECINSTR
: *p
= 'X'; break;
3761 case SHF_MERGE
: *p
= 'M'; break;
3762 case SHF_STRINGS
: *p
= 'S'; break;
3763 case SHF_INFO_LINK
: *p
= 'I'; break;
3764 case SHF_LINK_ORDER
: *p
= 'L'; break;
3765 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3766 case SHF_GROUP
: *p
= 'G'; break;
3767 case SHF_TLS
: *p
= 'T'; break;
3770 if (elf_header
.e_machine
== EM_X86_64
3771 && flag
== SHF_X86_64_LARGE
)
3773 else if (flag
& SHF_MASKOS
)
3776 sh_flags
&= ~ SHF_MASKOS
;
3778 else if (flag
& SHF_MASKPROC
)
3781 sh_flags
&= ~ SHF_MASKPROC
;
3791 if (do_section_details
)
3795 size
-= 5 + field_size
;
3796 if (p
!= buff
+ field_size
+ 4)
3804 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3805 (unsigned long) os_flags
);
3806 p
+= 5 + field_size
;
3810 size
-= 7 + field_size
;
3811 if (p
!= buff
+ field_size
+ 4)
3819 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
3820 (unsigned long) proc_flags
);
3821 p
+= 7 + field_size
;
3825 size
-= 10 + field_size
;
3826 if (p
!= buff
+ field_size
+ 4)
3834 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
3835 (unsigned long) unknown_flags
);
3836 p
+= 10 + field_size
;
3845 process_section_headers (FILE *file
)
3847 Elf_Internal_Shdr
*section
;
3850 section_headers
= NULL
;
3852 if (elf_header
.e_shnum
== 0)
3855 printf (_("\nThere are no sections in this file.\n"));
3860 if (do_sections
&& !do_header
)
3861 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3862 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3866 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3869 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3872 /* Read in the string table, so that we have names to display. */
3873 if (SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
3875 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3877 if (section
->sh_size
!= 0)
3879 string_table
= get_data (NULL
, file
, section
->sh_offset
,
3880 1, section
->sh_size
, _("string table"));
3882 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
3886 /* Scan the sections for the dynamic symbol table
3887 and dynamic string table and debug sections. */
3888 dynamic_symbols
= NULL
;
3889 dynamic_strings
= NULL
;
3890 dynamic_syminfo
= NULL
;
3891 symtab_shndx_hdr
= NULL
;
3893 eh_addr_size
= is_32bit_elf
? 4 : 8;
3894 switch (elf_header
.e_machine
)
3897 case EM_MIPS_RS3_LE
:
3898 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
3899 FDE addresses. However, the ABI also has a semi-official ILP32
3900 variant for which the normal FDE address size rules apply.
3902 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
3903 section, where XX is the size of longs in bits. Unfortunately,
3904 earlier compilers provided no way of distinguishing ILP32 objects
3905 from LP64 objects, so if there's any doubt, we should assume that
3906 the official LP64 form is being used. */
3907 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
3908 && find_section (".gcc_compiled_long32") == NULL
)
3913 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
3916 size_t expected_entsize \
3917 = is_32bit_elf ? size32 : size64; \
3918 if (section->sh_entsize != expected_entsize) \
3919 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
3920 i, (unsigned long int) section->sh_entsize, \
3921 (unsigned long int) expected_entsize); \
3922 section->sh_entsize = expected_entsize; \
3925 #define CHECK_ENTSIZE(section, i, type) \
3926 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
3927 sizeof (Elf64_External_##type))
3929 for (i
= 0, section
= section_headers
;
3930 i
< elf_header
.e_shnum
;
3933 char *name
= SECTION_NAME (section
);
3935 if (section
->sh_type
== SHT_DYNSYM
)
3937 if (dynamic_symbols
!= NULL
)
3939 error (_("File contains multiple dynamic symbol tables\n"));
3943 CHECK_ENTSIZE (section
, i
, Sym
);
3944 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3945 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3947 else if (section
->sh_type
== SHT_STRTAB
3948 && streq (name
, ".dynstr"))
3950 if (dynamic_strings
!= NULL
)
3952 error (_("File contains multiple dynamic string tables\n"));
3956 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
3957 1, section
->sh_size
, _("dynamic strings"));
3958 dynamic_strings_length
= section
->sh_size
;
3960 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3962 if (symtab_shndx_hdr
!= NULL
)
3964 error (_("File contains multiple symtab shndx tables\n"));
3967 symtab_shndx_hdr
= section
;
3969 else if (section
->sh_type
== SHT_SYMTAB
)
3970 CHECK_ENTSIZE (section
, i
, Sym
);
3971 else if (section
->sh_type
== SHT_GROUP
)
3972 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
3973 else if (section
->sh_type
== SHT_REL
)
3974 CHECK_ENTSIZE (section
, i
, Rel
);
3975 else if (section
->sh_type
== SHT_RELA
)
3976 CHECK_ENTSIZE (section
, i
, Rela
);
3977 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3978 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3979 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3980 || do_debug_loc
|| do_debug_ranges
)
3981 && strneq (name
, ".debug_", 7))
3986 || (do_debug_info
&& streq (name
, "info"))
3987 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
3988 || (do_debug_lines
&& streq (name
, "line"))
3989 || (do_debug_pubnames
&& streq (name
, "pubnames"))
3990 || (do_debug_aranges
&& streq (name
, "aranges"))
3991 || (do_debug_ranges
&& streq (name
, "ranges"))
3992 || (do_debug_frames
&& streq (name
, "frame"))
3993 || (do_debug_macinfo
&& streq (name
, "macinfo"))
3994 || (do_debug_str
&& streq (name
, "str"))
3995 || (do_debug_loc
&& streq (name
, "loc"))
3997 request_dump (i
, DEBUG_DUMP
);
3999 /* linkonce section to be combined with .debug_info at link time. */
4000 else if ((do_debugging
|| do_debug_info
)
4001 && strneq (name
, ".gnu.linkonce.wi.", 17))
4002 request_dump (i
, DEBUG_DUMP
);
4003 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4004 request_dump (i
, DEBUG_DUMP
);
4010 if (elf_header
.e_shnum
> 1)
4011 printf (_("\nSection Headers:\n"));
4013 printf (_("\nSection Header:\n"));
4017 if (do_section_details
)
4019 printf (_(" [Nr] Name\n"));
4020 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4024 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4028 if (do_section_details
)
4030 printf (_(" [Nr] Name\n"));
4031 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4035 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4039 if (do_section_details
)
4041 printf (_(" [Nr] Name\n"));
4042 printf (_(" Type Address Offset Link\n"));
4043 printf (_(" Size EntSize Info Align\n"));
4047 printf (_(" [Nr] Name Type Address Offset\n"));
4048 printf (_(" Size EntSize Flags Link Info Align\n"));
4052 if (do_section_details
)
4053 printf (_(" Flags\n"));
4055 for (i
= 0, section
= section_headers
;
4056 i
< elf_header
.e_shnum
;
4059 if (do_section_details
)
4061 printf (" [%2u] %s\n",
4062 SECTION_HEADER_NUM (i
),
4063 SECTION_NAME (section
));
4064 if (is_32bit_elf
|| do_wide
)
4065 printf (" %-15.15s ",
4066 get_section_type_name (section
->sh_type
));
4069 printf (" [%2u] %-17.17s %-15.15s ",
4070 SECTION_HEADER_NUM (i
),
4071 SECTION_NAME (section
),
4072 get_section_type_name (section
->sh_type
));
4076 print_vma (section
->sh_addr
, LONG_HEX
);
4078 printf ( " %6.6lx %6.6lx %2.2lx",
4079 (unsigned long) section
->sh_offset
,
4080 (unsigned long) section
->sh_size
,
4081 (unsigned long) section
->sh_entsize
);
4083 if (do_section_details
)
4084 fputs (" ", stdout
);
4086 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4088 printf ("%2ld %3lu %2ld\n",
4089 (unsigned long) section
->sh_link
,
4090 (unsigned long) section
->sh_info
,
4091 (unsigned long) section
->sh_addralign
);
4095 print_vma (section
->sh_addr
, LONG_HEX
);
4097 if ((long) section
->sh_offset
== section
->sh_offset
)
4098 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4102 print_vma (section
->sh_offset
, LONG_HEX
);
4105 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4106 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4110 print_vma (section
->sh_size
, LONG_HEX
);
4113 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4114 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4118 print_vma (section
->sh_entsize
, LONG_HEX
);
4121 if (do_section_details
)
4122 fputs (" ", stdout
);
4124 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4126 printf ("%2ld %3lu ",
4127 (unsigned long) section
->sh_link
,
4128 (unsigned long) section
->sh_info
);
4130 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4131 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4134 print_vma (section
->sh_addralign
, DEC
);
4138 else if (do_section_details
)
4140 printf (" %-15.15s ",
4141 get_section_type_name (section
->sh_type
));
4142 print_vma (section
->sh_addr
, LONG_HEX
);
4143 if ((long) section
->sh_offset
== section
->sh_offset
)
4144 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4148 print_vma (section
->sh_offset
, LONG_HEX
);
4150 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4151 print_vma (section
->sh_size
, LONG_HEX
);
4153 print_vma (section
->sh_entsize
, LONG_HEX
);
4155 printf (" %-16lu %ld\n",
4156 (unsigned long) section
->sh_info
,
4157 (unsigned long) section
->sh_addralign
);
4162 print_vma (section
->sh_addr
, LONG_HEX
);
4163 if ((long) section
->sh_offset
== section
->sh_offset
)
4164 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4168 print_vma (section
->sh_offset
, LONG_HEX
);
4171 print_vma (section
->sh_size
, LONG_HEX
);
4173 print_vma (section
->sh_entsize
, LONG_HEX
);
4175 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4177 printf (" %2ld %3lu %ld\n",
4178 (unsigned long) section
->sh_link
,
4179 (unsigned long) section
->sh_info
,
4180 (unsigned long) section
->sh_addralign
);
4183 if (do_section_details
)
4184 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4187 if (!do_section_details
)
4188 printf (_("Key to Flags:\n\
4189 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4190 I (info), L (link order), G (group), x (unknown)\n\
4191 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4197 get_group_flags (unsigned int flags
)
4199 static char buff
[32];
4206 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4213 process_section_groups (FILE *file
)
4215 Elf_Internal_Shdr
*section
;
4217 struct group
*group
;
4218 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4219 Elf_Internal_Sym
*symtab
;
4223 /* Don't process section groups unless needed. */
4224 if (!do_unwind
&& !do_section_groups
)
4227 if (elf_header
.e_shnum
== 0)
4229 if (do_section_groups
)
4230 printf (_("\nThere are no sections in this file.\n"));
4235 if (section_headers
== NULL
)
4237 error (_("Section headers are not available!\n"));
4241 section_headers_groups
= calloc (elf_header
.e_shnum
,
4242 sizeof (struct group
*));
4244 if (section_headers_groups
== NULL
)
4246 error (_("Out of memory\n"));
4250 /* Scan the sections for the group section. */
4252 for (i
= 0, section
= section_headers
;
4253 i
< elf_header
.e_shnum
;
4255 if (section
->sh_type
== SHT_GROUP
)
4258 if (group_count
== 0)
4260 if (do_section_groups
)
4261 printf (_("\nThere are no section groups in this file.\n"));
4266 section_groups
= calloc (group_count
, sizeof (struct group
));
4268 if (section_groups
== NULL
)
4270 error (_("Out of memory\n"));
4279 for (i
= 0, section
= section_headers
, group
= section_groups
;
4280 i
< elf_header
.e_shnum
;
4283 if (section
->sh_type
== SHT_GROUP
)
4285 char *name
= SECTION_NAME (section
);
4287 unsigned char *start
, *indices
;
4288 unsigned int entry
, j
, size
;
4289 Elf_Internal_Shdr
*sec
;
4290 Elf_Internal_Sym
*sym
;
4292 /* Get the symbol table. */
4293 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4294 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4297 error (_("Bad sh_link in group section `%s'\n"), name
);
4301 if (symtab_sec
!= sec
)
4306 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4309 sym
= symtab
+ section
->sh_info
;
4311 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4313 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4316 error (_("Bad sh_info in group section `%s'\n"), name
);
4320 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4329 /* Get the string table. */
4330 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4331 >= elf_header
.e_shnum
)
4340 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4345 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4346 1, strtab_sec
->sh_size
,
4348 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4350 group_name
= sym
->st_name
< strtab_size
4351 ? strtab
+ sym
->st_name
: "<corrupt>";
4354 start
= get_data (NULL
, file
, section
->sh_offset
,
4355 1, section
->sh_size
, _("section data"));
4358 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4359 entry
= byte_get (indices
, 4);
4362 if (do_section_groups
)
4364 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4365 get_group_flags (entry
), i
, name
, group_name
, size
);
4367 printf (_(" [Index] Name\n"));
4370 group
->group_index
= i
;
4372 for (j
= 0; j
< size
; j
++)
4374 struct group_list
*g
;
4376 entry
= byte_get (indices
, 4);
4379 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4381 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4382 entry
, i
, elf_header
.e_shnum
- 1);
4385 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4387 error (_("invalid section [%5u] in group section [%5u]\n"),
4392 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4397 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4399 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4404 /* Intel C/C++ compiler may put section 0 in a
4405 section group. We just warn it the first time
4406 and ignore it afterwards. */
4407 static int warned
= 0;
4410 error (_("section 0 in group section [%5u]\n"),
4411 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4417 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4420 if (do_section_groups
)
4422 sec
= SECTION_HEADER (entry
);
4423 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4426 g
= xmalloc (sizeof (struct group_list
));
4427 g
->section_index
= entry
;
4428 g
->next
= group
->root
;
4452 } dynamic_relocations
[] =
4454 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4455 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4456 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4459 /* Process the reloc section. */
4462 process_relocs (FILE *file
)
4464 unsigned long rel_size
;
4465 unsigned long rel_offset
;
4471 if (do_using_dynamic
)
4475 int has_dynamic_reloc
;
4478 has_dynamic_reloc
= 0;
4480 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4482 is_rela
= dynamic_relocations
[i
].rela
;
4483 name
= dynamic_relocations
[i
].name
;
4484 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4485 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4487 has_dynamic_reloc
|= rel_size
;
4489 if (is_rela
== UNKNOWN
)
4491 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4492 switch (dynamic_info
[DT_PLTREL
])
4506 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4507 name
, rel_offset
, rel_size
);
4509 dump_relocations (file
,
4510 offset_from_vma (file
, rel_offset
, rel_size
),
4512 dynamic_symbols
, num_dynamic_syms
,
4513 dynamic_strings
, dynamic_strings_length
, is_rela
);
4517 if (! has_dynamic_reloc
)
4518 printf (_("\nThere are no dynamic relocations in this file.\n"));
4522 Elf_Internal_Shdr
*section
;
4526 for (i
= 0, section
= section_headers
;
4527 i
< elf_header
.e_shnum
;
4530 if ( section
->sh_type
!= SHT_RELA
4531 && section
->sh_type
!= SHT_REL
)
4534 rel_offset
= section
->sh_offset
;
4535 rel_size
= section
->sh_size
;
4539 Elf_Internal_Shdr
*strsec
;
4542 printf (_("\nRelocation section "));
4544 if (string_table
== NULL
)
4545 printf ("%d", section
->sh_name
);
4547 printf (_("'%s'"), SECTION_NAME (section
));
4549 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4550 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4552 is_rela
= section
->sh_type
== SHT_RELA
;
4554 if (section
->sh_link
4555 && SECTION_HEADER_INDEX (section
->sh_link
)
4556 < elf_header
.e_shnum
)
4558 Elf_Internal_Shdr
*symsec
;
4559 Elf_Internal_Sym
*symtab
;
4560 unsigned long nsyms
;
4561 unsigned long strtablen
= 0;
4562 char *strtab
= NULL
;
4564 symsec
= SECTION_HEADER (section
->sh_link
);
4565 if (symsec
->sh_type
!= SHT_SYMTAB
4566 && symsec
->sh_type
!= SHT_DYNSYM
)
4569 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4570 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4575 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4576 < elf_header
.e_shnum
)
4578 strsec
= SECTION_HEADER (symsec
->sh_link
);
4580 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4583 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4586 dump_relocations (file
, rel_offset
, rel_size
,
4587 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4593 dump_relocations (file
, rel_offset
, rel_size
,
4594 NULL
, 0, NULL
, 0, is_rela
);
4601 printf (_("\nThere are no relocations in this file.\n"));
4607 /* Process the unwind section. */
4609 #include "unwind-ia64.h"
4611 /* An absolute address consists of a section and an offset. If the
4612 section is NULL, the offset itself is the address, otherwise, the
4613 address equals to LOAD_ADDRESS(section) + offset. */
4617 unsigned short section
;
4621 #define ABSADDR(a) \
4623 ? section_headers [(a).section].sh_addr + (a).offset \
4626 struct ia64_unw_aux_info
4628 struct ia64_unw_table_entry
4630 struct absaddr start
;
4632 struct absaddr info
;
4634 *table
; /* Unwind table. */
4635 unsigned long table_len
; /* Length of unwind table. */
4636 unsigned char *info
; /* Unwind info. */
4637 unsigned long info_size
; /* Size of unwind info. */
4638 bfd_vma info_addr
; /* starting address of unwind info. */
4639 bfd_vma seg_base
; /* Starting address of segment. */
4640 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4641 unsigned long nsyms
; /* Number of symbols. */
4642 char *strtab
; /* The string table. */
4643 unsigned long strtab_size
; /* Size of string table. */
4647 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4648 unsigned long nsyms
,
4650 unsigned long strtab_size
,
4651 struct absaddr addr
,
4652 const char **symname
,
4655 bfd_vma dist
= 0x100000;
4656 Elf_Internal_Sym
*sym
, *best
= NULL
;
4659 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4661 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4662 && sym
->st_name
!= 0
4663 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4664 && addr
.offset
>= sym
->st_value
4665 && addr
.offset
- sym
->st_value
< dist
)
4668 dist
= addr
.offset
- sym
->st_value
;
4675 *symname
= (best
->st_name
>= strtab_size
4676 ? "<corrupt>" : strtab
+ best
->st_name
);
4681 *offset
= addr
.offset
;
4685 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4687 struct ia64_unw_table_entry
*tp
;
4690 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4694 const unsigned char *dp
;
4695 const unsigned char *head
;
4696 const char *procname
;
4698 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4699 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4701 fputs ("\n<", stdout
);
4705 fputs (procname
, stdout
);
4708 printf ("+%lx", (unsigned long) offset
);
4711 fputs (">: [", stdout
);
4712 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4713 fputc ('-', stdout
);
4714 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4715 printf ("], info at +0x%lx\n",
4716 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4718 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4719 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4721 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4722 (unsigned) UNW_VER (stamp
),
4723 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4724 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4725 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4726 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4728 if (UNW_VER (stamp
) != 1)
4730 printf ("\tUnknown version.\n");
4735 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4736 dp
= unw_decode (dp
, in_body
, & in_body
);
4741 slurp_ia64_unwind_table (FILE *file
,
4742 struct ia64_unw_aux_info
*aux
,
4743 Elf_Internal_Shdr
*sec
)
4745 unsigned long size
, nrelas
, i
;
4746 Elf_Internal_Phdr
*seg
;
4747 struct ia64_unw_table_entry
*tep
;
4748 Elf_Internal_Shdr
*relsec
;
4749 Elf_Internal_Rela
*rela
, *rp
;
4750 unsigned char *table
, *tp
;
4751 Elf_Internal_Sym
*sym
;
4752 const char *relname
;
4754 /* First, find the starting address of the segment that includes
4757 if (elf_header
.e_phnum
)
4759 if (! get_program_headers (file
))
4762 for (seg
= program_headers
;
4763 seg
< program_headers
+ elf_header
.e_phnum
;
4766 if (seg
->p_type
!= PT_LOAD
)
4769 if (sec
->sh_addr
>= seg
->p_vaddr
4770 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4772 aux
->seg_base
= seg
->p_vaddr
;
4778 /* Second, build the unwind table from the contents of the unwind section: */
4779 size
= sec
->sh_size
;
4780 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4784 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4786 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4788 tep
->start
.section
= SHN_UNDEF
;
4789 tep
->end
.section
= SHN_UNDEF
;
4790 tep
->info
.section
= SHN_UNDEF
;
4793 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4794 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4795 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4799 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
4800 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
4801 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
4803 tep
->start
.offset
+= aux
->seg_base
;
4804 tep
->end
.offset
+= aux
->seg_base
;
4805 tep
->info
.offset
+= aux
->seg_base
;
4809 /* Third, apply any relocations to the unwind table: */
4811 for (relsec
= section_headers
;
4812 relsec
< section_headers
+ elf_header
.e_shnum
;
4815 if (relsec
->sh_type
!= SHT_RELA
4816 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
4817 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4820 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4824 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4828 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4829 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4833 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4834 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4837 if (! strneq (relname
, "R_IA64_SEGREL", 13))
4839 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4843 i
= rp
->r_offset
/ (3 * eh_addr_size
);
4845 switch (rp
->r_offset
/eh_addr_size
% 3)
4848 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4849 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
4852 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4853 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
4856 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4857 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
4867 aux
->table_len
= size
/ (3 * eh_addr_size
);
4872 ia64_process_unwind (FILE *file
)
4874 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4875 unsigned long i
, unwcount
= 0, unwstart
= 0;
4876 struct ia64_unw_aux_info aux
;
4878 memset (& aux
, 0, sizeof (aux
));
4880 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4882 if (sec
->sh_type
== SHT_SYMTAB
4883 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
4885 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4886 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4888 strsec
= SECTION_HEADER (sec
->sh_link
);
4889 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4890 1, strsec
->sh_size
, _("string table"));
4891 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
4893 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4898 printf (_("\nThere are no unwind sections in this file.\n"));
4900 while (unwcount
-- > 0)
4905 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4906 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4907 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4914 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4916 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
4918 /* We need to find which section group it is in. */
4919 struct group_list
*g
= section_headers_groups
[i
]->root
;
4921 for (; g
!= NULL
; g
= g
->next
)
4923 sec
= SECTION_HEADER (g
->section_index
);
4925 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
4930 i
= elf_header
.e_shnum
;
4932 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
4934 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
4935 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4936 suffix
= SECTION_NAME (unwsec
) + len
;
4937 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4939 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
4940 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4945 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4946 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
4947 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4948 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4950 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
4951 suffix
= SECTION_NAME (unwsec
) + len
;
4952 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4954 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
4955 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4959 if (i
== elf_header
.e_shnum
)
4961 printf (_("\nCould not find unwind info section for "));
4963 if (string_table
== NULL
)
4964 printf ("%d", unwsec
->sh_name
);
4966 printf (_("'%s'"), SECTION_NAME (unwsec
));
4970 aux
.info_size
= sec
->sh_size
;
4971 aux
.info_addr
= sec
->sh_addr
;
4972 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
4975 printf (_("\nUnwind section "));
4977 if (string_table
== NULL
)
4978 printf ("%d", unwsec
->sh_name
);
4980 printf (_("'%s'"), SECTION_NAME (unwsec
));
4982 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4983 (unsigned long) unwsec
->sh_offset
,
4984 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
4986 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4988 if (aux
.table_len
> 0)
4989 dump_ia64_unwind (& aux
);
4992 free ((char *) aux
.table
);
4994 free ((char *) aux
.info
);
5003 free ((char *) aux
.strtab
);
5008 struct hppa_unw_aux_info
5010 struct hppa_unw_table_entry
5012 struct absaddr start
;
5014 unsigned int Cannot_unwind
:1; /* 0 */
5015 unsigned int Millicode
:1; /* 1 */
5016 unsigned int Millicode_save_sr0
:1; /* 2 */
5017 unsigned int Region_description
:2; /* 3..4 */
5018 unsigned int reserved1
:1; /* 5 */
5019 unsigned int Entry_SR
:1; /* 6 */
5020 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5021 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5022 unsigned int Args_stored
:1; /* 16 */
5023 unsigned int Variable_Frame
:1; /* 17 */
5024 unsigned int Separate_Package_Body
:1; /* 18 */
5025 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5026 unsigned int Stack_Overflow_Check
:1; /* 20 */
5027 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5028 unsigned int Ada_Region
:1; /* 22 */
5029 unsigned int cxx_info
:1; /* 23 */
5030 unsigned int cxx_try_catch
:1; /* 24 */
5031 unsigned int sched_entry_seq
:1; /* 25 */
5032 unsigned int reserved2
:1; /* 26 */
5033 unsigned int Save_SP
:1; /* 27 */
5034 unsigned int Save_RP
:1; /* 28 */
5035 unsigned int Save_MRP_in_frame
:1; /* 29 */
5036 unsigned int extn_ptr_defined
:1; /* 30 */
5037 unsigned int Cleanup_defined
:1; /* 31 */
5039 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5040 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5041 unsigned int Large_frame
:1; /* 2 */
5042 unsigned int Pseudo_SP_Set
:1; /* 3 */
5043 unsigned int reserved4
:1; /* 4 */
5044 unsigned int Total_frame_size
:27; /* 5..31 */
5046 *table
; /* Unwind table. */
5047 unsigned long table_len
; /* Length of unwind table. */
5048 bfd_vma seg_base
; /* Starting address of segment. */
5049 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5050 unsigned long nsyms
; /* Number of symbols. */
5051 char *strtab
; /* The string table. */
5052 unsigned long strtab_size
; /* Size of string table. */
5056 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5058 struct hppa_unw_table_entry
*tp
;
5060 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5063 const char *procname
;
5065 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5066 aux
->strtab_size
, tp
->start
, &procname
,
5069 fputs ("\n<", stdout
);
5073 fputs (procname
, stdout
);
5076 printf ("+%lx", (unsigned long) offset
);
5079 fputs (">: [", stdout
);
5080 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5081 fputc ('-', stdout
);
5082 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5085 #define PF(_m) if (tp->_m) printf (#_m " ");
5086 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5089 PF(Millicode_save_sr0
);
5090 /* PV(Region_description); */
5096 PF(Separate_Package_Body
);
5097 PF(Frame_Extension_Millicode
);
5098 PF(Stack_Overflow_Check
);
5099 PF(Two_Instruction_SP_Increment
);
5103 PF(sched_entry_seq
);
5106 PF(Save_MRP_in_frame
);
5107 PF(extn_ptr_defined
);
5108 PF(Cleanup_defined
);
5109 PF(MPE_XL_interrupt_marker
);
5110 PF(HP_UX_interrupt_marker
);
5113 PV(Total_frame_size
);
5122 slurp_hppa_unwind_table (FILE *file
,
5123 struct hppa_unw_aux_info
*aux
,
5124 Elf_Internal_Shdr
*sec
)
5126 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5127 Elf_Internal_Phdr
*seg
;
5128 struct hppa_unw_table_entry
*tep
;
5129 Elf_Internal_Shdr
*relsec
;
5130 Elf_Internal_Rela
*rela
, *rp
;
5131 unsigned char *table
, *tp
;
5132 Elf_Internal_Sym
*sym
;
5133 const char *relname
;
5135 /* First, find the starting address of the segment that includes
5138 if (elf_header
.e_phnum
)
5140 if (! get_program_headers (file
))
5143 for (seg
= program_headers
;
5144 seg
< program_headers
+ elf_header
.e_phnum
;
5147 if (seg
->p_type
!= PT_LOAD
)
5150 if (sec
->sh_addr
>= seg
->p_vaddr
5151 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5153 aux
->seg_base
= seg
->p_vaddr
;
5159 /* Second, build the unwind table from the contents of the unwind
5161 size
= sec
->sh_size
;
5162 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5167 nentries
= size
/ unw_ent_size
;
5168 size
= unw_ent_size
* nentries
;
5170 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5172 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5174 unsigned int tmp1
, tmp2
;
5176 tep
->start
.section
= SHN_UNDEF
;
5177 tep
->end
.section
= SHN_UNDEF
;
5179 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5180 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5181 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5182 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5184 tep
->start
.offset
+= aux
->seg_base
;
5185 tep
->end
.offset
+= aux
->seg_base
;
5187 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5188 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5189 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5190 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5191 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5192 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5193 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5194 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5195 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5196 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5197 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5198 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5199 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5200 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5201 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5202 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5203 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5204 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5205 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5206 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5207 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5208 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5209 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5210 tep
->Cleanup_defined
= tmp1
& 0x1;
5212 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5213 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5214 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5215 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5216 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5217 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5221 /* Third, apply any relocations to the unwind table. */
5223 for (relsec
= section_headers
;
5224 relsec
< section_headers
+ elf_header
.e_shnum
;
5227 if (relsec
->sh_type
!= SHT_RELA
5228 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5229 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5232 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5236 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5240 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5241 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5245 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5246 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5249 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5250 if (strncmp (relname
, "R_PARISC_SEGREL", 15) != 0)
5252 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5256 i
= rp
->r_offset
/ unw_ent_size
;
5258 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5261 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5262 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5265 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5266 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5276 aux
->table_len
= nentries
;
5282 hppa_process_unwind (FILE *file
)
5284 struct hppa_unw_aux_info aux
;
5285 Elf_Internal_Shdr
*unwsec
= NULL
;
5286 Elf_Internal_Shdr
*strsec
;
5287 Elf_Internal_Shdr
*sec
;
5290 memset (& aux
, 0, sizeof (aux
));
5292 if (string_table
== NULL
)
5295 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5297 if (sec
->sh_type
== SHT_SYMTAB
5298 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5300 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5301 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5303 strsec
= SECTION_HEADER (sec
->sh_link
);
5304 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5305 1, strsec
->sh_size
, _("string table"));
5306 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5308 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5313 printf (_("\nThere are no unwind sections in this file.\n"));
5315 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5317 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5319 printf (_("\nUnwind section "));
5320 printf (_("'%s'"), SECTION_NAME (sec
));
5322 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5323 (unsigned long) sec
->sh_offset
,
5324 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5326 slurp_hppa_unwind_table (file
, &aux
, sec
);
5327 if (aux
.table_len
> 0)
5328 dump_hppa_unwind (&aux
);
5331 free ((char *) aux
.table
);
5339 free ((char *) aux
.strtab
);
5345 process_unwind (FILE *file
)
5347 struct unwind_handler
{
5349 int (*handler
)(FILE *file
);
5351 { EM_IA_64
, ia64_process_unwind
},
5352 { EM_PARISC
, hppa_process_unwind
},
5360 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5361 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5362 return handlers
[i
].handler (file
);
5364 printf (_("\nThere are no unwind sections in this file.\n"));
5369 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5371 switch (entry
->d_tag
)
5374 if (entry
->d_un
.d_val
== 0)
5378 static const char * opts
[] =
5380 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5381 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5382 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5383 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5388 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
5389 if (entry
->d_un
.d_val
& (1 << cnt
))
5391 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5398 case DT_MIPS_IVERSION
:
5399 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5400 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5402 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5405 case DT_MIPS_TIME_STAMP
:
5410 time_t time
= entry
->d_un
.d_val
;
5411 tmp
= gmtime (&time
);
5412 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5413 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5414 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5415 printf ("Time Stamp: %s\n", timebuf
);
5419 case DT_MIPS_RLD_VERSION
:
5420 case DT_MIPS_LOCAL_GOTNO
:
5421 case DT_MIPS_CONFLICTNO
:
5422 case DT_MIPS_LIBLISTNO
:
5423 case DT_MIPS_SYMTABNO
:
5424 case DT_MIPS_UNREFEXTNO
:
5425 case DT_MIPS_HIPAGENO
:
5426 case DT_MIPS_DELTA_CLASS_NO
:
5427 case DT_MIPS_DELTA_INSTANCE_NO
:
5428 case DT_MIPS_DELTA_RELOC_NO
:
5429 case DT_MIPS_DELTA_SYM_NO
:
5430 case DT_MIPS_DELTA_CLASSSYM_NO
:
5431 case DT_MIPS_COMPACT_SIZE
:
5432 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5436 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5442 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5444 switch (entry
->d_tag
)
5446 case DT_HP_DLD_FLAGS
:
5455 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5456 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5457 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5458 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5459 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5460 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5461 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5462 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5463 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5464 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5465 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5466 { DT_HP_GST
, "HP_GST" },
5467 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5468 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5469 { DT_HP_NODELETE
, "HP_NODELETE" },
5470 { DT_HP_GROUP
, "HP_GROUP" },
5471 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5475 bfd_vma val
= entry
->d_un
.d_val
;
5477 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
5478 if (val
& flags
[cnt
].bit
)
5482 fputs (flags
[cnt
].str
, stdout
);
5484 val
^= flags
[cnt
].bit
;
5487 if (val
!= 0 || first
)
5491 print_vma (val
, HEX
);
5497 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5504 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5506 switch (entry
->d_tag
)
5508 case DT_IA_64_PLT_RESERVE
:
5509 /* First 3 slots reserved. */
5510 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5512 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5516 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5523 get_32bit_dynamic_section (FILE *file
)
5525 Elf32_External_Dyn
*edyn
, *ext
;
5526 Elf_Internal_Dyn
*entry
;
5528 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5529 _("dynamic section"));
5533 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5534 might not have the luxury of section headers. Look for the DT_NULL
5535 terminator to determine the number of entries. */
5536 for (ext
= edyn
, dynamic_nent
= 0;
5537 (char *) ext
< (char *) edyn
+ dynamic_size
;
5541 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5545 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5546 if (dynamic_section
== NULL
)
5548 error (_("Out of memory\n"));
5553 for (ext
= edyn
, entry
= dynamic_section
;
5554 entry
< dynamic_section
+ dynamic_nent
;
5557 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5558 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5567 get_64bit_dynamic_section (FILE *file
)
5569 Elf64_External_Dyn
*edyn
, *ext
;
5570 Elf_Internal_Dyn
*entry
;
5572 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5573 _("dynamic section"));
5577 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5578 might not have the luxury of section headers. Look for the DT_NULL
5579 terminator to determine the number of entries. */
5580 for (ext
= edyn
, dynamic_nent
= 0;
5581 (char *) ext
< (char *) edyn
+ dynamic_size
;
5585 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5589 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5590 if (dynamic_section
== NULL
)
5592 error (_("Out of memory\n"));
5597 for (ext
= edyn
, entry
= dynamic_section
;
5598 entry
< dynamic_section
+ dynamic_nent
;
5601 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5602 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5611 print_dynamic_flags (bfd_vma flags
)
5619 flag
= flags
& - flags
;
5629 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5630 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5631 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5632 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5633 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5634 default: fputs ("unknown", stdout
); break;
5640 /* Parse and display the contents of the dynamic section. */
5643 process_dynamic_section (FILE *file
)
5645 Elf_Internal_Dyn
*entry
;
5647 if (dynamic_size
== 0)
5650 printf (_("\nThere is no dynamic section in this file.\n"));
5657 if (! get_32bit_dynamic_section (file
))
5660 else if (! get_64bit_dynamic_section (file
))
5663 /* Find the appropriate symbol table. */
5664 if (dynamic_symbols
== NULL
)
5666 for (entry
= dynamic_section
;
5667 entry
< dynamic_section
+ dynamic_nent
;
5670 Elf_Internal_Shdr section
;
5672 if (entry
->d_tag
!= DT_SYMTAB
)
5675 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5677 /* Since we do not know how big the symbol table is,
5678 we default to reading in the entire file (!) and
5679 processing that. This is overkill, I know, but it
5681 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5683 if (archive_file_offset
!= 0)
5684 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5687 if (fseek (file
, 0, SEEK_END
))
5688 error (_("Unable to seek to end of file!"));
5690 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5694 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5696 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5698 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5699 if (num_dynamic_syms
< 1)
5701 error (_("Unable to determine the number of symbols to load\n"));
5705 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5709 /* Similarly find a string table. */
5710 if (dynamic_strings
== NULL
)
5712 for (entry
= dynamic_section
;
5713 entry
< dynamic_section
+ dynamic_nent
;
5716 unsigned long offset
;
5719 if (entry
->d_tag
!= DT_STRTAB
)
5722 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5724 /* Since we do not know how big the string table is,
5725 we default to reading in the entire file (!) and
5726 processing that. This is overkill, I know, but it
5729 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5731 if (archive_file_offset
!= 0)
5732 str_tab_len
= archive_file_size
- offset
;
5735 if (fseek (file
, 0, SEEK_END
))
5736 error (_("Unable to seek to end of file\n"));
5737 str_tab_len
= ftell (file
) - offset
;
5740 if (str_tab_len
< 1)
5743 (_("Unable to determine the length of the dynamic string table\n"));
5747 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5748 _("dynamic string table"));
5749 dynamic_strings_length
= str_tab_len
;
5754 /* And find the syminfo section if available. */
5755 if (dynamic_syminfo
== NULL
)
5757 unsigned long syminsz
= 0;
5759 for (entry
= dynamic_section
;
5760 entry
< dynamic_section
+ dynamic_nent
;
5763 if (entry
->d_tag
== DT_SYMINENT
)
5765 /* Note: these braces are necessary to avoid a syntax
5766 error from the SunOS4 C compiler. */
5767 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5769 else if (entry
->d_tag
== DT_SYMINSZ
)
5770 syminsz
= entry
->d_un
.d_val
;
5771 else if (entry
->d_tag
== DT_SYMINFO
)
5772 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5776 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5778 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5779 Elf_Internal_Syminfo
*syminfo
;
5781 /* There is a syminfo section. Read the data. */
5782 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5783 syminsz
, _("symbol information"));
5787 dynamic_syminfo
= malloc (syminsz
);
5788 if (dynamic_syminfo
== NULL
)
5790 error (_("Out of memory\n"));
5794 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5795 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5796 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5797 ++syminfo
, ++extsym
)
5799 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5800 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5807 if (do_dynamic
&& dynamic_addr
)
5808 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5809 dynamic_addr
, dynamic_nent
);
5811 printf (_(" Tag Type Name/Value\n"));
5813 for (entry
= dynamic_section
;
5814 entry
< dynamic_section
+ dynamic_nent
;
5822 print_vma (entry
->d_tag
, FULL_HEX
);
5823 dtype
= get_dynamic_type (entry
->d_tag
);
5824 printf (" (%s)%*s", dtype
,
5825 ((is_32bit_elf
? 27 : 19)
5826 - (int) strlen (dtype
)),
5830 switch (entry
->d_tag
)
5834 print_dynamic_flags (entry
->d_un
.d_val
);
5844 switch (entry
->d_tag
)
5847 printf (_("Auxiliary library"));
5851 printf (_("Filter library"));
5855 printf (_("Configuration file"));
5859 printf (_("Dependency audit library"));
5863 printf (_("Audit library"));
5867 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5868 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5872 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5881 printf (_("Flags:"));
5883 if (entry
->d_un
.d_val
== 0)
5884 printf (_(" None\n"));
5887 unsigned long int val
= entry
->d_un
.d_val
;
5889 if (val
& DTF_1_PARINIT
)
5891 printf (" PARINIT");
5892 val
^= DTF_1_PARINIT
;
5894 if (val
& DTF_1_CONFEXP
)
5896 printf (" CONFEXP");
5897 val
^= DTF_1_CONFEXP
;
5900 printf (" %lx", val
);
5909 printf (_("Flags:"));
5911 if (entry
->d_un
.d_val
== 0)
5912 printf (_(" None\n"));
5915 unsigned long int val
= entry
->d_un
.d_val
;
5917 if (val
& DF_P1_LAZYLOAD
)
5919 printf (" LAZYLOAD");
5920 val
^= DF_P1_LAZYLOAD
;
5922 if (val
& DF_P1_GROUPPERM
)
5924 printf (" GROUPPERM");
5925 val
^= DF_P1_GROUPPERM
;
5928 printf (" %lx", val
);
5937 printf (_("Flags:"));
5938 if (entry
->d_un
.d_val
== 0)
5939 printf (_(" None\n"));
5942 unsigned long int val
= entry
->d_un
.d_val
;
5949 if (val
& DF_1_GLOBAL
)
5954 if (val
& DF_1_GROUP
)
5959 if (val
& DF_1_NODELETE
)
5961 printf (" NODELETE");
5962 val
^= DF_1_NODELETE
;
5964 if (val
& DF_1_LOADFLTR
)
5966 printf (" LOADFLTR");
5967 val
^= DF_1_LOADFLTR
;
5969 if (val
& DF_1_INITFIRST
)
5971 printf (" INITFIRST");
5972 val
^= DF_1_INITFIRST
;
5974 if (val
& DF_1_NOOPEN
)
5979 if (val
& DF_1_ORIGIN
)
5984 if (val
& DF_1_DIRECT
)
5989 if (val
& DF_1_TRANS
)
5994 if (val
& DF_1_INTERPOSE
)
5996 printf (" INTERPOSE");
5997 val
^= DF_1_INTERPOSE
;
5999 if (val
& DF_1_NODEFLIB
)
6001 printf (" NODEFLIB");
6002 val
^= DF_1_NODEFLIB
;
6004 if (val
& DF_1_NODUMP
)
6009 if (val
& DF_1_CONLFAT
)
6011 printf (" CONLFAT");
6012 val
^= DF_1_CONLFAT
;
6015 printf (" %lx", val
);
6022 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6024 puts (get_dynamic_type (entry
->d_un
.d_val
));
6044 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6050 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6051 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6057 switch (entry
->d_tag
)
6060 printf (_("Shared library: [%s]"), name
);
6062 if (streq (name
, program_interpreter
))
6063 printf (_(" program interpreter"));
6067 printf (_("Library soname: [%s]"), name
);
6071 printf (_("Library rpath: [%s]"), name
);
6075 printf (_("Library runpath: [%s]"), name
);
6079 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6084 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6097 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6101 case DT_INIT_ARRAYSZ
:
6102 case DT_FINI_ARRAYSZ
:
6103 case DT_GNU_CONFLICTSZ
:
6104 case DT_GNU_LIBLISTSZ
:
6107 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6108 printf (" (bytes)\n");
6118 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6131 if (entry
->d_tag
== DT_USED
6132 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6134 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6138 printf (_("Not needed object: [%s]\n"), name
);
6143 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6149 /* The value of this entry is ignored. */
6154 case DT_GNU_PRELINKED
:
6158 time_t time
= entry
->d_un
.d_val
;
6160 tmp
= gmtime (&time
);
6161 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6162 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6163 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6169 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6170 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6175 switch (elf_header
.e_machine
)
6178 case EM_MIPS_RS3_LE
:
6179 dynamic_section_mips_val (entry
);
6182 dynamic_section_parisc_val (entry
);
6185 dynamic_section_ia64_val (entry
);
6188 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6200 get_ver_flags (unsigned int flags
)
6202 static char buff
[32];
6209 if (flags
& VER_FLG_BASE
)
6210 strcat (buff
, "BASE ");
6212 if (flags
& VER_FLG_WEAK
)
6214 if (flags
& VER_FLG_BASE
)
6215 strcat (buff
, "| ");
6217 strcat (buff
, "WEAK ");
6220 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6221 strcat (buff
, "| <unknown>");
6226 /* Display the contents of the version sections. */
6228 process_version_sections (FILE *file
)
6230 Elf_Internal_Shdr
*section
;
6237 for (i
= 0, section
= section_headers
;
6238 i
< elf_header
.e_shnum
;
6241 switch (section
->sh_type
)
6243 case SHT_GNU_verdef
:
6245 Elf_External_Verdef
*edefs
;
6252 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6253 SECTION_NAME (section
), section
->sh_info
);
6255 printf (_(" Addr: 0x"));
6256 printf_vma (section
->sh_addr
);
6257 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6258 (unsigned long) section
->sh_offset
, section
->sh_link
,
6259 SECTION_HEADER_INDEX (section
->sh_link
)
6260 < elf_header
.e_shnum
6261 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6264 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6266 _("version definition section"));
6270 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6273 Elf_External_Verdef
*edef
;
6274 Elf_Internal_Verdef ent
;
6275 Elf_External_Verdaux
*eaux
;
6276 Elf_Internal_Verdaux aux
;
6280 vstart
= ((char *) edefs
) + idx
;
6282 edef
= (Elf_External_Verdef
*) vstart
;
6284 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6285 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6286 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6287 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6288 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6289 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6290 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6292 printf (_(" %#06x: Rev: %d Flags: %s"),
6293 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6295 printf (_(" Index: %d Cnt: %d "),
6296 ent
.vd_ndx
, ent
.vd_cnt
);
6298 vstart
+= ent
.vd_aux
;
6300 eaux
= (Elf_External_Verdaux
*) vstart
;
6302 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6303 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6305 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6306 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6308 printf (_("Name index: %ld\n"), aux
.vda_name
);
6310 isum
= idx
+ ent
.vd_aux
;
6312 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6314 isum
+= aux
.vda_next
;
6315 vstart
+= aux
.vda_next
;
6317 eaux
= (Elf_External_Verdaux
*) vstart
;
6319 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6320 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6322 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6323 printf (_(" %#06x: Parent %d: %s\n"),
6324 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6326 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6327 isum
, j
, aux
.vda_name
);
6337 case SHT_GNU_verneed
:
6339 Elf_External_Verneed
*eneed
;
6345 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6346 SECTION_NAME (section
), section
->sh_info
);
6348 printf (_(" Addr: 0x"));
6349 printf_vma (section
->sh_addr
);
6350 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6351 (unsigned long) section
->sh_offset
, section
->sh_link
,
6352 SECTION_HEADER_INDEX (section
->sh_link
)
6353 < elf_header
.e_shnum
6354 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6357 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6359 _("version need section"));
6363 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6365 Elf_External_Verneed
*entry
;
6366 Elf_Internal_Verneed ent
;
6371 vstart
= ((char *) eneed
) + idx
;
6373 entry
= (Elf_External_Verneed
*) vstart
;
6375 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6376 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6377 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6378 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6379 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6381 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6383 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6384 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6386 printf (_(" File: %lx"), ent
.vn_file
);
6388 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6390 vstart
+= ent
.vn_aux
;
6392 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6394 Elf_External_Vernaux
*eaux
;
6395 Elf_Internal_Vernaux aux
;
6397 eaux
= (Elf_External_Vernaux
*) vstart
;
6399 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6400 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6401 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6402 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6403 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6405 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6406 printf (_(" %#06x: Name: %s"),
6407 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6409 printf (_(" %#06x: Name index: %lx"),
6410 isum
, aux
.vna_name
);
6412 printf (_(" Flags: %s Version: %d\n"),
6413 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6415 isum
+= aux
.vna_next
;
6416 vstart
+= aux
.vna_next
;
6426 case SHT_GNU_versym
:
6428 Elf_Internal_Shdr
*link_section
;
6431 unsigned char *edata
;
6432 unsigned short *data
;
6434 Elf_Internal_Sym
*symbols
;
6435 Elf_Internal_Shdr
*string_sec
;
6438 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6441 link_section
= SECTION_HEADER (section
->sh_link
);
6442 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6444 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6445 >= elf_header
.e_shnum
)
6450 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6452 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6454 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6455 string_sec
->sh_size
, _("version string table"));
6459 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6460 SECTION_NAME (section
), total
);
6462 printf (_(" Addr: "));
6463 printf_vma (section
->sh_addr
);
6464 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6465 (unsigned long) section
->sh_offset
, section
->sh_link
,
6466 SECTION_NAME (link_section
));
6468 off
= offset_from_vma (file
,
6469 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6470 total
* sizeof (short));
6471 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6472 _("version symbol data"));
6479 data
= cmalloc (total
, sizeof (short));
6481 for (cnt
= total
; cnt
--;)
6482 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6487 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6490 int check_def
, check_need
;
6493 printf (" %03x:", cnt
);
6495 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6496 switch (data
[cnt
+ j
])
6499 fputs (_(" 0 (*local*) "), stdout
);
6503 fputs (_(" 1 (*global*) "), stdout
);
6507 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6508 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6512 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6513 >= elf_header
.e_shnum
6514 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6517 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6524 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6526 Elf_Internal_Verneed ivn
;
6527 unsigned long offset
;
6529 offset
= offset_from_vma
6530 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6531 sizeof (Elf_External_Verneed
));
6535 Elf_Internal_Vernaux ivna
;
6536 Elf_External_Verneed evn
;
6537 Elf_External_Vernaux evna
;
6538 unsigned long a_off
;
6540 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6543 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6544 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6546 a_off
= offset
+ ivn
.vn_aux
;
6550 get_data (&evna
, file
, a_off
, sizeof (evna
),
6551 1, _("version need aux (2)"));
6553 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6554 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6556 a_off
+= ivna
.vna_next
;
6558 while (ivna
.vna_other
!= data
[cnt
+ j
]
6559 && ivna
.vna_next
!= 0);
6561 if (ivna
.vna_other
== data
[cnt
+ j
])
6563 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6565 name
= strtab
+ ivna
.vna_name
;
6566 nn
+= printf ("(%s%-*s",
6568 12 - (int) strlen (name
),
6574 offset
+= ivn
.vn_next
;
6576 while (ivn
.vn_next
);
6579 if (check_def
&& data
[cnt
+ j
] != 0x8001
6580 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6582 Elf_Internal_Verdef ivd
;
6583 Elf_External_Verdef evd
;
6584 unsigned long offset
;
6586 offset
= offset_from_vma
6587 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6592 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6595 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6596 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6598 offset
+= ivd
.vd_next
;
6600 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6601 && ivd
.vd_next
!= 0);
6603 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6605 Elf_External_Verdaux evda
;
6606 Elf_Internal_Verdaux ivda
;
6608 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6610 get_data (&evda
, file
,
6611 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6613 _("version def aux"));
6615 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6617 name
= strtab
+ ivda
.vda_name
;
6618 nn
+= printf ("(%s%-*s",
6620 12 - (int) strlen (name
),
6626 printf ("%*c", 18 - nn
, ' ');
6644 printf (_("\nNo version information found in this file.\n"));
6650 get_symbol_binding (unsigned int binding
)
6652 static char buff
[32];
6656 case STB_LOCAL
: return "LOCAL";
6657 case STB_GLOBAL
: return "GLOBAL";
6658 case STB_WEAK
: return "WEAK";
6660 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6661 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6663 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6664 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6666 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6672 get_symbol_type (unsigned int type
)
6674 static char buff
[32];
6678 case STT_NOTYPE
: return "NOTYPE";
6679 case STT_OBJECT
: return "OBJECT";
6680 case STT_FUNC
: return "FUNC";
6681 case STT_SECTION
: return "SECTION";
6682 case STT_FILE
: return "FILE";
6683 case STT_COMMON
: return "COMMON";
6684 case STT_TLS
: return "TLS";
6686 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6688 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6689 return "THUMB_FUNC";
6691 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6694 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6695 return "PARISC_MILLI";
6697 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6699 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6701 if (elf_header
.e_machine
== EM_PARISC
)
6703 if (type
== STT_HP_OPAQUE
)
6705 if (type
== STT_HP_STUB
)
6709 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6712 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6718 get_symbol_visibility (unsigned int visibility
)
6722 case STV_DEFAULT
: return "DEFAULT";
6723 case STV_INTERNAL
: return "INTERNAL";
6724 case STV_HIDDEN
: return "HIDDEN";
6725 case STV_PROTECTED
: return "PROTECTED";
6731 get_mips_symbol_other (unsigned int other
)
6735 case STO_OPTIONAL
: return "OPTIONAL";
6736 case STO_MIPS16
: return "MIPS16";
6737 default: return NULL
;
6742 get_symbol_other (unsigned int other
)
6744 const char * result
= NULL
;
6745 static char buff
[32];
6750 switch (elf_header
.e_machine
)
6753 result
= get_mips_symbol_other (other
);
6761 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
6766 get_symbol_index_type (unsigned int type
)
6768 static char buff
[32];
6772 case SHN_UNDEF
: return "UND";
6773 case SHN_ABS
: return "ABS";
6774 case SHN_COMMON
: return "COM";
6776 if (type
== SHN_IA_64_ANSI_COMMON
6777 && elf_header
.e_machine
== EM_IA_64
6778 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6780 else if (elf_header
.e_machine
== EM_X86_64
6781 && type
== SHN_X86_64_LCOMMON
)
6783 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6784 sprintf (buff
, "PRC[0x%04x]", type
);
6785 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6786 sprintf (buff
, "OS [0x%04x]", type
);
6787 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6788 sprintf (buff
, "RSV[0x%04x]", type
);
6790 sprintf (buff
, "%3d", type
);
6798 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
6800 unsigned char *e_data
;
6803 e_data
= cmalloc (number
, ent_size
);
6807 error (_("Out of memory\n"));
6811 if (fread (e_data
, ent_size
, number
, file
) != number
)
6813 error (_("Unable to read in dynamic data\n"));
6817 i_data
= cmalloc (number
, sizeof (*i_data
));
6821 error (_("Out of memory\n"));
6827 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
6834 /* Dump the symbol table. */
6836 process_symbol_table (FILE *file
)
6838 Elf_Internal_Shdr
*section
;
6839 bfd_vma nbuckets
= 0;
6840 bfd_vma nchains
= 0;
6841 bfd_vma
*buckets
= NULL
;
6842 bfd_vma
*chains
= NULL
;
6844 if (! do_syms
&& !do_histogram
)
6847 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
6850 unsigned char nb
[8];
6851 unsigned char nc
[8];
6852 int hash_ent_size
= 4;
6854 if ((elf_header
.e_machine
== EM_ALPHA
6855 || elf_header
.e_machine
== EM_S390
6856 || elf_header
.e_machine
== EM_S390_OLD
)
6857 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
6861 (archive_file_offset
6862 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
6863 sizeof nb
+ sizeof nc
)),
6866 error (_("Unable to seek to start of dynamic information"));
6870 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
6872 error (_("Failed to read in number of buckets\n"));
6876 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
6878 error (_("Failed to read in number of chains\n"));
6882 nbuckets
= byte_get (nb
, hash_ent_size
);
6883 nchains
= byte_get (nc
, hash_ent_size
);
6885 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
6886 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
6888 if (buckets
== NULL
|| chains
== NULL
)
6893 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
6898 printf (_("\nSymbol table for image:\n"));
6900 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6902 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6904 for (hn
= 0; hn
< nbuckets
; hn
++)
6909 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
6911 Elf_Internal_Sym
*psym
;
6914 psym
= dynamic_symbols
+ si
;
6916 n
= print_vma (si
, DEC_5
);
6918 fputs (" " + n
, stdout
);
6919 printf (" %3lu: ", hn
);
6920 print_vma (psym
->st_value
, LONG_HEX
);
6922 print_vma (psym
->st_size
, DEC_5
);
6924 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6925 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6926 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6927 /* Check to see if any other bits in the st_other field are set.
6928 Note - displaying this information disrupts the layout of the
6929 table being generated, but for the moment this case is very rare. */
6930 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
6931 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
6932 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
6933 if (VALID_DYNAMIC_NAME (psym
->st_name
))
6934 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
6936 printf (" <corrupt: %14ld>", psym
->st_name
);
6941 else if (do_syms
&& !do_using_dynamic
)
6945 for (i
= 0, section
= section_headers
;
6946 i
< elf_header
.e_shnum
;
6950 char *strtab
= NULL
;
6951 unsigned long int strtab_size
= 0;
6952 Elf_Internal_Sym
*symtab
;
6953 Elf_Internal_Sym
*psym
;
6956 if ( section
->sh_type
!= SHT_SYMTAB
6957 && section
->sh_type
!= SHT_DYNSYM
)
6960 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
6961 SECTION_NAME (section
),
6962 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
6964 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6966 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6968 symtab
= GET_ELF_SYMBOLS (file
, section
);
6972 if (section
->sh_link
== elf_header
.e_shstrndx
)
6974 strtab
= string_table
;
6975 strtab_size
= string_table_length
;
6977 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
6979 Elf_Internal_Shdr
*string_sec
;
6981 string_sec
= SECTION_HEADER (section
->sh_link
);
6983 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
6984 1, string_sec
->sh_size
, _("string table"));
6985 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
6988 for (si
= 0, psym
= symtab
;
6989 si
< section
->sh_size
/ section
->sh_entsize
;
6992 printf ("%6d: ", si
);
6993 print_vma (psym
->st_value
, LONG_HEX
);
6995 print_vma (psym
->st_size
, DEC_5
);
6996 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6997 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6998 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6999 /* Check to see if any other bits in the st_other field are set.
7000 Note - displaying this information disrupts the layout of the
7001 table being generated, but for the moment this case is very rare. */
7002 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7003 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7004 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7005 print_symbol (25, psym
->st_name
< strtab_size
7006 ? strtab
+ psym
->st_name
: "<corrupt>");
7008 if (section
->sh_type
== SHT_DYNSYM
&&
7009 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7011 unsigned char data
[2];
7012 unsigned short vers_data
;
7013 unsigned long offset
;
7017 offset
= offset_from_vma
7018 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7019 sizeof data
+ si
* sizeof (vers_data
));
7021 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7022 sizeof (data
), 1, _("version data"));
7024 vers_data
= byte_get (data
, 2);
7026 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7027 < elf_header
.e_shnum
7028 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7031 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7033 if ((vers_data
& 0x8000) || vers_data
> 1)
7035 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7036 && (is_nobits
|| ! check_def
))
7038 Elf_External_Verneed evn
;
7039 Elf_Internal_Verneed ivn
;
7040 Elf_Internal_Vernaux ivna
;
7042 /* We must test both. */
7043 offset
= offset_from_vma
7044 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7049 unsigned long vna_off
;
7051 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7054 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7055 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7057 vna_off
= offset
+ ivn
.vn_aux
;
7061 Elf_External_Vernaux evna
;
7063 get_data (&evna
, file
, vna_off
,
7065 _("version need aux (3)"));
7067 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7068 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7069 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7071 vna_off
+= ivna
.vna_next
;
7073 while (ivna
.vna_other
!= vers_data
7074 && ivna
.vna_next
!= 0);
7076 if (ivna
.vna_other
== vers_data
)
7079 offset
+= ivn
.vn_next
;
7081 while (ivn
.vn_next
!= 0);
7083 if (ivna
.vna_other
== vers_data
)
7086 ivna
.vna_name
< strtab_size
7087 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7091 else if (! is_nobits
)
7092 error (_("bad dynamic symbol"));
7099 if (vers_data
!= 0x8001
7100 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7102 Elf_Internal_Verdef ivd
;
7103 Elf_Internal_Verdaux ivda
;
7104 Elf_External_Verdaux evda
;
7105 unsigned long offset
;
7107 offset
= offset_from_vma
7109 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7110 sizeof (Elf_External_Verdef
));
7114 Elf_External_Verdef evd
;
7116 get_data (&evd
, file
, offset
, sizeof (evd
),
7117 1, _("version def"));
7119 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7120 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7121 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7123 offset
+= ivd
.vd_next
;
7125 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7126 && ivd
.vd_next
!= 0);
7128 offset
-= ivd
.vd_next
;
7129 offset
+= ivd
.vd_aux
;
7131 get_data (&evda
, file
, offset
, sizeof (evda
),
7132 1, _("version def aux"));
7134 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7136 if (psym
->st_name
!= ivda
.vda_name
)
7137 printf ((vers_data
& 0x8000)
7139 ivda
.vda_name
< strtab_size
7140 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7150 if (strtab
!= string_table
)
7156 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7158 if (do_histogram
&& buckets
!= NULL
)
7160 unsigned long *lengths
;
7161 unsigned long *counts
;
7164 unsigned long maxlength
= 0;
7165 unsigned long nzero_counts
= 0;
7166 unsigned long nsyms
= 0;
7168 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7169 (unsigned long) nbuckets
);
7170 printf (_(" Length Number %% of total Coverage\n"));
7172 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7173 if (lengths
== NULL
)
7175 error (_("Out of memory"));
7178 for (hn
= 0; hn
< nbuckets
; ++hn
)
7180 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7183 if (maxlength
< ++lengths
[hn
])
7188 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7191 error (_("Out of memory"));
7195 for (hn
= 0; hn
< nbuckets
; ++hn
)
7196 ++counts
[lengths
[hn
]];
7201 printf (" 0 %-10lu (%5.1f%%)\n",
7202 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7203 for (i
= 1; i
<= maxlength
; ++i
)
7205 nzero_counts
+= counts
[i
] * i
;
7206 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7207 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7208 (nzero_counts
* 100.0) / nsyms
);
7216 if (buckets
!= NULL
)
7226 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7230 if (dynamic_syminfo
== NULL
7232 /* No syminfo, this is ok. */
7235 /* There better should be a dynamic symbol section. */
7236 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7240 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7241 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7243 printf (_(" Num: Name BoundTo Flags\n"));
7244 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7246 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7248 printf ("%4d: ", i
);
7249 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7250 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7252 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7255 switch (dynamic_syminfo
[i
].si_boundto
)
7257 case SYMINFO_BT_SELF
:
7258 fputs ("SELF ", stdout
);
7260 case SYMINFO_BT_PARENT
:
7261 fputs ("PARENT ", stdout
);
7264 if (dynamic_syminfo
[i
].si_boundto
> 0
7265 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7266 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7268 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7272 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7276 if (flags
& SYMINFO_FLG_DIRECT
)
7278 if (flags
& SYMINFO_FLG_PASSTHRU
)
7279 printf (" PASSTHRU");
7280 if (flags
& SYMINFO_FLG_COPY
)
7282 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7283 printf (" LAZYLOAD");
7291 #ifdef SUPPORT_DISASSEMBLY
7293 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7295 printf (_("\nAssembly dump of section %s\n"),
7296 SECTION_NAME (section
));
7298 /* XXX -- to be done --- XXX */
7305 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
7307 bfd_size_type bytes
;
7309 unsigned char *data
;
7310 unsigned char *start
;
7312 bytes
= section
->sh_size
;
7314 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7316 printf (_("\nSection '%s' has no data to dump.\n"),
7317 SECTION_NAME (section
));
7321 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7323 addr
= section
->sh_addr
;
7325 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7338 lbytes
= (bytes
> 16 ? 16 : bytes
);
7340 printf (" 0x%8.8lx ", (unsigned long) addr
);
7342 switch (elf_header
.e_ident
[EI_DATA
])
7346 for (j
= 15; j
>= 0; j
--)
7349 printf ("%2.2x", data
[j
]);
7359 for (j
= 0; j
< 16; j
++)
7362 printf ("%2.2x", data
[j
]);
7372 for (j
= 0; j
< lbytes
; j
++)
7375 if (k
>= ' ' && k
< 0x7f)
7393 /* Apply addends of RELA relocations. */
7396 debug_apply_rela_addends (void *file
,
7397 Elf_Internal_Shdr
*section
,
7398 unsigned char *start
)
7400 Elf_Internal_Shdr
*relsec
;
7401 unsigned char *end
= start
+ section
->sh_size
;
7402 /* FIXME: The relocation field size is relocation type dependent. */
7403 unsigned int reloc_size
= 4;
7405 if (!is_relocatable
)
7408 if (section
->sh_size
< reloc_size
)
7411 for (relsec
= section_headers
;
7412 relsec
< section_headers
+ elf_header
.e_shnum
;
7415 unsigned long nrelas
;
7416 Elf_Internal_Rela
*rela
, *rp
;
7417 Elf_Internal_Shdr
*symsec
;
7418 Elf_Internal_Sym
*symtab
;
7419 Elf_Internal_Sym
*sym
;
7421 if (relsec
->sh_type
!= SHT_RELA
7422 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7423 || SECTION_HEADER (relsec
->sh_info
) != section
7424 || relsec
->sh_size
== 0
7425 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7428 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7432 symsec
= SECTION_HEADER (relsec
->sh_link
);
7433 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7435 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7439 loc
= start
+ rp
->r_offset
;
7440 if ((loc
+ reloc_size
) > end
)
7442 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7443 (unsigned long) rp
->r_offset
,
7444 SECTION_NAME (section
));
7450 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7452 if (ELF32_R_SYM (rp
->r_info
) != 0
7453 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7454 /* Relocations against object symbols can happen,
7455 eg when referencing a global array. For an
7456 example of this see the _clz.o binary in libgcc.a. */
7457 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7459 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7460 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7461 SECTION_NAME (section
));
7467 /* In MIPS little-endian objects, r_info isn't really a
7468 64-bit little-endian value: it has a 32-bit little-endian
7469 symbol index followed by four individual byte fields.
7470 Reorder INFO accordingly. */
7471 if (elf_header
.e_machine
== EM_MIPS
7472 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7473 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7474 | ((rp
->r_info
>> 56) & 0xff)
7475 | ((rp
->r_info
>> 40) & 0xff00)
7476 | ((rp
->r_info
>> 24) & 0xff0000)
7477 | ((rp
->r_info
>> 8) & 0xff000000));
7479 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7481 if (ELF64_R_SYM (rp
->r_info
) != 0
7482 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7483 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7485 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7486 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7487 SECTION_NAME (section
));
7492 byte_put (loc
, rp
->r_addend
, reloc_size
);
7503 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
7505 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7506 Elf_Internal_Shdr
*sec
;
7509 /* If it is already loaded, do nothing. */
7510 if (section
->start
!= NULL
)
7513 /* Locate the debug section. */
7514 sec
= find_section (section
->name
);
7518 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
7519 section
->address
= sec
->sh_addr
;
7520 section
->size
= sec
->sh_size
;
7521 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
7524 if (debug_displays
[debug
].relocate
)
7525 debug_apply_rela_addends (file
, sec
, section
->start
);
7527 return section
->start
!= NULL
;
7531 free_debug_section (enum dwarf_section_display_enum debug
)
7533 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7535 if (section
->start
== NULL
)
7538 free ((char *) section
->start
);
7539 section
->start
= NULL
;
7540 section
->address
= 0;
7545 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
7547 char *name
= SECTION_NAME (section
);
7548 bfd_size_type length
;
7550 enum dwarf_section_display_enum i
;
7552 length
= section
->sh_size
;
7555 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7559 if (strneq (name
, ".gnu.linkonce.wi.", 17))
7560 name
= ".debug_info";
7562 /* See if we know how to display the contents of this section. */
7563 for (i
= 0; i
< max
; i
++)
7564 if (streq (debug_displays
[i
].section
.name
, name
))
7566 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
7568 if (load_debug_section (i
, file
))
7570 result
&= debug_displays
[i
].display (sec
, file
);
7572 if (i
!= info
&& i
!= abbrev
)
7573 free_debug_section (i
);
7581 printf (_("Unrecognized debug section: %s\n"), name
);
7588 /* Set DUMP_SECTS for all sections where dumps were requested
7589 based on section name. */
7592 initialise_dumps_byname (void)
7594 struct dump_list_entry
*cur
;
7596 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
7601 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
7602 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
7604 request_dump (i
, cur
->type
);
7609 warn (_("Section '%s' was not dumped because it does not exist!\n"),
7615 process_section_contents (FILE *file
)
7617 Elf_Internal_Shdr
*section
;
7623 initialise_dumps_byname ();
7625 for (i
= 0, section
= section_headers
;
7626 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
7629 #ifdef SUPPORT_DISASSEMBLY
7630 if (dump_sects
[i
] & DISASS_DUMP
)
7631 disassemble_section (section
, file
);
7633 if (dump_sects
[i
] & HEX_DUMP
)
7634 dump_section (section
, file
);
7636 if (dump_sects
[i
] & DEBUG_DUMP
)
7637 display_debug_section (section
, file
);
7640 /* Check to see if the user requested a
7641 dump of a section that does not exist. */
7642 while (i
++ < num_dump_sects
)
7644 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
7648 process_mips_fpe_exception (int mask
)
7653 if (mask
& OEX_FPU_INEX
)
7654 fputs ("INEX", stdout
), first
= 0;
7655 if (mask
& OEX_FPU_UFLO
)
7656 printf ("%sUFLO", first
? "" : "|"), first
= 0;
7657 if (mask
& OEX_FPU_OFLO
)
7658 printf ("%sOFLO", first
? "" : "|"), first
= 0;
7659 if (mask
& OEX_FPU_DIV0
)
7660 printf ("%sDIV0", first
? "" : "|"), first
= 0;
7661 if (mask
& OEX_FPU_INVAL
)
7662 printf ("%sINVAL", first
? "" : "|");
7665 fputs ("0", stdout
);
7668 /* ARM EABI attributes section. */
7673 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
7676 } arm_attr_public_tag
;
7678 static const char *arm_attr_tag_CPU_arch
[] =
7679 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
7681 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
7682 static const char *arm_attr_tag_THUMB_ISA_use
[] =
7683 {"No", "Thumb-1", "Thumb-2"};
7684 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2"};
7685 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
7686 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
7687 static const char *arm_attr_tag_ABI_PCS_config
[] =
7688 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
7689 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
7690 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
7691 {"V6", "SB", "TLS", "Unused"};
7692 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
7693 {"Absolute", "PC-relative", "SB-relative", "None"};
7694 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
7695 {"Absolute", "PC-relative", "None"};
7696 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
7697 {"None", "direct", "GOT-indirect"};
7698 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
7699 {"None", "??? 1", "2", "??? 3", "4"};
7700 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
7701 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
7702 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
7703 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
7704 static const char *arm_attr_tag_ABI_FP_number_model
[] =
7705 {"Unused", "Finite", "RTABI", "IEEE 754"};
7706 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
7707 static const char *arm_attr_tag_ABI_align8_preserved
[] =
7708 {"No", "Yes, except leaf SP", "Yes"};
7709 static const char *arm_attr_tag_ABI_enum_size
[] =
7710 {"Unused", "small", "int", "forced to int"};
7711 static const char *arm_attr_tag_ABI_HardFP_use
[] =
7712 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
7713 static const char *arm_attr_tag_ABI_VFP_args
[] =
7714 {"AAPCS", "VFP registers", "custom"};
7715 static const char *arm_attr_tag_ABI_WMMX_args
[] =
7716 {"AAPCS", "WMMX registers", "custom"};
7717 static const char *arm_attr_tag_ABI_optimization_goals
[] =
7718 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7719 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
7720 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
7721 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7722 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
7724 #define LOOKUP(id, name) \
7725 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
7726 static arm_attr_public_tag arm_attr_public_tags
[] =
7728 {4, "CPU_raw_name", 1, NULL
},
7729 {5, "CPU_name", 1, NULL
},
7730 LOOKUP(6, CPU_arch
),
7731 {7, "CPU_arch_profile", 0, NULL
},
7732 LOOKUP(8, ARM_ISA_use
),
7733 LOOKUP(9, THUMB_ISA_use
),
7734 LOOKUP(10, VFP_arch
),
7735 LOOKUP(11, WMMX_arch
),
7736 LOOKUP(12, NEON_arch
),
7737 LOOKUP(13, ABI_PCS_config
),
7738 LOOKUP(14, ABI_PCS_R9_use
),
7739 LOOKUP(15, ABI_PCS_RW_data
),
7740 LOOKUP(16, ABI_PCS_RO_DATA
),
7741 LOOKUP(17, ABI_PCS_GOT_use
),
7742 LOOKUP(18, ABI_PCS_wchar_t
),
7743 LOOKUP(19, ABI_FP_rounding
),
7744 LOOKUP(20, ABI_FP_denormal
),
7745 LOOKUP(21, ABI_FP_exceptions
),
7746 LOOKUP(22, ABI_FP_user_exceptions
),
7747 LOOKUP(23, ABI_FP_number_model
),
7748 LOOKUP(24, ABI_align8_needed
),
7749 LOOKUP(25, ABI_align8_preserved
),
7750 LOOKUP(26, ABI_enum_size
),
7751 LOOKUP(27, ABI_HardFP_use
),
7752 LOOKUP(28, ABI_VFP_args
),
7753 LOOKUP(29, ABI_WMMX_args
),
7754 LOOKUP(30, ABI_optimization_goals
),
7755 LOOKUP(31, ABI_FP_optimization_goals
),
7756 {32, "compatibility", 0, NULL
}
7760 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
7763 read_uleb128 (unsigned char *p
, unsigned int *plen
)
7777 val
|= ((unsigned int)c
& 0x7f) << shift
;
7786 static unsigned char *
7787 display_arm_attribute (unsigned char *p
)
7792 arm_attr_public_tag
*attr
;
7796 tag
= read_uleb128 (p
, &len
);
7799 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
7801 if (arm_attr_public_tags
[i
].tag
== tag
)
7803 attr
= &arm_attr_public_tags
[i
];
7810 printf (" Tag_%s: ", attr
->name
);
7816 case 7: /* Tag_CPU_arch_profile. */
7817 val
= read_uleb128 (p
, &len
);
7821 case 0: printf ("None\n"); break;
7822 case 'A': printf ("Application\n"); break;
7823 case 'R': printf ("Realtime\n"); break;
7824 case 'M': printf ("Microcontroller\n"); break;
7825 default: printf ("??? (%d)\n", val
); break;
7829 case 32: /* Tag_compatibility. */
7830 val
= read_uleb128 (p
, &len
);
7832 printf ("flag = %d, vendor = %s\n", val
, p
);
7833 p
+= strlen((char *)p
) + 1;
7847 assert (attr
->type
& 0x80);
7848 val
= read_uleb128 (p
, &len
);
7850 type
= attr
->type
& 0x7f;
7852 printf ("??? (%d)\n", val
);
7854 printf ("%s\n", attr
->table
[val
]);
7861 type
= 1; /* String. */
7863 type
= 2; /* uleb128. */
7864 printf (" Tag_unknown_%d: ", tag
);
7869 printf ("\"%s\"\n", p
);
7870 p
+= strlen((char *)p
) + 1;
7874 val
= read_uleb128 (p
, &len
);
7876 printf ("%d (0x%x)\n", val
, val
);
7883 process_arm_specific (FILE *file
)
7885 Elf_Internal_Shdr
*sect
;
7886 unsigned char *contents
;
7889 bfd_vma section_len
;
7893 /* Find the section header so that we get the size. */
7894 for (i
= 0, sect
= section_headers
;
7895 i
< elf_header
.e_shnum
;
7898 if (sect
->sh_type
!= SHT_ARM_ATTRIBUTES
)
7901 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
7909 len
= sect
->sh_size
- 1;
7914 bfd_boolean public_section
;
7916 section_len
= byte_get (p
, 4);
7918 if (section_len
> len
)
7920 printf (_("ERROR: Bad section length (%d > %d)\n"),
7921 (int)section_len
, (int)len
);
7925 printf ("Attribute Section: %s\n", p
);
7926 if (strcmp ((char *)p
, "aeabi") == 0)
7927 public_section
= TRUE
;
7929 public_section
= FALSE
;
7930 namelen
= strlen ((char *)p
) + 1;
7932 section_len
-= namelen
+ 4;
7933 while (section_len
> 0)
7938 size
= byte_get (p
, 4);
7939 if (size
> section_len
)
7941 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
7942 (int)size
, (int)section_len
);
7945 section_len
-= size
;
7951 printf ("File Attributes\n");
7954 printf ("Section Attributes:");
7957 printf ("Symbol Attributes:");
7962 val
= read_uleb128 (p
, &i
);
7966 printf (" %d", val
);
7971 printf ("Unknown tag: %d\n", tag
);
7972 public_section
= FALSE
;
7978 p
= display_arm_attribute(p
);
7982 /* ??? Do something sensible, like dump hex. */
7983 printf (" Unknown section contexts\n");
7991 printf (_("Unknown format '%c'\n"), *p
);
8000 process_mips_specific (FILE *file
)
8002 Elf_Internal_Dyn
*entry
;
8003 size_t liblist_offset
= 0;
8004 size_t liblistno
= 0;
8005 size_t conflictsno
= 0;
8006 size_t options_offset
= 0;
8007 size_t conflicts_offset
= 0;
8009 /* We have a lot of special sections. Thanks SGI! */
8010 if (dynamic_section
== NULL
)
8011 /* No information available. */
8014 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
8015 switch (entry
->d_tag
)
8017 case DT_MIPS_LIBLIST
:
8019 = offset_from_vma (file
, entry
->d_un
.d_val
,
8020 liblistno
* sizeof (Elf32_External_Lib
));
8022 case DT_MIPS_LIBLISTNO
:
8023 liblistno
= entry
->d_un
.d_val
;
8025 case DT_MIPS_OPTIONS
:
8026 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
8028 case DT_MIPS_CONFLICT
:
8030 = offset_from_vma (file
, entry
->d_un
.d_val
,
8031 conflictsno
* sizeof (Elf32_External_Conflict
));
8033 case DT_MIPS_CONFLICTNO
:
8034 conflictsno
= entry
->d_un
.d_val
;
8040 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
8042 Elf32_External_Lib
*elib
;
8045 elib
= get_data (NULL
, file
, liblist_offset
,
8046 liblistno
, sizeof (Elf32_External_Lib
),
8050 printf ("\nSection '.liblist' contains %lu entries:\n",
8051 (unsigned long) liblistno
);
8052 fputs (" Library Time Stamp Checksum Version Flags\n",
8055 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
8062 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8063 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8064 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8065 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8066 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8068 tmp
= gmtime (&time
);
8069 snprintf (timebuf
, sizeof (timebuf
),
8070 "%04u-%02u-%02uT%02u:%02u:%02u",
8071 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8072 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8074 printf ("%3lu: ", (unsigned long) cnt
);
8075 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
8076 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
8078 printf ("<corrupt: %9ld>", liblist
.l_name
);
8079 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
8082 if (liblist
.l_flags
== 0)
8093 { " EXACT_MATCH", LL_EXACT_MATCH
},
8094 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
8095 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
8096 { " EXPORTS", LL_EXPORTS
},
8097 { " DELAY_LOAD", LL_DELAY_LOAD
},
8098 { " DELTA", LL_DELTA
}
8100 int flags
= liblist
.l_flags
;
8104 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
8106 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
8108 fputs (l_flags_vals
[fcnt
].name
, stdout
);
8109 flags
^= l_flags_vals
[fcnt
].bit
;
8112 printf (" %#x", (unsigned int) flags
);
8122 if (options_offset
!= 0)
8124 Elf_External_Options
*eopt
;
8125 Elf_Internal_Shdr
*sect
= section_headers
;
8126 Elf_Internal_Options
*iopt
;
8127 Elf_Internal_Options
*option
;
8131 /* Find the section header so that we get the size. */
8132 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
8135 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
8139 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
8142 error (_("Out of memory"));
8149 while (offset
< sect
->sh_size
)
8151 Elf_External_Options
*eoption
;
8153 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
8155 option
->kind
= BYTE_GET (eoption
->kind
);
8156 option
->size
= BYTE_GET (eoption
->size
);
8157 option
->section
= BYTE_GET (eoption
->section
);
8158 option
->info
= BYTE_GET (eoption
->info
);
8160 offset
+= option
->size
;
8166 printf (_("\nSection '%s' contains %d entries:\n"),
8167 SECTION_NAME (sect
), cnt
);
8175 switch (option
->kind
)
8178 /* This shouldn't happen. */
8179 printf (" NULL %d %lx", option
->section
, option
->info
);
8182 printf (" REGINFO ");
8183 if (elf_header
.e_machine
== EM_MIPS
)
8186 Elf32_External_RegInfo
*ereg
;
8187 Elf32_RegInfo reginfo
;
8189 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
8190 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8191 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8192 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8193 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8194 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8195 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8197 printf ("GPR %08lx GP 0x%lx\n",
8199 (unsigned long) reginfo
.ri_gp_value
);
8200 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8201 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8202 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8207 Elf64_External_RegInfo
*ereg
;
8208 Elf64_Internal_RegInfo reginfo
;
8210 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
8211 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8212 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8213 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8214 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8215 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8216 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8218 printf ("GPR %08lx GP 0x",
8219 reginfo
.ri_gprmask
);
8220 printf_vma (reginfo
.ri_gp_value
);
8223 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8224 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8225 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8229 case ODK_EXCEPTIONS
:
8230 fputs (" EXCEPTIONS fpe_min(", stdout
);
8231 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
8232 fputs (") fpe_max(", stdout
);
8233 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
8234 fputs (")", stdout
);
8236 if (option
->info
& OEX_PAGE0
)
8237 fputs (" PAGE0", stdout
);
8238 if (option
->info
& OEX_SMM
)
8239 fputs (" SMM", stdout
);
8240 if (option
->info
& OEX_FPDBUG
)
8241 fputs (" FPDBUG", stdout
);
8242 if (option
->info
& OEX_DISMISS
)
8243 fputs (" DISMISS", stdout
);
8246 fputs (" PAD ", stdout
);
8247 if (option
->info
& OPAD_PREFIX
)
8248 fputs (" PREFIX", stdout
);
8249 if (option
->info
& OPAD_POSTFIX
)
8250 fputs (" POSTFIX", stdout
);
8251 if (option
->info
& OPAD_SYMBOL
)
8252 fputs (" SYMBOL", stdout
);
8255 fputs (" HWPATCH ", stdout
);
8256 if (option
->info
& OHW_R4KEOP
)
8257 fputs (" R4KEOP", stdout
);
8258 if (option
->info
& OHW_R8KPFETCH
)
8259 fputs (" R8KPFETCH", stdout
);
8260 if (option
->info
& OHW_R5KEOP
)
8261 fputs (" R5KEOP", stdout
);
8262 if (option
->info
& OHW_R5KCVTL
)
8263 fputs (" R5KCVTL", stdout
);
8266 fputs (" FILL ", stdout
);
8267 /* XXX Print content of info word? */
8270 fputs (" TAGS ", stdout
);
8271 /* XXX Print content of info word? */
8274 fputs (" HWAND ", stdout
);
8275 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8276 fputs (" R4KEOP_CHECKED", stdout
);
8277 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8278 fputs (" R4KEOP_CLEAN", stdout
);
8281 fputs (" HWOR ", stdout
);
8282 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8283 fputs (" R4KEOP_CHECKED", stdout
);
8284 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8285 fputs (" R4KEOP_CLEAN", stdout
);
8288 printf (" GP_GROUP %#06lx self-contained %#06lx",
8289 option
->info
& OGP_GROUP
,
8290 (option
->info
& OGP_SELF
) >> 16);
8293 printf (" IDENT %#06lx self-contained %#06lx",
8294 option
->info
& OGP_GROUP
,
8295 (option
->info
& OGP_SELF
) >> 16);
8298 /* This shouldn't happen. */
8299 printf (" %3d ??? %d %lx",
8300 option
->kind
, option
->section
, option
->info
);
8304 len
= sizeof (*eopt
);
8305 while (len
< option
->size
)
8306 if (((char *) option
)[len
] >= ' '
8307 && ((char *) option
)[len
] < 0x7f)
8308 printf ("%c", ((char *) option
)[len
++]);
8310 printf ("\\%03o", ((char *) option
)[len
++]);
8312 fputs ("\n", stdout
);
8320 if (conflicts_offset
!= 0 && conflictsno
!= 0)
8322 Elf32_Conflict
*iconf
;
8325 if (dynamic_symbols
== NULL
)
8327 error (_("conflict list found without a dynamic symbol table"));
8331 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
8334 error (_("Out of memory"));
8340 Elf32_External_Conflict
*econf32
;
8342 econf32
= get_data (NULL
, file
, conflicts_offset
,
8343 conflictsno
, sizeof (*econf32
), _("conflict"));
8347 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8348 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
8354 Elf64_External_Conflict
*econf64
;
8356 econf64
= get_data (NULL
, file
, conflicts_offset
,
8357 conflictsno
, sizeof (*econf64
), _("conflict"));
8361 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8362 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
8367 printf (_("\nSection '.conflict' contains %lu entries:\n"),
8368 (unsigned long) conflictsno
);
8369 puts (_(" Num: Index Value Name"));
8371 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8373 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
8375 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
8376 print_vma (psym
->st_value
, FULL_HEX
);
8378 if (VALID_DYNAMIC_NAME (psym
->st_name
))
8379 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
8381 printf ("<corrupt: %14ld>", psym
->st_name
);
8392 process_gnu_liblist (FILE *file
)
8394 Elf_Internal_Shdr
*section
, *string_sec
;
8395 Elf32_External_Lib
*elib
;
8404 for (i
= 0, section
= section_headers
;
8405 i
< elf_header
.e_shnum
;
8408 switch (section
->sh_type
)
8410 case SHT_GNU_LIBLIST
:
8411 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
8414 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
8419 string_sec
= SECTION_HEADER (section
->sh_link
);
8421 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
8422 string_sec
->sh_size
, _("liblist string table"));
8423 strtab_size
= string_sec
->sh_size
;
8426 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
8432 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
8433 SECTION_NAME (section
),
8434 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
8436 puts (" Library Time Stamp Checksum Version Flags");
8438 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
8446 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8447 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8448 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8449 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8450 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8452 tmp
= gmtime (&time
);
8453 snprintf (timebuf
, sizeof (timebuf
),
8454 "%04u-%02u-%02uT%02u:%02u:%02u",
8455 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8456 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8458 printf ("%3lu: ", (unsigned long) cnt
);
8460 printf ("%-20s", liblist
.l_name
< strtab_size
8461 ? strtab
+ liblist
.l_name
: "<corrupt>");
8463 printf ("%-20.20s", liblist
.l_name
< strtab_size
8464 ? strtab
+ liblist
.l_name
: "<corrupt>");
8465 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
8466 liblist
.l_version
, liblist
.l_flags
);
8477 get_note_type (unsigned e_type
)
8479 static char buff
[64];
8481 if (elf_header
.e_type
== ET_CORE
)
8485 return _("NT_AUXV (auxiliary vector)");
8487 return _("NT_PRSTATUS (prstatus structure)");
8489 return _("NT_FPREGSET (floating point registers)");
8491 return _("NT_PRPSINFO (prpsinfo structure)");
8493 return _("NT_TASKSTRUCT (task structure)");
8495 return _("NT_PRXFPREG (user_xfpregs structure)");
8497 return _("NT_PSTATUS (pstatus structure)");
8499 return _("NT_FPREGS (floating point registers)");
8501 return _("NT_PSINFO (psinfo structure)");
8503 return _("NT_LWPSTATUS (lwpstatus_t structure)");
8505 return _("NT_LWPSINFO (lwpsinfo_t structure)");
8506 case NT_WIN32PSTATUS
:
8507 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8515 return _("NT_VERSION (version)");
8517 return _("NT_ARCH (architecture)");
8522 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8527 get_netbsd_elfcore_note_type (unsigned e_type
)
8529 static char buff
[64];
8531 if (e_type
== NT_NETBSDCORE_PROCINFO
)
8533 /* NetBSD core "procinfo" structure. */
8534 return _("NetBSD procinfo structure");
8537 /* As of Jan 2002 there are no other machine-independent notes
8538 defined for NetBSD core files. If the note type is less
8539 than the start of the machine-dependent note types, we don't
8542 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
8544 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8548 switch (elf_header
.e_machine
)
8550 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8551 and PT_GETFPREGS == mach+2. */
8556 case EM_SPARC32PLUS
:
8560 case NT_NETBSDCORE_FIRSTMACH
+0:
8561 return _("PT_GETREGS (reg structure)");
8562 case NT_NETBSDCORE_FIRSTMACH
+2:
8563 return _("PT_GETFPREGS (fpreg structure)");
8569 /* On all other arch's, PT_GETREGS == mach+1 and
8570 PT_GETFPREGS == mach+3. */
8574 case NT_NETBSDCORE_FIRSTMACH
+1:
8575 return _("PT_GETREGS (reg structure)");
8576 case NT_NETBSDCORE_FIRSTMACH
+3:
8577 return _("PT_GETFPREGS (fpreg structure)");
8583 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
8584 e_type
- NT_NETBSDCORE_FIRSTMACH
);
8588 /* Note that by the ELF standard, the name field is already null byte
8589 terminated, and namesz includes the terminating null byte.
8590 I.E. the value of namesz for the name "FSF" is 4.
8592 If the value of namesz is zero, there is no name present. */
8594 process_note (Elf_Internal_Note
*pnote
)
8598 if (pnote
->namesz
== 0)
8599 /* If there is no note name, then use the default set of
8600 note type strings. */
8601 nt
= get_note_type (pnote
->type
);
8603 else if (strneq (pnote
->namedata
, "NetBSD-CORE", 11))
8604 /* NetBSD-specific core file notes. */
8605 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
8608 /* Don't recognize this note name; just use the default set of
8609 note type strings. */
8610 nt
= get_note_type (pnote
->type
);
8612 printf (" %s\t\t0x%08lx\t%s\n",
8613 pnote
->namesz
? pnote
->namedata
: "(NONE)",
8620 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
8622 Elf_External_Note
*pnotes
;
8623 Elf_External_Note
*external
;
8629 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
8635 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8636 (unsigned long) offset
, (unsigned long) length
);
8637 printf (_(" Owner\t\tData size\tDescription\n"));
8639 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
8641 Elf_External_Note
*next
;
8642 Elf_Internal_Note inote
;
8645 inote
.type
= BYTE_GET (external
->type
);
8646 inote
.namesz
= BYTE_GET (external
->namesz
);
8647 inote
.namedata
= external
->name
;
8648 inote
.descsz
= BYTE_GET (external
->descsz
);
8649 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
8650 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
8652 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
8654 if (((char *) next
) > (((char *) pnotes
) + length
))
8656 warn (_("corrupt note found at offset %lx into core notes\n"),
8657 (long)((char *)external
- (char *)pnotes
));
8658 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
8659 inote
.type
, inote
.namesz
, inote
.descsz
);
8665 /* Verify that name is null terminated. It appears that at least
8666 one version of Linux (RedHat 6.0) generates corefiles that don't
8667 comply with the ELF spec by failing to include the null byte in
8669 if (inote
.namedata
[inote
.namesz
] != '\0')
8671 temp
= malloc (inote
.namesz
+ 1);
8675 error (_("Out of memory\n"));
8680 strncpy (temp
, inote
.namedata
, inote
.namesz
);
8681 temp
[inote
.namesz
] = 0;
8683 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8684 inote
.namedata
= temp
;
8687 res
&= process_note (& inote
);
8702 process_corefile_note_segments (FILE *file
)
8704 Elf_Internal_Phdr
*segment
;
8708 if (! get_program_headers (file
))
8711 for (i
= 0, segment
= program_headers
;
8712 i
< elf_header
.e_phnum
;
8715 if (segment
->p_type
== PT_NOTE
)
8716 res
&= process_corefile_note_segment (file
,
8717 (bfd_vma
) segment
->p_offset
,
8718 (bfd_vma
) segment
->p_filesz
);
8725 process_note_sections (FILE *file
)
8727 Elf_Internal_Shdr
*section
;
8731 for (i
= 0, section
= section_headers
;
8732 i
< elf_header
.e_shnum
;
8734 if (section
->sh_type
== SHT_NOTE
)
8735 res
&= process_corefile_note_segment (file
,
8736 (bfd_vma
) section
->sh_offset
,
8737 (bfd_vma
) section
->sh_size
);
8743 process_notes (FILE *file
)
8745 /* If we have not been asked to display the notes then do nothing. */
8749 if (elf_header
.e_type
!= ET_CORE
)
8750 return process_note_sections (file
);
8752 /* No program headers means no NOTE segment. */
8753 if (elf_header
.e_phnum
> 0)
8754 return process_corefile_note_segments (file
);
8756 printf (_("No note segments present in the core file.\n"));
8761 process_arch_specific (FILE *file
)
8766 switch (elf_header
.e_machine
)
8769 return process_arm_specific (file
);
8771 case EM_MIPS_RS3_LE
:
8772 return process_mips_specific (file
);
8781 get_file_header (FILE *file
)
8783 /* Read in the identity array. */
8784 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
8787 /* Determine how to read the rest of the header. */
8788 switch (elf_header
.e_ident
[EI_DATA
])
8790 default: /* fall through */
8791 case ELFDATANONE
: /* fall through */
8793 byte_get
= byte_get_little_endian
;
8794 byte_put
= byte_put_little_endian
;
8797 byte_get
= byte_get_big_endian
;
8798 byte_put
= byte_put_big_endian
;
8802 /* For now we only support 32 bit and 64 bit ELF files. */
8803 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
8805 /* Read in the rest of the header. */
8808 Elf32_External_Ehdr ehdr32
;
8810 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
8813 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
8814 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
8815 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
8816 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
8817 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
8818 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
8819 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
8820 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
8821 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
8822 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
8823 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
8824 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
8825 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
8829 Elf64_External_Ehdr ehdr64
;
8831 /* If we have been compiled with sizeof (bfd_vma) == 4, then
8832 we will not be able to cope with the 64bit data found in
8833 64 ELF files. Detect this now and abort before we start
8834 overwriting things. */
8835 if (sizeof (bfd_vma
) < 8)
8837 error (_("This instance of readelf has been built without support for a\n\
8838 64 bit data type and so it cannot read 64 bit ELF files.\n"));
8842 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
8845 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
8846 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
8847 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
8848 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
8849 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
8850 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
8851 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
8852 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
8853 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
8854 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
8855 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
8856 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
8857 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
8860 if (elf_header
.e_shoff
)
8862 /* There may be some extensions in the first section header. Don't
8863 bomb if we can't read it. */
8865 get_32bit_section_headers (file
, 1);
8867 get_64bit_section_headers (file
, 1);
8870 is_relocatable
= elf_header
.e_type
== ET_REL
;
8875 /* Process one ELF object file according to the command line options.
8876 This file may actually be stored in an archive. The file is
8877 positioned at the start of the ELF object. */
8880 process_object (char *file_name
, FILE *file
)
8884 if (! get_file_header (file
))
8886 error (_("%s: Failed to read file header\n"), file_name
);
8890 /* Initialise per file variables. */
8891 for (i
= NUM_ELEM (version_info
); i
--;)
8892 version_info
[i
] = 0;
8894 for (i
= NUM_ELEM (dynamic_info
); i
--;)
8895 dynamic_info
[i
] = 0;
8897 /* Process the file. */
8899 printf (_("\nFile: %s\n"), file_name
);
8901 /* Initialise the dump_sects array from the cmdline_dump_sects array.
8902 Note we do this even if cmdline_dump_sects is empty because we
8903 must make sure that the dump_sets array is zeroed out before each
8904 object file is processed. */
8905 if (num_dump_sects
> num_cmdline_dump_sects
)
8906 memset (dump_sects
, 0, num_dump_sects
);
8908 if (num_cmdline_dump_sects
> 0)
8910 if (num_dump_sects
== 0)
8911 /* A sneaky way of allocating the dump_sects array. */
8912 request_dump (num_cmdline_dump_sects
, 0);
8914 assert (num_dump_sects
>= num_cmdline_dump_sects
);
8915 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
8918 if (! process_file_header ())
8921 if (! process_section_headers (file
))
8923 /* Without loaded section headers we cannot process lots of
8925 do_unwind
= do_version
= do_dump
= do_arch
= 0;
8927 if (! do_using_dynamic
)
8928 do_syms
= do_reloc
= 0;
8931 if (! process_section_groups (file
))
8933 /* Without loaded section groups we cannot process unwind. */
8937 if (process_program_headers (file
))
8938 process_dynamic_section (file
);
8940 process_relocs (file
);
8942 process_unwind (file
);
8944 process_symbol_table (file
);
8946 process_syminfo (file
);
8948 process_version_sections (file
);
8950 process_section_contents (file
);
8952 process_notes (file
);
8954 process_gnu_liblist (file
);
8956 process_arch_specific (file
);
8958 if (program_headers
)
8960 free (program_headers
);
8961 program_headers
= NULL
;
8964 if (section_headers
)
8966 free (section_headers
);
8967 section_headers
= NULL
;
8972 free (string_table
);
8973 string_table
= NULL
;
8974 string_table_length
= 0;
8977 if (dynamic_strings
)
8979 free (dynamic_strings
);
8980 dynamic_strings
= NULL
;
8981 dynamic_strings_length
= 0;
8984 if (dynamic_symbols
)
8986 free (dynamic_symbols
);
8987 dynamic_symbols
= NULL
;
8988 num_dynamic_syms
= 0;
8991 if (dynamic_syminfo
)
8993 free (dynamic_syminfo
);
8994 dynamic_syminfo
= NULL
;
8997 if (section_headers_groups
)
8999 free (section_headers_groups
);
9000 section_headers_groups
= NULL
;
9005 struct group_list
*g
, *next
;
9007 for (i
= 0; i
< group_count
; i
++)
9009 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
9016 free (section_groups
);
9017 section_groups
= NULL
;
9020 free_debug_memory ();
9025 /* Process an ELF archive. The file is positioned just after the
9029 process_archive (char *file_name
, FILE *file
)
9031 struct ar_hdr arhdr
;
9034 char *longnames
= NULL
;
9035 unsigned long longnames_size
= 0;
9036 size_t file_name_size
;
9041 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9042 if (got
!= sizeof arhdr
)
9047 error (_("%s: failed to read archive header\n"), file_name
);
9051 if (memcmp (arhdr
.ar_name
, "/ ", 16) == 0)
9053 /* This is the archive symbol table. Skip it.
9054 FIXME: We should have an option to dump it. */
9055 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9056 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
9058 error (_("%s: failed to skip archive symbol table\n"), file_name
);
9062 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9063 if (got
!= sizeof arhdr
)
9068 error (_("%s: failed to read archive header\n"), file_name
);
9073 if (memcmp (arhdr
.ar_name
, "// ", 16) == 0)
9075 /* This is the archive string table holding long member
9078 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9080 longnames
= malloc (longnames_size
);
9081 if (longnames
== NULL
)
9083 error (_("Out of memory\n"));
9087 if (fread (longnames
, longnames_size
, 1, file
) != 1)
9090 error (_("%s: failed to read string table\n"), file_name
);
9094 if ((longnames_size
& 1) != 0)
9097 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9098 if (got
!= sizeof arhdr
)
9105 error (_("%s: failed to read archive header\n"), file_name
);
9110 file_name_size
= strlen (file_name
);
9119 if (arhdr
.ar_name
[0] == '/')
9123 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
9124 if (off
>= longnames_size
)
9126 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
9131 name
= longnames
+ off
;
9132 nameend
= memchr (name
, '/', longnames_size
- off
);
9136 name
= arhdr
.ar_name
;
9137 nameend
= memchr (name
, '/', 16);
9140 if (nameend
== NULL
)
9142 error (_("%s: bad archive file name\n"), file_name
);
9147 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
9148 if (namealc
== NULL
)
9150 error (_("Out of memory\n"));
9155 memcpy (namealc
, file_name
, file_name_size
);
9156 namealc
[file_name_size
] = '(';
9157 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
9158 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
9159 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
9161 archive_file_offset
= ftell (file
);
9162 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9164 ret
|= process_object (namealc
, file
);
9169 (archive_file_offset
9171 + (archive_file_size
& 1)),
9174 error (_("%s: failed to seek to next archive header\n"), file_name
);
9179 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9180 if (got
!= sizeof arhdr
)
9185 error (_("%s: failed to read archive header\n"), file_name
);
9198 process_file (char *file_name
)
9201 struct stat statbuf
;
9205 if (stat (file_name
, &statbuf
) < 0)
9207 if (errno
== ENOENT
)
9208 error (_("'%s': No such file\n"), file_name
);
9210 error (_("Could not locate '%s'. System error message: %s\n"),
9211 file_name
, strerror (errno
));
9215 if (! S_ISREG (statbuf
.st_mode
))
9217 error (_("'%s' is not an ordinary file\n"), file_name
);
9221 file
= fopen (file_name
, "rb");
9224 error (_("Input file '%s' is not readable.\n"), file_name
);
9228 if (fread (armag
, SARMAG
, 1, file
) != 1)
9230 error (_("%s: Failed to read file header\n"), file_name
);
9235 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
9236 ret
= process_archive (file_name
, file
);
9240 archive_file_size
= archive_file_offset
= 0;
9241 ret
= process_object (file_name
, file
);
9249 #ifdef SUPPORT_DISASSEMBLY
9250 /* Needed by the i386 disassembler. For extra credit, someone could
9251 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9255 print_address (unsigned int addr
, FILE *outfile
)
9257 fprintf (outfile
,"0x%8.8x", addr
);
9260 /* Needed by the i386 disassembler. */
9262 db_task_printsym (unsigned int addr
)
9264 print_address (addr
, stderr
);
9269 main (int argc
, char **argv
)
9273 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9274 setlocale (LC_MESSAGES
, "");
9276 #if defined (HAVE_SETLOCALE)
9277 setlocale (LC_CTYPE
, "");
9279 bindtextdomain (PACKAGE
, LOCALEDIR
);
9280 textdomain (PACKAGE
);
9282 expandargv (&argc
, &argv
);
9284 parse_args (argc
, argv
);
9286 if (num_dump_sects
> 0)
9288 /* Make a copy of the dump_sects array. */
9289 cmdline_dump_sects
= malloc (num_dump_sects
);
9290 if (cmdline_dump_sects
== NULL
)
9291 error (_("Out of memory allocating dump request table."));
9294 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
9295 num_cmdline_dump_sects
= num_dump_sects
;
9299 if (optind
< (argc
- 1))
9303 while (optind
< argc
)
9304 err
|= process_file (argv
[optind
++]);
9306 if (dump_sects
!= NULL
)
9308 if (cmdline_dump_sects
!= NULL
)
9309 free (cmdline_dump_sects
);