1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 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
:
634 warn (_("Don't know about relocations on this machine architecture\n"));
640 slurp_rela_relocs (FILE *file
,
641 unsigned long rel_offset
,
642 unsigned long rel_size
,
643 Elf_Internal_Rela
**relasp
,
644 unsigned long *nrelasp
)
646 Elf_Internal_Rela
*relas
;
647 unsigned long nrelas
;
652 Elf32_External_Rela
*erelas
;
654 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
658 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
660 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
665 error (_("out of memory parsing relocs"));
669 for (i
= 0; i
< nrelas
; i
++)
671 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
672 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
673 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
680 Elf64_External_Rela
*erelas
;
682 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
686 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
688 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
693 error (_("out of memory parsing relocs"));
697 for (i
= 0; i
< nrelas
; i
++)
699 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
700 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
701 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
712 slurp_rel_relocs (FILE *file
,
713 unsigned long rel_offset
,
714 unsigned long rel_size
,
715 Elf_Internal_Rela
**relsp
,
716 unsigned long *nrelsp
)
718 Elf_Internal_Rela
*rels
;
724 Elf32_External_Rel
*erels
;
726 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
730 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
732 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
737 error (_("out of memory parsing relocs"));
741 for (i
= 0; i
< nrels
; i
++)
743 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
744 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
745 rels
[i
].r_addend
= 0;
752 Elf64_External_Rel
*erels
;
754 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
758 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
760 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
765 error (_("out of memory parsing relocs"));
769 for (i
= 0; i
< nrels
; i
++)
771 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
772 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
773 rels
[i
].r_addend
= 0;
783 /* Display the contents of the relocation data found at the specified
787 dump_relocations (FILE *file
,
788 unsigned long rel_offset
,
789 unsigned long rel_size
,
790 Elf_Internal_Sym
*symtab
,
793 unsigned long strtablen
,
797 Elf_Internal_Rela
*rels
;
800 if (is_rela
== UNKNOWN
)
801 is_rela
= guess_is_rela (elf_header
.e_machine
);
805 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
810 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
819 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
821 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
826 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
828 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
836 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
838 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
843 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
845 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
849 for (i
= 0; i
< rel_size
; i
++)
852 const char *rtype2
= NULL
;
853 const char *rtype3
= NULL
;
856 bfd_vma symtab_index
;
861 offset
= rels
[i
].r_offset
;
862 info
= rels
[i
].r_info
;
866 type
= ELF32_R_TYPE (info
);
867 symtab_index
= ELF32_R_SYM (info
);
871 /* The #ifdef BFD64 below is to prevent a compile time warning.
872 We know that if we do not have a 64 bit data type that we
873 will never execute this code anyway. */
875 if (elf_header
.e_machine
== EM_MIPS
)
877 /* In little-endian objects, r_info isn't really a 64-bit
878 little-endian value: it has a 32-bit little-endian
879 symbol index followed by four individual byte fields.
880 Reorder INFO accordingly. */
881 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
882 info
= (((info
& 0xffffffff) << 32)
883 | ((info
>> 56) & 0xff)
884 | ((info
>> 40) & 0xff00)
885 | ((info
>> 24) & 0xff0000)
886 | ((info
>> 8) & 0xff000000));
887 type
= ELF64_MIPS_R_TYPE (info
);
888 type2
= ELF64_MIPS_R_TYPE2 (info
);
889 type3
= ELF64_MIPS_R_TYPE3 (info
);
891 else if (elf_header
.e_machine
== EM_SPARCV9
)
892 type
= ELF64_R_TYPE_ID (info
);
894 type
= ELF64_R_TYPE (info
);
896 symtab_index
= ELF64_R_SYM (info
);
902 #ifdef _bfd_int64_low
903 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
905 printf ("%8.8lx %8.8lx ", offset
, info
);
910 #ifdef _bfd_int64_low
912 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
913 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
914 _bfd_int64_high (offset
),
915 _bfd_int64_low (offset
),
916 _bfd_int64_high (info
),
917 _bfd_int64_low (info
));
920 ? "%16.16lx %16.16lx "
921 : "%12.12lx %12.12lx ",
926 switch (elf_header
.e_machine
)
934 rtype
= elf_m32r_reloc_type (type
);
939 rtype
= elf_i386_reloc_type (type
);
944 rtype
= elf_m68hc11_reloc_type (type
);
948 rtype
= elf_m68k_reloc_type (type
);
952 rtype
= elf_i960_reloc_type (type
);
957 rtype
= elf_avr_reloc_type (type
);
964 rtype
= elf_sparc_reloc_type (type
);
969 rtype
= v850_reloc_type (type
);
974 rtype
= elf_d10v_reloc_type (type
);
979 rtype
= elf_d30v_reloc_type (type
);
983 rtype
= elf_dlx_reloc_type (type
);
987 rtype
= elf_sh_reloc_type (type
);
991 case EM_CYGNUS_MN10300
:
992 rtype
= elf_mn10300_reloc_type (type
);
996 case EM_CYGNUS_MN10200
:
997 rtype
= elf_mn10200_reloc_type (type
);
1001 case EM_CYGNUS_FR30
:
1002 rtype
= elf_fr30_reloc_type (type
);
1006 rtype
= elf_frv_reloc_type (type
);
1010 rtype
= elf_mcore_reloc_type (type
);
1014 rtype
= elf_mmix_reloc_type (type
);
1019 rtype
= elf_msp430_reloc_type (type
);
1023 rtype
= elf_ppc_reloc_type (type
);
1027 rtype
= elf_ppc64_reloc_type (type
);
1031 case EM_MIPS_RS3_LE
:
1032 rtype
= elf_mips_reloc_type (type
);
1035 rtype2
= elf_mips_reloc_type (type2
);
1036 rtype3
= elf_mips_reloc_type (type3
);
1041 rtype
= elf_alpha_reloc_type (type
);
1045 rtype
= elf_arm_reloc_type (type
);
1049 rtype
= elf_arc_reloc_type (type
);
1053 rtype
= elf_hppa_reloc_type (type
);
1059 rtype
= elf_h8_reloc_type (type
);
1064 rtype
= elf_or32_reloc_type (type
);
1069 rtype
= elf_pj_reloc_type (type
);
1072 rtype
= elf_ia64_reloc_type (type
);
1076 rtype
= elf_cris_reloc_type (type
);
1080 rtype
= elf_i860_reloc_type (type
);
1084 rtype
= elf_x86_64_reloc_type (type
);
1088 rtype
= i370_reloc_type (type
);
1093 rtype
= elf_s390_reloc_type (type
);
1097 rtype
= elf_xstormy16_reloc_type (type
);
1101 rtype
= elf_crx_reloc_type (type
);
1105 rtype
= elf_vax_reloc_type (type
);
1110 rtype
= elf_ip2k_reloc_type (type
);
1114 rtype
= elf_iq2000_reloc_type (type
);
1119 rtype
= elf_xtensa_reloc_type (type
);
1123 rtype
= elf_m32c_reloc_type (type
);
1127 rtype
= elf_mt_reloc_type (type
);
1131 rtype
= elf_bfin_reloc_type (type
);
1137 #ifdef _bfd_int64_low
1138 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1140 printf (_("unrecognized: %-7lx"), type
);
1143 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1145 if (elf_header
.e_machine
== EM_ALPHA
1146 && streq (rtype
, "R_ALPHA_LITUSE")
1149 switch (rels
[i
].r_addend
)
1151 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1152 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1153 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1154 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1155 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1156 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1157 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1158 default: rtype
= NULL
;
1161 printf (" (%s)", rtype
);
1165 printf (_("<unknown addend: %lx>"),
1166 (unsigned long) rels
[i
].r_addend
);
1169 else if (symtab_index
)
1171 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1172 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1175 Elf_Internal_Sym
*psym
;
1177 psym
= symtab
+ symtab_index
;
1180 print_vma (psym
->st_value
, LONG_HEX
);
1181 printf (is_32bit_elf
? " " : " ");
1183 if (psym
->st_name
== 0)
1185 const char *sec_name
= "<null>";
1188 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1190 bfd_vma sec_index
= (bfd_vma
) -1;
1192 if (psym
->st_shndx
< SHN_LORESERVE
)
1193 sec_index
= psym
->st_shndx
;
1194 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1195 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1198 if (sec_index
!= (bfd_vma
) -1)
1199 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1200 else if (psym
->st_shndx
== SHN_ABS
)
1202 else if (psym
->st_shndx
== SHN_COMMON
)
1203 sec_name
= "COMMON";
1204 else if (elf_header
.e_machine
== EM_X86_64
1205 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1206 sec_name
= "LARGE_COMMON";
1207 else if (elf_header
.e_machine
== EM_IA_64
1208 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1209 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1210 sec_name
= "ANSI_COM";
1213 sprintf (name_buf
, "<section 0x%x>",
1214 (unsigned int) psym
->st_shndx
);
1215 sec_name
= name_buf
;
1218 print_symbol (22, sec_name
);
1220 else if (strtab
== NULL
)
1221 printf (_("<string table index: %3ld>"), psym
->st_name
);
1222 else if (psym
->st_name
>= strtablen
)
1223 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1225 print_symbol (22, strtab
+ psym
->st_name
);
1228 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1233 printf ("%*c", is_32bit_elf
?
1234 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1235 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1238 if (elf_header
.e_machine
== EM_SPARCV9
&& streq (rtype
, "R_SPARC_OLO10"))
1239 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1243 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1245 printf (" Type2: ");
1248 #ifdef _bfd_int64_low
1249 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1251 printf (_("unrecognized: %-7lx"), type2
);
1254 printf ("%-17.17s", rtype2
);
1256 printf ("\n Type3: ");
1259 #ifdef _bfd_int64_low
1260 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1262 printf (_("unrecognized: %-7lx"), type3
);
1265 printf ("%-17.17s", rtype3
);
1277 get_mips_dynamic_type (unsigned long type
)
1281 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1282 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1283 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1284 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1285 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1286 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1287 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1288 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1289 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1290 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1291 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1292 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1293 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1294 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1295 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1296 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1297 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1298 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1299 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1300 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1301 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1302 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1303 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1304 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1305 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1306 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1307 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1308 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1309 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1310 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1311 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1312 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1313 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1314 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1315 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1316 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1317 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1318 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1319 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1320 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1321 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1322 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1323 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1330 get_sparc64_dynamic_type (unsigned long type
)
1334 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1341 get_ppc_dynamic_type (unsigned long type
)
1345 case DT_PPC_GOT
: return "PPC_GOT";
1352 get_ppc64_dynamic_type (unsigned long type
)
1356 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1357 case DT_PPC64_OPD
: return "PPC64_OPD";
1358 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1365 get_parisc_dynamic_type (unsigned long type
)
1369 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1370 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1371 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1372 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1373 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1374 case DT_HP_PREINIT
: return "HP_PREINIT";
1375 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1376 case DT_HP_NEEDED
: return "HP_NEEDED";
1377 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1378 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1379 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1380 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1381 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1382 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1383 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1384 case DT_HP_FILTERED
: return "HP_FILTERED";
1385 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1386 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1387 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1388 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1389 case DT_PLT
: return "PLT";
1390 case DT_PLT_SIZE
: return "PLT_SIZE";
1391 case DT_DLT
: return "DLT";
1392 case DT_DLT_SIZE
: return "DLT_SIZE";
1399 get_ia64_dynamic_type (unsigned long type
)
1403 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1410 get_alpha_dynamic_type (unsigned long type
)
1414 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1421 get_dynamic_type (unsigned long type
)
1423 static char buff
[64];
1427 case DT_NULL
: return "NULL";
1428 case DT_NEEDED
: return "NEEDED";
1429 case DT_PLTRELSZ
: return "PLTRELSZ";
1430 case DT_PLTGOT
: return "PLTGOT";
1431 case DT_HASH
: return "HASH";
1432 case DT_STRTAB
: return "STRTAB";
1433 case DT_SYMTAB
: return "SYMTAB";
1434 case DT_RELA
: return "RELA";
1435 case DT_RELASZ
: return "RELASZ";
1436 case DT_RELAENT
: return "RELAENT";
1437 case DT_STRSZ
: return "STRSZ";
1438 case DT_SYMENT
: return "SYMENT";
1439 case DT_INIT
: return "INIT";
1440 case DT_FINI
: return "FINI";
1441 case DT_SONAME
: return "SONAME";
1442 case DT_RPATH
: return "RPATH";
1443 case DT_SYMBOLIC
: return "SYMBOLIC";
1444 case DT_REL
: return "REL";
1445 case DT_RELSZ
: return "RELSZ";
1446 case DT_RELENT
: return "RELENT";
1447 case DT_PLTREL
: return "PLTREL";
1448 case DT_DEBUG
: return "DEBUG";
1449 case DT_TEXTREL
: return "TEXTREL";
1450 case DT_JMPREL
: return "JMPREL";
1451 case DT_BIND_NOW
: return "BIND_NOW";
1452 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1453 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1454 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1455 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1456 case DT_RUNPATH
: return "RUNPATH";
1457 case DT_FLAGS
: return "FLAGS";
1459 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1460 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1462 case DT_CHECKSUM
: return "CHECKSUM";
1463 case DT_PLTPADSZ
: return "PLTPADSZ";
1464 case DT_MOVEENT
: return "MOVEENT";
1465 case DT_MOVESZ
: return "MOVESZ";
1466 case DT_FEATURE
: return "FEATURE";
1467 case DT_POSFLAG_1
: return "POSFLAG_1";
1468 case DT_SYMINSZ
: return "SYMINSZ";
1469 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1471 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1472 case DT_CONFIG
: return "CONFIG";
1473 case DT_DEPAUDIT
: return "DEPAUDIT";
1474 case DT_AUDIT
: return "AUDIT";
1475 case DT_PLTPAD
: return "PLTPAD";
1476 case DT_MOVETAB
: return "MOVETAB";
1477 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1479 case DT_VERSYM
: return "VERSYM";
1481 case DT_RELACOUNT
: return "RELACOUNT";
1482 case DT_RELCOUNT
: return "RELCOUNT";
1483 case DT_FLAGS_1
: return "FLAGS_1";
1484 case DT_VERDEF
: return "VERDEF";
1485 case DT_VERDEFNUM
: return "VERDEFNUM";
1486 case DT_VERNEED
: return "VERNEED";
1487 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1489 case DT_AUXILIARY
: return "AUXILIARY";
1490 case DT_USED
: return "USED";
1491 case DT_FILTER
: return "FILTER";
1493 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1494 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1495 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1496 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1497 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1500 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1504 switch (elf_header
.e_machine
)
1507 case EM_MIPS_RS3_LE
:
1508 result
= get_mips_dynamic_type (type
);
1511 result
= get_sparc64_dynamic_type (type
);
1514 result
= get_ppc_dynamic_type (type
);
1517 result
= get_ppc64_dynamic_type (type
);
1520 result
= get_ia64_dynamic_type (type
);
1523 result
= get_alpha_dynamic_type (type
);
1533 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1535 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1536 || (elf_header
.e_machine
== EM_PARISC
1537 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1541 switch (elf_header
.e_machine
)
1544 result
= get_parisc_dynamic_type (type
);
1554 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1558 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1565 get_file_type (unsigned e_type
)
1567 static char buff
[32];
1571 case ET_NONE
: return _("NONE (None)");
1572 case ET_REL
: return _("REL (Relocatable file)");
1573 case ET_EXEC
: return _("EXEC (Executable file)");
1574 case ET_DYN
: return _("DYN (Shared object file)");
1575 case ET_CORE
: return _("CORE (Core file)");
1578 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1579 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1580 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1581 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1583 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1589 get_machine_name (unsigned e_machine
)
1591 static char buff
[64]; /* XXX */
1595 case EM_NONE
: return _("None");
1596 case EM_M32
: return "WE32100";
1597 case EM_SPARC
: return "Sparc";
1598 case EM_386
: return "Intel 80386";
1599 case EM_68K
: return "MC68000";
1600 case EM_88K
: return "MC88000";
1601 case EM_486
: return "Intel 80486";
1602 case EM_860
: return "Intel 80860";
1603 case EM_MIPS
: return "MIPS R3000";
1604 case EM_S370
: return "IBM System/370";
1605 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1606 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1607 case EM_PARISC
: return "HPPA";
1608 case EM_PPC_OLD
: return "Power PC (old)";
1609 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1610 case EM_960
: return "Intel 90860";
1611 case EM_PPC
: return "PowerPC";
1612 case EM_PPC64
: return "PowerPC64";
1613 case EM_V800
: return "NEC V800";
1614 case EM_FR20
: return "Fujitsu FR20";
1615 case EM_RH32
: return "TRW RH32";
1616 case EM_MCORE
: return "MCORE";
1617 case EM_ARM
: return "ARM";
1618 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1619 case EM_SH
: return "Renesas / SuperH SH";
1620 case EM_SPARCV9
: return "Sparc v9";
1621 case EM_TRICORE
: return "Siemens Tricore";
1622 case EM_ARC
: return "ARC";
1623 case EM_H8_300
: return "Renesas H8/300";
1624 case EM_H8_300H
: return "Renesas H8/300H";
1625 case EM_H8S
: return "Renesas H8S";
1626 case EM_H8_500
: return "Renesas H8/500";
1627 case EM_IA_64
: return "Intel IA-64";
1628 case EM_MIPS_X
: return "Stanford MIPS-X";
1629 case EM_COLDFIRE
: return "Motorola Coldfire";
1630 case EM_68HC12
: return "Motorola M68HC12";
1631 case EM_ALPHA
: return "Alpha";
1632 case EM_CYGNUS_D10V
:
1633 case EM_D10V
: return "d10v";
1634 case EM_CYGNUS_D30V
:
1635 case EM_D30V
: return "d30v";
1636 case EM_CYGNUS_M32R
:
1637 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1638 case EM_CYGNUS_V850
:
1639 case EM_V850
: return "NEC v850";
1640 case EM_CYGNUS_MN10300
:
1641 case EM_MN10300
: return "mn10300";
1642 case EM_CYGNUS_MN10200
:
1643 case EM_MN10200
: return "mn10200";
1644 case EM_CYGNUS_FR30
:
1645 case EM_FR30
: return "Fujitsu FR30";
1646 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1648 case EM_PJ
: return "picoJava";
1649 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1650 case EM_PCP
: return "Siemens PCP";
1651 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1652 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1653 case EM_STARCORE
: return "Motorola Star*Core processor";
1654 case EM_ME16
: return "Toyota ME16 processor";
1655 case EM_ST100
: return "STMicroelectronics ST100 processor";
1656 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1657 case EM_FX66
: return "Siemens FX66 microcontroller";
1658 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1659 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1660 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1661 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1662 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1663 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1664 case EM_SVX
: return "Silicon Graphics SVx";
1665 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1666 case EM_VAX
: return "Digital VAX";
1668 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1669 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1670 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1671 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1672 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1673 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1674 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1675 case EM_PRISM
: return "Vitesse Prism";
1676 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1678 case EM_S390
: return "IBM S/390";
1679 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1681 case EM_OR32
: return "OpenRISC";
1682 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1683 case EM_DLX
: return "OpenDLX";
1685 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1686 case EM_IQ2000
: return "Vitesse IQ2000";
1688 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1689 case EM_M32C
: return "Renesas M32c";
1690 case EM_MT
: return "Morpho Techologies MT processor";
1691 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1693 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_machine
);
1699 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1704 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1705 e_flags
&= ~ EF_ARM_EABIMASK
;
1707 /* Handle "generic" ARM flags. */
1708 if (e_flags
& EF_ARM_RELEXEC
)
1710 strcat (buf
, ", relocatable executable");
1711 e_flags
&= ~ EF_ARM_RELEXEC
;
1714 if (e_flags
& EF_ARM_HASENTRY
)
1716 strcat (buf
, ", has entry point");
1717 e_flags
&= ~ EF_ARM_HASENTRY
;
1720 /* Now handle EABI specific flags. */
1724 strcat (buf
, ", <unrecognized EABI>");
1729 case EF_ARM_EABI_VER1
:
1730 strcat (buf
, ", Version1 EABI");
1735 /* Process flags one bit at a time. */
1736 flag
= e_flags
& - e_flags
;
1741 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1742 strcat (buf
, ", sorted symbol tables");
1752 case EF_ARM_EABI_VER2
:
1753 strcat (buf
, ", Version2 EABI");
1758 /* Process flags one bit at a time. */
1759 flag
= e_flags
& - e_flags
;
1764 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1765 strcat (buf
, ", sorted symbol tables");
1768 case EF_ARM_DYNSYMSUSESEGIDX
:
1769 strcat (buf
, ", dynamic symbols use segment index");
1772 case EF_ARM_MAPSYMSFIRST
:
1773 strcat (buf
, ", mapping symbols precede others");
1783 case EF_ARM_EABI_VER3
:
1784 strcat (buf
, ", Version3 EABI");
1787 case EF_ARM_EABI_VER4
:
1788 strcat (buf
, ", Version4 EABI");
1793 /* Process flags one bit at a time. */
1794 flag
= e_flags
& - e_flags
;
1800 strcat (buf
, ", BE8");
1804 strcat (buf
, ", LE8");
1814 case EF_ARM_EABI_UNKNOWN
:
1815 strcat (buf
, ", GNU EABI");
1820 /* Process flags one bit at a time. */
1821 flag
= e_flags
& - e_flags
;
1826 case EF_ARM_INTERWORK
:
1827 strcat (buf
, ", interworking enabled");
1830 case EF_ARM_APCS_26
:
1831 strcat (buf
, ", uses APCS/26");
1834 case EF_ARM_APCS_FLOAT
:
1835 strcat (buf
, ", uses APCS/float");
1839 strcat (buf
, ", position independent");
1843 strcat (buf
, ", 8 bit structure alignment");
1846 case EF_ARM_NEW_ABI
:
1847 strcat (buf
, ", uses new ABI");
1850 case EF_ARM_OLD_ABI
:
1851 strcat (buf
, ", uses old ABI");
1854 case EF_ARM_SOFT_FLOAT
:
1855 strcat (buf
, ", software FP");
1858 case EF_ARM_VFP_FLOAT
:
1859 strcat (buf
, ", VFP");
1862 case EF_ARM_MAVERICK_FLOAT
:
1863 strcat (buf
, ", Maverick FP");
1874 strcat (buf
,", <unknown>");
1878 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1880 static char buf
[1024];
1892 decode_ARM_machine_flags (e_flags
, buf
);
1896 switch (e_flags
& EF_FRV_CPU_MASK
)
1898 case EF_FRV_CPU_GENERIC
:
1902 strcat (buf
, ", fr???");
1905 case EF_FRV_CPU_FR300
:
1906 strcat (buf
, ", fr300");
1909 case EF_FRV_CPU_FR400
:
1910 strcat (buf
, ", fr400");
1912 case EF_FRV_CPU_FR405
:
1913 strcat (buf
, ", fr405");
1916 case EF_FRV_CPU_FR450
:
1917 strcat (buf
, ", fr450");
1920 case EF_FRV_CPU_FR500
:
1921 strcat (buf
, ", fr500");
1923 case EF_FRV_CPU_FR550
:
1924 strcat (buf
, ", fr550");
1927 case EF_FRV_CPU_SIMPLE
:
1928 strcat (buf
, ", simple");
1930 case EF_FRV_CPU_TOMCAT
:
1931 strcat (buf
, ", tomcat");
1937 if (e_flags
& EF_CPU32
)
1938 strcat (buf
, ", cpu32");
1939 if (e_flags
& EF_M68000
)
1940 strcat (buf
, ", m68000");
1944 if (e_flags
& EF_PPC_EMB
)
1945 strcat (buf
, ", emb");
1947 if (e_flags
& EF_PPC_RELOCATABLE
)
1948 strcat (buf
, ", relocatable");
1950 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1951 strcat (buf
, ", relocatable-lib");
1955 case EM_CYGNUS_V850
:
1956 switch (e_flags
& EF_V850_ARCH
)
1959 strcat (buf
, ", v850e1");
1962 strcat (buf
, ", v850e");
1965 strcat (buf
, ", v850");
1968 strcat (buf
, ", unknown v850 architecture variant");
1974 case EM_CYGNUS_M32R
:
1975 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1976 strcat (buf
, ", m32r");
1981 case EM_MIPS_RS3_LE
:
1982 if (e_flags
& EF_MIPS_NOREORDER
)
1983 strcat (buf
, ", noreorder");
1985 if (e_flags
& EF_MIPS_PIC
)
1986 strcat (buf
, ", pic");
1988 if (e_flags
& EF_MIPS_CPIC
)
1989 strcat (buf
, ", cpic");
1991 if (e_flags
& EF_MIPS_UCODE
)
1992 strcat (buf
, ", ugen_reserved");
1994 if (e_flags
& EF_MIPS_ABI2
)
1995 strcat (buf
, ", abi2");
1997 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
1998 strcat (buf
, ", odk first");
2000 if (e_flags
& EF_MIPS_32BITMODE
)
2001 strcat (buf
, ", 32bitmode");
2003 switch ((e_flags
& EF_MIPS_MACH
))
2005 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2006 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2007 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2008 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2009 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2010 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2011 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2012 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2013 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2014 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2016 /* We simply ignore the field in this case to avoid confusion:
2017 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2020 default: strcat (buf
, ", unknown CPU"); break;
2023 switch ((e_flags
& EF_MIPS_ABI
))
2025 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2026 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2027 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2028 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2030 /* We simply ignore the field in this case to avoid confusion:
2031 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2032 This means it is likely to be an o32 file, but not for
2035 default: strcat (buf
, ", unknown ABI"); break;
2038 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2039 strcat (buf
, ", mdmx");
2041 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2042 strcat (buf
, ", mips16");
2044 switch ((e_flags
& EF_MIPS_ARCH
))
2046 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2047 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2048 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2049 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2050 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2051 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2052 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2053 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2054 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2055 default: strcat (buf
, ", unknown ISA"); break;
2061 switch ((e_flags
& EF_SH_MACH_MASK
))
2063 case EF_SH1
: strcat (buf
, ", sh1"); break;
2064 case EF_SH2
: strcat (buf
, ", sh2"); break;
2065 case EF_SH3
: strcat (buf
, ", sh3"); break;
2066 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2067 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2068 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2069 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2070 case EF_SH4
: strcat (buf
, ", sh4"); break;
2071 case EF_SH5
: strcat (buf
, ", sh5"); break;
2072 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2073 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2074 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2075 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2076 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2077 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2078 default: strcat (buf
, ", unknown ISA"); break;
2084 if (e_flags
& EF_SPARC_32PLUS
)
2085 strcat (buf
, ", v8+");
2087 if (e_flags
& EF_SPARC_SUN_US1
)
2088 strcat (buf
, ", ultrasparcI");
2090 if (e_flags
& EF_SPARC_SUN_US3
)
2091 strcat (buf
, ", ultrasparcIII");
2093 if (e_flags
& EF_SPARC_HAL_R1
)
2094 strcat (buf
, ", halr1");
2096 if (e_flags
& EF_SPARC_LEDATA
)
2097 strcat (buf
, ", ledata");
2099 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2100 strcat (buf
, ", tso");
2102 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2103 strcat (buf
, ", pso");
2105 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2106 strcat (buf
, ", rmo");
2110 switch (e_flags
& EF_PARISC_ARCH
)
2112 case EFA_PARISC_1_0
:
2113 strcpy (buf
, ", PA-RISC 1.0");
2115 case EFA_PARISC_1_1
:
2116 strcpy (buf
, ", PA-RISC 1.1");
2118 case EFA_PARISC_2_0
:
2119 strcpy (buf
, ", PA-RISC 2.0");
2124 if (e_flags
& EF_PARISC_TRAPNIL
)
2125 strcat (buf
, ", trapnil");
2126 if (e_flags
& EF_PARISC_EXT
)
2127 strcat (buf
, ", ext");
2128 if (e_flags
& EF_PARISC_LSB
)
2129 strcat (buf
, ", lsb");
2130 if (e_flags
& EF_PARISC_WIDE
)
2131 strcat (buf
, ", wide");
2132 if (e_flags
& EF_PARISC_NO_KABP
)
2133 strcat (buf
, ", no kabp");
2134 if (e_flags
& EF_PARISC_LAZYSWAP
)
2135 strcat (buf
, ", lazyswap");
2140 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2141 strcat (buf
, ", new calling convention");
2143 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2144 strcat (buf
, ", gnu calling convention");
2148 if ((e_flags
& EF_IA_64_ABI64
))
2149 strcat (buf
, ", 64-bit");
2151 strcat (buf
, ", 32-bit");
2152 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2153 strcat (buf
, ", reduced fp model");
2154 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2155 strcat (buf
, ", no function descriptors, constant gp");
2156 else if ((e_flags
& EF_IA_64_CONS_GP
))
2157 strcat (buf
, ", constant gp");
2158 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2159 strcat (buf
, ", absolute");
2163 if ((e_flags
& EF_VAX_NONPIC
))
2164 strcat (buf
, ", non-PIC");
2165 if ((e_flags
& EF_VAX_DFLOAT
))
2166 strcat (buf
, ", D-Float");
2167 if ((e_flags
& EF_VAX_GFLOAT
))
2168 strcat (buf
, ", G-Float");
2177 get_osabi_name (unsigned int osabi
)
2179 static char buff
[32];
2183 case ELFOSABI_NONE
: return "UNIX - System V";
2184 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2185 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2186 case ELFOSABI_LINUX
: return "UNIX - Linux";
2187 case ELFOSABI_HURD
: return "GNU/Hurd";
2188 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2189 case ELFOSABI_AIX
: return "UNIX - AIX";
2190 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2191 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2192 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2193 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2194 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2195 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2196 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2197 case ELFOSABI_AROS
: return "Amiga Research OS";
2198 case ELFOSABI_STANDALONE
: return _("Standalone App");
2199 case ELFOSABI_ARM
: return "ARM";
2201 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2207 get_arm_segment_type (unsigned long type
)
2221 get_mips_segment_type (unsigned long type
)
2225 case PT_MIPS_REGINFO
:
2227 case PT_MIPS_RTPROC
:
2229 case PT_MIPS_OPTIONS
:
2239 get_parisc_segment_type (unsigned long type
)
2243 case PT_HP_TLS
: return "HP_TLS";
2244 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2245 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2246 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2247 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2248 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2249 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2250 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2251 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2252 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2253 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2254 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2255 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2256 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2257 case PT_HP_STACK
: return "HP_STACK";
2258 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2259 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2260 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2261 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2270 get_ia64_segment_type (unsigned long type
)
2274 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2275 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2276 case PT_HP_TLS
: return "HP_TLS";
2277 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2278 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2279 case PT_IA_64_HP_STACK
: return "HP_STACK";
2288 get_segment_type (unsigned long p_type
)
2290 static char buff
[32];
2294 case PT_NULL
: return "NULL";
2295 case PT_LOAD
: return "LOAD";
2296 case PT_DYNAMIC
: return "DYNAMIC";
2297 case PT_INTERP
: return "INTERP";
2298 case PT_NOTE
: return "NOTE";
2299 case PT_SHLIB
: return "SHLIB";
2300 case PT_PHDR
: return "PHDR";
2301 case PT_TLS
: return "TLS";
2303 case PT_GNU_EH_FRAME
:
2304 return "GNU_EH_FRAME";
2305 case PT_GNU_STACK
: return "GNU_STACK";
2306 case PT_GNU_RELRO
: return "GNU_RELRO";
2309 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2313 switch (elf_header
.e_machine
)
2316 result
= get_arm_segment_type (p_type
);
2319 case EM_MIPS_RS3_LE
:
2320 result
= get_mips_segment_type (p_type
);
2323 result
= get_parisc_segment_type (p_type
);
2326 result
= get_ia64_segment_type (p_type
);
2336 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2338 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2342 switch (elf_header
.e_machine
)
2345 result
= get_parisc_segment_type (p_type
);
2348 result
= get_ia64_segment_type (p_type
);
2358 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2361 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2368 get_mips_section_type_name (unsigned int sh_type
)
2372 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2373 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2374 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2375 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2376 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2377 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2378 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2379 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2380 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2381 case SHT_MIPS_RELD
: return "MIPS_RELD";
2382 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2383 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2384 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2385 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2386 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2387 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2388 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2389 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2390 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2391 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2392 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2393 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2394 case SHT_MIPS_LINE
: return "MIPS_LINE";
2395 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2396 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2397 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2398 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2399 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2400 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2401 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2402 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2403 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2404 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2405 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2406 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2407 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2408 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2409 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2410 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2418 get_parisc_section_type_name (unsigned int sh_type
)
2422 case SHT_PARISC_EXT
: return "PARISC_EXT";
2423 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2424 case SHT_PARISC_DOC
: return "PARISC_DOC";
2425 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2426 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2427 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2428 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2436 get_ia64_section_type_name (unsigned int sh_type
)
2438 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2439 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2440 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2444 case SHT_IA_64_EXT
: return "IA_64_EXT";
2445 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2446 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2454 get_x86_64_section_type_name (unsigned int sh_type
)
2458 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2466 get_arm_section_type_name (unsigned int sh_type
)
2472 case SHT_ARM_PREEMPTMAP
:
2473 return "ARM_PREEMPTMAP";
2474 case SHT_ARM_ATTRIBUTES
:
2475 return "ARM_ATTRIBUTES";
2483 get_section_type_name (unsigned int sh_type
)
2485 static char buff
[32];
2489 case SHT_NULL
: return "NULL";
2490 case SHT_PROGBITS
: return "PROGBITS";
2491 case SHT_SYMTAB
: return "SYMTAB";
2492 case SHT_STRTAB
: return "STRTAB";
2493 case SHT_RELA
: return "RELA";
2494 case SHT_HASH
: return "HASH";
2495 case SHT_DYNAMIC
: return "DYNAMIC";
2496 case SHT_NOTE
: return "NOTE";
2497 case SHT_NOBITS
: return "NOBITS";
2498 case SHT_REL
: return "REL";
2499 case SHT_SHLIB
: return "SHLIB";
2500 case SHT_DYNSYM
: return "DYNSYM";
2501 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2502 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2503 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2504 case SHT_GROUP
: return "GROUP";
2505 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2506 case SHT_GNU_verdef
: return "VERDEF";
2507 case SHT_GNU_verneed
: return "VERNEED";
2508 case SHT_GNU_versym
: return "VERSYM";
2509 case 0x6ffffff0: return "VERSYM";
2510 case 0x6ffffffc: return "VERDEF";
2511 case 0x7ffffffd: return "AUXILIARY";
2512 case 0x7fffffff: return "FILTER";
2513 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2516 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2520 switch (elf_header
.e_machine
)
2523 case EM_MIPS_RS3_LE
:
2524 result
= get_mips_section_type_name (sh_type
);
2527 result
= get_parisc_section_type_name (sh_type
);
2530 result
= get_ia64_section_type_name (sh_type
);
2533 result
= get_x86_64_section_type_name (sh_type
);
2536 result
= get_arm_section_type_name (sh_type
);
2546 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2548 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2549 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2550 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2551 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2553 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2559 #define OPTION_DEBUG_DUMP 512
2561 static struct option options
[] =
2563 {"all", no_argument
, 0, 'a'},
2564 {"file-header", no_argument
, 0, 'h'},
2565 {"program-headers", no_argument
, 0, 'l'},
2566 {"headers", no_argument
, 0, 'e'},
2567 {"histogram", no_argument
, 0, 'I'},
2568 {"segments", no_argument
, 0, 'l'},
2569 {"sections", no_argument
, 0, 'S'},
2570 {"section-headers", no_argument
, 0, 'S'},
2571 {"section-groups", no_argument
, 0, 'g'},
2572 {"section-details", no_argument
, 0, 't'},
2573 {"full-section-name",no_argument
, 0, 'N'},
2574 {"symbols", no_argument
, 0, 's'},
2575 {"syms", no_argument
, 0, 's'},
2576 {"relocs", no_argument
, 0, 'r'},
2577 {"notes", no_argument
, 0, 'n'},
2578 {"dynamic", no_argument
, 0, 'd'},
2579 {"arch-specific", no_argument
, 0, 'A'},
2580 {"version-info", no_argument
, 0, 'V'},
2581 {"use-dynamic", no_argument
, 0, 'D'},
2582 {"hex-dump", required_argument
, 0, 'x'},
2583 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2584 {"unwind", no_argument
, 0, 'u'},
2585 #ifdef SUPPORT_DISASSEMBLY
2586 {"instruction-dump", required_argument
, 0, 'i'},
2589 {"version", no_argument
, 0, 'v'},
2590 {"wide", no_argument
, 0, 'W'},
2591 {"help", no_argument
, 0, 'H'},
2592 {0, no_argument
, 0, 0}
2598 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2599 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2600 fprintf (stdout
, _(" Options are:\n\
2601 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2602 -h --file-header Display the ELF file header\n\
2603 -l --program-headers Display the program headers\n\
2604 --segments An alias for --program-headers\n\
2605 -S --section-headers Display the sections' header\n\
2606 --sections An alias for --section-headers\n\
2607 -g --section-groups Display the section groups\n\
2608 -t --section-details Display the section details\n\
2609 -e --headers Equivalent to: -h -l -S\n\
2610 -s --syms Display the symbol table\n\
2611 --symbols An alias for --syms\n\
2612 -n --notes Display the core notes (if present)\n\
2613 -r --relocs Display the relocations (if present)\n\
2614 -u --unwind Display the unwind info (if present)\n\
2615 -d --dynamic Display the dynamic section (if present)\n\
2616 -V --version-info Display the version sections (if present)\n\
2617 -A --arch-specific Display architecture specific information (if any).\n\
2618 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2619 -x --hex-dump=<number> Dump the contents of section <number>\n\
2620 -w[liaprmfFsoR] or\n\
2621 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2622 Display the contents of DWARF2 debug sections\n"));
2623 #ifdef SUPPORT_DISASSEMBLY
2624 fprintf (stdout
, _("\
2625 -i --instruction-dump=<number>\n\
2626 Disassemble the contents of section <number>\n"));
2628 fprintf (stdout
, _("\
2629 -I --histogram Display histogram of bucket list lengths\n\
2630 -W --wide Allow output width to exceed 80 characters\n\
2631 @<file> Read options from <file>\n\
2632 -H --help Display this information\n\
2633 -v --version Display the version number of readelf\n"));
2634 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2639 /* Record the fact that the user wants the contents of section number
2640 SECTION to be displayed using the method(s) encoded as flags bits
2641 in TYPE. Note, TYPE can be zero if we are creating the array for
2645 request_dump (unsigned int section
, int type
)
2647 if (section
>= num_dump_sects
)
2649 char *new_dump_sects
;
2651 new_dump_sects
= calloc (section
+ 1, 1);
2653 if (new_dump_sects
== NULL
)
2654 error (_("Out of memory allocating dump request table."));
2657 /* Copy current flag settings. */
2658 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2662 dump_sects
= new_dump_sects
;
2663 num_dump_sects
= section
+ 1;
2668 dump_sects
[section
] |= type
;
2673 /* Request a dump by section name. */
2676 request_dump_byname (const char *section
, int type
)
2678 struct dump_list_entry
*new_request
;
2680 new_request
= malloc (sizeof (struct dump_list_entry
));
2682 error (_("Out of memory allocating dump request table."));
2684 new_request
->name
= strdup (section
);
2685 if (!new_request
->name
)
2686 error (_("Out of memory allocating dump request table."));
2688 new_request
->type
= type
;
2690 new_request
->next
= dump_sects_byname
;
2691 dump_sects_byname
= new_request
;
2695 parse_args (int argc
, char **argv
)
2702 while ((c
= getopt_long
2703 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWH", options
, NULL
)) != EOF
)
2724 do_section_groups
++;
2732 do_section_groups
++;
2737 do_section_details
++;
2779 section
= strtoul (optarg
, & cp
, 0);
2780 if (! *cp
&& section
>= 0)
2781 request_dump (section
, HEX_DUMP
);
2783 request_dump_byname (optarg
, HEX_DUMP
);
2791 unsigned int index
= 0;
2795 while (optarg
[index
])
2796 switch (optarg
[index
++])
2805 do_debug_abbrevs
= 1;
2815 do_debug_pubnames
= 1;
2819 do_debug_aranges
= 1;
2823 do_debug_ranges
= 1;
2827 do_debug_frames_interp
= 1;
2829 do_debug_frames
= 1;
2834 do_debug_macinfo
= 1;
2848 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2853 case OPTION_DEBUG_DUMP
:
2861 const char * option
;
2864 debug_dump_long_opts
;
2866 debug_dump_long_opts opts_table
[] =
2868 /* Please keep this table alpha- sorted. */
2869 { "Ranges", & do_debug_ranges
},
2870 { "abbrev", & do_debug_abbrevs
},
2871 { "aranges", & do_debug_aranges
},
2872 { "frames", & do_debug_frames
},
2873 { "frames-interp", & do_debug_frames_interp
},
2874 { "info", & do_debug_info
},
2875 { "line", & do_debug_lines
},
2876 { "loc", & do_debug_loc
},
2877 { "macro", & do_debug_macinfo
},
2878 { "pubnames", & do_debug_pubnames
},
2879 /* This entry is for compatability
2880 with earlier versions of readelf. */
2881 { "ranges", & do_debug_aranges
},
2882 { "str", & do_debug_str
},
2893 debug_dump_long_opts
* entry
;
2895 for (entry
= opts_table
; entry
->option
; entry
++)
2897 size_t len
= strlen (entry
->option
);
2899 if (strneq (p
, entry
->option
, len
)
2900 && (p
[len
] == ',' || p
[len
] == '\0'))
2902 * entry
->variable
= 1;
2904 /* The --debug-dump=frames-interp option also
2905 enables the --debug-dump=frames option. */
2906 if (do_debug_frames_interp
)
2907 do_debug_frames
= 1;
2914 if (entry
->option
== NULL
)
2916 warn (_("Unrecognized debug option '%s'\n"), p
);
2917 p
= strchr (p
, ',');
2927 #ifdef SUPPORT_DISASSEMBLY
2930 section
= strtoul (optarg
, & cp
, 0);
2931 if (! *cp
&& section
>= 0)
2933 request_dump (section
, DISASS_DUMP
);
2939 print_version (program_name
);
2948 #ifdef SUPPORT_DISASSEMBLY
2951 /* xgettext:c-format */
2952 error (_("Invalid option '-%c'\n"), c
);
2959 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2960 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2961 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
2962 && !do_section_groups
)
2966 warn (_("Nothing to do.\n"));
2972 get_elf_class (unsigned int elf_class
)
2974 static char buff
[32];
2978 case ELFCLASSNONE
: return _("none");
2979 case ELFCLASS32
: return "ELF32";
2980 case ELFCLASS64
: return "ELF64";
2982 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
2988 get_data_encoding (unsigned int encoding
)
2990 static char buff
[32];
2994 case ELFDATANONE
: return _("none");
2995 case ELFDATA2LSB
: return _("2's complement, little endian");
2996 case ELFDATA2MSB
: return _("2's complement, big endian");
2998 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3003 /* Decode the data held in 'elf_header'. */
3006 process_file_header (void)
3008 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3009 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3010 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3011 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3014 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3022 printf (_("ELF Header:\n"));
3023 printf (_(" Magic: "));
3024 for (i
= 0; i
< EI_NIDENT
; i
++)
3025 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3027 printf (_(" Class: %s\n"),
3028 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3029 printf (_(" Data: %s\n"),
3030 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3031 printf (_(" Version: %d %s\n"),
3032 elf_header
.e_ident
[EI_VERSION
],
3033 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3035 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3038 printf (_(" OS/ABI: %s\n"),
3039 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3040 printf (_(" ABI Version: %d\n"),
3041 elf_header
.e_ident
[EI_ABIVERSION
]);
3042 printf (_(" Type: %s\n"),
3043 get_file_type (elf_header
.e_type
));
3044 printf (_(" Machine: %s\n"),
3045 get_machine_name (elf_header
.e_machine
));
3046 printf (_(" Version: 0x%lx\n"),
3047 (unsigned long) elf_header
.e_version
);
3049 printf (_(" Entry point address: "));
3050 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3051 printf (_("\n Start of program headers: "));
3052 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3053 printf (_(" (bytes into file)\n Start of section headers: "));
3054 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3055 printf (_(" (bytes into file)\n"));
3057 printf (_(" Flags: 0x%lx%s\n"),
3058 (unsigned long) elf_header
.e_flags
,
3059 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3060 printf (_(" Size of this header: %ld (bytes)\n"),
3061 (long) elf_header
.e_ehsize
);
3062 printf (_(" Size of program headers: %ld (bytes)\n"),
3063 (long) elf_header
.e_phentsize
);
3064 printf (_(" Number of program headers: %ld\n"),
3065 (long) elf_header
.e_phnum
);
3066 printf (_(" Size of section headers: %ld (bytes)\n"),
3067 (long) elf_header
.e_shentsize
);
3068 printf (_(" Number of section headers: %ld"),
3069 (long) elf_header
.e_shnum
);
3070 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3071 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3072 putc ('\n', stdout
);
3073 printf (_(" Section header string table index: %ld"),
3074 (long) elf_header
.e_shstrndx
);
3075 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3076 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3077 putc ('\n', stdout
);
3080 if (section_headers
!= NULL
)
3082 if (elf_header
.e_shnum
== 0)
3083 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3084 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3085 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3086 free (section_headers
);
3087 section_headers
= NULL
;
3095 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3097 Elf32_External_Phdr
*phdrs
;
3098 Elf32_External_Phdr
*external
;
3099 Elf_Internal_Phdr
*internal
;
3102 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3103 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3104 _("program headers"));
3108 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3109 i
< elf_header
.e_phnum
;
3110 i
++, internal
++, external
++)
3112 internal
->p_type
= BYTE_GET (external
->p_type
);
3113 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3114 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3115 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3116 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3117 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3118 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3119 internal
->p_align
= BYTE_GET (external
->p_align
);
3128 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3130 Elf64_External_Phdr
*phdrs
;
3131 Elf64_External_Phdr
*external
;
3132 Elf_Internal_Phdr
*internal
;
3135 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3136 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3137 _("program headers"));
3141 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3142 i
< elf_header
.e_phnum
;
3143 i
++, internal
++, external
++)
3145 internal
->p_type
= BYTE_GET (external
->p_type
);
3146 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3147 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3148 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3149 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3150 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3151 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3152 internal
->p_align
= BYTE_GET (external
->p_align
);
3160 /* Returns 1 if the program headers were read into `program_headers'. */
3163 get_program_headers (FILE *file
)
3165 Elf_Internal_Phdr
*phdrs
;
3167 /* Check cache of prior read. */
3168 if (program_headers
!= NULL
)
3171 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3175 error (_("Out of memory\n"));
3180 ? get_32bit_program_headers (file
, phdrs
)
3181 : get_64bit_program_headers (file
, phdrs
))
3183 program_headers
= phdrs
;
3191 /* Returns 1 if the program headers were loaded. */
3194 process_program_headers (FILE *file
)
3196 Elf_Internal_Phdr
*segment
;
3199 if (elf_header
.e_phnum
== 0)
3202 printf (_("\nThere are no program headers in this file.\n"));
3206 if (do_segments
&& !do_header
)
3208 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3209 printf (_("Entry point "));
3210 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3211 printf (_("\nThere are %d program headers, starting at offset "),
3212 elf_header
.e_phnum
);
3213 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3217 if (! get_program_headers (file
))
3222 if (elf_header
.e_phnum
> 1)
3223 printf (_("\nProgram Headers:\n"));
3225 printf (_("\nProgram Headers:\n"));
3229 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3232 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3236 (_(" Type Offset VirtAddr PhysAddr\n"));
3238 (_(" FileSiz MemSiz Flags Align\n"));
3245 for (i
= 0, segment
= program_headers
;
3246 i
< elf_header
.e_phnum
;
3251 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3255 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3256 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3257 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3258 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3259 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3261 (segment
->p_flags
& PF_R
? 'R' : ' '),
3262 (segment
->p_flags
& PF_W
? 'W' : ' '),
3263 (segment
->p_flags
& PF_X
? 'E' : ' '));
3264 printf ("%#lx", (unsigned long) segment
->p_align
);
3268 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3269 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3272 print_vma (segment
->p_offset
, FULL_HEX
);
3276 print_vma (segment
->p_vaddr
, FULL_HEX
);
3278 print_vma (segment
->p_paddr
, FULL_HEX
);
3281 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3282 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3285 print_vma (segment
->p_filesz
, FULL_HEX
);
3289 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3290 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3293 print_vma (segment
->p_offset
, FULL_HEX
);
3297 (segment
->p_flags
& PF_R
? 'R' : ' '),
3298 (segment
->p_flags
& PF_W
? 'W' : ' '),
3299 (segment
->p_flags
& PF_X
? 'E' : ' '));
3301 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3302 printf ("%#lx", (unsigned long) segment
->p_align
);
3305 print_vma (segment
->p_align
, PREFIX_HEX
);
3310 print_vma (segment
->p_offset
, FULL_HEX
);
3312 print_vma (segment
->p_vaddr
, FULL_HEX
);
3314 print_vma (segment
->p_paddr
, FULL_HEX
);
3316 print_vma (segment
->p_filesz
, FULL_HEX
);
3318 print_vma (segment
->p_memsz
, FULL_HEX
);
3320 (segment
->p_flags
& PF_R
? 'R' : ' '),
3321 (segment
->p_flags
& PF_W
? 'W' : ' '),
3322 (segment
->p_flags
& PF_X
? 'E' : ' '));
3323 print_vma (segment
->p_align
, HEX
);
3327 switch (segment
->p_type
)
3331 error (_("more than one dynamic segment\n"));
3333 /* Try to locate the .dynamic section. If there is
3334 a section header table, we can easily locate it. */
3335 if (section_headers
!= NULL
)
3337 Elf_Internal_Shdr
*sec
;
3339 sec
= find_section (".dynamic");
3340 if (sec
== NULL
|| sec
->sh_size
== 0)
3342 error (_("no .dynamic section in the dynamic segment"));
3346 dynamic_addr
= sec
->sh_offset
;
3347 dynamic_size
= sec
->sh_size
;
3349 if (dynamic_addr
< segment
->p_offset
3350 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3351 warn (_("the .dynamic section is not contained within the dynamic segment"));
3352 else if (dynamic_addr
> segment
->p_offset
)
3353 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3357 /* Otherwise, we can only assume that the .dynamic
3358 section is the first section in the DYNAMIC segment. */
3359 dynamic_addr
= segment
->p_offset
;
3360 dynamic_size
= segment
->p_filesz
;
3365 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3367 error (_("Unable to find program interpreter name\n"));
3370 program_interpreter
[0] = 0;
3371 fscanf (file
, "%63s", program_interpreter
);
3374 printf (_("\n [Requesting program interpreter: %s]"),
3375 program_interpreter
);
3381 putc ('\n', stdout
);
3384 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3386 printf (_("\n Section to Segment mapping:\n"));
3387 printf (_(" Segment Sections...\n"));
3389 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3392 Elf_Internal_Shdr
*section
;
3394 segment
= program_headers
+ i
;
3395 section
= section_headers
;
3397 printf (" %2.2d ", i
);
3399 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3401 if (section
->sh_size
> 0
3402 /* Compare allocated sections by VMA, unallocated
3403 sections by file offset. */
3404 && (section
->sh_flags
& SHF_ALLOC
3405 ? (section
->sh_addr
>= segment
->p_vaddr
3406 && section
->sh_addr
+ section
->sh_size
3407 <= segment
->p_vaddr
+ segment
->p_memsz
)
3408 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3409 && (section
->sh_offset
+ section
->sh_size
3410 <= segment
->p_offset
+ segment
->p_filesz
)))
3411 /* .tbss is special. It doesn't contribute memory space
3412 to normal segments. */
3413 && (!((section
->sh_flags
& SHF_TLS
) != 0
3414 && section
->sh_type
== SHT_NOBITS
)
3415 || segment
->p_type
== PT_TLS
))
3416 printf ("%s ", SECTION_NAME (section
));
3427 /* Find the file offset corresponding to VMA by using the program headers. */
3430 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3432 Elf_Internal_Phdr
*seg
;
3434 if (! get_program_headers (file
))
3436 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3440 for (seg
= program_headers
;
3441 seg
< program_headers
+ elf_header
.e_phnum
;
3444 if (seg
->p_type
!= PT_LOAD
)
3447 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3448 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3449 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3452 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3459 get_32bit_section_headers (FILE *file
, unsigned int num
)
3461 Elf32_External_Shdr
*shdrs
;
3462 Elf_Internal_Shdr
*internal
;
3465 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3466 elf_header
.e_shentsize
, num
, _("section headers"));
3470 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3472 if (section_headers
== NULL
)
3474 error (_("Out of memory\n"));
3478 for (i
= 0, internal
= section_headers
;
3482 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3483 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3484 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3485 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3486 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3487 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3488 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3489 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3490 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3491 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3500 get_64bit_section_headers (FILE *file
, unsigned int num
)
3502 Elf64_External_Shdr
*shdrs
;
3503 Elf_Internal_Shdr
*internal
;
3506 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3507 elf_header
.e_shentsize
, num
, _("section headers"));
3511 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3513 if (section_headers
== NULL
)
3515 error (_("Out of memory\n"));
3519 for (i
= 0, internal
= section_headers
;
3523 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3524 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3525 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3526 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3527 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3528 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3529 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3530 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3531 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3532 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3540 static Elf_Internal_Sym
*
3541 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3543 unsigned long number
;
3544 Elf32_External_Sym
*esyms
;
3545 Elf_External_Sym_Shndx
*shndx
;
3546 Elf_Internal_Sym
*isyms
;
3547 Elf_Internal_Sym
*psym
;
3550 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3556 if (symtab_shndx_hdr
!= NULL
3557 && (symtab_shndx_hdr
->sh_link
3558 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3560 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3561 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3569 number
= section
->sh_size
/ section
->sh_entsize
;
3570 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3574 error (_("Out of memory\n"));
3581 for (j
= 0, psym
= isyms
;
3585 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3586 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3587 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3588 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3589 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3591 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3592 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3593 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3603 static Elf_Internal_Sym
*
3604 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3606 unsigned long number
;
3607 Elf64_External_Sym
*esyms
;
3608 Elf_External_Sym_Shndx
*shndx
;
3609 Elf_Internal_Sym
*isyms
;
3610 Elf_Internal_Sym
*psym
;
3613 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3619 if (symtab_shndx_hdr
!= NULL
3620 && (symtab_shndx_hdr
->sh_link
3621 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3623 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3624 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3632 number
= section
->sh_size
/ section
->sh_entsize
;
3633 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3637 error (_("Out of memory\n"));
3644 for (j
= 0, psym
= isyms
;
3648 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3649 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3650 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3651 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3652 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3654 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3655 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3656 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3667 get_elf_section_flags (bfd_vma sh_flags
)
3669 static char buff
[1024];
3671 int field_size
= is_32bit_elf
? 8 : 16;
3672 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3673 bfd_vma os_flags
= 0;
3674 bfd_vma proc_flags
= 0;
3675 bfd_vma unknown_flags
= 0;
3689 { "LINK ORDER", 10 },
3690 { "OS NONCONF", 10 },
3695 if (do_section_details
)
3697 sprintf (buff
, "[%*.*lx]: ",
3698 field_size
, field_size
, (unsigned long) sh_flags
);
3699 p
+= field_size
+ 4;
3706 flag
= sh_flags
& - sh_flags
;
3709 if (do_section_details
)
3713 case SHF_WRITE
: index
= 0; break;
3714 case SHF_ALLOC
: index
= 1; break;
3715 case SHF_EXECINSTR
: index
= 2; break;
3716 case SHF_MERGE
: index
= 3; break;
3717 case SHF_STRINGS
: index
= 4; break;
3718 case SHF_INFO_LINK
: index
= 5; break;
3719 case SHF_LINK_ORDER
: index
= 6; break;
3720 case SHF_OS_NONCONFORMING
: index
= 7; break;
3721 case SHF_GROUP
: index
= 8; break;
3722 case SHF_TLS
: index
= 9; break;
3731 if (p
!= buff
+ field_size
+ 4)
3733 if (size
< (10 + 2))
3740 size
-= flags
[index
].len
;
3741 p
= stpcpy (p
, flags
[index
].str
);
3743 else if (flag
& SHF_MASKOS
)
3745 else if (flag
& SHF_MASKPROC
)
3748 unknown_flags
|= flag
;
3754 case SHF_WRITE
: *p
= 'W'; break;
3755 case SHF_ALLOC
: *p
= 'A'; break;
3756 case SHF_EXECINSTR
: *p
= 'X'; break;
3757 case SHF_MERGE
: *p
= 'M'; break;
3758 case SHF_STRINGS
: *p
= 'S'; break;
3759 case SHF_INFO_LINK
: *p
= 'I'; break;
3760 case SHF_LINK_ORDER
: *p
= 'L'; break;
3761 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3762 case SHF_GROUP
: *p
= 'G'; break;
3763 case SHF_TLS
: *p
= 'T'; break;
3766 if (elf_header
.e_machine
== EM_X86_64
3767 && flag
== SHF_X86_64_LARGE
)
3769 else if (flag
& SHF_MASKOS
)
3772 sh_flags
&= ~ SHF_MASKOS
;
3774 else if (flag
& SHF_MASKPROC
)
3777 sh_flags
&= ~ SHF_MASKPROC
;
3787 if (do_section_details
)
3791 size
-= 5 + field_size
;
3792 if (p
!= buff
+ field_size
+ 4)
3800 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3801 (unsigned long) os_flags
);
3802 p
+= 5 + field_size
;
3806 size
-= 7 + field_size
;
3807 if (p
!= buff
+ field_size
+ 4)
3815 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
3816 (unsigned long) proc_flags
);
3817 p
+= 7 + field_size
;
3821 size
-= 10 + field_size
;
3822 if (p
!= buff
+ field_size
+ 4)
3830 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
3831 (unsigned long) unknown_flags
);
3832 p
+= 10 + field_size
;
3841 process_section_headers (FILE *file
)
3843 Elf_Internal_Shdr
*section
;
3846 section_headers
= NULL
;
3848 if (elf_header
.e_shnum
== 0)
3851 printf (_("\nThere are no sections in this file.\n"));
3856 if (do_sections
&& !do_header
)
3857 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3858 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3862 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3865 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3868 /* Read in the string table, so that we have names to display. */
3869 if (SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
3871 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3873 if (section
->sh_size
!= 0)
3875 string_table
= get_data (NULL
, file
, section
->sh_offset
,
3876 1, section
->sh_size
, _("string table"));
3878 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
3882 /* Scan the sections for the dynamic symbol table
3883 and dynamic string table and debug sections. */
3884 dynamic_symbols
= NULL
;
3885 dynamic_strings
= NULL
;
3886 dynamic_syminfo
= NULL
;
3887 symtab_shndx_hdr
= NULL
;
3889 eh_addr_size
= is_32bit_elf
? 4 : 8;
3890 switch (elf_header
.e_machine
)
3893 case EM_MIPS_RS3_LE
:
3894 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
3895 FDE addresses. However, the ABI also has a semi-official ILP32
3896 variant for which the normal FDE address size rules apply.
3898 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
3899 section, where XX is the size of longs in bits. Unfortunately,
3900 earlier compilers provided no way of distinguishing ILP32 objects
3901 from LP64 objects, so if there's any doubt, we should assume that
3902 the official LP64 form is being used. */
3903 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
3904 && find_section (".gcc_compiled_long32") == NULL
)
3909 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
3912 size_t expected_entsize \
3913 = is_32bit_elf ? size32 : size64; \
3914 if (section->sh_entsize != expected_entsize) \
3915 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
3916 i, (unsigned long int) section->sh_entsize, \
3917 (unsigned long int) expected_entsize); \
3918 section->sh_entsize = expected_entsize; \
3921 #define CHECK_ENTSIZE(section, i, type) \
3922 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
3923 sizeof (Elf64_External_##type))
3925 for (i
= 0, section
= section_headers
;
3926 i
< elf_header
.e_shnum
;
3929 char *name
= SECTION_NAME (section
);
3931 if (section
->sh_type
== SHT_DYNSYM
)
3933 if (dynamic_symbols
!= NULL
)
3935 error (_("File contains multiple dynamic symbol tables\n"));
3939 CHECK_ENTSIZE (section
, i
, Sym
);
3940 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3941 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3943 else if (section
->sh_type
== SHT_STRTAB
3944 && streq (name
, ".dynstr"))
3946 if (dynamic_strings
!= NULL
)
3948 error (_("File contains multiple dynamic string tables\n"));
3952 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
3953 1, section
->sh_size
, _("dynamic strings"));
3954 dynamic_strings_length
= section
->sh_size
;
3956 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3958 if (symtab_shndx_hdr
!= NULL
)
3960 error (_("File contains multiple symtab shndx tables\n"));
3963 symtab_shndx_hdr
= section
;
3965 else if (section
->sh_type
== SHT_SYMTAB
)
3966 CHECK_ENTSIZE (section
, i
, Sym
);
3967 else if (section
->sh_type
== SHT_GROUP
)
3968 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
3969 else if (section
->sh_type
== SHT_REL
)
3970 CHECK_ENTSIZE (section
, i
, Rel
);
3971 else if (section
->sh_type
== SHT_RELA
)
3972 CHECK_ENTSIZE (section
, i
, Rela
);
3973 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3974 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3975 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3976 || do_debug_loc
|| do_debug_ranges
)
3977 && strneq (name
, ".debug_", 7))
3982 || (do_debug_info
&& streq (name
, "info"))
3983 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
3984 || (do_debug_lines
&& streq (name
, "line"))
3985 || (do_debug_pubnames
&& streq (name
, "pubnames"))
3986 || (do_debug_aranges
&& streq (name
, "aranges"))
3987 || (do_debug_ranges
&& streq (name
, "ranges"))
3988 || (do_debug_frames
&& streq (name
, "frame"))
3989 || (do_debug_macinfo
&& streq (name
, "macinfo"))
3990 || (do_debug_str
&& streq (name
, "str"))
3991 || (do_debug_loc
&& streq (name
, "loc"))
3993 request_dump (i
, DEBUG_DUMP
);
3995 /* linkonce section to be combined with .debug_info at link time. */
3996 else if ((do_debugging
|| do_debug_info
)
3997 && strneq (name
, ".gnu.linkonce.wi.", 17))
3998 request_dump (i
, DEBUG_DUMP
);
3999 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4000 request_dump (i
, DEBUG_DUMP
);
4006 if (elf_header
.e_shnum
> 1)
4007 printf (_("\nSection Headers:\n"));
4009 printf (_("\nSection Header:\n"));
4013 if (do_section_details
)
4015 printf (_(" [Nr] Name\n"));
4016 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4020 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4024 if (do_section_details
)
4026 printf (_(" [Nr] Name\n"));
4027 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4031 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4035 if (do_section_details
)
4037 printf (_(" [Nr] Name\n"));
4038 printf (_(" Type Address Offset Link\n"));
4039 printf (_(" Size EntSize Info Align\n"));
4043 printf (_(" [Nr] Name Type Address Offset\n"));
4044 printf (_(" Size EntSize Flags Link Info Align\n"));
4048 if (do_section_details
)
4049 printf (_(" Flags\n"));
4051 for (i
= 0, section
= section_headers
;
4052 i
< elf_header
.e_shnum
;
4055 if (do_section_details
)
4057 printf (" [%2u] %s\n",
4058 SECTION_HEADER_NUM (i
),
4059 SECTION_NAME (section
));
4060 if (is_32bit_elf
|| do_wide
)
4061 printf (" %-15.15s ",
4062 get_section_type_name (section
->sh_type
));
4065 printf (" [%2u] %-17.17s %-15.15s ",
4066 SECTION_HEADER_NUM (i
),
4067 SECTION_NAME (section
),
4068 get_section_type_name (section
->sh_type
));
4072 print_vma (section
->sh_addr
, LONG_HEX
);
4074 printf ( " %6.6lx %6.6lx %2.2lx",
4075 (unsigned long) section
->sh_offset
,
4076 (unsigned long) section
->sh_size
,
4077 (unsigned long) section
->sh_entsize
);
4079 if (do_section_details
)
4080 fputs (" ", stdout
);
4082 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4084 printf ("%2ld %3lu %2ld\n",
4085 (unsigned long) section
->sh_link
,
4086 (unsigned long) section
->sh_info
,
4087 (unsigned long) section
->sh_addralign
);
4091 print_vma (section
->sh_addr
, LONG_HEX
);
4093 if ((long) section
->sh_offset
== section
->sh_offset
)
4094 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4098 print_vma (section
->sh_offset
, LONG_HEX
);
4101 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4102 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4106 print_vma (section
->sh_size
, LONG_HEX
);
4109 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4110 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4114 print_vma (section
->sh_entsize
, LONG_HEX
);
4117 if (do_section_details
)
4118 fputs (" ", stdout
);
4120 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4122 printf ("%2ld %3lu ",
4123 (unsigned long) section
->sh_link
,
4124 (unsigned long) section
->sh_info
);
4126 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4127 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4130 print_vma (section
->sh_addralign
, DEC
);
4134 else if (do_section_details
)
4136 printf (" %-15.15s ",
4137 get_section_type_name (section
->sh_type
));
4138 print_vma (section
->sh_addr
, LONG_HEX
);
4139 if ((long) section
->sh_offset
== section
->sh_offset
)
4140 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4144 print_vma (section
->sh_offset
, LONG_HEX
);
4146 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4147 print_vma (section
->sh_size
, LONG_HEX
);
4149 print_vma (section
->sh_entsize
, LONG_HEX
);
4151 printf (" %-16lu %ld\n",
4152 (unsigned long) section
->sh_info
,
4153 (unsigned long) section
->sh_addralign
);
4158 print_vma (section
->sh_addr
, LONG_HEX
);
4159 if ((long) section
->sh_offset
== section
->sh_offset
)
4160 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4164 print_vma (section
->sh_offset
, LONG_HEX
);
4167 print_vma (section
->sh_size
, LONG_HEX
);
4169 print_vma (section
->sh_entsize
, LONG_HEX
);
4171 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4173 printf (" %2ld %3lu %ld\n",
4174 (unsigned long) section
->sh_link
,
4175 (unsigned long) section
->sh_info
,
4176 (unsigned long) section
->sh_addralign
);
4179 if (do_section_details
)
4180 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4183 if (!do_section_details
)
4184 printf (_("Key to Flags:\n\
4185 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4186 I (info), L (link order), G (group), x (unknown)\n\
4187 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4193 get_group_flags (unsigned int flags
)
4195 static char buff
[32];
4202 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4209 process_section_groups (FILE *file
)
4211 Elf_Internal_Shdr
*section
;
4213 struct group
*group
;
4214 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4215 Elf_Internal_Sym
*symtab
;
4219 /* Don't process section groups unless needed. */
4220 if (!do_unwind
&& !do_section_groups
)
4223 if (elf_header
.e_shnum
== 0)
4225 if (do_section_groups
)
4226 printf (_("\nThere are no sections in this file.\n"));
4231 if (section_headers
== NULL
)
4233 error (_("Section headers are not available!\n"));
4237 section_headers_groups
= calloc (elf_header
.e_shnum
,
4238 sizeof (struct group
*));
4240 if (section_headers_groups
== NULL
)
4242 error (_("Out of memory\n"));
4246 /* Scan the sections for the group section. */
4248 for (i
= 0, section
= section_headers
;
4249 i
< elf_header
.e_shnum
;
4251 if (section
->sh_type
== SHT_GROUP
)
4254 if (group_count
== 0)
4256 if (do_section_groups
)
4257 printf (_("\nThere are no section groups in this file.\n"));
4262 section_groups
= calloc (group_count
, sizeof (struct group
));
4264 if (section_groups
== NULL
)
4266 error (_("Out of memory\n"));
4275 for (i
= 0, section
= section_headers
, group
= section_groups
;
4276 i
< elf_header
.e_shnum
;
4279 if (section
->sh_type
== SHT_GROUP
)
4281 char *name
= SECTION_NAME (section
);
4283 unsigned char *start
, *indices
;
4284 unsigned int entry
, j
, size
;
4285 Elf_Internal_Shdr
*sec
;
4286 Elf_Internal_Sym
*sym
;
4288 /* Get the symbol table. */
4289 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4290 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4293 error (_("Bad sh_link in group section `%s'\n"), name
);
4297 if (symtab_sec
!= sec
)
4302 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4305 sym
= symtab
+ section
->sh_info
;
4307 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4309 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4312 error (_("Bad sh_info in group section `%s'\n"), name
);
4316 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4325 /* Get the string table. */
4326 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4327 >= elf_header
.e_shnum
)
4336 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4341 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4342 1, strtab_sec
->sh_size
,
4344 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4346 group_name
= sym
->st_name
< strtab_size
4347 ? strtab
+ sym
->st_name
: "<corrupt>";
4350 start
= get_data (NULL
, file
, section
->sh_offset
,
4351 1, section
->sh_size
, _("section data"));
4354 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4355 entry
= byte_get (indices
, 4);
4358 if (do_section_groups
)
4360 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4361 get_group_flags (entry
), i
, name
, group_name
, size
);
4363 printf (_(" [Index] Name\n"));
4366 group
->group_index
= i
;
4368 for (j
= 0; j
< size
; j
++)
4370 struct group_list
*g
;
4372 entry
= byte_get (indices
, 4);
4375 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4377 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4378 entry
, i
, elf_header
.e_shnum
- 1);
4381 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4383 error (_("invalid section [%5u] in group section [%5u]\n"),
4388 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4393 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4395 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4400 /* Intel C/C++ compiler may put section 0 in a
4401 section group. We just warn it the first time
4402 and ignore it afterwards. */
4403 static int warned
= 0;
4406 error (_("section 0 in group section [%5u]\n"),
4407 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4413 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4416 if (do_section_groups
)
4418 sec
= SECTION_HEADER (entry
);
4419 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4422 g
= xmalloc (sizeof (struct group_list
));
4423 g
->section_index
= entry
;
4424 g
->next
= group
->root
;
4448 } dynamic_relocations
[] =
4450 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4451 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4452 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4455 /* Process the reloc section. */
4458 process_relocs (FILE *file
)
4460 unsigned long rel_size
;
4461 unsigned long rel_offset
;
4467 if (do_using_dynamic
)
4471 int has_dynamic_reloc
;
4474 has_dynamic_reloc
= 0;
4476 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4478 is_rela
= dynamic_relocations
[i
].rela
;
4479 name
= dynamic_relocations
[i
].name
;
4480 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4481 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4483 has_dynamic_reloc
|= rel_size
;
4485 if (is_rela
== UNKNOWN
)
4487 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4488 switch (dynamic_info
[DT_PLTREL
])
4502 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4503 name
, rel_offset
, rel_size
);
4505 dump_relocations (file
,
4506 offset_from_vma (file
, rel_offset
, rel_size
),
4508 dynamic_symbols
, num_dynamic_syms
,
4509 dynamic_strings
, dynamic_strings_length
, is_rela
);
4513 if (! has_dynamic_reloc
)
4514 printf (_("\nThere are no dynamic relocations in this file.\n"));
4518 Elf_Internal_Shdr
*section
;
4522 for (i
= 0, section
= section_headers
;
4523 i
< elf_header
.e_shnum
;
4526 if ( section
->sh_type
!= SHT_RELA
4527 && section
->sh_type
!= SHT_REL
)
4530 rel_offset
= section
->sh_offset
;
4531 rel_size
= section
->sh_size
;
4535 Elf_Internal_Shdr
*strsec
;
4538 printf (_("\nRelocation section "));
4540 if (string_table
== NULL
)
4541 printf ("%d", section
->sh_name
);
4543 printf (_("'%s'"), SECTION_NAME (section
));
4545 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4546 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4548 is_rela
= section
->sh_type
== SHT_RELA
;
4550 if (section
->sh_link
4551 && SECTION_HEADER_INDEX (section
->sh_link
)
4552 < elf_header
.e_shnum
)
4554 Elf_Internal_Shdr
*symsec
;
4555 Elf_Internal_Sym
*symtab
;
4556 unsigned long nsyms
;
4557 unsigned long strtablen
= 0;
4558 char *strtab
= NULL
;
4560 symsec
= SECTION_HEADER (section
->sh_link
);
4561 if (symsec
->sh_type
!= SHT_SYMTAB
4562 && symsec
->sh_type
!= SHT_DYNSYM
)
4565 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4566 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4571 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4572 < elf_header
.e_shnum
)
4574 strsec
= SECTION_HEADER (symsec
->sh_link
);
4576 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4579 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4582 dump_relocations (file
, rel_offset
, rel_size
,
4583 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4589 dump_relocations (file
, rel_offset
, rel_size
,
4590 NULL
, 0, NULL
, 0, is_rela
);
4597 printf (_("\nThere are no relocations in this file.\n"));
4603 /* Process the unwind section. */
4605 #include "unwind-ia64.h"
4607 /* An absolute address consists of a section and an offset. If the
4608 section is NULL, the offset itself is the address, otherwise, the
4609 address equals to LOAD_ADDRESS(section) + offset. */
4613 unsigned short section
;
4617 #define ABSADDR(a) \
4619 ? section_headers [(a).section].sh_addr + (a).offset \
4622 struct ia64_unw_aux_info
4624 struct ia64_unw_table_entry
4626 struct absaddr start
;
4628 struct absaddr info
;
4630 *table
; /* Unwind table. */
4631 unsigned long table_len
; /* Length of unwind table. */
4632 unsigned char *info
; /* Unwind info. */
4633 unsigned long info_size
; /* Size of unwind info. */
4634 bfd_vma info_addr
; /* starting address of unwind info. */
4635 bfd_vma seg_base
; /* Starting address of segment. */
4636 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4637 unsigned long nsyms
; /* Number of symbols. */
4638 char *strtab
; /* The string table. */
4639 unsigned long strtab_size
; /* Size of string table. */
4643 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4644 unsigned long nsyms
,
4646 unsigned long strtab_size
,
4647 struct absaddr addr
,
4648 const char **symname
,
4651 bfd_vma dist
= 0x100000;
4652 Elf_Internal_Sym
*sym
, *best
= NULL
;
4655 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4657 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4658 && sym
->st_name
!= 0
4659 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4660 && addr
.offset
>= sym
->st_value
4661 && addr
.offset
- sym
->st_value
< dist
)
4664 dist
= addr
.offset
- sym
->st_value
;
4671 *symname
= (best
->st_name
>= strtab_size
4672 ? "<corrupt>" : strtab
+ best
->st_name
);
4677 *offset
= addr
.offset
;
4681 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4683 struct ia64_unw_table_entry
*tp
;
4686 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4690 const unsigned char *dp
;
4691 const unsigned char *head
;
4692 const char *procname
;
4694 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4695 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4697 fputs ("\n<", stdout
);
4701 fputs (procname
, stdout
);
4704 printf ("+%lx", (unsigned long) offset
);
4707 fputs (">: [", stdout
);
4708 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4709 fputc ('-', stdout
);
4710 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4711 printf ("], info at +0x%lx\n",
4712 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4714 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4715 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4717 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4718 (unsigned) UNW_VER (stamp
),
4719 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4720 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4721 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4722 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4724 if (UNW_VER (stamp
) != 1)
4726 printf ("\tUnknown version.\n");
4731 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4732 dp
= unw_decode (dp
, in_body
, & in_body
);
4737 slurp_ia64_unwind_table (FILE *file
,
4738 struct ia64_unw_aux_info
*aux
,
4739 Elf_Internal_Shdr
*sec
)
4741 unsigned long size
, nrelas
, i
;
4742 Elf_Internal_Phdr
*seg
;
4743 struct ia64_unw_table_entry
*tep
;
4744 Elf_Internal_Shdr
*relsec
;
4745 Elf_Internal_Rela
*rela
, *rp
;
4746 unsigned char *table
, *tp
;
4747 Elf_Internal_Sym
*sym
;
4748 const char *relname
;
4750 /* First, find the starting address of the segment that includes
4753 if (elf_header
.e_phnum
)
4755 if (! get_program_headers (file
))
4758 for (seg
= program_headers
;
4759 seg
< program_headers
+ elf_header
.e_phnum
;
4762 if (seg
->p_type
!= PT_LOAD
)
4765 if (sec
->sh_addr
>= seg
->p_vaddr
4766 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4768 aux
->seg_base
= seg
->p_vaddr
;
4774 /* Second, build the unwind table from the contents of the unwind section: */
4775 size
= sec
->sh_size
;
4776 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4780 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4782 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4784 tep
->start
.section
= SHN_UNDEF
;
4785 tep
->end
.section
= SHN_UNDEF
;
4786 tep
->info
.section
= SHN_UNDEF
;
4789 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4790 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4791 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4795 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
4796 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
4797 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
4799 tep
->start
.offset
+= aux
->seg_base
;
4800 tep
->end
.offset
+= aux
->seg_base
;
4801 tep
->info
.offset
+= aux
->seg_base
;
4805 /* Third, apply any relocations to the unwind table: */
4807 for (relsec
= section_headers
;
4808 relsec
< section_headers
+ elf_header
.e_shnum
;
4811 if (relsec
->sh_type
!= SHT_RELA
4812 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
4813 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4816 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4820 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4824 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4825 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4829 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4830 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4833 if (! strneq (relname
, "R_IA64_SEGREL", 13))
4835 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4839 i
= rp
->r_offset
/ (3 * eh_addr_size
);
4841 switch (rp
->r_offset
/eh_addr_size
% 3)
4844 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4845 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
4848 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4849 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
4852 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4853 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
4863 aux
->table_len
= size
/ (3 * eh_addr_size
);
4868 ia64_process_unwind (FILE *file
)
4870 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4871 unsigned long i
, unwcount
= 0, unwstart
= 0;
4872 struct ia64_unw_aux_info aux
;
4874 memset (& aux
, 0, sizeof (aux
));
4876 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4878 if (sec
->sh_type
== SHT_SYMTAB
4879 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
4881 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4882 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4884 strsec
= SECTION_HEADER (sec
->sh_link
);
4885 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4886 1, strsec
->sh_size
, _("string table"));
4887 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
4889 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4894 printf (_("\nThere are no unwind sections in this file.\n"));
4896 while (unwcount
-- > 0)
4901 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4902 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4903 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4910 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4912 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
4914 /* We need to find which section group it is in. */
4915 struct group_list
*g
= section_headers_groups
[i
]->root
;
4917 for (; g
!= NULL
; g
= g
->next
)
4919 sec
= SECTION_HEADER (g
->section_index
);
4921 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
4926 i
= elf_header
.e_shnum
;
4928 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
4930 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
4931 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4932 suffix
= SECTION_NAME (unwsec
) + len
;
4933 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4935 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
4936 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4941 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4942 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
4943 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4944 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4946 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
4947 suffix
= SECTION_NAME (unwsec
) + len
;
4948 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4950 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
4951 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4955 if (i
== elf_header
.e_shnum
)
4957 printf (_("\nCould not find unwind info section for "));
4959 if (string_table
== NULL
)
4960 printf ("%d", unwsec
->sh_name
);
4962 printf (_("'%s'"), SECTION_NAME (unwsec
));
4966 aux
.info_size
= sec
->sh_size
;
4967 aux
.info_addr
= sec
->sh_addr
;
4968 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
4971 printf (_("\nUnwind section "));
4973 if (string_table
== NULL
)
4974 printf ("%d", unwsec
->sh_name
);
4976 printf (_("'%s'"), SECTION_NAME (unwsec
));
4978 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4979 (unsigned long) unwsec
->sh_offset
,
4980 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
4982 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4984 if (aux
.table_len
> 0)
4985 dump_ia64_unwind (& aux
);
4988 free ((char *) aux
.table
);
4990 free ((char *) aux
.info
);
4999 free ((char *) aux
.strtab
);
5004 struct hppa_unw_aux_info
5006 struct hppa_unw_table_entry
5008 struct absaddr start
;
5010 unsigned int Cannot_unwind
:1; /* 0 */
5011 unsigned int Millicode
:1; /* 1 */
5012 unsigned int Millicode_save_sr0
:1; /* 2 */
5013 unsigned int Region_description
:2; /* 3..4 */
5014 unsigned int reserved1
:1; /* 5 */
5015 unsigned int Entry_SR
:1; /* 6 */
5016 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5017 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5018 unsigned int Args_stored
:1; /* 16 */
5019 unsigned int Variable_Frame
:1; /* 17 */
5020 unsigned int Separate_Package_Body
:1; /* 18 */
5021 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5022 unsigned int Stack_Overflow_Check
:1; /* 20 */
5023 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5024 unsigned int Ada_Region
:1; /* 22 */
5025 unsigned int cxx_info
:1; /* 23 */
5026 unsigned int cxx_try_catch
:1; /* 24 */
5027 unsigned int sched_entry_seq
:1; /* 25 */
5028 unsigned int reserved2
:1; /* 26 */
5029 unsigned int Save_SP
:1; /* 27 */
5030 unsigned int Save_RP
:1; /* 28 */
5031 unsigned int Save_MRP_in_frame
:1; /* 29 */
5032 unsigned int extn_ptr_defined
:1; /* 30 */
5033 unsigned int Cleanup_defined
:1; /* 31 */
5035 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5036 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5037 unsigned int Large_frame
:1; /* 2 */
5038 unsigned int Pseudo_SP_Set
:1; /* 3 */
5039 unsigned int reserved4
:1; /* 4 */
5040 unsigned int Total_frame_size
:27; /* 5..31 */
5042 *table
; /* Unwind table. */
5043 unsigned long table_len
; /* Length of unwind table. */
5044 bfd_vma seg_base
; /* Starting address of segment. */
5045 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5046 unsigned long nsyms
; /* Number of symbols. */
5047 char *strtab
; /* The string table. */
5048 unsigned long strtab_size
; /* Size of string table. */
5052 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5054 struct hppa_unw_table_entry
*tp
;
5056 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5059 const char *procname
;
5061 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5062 aux
->strtab_size
, tp
->start
, &procname
,
5065 fputs ("\n<", stdout
);
5069 fputs (procname
, stdout
);
5072 printf ("+%lx", (unsigned long) offset
);
5075 fputs (">: [", stdout
);
5076 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5077 fputc ('-', stdout
);
5078 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5081 #define PF(_m) if (tp->_m) printf (#_m " ");
5082 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5085 PF(Millicode_save_sr0
);
5086 /* PV(Region_description); */
5092 PF(Separate_Package_Body
);
5093 PF(Frame_Extension_Millicode
);
5094 PF(Stack_Overflow_Check
);
5095 PF(Two_Instruction_SP_Increment
);
5099 PF(sched_entry_seq
);
5102 PF(Save_MRP_in_frame
);
5103 PF(extn_ptr_defined
);
5104 PF(Cleanup_defined
);
5105 PF(MPE_XL_interrupt_marker
);
5106 PF(HP_UX_interrupt_marker
);
5109 PV(Total_frame_size
);
5118 slurp_hppa_unwind_table (FILE *file
,
5119 struct hppa_unw_aux_info
*aux
,
5120 Elf_Internal_Shdr
*sec
)
5122 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5123 Elf_Internal_Phdr
*seg
;
5124 struct hppa_unw_table_entry
*tep
;
5125 Elf_Internal_Shdr
*relsec
;
5126 Elf_Internal_Rela
*rela
, *rp
;
5127 unsigned char *table
, *tp
;
5128 Elf_Internal_Sym
*sym
;
5129 const char *relname
;
5131 /* First, find the starting address of the segment that includes
5134 if (elf_header
.e_phnum
)
5136 if (! get_program_headers (file
))
5139 for (seg
= program_headers
;
5140 seg
< program_headers
+ elf_header
.e_phnum
;
5143 if (seg
->p_type
!= PT_LOAD
)
5146 if (sec
->sh_addr
>= seg
->p_vaddr
5147 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5149 aux
->seg_base
= seg
->p_vaddr
;
5155 /* Second, build the unwind table from the contents of the unwind
5157 size
= sec
->sh_size
;
5158 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5163 nentries
= size
/ unw_ent_size
;
5164 size
= unw_ent_size
* nentries
;
5166 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5168 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5170 unsigned int tmp1
, tmp2
;
5172 tep
->start
.section
= SHN_UNDEF
;
5173 tep
->end
.section
= SHN_UNDEF
;
5175 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5176 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5177 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5178 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5180 tep
->start
.offset
+= aux
->seg_base
;
5181 tep
->end
.offset
+= aux
->seg_base
;
5183 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5184 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5185 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5186 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5187 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5188 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5189 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5190 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5191 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5192 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5193 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5194 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5195 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5196 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5197 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5198 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5199 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5200 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5201 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5202 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5203 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5204 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5205 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5206 tep
->Cleanup_defined
= tmp1
& 0x1;
5208 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5209 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5210 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5211 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5212 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5213 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5217 /* Third, apply any relocations to the unwind table. */
5219 for (relsec
= section_headers
;
5220 relsec
< section_headers
+ elf_header
.e_shnum
;
5223 if (relsec
->sh_type
!= SHT_RELA
5224 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5225 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5228 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5232 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5236 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5237 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5241 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5242 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5245 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5246 if (strncmp (relname
, "R_PARISC_SEGREL", 15) != 0)
5248 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5252 i
= rp
->r_offset
/ unw_ent_size
;
5254 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5257 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5258 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5261 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5262 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5272 aux
->table_len
= nentries
;
5278 hppa_process_unwind (FILE *file
)
5280 struct hppa_unw_aux_info aux
;
5281 Elf_Internal_Shdr
*unwsec
= NULL
;
5282 Elf_Internal_Shdr
*strsec
;
5283 Elf_Internal_Shdr
*sec
;
5286 memset (& aux
, 0, sizeof (aux
));
5288 if (string_table
== NULL
)
5291 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5293 if (sec
->sh_type
== SHT_SYMTAB
5294 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5296 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5297 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5299 strsec
= SECTION_HEADER (sec
->sh_link
);
5300 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5301 1, strsec
->sh_size
, _("string table"));
5302 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5304 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5309 printf (_("\nThere are no unwind sections in this file.\n"));
5311 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5313 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5315 printf (_("\nUnwind section "));
5316 printf (_("'%s'"), SECTION_NAME (sec
));
5318 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5319 (unsigned long) sec
->sh_offset
,
5320 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5322 slurp_hppa_unwind_table (file
, &aux
, sec
);
5323 if (aux
.table_len
> 0)
5324 dump_hppa_unwind (&aux
);
5327 free ((char *) aux
.table
);
5335 free ((char *) aux
.strtab
);
5341 process_unwind (FILE *file
)
5343 struct unwind_handler
{
5345 int (*handler
)(FILE *file
);
5347 { EM_IA_64
, ia64_process_unwind
},
5348 { EM_PARISC
, hppa_process_unwind
},
5356 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5357 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5358 return handlers
[i
].handler (file
);
5360 printf (_("\nThere are no unwind sections in this file.\n"));
5365 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5367 switch (entry
->d_tag
)
5370 if (entry
->d_un
.d_val
== 0)
5374 static const char * opts
[] =
5376 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5377 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5378 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5379 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5384 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
5385 if (entry
->d_un
.d_val
& (1 << cnt
))
5387 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5394 case DT_MIPS_IVERSION
:
5395 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5396 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5398 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5401 case DT_MIPS_TIME_STAMP
:
5406 time_t time
= entry
->d_un
.d_val
;
5407 tmp
= gmtime (&time
);
5408 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5409 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5410 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5411 printf ("Time Stamp: %s\n", timebuf
);
5415 case DT_MIPS_RLD_VERSION
:
5416 case DT_MIPS_LOCAL_GOTNO
:
5417 case DT_MIPS_CONFLICTNO
:
5418 case DT_MIPS_LIBLISTNO
:
5419 case DT_MIPS_SYMTABNO
:
5420 case DT_MIPS_UNREFEXTNO
:
5421 case DT_MIPS_HIPAGENO
:
5422 case DT_MIPS_DELTA_CLASS_NO
:
5423 case DT_MIPS_DELTA_INSTANCE_NO
:
5424 case DT_MIPS_DELTA_RELOC_NO
:
5425 case DT_MIPS_DELTA_SYM_NO
:
5426 case DT_MIPS_DELTA_CLASSSYM_NO
:
5427 case DT_MIPS_COMPACT_SIZE
:
5428 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5432 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5438 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5440 switch (entry
->d_tag
)
5442 case DT_HP_DLD_FLAGS
:
5451 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5452 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5453 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5454 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5455 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5456 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5457 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5458 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5459 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5460 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5461 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5462 { DT_HP_GST
, "HP_GST" },
5463 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5464 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5465 { DT_HP_NODELETE
, "HP_NODELETE" },
5466 { DT_HP_GROUP
, "HP_GROUP" },
5467 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5471 bfd_vma val
= entry
->d_un
.d_val
;
5473 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
5474 if (val
& flags
[cnt
].bit
)
5478 fputs (flags
[cnt
].str
, stdout
);
5480 val
^= flags
[cnt
].bit
;
5483 if (val
!= 0 || first
)
5487 print_vma (val
, HEX
);
5493 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5500 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5502 switch (entry
->d_tag
)
5504 case DT_IA_64_PLT_RESERVE
:
5505 /* First 3 slots reserved. */
5506 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5508 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5512 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5519 get_32bit_dynamic_section (FILE *file
)
5521 Elf32_External_Dyn
*edyn
, *ext
;
5522 Elf_Internal_Dyn
*entry
;
5524 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5525 _("dynamic section"));
5529 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5530 might not have the luxury of section headers. Look for the DT_NULL
5531 terminator to determine the number of entries. */
5532 for (ext
= edyn
, dynamic_nent
= 0;
5533 (char *) ext
< (char *) edyn
+ dynamic_size
;
5537 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5541 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5542 if (dynamic_section
== NULL
)
5544 error (_("Out of memory\n"));
5549 for (ext
= edyn
, entry
= dynamic_section
;
5550 entry
< dynamic_section
+ dynamic_nent
;
5553 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5554 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5563 get_64bit_dynamic_section (FILE *file
)
5565 Elf64_External_Dyn
*edyn
, *ext
;
5566 Elf_Internal_Dyn
*entry
;
5568 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5569 _("dynamic section"));
5573 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5574 might not have the luxury of section headers. Look for the DT_NULL
5575 terminator to determine the number of entries. */
5576 for (ext
= edyn
, dynamic_nent
= 0;
5577 (char *) ext
< (char *) edyn
+ dynamic_size
;
5581 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5585 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5586 if (dynamic_section
== NULL
)
5588 error (_("Out of memory\n"));
5593 for (ext
= edyn
, entry
= dynamic_section
;
5594 entry
< dynamic_section
+ dynamic_nent
;
5597 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5598 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5607 print_dynamic_flags (bfd_vma flags
)
5615 flag
= flags
& - flags
;
5625 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5626 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5627 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5628 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5629 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5630 default: fputs ("unknown", stdout
); break;
5636 /* Parse and display the contents of the dynamic section. */
5639 process_dynamic_section (FILE *file
)
5641 Elf_Internal_Dyn
*entry
;
5643 if (dynamic_size
== 0)
5646 printf (_("\nThere is no dynamic section in this file.\n"));
5653 if (! get_32bit_dynamic_section (file
))
5656 else if (! get_64bit_dynamic_section (file
))
5659 /* Find the appropriate symbol table. */
5660 if (dynamic_symbols
== NULL
)
5662 for (entry
= dynamic_section
;
5663 entry
< dynamic_section
+ dynamic_nent
;
5666 Elf_Internal_Shdr section
;
5668 if (entry
->d_tag
!= DT_SYMTAB
)
5671 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5673 /* Since we do not know how big the symbol table is,
5674 we default to reading in the entire file (!) and
5675 processing that. This is overkill, I know, but it
5677 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5679 if (archive_file_offset
!= 0)
5680 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5683 if (fseek (file
, 0, SEEK_END
))
5684 error (_("Unable to seek to end of file!"));
5686 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5690 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5692 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5694 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5695 if (num_dynamic_syms
< 1)
5697 error (_("Unable to determine the number of symbols to load\n"));
5701 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5705 /* Similarly find a string table. */
5706 if (dynamic_strings
== NULL
)
5708 for (entry
= dynamic_section
;
5709 entry
< dynamic_section
+ dynamic_nent
;
5712 unsigned long offset
;
5715 if (entry
->d_tag
!= DT_STRTAB
)
5718 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5720 /* Since we do not know how big the string table is,
5721 we default to reading in the entire file (!) and
5722 processing that. This is overkill, I know, but it
5725 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5727 if (archive_file_offset
!= 0)
5728 str_tab_len
= archive_file_size
- offset
;
5731 if (fseek (file
, 0, SEEK_END
))
5732 error (_("Unable to seek to end of file\n"));
5733 str_tab_len
= ftell (file
) - offset
;
5736 if (str_tab_len
< 1)
5739 (_("Unable to determine the length of the dynamic string table\n"));
5743 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5744 _("dynamic string table"));
5745 dynamic_strings_length
= str_tab_len
;
5750 /* And find the syminfo section if available. */
5751 if (dynamic_syminfo
== NULL
)
5753 unsigned long syminsz
= 0;
5755 for (entry
= dynamic_section
;
5756 entry
< dynamic_section
+ dynamic_nent
;
5759 if (entry
->d_tag
== DT_SYMINENT
)
5761 /* Note: these braces are necessary to avoid a syntax
5762 error from the SunOS4 C compiler. */
5763 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5765 else if (entry
->d_tag
== DT_SYMINSZ
)
5766 syminsz
= entry
->d_un
.d_val
;
5767 else if (entry
->d_tag
== DT_SYMINFO
)
5768 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5772 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5774 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5775 Elf_Internal_Syminfo
*syminfo
;
5777 /* There is a syminfo section. Read the data. */
5778 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5779 syminsz
, _("symbol information"));
5783 dynamic_syminfo
= malloc (syminsz
);
5784 if (dynamic_syminfo
== NULL
)
5786 error (_("Out of memory\n"));
5790 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5791 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5792 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5793 ++syminfo
, ++extsym
)
5795 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5796 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5803 if (do_dynamic
&& dynamic_addr
)
5804 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5805 dynamic_addr
, dynamic_nent
);
5807 printf (_(" Tag Type Name/Value\n"));
5809 for (entry
= dynamic_section
;
5810 entry
< dynamic_section
+ dynamic_nent
;
5818 print_vma (entry
->d_tag
, FULL_HEX
);
5819 dtype
= get_dynamic_type (entry
->d_tag
);
5820 printf (" (%s)%*s", dtype
,
5821 ((is_32bit_elf
? 27 : 19)
5822 - (int) strlen (dtype
)),
5826 switch (entry
->d_tag
)
5830 print_dynamic_flags (entry
->d_un
.d_val
);
5840 switch (entry
->d_tag
)
5843 printf (_("Auxiliary library"));
5847 printf (_("Filter library"));
5851 printf (_("Configuration file"));
5855 printf (_("Dependency audit library"));
5859 printf (_("Audit library"));
5863 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5864 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5868 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5877 printf (_("Flags:"));
5879 if (entry
->d_un
.d_val
== 0)
5880 printf (_(" None\n"));
5883 unsigned long int val
= entry
->d_un
.d_val
;
5885 if (val
& DTF_1_PARINIT
)
5887 printf (" PARINIT");
5888 val
^= DTF_1_PARINIT
;
5890 if (val
& DTF_1_CONFEXP
)
5892 printf (" CONFEXP");
5893 val
^= DTF_1_CONFEXP
;
5896 printf (" %lx", val
);
5905 printf (_("Flags:"));
5907 if (entry
->d_un
.d_val
== 0)
5908 printf (_(" None\n"));
5911 unsigned long int val
= entry
->d_un
.d_val
;
5913 if (val
& DF_P1_LAZYLOAD
)
5915 printf (" LAZYLOAD");
5916 val
^= DF_P1_LAZYLOAD
;
5918 if (val
& DF_P1_GROUPPERM
)
5920 printf (" GROUPPERM");
5921 val
^= DF_P1_GROUPPERM
;
5924 printf (" %lx", val
);
5933 printf (_("Flags:"));
5934 if (entry
->d_un
.d_val
== 0)
5935 printf (_(" None\n"));
5938 unsigned long int val
= entry
->d_un
.d_val
;
5945 if (val
& DF_1_GLOBAL
)
5950 if (val
& DF_1_GROUP
)
5955 if (val
& DF_1_NODELETE
)
5957 printf (" NODELETE");
5958 val
^= DF_1_NODELETE
;
5960 if (val
& DF_1_LOADFLTR
)
5962 printf (" LOADFLTR");
5963 val
^= DF_1_LOADFLTR
;
5965 if (val
& DF_1_INITFIRST
)
5967 printf (" INITFIRST");
5968 val
^= DF_1_INITFIRST
;
5970 if (val
& DF_1_NOOPEN
)
5975 if (val
& DF_1_ORIGIN
)
5980 if (val
& DF_1_DIRECT
)
5985 if (val
& DF_1_TRANS
)
5990 if (val
& DF_1_INTERPOSE
)
5992 printf (" INTERPOSE");
5993 val
^= DF_1_INTERPOSE
;
5995 if (val
& DF_1_NODEFLIB
)
5997 printf (" NODEFLIB");
5998 val
^= DF_1_NODEFLIB
;
6000 if (val
& DF_1_NODUMP
)
6005 if (val
& DF_1_CONLFAT
)
6007 printf (" CONLFAT");
6008 val
^= DF_1_CONLFAT
;
6011 printf (" %lx", val
);
6018 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6020 puts (get_dynamic_type (entry
->d_un
.d_val
));
6040 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6046 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6047 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6053 switch (entry
->d_tag
)
6056 printf (_("Shared library: [%s]"), name
);
6058 if (streq (name
, program_interpreter
))
6059 printf (_(" program interpreter"));
6063 printf (_("Library soname: [%s]"), name
);
6067 printf (_("Library rpath: [%s]"), name
);
6071 printf (_("Library runpath: [%s]"), name
);
6075 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6080 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6093 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6097 case DT_INIT_ARRAYSZ
:
6098 case DT_FINI_ARRAYSZ
:
6099 case DT_GNU_CONFLICTSZ
:
6100 case DT_GNU_LIBLISTSZ
:
6103 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6104 printf (" (bytes)\n");
6114 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6127 if (entry
->d_tag
== DT_USED
6128 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6130 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6134 printf (_("Not needed object: [%s]\n"), name
);
6139 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6145 /* The value of this entry is ignored. */
6150 case DT_GNU_PRELINKED
:
6154 time_t time
= entry
->d_un
.d_val
;
6156 tmp
= gmtime (&time
);
6157 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6158 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6159 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6165 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6166 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6171 switch (elf_header
.e_machine
)
6174 case EM_MIPS_RS3_LE
:
6175 dynamic_section_mips_val (entry
);
6178 dynamic_section_parisc_val (entry
);
6181 dynamic_section_ia64_val (entry
);
6184 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6196 get_ver_flags (unsigned int flags
)
6198 static char buff
[32];
6205 if (flags
& VER_FLG_BASE
)
6206 strcat (buff
, "BASE ");
6208 if (flags
& VER_FLG_WEAK
)
6210 if (flags
& VER_FLG_BASE
)
6211 strcat (buff
, "| ");
6213 strcat (buff
, "WEAK ");
6216 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6217 strcat (buff
, "| <unknown>");
6222 /* Display the contents of the version sections. */
6224 process_version_sections (FILE *file
)
6226 Elf_Internal_Shdr
*section
;
6233 for (i
= 0, section
= section_headers
;
6234 i
< elf_header
.e_shnum
;
6237 switch (section
->sh_type
)
6239 case SHT_GNU_verdef
:
6241 Elf_External_Verdef
*edefs
;
6248 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6249 SECTION_NAME (section
), section
->sh_info
);
6251 printf (_(" Addr: 0x"));
6252 printf_vma (section
->sh_addr
);
6253 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6254 (unsigned long) section
->sh_offset
, section
->sh_link
,
6255 SECTION_HEADER_INDEX (section
->sh_link
)
6256 < elf_header
.e_shnum
6257 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6260 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6262 _("version definition section"));
6266 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6269 Elf_External_Verdef
*edef
;
6270 Elf_Internal_Verdef ent
;
6271 Elf_External_Verdaux
*eaux
;
6272 Elf_Internal_Verdaux aux
;
6276 vstart
= ((char *) edefs
) + idx
;
6278 edef
= (Elf_External_Verdef
*) vstart
;
6280 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6281 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6282 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6283 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6284 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6285 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6286 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6288 printf (_(" %#06x: Rev: %d Flags: %s"),
6289 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6291 printf (_(" Index: %d Cnt: %d "),
6292 ent
.vd_ndx
, ent
.vd_cnt
);
6294 vstart
+= ent
.vd_aux
;
6296 eaux
= (Elf_External_Verdaux
*) vstart
;
6298 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6299 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6301 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6302 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6304 printf (_("Name index: %ld\n"), aux
.vda_name
);
6306 isum
= idx
+ ent
.vd_aux
;
6308 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6310 isum
+= aux
.vda_next
;
6311 vstart
+= aux
.vda_next
;
6313 eaux
= (Elf_External_Verdaux
*) vstart
;
6315 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6316 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6318 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6319 printf (_(" %#06x: Parent %d: %s\n"),
6320 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6322 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6323 isum
, j
, aux
.vda_name
);
6333 case SHT_GNU_verneed
:
6335 Elf_External_Verneed
*eneed
;
6341 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6342 SECTION_NAME (section
), section
->sh_info
);
6344 printf (_(" Addr: 0x"));
6345 printf_vma (section
->sh_addr
);
6346 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6347 (unsigned long) section
->sh_offset
, section
->sh_link
,
6348 SECTION_HEADER_INDEX (section
->sh_link
)
6349 < elf_header
.e_shnum
6350 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6353 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6355 _("version need section"));
6359 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6361 Elf_External_Verneed
*entry
;
6362 Elf_Internal_Verneed ent
;
6367 vstart
= ((char *) eneed
) + idx
;
6369 entry
= (Elf_External_Verneed
*) vstart
;
6371 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6372 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6373 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6374 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6375 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6377 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6379 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6380 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6382 printf (_(" File: %lx"), ent
.vn_file
);
6384 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6386 vstart
+= ent
.vn_aux
;
6388 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6390 Elf_External_Vernaux
*eaux
;
6391 Elf_Internal_Vernaux aux
;
6393 eaux
= (Elf_External_Vernaux
*) vstart
;
6395 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6396 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6397 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6398 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6399 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6401 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6402 printf (_(" %#06x: Name: %s"),
6403 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6405 printf (_(" %#06x: Name index: %lx"),
6406 isum
, aux
.vna_name
);
6408 printf (_(" Flags: %s Version: %d\n"),
6409 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6411 isum
+= aux
.vna_next
;
6412 vstart
+= aux
.vna_next
;
6422 case SHT_GNU_versym
:
6424 Elf_Internal_Shdr
*link_section
;
6427 unsigned char *edata
;
6428 unsigned short *data
;
6430 Elf_Internal_Sym
*symbols
;
6431 Elf_Internal_Shdr
*string_sec
;
6434 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6437 link_section
= SECTION_HEADER (section
->sh_link
);
6438 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6440 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6441 >= elf_header
.e_shnum
)
6446 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6448 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6450 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6451 string_sec
->sh_size
, _("version string table"));
6455 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6456 SECTION_NAME (section
), total
);
6458 printf (_(" Addr: "));
6459 printf_vma (section
->sh_addr
);
6460 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6461 (unsigned long) section
->sh_offset
, section
->sh_link
,
6462 SECTION_NAME (link_section
));
6464 off
= offset_from_vma (file
,
6465 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6466 total
* sizeof (short));
6467 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6468 _("version symbol data"));
6475 data
= cmalloc (total
, sizeof (short));
6477 for (cnt
= total
; cnt
--;)
6478 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6483 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6486 int check_def
, check_need
;
6489 printf (" %03x:", cnt
);
6491 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6492 switch (data
[cnt
+ j
])
6495 fputs (_(" 0 (*local*) "), stdout
);
6499 fputs (_(" 1 (*global*) "), stdout
);
6503 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6504 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6508 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6509 >= elf_header
.e_shnum
6510 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6513 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6520 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6522 Elf_Internal_Verneed ivn
;
6523 unsigned long offset
;
6525 offset
= offset_from_vma
6526 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6527 sizeof (Elf_External_Verneed
));
6531 Elf_Internal_Vernaux ivna
;
6532 Elf_External_Verneed evn
;
6533 Elf_External_Vernaux evna
;
6534 unsigned long a_off
;
6536 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6539 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6540 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6542 a_off
= offset
+ ivn
.vn_aux
;
6546 get_data (&evna
, file
, a_off
, sizeof (evna
),
6547 1, _("version need aux (2)"));
6549 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6550 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6552 a_off
+= ivna
.vna_next
;
6554 while (ivna
.vna_other
!= data
[cnt
+ j
]
6555 && ivna
.vna_next
!= 0);
6557 if (ivna
.vna_other
== data
[cnt
+ j
])
6559 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6561 name
= strtab
+ ivna
.vna_name
;
6562 nn
+= printf ("(%s%-*s",
6564 12 - (int) strlen (name
),
6570 offset
+= ivn
.vn_next
;
6572 while (ivn
.vn_next
);
6575 if (check_def
&& data
[cnt
+ j
] != 0x8001
6576 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6578 Elf_Internal_Verdef ivd
;
6579 Elf_External_Verdef evd
;
6580 unsigned long offset
;
6582 offset
= offset_from_vma
6583 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6588 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6591 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6592 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6594 offset
+= ivd
.vd_next
;
6596 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6597 && ivd
.vd_next
!= 0);
6599 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6601 Elf_External_Verdaux evda
;
6602 Elf_Internal_Verdaux ivda
;
6604 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6606 get_data (&evda
, file
,
6607 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6609 _("version def aux"));
6611 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6613 name
= strtab
+ ivda
.vda_name
;
6614 nn
+= printf ("(%s%-*s",
6616 12 - (int) strlen (name
),
6622 printf ("%*c", 18 - nn
, ' ');
6640 printf (_("\nNo version information found in this file.\n"));
6646 get_symbol_binding (unsigned int binding
)
6648 static char buff
[32];
6652 case STB_LOCAL
: return "LOCAL";
6653 case STB_GLOBAL
: return "GLOBAL";
6654 case STB_WEAK
: return "WEAK";
6656 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6657 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6659 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6660 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6662 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6668 get_symbol_type (unsigned int type
)
6670 static char buff
[32];
6674 case STT_NOTYPE
: return "NOTYPE";
6675 case STT_OBJECT
: return "OBJECT";
6676 case STT_FUNC
: return "FUNC";
6677 case STT_SECTION
: return "SECTION";
6678 case STT_FILE
: return "FILE";
6679 case STT_COMMON
: return "COMMON";
6680 case STT_TLS
: return "TLS";
6682 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6684 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6685 return "THUMB_FUNC";
6687 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6690 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6691 return "PARISC_MILLI";
6693 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6695 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6697 if (elf_header
.e_machine
== EM_PARISC
)
6699 if (type
== STT_HP_OPAQUE
)
6701 if (type
== STT_HP_STUB
)
6705 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6708 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6714 get_symbol_visibility (unsigned int visibility
)
6718 case STV_DEFAULT
: return "DEFAULT";
6719 case STV_INTERNAL
: return "INTERNAL";
6720 case STV_HIDDEN
: return "HIDDEN";
6721 case STV_PROTECTED
: return "PROTECTED";
6727 get_mips_symbol_other (unsigned int other
)
6731 case STO_OPTIONAL
: return "OPTIONAL";
6732 case STO_MIPS16
: return "MIPS16";
6733 default: return NULL
;
6738 get_symbol_other (unsigned int other
)
6740 const char * result
= NULL
;
6741 static char buff
[32];
6746 switch (elf_header
.e_machine
)
6749 result
= get_mips_symbol_other (other
);
6757 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
6762 get_symbol_index_type (unsigned int type
)
6764 static char buff
[32];
6768 case SHN_UNDEF
: return "UND";
6769 case SHN_ABS
: return "ABS";
6770 case SHN_COMMON
: return "COM";
6772 if (type
== SHN_IA_64_ANSI_COMMON
6773 && elf_header
.e_machine
== EM_IA_64
6774 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6776 else if (elf_header
.e_machine
== EM_X86_64
6777 && type
== SHN_X86_64_LCOMMON
)
6779 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6780 sprintf (buff
, "PRC[0x%04x]", type
);
6781 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6782 sprintf (buff
, "OS [0x%04x]", type
);
6783 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6784 sprintf (buff
, "RSV[0x%04x]", type
);
6786 sprintf (buff
, "%3d", type
);
6794 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
6796 unsigned char *e_data
;
6799 e_data
= cmalloc (number
, ent_size
);
6803 error (_("Out of memory\n"));
6807 if (fread (e_data
, ent_size
, number
, file
) != number
)
6809 error (_("Unable to read in dynamic data\n"));
6813 i_data
= cmalloc (number
, sizeof (*i_data
));
6817 error (_("Out of memory\n"));
6823 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
6830 /* Dump the symbol table. */
6832 process_symbol_table (FILE *file
)
6834 Elf_Internal_Shdr
*section
;
6835 bfd_vma nbuckets
= 0;
6836 bfd_vma nchains
= 0;
6837 bfd_vma
*buckets
= NULL
;
6838 bfd_vma
*chains
= NULL
;
6840 if (! do_syms
&& !do_histogram
)
6843 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
6846 unsigned char nb
[8];
6847 unsigned char nc
[8];
6848 int hash_ent_size
= 4;
6850 if ((elf_header
.e_machine
== EM_ALPHA
6851 || elf_header
.e_machine
== EM_S390
6852 || elf_header
.e_machine
== EM_S390_OLD
)
6853 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
6857 (archive_file_offset
6858 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
6859 sizeof nb
+ sizeof nc
)),
6862 error (_("Unable to seek to start of dynamic information"));
6866 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
6868 error (_("Failed to read in number of buckets\n"));
6872 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
6874 error (_("Failed to read in number of chains\n"));
6878 nbuckets
= byte_get (nb
, hash_ent_size
);
6879 nchains
= byte_get (nc
, hash_ent_size
);
6881 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
6882 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
6884 if (buckets
== NULL
|| chains
== NULL
)
6889 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
6894 printf (_("\nSymbol table for image:\n"));
6896 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6898 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6900 for (hn
= 0; hn
< nbuckets
; hn
++)
6905 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
6907 Elf_Internal_Sym
*psym
;
6910 psym
= dynamic_symbols
+ si
;
6912 n
= print_vma (si
, DEC_5
);
6914 fputs (" " + n
, stdout
);
6915 printf (" %3lu: ", hn
);
6916 print_vma (psym
->st_value
, LONG_HEX
);
6918 print_vma (psym
->st_size
, DEC_5
);
6920 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6921 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6922 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6923 /* Check to see if any other bits in the st_other field are set.
6924 Note - displaying this information disrupts the layout of the
6925 table being generated, but for the moment this case is very rare. */
6926 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
6927 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
6928 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
6929 if (VALID_DYNAMIC_NAME (psym
->st_name
))
6930 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
6932 printf (" <corrupt: %14ld>", psym
->st_name
);
6937 else if (do_syms
&& !do_using_dynamic
)
6941 for (i
= 0, section
= section_headers
;
6942 i
< elf_header
.e_shnum
;
6946 char *strtab
= NULL
;
6947 unsigned long int strtab_size
= 0;
6948 Elf_Internal_Sym
*symtab
;
6949 Elf_Internal_Sym
*psym
;
6952 if ( section
->sh_type
!= SHT_SYMTAB
6953 && section
->sh_type
!= SHT_DYNSYM
)
6956 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
6957 SECTION_NAME (section
),
6958 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
6960 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6962 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6964 symtab
= GET_ELF_SYMBOLS (file
, section
);
6968 if (section
->sh_link
== elf_header
.e_shstrndx
)
6970 strtab
= string_table
;
6971 strtab_size
= string_table_length
;
6973 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
6975 Elf_Internal_Shdr
*string_sec
;
6977 string_sec
= SECTION_HEADER (section
->sh_link
);
6979 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
6980 1, string_sec
->sh_size
, _("string table"));
6981 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
6984 for (si
= 0, psym
= symtab
;
6985 si
< section
->sh_size
/ section
->sh_entsize
;
6988 printf ("%6d: ", si
);
6989 print_vma (psym
->st_value
, LONG_HEX
);
6991 print_vma (psym
->st_size
, DEC_5
);
6992 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6993 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6994 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6995 /* Check to see if any other bits in the st_other field are set.
6996 Note - displaying this information disrupts the layout of the
6997 table being generated, but for the moment this case is very rare. */
6998 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
6999 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7000 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7001 print_symbol (25, psym
->st_name
< strtab_size
7002 ? strtab
+ psym
->st_name
: "<corrupt>");
7004 if (section
->sh_type
== SHT_DYNSYM
&&
7005 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7007 unsigned char data
[2];
7008 unsigned short vers_data
;
7009 unsigned long offset
;
7013 offset
= offset_from_vma
7014 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7015 sizeof data
+ si
* sizeof (vers_data
));
7017 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7018 sizeof (data
), 1, _("version data"));
7020 vers_data
= byte_get (data
, 2);
7022 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7023 < elf_header
.e_shnum
7024 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7027 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7029 if ((vers_data
& 0x8000) || vers_data
> 1)
7031 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7032 && (is_nobits
|| ! check_def
))
7034 Elf_External_Verneed evn
;
7035 Elf_Internal_Verneed ivn
;
7036 Elf_Internal_Vernaux ivna
;
7038 /* We must test both. */
7039 offset
= offset_from_vma
7040 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7045 unsigned long vna_off
;
7047 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7050 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7051 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7053 vna_off
= offset
+ ivn
.vn_aux
;
7057 Elf_External_Vernaux evna
;
7059 get_data (&evna
, file
, vna_off
,
7061 _("version need aux (3)"));
7063 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7064 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7065 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7067 vna_off
+= ivna
.vna_next
;
7069 while (ivna
.vna_other
!= vers_data
7070 && ivna
.vna_next
!= 0);
7072 if (ivna
.vna_other
== vers_data
)
7075 offset
+= ivn
.vn_next
;
7077 while (ivn
.vn_next
!= 0);
7079 if (ivna
.vna_other
== vers_data
)
7082 ivna
.vna_name
< strtab_size
7083 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7087 else if (! is_nobits
)
7088 error (_("bad dynamic symbol"));
7095 if (vers_data
!= 0x8001
7096 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7098 Elf_Internal_Verdef ivd
;
7099 Elf_Internal_Verdaux ivda
;
7100 Elf_External_Verdaux evda
;
7101 unsigned long offset
;
7103 offset
= offset_from_vma
7105 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7106 sizeof (Elf_External_Verdef
));
7110 Elf_External_Verdef evd
;
7112 get_data (&evd
, file
, offset
, sizeof (evd
),
7113 1, _("version def"));
7115 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7116 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7117 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7119 offset
+= ivd
.vd_next
;
7121 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7122 && ivd
.vd_next
!= 0);
7124 offset
-= ivd
.vd_next
;
7125 offset
+= ivd
.vd_aux
;
7127 get_data (&evda
, file
, offset
, sizeof (evda
),
7128 1, _("version def aux"));
7130 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7132 if (psym
->st_name
!= ivda
.vda_name
)
7133 printf ((vers_data
& 0x8000)
7135 ivda
.vda_name
< strtab_size
7136 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7146 if (strtab
!= string_table
)
7152 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7154 if (do_histogram
&& buckets
!= NULL
)
7156 unsigned long *lengths
;
7157 unsigned long *counts
;
7160 unsigned long maxlength
= 0;
7161 unsigned long nzero_counts
= 0;
7162 unsigned long nsyms
= 0;
7164 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7165 (unsigned long) nbuckets
);
7166 printf (_(" Length Number %% of total Coverage\n"));
7168 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7169 if (lengths
== NULL
)
7171 error (_("Out of memory"));
7174 for (hn
= 0; hn
< nbuckets
; ++hn
)
7176 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7179 if (maxlength
< ++lengths
[hn
])
7184 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7187 error (_("Out of memory"));
7191 for (hn
= 0; hn
< nbuckets
; ++hn
)
7192 ++counts
[lengths
[hn
]];
7197 printf (" 0 %-10lu (%5.1f%%)\n",
7198 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7199 for (i
= 1; i
<= maxlength
; ++i
)
7201 nzero_counts
+= counts
[i
] * i
;
7202 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7203 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7204 (nzero_counts
* 100.0) / nsyms
);
7212 if (buckets
!= NULL
)
7222 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7226 if (dynamic_syminfo
== NULL
7228 /* No syminfo, this is ok. */
7231 /* There better should be a dynamic symbol section. */
7232 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7236 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7237 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7239 printf (_(" Num: Name BoundTo Flags\n"));
7240 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7242 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7244 printf ("%4d: ", i
);
7245 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7246 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7248 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7251 switch (dynamic_syminfo
[i
].si_boundto
)
7253 case SYMINFO_BT_SELF
:
7254 fputs ("SELF ", stdout
);
7256 case SYMINFO_BT_PARENT
:
7257 fputs ("PARENT ", stdout
);
7260 if (dynamic_syminfo
[i
].si_boundto
> 0
7261 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7262 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7264 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7268 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7272 if (flags
& SYMINFO_FLG_DIRECT
)
7274 if (flags
& SYMINFO_FLG_PASSTHRU
)
7275 printf (" PASSTHRU");
7276 if (flags
& SYMINFO_FLG_COPY
)
7278 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7279 printf (" LAZYLOAD");
7287 #ifdef SUPPORT_DISASSEMBLY
7289 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7291 printf (_("\nAssembly dump of section %s\n"),
7292 SECTION_NAME (section
));
7294 /* XXX -- to be done --- XXX */
7301 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
7303 bfd_size_type bytes
;
7305 unsigned char *data
;
7306 unsigned char *start
;
7308 bytes
= section
->sh_size
;
7310 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7312 printf (_("\nSection '%s' has no data to dump.\n"),
7313 SECTION_NAME (section
));
7317 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7319 addr
= section
->sh_addr
;
7321 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7334 lbytes
= (bytes
> 16 ? 16 : bytes
);
7336 printf (" 0x%8.8lx ", (unsigned long) addr
);
7338 switch (elf_header
.e_ident
[EI_DATA
])
7342 for (j
= 15; j
>= 0; j
--)
7345 printf ("%2.2x", data
[j
]);
7355 for (j
= 0; j
< 16; j
++)
7358 printf ("%2.2x", data
[j
]);
7368 for (j
= 0; j
< lbytes
; j
++)
7371 if (k
>= ' ' && k
< 0x7f)
7389 /* Apply addends of RELA relocations. */
7392 debug_apply_rela_addends (void *file
,
7393 Elf_Internal_Shdr
*section
,
7394 unsigned char *start
)
7396 Elf_Internal_Shdr
*relsec
;
7397 unsigned char *end
= start
+ section
->sh_size
;
7398 /* FIXME: The relocation field size is relocation type dependent. */
7399 unsigned int reloc_size
= 4;
7401 if (!is_relocatable
)
7404 if (section
->sh_size
< reloc_size
)
7407 for (relsec
= section_headers
;
7408 relsec
< section_headers
+ elf_header
.e_shnum
;
7411 unsigned long nrelas
;
7412 Elf_Internal_Rela
*rela
, *rp
;
7413 Elf_Internal_Shdr
*symsec
;
7414 Elf_Internal_Sym
*symtab
;
7415 Elf_Internal_Sym
*sym
;
7417 if (relsec
->sh_type
!= SHT_RELA
7418 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7419 || SECTION_HEADER (relsec
->sh_info
) != section
7420 || relsec
->sh_size
== 0
7421 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7424 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7428 symsec
= SECTION_HEADER (relsec
->sh_link
);
7429 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7431 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7435 loc
= start
+ rp
->r_offset
;
7436 if ((loc
+ reloc_size
) > end
)
7438 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7439 (unsigned long) rp
->r_offset
,
7440 SECTION_NAME (section
));
7446 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7448 if (ELF32_R_SYM (rp
->r_info
) != 0
7449 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7450 /* Relocations against object symbols can happen,
7451 eg when referencing a global array. For an
7452 example of this see the _clz.o binary in libgcc.a. */
7453 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7455 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7456 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7457 SECTION_NAME (section
));
7463 /* In MIPS little-endian objects, r_info isn't really a
7464 64-bit little-endian value: it has a 32-bit little-endian
7465 symbol index followed by four individual byte fields.
7466 Reorder INFO accordingly. */
7467 if (elf_header
.e_machine
== EM_MIPS
7468 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7469 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7470 | ((rp
->r_info
>> 56) & 0xff)
7471 | ((rp
->r_info
>> 40) & 0xff00)
7472 | ((rp
->r_info
>> 24) & 0xff0000)
7473 | ((rp
->r_info
>> 8) & 0xff000000));
7475 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7477 if (ELF64_R_SYM (rp
->r_info
) != 0
7478 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7479 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7481 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7482 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7483 SECTION_NAME (section
));
7488 byte_put (loc
, rp
->r_addend
, reloc_size
);
7499 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
7501 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7502 Elf_Internal_Shdr
*sec
;
7505 /* If it is already loaded, do nothing. */
7506 if (section
->start
!= NULL
)
7509 /* Locate the debug section. */
7510 sec
= find_section (section
->name
);
7514 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
7515 section
->address
= sec
->sh_addr
;
7516 section
->size
= sec
->sh_size
;
7517 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
7520 if (debug_displays
[debug
].relocate
)
7521 debug_apply_rela_addends (file
, sec
, section
->start
);
7523 return section
->start
!= NULL
;
7527 free_debug_section (enum dwarf_section_display_enum debug
)
7529 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7531 if (section
->start
== NULL
)
7534 free ((char *) section
->start
);
7535 section
->start
= NULL
;
7536 section
->address
= 0;
7541 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
7543 char *name
= SECTION_NAME (section
);
7544 bfd_size_type length
;
7546 enum dwarf_section_display_enum i
;
7548 length
= section
->sh_size
;
7551 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7555 if (strneq (name
, ".gnu.linkonce.wi.", 17))
7556 name
= ".debug_info";
7558 /* See if we know how to display the contents of this section. */
7559 for (i
= 0; i
< max
; i
++)
7560 if (streq (debug_displays
[i
].section
.name
, name
))
7562 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
7564 if (load_debug_section (i
, file
))
7566 result
&= debug_displays
[i
].display (sec
, file
);
7568 if (i
!= info
&& i
!= abbrev
)
7569 free_debug_section (i
);
7577 printf (_("Unrecognized debug section: %s\n"), name
);
7584 /* Set DUMP_SECTS for all sections where dumps were requested
7585 based on section name. */
7588 initialise_dumps_byname (void)
7590 struct dump_list_entry
*cur
;
7592 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
7597 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
7598 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
7600 request_dump (i
, cur
->type
);
7605 warn (_("Section '%s' was not dumped because it does not exist!\n"),
7611 process_section_contents (FILE *file
)
7613 Elf_Internal_Shdr
*section
;
7619 initialise_dumps_byname ();
7621 for (i
= 0, section
= section_headers
;
7622 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
7625 #ifdef SUPPORT_DISASSEMBLY
7626 if (dump_sects
[i
] & DISASS_DUMP
)
7627 disassemble_section (section
, file
);
7629 if (dump_sects
[i
] & HEX_DUMP
)
7630 dump_section (section
, file
);
7632 if (dump_sects
[i
] & DEBUG_DUMP
)
7633 display_debug_section (section
, file
);
7636 /* Check to see if the user requested a
7637 dump of a section that does not exist. */
7638 while (i
++ < num_dump_sects
)
7640 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
7644 process_mips_fpe_exception (int mask
)
7649 if (mask
& OEX_FPU_INEX
)
7650 fputs ("INEX", stdout
), first
= 0;
7651 if (mask
& OEX_FPU_UFLO
)
7652 printf ("%sUFLO", first
? "" : "|"), first
= 0;
7653 if (mask
& OEX_FPU_OFLO
)
7654 printf ("%sOFLO", first
? "" : "|"), first
= 0;
7655 if (mask
& OEX_FPU_DIV0
)
7656 printf ("%sDIV0", first
? "" : "|"), first
= 0;
7657 if (mask
& OEX_FPU_INVAL
)
7658 printf ("%sINVAL", first
? "" : "|");
7661 fputs ("0", stdout
);
7664 /* ARM EABI attributes section. */
7669 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
7672 } arm_attr_public_tag
;
7674 static const char *arm_attr_tag_CPU_arch
[] =
7675 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
7677 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
7678 static const char *arm_attr_tag_THUMB_ISA_use
[] =
7679 {"No", "Thumb-1", "Thumb-2"};
7680 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2"};
7681 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
7682 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
7683 static const char *arm_attr_tag_ABI_PCS_config
[] =
7684 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
7685 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
7686 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
7687 {"V6", "SB", "TLS", "Unused"};
7688 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
7689 {"Absolute", "PC-relative", "SB-relative", "None"};
7690 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
7691 {"Absolute", "PC-relative", "None"};
7692 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
7693 {"None", "direct", "GOT-indirect"};
7694 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
7695 {"None", "??? 1", "2", "??? 3", "4"};
7696 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
7697 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
7698 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
7699 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
7700 static const char *arm_attr_tag_ABI_FP_number_model
[] =
7701 {"Unused", "Finite", "RTABI", "IEEE 754"};
7702 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
7703 static const char *arm_attr_tag_ABI_align8_preserved
[] =
7704 {"No", "Yes, except leaf SP", "Yes"};
7705 static const char *arm_attr_tag_ABI_enum_size
[] =
7706 {"Unused", "small", "int", "forced to int"};
7707 static const char *arm_attr_tag_ABI_HardFP_use
[] =
7708 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
7709 static const char *arm_attr_tag_ABI_VFP_args
[] =
7710 {"AAPCS", "VFP registers", "custom"};
7711 static const char *arm_attr_tag_ABI_WMMX_args
[] =
7712 {"AAPCS", "WMMX registers", "custom"};
7713 static const char *arm_attr_tag_ABI_optimization_goals
[] =
7714 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7715 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
7716 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
7717 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7718 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
7720 #define LOOKUP(id, name) \
7721 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
7722 static arm_attr_public_tag arm_attr_public_tags
[] =
7724 {4, "CPU_raw_name", 1, NULL
},
7725 {5, "CPU_name", 1, NULL
},
7726 LOOKUP(6, CPU_arch
),
7727 {7, "CPU_arch_profile", 0, NULL
},
7728 LOOKUP(8, ARM_ISA_use
),
7729 LOOKUP(9, THUMB_ISA_use
),
7730 LOOKUP(10, VFP_arch
),
7731 LOOKUP(11, WMMX_arch
),
7732 LOOKUP(12, NEON_arch
),
7733 LOOKUP(13, ABI_PCS_config
),
7734 LOOKUP(14, ABI_PCS_R9_use
),
7735 LOOKUP(15, ABI_PCS_RW_data
),
7736 LOOKUP(16, ABI_PCS_RO_DATA
),
7737 LOOKUP(17, ABI_PCS_GOT_use
),
7738 LOOKUP(18, ABI_PCS_wchar_t
),
7739 LOOKUP(19, ABI_FP_rounding
),
7740 LOOKUP(20, ABI_FP_denormal
),
7741 LOOKUP(21, ABI_FP_exceptions
),
7742 LOOKUP(22, ABI_FP_user_exceptions
),
7743 LOOKUP(23, ABI_FP_number_model
),
7744 LOOKUP(24, ABI_align8_needed
),
7745 LOOKUP(25, ABI_align8_preserved
),
7746 LOOKUP(26, ABI_enum_size
),
7747 LOOKUP(27, ABI_HardFP_use
),
7748 LOOKUP(28, ABI_VFP_args
),
7749 LOOKUP(29, ABI_WMMX_args
),
7750 LOOKUP(30, ABI_optimization_goals
),
7751 LOOKUP(31, ABI_FP_optimization_goals
),
7752 {32, "compatibility", 0, NULL
}
7756 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
7759 read_uleb128 (unsigned char *p
, unsigned int *plen
)
7773 val
|= ((unsigned int)c
& 0x7f) << shift
;
7782 static unsigned char *
7783 display_arm_attribute (unsigned char *p
)
7788 arm_attr_public_tag
*attr
;
7792 tag
= read_uleb128 (p
, &len
);
7795 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
7797 if (arm_attr_public_tags
[i
].tag
== tag
)
7799 attr
= &arm_attr_public_tags
[i
];
7806 printf (" Tag_%s: ", attr
->name
);
7812 case 7: /* Tag_CPU_arch_profile. */
7813 val
= read_uleb128 (p
, &len
);
7817 case 0: printf ("None\n"); break;
7818 case 'A': printf ("Application\n"); break;
7819 case 'R': printf ("Realtime\n"); break;
7820 case 'M': printf ("Microcontroller\n"); break;
7821 default: printf ("??? (%d)\n", val
); break;
7825 case 32: /* Tag_compatibility. */
7826 val
= read_uleb128 (p
, &len
);
7828 printf ("flag = %d, vendor = %s\n", val
, p
);
7829 p
+= strlen((char *)p
) + 1;
7843 assert (attr
->type
& 0x80);
7844 val
= read_uleb128 (p
, &len
);
7846 type
= attr
->type
& 0x7f;
7848 printf ("??? (%d)\n", val
);
7850 printf ("%s\n", attr
->table
[val
]);
7857 type
= 1; /* String. */
7859 type
= 2; /* uleb128. */
7860 printf (" Tag_unknown_%d: ", tag
);
7865 printf ("\"%s\"\n", p
);
7866 p
+= strlen((char *)p
) + 1;
7870 val
= read_uleb128 (p
, &len
);
7872 printf ("%d (0x%x)\n", val
, val
);
7879 process_arm_specific (FILE *file
)
7881 Elf_Internal_Shdr
*sect
;
7882 unsigned char *contents
;
7885 bfd_vma section_len
;
7889 /* Find the section header so that we get the size. */
7890 for (i
= 0, sect
= section_headers
;
7891 i
< elf_header
.e_shnum
;
7894 if (sect
->sh_type
!= SHT_ARM_ATTRIBUTES
)
7897 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
7905 len
= sect
->sh_size
- 1;
7910 bfd_boolean public_section
;
7912 section_len
= byte_get (p
, 4);
7914 if (section_len
> len
)
7916 printf (_("ERROR: Bad section length (%d > %d)\n"),
7917 (int)section_len
, (int)len
);
7921 printf ("Attribute Section: %s\n", p
);
7922 if (strcmp ((char *)p
, "aeabi") == 0)
7923 public_section
= TRUE
;
7925 public_section
= FALSE
;
7926 namelen
= strlen ((char *)p
) + 1;
7928 section_len
-= namelen
+ 4;
7929 while (section_len
> 0)
7934 size
= byte_get (p
, 4);
7935 if (size
> section_len
)
7937 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
7938 (int)size
, (int)section_len
);
7941 section_len
-= size
;
7947 printf ("File Attributes\n");
7950 printf ("Section Attributes:");
7953 printf ("Symbol Attributes:");
7958 val
= read_uleb128 (p
, &i
);
7962 printf (" %d", val
);
7967 printf ("Unknown tag: %d\n", tag
);
7968 public_section
= FALSE
;
7974 p
= display_arm_attribute(p
);
7978 /* ??? Do something sensible, like dump hex. */
7979 printf (" Unknown section contexts\n");
7987 printf (_("Unknown format '%c'\n"), *p
);
7996 process_mips_specific (FILE *file
)
7998 Elf_Internal_Dyn
*entry
;
7999 size_t liblist_offset
= 0;
8000 size_t liblistno
= 0;
8001 size_t conflictsno
= 0;
8002 size_t options_offset
= 0;
8003 size_t conflicts_offset
= 0;
8005 /* We have a lot of special sections. Thanks SGI! */
8006 if (dynamic_section
== NULL
)
8007 /* No information available. */
8010 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
8011 switch (entry
->d_tag
)
8013 case DT_MIPS_LIBLIST
:
8015 = offset_from_vma (file
, entry
->d_un
.d_val
,
8016 liblistno
* sizeof (Elf32_External_Lib
));
8018 case DT_MIPS_LIBLISTNO
:
8019 liblistno
= entry
->d_un
.d_val
;
8021 case DT_MIPS_OPTIONS
:
8022 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
8024 case DT_MIPS_CONFLICT
:
8026 = offset_from_vma (file
, entry
->d_un
.d_val
,
8027 conflictsno
* sizeof (Elf32_External_Conflict
));
8029 case DT_MIPS_CONFLICTNO
:
8030 conflictsno
= entry
->d_un
.d_val
;
8036 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
8038 Elf32_External_Lib
*elib
;
8041 elib
= get_data (NULL
, file
, liblist_offset
,
8042 liblistno
, sizeof (Elf32_External_Lib
),
8046 printf ("\nSection '.liblist' contains %lu entries:\n",
8047 (unsigned long) liblistno
);
8048 fputs (" Library Time Stamp Checksum Version Flags\n",
8051 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
8058 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8059 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8060 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8061 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8062 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8064 tmp
= gmtime (&time
);
8065 snprintf (timebuf
, sizeof (timebuf
),
8066 "%04u-%02u-%02uT%02u:%02u:%02u",
8067 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8068 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8070 printf ("%3lu: ", (unsigned long) cnt
);
8071 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
8072 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
8074 printf ("<corrupt: %9ld>", liblist
.l_name
);
8075 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
8078 if (liblist
.l_flags
== 0)
8089 { " EXACT_MATCH", LL_EXACT_MATCH
},
8090 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
8091 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
8092 { " EXPORTS", LL_EXPORTS
},
8093 { " DELAY_LOAD", LL_DELAY_LOAD
},
8094 { " DELTA", LL_DELTA
}
8096 int flags
= liblist
.l_flags
;
8100 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
8102 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
8104 fputs (l_flags_vals
[fcnt
].name
, stdout
);
8105 flags
^= l_flags_vals
[fcnt
].bit
;
8108 printf (" %#x", (unsigned int) flags
);
8118 if (options_offset
!= 0)
8120 Elf_External_Options
*eopt
;
8121 Elf_Internal_Shdr
*sect
= section_headers
;
8122 Elf_Internal_Options
*iopt
;
8123 Elf_Internal_Options
*option
;
8127 /* Find the section header so that we get the size. */
8128 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
8131 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
8135 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
8138 error (_("Out of memory"));
8145 while (offset
< sect
->sh_size
)
8147 Elf_External_Options
*eoption
;
8149 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
8151 option
->kind
= BYTE_GET (eoption
->kind
);
8152 option
->size
= BYTE_GET (eoption
->size
);
8153 option
->section
= BYTE_GET (eoption
->section
);
8154 option
->info
= BYTE_GET (eoption
->info
);
8156 offset
+= option
->size
;
8162 printf (_("\nSection '%s' contains %d entries:\n"),
8163 SECTION_NAME (sect
), cnt
);
8171 switch (option
->kind
)
8174 /* This shouldn't happen. */
8175 printf (" NULL %d %lx", option
->section
, option
->info
);
8178 printf (" REGINFO ");
8179 if (elf_header
.e_machine
== EM_MIPS
)
8182 Elf32_External_RegInfo
*ereg
;
8183 Elf32_RegInfo reginfo
;
8185 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
8186 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8187 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8188 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8189 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8190 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8191 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8193 printf ("GPR %08lx GP 0x%lx\n",
8195 (unsigned long) reginfo
.ri_gp_value
);
8196 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8197 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8198 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8203 Elf64_External_RegInfo
*ereg
;
8204 Elf64_Internal_RegInfo reginfo
;
8206 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
8207 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8208 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8209 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8210 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8211 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8212 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8214 printf ("GPR %08lx GP 0x",
8215 reginfo
.ri_gprmask
);
8216 printf_vma (reginfo
.ri_gp_value
);
8219 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8220 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8221 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8225 case ODK_EXCEPTIONS
:
8226 fputs (" EXCEPTIONS fpe_min(", stdout
);
8227 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
8228 fputs (") fpe_max(", stdout
);
8229 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
8230 fputs (")", stdout
);
8232 if (option
->info
& OEX_PAGE0
)
8233 fputs (" PAGE0", stdout
);
8234 if (option
->info
& OEX_SMM
)
8235 fputs (" SMM", stdout
);
8236 if (option
->info
& OEX_FPDBUG
)
8237 fputs (" FPDBUG", stdout
);
8238 if (option
->info
& OEX_DISMISS
)
8239 fputs (" DISMISS", stdout
);
8242 fputs (" PAD ", stdout
);
8243 if (option
->info
& OPAD_PREFIX
)
8244 fputs (" PREFIX", stdout
);
8245 if (option
->info
& OPAD_POSTFIX
)
8246 fputs (" POSTFIX", stdout
);
8247 if (option
->info
& OPAD_SYMBOL
)
8248 fputs (" SYMBOL", stdout
);
8251 fputs (" HWPATCH ", stdout
);
8252 if (option
->info
& OHW_R4KEOP
)
8253 fputs (" R4KEOP", stdout
);
8254 if (option
->info
& OHW_R8KPFETCH
)
8255 fputs (" R8KPFETCH", stdout
);
8256 if (option
->info
& OHW_R5KEOP
)
8257 fputs (" R5KEOP", stdout
);
8258 if (option
->info
& OHW_R5KCVTL
)
8259 fputs (" R5KCVTL", stdout
);
8262 fputs (" FILL ", stdout
);
8263 /* XXX Print content of info word? */
8266 fputs (" TAGS ", stdout
);
8267 /* XXX Print content of info word? */
8270 fputs (" HWAND ", stdout
);
8271 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8272 fputs (" R4KEOP_CHECKED", stdout
);
8273 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8274 fputs (" R4KEOP_CLEAN", stdout
);
8277 fputs (" HWOR ", stdout
);
8278 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8279 fputs (" R4KEOP_CHECKED", stdout
);
8280 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8281 fputs (" R4KEOP_CLEAN", stdout
);
8284 printf (" GP_GROUP %#06lx self-contained %#06lx",
8285 option
->info
& OGP_GROUP
,
8286 (option
->info
& OGP_SELF
) >> 16);
8289 printf (" IDENT %#06lx self-contained %#06lx",
8290 option
->info
& OGP_GROUP
,
8291 (option
->info
& OGP_SELF
) >> 16);
8294 /* This shouldn't happen. */
8295 printf (" %3d ??? %d %lx",
8296 option
->kind
, option
->section
, option
->info
);
8300 len
= sizeof (*eopt
);
8301 while (len
< option
->size
)
8302 if (((char *) option
)[len
] >= ' '
8303 && ((char *) option
)[len
] < 0x7f)
8304 printf ("%c", ((char *) option
)[len
++]);
8306 printf ("\\%03o", ((char *) option
)[len
++]);
8308 fputs ("\n", stdout
);
8316 if (conflicts_offset
!= 0 && conflictsno
!= 0)
8318 Elf32_Conflict
*iconf
;
8321 if (dynamic_symbols
== NULL
)
8323 error (_("conflict list found without a dynamic symbol table"));
8327 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
8330 error (_("Out of memory"));
8336 Elf32_External_Conflict
*econf32
;
8338 econf32
= get_data (NULL
, file
, conflicts_offset
,
8339 conflictsno
, sizeof (*econf32
), _("conflict"));
8343 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8344 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
8350 Elf64_External_Conflict
*econf64
;
8352 econf64
= get_data (NULL
, file
, conflicts_offset
,
8353 conflictsno
, sizeof (*econf64
), _("conflict"));
8357 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8358 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
8363 printf (_("\nSection '.conflict' contains %lu entries:\n"),
8364 (unsigned long) conflictsno
);
8365 puts (_(" Num: Index Value Name"));
8367 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8369 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
8371 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
8372 print_vma (psym
->st_value
, FULL_HEX
);
8374 if (VALID_DYNAMIC_NAME (psym
->st_name
))
8375 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
8377 printf ("<corrupt: %14ld>", psym
->st_name
);
8388 process_gnu_liblist (FILE *file
)
8390 Elf_Internal_Shdr
*section
, *string_sec
;
8391 Elf32_External_Lib
*elib
;
8400 for (i
= 0, section
= section_headers
;
8401 i
< elf_header
.e_shnum
;
8404 switch (section
->sh_type
)
8406 case SHT_GNU_LIBLIST
:
8407 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
8410 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
8415 string_sec
= SECTION_HEADER (section
->sh_link
);
8417 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
8418 string_sec
->sh_size
, _("liblist string table"));
8419 strtab_size
= string_sec
->sh_size
;
8422 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
8428 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
8429 SECTION_NAME (section
),
8430 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
8432 puts (" Library Time Stamp Checksum Version Flags");
8434 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
8442 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8443 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8444 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8445 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8446 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8448 tmp
= gmtime (&time
);
8449 snprintf (timebuf
, sizeof (timebuf
),
8450 "%04u-%02u-%02uT%02u:%02u:%02u",
8451 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8452 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8454 printf ("%3lu: ", (unsigned long) cnt
);
8456 printf ("%-20s", liblist
.l_name
< strtab_size
8457 ? strtab
+ liblist
.l_name
: "<corrupt>");
8459 printf ("%-20.20s", liblist
.l_name
< strtab_size
8460 ? strtab
+ liblist
.l_name
: "<corrupt>");
8461 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
8462 liblist
.l_version
, liblist
.l_flags
);
8473 get_note_type (unsigned e_type
)
8475 static char buff
[64];
8477 if (elf_header
.e_type
== ET_CORE
)
8481 return _("NT_AUXV (auxiliary vector)");
8483 return _("NT_PRSTATUS (prstatus structure)");
8485 return _("NT_FPREGSET (floating point registers)");
8487 return _("NT_PRPSINFO (prpsinfo structure)");
8489 return _("NT_TASKSTRUCT (task structure)");
8491 return _("NT_PRXFPREG (user_xfpregs structure)");
8493 return _("NT_PSTATUS (pstatus structure)");
8495 return _("NT_FPREGS (floating point registers)");
8497 return _("NT_PSINFO (psinfo structure)");
8499 return _("NT_LWPSTATUS (lwpstatus_t structure)");
8501 return _("NT_LWPSINFO (lwpsinfo_t structure)");
8502 case NT_WIN32PSTATUS
:
8503 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8511 return _("NT_VERSION (version)");
8513 return _("NT_ARCH (architecture)");
8518 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8523 get_netbsd_elfcore_note_type (unsigned e_type
)
8525 static char buff
[64];
8527 if (e_type
== NT_NETBSDCORE_PROCINFO
)
8529 /* NetBSD core "procinfo" structure. */
8530 return _("NetBSD procinfo structure");
8533 /* As of Jan 2002 there are no other machine-independent notes
8534 defined for NetBSD core files. If the note type is less
8535 than the start of the machine-dependent note types, we don't
8538 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
8540 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8544 switch (elf_header
.e_machine
)
8546 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8547 and PT_GETFPREGS == mach+2. */
8552 case EM_SPARC32PLUS
:
8556 case NT_NETBSDCORE_FIRSTMACH
+0:
8557 return _("PT_GETREGS (reg structure)");
8558 case NT_NETBSDCORE_FIRSTMACH
+2:
8559 return _("PT_GETFPREGS (fpreg structure)");
8565 /* On all other arch's, PT_GETREGS == mach+1 and
8566 PT_GETFPREGS == mach+3. */
8570 case NT_NETBSDCORE_FIRSTMACH
+1:
8571 return _("PT_GETREGS (reg structure)");
8572 case NT_NETBSDCORE_FIRSTMACH
+3:
8573 return _("PT_GETFPREGS (fpreg structure)");
8579 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
8580 e_type
- NT_NETBSDCORE_FIRSTMACH
);
8584 /* Note that by the ELF standard, the name field is already null byte
8585 terminated, and namesz includes the terminating null byte.
8586 I.E. the value of namesz for the name "FSF" is 4.
8588 If the value of namesz is zero, there is no name present. */
8590 process_note (Elf_Internal_Note
*pnote
)
8594 if (pnote
->namesz
== 0)
8595 /* If there is no note name, then use the default set of
8596 note type strings. */
8597 nt
= get_note_type (pnote
->type
);
8599 else if (strneq (pnote
->namedata
, "NetBSD-CORE", 11))
8600 /* NetBSD-specific core file notes. */
8601 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
8604 /* Don't recognize this note name; just use the default set of
8605 note type strings. */
8606 nt
= get_note_type (pnote
->type
);
8608 printf (" %s\t\t0x%08lx\t%s\n",
8609 pnote
->namesz
? pnote
->namedata
: "(NONE)",
8616 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
8618 Elf_External_Note
*pnotes
;
8619 Elf_External_Note
*external
;
8625 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
8631 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8632 (unsigned long) offset
, (unsigned long) length
);
8633 printf (_(" Owner\t\tData size\tDescription\n"));
8635 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
8637 Elf_External_Note
*next
;
8638 Elf_Internal_Note inote
;
8641 inote
.type
= BYTE_GET (external
->type
);
8642 inote
.namesz
= BYTE_GET (external
->namesz
);
8643 inote
.namedata
= external
->name
;
8644 inote
.descsz
= BYTE_GET (external
->descsz
);
8645 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
8646 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
8648 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
8650 if (((char *) next
) > (((char *) pnotes
) + length
))
8652 warn (_("corrupt note found at offset %lx into core notes\n"),
8653 (long)((char *)external
- (char *)pnotes
));
8654 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
8655 inote
.type
, inote
.namesz
, inote
.descsz
);
8661 /* Verify that name is null terminated. It appears that at least
8662 one version of Linux (RedHat 6.0) generates corefiles that don't
8663 comply with the ELF spec by failing to include the null byte in
8665 if (inote
.namedata
[inote
.namesz
] != '\0')
8667 temp
= malloc (inote
.namesz
+ 1);
8671 error (_("Out of memory\n"));
8676 strncpy (temp
, inote
.namedata
, inote
.namesz
);
8677 temp
[inote
.namesz
] = 0;
8679 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8680 inote
.namedata
= temp
;
8683 res
&= process_note (& inote
);
8698 process_corefile_note_segments (FILE *file
)
8700 Elf_Internal_Phdr
*segment
;
8704 if (! get_program_headers (file
))
8707 for (i
= 0, segment
= program_headers
;
8708 i
< elf_header
.e_phnum
;
8711 if (segment
->p_type
== PT_NOTE
)
8712 res
&= process_corefile_note_segment (file
,
8713 (bfd_vma
) segment
->p_offset
,
8714 (bfd_vma
) segment
->p_filesz
);
8721 process_note_sections (FILE *file
)
8723 Elf_Internal_Shdr
*section
;
8727 for (i
= 0, section
= section_headers
;
8728 i
< elf_header
.e_shnum
;
8730 if (section
->sh_type
== SHT_NOTE
)
8731 res
&= process_corefile_note_segment (file
,
8732 (bfd_vma
) section
->sh_offset
,
8733 (bfd_vma
) section
->sh_size
);
8739 process_notes (FILE *file
)
8741 /* If we have not been asked to display the notes then do nothing. */
8745 if (elf_header
.e_type
!= ET_CORE
)
8746 return process_note_sections (file
);
8748 /* No program headers means no NOTE segment. */
8749 if (elf_header
.e_phnum
> 0)
8750 return process_corefile_note_segments (file
);
8752 printf (_("No note segments present in the core file.\n"));
8757 process_arch_specific (FILE *file
)
8762 switch (elf_header
.e_machine
)
8765 return process_arm_specific (file
);
8767 case EM_MIPS_RS3_LE
:
8768 return process_mips_specific (file
);
8777 get_file_header (FILE *file
)
8779 /* Read in the identity array. */
8780 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
8783 /* Determine how to read the rest of the header. */
8784 switch (elf_header
.e_ident
[EI_DATA
])
8786 default: /* fall through */
8787 case ELFDATANONE
: /* fall through */
8789 byte_get
= byte_get_little_endian
;
8790 byte_put
= byte_put_little_endian
;
8793 byte_get
= byte_get_big_endian
;
8794 byte_put
= byte_put_big_endian
;
8798 /* For now we only support 32 bit and 64 bit ELF files. */
8799 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
8801 /* Read in the rest of the header. */
8804 Elf32_External_Ehdr ehdr32
;
8806 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
8809 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
8810 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
8811 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
8812 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
8813 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
8814 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
8815 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
8816 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
8817 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
8818 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
8819 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
8820 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
8821 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
8825 Elf64_External_Ehdr ehdr64
;
8827 /* If we have been compiled with sizeof (bfd_vma) == 4, then
8828 we will not be able to cope with the 64bit data found in
8829 64 ELF files. Detect this now and abort before we start
8830 overwriting things. */
8831 if (sizeof (bfd_vma
) < 8)
8833 error (_("This instance of readelf has been built without support for a\n\
8834 64 bit data type and so it cannot read 64 bit ELF files.\n"));
8838 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
8841 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
8842 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
8843 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
8844 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
8845 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
8846 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
8847 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
8848 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
8849 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
8850 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
8851 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
8852 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
8853 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
8856 if (elf_header
.e_shoff
)
8858 /* There may be some extensions in the first section header. Don't
8859 bomb if we can't read it. */
8861 get_32bit_section_headers (file
, 1);
8863 get_64bit_section_headers (file
, 1);
8866 is_relocatable
= elf_header
.e_type
== ET_REL
;
8871 /* Process one ELF object file according to the command line options.
8872 This file may actually be stored in an archive. The file is
8873 positioned at the start of the ELF object. */
8876 process_object (char *file_name
, FILE *file
)
8880 if (! get_file_header (file
))
8882 error (_("%s: Failed to read file header\n"), file_name
);
8886 /* Initialise per file variables. */
8887 for (i
= NUM_ELEM (version_info
); i
--;)
8888 version_info
[i
] = 0;
8890 for (i
= NUM_ELEM (dynamic_info
); i
--;)
8891 dynamic_info
[i
] = 0;
8893 /* Process the file. */
8895 printf (_("\nFile: %s\n"), file_name
);
8897 /* Initialise the dump_sects array from the cmdline_dump_sects array.
8898 Note we do this even if cmdline_dump_sects is empty because we
8899 must make sure that the dump_sets array is zeroed out before each
8900 object file is processed. */
8901 if (num_dump_sects
> num_cmdline_dump_sects
)
8902 memset (dump_sects
, 0, num_dump_sects
);
8904 if (num_cmdline_dump_sects
> 0)
8906 if (num_dump_sects
== 0)
8907 /* A sneaky way of allocating the dump_sects array. */
8908 request_dump (num_cmdline_dump_sects
, 0);
8910 assert (num_dump_sects
>= num_cmdline_dump_sects
);
8911 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
8914 if (! process_file_header ())
8917 if (! process_section_headers (file
))
8919 /* Without loaded section headers we cannot process lots of
8921 do_unwind
= do_version
= do_dump
= do_arch
= 0;
8923 if (! do_using_dynamic
)
8924 do_syms
= do_reloc
= 0;
8927 if (! process_section_groups (file
))
8929 /* Without loaded section groups we cannot process unwind. */
8933 if (process_program_headers (file
))
8934 process_dynamic_section (file
);
8936 process_relocs (file
);
8938 process_unwind (file
);
8940 process_symbol_table (file
);
8942 process_syminfo (file
);
8944 process_version_sections (file
);
8946 process_section_contents (file
);
8948 process_notes (file
);
8950 process_gnu_liblist (file
);
8952 process_arch_specific (file
);
8954 if (program_headers
)
8956 free (program_headers
);
8957 program_headers
= NULL
;
8960 if (section_headers
)
8962 free (section_headers
);
8963 section_headers
= NULL
;
8968 free (string_table
);
8969 string_table
= NULL
;
8970 string_table_length
= 0;
8973 if (dynamic_strings
)
8975 free (dynamic_strings
);
8976 dynamic_strings
= NULL
;
8977 dynamic_strings_length
= 0;
8980 if (dynamic_symbols
)
8982 free (dynamic_symbols
);
8983 dynamic_symbols
= NULL
;
8984 num_dynamic_syms
= 0;
8987 if (dynamic_syminfo
)
8989 free (dynamic_syminfo
);
8990 dynamic_syminfo
= NULL
;
8993 if (section_headers_groups
)
8995 free (section_headers_groups
);
8996 section_headers_groups
= NULL
;
9001 struct group_list
*g
, *next
;
9003 for (i
= 0; i
< group_count
; i
++)
9005 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
9012 free (section_groups
);
9013 section_groups
= NULL
;
9016 free_debug_memory ();
9021 /* Process an ELF archive. The file is positioned just after the
9025 process_archive (char *file_name
, FILE *file
)
9027 struct ar_hdr arhdr
;
9030 char *longnames
= NULL
;
9031 unsigned long longnames_size
= 0;
9032 size_t file_name_size
;
9037 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9038 if (got
!= sizeof arhdr
)
9043 error (_("%s: failed to read archive header\n"), file_name
);
9047 if (memcmp (arhdr
.ar_name
, "/ ", 16) == 0)
9049 /* This is the archive symbol table. Skip it.
9050 FIXME: We should have an option to dump it. */
9051 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9052 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
9054 error (_("%s: failed to skip archive symbol table\n"), file_name
);
9058 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9059 if (got
!= sizeof arhdr
)
9064 error (_("%s: failed to read archive header\n"), file_name
);
9069 if (memcmp (arhdr
.ar_name
, "// ", 16) == 0)
9071 /* This is the archive string table holding long member
9074 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9076 longnames
= malloc (longnames_size
);
9077 if (longnames
== NULL
)
9079 error (_("Out of memory\n"));
9083 if (fread (longnames
, longnames_size
, 1, file
) != 1)
9086 error (_("%s: failed to read string table\n"), file_name
);
9090 if ((longnames_size
& 1) != 0)
9093 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9094 if (got
!= sizeof arhdr
)
9101 error (_("%s: failed to read archive header\n"), file_name
);
9106 file_name_size
= strlen (file_name
);
9115 if (arhdr
.ar_name
[0] == '/')
9119 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
9120 if (off
>= longnames_size
)
9122 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
9127 name
= longnames
+ off
;
9128 nameend
= memchr (name
, '/', longnames_size
- off
);
9132 name
= arhdr
.ar_name
;
9133 nameend
= memchr (name
, '/', 16);
9136 if (nameend
== NULL
)
9138 error (_("%s: bad archive file name\n"), file_name
);
9143 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
9144 if (namealc
== NULL
)
9146 error (_("Out of memory\n"));
9151 memcpy (namealc
, file_name
, file_name_size
);
9152 namealc
[file_name_size
] = '(';
9153 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
9154 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
9155 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
9157 archive_file_offset
= ftell (file
);
9158 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9160 ret
|= process_object (namealc
, file
);
9165 (archive_file_offset
9167 + (archive_file_size
& 1)),
9170 error (_("%s: failed to seek to next archive header\n"), file_name
);
9175 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9176 if (got
!= sizeof arhdr
)
9181 error (_("%s: failed to read archive header\n"), file_name
);
9194 process_file (char *file_name
)
9197 struct stat statbuf
;
9201 if (stat (file_name
, &statbuf
) < 0)
9203 if (errno
== ENOENT
)
9204 error (_("'%s': No such file\n"), file_name
);
9206 error (_("Could not locate '%s'. System error message: %s\n"),
9207 file_name
, strerror (errno
));
9211 if (! S_ISREG (statbuf
.st_mode
))
9213 error (_("'%s' is not an ordinary file\n"), file_name
);
9217 file
= fopen (file_name
, "rb");
9220 error (_("Input file '%s' is not readable.\n"), file_name
);
9224 if (fread (armag
, SARMAG
, 1, file
) != 1)
9226 error (_("%s: Failed to read file header\n"), file_name
);
9231 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
9232 ret
= process_archive (file_name
, file
);
9236 archive_file_size
= archive_file_offset
= 0;
9237 ret
= process_object (file_name
, file
);
9245 #ifdef SUPPORT_DISASSEMBLY
9246 /* Needed by the i386 disassembler. For extra credit, someone could
9247 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9251 print_address (unsigned int addr
, FILE *outfile
)
9253 fprintf (outfile
,"0x%8.8x", addr
);
9256 /* Needed by the i386 disassembler. */
9258 db_task_printsym (unsigned int addr
)
9260 print_address (addr
, stderr
);
9265 main (int argc
, char **argv
)
9269 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9270 setlocale (LC_MESSAGES
, "");
9272 #if defined (HAVE_SETLOCALE)
9273 setlocale (LC_CTYPE
, "");
9275 bindtextdomain (PACKAGE
, LOCALEDIR
);
9276 textdomain (PACKAGE
);
9278 expandargv (&argc
, &argv
);
9280 parse_args (argc
, argv
);
9282 if (num_dump_sects
> 0)
9284 /* Make a copy of the dump_sects array. */
9285 cmdline_dump_sects
= malloc (num_dump_sects
);
9286 if (cmdline_dump_sects
== NULL
)
9287 error (_("Out of memory allocating dump request table."));
9290 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
9291 num_cmdline_dump_sects
= num_dump_sects
;
9295 if (optind
< (argc
- 1))
9299 while (optind
< argc
)
9300 err
|= process_file (argv
[optind
++]);
9302 if (dump_sects
!= NULL
)
9304 if (cmdline_dump_sects
!= NULL
)
9305 free (cmdline_dump_sects
);