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_ms1_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_MS1
: return "Morpho Techologies MS1 processor";
1692 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_machine
);
1698 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1703 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1704 e_flags
&= ~ EF_ARM_EABIMASK
;
1706 /* Handle "generic" ARM flags. */
1707 if (e_flags
& EF_ARM_RELEXEC
)
1709 strcat (buf
, ", relocatable executable");
1710 e_flags
&= ~ EF_ARM_RELEXEC
;
1713 if (e_flags
& EF_ARM_HASENTRY
)
1715 strcat (buf
, ", has entry point");
1716 e_flags
&= ~ EF_ARM_HASENTRY
;
1719 /* Now handle EABI specific flags. */
1723 strcat (buf
, ", <unrecognized EABI>");
1728 case EF_ARM_EABI_VER1
:
1729 strcat (buf
, ", Version1 EABI");
1734 /* Process flags one bit at a time. */
1735 flag
= e_flags
& - e_flags
;
1740 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1741 strcat (buf
, ", sorted symbol tables");
1751 case EF_ARM_EABI_VER2
:
1752 strcat (buf
, ", Version2 EABI");
1757 /* Process flags one bit at a time. */
1758 flag
= e_flags
& - e_flags
;
1763 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1764 strcat (buf
, ", sorted symbol tables");
1767 case EF_ARM_DYNSYMSUSESEGIDX
:
1768 strcat (buf
, ", dynamic symbols use segment index");
1771 case EF_ARM_MAPSYMSFIRST
:
1772 strcat (buf
, ", mapping symbols precede others");
1782 case EF_ARM_EABI_VER3
:
1783 strcat (buf
, ", Version3 EABI");
1786 case EF_ARM_EABI_VER4
:
1787 strcat (buf
, ", Version4 EABI");
1792 /* Process flags one bit at a time. */
1793 flag
= e_flags
& - e_flags
;
1799 strcat (buf
, ", BE8");
1803 strcat (buf
, ", LE8");
1813 case EF_ARM_EABI_UNKNOWN
:
1814 strcat (buf
, ", GNU EABI");
1819 /* Process flags one bit at a time. */
1820 flag
= e_flags
& - e_flags
;
1825 case EF_ARM_INTERWORK
:
1826 strcat (buf
, ", interworking enabled");
1829 case EF_ARM_APCS_26
:
1830 strcat (buf
, ", uses APCS/26");
1833 case EF_ARM_APCS_FLOAT
:
1834 strcat (buf
, ", uses APCS/float");
1838 strcat (buf
, ", position independent");
1842 strcat (buf
, ", 8 bit structure alignment");
1845 case EF_ARM_NEW_ABI
:
1846 strcat (buf
, ", uses new ABI");
1849 case EF_ARM_OLD_ABI
:
1850 strcat (buf
, ", uses old ABI");
1853 case EF_ARM_SOFT_FLOAT
:
1854 strcat (buf
, ", software FP");
1857 case EF_ARM_VFP_FLOAT
:
1858 strcat (buf
, ", VFP");
1861 case EF_ARM_MAVERICK_FLOAT
:
1862 strcat (buf
, ", Maverick FP");
1873 strcat (buf
,", <unknown>");
1877 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1879 static char buf
[1024];
1891 decode_ARM_machine_flags (e_flags
, buf
);
1895 switch (e_flags
& EF_FRV_CPU_MASK
)
1897 case EF_FRV_CPU_GENERIC
:
1901 strcat (buf
, ", fr???");
1904 case EF_FRV_CPU_FR300
:
1905 strcat (buf
, ", fr300");
1908 case EF_FRV_CPU_FR400
:
1909 strcat (buf
, ", fr400");
1911 case EF_FRV_CPU_FR405
:
1912 strcat (buf
, ", fr405");
1915 case EF_FRV_CPU_FR450
:
1916 strcat (buf
, ", fr450");
1919 case EF_FRV_CPU_FR500
:
1920 strcat (buf
, ", fr500");
1922 case EF_FRV_CPU_FR550
:
1923 strcat (buf
, ", fr550");
1926 case EF_FRV_CPU_SIMPLE
:
1927 strcat (buf
, ", simple");
1929 case EF_FRV_CPU_TOMCAT
:
1930 strcat (buf
, ", tomcat");
1936 if (e_flags
& EF_CPU32
)
1937 strcat (buf
, ", cpu32");
1938 if (e_flags
& EF_M68000
)
1939 strcat (buf
, ", m68000");
1943 if (e_flags
& EF_PPC_EMB
)
1944 strcat (buf
, ", emb");
1946 if (e_flags
& EF_PPC_RELOCATABLE
)
1947 strcat (buf
, ", relocatable");
1949 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1950 strcat (buf
, ", relocatable-lib");
1954 case EM_CYGNUS_V850
:
1955 switch (e_flags
& EF_V850_ARCH
)
1958 strcat (buf
, ", v850e1");
1961 strcat (buf
, ", v850e");
1964 strcat (buf
, ", v850");
1967 strcat (buf
, ", unknown v850 architecture variant");
1973 case EM_CYGNUS_M32R
:
1974 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1975 strcat (buf
, ", m32r");
1980 case EM_MIPS_RS3_LE
:
1981 if (e_flags
& EF_MIPS_NOREORDER
)
1982 strcat (buf
, ", noreorder");
1984 if (e_flags
& EF_MIPS_PIC
)
1985 strcat (buf
, ", pic");
1987 if (e_flags
& EF_MIPS_CPIC
)
1988 strcat (buf
, ", cpic");
1990 if (e_flags
& EF_MIPS_UCODE
)
1991 strcat (buf
, ", ugen_reserved");
1993 if (e_flags
& EF_MIPS_ABI2
)
1994 strcat (buf
, ", abi2");
1996 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
1997 strcat (buf
, ", odk first");
1999 if (e_flags
& EF_MIPS_32BITMODE
)
2000 strcat (buf
, ", 32bitmode");
2002 switch ((e_flags
& EF_MIPS_MACH
))
2004 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2005 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2006 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2007 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2008 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2009 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2010 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2011 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2012 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2013 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2015 /* We simply ignore the field in this case to avoid confusion:
2016 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2019 default: strcat (buf
, ", unknown CPU"); break;
2022 switch ((e_flags
& EF_MIPS_ABI
))
2024 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2025 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2026 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2027 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2029 /* We simply ignore the field in this case to avoid confusion:
2030 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2031 This means it is likely to be an o32 file, but not for
2034 default: strcat (buf
, ", unknown ABI"); break;
2037 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2038 strcat (buf
, ", mdmx");
2040 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2041 strcat (buf
, ", mips16");
2043 switch ((e_flags
& EF_MIPS_ARCH
))
2045 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2046 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2047 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2048 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2049 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2050 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2051 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2052 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2053 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2054 default: strcat (buf
, ", unknown ISA"); break;
2060 switch ((e_flags
& EF_SH_MACH_MASK
))
2062 case EF_SH1
: strcat (buf
, ", sh1"); break;
2063 case EF_SH2
: strcat (buf
, ", sh2"); break;
2064 case EF_SH3
: strcat (buf
, ", sh3"); break;
2065 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2066 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2067 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2068 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2069 case EF_SH4
: strcat (buf
, ", sh4"); break;
2070 case EF_SH5
: strcat (buf
, ", sh5"); break;
2071 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2072 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2073 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2074 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2075 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2076 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2077 default: strcat (buf
, ", unknown ISA"); break;
2083 if (e_flags
& EF_SPARC_32PLUS
)
2084 strcat (buf
, ", v8+");
2086 if (e_flags
& EF_SPARC_SUN_US1
)
2087 strcat (buf
, ", ultrasparcI");
2089 if (e_flags
& EF_SPARC_SUN_US3
)
2090 strcat (buf
, ", ultrasparcIII");
2092 if (e_flags
& EF_SPARC_HAL_R1
)
2093 strcat (buf
, ", halr1");
2095 if (e_flags
& EF_SPARC_LEDATA
)
2096 strcat (buf
, ", ledata");
2098 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2099 strcat (buf
, ", tso");
2101 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2102 strcat (buf
, ", pso");
2104 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2105 strcat (buf
, ", rmo");
2109 switch (e_flags
& EF_PARISC_ARCH
)
2111 case EFA_PARISC_1_0
:
2112 strcpy (buf
, ", PA-RISC 1.0");
2114 case EFA_PARISC_1_1
:
2115 strcpy (buf
, ", PA-RISC 1.1");
2117 case EFA_PARISC_2_0
:
2118 strcpy (buf
, ", PA-RISC 2.0");
2123 if (e_flags
& EF_PARISC_TRAPNIL
)
2124 strcat (buf
, ", trapnil");
2125 if (e_flags
& EF_PARISC_EXT
)
2126 strcat (buf
, ", ext");
2127 if (e_flags
& EF_PARISC_LSB
)
2128 strcat (buf
, ", lsb");
2129 if (e_flags
& EF_PARISC_WIDE
)
2130 strcat (buf
, ", wide");
2131 if (e_flags
& EF_PARISC_NO_KABP
)
2132 strcat (buf
, ", no kabp");
2133 if (e_flags
& EF_PARISC_LAZYSWAP
)
2134 strcat (buf
, ", lazyswap");
2139 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2140 strcat (buf
, ", new calling convention");
2142 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2143 strcat (buf
, ", gnu calling convention");
2147 if ((e_flags
& EF_IA_64_ABI64
))
2148 strcat (buf
, ", 64-bit");
2150 strcat (buf
, ", 32-bit");
2151 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2152 strcat (buf
, ", reduced fp model");
2153 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2154 strcat (buf
, ", no function descriptors, constant gp");
2155 else if ((e_flags
& EF_IA_64_CONS_GP
))
2156 strcat (buf
, ", constant gp");
2157 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2158 strcat (buf
, ", absolute");
2162 if ((e_flags
& EF_VAX_NONPIC
))
2163 strcat (buf
, ", non-PIC");
2164 if ((e_flags
& EF_VAX_DFLOAT
))
2165 strcat (buf
, ", D-Float");
2166 if ((e_flags
& EF_VAX_GFLOAT
))
2167 strcat (buf
, ", G-Float");
2176 get_osabi_name (unsigned int osabi
)
2178 static char buff
[32];
2182 case ELFOSABI_NONE
: return "UNIX - System V";
2183 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2184 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2185 case ELFOSABI_LINUX
: return "UNIX - Linux";
2186 case ELFOSABI_HURD
: return "GNU/Hurd";
2187 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2188 case ELFOSABI_AIX
: return "UNIX - AIX";
2189 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2190 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2191 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2192 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2193 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2194 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2195 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2196 case ELFOSABI_AROS
: return "Amiga Research OS";
2197 case ELFOSABI_STANDALONE
: return _("Standalone App");
2198 case ELFOSABI_ARM
: return "ARM";
2200 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2206 get_arm_segment_type (unsigned long type
)
2220 get_mips_segment_type (unsigned long type
)
2224 case PT_MIPS_REGINFO
:
2226 case PT_MIPS_RTPROC
:
2228 case PT_MIPS_OPTIONS
:
2238 get_parisc_segment_type (unsigned long type
)
2242 case PT_HP_TLS
: return "HP_TLS";
2243 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2244 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2245 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2246 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2247 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2248 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2249 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2250 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2251 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2252 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2253 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2254 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2255 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2256 case PT_HP_STACK
: return "HP_STACK";
2257 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2258 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2259 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2260 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2269 get_ia64_segment_type (unsigned long type
)
2273 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2274 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2275 case PT_HP_TLS
: return "HP_TLS";
2276 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2277 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2278 case PT_IA_64_HP_STACK
: return "HP_STACK";
2287 get_segment_type (unsigned long p_type
)
2289 static char buff
[32];
2293 case PT_NULL
: return "NULL";
2294 case PT_LOAD
: return "LOAD";
2295 case PT_DYNAMIC
: return "DYNAMIC";
2296 case PT_INTERP
: return "INTERP";
2297 case PT_NOTE
: return "NOTE";
2298 case PT_SHLIB
: return "SHLIB";
2299 case PT_PHDR
: return "PHDR";
2300 case PT_TLS
: return "TLS";
2302 case PT_GNU_EH_FRAME
:
2303 return "GNU_EH_FRAME";
2304 case PT_GNU_STACK
: return "GNU_STACK";
2305 case PT_GNU_RELRO
: return "GNU_RELRO";
2308 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2312 switch (elf_header
.e_machine
)
2315 result
= get_arm_segment_type (p_type
);
2318 case EM_MIPS_RS3_LE
:
2319 result
= get_mips_segment_type (p_type
);
2322 result
= get_parisc_segment_type (p_type
);
2325 result
= get_ia64_segment_type (p_type
);
2335 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2337 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2341 switch (elf_header
.e_machine
)
2344 result
= get_parisc_segment_type (p_type
);
2347 result
= get_ia64_segment_type (p_type
);
2357 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2360 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2367 get_mips_section_type_name (unsigned int sh_type
)
2371 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2372 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2373 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2374 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2375 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2376 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2377 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2378 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2379 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2380 case SHT_MIPS_RELD
: return "MIPS_RELD";
2381 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2382 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2383 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2384 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2385 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2386 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2387 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2388 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2389 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2390 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2391 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2392 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2393 case SHT_MIPS_LINE
: return "MIPS_LINE";
2394 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2395 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2396 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2397 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2398 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2399 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2400 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2401 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2402 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2403 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2404 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2405 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2406 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2407 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2408 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2409 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2417 get_parisc_section_type_name (unsigned int sh_type
)
2421 case SHT_PARISC_EXT
: return "PARISC_EXT";
2422 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2423 case SHT_PARISC_DOC
: return "PARISC_DOC";
2424 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2425 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2426 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2427 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2435 get_ia64_section_type_name (unsigned int sh_type
)
2437 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2438 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2439 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2443 case SHT_IA_64_EXT
: return "IA_64_EXT";
2444 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2445 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2453 get_x86_64_section_type_name (unsigned int sh_type
)
2457 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2465 get_arm_section_type_name (unsigned int sh_type
)
2471 case SHT_ARM_PREEMPTMAP
:
2472 return "ARM_PREEMPTMAP";
2473 case SHT_ARM_ATTRIBUTES
:
2474 return "ARM_ATTRIBUTES";
2482 get_section_type_name (unsigned int sh_type
)
2484 static char buff
[32];
2488 case SHT_NULL
: return "NULL";
2489 case SHT_PROGBITS
: return "PROGBITS";
2490 case SHT_SYMTAB
: return "SYMTAB";
2491 case SHT_STRTAB
: return "STRTAB";
2492 case SHT_RELA
: return "RELA";
2493 case SHT_HASH
: return "HASH";
2494 case SHT_DYNAMIC
: return "DYNAMIC";
2495 case SHT_NOTE
: return "NOTE";
2496 case SHT_NOBITS
: return "NOBITS";
2497 case SHT_REL
: return "REL";
2498 case SHT_SHLIB
: return "SHLIB";
2499 case SHT_DYNSYM
: return "DYNSYM";
2500 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2501 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2502 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2503 case SHT_GROUP
: return "GROUP";
2504 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2505 case SHT_GNU_verdef
: return "VERDEF";
2506 case SHT_GNU_verneed
: return "VERNEED";
2507 case SHT_GNU_versym
: return "VERSYM";
2508 case 0x6ffffff0: return "VERSYM";
2509 case 0x6ffffffc: return "VERDEF";
2510 case 0x7ffffffd: return "AUXILIARY";
2511 case 0x7fffffff: return "FILTER";
2512 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2515 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2519 switch (elf_header
.e_machine
)
2522 case EM_MIPS_RS3_LE
:
2523 result
= get_mips_section_type_name (sh_type
);
2526 result
= get_parisc_section_type_name (sh_type
);
2529 result
= get_ia64_section_type_name (sh_type
);
2532 result
= get_x86_64_section_type_name (sh_type
);
2535 result
= get_arm_section_type_name (sh_type
);
2545 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2547 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2548 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2549 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2550 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2552 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2558 #define OPTION_DEBUG_DUMP 512
2560 static struct option options
[] =
2562 {"all", no_argument
, 0, 'a'},
2563 {"file-header", no_argument
, 0, 'h'},
2564 {"program-headers", no_argument
, 0, 'l'},
2565 {"headers", no_argument
, 0, 'e'},
2566 {"histogram", no_argument
, 0, 'I'},
2567 {"segments", no_argument
, 0, 'l'},
2568 {"sections", no_argument
, 0, 'S'},
2569 {"section-headers", no_argument
, 0, 'S'},
2570 {"section-groups", no_argument
, 0, 'g'},
2571 {"section-details", no_argument
, 0, 't'},
2572 {"full-section-name",no_argument
, 0, 'N'},
2573 {"symbols", no_argument
, 0, 's'},
2574 {"syms", no_argument
, 0, 's'},
2575 {"relocs", no_argument
, 0, 'r'},
2576 {"notes", no_argument
, 0, 'n'},
2577 {"dynamic", no_argument
, 0, 'd'},
2578 {"arch-specific", no_argument
, 0, 'A'},
2579 {"version-info", no_argument
, 0, 'V'},
2580 {"use-dynamic", no_argument
, 0, 'D'},
2581 {"hex-dump", required_argument
, 0, 'x'},
2582 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2583 {"unwind", no_argument
, 0, 'u'},
2584 #ifdef SUPPORT_DISASSEMBLY
2585 {"instruction-dump", required_argument
, 0, 'i'},
2588 {"version", no_argument
, 0, 'v'},
2589 {"wide", no_argument
, 0, 'W'},
2590 {"help", no_argument
, 0, 'H'},
2591 {0, no_argument
, 0, 0}
2597 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2598 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2599 fprintf (stdout
, _(" Options are:\n\
2600 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2601 -h --file-header Display the ELF file header\n\
2602 -l --program-headers Display the program headers\n\
2603 --segments An alias for --program-headers\n\
2604 -S --section-headers Display the sections' header\n\
2605 --sections An alias for --section-headers\n\
2606 -g --section-groups Display the section groups\n\
2607 -t --section-details Display the section details\n\
2608 -e --headers Equivalent to: -h -l -S\n\
2609 -s --syms Display the symbol table\n\
2610 --symbols An alias for --syms\n\
2611 -n --notes Display the core notes (if present)\n\
2612 -r --relocs Display the relocations (if present)\n\
2613 -u --unwind Display the unwind info (if present)\n\
2614 -d --dynamic Display the dynamic section (if present)\n\
2615 -V --version-info Display the version sections (if present)\n\
2616 -A --arch-specific Display architecture specific information (if any).\n\
2617 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2618 -x --hex-dump=<number> Dump the contents of section <number>\n\
2619 -w[liaprmfFsoR] or\n\
2620 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2621 Display the contents of DWARF2 debug sections\n"));
2622 #ifdef SUPPORT_DISASSEMBLY
2623 fprintf (stdout
, _("\
2624 -i --instruction-dump=<number>\n\
2625 Disassemble the contents of section <number>\n"));
2627 fprintf (stdout
, _("\
2628 -I --histogram Display histogram of bucket list lengths\n\
2629 -W --wide Allow output width to exceed 80 characters\n\
2630 @<file> Read options from <file>\n\
2631 -H --help Display this information\n\
2632 -v --version Display the version number of readelf\n"));
2633 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2638 /* Record the fact that the user wants the contents of section number
2639 SECTION to be displayed using the method(s) encoded as flags bits
2640 in TYPE. Note, TYPE can be zero if we are creating the array for
2644 request_dump (unsigned int section
, int type
)
2646 if (section
>= num_dump_sects
)
2648 char *new_dump_sects
;
2650 new_dump_sects
= calloc (section
+ 1, 1);
2652 if (new_dump_sects
== NULL
)
2653 error (_("Out of memory allocating dump request table."));
2656 /* Copy current flag settings. */
2657 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2661 dump_sects
= new_dump_sects
;
2662 num_dump_sects
= section
+ 1;
2667 dump_sects
[section
] |= type
;
2672 /* Request a dump by section name. */
2675 request_dump_byname (const char *section
, int type
)
2677 struct dump_list_entry
*new_request
;
2679 new_request
= malloc (sizeof (struct dump_list_entry
));
2681 error (_("Out of memory allocating dump request table."));
2683 new_request
->name
= strdup (section
);
2684 if (!new_request
->name
)
2685 error (_("Out of memory allocating dump request table."));
2687 new_request
->type
= type
;
2689 new_request
->next
= dump_sects_byname
;
2690 dump_sects_byname
= new_request
;
2694 parse_args (int argc
, char **argv
)
2701 while ((c
= getopt_long
2702 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWH", options
, NULL
)) != EOF
)
2723 do_section_groups
++;
2731 do_section_groups
++;
2736 do_section_details
++;
2778 section
= strtoul (optarg
, & cp
, 0);
2779 if (! *cp
&& section
>= 0)
2780 request_dump (section
, HEX_DUMP
);
2782 request_dump_byname (optarg
, HEX_DUMP
);
2790 unsigned int index
= 0;
2794 while (optarg
[index
])
2795 switch (optarg
[index
++])
2804 do_debug_abbrevs
= 1;
2814 do_debug_pubnames
= 1;
2818 do_debug_aranges
= 1;
2822 do_debug_ranges
= 1;
2826 do_debug_frames_interp
= 1;
2828 do_debug_frames
= 1;
2833 do_debug_macinfo
= 1;
2847 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2852 case OPTION_DEBUG_DUMP
:
2860 const char * option
;
2863 debug_dump_long_opts
;
2865 debug_dump_long_opts opts_table
[] =
2867 /* Please keep this table alpha- sorted. */
2868 { "Ranges", & do_debug_ranges
},
2869 { "abbrev", & do_debug_abbrevs
},
2870 { "aranges", & do_debug_aranges
},
2871 { "frames", & do_debug_frames
},
2872 { "frames-interp", & do_debug_frames_interp
},
2873 { "info", & do_debug_info
},
2874 { "line", & do_debug_lines
},
2875 { "loc", & do_debug_loc
},
2876 { "macro", & do_debug_macinfo
},
2877 { "pubnames", & do_debug_pubnames
},
2878 /* This entry is for compatability
2879 with earlier versions of readelf. */
2880 { "ranges", & do_debug_aranges
},
2881 { "str", & do_debug_str
},
2892 debug_dump_long_opts
* entry
;
2894 for (entry
= opts_table
; entry
->option
; entry
++)
2896 size_t len
= strlen (entry
->option
);
2898 if (strneq (p
, entry
->option
, len
)
2899 && (p
[len
] == ',' || p
[len
] == '\0'))
2901 * entry
->variable
= 1;
2903 /* The --debug-dump=frames-interp option also
2904 enables the --debug-dump=frames option. */
2905 if (do_debug_frames_interp
)
2906 do_debug_frames
= 1;
2913 if (entry
->option
== NULL
)
2915 warn (_("Unrecognized debug option '%s'\n"), p
);
2916 p
= strchr (p
, ',');
2926 #ifdef SUPPORT_DISASSEMBLY
2929 section
= strtoul (optarg
, & cp
, 0);
2930 if (! *cp
&& section
>= 0)
2932 request_dump (section
, DISASS_DUMP
);
2938 print_version (program_name
);
2947 #ifdef SUPPORT_DISASSEMBLY
2950 /* xgettext:c-format */
2951 error (_("Invalid option '-%c'\n"), c
);
2958 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2959 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2960 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
2961 && !do_section_groups
)
2965 warn (_("Nothing to do.\n"));
2971 get_elf_class (unsigned int elf_class
)
2973 static char buff
[32];
2977 case ELFCLASSNONE
: return _("none");
2978 case ELFCLASS32
: return "ELF32";
2979 case ELFCLASS64
: return "ELF64";
2981 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
2987 get_data_encoding (unsigned int encoding
)
2989 static char buff
[32];
2993 case ELFDATANONE
: return _("none");
2994 case ELFDATA2LSB
: return _("2's complement, little endian");
2995 case ELFDATA2MSB
: return _("2's complement, big endian");
2997 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3002 /* Decode the data held in 'elf_header'. */
3005 process_file_header (void)
3007 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3008 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3009 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3010 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3013 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3021 printf (_("ELF Header:\n"));
3022 printf (_(" Magic: "));
3023 for (i
= 0; i
< EI_NIDENT
; i
++)
3024 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3026 printf (_(" Class: %s\n"),
3027 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3028 printf (_(" Data: %s\n"),
3029 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3030 printf (_(" Version: %d %s\n"),
3031 elf_header
.e_ident
[EI_VERSION
],
3032 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3034 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3037 printf (_(" OS/ABI: %s\n"),
3038 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3039 printf (_(" ABI Version: %d\n"),
3040 elf_header
.e_ident
[EI_ABIVERSION
]);
3041 printf (_(" Type: %s\n"),
3042 get_file_type (elf_header
.e_type
));
3043 printf (_(" Machine: %s\n"),
3044 get_machine_name (elf_header
.e_machine
));
3045 printf (_(" Version: 0x%lx\n"),
3046 (unsigned long) elf_header
.e_version
);
3048 printf (_(" Entry point address: "));
3049 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3050 printf (_("\n Start of program headers: "));
3051 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3052 printf (_(" (bytes into file)\n Start of section headers: "));
3053 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3054 printf (_(" (bytes into file)\n"));
3056 printf (_(" Flags: 0x%lx%s\n"),
3057 (unsigned long) elf_header
.e_flags
,
3058 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3059 printf (_(" Size of this header: %ld (bytes)\n"),
3060 (long) elf_header
.e_ehsize
);
3061 printf (_(" Size of program headers: %ld (bytes)\n"),
3062 (long) elf_header
.e_phentsize
);
3063 printf (_(" Number of program headers: %ld\n"),
3064 (long) elf_header
.e_phnum
);
3065 printf (_(" Size of section headers: %ld (bytes)\n"),
3066 (long) elf_header
.e_shentsize
);
3067 printf (_(" Number of section headers: %ld"),
3068 (long) elf_header
.e_shnum
);
3069 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3070 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3071 putc ('\n', stdout
);
3072 printf (_(" Section header string table index: %ld"),
3073 (long) elf_header
.e_shstrndx
);
3074 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3075 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3076 putc ('\n', stdout
);
3079 if (section_headers
!= NULL
)
3081 if (elf_header
.e_shnum
== 0)
3082 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3083 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3084 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3085 free (section_headers
);
3086 section_headers
= NULL
;
3094 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3096 Elf32_External_Phdr
*phdrs
;
3097 Elf32_External_Phdr
*external
;
3098 Elf_Internal_Phdr
*internal
;
3101 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3102 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3103 _("program headers"));
3107 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3108 i
< elf_header
.e_phnum
;
3109 i
++, internal
++, external
++)
3111 internal
->p_type
= BYTE_GET (external
->p_type
);
3112 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3113 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3114 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3115 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3116 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3117 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3118 internal
->p_align
= BYTE_GET (external
->p_align
);
3127 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3129 Elf64_External_Phdr
*phdrs
;
3130 Elf64_External_Phdr
*external
;
3131 Elf_Internal_Phdr
*internal
;
3134 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3135 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3136 _("program headers"));
3140 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3141 i
< elf_header
.e_phnum
;
3142 i
++, internal
++, external
++)
3144 internal
->p_type
= BYTE_GET (external
->p_type
);
3145 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3146 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3147 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3148 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3149 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3150 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3151 internal
->p_align
= BYTE_GET (external
->p_align
);
3159 /* Returns 1 if the program headers were read into `program_headers'. */
3162 get_program_headers (FILE *file
)
3164 Elf_Internal_Phdr
*phdrs
;
3166 /* Check cache of prior read. */
3167 if (program_headers
!= NULL
)
3170 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3174 error (_("Out of memory\n"));
3179 ? get_32bit_program_headers (file
, phdrs
)
3180 : get_64bit_program_headers (file
, phdrs
))
3182 program_headers
= phdrs
;
3190 /* Returns 1 if the program headers were loaded. */
3193 process_program_headers (FILE *file
)
3195 Elf_Internal_Phdr
*segment
;
3198 if (elf_header
.e_phnum
== 0)
3201 printf (_("\nThere are no program headers in this file.\n"));
3205 if (do_segments
&& !do_header
)
3207 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3208 printf (_("Entry point "));
3209 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3210 printf (_("\nThere are %d program headers, starting at offset "),
3211 elf_header
.e_phnum
);
3212 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3216 if (! get_program_headers (file
))
3221 if (elf_header
.e_phnum
> 1)
3222 printf (_("\nProgram Headers:\n"));
3224 printf (_("\nProgram Headers:\n"));
3228 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3231 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3235 (_(" Type Offset VirtAddr PhysAddr\n"));
3237 (_(" FileSiz MemSiz Flags Align\n"));
3244 for (i
= 0, segment
= program_headers
;
3245 i
< elf_header
.e_phnum
;
3250 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3254 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3255 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3256 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3257 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3258 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3260 (segment
->p_flags
& PF_R
? 'R' : ' '),
3261 (segment
->p_flags
& PF_W
? 'W' : ' '),
3262 (segment
->p_flags
& PF_X
? 'E' : ' '));
3263 printf ("%#lx", (unsigned long) segment
->p_align
);
3267 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3268 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3271 print_vma (segment
->p_offset
, FULL_HEX
);
3275 print_vma (segment
->p_vaddr
, FULL_HEX
);
3277 print_vma (segment
->p_paddr
, FULL_HEX
);
3280 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3281 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3284 print_vma (segment
->p_filesz
, FULL_HEX
);
3288 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3289 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3292 print_vma (segment
->p_offset
, FULL_HEX
);
3296 (segment
->p_flags
& PF_R
? 'R' : ' '),
3297 (segment
->p_flags
& PF_W
? 'W' : ' '),
3298 (segment
->p_flags
& PF_X
? 'E' : ' '));
3300 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3301 printf ("%#lx", (unsigned long) segment
->p_align
);
3304 print_vma (segment
->p_align
, PREFIX_HEX
);
3309 print_vma (segment
->p_offset
, FULL_HEX
);
3311 print_vma (segment
->p_vaddr
, FULL_HEX
);
3313 print_vma (segment
->p_paddr
, FULL_HEX
);
3315 print_vma (segment
->p_filesz
, FULL_HEX
);
3317 print_vma (segment
->p_memsz
, FULL_HEX
);
3319 (segment
->p_flags
& PF_R
? 'R' : ' '),
3320 (segment
->p_flags
& PF_W
? 'W' : ' '),
3321 (segment
->p_flags
& PF_X
? 'E' : ' '));
3322 print_vma (segment
->p_align
, HEX
);
3326 switch (segment
->p_type
)
3330 error (_("more than one dynamic segment\n"));
3332 /* Try to locate the .dynamic section. If there is
3333 a section header table, we can easily locate it. */
3334 if (section_headers
!= NULL
)
3336 Elf_Internal_Shdr
*sec
;
3338 sec
= find_section (".dynamic");
3339 if (sec
== NULL
|| sec
->sh_size
== 0)
3341 error (_("no .dynamic section in the dynamic segment"));
3345 dynamic_addr
= sec
->sh_offset
;
3346 dynamic_size
= sec
->sh_size
;
3348 if (dynamic_addr
< segment
->p_offset
3349 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3350 warn (_("the .dynamic section is not contained within the dynamic segment"));
3351 else if (dynamic_addr
> segment
->p_offset
)
3352 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3356 /* Otherwise, we can only assume that the .dynamic
3357 section is the first section in the DYNAMIC segment. */
3358 dynamic_addr
= segment
->p_offset
;
3359 dynamic_size
= segment
->p_filesz
;
3364 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3366 error (_("Unable to find program interpreter name\n"));
3369 program_interpreter
[0] = 0;
3370 fscanf (file
, "%63s", program_interpreter
);
3373 printf (_("\n [Requesting program interpreter: %s]"),
3374 program_interpreter
);
3380 putc ('\n', stdout
);
3383 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3385 printf (_("\n Section to Segment mapping:\n"));
3386 printf (_(" Segment Sections...\n"));
3388 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3391 Elf_Internal_Shdr
*section
;
3393 segment
= program_headers
+ i
;
3394 section
= section_headers
;
3396 printf (" %2.2d ", i
);
3398 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3400 if (section
->sh_size
> 0
3401 /* Compare allocated sections by VMA, unallocated
3402 sections by file offset. */
3403 && (section
->sh_flags
& SHF_ALLOC
3404 ? (section
->sh_addr
>= segment
->p_vaddr
3405 && section
->sh_addr
+ section
->sh_size
3406 <= segment
->p_vaddr
+ segment
->p_memsz
)
3407 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3408 && (section
->sh_offset
+ section
->sh_size
3409 <= segment
->p_offset
+ segment
->p_filesz
)))
3410 /* .tbss is special. It doesn't contribute memory space
3411 to normal segments. */
3412 && (!((section
->sh_flags
& SHF_TLS
) != 0
3413 && section
->sh_type
== SHT_NOBITS
)
3414 || segment
->p_type
== PT_TLS
))
3415 printf ("%s ", SECTION_NAME (section
));
3426 /* Find the file offset corresponding to VMA by using the program headers. */
3429 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3431 Elf_Internal_Phdr
*seg
;
3433 if (! get_program_headers (file
))
3435 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3439 for (seg
= program_headers
;
3440 seg
< program_headers
+ elf_header
.e_phnum
;
3443 if (seg
->p_type
!= PT_LOAD
)
3446 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3447 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3448 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3451 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3458 get_32bit_section_headers (FILE *file
, unsigned int num
)
3460 Elf32_External_Shdr
*shdrs
;
3461 Elf_Internal_Shdr
*internal
;
3464 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3465 elf_header
.e_shentsize
, num
, _("section headers"));
3469 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3471 if (section_headers
== NULL
)
3473 error (_("Out of memory\n"));
3477 for (i
= 0, internal
= section_headers
;
3481 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3482 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3483 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3484 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3485 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3486 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3487 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3488 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3489 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3490 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3499 get_64bit_section_headers (FILE *file
, unsigned int num
)
3501 Elf64_External_Shdr
*shdrs
;
3502 Elf_Internal_Shdr
*internal
;
3505 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3506 elf_header
.e_shentsize
, num
, _("section headers"));
3510 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3512 if (section_headers
== NULL
)
3514 error (_("Out of memory\n"));
3518 for (i
= 0, internal
= section_headers
;
3522 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3523 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3524 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3525 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3526 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3527 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3528 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3529 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3530 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3531 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3539 static Elf_Internal_Sym
*
3540 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3542 unsigned long number
;
3543 Elf32_External_Sym
*esyms
;
3544 Elf_External_Sym_Shndx
*shndx
;
3545 Elf_Internal_Sym
*isyms
;
3546 Elf_Internal_Sym
*psym
;
3549 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3555 if (symtab_shndx_hdr
!= NULL
3556 && (symtab_shndx_hdr
->sh_link
3557 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3559 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3560 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3568 number
= section
->sh_size
/ section
->sh_entsize
;
3569 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3573 error (_("Out of memory\n"));
3580 for (j
= 0, psym
= isyms
;
3584 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3585 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3586 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3587 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3588 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3590 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3591 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3592 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3602 static Elf_Internal_Sym
*
3603 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3605 unsigned long number
;
3606 Elf64_External_Sym
*esyms
;
3607 Elf_External_Sym_Shndx
*shndx
;
3608 Elf_Internal_Sym
*isyms
;
3609 Elf_Internal_Sym
*psym
;
3612 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3618 if (symtab_shndx_hdr
!= NULL
3619 && (symtab_shndx_hdr
->sh_link
3620 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3622 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3623 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3631 number
= section
->sh_size
/ section
->sh_entsize
;
3632 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3636 error (_("Out of memory\n"));
3643 for (j
= 0, psym
= isyms
;
3647 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3648 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3649 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3650 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3651 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3653 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3654 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3655 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3666 get_elf_section_flags (bfd_vma sh_flags
)
3668 static char buff
[1024];
3670 int field_size
= is_32bit_elf
? 8 : 16;
3671 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3672 bfd_vma os_flags
= 0;
3673 bfd_vma proc_flags
= 0;
3674 bfd_vma unknown_flags
= 0;
3688 { "LINK ORDER", 10 },
3689 { "OS NONCONF", 10 },
3694 if (do_section_details
)
3696 sprintf (buff
, "[%*.*lx]: ",
3697 field_size
, field_size
, (unsigned long) sh_flags
);
3698 p
+= field_size
+ 4;
3705 flag
= sh_flags
& - sh_flags
;
3708 if (do_section_details
)
3712 case SHF_WRITE
: index
= 0; break;
3713 case SHF_ALLOC
: index
= 1; break;
3714 case SHF_EXECINSTR
: index
= 2; break;
3715 case SHF_MERGE
: index
= 3; break;
3716 case SHF_STRINGS
: index
= 4; break;
3717 case SHF_INFO_LINK
: index
= 5; break;
3718 case SHF_LINK_ORDER
: index
= 6; break;
3719 case SHF_OS_NONCONFORMING
: index
= 7; break;
3720 case SHF_GROUP
: index
= 8; break;
3721 case SHF_TLS
: index
= 9; break;
3730 if (p
!= buff
+ field_size
+ 4)
3732 if (size
< (10 + 2))
3739 size
-= flags
[index
].len
;
3740 p
= stpcpy (p
, flags
[index
].str
);
3742 else if (flag
& SHF_MASKOS
)
3744 else if (flag
& SHF_MASKPROC
)
3747 unknown_flags
|= flag
;
3753 case SHF_WRITE
: *p
= 'W'; break;
3754 case SHF_ALLOC
: *p
= 'A'; break;
3755 case SHF_EXECINSTR
: *p
= 'X'; break;
3756 case SHF_MERGE
: *p
= 'M'; break;
3757 case SHF_STRINGS
: *p
= 'S'; break;
3758 case SHF_INFO_LINK
: *p
= 'I'; break;
3759 case SHF_LINK_ORDER
: *p
= 'L'; break;
3760 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3761 case SHF_GROUP
: *p
= 'G'; break;
3762 case SHF_TLS
: *p
= 'T'; break;
3765 if (elf_header
.e_machine
== EM_X86_64
3766 && flag
== SHF_X86_64_LARGE
)
3768 else if (flag
& SHF_MASKOS
)
3771 sh_flags
&= ~ SHF_MASKOS
;
3773 else if (flag
& SHF_MASKPROC
)
3776 sh_flags
&= ~ SHF_MASKPROC
;
3786 if (do_section_details
)
3790 size
-= 5 + field_size
;
3791 if (p
!= buff
+ field_size
+ 4)
3799 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3800 (unsigned long) os_flags
);
3801 p
+= 5 + field_size
;
3805 size
-= 7 + field_size
;
3806 if (p
!= buff
+ field_size
+ 4)
3814 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
3815 (unsigned long) proc_flags
);
3816 p
+= 7 + field_size
;
3820 size
-= 10 + field_size
;
3821 if (p
!= buff
+ field_size
+ 4)
3829 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
3830 (unsigned long) unknown_flags
);
3831 p
+= 10 + field_size
;
3840 process_section_headers (FILE *file
)
3842 Elf_Internal_Shdr
*section
;
3845 section_headers
= NULL
;
3847 if (elf_header
.e_shnum
== 0)
3850 printf (_("\nThere are no sections in this file.\n"));
3855 if (do_sections
&& !do_header
)
3856 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3857 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3861 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3864 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3867 /* Read in the string table, so that we have names to display. */
3868 if (SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
3870 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3872 if (section
->sh_size
!= 0)
3874 string_table
= get_data (NULL
, file
, section
->sh_offset
,
3875 1, section
->sh_size
, _("string table"));
3877 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
3881 /* Scan the sections for the dynamic symbol table
3882 and dynamic string table and debug sections. */
3883 dynamic_symbols
= NULL
;
3884 dynamic_strings
= NULL
;
3885 dynamic_syminfo
= NULL
;
3886 symtab_shndx_hdr
= NULL
;
3888 eh_addr_size
= is_32bit_elf
? 4 : 8;
3889 switch (elf_header
.e_machine
)
3892 case EM_MIPS_RS3_LE
:
3893 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
3894 FDE addresses. However, the ABI also has a semi-official ILP32
3895 variant for which the normal FDE address size rules apply.
3897 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
3898 section, where XX is the size of longs in bits. Unfortunately,
3899 earlier compilers provided no way of distinguishing ILP32 objects
3900 from LP64 objects, so if there's any doubt, we should assume that
3901 the official LP64 form is being used. */
3902 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
3903 && find_section (".gcc_compiled_long32") == NULL
)
3908 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
3911 size_t expected_entsize \
3912 = is_32bit_elf ? size32 : size64; \
3913 if (section->sh_entsize != expected_entsize) \
3914 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
3915 i, (unsigned long int) section->sh_entsize, \
3916 (unsigned long int) expected_entsize); \
3917 section->sh_entsize = expected_entsize; \
3920 #define CHECK_ENTSIZE(section, i, type) \
3921 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
3922 sizeof (Elf64_External_##type))
3924 for (i
= 0, section
= section_headers
;
3925 i
< elf_header
.e_shnum
;
3928 char *name
= SECTION_NAME (section
);
3930 if (section
->sh_type
== SHT_DYNSYM
)
3932 if (dynamic_symbols
!= NULL
)
3934 error (_("File contains multiple dynamic symbol tables\n"));
3938 CHECK_ENTSIZE (section
, i
, Sym
);
3939 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3940 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3942 else if (section
->sh_type
== SHT_STRTAB
3943 && streq (name
, ".dynstr"))
3945 if (dynamic_strings
!= NULL
)
3947 error (_("File contains multiple dynamic string tables\n"));
3951 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
3952 1, section
->sh_size
, _("dynamic strings"));
3953 dynamic_strings_length
= section
->sh_size
;
3955 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3957 if (symtab_shndx_hdr
!= NULL
)
3959 error (_("File contains multiple symtab shndx tables\n"));
3962 symtab_shndx_hdr
= section
;
3964 else if (section
->sh_type
== SHT_SYMTAB
)
3965 CHECK_ENTSIZE (section
, i
, Sym
);
3966 else if (section
->sh_type
== SHT_GROUP
)
3967 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
3968 else if (section
->sh_type
== SHT_REL
)
3969 CHECK_ENTSIZE (section
, i
, Rel
);
3970 else if (section
->sh_type
== SHT_RELA
)
3971 CHECK_ENTSIZE (section
, i
, Rela
);
3972 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3973 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3974 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3975 || do_debug_loc
|| do_debug_ranges
)
3976 && strneq (name
, ".debug_", 7))
3981 || (do_debug_info
&& streq (name
, "info"))
3982 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
3983 || (do_debug_lines
&& streq (name
, "line"))
3984 || (do_debug_pubnames
&& streq (name
, "pubnames"))
3985 || (do_debug_aranges
&& streq (name
, "aranges"))
3986 || (do_debug_ranges
&& streq (name
, "ranges"))
3987 || (do_debug_frames
&& streq (name
, "frame"))
3988 || (do_debug_macinfo
&& streq (name
, "macinfo"))
3989 || (do_debug_str
&& streq (name
, "str"))
3990 || (do_debug_loc
&& streq (name
, "loc"))
3992 request_dump (i
, DEBUG_DUMP
);
3994 /* linkonce section to be combined with .debug_info at link time. */
3995 else if ((do_debugging
|| do_debug_info
)
3996 && strneq (name
, ".gnu.linkonce.wi.", 17))
3997 request_dump (i
, DEBUG_DUMP
);
3998 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
3999 request_dump (i
, DEBUG_DUMP
);
4005 if (elf_header
.e_shnum
> 1)
4006 printf (_("\nSection Headers:\n"));
4008 printf (_("\nSection Header:\n"));
4012 if (do_section_details
)
4014 printf (_(" [Nr] Name\n"));
4015 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4019 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4023 if (do_section_details
)
4025 printf (_(" [Nr] Name\n"));
4026 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4030 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4034 if (do_section_details
)
4036 printf (_(" [Nr] Name\n"));
4037 printf (_(" Type Address Offset Link\n"));
4038 printf (_(" Size EntSize Info Align\n"));
4042 printf (_(" [Nr] Name Type Address Offset\n"));
4043 printf (_(" Size EntSize Flags Link Info Align\n"));
4047 if (do_section_details
)
4048 printf (_(" Flags\n"));
4050 for (i
= 0, section
= section_headers
;
4051 i
< elf_header
.e_shnum
;
4054 if (do_section_details
)
4056 printf (" [%2u] %s\n",
4057 SECTION_HEADER_NUM (i
),
4058 SECTION_NAME (section
));
4059 if (is_32bit_elf
|| do_wide
)
4060 printf (" %-15.15s ",
4061 get_section_type_name (section
->sh_type
));
4064 printf (" [%2u] %-17.17s %-15.15s ",
4065 SECTION_HEADER_NUM (i
),
4066 SECTION_NAME (section
),
4067 get_section_type_name (section
->sh_type
));
4071 print_vma (section
->sh_addr
, LONG_HEX
);
4073 printf ( " %6.6lx %6.6lx %2.2lx",
4074 (unsigned long) section
->sh_offset
,
4075 (unsigned long) section
->sh_size
,
4076 (unsigned long) section
->sh_entsize
);
4078 if (do_section_details
)
4079 fputs (" ", stdout
);
4081 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4083 printf ("%2ld %3lu %2ld\n",
4084 (unsigned long) section
->sh_link
,
4085 (unsigned long) section
->sh_info
,
4086 (unsigned long) section
->sh_addralign
);
4090 print_vma (section
->sh_addr
, LONG_HEX
);
4092 if ((long) section
->sh_offset
== section
->sh_offset
)
4093 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4097 print_vma (section
->sh_offset
, LONG_HEX
);
4100 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4101 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4105 print_vma (section
->sh_size
, LONG_HEX
);
4108 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4109 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4113 print_vma (section
->sh_entsize
, LONG_HEX
);
4116 if (do_section_details
)
4117 fputs (" ", stdout
);
4119 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4121 printf ("%2ld %3lu ",
4122 (unsigned long) section
->sh_link
,
4123 (unsigned long) section
->sh_info
);
4125 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4126 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4129 print_vma (section
->sh_addralign
, DEC
);
4133 else if (do_section_details
)
4135 printf (" %-15.15s ",
4136 get_section_type_name (section
->sh_type
));
4137 print_vma (section
->sh_addr
, LONG_HEX
);
4138 if ((long) section
->sh_offset
== section
->sh_offset
)
4139 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4143 print_vma (section
->sh_offset
, LONG_HEX
);
4145 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4146 print_vma (section
->sh_size
, LONG_HEX
);
4148 print_vma (section
->sh_entsize
, LONG_HEX
);
4150 printf (" %-16lu %ld\n",
4151 (unsigned long) section
->sh_info
,
4152 (unsigned long) section
->sh_addralign
);
4157 print_vma (section
->sh_addr
, LONG_HEX
);
4158 if ((long) section
->sh_offset
== section
->sh_offset
)
4159 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4163 print_vma (section
->sh_offset
, LONG_HEX
);
4166 print_vma (section
->sh_size
, LONG_HEX
);
4168 print_vma (section
->sh_entsize
, LONG_HEX
);
4170 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4172 printf (" %2ld %3lu %ld\n",
4173 (unsigned long) section
->sh_link
,
4174 (unsigned long) section
->sh_info
,
4175 (unsigned long) section
->sh_addralign
);
4178 if (do_section_details
)
4179 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4182 if (!do_section_details
)
4183 printf (_("Key to Flags:\n\
4184 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4185 I (info), L (link order), G (group), x (unknown)\n\
4186 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4192 get_group_flags (unsigned int flags
)
4194 static char buff
[32];
4201 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4208 process_section_groups (FILE *file
)
4210 Elf_Internal_Shdr
*section
;
4212 struct group
*group
;
4213 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4214 Elf_Internal_Sym
*symtab
;
4218 /* Don't process section groups unless needed. */
4219 if (!do_unwind
&& !do_section_groups
)
4222 if (elf_header
.e_shnum
== 0)
4224 if (do_section_groups
)
4225 printf (_("\nThere are no sections in this file.\n"));
4230 if (section_headers
== NULL
)
4232 error (_("Section headers are not available!\n"));
4236 section_headers_groups
= calloc (elf_header
.e_shnum
,
4237 sizeof (struct group
*));
4239 if (section_headers_groups
== NULL
)
4241 error (_("Out of memory\n"));
4245 /* Scan the sections for the group section. */
4247 for (i
= 0, section
= section_headers
;
4248 i
< elf_header
.e_shnum
;
4250 if (section
->sh_type
== SHT_GROUP
)
4253 if (group_count
== 0)
4255 if (do_section_groups
)
4256 printf (_("\nThere are no section groups in this file.\n"));
4261 section_groups
= calloc (group_count
, sizeof (struct group
));
4263 if (section_groups
== NULL
)
4265 error (_("Out of memory\n"));
4274 for (i
= 0, section
= section_headers
, group
= section_groups
;
4275 i
< elf_header
.e_shnum
;
4278 if (section
->sh_type
== SHT_GROUP
)
4280 char *name
= SECTION_NAME (section
);
4282 unsigned char *start
, *indices
;
4283 unsigned int entry
, j
, size
;
4284 Elf_Internal_Shdr
*sec
;
4285 Elf_Internal_Sym
*sym
;
4287 /* Get the symbol table. */
4288 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4289 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4292 error (_("Bad sh_link in group section `%s'\n"), name
);
4296 if (symtab_sec
!= sec
)
4301 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4304 sym
= symtab
+ section
->sh_info
;
4306 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4308 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4311 error (_("Bad sh_info in group section `%s'\n"), name
);
4315 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4324 /* Get the string table. */
4325 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4326 >= elf_header
.e_shnum
)
4335 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4340 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4341 1, strtab_sec
->sh_size
,
4343 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4345 group_name
= sym
->st_name
< strtab_size
4346 ? strtab
+ sym
->st_name
: "<corrupt>";
4349 start
= get_data (NULL
, file
, section
->sh_offset
,
4350 1, section
->sh_size
, _("section data"));
4353 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4354 entry
= byte_get (indices
, 4);
4357 if (do_section_groups
)
4359 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4360 get_group_flags (entry
), i
, name
, group_name
, size
);
4362 printf (_(" [Index] Name\n"));
4365 group
->group_index
= i
;
4367 for (j
= 0; j
< size
; j
++)
4369 struct group_list
*g
;
4371 entry
= byte_get (indices
, 4);
4374 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4376 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4377 entry
, i
, elf_header
.e_shnum
- 1);
4380 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4382 error (_("invalid section [%5u] in group section [%5u]\n"),
4387 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4392 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4394 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4399 /* Intel C/C++ compiler may put section 0 in a
4400 section group. We just warn it the first time
4401 and ignore it afterwards. */
4402 static int warned
= 0;
4405 error (_("section 0 in group section [%5u]\n"),
4406 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4412 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4415 if (do_section_groups
)
4417 sec
= SECTION_HEADER (entry
);
4418 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4421 g
= xmalloc (sizeof (struct group_list
));
4422 g
->section_index
= entry
;
4423 g
->next
= group
->root
;
4447 } dynamic_relocations
[] =
4449 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4450 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4451 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4454 /* Process the reloc section. */
4457 process_relocs (FILE *file
)
4459 unsigned long rel_size
;
4460 unsigned long rel_offset
;
4466 if (do_using_dynamic
)
4470 int has_dynamic_reloc
;
4473 has_dynamic_reloc
= 0;
4475 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4477 is_rela
= dynamic_relocations
[i
].rela
;
4478 name
= dynamic_relocations
[i
].name
;
4479 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4480 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4482 has_dynamic_reloc
|= rel_size
;
4484 if (is_rela
== UNKNOWN
)
4486 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4487 switch (dynamic_info
[DT_PLTREL
])
4501 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4502 name
, rel_offset
, rel_size
);
4504 dump_relocations (file
,
4505 offset_from_vma (file
, rel_offset
, rel_size
),
4507 dynamic_symbols
, num_dynamic_syms
,
4508 dynamic_strings
, dynamic_strings_length
, is_rela
);
4512 if (! has_dynamic_reloc
)
4513 printf (_("\nThere are no dynamic relocations in this file.\n"));
4517 Elf_Internal_Shdr
*section
;
4521 for (i
= 0, section
= section_headers
;
4522 i
< elf_header
.e_shnum
;
4525 if ( section
->sh_type
!= SHT_RELA
4526 && section
->sh_type
!= SHT_REL
)
4529 rel_offset
= section
->sh_offset
;
4530 rel_size
= section
->sh_size
;
4534 Elf_Internal_Shdr
*strsec
;
4537 printf (_("\nRelocation section "));
4539 if (string_table
== NULL
)
4540 printf ("%d", section
->sh_name
);
4542 printf (_("'%s'"), SECTION_NAME (section
));
4544 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4545 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4547 is_rela
= section
->sh_type
== SHT_RELA
;
4549 if (section
->sh_link
4550 && SECTION_HEADER_INDEX (section
->sh_link
)
4551 < elf_header
.e_shnum
)
4553 Elf_Internal_Shdr
*symsec
;
4554 Elf_Internal_Sym
*symtab
;
4555 unsigned long nsyms
;
4556 unsigned long strtablen
= 0;
4557 char *strtab
= NULL
;
4559 symsec
= SECTION_HEADER (section
->sh_link
);
4560 if (symsec
->sh_type
!= SHT_SYMTAB
4561 && symsec
->sh_type
!= SHT_DYNSYM
)
4564 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4565 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4570 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4571 < elf_header
.e_shnum
)
4573 strsec
= SECTION_HEADER (symsec
->sh_link
);
4575 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4578 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4581 dump_relocations (file
, rel_offset
, rel_size
,
4582 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4588 dump_relocations (file
, rel_offset
, rel_size
,
4589 NULL
, 0, NULL
, 0, is_rela
);
4596 printf (_("\nThere are no relocations in this file.\n"));
4602 /* Process the unwind section. */
4604 #include "unwind-ia64.h"
4606 /* An absolute address consists of a section and an offset. If the
4607 section is NULL, the offset itself is the address, otherwise, the
4608 address equals to LOAD_ADDRESS(section) + offset. */
4612 unsigned short section
;
4616 #define ABSADDR(a) \
4618 ? section_headers [(a).section].sh_addr + (a).offset \
4621 struct ia64_unw_aux_info
4623 struct ia64_unw_table_entry
4625 struct absaddr start
;
4627 struct absaddr info
;
4629 *table
; /* Unwind table. */
4630 unsigned long table_len
; /* Length of unwind table. */
4631 unsigned char *info
; /* Unwind info. */
4632 unsigned long info_size
; /* Size of unwind info. */
4633 bfd_vma info_addr
; /* starting address of unwind info. */
4634 bfd_vma seg_base
; /* Starting address of segment. */
4635 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4636 unsigned long nsyms
; /* Number of symbols. */
4637 char *strtab
; /* The string table. */
4638 unsigned long strtab_size
; /* Size of string table. */
4642 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4643 unsigned long nsyms
,
4645 unsigned long strtab_size
,
4646 struct absaddr addr
,
4647 const char **symname
,
4650 bfd_vma dist
= 0x100000;
4651 Elf_Internal_Sym
*sym
, *best
= NULL
;
4654 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4656 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4657 && sym
->st_name
!= 0
4658 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4659 && addr
.offset
>= sym
->st_value
4660 && addr
.offset
- sym
->st_value
< dist
)
4663 dist
= addr
.offset
- sym
->st_value
;
4670 *symname
= (best
->st_name
>= strtab_size
4671 ? "<corrupt>" : strtab
+ best
->st_name
);
4676 *offset
= addr
.offset
;
4680 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4682 struct ia64_unw_table_entry
*tp
;
4685 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4689 const unsigned char *dp
;
4690 const unsigned char *head
;
4691 const char *procname
;
4693 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4694 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4696 fputs ("\n<", stdout
);
4700 fputs (procname
, stdout
);
4703 printf ("+%lx", (unsigned long) offset
);
4706 fputs (">: [", stdout
);
4707 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4708 fputc ('-', stdout
);
4709 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4710 printf ("], info at +0x%lx\n",
4711 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4713 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4714 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4716 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4717 (unsigned) UNW_VER (stamp
),
4718 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4719 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4720 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4721 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4723 if (UNW_VER (stamp
) != 1)
4725 printf ("\tUnknown version.\n");
4730 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4731 dp
= unw_decode (dp
, in_body
, & in_body
);
4736 slurp_ia64_unwind_table (FILE *file
,
4737 struct ia64_unw_aux_info
*aux
,
4738 Elf_Internal_Shdr
*sec
)
4740 unsigned long size
, nrelas
, i
;
4741 Elf_Internal_Phdr
*seg
;
4742 struct ia64_unw_table_entry
*tep
;
4743 Elf_Internal_Shdr
*relsec
;
4744 Elf_Internal_Rela
*rela
, *rp
;
4745 unsigned char *table
, *tp
;
4746 Elf_Internal_Sym
*sym
;
4747 const char *relname
;
4749 /* First, find the starting address of the segment that includes
4752 if (elf_header
.e_phnum
)
4754 if (! get_program_headers (file
))
4757 for (seg
= program_headers
;
4758 seg
< program_headers
+ elf_header
.e_phnum
;
4761 if (seg
->p_type
!= PT_LOAD
)
4764 if (sec
->sh_addr
>= seg
->p_vaddr
4765 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4767 aux
->seg_base
= seg
->p_vaddr
;
4773 /* Second, build the unwind table from the contents of the unwind section: */
4774 size
= sec
->sh_size
;
4775 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4779 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4781 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4783 tep
->start
.section
= SHN_UNDEF
;
4784 tep
->end
.section
= SHN_UNDEF
;
4785 tep
->info
.section
= SHN_UNDEF
;
4788 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4789 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4790 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4794 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
4795 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
4796 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
4798 tep
->start
.offset
+= aux
->seg_base
;
4799 tep
->end
.offset
+= aux
->seg_base
;
4800 tep
->info
.offset
+= aux
->seg_base
;
4804 /* Third, apply any relocations to the unwind table: */
4806 for (relsec
= section_headers
;
4807 relsec
< section_headers
+ elf_header
.e_shnum
;
4810 if (relsec
->sh_type
!= SHT_RELA
4811 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
4812 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4815 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4819 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4823 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4824 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4828 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4829 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4832 if (! strneq (relname
, "R_IA64_SEGREL", 13))
4834 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4838 i
= rp
->r_offset
/ (3 * eh_addr_size
);
4840 switch (rp
->r_offset
/eh_addr_size
% 3)
4843 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4844 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
4847 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4848 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
4851 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4852 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
4862 aux
->table_len
= size
/ (3 * eh_addr_size
);
4867 ia64_process_unwind (FILE *file
)
4869 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4870 unsigned long i
, unwcount
= 0, unwstart
= 0;
4871 struct ia64_unw_aux_info aux
;
4873 memset (& aux
, 0, sizeof (aux
));
4875 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4877 if (sec
->sh_type
== SHT_SYMTAB
4878 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
4880 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4881 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4883 strsec
= SECTION_HEADER (sec
->sh_link
);
4884 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4885 1, strsec
->sh_size
, _("string table"));
4886 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
4888 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4893 printf (_("\nThere are no unwind sections in this file.\n"));
4895 while (unwcount
-- > 0)
4900 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4901 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4902 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4909 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4911 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
4913 /* We need to find which section group it is in. */
4914 struct group_list
*g
= section_headers_groups
[i
]->root
;
4916 for (; g
!= NULL
; g
= g
->next
)
4918 sec
= SECTION_HEADER (g
->section_index
);
4920 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
4925 i
= elf_header
.e_shnum
;
4927 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
4929 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
4930 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4931 suffix
= SECTION_NAME (unwsec
) + len
;
4932 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4934 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
4935 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4940 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4941 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
4942 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4943 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4945 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
4946 suffix
= SECTION_NAME (unwsec
) + len
;
4947 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4949 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
4950 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4954 if (i
== elf_header
.e_shnum
)
4956 printf (_("\nCould not find unwind info section for "));
4958 if (string_table
== NULL
)
4959 printf ("%d", unwsec
->sh_name
);
4961 printf (_("'%s'"), SECTION_NAME (unwsec
));
4965 aux
.info_size
= sec
->sh_size
;
4966 aux
.info_addr
= sec
->sh_addr
;
4967 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
4970 printf (_("\nUnwind section "));
4972 if (string_table
== NULL
)
4973 printf ("%d", unwsec
->sh_name
);
4975 printf (_("'%s'"), SECTION_NAME (unwsec
));
4977 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4978 (unsigned long) unwsec
->sh_offset
,
4979 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
4981 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4983 if (aux
.table_len
> 0)
4984 dump_ia64_unwind (& aux
);
4987 free ((char *) aux
.table
);
4989 free ((char *) aux
.info
);
4998 free ((char *) aux
.strtab
);
5003 struct hppa_unw_aux_info
5005 struct hppa_unw_table_entry
5007 struct absaddr start
;
5009 unsigned int Cannot_unwind
:1; /* 0 */
5010 unsigned int Millicode
:1; /* 1 */
5011 unsigned int Millicode_save_sr0
:1; /* 2 */
5012 unsigned int Region_description
:2; /* 3..4 */
5013 unsigned int reserved1
:1; /* 5 */
5014 unsigned int Entry_SR
:1; /* 6 */
5015 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5016 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5017 unsigned int Args_stored
:1; /* 16 */
5018 unsigned int Variable_Frame
:1; /* 17 */
5019 unsigned int Separate_Package_Body
:1; /* 18 */
5020 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5021 unsigned int Stack_Overflow_Check
:1; /* 20 */
5022 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5023 unsigned int Ada_Region
:1; /* 22 */
5024 unsigned int cxx_info
:1; /* 23 */
5025 unsigned int cxx_try_catch
:1; /* 24 */
5026 unsigned int sched_entry_seq
:1; /* 25 */
5027 unsigned int reserved2
:1; /* 26 */
5028 unsigned int Save_SP
:1; /* 27 */
5029 unsigned int Save_RP
:1; /* 28 */
5030 unsigned int Save_MRP_in_frame
:1; /* 29 */
5031 unsigned int extn_ptr_defined
:1; /* 30 */
5032 unsigned int Cleanup_defined
:1; /* 31 */
5034 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5035 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5036 unsigned int Large_frame
:1; /* 2 */
5037 unsigned int Pseudo_SP_Set
:1; /* 3 */
5038 unsigned int reserved4
:1; /* 4 */
5039 unsigned int Total_frame_size
:27; /* 5..31 */
5041 *table
; /* Unwind table. */
5042 unsigned long table_len
; /* Length of unwind table. */
5043 bfd_vma seg_base
; /* Starting address of segment. */
5044 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5045 unsigned long nsyms
; /* Number of symbols. */
5046 char *strtab
; /* The string table. */
5047 unsigned long strtab_size
; /* Size of string table. */
5051 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5053 struct hppa_unw_table_entry
*tp
;
5055 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5058 const char *procname
;
5060 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5061 aux
->strtab_size
, tp
->start
, &procname
,
5064 fputs ("\n<", stdout
);
5068 fputs (procname
, stdout
);
5071 printf ("+%lx", (unsigned long) offset
);
5074 fputs (">: [", stdout
);
5075 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5076 fputc ('-', stdout
);
5077 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5080 #define PF(_m) if (tp->_m) printf (#_m " ");
5081 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5084 PF(Millicode_save_sr0
);
5085 /* PV(Region_description); */
5091 PF(Separate_Package_Body
);
5092 PF(Frame_Extension_Millicode
);
5093 PF(Stack_Overflow_Check
);
5094 PF(Two_Instruction_SP_Increment
);
5098 PF(sched_entry_seq
);
5101 PF(Save_MRP_in_frame
);
5102 PF(extn_ptr_defined
);
5103 PF(Cleanup_defined
);
5104 PF(MPE_XL_interrupt_marker
);
5105 PF(HP_UX_interrupt_marker
);
5108 PV(Total_frame_size
);
5117 slurp_hppa_unwind_table (FILE *file
,
5118 struct hppa_unw_aux_info
*aux
,
5119 Elf_Internal_Shdr
*sec
)
5121 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5122 Elf_Internal_Phdr
*seg
;
5123 struct hppa_unw_table_entry
*tep
;
5124 Elf_Internal_Shdr
*relsec
;
5125 Elf_Internal_Rela
*rela
, *rp
;
5126 unsigned char *table
, *tp
;
5127 Elf_Internal_Sym
*sym
;
5128 const char *relname
;
5130 /* First, find the starting address of the segment that includes
5133 if (elf_header
.e_phnum
)
5135 if (! get_program_headers (file
))
5138 for (seg
= program_headers
;
5139 seg
< program_headers
+ elf_header
.e_phnum
;
5142 if (seg
->p_type
!= PT_LOAD
)
5145 if (sec
->sh_addr
>= seg
->p_vaddr
5146 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5148 aux
->seg_base
= seg
->p_vaddr
;
5154 /* Second, build the unwind table from the contents of the unwind
5156 size
= sec
->sh_size
;
5157 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5162 nentries
= size
/ unw_ent_size
;
5163 size
= unw_ent_size
* nentries
;
5165 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5167 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5169 unsigned int tmp1
, tmp2
;
5171 tep
->start
.section
= SHN_UNDEF
;
5172 tep
->end
.section
= SHN_UNDEF
;
5174 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5175 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5176 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5177 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5179 tep
->start
.offset
+= aux
->seg_base
;
5180 tep
->end
.offset
+= aux
->seg_base
;
5182 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5183 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5184 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5185 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5186 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5187 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5188 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5189 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5190 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5191 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5192 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5193 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5194 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5195 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5196 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5197 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5198 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5199 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5200 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5201 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5202 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5203 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5204 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5205 tep
->Cleanup_defined
= tmp1
& 0x1;
5207 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5208 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5209 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5210 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5211 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5212 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5216 /* Third, apply any relocations to the unwind table. */
5218 for (relsec
= section_headers
;
5219 relsec
< section_headers
+ elf_header
.e_shnum
;
5222 if (relsec
->sh_type
!= SHT_RELA
5223 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5224 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5227 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5231 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5235 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5236 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5240 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5241 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5244 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5245 if (strncmp (relname
, "R_PARISC_SEGREL", 15) != 0)
5247 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5251 i
= rp
->r_offset
/ unw_ent_size
;
5253 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5256 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5257 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5260 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5261 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5271 aux
->table_len
= nentries
;
5277 hppa_process_unwind (FILE *file
)
5279 struct hppa_unw_aux_info aux
;
5280 Elf_Internal_Shdr
*unwsec
= NULL
;
5281 Elf_Internal_Shdr
*strsec
;
5282 Elf_Internal_Shdr
*sec
;
5285 memset (& aux
, 0, sizeof (aux
));
5287 if (string_table
== NULL
)
5290 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5292 if (sec
->sh_type
== SHT_SYMTAB
5293 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5295 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5296 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5298 strsec
= SECTION_HEADER (sec
->sh_link
);
5299 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5300 1, strsec
->sh_size
, _("string table"));
5301 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5303 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5308 printf (_("\nThere are no unwind sections in this file.\n"));
5310 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5312 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5314 printf (_("\nUnwind section "));
5315 printf (_("'%s'"), SECTION_NAME (sec
));
5317 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5318 (unsigned long) sec
->sh_offset
,
5319 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5321 slurp_hppa_unwind_table (file
, &aux
, sec
);
5322 if (aux
.table_len
> 0)
5323 dump_hppa_unwind (&aux
);
5326 free ((char *) aux
.table
);
5334 free ((char *) aux
.strtab
);
5340 process_unwind (FILE *file
)
5342 struct unwind_handler
{
5344 int (*handler
)(FILE *file
);
5346 { EM_IA_64
, ia64_process_unwind
},
5347 { EM_PARISC
, hppa_process_unwind
},
5355 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5356 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5357 return handlers
[i
].handler (file
);
5359 printf (_("\nThere are no unwind sections in this file.\n"));
5364 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5366 switch (entry
->d_tag
)
5369 if (entry
->d_un
.d_val
== 0)
5373 static const char * opts
[] =
5375 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5376 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5377 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5378 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5383 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
5384 if (entry
->d_un
.d_val
& (1 << cnt
))
5386 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5393 case DT_MIPS_IVERSION
:
5394 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5395 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5397 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5400 case DT_MIPS_TIME_STAMP
:
5405 time_t time
= entry
->d_un
.d_val
;
5406 tmp
= gmtime (&time
);
5407 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5408 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5409 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5410 printf ("Time Stamp: %s\n", timebuf
);
5414 case DT_MIPS_RLD_VERSION
:
5415 case DT_MIPS_LOCAL_GOTNO
:
5416 case DT_MIPS_CONFLICTNO
:
5417 case DT_MIPS_LIBLISTNO
:
5418 case DT_MIPS_SYMTABNO
:
5419 case DT_MIPS_UNREFEXTNO
:
5420 case DT_MIPS_HIPAGENO
:
5421 case DT_MIPS_DELTA_CLASS_NO
:
5422 case DT_MIPS_DELTA_INSTANCE_NO
:
5423 case DT_MIPS_DELTA_RELOC_NO
:
5424 case DT_MIPS_DELTA_SYM_NO
:
5425 case DT_MIPS_DELTA_CLASSSYM_NO
:
5426 case DT_MIPS_COMPACT_SIZE
:
5427 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5431 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5437 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5439 switch (entry
->d_tag
)
5441 case DT_HP_DLD_FLAGS
:
5450 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5451 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5452 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5453 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5454 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5455 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5456 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5457 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5458 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5459 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5460 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5461 { DT_HP_GST
, "HP_GST" },
5462 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5463 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5464 { DT_HP_NODELETE
, "HP_NODELETE" },
5465 { DT_HP_GROUP
, "HP_GROUP" },
5466 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5470 bfd_vma val
= entry
->d_un
.d_val
;
5472 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
5473 if (val
& flags
[cnt
].bit
)
5477 fputs (flags
[cnt
].str
, stdout
);
5479 val
^= flags
[cnt
].bit
;
5482 if (val
!= 0 || first
)
5486 print_vma (val
, HEX
);
5492 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5499 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5501 switch (entry
->d_tag
)
5503 case DT_IA_64_PLT_RESERVE
:
5504 /* First 3 slots reserved. */
5505 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5507 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5511 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5518 get_32bit_dynamic_section (FILE *file
)
5520 Elf32_External_Dyn
*edyn
, *ext
;
5521 Elf_Internal_Dyn
*entry
;
5523 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5524 _("dynamic section"));
5528 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5529 might not have the luxury of section headers. Look for the DT_NULL
5530 terminator to determine the number of entries. */
5531 for (ext
= edyn
, dynamic_nent
= 0;
5532 (char *) ext
< (char *) edyn
+ dynamic_size
;
5536 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5540 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5541 if (dynamic_section
== NULL
)
5543 error (_("Out of memory\n"));
5548 for (ext
= edyn
, entry
= dynamic_section
;
5549 entry
< dynamic_section
+ dynamic_nent
;
5552 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5553 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5562 get_64bit_dynamic_section (FILE *file
)
5564 Elf64_External_Dyn
*edyn
, *ext
;
5565 Elf_Internal_Dyn
*entry
;
5567 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5568 _("dynamic section"));
5572 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5573 might not have the luxury of section headers. Look for the DT_NULL
5574 terminator to determine the number of entries. */
5575 for (ext
= edyn
, dynamic_nent
= 0;
5576 (char *) ext
< (char *) edyn
+ dynamic_size
;
5580 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5584 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5585 if (dynamic_section
== NULL
)
5587 error (_("Out of memory\n"));
5592 for (ext
= edyn
, entry
= dynamic_section
;
5593 entry
< dynamic_section
+ dynamic_nent
;
5596 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5597 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5606 print_dynamic_flags (bfd_vma flags
)
5614 flag
= flags
& - flags
;
5624 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5625 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5626 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5627 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5628 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5629 default: fputs ("unknown", stdout
); break;
5635 /* Parse and display the contents of the dynamic section. */
5638 process_dynamic_section (FILE *file
)
5640 Elf_Internal_Dyn
*entry
;
5642 if (dynamic_size
== 0)
5645 printf (_("\nThere is no dynamic section in this file.\n"));
5652 if (! get_32bit_dynamic_section (file
))
5655 else if (! get_64bit_dynamic_section (file
))
5658 /* Find the appropriate symbol table. */
5659 if (dynamic_symbols
== NULL
)
5661 for (entry
= dynamic_section
;
5662 entry
< dynamic_section
+ dynamic_nent
;
5665 Elf_Internal_Shdr section
;
5667 if (entry
->d_tag
!= DT_SYMTAB
)
5670 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5672 /* Since we do not know how big the symbol table is,
5673 we default to reading in the entire file (!) and
5674 processing that. This is overkill, I know, but it
5676 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5678 if (archive_file_offset
!= 0)
5679 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5682 if (fseek (file
, 0, SEEK_END
))
5683 error (_("Unable to seek to end of file!"));
5685 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5689 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5691 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5693 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5694 if (num_dynamic_syms
< 1)
5696 error (_("Unable to determine the number of symbols to load\n"));
5700 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5704 /* Similarly find a string table. */
5705 if (dynamic_strings
== NULL
)
5707 for (entry
= dynamic_section
;
5708 entry
< dynamic_section
+ dynamic_nent
;
5711 unsigned long offset
;
5714 if (entry
->d_tag
!= DT_STRTAB
)
5717 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5719 /* Since we do not know how big the string table is,
5720 we default to reading in the entire file (!) and
5721 processing that. This is overkill, I know, but it
5724 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5726 if (archive_file_offset
!= 0)
5727 str_tab_len
= archive_file_size
- offset
;
5730 if (fseek (file
, 0, SEEK_END
))
5731 error (_("Unable to seek to end of file\n"));
5732 str_tab_len
= ftell (file
) - offset
;
5735 if (str_tab_len
< 1)
5738 (_("Unable to determine the length of the dynamic string table\n"));
5742 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5743 _("dynamic string table"));
5744 dynamic_strings_length
= str_tab_len
;
5749 /* And find the syminfo section if available. */
5750 if (dynamic_syminfo
== NULL
)
5752 unsigned long syminsz
= 0;
5754 for (entry
= dynamic_section
;
5755 entry
< dynamic_section
+ dynamic_nent
;
5758 if (entry
->d_tag
== DT_SYMINENT
)
5760 /* Note: these braces are necessary to avoid a syntax
5761 error from the SunOS4 C compiler. */
5762 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5764 else if (entry
->d_tag
== DT_SYMINSZ
)
5765 syminsz
= entry
->d_un
.d_val
;
5766 else if (entry
->d_tag
== DT_SYMINFO
)
5767 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5771 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5773 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5774 Elf_Internal_Syminfo
*syminfo
;
5776 /* There is a syminfo section. Read the data. */
5777 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5778 syminsz
, _("symbol information"));
5782 dynamic_syminfo
= malloc (syminsz
);
5783 if (dynamic_syminfo
== NULL
)
5785 error (_("Out of memory\n"));
5789 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5790 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5791 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5792 ++syminfo
, ++extsym
)
5794 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5795 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5802 if (do_dynamic
&& dynamic_addr
)
5803 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5804 dynamic_addr
, dynamic_nent
);
5806 printf (_(" Tag Type Name/Value\n"));
5808 for (entry
= dynamic_section
;
5809 entry
< dynamic_section
+ dynamic_nent
;
5817 print_vma (entry
->d_tag
, FULL_HEX
);
5818 dtype
= get_dynamic_type (entry
->d_tag
);
5819 printf (" (%s)%*s", dtype
,
5820 ((is_32bit_elf
? 27 : 19)
5821 - (int) strlen (dtype
)),
5825 switch (entry
->d_tag
)
5829 print_dynamic_flags (entry
->d_un
.d_val
);
5839 switch (entry
->d_tag
)
5842 printf (_("Auxiliary library"));
5846 printf (_("Filter library"));
5850 printf (_("Configuration file"));
5854 printf (_("Dependency audit library"));
5858 printf (_("Audit library"));
5862 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5863 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5867 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5876 printf (_("Flags:"));
5878 if (entry
->d_un
.d_val
== 0)
5879 printf (_(" None\n"));
5882 unsigned long int val
= entry
->d_un
.d_val
;
5884 if (val
& DTF_1_PARINIT
)
5886 printf (" PARINIT");
5887 val
^= DTF_1_PARINIT
;
5889 if (val
& DTF_1_CONFEXP
)
5891 printf (" CONFEXP");
5892 val
^= DTF_1_CONFEXP
;
5895 printf (" %lx", val
);
5904 printf (_("Flags:"));
5906 if (entry
->d_un
.d_val
== 0)
5907 printf (_(" None\n"));
5910 unsigned long int val
= entry
->d_un
.d_val
;
5912 if (val
& DF_P1_LAZYLOAD
)
5914 printf (" LAZYLOAD");
5915 val
^= DF_P1_LAZYLOAD
;
5917 if (val
& DF_P1_GROUPPERM
)
5919 printf (" GROUPPERM");
5920 val
^= DF_P1_GROUPPERM
;
5923 printf (" %lx", val
);
5932 printf (_("Flags:"));
5933 if (entry
->d_un
.d_val
== 0)
5934 printf (_(" None\n"));
5937 unsigned long int val
= entry
->d_un
.d_val
;
5944 if (val
& DF_1_GLOBAL
)
5949 if (val
& DF_1_GROUP
)
5954 if (val
& DF_1_NODELETE
)
5956 printf (" NODELETE");
5957 val
^= DF_1_NODELETE
;
5959 if (val
& DF_1_LOADFLTR
)
5961 printf (" LOADFLTR");
5962 val
^= DF_1_LOADFLTR
;
5964 if (val
& DF_1_INITFIRST
)
5966 printf (" INITFIRST");
5967 val
^= DF_1_INITFIRST
;
5969 if (val
& DF_1_NOOPEN
)
5974 if (val
& DF_1_ORIGIN
)
5979 if (val
& DF_1_DIRECT
)
5984 if (val
& DF_1_TRANS
)
5989 if (val
& DF_1_INTERPOSE
)
5991 printf (" INTERPOSE");
5992 val
^= DF_1_INTERPOSE
;
5994 if (val
& DF_1_NODEFLIB
)
5996 printf (" NODEFLIB");
5997 val
^= DF_1_NODEFLIB
;
5999 if (val
& DF_1_NODUMP
)
6004 if (val
& DF_1_CONLFAT
)
6006 printf (" CONLFAT");
6007 val
^= DF_1_CONLFAT
;
6010 printf (" %lx", val
);
6017 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6019 puts (get_dynamic_type (entry
->d_un
.d_val
));
6039 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6045 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6046 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6052 switch (entry
->d_tag
)
6055 printf (_("Shared library: [%s]"), name
);
6057 if (streq (name
, program_interpreter
))
6058 printf (_(" program interpreter"));
6062 printf (_("Library soname: [%s]"), name
);
6066 printf (_("Library rpath: [%s]"), name
);
6070 printf (_("Library runpath: [%s]"), name
);
6074 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6079 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6092 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6096 case DT_INIT_ARRAYSZ
:
6097 case DT_FINI_ARRAYSZ
:
6098 case DT_GNU_CONFLICTSZ
:
6099 case DT_GNU_LIBLISTSZ
:
6102 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6103 printf (" (bytes)\n");
6113 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6126 if (entry
->d_tag
== DT_USED
6127 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6129 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6133 printf (_("Not needed object: [%s]\n"), name
);
6138 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6144 /* The value of this entry is ignored. */
6149 case DT_GNU_PRELINKED
:
6153 time_t time
= entry
->d_un
.d_val
;
6155 tmp
= gmtime (&time
);
6156 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6157 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6158 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6164 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6165 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6170 switch (elf_header
.e_machine
)
6173 case EM_MIPS_RS3_LE
:
6174 dynamic_section_mips_val (entry
);
6177 dynamic_section_parisc_val (entry
);
6180 dynamic_section_ia64_val (entry
);
6183 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6195 get_ver_flags (unsigned int flags
)
6197 static char buff
[32];
6204 if (flags
& VER_FLG_BASE
)
6205 strcat (buff
, "BASE ");
6207 if (flags
& VER_FLG_WEAK
)
6209 if (flags
& VER_FLG_BASE
)
6210 strcat (buff
, "| ");
6212 strcat (buff
, "WEAK ");
6215 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6216 strcat (buff
, "| <unknown>");
6221 /* Display the contents of the version sections. */
6223 process_version_sections (FILE *file
)
6225 Elf_Internal_Shdr
*section
;
6232 for (i
= 0, section
= section_headers
;
6233 i
< elf_header
.e_shnum
;
6236 switch (section
->sh_type
)
6238 case SHT_GNU_verdef
:
6240 Elf_External_Verdef
*edefs
;
6247 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6248 SECTION_NAME (section
), section
->sh_info
);
6250 printf (_(" Addr: 0x"));
6251 printf_vma (section
->sh_addr
);
6252 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6253 (unsigned long) section
->sh_offset
, section
->sh_link
,
6254 SECTION_HEADER_INDEX (section
->sh_link
)
6255 < elf_header
.e_shnum
6256 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6259 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6261 _("version definition section"));
6265 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6268 Elf_External_Verdef
*edef
;
6269 Elf_Internal_Verdef ent
;
6270 Elf_External_Verdaux
*eaux
;
6271 Elf_Internal_Verdaux aux
;
6275 vstart
= ((char *) edefs
) + idx
;
6277 edef
= (Elf_External_Verdef
*) vstart
;
6279 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6280 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6281 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6282 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6283 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6284 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6285 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6287 printf (_(" %#06x: Rev: %d Flags: %s"),
6288 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6290 printf (_(" Index: %d Cnt: %d "),
6291 ent
.vd_ndx
, ent
.vd_cnt
);
6293 vstart
+= ent
.vd_aux
;
6295 eaux
= (Elf_External_Verdaux
*) vstart
;
6297 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6298 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6300 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6301 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6303 printf (_("Name index: %ld\n"), aux
.vda_name
);
6305 isum
= idx
+ ent
.vd_aux
;
6307 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6309 isum
+= aux
.vda_next
;
6310 vstart
+= aux
.vda_next
;
6312 eaux
= (Elf_External_Verdaux
*) vstart
;
6314 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6315 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6317 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6318 printf (_(" %#06x: Parent %d: %s\n"),
6319 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6321 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6322 isum
, j
, aux
.vda_name
);
6332 case SHT_GNU_verneed
:
6334 Elf_External_Verneed
*eneed
;
6340 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6341 SECTION_NAME (section
), section
->sh_info
);
6343 printf (_(" Addr: 0x"));
6344 printf_vma (section
->sh_addr
);
6345 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6346 (unsigned long) section
->sh_offset
, section
->sh_link
,
6347 SECTION_HEADER_INDEX (section
->sh_link
)
6348 < elf_header
.e_shnum
6349 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6352 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6354 _("version need section"));
6358 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6360 Elf_External_Verneed
*entry
;
6361 Elf_Internal_Verneed ent
;
6366 vstart
= ((char *) eneed
) + idx
;
6368 entry
= (Elf_External_Verneed
*) vstart
;
6370 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6371 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6372 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6373 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6374 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6376 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6378 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6379 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6381 printf (_(" File: %lx"), ent
.vn_file
);
6383 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6385 vstart
+= ent
.vn_aux
;
6387 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6389 Elf_External_Vernaux
*eaux
;
6390 Elf_Internal_Vernaux aux
;
6392 eaux
= (Elf_External_Vernaux
*) vstart
;
6394 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6395 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6396 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6397 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6398 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6400 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6401 printf (_(" %#06x: Name: %s"),
6402 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6404 printf (_(" %#06x: Name index: %lx"),
6405 isum
, aux
.vna_name
);
6407 printf (_(" Flags: %s Version: %d\n"),
6408 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6410 isum
+= aux
.vna_next
;
6411 vstart
+= aux
.vna_next
;
6421 case SHT_GNU_versym
:
6423 Elf_Internal_Shdr
*link_section
;
6426 unsigned char *edata
;
6427 unsigned short *data
;
6429 Elf_Internal_Sym
*symbols
;
6430 Elf_Internal_Shdr
*string_sec
;
6433 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6436 link_section
= SECTION_HEADER (section
->sh_link
);
6437 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6439 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6440 >= elf_header
.e_shnum
)
6445 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6447 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6449 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6450 string_sec
->sh_size
, _("version string table"));
6454 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6455 SECTION_NAME (section
), total
);
6457 printf (_(" Addr: "));
6458 printf_vma (section
->sh_addr
);
6459 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6460 (unsigned long) section
->sh_offset
, section
->sh_link
,
6461 SECTION_NAME (link_section
));
6463 off
= offset_from_vma (file
,
6464 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6465 total
* sizeof (short));
6466 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6467 _("version symbol data"));
6474 data
= cmalloc (total
, sizeof (short));
6476 for (cnt
= total
; cnt
--;)
6477 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6482 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6485 int check_def
, check_need
;
6488 printf (" %03x:", cnt
);
6490 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6491 switch (data
[cnt
+ j
])
6494 fputs (_(" 0 (*local*) "), stdout
);
6498 fputs (_(" 1 (*global*) "), stdout
);
6502 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6503 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6507 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6508 >= elf_header
.e_shnum
6509 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6512 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6519 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6521 Elf_Internal_Verneed ivn
;
6522 unsigned long offset
;
6524 offset
= offset_from_vma
6525 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6526 sizeof (Elf_External_Verneed
));
6530 Elf_Internal_Vernaux ivna
;
6531 Elf_External_Verneed evn
;
6532 Elf_External_Vernaux evna
;
6533 unsigned long a_off
;
6535 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6538 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6539 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6541 a_off
= offset
+ ivn
.vn_aux
;
6545 get_data (&evna
, file
, a_off
, sizeof (evna
),
6546 1, _("version need aux (2)"));
6548 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6549 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6551 a_off
+= ivna
.vna_next
;
6553 while (ivna
.vna_other
!= data
[cnt
+ j
]
6554 && ivna
.vna_next
!= 0);
6556 if (ivna
.vna_other
== data
[cnt
+ j
])
6558 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6560 name
= strtab
+ ivna
.vna_name
;
6561 nn
+= printf ("(%s%-*s",
6563 12 - (int) strlen (name
),
6569 offset
+= ivn
.vn_next
;
6571 while (ivn
.vn_next
);
6574 if (check_def
&& data
[cnt
+ j
] != 0x8001
6575 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6577 Elf_Internal_Verdef ivd
;
6578 Elf_External_Verdef evd
;
6579 unsigned long offset
;
6581 offset
= offset_from_vma
6582 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6587 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6590 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6591 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6593 offset
+= ivd
.vd_next
;
6595 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6596 && ivd
.vd_next
!= 0);
6598 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6600 Elf_External_Verdaux evda
;
6601 Elf_Internal_Verdaux ivda
;
6603 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6605 get_data (&evda
, file
,
6606 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6608 _("version def aux"));
6610 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6612 name
= strtab
+ ivda
.vda_name
;
6613 nn
+= printf ("(%s%-*s",
6615 12 - (int) strlen (name
),
6621 printf ("%*c", 18 - nn
, ' ');
6639 printf (_("\nNo version information found in this file.\n"));
6645 get_symbol_binding (unsigned int binding
)
6647 static char buff
[32];
6651 case STB_LOCAL
: return "LOCAL";
6652 case STB_GLOBAL
: return "GLOBAL";
6653 case STB_WEAK
: return "WEAK";
6655 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6656 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6658 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6659 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6661 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6667 get_symbol_type (unsigned int type
)
6669 static char buff
[32];
6673 case STT_NOTYPE
: return "NOTYPE";
6674 case STT_OBJECT
: return "OBJECT";
6675 case STT_FUNC
: return "FUNC";
6676 case STT_SECTION
: return "SECTION";
6677 case STT_FILE
: return "FILE";
6678 case STT_COMMON
: return "COMMON";
6679 case STT_TLS
: return "TLS";
6681 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6683 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6684 return "THUMB_FUNC";
6686 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6689 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6690 return "PARISC_MILLI";
6692 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6694 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6696 if (elf_header
.e_machine
== EM_PARISC
)
6698 if (type
== STT_HP_OPAQUE
)
6700 if (type
== STT_HP_STUB
)
6704 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6707 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6713 get_symbol_visibility (unsigned int visibility
)
6717 case STV_DEFAULT
: return "DEFAULT";
6718 case STV_INTERNAL
: return "INTERNAL";
6719 case STV_HIDDEN
: return "HIDDEN";
6720 case STV_PROTECTED
: return "PROTECTED";
6726 get_mips_symbol_other (unsigned int other
)
6730 case STO_OPTIONAL
: return "OPTIONAL";
6731 case STO_MIPS16
: return "MIPS16";
6732 default: return NULL
;
6737 get_symbol_other (unsigned int other
)
6739 const char * result
= NULL
;
6740 static char buff
[32];
6745 switch (elf_header
.e_machine
)
6748 result
= get_mips_symbol_other (other
);
6756 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
6761 get_symbol_index_type (unsigned int type
)
6763 static char buff
[32];
6767 case SHN_UNDEF
: return "UND";
6768 case SHN_ABS
: return "ABS";
6769 case SHN_COMMON
: return "COM";
6771 if (type
== SHN_IA_64_ANSI_COMMON
6772 && elf_header
.e_machine
== EM_IA_64
6773 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6775 else if (elf_header
.e_machine
== EM_X86_64
6776 && type
== SHN_X86_64_LCOMMON
)
6778 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6779 sprintf (buff
, "PRC[0x%04x]", type
);
6780 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6781 sprintf (buff
, "OS [0x%04x]", type
);
6782 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6783 sprintf (buff
, "RSV[0x%04x]", type
);
6785 sprintf (buff
, "%3d", type
);
6793 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
6795 unsigned char *e_data
;
6798 e_data
= cmalloc (number
, ent_size
);
6802 error (_("Out of memory\n"));
6806 if (fread (e_data
, ent_size
, number
, file
) != number
)
6808 error (_("Unable to read in dynamic data\n"));
6812 i_data
= cmalloc (number
, sizeof (*i_data
));
6816 error (_("Out of memory\n"));
6822 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
6829 /* Dump the symbol table. */
6831 process_symbol_table (FILE *file
)
6833 Elf_Internal_Shdr
*section
;
6834 bfd_vma nbuckets
= 0;
6835 bfd_vma nchains
= 0;
6836 bfd_vma
*buckets
= NULL
;
6837 bfd_vma
*chains
= NULL
;
6839 if (! do_syms
&& !do_histogram
)
6842 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
6845 unsigned char nb
[8];
6846 unsigned char nc
[8];
6847 int hash_ent_size
= 4;
6849 if ((elf_header
.e_machine
== EM_ALPHA
6850 || elf_header
.e_machine
== EM_S390
6851 || elf_header
.e_machine
== EM_S390_OLD
)
6852 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
6856 (archive_file_offset
6857 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
6858 sizeof nb
+ sizeof nc
)),
6861 error (_("Unable to seek to start of dynamic information"));
6865 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
6867 error (_("Failed to read in number of buckets\n"));
6871 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
6873 error (_("Failed to read in number of chains\n"));
6877 nbuckets
= byte_get (nb
, hash_ent_size
);
6878 nchains
= byte_get (nc
, hash_ent_size
);
6880 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
6881 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
6883 if (buckets
== NULL
|| chains
== NULL
)
6888 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
6893 printf (_("\nSymbol table for image:\n"));
6895 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6897 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6899 for (hn
= 0; hn
< nbuckets
; hn
++)
6904 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
6906 Elf_Internal_Sym
*psym
;
6909 psym
= dynamic_symbols
+ si
;
6911 n
= print_vma (si
, DEC_5
);
6913 fputs (" " + n
, stdout
);
6914 printf (" %3lu: ", hn
);
6915 print_vma (psym
->st_value
, LONG_HEX
);
6917 print_vma (psym
->st_size
, DEC_5
);
6919 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6920 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6921 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6922 /* Check to see if any other bits in the st_other field are set.
6923 Note - displaying this information disrupts the layout of the
6924 table being generated, but for the moment this case is very rare. */
6925 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
6926 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
6927 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
6928 if (VALID_DYNAMIC_NAME (psym
->st_name
))
6929 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
6931 printf (" <corrupt: %14ld>", psym
->st_name
);
6936 else if (do_syms
&& !do_using_dynamic
)
6940 for (i
= 0, section
= section_headers
;
6941 i
< elf_header
.e_shnum
;
6945 char *strtab
= NULL
;
6946 unsigned long int strtab_size
= 0;
6947 Elf_Internal_Sym
*symtab
;
6948 Elf_Internal_Sym
*psym
;
6951 if ( section
->sh_type
!= SHT_SYMTAB
6952 && section
->sh_type
!= SHT_DYNSYM
)
6955 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
6956 SECTION_NAME (section
),
6957 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
6959 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6961 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6963 symtab
= GET_ELF_SYMBOLS (file
, section
);
6967 if (section
->sh_link
== elf_header
.e_shstrndx
)
6969 strtab
= string_table
;
6970 strtab_size
= string_table_length
;
6972 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
6974 Elf_Internal_Shdr
*string_sec
;
6976 string_sec
= SECTION_HEADER (section
->sh_link
);
6978 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
6979 1, string_sec
->sh_size
, _("string table"));
6980 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
6983 for (si
= 0, psym
= symtab
;
6984 si
< section
->sh_size
/ section
->sh_entsize
;
6987 printf ("%6d: ", si
);
6988 print_vma (psym
->st_value
, LONG_HEX
);
6990 print_vma (psym
->st_size
, DEC_5
);
6991 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6992 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6993 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6994 /* Check to see if any other bits in the st_other field are set.
6995 Note - displaying this information disrupts the layout of the
6996 table being generated, but for the moment this case is very rare. */
6997 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
6998 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
6999 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7000 print_symbol (25, psym
->st_name
< strtab_size
7001 ? strtab
+ psym
->st_name
: "<corrupt>");
7003 if (section
->sh_type
== SHT_DYNSYM
&&
7004 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7006 unsigned char data
[2];
7007 unsigned short vers_data
;
7008 unsigned long offset
;
7012 offset
= offset_from_vma
7013 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7014 sizeof data
+ si
* sizeof (vers_data
));
7016 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7017 sizeof (data
), 1, _("version data"));
7019 vers_data
= byte_get (data
, 2);
7021 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7022 < elf_header
.e_shnum
7023 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7026 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7028 if ((vers_data
& 0x8000) || vers_data
> 1)
7030 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7031 && (is_nobits
|| ! check_def
))
7033 Elf_External_Verneed evn
;
7034 Elf_Internal_Verneed ivn
;
7035 Elf_Internal_Vernaux ivna
;
7037 /* We must test both. */
7038 offset
= offset_from_vma
7039 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7044 unsigned long vna_off
;
7046 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7049 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7050 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7052 vna_off
= offset
+ ivn
.vn_aux
;
7056 Elf_External_Vernaux evna
;
7058 get_data (&evna
, file
, vna_off
,
7060 _("version need aux (3)"));
7062 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7063 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7064 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7066 vna_off
+= ivna
.vna_next
;
7068 while (ivna
.vna_other
!= vers_data
7069 && ivna
.vna_next
!= 0);
7071 if (ivna
.vna_other
== vers_data
)
7074 offset
+= ivn
.vn_next
;
7076 while (ivn
.vn_next
!= 0);
7078 if (ivna
.vna_other
== vers_data
)
7081 ivna
.vna_name
< strtab_size
7082 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7086 else if (! is_nobits
)
7087 error (_("bad dynamic symbol"));
7094 if (vers_data
!= 0x8001
7095 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7097 Elf_Internal_Verdef ivd
;
7098 Elf_Internal_Verdaux ivda
;
7099 Elf_External_Verdaux evda
;
7100 unsigned long offset
;
7102 offset
= offset_from_vma
7104 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7105 sizeof (Elf_External_Verdef
));
7109 Elf_External_Verdef evd
;
7111 get_data (&evd
, file
, offset
, sizeof (evd
),
7112 1, _("version def"));
7114 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7115 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7116 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7118 offset
+= ivd
.vd_next
;
7120 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7121 && ivd
.vd_next
!= 0);
7123 offset
-= ivd
.vd_next
;
7124 offset
+= ivd
.vd_aux
;
7126 get_data (&evda
, file
, offset
, sizeof (evda
),
7127 1, _("version def aux"));
7129 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7131 if (psym
->st_name
!= ivda
.vda_name
)
7132 printf ((vers_data
& 0x8000)
7134 ivda
.vda_name
< strtab_size
7135 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7145 if (strtab
!= string_table
)
7151 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7153 if (do_histogram
&& buckets
!= NULL
)
7155 unsigned long *lengths
;
7156 unsigned long *counts
;
7159 unsigned long maxlength
= 0;
7160 unsigned long nzero_counts
= 0;
7161 unsigned long nsyms
= 0;
7163 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7164 (unsigned long) nbuckets
);
7165 printf (_(" Length Number %% of total Coverage\n"));
7167 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7168 if (lengths
== NULL
)
7170 error (_("Out of memory"));
7173 for (hn
= 0; hn
< nbuckets
; ++hn
)
7175 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7178 if (maxlength
< ++lengths
[hn
])
7183 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7186 error (_("Out of memory"));
7190 for (hn
= 0; hn
< nbuckets
; ++hn
)
7191 ++counts
[lengths
[hn
]];
7196 printf (" 0 %-10lu (%5.1f%%)\n",
7197 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7198 for (i
= 1; i
<= maxlength
; ++i
)
7200 nzero_counts
+= counts
[i
] * i
;
7201 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7202 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7203 (nzero_counts
* 100.0) / nsyms
);
7211 if (buckets
!= NULL
)
7221 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7225 if (dynamic_syminfo
== NULL
7227 /* No syminfo, this is ok. */
7230 /* There better should be a dynamic symbol section. */
7231 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7235 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7236 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7238 printf (_(" Num: Name BoundTo Flags\n"));
7239 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7241 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7243 printf ("%4d: ", i
);
7244 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7245 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7247 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7250 switch (dynamic_syminfo
[i
].si_boundto
)
7252 case SYMINFO_BT_SELF
:
7253 fputs ("SELF ", stdout
);
7255 case SYMINFO_BT_PARENT
:
7256 fputs ("PARENT ", stdout
);
7259 if (dynamic_syminfo
[i
].si_boundto
> 0
7260 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7261 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7263 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7267 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7271 if (flags
& SYMINFO_FLG_DIRECT
)
7273 if (flags
& SYMINFO_FLG_PASSTHRU
)
7274 printf (" PASSTHRU");
7275 if (flags
& SYMINFO_FLG_COPY
)
7277 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7278 printf (" LAZYLOAD");
7286 #ifdef SUPPORT_DISASSEMBLY
7288 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7290 printf (_("\nAssembly dump of section %s\n"),
7291 SECTION_NAME (section
));
7293 /* XXX -- to be done --- XXX */
7300 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
7302 bfd_size_type bytes
;
7304 unsigned char *data
;
7305 unsigned char *start
;
7307 bytes
= section
->sh_size
;
7309 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7311 printf (_("\nSection '%s' has no data to dump.\n"),
7312 SECTION_NAME (section
));
7316 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7318 addr
= section
->sh_addr
;
7320 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7333 lbytes
= (bytes
> 16 ? 16 : bytes
);
7335 printf (" 0x%8.8lx ", (unsigned long) addr
);
7337 switch (elf_header
.e_ident
[EI_DATA
])
7341 for (j
= 15; j
>= 0; j
--)
7344 printf ("%2.2x", data
[j
]);
7354 for (j
= 0; j
< 16; j
++)
7357 printf ("%2.2x", data
[j
]);
7367 for (j
= 0; j
< lbytes
; j
++)
7370 if (k
>= ' ' && k
< 0x7f)
7388 /* Apply addends of RELA relocations. */
7391 debug_apply_rela_addends (void *file
,
7392 Elf_Internal_Shdr
*section
,
7393 unsigned char *start
)
7395 Elf_Internal_Shdr
*relsec
;
7396 unsigned char *end
= start
+ section
->sh_size
;
7397 /* FIXME: The relocation field size is relocation type dependent. */
7398 unsigned int reloc_size
= 4;
7400 if (!is_relocatable
)
7403 if (section
->sh_size
< reloc_size
)
7406 for (relsec
= section_headers
;
7407 relsec
< section_headers
+ elf_header
.e_shnum
;
7410 unsigned long nrelas
;
7411 Elf_Internal_Rela
*rela
, *rp
;
7412 Elf_Internal_Shdr
*symsec
;
7413 Elf_Internal_Sym
*symtab
;
7414 Elf_Internal_Sym
*sym
;
7416 if (relsec
->sh_type
!= SHT_RELA
7417 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7418 || SECTION_HEADER (relsec
->sh_info
) != section
7419 || relsec
->sh_size
== 0
7420 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7423 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7427 symsec
= SECTION_HEADER (relsec
->sh_link
);
7428 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7430 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7434 loc
= start
+ rp
->r_offset
;
7435 if ((loc
+ reloc_size
) > end
)
7437 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7438 (unsigned long) rp
->r_offset
,
7439 SECTION_NAME (section
));
7445 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7447 if (ELF32_R_SYM (rp
->r_info
) != 0
7448 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7449 /* Relocations against object symbols can happen,
7450 eg when referencing a global array. For an
7451 example of this see the _clz.o binary in libgcc.a. */
7452 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7454 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7455 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7456 SECTION_NAME (section
));
7462 /* In MIPS little-endian objects, r_info isn't really a
7463 64-bit little-endian value: it has a 32-bit little-endian
7464 symbol index followed by four individual byte fields.
7465 Reorder INFO accordingly. */
7466 if (elf_header
.e_machine
== EM_MIPS
7467 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7468 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7469 | ((rp
->r_info
>> 56) & 0xff)
7470 | ((rp
->r_info
>> 40) & 0xff00)
7471 | ((rp
->r_info
>> 24) & 0xff0000)
7472 | ((rp
->r_info
>> 8) & 0xff000000));
7474 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7476 if (ELF64_R_SYM (rp
->r_info
) != 0
7477 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7478 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7480 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7481 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7482 SECTION_NAME (section
));
7487 byte_put (loc
, rp
->r_addend
, reloc_size
);
7498 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
7500 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7501 Elf_Internal_Shdr
*sec
;
7504 /* If it is already loaded, do nothing. */
7505 if (section
->start
!= NULL
)
7508 /* Locate the debug section. */
7509 sec
= find_section (section
->name
);
7513 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
7514 section
->address
= sec
->sh_addr
;
7515 section
->size
= sec
->sh_size
;
7516 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
7519 if (debug_displays
[debug
].relocate
)
7520 debug_apply_rela_addends (file
, sec
, section
->start
);
7522 return section
->start
!= NULL
;
7526 free_debug_section (enum dwarf_section_display_enum debug
)
7528 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7530 if (section
->start
== NULL
)
7533 free ((char *) section
->start
);
7534 section
->start
= NULL
;
7535 section
->address
= 0;
7540 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
7542 char *name
= SECTION_NAME (section
);
7543 bfd_size_type length
;
7545 enum dwarf_section_display_enum i
;
7547 length
= section
->sh_size
;
7550 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7554 if (strneq (name
, ".gnu.linkonce.wi.", 17))
7555 name
= ".debug_info";
7557 /* See if we know how to display the contents of this section. */
7558 for (i
= 0; i
< max
; i
++)
7559 if (streq (debug_displays
[i
].section
.name
, name
))
7561 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
7563 if (load_debug_section (i
, file
))
7565 result
&= debug_displays
[i
].display (sec
, file
);
7567 if (i
!= info
&& i
!= abbrev
)
7568 free_debug_section (i
);
7576 printf (_("Unrecognized debug section: %s\n"), name
);
7583 /* Set DUMP_SECTS for all sections where dumps were requested
7584 based on section name. */
7587 initialise_dumps_byname (void)
7589 struct dump_list_entry
*cur
;
7591 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
7596 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
7597 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
7599 request_dump (i
, cur
->type
);
7604 warn (_("Section '%s' was not dumped because it does not exist!\n"),
7610 process_section_contents (FILE *file
)
7612 Elf_Internal_Shdr
*section
;
7618 initialise_dumps_byname ();
7620 for (i
= 0, section
= section_headers
;
7621 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
7624 #ifdef SUPPORT_DISASSEMBLY
7625 if (dump_sects
[i
] & DISASS_DUMP
)
7626 disassemble_section (section
, file
);
7628 if (dump_sects
[i
] & HEX_DUMP
)
7629 dump_section (section
, file
);
7631 if (dump_sects
[i
] & DEBUG_DUMP
)
7632 display_debug_section (section
, file
);
7635 /* Check to see if the user requested a
7636 dump of a section that does not exist. */
7637 while (i
++ < num_dump_sects
)
7639 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
7643 process_mips_fpe_exception (int mask
)
7648 if (mask
& OEX_FPU_INEX
)
7649 fputs ("INEX", stdout
), first
= 0;
7650 if (mask
& OEX_FPU_UFLO
)
7651 printf ("%sUFLO", first
? "" : "|"), first
= 0;
7652 if (mask
& OEX_FPU_OFLO
)
7653 printf ("%sOFLO", first
? "" : "|"), first
= 0;
7654 if (mask
& OEX_FPU_DIV0
)
7655 printf ("%sDIV0", first
? "" : "|"), first
= 0;
7656 if (mask
& OEX_FPU_INVAL
)
7657 printf ("%sINVAL", first
? "" : "|");
7660 fputs ("0", stdout
);
7663 /* ARM EABI attributes section. */
7668 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
7671 } arm_attr_public_tag
;
7673 static const char *arm_attr_tag_CPU_arch
[] =
7674 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
7676 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
7677 static const char *arm_attr_tag_THUMB_ISA_use
[] =
7678 {"No", "Thumb-1", "Thumb-2"};
7679 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2"};
7680 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
7681 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
7682 static const char *arm_attr_tag_ABI_PCS_config
[] =
7683 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
7684 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
7685 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
7686 {"V6", "SB", "TLS", "Unused"};
7687 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
7688 {"Absolute", "PC-relative", "SB-relative", "None"};
7689 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
7690 {"Absolute", "PC-relative", "None"};
7691 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
7692 {"None", "direct", "GOT-indirect"};
7693 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
7694 {"None", "??? 1", "2", "??? 3", "4"};
7695 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
7696 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
7697 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
7698 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
7699 static const char *arm_attr_tag_ABI_FP_number_model
[] =
7700 {"Unused", "Finite", "RTABI", "IEEE 754"};
7701 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
7702 static const char *arm_attr_tag_ABI_align8_preserved
[] =
7703 {"No", "Yes, except leaf SP", "Yes"};
7704 static const char *arm_attr_tag_ABI_enum_size
[] =
7705 {"Unused", "small", "int", "forced to int"};
7706 static const char *arm_attr_tag_ABI_HardFP_use
[] =
7707 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
7708 static const char *arm_attr_tag_ABI_VFP_args
[] =
7709 {"AAPCS", "VFP registers", "custom"};
7710 static const char *arm_attr_tag_ABI_WMMX_args
[] =
7711 {"AAPCS", "WMMX registers", "custom"};
7712 static const char *arm_attr_tag_ABI_optimization_goals
[] =
7713 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7714 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
7715 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
7716 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7717 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
7719 #define LOOKUP(id, name) \
7720 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
7721 static arm_attr_public_tag arm_attr_public_tags
[] =
7723 {4, "CPU_raw_name", 1, NULL
},
7724 {5, "CPU_name", 1, NULL
},
7725 LOOKUP(6, CPU_arch
),
7726 {7, "CPU_arch_profile", 0, NULL
},
7727 LOOKUP(8, ARM_ISA_use
),
7728 LOOKUP(9, THUMB_ISA_use
),
7729 LOOKUP(10, VFP_arch
),
7730 LOOKUP(11, WMMX_arch
),
7731 LOOKUP(12, NEON_arch
),
7732 LOOKUP(13, ABI_PCS_config
),
7733 LOOKUP(14, ABI_PCS_R9_use
),
7734 LOOKUP(15, ABI_PCS_RW_data
),
7735 LOOKUP(16, ABI_PCS_RO_DATA
),
7736 LOOKUP(17, ABI_PCS_GOT_use
),
7737 LOOKUP(18, ABI_PCS_wchar_t
),
7738 LOOKUP(19, ABI_FP_rounding
),
7739 LOOKUP(20, ABI_FP_denormal
),
7740 LOOKUP(21, ABI_FP_exceptions
),
7741 LOOKUP(22, ABI_FP_user_exceptions
),
7742 LOOKUP(23, ABI_FP_number_model
),
7743 LOOKUP(24, ABI_align8_needed
),
7744 LOOKUP(25, ABI_align8_preserved
),
7745 LOOKUP(26, ABI_enum_size
),
7746 LOOKUP(27, ABI_HardFP_use
),
7747 LOOKUP(28, ABI_VFP_args
),
7748 LOOKUP(29, ABI_WMMX_args
),
7749 LOOKUP(30, ABI_optimization_goals
),
7750 LOOKUP(31, ABI_FP_optimization_goals
),
7751 {32, "compatibility", 0, NULL
}
7755 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
7758 read_uleb128 (unsigned char *p
, unsigned int *plen
)
7772 val
|= ((unsigned int)c
& 0x7f) << shift
;
7781 static unsigned char *
7782 display_arm_attribute (unsigned char *p
)
7787 arm_attr_public_tag
*attr
;
7791 tag
= read_uleb128 (p
, &len
);
7794 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
7796 if (arm_attr_public_tags
[i
].tag
== tag
)
7798 attr
= &arm_attr_public_tags
[i
];
7805 printf (" Tag_%s: ", attr
->name
);
7811 case 7: /* Tag_CPU_arch_profile. */
7812 val
= read_uleb128 (p
, &len
);
7816 case 0: printf ("None\n"); break;
7817 case 'A': printf ("Application\n"); break;
7818 case 'R': printf ("Realtime\n"); break;
7819 case 'M': printf ("Microcontroller\n"); break;
7820 default: printf ("??? (%d)\n", val
); break;
7824 case 32: /* Tag_compatibility. */
7825 val
= read_uleb128 (p
, &len
);
7827 printf ("flag = %d, vendor = %s\n", val
, p
);
7828 p
+= strlen((char *)p
) + 1;
7842 assert (attr
->type
& 0x80);
7843 val
= read_uleb128 (p
, &len
);
7845 type
= attr
->type
& 0x7f;
7847 printf ("??? (%d)\n", val
);
7849 printf ("%s\n", attr
->table
[val
]);
7856 type
= 1; /* String. */
7858 type
= 2; /* uleb128. */
7859 printf (" Tag_unknown_%d: ", tag
);
7864 printf ("\"%s\"\n", p
);
7865 p
+= strlen((char *)p
) + 1;
7869 val
= read_uleb128 (p
, &len
);
7871 printf ("%d (0x%x)\n", val
, val
);
7878 process_arm_specific (FILE *file
)
7880 Elf_Internal_Shdr
*sect
;
7881 unsigned char *contents
;
7884 bfd_vma section_len
;
7888 /* Find the section header so that we get the size. */
7889 for (i
= 0, sect
= section_headers
;
7890 i
< elf_header
.e_shnum
;
7893 if (sect
->sh_type
!= SHT_ARM_ATTRIBUTES
)
7896 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
7904 len
= sect
->sh_size
- 1;
7909 bfd_boolean public_section
;
7911 section_len
= byte_get (p
, 4);
7913 if (section_len
> len
)
7915 printf (_("ERROR: Bad section length (%d > %d)\n"),
7916 (int)section_len
, (int)len
);
7920 printf ("Attribute Section: %s\n", p
);
7921 if (strcmp ((char *)p
, "aeabi") == 0)
7922 public_section
= TRUE
;
7924 public_section
= FALSE
;
7925 namelen
= strlen ((char *)p
) + 1;
7927 section_len
-= namelen
+ 4;
7928 while (section_len
> 0)
7933 size
= byte_get (p
, 4);
7934 if (size
> section_len
)
7936 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
7937 (int)size
, (int)section_len
);
7940 section_len
-= size
;
7946 printf ("File Attributes\n");
7949 printf ("Section Attributes:");
7952 printf ("Symbol Attributes:");
7957 val
= read_uleb128 (p
, &i
);
7961 printf (" %d", val
);
7966 printf ("Unknown tag: %d\n", tag
);
7967 public_section
= FALSE
;
7973 p
= display_arm_attribute(p
);
7977 /* ??? Do something sensible, like dump hex. */
7978 printf (" Unknown section contexts\n");
7986 printf (_("Unknown format '%c'\n"), *p
);
7995 process_mips_specific (FILE *file
)
7997 Elf_Internal_Dyn
*entry
;
7998 size_t liblist_offset
= 0;
7999 size_t liblistno
= 0;
8000 size_t conflictsno
= 0;
8001 size_t options_offset
= 0;
8002 size_t conflicts_offset
= 0;
8004 /* We have a lot of special sections. Thanks SGI! */
8005 if (dynamic_section
== NULL
)
8006 /* No information available. */
8009 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
8010 switch (entry
->d_tag
)
8012 case DT_MIPS_LIBLIST
:
8014 = offset_from_vma (file
, entry
->d_un
.d_val
,
8015 liblistno
* sizeof (Elf32_External_Lib
));
8017 case DT_MIPS_LIBLISTNO
:
8018 liblistno
= entry
->d_un
.d_val
;
8020 case DT_MIPS_OPTIONS
:
8021 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
8023 case DT_MIPS_CONFLICT
:
8025 = offset_from_vma (file
, entry
->d_un
.d_val
,
8026 conflictsno
* sizeof (Elf32_External_Conflict
));
8028 case DT_MIPS_CONFLICTNO
:
8029 conflictsno
= entry
->d_un
.d_val
;
8035 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
8037 Elf32_External_Lib
*elib
;
8040 elib
= get_data (NULL
, file
, liblist_offset
,
8041 liblistno
, sizeof (Elf32_External_Lib
),
8045 printf ("\nSection '.liblist' contains %lu entries:\n",
8046 (unsigned long) liblistno
);
8047 fputs (" Library Time Stamp Checksum Version Flags\n",
8050 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
8057 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8058 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8059 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8060 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8061 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8063 tmp
= gmtime (&time
);
8064 snprintf (timebuf
, sizeof (timebuf
),
8065 "%04u-%02u-%02uT%02u:%02u:%02u",
8066 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8067 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8069 printf ("%3lu: ", (unsigned long) cnt
);
8070 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
8071 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
8073 printf ("<corrupt: %9ld>", liblist
.l_name
);
8074 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
8077 if (liblist
.l_flags
== 0)
8088 { " EXACT_MATCH", LL_EXACT_MATCH
},
8089 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
8090 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
8091 { " EXPORTS", LL_EXPORTS
},
8092 { " DELAY_LOAD", LL_DELAY_LOAD
},
8093 { " DELTA", LL_DELTA
}
8095 int flags
= liblist
.l_flags
;
8099 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
8101 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
8103 fputs (l_flags_vals
[fcnt
].name
, stdout
);
8104 flags
^= l_flags_vals
[fcnt
].bit
;
8107 printf (" %#x", (unsigned int) flags
);
8117 if (options_offset
!= 0)
8119 Elf_External_Options
*eopt
;
8120 Elf_Internal_Shdr
*sect
= section_headers
;
8121 Elf_Internal_Options
*iopt
;
8122 Elf_Internal_Options
*option
;
8126 /* Find the section header so that we get the size. */
8127 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
8130 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
8134 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
8137 error (_("Out of memory"));
8144 while (offset
< sect
->sh_size
)
8146 Elf_External_Options
*eoption
;
8148 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
8150 option
->kind
= BYTE_GET (eoption
->kind
);
8151 option
->size
= BYTE_GET (eoption
->size
);
8152 option
->section
= BYTE_GET (eoption
->section
);
8153 option
->info
= BYTE_GET (eoption
->info
);
8155 offset
+= option
->size
;
8161 printf (_("\nSection '%s' contains %d entries:\n"),
8162 SECTION_NAME (sect
), cnt
);
8170 switch (option
->kind
)
8173 /* This shouldn't happen. */
8174 printf (" NULL %d %lx", option
->section
, option
->info
);
8177 printf (" REGINFO ");
8178 if (elf_header
.e_machine
== EM_MIPS
)
8181 Elf32_External_RegInfo
*ereg
;
8182 Elf32_RegInfo reginfo
;
8184 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
8185 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8186 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8187 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8188 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8189 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8190 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8192 printf ("GPR %08lx GP 0x%lx\n",
8194 (unsigned long) reginfo
.ri_gp_value
);
8195 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8196 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8197 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8202 Elf64_External_RegInfo
*ereg
;
8203 Elf64_Internal_RegInfo reginfo
;
8205 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
8206 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8207 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8208 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8209 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8210 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8211 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8213 printf ("GPR %08lx GP 0x",
8214 reginfo
.ri_gprmask
);
8215 printf_vma (reginfo
.ri_gp_value
);
8218 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8219 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8220 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8224 case ODK_EXCEPTIONS
:
8225 fputs (" EXCEPTIONS fpe_min(", stdout
);
8226 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
8227 fputs (") fpe_max(", stdout
);
8228 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
8229 fputs (")", stdout
);
8231 if (option
->info
& OEX_PAGE0
)
8232 fputs (" PAGE0", stdout
);
8233 if (option
->info
& OEX_SMM
)
8234 fputs (" SMM", stdout
);
8235 if (option
->info
& OEX_FPDBUG
)
8236 fputs (" FPDBUG", stdout
);
8237 if (option
->info
& OEX_DISMISS
)
8238 fputs (" DISMISS", stdout
);
8241 fputs (" PAD ", stdout
);
8242 if (option
->info
& OPAD_PREFIX
)
8243 fputs (" PREFIX", stdout
);
8244 if (option
->info
& OPAD_POSTFIX
)
8245 fputs (" POSTFIX", stdout
);
8246 if (option
->info
& OPAD_SYMBOL
)
8247 fputs (" SYMBOL", stdout
);
8250 fputs (" HWPATCH ", stdout
);
8251 if (option
->info
& OHW_R4KEOP
)
8252 fputs (" R4KEOP", stdout
);
8253 if (option
->info
& OHW_R8KPFETCH
)
8254 fputs (" R8KPFETCH", stdout
);
8255 if (option
->info
& OHW_R5KEOP
)
8256 fputs (" R5KEOP", stdout
);
8257 if (option
->info
& OHW_R5KCVTL
)
8258 fputs (" R5KCVTL", stdout
);
8261 fputs (" FILL ", stdout
);
8262 /* XXX Print content of info word? */
8265 fputs (" TAGS ", stdout
);
8266 /* XXX Print content of info word? */
8269 fputs (" HWAND ", stdout
);
8270 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8271 fputs (" R4KEOP_CHECKED", stdout
);
8272 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8273 fputs (" R4KEOP_CLEAN", stdout
);
8276 fputs (" HWOR ", stdout
);
8277 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8278 fputs (" R4KEOP_CHECKED", stdout
);
8279 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8280 fputs (" R4KEOP_CLEAN", stdout
);
8283 printf (" GP_GROUP %#06lx self-contained %#06lx",
8284 option
->info
& OGP_GROUP
,
8285 (option
->info
& OGP_SELF
) >> 16);
8288 printf (" IDENT %#06lx self-contained %#06lx",
8289 option
->info
& OGP_GROUP
,
8290 (option
->info
& OGP_SELF
) >> 16);
8293 /* This shouldn't happen. */
8294 printf (" %3d ??? %d %lx",
8295 option
->kind
, option
->section
, option
->info
);
8299 len
= sizeof (*eopt
);
8300 while (len
< option
->size
)
8301 if (((char *) option
)[len
] >= ' '
8302 && ((char *) option
)[len
] < 0x7f)
8303 printf ("%c", ((char *) option
)[len
++]);
8305 printf ("\\%03o", ((char *) option
)[len
++]);
8307 fputs ("\n", stdout
);
8315 if (conflicts_offset
!= 0 && conflictsno
!= 0)
8317 Elf32_Conflict
*iconf
;
8320 if (dynamic_symbols
== NULL
)
8322 error (_("conflict list found without a dynamic symbol table"));
8326 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
8329 error (_("Out of memory"));
8335 Elf32_External_Conflict
*econf32
;
8337 econf32
= get_data (NULL
, file
, conflicts_offset
,
8338 conflictsno
, sizeof (*econf32
), _("conflict"));
8342 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8343 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
8349 Elf64_External_Conflict
*econf64
;
8351 econf64
= get_data (NULL
, file
, conflicts_offset
,
8352 conflictsno
, sizeof (*econf64
), _("conflict"));
8356 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8357 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
8362 printf (_("\nSection '.conflict' contains %lu entries:\n"),
8363 (unsigned long) conflictsno
);
8364 puts (_(" Num: Index Value Name"));
8366 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8368 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
8370 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
8371 print_vma (psym
->st_value
, FULL_HEX
);
8373 if (VALID_DYNAMIC_NAME (psym
->st_name
))
8374 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
8376 printf ("<corrupt: %14ld>", psym
->st_name
);
8387 process_gnu_liblist (FILE *file
)
8389 Elf_Internal_Shdr
*section
, *string_sec
;
8390 Elf32_External_Lib
*elib
;
8399 for (i
= 0, section
= section_headers
;
8400 i
< elf_header
.e_shnum
;
8403 switch (section
->sh_type
)
8405 case SHT_GNU_LIBLIST
:
8406 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
8409 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
8414 string_sec
= SECTION_HEADER (section
->sh_link
);
8416 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
8417 string_sec
->sh_size
, _("liblist string table"));
8418 strtab_size
= string_sec
->sh_size
;
8421 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
8427 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
8428 SECTION_NAME (section
),
8429 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
8431 puts (" Library Time Stamp Checksum Version Flags");
8433 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
8441 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8442 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8443 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8444 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8445 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8447 tmp
= gmtime (&time
);
8448 snprintf (timebuf
, sizeof (timebuf
),
8449 "%04u-%02u-%02uT%02u:%02u:%02u",
8450 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8451 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8453 printf ("%3lu: ", (unsigned long) cnt
);
8455 printf ("%-20s", liblist
.l_name
< strtab_size
8456 ? strtab
+ liblist
.l_name
: "<corrupt>");
8458 printf ("%-20.20s", liblist
.l_name
< strtab_size
8459 ? strtab
+ liblist
.l_name
: "<corrupt>");
8460 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
8461 liblist
.l_version
, liblist
.l_flags
);
8472 get_note_type (unsigned e_type
)
8474 static char buff
[64];
8476 if (elf_header
.e_type
== ET_CORE
)
8480 return _("NT_AUXV (auxiliary vector)");
8482 return _("NT_PRSTATUS (prstatus structure)");
8484 return _("NT_FPREGSET (floating point registers)");
8486 return _("NT_PRPSINFO (prpsinfo structure)");
8488 return _("NT_TASKSTRUCT (task structure)");
8490 return _("NT_PRXFPREG (user_xfpregs structure)");
8492 return _("NT_PSTATUS (pstatus structure)");
8494 return _("NT_FPREGS (floating point registers)");
8496 return _("NT_PSINFO (psinfo structure)");
8498 return _("NT_LWPSTATUS (lwpstatus_t structure)");
8500 return _("NT_LWPSINFO (lwpsinfo_t structure)");
8501 case NT_WIN32PSTATUS
:
8502 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8510 return _("NT_VERSION (version)");
8512 return _("NT_ARCH (architecture)");
8517 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8522 get_netbsd_elfcore_note_type (unsigned e_type
)
8524 static char buff
[64];
8526 if (e_type
== NT_NETBSDCORE_PROCINFO
)
8528 /* NetBSD core "procinfo" structure. */
8529 return _("NetBSD procinfo structure");
8532 /* As of Jan 2002 there are no other machine-independent notes
8533 defined for NetBSD core files. If the note type is less
8534 than the start of the machine-dependent note types, we don't
8537 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
8539 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8543 switch (elf_header
.e_machine
)
8545 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8546 and PT_GETFPREGS == mach+2. */
8551 case EM_SPARC32PLUS
:
8555 case NT_NETBSDCORE_FIRSTMACH
+0:
8556 return _("PT_GETREGS (reg structure)");
8557 case NT_NETBSDCORE_FIRSTMACH
+2:
8558 return _("PT_GETFPREGS (fpreg structure)");
8564 /* On all other arch's, PT_GETREGS == mach+1 and
8565 PT_GETFPREGS == mach+3. */
8569 case NT_NETBSDCORE_FIRSTMACH
+1:
8570 return _("PT_GETREGS (reg structure)");
8571 case NT_NETBSDCORE_FIRSTMACH
+3:
8572 return _("PT_GETFPREGS (fpreg structure)");
8578 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
8579 e_type
- NT_NETBSDCORE_FIRSTMACH
);
8583 /* Note that by the ELF standard, the name field is already null byte
8584 terminated, and namesz includes the terminating null byte.
8585 I.E. the value of namesz for the name "FSF" is 4.
8587 If the value of namesz is zero, there is no name present. */
8589 process_note (Elf_Internal_Note
*pnote
)
8593 if (pnote
->namesz
== 0)
8594 /* If there is no note name, then use the default set of
8595 note type strings. */
8596 nt
= get_note_type (pnote
->type
);
8598 else if (strneq (pnote
->namedata
, "NetBSD-CORE", 11))
8599 /* NetBSD-specific core file notes. */
8600 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
8603 /* Don't recognize this note name; just use the default set of
8604 note type strings. */
8605 nt
= get_note_type (pnote
->type
);
8607 printf (" %s\t\t0x%08lx\t%s\n",
8608 pnote
->namesz
? pnote
->namedata
: "(NONE)",
8615 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
8617 Elf_External_Note
*pnotes
;
8618 Elf_External_Note
*external
;
8624 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
8630 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8631 (unsigned long) offset
, (unsigned long) length
);
8632 printf (_(" Owner\t\tData size\tDescription\n"));
8634 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
8636 Elf_External_Note
*next
;
8637 Elf_Internal_Note inote
;
8640 inote
.type
= BYTE_GET (external
->type
);
8641 inote
.namesz
= BYTE_GET (external
->namesz
);
8642 inote
.namedata
= external
->name
;
8643 inote
.descsz
= BYTE_GET (external
->descsz
);
8644 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
8645 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
8647 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
8649 if (((char *) next
) > (((char *) pnotes
) + length
))
8651 warn (_("corrupt note found at offset %lx into core notes\n"),
8652 (long)((char *)external
- (char *)pnotes
));
8653 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
8654 inote
.type
, inote
.namesz
, inote
.descsz
);
8660 /* Verify that name is null terminated. It appears that at least
8661 one version of Linux (RedHat 6.0) generates corefiles that don't
8662 comply with the ELF spec by failing to include the null byte in
8664 if (inote
.namedata
[inote
.namesz
] != '\0')
8666 temp
= malloc (inote
.namesz
+ 1);
8670 error (_("Out of memory\n"));
8675 strncpy (temp
, inote
.namedata
, inote
.namesz
);
8676 temp
[inote
.namesz
] = 0;
8678 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8679 inote
.namedata
= temp
;
8682 res
&= process_note (& inote
);
8697 process_corefile_note_segments (FILE *file
)
8699 Elf_Internal_Phdr
*segment
;
8703 if (! get_program_headers (file
))
8706 for (i
= 0, segment
= program_headers
;
8707 i
< elf_header
.e_phnum
;
8710 if (segment
->p_type
== PT_NOTE
)
8711 res
&= process_corefile_note_segment (file
,
8712 (bfd_vma
) segment
->p_offset
,
8713 (bfd_vma
) segment
->p_filesz
);
8720 process_note_sections (FILE *file
)
8722 Elf_Internal_Shdr
*section
;
8726 for (i
= 0, section
= section_headers
;
8727 i
< elf_header
.e_shnum
;
8729 if (section
->sh_type
== SHT_NOTE
)
8730 res
&= process_corefile_note_segment (file
,
8731 (bfd_vma
) section
->sh_offset
,
8732 (bfd_vma
) section
->sh_size
);
8738 process_notes (FILE *file
)
8740 /* If we have not been asked to display the notes then do nothing. */
8744 if (elf_header
.e_type
!= ET_CORE
)
8745 return process_note_sections (file
);
8747 /* No program headers means no NOTE segment. */
8748 if (elf_header
.e_phnum
> 0)
8749 return process_corefile_note_segments (file
);
8751 printf (_("No note segments present in the core file.\n"));
8756 process_arch_specific (FILE *file
)
8761 switch (elf_header
.e_machine
)
8764 return process_arm_specific (file
);
8766 case EM_MIPS_RS3_LE
:
8767 return process_mips_specific (file
);
8776 get_file_header (FILE *file
)
8778 /* Read in the identity array. */
8779 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
8782 /* Determine how to read the rest of the header. */
8783 switch (elf_header
.e_ident
[EI_DATA
])
8785 default: /* fall through */
8786 case ELFDATANONE
: /* fall through */
8788 byte_get
= byte_get_little_endian
;
8789 byte_put
= byte_put_little_endian
;
8792 byte_get
= byte_get_big_endian
;
8793 byte_put
= byte_put_big_endian
;
8797 /* For now we only support 32 bit and 64 bit ELF files. */
8798 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
8800 /* Read in the rest of the header. */
8803 Elf32_External_Ehdr ehdr32
;
8805 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
8808 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
8809 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
8810 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
8811 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
8812 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
8813 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
8814 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
8815 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
8816 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
8817 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
8818 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
8819 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
8820 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
8824 Elf64_External_Ehdr ehdr64
;
8826 /* If we have been compiled with sizeof (bfd_vma) == 4, then
8827 we will not be able to cope with the 64bit data found in
8828 64 ELF files. Detect this now and abort before we start
8829 overwriting things. */
8830 if (sizeof (bfd_vma
) < 8)
8832 error (_("This instance of readelf has been built without support for a\n\
8833 64 bit data type and so it cannot read 64 bit ELF files.\n"));
8837 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
8840 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
8841 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
8842 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
8843 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
8844 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
8845 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
8846 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
8847 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
8848 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
8849 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
8850 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
8851 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
8852 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
8855 if (elf_header
.e_shoff
)
8857 /* There may be some extensions in the first section header. Don't
8858 bomb if we can't read it. */
8860 get_32bit_section_headers (file
, 1);
8862 get_64bit_section_headers (file
, 1);
8865 is_relocatable
= elf_header
.e_type
== ET_REL
;
8870 /* Process one ELF object file according to the command line options.
8871 This file may actually be stored in an archive. The file is
8872 positioned at the start of the ELF object. */
8875 process_object (char *file_name
, FILE *file
)
8879 if (! get_file_header (file
))
8881 error (_("%s: Failed to read file header\n"), file_name
);
8885 /* Initialise per file variables. */
8886 for (i
= NUM_ELEM (version_info
); i
--;)
8887 version_info
[i
] = 0;
8889 for (i
= NUM_ELEM (dynamic_info
); i
--;)
8890 dynamic_info
[i
] = 0;
8892 /* Process the file. */
8894 printf (_("\nFile: %s\n"), file_name
);
8896 /* Initialise the dump_sects array from the cmdline_dump_sects array.
8897 Note we do this even if cmdline_dump_sects is empty because we
8898 must make sure that the dump_sets array is zeroed out before each
8899 object file is processed. */
8900 if (num_dump_sects
> num_cmdline_dump_sects
)
8901 memset (dump_sects
, 0, num_dump_sects
);
8903 if (num_cmdline_dump_sects
> 0)
8905 if (num_dump_sects
== 0)
8906 /* A sneaky way of allocating the dump_sects array. */
8907 request_dump (num_cmdline_dump_sects
, 0);
8909 assert (num_dump_sects
>= num_cmdline_dump_sects
);
8910 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
8913 if (! process_file_header ())
8916 if (! process_section_headers (file
))
8918 /* Without loaded section headers we cannot process lots of
8920 do_unwind
= do_version
= do_dump
= do_arch
= 0;
8922 if (! do_using_dynamic
)
8923 do_syms
= do_reloc
= 0;
8926 if (! process_section_groups (file
))
8928 /* Without loaded section groups we cannot process unwind. */
8932 if (process_program_headers (file
))
8933 process_dynamic_section (file
);
8935 process_relocs (file
);
8937 process_unwind (file
);
8939 process_symbol_table (file
);
8941 process_syminfo (file
);
8943 process_version_sections (file
);
8945 process_section_contents (file
);
8947 process_notes (file
);
8949 process_gnu_liblist (file
);
8951 process_arch_specific (file
);
8953 if (program_headers
)
8955 free (program_headers
);
8956 program_headers
= NULL
;
8959 if (section_headers
)
8961 free (section_headers
);
8962 section_headers
= NULL
;
8967 free (string_table
);
8968 string_table
= NULL
;
8969 string_table_length
= 0;
8972 if (dynamic_strings
)
8974 free (dynamic_strings
);
8975 dynamic_strings
= NULL
;
8976 dynamic_strings_length
= 0;
8979 if (dynamic_symbols
)
8981 free (dynamic_symbols
);
8982 dynamic_symbols
= NULL
;
8983 num_dynamic_syms
= 0;
8986 if (dynamic_syminfo
)
8988 free (dynamic_syminfo
);
8989 dynamic_syminfo
= NULL
;
8992 if (section_headers_groups
)
8994 free (section_headers_groups
);
8995 section_headers_groups
= NULL
;
9000 struct group_list
*g
, *next
;
9002 for (i
= 0; i
< group_count
; i
++)
9004 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
9011 free (section_groups
);
9012 section_groups
= NULL
;
9015 free_debug_memory ();
9020 /* Process an ELF archive. The file is positioned just after the
9024 process_archive (char *file_name
, FILE *file
)
9026 struct ar_hdr arhdr
;
9029 char *longnames
= NULL
;
9030 unsigned long longnames_size
= 0;
9031 size_t file_name_size
;
9036 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9037 if (got
!= sizeof arhdr
)
9042 error (_("%s: failed to read archive header\n"), file_name
);
9046 if (memcmp (arhdr
.ar_name
, "/ ", 16) == 0)
9048 /* This is the archive symbol table. Skip it.
9049 FIXME: We should have an option to dump it. */
9050 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9051 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
9053 error (_("%s: failed to skip archive symbol table\n"), file_name
);
9057 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9058 if (got
!= sizeof arhdr
)
9063 error (_("%s: failed to read archive header\n"), file_name
);
9068 if (memcmp (arhdr
.ar_name
, "// ", 16) == 0)
9070 /* This is the archive string table holding long member
9073 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9075 longnames
= malloc (longnames_size
);
9076 if (longnames
== NULL
)
9078 error (_("Out of memory\n"));
9082 if (fread (longnames
, longnames_size
, 1, file
) != 1)
9085 error (_("%s: failed to read string table\n"), file_name
);
9089 if ((longnames_size
& 1) != 0)
9092 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9093 if (got
!= sizeof arhdr
)
9100 error (_("%s: failed to read archive header\n"), file_name
);
9105 file_name_size
= strlen (file_name
);
9114 if (arhdr
.ar_name
[0] == '/')
9118 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
9119 if (off
>= longnames_size
)
9121 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
9126 name
= longnames
+ off
;
9127 nameend
= memchr (name
, '/', longnames_size
- off
);
9131 name
= arhdr
.ar_name
;
9132 nameend
= memchr (name
, '/', 16);
9135 if (nameend
== NULL
)
9137 error (_("%s: bad archive file name\n"), file_name
);
9142 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
9143 if (namealc
== NULL
)
9145 error (_("Out of memory\n"));
9150 memcpy (namealc
, file_name
, file_name_size
);
9151 namealc
[file_name_size
] = '(';
9152 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
9153 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
9154 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
9156 archive_file_offset
= ftell (file
);
9157 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9159 ret
|= process_object (namealc
, file
);
9164 (archive_file_offset
9166 + (archive_file_size
& 1)),
9169 error (_("%s: failed to seek to next archive header\n"), file_name
);
9174 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9175 if (got
!= sizeof arhdr
)
9180 error (_("%s: failed to read archive header\n"), file_name
);
9193 process_file (char *file_name
)
9196 struct stat statbuf
;
9200 if (stat (file_name
, &statbuf
) < 0)
9202 if (errno
== ENOENT
)
9203 error (_("'%s': No such file\n"), file_name
);
9205 error (_("Could not locate '%s'. System error message: %s\n"),
9206 file_name
, strerror (errno
));
9210 if (! S_ISREG (statbuf
.st_mode
))
9212 error (_("'%s' is not an ordinary file\n"), file_name
);
9216 file
= fopen (file_name
, "rb");
9219 error (_("Input file '%s' is not readable.\n"), file_name
);
9223 if (fread (armag
, SARMAG
, 1, file
) != 1)
9225 error (_("%s: Failed to read file header\n"), file_name
);
9230 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
9231 ret
= process_archive (file_name
, file
);
9235 archive_file_size
= archive_file_offset
= 0;
9236 ret
= process_object (file_name
, file
);
9244 #ifdef SUPPORT_DISASSEMBLY
9245 /* Needed by the i386 disassembler. For extra credit, someone could
9246 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9250 print_address (unsigned int addr
, FILE *outfile
)
9252 fprintf (outfile
,"0x%8.8x", addr
);
9255 /* Needed by the i386 disassembler. */
9257 db_task_printsym (unsigned int addr
)
9259 print_address (addr
, stderr
);
9264 main (int argc
, char **argv
)
9268 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9269 setlocale (LC_MESSAGES
, "");
9271 #if defined (HAVE_SETLOCALE)
9272 setlocale (LC_CTYPE
, "");
9274 bindtextdomain (PACKAGE
, LOCALEDIR
);
9275 textdomain (PACKAGE
);
9277 expandargv (&argc
, &argv
);
9279 parse_args (argc
, argv
);
9281 if (num_dump_sects
> 0)
9283 /* Make a copy of the dump_sects array. */
9284 cmdline_dump_sects
= malloc (num_dump_sects
);
9285 if (cmdline_dump_sects
== NULL
)
9286 error (_("Out of memory allocating dump request table."));
9289 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
9290 num_cmdline_dump_sects
= num_dump_sects
;
9294 if (optind
< (argc
- 1))
9298 while (optind
< argc
)
9299 err
|= process_file (argv
[optind
++]);
9301 if (dump_sects
!= NULL
)
9303 if (cmdline_dump_sects
!= NULL
)
9304 free (cmdline_dump_sects
);