1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 /* The difference between readelf and objdump:
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
56 # ifdef HAVE_SYS_PARAM_H
57 # include <sys/param.h>
61 # define PATH_MAX MAXPATHLEN
63 # define PATH_MAX 1024
69 /* Define BFD64 here, even if our default architecture is 32 bit ELF
70 as this will allow us to read in and parse 64bit and 32bit ELF files.
71 Only do this if we believe that the compiler can support a 64 bit
72 data type. For now we only rely on GCC being able to do this. */
80 #include "elf/common.h"
81 #include "elf/external.h"
82 #include "elf/internal.h"
85 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
86 we can obtain the H8 reloc numbers. We need these for the
87 get_reloc_size() function. We include h8.h again after defining
88 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
93 /* Undo the effects of #including reloc-macros.h. */
95 #undef START_RELOC_NUMBERS
99 #undef END_RELOC_NUMBERS
100 #undef _RELOC_MACROS_H
102 /* The following headers use the elf/reloc-macros.h file to
103 automatically generate relocation recognition functions
104 such as elf_mips_reloc_type() */
106 #define RELOC_MACROS_GEN_FUNC
108 #include "elf/alpha.h"
112 #include "elf/bfin.h"
113 #include "elf/cr16.h"
114 #include "elf/cris.h"
116 #include "elf/d10v.h"
117 #include "elf/d30v.h"
119 #include "elf/fr30.h"
122 #include "elf/hppa.h"
123 #include "elf/i386.h"
124 #include "elf/i370.h"
125 #include "elf/i860.h"
126 #include "elf/i960.h"
127 #include "elf/ia64.h"
128 #include "elf/ip2k.h"
129 #include "elf/iq2000.h"
130 #include "elf/m32c.h"
131 #include "elf/m32r.h"
132 #include "elf/m68k.h"
133 #include "elf/m68hc11.h"
134 #include "elf/mcore.h"
136 #include "elf/mips.h"
137 #include "elf/mmix.h"
138 #include "elf/mn10200.h"
139 #include "elf/mn10300.h"
141 #include "elf/msp430.h"
142 #include "elf/or32.h"
145 #include "elf/ppc64.h"
146 #include "elf/s390.h"
147 #include "elf/score.h"
149 #include "elf/sparc.h"
151 #include "elf/v850.h"
153 #include "elf/x86-64.h"
154 #include "elf/xstormy16.h"
155 #include "elf/xtensa.h"
160 #include "libiberty.h"
161 #include "safe-ctype.h"
163 char *program_name
= "readelf";
164 static long archive_file_offset
;
165 static unsigned long archive_file_size
;
166 static unsigned long dynamic_addr
;
167 static bfd_size_type dynamic_size
;
168 static unsigned int dynamic_nent
;
169 static char *dynamic_strings
;
170 static unsigned long dynamic_strings_length
;
171 static char *string_table
;
172 static unsigned long string_table_length
;
173 static unsigned long num_dynamic_syms
;
174 static Elf_Internal_Sym
*dynamic_symbols
;
175 static Elf_Internal_Syminfo
*dynamic_syminfo
;
176 static unsigned long dynamic_syminfo_offset
;
177 static unsigned int dynamic_syminfo_nent
;
178 static char program_interpreter
[PATH_MAX
];
179 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
180 static bfd_vma dynamic_info_DT_GNU_HASH
;
181 static bfd_vma version_info
[16];
182 static Elf_Internal_Ehdr elf_header
;
183 static Elf_Internal_Shdr
*section_headers
;
184 static Elf_Internal_Phdr
*program_headers
;
185 static Elf_Internal_Dyn
*dynamic_section
;
186 static Elf_Internal_Shdr
*symtab_shndx_hdr
;
187 static int show_name
;
188 static int do_dynamic
;
191 static int do_sections
;
192 static int do_section_groups
;
193 static int do_section_details
;
194 static int do_segments
;
195 static int do_unwind
;
196 static int do_using_dynamic
;
197 static int do_header
;
199 static int do_version
;
201 static int do_histogram
;
202 static int do_debugging
;
205 static int do_archive_index
;
206 static int is_32bit_elf
;
210 struct group_list
*next
;
211 unsigned int section_index
;
216 struct group_list
*root
;
217 unsigned int group_index
;
220 static size_t group_count
;
221 static struct group
*section_groups
;
222 static struct group
**section_headers_groups
;
225 /* Flag bits indicating particular types of dump. */
226 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
227 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
228 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
229 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
231 typedef unsigned char dump_type
;
233 /* A linked list of the section names for which dumps were requested. */
234 struct dump_list_entry
238 struct dump_list_entry
*next
;
240 static struct dump_list_entry
*dump_sects_byname
;
242 /* A dynamic array of flags indicating for which sections a dump
243 has been requested via command line switches. */
244 static dump_type
* cmdline_dump_sects
= NULL
;
245 static unsigned int num_cmdline_dump_sects
= 0;
247 /* A dynamic array of flags indicating for which sections a dump of
248 some kind has been requested. It is reset on a per-object file
249 basis and then initialised from the cmdline_dump_sects array,
250 the results of interpreting the -w switch, and the
251 dump_sects_byname list. */
252 static dump_type
* dump_sects
= NULL
;
253 static unsigned int num_dump_sects
= 0;
256 /* How to print a vma value. */
257 typedef enum print_mode
269 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
273 #define SECTION_NAME(X) \
274 ((X) == NULL ? "<none>" \
275 : string_table == NULL ? "<no-name>" \
276 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
277 : string_table + (X)->sh_name))
279 /* Given st_shndx I, map to section_headers index. */
280 #define SECTION_HEADER_INDEX(I) \
281 ((I) < SHN_LORESERVE \
283 : ((I) <= SHN_HIRESERVE \
285 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
287 /* Reverse of the above. */
288 #define SECTION_HEADER_NUM(N) \
289 ((N) < SHN_LORESERVE \
291 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
293 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
295 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
297 #define BYTE_GET(field) byte_get (field, sizeof (field))
299 #define GET_ELF_SYMBOLS(file, section) \
300 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
301 : get_64bit_elf_symbols (file, section))
303 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
304 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
305 already been called and verified that the string exists. */
306 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
308 /* This is just a bit of syntatic sugar. */
309 #define streq(a,b) (strcmp ((a), (b)) == 0)
310 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
311 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
314 get_data (void *var
, FILE *file
, long offset
, size_t size
, size_t nmemb
,
319 if (size
== 0 || nmemb
== 0)
322 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
324 error (_("Unable to seek to 0x%lx for %s\n"),
325 archive_file_offset
+ offset
, reason
);
332 /* Check for overflow. */
333 if (nmemb
< (~(size_t) 0 - 1) / size
)
334 /* + 1 so that we can '\0' terminate invalid string table sections. */
335 mvar
= malloc (size
* nmemb
+ 1);
339 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
340 (unsigned long)(size
* nmemb
), reason
);
344 ((char *) mvar
)[size
* nmemb
] = '\0';
347 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
349 error (_("Unable to read in 0x%lx bytes of %s\n"),
350 (unsigned long)(size
* nmemb
), reason
);
360 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
365 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
366 field
[6] = ((value
>> 24) >> 24) & 0xff;
367 field
[5] = ((value
>> 24) >> 16) & 0xff;
368 field
[4] = ((value
>> 24) >> 8) & 0xff;
371 field
[3] = (value
>> 24) & 0xff;
372 field
[2] = (value
>> 16) & 0xff;
375 field
[1] = (value
>> 8) & 0xff;
378 field
[0] = value
& 0xff;
382 error (_("Unhandled data length: %d\n"), size
);
387 #if defined BFD64 && !BFD_HOST_64BIT_LONG && !BFD_HOST_64BIT_LONG_LONG
389 print_dec_vma (bfd_vma vma
, int is_signed
)
395 if (is_signed
&& (bfd_signed_vma
) vma
< 0)
404 *bufp
++ = '0' + vma
% 10;
416 print_hex_vma (bfd_vma vma
)
424 char digit
= '0' + (vma
& 0x0f);
426 digit
+= 'a' - '0' - 10;
439 /* Print a VMA value. */
441 print_vma (bfd_vma vma
, print_mode mode
)
450 return printf ("0x%8.8lx", (unsigned long) vma
);
453 return printf ("%8.8lx", (unsigned long) vma
);
457 return printf ("%5ld", (long) vma
);
461 return printf ("0x%lx", (unsigned long) vma
);
464 return printf ("%lx", (unsigned long) vma
);
467 return printf ("%ld", (unsigned long) vma
);
470 return printf ("%lu", (unsigned long) vma
);
493 #if BFD_HOST_64BIT_LONG
494 return nc
+ printf ("%lx", vma
);
495 #elif BFD_HOST_64BIT_LONG_LONG
497 return nc
+ printf ("%llx", vma
);
499 return nc
+ printf ("%I64x", vma
);
502 return nc
+ print_hex_vma (vma
);
506 #if BFD_HOST_64BIT_LONG
507 return printf ("%ld", vma
);
508 #elif BFD_HOST_64BIT_LONG_LONG
510 return printf ("%lld", vma
);
512 return printf ("%I64d", vma
);
515 return print_dec_vma (vma
, 1);
519 #if BFD_HOST_64BIT_LONG
521 return printf ("%5ld", vma
);
523 return printf ("%#lx", vma
);
524 #elif BFD_HOST_64BIT_LONG_LONG
527 return printf ("%5lld", vma
);
529 return printf ("%#llx", vma
);
532 return printf ("%5I64d", vma
);
534 return printf ("%#I64x", vma
);
538 return printf ("%5ld", _bfd_int64_low (vma
));
540 return print_hex_vma (vma
);
544 #if BFD_HOST_64BIT_LONG
545 return printf ("%lu", vma
);
546 #elif BFD_HOST_64BIT_LONG_LONG
548 return printf ("%llu", vma
);
550 return printf ("%I64u", vma
);
553 return print_dec_vma (vma
, 0);
561 /* Display a symbol on stdout. If do_wide is not true then
562 format the symbol to be at most WIDTH characters,
563 truncating as necessary. If WIDTH is negative then
564 format the string to be exactly - WIDTH characters,
565 truncating or padding as necessary. */
568 print_symbol (int width
, const char *symbol
)
571 printf ("%s", symbol
);
573 printf ("%-*.*s", width
, width
, symbol
);
575 printf ("%-.*s", width
, symbol
);
579 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
584 field
[7] = value
& 0xff;
585 field
[6] = (value
>> 8) & 0xff;
586 field
[5] = (value
>> 16) & 0xff;
587 field
[4] = (value
>> 24) & 0xff;
592 field
[3] = value
& 0xff;
593 field
[2] = (value
>> 8) & 0xff;
597 field
[1] = value
& 0xff;
601 field
[0] = value
& 0xff;
605 error (_("Unhandled data length: %d\n"), size
);
610 /* Return a pointer to section NAME, or NULL if no such section exists. */
612 static Elf_Internal_Shdr
*
613 find_section (const char *name
)
617 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
618 if (streq (SECTION_NAME (section_headers
+ i
), name
))
619 return section_headers
+ i
;
624 /* Guess the relocation size commonly used by the specific machines. */
627 guess_is_rela (unsigned int e_machine
)
631 /* Targets that use REL relocations. */
647 /* Targets that use RELA relocations. */
651 case EM_ALTERA_NIOS2
:
676 case EM_CYGNUS_MN10200
:
678 case EM_CYGNUS_MN10300
:
719 warn (_("Don't know about relocations on this machine architecture\n"));
725 slurp_rela_relocs (FILE *file
,
726 unsigned long rel_offset
,
727 unsigned long rel_size
,
728 Elf_Internal_Rela
**relasp
,
729 unsigned long *nrelasp
)
731 Elf_Internal_Rela
*relas
;
732 unsigned long nrelas
;
737 Elf32_External_Rela
*erelas
;
739 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
743 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
745 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
750 error (_("out of memory parsing relocs\n"));
754 for (i
= 0; i
< nrelas
; i
++)
756 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
757 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
758 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
765 Elf64_External_Rela
*erelas
;
767 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
771 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
773 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
778 error (_("out of memory parsing relocs\n"));
782 for (i
= 0; i
< nrelas
; i
++)
784 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
785 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
786 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
797 slurp_rel_relocs (FILE *file
,
798 unsigned long rel_offset
,
799 unsigned long rel_size
,
800 Elf_Internal_Rela
**relsp
,
801 unsigned long *nrelsp
)
803 Elf_Internal_Rela
*rels
;
809 Elf32_External_Rel
*erels
;
811 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
815 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
817 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
822 error (_("out of memory parsing relocs\n"));
826 for (i
= 0; i
< nrels
; i
++)
828 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
829 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
830 rels
[i
].r_addend
= 0;
837 Elf64_External_Rel
*erels
;
839 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
843 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
845 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
850 error (_("out of memory parsing relocs\n"));
854 for (i
= 0; i
< nrels
; i
++)
856 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
857 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
858 rels
[i
].r_addend
= 0;
868 /* Returns the reloc type extracted from the reloc info field. */
871 get_reloc_type (bfd_vma reloc_info
)
874 return ELF32_R_TYPE (reloc_info
);
876 switch (elf_header
.e_machine
)
879 /* Note: We assume that reloc_info has already been adjusted for us. */
880 return ELF64_MIPS_R_TYPE (reloc_info
);
883 return ELF64_R_TYPE_ID (reloc_info
);
886 return ELF64_R_TYPE (reloc_info
);
890 /* Return the symbol index extracted from the reloc info field. */
893 get_reloc_symindex (bfd_vma reloc_info
)
895 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
898 /* Display the contents of the relocation data found at the specified
902 dump_relocations (FILE *file
,
903 unsigned long rel_offset
,
904 unsigned long rel_size
,
905 Elf_Internal_Sym
*symtab
,
908 unsigned long strtablen
,
912 Elf_Internal_Rela
*rels
;
915 if (is_rela
== UNKNOWN
)
916 is_rela
= guess_is_rela (elf_header
.e_machine
);
920 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
925 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
934 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
936 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
941 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
943 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
951 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
953 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
958 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
960 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
964 for (i
= 0; i
< rel_size
; i
++)
969 bfd_vma symtab_index
;
972 offset
= rels
[i
].r_offset
;
973 info
= rels
[i
].r_info
;
975 /* The #ifdef BFD64 below is to prevent a compile time warning.
976 We know that if we do not have a 64 bit data type that we
977 will never execute this code anyway. */
980 && elf_header
.e_machine
== EM_MIPS
981 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
983 /* In little-endian objects, r_info isn't really a 64-bit
984 little-endian value: it has a 32-bit little-endian
985 symbol index followed by four individual byte fields.
986 Reorder INFO accordingly. */
987 info
= (((info
& 0xffffffff) << 32)
988 | ((info
>> 56) & 0xff)
989 | ((info
>> 40) & 0xff00)
990 | ((info
>> 24) & 0xff0000)
991 | ((info
>> 8) & 0xff000000));
995 type
= get_reloc_type (info
);
996 symtab_index
= get_reloc_symindex (info
);
1000 printf ("%8.8lx %8.8lx ",
1001 (unsigned long) offset
& 0xffffffff,
1002 (unsigned long) info
& 0xffffffff);
1006 #if BFD_HOST_64BIT_LONG
1008 ? "%16.16lx %16.16lx "
1009 : "%12.12lx %12.12lx ",
1011 #elif BFD_HOST_64BIT_LONG_LONG
1014 ? "%16.16llx %16.16llx "
1015 : "%12.12llx %12.12llx ",
1019 ? "%16.16I64x %16.16I64x "
1020 : "%12.12I64x %12.12I64x ",
1025 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1026 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1027 _bfd_int64_high (offset
),
1028 _bfd_int64_low (offset
),
1029 _bfd_int64_high (info
),
1030 _bfd_int64_low (info
));
1034 switch (elf_header
.e_machine
)
1041 case EM_CYGNUS_M32R
:
1042 rtype
= elf_m32r_reloc_type (type
);
1047 rtype
= elf_i386_reloc_type (type
);
1052 rtype
= elf_m68hc11_reloc_type (type
);
1056 rtype
= elf_m68k_reloc_type (type
);
1060 rtype
= elf_i960_reloc_type (type
);
1065 rtype
= elf_avr_reloc_type (type
);
1068 case EM_OLD_SPARCV9
:
1069 case EM_SPARC32PLUS
:
1072 rtype
= elf_sparc_reloc_type (type
);
1076 rtype
= elf_spu_reloc_type (type
);
1080 case EM_CYGNUS_V850
:
1081 rtype
= v850_reloc_type (type
);
1085 case EM_CYGNUS_D10V
:
1086 rtype
= elf_d10v_reloc_type (type
);
1090 case EM_CYGNUS_D30V
:
1091 rtype
= elf_d30v_reloc_type (type
);
1095 rtype
= elf_dlx_reloc_type (type
);
1099 rtype
= elf_sh_reloc_type (type
);
1103 case EM_CYGNUS_MN10300
:
1104 rtype
= elf_mn10300_reloc_type (type
);
1108 case EM_CYGNUS_MN10200
:
1109 rtype
= elf_mn10200_reloc_type (type
);
1113 case EM_CYGNUS_FR30
:
1114 rtype
= elf_fr30_reloc_type (type
);
1118 rtype
= elf_frv_reloc_type (type
);
1122 rtype
= elf_mcore_reloc_type (type
);
1126 rtype
= elf_mmix_reloc_type (type
);
1131 rtype
= elf_msp430_reloc_type (type
);
1135 rtype
= elf_ppc_reloc_type (type
);
1139 rtype
= elf_ppc64_reloc_type (type
);
1143 case EM_MIPS_RS3_LE
:
1144 rtype
= elf_mips_reloc_type (type
);
1148 rtype
= elf_alpha_reloc_type (type
);
1152 rtype
= elf_arm_reloc_type (type
);
1156 rtype
= elf_arc_reloc_type (type
);
1160 rtype
= elf_hppa_reloc_type (type
);
1166 rtype
= elf_h8_reloc_type (type
);
1171 rtype
= elf_or32_reloc_type (type
);
1176 rtype
= elf_pj_reloc_type (type
);
1179 rtype
= elf_ia64_reloc_type (type
);
1183 rtype
= elf_cris_reloc_type (type
);
1187 rtype
= elf_i860_reloc_type (type
);
1191 rtype
= elf_x86_64_reloc_type (type
);
1195 rtype
= i370_reloc_type (type
);
1200 rtype
= elf_s390_reloc_type (type
);
1204 rtype
= elf_score_reloc_type (type
);
1208 rtype
= elf_xstormy16_reloc_type (type
);
1212 rtype
= elf_crx_reloc_type (type
);
1216 rtype
= elf_vax_reloc_type (type
);
1221 rtype
= elf_ip2k_reloc_type (type
);
1225 rtype
= elf_iq2000_reloc_type (type
);
1230 rtype
= elf_xtensa_reloc_type (type
);
1234 rtype
= elf_m32c_reloc_type (type
);
1238 rtype
= elf_mt_reloc_type (type
);
1242 rtype
= elf_bfin_reloc_type (type
);
1246 rtype
= elf_mep_reloc_type (type
);
1250 rtype
= elf_cr16_reloc_type (type
);
1255 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1257 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1259 if (elf_header
.e_machine
== EM_ALPHA
1261 && streq (rtype
, "R_ALPHA_LITUSE")
1264 switch (rels
[i
].r_addend
)
1266 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1267 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1268 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1269 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1270 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1271 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1272 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1273 default: rtype
= NULL
;
1276 printf (" (%s)", rtype
);
1280 printf (_("<unknown addend: %lx>"),
1281 (unsigned long) rels
[i
].r_addend
);
1284 else if (symtab_index
)
1286 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1287 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1290 Elf_Internal_Sym
*psym
;
1292 psym
= symtab
+ symtab_index
;
1295 print_vma (psym
->st_value
, LONG_HEX
);
1296 printf (is_32bit_elf
? " " : " ");
1298 if (psym
->st_name
== 0)
1300 const char *sec_name
= "<null>";
1303 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1305 bfd_vma sec_index
= (bfd_vma
) -1;
1307 if (psym
->st_shndx
< SHN_LORESERVE
)
1308 sec_index
= psym
->st_shndx
;
1309 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1310 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1313 if (sec_index
!= (bfd_vma
) -1)
1314 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1315 else if (psym
->st_shndx
== SHN_ABS
)
1317 else if (psym
->st_shndx
== SHN_COMMON
)
1318 sec_name
= "COMMON";
1319 else if (elf_header
.e_machine
== EM_MIPS
1320 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1321 sec_name
= "SCOMMON";
1322 else if (elf_header
.e_machine
== EM_MIPS
1323 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1324 sec_name
= "SUNDEF";
1325 else if (elf_header
.e_machine
== EM_X86_64
1326 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1327 sec_name
= "LARGE_COMMON";
1328 else if (elf_header
.e_machine
== EM_IA_64
1329 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1330 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1331 sec_name
= "ANSI_COM";
1334 sprintf (name_buf
, "<section 0x%x>",
1335 (unsigned int) psym
->st_shndx
);
1336 sec_name
= name_buf
;
1339 print_symbol (22, sec_name
);
1341 else if (strtab
== NULL
)
1342 printf (_("<string table index: %3ld>"), psym
->st_name
);
1343 else if (psym
->st_name
>= strtablen
)
1344 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1346 print_symbol (22, strtab
+ psym
->st_name
);
1349 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1354 printf ("%*c", is_32bit_elf
?
1355 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1356 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1359 if (elf_header
.e_machine
== EM_SPARCV9
1361 && streq (rtype
, "R_SPARC_OLO10"))
1362 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1367 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1369 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (info
);
1370 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (info
);
1371 const char *rtype2
= elf_mips_reloc_type (type2
);
1372 const char *rtype3
= elf_mips_reloc_type (type3
);
1374 printf (" Type2: ");
1377 printf (_("unrecognized: %-7lx"),
1378 (unsigned long) type2
& 0xffffffff);
1380 printf ("%-17.17s", rtype2
);
1382 printf ("\n Type3: ");
1385 printf (_("unrecognized: %-7lx"),
1386 (unsigned long) type3
& 0xffffffff);
1388 printf ("%-17.17s", rtype3
);
1399 get_mips_dynamic_type (unsigned long type
)
1403 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1404 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1405 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1406 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1407 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1408 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1409 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1410 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1411 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1412 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1413 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1414 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1415 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1416 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1417 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1418 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1419 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1420 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1421 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1422 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1423 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1424 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1425 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1426 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1427 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1428 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1429 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1430 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1431 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1432 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1433 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1434 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1435 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1436 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1437 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1438 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1439 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1440 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1441 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1442 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1443 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1444 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1445 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1452 get_sparc64_dynamic_type (unsigned long type
)
1456 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1463 get_ppc_dynamic_type (unsigned long type
)
1467 case DT_PPC_GOT
: return "PPC_GOT";
1474 get_ppc64_dynamic_type (unsigned long type
)
1478 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1479 case DT_PPC64_OPD
: return "PPC64_OPD";
1480 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1487 get_parisc_dynamic_type (unsigned long type
)
1491 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1492 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1493 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1494 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1495 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1496 case DT_HP_PREINIT
: return "HP_PREINIT";
1497 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1498 case DT_HP_NEEDED
: return "HP_NEEDED";
1499 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1500 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1501 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1502 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1503 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1504 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1505 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1506 case DT_HP_FILTERED
: return "HP_FILTERED";
1507 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1508 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1509 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1510 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1511 case DT_PLT
: return "PLT";
1512 case DT_PLT_SIZE
: return "PLT_SIZE";
1513 case DT_DLT
: return "DLT";
1514 case DT_DLT_SIZE
: return "DLT_SIZE";
1521 get_ia64_dynamic_type (unsigned long type
)
1525 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1532 get_alpha_dynamic_type (unsigned long type
)
1536 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1543 get_score_dynamic_type (unsigned long type
)
1547 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1548 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1549 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1550 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1551 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1552 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1560 get_dynamic_type (unsigned long type
)
1562 static char buff
[64];
1566 case DT_NULL
: return "NULL";
1567 case DT_NEEDED
: return "NEEDED";
1568 case DT_PLTRELSZ
: return "PLTRELSZ";
1569 case DT_PLTGOT
: return "PLTGOT";
1570 case DT_HASH
: return "HASH";
1571 case DT_STRTAB
: return "STRTAB";
1572 case DT_SYMTAB
: return "SYMTAB";
1573 case DT_RELA
: return "RELA";
1574 case DT_RELASZ
: return "RELASZ";
1575 case DT_RELAENT
: return "RELAENT";
1576 case DT_STRSZ
: return "STRSZ";
1577 case DT_SYMENT
: return "SYMENT";
1578 case DT_INIT
: return "INIT";
1579 case DT_FINI
: return "FINI";
1580 case DT_SONAME
: return "SONAME";
1581 case DT_RPATH
: return "RPATH";
1582 case DT_SYMBOLIC
: return "SYMBOLIC";
1583 case DT_REL
: return "REL";
1584 case DT_RELSZ
: return "RELSZ";
1585 case DT_RELENT
: return "RELENT";
1586 case DT_PLTREL
: return "PLTREL";
1587 case DT_DEBUG
: return "DEBUG";
1588 case DT_TEXTREL
: return "TEXTREL";
1589 case DT_JMPREL
: return "JMPREL";
1590 case DT_BIND_NOW
: return "BIND_NOW";
1591 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1592 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1593 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1594 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1595 case DT_RUNPATH
: return "RUNPATH";
1596 case DT_FLAGS
: return "FLAGS";
1598 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1599 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1601 case DT_CHECKSUM
: return "CHECKSUM";
1602 case DT_PLTPADSZ
: return "PLTPADSZ";
1603 case DT_MOVEENT
: return "MOVEENT";
1604 case DT_MOVESZ
: return "MOVESZ";
1605 case DT_FEATURE
: return "FEATURE";
1606 case DT_POSFLAG_1
: return "POSFLAG_1";
1607 case DT_SYMINSZ
: return "SYMINSZ";
1608 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1610 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1611 case DT_CONFIG
: return "CONFIG";
1612 case DT_DEPAUDIT
: return "DEPAUDIT";
1613 case DT_AUDIT
: return "AUDIT";
1614 case DT_PLTPAD
: return "PLTPAD";
1615 case DT_MOVETAB
: return "MOVETAB";
1616 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1618 case DT_VERSYM
: return "VERSYM";
1620 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1621 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1622 case DT_RELACOUNT
: return "RELACOUNT";
1623 case DT_RELCOUNT
: return "RELCOUNT";
1624 case DT_FLAGS_1
: return "FLAGS_1";
1625 case DT_VERDEF
: return "VERDEF";
1626 case DT_VERDEFNUM
: return "VERDEFNUM";
1627 case DT_VERNEED
: return "VERNEED";
1628 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1630 case DT_AUXILIARY
: return "AUXILIARY";
1631 case DT_USED
: return "USED";
1632 case DT_FILTER
: return "FILTER";
1634 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1635 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1636 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1637 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1638 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1639 case DT_GNU_HASH
: return "GNU_HASH";
1642 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1646 switch (elf_header
.e_machine
)
1649 case EM_MIPS_RS3_LE
:
1650 result
= get_mips_dynamic_type (type
);
1653 result
= get_sparc64_dynamic_type (type
);
1656 result
= get_ppc_dynamic_type (type
);
1659 result
= get_ppc64_dynamic_type (type
);
1662 result
= get_ia64_dynamic_type (type
);
1665 result
= get_alpha_dynamic_type (type
);
1668 result
= get_score_dynamic_type (type
);
1678 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1680 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1681 || (elf_header
.e_machine
== EM_PARISC
1682 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1686 switch (elf_header
.e_machine
)
1689 result
= get_parisc_dynamic_type (type
);
1699 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1703 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1710 get_file_type (unsigned e_type
)
1712 static char buff
[32];
1716 case ET_NONE
: return _("NONE (None)");
1717 case ET_REL
: return _("REL (Relocatable file)");
1718 case ET_EXEC
: return _("EXEC (Executable file)");
1719 case ET_DYN
: return _("DYN (Shared object file)");
1720 case ET_CORE
: return _("CORE (Core file)");
1723 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1724 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1725 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1726 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1728 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1734 get_machine_name (unsigned e_machine
)
1736 static char buff
[64]; /* XXX */
1740 case EM_NONE
: return _("None");
1741 case EM_M32
: return "WE32100";
1742 case EM_SPARC
: return "Sparc";
1743 case EM_SPU
: return "SPU";
1744 case EM_386
: return "Intel 80386";
1745 case EM_68K
: return "MC68000";
1746 case EM_88K
: return "MC88000";
1747 case EM_486
: return "Intel 80486";
1748 case EM_860
: return "Intel 80860";
1749 case EM_MIPS
: return "MIPS R3000";
1750 case EM_S370
: return "IBM System/370";
1751 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1752 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1753 case EM_PARISC
: return "HPPA";
1754 case EM_PPC_OLD
: return "Power PC (old)";
1755 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1756 case EM_960
: return "Intel 90860";
1757 case EM_PPC
: return "PowerPC";
1758 case EM_PPC64
: return "PowerPC64";
1759 case EM_V800
: return "NEC V800";
1760 case EM_FR20
: return "Fujitsu FR20";
1761 case EM_RH32
: return "TRW RH32";
1762 case EM_MCORE
: return "MCORE";
1763 case EM_ARM
: return "ARM";
1764 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1765 case EM_SH
: return "Renesas / SuperH SH";
1766 case EM_SPARCV9
: return "Sparc v9";
1767 case EM_TRICORE
: return "Siemens Tricore";
1768 case EM_ARC
: return "ARC";
1769 case EM_H8_300
: return "Renesas H8/300";
1770 case EM_H8_300H
: return "Renesas H8/300H";
1771 case EM_H8S
: return "Renesas H8S";
1772 case EM_H8_500
: return "Renesas H8/500";
1773 case EM_IA_64
: return "Intel IA-64";
1774 case EM_MIPS_X
: return "Stanford MIPS-X";
1775 case EM_COLDFIRE
: return "Motorola Coldfire";
1776 case EM_68HC12
: return "Motorola M68HC12";
1777 case EM_ALPHA
: return "Alpha";
1778 case EM_CYGNUS_D10V
:
1779 case EM_D10V
: return "d10v";
1780 case EM_CYGNUS_D30V
:
1781 case EM_D30V
: return "d30v";
1782 case EM_CYGNUS_M32R
:
1783 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1784 case EM_CYGNUS_V850
:
1785 case EM_V850
: return "NEC v850";
1786 case EM_CYGNUS_MN10300
:
1787 case EM_MN10300
: return "mn10300";
1788 case EM_CYGNUS_MN10200
:
1789 case EM_MN10200
: return "mn10200";
1790 case EM_CYGNUS_FR30
:
1791 case EM_FR30
: return "Fujitsu FR30";
1792 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1794 case EM_PJ
: return "picoJava";
1795 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1796 case EM_PCP
: return "Siemens PCP";
1797 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1798 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1799 case EM_STARCORE
: return "Motorola Star*Core processor";
1800 case EM_ME16
: return "Toyota ME16 processor";
1801 case EM_ST100
: return "STMicroelectronics ST100 processor";
1802 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1803 case EM_FX66
: return "Siemens FX66 microcontroller";
1804 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1805 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1806 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1807 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1808 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1809 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1810 case EM_SVX
: return "Silicon Graphics SVx";
1811 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1812 case EM_VAX
: return "Digital VAX";
1814 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1815 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1816 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1817 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1818 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1819 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1820 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1821 case EM_PRISM
: return "Vitesse Prism";
1822 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1824 case EM_S390
: return "IBM S/390";
1825 case EM_SCORE
: return "SUNPLUS S+Core";
1826 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1828 case EM_OR32
: return "OpenRISC";
1829 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1830 case EM_DLX
: return "OpenDLX";
1832 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1833 case EM_IQ2000
: return "Vitesse IQ2000";
1835 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1836 case EM_M32C
: return "Renesas M32c";
1837 case EM_MT
: return "Morpho Techologies MT processor";
1838 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1839 case EM_NIOS32
: return "Altera Nios";
1840 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1841 case EM_XC16X
: return "Infineon Technologies xc16x";
1842 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1843 case EM_CR16
: return "National Semiconductor's CR16";
1845 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
1851 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1856 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1857 e_flags
&= ~ EF_ARM_EABIMASK
;
1859 /* Handle "generic" ARM flags. */
1860 if (e_flags
& EF_ARM_RELEXEC
)
1862 strcat (buf
, ", relocatable executable");
1863 e_flags
&= ~ EF_ARM_RELEXEC
;
1866 if (e_flags
& EF_ARM_HASENTRY
)
1868 strcat (buf
, ", has entry point");
1869 e_flags
&= ~ EF_ARM_HASENTRY
;
1872 /* Now handle EABI specific flags. */
1876 strcat (buf
, ", <unrecognized EABI>");
1881 case EF_ARM_EABI_VER1
:
1882 strcat (buf
, ", Version1 EABI");
1887 /* Process flags one bit at a time. */
1888 flag
= e_flags
& - e_flags
;
1893 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1894 strcat (buf
, ", sorted symbol tables");
1904 case EF_ARM_EABI_VER2
:
1905 strcat (buf
, ", Version2 EABI");
1910 /* Process flags one bit at a time. */
1911 flag
= e_flags
& - e_flags
;
1916 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1917 strcat (buf
, ", sorted symbol tables");
1920 case EF_ARM_DYNSYMSUSESEGIDX
:
1921 strcat (buf
, ", dynamic symbols use segment index");
1924 case EF_ARM_MAPSYMSFIRST
:
1925 strcat (buf
, ", mapping symbols precede others");
1935 case EF_ARM_EABI_VER3
:
1936 strcat (buf
, ", Version3 EABI");
1939 case EF_ARM_EABI_VER4
:
1940 strcat (buf
, ", Version4 EABI");
1943 case EF_ARM_EABI_VER5
:
1944 strcat (buf
, ", Version5 EABI");
1950 /* Process flags one bit at a time. */
1951 flag
= e_flags
& - e_flags
;
1957 strcat (buf
, ", BE8");
1961 strcat (buf
, ", LE8");
1971 case EF_ARM_EABI_UNKNOWN
:
1972 strcat (buf
, ", GNU EABI");
1977 /* Process flags one bit at a time. */
1978 flag
= e_flags
& - e_flags
;
1983 case EF_ARM_INTERWORK
:
1984 strcat (buf
, ", interworking enabled");
1987 case EF_ARM_APCS_26
:
1988 strcat (buf
, ", uses APCS/26");
1991 case EF_ARM_APCS_FLOAT
:
1992 strcat (buf
, ", uses APCS/float");
1996 strcat (buf
, ", position independent");
2000 strcat (buf
, ", 8 bit structure alignment");
2003 case EF_ARM_NEW_ABI
:
2004 strcat (buf
, ", uses new ABI");
2007 case EF_ARM_OLD_ABI
:
2008 strcat (buf
, ", uses old ABI");
2011 case EF_ARM_SOFT_FLOAT
:
2012 strcat (buf
, ", software FP");
2015 case EF_ARM_VFP_FLOAT
:
2016 strcat (buf
, ", VFP");
2019 case EF_ARM_MAVERICK_FLOAT
:
2020 strcat (buf
, ", Maverick FP");
2031 strcat (buf
,", <unknown>");
2035 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
2037 static char buf
[1024];
2049 decode_ARM_machine_flags (e_flags
, buf
);
2053 switch (e_flags
& EF_FRV_CPU_MASK
)
2055 case EF_FRV_CPU_GENERIC
:
2059 strcat (buf
, ", fr???");
2062 case EF_FRV_CPU_FR300
:
2063 strcat (buf
, ", fr300");
2066 case EF_FRV_CPU_FR400
:
2067 strcat (buf
, ", fr400");
2069 case EF_FRV_CPU_FR405
:
2070 strcat (buf
, ", fr405");
2073 case EF_FRV_CPU_FR450
:
2074 strcat (buf
, ", fr450");
2077 case EF_FRV_CPU_FR500
:
2078 strcat (buf
, ", fr500");
2080 case EF_FRV_CPU_FR550
:
2081 strcat (buf
, ", fr550");
2084 case EF_FRV_CPU_SIMPLE
:
2085 strcat (buf
, ", simple");
2087 case EF_FRV_CPU_TOMCAT
:
2088 strcat (buf
, ", tomcat");
2094 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2095 strcat (buf
, ", m68000");
2096 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2097 strcat (buf
, ", cpu32");
2098 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2099 strcat (buf
, ", fido_a");
2102 char const *isa
= _("unknown");
2103 char const *mac
= _("unknown mac");
2104 char const *additional
= NULL
;
2106 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2108 case EF_M68K_CF_ISA_A_NODIV
:
2110 additional
= ", nodiv";
2112 case EF_M68K_CF_ISA_A
:
2115 case EF_M68K_CF_ISA_A_PLUS
:
2118 case EF_M68K_CF_ISA_B_NOUSP
:
2120 additional
= ", nousp";
2122 case EF_M68K_CF_ISA_B
:
2126 strcat (buf
, ", cf, isa ");
2129 strcat (buf
, additional
);
2130 if (e_flags
& EF_M68K_CF_FLOAT
)
2131 strcat (buf
, ", float");
2132 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2137 case EF_M68K_CF_MAC
:
2140 case EF_M68K_CF_EMAC
:
2153 if (e_flags
& EF_PPC_EMB
)
2154 strcat (buf
, ", emb");
2156 if (e_flags
& EF_PPC_RELOCATABLE
)
2157 strcat (buf
, ", relocatable");
2159 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2160 strcat (buf
, ", relocatable-lib");
2164 case EM_CYGNUS_V850
:
2165 switch (e_flags
& EF_V850_ARCH
)
2168 strcat (buf
, ", v850e1");
2171 strcat (buf
, ", v850e");
2174 strcat (buf
, ", v850");
2177 strcat (buf
, ", unknown v850 architecture variant");
2183 case EM_CYGNUS_M32R
:
2184 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2185 strcat (buf
, ", m32r");
2189 case EM_MIPS_RS3_LE
:
2190 if (e_flags
& EF_MIPS_NOREORDER
)
2191 strcat (buf
, ", noreorder");
2193 if (e_flags
& EF_MIPS_PIC
)
2194 strcat (buf
, ", pic");
2196 if (e_flags
& EF_MIPS_CPIC
)
2197 strcat (buf
, ", cpic");
2199 if (e_flags
& EF_MIPS_UCODE
)
2200 strcat (buf
, ", ugen_reserved");
2202 if (e_flags
& EF_MIPS_ABI2
)
2203 strcat (buf
, ", abi2");
2205 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2206 strcat (buf
, ", odk first");
2208 if (e_flags
& EF_MIPS_32BITMODE
)
2209 strcat (buf
, ", 32bitmode");
2211 switch ((e_flags
& EF_MIPS_MACH
))
2213 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2214 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2215 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2216 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2217 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2218 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2219 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2220 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2221 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2222 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2223 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
2224 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
2226 /* We simply ignore the field in this case to avoid confusion:
2227 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2230 default: strcat (buf
, ", unknown CPU"); break;
2233 switch ((e_flags
& EF_MIPS_ABI
))
2235 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2236 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2237 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2238 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2240 /* We simply ignore the field in this case to avoid confusion:
2241 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2242 This means it is likely to be an o32 file, but not for
2245 default: strcat (buf
, ", unknown ABI"); break;
2248 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2249 strcat (buf
, ", mdmx");
2251 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2252 strcat (buf
, ", mips16");
2254 switch ((e_flags
& EF_MIPS_ARCH
))
2256 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2257 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2258 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2259 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2260 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2261 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2262 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2263 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2264 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2265 default: strcat (buf
, ", unknown ISA"); break;
2271 switch ((e_flags
& EF_SH_MACH_MASK
))
2273 case EF_SH1
: strcat (buf
, ", sh1"); break;
2274 case EF_SH2
: strcat (buf
, ", sh2"); break;
2275 case EF_SH3
: strcat (buf
, ", sh3"); break;
2276 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2277 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2278 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2279 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2280 case EF_SH4
: strcat (buf
, ", sh4"); break;
2281 case EF_SH5
: strcat (buf
, ", sh5"); break;
2282 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2283 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2284 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2285 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2286 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2287 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2288 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2289 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2290 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2291 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2292 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2293 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2294 default: strcat (buf
, ", unknown ISA"); break;
2300 if (e_flags
& EF_SPARC_32PLUS
)
2301 strcat (buf
, ", v8+");
2303 if (e_flags
& EF_SPARC_SUN_US1
)
2304 strcat (buf
, ", ultrasparcI");
2306 if (e_flags
& EF_SPARC_SUN_US3
)
2307 strcat (buf
, ", ultrasparcIII");
2309 if (e_flags
& EF_SPARC_HAL_R1
)
2310 strcat (buf
, ", halr1");
2312 if (e_flags
& EF_SPARC_LEDATA
)
2313 strcat (buf
, ", ledata");
2315 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2316 strcat (buf
, ", tso");
2318 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2319 strcat (buf
, ", pso");
2321 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2322 strcat (buf
, ", rmo");
2326 switch (e_flags
& EF_PARISC_ARCH
)
2328 case EFA_PARISC_1_0
:
2329 strcpy (buf
, ", PA-RISC 1.0");
2331 case EFA_PARISC_1_1
:
2332 strcpy (buf
, ", PA-RISC 1.1");
2334 case EFA_PARISC_2_0
:
2335 strcpy (buf
, ", PA-RISC 2.0");
2340 if (e_flags
& EF_PARISC_TRAPNIL
)
2341 strcat (buf
, ", trapnil");
2342 if (e_flags
& EF_PARISC_EXT
)
2343 strcat (buf
, ", ext");
2344 if (e_flags
& EF_PARISC_LSB
)
2345 strcat (buf
, ", lsb");
2346 if (e_flags
& EF_PARISC_WIDE
)
2347 strcat (buf
, ", wide");
2348 if (e_flags
& EF_PARISC_NO_KABP
)
2349 strcat (buf
, ", no kabp");
2350 if (e_flags
& EF_PARISC_LAZYSWAP
)
2351 strcat (buf
, ", lazyswap");
2356 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2357 strcat (buf
, ", new calling convention");
2359 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2360 strcat (buf
, ", gnu calling convention");
2364 if ((e_flags
& EF_IA_64_ABI64
))
2365 strcat (buf
, ", 64-bit");
2367 strcat (buf
, ", 32-bit");
2368 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2369 strcat (buf
, ", reduced fp model");
2370 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2371 strcat (buf
, ", no function descriptors, constant gp");
2372 else if ((e_flags
& EF_IA_64_CONS_GP
))
2373 strcat (buf
, ", constant gp");
2374 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2375 strcat (buf
, ", absolute");
2379 if ((e_flags
& EF_VAX_NONPIC
))
2380 strcat (buf
, ", non-PIC");
2381 if ((e_flags
& EF_VAX_DFLOAT
))
2382 strcat (buf
, ", D-Float");
2383 if ((e_flags
& EF_VAX_GFLOAT
))
2384 strcat (buf
, ", G-Float");
2393 get_osabi_name (unsigned int osabi
)
2395 static char buff
[32];
2399 case ELFOSABI_NONE
: return "UNIX - System V";
2400 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2401 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2402 case ELFOSABI_LINUX
: return "UNIX - Linux";
2403 case ELFOSABI_HURD
: return "GNU/Hurd";
2404 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2405 case ELFOSABI_AIX
: return "UNIX - AIX";
2406 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2407 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2408 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2409 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2410 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2411 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2412 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2413 case ELFOSABI_AROS
: return "Amiga Research OS";
2414 case ELFOSABI_STANDALONE
: return _("Standalone App");
2415 case ELFOSABI_ARM
: return "ARM";
2417 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2423 get_arm_segment_type (unsigned long type
)
2437 get_mips_segment_type (unsigned long type
)
2441 case PT_MIPS_REGINFO
:
2443 case PT_MIPS_RTPROC
:
2445 case PT_MIPS_OPTIONS
:
2455 get_parisc_segment_type (unsigned long type
)
2459 case PT_HP_TLS
: return "HP_TLS";
2460 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2461 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2462 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2463 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2464 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2465 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2466 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2467 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2468 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2469 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2470 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2471 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2472 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2473 case PT_HP_STACK
: return "HP_STACK";
2474 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2475 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2476 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2477 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2486 get_ia64_segment_type (unsigned long type
)
2490 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2491 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2492 case PT_HP_TLS
: return "HP_TLS";
2493 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2494 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2495 case PT_IA_64_HP_STACK
: return "HP_STACK";
2504 get_segment_type (unsigned long p_type
)
2506 static char buff
[32];
2510 case PT_NULL
: return "NULL";
2511 case PT_LOAD
: return "LOAD";
2512 case PT_DYNAMIC
: return "DYNAMIC";
2513 case PT_INTERP
: return "INTERP";
2514 case PT_NOTE
: return "NOTE";
2515 case PT_SHLIB
: return "SHLIB";
2516 case PT_PHDR
: return "PHDR";
2517 case PT_TLS
: return "TLS";
2519 case PT_GNU_EH_FRAME
:
2520 return "GNU_EH_FRAME";
2521 case PT_GNU_STACK
: return "GNU_STACK";
2522 case PT_GNU_RELRO
: return "GNU_RELRO";
2525 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2529 switch (elf_header
.e_machine
)
2532 result
= get_arm_segment_type (p_type
);
2535 case EM_MIPS_RS3_LE
:
2536 result
= get_mips_segment_type (p_type
);
2539 result
= get_parisc_segment_type (p_type
);
2542 result
= get_ia64_segment_type (p_type
);
2552 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2554 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2558 switch (elf_header
.e_machine
)
2561 result
= get_parisc_segment_type (p_type
);
2564 result
= get_ia64_segment_type (p_type
);
2574 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2577 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2584 get_mips_section_type_name (unsigned int sh_type
)
2588 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2589 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2590 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2591 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2592 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2593 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2594 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2595 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2596 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2597 case SHT_MIPS_RELD
: return "MIPS_RELD";
2598 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2599 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2600 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2601 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2602 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2603 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2604 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2605 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2606 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2607 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2608 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2609 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2610 case SHT_MIPS_LINE
: return "MIPS_LINE";
2611 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2612 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2613 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2614 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2615 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2616 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2617 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2618 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2619 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2620 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2621 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2622 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2623 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2624 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2625 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2626 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2634 get_parisc_section_type_name (unsigned int sh_type
)
2638 case SHT_PARISC_EXT
: return "PARISC_EXT";
2639 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2640 case SHT_PARISC_DOC
: return "PARISC_DOC";
2641 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2642 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2643 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2644 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2652 get_ia64_section_type_name (unsigned int sh_type
)
2654 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2655 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2656 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2660 case SHT_IA_64_EXT
: return "IA_64_EXT";
2661 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2662 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2670 get_x86_64_section_type_name (unsigned int sh_type
)
2674 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2682 get_arm_section_type_name (unsigned int sh_type
)
2688 case SHT_ARM_PREEMPTMAP
:
2689 return "ARM_PREEMPTMAP";
2690 case SHT_ARM_ATTRIBUTES
:
2691 return "ARM_ATTRIBUTES";
2699 get_section_type_name (unsigned int sh_type
)
2701 static char buff
[32];
2705 case SHT_NULL
: return "NULL";
2706 case SHT_PROGBITS
: return "PROGBITS";
2707 case SHT_SYMTAB
: return "SYMTAB";
2708 case SHT_STRTAB
: return "STRTAB";
2709 case SHT_RELA
: return "RELA";
2710 case SHT_HASH
: return "HASH";
2711 case SHT_DYNAMIC
: return "DYNAMIC";
2712 case SHT_NOTE
: return "NOTE";
2713 case SHT_NOBITS
: return "NOBITS";
2714 case SHT_REL
: return "REL";
2715 case SHT_SHLIB
: return "SHLIB";
2716 case SHT_DYNSYM
: return "DYNSYM";
2717 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2718 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2719 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2720 case SHT_GNU_HASH
: return "GNU_HASH";
2721 case SHT_GROUP
: return "GROUP";
2722 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2723 case SHT_GNU_verdef
: return "VERDEF";
2724 case SHT_GNU_verneed
: return "VERNEED";
2725 case SHT_GNU_versym
: return "VERSYM";
2726 case 0x6ffffff0: return "VERSYM";
2727 case 0x6ffffffc: return "VERDEF";
2728 case 0x7ffffffd: return "AUXILIARY";
2729 case 0x7fffffff: return "FILTER";
2730 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2733 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2737 switch (elf_header
.e_machine
)
2740 case EM_MIPS_RS3_LE
:
2741 result
= get_mips_section_type_name (sh_type
);
2744 result
= get_parisc_section_type_name (sh_type
);
2747 result
= get_ia64_section_type_name (sh_type
);
2750 result
= get_x86_64_section_type_name (sh_type
);
2753 result
= get_arm_section_type_name (sh_type
);
2763 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2765 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2766 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2767 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2768 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2770 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2776 #define OPTION_DEBUG_DUMP 512
2778 static struct option options
[] =
2780 {"all", no_argument
, 0, 'a'},
2781 {"file-header", no_argument
, 0, 'h'},
2782 {"program-headers", no_argument
, 0, 'l'},
2783 {"headers", no_argument
, 0, 'e'},
2784 {"histogram", no_argument
, 0, 'I'},
2785 {"segments", no_argument
, 0, 'l'},
2786 {"sections", no_argument
, 0, 'S'},
2787 {"section-headers", no_argument
, 0, 'S'},
2788 {"section-groups", no_argument
, 0, 'g'},
2789 {"section-details", no_argument
, 0, 't'},
2790 {"full-section-name",no_argument
, 0, 'N'},
2791 {"symbols", no_argument
, 0, 's'},
2792 {"syms", no_argument
, 0, 's'},
2793 {"relocs", no_argument
, 0, 'r'},
2794 {"notes", no_argument
, 0, 'n'},
2795 {"dynamic", no_argument
, 0, 'd'},
2796 {"arch-specific", no_argument
, 0, 'A'},
2797 {"version-info", no_argument
, 0, 'V'},
2798 {"use-dynamic", no_argument
, 0, 'D'},
2799 {"unwind", no_argument
, 0, 'u'},
2800 {"archive-index", no_argument
, 0, 'c'},
2801 {"hex-dump", required_argument
, 0, 'x'},
2802 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2803 {"string-dump", required_argument
, 0, 'p'},
2804 #ifdef SUPPORT_DISASSEMBLY
2805 {"instruction-dump", required_argument
, 0, 'i'},
2808 {"version", no_argument
, 0, 'v'},
2809 {"wide", no_argument
, 0, 'W'},
2810 {"help", no_argument
, 0, 'H'},
2811 {0, no_argument
, 0, 0}
2815 usage (FILE *stream
)
2817 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2818 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
2819 fprintf (stream
, _(" Options are:\n\
2820 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2821 -h --file-header Display the ELF file header\n\
2822 -l --program-headers Display the program headers\n\
2823 --segments An alias for --program-headers\n\
2824 -S --section-headers Display the sections' header\n\
2825 --sections An alias for --section-headers\n\
2826 -g --section-groups Display the section groups\n\
2827 -t --section-details Display the section details\n\
2828 -e --headers Equivalent to: -h -l -S\n\
2829 -s --syms Display the symbol table\n\
2830 --symbols An alias for --syms\n\
2831 -n --notes Display the core notes (if present)\n\
2832 -r --relocs Display the relocations (if present)\n\
2833 -u --unwind Display the unwind info (if present)\n\
2834 -d --dynamic Display the dynamic section (if present)\n\
2835 -V --version-info Display the version sections (if present)\n\
2836 -A --arch-specific Display architecture specific information (if any).\n\
2837 -c --archive-index Display the symbol/file index in an archive\n\
2838 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2839 -x --hex-dump=<number|name>\n\
2840 Dump the contents of section <number|name> as bytes\n\
2841 -p --string-dump=<number|name>\n\
2842 Dump the contents of section <number|name> as strings\n\
2843 -w[liaprmfFsoR] or\n\
2844 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2845 Display the contents of DWARF2 debug sections\n"));
2846 #ifdef SUPPORT_DISASSEMBLY
2847 fprintf (stream
, _("\
2848 -i --instruction-dump=<number|name>\n\
2849 Disassemble the contents of section <number|name>\n"));
2851 fprintf (stream
, _("\
2852 -I --histogram Display histogram of bucket list lengths\n\
2853 -W --wide Allow output width to exceed 80 characters\n\
2854 @<file> Read options from <file>\n\
2855 -H --help Display this information\n\
2856 -v --version Display the version number of readelf\n"));
2858 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2859 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2861 exit (stream
== stdout
? 0 : 1);
2864 /* Record the fact that the user wants the contents of section number
2865 SECTION to be displayed using the method(s) encoded as flags bits
2866 in TYPE. Note, TYPE can be zero if we are creating the array for
2870 request_dump_bynumber (unsigned int section
, dump_type type
)
2872 if (section
>= num_dump_sects
)
2874 dump_type
*new_dump_sects
;
2876 new_dump_sects
= calloc (section
+ 1, sizeof (* dump_sects
));
2878 if (new_dump_sects
== NULL
)
2879 error (_("Out of memory allocating dump request table.\n"));
2882 /* Copy current flag settings. */
2883 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
* sizeof (* dump_sects
));
2887 dump_sects
= new_dump_sects
;
2888 num_dump_sects
= section
+ 1;
2893 dump_sects
[section
] |= type
;
2898 /* Request a dump by section name. */
2901 request_dump_byname (const char *section
, dump_type type
)
2903 struct dump_list_entry
*new_request
;
2905 new_request
= malloc (sizeof (struct dump_list_entry
));
2907 error (_("Out of memory allocating dump request table.\n"));
2909 new_request
->name
= strdup (section
);
2910 if (!new_request
->name
)
2911 error (_("Out of memory allocating dump request table.\n"));
2913 new_request
->type
= type
;
2915 new_request
->next
= dump_sects_byname
;
2916 dump_sects_byname
= new_request
;
2920 parse_args (int argc
, char **argv
)
2927 while ((c
= getopt_long
2928 (argc
, argv
, "ADHINSVWacdeghi:lnp:rstuvw::x:", options
, NULL
)) != EOF
)
2949 do_section_groups
++;
2957 do_section_groups
++;
2962 do_section_details
++;
3007 section
= strtoul (optarg
, & cp
, 0);
3008 if (! *cp
&& section
>= 0)
3009 request_dump_bynumber (section
, HEX_DUMP
);
3011 request_dump_byname (optarg
, HEX_DUMP
);
3015 section
= strtoul (optarg
, & cp
, 0);
3016 if (! *cp
&& section
>= 0)
3017 request_dump_bynumber (section
, STRING_DUMP
);
3019 request_dump_byname (optarg
, STRING_DUMP
);
3027 unsigned int index
= 0;
3031 while (optarg
[index
])
3032 switch (optarg
[index
++])
3039 do_debug_abbrevs
= 1;
3047 do_debug_pubnames
= 1;
3051 do_debug_aranges
= 1;
3055 do_debug_ranges
= 1;
3059 do_debug_frames_interp
= 1;
3061 do_debug_frames
= 1;
3065 do_debug_macinfo
= 1;
3077 warn (_("Unrecognized debug option '%s'\n"), optarg
);
3082 case OPTION_DEBUG_DUMP
:
3090 const char * option
;
3093 debug_dump_long_opts
;
3095 debug_dump_long_opts opts_table
[] =
3097 /* Please keep this table alpha- sorted. */
3098 { "Ranges", & do_debug_ranges
},
3099 { "abbrev", & do_debug_abbrevs
},
3100 { "aranges", & do_debug_aranges
},
3101 { "frames", & do_debug_frames
},
3102 { "frames-interp", & do_debug_frames_interp
},
3103 { "info", & do_debug_info
},
3104 { "line", & do_debug_lines
},
3105 { "loc", & do_debug_loc
},
3106 { "macro", & do_debug_macinfo
},
3107 { "pubnames", & do_debug_pubnames
},
3108 /* This entry is for compatability
3109 with earlier versions of readelf. */
3110 { "ranges", & do_debug_aranges
},
3111 { "str", & do_debug_str
},
3122 debug_dump_long_opts
* entry
;
3124 for (entry
= opts_table
; entry
->option
; entry
++)
3126 size_t len
= strlen (entry
->option
);
3128 if (strneq (p
, entry
->option
, len
)
3129 && (p
[len
] == ',' || p
[len
] == '\0'))
3131 * entry
->variable
= 1;
3133 /* The --debug-dump=frames-interp option also
3134 enables the --debug-dump=frames option. */
3135 if (do_debug_frames_interp
)
3136 do_debug_frames
= 1;
3143 if (entry
->option
== NULL
)
3145 warn (_("Unrecognized debug option '%s'\n"), p
);
3146 p
= strchr (p
, ',');
3156 #ifdef SUPPORT_DISASSEMBLY
3159 section
= strtoul (optarg
, & cp
, 0);
3160 if (! *cp
&& section
>= 0)
3161 request_dump_bynumber (section
, DISASS_DUMP
);
3163 request_dump_byname (optarg
, DISASS_DUMP
);
3166 print_version (program_name
);
3175 /* xgettext:c-format */
3176 error (_("Invalid option '-%c'\n"), c
);
3183 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3184 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3185 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3186 && !do_section_groups
&& !do_archive_index
)
3190 warn (_("Nothing to do.\n"));
3196 get_elf_class (unsigned int elf_class
)
3198 static char buff
[32];
3202 case ELFCLASSNONE
: return _("none");
3203 case ELFCLASS32
: return "ELF32";
3204 case ELFCLASS64
: return "ELF64";
3206 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3212 get_data_encoding (unsigned int encoding
)
3214 static char buff
[32];
3218 case ELFDATANONE
: return _("none");
3219 case ELFDATA2LSB
: return _("2's complement, little endian");
3220 case ELFDATA2MSB
: return _("2's complement, big endian");
3222 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3227 /* Decode the data held in 'elf_header'. */
3230 process_file_header (void)
3232 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3233 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3234 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3235 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3238 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3242 init_dwarf_regnames (elf_header
.e_machine
);
3248 printf (_("ELF Header:\n"));
3249 printf (_(" Magic: "));
3250 for (i
= 0; i
< EI_NIDENT
; i
++)
3251 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3253 printf (_(" Class: %s\n"),
3254 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3255 printf (_(" Data: %s\n"),
3256 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3257 printf (_(" Version: %d %s\n"),
3258 elf_header
.e_ident
[EI_VERSION
],
3259 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3261 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3264 printf (_(" OS/ABI: %s\n"),
3265 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3266 printf (_(" ABI Version: %d\n"),
3267 elf_header
.e_ident
[EI_ABIVERSION
]);
3268 printf (_(" Type: %s\n"),
3269 get_file_type (elf_header
.e_type
));
3270 printf (_(" Machine: %s\n"),
3271 get_machine_name (elf_header
.e_machine
));
3272 printf (_(" Version: 0x%lx\n"),
3273 (unsigned long) elf_header
.e_version
);
3275 printf (_(" Entry point address: "));
3276 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3277 printf (_("\n Start of program headers: "));
3278 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3279 printf (_(" (bytes into file)\n Start of section headers: "));
3280 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3281 printf (_(" (bytes into file)\n"));
3283 printf (_(" Flags: 0x%lx%s\n"),
3284 (unsigned long) elf_header
.e_flags
,
3285 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3286 printf (_(" Size of this header: %ld (bytes)\n"),
3287 (long) elf_header
.e_ehsize
);
3288 printf (_(" Size of program headers: %ld (bytes)\n"),
3289 (long) elf_header
.e_phentsize
);
3290 printf (_(" Number of program headers: %ld\n"),
3291 (long) elf_header
.e_phnum
);
3292 printf (_(" Size of section headers: %ld (bytes)\n"),
3293 (long) elf_header
.e_shentsize
);
3294 printf (_(" Number of section headers: %ld"),
3295 (long) elf_header
.e_shnum
);
3296 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3297 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3298 putc ('\n', stdout
);
3299 printf (_(" Section header string table index: %ld"),
3300 (long) elf_header
.e_shstrndx
);
3301 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3302 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3303 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3304 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3305 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3306 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3307 printf (" <corrupt: out of range>");
3308 putc ('\n', stdout
);
3311 if (section_headers
!= NULL
)
3313 if (elf_header
.e_shnum
== 0)
3314 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3315 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3316 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3317 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3318 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3319 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3320 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3321 elf_header
.e_shstrndx
= SHN_UNDEF
;
3322 free (section_headers
);
3323 section_headers
= NULL
;
3331 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3333 Elf32_External_Phdr
*phdrs
;
3334 Elf32_External_Phdr
*external
;
3335 Elf_Internal_Phdr
*internal
;
3338 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3339 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3340 _("program headers"));
3344 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3345 i
< elf_header
.e_phnum
;
3346 i
++, internal
++, external
++)
3348 internal
->p_type
= BYTE_GET (external
->p_type
);
3349 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3350 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3351 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3352 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3353 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3354 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3355 internal
->p_align
= BYTE_GET (external
->p_align
);
3364 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3366 Elf64_External_Phdr
*phdrs
;
3367 Elf64_External_Phdr
*external
;
3368 Elf_Internal_Phdr
*internal
;
3371 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3372 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3373 _("program headers"));
3377 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3378 i
< elf_header
.e_phnum
;
3379 i
++, internal
++, external
++)
3381 internal
->p_type
= BYTE_GET (external
->p_type
);
3382 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3383 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3384 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3385 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3386 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3387 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3388 internal
->p_align
= BYTE_GET (external
->p_align
);
3396 /* Returns 1 if the program headers were read into `program_headers'. */
3399 get_program_headers (FILE *file
)
3401 Elf_Internal_Phdr
*phdrs
;
3403 /* Check cache of prior read. */
3404 if (program_headers
!= NULL
)
3407 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3411 error (_("Out of memory\n"));
3416 ? get_32bit_program_headers (file
, phdrs
)
3417 : get_64bit_program_headers (file
, phdrs
))
3419 program_headers
= phdrs
;
3427 /* Returns 1 if the program headers were loaded. */
3430 process_program_headers (FILE *file
)
3432 Elf_Internal_Phdr
*segment
;
3435 if (elf_header
.e_phnum
== 0)
3438 printf (_("\nThere are no program headers in this file.\n"));
3442 if (do_segments
&& !do_header
)
3444 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3445 printf (_("Entry point "));
3446 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3447 printf (_("\nThere are %d program headers, starting at offset "),
3448 elf_header
.e_phnum
);
3449 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3453 if (! get_program_headers (file
))
3458 if (elf_header
.e_phnum
> 1)
3459 printf (_("\nProgram Headers:\n"));
3461 printf (_("\nProgram Headers:\n"));
3465 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3468 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3472 (_(" Type Offset VirtAddr PhysAddr\n"));
3474 (_(" FileSiz MemSiz Flags Align\n"));
3481 for (i
= 0, segment
= program_headers
;
3482 i
< elf_header
.e_phnum
;
3487 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3491 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3492 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3493 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3494 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3495 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3497 (segment
->p_flags
& PF_R
? 'R' : ' '),
3498 (segment
->p_flags
& PF_W
? 'W' : ' '),
3499 (segment
->p_flags
& PF_X
? 'E' : ' '));
3500 printf ("%#lx", (unsigned long) segment
->p_align
);
3504 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3505 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3508 print_vma (segment
->p_offset
, FULL_HEX
);
3512 print_vma (segment
->p_vaddr
, FULL_HEX
);
3514 print_vma (segment
->p_paddr
, FULL_HEX
);
3517 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3518 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3521 print_vma (segment
->p_filesz
, FULL_HEX
);
3525 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3526 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3529 print_vma (segment
->p_offset
, FULL_HEX
);
3533 (segment
->p_flags
& PF_R
? 'R' : ' '),
3534 (segment
->p_flags
& PF_W
? 'W' : ' '),
3535 (segment
->p_flags
& PF_X
? 'E' : ' '));
3537 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3538 printf ("%#lx", (unsigned long) segment
->p_align
);
3541 print_vma (segment
->p_align
, PREFIX_HEX
);
3546 print_vma (segment
->p_offset
, FULL_HEX
);
3548 print_vma (segment
->p_vaddr
, FULL_HEX
);
3550 print_vma (segment
->p_paddr
, FULL_HEX
);
3552 print_vma (segment
->p_filesz
, FULL_HEX
);
3554 print_vma (segment
->p_memsz
, FULL_HEX
);
3556 (segment
->p_flags
& PF_R
? 'R' : ' '),
3557 (segment
->p_flags
& PF_W
? 'W' : ' '),
3558 (segment
->p_flags
& PF_X
? 'E' : ' '));
3559 print_vma (segment
->p_align
, HEX
);
3563 switch (segment
->p_type
)
3567 error (_("more than one dynamic segment\n"));
3569 /* By default, assume that the .dynamic section is the first
3570 section in the DYNAMIC segment. */
3571 dynamic_addr
= segment
->p_offset
;
3572 dynamic_size
= segment
->p_filesz
;
3574 /* Try to locate the .dynamic section. If there is
3575 a section header table, we can easily locate it. */
3576 if (section_headers
!= NULL
)
3578 Elf_Internal_Shdr
*sec
;
3580 sec
= find_section (".dynamic");
3581 if (sec
== NULL
|| sec
->sh_size
== 0)
3583 error (_("no .dynamic section in the dynamic segment\n"));
3587 if (sec
->sh_type
== SHT_NOBITS
)
3593 dynamic_addr
= sec
->sh_offset
;
3594 dynamic_size
= sec
->sh_size
;
3596 if (dynamic_addr
< segment
->p_offset
3597 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3598 warn (_("the .dynamic section is not contained"
3599 " within the dynamic segment\n"));
3600 else if (dynamic_addr
> segment
->p_offset
)
3601 warn (_("the .dynamic section is not the first section"
3602 " in the dynamic segment.\n"));
3607 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3609 error (_("Unable to find program interpreter name\n"));
3613 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3615 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3616 error (_("Internal error: failed to create format string to display program interpreter\n"));
3618 program_interpreter
[0] = 0;
3619 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3620 error (_("Unable to read program interpreter name\n"));
3623 printf (_("\n [Requesting program interpreter: %s]"),
3624 program_interpreter
);
3630 putc ('\n', stdout
);
3633 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3635 printf (_("\n Section to Segment mapping:\n"));
3636 printf (_(" Segment Sections...\n"));
3638 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3641 Elf_Internal_Shdr
*section
;
3643 segment
= program_headers
+ i
;
3644 section
= section_headers
;
3646 printf (" %2.2d ", i
);
3648 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3650 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section
, segment
))
3651 printf ("%s ", SECTION_NAME (section
));
3662 /* Find the file offset corresponding to VMA by using the program headers. */
3665 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3667 Elf_Internal_Phdr
*seg
;
3669 if (! get_program_headers (file
))
3671 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3675 for (seg
= program_headers
;
3676 seg
< program_headers
+ elf_header
.e_phnum
;
3679 if (seg
->p_type
!= PT_LOAD
)
3682 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3683 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3684 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3687 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3694 get_32bit_section_headers (FILE *file
, unsigned int num
)
3696 Elf32_External_Shdr
*shdrs
;
3697 Elf_Internal_Shdr
*internal
;
3700 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3701 elf_header
.e_shentsize
, num
, _("section headers"));
3705 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3707 if (section_headers
== NULL
)
3709 error (_("Out of memory\n"));
3713 for (i
= 0, internal
= section_headers
;
3717 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3718 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3719 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3720 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3721 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3722 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3723 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3724 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3725 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3726 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3735 get_64bit_section_headers (FILE *file
, unsigned int num
)
3737 Elf64_External_Shdr
*shdrs
;
3738 Elf_Internal_Shdr
*internal
;
3741 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3742 elf_header
.e_shentsize
, num
, _("section headers"));
3746 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3748 if (section_headers
== NULL
)
3750 error (_("Out of memory\n"));
3754 for (i
= 0, internal
= section_headers
;
3758 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3759 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3760 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3761 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3762 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3763 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3764 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3765 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3766 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3767 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3775 static Elf_Internal_Sym
*
3776 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3778 unsigned long number
;
3779 Elf32_External_Sym
*esyms
;
3780 Elf_External_Sym_Shndx
*shndx
;
3781 Elf_Internal_Sym
*isyms
;
3782 Elf_Internal_Sym
*psym
;
3785 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3791 if (symtab_shndx_hdr
!= NULL
3792 && (symtab_shndx_hdr
->sh_link
3793 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3795 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3796 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3804 number
= section
->sh_size
/ section
->sh_entsize
;
3805 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3809 error (_("Out of memory\n"));
3816 for (j
= 0, psym
= isyms
;
3820 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3821 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3822 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3823 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3824 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3826 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3827 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3828 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3838 static Elf_Internal_Sym
*
3839 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3841 unsigned long number
;
3842 Elf64_External_Sym
*esyms
;
3843 Elf_External_Sym_Shndx
*shndx
;
3844 Elf_Internal_Sym
*isyms
;
3845 Elf_Internal_Sym
*psym
;
3848 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3854 if (symtab_shndx_hdr
!= NULL
3855 && (symtab_shndx_hdr
->sh_link
3856 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3858 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3859 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3867 number
= section
->sh_size
/ section
->sh_entsize
;
3868 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3872 error (_("Out of memory\n"));
3879 for (j
= 0, psym
= isyms
;
3883 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3884 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3885 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3886 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3887 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3889 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3890 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3891 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3902 get_elf_section_flags (bfd_vma sh_flags
)
3904 static char buff
[1024];
3906 int field_size
= is_32bit_elf
? 8 : 16;
3907 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3908 bfd_vma os_flags
= 0;
3909 bfd_vma proc_flags
= 0;
3910 bfd_vma unknown_flags
= 0;
3924 { "LINK ORDER", 10 },
3925 { "OS NONCONF", 10 },
3930 if (do_section_details
)
3932 sprintf (buff
, "[%*.*lx]: ",
3933 field_size
, field_size
, (unsigned long) sh_flags
);
3934 p
+= field_size
+ 4;
3941 flag
= sh_flags
& - sh_flags
;
3944 if (do_section_details
)
3948 case SHF_WRITE
: index
= 0; break;
3949 case SHF_ALLOC
: index
= 1; break;
3950 case SHF_EXECINSTR
: index
= 2; break;
3951 case SHF_MERGE
: index
= 3; break;
3952 case SHF_STRINGS
: index
= 4; break;
3953 case SHF_INFO_LINK
: index
= 5; break;
3954 case SHF_LINK_ORDER
: index
= 6; break;
3955 case SHF_OS_NONCONFORMING
: index
= 7; break;
3956 case SHF_GROUP
: index
= 8; break;
3957 case SHF_TLS
: index
= 9; break;
3966 if (p
!= buff
+ field_size
+ 4)
3968 if (size
< (10 + 2))
3975 size
-= flags
[index
].len
;
3976 p
= stpcpy (p
, flags
[index
].str
);
3978 else if (flag
& SHF_MASKOS
)
3980 else if (flag
& SHF_MASKPROC
)
3983 unknown_flags
|= flag
;
3989 case SHF_WRITE
: *p
= 'W'; break;
3990 case SHF_ALLOC
: *p
= 'A'; break;
3991 case SHF_EXECINSTR
: *p
= 'X'; break;
3992 case SHF_MERGE
: *p
= 'M'; break;
3993 case SHF_STRINGS
: *p
= 'S'; break;
3994 case SHF_INFO_LINK
: *p
= 'I'; break;
3995 case SHF_LINK_ORDER
: *p
= 'L'; break;
3996 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3997 case SHF_GROUP
: *p
= 'G'; break;
3998 case SHF_TLS
: *p
= 'T'; break;
4001 if (elf_header
.e_machine
== EM_X86_64
4002 && flag
== SHF_X86_64_LARGE
)
4004 else if (flag
& SHF_MASKOS
)
4007 sh_flags
&= ~ SHF_MASKOS
;
4009 else if (flag
& SHF_MASKPROC
)
4012 sh_flags
&= ~ SHF_MASKPROC
;
4022 if (do_section_details
)
4026 size
-= 5 + field_size
;
4027 if (p
!= buff
+ field_size
+ 4)
4035 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
4036 (unsigned long) os_flags
);
4037 p
+= 5 + field_size
;
4041 size
-= 7 + field_size
;
4042 if (p
!= buff
+ field_size
+ 4)
4050 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
4051 (unsigned long) proc_flags
);
4052 p
+= 7 + field_size
;
4056 size
-= 10 + field_size
;
4057 if (p
!= buff
+ field_size
+ 4)
4065 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
4066 (unsigned long) unknown_flags
);
4067 p
+= 10 + field_size
;
4076 process_section_headers (FILE *file
)
4078 Elf_Internal_Shdr
*section
;
4081 section_headers
= NULL
;
4083 if (elf_header
.e_shnum
== 0)
4086 printf (_("\nThere are no sections in this file.\n"));
4091 if (do_sections
&& !do_header
)
4092 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4093 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4097 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4100 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4103 /* Read in the string table, so that we have names to display. */
4104 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4105 && SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
4107 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
4109 if (section
->sh_size
!= 0)
4111 string_table
= get_data (NULL
, file
, section
->sh_offset
,
4112 1, section
->sh_size
, _("string table"));
4114 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4118 /* Scan the sections for the dynamic symbol table
4119 and dynamic string table and debug sections. */
4120 dynamic_symbols
= NULL
;
4121 dynamic_strings
= NULL
;
4122 dynamic_syminfo
= NULL
;
4123 symtab_shndx_hdr
= NULL
;
4125 eh_addr_size
= is_32bit_elf
? 4 : 8;
4126 switch (elf_header
.e_machine
)
4129 case EM_MIPS_RS3_LE
:
4130 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4131 FDE addresses. However, the ABI also has a semi-official ILP32
4132 variant for which the normal FDE address size rules apply.
4134 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4135 section, where XX is the size of longs in bits. Unfortunately,
4136 earlier compilers provided no way of distinguishing ILP32 objects
4137 from LP64 objects, so if there's any doubt, we should assume that
4138 the official LP64 form is being used. */
4139 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4140 && find_section (".gcc_compiled_long32") == NULL
)
4146 switch (elf_header
.e_flags
& EF_H8_MACH
)
4148 case E_H8_MACH_H8300
:
4149 case E_H8_MACH_H8300HN
:
4150 case E_H8_MACH_H8300SN
:
4151 case E_H8_MACH_H8300SXN
:
4154 case E_H8_MACH_H8300H
:
4155 case E_H8_MACH_H8300S
:
4156 case E_H8_MACH_H8300SX
:
4163 switch (elf_header
.e_flags
& EF_M32C_CPU_MASK
)
4165 case EF_M32C_CPU_M16C
:
4172 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4175 size_t expected_entsize \
4176 = is_32bit_elf ? size32 : size64; \
4177 if (section->sh_entsize != expected_entsize) \
4178 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4179 i, (unsigned long int) section->sh_entsize, \
4180 (unsigned long int) expected_entsize); \
4181 section->sh_entsize = expected_entsize; \
4184 #define CHECK_ENTSIZE(section, i, type) \
4185 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4186 sizeof (Elf64_External_##type))
4188 for (i
= 0, section
= section_headers
;
4189 i
< elf_header
.e_shnum
;
4192 char *name
= SECTION_NAME (section
);
4194 if (section
->sh_type
== SHT_DYNSYM
)
4196 if (dynamic_symbols
!= NULL
)
4198 error (_("File contains multiple dynamic symbol tables\n"));
4202 CHECK_ENTSIZE (section
, i
, Sym
);
4203 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4204 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4206 else if (section
->sh_type
== SHT_STRTAB
4207 && streq (name
, ".dynstr"))
4209 if (dynamic_strings
!= NULL
)
4211 error (_("File contains multiple dynamic string tables\n"));
4215 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
4216 1, section
->sh_size
, _("dynamic strings"));
4217 dynamic_strings_length
= section
->sh_size
;
4219 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4221 if (symtab_shndx_hdr
!= NULL
)
4223 error (_("File contains multiple symtab shndx tables\n"));
4226 symtab_shndx_hdr
= section
;
4228 else if (section
->sh_type
== SHT_SYMTAB
)
4229 CHECK_ENTSIZE (section
, i
, Sym
);
4230 else if (section
->sh_type
== SHT_GROUP
)
4231 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4232 else if (section
->sh_type
== SHT_REL
)
4233 CHECK_ENTSIZE (section
, i
, Rel
);
4234 else if (section
->sh_type
== SHT_RELA
)
4235 CHECK_ENTSIZE (section
, i
, Rela
);
4236 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4237 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
4238 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
4239 || do_debug_loc
|| do_debug_ranges
)
4240 && const_strneq (name
, ".debug_"))
4245 || (do_debug_info
&& streq (name
, "info"))
4246 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4247 || (do_debug_lines
&& streq (name
, "line"))
4248 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4249 || (do_debug_aranges
&& streq (name
, "aranges"))
4250 || (do_debug_ranges
&& streq (name
, "ranges"))
4251 || (do_debug_frames
&& streq (name
, "frame"))
4252 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4253 || (do_debug_str
&& streq (name
, "str"))
4254 || (do_debug_loc
&& streq (name
, "loc"))
4256 request_dump_bynumber (i
, DEBUG_DUMP
);
4258 /* linkonce section to be combined with .debug_info at link time. */
4259 else if ((do_debugging
|| do_debug_info
)
4260 && const_strneq (name
, ".gnu.linkonce.wi."))
4261 request_dump_bynumber (i
, DEBUG_DUMP
);
4262 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4263 request_dump_bynumber (i
, DEBUG_DUMP
);
4269 if (elf_header
.e_shnum
> 1)
4270 printf (_("\nSection Headers:\n"));
4272 printf (_("\nSection Header:\n"));
4276 if (do_section_details
)
4278 printf (_(" [Nr] Name\n"));
4279 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4283 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4287 if (do_section_details
)
4289 printf (_(" [Nr] Name\n"));
4290 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4294 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4298 if (do_section_details
)
4300 printf (_(" [Nr] Name\n"));
4301 printf (_(" Type Address Offset Link\n"));
4302 printf (_(" Size EntSize Info Align\n"));
4306 printf (_(" [Nr] Name Type Address Offset\n"));
4307 printf (_(" Size EntSize Flags Link Info Align\n"));
4311 if (do_section_details
)
4312 printf (_(" Flags\n"));
4314 for (i
= 0, section
= section_headers
;
4315 i
< elf_header
.e_shnum
;
4318 if (do_section_details
)
4320 printf (" [%2u] %s\n",
4321 SECTION_HEADER_NUM (i
),
4322 SECTION_NAME (section
));
4323 if (is_32bit_elf
|| do_wide
)
4324 printf (" %-15.15s ",
4325 get_section_type_name (section
->sh_type
));
4328 printf (" [%2u] %-17.17s %-15.15s ",
4329 SECTION_HEADER_NUM (i
),
4330 SECTION_NAME (section
),
4331 get_section_type_name (section
->sh_type
));
4335 print_vma (section
->sh_addr
, LONG_HEX
);
4337 printf ( " %6.6lx %6.6lx %2.2lx",
4338 (unsigned long) section
->sh_offset
,
4339 (unsigned long) section
->sh_size
,
4340 (unsigned long) section
->sh_entsize
);
4342 if (do_section_details
)
4343 fputs (" ", stdout
);
4345 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4347 printf ("%2ld %3lu %2ld\n",
4348 (unsigned long) section
->sh_link
,
4349 (unsigned long) section
->sh_info
,
4350 (unsigned long) section
->sh_addralign
);
4354 print_vma (section
->sh_addr
, LONG_HEX
);
4356 if ((long) section
->sh_offset
== section
->sh_offset
)
4357 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4361 print_vma (section
->sh_offset
, LONG_HEX
);
4364 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4365 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4369 print_vma (section
->sh_size
, LONG_HEX
);
4372 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4373 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4377 print_vma (section
->sh_entsize
, LONG_HEX
);
4380 if (do_section_details
)
4381 fputs (" ", stdout
);
4383 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4385 printf ("%2ld %3lu ",
4386 (unsigned long) section
->sh_link
,
4387 (unsigned long) section
->sh_info
);
4389 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4390 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4393 print_vma (section
->sh_addralign
, DEC
);
4397 else if (do_section_details
)
4399 printf (" %-15.15s ",
4400 get_section_type_name (section
->sh_type
));
4401 print_vma (section
->sh_addr
, LONG_HEX
);
4402 if ((long) section
->sh_offset
== section
->sh_offset
)
4403 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4407 print_vma (section
->sh_offset
, LONG_HEX
);
4409 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4410 print_vma (section
->sh_size
, LONG_HEX
);
4412 print_vma (section
->sh_entsize
, LONG_HEX
);
4414 printf (" %-16lu %ld\n",
4415 (unsigned long) section
->sh_info
,
4416 (unsigned long) section
->sh_addralign
);
4421 print_vma (section
->sh_addr
, LONG_HEX
);
4422 if ((long) section
->sh_offset
== section
->sh_offset
)
4423 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4427 print_vma (section
->sh_offset
, LONG_HEX
);
4430 print_vma (section
->sh_size
, LONG_HEX
);
4432 print_vma (section
->sh_entsize
, LONG_HEX
);
4434 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4436 printf (" %2ld %3lu %ld\n",
4437 (unsigned long) section
->sh_link
,
4438 (unsigned long) section
->sh_info
,
4439 (unsigned long) section
->sh_addralign
);
4442 if (do_section_details
)
4443 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4446 if (!do_section_details
)
4447 printf (_("Key to Flags:\n\
4448 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4449 I (info), L (link order), G (group), x (unknown)\n\
4450 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4456 get_group_flags (unsigned int flags
)
4458 static char buff
[32];
4465 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4472 process_section_groups (FILE *file
)
4474 Elf_Internal_Shdr
*section
;
4476 struct group
*group
;
4477 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4478 Elf_Internal_Sym
*symtab
;
4482 /* Don't process section groups unless needed. */
4483 if (!do_unwind
&& !do_section_groups
)
4486 if (elf_header
.e_shnum
== 0)
4488 if (do_section_groups
)
4489 printf (_("\nThere are no sections in this file.\n"));
4494 if (section_headers
== NULL
)
4496 error (_("Section headers are not available!\n"));
4500 section_headers_groups
= calloc (elf_header
.e_shnum
,
4501 sizeof (struct group
*));
4503 if (section_headers_groups
== NULL
)
4505 error (_("Out of memory\n"));
4509 /* Scan the sections for the group section. */
4511 for (i
= 0, section
= section_headers
;
4512 i
< elf_header
.e_shnum
;
4514 if (section
->sh_type
== SHT_GROUP
)
4517 if (group_count
== 0)
4519 if (do_section_groups
)
4520 printf (_("\nThere are no section groups in this file.\n"));
4525 section_groups
= calloc (group_count
, sizeof (struct group
));
4527 if (section_groups
== NULL
)
4529 error (_("Out of memory\n"));
4538 for (i
= 0, section
= section_headers
, group
= section_groups
;
4539 i
< elf_header
.e_shnum
;
4542 if (section
->sh_type
== SHT_GROUP
)
4544 char *name
= SECTION_NAME (section
);
4546 unsigned char *start
, *indices
;
4547 unsigned int entry
, j
, size
;
4548 Elf_Internal_Shdr
*sec
;
4549 Elf_Internal_Sym
*sym
;
4551 /* Get the symbol table. */
4552 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4553 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4556 error (_("Bad sh_link in group section `%s'\n"), name
);
4560 if (symtab_sec
!= sec
)
4565 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4568 sym
= symtab
+ section
->sh_info
;
4570 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4572 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4575 error (_("Bad sh_info in group section `%s'\n"), name
);
4579 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4588 /* Get the string table. */
4589 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4590 >= elf_header
.e_shnum
)
4599 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4604 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4605 1, strtab_sec
->sh_size
,
4607 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4609 group_name
= sym
->st_name
< strtab_size
4610 ? strtab
+ sym
->st_name
: "<corrupt>";
4613 start
= get_data (NULL
, file
, section
->sh_offset
,
4614 1, section
->sh_size
, _("section data"));
4617 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4618 entry
= byte_get (indices
, 4);
4621 if (do_section_groups
)
4623 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4624 get_group_flags (entry
), i
, name
, group_name
, size
);
4626 printf (_(" [Index] Name\n"));
4629 group
->group_index
= i
;
4631 for (j
= 0; j
< size
; j
++)
4633 struct group_list
*g
;
4635 entry
= byte_get (indices
, 4);
4638 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4640 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4641 entry
, i
, elf_header
.e_shnum
- 1);
4644 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4646 error (_("invalid section [%5u] in group section [%5u]\n"),
4651 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4656 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4658 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4663 /* Intel C/C++ compiler may put section 0 in a
4664 section group. We just warn it the first time
4665 and ignore it afterwards. */
4666 static int warned
= 0;
4669 error (_("section 0 in group section [%5u]\n"),
4670 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4676 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4679 if (do_section_groups
)
4681 sec
= SECTION_HEADER (entry
);
4682 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4685 g
= xmalloc (sizeof (struct group_list
));
4686 g
->section_index
= entry
;
4687 g
->next
= group
->root
;
4711 } dynamic_relocations
[] =
4713 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4714 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4715 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4718 /* Process the reloc section. */
4721 process_relocs (FILE *file
)
4723 unsigned long rel_size
;
4724 unsigned long rel_offset
;
4730 if (do_using_dynamic
)
4734 int has_dynamic_reloc
;
4737 has_dynamic_reloc
= 0;
4739 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4741 is_rela
= dynamic_relocations
[i
].rela
;
4742 name
= dynamic_relocations
[i
].name
;
4743 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4744 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4746 has_dynamic_reloc
|= rel_size
;
4748 if (is_rela
== UNKNOWN
)
4750 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4751 switch (dynamic_info
[DT_PLTREL
])
4765 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4766 name
, rel_offset
, rel_size
);
4768 dump_relocations (file
,
4769 offset_from_vma (file
, rel_offset
, rel_size
),
4771 dynamic_symbols
, num_dynamic_syms
,
4772 dynamic_strings
, dynamic_strings_length
, is_rela
);
4776 if (! has_dynamic_reloc
)
4777 printf (_("\nThere are no dynamic relocations in this file.\n"));
4781 Elf_Internal_Shdr
*section
;
4785 for (i
= 0, section
= section_headers
;
4786 i
< elf_header
.e_shnum
;
4789 if ( section
->sh_type
!= SHT_RELA
4790 && section
->sh_type
!= SHT_REL
)
4793 rel_offset
= section
->sh_offset
;
4794 rel_size
= section
->sh_size
;
4798 Elf_Internal_Shdr
*strsec
;
4801 printf (_("\nRelocation section "));
4803 if (string_table
== NULL
)
4804 printf ("%d", section
->sh_name
);
4806 printf (_("'%s'"), SECTION_NAME (section
));
4808 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4809 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4811 is_rela
= section
->sh_type
== SHT_RELA
;
4813 if (section
->sh_link
4814 && SECTION_HEADER_INDEX (section
->sh_link
)
4815 < elf_header
.e_shnum
)
4817 Elf_Internal_Shdr
*symsec
;
4818 Elf_Internal_Sym
*symtab
;
4819 unsigned long nsyms
;
4820 unsigned long strtablen
= 0;
4821 char *strtab
= NULL
;
4823 symsec
= SECTION_HEADER (section
->sh_link
);
4824 if (symsec
->sh_type
!= SHT_SYMTAB
4825 && symsec
->sh_type
!= SHT_DYNSYM
)
4828 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4829 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4834 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4835 < elf_header
.e_shnum
)
4837 strsec
= SECTION_HEADER (symsec
->sh_link
);
4839 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4842 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4845 dump_relocations (file
, rel_offset
, rel_size
,
4846 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4852 dump_relocations (file
, rel_offset
, rel_size
,
4853 NULL
, 0, NULL
, 0, is_rela
);
4860 printf (_("\nThere are no relocations in this file.\n"));
4866 /* Process the unwind section. */
4868 #include "unwind-ia64.h"
4870 /* An absolute address consists of a section and an offset. If the
4871 section is NULL, the offset itself is the address, otherwise, the
4872 address equals to LOAD_ADDRESS(section) + offset. */
4876 unsigned short section
;
4880 #define ABSADDR(a) \
4882 ? section_headers [(a).section].sh_addr + (a).offset \
4885 struct ia64_unw_aux_info
4887 struct ia64_unw_table_entry
4889 struct absaddr start
;
4891 struct absaddr info
;
4893 *table
; /* Unwind table. */
4894 unsigned long table_len
; /* Length of unwind table. */
4895 unsigned char *info
; /* Unwind info. */
4896 unsigned long info_size
; /* Size of unwind info. */
4897 bfd_vma info_addr
; /* starting address of unwind info. */
4898 bfd_vma seg_base
; /* Starting address of segment. */
4899 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4900 unsigned long nsyms
; /* Number of symbols. */
4901 char *strtab
; /* The string table. */
4902 unsigned long strtab_size
; /* Size of string table. */
4906 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4907 unsigned long nsyms
,
4909 unsigned long strtab_size
,
4910 struct absaddr addr
,
4911 const char **symname
,
4914 bfd_vma dist
= 0x100000;
4915 Elf_Internal_Sym
*sym
, *best
= NULL
;
4918 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4920 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4921 && sym
->st_name
!= 0
4922 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4923 && addr
.offset
>= sym
->st_value
4924 && addr
.offset
- sym
->st_value
< dist
)
4927 dist
= addr
.offset
- sym
->st_value
;
4934 *symname
= (best
->st_name
>= strtab_size
4935 ? "<corrupt>" : strtab
+ best
->st_name
);
4940 *offset
= addr
.offset
;
4944 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4946 struct ia64_unw_table_entry
*tp
;
4949 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4953 const unsigned char *dp
;
4954 const unsigned char *head
;
4955 const char *procname
;
4957 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4958 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4960 fputs ("\n<", stdout
);
4964 fputs (procname
, stdout
);
4967 printf ("+%lx", (unsigned long) offset
);
4970 fputs (">: [", stdout
);
4971 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4972 fputc ('-', stdout
);
4973 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4974 printf ("], info at +0x%lx\n",
4975 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4977 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4978 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4980 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4981 (unsigned) UNW_VER (stamp
),
4982 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4983 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4984 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4985 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4987 if (UNW_VER (stamp
) != 1)
4989 printf ("\tUnknown version.\n");
4994 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4995 dp
= unw_decode (dp
, in_body
, & in_body
);
5000 slurp_ia64_unwind_table (FILE *file
,
5001 struct ia64_unw_aux_info
*aux
,
5002 Elf_Internal_Shdr
*sec
)
5004 unsigned long size
, nrelas
, i
;
5005 Elf_Internal_Phdr
*seg
;
5006 struct ia64_unw_table_entry
*tep
;
5007 Elf_Internal_Shdr
*relsec
;
5008 Elf_Internal_Rela
*rela
, *rp
;
5009 unsigned char *table
, *tp
;
5010 Elf_Internal_Sym
*sym
;
5011 const char *relname
;
5013 /* First, find the starting address of the segment that includes
5016 if (elf_header
.e_phnum
)
5018 if (! get_program_headers (file
))
5021 for (seg
= program_headers
;
5022 seg
< program_headers
+ elf_header
.e_phnum
;
5025 if (seg
->p_type
!= PT_LOAD
)
5028 if (sec
->sh_addr
>= seg
->p_vaddr
5029 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5031 aux
->seg_base
= seg
->p_vaddr
;
5037 /* Second, build the unwind table from the contents of the unwind section: */
5038 size
= sec
->sh_size
;
5039 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5043 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
5045 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
5047 tep
->start
.section
= SHN_UNDEF
;
5048 tep
->end
.section
= SHN_UNDEF
;
5049 tep
->info
.section
= SHN_UNDEF
;
5052 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5053 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5054 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
5058 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
5059 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
5060 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
5062 tep
->start
.offset
+= aux
->seg_base
;
5063 tep
->end
.offset
+= aux
->seg_base
;
5064 tep
->info
.offset
+= aux
->seg_base
;
5068 /* Third, apply any relocations to the unwind table: */
5069 for (relsec
= section_headers
;
5070 relsec
< section_headers
+ elf_header
.e_shnum
;
5073 if (relsec
->sh_type
!= SHT_RELA
5074 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5075 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5078 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5082 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5084 relname
= elf_ia64_reloc_type (get_reloc_type (rp
->r_info
));
5085 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5087 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5089 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5093 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5095 switch (rp
->r_offset
/eh_addr_size
% 3)
5098 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5099 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5102 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5103 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5106 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5107 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5117 aux
->table_len
= size
/ (3 * eh_addr_size
);
5122 ia64_process_unwind (FILE *file
)
5124 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
5125 unsigned long i
, unwcount
= 0, unwstart
= 0;
5126 struct ia64_unw_aux_info aux
;
5128 memset (& aux
, 0, sizeof (aux
));
5130 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5132 if (sec
->sh_type
== SHT_SYMTAB
5133 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5135 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5136 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5138 strsec
= SECTION_HEADER (sec
->sh_link
);
5139 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5140 1, strsec
->sh_size
, _("string table"));
5141 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5143 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5148 printf (_("\nThere are no unwind sections in this file.\n"));
5150 while (unwcount
-- > 0)
5155 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5156 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5157 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5164 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5166 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5168 /* We need to find which section group it is in. */
5169 struct group_list
*g
= section_headers_groups
[i
]->root
;
5171 for (; g
!= NULL
; g
= g
->next
)
5173 sec
= SECTION_HEADER (g
->section_index
);
5175 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5180 i
= elf_header
.e_shnum
;
5182 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5184 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5185 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5186 suffix
= SECTION_NAME (unwsec
) + len
;
5187 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5189 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5190 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5195 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5196 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5197 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5198 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5200 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5201 suffix
= SECTION_NAME (unwsec
) + len
;
5202 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5204 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5205 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5209 if (i
== elf_header
.e_shnum
)
5211 printf (_("\nCould not find unwind info section for "));
5213 if (string_table
== NULL
)
5214 printf ("%d", unwsec
->sh_name
);
5216 printf (_("'%s'"), SECTION_NAME (unwsec
));
5220 aux
.info_size
= sec
->sh_size
;
5221 aux
.info_addr
= sec
->sh_addr
;
5222 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
5225 printf (_("\nUnwind section "));
5227 if (string_table
== NULL
)
5228 printf ("%d", unwsec
->sh_name
);
5230 printf (_("'%s'"), SECTION_NAME (unwsec
));
5232 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5233 (unsigned long) unwsec
->sh_offset
,
5234 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5236 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5238 if (aux
.table_len
> 0)
5239 dump_ia64_unwind (& aux
);
5242 free ((char *) aux
.table
);
5244 free ((char *) aux
.info
);
5253 free ((char *) aux
.strtab
);
5258 struct hppa_unw_aux_info
5260 struct hppa_unw_table_entry
5262 struct absaddr start
;
5264 unsigned int Cannot_unwind
:1; /* 0 */
5265 unsigned int Millicode
:1; /* 1 */
5266 unsigned int Millicode_save_sr0
:1; /* 2 */
5267 unsigned int Region_description
:2; /* 3..4 */
5268 unsigned int reserved1
:1; /* 5 */
5269 unsigned int Entry_SR
:1; /* 6 */
5270 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5271 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5272 unsigned int Args_stored
:1; /* 16 */
5273 unsigned int Variable_Frame
:1; /* 17 */
5274 unsigned int Separate_Package_Body
:1; /* 18 */
5275 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5276 unsigned int Stack_Overflow_Check
:1; /* 20 */
5277 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5278 unsigned int Ada_Region
:1; /* 22 */
5279 unsigned int cxx_info
:1; /* 23 */
5280 unsigned int cxx_try_catch
:1; /* 24 */
5281 unsigned int sched_entry_seq
:1; /* 25 */
5282 unsigned int reserved2
:1; /* 26 */
5283 unsigned int Save_SP
:1; /* 27 */
5284 unsigned int Save_RP
:1; /* 28 */
5285 unsigned int Save_MRP_in_frame
:1; /* 29 */
5286 unsigned int extn_ptr_defined
:1; /* 30 */
5287 unsigned int Cleanup_defined
:1; /* 31 */
5289 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5290 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5291 unsigned int Large_frame
:1; /* 2 */
5292 unsigned int Pseudo_SP_Set
:1; /* 3 */
5293 unsigned int reserved4
:1; /* 4 */
5294 unsigned int Total_frame_size
:27; /* 5..31 */
5296 *table
; /* Unwind table. */
5297 unsigned long table_len
; /* Length of unwind table. */
5298 bfd_vma seg_base
; /* Starting address of segment. */
5299 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5300 unsigned long nsyms
; /* Number of symbols. */
5301 char *strtab
; /* The string table. */
5302 unsigned long strtab_size
; /* Size of string table. */
5306 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5308 struct hppa_unw_table_entry
*tp
;
5310 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5313 const char *procname
;
5315 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5316 aux
->strtab_size
, tp
->start
, &procname
,
5319 fputs ("\n<", stdout
);
5323 fputs (procname
, stdout
);
5326 printf ("+%lx", (unsigned long) offset
);
5329 fputs (">: [", stdout
);
5330 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5331 fputc ('-', stdout
);
5332 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5335 #define PF(_m) if (tp->_m) printf (#_m " ");
5336 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5339 PF(Millicode_save_sr0
);
5340 /* PV(Region_description); */
5346 PF(Separate_Package_Body
);
5347 PF(Frame_Extension_Millicode
);
5348 PF(Stack_Overflow_Check
);
5349 PF(Two_Instruction_SP_Increment
);
5353 PF(sched_entry_seq
);
5356 PF(Save_MRP_in_frame
);
5357 PF(extn_ptr_defined
);
5358 PF(Cleanup_defined
);
5359 PF(MPE_XL_interrupt_marker
);
5360 PF(HP_UX_interrupt_marker
);
5363 PV(Total_frame_size
);
5372 slurp_hppa_unwind_table (FILE *file
,
5373 struct hppa_unw_aux_info
*aux
,
5374 Elf_Internal_Shdr
*sec
)
5376 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5377 Elf_Internal_Phdr
*seg
;
5378 struct hppa_unw_table_entry
*tep
;
5379 Elf_Internal_Shdr
*relsec
;
5380 Elf_Internal_Rela
*rela
, *rp
;
5381 unsigned char *table
, *tp
;
5382 Elf_Internal_Sym
*sym
;
5383 const char *relname
;
5385 /* First, find the starting address of the segment that includes
5388 if (elf_header
.e_phnum
)
5390 if (! get_program_headers (file
))
5393 for (seg
= program_headers
;
5394 seg
< program_headers
+ elf_header
.e_phnum
;
5397 if (seg
->p_type
!= PT_LOAD
)
5400 if (sec
->sh_addr
>= seg
->p_vaddr
5401 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5403 aux
->seg_base
= seg
->p_vaddr
;
5409 /* Second, build the unwind table from the contents of the unwind
5411 size
= sec
->sh_size
;
5412 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5417 nentries
= size
/ unw_ent_size
;
5418 size
= unw_ent_size
* nentries
;
5420 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5422 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5424 unsigned int tmp1
, tmp2
;
5426 tep
->start
.section
= SHN_UNDEF
;
5427 tep
->end
.section
= SHN_UNDEF
;
5429 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5430 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5431 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5432 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5434 tep
->start
.offset
+= aux
->seg_base
;
5435 tep
->end
.offset
+= aux
->seg_base
;
5437 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5438 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5439 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5440 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5441 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5442 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5443 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5444 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5445 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5446 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5447 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5448 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5449 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5450 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5451 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5452 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5453 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5454 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5455 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5456 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5457 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5458 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5459 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5460 tep
->Cleanup_defined
= tmp1
& 0x1;
5462 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5463 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5464 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5465 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5466 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5467 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5471 /* Third, apply any relocations to the unwind table. */
5472 for (relsec
= section_headers
;
5473 relsec
< section_headers
+ elf_header
.e_shnum
;
5476 if (relsec
->sh_type
!= SHT_RELA
5477 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5478 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5481 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5485 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5487 relname
= elf_hppa_reloc_type (get_reloc_type (rp
->r_info
));
5488 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5490 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5491 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5493 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5497 i
= rp
->r_offset
/ unw_ent_size
;
5499 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5502 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5503 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5506 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5507 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5517 aux
->table_len
= nentries
;
5523 hppa_process_unwind (FILE *file
)
5525 struct hppa_unw_aux_info aux
;
5526 Elf_Internal_Shdr
*unwsec
= NULL
;
5527 Elf_Internal_Shdr
*strsec
;
5528 Elf_Internal_Shdr
*sec
;
5531 memset (& aux
, 0, sizeof (aux
));
5533 if (string_table
== NULL
)
5536 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5538 if (sec
->sh_type
== SHT_SYMTAB
5539 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5541 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5542 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5544 strsec
= SECTION_HEADER (sec
->sh_link
);
5545 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5546 1, strsec
->sh_size
, _("string table"));
5547 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5549 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5554 printf (_("\nThere are no unwind sections in this file.\n"));
5556 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5558 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5560 printf (_("\nUnwind section "));
5561 printf (_("'%s'"), SECTION_NAME (sec
));
5563 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5564 (unsigned long) sec
->sh_offset
,
5565 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5567 slurp_hppa_unwind_table (file
, &aux
, sec
);
5568 if (aux
.table_len
> 0)
5569 dump_hppa_unwind (&aux
);
5572 free ((char *) aux
.table
);
5580 free ((char *) aux
.strtab
);
5586 process_unwind (FILE *file
)
5588 struct unwind_handler
{
5590 int (*handler
)(FILE *file
);
5592 { EM_IA_64
, ia64_process_unwind
},
5593 { EM_PARISC
, hppa_process_unwind
},
5601 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5602 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5603 return handlers
[i
].handler (file
);
5605 printf (_("\nThere are no unwind sections in this file.\n"));
5610 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5612 switch (entry
->d_tag
)
5615 if (entry
->d_un
.d_val
== 0)
5619 static const char * opts
[] =
5621 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5622 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5623 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5624 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5629 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
5630 if (entry
->d_un
.d_val
& (1 << cnt
))
5632 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5639 case DT_MIPS_IVERSION
:
5640 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5641 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5643 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5646 case DT_MIPS_TIME_STAMP
:
5651 time_t time
= entry
->d_un
.d_val
;
5652 tmp
= gmtime (&time
);
5653 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5654 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5655 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5656 printf ("Time Stamp: %s\n", timebuf
);
5660 case DT_MIPS_RLD_VERSION
:
5661 case DT_MIPS_LOCAL_GOTNO
:
5662 case DT_MIPS_CONFLICTNO
:
5663 case DT_MIPS_LIBLISTNO
:
5664 case DT_MIPS_SYMTABNO
:
5665 case DT_MIPS_UNREFEXTNO
:
5666 case DT_MIPS_HIPAGENO
:
5667 case DT_MIPS_DELTA_CLASS_NO
:
5668 case DT_MIPS_DELTA_INSTANCE_NO
:
5669 case DT_MIPS_DELTA_RELOC_NO
:
5670 case DT_MIPS_DELTA_SYM_NO
:
5671 case DT_MIPS_DELTA_CLASSSYM_NO
:
5672 case DT_MIPS_COMPACT_SIZE
:
5673 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5677 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5683 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5685 switch (entry
->d_tag
)
5687 case DT_HP_DLD_FLAGS
:
5696 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5697 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5698 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5699 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5700 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5701 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5702 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5703 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5704 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5705 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5706 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5707 { DT_HP_GST
, "HP_GST" },
5708 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5709 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5710 { DT_HP_NODELETE
, "HP_NODELETE" },
5711 { DT_HP_GROUP
, "HP_GROUP" },
5712 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5716 bfd_vma val
= entry
->d_un
.d_val
;
5718 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
5719 if (val
& flags
[cnt
].bit
)
5723 fputs (flags
[cnt
].str
, stdout
);
5725 val
^= flags
[cnt
].bit
;
5728 if (val
!= 0 || first
)
5732 print_vma (val
, HEX
);
5738 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5745 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5747 switch (entry
->d_tag
)
5749 case DT_IA_64_PLT_RESERVE
:
5750 /* First 3 slots reserved. */
5751 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5753 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5757 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5764 get_32bit_dynamic_section (FILE *file
)
5766 Elf32_External_Dyn
*edyn
, *ext
;
5767 Elf_Internal_Dyn
*entry
;
5769 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5770 _("dynamic section"));
5774 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5775 might not have the luxury of section headers. Look for the DT_NULL
5776 terminator to determine the number of entries. */
5777 for (ext
= edyn
, dynamic_nent
= 0;
5778 (char *) ext
< (char *) edyn
+ dynamic_size
;
5782 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5786 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5787 if (dynamic_section
== NULL
)
5789 error (_("Out of memory\n"));
5794 for (ext
= edyn
, entry
= dynamic_section
;
5795 entry
< dynamic_section
+ dynamic_nent
;
5798 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5799 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5808 get_64bit_dynamic_section (FILE *file
)
5810 Elf64_External_Dyn
*edyn
, *ext
;
5811 Elf_Internal_Dyn
*entry
;
5813 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5814 _("dynamic section"));
5818 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5819 might not have the luxury of section headers. Look for the DT_NULL
5820 terminator to determine the number of entries. */
5821 for (ext
= edyn
, dynamic_nent
= 0;
5822 (char *) ext
< (char *) edyn
+ dynamic_size
;
5826 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5830 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5831 if (dynamic_section
== NULL
)
5833 error (_("Out of memory\n"));
5838 for (ext
= edyn
, entry
= dynamic_section
;
5839 entry
< dynamic_section
+ dynamic_nent
;
5842 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5843 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5852 print_dynamic_flags (bfd_vma flags
)
5860 flag
= flags
& - flags
;
5870 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5871 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5872 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5873 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5874 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5875 default: fputs ("unknown", stdout
); break;
5881 /* Parse and display the contents of the dynamic section. */
5884 process_dynamic_section (FILE *file
)
5886 Elf_Internal_Dyn
*entry
;
5888 if (dynamic_size
== 0)
5891 printf (_("\nThere is no dynamic section in this file.\n"));
5898 if (! get_32bit_dynamic_section (file
))
5901 else if (! get_64bit_dynamic_section (file
))
5904 /* Find the appropriate symbol table. */
5905 if (dynamic_symbols
== NULL
)
5907 for (entry
= dynamic_section
;
5908 entry
< dynamic_section
+ dynamic_nent
;
5911 Elf_Internal_Shdr section
;
5913 if (entry
->d_tag
!= DT_SYMTAB
)
5916 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5918 /* Since we do not know how big the symbol table is,
5919 we default to reading in the entire file (!) and
5920 processing that. This is overkill, I know, but it
5922 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5924 if (archive_file_offset
!= 0)
5925 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5928 if (fseek (file
, 0, SEEK_END
))
5929 error (_("Unable to seek to end of file!\n"));
5931 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5935 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5937 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5939 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5940 if (num_dynamic_syms
< 1)
5942 error (_("Unable to determine the number of symbols to load\n"));
5946 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5950 /* Similarly find a string table. */
5951 if (dynamic_strings
== NULL
)
5953 for (entry
= dynamic_section
;
5954 entry
< dynamic_section
+ dynamic_nent
;
5957 unsigned long offset
;
5960 if (entry
->d_tag
!= DT_STRTAB
)
5963 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5965 /* Since we do not know how big the string table is,
5966 we default to reading in the entire file (!) and
5967 processing that. This is overkill, I know, but it
5970 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5972 if (archive_file_offset
!= 0)
5973 str_tab_len
= archive_file_size
- offset
;
5976 if (fseek (file
, 0, SEEK_END
))
5977 error (_("Unable to seek to end of file\n"));
5978 str_tab_len
= ftell (file
) - offset
;
5981 if (str_tab_len
< 1)
5984 (_("Unable to determine the length of the dynamic string table\n"));
5988 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5989 _("dynamic string table"));
5990 dynamic_strings_length
= str_tab_len
;
5995 /* And find the syminfo section if available. */
5996 if (dynamic_syminfo
== NULL
)
5998 unsigned long syminsz
= 0;
6000 for (entry
= dynamic_section
;
6001 entry
< dynamic_section
+ dynamic_nent
;
6004 if (entry
->d_tag
== DT_SYMINENT
)
6006 /* Note: these braces are necessary to avoid a syntax
6007 error from the SunOS4 C compiler. */
6008 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
6010 else if (entry
->d_tag
== DT_SYMINSZ
)
6011 syminsz
= entry
->d_un
.d_val
;
6012 else if (entry
->d_tag
== DT_SYMINFO
)
6013 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
6017 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
6019 Elf_External_Syminfo
*extsyminfo
, *extsym
;
6020 Elf_Internal_Syminfo
*syminfo
;
6022 /* There is a syminfo section. Read the data. */
6023 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
6024 syminsz
, _("symbol information"));
6028 dynamic_syminfo
= malloc (syminsz
);
6029 if (dynamic_syminfo
== NULL
)
6031 error (_("Out of memory\n"));
6035 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
6036 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
6037 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
6038 ++syminfo
, ++extsym
)
6040 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
6041 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
6048 if (do_dynamic
&& dynamic_addr
)
6049 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
6050 dynamic_addr
, dynamic_nent
);
6052 printf (_(" Tag Type Name/Value\n"));
6054 for (entry
= dynamic_section
;
6055 entry
< dynamic_section
+ dynamic_nent
;
6063 print_vma (entry
->d_tag
, FULL_HEX
);
6064 dtype
= get_dynamic_type (entry
->d_tag
);
6065 printf (" (%s)%*s", dtype
,
6066 ((is_32bit_elf
? 27 : 19)
6067 - (int) strlen (dtype
)),
6071 switch (entry
->d_tag
)
6075 print_dynamic_flags (entry
->d_un
.d_val
);
6085 switch (entry
->d_tag
)
6088 printf (_("Auxiliary library"));
6092 printf (_("Filter library"));
6096 printf (_("Configuration file"));
6100 printf (_("Dependency audit library"));
6104 printf (_("Audit library"));
6108 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6109 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6113 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6122 printf (_("Flags:"));
6124 if (entry
->d_un
.d_val
== 0)
6125 printf (_(" None\n"));
6128 unsigned long int val
= entry
->d_un
.d_val
;
6130 if (val
& DTF_1_PARINIT
)
6132 printf (" PARINIT");
6133 val
^= DTF_1_PARINIT
;
6135 if (val
& DTF_1_CONFEXP
)
6137 printf (" CONFEXP");
6138 val
^= DTF_1_CONFEXP
;
6141 printf (" %lx", val
);
6150 printf (_("Flags:"));
6152 if (entry
->d_un
.d_val
== 0)
6153 printf (_(" None\n"));
6156 unsigned long int val
= entry
->d_un
.d_val
;
6158 if (val
& DF_P1_LAZYLOAD
)
6160 printf (" LAZYLOAD");
6161 val
^= DF_P1_LAZYLOAD
;
6163 if (val
& DF_P1_GROUPPERM
)
6165 printf (" GROUPPERM");
6166 val
^= DF_P1_GROUPPERM
;
6169 printf (" %lx", val
);
6178 printf (_("Flags:"));
6179 if (entry
->d_un
.d_val
== 0)
6180 printf (_(" None\n"));
6183 unsigned long int val
= entry
->d_un
.d_val
;
6190 if (val
& DF_1_GLOBAL
)
6195 if (val
& DF_1_GROUP
)
6200 if (val
& DF_1_NODELETE
)
6202 printf (" NODELETE");
6203 val
^= DF_1_NODELETE
;
6205 if (val
& DF_1_LOADFLTR
)
6207 printf (" LOADFLTR");
6208 val
^= DF_1_LOADFLTR
;
6210 if (val
& DF_1_INITFIRST
)
6212 printf (" INITFIRST");
6213 val
^= DF_1_INITFIRST
;
6215 if (val
& DF_1_NOOPEN
)
6220 if (val
& DF_1_ORIGIN
)
6225 if (val
& DF_1_DIRECT
)
6230 if (val
& DF_1_TRANS
)
6235 if (val
& DF_1_INTERPOSE
)
6237 printf (" INTERPOSE");
6238 val
^= DF_1_INTERPOSE
;
6240 if (val
& DF_1_NODEFLIB
)
6242 printf (" NODEFLIB");
6243 val
^= DF_1_NODEFLIB
;
6245 if (val
& DF_1_NODUMP
)
6250 if (val
& DF_1_CONLFAT
)
6252 printf (" CONLFAT");
6253 val
^= DF_1_CONLFAT
;
6256 printf (" %lx", val
);
6263 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6265 puts (get_dynamic_type (entry
->d_un
.d_val
));
6285 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6291 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6292 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6298 switch (entry
->d_tag
)
6301 printf (_("Shared library: [%s]"), name
);
6303 if (streq (name
, program_interpreter
))
6304 printf (_(" program interpreter"));
6308 printf (_("Library soname: [%s]"), name
);
6312 printf (_("Library rpath: [%s]"), name
);
6316 printf (_("Library runpath: [%s]"), name
);
6320 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6325 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6338 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6342 case DT_INIT_ARRAYSZ
:
6343 case DT_FINI_ARRAYSZ
:
6344 case DT_GNU_CONFLICTSZ
:
6345 case DT_GNU_LIBLISTSZ
:
6348 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6349 printf (" (bytes)\n");
6359 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6372 if (entry
->d_tag
== DT_USED
6373 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6375 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6379 printf (_("Not needed object: [%s]\n"), name
);
6384 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6390 /* The value of this entry is ignored. */
6395 case DT_GNU_PRELINKED
:
6399 time_t time
= entry
->d_un
.d_val
;
6401 tmp
= gmtime (&time
);
6402 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6403 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6404 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6410 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6413 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6419 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6420 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6425 switch (elf_header
.e_machine
)
6428 case EM_MIPS_RS3_LE
:
6429 dynamic_section_mips_val (entry
);
6432 dynamic_section_parisc_val (entry
);
6435 dynamic_section_ia64_val (entry
);
6438 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6450 get_ver_flags (unsigned int flags
)
6452 static char buff
[32];
6459 if (flags
& VER_FLG_BASE
)
6460 strcat (buff
, "BASE ");
6462 if (flags
& VER_FLG_WEAK
)
6464 if (flags
& VER_FLG_BASE
)
6465 strcat (buff
, "| ");
6467 strcat (buff
, "WEAK ");
6470 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6471 strcat (buff
, "| <unknown>");
6476 /* Display the contents of the version sections. */
6478 process_version_sections (FILE *file
)
6480 Elf_Internal_Shdr
*section
;
6487 for (i
= 0, section
= section_headers
;
6488 i
< elf_header
.e_shnum
;
6491 switch (section
->sh_type
)
6493 case SHT_GNU_verdef
:
6495 Elf_External_Verdef
*edefs
;
6503 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6504 SECTION_NAME (section
), section
->sh_info
);
6506 printf (_(" Addr: 0x"));
6507 printf_vma (section
->sh_addr
);
6508 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6509 (unsigned long) section
->sh_offset
, section
->sh_link
,
6510 SECTION_HEADER_INDEX (section
->sh_link
)
6511 < elf_header
.e_shnum
6512 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6515 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6517 _("version definition section"));
6518 endbuf
= (char *) edefs
+ section
->sh_size
;
6522 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6525 Elf_External_Verdef
*edef
;
6526 Elf_Internal_Verdef ent
;
6527 Elf_External_Verdaux
*eaux
;
6528 Elf_Internal_Verdaux aux
;
6532 vstart
= ((char *) edefs
) + idx
;
6533 if (vstart
+ sizeof (*edef
) > endbuf
)
6536 edef
= (Elf_External_Verdef
*) vstart
;
6538 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6539 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6540 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6541 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6542 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6543 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6544 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6546 printf (_(" %#06x: Rev: %d Flags: %s"),
6547 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6549 printf (_(" Index: %d Cnt: %d "),
6550 ent
.vd_ndx
, ent
.vd_cnt
);
6552 vstart
+= ent
.vd_aux
;
6554 eaux
= (Elf_External_Verdaux
*) vstart
;
6556 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6557 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6559 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6560 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6562 printf (_("Name index: %ld\n"), aux
.vda_name
);
6564 isum
= idx
+ ent
.vd_aux
;
6566 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6568 isum
+= aux
.vda_next
;
6569 vstart
+= aux
.vda_next
;
6571 eaux
= (Elf_External_Verdaux
*) vstart
;
6572 if (vstart
+ sizeof (*eaux
) > endbuf
)
6575 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6576 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6578 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6579 printf (_(" %#06x: Parent %d: %s\n"),
6580 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6582 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6583 isum
, j
, aux
.vda_name
);
6586 printf (_(" Version def aux past end of section\n"));
6590 if (cnt
< section
->sh_info
)
6591 printf (_(" Version definition past end of section\n"));
6597 case SHT_GNU_verneed
:
6599 Elf_External_Verneed
*eneed
;
6606 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6607 SECTION_NAME (section
), section
->sh_info
);
6609 printf (_(" Addr: 0x"));
6610 printf_vma (section
->sh_addr
);
6611 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6612 (unsigned long) section
->sh_offset
, section
->sh_link
,
6613 SECTION_HEADER_INDEX (section
->sh_link
)
6614 < elf_header
.e_shnum
6615 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6618 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6620 _("version need section"));
6621 endbuf
= (char *) eneed
+ section
->sh_size
;
6625 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6627 Elf_External_Verneed
*entry
;
6628 Elf_Internal_Verneed ent
;
6633 vstart
= ((char *) eneed
) + idx
;
6634 if (vstart
+ sizeof (*entry
) > endbuf
)
6637 entry
= (Elf_External_Verneed
*) vstart
;
6639 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6640 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6641 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6642 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6643 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6645 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6647 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6648 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6650 printf (_(" File: %lx"), ent
.vn_file
);
6652 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6654 vstart
+= ent
.vn_aux
;
6656 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6658 Elf_External_Vernaux
*eaux
;
6659 Elf_Internal_Vernaux aux
;
6661 if (vstart
+ sizeof (*eaux
) > endbuf
)
6663 eaux
= (Elf_External_Vernaux
*) vstart
;
6665 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6666 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6667 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6668 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6669 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6671 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6672 printf (_(" %#06x: Name: %s"),
6673 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6675 printf (_(" %#06x: Name index: %lx"),
6676 isum
, aux
.vna_name
);
6678 printf (_(" Flags: %s Version: %d\n"),
6679 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6681 isum
+= aux
.vna_next
;
6682 vstart
+= aux
.vna_next
;
6685 printf (_(" Version need aux past end of section\n"));
6689 if (cnt
< section
->sh_info
)
6690 printf (_(" Version need past end of section\n"));
6696 case SHT_GNU_versym
:
6698 Elf_Internal_Shdr
*link_section
;
6701 unsigned char *edata
;
6702 unsigned short *data
;
6704 Elf_Internal_Sym
*symbols
;
6705 Elf_Internal_Shdr
*string_sec
;
6708 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6711 link_section
= SECTION_HEADER (section
->sh_link
);
6712 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6714 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6715 >= elf_header
.e_shnum
)
6720 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6722 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6724 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6725 string_sec
->sh_size
, _("version string table"));
6729 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6730 SECTION_NAME (section
), total
);
6732 printf (_(" Addr: "));
6733 printf_vma (section
->sh_addr
);
6734 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6735 (unsigned long) section
->sh_offset
, section
->sh_link
,
6736 SECTION_NAME (link_section
));
6738 off
= offset_from_vma (file
,
6739 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6740 total
* sizeof (short));
6741 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6742 _("version symbol data"));
6749 data
= cmalloc (total
, sizeof (short));
6751 for (cnt
= total
; cnt
--;)
6752 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6757 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6760 int check_def
, check_need
;
6763 printf (" %03x:", cnt
);
6765 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6766 switch (data
[cnt
+ j
])
6769 fputs (_(" 0 (*local*) "), stdout
);
6773 fputs (_(" 1 (*global*) "), stdout
);
6777 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6778 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6782 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6783 >= elf_header
.e_shnum
6784 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6787 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6794 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6796 Elf_Internal_Verneed ivn
;
6797 unsigned long offset
;
6799 offset
= offset_from_vma
6800 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6801 sizeof (Elf_External_Verneed
));
6805 Elf_Internal_Vernaux ivna
;
6806 Elf_External_Verneed evn
;
6807 Elf_External_Vernaux evna
;
6808 unsigned long a_off
;
6810 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6813 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6814 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6816 a_off
= offset
+ ivn
.vn_aux
;
6820 get_data (&evna
, file
, a_off
, sizeof (evna
),
6821 1, _("version need aux (2)"));
6823 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6824 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6826 a_off
+= ivna
.vna_next
;
6828 while (ivna
.vna_other
!= data
[cnt
+ j
]
6829 && ivna
.vna_next
!= 0);
6831 if (ivna
.vna_other
== data
[cnt
+ j
])
6833 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6835 if (ivna
.vna_name
>= string_sec
->sh_size
)
6836 name
= _("*invalid*");
6838 name
= strtab
+ ivna
.vna_name
;
6839 nn
+= printf ("(%s%-*s",
6841 12 - (int) strlen (name
),
6847 offset
+= ivn
.vn_next
;
6849 while (ivn
.vn_next
);
6852 if (check_def
&& data
[cnt
+ j
] != 0x8001
6853 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6855 Elf_Internal_Verdef ivd
;
6856 Elf_External_Verdef evd
;
6857 unsigned long offset
;
6859 offset
= offset_from_vma
6860 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6865 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6868 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6869 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6871 offset
+= ivd
.vd_next
;
6873 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6874 && ivd
.vd_next
!= 0);
6876 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6878 Elf_External_Verdaux evda
;
6879 Elf_Internal_Verdaux ivda
;
6881 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6883 get_data (&evda
, file
,
6884 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6886 _("version def aux"));
6888 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6890 if (ivda
.vda_name
>= string_sec
->sh_size
)
6891 name
= _("*invalid*");
6893 name
= strtab
+ ivda
.vda_name
;
6894 nn
+= printf ("(%s%-*s",
6896 12 - (int) strlen (name
),
6902 printf ("%*c", 18 - nn
, ' ');
6920 printf (_("\nNo version information found in this file.\n"));
6926 get_symbol_binding (unsigned int binding
)
6928 static char buff
[32];
6932 case STB_LOCAL
: return "LOCAL";
6933 case STB_GLOBAL
: return "GLOBAL";
6934 case STB_WEAK
: return "WEAK";
6936 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6937 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6939 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6940 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6942 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6948 get_symbol_type (unsigned int type
)
6950 static char buff
[32];
6954 case STT_NOTYPE
: return "NOTYPE";
6955 case STT_OBJECT
: return "OBJECT";
6956 case STT_FUNC
: return "FUNC";
6957 case STT_SECTION
: return "SECTION";
6958 case STT_FILE
: return "FILE";
6959 case STT_COMMON
: return "COMMON";
6960 case STT_TLS
: return "TLS";
6961 case STT_RELC
: return "RELC";
6962 case STT_SRELC
: return "SRELC";
6964 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6966 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6967 return "THUMB_FUNC";
6969 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6972 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6973 return "PARISC_MILLI";
6975 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6977 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6979 if (elf_header
.e_machine
== EM_PARISC
)
6981 if (type
== STT_HP_OPAQUE
)
6983 if (type
== STT_HP_STUB
)
6987 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6990 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6996 get_symbol_visibility (unsigned int visibility
)
7000 case STV_DEFAULT
: return "DEFAULT";
7001 case STV_INTERNAL
: return "INTERNAL";
7002 case STV_HIDDEN
: return "HIDDEN";
7003 case STV_PROTECTED
: return "PROTECTED";
7009 get_mips_symbol_other (unsigned int other
)
7013 case STO_OPTIONAL
: return "OPTIONAL";
7014 case STO_MIPS16
: return "MIPS16";
7015 default: return NULL
;
7020 get_symbol_other (unsigned int other
)
7022 const char * result
= NULL
;
7023 static char buff
[32];
7028 switch (elf_header
.e_machine
)
7031 result
= get_mips_symbol_other (other
);
7039 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
7044 get_symbol_index_type (unsigned int type
)
7046 static char buff
[32];
7050 case SHN_UNDEF
: return "UND";
7051 case SHN_ABS
: return "ABS";
7052 case SHN_COMMON
: return "COM";
7054 if (type
== SHN_IA_64_ANSI_COMMON
7055 && elf_header
.e_machine
== EM_IA_64
7056 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
7058 else if (elf_header
.e_machine
== EM_X86_64
7059 && type
== SHN_X86_64_LCOMMON
)
7061 else if (type
== SHN_MIPS_SCOMMON
7062 && elf_header
.e_machine
== EM_MIPS
)
7064 else if (type
== SHN_MIPS_SUNDEFINED
7065 && elf_header
.e_machine
== EM_MIPS
)
7067 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
7068 sprintf (buff
, "PRC[0x%04x]", type
);
7069 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
7070 sprintf (buff
, "OS [0x%04x]", type
);
7071 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
7072 sprintf (buff
, "RSV[0x%04x]", type
);
7074 sprintf (buff
, "%3d", type
);
7082 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
7084 unsigned char *e_data
;
7087 e_data
= cmalloc (number
, ent_size
);
7091 error (_("Out of memory\n"));
7095 if (fread (e_data
, ent_size
, number
, file
) != number
)
7097 error (_("Unable to read in dynamic data\n"));
7101 i_data
= cmalloc (number
, sizeof (*i_data
));
7105 error (_("Out of memory\n"));
7111 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7119 print_dynamic_symbol (bfd_vma si
, unsigned long hn
)
7121 Elf_Internal_Sym
*psym
;
7124 psym
= dynamic_symbols
+ si
;
7126 n
= print_vma (si
, DEC_5
);
7128 fputs (" " + n
, stdout
);
7129 printf (" %3lu: ", hn
);
7130 print_vma (psym
->st_value
, LONG_HEX
);
7132 print_vma (psym
->st_size
, DEC_5
);
7134 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7135 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7136 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7137 /* Check to see if any other bits in the st_other field are set.
7138 Note - displaying this information disrupts the layout of the
7139 table being generated, but for the moment this case is very
7141 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7142 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7143 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7144 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7145 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7147 printf (" <corrupt: %14ld>", psym
->st_name
);
7151 /* Dump the symbol table. */
7153 process_symbol_table (FILE *file
)
7155 Elf_Internal_Shdr
*section
;
7156 bfd_vma nbuckets
= 0;
7157 bfd_vma nchains
= 0;
7158 bfd_vma
*buckets
= NULL
;
7159 bfd_vma
*chains
= NULL
;
7160 bfd_vma ngnubuckets
= 0;
7161 bfd_vma
*gnubuckets
= NULL
;
7162 bfd_vma
*gnuchains
= NULL
;
7163 bfd_vma gnusymidx
= 0;
7165 if (! do_syms
&& !do_histogram
)
7168 if (dynamic_info
[DT_HASH
]
7170 || (do_using_dynamic
&& dynamic_strings
!= NULL
)))
7172 unsigned char nb
[8];
7173 unsigned char nc
[8];
7174 int hash_ent_size
= 4;
7176 if ((elf_header
.e_machine
== EM_ALPHA
7177 || elf_header
.e_machine
== EM_S390
7178 || elf_header
.e_machine
== EM_S390_OLD
)
7179 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7183 (archive_file_offset
7184 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7185 sizeof nb
+ sizeof nc
)),
7188 error (_("Unable to seek to start of dynamic information\n"));
7192 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7194 error (_("Failed to read in number of buckets\n"));
7198 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7200 error (_("Failed to read in number of chains\n"));
7204 nbuckets
= byte_get (nb
, hash_ent_size
);
7205 nchains
= byte_get (nc
, hash_ent_size
);
7207 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7208 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7210 if (buckets
== NULL
|| chains
== NULL
)
7214 if (dynamic_info_DT_GNU_HASH
7216 || (do_using_dynamic
&& dynamic_strings
!= NULL
)))
7218 unsigned char nb
[16];
7219 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
7220 bfd_vma buckets_vma
;
7223 (archive_file_offset
7224 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7228 error (_("Unable to seek to start of dynamic information\n"));
7232 if (fread (nb
, 16, 1, file
) != 1)
7234 error (_("Failed to read in number of buckets\n"));
7238 ngnubuckets
= byte_get (nb
, 4);
7239 gnusymidx
= byte_get (nb
+ 4, 4);
7240 bitmaskwords
= byte_get (nb
+ 8, 4);
7241 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7243 buckets_vma
+= bitmaskwords
* 4;
7245 buckets_vma
+= bitmaskwords
* 8;
7248 (archive_file_offset
7249 + offset_from_vma (file
, buckets_vma
, 4)),
7252 error (_("Unable to seek to start of dynamic information\n"));
7256 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7258 if (gnubuckets
== NULL
)
7261 for (i
= 0; i
< ngnubuckets
; i
++)
7262 if (gnubuckets
[i
] != 0)
7264 if (gnubuckets
[i
] < gnusymidx
)
7267 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7268 maxchain
= gnubuckets
[i
];
7271 if (maxchain
== 0xffffffff)
7274 maxchain
-= gnusymidx
;
7277 (archive_file_offset
7278 + offset_from_vma (file
, buckets_vma
7279 + 4 * (ngnubuckets
+ maxchain
), 4)),
7282 error (_("Unable to seek to start of dynamic information\n"));
7288 if (fread (nb
, 4, 1, file
) != 1)
7290 error (_("Failed to determine last chain length\n"));
7294 if (maxchain
+ 1 == 0)
7299 while ((byte_get (nb
, 4) & 1) == 0);
7302 (archive_file_offset
7303 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7306 error (_("Unable to seek to start of dynamic information\n"));
7310 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7312 if (gnuchains
== NULL
)
7316 if ((dynamic_info
[DT_HASH
] || dynamic_info_DT_GNU_HASH
)
7319 && dynamic_strings
!= NULL
)
7323 if (dynamic_info
[DT_HASH
])
7327 printf (_("\nSymbol table for image:\n"));
7329 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7331 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7333 for (hn
= 0; hn
< nbuckets
; hn
++)
7338 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7339 print_dynamic_symbol (si
, hn
);
7343 if (dynamic_info_DT_GNU_HASH
)
7345 printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
7347 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7349 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7351 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7352 if (gnubuckets
[hn
] != 0)
7354 bfd_vma si
= gnubuckets
[hn
];
7355 bfd_vma off
= si
- gnusymidx
;
7359 print_dynamic_symbol (si
, hn
);
7362 while ((gnuchains
[off
++] & 1) == 0);
7366 else if (do_syms
&& !do_using_dynamic
)
7370 for (i
= 0, section
= section_headers
;
7371 i
< elf_header
.e_shnum
;
7375 char *strtab
= NULL
;
7376 unsigned long int strtab_size
= 0;
7377 Elf_Internal_Sym
*symtab
;
7378 Elf_Internal_Sym
*psym
;
7381 if ( section
->sh_type
!= SHT_SYMTAB
7382 && section
->sh_type
!= SHT_DYNSYM
)
7385 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7386 SECTION_NAME (section
),
7387 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7389 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7391 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7393 symtab
= GET_ELF_SYMBOLS (file
, section
);
7397 if (section
->sh_link
== elf_header
.e_shstrndx
)
7399 strtab
= string_table
;
7400 strtab_size
= string_table_length
;
7402 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
7404 Elf_Internal_Shdr
*string_sec
;
7406 string_sec
= SECTION_HEADER (section
->sh_link
);
7408 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
7409 1, string_sec
->sh_size
, _("string table"));
7410 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7413 for (si
= 0, psym
= symtab
;
7414 si
< section
->sh_size
/ section
->sh_entsize
;
7417 printf ("%6d: ", si
);
7418 print_vma (psym
->st_value
, LONG_HEX
);
7420 print_vma (psym
->st_size
, DEC_5
);
7421 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7422 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7423 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7424 /* Check to see if any other bits in the st_other field are set.
7425 Note - displaying this information disrupts the layout of the
7426 table being generated, but for the moment this case is very rare. */
7427 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7428 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7429 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7430 print_symbol (25, psym
->st_name
< strtab_size
7431 ? strtab
+ psym
->st_name
: "<corrupt>");
7433 if (section
->sh_type
== SHT_DYNSYM
&&
7434 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7436 unsigned char data
[2];
7437 unsigned short vers_data
;
7438 unsigned long offset
;
7442 offset
= offset_from_vma
7443 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7444 sizeof data
+ si
* sizeof (vers_data
));
7446 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7447 sizeof (data
), 1, _("version data"));
7449 vers_data
= byte_get (data
, 2);
7451 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7452 < elf_header
.e_shnum
7453 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7456 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7458 if ((vers_data
& 0x8000) || vers_data
> 1)
7460 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7461 && (is_nobits
|| ! check_def
))
7463 Elf_External_Verneed evn
;
7464 Elf_Internal_Verneed ivn
;
7465 Elf_Internal_Vernaux ivna
;
7467 /* We must test both. */
7468 offset
= offset_from_vma
7469 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7474 unsigned long vna_off
;
7476 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7479 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7480 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7482 vna_off
= offset
+ ivn
.vn_aux
;
7486 Elf_External_Vernaux evna
;
7488 get_data (&evna
, file
, vna_off
,
7490 _("version need aux (3)"));
7492 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7493 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7494 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7496 vna_off
+= ivna
.vna_next
;
7498 while (ivna
.vna_other
!= vers_data
7499 && ivna
.vna_next
!= 0);
7501 if (ivna
.vna_other
== vers_data
)
7504 offset
+= ivn
.vn_next
;
7506 while (ivn
.vn_next
!= 0);
7508 if (ivna
.vna_other
== vers_data
)
7511 ivna
.vna_name
< strtab_size
7512 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7516 else if (! is_nobits
)
7517 error (_("bad dynamic symbol\n"));
7524 if (vers_data
!= 0x8001
7525 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7527 Elf_Internal_Verdef ivd
;
7528 Elf_Internal_Verdaux ivda
;
7529 Elf_External_Verdaux evda
;
7530 unsigned long offset
;
7532 offset
= offset_from_vma
7534 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7535 sizeof (Elf_External_Verdef
));
7539 Elf_External_Verdef evd
;
7541 get_data (&evd
, file
, offset
, sizeof (evd
),
7542 1, _("version def"));
7544 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7545 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7546 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7548 offset
+= ivd
.vd_next
;
7550 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7551 && ivd
.vd_next
!= 0);
7553 offset
-= ivd
.vd_next
;
7554 offset
+= ivd
.vd_aux
;
7556 get_data (&evda
, file
, offset
, sizeof (evda
),
7557 1, _("version def aux"));
7559 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7561 if (psym
->st_name
!= ivda
.vda_name
)
7562 printf ((vers_data
& 0x8000)
7564 ivda
.vda_name
< strtab_size
7565 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7575 if (strtab
!= string_table
)
7581 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7583 if (do_histogram
&& buckets
!= NULL
)
7585 unsigned long *lengths
;
7586 unsigned long *counts
;
7589 unsigned long maxlength
= 0;
7590 unsigned long nzero_counts
= 0;
7591 unsigned long nsyms
= 0;
7593 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7594 (unsigned long) nbuckets
);
7595 printf (_(" Length Number %% of total Coverage\n"));
7597 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7598 if (lengths
== NULL
)
7600 error (_("Out of memory\n"));
7603 for (hn
= 0; hn
< nbuckets
; ++hn
)
7605 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7608 if (maxlength
< ++lengths
[hn
])
7613 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7616 error (_("Out of memory\n"));
7620 for (hn
= 0; hn
< nbuckets
; ++hn
)
7621 ++counts
[lengths
[hn
]];
7626 printf (" 0 %-10lu (%5.1f%%)\n",
7627 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7628 for (i
= 1; i
<= maxlength
; ++i
)
7630 nzero_counts
+= counts
[i
] * i
;
7631 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7632 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7633 (nzero_counts
* 100.0) / nsyms
);
7641 if (buckets
!= NULL
)
7647 if (do_histogram
&& dynamic_info_DT_GNU_HASH
)
7649 unsigned long *lengths
;
7650 unsigned long *counts
;
7652 unsigned long maxlength
= 0;
7653 unsigned long nzero_counts
= 0;
7654 unsigned long nsyms
= 0;
7656 lengths
= calloc (ngnubuckets
, sizeof (*lengths
));
7657 if (lengths
== NULL
)
7659 error (_("Out of memory\n"));
7663 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7664 (unsigned long) ngnubuckets
);
7665 printf (_(" Length Number %% of total Coverage\n"));
7667 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7668 if (gnubuckets
[hn
] != 0)
7670 bfd_vma off
, length
= 1;
7672 for (off
= gnubuckets
[hn
] - gnusymidx
;
7673 (gnuchains
[off
] & 1) == 0; ++off
)
7675 lengths
[hn
] = length
;
7676 if (length
> maxlength
)
7681 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7684 error (_("Out of memory\n"));
7688 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7689 ++counts
[lengths
[hn
]];
7691 if (ngnubuckets
> 0)
7694 printf (" 0 %-10lu (%5.1f%%)\n",
7695 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7696 for (j
= 1; j
<= maxlength
; ++j
)
7698 nzero_counts
+= counts
[j
] * j
;
7699 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7700 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7701 (nzero_counts
* 100.0) / nsyms
);
7715 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7719 if (dynamic_syminfo
== NULL
7721 /* No syminfo, this is ok. */
7724 /* There better should be a dynamic symbol section. */
7725 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7729 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7730 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7732 printf (_(" Num: Name BoundTo Flags\n"));
7733 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7735 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7737 printf ("%4d: ", i
);
7738 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7739 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7741 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7744 switch (dynamic_syminfo
[i
].si_boundto
)
7746 case SYMINFO_BT_SELF
:
7747 fputs ("SELF ", stdout
);
7749 case SYMINFO_BT_PARENT
:
7750 fputs ("PARENT ", stdout
);
7753 if (dynamic_syminfo
[i
].si_boundto
> 0
7754 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7755 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7757 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7761 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7765 if (flags
& SYMINFO_FLG_DIRECT
)
7767 if (flags
& SYMINFO_FLG_PASSTHRU
)
7768 printf (" PASSTHRU");
7769 if (flags
& SYMINFO_FLG_COPY
)
7771 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7772 printf (" LAZYLOAD");
7780 #ifdef SUPPORT_DISASSEMBLY
7782 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7784 printf (_("\nAssembly dump of section %s\n"),
7785 SECTION_NAME (section
));
7787 /* XXX -- to be done --- XXX */
7794 dump_section_as_strings (Elf_Internal_Shdr
*section
, FILE *file
)
7796 Elf_Internal_Shdr
*relsec
;
7797 bfd_size_type num_bytes
;
7802 char *name
= SECTION_NAME (section
);
7803 bfd_boolean some_strings_shown
;
7805 num_bytes
= section
->sh_size
;
7807 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7809 printf (_("\nSection '%s' has no data to dump.\n"), name
);
7813 addr
= section
->sh_addr
;
7815 start
= get_data (NULL
, file
, section
->sh_offset
, 1, num_bytes
,
7820 printf (_("\nString dump of section '%s':\n"), name
);
7822 /* If the section being dumped has relocations against it the user might
7823 be expecting these relocations to have been applied. Check for this
7824 case and issue a warning message in order to avoid confusion.
7825 FIXME: Maybe we ought to have an option that dumps a section with
7827 for (relsec
= section_headers
;
7828 relsec
< section_headers
+ elf_header
.e_shnum
;
7831 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
7832 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7833 || SECTION_HEADER (relsec
->sh_info
) != section
7834 || relsec
->sh_size
== 0
7835 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7838 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
7843 end
= start
+ num_bytes
;
7844 some_strings_shown
= FALSE
;
7848 while (!ISPRINT (* data
))
7855 printf (" [%6tx] %s\n", data
- start
, data
);
7857 printf (" [%6Ix] %s\n", (size_t) (data
- start
), data
);
7859 data
+= strlen (data
);
7860 some_strings_shown
= TRUE
;
7864 if (! some_strings_shown
)
7865 printf (_(" No strings found in this section."));
7875 dump_section_as_bytes (Elf_Internal_Shdr
*section
, FILE *file
)
7877 Elf_Internal_Shdr
*relsec
;
7878 bfd_size_type bytes
;
7880 unsigned char *data
;
7881 unsigned char *start
;
7883 bytes
= section
->sh_size
;
7885 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7887 printf (_("\nSection '%s' has no data to dump.\n"),
7888 SECTION_NAME (section
));
7892 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7894 addr
= section
->sh_addr
;
7896 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7901 /* If the section being dumped has relocations against it the user might
7902 be expecting these relocations to have been applied. Check for this
7903 case and issue a warning message in order to avoid confusion.
7904 FIXME: Maybe we ought to have an option that dumps a section with
7906 for (relsec
= section_headers
;
7907 relsec
< section_headers
+ elf_header
.e_shnum
;
7910 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
7911 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7912 || SECTION_HEADER (relsec
->sh_info
) != section
7913 || relsec
->sh_size
== 0
7914 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7917 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
7929 lbytes
= (bytes
> 16 ? 16 : bytes
);
7931 printf (" 0x%8.8lx ", (unsigned long) addr
);
7933 for (j
= 0; j
< 16; j
++)
7936 printf ("%2.2x", data
[j
]);
7944 for (j
= 0; j
< lbytes
; j
++)
7947 if (k
>= ' ' && k
< 0x7f)
7966 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
7967 DWARF debug sections. This is a target specific test. Note - we do not
7968 go through the whole including-target-headers-multiple-times route, (as
7969 we have already done with <elf/h8.h>) because this would become very
7970 messy and even then this function would have to contain target specific
7971 information (the names of the relocs instead of their numeric values).
7972 FIXME: This is not the correct way to solve this problem. The proper way
7973 is to have target specific reloc sizing and typing functions created by
7974 the reloc-macros.h header, in the same way that it already creates the
7975 reloc naming functions. */
7978 is_32bit_abs_reloc (unsigned int reloc_type
)
7980 switch (elf_header
.e_machine
)
7984 return reloc_type
== 1; /* R_386_32. */
7986 return reloc_type
== 1; /* R_68K_32. */
7988 return reloc_type
== 1; /* R_860_32. */
7990 return reloc_type
== 1; /* XXX Is this right ? */
7992 return reloc_type
== 1; /* R_ARC_32. */
7994 return reloc_type
== 2; /* R_ARM_ABS32 */
7997 return reloc_type
== 1;
7999 return reloc_type
== 0x12; /* R_byte4_data. */
8001 return reloc_type
== 3; /* R_CRIS_32. */
8003 return reloc_type
== 3; /* R_CR16_NUM32. */
8005 return reloc_type
== 15; /* R_CRX_NUM32. */
8007 return reloc_type
== 1;
8008 case EM_CYGNUS_D10V
:
8010 return reloc_type
== 6; /* R_D10V_32. */
8011 case EM_CYGNUS_D30V
:
8013 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
8015 return reloc_type
== 3; /* R_DLX_RELOC_32. */
8016 case EM_CYGNUS_FR30
:
8018 return reloc_type
== 3; /* R_FR30_32. */
8022 return reloc_type
== 1; /* R_H8_DIR32. */
8024 return reloc_type
== 0x65; /* R_IA64_SECREL32LSB. */
8027 return reloc_type
== 2; /* R_IP2K_32. */
8029 return reloc_type
== 2; /* R_IQ2000_32. */
8031 return reloc_type
== 3; /* R_M32C_32. */
8033 return reloc_type
== 34; /* R_M32R_32_RELA. */
8035 return reloc_type
== 1; /* R_MCORE_ADDR32. */
8037 return reloc_type
== 4; /* R_MEP_32. */
8039 return reloc_type
== 2; /* R_MIPS_32. */
8041 return reloc_type
== 4; /* R_MMIX_32. */
8042 case EM_CYGNUS_MN10200
:
8044 return reloc_type
== 1; /* R_MN10200_32. */
8045 case EM_CYGNUS_MN10300
:
8047 return reloc_type
== 1; /* R_MN10300_32. */
8050 return reloc_type
== 1; /* R_MSP43_32. */
8052 return reloc_type
== 2; /* R_MT_32. */
8053 case EM_ALTERA_NIOS2
:
8055 return reloc_type
== 1; /* R_NIOS_32. */
8058 return reloc_type
== 1; /* R_OR32_32. */
8060 return reloc_type
== 1; /* R_PARISC_DIR32. */
8063 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
8065 return reloc_type
== 1; /* R_PPC64_ADDR32. */
8067 return reloc_type
== 1; /* R_PPC_ADDR32. */
8069 return reloc_type
== 1; /* R_I370_ADDR31. */
8072 return reloc_type
== 4; /* R_S390_32. */
8074 return reloc_type
== 8; /* R_SCORE_ABS32. */
8076 return reloc_type
== 1; /* R_SH_DIR32. */
8077 case EM_SPARC32PLUS
:
8080 return reloc_type
== 3 /* R_SPARC_32. */
8081 || reloc_type
== 23; /* R_SPARC_UA32. */
8083 return reloc_type
== 6; /* R_SPU_ADDR32 */
8084 case EM_CYGNUS_V850
:
8086 return reloc_type
== 6; /* R_V850_ABS32. */
8088 return reloc_type
== 1; /* R_VAX_32. */
8090 return reloc_type
== 10; /* R_X86_64_32. */
8092 return reloc_type
== 1; /* R_XSTROMY16_32. */
8095 return reloc_type
== 1; /* R_XTENSA_32. */
8098 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
8099 elf_header
.e_machine
);
8104 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8105 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
8108 is_32bit_pcrel_reloc (unsigned int reloc_type
)
8110 switch (elf_header
.e_machine
)
8114 return reloc_type
== 2; /* R_386_PC32. */
8116 return reloc_type
== 4; /* R_68K_PC32. */
8118 return reloc_type
== 10; /* R_ALPHA_SREL32. */
8120 return reloc_type
== 3; /* R_ARM_REL32 */
8122 return reloc_type
== 0; /* R_PARISC_NONE. *//* FIXME: This reloc is generated, but it may be a bug. */
8124 return reloc_type
== 26; /* R_PPC_REL32. */
8126 return reloc_type
== 26; /* R_PPC64_REL32. */
8129 return reloc_type
== 5; /* R_390_PC32. */
8131 return reloc_type
== 2; /* R_SH_REL32. */
8132 case EM_SPARC32PLUS
:
8135 return reloc_type
== 6; /* R_SPARC_DISP32. */
8137 return reloc_type
== 13; /* R_SPU_REL32. */
8139 return reloc_type
== 2; /* R_X86_64_PC32. */
8142 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
8144 /* Do not abort or issue an error message here. Not all targets use
8145 pc-relative 32-bit relocs in their DWARF debug information and we
8146 have already tested for target coverage in is_32bit_abs_reloc. A
8147 more helpful warning message will be generated by
8148 debug_apply_relocations anyway, so just return. */
8153 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8154 a 64-bit absolute RELA relocation used in DWARF debug sections. */
8157 is_64bit_abs_reloc (unsigned int reloc_type
)
8159 switch (elf_header
.e_machine
)
8162 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
8164 return reloc_type
== 0x27; /* R_IA64_DIR64LSB. */
8166 return reloc_type
== 80; /* R_PARISC_DIR64. */
8168 return reloc_type
== 38; /* R_PPC64_ADDR64. */
8169 case EM_SPARC32PLUS
:
8172 return reloc_type
== 54; /* R_SPARC_UA64. */
8174 return reloc_type
== 1; /* R_X86_64_64. */
8177 return reloc_type
== 22; /* R_S390_64 */
8183 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8184 a 16-bit absolute RELA relocation used in DWARF debug sections. */
8187 is_16bit_abs_reloc (unsigned int reloc_type
)
8189 switch (elf_header
.e_machine
)
8193 return reloc_type
== 4; /* R_AVR_16. */
8194 case EM_CYGNUS_D10V
:
8196 return reloc_type
== 3; /* R_D10V_16. */
8200 return reloc_type
== R_H8_DIR16
;
8203 return reloc_type
== 1; /* R_IP2K_16. */
8205 return reloc_type
== 1; /* R_M32C_16 */
8208 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
8209 case EM_ALTERA_NIOS2
:
8211 return reloc_type
== 9; /* R_NIOS_16. */
8217 /* Apply relocations to a debug section. */
8220 debug_apply_relocations (void *file
,
8221 Elf_Internal_Shdr
*section
,
8222 unsigned char *start
)
8224 Elf_Internal_Shdr
*relsec
;
8225 unsigned char *end
= start
+ section
->sh_size
;
8227 if (elf_header
.e_type
!= ET_REL
)
8230 /* Find the reloc section associated with the debug section. */
8231 for (relsec
= section_headers
;
8232 relsec
< section_headers
+ elf_header
.e_shnum
;
8235 bfd_boolean is_rela
;
8236 unsigned long num_relocs
;
8237 Elf_Internal_Rela
*relocs
, *rp
;
8238 Elf_Internal_Shdr
*symsec
;
8239 Elf_Internal_Sym
*symtab
;
8240 Elf_Internal_Sym
*sym
;
8242 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8243 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
8244 || SECTION_HEADER (relsec
->sh_info
) != section
8245 || relsec
->sh_size
== 0
8246 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
8249 is_rela
= relsec
->sh_type
== SHT_RELA
;
8253 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8254 & relocs
, & num_relocs
))
8259 if (!slurp_rel_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8260 & relocs
, & num_relocs
))
8264 /* SH uses RELA but uses in place value instead of the addend field. */
8265 if (elf_header
.e_machine
== EM_SH
)
8268 symsec
= SECTION_HEADER (relsec
->sh_link
);
8269 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
8271 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
8274 unsigned int reloc_type
;
8275 unsigned int reloc_size
;
8276 unsigned char * loc
;
8278 /* In MIPS little-endian objects, r_info isn't really a
8279 64-bit little-endian value: it has a 32-bit little-endian
8280 symbol index followed by four individual byte fields.
8281 Reorder INFO accordingly. */
8283 && elf_header
.e_machine
== EM_MIPS
8284 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
8285 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
8286 | ((rp
->r_info
>> 56) & 0xff)
8287 | ((rp
->r_info
>> 40) & 0xff00)
8288 | ((rp
->r_info
>> 24) & 0xff0000)
8289 | ((rp
->r_info
>> 8) & 0xff000000));
8291 reloc_type
= get_reloc_type (rp
->r_info
);
8293 if (is_32bit_abs_reloc (reloc_type
)
8294 || is_32bit_pcrel_reloc (reloc_type
))
8296 else if (is_64bit_abs_reloc (reloc_type
))
8298 else if (is_16bit_abs_reloc (reloc_type
))
8302 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
8303 reloc_type
, SECTION_NAME (section
));
8307 loc
= start
+ rp
->r_offset
;
8308 if ((loc
+ reloc_size
) > end
)
8310 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
8311 (unsigned long) rp
->r_offset
,
8312 SECTION_NAME (section
));
8316 sym
= symtab
+ get_reloc_symindex (rp
->r_info
);
8318 /* If the reloc has a symbol associated with it,
8319 make sure that it is of an appropriate type. */
8321 && ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
8322 /* Relocations against symbols without type can happen.
8323 Gcc -feliminate-dwarf2-dups may generate symbols
8324 without type for debug info. */
8325 && ELF_ST_TYPE (sym
->st_info
) != STT_NOTYPE
8326 /* Relocations against object symbols can happen,
8327 eg when referencing a global array. For an
8328 example of this see the _clz.o binary in libgcc.a. */
8329 && ELF_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
8331 warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
8332 get_symbol_type (ELF_ST_TYPE (sym
->st_info
)),
8333 (long int)(rp
- relocs
),
8334 SECTION_NAME (relsec
));
8338 addend
= is_rela
? rp
->r_addend
: byte_get (loc
, reloc_size
);
8340 if (is_32bit_pcrel_reloc (reloc_type
))
8341 byte_put (loc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
8344 byte_put (loc
, addend
+ sym
->st_value
, reloc_size
);
8354 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
8356 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
8357 Elf_Internal_Shdr
*sec
;
8360 /* If it is already loaded, do nothing. */
8361 if (section
->start
!= NULL
)
8364 /* Locate the debug section. */
8365 sec
= find_section (section
->name
);
8369 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
8370 section
->address
= sec
->sh_addr
;
8371 section
->size
= sec
->sh_size
;
8372 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
8375 if (debug_displays
[debug
].relocate
)
8376 debug_apply_relocations (file
, sec
, section
->start
);
8378 return section
->start
!= NULL
;
8382 free_debug_section (enum dwarf_section_display_enum debug
)
8384 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
8386 if (section
->start
== NULL
)
8389 free ((char *) section
->start
);
8390 section
->start
= NULL
;
8391 section
->address
= 0;
8396 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
8398 char *name
= SECTION_NAME (section
);
8399 bfd_size_type length
;
8401 enum dwarf_section_display_enum i
;
8403 length
= section
->sh_size
;
8406 printf (_("\nSection '%s' has no debugging data.\n"), name
);
8410 if (const_strneq (name
, ".gnu.linkonce.wi."))
8411 name
= ".debug_info";
8413 /* See if we know how to display the contents of this section. */
8414 for (i
= 0; i
< max
; i
++)
8415 if (streq (debug_displays
[i
].section
.name
, name
))
8417 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
8419 if (load_debug_section (i
, file
))
8421 result
&= debug_displays
[i
].display (sec
, file
);
8423 if (i
!= info
&& i
!= abbrev
)
8424 free_debug_section (i
);
8432 printf (_("Unrecognized debug section: %s\n"), name
);
8439 /* Set DUMP_SECTS for all sections where dumps were requested
8440 based on section name. */
8443 initialise_dumps_byname (void)
8445 struct dump_list_entry
*cur
;
8447 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
8452 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
8453 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
8455 request_dump_bynumber (i
, cur
->type
);
8460 warn (_("Section '%s' was not dumped because it does not exist!\n"),
8466 process_section_contents (FILE *file
)
8468 Elf_Internal_Shdr
*section
;
8474 initialise_dumps_byname ();
8476 for (i
= 0, section
= section_headers
;
8477 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8480 #ifdef SUPPORT_DISASSEMBLY
8481 if (dump_sects
[i
] & DISASS_DUMP
)
8482 disassemble_section (section
, file
);
8484 if (dump_sects
[i
] & HEX_DUMP
)
8485 dump_section_as_bytes (section
, file
);
8487 if (dump_sects
[i
] & DEBUG_DUMP
)
8488 display_debug_section (section
, file
);
8490 if (dump_sects
[i
] & STRING_DUMP
)
8491 dump_section_as_strings (section
, file
);
8494 /* Check to see if the user requested a
8495 dump of a section that does not exist. */
8496 while (i
++ < num_dump_sects
)
8498 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
8502 process_mips_fpe_exception (int mask
)
8507 if (mask
& OEX_FPU_INEX
)
8508 fputs ("INEX", stdout
), first
= 0;
8509 if (mask
& OEX_FPU_UFLO
)
8510 printf ("%sUFLO", first
? "" : "|"), first
= 0;
8511 if (mask
& OEX_FPU_OFLO
)
8512 printf ("%sOFLO", first
? "" : "|"), first
= 0;
8513 if (mask
& OEX_FPU_DIV0
)
8514 printf ("%sDIV0", first
? "" : "|"), first
= 0;
8515 if (mask
& OEX_FPU_INVAL
)
8516 printf ("%sINVAL", first
? "" : "|");
8519 fputs ("0", stdout
);
8522 /* ARM EABI attributes section. */
8527 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8530 } arm_attr_public_tag
;
8532 static const char *arm_attr_tag_CPU_arch
[] =
8533 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8535 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8536 static const char *arm_attr_tag_THUMB_ISA_use
[] =
8537 {"No", "Thumb-1", "Thumb-2"};
8538 /* FIXME: VFPv3 encoding was extrapolated! */
8539 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
8540 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
8541 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
8542 static const char *arm_attr_tag_ABI_PCS_config
[] =
8543 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8544 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8545 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
8546 {"V6", "SB", "TLS", "Unused"};
8547 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
8548 {"Absolute", "PC-relative", "SB-relative", "None"};
8549 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
8550 {"Absolute", "PC-relative", "None"};
8551 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
8552 {"None", "direct", "GOT-indirect"};
8553 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
8554 {"None", "??? 1", "2", "??? 3", "4"};
8555 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8556 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
8557 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8558 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8559 static const char *arm_attr_tag_ABI_FP_number_model
[] =
8560 {"Unused", "Finite", "RTABI", "IEEE 754"};
8561 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8562 static const char *arm_attr_tag_ABI_align8_preserved
[] =
8563 {"No", "Yes, except leaf SP", "Yes"};
8564 static const char *arm_attr_tag_ABI_enum_size
[] =
8565 {"Unused", "small", "int", "forced to int"};
8566 static const char *arm_attr_tag_ABI_HardFP_use
[] =
8567 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8568 static const char *arm_attr_tag_ABI_VFP_args
[] =
8569 {"AAPCS", "VFP registers", "custom"};
8570 static const char *arm_attr_tag_ABI_WMMX_args
[] =
8571 {"AAPCS", "WMMX registers", "custom"};
8572 static const char *arm_attr_tag_ABI_optimization_goals
[] =
8573 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8574 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8575 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
8576 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8577 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8579 #define LOOKUP(id, name) \
8580 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8581 static arm_attr_public_tag arm_attr_public_tags
[] =
8583 {4, "CPU_raw_name", 1, NULL
},
8584 {5, "CPU_name", 1, NULL
},
8585 LOOKUP(6, CPU_arch
),
8586 {7, "CPU_arch_profile", 0, NULL
},
8587 LOOKUP(8, ARM_ISA_use
),
8588 LOOKUP(9, THUMB_ISA_use
),
8589 LOOKUP(10, VFP_arch
),
8590 LOOKUP(11, WMMX_arch
),
8591 LOOKUP(12, NEON_arch
),
8592 LOOKUP(13, ABI_PCS_config
),
8593 LOOKUP(14, ABI_PCS_R9_use
),
8594 LOOKUP(15, ABI_PCS_RW_data
),
8595 LOOKUP(16, ABI_PCS_RO_DATA
),
8596 LOOKUP(17, ABI_PCS_GOT_use
),
8597 LOOKUP(18, ABI_PCS_wchar_t
),
8598 LOOKUP(19, ABI_FP_rounding
),
8599 LOOKUP(20, ABI_FP_denormal
),
8600 LOOKUP(21, ABI_FP_exceptions
),
8601 LOOKUP(22, ABI_FP_user_exceptions
),
8602 LOOKUP(23, ABI_FP_number_model
),
8603 LOOKUP(24, ABI_align8_needed
),
8604 LOOKUP(25, ABI_align8_preserved
),
8605 LOOKUP(26, ABI_enum_size
),
8606 LOOKUP(27, ABI_HardFP_use
),
8607 LOOKUP(28, ABI_VFP_args
),
8608 LOOKUP(29, ABI_WMMX_args
),
8609 LOOKUP(30, ABI_optimization_goals
),
8610 LOOKUP(31, ABI_FP_optimization_goals
),
8611 {32, "compatibility", 0, NULL
}
8615 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8618 read_uleb128 (unsigned char *p
, unsigned int *plen
)
8632 val
|= ((unsigned int)c
& 0x7f) << shift
;
8641 static unsigned char *
8642 display_arm_attribute (unsigned char *p
)
8647 arm_attr_public_tag
*attr
;
8651 tag
= read_uleb128 (p
, &len
);
8654 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
8656 if (arm_attr_public_tags
[i
].tag
== tag
)
8658 attr
= &arm_attr_public_tags
[i
];
8665 printf (" Tag_%s: ", attr
->name
);
8671 case 7: /* Tag_CPU_arch_profile. */
8672 val
= read_uleb128 (p
, &len
);
8676 case 0: printf ("None\n"); break;
8677 case 'A': printf ("Application\n"); break;
8678 case 'R': printf ("Realtime\n"); break;
8679 case 'M': printf ("Microcontroller\n"); break;
8680 default: printf ("??? (%d)\n", val
); break;
8684 case 32: /* Tag_compatibility. */
8685 val
= read_uleb128 (p
, &len
);
8687 printf ("flag = %d, vendor = %s\n", val
, p
);
8688 p
+= strlen((char *)p
) + 1;
8702 assert (attr
->type
& 0x80);
8703 val
= read_uleb128 (p
, &len
);
8705 type
= attr
->type
& 0x7f;
8707 printf ("??? (%d)\n", val
);
8709 printf ("%s\n", attr
->table
[val
]);
8716 type
= 1; /* String. */
8718 type
= 2; /* uleb128. */
8719 printf (" Tag_unknown_%d: ", tag
);
8724 printf ("\"%s\"\n", p
);
8725 p
+= strlen((char *)p
) + 1;
8729 val
= read_uleb128 (p
, &len
);
8731 printf ("%d (0x%x)\n", val
, val
);
8737 static unsigned char *
8738 display_gnu_attribute (unsigned char * p
,
8739 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8746 tag
= read_uleb128 (p
, &len
);
8749 /* Tag_compatibility is the only generic GNU attribute defined at
8753 val
= read_uleb128 (p
, &len
);
8755 printf ("flag = %d, vendor = %s\n", val
, p
);
8756 p
+= strlen ((char *) p
) + 1;
8760 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
8761 return display_proc_gnu_attribute (p
, tag
);
8764 type
= 1; /* String. */
8766 type
= 2; /* uleb128. */
8767 printf (" Tag_unknown_%d: ", tag
);
8771 printf ("\"%s\"\n", p
);
8772 p
+= strlen ((char *) p
) + 1;
8776 val
= read_uleb128 (p
, &len
);
8778 printf ("%d (0x%x)\n", val
, val
);
8784 static unsigned char *
8785 display_power_gnu_attribute (unsigned char *p
, int tag
)
8791 if (tag
== Tag_GNU_Power_ABI_FP
)
8793 val
= read_uleb128 (p
, &len
);
8795 printf (" Tag_GNU_Power_ABI_FP: ");
8800 printf ("Hard or soft float\n");
8803 printf ("Hard float\n");
8806 printf ("Soft float\n");
8809 printf ("??? (%d)\n", val
);
8815 if (tag
== Tag_GNU_Power_ABI_Vector
)
8817 val
= read_uleb128 (p
, &len
);
8819 printf (" Tag_GNU_Power_ABI_Vector: ");
8826 printf ("Generic\n");
8829 printf ("AltiVec\n");
8835 printf ("??? (%d)\n", val
);
8842 type
= 1; /* String. */
8844 type
= 2; /* uleb128. */
8845 printf (" Tag_unknown_%d: ", tag
);
8849 printf ("\"%s\"\n", p
);
8850 p
+= strlen ((char *) p
) + 1;
8854 val
= read_uleb128 (p
, &len
);
8856 printf ("%d (0x%x)\n", val
, val
);
8862 static unsigned char *
8863 display_mips_gnu_attribute (unsigned char *p
, int tag
)
8869 if (tag
== Tag_GNU_MIPS_ABI_FP
)
8871 val
= read_uleb128 (p
, &len
);
8873 printf (" Tag_GNU_MIPS_ABI_FP: ");
8878 printf ("Hard or soft float\n");
8881 printf ("Hard float (-mdouble-float)\n");
8884 printf ("Hard float (-msingle-float)\n");
8887 printf ("Soft float\n");
8890 printf ("64-bit float (-mips32r2 -mfp64)\n");
8893 printf ("??? (%d)\n", val
);
8900 type
= 1; /* String. */
8902 type
= 2; /* uleb128. */
8903 printf (" Tag_unknown_%d: ", tag
);
8907 printf ("\"%s\"\n", p
);
8908 p
+= strlen ((char *) p
) + 1;
8912 val
= read_uleb128 (p
, &len
);
8914 printf ("%d (0x%x)\n", val
, val
);
8921 process_attributes (FILE * file
,
8922 const char * public_name
,
8923 unsigned int proc_type
,
8924 unsigned char * (* display_pub_attribute
) (unsigned char *),
8925 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8927 Elf_Internal_Shdr
*sect
;
8928 unsigned char *contents
;
8931 bfd_vma section_len
;
8935 /* Find the section header so that we get the size. */
8936 for (i
= 0, sect
= section_headers
;
8937 i
< elf_header
.e_shnum
;
8940 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
8943 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
8945 if (contents
== NULL
)
8951 len
= sect
->sh_size
- 1;
8957 bfd_boolean public_section
;
8958 bfd_boolean gnu_section
;
8960 section_len
= byte_get (p
, 4);
8963 if (section_len
> len
)
8965 printf (_("ERROR: Bad section length (%d > %d)\n"),
8966 (int) section_len
, (int) len
);
8971 printf ("Attribute Section: %s\n", p
);
8973 if (public_name
&& streq ((char *) p
, public_name
))
8974 public_section
= TRUE
;
8976 public_section
= FALSE
;
8978 if (streq ((char *) p
, "gnu"))
8981 gnu_section
= FALSE
;
8983 namelen
= strlen ((char *) p
) + 1;
8985 section_len
-= namelen
+ 4;
8987 while (section_len
> 0)
8993 size
= byte_get (p
, 4);
8994 if (size
> section_len
)
8996 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
8997 (int) size
, (int) section_len
);
9001 section_len
-= size
;
9008 printf ("File Attributes\n");
9011 printf ("Section Attributes:");
9014 printf ("Symbol Attributes:");
9020 val
= read_uleb128 (p
, &i
);
9024 printf (" %d", val
);
9029 printf ("Unknown tag: %d\n", tag
);
9030 public_section
= FALSE
;
9037 p
= display_pub_attribute (p
);
9039 else if (gnu_section
)
9042 p
= display_gnu_attribute (p
,
9043 display_proc_gnu_attribute
);
9047 /* ??? Do something sensible, like dump hex. */
9048 printf (" Unknown section contexts\n");
9055 printf (_("Unknown format '%c'\n"), *p
);
9063 process_arm_specific (FILE *file
)
9065 return process_attributes (file
, "aeabi", SHT_ARM_ATTRIBUTES
,
9066 display_arm_attribute
, NULL
);
9070 process_power_specific (FILE *file
)
9072 return process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
9073 display_power_gnu_attribute
);
9077 process_mips_specific (FILE *file
)
9079 Elf_Internal_Dyn
*entry
;
9080 size_t liblist_offset
= 0;
9081 size_t liblistno
= 0;
9082 size_t conflictsno
= 0;
9083 size_t options_offset
= 0;
9084 size_t conflicts_offset
= 0;
9086 process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
9087 display_mips_gnu_attribute
);
9089 /* We have a lot of special sections. Thanks SGI! */
9090 if (dynamic_section
== NULL
)
9091 /* No information available. */
9094 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
9095 switch (entry
->d_tag
)
9097 case DT_MIPS_LIBLIST
:
9099 = offset_from_vma (file
, entry
->d_un
.d_val
,
9100 liblistno
* sizeof (Elf32_External_Lib
));
9102 case DT_MIPS_LIBLISTNO
:
9103 liblistno
= entry
->d_un
.d_val
;
9105 case DT_MIPS_OPTIONS
:
9106 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
9108 case DT_MIPS_CONFLICT
:
9110 = offset_from_vma (file
, entry
->d_un
.d_val
,
9111 conflictsno
* sizeof (Elf32_External_Conflict
));
9113 case DT_MIPS_CONFLICTNO
:
9114 conflictsno
= entry
->d_un
.d_val
;
9120 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9122 Elf32_External_Lib
*elib
;
9125 elib
= get_data (NULL
, file
, liblist_offset
,
9126 liblistno
, sizeof (Elf32_External_Lib
),
9130 printf ("\nSection '.liblist' contains %lu entries:\n",
9131 (unsigned long) liblistno
);
9132 fputs (" Library Time Stamp Checksum Version Flags\n",
9135 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9142 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9143 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9144 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9145 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9146 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9148 tmp
= gmtime (&time
);
9149 snprintf (timebuf
, sizeof (timebuf
),
9150 "%04u-%02u-%02uT%02u:%02u:%02u",
9151 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9152 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9154 printf ("%3lu: ", (unsigned long) cnt
);
9155 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
9156 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
9158 printf ("<corrupt: %9ld>", liblist
.l_name
);
9159 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9162 if (liblist
.l_flags
== 0)
9173 { " EXACT_MATCH", LL_EXACT_MATCH
},
9174 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9175 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9176 { " EXPORTS", LL_EXPORTS
},
9177 { " DELAY_LOAD", LL_DELAY_LOAD
},
9178 { " DELTA", LL_DELTA
}
9180 int flags
= liblist
.l_flags
;
9183 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
9184 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9186 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9187 flags
^= l_flags_vals
[fcnt
].bit
;
9190 printf (" %#x", (unsigned int) flags
);
9200 if (options_offset
!= 0)
9202 Elf_External_Options
*eopt
;
9203 Elf_Internal_Shdr
*sect
= section_headers
;
9204 Elf_Internal_Options
*iopt
;
9205 Elf_Internal_Options
*option
;
9209 /* Find the section header so that we get the size. */
9210 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9213 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
9217 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
9220 error (_("Out of memory\n"));
9227 while (offset
< sect
->sh_size
)
9229 Elf_External_Options
*eoption
;
9231 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9233 option
->kind
= BYTE_GET (eoption
->kind
);
9234 option
->size
= BYTE_GET (eoption
->size
);
9235 option
->section
= BYTE_GET (eoption
->section
);
9236 option
->info
= BYTE_GET (eoption
->info
);
9238 offset
+= option
->size
;
9244 printf (_("\nSection '%s' contains %d entries:\n"),
9245 SECTION_NAME (sect
), cnt
);
9253 switch (option
->kind
)
9256 /* This shouldn't happen. */
9257 printf (" NULL %d %lx", option
->section
, option
->info
);
9260 printf (" REGINFO ");
9261 if (elf_header
.e_machine
== EM_MIPS
)
9264 Elf32_External_RegInfo
*ereg
;
9265 Elf32_RegInfo reginfo
;
9267 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9268 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9269 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9270 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9271 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9272 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9273 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9275 printf ("GPR %08lx GP 0x%lx\n",
9277 (unsigned long) reginfo
.ri_gp_value
);
9278 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9279 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9280 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9285 Elf64_External_RegInfo
*ereg
;
9286 Elf64_Internal_RegInfo reginfo
;
9288 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9289 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9290 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9291 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9292 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9293 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9294 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9296 printf ("GPR %08lx GP 0x",
9297 reginfo
.ri_gprmask
);
9298 printf_vma (reginfo
.ri_gp_value
);
9301 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9302 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9303 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9307 case ODK_EXCEPTIONS
:
9308 fputs (" EXCEPTIONS fpe_min(", stdout
);
9309 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9310 fputs (") fpe_max(", stdout
);
9311 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9312 fputs (")", stdout
);
9314 if (option
->info
& OEX_PAGE0
)
9315 fputs (" PAGE0", stdout
);
9316 if (option
->info
& OEX_SMM
)
9317 fputs (" SMM", stdout
);
9318 if (option
->info
& OEX_FPDBUG
)
9319 fputs (" FPDBUG", stdout
);
9320 if (option
->info
& OEX_DISMISS
)
9321 fputs (" DISMISS", stdout
);
9324 fputs (" PAD ", stdout
);
9325 if (option
->info
& OPAD_PREFIX
)
9326 fputs (" PREFIX", stdout
);
9327 if (option
->info
& OPAD_POSTFIX
)
9328 fputs (" POSTFIX", stdout
);
9329 if (option
->info
& OPAD_SYMBOL
)
9330 fputs (" SYMBOL", stdout
);
9333 fputs (" HWPATCH ", stdout
);
9334 if (option
->info
& OHW_R4KEOP
)
9335 fputs (" R4KEOP", stdout
);
9336 if (option
->info
& OHW_R8KPFETCH
)
9337 fputs (" R8KPFETCH", stdout
);
9338 if (option
->info
& OHW_R5KEOP
)
9339 fputs (" R5KEOP", stdout
);
9340 if (option
->info
& OHW_R5KCVTL
)
9341 fputs (" R5KCVTL", stdout
);
9344 fputs (" FILL ", stdout
);
9345 /* XXX Print content of info word? */
9348 fputs (" TAGS ", stdout
);
9349 /* XXX Print content of info word? */
9352 fputs (" HWAND ", stdout
);
9353 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9354 fputs (" R4KEOP_CHECKED", stdout
);
9355 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9356 fputs (" R4KEOP_CLEAN", stdout
);
9359 fputs (" HWOR ", stdout
);
9360 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9361 fputs (" R4KEOP_CHECKED", stdout
);
9362 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9363 fputs (" R4KEOP_CLEAN", stdout
);
9366 printf (" GP_GROUP %#06lx self-contained %#06lx",
9367 option
->info
& OGP_GROUP
,
9368 (option
->info
& OGP_SELF
) >> 16);
9371 printf (" IDENT %#06lx self-contained %#06lx",
9372 option
->info
& OGP_GROUP
,
9373 (option
->info
& OGP_SELF
) >> 16);
9376 /* This shouldn't happen. */
9377 printf (" %3d ??? %d %lx",
9378 option
->kind
, option
->section
, option
->info
);
9382 len
= sizeof (*eopt
);
9383 while (len
< option
->size
)
9384 if (((char *) option
)[len
] >= ' '
9385 && ((char *) option
)[len
] < 0x7f)
9386 printf ("%c", ((char *) option
)[len
++]);
9388 printf ("\\%03o", ((char *) option
)[len
++]);
9390 fputs ("\n", stdout
);
9398 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9400 Elf32_Conflict
*iconf
;
9403 if (dynamic_symbols
== NULL
)
9405 error (_("conflict list found without a dynamic symbol table\n"));
9409 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
9412 error (_("Out of memory\n"));
9418 Elf32_External_Conflict
*econf32
;
9420 econf32
= get_data (NULL
, file
, conflicts_offset
,
9421 conflictsno
, sizeof (*econf32
), _("conflict"));
9425 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9426 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9432 Elf64_External_Conflict
*econf64
;
9434 econf64
= get_data (NULL
, file
, conflicts_offset
,
9435 conflictsno
, sizeof (*econf64
), _("conflict"));
9439 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9440 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9445 printf (_("\nSection '.conflict' contains %lu entries:\n"),
9446 (unsigned long) conflictsno
);
9447 puts (_(" Num: Index Value Name"));
9449 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9451 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
9453 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9454 print_vma (psym
->st_value
, FULL_HEX
);
9456 if (VALID_DYNAMIC_NAME (psym
->st_name
))
9457 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
9459 printf ("<corrupt: %14ld>", psym
->st_name
);
9470 process_gnu_liblist (FILE *file
)
9472 Elf_Internal_Shdr
*section
, *string_sec
;
9473 Elf32_External_Lib
*elib
;
9482 for (i
= 0, section
= section_headers
;
9483 i
< elf_header
.e_shnum
;
9486 switch (section
->sh_type
)
9488 case SHT_GNU_LIBLIST
:
9489 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
9492 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
9497 string_sec
= SECTION_HEADER (section
->sh_link
);
9499 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
9500 string_sec
->sh_size
, _("liblist string table"));
9501 strtab_size
= string_sec
->sh_size
;
9504 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9510 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9511 SECTION_NAME (section
),
9512 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9514 puts (" Library Time Stamp Checksum Version Flags");
9516 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9524 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9525 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9526 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9527 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9528 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9530 tmp
= gmtime (&time
);
9531 snprintf (timebuf
, sizeof (timebuf
),
9532 "%04u-%02u-%02uT%02u:%02u:%02u",
9533 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9534 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9536 printf ("%3lu: ", (unsigned long) cnt
);
9538 printf ("%-20s", liblist
.l_name
< strtab_size
9539 ? strtab
+ liblist
.l_name
: "<corrupt>");
9541 printf ("%-20.20s", liblist
.l_name
< strtab_size
9542 ? strtab
+ liblist
.l_name
: "<corrupt>");
9543 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9544 liblist
.l_version
, liblist
.l_flags
);
9555 get_note_type (unsigned e_type
)
9557 static char buff
[64];
9559 if (elf_header
.e_type
== ET_CORE
)
9563 return _("NT_AUXV (auxiliary vector)");
9565 return _("NT_PRSTATUS (prstatus structure)");
9567 return _("NT_FPREGSET (floating point registers)");
9569 return _("NT_PRPSINFO (prpsinfo structure)");
9571 return _("NT_TASKSTRUCT (task structure)");
9573 return _("NT_PRXFPREG (user_xfpregs structure)");
9575 return _("NT_PPC_VMX (ppc Altivec registers)");
9577 return _("NT_PSTATUS (pstatus structure)");
9579 return _("NT_FPREGS (floating point registers)");
9581 return _("NT_PSINFO (psinfo structure)");
9583 return _("NT_LWPSTATUS (lwpstatus_t structure)");
9585 return _("NT_LWPSINFO (lwpsinfo_t structure)");
9586 case NT_WIN32PSTATUS
:
9587 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9595 return _("NT_VERSION (version)");
9597 return _("NT_ARCH (architecture)");
9602 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9607 get_gnu_elf_note_type (unsigned e_type
)
9609 static char buff
[64];
9613 case NT_GNU_ABI_TAG
:
9614 return _("NT_GNU_ABI_TAG (ABI version tag)");
9616 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
9617 case NT_GNU_BUILD_ID
:
9618 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
9623 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9628 get_netbsd_elfcore_note_type (unsigned e_type
)
9630 static char buff
[64];
9632 if (e_type
== NT_NETBSDCORE_PROCINFO
)
9634 /* NetBSD core "procinfo" structure. */
9635 return _("NetBSD procinfo structure");
9638 /* As of Jan 2002 there are no other machine-independent notes
9639 defined for NetBSD core files. If the note type is less
9640 than the start of the machine-dependent note types, we don't
9643 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
9645 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9649 switch (elf_header
.e_machine
)
9651 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9652 and PT_GETFPREGS == mach+2. */
9657 case EM_SPARC32PLUS
:
9661 case NT_NETBSDCORE_FIRSTMACH
+0:
9662 return _("PT_GETREGS (reg structure)");
9663 case NT_NETBSDCORE_FIRSTMACH
+2:
9664 return _("PT_GETFPREGS (fpreg structure)");
9670 /* On all other arch's, PT_GETREGS == mach+1 and
9671 PT_GETFPREGS == mach+3. */
9675 case NT_NETBSDCORE_FIRSTMACH
+1:
9676 return _("PT_GETREGS (reg structure)");
9677 case NT_NETBSDCORE_FIRSTMACH
+3:
9678 return _("PT_GETFPREGS (fpreg structure)");
9684 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
9685 e_type
- NT_NETBSDCORE_FIRSTMACH
);
9689 /* Note that by the ELF standard, the name field is already null byte
9690 terminated, and namesz includes the terminating null byte.
9691 I.E. the value of namesz for the name "FSF" is 4.
9693 If the value of namesz is zero, there is no name present. */
9695 process_note (Elf_Internal_Note
*pnote
)
9697 const char *name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
9700 if (pnote
->namesz
== 0)
9701 /* If there is no note name, then use the default set of
9702 note type strings. */
9703 nt
= get_note_type (pnote
->type
);
9705 else if (const_strneq (pnote
->namedata
, "GNU"))
9706 /* GNU-specific object file notes. */
9707 nt
= get_gnu_elf_note_type (pnote
->type
);
9709 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
9710 /* NetBSD-specific core file notes. */
9711 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
9713 else if (strneq (pnote
->namedata
, "SPU/", 4))
9715 /* SPU-specific core file notes. */
9716 nt
= pnote
->namedata
+ 4;
9721 /* Don't recognize this note name; just use the default set of
9722 note type strings. */
9723 nt
= get_note_type (pnote
->type
);
9725 printf (" %s\t\t0x%08lx\t%s\n", name
, pnote
->descsz
, nt
);
9731 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
9733 Elf_External_Note
*pnotes
;
9734 Elf_External_Note
*external
;
9740 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
9746 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9747 (unsigned long) offset
, (unsigned long) length
);
9748 printf (_(" Owner\t\tData size\tDescription\n"));
9750 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
9752 Elf_External_Note
*next
;
9753 Elf_Internal_Note inote
;
9756 inote
.type
= BYTE_GET (external
->type
);
9757 inote
.namesz
= BYTE_GET (external
->namesz
);
9758 inote
.namedata
= external
->name
;
9759 inote
.descsz
= BYTE_GET (external
->descsz
);
9760 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
9761 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
9763 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
9765 if (((char *) next
) > (((char *) pnotes
) + length
))
9767 warn (_("corrupt note found at offset %lx into core notes\n"),
9768 (long)((char *)external
- (char *)pnotes
));
9769 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
9770 inote
.type
, inote
.namesz
, inote
.descsz
);
9776 /* Verify that name is null terminated. It appears that at least
9777 one version of Linux (RedHat 6.0) generates corefiles that don't
9778 comply with the ELF spec by failing to include the null byte in
9780 if (inote
.namedata
[inote
.namesz
] != '\0')
9782 temp
= malloc (inote
.namesz
+ 1);
9786 error (_("Out of memory\n"));
9791 strncpy (temp
, inote
.namedata
, inote
.namesz
);
9792 temp
[inote
.namesz
] = 0;
9794 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9795 inote
.namedata
= temp
;
9798 res
&= process_note (& inote
);
9813 process_corefile_note_segments (FILE *file
)
9815 Elf_Internal_Phdr
*segment
;
9819 if (! get_program_headers (file
))
9822 for (i
= 0, segment
= program_headers
;
9823 i
< elf_header
.e_phnum
;
9826 if (segment
->p_type
== PT_NOTE
)
9827 res
&= process_corefile_note_segment (file
,
9828 (bfd_vma
) segment
->p_offset
,
9829 (bfd_vma
) segment
->p_filesz
);
9836 process_note_sections (FILE *file
)
9838 Elf_Internal_Shdr
*section
;
9842 for (i
= 0, section
= section_headers
;
9843 i
< elf_header
.e_shnum
;
9845 if (section
->sh_type
== SHT_NOTE
)
9846 res
&= process_corefile_note_segment (file
,
9847 (bfd_vma
) section
->sh_offset
,
9848 (bfd_vma
) section
->sh_size
);
9854 process_notes (FILE *file
)
9856 /* If we have not been asked to display the notes then do nothing. */
9860 if (elf_header
.e_type
!= ET_CORE
)
9861 return process_note_sections (file
);
9863 /* No program headers means no NOTE segment. */
9864 if (elf_header
.e_phnum
> 0)
9865 return process_corefile_note_segments (file
);
9867 printf (_("No note segments present in the core file.\n"));
9872 process_arch_specific (FILE *file
)
9877 switch (elf_header
.e_machine
)
9880 return process_arm_specific (file
);
9882 case EM_MIPS_RS3_LE
:
9883 return process_mips_specific (file
);
9886 return process_power_specific (file
);
9895 get_file_header (FILE *file
)
9897 /* Read in the identity array. */
9898 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
9901 /* Determine how to read the rest of the header. */
9902 switch (elf_header
.e_ident
[EI_DATA
])
9904 default: /* fall through */
9905 case ELFDATANONE
: /* fall through */
9907 byte_get
= byte_get_little_endian
;
9908 byte_put
= byte_put_little_endian
;
9911 byte_get
= byte_get_big_endian
;
9912 byte_put
= byte_put_big_endian
;
9916 /* For now we only support 32 bit and 64 bit ELF files. */
9917 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
9919 /* Read in the rest of the header. */
9922 Elf32_External_Ehdr ehdr32
;
9924 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
9927 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
9928 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
9929 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
9930 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
9931 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
9932 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
9933 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
9934 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
9935 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
9936 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
9937 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
9938 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
9939 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
9943 Elf64_External_Ehdr ehdr64
;
9945 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9946 we will not be able to cope with the 64bit data found in
9947 64 ELF files. Detect this now and abort before we start
9948 overwriting things. */
9949 if (sizeof (bfd_vma
) < 8)
9951 error (_("This instance of readelf has been built without support for a\n\
9952 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9956 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
9959 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
9960 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
9961 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
9962 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
9963 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
9964 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
9965 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
9966 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
9967 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
9968 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
9969 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
9970 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
9971 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
9974 if (elf_header
.e_shoff
)
9976 /* There may be some extensions in the first section header. Don't
9977 bomb if we can't read it. */
9979 get_32bit_section_headers (file
, 1);
9981 get_64bit_section_headers (file
, 1);
9987 /* Process one ELF object file according to the command line options.
9988 This file may actually be stored in an archive. The file is
9989 positioned at the start of the ELF object. */
9992 process_object (char *file_name
, FILE *file
)
9996 if (! get_file_header (file
))
9998 error (_("%s: Failed to read file header\n"), file_name
);
10002 /* Initialise per file variables. */
10003 for (i
= ARRAY_SIZE (version_info
); i
--;)
10004 version_info
[i
] = 0;
10006 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
10007 dynamic_info
[i
] = 0;
10009 /* Process the file. */
10011 printf (_("\nFile: %s\n"), file_name
);
10013 /* Initialise the dump_sects array from the cmdline_dump_sects array.
10014 Note we do this even if cmdline_dump_sects is empty because we
10015 must make sure that the dump_sets array is zeroed out before each
10016 object file is processed. */
10017 if (num_dump_sects
> num_cmdline_dump_sects
)
10018 memset (dump_sects
, 0, num_dump_sects
* sizeof (* dump_sects
));
10020 if (num_cmdline_dump_sects
> 0)
10022 if (num_dump_sects
== 0)
10023 /* A sneaky way of allocating the dump_sects array. */
10024 request_dump_bynumber (num_cmdline_dump_sects
, 0);
10026 assert (num_dump_sects
>= num_cmdline_dump_sects
);
10027 memcpy (dump_sects
, cmdline_dump_sects
,
10028 num_cmdline_dump_sects
* sizeof (* dump_sects
));
10031 if (! process_file_header ())
10034 if (! process_section_headers (file
))
10036 /* Without loaded section headers we cannot process lots of
10038 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10040 if (! do_using_dynamic
)
10041 do_syms
= do_reloc
= 0;
10044 if (! process_section_groups (file
))
10046 /* Without loaded section groups we cannot process unwind. */
10050 if (process_program_headers (file
))
10051 process_dynamic_section (file
);
10053 process_relocs (file
);
10055 process_unwind (file
);
10057 process_symbol_table (file
);
10059 process_syminfo (file
);
10061 process_version_sections (file
);
10063 process_section_contents (file
);
10065 process_notes (file
);
10067 process_gnu_liblist (file
);
10069 process_arch_specific (file
);
10071 if (program_headers
)
10073 free (program_headers
);
10074 program_headers
= NULL
;
10077 if (section_headers
)
10079 free (section_headers
);
10080 section_headers
= NULL
;
10085 free (string_table
);
10086 string_table
= NULL
;
10087 string_table_length
= 0;
10090 if (dynamic_strings
)
10092 free (dynamic_strings
);
10093 dynamic_strings
= NULL
;
10094 dynamic_strings_length
= 0;
10097 if (dynamic_symbols
)
10099 free (dynamic_symbols
);
10100 dynamic_symbols
= NULL
;
10101 num_dynamic_syms
= 0;
10104 if (dynamic_syminfo
)
10106 free (dynamic_syminfo
);
10107 dynamic_syminfo
= NULL
;
10110 if (section_headers_groups
)
10112 free (section_headers_groups
);
10113 section_headers_groups
= NULL
;
10116 if (section_groups
)
10118 struct group_list
*g
, *next
;
10120 for (i
= 0; i
< group_count
; i
++)
10122 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
10129 free (section_groups
);
10130 section_groups
= NULL
;
10133 free_debug_memory ();
10138 /* Process an ELF archive.
10139 On entry the file is positioned just after the ARMAG string. */
10142 process_archive (char *file_name
, FILE *file
)
10144 struct ar_hdr arhdr
;
10146 unsigned long size
;
10147 unsigned long index_num
= 0;
10148 unsigned long *index_array
= NULL
;
10149 char *sym_table
= NULL
;
10150 unsigned long sym_size
= 0;
10151 char *longnames
= NULL
;
10152 unsigned long longnames_size
= 0;
10153 size_t file_name_size
;
10158 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
10159 if (got
!= sizeof arhdr
)
10164 error (_("%s: failed to read archive header\n"), file_name
);
10168 /* See if this is the archive symbol table. */
10169 if (const_strneq (arhdr
.ar_name
, "/ ")
10170 || const_strneq (arhdr
.ar_name
, "/SYM64/ "))
10172 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
10173 size
= size
+ (size
& 1);
10175 if (do_archive_index
)
10178 /* A buffer used to hold numbers read in from an archive index.
10179 These are always 4 bytes long and stored in big-endian format. */
10180 #define SIZEOF_AR_INDEX_NUMBERS 4
10181 unsigned char integer_buffer
[SIZEOF_AR_INDEX_NUMBERS
];
10182 unsigned char * index_buffer
;
10184 /* Check the size of the archive index. */
10185 if (size
< SIZEOF_AR_INDEX_NUMBERS
)
10187 error (_("%s: the archive index is empty\n"), file_name
);
10191 /* Read the numer of entries in the archive index. */
10192 got
= fread (integer_buffer
, 1, sizeof integer_buffer
, file
);
10193 if (got
!= sizeof (integer_buffer
))
10195 error (_("%s: failed to read archive index\n"), file_name
);
10198 index_num
= byte_get_big_endian (integer_buffer
, sizeof integer_buffer
);
10199 size
-= SIZEOF_AR_INDEX_NUMBERS
;
10201 /* Read in the archive index. */
10202 if (size
< index_num
* SIZEOF_AR_INDEX_NUMBERS
)
10204 error (_("%s: the archive index is supposed to have %ld entries, but the size in the header is too small\n"),
10205 file_name
, index_num
);
10208 index_buffer
= malloc (index_num
* SIZEOF_AR_INDEX_NUMBERS
);
10209 if (index_buffer
== NULL
)
10211 error (_("Out of memory whilst trying to read archive symbol index\n"));
10214 got
= fread (index_buffer
, SIZEOF_AR_INDEX_NUMBERS
, index_num
, file
);
10215 if (got
!= index_num
)
10217 free (index_buffer
);
10218 error (_("%s: failed to read archive index\n"), file_name
);
10222 size
-= index_num
* SIZEOF_AR_INDEX_NUMBERS
;
10224 /* Convert the index numbers into the host's numeric format. */
10225 index_array
= malloc (index_num
* sizeof (* index_array
));
10226 if (index_array
== NULL
)
10228 free (index_buffer
);
10229 error (_("Out of memory whilst trying to convert the archive symbol index\n"));
10233 for (i
= 0; i
< index_num
; i
++)
10234 index_array
[i
] = byte_get_big_endian ((unsigned char *)(index_buffer
+ (i
* SIZEOF_AR_INDEX_NUMBERS
)),
10235 SIZEOF_AR_INDEX_NUMBERS
);
10236 free (index_buffer
);
10238 /* The remaining space in the header is taken up by the symbol table. */
10241 error (_("%s: the archive has an index but no symbols\n"), file_name
);
10245 sym_table
= malloc (size
);
10247 if (sym_table
== NULL
)
10249 error (_("Out of memory whilst trying to read archive index symbol table\n"));
10253 got
= fread (sym_table
, 1, size
, file
);
10256 error (_("%s: failed to read archive index symbol table\n"), file_name
);
10263 if (fseek (file
, size
, SEEK_CUR
) != 0)
10265 error (_("%s: failed to skip archive symbol table\n"), file_name
);
10270 got
= fread (& arhdr
, 1, sizeof arhdr
, file
);
10271 if (got
!= sizeof arhdr
)
10279 error (_("%s: failed to read archive header following archive index\n"), file_name
);
10284 else if (do_archive_index
)
10285 printf (_("%s has no archive index\n"), file_name
);
10287 if (const_strneq (arhdr
.ar_name
, "// "))
10289 /* This is the archive string table holding long member
10292 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
10293 longnames
= malloc (longnames_size
);
10294 if (longnames
== NULL
)
10296 error (_("Out of memory reading long symbol names in archive\n"));
10301 if (fread (longnames
, longnames_size
, 1, file
) != 1)
10304 error (_("%s: failed to read long symbol name string table\n"), file_name
);
10309 if ((longnames_size
& 1) != 0)
10312 got
= fread (& arhdr
, 1, sizeof arhdr
, file
);
10313 if (got
!= sizeof arhdr
)
10319 error (_("%s: failed to read archive header following long symbol names\n"), file_name
);
10326 if (do_archive_index
)
10328 if (sym_table
== NULL
)
10329 error (_("%s: unable to dump the index as none was found\n"), file_name
);
10332 unsigned int i
, j
, k
, l
;
10334 unsigned long current_pos
;
10336 printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
10337 file_name
, index_num
, sym_size
);
10338 current_pos
= ftell (file
);
10340 for (i
= l
= 0; i
< index_num
; i
++)
10342 if ((i
== 0) || ((i
> 0) && (index_array
[i
] != index_array
[i
- 1])))
10344 if (fseek (file
, index_array
[i
], SEEK_SET
) != 0)
10346 error (_("%s: failed to seek to next file name\n"), file_name
);
10350 got
= fread (elf_name
, 1, 16, file
);
10353 error (_("%s: failed to read file name\n"), file_name
);
10358 if (elf_name
[0] == '/')
10360 /* We have a long name. */
10361 k
= j
= strtoul (elf_name
+ 1, NULL
, 10);
10362 while ((j
< longnames_size
) && (longnames
[j
] != '/'))
10364 longnames
[j
] = '\0';
10365 printf (_("Binary %s contains:\n"), longnames
+ k
);
10366 longnames
[j
] = '/';
10371 while ((elf_name
[j
] != '/') && (j
< 16))
10373 elf_name
[j
] = '\0';
10374 printf(_("Binary %s contains:\n"), elf_name
);
10379 error (_("%s: end of the symbol table reached before the end of the index\n"),
10383 printf ("\t%s\n", sym_table
+ l
);
10384 l
+= strlen (sym_table
+ l
) + 1;
10388 error (_("%s: symbols remain in the index symbol table, but without corresponding entries in the index table\n"),
10391 free (index_array
);
10392 index_array
= NULL
;
10395 if (fseek (file
, current_pos
, SEEK_SET
) != 0)
10397 error (_("%s: failed to seek back to start of object files in the archive\n"), file_name
);
10402 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
10403 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
10404 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
10405 && !do_section_groups
)
10406 return 0; /* Archive index only. */
10409 file_name_size
= strlen (file_name
);
10418 if (arhdr
.ar_name
[0] == '/')
10422 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
10423 if (off
>= longnames_size
)
10425 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
10430 name
= longnames
+ off
;
10431 nameend
= memchr (name
, '/', longnames_size
- off
);
10435 name
= arhdr
.ar_name
;
10436 nameend
= memchr (name
, '/', 16);
10439 if (nameend
== NULL
)
10441 error (_("%s: bad archive file name\n"), file_name
);
10446 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
10447 if (namealc
== NULL
)
10449 error (_("Out of memory\n"));
10454 memcpy (namealc
, file_name
, file_name_size
);
10455 namealc
[file_name_size
] = '(';
10456 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
10457 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
10458 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
10460 archive_file_offset
= ftell (file
);
10461 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
10463 ret
|= process_object (namealc
, file
);
10468 (archive_file_offset
10469 + archive_file_size
10470 + (archive_file_size
& 1)),
10473 error (_("%s: failed to seek to next archive header\n"), file_name
);
10478 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
10479 if (got
!= sizeof arhdr
)
10484 error (_("%s: failed to read archive header\n"), file_name
);
10491 if (index_array
!= NULL
)
10492 free (index_array
);
10493 if (sym_table
!= NULL
)
10495 if (longnames
!= NULL
)
10502 process_file (char *file_name
)
10505 struct stat statbuf
;
10506 char armag
[SARMAG
];
10509 if (stat (file_name
, &statbuf
) < 0)
10511 if (errno
== ENOENT
)
10512 error (_("'%s': No such file\n"), file_name
);
10514 error (_("Could not locate '%s'. System error message: %s\n"),
10515 file_name
, strerror (errno
));
10519 if (! S_ISREG (statbuf
.st_mode
))
10521 error (_("'%s' is not an ordinary file\n"), file_name
);
10525 file
= fopen (file_name
, "rb");
10528 error (_("Input file '%s' is not readable.\n"), file_name
);
10532 if (fread (armag
, SARMAG
, 1, file
) != 1)
10534 error (_("%s: Failed to read file's magic number\n"), file_name
);
10539 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
10540 ret
= process_archive (file_name
, file
);
10543 if (do_archive_index
)
10544 error (_("File %s is not an archive so its index cannot be displayed.\n"),
10548 archive_file_size
= archive_file_offset
= 0;
10549 ret
= process_object (file_name
, file
);
10557 #ifdef SUPPORT_DISASSEMBLY
10558 /* Needed by the i386 disassembler. For extra credit, someone could
10559 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10563 print_address (unsigned int addr
, FILE *outfile
)
10565 fprintf (outfile
,"0x%8.8x", addr
);
10568 /* Needed by the i386 disassembler. */
10570 db_task_printsym (unsigned int addr
)
10572 print_address (addr
, stderr
);
10577 main (int argc
, char **argv
)
10581 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10582 setlocale (LC_MESSAGES
, "");
10584 #if defined (HAVE_SETLOCALE)
10585 setlocale (LC_CTYPE
, "");
10587 bindtextdomain (PACKAGE
, LOCALEDIR
);
10588 textdomain (PACKAGE
);
10590 expandargv (&argc
, &argv
);
10592 parse_args (argc
, argv
);
10594 if (num_dump_sects
> 0)
10596 /* Make a copy of the dump_sects array. */
10597 cmdline_dump_sects
= malloc (num_dump_sects
* sizeof (* dump_sects
));
10598 if (cmdline_dump_sects
== NULL
)
10599 error (_("Out of memory allocating dump request table.\n"));
10602 memcpy (cmdline_dump_sects
, dump_sects
,
10603 num_dump_sects
* sizeof (* dump_sects
));
10604 num_cmdline_dump_sects
= num_dump_sects
;
10608 if (optind
< (argc
- 1))
10612 while (optind
< argc
)
10613 err
|= process_file (argv
[optind
++]);
10615 if (dump_sects
!= NULL
)
10617 if (cmdline_dump_sects
!= NULL
)
10618 free (cmdline_dump_sects
);