1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 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 is_32bit_elf
;
209 struct group_list
*next
;
210 unsigned int section_index
;
215 struct group_list
*root
;
216 unsigned int group_index
;
219 static size_t group_count
;
220 static struct group
*section_groups
;
221 static struct group
**section_headers_groups
;
224 /* Flag bits indicating particular types of dump. */
225 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
226 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
227 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
228 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
230 typedef unsigned char dump_type
;
232 /* A linked list of the section names for which dumps were requested. */
233 struct dump_list_entry
237 struct dump_list_entry
*next
;
239 static struct dump_list_entry
*dump_sects_byname
;
241 /* A dynamic array of flags indicating for which sections a dump
242 has been requested via command line switches. */
243 static dump_type
* cmdline_dump_sects
= NULL
;
244 static unsigned int num_cmdline_dump_sects
= 0;
246 /* A dynamic array of flags indicating for which sections a dump of
247 some kind has been requested. It is reset on a per-object file
248 basis and then initialised from the cmdline_dump_sects array,
249 the results of interpreting the -w switch, and the
250 dump_sects_byname list. */
251 static dump_type
* dump_sects
= NULL
;
252 static unsigned int num_dump_sects
= 0;
255 /* How to print a vma value. */
256 typedef enum print_mode
268 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
272 #define SECTION_NAME(X) \
273 ((X) == NULL ? "<none>" \
274 : string_table == NULL ? "<no-name>" \
275 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
276 : string_table + (X)->sh_name))
278 /* Given st_shndx I, map to section_headers index. */
279 #define SECTION_HEADER_INDEX(I) \
280 ((I) < SHN_LORESERVE \
282 : ((I) <= SHN_HIRESERVE \
284 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
286 /* Reverse of the above. */
287 #define SECTION_HEADER_NUM(N) \
288 ((N) < SHN_LORESERVE \
290 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
292 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
294 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
296 #define BYTE_GET(field) byte_get (field, sizeof (field))
298 #define GET_ELF_SYMBOLS(file, section) \
299 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
300 : get_64bit_elf_symbols (file, section))
302 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
303 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
304 already been called and verified that the string exists. */
305 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
307 /* This is just a bit of syntatic sugar. */
308 #define streq(a,b) (strcmp ((a), (b)) == 0)
309 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
310 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
313 get_data (void *var
, FILE *file
, long offset
, size_t size
, size_t nmemb
,
318 if (size
== 0 || nmemb
== 0)
321 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
323 error (_("Unable to seek to 0x%lx for %s\n"),
324 archive_file_offset
+ offset
, reason
);
331 /* Check for overflow. */
332 if (nmemb
< (~(size_t) 0 - 1) / size
)
333 /* + 1 so that we can '\0' terminate invalid string table sections. */
334 mvar
= malloc (size
* nmemb
+ 1);
338 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
339 (unsigned long)(size
* nmemb
), reason
);
343 ((char *) mvar
)[size
* nmemb
] = '\0';
346 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
348 error (_("Unable to read in 0x%lx bytes of %s\n"),
349 (unsigned long)(size
* nmemb
), reason
);
359 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
364 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
365 field
[6] = ((value
>> 24) >> 24) & 0xff;
366 field
[5] = ((value
>> 24) >> 16) & 0xff;
367 field
[4] = ((value
>> 24) >> 8) & 0xff;
370 field
[3] = (value
>> 24) & 0xff;
371 field
[2] = (value
>> 16) & 0xff;
374 field
[1] = (value
>> 8) & 0xff;
377 field
[0] = value
& 0xff;
381 error (_("Unhandled data length: %d\n"), size
);
386 #if defined BFD64 && !BFD_HOST_64BIT_LONG
388 print_dec_vma (bfd_vma vma
, int is_signed
)
394 if (is_signed
&& (bfd_signed_vma
) vma
< 0)
403 *bufp
++ = '0' + vma
% 10;
415 print_hex_vma (bfd_vma vma
)
423 char digit
= '0' + (vma
& 0x0f);
425 digit
+= 'a' - '0' - 10;
438 /* Print a VMA value. */
440 print_vma (bfd_vma vma
, print_mode mode
)
449 return printf ("0x%8.8lx", (unsigned long) vma
);
452 return printf ("%8.8lx", (unsigned long) vma
);
456 return printf ("%5ld", (long) vma
);
460 return printf ("0x%lx", (unsigned long) vma
);
463 return printf ("%lx", (unsigned long) vma
);
466 return printf ("%ld", (unsigned long) vma
);
469 return printf ("%lu", (unsigned long) vma
);
492 #if BFD_HOST_64BIT_LONG
493 return nc
+ printf ("%lx", vma
);
495 return nc
+ print_hex_vma (vma
);
499 #if BFD_HOST_64BIT_LONG
500 return printf ("%ld", vma
);
502 return print_dec_vma (vma
, 1);
506 #if BFD_HOST_64BIT_LONG
508 return printf ("%5ld", vma
);
510 return printf ("%#lx", vma
);
513 return printf ("%5ld", _bfd_int64_low (vma
));
515 return print_hex_vma (vma
);
519 #if BFD_HOST_64BIT_LONG
520 return printf ("%lu", vma
);
522 return print_dec_vma (vma
, 0);
530 /* Display a symbol on stdout. If do_wide is not true then
531 format the symbol to be at most WIDTH characters,
532 truncating as necessary. If WIDTH is negative then
533 format the string to be exactly - WIDTH characters,
534 truncating or padding as necessary. */
537 print_symbol (int width
, const char *symbol
)
540 printf ("%s", symbol
);
542 printf ("%-*.*s", width
, width
, symbol
);
544 printf ("%-.*s", width
, symbol
);
548 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
553 field
[7] = value
& 0xff;
554 field
[6] = (value
>> 8) & 0xff;
555 field
[5] = (value
>> 16) & 0xff;
556 field
[4] = (value
>> 24) & 0xff;
561 field
[3] = value
& 0xff;
562 field
[2] = (value
>> 8) & 0xff;
566 field
[1] = value
& 0xff;
570 field
[0] = value
& 0xff;
574 error (_("Unhandled data length: %d\n"), size
);
579 /* Return a pointer to section NAME, or NULL if no such section exists. */
581 static Elf_Internal_Shdr
*
582 find_section (const char *name
)
586 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
587 if (streq (SECTION_NAME (section_headers
+ i
), name
))
588 return section_headers
+ i
;
593 /* Guess the relocation size commonly used by the specific machines. */
596 guess_is_rela (unsigned long e_machine
)
600 /* Targets that use REL relocations. */
616 /* Targets that use RELA relocations. */
620 case EM_ALTERA_NIOS2
:
645 case EM_CYGNUS_MN10200
:
647 case EM_CYGNUS_MN10300
:
688 warn (_("Don't know about relocations on this machine architecture\n"));
694 slurp_rela_relocs (FILE *file
,
695 unsigned long rel_offset
,
696 unsigned long rel_size
,
697 Elf_Internal_Rela
**relasp
,
698 unsigned long *nrelasp
)
700 Elf_Internal_Rela
*relas
;
701 unsigned long nrelas
;
706 Elf32_External_Rela
*erelas
;
708 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
712 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
714 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
719 error (_("out of memory parsing relocs\n"));
723 for (i
= 0; i
< nrelas
; i
++)
725 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
726 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
727 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
734 Elf64_External_Rela
*erelas
;
736 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
740 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
742 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
747 error (_("out of memory parsing relocs\n"));
751 for (i
= 0; i
< nrelas
; i
++)
753 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
754 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
755 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
766 slurp_rel_relocs (FILE *file
,
767 unsigned long rel_offset
,
768 unsigned long rel_size
,
769 Elf_Internal_Rela
**relsp
,
770 unsigned long *nrelsp
)
772 Elf_Internal_Rela
*rels
;
778 Elf32_External_Rel
*erels
;
780 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
784 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
786 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
791 error (_("out of memory parsing relocs\n"));
795 for (i
= 0; i
< nrels
; i
++)
797 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
798 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
799 rels
[i
].r_addend
= 0;
806 Elf64_External_Rel
*erels
;
808 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
812 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
814 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
819 error (_("out of memory parsing relocs\n"));
823 for (i
= 0; i
< nrels
; i
++)
825 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
826 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
827 rels
[i
].r_addend
= 0;
837 /* Display the contents of the relocation data found at the specified
841 dump_relocations (FILE *file
,
842 unsigned long rel_offset
,
843 unsigned long rel_size
,
844 Elf_Internal_Sym
*symtab
,
847 unsigned long strtablen
,
851 Elf_Internal_Rela
*rels
;
854 if (is_rela
== UNKNOWN
)
855 is_rela
= guess_is_rela (elf_header
.e_machine
);
859 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
864 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
873 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
875 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
880 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
882 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
890 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
892 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
897 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
899 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
903 for (i
= 0; i
< rel_size
; i
++)
906 const char *rtype2
= NULL
;
907 const char *rtype3
= NULL
;
910 bfd_vma symtab_index
;
915 offset
= rels
[i
].r_offset
;
916 info
= rels
[i
].r_info
;
920 type
= ELF32_R_TYPE (info
);
921 symtab_index
= ELF32_R_SYM (info
);
925 /* The #ifdef BFD64 below is to prevent a compile time warning.
926 We know that if we do not have a 64 bit data type that we
927 will never execute this code anyway. */
929 if (elf_header
.e_machine
== EM_MIPS
)
931 /* In little-endian objects, r_info isn't really a 64-bit
932 little-endian value: it has a 32-bit little-endian
933 symbol index followed by four individual byte fields.
934 Reorder INFO accordingly. */
935 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
936 info
= (((info
& 0xffffffff) << 32)
937 | ((info
>> 56) & 0xff)
938 | ((info
>> 40) & 0xff00)
939 | ((info
>> 24) & 0xff0000)
940 | ((info
>> 8) & 0xff000000));
941 type
= ELF64_MIPS_R_TYPE (info
);
942 type2
= ELF64_MIPS_R_TYPE2 (info
);
943 type3
= ELF64_MIPS_R_TYPE3 (info
);
945 else if (elf_header
.e_machine
== EM_SPARCV9
)
946 type
= ELF64_R_TYPE_ID (info
);
948 type
= ELF64_R_TYPE (info
);
950 symtab_index
= ELF64_R_SYM (info
);
956 #ifdef _bfd_int64_low
957 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
959 printf ("%8.8lx %8.8lx ", offset
, info
);
964 #ifdef _bfd_int64_low
966 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
967 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
968 _bfd_int64_high (offset
),
969 _bfd_int64_low (offset
),
970 _bfd_int64_high (info
),
971 _bfd_int64_low (info
));
974 ? "%16.16lx %16.16lx "
975 : "%12.12lx %12.12lx ",
980 switch (elf_header
.e_machine
)
988 rtype
= elf_m32r_reloc_type (type
);
993 rtype
= elf_i386_reloc_type (type
);
998 rtype
= elf_m68hc11_reloc_type (type
);
1002 rtype
= elf_m68k_reloc_type (type
);
1006 rtype
= elf_i960_reloc_type (type
);
1011 rtype
= elf_avr_reloc_type (type
);
1014 case EM_OLD_SPARCV9
:
1015 case EM_SPARC32PLUS
:
1018 rtype
= elf_sparc_reloc_type (type
);
1022 rtype
= elf_spu_reloc_type (type
);
1026 case EM_CYGNUS_V850
:
1027 rtype
= v850_reloc_type (type
);
1031 case EM_CYGNUS_D10V
:
1032 rtype
= elf_d10v_reloc_type (type
);
1036 case EM_CYGNUS_D30V
:
1037 rtype
= elf_d30v_reloc_type (type
);
1041 rtype
= elf_dlx_reloc_type (type
);
1045 rtype
= elf_sh_reloc_type (type
);
1049 case EM_CYGNUS_MN10300
:
1050 rtype
= elf_mn10300_reloc_type (type
);
1054 case EM_CYGNUS_MN10200
:
1055 rtype
= elf_mn10200_reloc_type (type
);
1059 case EM_CYGNUS_FR30
:
1060 rtype
= elf_fr30_reloc_type (type
);
1064 rtype
= elf_frv_reloc_type (type
);
1068 rtype
= elf_mcore_reloc_type (type
);
1072 rtype
= elf_mmix_reloc_type (type
);
1077 rtype
= elf_msp430_reloc_type (type
);
1081 rtype
= elf_ppc_reloc_type (type
);
1085 rtype
= elf_ppc64_reloc_type (type
);
1089 case EM_MIPS_RS3_LE
:
1090 rtype
= elf_mips_reloc_type (type
);
1093 rtype2
= elf_mips_reloc_type (type2
);
1094 rtype3
= elf_mips_reloc_type (type3
);
1099 rtype
= elf_alpha_reloc_type (type
);
1103 rtype
= elf_arm_reloc_type (type
);
1107 rtype
= elf_arc_reloc_type (type
);
1111 rtype
= elf_hppa_reloc_type (type
);
1117 rtype
= elf_h8_reloc_type (type
);
1122 rtype
= elf_or32_reloc_type (type
);
1127 rtype
= elf_pj_reloc_type (type
);
1130 rtype
= elf_ia64_reloc_type (type
);
1134 rtype
= elf_cris_reloc_type (type
);
1138 rtype
= elf_i860_reloc_type (type
);
1142 rtype
= elf_x86_64_reloc_type (type
);
1146 rtype
= i370_reloc_type (type
);
1151 rtype
= elf_s390_reloc_type (type
);
1155 rtype
= elf_score_reloc_type (type
);
1159 rtype
= elf_xstormy16_reloc_type (type
);
1163 rtype
= elf_crx_reloc_type (type
);
1167 rtype
= elf_vax_reloc_type (type
);
1172 rtype
= elf_ip2k_reloc_type (type
);
1176 rtype
= elf_iq2000_reloc_type (type
);
1181 rtype
= elf_xtensa_reloc_type (type
);
1185 rtype
= elf_m32c_reloc_type (type
);
1189 rtype
= elf_mt_reloc_type (type
);
1193 rtype
= elf_bfin_reloc_type (type
);
1197 rtype
= elf_mep_reloc_type (type
);
1201 rtype
= elf_cr16_reloc_type (type
);
1206 #ifdef _bfd_int64_low
1207 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1209 printf (_("unrecognized: %-7lx"), type
);
1212 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1214 if (elf_header
.e_machine
== EM_ALPHA
1216 && streq (rtype
, "R_ALPHA_LITUSE")
1219 switch (rels
[i
].r_addend
)
1221 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1222 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1223 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1224 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1225 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1226 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1227 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1228 default: rtype
= NULL
;
1231 printf (" (%s)", rtype
);
1235 printf (_("<unknown addend: %lx>"),
1236 (unsigned long) rels
[i
].r_addend
);
1239 else if (symtab_index
)
1241 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1242 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1245 Elf_Internal_Sym
*psym
;
1247 psym
= symtab
+ symtab_index
;
1250 print_vma (psym
->st_value
, LONG_HEX
);
1251 printf (is_32bit_elf
? " " : " ");
1253 if (psym
->st_name
== 0)
1255 const char *sec_name
= "<null>";
1258 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1260 bfd_vma sec_index
= (bfd_vma
) -1;
1262 if (psym
->st_shndx
< SHN_LORESERVE
)
1263 sec_index
= psym
->st_shndx
;
1264 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1265 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1268 if (sec_index
!= (bfd_vma
) -1)
1269 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1270 else if (psym
->st_shndx
== SHN_ABS
)
1272 else if (psym
->st_shndx
== SHN_COMMON
)
1273 sec_name
= "COMMON";
1274 else if (elf_header
.e_machine
== EM_MIPS
1275 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1276 sec_name
= "SCOMMON";
1277 else if (elf_header
.e_machine
== EM_MIPS
1278 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1279 sec_name
= "SUNDEF";
1280 else if (elf_header
.e_machine
== EM_X86_64
1281 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1282 sec_name
= "LARGE_COMMON";
1283 else if (elf_header
.e_machine
== EM_IA_64
1284 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1285 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1286 sec_name
= "ANSI_COM";
1289 sprintf (name_buf
, "<section 0x%x>",
1290 (unsigned int) psym
->st_shndx
);
1291 sec_name
= name_buf
;
1294 print_symbol (22, sec_name
);
1296 else if (strtab
== NULL
)
1297 printf (_("<string table index: %3ld>"), psym
->st_name
);
1298 else if (psym
->st_name
>= strtablen
)
1299 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1301 print_symbol (22, strtab
+ psym
->st_name
);
1304 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1309 printf ("%*c", is_32bit_elf
?
1310 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1311 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1314 if (elf_header
.e_machine
== EM_SPARCV9
1316 && streq (rtype
, "R_SPARC_OLO10"))
1317 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1321 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1323 printf (" Type2: ");
1326 #ifdef _bfd_int64_low
1327 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1329 printf (_("unrecognized: %-7lx"), type2
);
1332 printf ("%-17.17s", rtype2
);
1334 printf ("\n Type3: ");
1337 #ifdef _bfd_int64_low
1338 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1340 printf (_("unrecognized: %-7lx"), type3
);
1343 printf ("%-17.17s", rtype3
);
1355 get_mips_dynamic_type (unsigned long type
)
1359 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1360 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1361 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1362 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1363 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1364 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1365 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1366 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1367 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1368 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1369 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1370 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1371 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1372 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1373 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1374 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1375 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1376 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1377 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1378 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1379 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1380 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1381 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1382 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1383 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1384 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1385 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1386 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1387 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1388 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1389 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1390 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1391 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1392 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1393 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1394 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1395 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1396 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1397 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1398 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1399 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1400 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1401 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1408 get_sparc64_dynamic_type (unsigned long type
)
1412 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1419 get_ppc_dynamic_type (unsigned long type
)
1423 case DT_PPC_GOT
: return "PPC_GOT";
1430 get_ppc64_dynamic_type (unsigned long type
)
1434 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1435 case DT_PPC64_OPD
: return "PPC64_OPD";
1436 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1443 get_parisc_dynamic_type (unsigned long type
)
1447 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1448 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1449 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1450 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1451 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1452 case DT_HP_PREINIT
: return "HP_PREINIT";
1453 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1454 case DT_HP_NEEDED
: return "HP_NEEDED";
1455 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1456 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1457 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1458 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1459 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1460 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1461 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1462 case DT_HP_FILTERED
: return "HP_FILTERED";
1463 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1464 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1465 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1466 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1467 case DT_PLT
: return "PLT";
1468 case DT_PLT_SIZE
: return "PLT_SIZE";
1469 case DT_DLT
: return "DLT";
1470 case DT_DLT_SIZE
: return "DLT_SIZE";
1477 get_ia64_dynamic_type (unsigned long type
)
1481 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1488 get_alpha_dynamic_type (unsigned long type
)
1492 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1499 get_score_dynamic_type (unsigned long type
)
1503 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1504 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1505 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1506 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1507 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1508 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1516 get_dynamic_type (unsigned long type
)
1518 static char buff
[64];
1522 case DT_NULL
: return "NULL";
1523 case DT_NEEDED
: return "NEEDED";
1524 case DT_PLTRELSZ
: return "PLTRELSZ";
1525 case DT_PLTGOT
: return "PLTGOT";
1526 case DT_HASH
: return "HASH";
1527 case DT_STRTAB
: return "STRTAB";
1528 case DT_SYMTAB
: return "SYMTAB";
1529 case DT_RELA
: return "RELA";
1530 case DT_RELASZ
: return "RELASZ";
1531 case DT_RELAENT
: return "RELAENT";
1532 case DT_STRSZ
: return "STRSZ";
1533 case DT_SYMENT
: return "SYMENT";
1534 case DT_INIT
: return "INIT";
1535 case DT_FINI
: return "FINI";
1536 case DT_SONAME
: return "SONAME";
1537 case DT_RPATH
: return "RPATH";
1538 case DT_SYMBOLIC
: return "SYMBOLIC";
1539 case DT_REL
: return "REL";
1540 case DT_RELSZ
: return "RELSZ";
1541 case DT_RELENT
: return "RELENT";
1542 case DT_PLTREL
: return "PLTREL";
1543 case DT_DEBUG
: return "DEBUG";
1544 case DT_TEXTREL
: return "TEXTREL";
1545 case DT_JMPREL
: return "JMPREL";
1546 case DT_BIND_NOW
: return "BIND_NOW";
1547 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1548 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1549 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1550 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1551 case DT_RUNPATH
: return "RUNPATH";
1552 case DT_FLAGS
: return "FLAGS";
1554 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1555 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1557 case DT_CHECKSUM
: return "CHECKSUM";
1558 case DT_PLTPADSZ
: return "PLTPADSZ";
1559 case DT_MOVEENT
: return "MOVEENT";
1560 case DT_MOVESZ
: return "MOVESZ";
1561 case DT_FEATURE
: return "FEATURE";
1562 case DT_POSFLAG_1
: return "POSFLAG_1";
1563 case DT_SYMINSZ
: return "SYMINSZ";
1564 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1566 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1567 case DT_CONFIG
: return "CONFIG";
1568 case DT_DEPAUDIT
: return "DEPAUDIT";
1569 case DT_AUDIT
: return "AUDIT";
1570 case DT_PLTPAD
: return "PLTPAD";
1571 case DT_MOVETAB
: return "MOVETAB";
1572 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1574 case DT_VERSYM
: return "VERSYM";
1576 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1577 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1578 case DT_RELACOUNT
: return "RELACOUNT";
1579 case DT_RELCOUNT
: return "RELCOUNT";
1580 case DT_FLAGS_1
: return "FLAGS_1";
1581 case DT_VERDEF
: return "VERDEF";
1582 case DT_VERDEFNUM
: return "VERDEFNUM";
1583 case DT_VERNEED
: return "VERNEED";
1584 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1586 case DT_AUXILIARY
: return "AUXILIARY";
1587 case DT_USED
: return "USED";
1588 case DT_FILTER
: return "FILTER";
1590 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1591 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1592 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1593 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1594 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1595 case DT_GNU_HASH
: return "GNU_HASH";
1598 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1602 switch (elf_header
.e_machine
)
1605 case EM_MIPS_RS3_LE
:
1606 result
= get_mips_dynamic_type (type
);
1609 result
= get_sparc64_dynamic_type (type
);
1612 result
= get_ppc_dynamic_type (type
);
1615 result
= get_ppc64_dynamic_type (type
);
1618 result
= get_ia64_dynamic_type (type
);
1621 result
= get_alpha_dynamic_type (type
);
1624 result
= get_score_dynamic_type (type
);
1634 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1636 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1637 || (elf_header
.e_machine
== EM_PARISC
1638 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1642 switch (elf_header
.e_machine
)
1645 result
= get_parisc_dynamic_type (type
);
1655 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1659 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1666 get_file_type (unsigned e_type
)
1668 static char buff
[32];
1672 case ET_NONE
: return _("NONE (None)");
1673 case ET_REL
: return _("REL (Relocatable file)");
1674 case ET_EXEC
: return _("EXEC (Executable file)");
1675 case ET_DYN
: return _("DYN (Shared object file)");
1676 case ET_CORE
: return _("CORE (Core file)");
1679 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1680 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1681 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1682 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1684 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1690 get_machine_name (unsigned e_machine
)
1692 static char buff
[64]; /* XXX */
1696 case EM_NONE
: return _("None");
1697 case EM_M32
: return "WE32100";
1698 case EM_SPARC
: return "Sparc";
1699 case EM_SPU
: return "SPU";
1700 case EM_386
: return "Intel 80386";
1701 case EM_68K
: return "MC68000";
1702 case EM_88K
: return "MC88000";
1703 case EM_486
: return "Intel 80486";
1704 case EM_860
: return "Intel 80860";
1705 case EM_MIPS
: return "MIPS R3000";
1706 case EM_S370
: return "IBM System/370";
1707 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1708 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1709 case EM_PARISC
: return "HPPA";
1710 case EM_PPC_OLD
: return "Power PC (old)";
1711 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1712 case EM_960
: return "Intel 90860";
1713 case EM_PPC
: return "PowerPC";
1714 case EM_PPC64
: return "PowerPC64";
1715 case EM_V800
: return "NEC V800";
1716 case EM_FR20
: return "Fujitsu FR20";
1717 case EM_RH32
: return "TRW RH32";
1718 case EM_MCORE
: return "MCORE";
1719 case EM_ARM
: return "ARM";
1720 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1721 case EM_SH
: return "Renesas / SuperH SH";
1722 case EM_SPARCV9
: return "Sparc v9";
1723 case EM_TRICORE
: return "Siemens Tricore";
1724 case EM_ARC
: return "ARC";
1725 case EM_H8_300
: return "Renesas H8/300";
1726 case EM_H8_300H
: return "Renesas H8/300H";
1727 case EM_H8S
: return "Renesas H8S";
1728 case EM_H8_500
: return "Renesas H8/500";
1729 case EM_IA_64
: return "Intel IA-64";
1730 case EM_MIPS_X
: return "Stanford MIPS-X";
1731 case EM_COLDFIRE
: return "Motorola Coldfire";
1732 case EM_68HC12
: return "Motorola M68HC12";
1733 case EM_ALPHA
: return "Alpha";
1734 case EM_CYGNUS_D10V
:
1735 case EM_D10V
: return "d10v";
1736 case EM_CYGNUS_D30V
:
1737 case EM_D30V
: return "d30v";
1738 case EM_CYGNUS_M32R
:
1739 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1740 case EM_CYGNUS_V850
:
1741 case EM_V850
: return "NEC v850";
1742 case EM_CYGNUS_MN10300
:
1743 case EM_MN10300
: return "mn10300";
1744 case EM_CYGNUS_MN10200
:
1745 case EM_MN10200
: return "mn10200";
1746 case EM_CYGNUS_FR30
:
1747 case EM_FR30
: return "Fujitsu FR30";
1748 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1750 case EM_PJ
: return "picoJava";
1751 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1752 case EM_PCP
: return "Siemens PCP";
1753 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1754 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1755 case EM_STARCORE
: return "Motorola Star*Core processor";
1756 case EM_ME16
: return "Toyota ME16 processor";
1757 case EM_ST100
: return "STMicroelectronics ST100 processor";
1758 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1759 case EM_FX66
: return "Siemens FX66 microcontroller";
1760 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1761 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1762 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1763 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1764 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1765 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1766 case EM_SVX
: return "Silicon Graphics SVx";
1767 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1768 case EM_VAX
: return "Digital VAX";
1770 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1771 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1772 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1773 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1774 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1775 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1776 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1777 case EM_PRISM
: return "Vitesse Prism";
1778 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1780 case EM_S390
: return "IBM S/390";
1781 case EM_SCORE
: return "SUNPLUS S+Core";
1782 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1784 case EM_OR32
: return "OpenRISC";
1785 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1786 case EM_DLX
: return "OpenDLX";
1788 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1789 case EM_IQ2000
: return "Vitesse IQ2000";
1791 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1792 case EM_M32C
: return "Renesas M32c";
1793 case EM_MT
: return "Morpho Techologies MT processor";
1794 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1795 case EM_NIOS32
: return "Altera Nios";
1796 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1797 case EM_XC16X
: return "Infineon Technologies xc16x";
1798 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1799 case EM_CR16
: return "National Semiconductor's CR16";
1801 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
1807 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1812 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1813 e_flags
&= ~ EF_ARM_EABIMASK
;
1815 /* Handle "generic" ARM flags. */
1816 if (e_flags
& EF_ARM_RELEXEC
)
1818 strcat (buf
, ", relocatable executable");
1819 e_flags
&= ~ EF_ARM_RELEXEC
;
1822 if (e_flags
& EF_ARM_HASENTRY
)
1824 strcat (buf
, ", has entry point");
1825 e_flags
&= ~ EF_ARM_HASENTRY
;
1828 /* Now handle EABI specific flags. */
1832 strcat (buf
, ", <unrecognized EABI>");
1837 case EF_ARM_EABI_VER1
:
1838 strcat (buf
, ", Version1 EABI");
1843 /* Process flags one bit at a time. */
1844 flag
= e_flags
& - e_flags
;
1849 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1850 strcat (buf
, ", sorted symbol tables");
1860 case EF_ARM_EABI_VER2
:
1861 strcat (buf
, ", Version2 EABI");
1866 /* Process flags one bit at a time. */
1867 flag
= e_flags
& - e_flags
;
1872 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1873 strcat (buf
, ", sorted symbol tables");
1876 case EF_ARM_DYNSYMSUSESEGIDX
:
1877 strcat (buf
, ", dynamic symbols use segment index");
1880 case EF_ARM_MAPSYMSFIRST
:
1881 strcat (buf
, ", mapping symbols precede others");
1891 case EF_ARM_EABI_VER3
:
1892 strcat (buf
, ", Version3 EABI");
1895 case EF_ARM_EABI_VER4
:
1896 strcat (buf
, ", Version4 EABI");
1899 case EF_ARM_EABI_VER5
:
1900 strcat (buf
, ", Version5 EABI");
1906 /* Process flags one bit at a time. */
1907 flag
= e_flags
& - e_flags
;
1913 strcat (buf
, ", BE8");
1917 strcat (buf
, ", LE8");
1927 case EF_ARM_EABI_UNKNOWN
:
1928 strcat (buf
, ", GNU EABI");
1933 /* Process flags one bit at a time. */
1934 flag
= e_flags
& - e_flags
;
1939 case EF_ARM_INTERWORK
:
1940 strcat (buf
, ", interworking enabled");
1943 case EF_ARM_APCS_26
:
1944 strcat (buf
, ", uses APCS/26");
1947 case EF_ARM_APCS_FLOAT
:
1948 strcat (buf
, ", uses APCS/float");
1952 strcat (buf
, ", position independent");
1956 strcat (buf
, ", 8 bit structure alignment");
1959 case EF_ARM_NEW_ABI
:
1960 strcat (buf
, ", uses new ABI");
1963 case EF_ARM_OLD_ABI
:
1964 strcat (buf
, ", uses old ABI");
1967 case EF_ARM_SOFT_FLOAT
:
1968 strcat (buf
, ", software FP");
1971 case EF_ARM_VFP_FLOAT
:
1972 strcat (buf
, ", VFP");
1975 case EF_ARM_MAVERICK_FLOAT
:
1976 strcat (buf
, ", Maverick FP");
1987 strcat (buf
,", <unknown>");
1991 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1993 static char buf
[1024];
2005 decode_ARM_machine_flags (e_flags
, buf
);
2009 switch (e_flags
& EF_FRV_CPU_MASK
)
2011 case EF_FRV_CPU_GENERIC
:
2015 strcat (buf
, ", fr???");
2018 case EF_FRV_CPU_FR300
:
2019 strcat (buf
, ", fr300");
2022 case EF_FRV_CPU_FR400
:
2023 strcat (buf
, ", fr400");
2025 case EF_FRV_CPU_FR405
:
2026 strcat (buf
, ", fr405");
2029 case EF_FRV_CPU_FR450
:
2030 strcat (buf
, ", fr450");
2033 case EF_FRV_CPU_FR500
:
2034 strcat (buf
, ", fr500");
2036 case EF_FRV_CPU_FR550
:
2037 strcat (buf
, ", fr550");
2040 case EF_FRV_CPU_SIMPLE
:
2041 strcat (buf
, ", simple");
2043 case EF_FRV_CPU_TOMCAT
:
2044 strcat (buf
, ", tomcat");
2050 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2051 strcat (buf
, ", m68000");
2052 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2053 strcat (buf
, ", cpu32");
2054 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2055 strcat (buf
, ", fido_a");
2058 char const *isa
= _("unknown");
2059 char const *mac
= _("unknown mac");
2060 char const *additional
= NULL
;
2062 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2064 case EF_M68K_CF_ISA_A_NODIV
:
2066 additional
= ", nodiv";
2068 case EF_M68K_CF_ISA_A
:
2071 case EF_M68K_CF_ISA_A_PLUS
:
2074 case EF_M68K_CF_ISA_B_NOUSP
:
2076 additional
= ", nousp";
2078 case EF_M68K_CF_ISA_B
:
2082 strcat (buf
, ", cf, isa ");
2085 strcat (buf
, additional
);
2086 if (e_flags
& EF_M68K_CF_FLOAT
)
2087 strcat (buf
, ", float");
2088 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2093 case EF_M68K_CF_MAC
:
2096 case EF_M68K_CF_EMAC
:
2109 if (e_flags
& EF_PPC_EMB
)
2110 strcat (buf
, ", emb");
2112 if (e_flags
& EF_PPC_RELOCATABLE
)
2113 strcat (buf
, ", relocatable");
2115 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2116 strcat (buf
, ", relocatable-lib");
2120 case EM_CYGNUS_V850
:
2121 switch (e_flags
& EF_V850_ARCH
)
2124 strcat (buf
, ", v850e1");
2127 strcat (buf
, ", v850e");
2130 strcat (buf
, ", v850");
2133 strcat (buf
, ", unknown v850 architecture variant");
2139 case EM_CYGNUS_M32R
:
2140 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2141 strcat (buf
, ", m32r");
2145 case EM_MIPS_RS3_LE
:
2146 if (e_flags
& EF_MIPS_NOREORDER
)
2147 strcat (buf
, ", noreorder");
2149 if (e_flags
& EF_MIPS_PIC
)
2150 strcat (buf
, ", pic");
2152 if (e_flags
& EF_MIPS_CPIC
)
2153 strcat (buf
, ", cpic");
2155 if (e_flags
& EF_MIPS_UCODE
)
2156 strcat (buf
, ", ugen_reserved");
2158 if (e_flags
& EF_MIPS_ABI2
)
2159 strcat (buf
, ", abi2");
2161 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2162 strcat (buf
, ", odk first");
2164 if (e_flags
& EF_MIPS_32BITMODE
)
2165 strcat (buf
, ", 32bitmode");
2167 switch ((e_flags
& EF_MIPS_MACH
))
2169 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2170 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2171 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2172 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2173 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2174 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2175 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2176 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2177 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2178 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2180 /* We simply ignore the field in this case to avoid confusion:
2181 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2184 default: strcat (buf
, ", unknown CPU"); break;
2187 switch ((e_flags
& EF_MIPS_ABI
))
2189 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2190 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2191 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2192 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2194 /* We simply ignore the field in this case to avoid confusion:
2195 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2196 This means it is likely to be an o32 file, but not for
2199 default: strcat (buf
, ", unknown ABI"); break;
2202 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2203 strcat (buf
, ", mdmx");
2205 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2206 strcat (buf
, ", mips16");
2208 switch ((e_flags
& EF_MIPS_ARCH
))
2210 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2211 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2212 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2213 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2214 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2215 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2216 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2217 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2218 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2219 default: strcat (buf
, ", unknown ISA"); break;
2225 switch ((e_flags
& EF_SH_MACH_MASK
))
2227 case EF_SH1
: strcat (buf
, ", sh1"); break;
2228 case EF_SH2
: strcat (buf
, ", sh2"); break;
2229 case EF_SH3
: strcat (buf
, ", sh3"); break;
2230 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2231 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2232 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2233 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2234 case EF_SH4
: strcat (buf
, ", sh4"); break;
2235 case EF_SH5
: strcat (buf
, ", sh5"); break;
2236 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2237 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2238 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2239 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2240 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2241 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2242 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2243 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2244 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2245 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2246 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2247 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2248 default: strcat (buf
, ", unknown ISA"); break;
2254 if (e_flags
& EF_SPARC_32PLUS
)
2255 strcat (buf
, ", v8+");
2257 if (e_flags
& EF_SPARC_SUN_US1
)
2258 strcat (buf
, ", ultrasparcI");
2260 if (e_flags
& EF_SPARC_SUN_US3
)
2261 strcat (buf
, ", ultrasparcIII");
2263 if (e_flags
& EF_SPARC_HAL_R1
)
2264 strcat (buf
, ", halr1");
2266 if (e_flags
& EF_SPARC_LEDATA
)
2267 strcat (buf
, ", ledata");
2269 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2270 strcat (buf
, ", tso");
2272 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2273 strcat (buf
, ", pso");
2275 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2276 strcat (buf
, ", rmo");
2280 switch (e_flags
& EF_PARISC_ARCH
)
2282 case EFA_PARISC_1_0
:
2283 strcpy (buf
, ", PA-RISC 1.0");
2285 case EFA_PARISC_1_1
:
2286 strcpy (buf
, ", PA-RISC 1.1");
2288 case EFA_PARISC_2_0
:
2289 strcpy (buf
, ", PA-RISC 2.0");
2294 if (e_flags
& EF_PARISC_TRAPNIL
)
2295 strcat (buf
, ", trapnil");
2296 if (e_flags
& EF_PARISC_EXT
)
2297 strcat (buf
, ", ext");
2298 if (e_flags
& EF_PARISC_LSB
)
2299 strcat (buf
, ", lsb");
2300 if (e_flags
& EF_PARISC_WIDE
)
2301 strcat (buf
, ", wide");
2302 if (e_flags
& EF_PARISC_NO_KABP
)
2303 strcat (buf
, ", no kabp");
2304 if (e_flags
& EF_PARISC_LAZYSWAP
)
2305 strcat (buf
, ", lazyswap");
2310 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2311 strcat (buf
, ", new calling convention");
2313 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2314 strcat (buf
, ", gnu calling convention");
2318 if ((e_flags
& EF_IA_64_ABI64
))
2319 strcat (buf
, ", 64-bit");
2321 strcat (buf
, ", 32-bit");
2322 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2323 strcat (buf
, ", reduced fp model");
2324 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2325 strcat (buf
, ", no function descriptors, constant gp");
2326 else if ((e_flags
& EF_IA_64_CONS_GP
))
2327 strcat (buf
, ", constant gp");
2328 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2329 strcat (buf
, ", absolute");
2333 if ((e_flags
& EF_VAX_NONPIC
))
2334 strcat (buf
, ", non-PIC");
2335 if ((e_flags
& EF_VAX_DFLOAT
))
2336 strcat (buf
, ", D-Float");
2337 if ((e_flags
& EF_VAX_GFLOAT
))
2338 strcat (buf
, ", G-Float");
2347 get_osabi_name (unsigned int osabi
)
2349 static char buff
[32];
2353 case ELFOSABI_NONE
: return "UNIX - System V";
2354 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2355 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2356 case ELFOSABI_LINUX
: return "UNIX - Linux";
2357 case ELFOSABI_HURD
: return "GNU/Hurd";
2358 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2359 case ELFOSABI_AIX
: return "UNIX - AIX";
2360 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2361 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2362 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2363 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2364 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2365 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2366 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2367 case ELFOSABI_AROS
: return "Amiga Research OS";
2368 case ELFOSABI_STANDALONE
: return _("Standalone App");
2369 case ELFOSABI_ARM
: return "ARM";
2371 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2377 get_arm_segment_type (unsigned long type
)
2391 get_mips_segment_type (unsigned long type
)
2395 case PT_MIPS_REGINFO
:
2397 case PT_MIPS_RTPROC
:
2399 case PT_MIPS_OPTIONS
:
2409 get_parisc_segment_type (unsigned long type
)
2413 case PT_HP_TLS
: return "HP_TLS";
2414 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2415 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2416 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2417 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2418 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2419 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2420 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2421 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2422 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2423 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2424 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2425 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2426 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2427 case PT_HP_STACK
: return "HP_STACK";
2428 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2429 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2430 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2431 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2440 get_ia64_segment_type (unsigned long type
)
2444 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2445 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2446 case PT_HP_TLS
: return "HP_TLS";
2447 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2448 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2449 case PT_IA_64_HP_STACK
: return "HP_STACK";
2458 get_segment_type (unsigned long p_type
)
2460 static char buff
[32];
2464 case PT_NULL
: return "NULL";
2465 case PT_LOAD
: return "LOAD";
2466 case PT_DYNAMIC
: return "DYNAMIC";
2467 case PT_INTERP
: return "INTERP";
2468 case PT_NOTE
: return "NOTE";
2469 case PT_SHLIB
: return "SHLIB";
2470 case PT_PHDR
: return "PHDR";
2471 case PT_TLS
: return "TLS";
2473 case PT_GNU_EH_FRAME
:
2474 return "GNU_EH_FRAME";
2475 case PT_GNU_STACK
: return "GNU_STACK";
2476 case PT_GNU_RELRO
: return "GNU_RELRO";
2479 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2483 switch (elf_header
.e_machine
)
2486 result
= get_arm_segment_type (p_type
);
2489 case EM_MIPS_RS3_LE
:
2490 result
= get_mips_segment_type (p_type
);
2493 result
= get_parisc_segment_type (p_type
);
2496 result
= get_ia64_segment_type (p_type
);
2506 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2508 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2512 switch (elf_header
.e_machine
)
2515 result
= get_parisc_segment_type (p_type
);
2518 result
= get_ia64_segment_type (p_type
);
2528 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2531 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2538 get_mips_section_type_name (unsigned int sh_type
)
2542 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2543 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2544 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2545 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2546 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2547 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2548 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2549 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2550 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2551 case SHT_MIPS_RELD
: return "MIPS_RELD";
2552 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2553 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2554 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2555 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2556 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2557 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2558 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2559 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2560 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2561 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2562 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2563 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2564 case SHT_MIPS_LINE
: return "MIPS_LINE";
2565 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2566 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2567 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2568 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2569 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2570 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2571 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2572 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2573 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2574 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2575 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2576 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2577 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2578 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2579 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2580 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2588 get_parisc_section_type_name (unsigned int sh_type
)
2592 case SHT_PARISC_EXT
: return "PARISC_EXT";
2593 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2594 case SHT_PARISC_DOC
: return "PARISC_DOC";
2595 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2596 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2597 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2598 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2606 get_ia64_section_type_name (unsigned int sh_type
)
2608 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2609 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2610 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2614 case SHT_IA_64_EXT
: return "IA_64_EXT";
2615 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2616 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2624 get_x86_64_section_type_name (unsigned int sh_type
)
2628 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2636 get_arm_section_type_name (unsigned int sh_type
)
2642 case SHT_ARM_PREEMPTMAP
:
2643 return "ARM_PREEMPTMAP";
2644 case SHT_ARM_ATTRIBUTES
:
2645 return "ARM_ATTRIBUTES";
2653 get_section_type_name (unsigned int sh_type
)
2655 static char buff
[32];
2659 case SHT_NULL
: return "NULL";
2660 case SHT_PROGBITS
: return "PROGBITS";
2661 case SHT_SYMTAB
: return "SYMTAB";
2662 case SHT_STRTAB
: return "STRTAB";
2663 case SHT_RELA
: return "RELA";
2664 case SHT_HASH
: return "HASH";
2665 case SHT_DYNAMIC
: return "DYNAMIC";
2666 case SHT_NOTE
: return "NOTE";
2667 case SHT_NOBITS
: return "NOBITS";
2668 case SHT_REL
: return "REL";
2669 case SHT_SHLIB
: return "SHLIB";
2670 case SHT_DYNSYM
: return "DYNSYM";
2671 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2672 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2673 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2674 case SHT_GNU_HASH
: return "GNU_HASH";
2675 case SHT_GROUP
: return "GROUP";
2676 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2677 case SHT_GNU_verdef
: return "VERDEF";
2678 case SHT_GNU_verneed
: return "VERNEED";
2679 case SHT_GNU_versym
: return "VERSYM";
2680 case 0x6ffffff0: return "VERSYM";
2681 case 0x6ffffffc: return "VERDEF";
2682 case 0x7ffffffd: return "AUXILIARY";
2683 case 0x7fffffff: return "FILTER";
2684 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2687 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2691 switch (elf_header
.e_machine
)
2694 case EM_MIPS_RS3_LE
:
2695 result
= get_mips_section_type_name (sh_type
);
2698 result
= get_parisc_section_type_name (sh_type
);
2701 result
= get_ia64_section_type_name (sh_type
);
2704 result
= get_x86_64_section_type_name (sh_type
);
2707 result
= get_arm_section_type_name (sh_type
);
2717 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2719 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2720 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2721 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2722 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2724 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2730 #define OPTION_DEBUG_DUMP 512
2732 static struct option options
[] =
2734 {"all", no_argument
, 0, 'a'},
2735 {"file-header", no_argument
, 0, 'h'},
2736 {"program-headers", no_argument
, 0, 'l'},
2737 {"headers", no_argument
, 0, 'e'},
2738 {"histogram", no_argument
, 0, 'I'},
2739 {"segments", no_argument
, 0, 'l'},
2740 {"sections", no_argument
, 0, 'S'},
2741 {"section-headers", no_argument
, 0, 'S'},
2742 {"section-groups", no_argument
, 0, 'g'},
2743 {"section-details", no_argument
, 0, 't'},
2744 {"full-section-name",no_argument
, 0, 'N'},
2745 {"symbols", no_argument
, 0, 's'},
2746 {"syms", no_argument
, 0, 's'},
2747 {"relocs", no_argument
, 0, 'r'},
2748 {"notes", no_argument
, 0, 'n'},
2749 {"dynamic", no_argument
, 0, 'd'},
2750 {"arch-specific", no_argument
, 0, 'A'},
2751 {"version-info", no_argument
, 0, 'V'},
2752 {"use-dynamic", no_argument
, 0, 'D'},
2753 {"unwind", no_argument
, 0, 'u'},
2754 {"hex-dump", required_argument
, 0, 'x'},
2755 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2756 {"string-dump", required_argument
, 0, 'p'},
2757 #ifdef SUPPORT_DISASSEMBLY
2758 {"instruction-dump", required_argument
, 0, 'i'},
2761 {"version", no_argument
, 0, 'v'},
2762 {"wide", no_argument
, 0, 'W'},
2763 {"help", no_argument
, 0, 'H'},
2764 {0, no_argument
, 0, 0}
2768 usage (FILE *stream
)
2770 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2771 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
2772 fprintf (stream
, _(" Options are:\n\
2773 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2774 -h --file-header Display the ELF file header\n\
2775 -l --program-headers Display the program headers\n\
2776 --segments An alias for --program-headers\n\
2777 -S --section-headers Display the sections' header\n\
2778 --sections An alias for --section-headers\n\
2779 -g --section-groups Display the section groups\n\
2780 -t --section-details Display the section details\n\
2781 -e --headers Equivalent to: -h -l -S\n\
2782 -s --syms Display the symbol table\n\
2783 --symbols An alias for --syms\n\
2784 -n --notes Display the core notes (if present)\n\
2785 -r --relocs Display the relocations (if present)\n\
2786 -u --unwind Display the unwind info (if present)\n\
2787 -d --dynamic Display the dynamic section (if present)\n\
2788 -V --version-info Display the version sections (if present)\n\
2789 -A --arch-specific Display architecture specific information (if any).\n\
2790 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2791 -x --hex-dump=<number|name>\n\
2792 Dump the contents of section <number|name> as bytes\n\
2793 -p --string-dump=<number|name>\n\
2794 Dump the contents of section <number|name> as strings\n\
2795 -w[liaprmfFsoR] or\n\
2796 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2797 Display the contents of DWARF2 debug sections\n"));
2798 #ifdef SUPPORT_DISASSEMBLY
2799 fprintf (stream
, _("\
2800 -i --instruction-dump=<number|name>\n\
2801 Disassemble the contents of section <number|name>\n"));
2803 fprintf (stream
, _("\
2804 -I --histogram Display histogram of bucket list lengths\n\
2805 -W --wide Allow output width to exceed 80 characters\n\
2806 @<file> Read options from <file>\n\
2807 -H --help Display this information\n\
2808 -v --version Display the version number of readelf\n"));
2810 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2811 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2813 exit (stream
== stdout
? 0 : 1);
2816 /* Record the fact that the user wants the contents of section number
2817 SECTION to be displayed using the method(s) encoded as flags bits
2818 in TYPE. Note, TYPE can be zero if we are creating the array for
2822 request_dump_bynumber (unsigned int section
, dump_type type
)
2824 if (section
>= num_dump_sects
)
2826 dump_type
*new_dump_sects
;
2828 new_dump_sects
= calloc (section
+ 1, sizeof (* dump_sects
));
2830 if (new_dump_sects
== NULL
)
2831 error (_("Out of memory allocating dump request table.\n"));
2834 /* Copy current flag settings. */
2835 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
* sizeof (* dump_sects
));
2839 dump_sects
= new_dump_sects
;
2840 num_dump_sects
= section
+ 1;
2845 dump_sects
[section
] |= type
;
2850 /* Request a dump by section name. */
2853 request_dump_byname (const char *section
, dump_type type
)
2855 struct dump_list_entry
*new_request
;
2857 new_request
= malloc (sizeof (struct dump_list_entry
));
2859 error (_("Out of memory allocating dump request table.\n"));
2861 new_request
->name
= strdup (section
);
2862 if (!new_request
->name
)
2863 error (_("Out of memory allocating dump request table.\n"));
2865 new_request
->type
= type
;
2867 new_request
->next
= dump_sects_byname
;
2868 dump_sects_byname
= new_request
;
2872 parse_args (int argc
, char **argv
)
2879 while ((c
= getopt_long
2880 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWHp:", options
, NULL
)) != EOF
)
2901 do_section_groups
++;
2909 do_section_groups
++;
2914 do_section_details
++;
2956 section
= strtoul (optarg
, & cp
, 0);
2957 if (! *cp
&& section
>= 0)
2958 request_dump_bynumber (section
, HEX_DUMP
);
2960 request_dump_byname (optarg
, HEX_DUMP
);
2964 section
= strtoul (optarg
, & cp
, 0);
2965 if (! *cp
&& section
>= 0)
2966 request_dump_bynumber (section
, STRING_DUMP
);
2968 request_dump_byname (optarg
, STRING_DUMP
);
2976 unsigned int index
= 0;
2980 while (optarg
[index
])
2981 switch (optarg
[index
++])
2990 do_debug_abbrevs
= 1;
3000 do_debug_pubnames
= 1;
3004 do_debug_aranges
= 1;
3008 do_debug_ranges
= 1;
3012 do_debug_frames_interp
= 1;
3014 do_debug_frames
= 1;
3019 do_debug_macinfo
= 1;
3033 warn (_("Unrecognized debug option '%s'\n"), optarg
);
3038 case OPTION_DEBUG_DUMP
:
3046 const char * option
;
3049 debug_dump_long_opts
;
3051 debug_dump_long_opts opts_table
[] =
3053 /* Please keep this table alpha- sorted. */
3054 { "Ranges", & do_debug_ranges
},
3055 { "abbrev", & do_debug_abbrevs
},
3056 { "aranges", & do_debug_aranges
},
3057 { "frames", & do_debug_frames
},
3058 { "frames-interp", & do_debug_frames_interp
},
3059 { "info", & do_debug_info
},
3060 { "line", & do_debug_lines
},
3061 { "loc", & do_debug_loc
},
3062 { "macro", & do_debug_macinfo
},
3063 { "pubnames", & do_debug_pubnames
},
3064 /* This entry is for compatability
3065 with earlier versions of readelf. */
3066 { "ranges", & do_debug_aranges
},
3067 { "str", & do_debug_str
},
3078 debug_dump_long_opts
* entry
;
3080 for (entry
= opts_table
; entry
->option
; entry
++)
3082 size_t len
= strlen (entry
->option
);
3084 if (strneq (p
, entry
->option
, len
)
3085 && (p
[len
] == ',' || p
[len
] == '\0'))
3087 * entry
->variable
= 1;
3089 /* The --debug-dump=frames-interp option also
3090 enables the --debug-dump=frames option. */
3091 if (do_debug_frames_interp
)
3092 do_debug_frames
= 1;
3099 if (entry
->option
== NULL
)
3101 warn (_("Unrecognized debug option '%s'\n"), p
);
3102 p
= strchr (p
, ',');
3112 #ifdef SUPPORT_DISASSEMBLY
3115 section
= strtoul (optarg
, & cp
, 0);
3116 if (! *cp
&& section
>= 0)
3117 request_dump_bynumber (section
, DISASS_DUMP
);
3119 request_dump_byname (optarg
, DISASS_DUMP
);
3122 print_version (program_name
);
3131 /* xgettext:c-format */
3132 error (_("Invalid option '-%c'\n"), c
);
3139 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3140 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3141 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3142 && !do_section_groups
)
3146 warn (_("Nothing to do.\n"));
3152 get_elf_class (unsigned int elf_class
)
3154 static char buff
[32];
3158 case ELFCLASSNONE
: return _("none");
3159 case ELFCLASS32
: return "ELF32";
3160 case ELFCLASS64
: return "ELF64";
3162 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3168 get_data_encoding (unsigned int encoding
)
3170 static char buff
[32];
3174 case ELFDATANONE
: return _("none");
3175 case ELFDATA2LSB
: return _("2's complement, little endian");
3176 case ELFDATA2MSB
: return _("2's complement, big endian");
3178 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3183 /* Decode the data held in 'elf_header'. */
3186 process_file_header (void)
3188 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3189 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3190 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3191 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3194 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3202 printf (_("ELF Header:\n"));
3203 printf (_(" Magic: "));
3204 for (i
= 0; i
< EI_NIDENT
; i
++)
3205 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3207 printf (_(" Class: %s\n"),
3208 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3209 printf (_(" Data: %s\n"),
3210 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3211 printf (_(" Version: %d %s\n"),
3212 elf_header
.e_ident
[EI_VERSION
],
3213 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3215 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3218 printf (_(" OS/ABI: %s\n"),
3219 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3220 printf (_(" ABI Version: %d\n"),
3221 elf_header
.e_ident
[EI_ABIVERSION
]);
3222 printf (_(" Type: %s\n"),
3223 get_file_type (elf_header
.e_type
));
3224 printf (_(" Machine: %s\n"),
3225 get_machine_name (elf_header
.e_machine
));
3226 printf (_(" Version: 0x%lx\n"),
3227 (unsigned long) elf_header
.e_version
);
3229 printf (_(" Entry point address: "));
3230 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3231 printf (_("\n Start of program headers: "));
3232 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3233 printf (_(" (bytes into file)\n Start of section headers: "));
3234 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3235 printf (_(" (bytes into file)\n"));
3237 printf (_(" Flags: 0x%lx%s\n"),
3238 (unsigned long) elf_header
.e_flags
,
3239 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3240 printf (_(" Size of this header: %ld (bytes)\n"),
3241 (long) elf_header
.e_ehsize
);
3242 printf (_(" Size of program headers: %ld (bytes)\n"),
3243 (long) elf_header
.e_phentsize
);
3244 printf (_(" Number of program headers: %ld\n"),
3245 (long) elf_header
.e_phnum
);
3246 printf (_(" Size of section headers: %ld (bytes)\n"),
3247 (long) elf_header
.e_shentsize
);
3248 printf (_(" Number of section headers: %ld"),
3249 (long) elf_header
.e_shnum
);
3250 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3251 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3252 putc ('\n', stdout
);
3253 printf (_(" Section header string table index: %ld"),
3254 (long) elf_header
.e_shstrndx
);
3255 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3256 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3257 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3258 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3259 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3260 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3261 printf (" <corrupt: out of range>");
3262 putc ('\n', stdout
);
3265 if (section_headers
!= NULL
)
3267 if (elf_header
.e_shnum
== 0)
3268 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3269 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3270 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3271 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3272 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3273 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3274 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3275 elf_header
.e_shstrndx
= SHN_UNDEF
;
3276 free (section_headers
);
3277 section_headers
= NULL
;
3285 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3287 Elf32_External_Phdr
*phdrs
;
3288 Elf32_External_Phdr
*external
;
3289 Elf_Internal_Phdr
*internal
;
3292 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3293 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3294 _("program headers"));
3298 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3299 i
< elf_header
.e_phnum
;
3300 i
++, internal
++, external
++)
3302 internal
->p_type
= BYTE_GET (external
->p_type
);
3303 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3304 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3305 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3306 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3307 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3308 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3309 internal
->p_align
= BYTE_GET (external
->p_align
);
3318 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3320 Elf64_External_Phdr
*phdrs
;
3321 Elf64_External_Phdr
*external
;
3322 Elf_Internal_Phdr
*internal
;
3325 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3326 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3327 _("program headers"));
3331 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3332 i
< elf_header
.e_phnum
;
3333 i
++, internal
++, external
++)
3335 internal
->p_type
= BYTE_GET (external
->p_type
);
3336 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3337 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3338 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3339 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3340 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3341 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3342 internal
->p_align
= BYTE_GET (external
->p_align
);
3350 /* Returns 1 if the program headers were read into `program_headers'. */
3353 get_program_headers (FILE *file
)
3355 Elf_Internal_Phdr
*phdrs
;
3357 /* Check cache of prior read. */
3358 if (program_headers
!= NULL
)
3361 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3365 error (_("Out of memory\n"));
3370 ? get_32bit_program_headers (file
, phdrs
)
3371 : get_64bit_program_headers (file
, phdrs
))
3373 program_headers
= phdrs
;
3381 /* Returns 1 if the program headers were loaded. */
3384 process_program_headers (FILE *file
)
3386 Elf_Internal_Phdr
*segment
;
3389 if (elf_header
.e_phnum
== 0)
3392 printf (_("\nThere are no program headers in this file.\n"));
3396 if (do_segments
&& !do_header
)
3398 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3399 printf (_("Entry point "));
3400 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3401 printf (_("\nThere are %d program headers, starting at offset "),
3402 elf_header
.e_phnum
);
3403 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3407 if (! get_program_headers (file
))
3412 if (elf_header
.e_phnum
> 1)
3413 printf (_("\nProgram Headers:\n"));
3415 printf (_("\nProgram Headers:\n"));
3419 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3422 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3426 (_(" Type Offset VirtAddr PhysAddr\n"));
3428 (_(" FileSiz MemSiz Flags Align\n"));
3435 for (i
= 0, segment
= program_headers
;
3436 i
< elf_header
.e_phnum
;
3441 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3445 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3446 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3447 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3448 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3449 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3451 (segment
->p_flags
& PF_R
? 'R' : ' '),
3452 (segment
->p_flags
& PF_W
? 'W' : ' '),
3453 (segment
->p_flags
& PF_X
? 'E' : ' '));
3454 printf ("%#lx", (unsigned long) segment
->p_align
);
3458 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3459 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3462 print_vma (segment
->p_offset
, FULL_HEX
);
3466 print_vma (segment
->p_vaddr
, FULL_HEX
);
3468 print_vma (segment
->p_paddr
, FULL_HEX
);
3471 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3472 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3475 print_vma (segment
->p_filesz
, FULL_HEX
);
3479 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3480 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3483 print_vma (segment
->p_offset
, FULL_HEX
);
3487 (segment
->p_flags
& PF_R
? 'R' : ' '),
3488 (segment
->p_flags
& PF_W
? 'W' : ' '),
3489 (segment
->p_flags
& PF_X
? 'E' : ' '));
3491 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3492 printf ("%#lx", (unsigned long) segment
->p_align
);
3495 print_vma (segment
->p_align
, PREFIX_HEX
);
3500 print_vma (segment
->p_offset
, FULL_HEX
);
3502 print_vma (segment
->p_vaddr
, FULL_HEX
);
3504 print_vma (segment
->p_paddr
, FULL_HEX
);
3506 print_vma (segment
->p_filesz
, FULL_HEX
);
3508 print_vma (segment
->p_memsz
, FULL_HEX
);
3510 (segment
->p_flags
& PF_R
? 'R' : ' '),
3511 (segment
->p_flags
& PF_W
? 'W' : ' '),
3512 (segment
->p_flags
& PF_X
? 'E' : ' '));
3513 print_vma (segment
->p_align
, HEX
);
3517 switch (segment
->p_type
)
3521 error (_("more than one dynamic segment\n"));
3523 /* Try to locate the .dynamic section. If there is
3524 a section header table, we can easily locate it. */
3525 if (section_headers
!= NULL
)
3527 Elf_Internal_Shdr
*sec
;
3529 sec
= find_section (".dynamic");
3530 if (sec
== NULL
|| sec
->sh_size
== 0)
3532 error (_("no .dynamic section in the dynamic segment\n"));
3536 if (sec
->sh_type
== SHT_NOBITS
)
3539 dynamic_addr
= sec
->sh_offset
;
3540 dynamic_size
= sec
->sh_size
;
3542 if (dynamic_addr
< segment
->p_offset
3543 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3544 warn (_("the .dynamic section is not contained within the dynamic segment\n"));
3545 else if (dynamic_addr
> segment
->p_offset
)
3546 warn (_("the .dynamic section is not the first section in the dynamic segment.\n"));
3550 /* Otherwise, we can only assume that the .dynamic
3551 section is the first section in the DYNAMIC segment. */
3552 dynamic_addr
= segment
->p_offset
;
3553 dynamic_size
= segment
->p_filesz
;
3558 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3560 error (_("Unable to find program interpreter name\n"));
3564 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3566 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3567 error (_("Internal error: failed to create format string to display program interpreter\n"));
3569 program_interpreter
[0] = 0;
3570 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3571 error (_("Unable to read program interpreter name\n"));
3574 printf (_("\n [Requesting program interpreter: %s]"),
3575 program_interpreter
);
3581 putc ('\n', stdout
);
3584 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3586 printf (_("\n Section to Segment mapping:\n"));
3587 printf (_(" Segment Sections...\n"));
3589 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3592 Elf_Internal_Shdr
*section
;
3594 segment
= program_headers
+ i
;
3595 section
= section_headers
;
3597 printf (" %2.2d ", i
);
3599 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3601 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section
, segment
))
3602 printf ("%s ", SECTION_NAME (section
));
3613 /* Find the file offset corresponding to VMA by using the program headers. */
3616 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3618 Elf_Internal_Phdr
*seg
;
3620 if (! get_program_headers (file
))
3622 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3626 for (seg
= program_headers
;
3627 seg
< program_headers
+ elf_header
.e_phnum
;
3630 if (seg
->p_type
!= PT_LOAD
)
3633 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3634 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3635 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3638 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3645 get_32bit_section_headers (FILE *file
, unsigned int num
)
3647 Elf32_External_Shdr
*shdrs
;
3648 Elf_Internal_Shdr
*internal
;
3651 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3652 elf_header
.e_shentsize
, num
, _("section headers"));
3656 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3658 if (section_headers
== NULL
)
3660 error (_("Out of memory\n"));
3664 for (i
= 0, internal
= section_headers
;
3668 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3669 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3670 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3671 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3672 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3673 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3674 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3675 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3676 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3677 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3686 get_64bit_section_headers (FILE *file
, unsigned int num
)
3688 Elf64_External_Shdr
*shdrs
;
3689 Elf_Internal_Shdr
*internal
;
3692 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3693 elf_header
.e_shentsize
, num
, _("section headers"));
3697 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3699 if (section_headers
== NULL
)
3701 error (_("Out of memory\n"));
3705 for (i
= 0, internal
= section_headers
;
3709 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3710 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3711 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3712 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3713 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3714 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3715 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3716 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3717 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3718 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3726 static Elf_Internal_Sym
*
3727 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3729 unsigned long number
;
3730 Elf32_External_Sym
*esyms
;
3731 Elf_External_Sym_Shndx
*shndx
;
3732 Elf_Internal_Sym
*isyms
;
3733 Elf_Internal_Sym
*psym
;
3736 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3742 if (symtab_shndx_hdr
!= NULL
3743 && (symtab_shndx_hdr
->sh_link
3744 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3746 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3747 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3755 number
= section
->sh_size
/ section
->sh_entsize
;
3756 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3760 error (_("Out of memory\n"));
3767 for (j
= 0, psym
= isyms
;
3771 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3772 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3773 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3774 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3775 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3777 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3778 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3779 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3789 static Elf_Internal_Sym
*
3790 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3792 unsigned long number
;
3793 Elf64_External_Sym
*esyms
;
3794 Elf_External_Sym_Shndx
*shndx
;
3795 Elf_Internal_Sym
*isyms
;
3796 Elf_Internal_Sym
*psym
;
3799 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3805 if (symtab_shndx_hdr
!= NULL
3806 && (symtab_shndx_hdr
->sh_link
3807 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3809 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3810 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3818 number
= section
->sh_size
/ section
->sh_entsize
;
3819 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3823 error (_("Out of memory\n"));
3830 for (j
= 0, psym
= isyms
;
3834 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3835 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3836 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3837 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3838 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3840 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3841 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3842 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3853 get_elf_section_flags (bfd_vma sh_flags
)
3855 static char buff
[1024];
3857 int field_size
= is_32bit_elf
? 8 : 16;
3858 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3859 bfd_vma os_flags
= 0;
3860 bfd_vma proc_flags
= 0;
3861 bfd_vma unknown_flags
= 0;
3875 { "LINK ORDER", 10 },
3876 { "OS NONCONF", 10 },
3881 if (do_section_details
)
3883 sprintf (buff
, "[%*.*lx]: ",
3884 field_size
, field_size
, (unsigned long) sh_flags
);
3885 p
+= field_size
+ 4;
3892 flag
= sh_flags
& - sh_flags
;
3895 if (do_section_details
)
3899 case SHF_WRITE
: index
= 0; break;
3900 case SHF_ALLOC
: index
= 1; break;
3901 case SHF_EXECINSTR
: index
= 2; break;
3902 case SHF_MERGE
: index
= 3; break;
3903 case SHF_STRINGS
: index
= 4; break;
3904 case SHF_INFO_LINK
: index
= 5; break;
3905 case SHF_LINK_ORDER
: index
= 6; break;
3906 case SHF_OS_NONCONFORMING
: index
= 7; break;
3907 case SHF_GROUP
: index
= 8; break;
3908 case SHF_TLS
: index
= 9; break;
3917 if (p
!= buff
+ field_size
+ 4)
3919 if (size
< (10 + 2))
3926 size
-= flags
[index
].len
;
3927 p
= stpcpy (p
, flags
[index
].str
);
3929 else if (flag
& SHF_MASKOS
)
3931 else if (flag
& SHF_MASKPROC
)
3934 unknown_flags
|= flag
;
3940 case SHF_WRITE
: *p
= 'W'; break;
3941 case SHF_ALLOC
: *p
= 'A'; break;
3942 case SHF_EXECINSTR
: *p
= 'X'; break;
3943 case SHF_MERGE
: *p
= 'M'; break;
3944 case SHF_STRINGS
: *p
= 'S'; break;
3945 case SHF_INFO_LINK
: *p
= 'I'; break;
3946 case SHF_LINK_ORDER
: *p
= 'L'; break;
3947 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3948 case SHF_GROUP
: *p
= 'G'; break;
3949 case SHF_TLS
: *p
= 'T'; break;
3952 if (elf_header
.e_machine
== EM_X86_64
3953 && flag
== SHF_X86_64_LARGE
)
3955 else if (flag
& SHF_MASKOS
)
3958 sh_flags
&= ~ SHF_MASKOS
;
3960 else if (flag
& SHF_MASKPROC
)
3963 sh_flags
&= ~ SHF_MASKPROC
;
3973 if (do_section_details
)
3977 size
-= 5 + field_size
;
3978 if (p
!= buff
+ field_size
+ 4)
3986 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3987 (unsigned long) os_flags
);
3988 p
+= 5 + field_size
;
3992 size
-= 7 + field_size
;
3993 if (p
!= buff
+ field_size
+ 4)
4001 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
4002 (unsigned long) proc_flags
);
4003 p
+= 7 + field_size
;
4007 size
-= 10 + field_size
;
4008 if (p
!= buff
+ field_size
+ 4)
4016 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
4017 (unsigned long) unknown_flags
);
4018 p
+= 10 + field_size
;
4027 process_section_headers (FILE *file
)
4029 Elf_Internal_Shdr
*section
;
4032 section_headers
= NULL
;
4034 if (elf_header
.e_shnum
== 0)
4037 printf (_("\nThere are no sections in this file.\n"));
4042 if (do_sections
&& !do_header
)
4043 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4044 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4048 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4051 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4054 /* Read in the string table, so that we have names to display. */
4055 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4056 && SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
4058 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
4060 if (section
->sh_size
!= 0)
4062 string_table
= get_data (NULL
, file
, section
->sh_offset
,
4063 1, section
->sh_size
, _("string table"));
4065 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4069 /* Scan the sections for the dynamic symbol table
4070 and dynamic string table and debug sections. */
4071 dynamic_symbols
= NULL
;
4072 dynamic_strings
= NULL
;
4073 dynamic_syminfo
= NULL
;
4074 symtab_shndx_hdr
= NULL
;
4076 eh_addr_size
= is_32bit_elf
? 4 : 8;
4077 switch (elf_header
.e_machine
)
4080 case EM_MIPS_RS3_LE
:
4081 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4082 FDE addresses. However, the ABI also has a semi-official ILP32
4083 variant for which the normal FDE address size rules apply.
4085 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4086 section, where XX is the size of longs in bits. Unfortunately,
4087 earlier compilers provided no way of distinguishing ILP32 objects
4088 from LP64 objects, so if there's any doubt, we should assume that
4089 the official LP64 form is being used. */
4090 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4091 && find_section (".gcc_compiled_long32") == NULL
)
4097 switch (elf_header
.e_flags
& EF_H8_MACH
)
4099 case E_H8_MACH_H8300
:
4100 case E_H8_MACH_H8300HN
:
4101 case E_H8_MACH_H8300SN
:
4102 case E_H8_MACH_H8300SXN
:
4105 case E_H8_MACH_H8300H
:
4106 case E_H8_MACH_H8300S
:
4107 case E_H8_MACH_H8300SX
:
4113 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4116 size_t expected_entsize \
4117 = is_32bit_elf ? size32 : size64; \
4118 if (section->sh_entsize != expected_entsize) \
4119 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4120 i, (unsigned long int) section->sh_entsize, \
4121 (unsigned long int) expected_entsize); \
4122 section->sh_entsize = expected_entsize; \
4125 #define CHECK_ENTSIZE(section, i, type) \
4126 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4127 sizeof (Elf64_External_##type))
4129 for (i
= 0, section
= section_headers
;
4130 i
< elf_header
.e_shnum
;
4133 char *name
= SECTION_NAME (section
);
4135 if (section
->sh_type
== SHT_DYNSYM
)
4137 if (dynamic_symbols
!= NULL
)
4139 error (_("File contains multiple dynamic symbol tables\n"));
4143 CHECK_ENTSIZE (section
, i
, Sym
);
4144 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4145 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4147 else if (section
->sh_type
== SHT_STRTAB
4148 && streq (name
, ".dynstr"))
4150 if (dynamic_strings
!= NULL
)
4152 error (_("File contains multiple dynamic string tables\n"));
4156 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
4157 1, section
->sh_size
, _("dynamic strings"));
4158 dynamic_strings_length
= section
->sh_size
;
4160 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4162 if (symtab_shndx_hdr
!= NULL
)
4164 error (_("File contains multiple symtab shndx tables\n"));
4167 symtab_shndx_hdr
= section
;
4169 else if (section
->sh_type
== SHT_SYMTAB
)
4170 CHECK_ENTSIZE (section
, i
, Sym
);
4171 else if (section
->sh_type
== SHT_GROUP
)
4172 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4173 else if (section
->sh_type
== SHT_REL
)
4174 CHECK_ENTSIZE (section
, i
, Rel
);
4175 else if (section
->sh_type
== SHT_RELA
)
4176 CHECK_ENTSIZE (section
, i
, Rela
);
4177 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4178 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
4179 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
4180 || do_debug_loc
|| do_debug_ranges
)
4181 && const_strneq (name
, ".debug_"))
4186 || (do_debug_info
&& streq (name
, "info"))
4187 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4188 || (do_debug_lines
&& streq (name
, "line"))
4189 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4190 || (do_debug_aranges
&& streq (name
, "aranges"))
4191 || (do_debug_ranges
&& streq (name
, "ranges"))
4192 || (do_debug_frames
&& streq (name
, "frame"))
4193 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4194 || (do_debug_str
&& streq (name
, "str"))
4195 || (do_debug_loc
&& streq (name
, "loc"))
4197 request_dump_bynumber (i
, DEBUG_DUMP
);
4199 /* linkonce section to be combined with .debug_info at link time. */
4200 else if ((do_debugging
|| do_debug_info
)
4201 && const_strneq (name
, ".gnu.linkonce.wi."))
4202 request_dump_bynumber (i
, DEBUG_DUMP
);
4203 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4204 request_dump_bynumber (i
, DEBUG_DUMP
);
4210 if (elf_header
.e_shnum
> 1)
4211 printf (_("\nSection Headers:\n"));
4213 printf (_("\nSection Header:\n"));
4217 if (do_section_details
)
4219 printf (_(" [Nr] Name\n"));
4220 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4224 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4228 if (do_section_details
)
4230 printf (_(" [Nr] Name\n"));
4231 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4235 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4239 if (do_section_details
)
4241 printf (_(" [Nr] Name\n"));
4242 printf (_(" Type Address Offset Link\n"));
4243 printf (_(" Size EntSize Info Align\n"));
4247 printf (_(" [Nr] Name Type Address Offset\n"));
4248 printf (_(" Size EntSize Flags Link Info Align\n"));
4252 if (do_section_details
)
4253 printf (_(" Flags\n"));
4255 for (i
= 0, section
= section_headers
;
4256 i
< elf_header
.e_shnum
;
4259 if (do_section_details
)
4261 printf (" [%2u] %s\n",
4262 SECTION_HEADER_NUM (i
),
4263 SECTION_NAME (section
));
4264 if (is_32bit_elf
|| do_wide
)
4265 printf (" %-15.15s ",
4266 get_section_type_name (section
->sh_type
));
4269 printf (" [%2u] %-17.17s %-15.15s ",
4270 SECTION_HEADER_NUM (i
),
4271 SECTION_NAME (section
),
4272 get_section_type_name (section
->sh_type
));
4276 print_vma (section
->sh_addr
, LONG_HEX
);
4278 printf ( " %6.6lx %6.6lx %2.2lx",
4279 (unsigned long) section
->sh_offset
,
4280 (unsigned long) section
->sh_size
,
4281 (unsigned long) section
->sh_entsize
);
4283 if (do_section_details
)
4284 fputs (" ", stdout
);
4286 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4288 printf ("%2ld %3lu %2ld\n",
4289 (unsigned long) section
->sh_link
,
4290 (unsigned long) section
->sh_info
,
4291 (unsigned long) section
->sh_addralign
);
4295 print_vma (section
->sh_addr
, LONG_HEX
);
4297 if ((long) section
->sh_offset
== section
->sh_offset
)
4298 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4302 print_vma (section
->sh_offset
, LONG_HEX
);
4305 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4306 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4310 print_vma (section
->sh_size
, LONG_HEX
);
4313 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4314 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4318 print_vma (section
->sh_entsize
, LONG_HEX
);
4321 if (do_section_details
)
4322 fputs (" ", stdout
);
4324 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4326 printf ("%2ld %3lu ",
4327 (unsigned long) section
->sh_link
,
4328 (unsigned long) section
->sh_info
);
4330 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4331 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4334 print_vma (section
->sh_addralign
, DEC
);
4338 else if (do_section_details
)
4340 printf (" %-15.15s ",
4341 get_section_type_name (section
->sh_type
));
4342 print_vma (section
->sh_addr
, LONG_HEX
);
4343 if ((long) section
->sh_offset
== section
->sh_offset
)
4344 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4348 print_vma (section
->sh_offset
, LONG_HEX
);
4350 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4351 print_vma (section
->sh_size
, LONG_HEX
);
4353 print_vma (section
->sh_entsize
, LONG_HEX
);
4355 printf (" %-16lu %ld\n",
4356 (unsigned long) section
->sh_info
,
4357 (unsigned long) section
->sh_addralign
);
4362 print_vma (section
->sh_addr
, LONG_HEX
);
4363 if ((long) section
->sh_offset
== section
->sh_offset
)
4364 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4368 print_vma (section
->sh_offset
, LONG_HEX
);
4371 print_vma (section
->sh_size
, LONG_HEX
);
4373 print_vma (section
->sh_entsize
, LONG_HEX
);
4375 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4377 printf (" %2ld %3lu %ld\n",
4378 (unsigned long) section
->sh_link
,
4379 (unsigned long) section
->sh_info
,
4380 (unsigned long) section
->sh_addralign
);
4383 if (do_section_details
)
4384 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4387 if (!do_section_details
)
4388 printf (_("Key to Flags:\n\
4389 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4390 I (info), L (link order), G (group), x (unknown)\n\
4391 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4397 get_group_flags (unsigned int flags
)
4399 static char buff
[32];
4406 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4413 process_section_groups (FILE *file
)
4415 Elf_Internal_Shdr
*section
;
4417 struct group
*group
;
4418 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4419 Elf_Internal_Sym
*symtab
;
4423 /* Don't process section groups unless needed. */
4424 if (!do_unwind
&& !do_section_groups
)
4427 if (elf_header
.e_shnum
== 0)
4429 if (do_section_groups
)
4430 printf (_("\nThere are no sections in this file.\n"));
4435 if (section_headers
== NULL
)
4437 error (_("Section headers are not available!\n"));
4441 section_headers_groups
= calloc (elf_header
.e_shnum
,
4442 sizeof (struct group
*));
4444 if (section_headers_groups
== NULL
)
4446 error (_("Out of memory\n"));
4450 /* Scan the sections for the group section. */
4452 for (i
= 0, section
= section_headers
;
4453 i
< elf_header
.e_shnum
;
4455 if (section
->sh_type
== SHT_GROUP
)
4458 if (group_count
== 0)
4460 if (do_section_groups
)
4461 printf (_("\nThere are no section groups in this file.\n"));
4466 section_groups
= calloc (group_count
, sizeof (struct group
));
4468 if (section_groups
== NULL
)
4470 error (_("Out of memory\n"));
4479 for (i
= 0, section
= section_headers
, group
= section_groups
;
4480 i
< elf_header
.e_shnum
;
4483 if (section
->sh_type
== SHT_GROUP
)
4485 char *name
= SECTION_NAME (section
);
4487 unsigned char *start
, *indices
;
4488 unsigned int entry
, j
, size
;
4489 Elf_Internal_Shdr
*sec
;
4490 Elf_Internal_Sym
*sym
;
4492 /* Get the symbol table. */
4493 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4494 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4497 error (_("Bad sh_link in group section `%s'\n"), name
);
4501 if (symtab_sec
!= sec
)
4506 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4509 sym
= symtab
+ section
->sh_info
;
4511 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4513 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4516 error (_("Bad sh_info in group section `%s'\n"), name
);
4520 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4529 /* Get the string table. */
4530 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4531 >= elf_header
.e_shnum
)
4540 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4545 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4546 1, strtab_sec
->sh_size
,
4548 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4550 group_name
= sym
->st_name
< strtab_size
4551 ? strtab
+ sym
->st_name
: "<corrupt>";
4554 start
= get_data (NULL
, file
, section
->sh_offset
,
4555 1, section
->sh_size
, _("section data"));
4558 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4559 entry
= byte_get (indices
, 4);
4562 if (do_section_groups
)
4564 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4565 get_group_flags (entry
), i
, name
, group_name
, size
);
4567 printf (_(" [Index] Name\n"));
4570 group
->group_index
= i
;
4572 for (j
= 0; j
< size
; j
++)
4574 struct group_list
*g
;
4576 entry
= byte_get (indices
, 4);
4579 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4581 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4582 entry
, i
, elf_header
.e_shnum
- 1);
4585 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4587 error (_("invalid section [%5u] in group section [%5u]\n"),
4592 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4597 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4599 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4604 /* Intel C/C++ compiler may put section 0 in a
4605 section group. We just warn it the first time
4606 and ignore it afterwards. */
4607 static int warned
= 0;
4610 error (_("section 0 in group section [%5u]\n"),
4611 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4617 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4620 if (do_section_groups
)
4622 sec
= SECTION_HEADER (entry
);
4623 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4626 g
= xmalloc (sizeof (struct group_list
));
4627 g
->section_index
= entry
;
4628 g
->next
= group
->root
;
4652 } dynamic_relocations
[] =
4654 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4655 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4656 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4659 /* Process the reloc section. */
4662 process_relocs (FILE *file
)
4664 unsigned long rel_size
;
4665 unsigned long rel_offset
;
4671 if (do_using_dynamic
)
4675 int has_dynamic_reloc
;
4678 has_dynamic_reloc
= 0;
4680 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4682 is_rela
= dynamic_relocations
[i
].rela
;
4683 name
= dynamic_relocations
[i
].name
;
4684 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4685 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4687 has_dynamic_reloc
|= rel_size
;
4689 if (is_rela
== UNKNOWN
)
4691 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4692 switch (dynamic_info
[DT_PLTREL
])
4706 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4707 name
, rel_offset
, rel_size
);
4709 dump_relocations (file
,
4710 offset_from_vma (file
, rel_offset
, rel_size
),
4712 dynamic_symbols
, num_dynamic_syms
,
4713 dynamic_strings
, dynamic_strings_length
, is_rela
);
4717 if (! has_dynamic_reloc
)
4718 printf (_("\nThere are no dynamic relocations in this file.\n"));
4722 Elf_Internal_Shdr
*section
;
4726 for (i
= 0, section
= section_headers
;
4727 i
< elf_header
.e_shnum
;
4730 if ( section
->sh_type
!= SHT_RELA
4731 && section
->sh_type
!= SHT_REL
)
4734 rel_offset
= section
->sh_offset
;
4735 rel_size
= section
->sh_size
;
4739 Elf_Internal_Shdr
*strsec
;
4742 printf (_("\nRelocation section "));
4744 if (string_table
== NULL
)
4745 printf ("%d", section
->sh_name
);
4747 printf (_("'%s'"), SECTION_NAME (section
));
4749 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4750 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4752 is_rela
= section
->sh_type
== SHT_RELA
;
4754 if (section
->sh_link
4755 && SECTION_HEADER_INDEX (section
->sh_link
)
4756 < elf_header
.e_shnum
)
4758 Elf_Internal_Shdr
*symsec
;
4759 Elf_Internal_Sym
*symtab
;
4760 unsigned long nsyms
;
4761 unsigned long strtablen
= 0;
4762 char *strtab
= NULL
;
4764 symsec
= SECTION_HEADER (section
->sh_link
);
4765 if (symsec
->sh_type
!= SHT_SYMTAB
4766 && symsec
->sh_type
!= SHT_DYNSYM
)
4769 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4770 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4775 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4776 < elf_header
.e_shnum
)
4778 strsec
= SECTION_HEADER (symsec
->sh_link
);
4780 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4783 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4786 dump_relocations (file
, rel_offset
, rel_size
,
4787 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4793 dump_relocations (file
, rel_offset
, rel_size
,
4794 NULL
, 0, NULL
, 0, is_rela
);
4801 printf (_("\nThere are no relocations in this file.\n"));
4807 /* Process the unwind section. */
4809 #include "unwind-ia64.h"
4811 /* An absolute address consists of a section and an offset. If the
4812 section is NULL, the offset itself is the address, otherwise, the
4813 address equals to LOAD_ADDRESS(section) + offset. */
4817 unsigned short section
;
4821 #define ABSADDR(a) \
4823 ? section_headers [(a).section].sh_addr + (a).offset \
4826 struct ia64_unw_aux_info
4828 struct ia64_unw_table_entry
4830 struct absaddr start
;
4832 struct absaddr info
;
4834 *table
; /* Unwind table. */
4835 unsigned long table_len
; /* Length of unwind table. */
4836 unsigned char *info
; /* Unwind info. */
4837 unsigned long info_size
; /* Size of unwind info. */
4838 bfd_vma info_addr
; /* starting address of unwind info. */
4839 bfd_vma seg_base
; /* Starting address of segment. */
4840 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4841 unsigned long nsyms
; /* Number of symbols. */
4842 char *strtab
; /* The string table. */
4843 unsigned long strtab_size
; /* Size of string table. */
4847 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4848 unsigned long nsyms
,
4850 unsigned long strtab_size
,
4851 struct absaddr addr
,
4852 const char **symname
,
4855 bfd_vma dist
= 0x100000;
4856 Elf_Internal_Sym
*sym
, *best
= NULL
;
4859 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4861 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4862 && sym
->st_name
!= 0
4863 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4864 && addr
.offset
>= sym
->st_value
4865 && addr
.offset
- sym
->st_value
< dist
)
4868 dist
= addr
.offset
- sym
->st_value
;
4875 *symname
= (best
->st_name
>= strtab_size
4876 ? "<corrupt>" : strtab
+ best
->st_name
);
4881 *offset
= addr
.offset
;
4885 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4887 struct ia64_unw_table_entry
*tp
;
4890 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4894 const unsigned char *dp
;
4895 const unsigned char *head
;
4896 const char *procname
;
4898 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4899 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4901 fputs ("\n<", stdout
);
4905 fputs (procname
, stdout
);
4908 printf ("+%lx", (unsigned long) offset
);
4911 fputs (">: [", stdout
);
4912 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4913 fputc ('-', stdout
);
4914 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4915 printf ("], info at +0x%lx\n",
4916 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4918 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4919 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4921 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4922 (unsigned) UNW_VER (stamp
),
4923 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4924 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4925 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4926 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4928 if (UNW_VER (stamp
) != 1)
4930 printf ("\tUnknown version.\n");
4935 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4936 dp
= unw_decode (dp
, in_body
, & in_body
);
4941 slurp_ia64_unwind_table (FILE *file
,
4942 struct ia64_unw_aux_info
*aux
,
4943 Elf_Internal_Shdr
*sec
)
4945 unsigned long size
, nrelas
, i
;
4946 Elf_Internal_Phdr
*seg
;
4947 struct ia64_unw_table_entry
*tep
;
4948 Elf_Internal_Shdr
*relsec
;
4949 Elf_Internal_Rela
*rela
, *rp
;
4950 unsigned char *table
, *tp
;
4951 Elf_Internal_Sym
*sym
;
4952 const char *relname
;
4954 /* First, find the starting address of the segment that includes
4957 if (elf_header
.e_phnum
)
4959 if (! get_program_headers (file
))
4962 for (seg
= program_headers
;
4963 seg
< program_headers
+ elf_header
.e_phnum
;
4966 if (seg
->p_type
!= PT_LOAD
)
4969 if (sec
->sh_addr
>= seg
->p_vaddr
4970 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4972 aux
->seg_base
= seg
->p_vaddr
;
4978 /* Second, build the unwind table from the contents of the unwind section: */
4979 size
= sec
->sh_size
;
4980 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4984 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4986 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4988 tep
->start
.section
= SHN_UNDEF
;
4989 tep
->end
.section
= SHN_UNDEF
;
4990 tep
->info
.section
= SHN_UNDEF
;
4993 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4994 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4995 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4999 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
5000 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
5001 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
5003 tep
->start
.offset
+= aux
->seg_base
;
5004 tep
->end
.offset
+= aux
->seg_base
;
5005 tep
->info
.offset
+= aux
->seg_base
;
5009 /* Third, apply any relocations to the unwind table: */
5011 for (relsec
= section_headers
;
5012 relsec
< section_headers
+ elf_header
.e_shnum
;
5015 if (relsec
->sh_type
!= SHT_RELA
5016 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5017 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5020 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5024 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5028 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5029 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5033 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5034 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5037 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5039 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5043 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5045 switch (rp
->r_offset
/eh_addr_size
% 3)
5048 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5049 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5052 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5053 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5056 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5057 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5067 aux
->table_len
= size
/ (3 * eh_addr_size
);
5072 ia64_process_unwind (FILE *file
)
5074 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
5075 unsigned long i
, unwcount
= 0, unwstart
= 0;
5076 struct ia64_unw_aux_info aux
;
5078 memset (& aux
, 0, sizeof (aux
));
5080 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5082 if (sec
->sh_type
== SHT_SYMTAB
5083 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5085 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5086 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5088 strsec
= SECTION_HEADER (sec
->sh_link
);
5089 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5090 1, strsec
->sh_size
, _("string table"));
5091 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5093 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5098 printf (_("\nThere are no unwind sections in this file.\n"));
5100 while (unwcount
-- > 0)
5105 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5106 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5107 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5114 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5116 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5118 /* We need to find which section group it is in. */
5119 struct group_list
*g
= section_headers_groups
[i
]->root
;
5121 for (; g
!= NULL
; g
= g
->next
)
5123 sec
= SECTION_HEADER (g
->section_index
);
5125 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5130 i
= elf_header
.e_shnum
;
5132 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5134 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5135 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5136 suffix
= SECTION_NAME (unwsec
) + len
;
5137 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5139 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5140 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5145 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5146 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5147 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5148 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5150 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5151 suffix
= SECTION_NAME (unwsec
) + len
;
5152 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5154 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5155 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5159 if (i
== elf_header
.e_shnum
)
5161 printf (_("\nCould not find unwind info section for "));
5163 if (string_table
== NULL
)
5164 printf ("%d", unwsec
->sh_name
);
5166 printf (_("'%s'"), SECTION_NAME (unwsec
));
5170 aux
.info_size
= sec
->sh_size
;
5171 aux
.info_addr
= sec
->sh_addr
;
5172 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
5175 printf (_("\nUnwind section "));
5177 if (string_table
== NULL
)
5178 printf ("%d", unwsec
->sh_name
);
5180 printf (_("'%s'"), SECTION_NAME (unwsec
));
5182 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5183 (unsigned long) unwsec
->sh_offset
,
5184 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5186 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5188 if (aux
.table_len
> 0)
5189 dump_ia64_unwind (& aux
);
5192 free ((char *) aux
.table
);
5194 free ((char *) aux
.info
);
5203 free ((char *) aux
.strtab
);
5208 struct hppa_unw_aux_info
5210 struct hppa_unw_table_entry
5212 struct absaddr start
;
5214 unsigned int Cannot_unwind
:1; /* 0 */
5215 unsigned int Millicode
:1; /* 1 */
5216 unsigned int Millicode_save_sr0
:1; /* 2 */
5217 unsigned int Region_description
:2; /* 3..4 */
5218 unsigned int reserved1
:1; /* 5 */
5219 unsigned int Entry_SR
:1; /* 6 */
5220 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5221 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5222 unsigned int Args_stored
:1; /* 16 */
5223 unsigned int Variable_Frame
:1; /* 17 */
5224 unsigned int Separate_Package_Body
:1; /* 18 */
5225 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5226 unsigned int Stack_Overflow_Check
:1; /* 20 */
5227 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5228 unsigned int Ada_Region
:1; /* 22 */
5229 unsigned int cxx_info
:1; /* 23 */
5230 unsigned int cxx_try_catch
:1; /* 24 */
5231 unsigned int sched_entry_seq
:1; /* 25 */
5232 unsigned int reserved2
:1; /* 26 */
5233 unsigned int Save_SP
:1; /* 27 */
5234 unsigned int Save_RP
:1; /* 28 */
5235 unsigned int Save_MRP_in_frame
:1; /* 29 */
5236 unsigned int extn_ptr_defined
:1; /* 30 */
5237 unsigned int Cleanup_defined
:1; /* 31 */
5239 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5240 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5241 unsigned int Large_frame
:1; /* 2 */
5242 unsigned int Pseudo_SP_Set
:1; /* 3 */
5243 unsigned int reserved4
:1; /* 4 */
5244 unsigned int Total_frame_size
:27; /* 5..31 */
5246 *table
; /* Unwind table. */
5247 unsigned long table_len
; /* Length of unwind table. */
5248 bfd_vma seg_base
; /* Starting address of segment. */
5249 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5250 unsigned long nsyms
; /* Number of symbols. */
5251 char *strtab
; /* The string table. */
5252 unsigned long strtab_size
; /* Size of string table. */
5256 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5258 struct hppa_unw_table_entry
*tp
;
5260 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5263 const char *procname
;
5265 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5266 aux
->strtab_size
, tp
->start
, &procname
,
5269 fputs ("\n<", stdout
);
5273 fputs (procname
, stdout
);
5276 printf ("+%lx", (unsigned long) offset
);
5279 fputs (">: [", stdout
);
5280 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5281 fputc ('-', stdout
);
5282 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5285 #define PF(_m) if (tp->_m) printf (#_m " ");
5286 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5289 PF(Millicode_save_sr0
);
5290 /* PV(Region_description); */
5296 PF(Separate_Package_Body
);
5297 PF(Frame_Extension_Millicode
);
5298 PF(Stack_Overflow_Check
);
5299 PF(Two_Instruction_SP_Increment
);
5303 PF(sched_entry_seq
);
5306 PF(Save_MRP_in_frame
);
5307 PF(extn_ptr_defined
);
5308 PF(Cleanup_defined
);
5309 PF(MPE_XL_interrupt_marker
);
5310 PF(HP_UX_interrupt_marker
);
5313 PV(Total_frame_size
);
5322 slurp_hppa_unwind_table (FILE *file
,
5323 struct hppa_unw_aux_info
*aux
,
5324 Elf_Internal_Shdr
*sec
)
5326 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5327 Elf_Internal_Phdr
*seg
;
5328 struct hppa_unw_table_entry
*tep
;
5329 Elf_Internal_Shdr
*relsec
;
5330 Elf_Internal_Rela
*rela
, *rp
;
5331 unsigned char *table
, *tp
;
5332 Elf_Internal_Sym
*sym
;
5333 const char *relname
;
5335 /* First, find the starting address of the segment that includes
5338 if (elf_header
.e_phnum
)
5340 if (! get_program_headers (file
))
5343 for (seg
= program_headers
;
5344 seg
< program_headers
+ elf_header
.e_phnum
;
5347 if (seg
->p_type
!= PT_LOAD
)
5350 if (sec
->sh_addr
>= seg
->p_vaddr
5351 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5353 aux
->seg_base
= seg
->p_vaddr
;
5359 /* Second, build the unwind table from the contents of the unwind
5361 size
= sec
->sh_size
;
5362 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5367 nentries
= size
/ unw_ent_size
;
5368 size
= unw_ent_size
* nentries
;
5370 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5372 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5374 unsigned int tmp1
, tmp2
;
5376 tep
->start
.section
= SHN_UNDEF
;
5377 tep
->end
.section
= SHN_UNDEF
;
5379 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5380 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5381 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5382 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5384 tep
->start
.offset
+= aux
->seg_base
;
5385 tep
->end
.offset
+= aux
->seg_base
;
5387 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5388 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5389 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5390 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5391 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5392 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5393 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5394 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5395 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5396 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5397 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5398 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5399 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5400 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5401 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5402 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5403 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5404 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5405 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5406 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5407 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5408 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5409 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5410 tep
->Cleanup_defined
= tmp1
& 0x1;
5412 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5413 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5414 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5415 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5416 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5417 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5421 /* Third, apply any relocations to the unwind table. */
5423 for (relsec
= section_headers
;
5424 relsec
< section_headers
+ elf_header
.e_shnum
;
5427 if (relsec
->sh_type
!= SHT_RELA
5428 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5429 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5432 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5436 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5440 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5441 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5445 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5446 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5449 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5450 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5452 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5456 i
= rp
->r_offset
/ unw_ent_size
;
5458 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5461 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5462 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5465 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5466 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5476 aux
->table_len
= nentries
;
5482 hppa_process_unwind (FILE *file
)
5484 struct hppa_unw_aux_info aux
;
5485 Elf_Internal_Shdr
*unwsec
= NULL
;
5486 Elf_Internal_Shdr
*strsec
;
5487 Elf_Internal_Shdr
*sec
;
5490 memset (& aux
, 0, sizeof (aux
));
5492 if (string_table
== NULL
)
5495 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5497 if (sec
->sh_type
== SHT_SYMTAB
5498 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5500 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5501 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5503 strsec
= SECTION_HEADER (sec
->sh_link
);
5504 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5505 1, strsec
->sh_size
, _("string table"));
5506 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5508 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5513 printf (_("\nThere are no unwind sections in this file.\n"));
5515 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5517 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5519 printf (_("\nUnwind section "));
5520 printf (_("'%s'"), SECTION_NAME (sec
));
5522 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5523 (unsigned long) sec
->sh_offset
,
5524 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5526 slurp_hppa_unwind_table (file
, &aux
, sec
);
5527 if (aux
.table_len
> 0)
5528 dump_hppa_unwind (&aux
);
5531 free ((char *) aux
.table
);
5539 free ((char *) aux
.strtab
);
5545 process_unwind (FILE *file
)
5547 struct unwind_handler
{
5549 int (*handler
)(FILE *file
);
5551 { EM_IA_64
, ia64_process_unwind
},
5552 { EM_PARISC
, hppa_process_unwind
},
5560 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5561 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5562 return handlers
[i
].handler (file
);
5564 printf (_("\nThere are no unwind sections in this file.\n"));
5569 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5571 switch (entry
->d_tag
)
5574 if (entry
->d_un
.d_val
== 0)
5578 static const char * opts
[] =
5580 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5581 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5582 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5583 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5588 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
5589 if (entry
->d_un
.d_val
& (1 << cnt
))
5591 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5598 case DT_MIPS_IVERSION
:
5599 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5600 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5602 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5605 case DT_MIPS_TIME_STAMP
:
5610 time_t time
= entry
->d_un
.d_val
;
5611 tmp
= gmtime (&time
);
5612 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5613 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5614 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5615 printf ("Time Stamp: %s\n", timebuf
);
5619 case DT_MIPS_RLD_VERSION
:
5620 case DT_MIPS_LOCAL_GOTNO
:
5621 case DT_MIPS_CONFLICTNO
:
5622 case DT_MIPS_LIBLISTNO
:
5623 case DT_MIPS_SYMTABNO
:
5624 case DT_MIPS_UNREFEXTNO
:
5625 case DT_MIPS_HIPAGENO
:
5626 case DT_MIPS_DELTA_CLASS_NO
:
5627 case DT_MIPS_DELTA_INSTANCE_NO
:
5628 case DT_MIPS_DELTA_RELOC_NO
:
5629 case DT_MIPS_DELTA_SYM_NO
:
5630 case DT_MIPS_DELTA_CLASSSYM_NO
:
5631 case DT_MIPS_COMPACT_SIZE
:
5632 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5636 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5642 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5644 switch (entry
->d_tag
)
5646 case DT_HP_DLD_FLAGS
:
5655 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5656 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5657 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5658 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5659 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5660 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5661 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5662 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5663 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5664 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5665 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5666 { DT_HP_GST
, "HP_GST" },
5667 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5668 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5669 { DT_HP_NODELETE
, "HP_NODELETE" },
5670 { DT_HP_GROUP
, "HP_GROUP" },
5671 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5675 bfd_vma val
= entry
->d_un
.d_val
;
5677 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
5678 if (val
& flags
[cnt
].bit
)
5682 fputs (flags
[cnt
].str
, stdout
);
5684 val
^= flags
[cnt
].bit
;
5687 if (val
!= 0 || first
)
5691 print_vma (val
, HEX
);
5697 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5704 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5706 switch (entry
->d_tag
)
5708 case DT_IA_64_PLT_RESERVE
:
5709 /* First 3 slots reserved. */
5710 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5712 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5716 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5723 get_32bit_dynamic_section (FILE *file
)
5725 Elf32_External_Dyn
*edyn
, *ext
;
5726 Elf_Internal_Dyn
*entry
;
5728 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5729 _("dynamic section"));
5733 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5734 might not have the luxury of section headers. Look for the DT_NULL
5735 terminator to determine the number of entries. */
5736 for (ext
= edyn
, dynamic_nent
= 0;
5737 (char *) ext
< (char *) edyn
+ dynamic_size
;
5741 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5745 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5746 if (dynamic_section
== NULL
)
5748 error (_("Out of memory\n"));
5753 for (ext
= edyn
, entry
= dynamic_section
;
5754 entry
< dynamic_section
+ dynamic_nent
;
5757 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5758 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5767 get_64bit_dynamic_section (FILE *file
)
5769 Elf64_External_Dyn
*edyn
, *ext
;
5770 Elf_Internal_Dyn
*entry
;
5772 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5773 _("dynamic section"));
5777 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5778 might not have the luxury of section headers. Look for the DT_NULL
5779 terminator to determine the number of entries. */
5780 for (ext
= edyn
, dynamic_nent
= 0;
5781 (char *) ext
< (char *) edyn
+ dynamic_size
;
5785 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5789 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5790 if (dynamic_section
== NULL
)
5792 error (_("Out of memory\n"));
5797 for (ext
= edyn
, entry
= dynamic_section
;
5798 entry
< dynamic_section
+ dynamic_nent
;
5801 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5802 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5811 print_dynamic_flags (bfd_vma flags
)
5819 flag
= flags
& - flags
;
5829 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5830 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5831 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5832 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5833 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5834 default: fputs ("unknown", stdout
); break;
5840 /* Parse and display the contents of the dynamic section. */
5843 process_dynamic_section (FILE *file
)
5845 Elf_Internal_Dyn
*entry
;
5847 if (dynamic_size
== 0)
5850 printf (_("\nThere is no dynamic section in this file.\n"));
5857 if (! get_32bit_dynamic_section (file
))
5860 else if (! get_64bit_dynamic_section (file
))
5863 /* Find the appropriate symbol table. */
5864 if (dynamic_symbols
== NULL
)
5866 for (entry
= dynamic_section
;
5867 entry
< dynamic_section
+ dynamic_nent
;
5870 Elf_Internal_Shdr section
;
5872 if (entry
->d_tag
!= DT_SYMTAB
)
5875 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5877 /* Since we do not know how big the symbol table is,
5878 we default to reading in the entire file (!) and
5879 processing that. This is overkill, I know, but it
5881 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5883 if (archive_file_offset
!= 0)
5884 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5887 if (fseek (file
, 0, SEEK_END
))
5888 error (_("Unable to seek to end of file!\n"));
5890 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5894 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5896 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5898 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5899 if (num_dynamic_syms
< 1)
5901 error (_("Unable to determine the number of symbols to load\n"));
5905 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5909 /* Similarly find a string table. */
5910 if (dynamic_strings
== NULL
)
5912 for (entry
= dynamic_section
;
5913 entry
< dynamic_section
+ dynamic_nent
;
5916 unsigned long offset
;
5919 if (entry
->d_tag
!= DT_STRTAB
)
5922 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5924 /* Since we do not know how big the string table is,
5925 we default to reading in the entire file (!) and
5926 processing that. This is overkill, I know, but it
5929 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5931 if (archive_file_offset
!= 0)
5932 str_tab_len
= archive_file_size
- offset
;
5935 if (fseek (file
, 0, SEEK_END
))
5936 error (_("Unable to seek to end of file\n"));
5937 str_tab_len
= ftell (file
) - offset
;
5940 if (str_tab_len
< 1)
5943 (_("Unable to determine the length of the dynamic string table\n"));
5947 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5948 _("dynamic string table"));
5949 dynamic_strings_length
= str_tab_len
;
5954 /* And find the syminfo section if available. */
5955 if (dynamic_syminfo
== NULL
)
5957 unsigned long syminsz
= 0;
5959 for (entry
= dynamic_section
;
5960 entry
< dynamic_section
+ dynamic_nent
;
5963 if (entry
->d_tag
== DT_SYMINENT
)
5965 /* Note: these braces are necessary to avoid a syntax
5966 error from the SunOS4 C compiler. */
5967 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5969 else if (entry
->d_tag
== DT_SYMINSZ
)
5970 syminsz
= entry
->d_un
.d_val
;
5971 else if (entry
->d_tag
== DT_SYMINFO
)
5972 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5976 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5978 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5979 Elf_Internal_Syminfo
*syminfo
;
5981 /* There is a syminfo section. Read the data. */
5982 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5983 syminsz
, _("symbol information"));
5987 dynamic_syminfo
= malloc (syminsz
);
5988 if (dynamic_syminfo
== NULL
)
5990 error (_("Out of memory\n"));
5994 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5995 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5996 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5997 ++syminfo
, ++extsym
)
5999 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
6000 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
6007 if (do_dynamic
&& dynamic_addr
)
6008 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
6009 dynamic_addr
, dynamic_nent
);
6011 printf (_(" Tag Type Name/Value\n"));
6013 for (entry
= dynamic_section
;
6014 entry
< dynamic_section
+ dynamic_nent
;
6022 print_vma (entry
->d_tag
, FULL_HEX
);
6023 dtype
= get_dynamic_type (entry
->d_tag
);
6024 printf (" (%s)%*s", dtype
,
6025 ((is_32bit_elf
? 27 : 19)
6026 - (int) strlen (dtype
)),
6030 switch (entry
->d_tag
)
6034 print_dynamic_flags (entry
->d_un
.d_val
);
6044 switch (entry
->d_tag
)
6047 printf (_("Auxiliary library"));
6051 printf (_("Filter library"));
6055 printf (_("Configuration file"));
6059 printf (_("Dependency audit library"));
6063 printf (_("Audit library"));
6067 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6068 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6072 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6081 printf (_("Flags:"));
6083 if (entry
->d_un
.d_val
== 0)
6084 printf (_(" None\n"));
6087 unsigned long int val
= entry
->d_un
.d_val
;
6089 if (val
& DTF_1_PARINIT
)
6091 printf (" PARINIT");
6092 val
^= DTF_1_PARINIT
;
6094 if (val
& DTF_1_CONFEXP
)
6096 printf (" CONFEXP");
6097 val
^= DTF_1_CONFEXP
;
6100 printf (" %lx", val
);
6109 printf (_("Flags:"));
6111 if (entry
->d_un
.d_val
== 0)
6112 printf (_(" None\n"));
6115 unsigned long int val
= entry
->d_un
.d_val
;
6117 if (val
& DF_P1_LAZYLOAD
)
6119 printf (" LAZYLOAD");
6120 val
^= DF_P1_LAZYLOAD
;
6122 if (val
& DF_P1_GROUPPERM
)
6124 printf (" GROUPPERM");
6125 val
^= DF_P1_GROUPPERM
;
6128 printf (" %lx", val
);
6137 printf (_("Flags:"));
6138 if (entry
->d_un
.d_val
== 0)
6139 printf (_(" None\n"));
6142 unsigned long int val
= entry
->d_un
.d_val
;
6149 if (val
& DF_1_GLOBAL
)
6154 if (val
& DF_1_GROUP
)
6159 if (val
& DF_1_NODELETE
)
6161 printf (" NODELETE");
6162 val
^= DF_1_NODELETE
;
6164 if (val
& DF_1_LOADFLTR
)
6166 printf (" LOADFLTR");
6167 val
^= DF_1_LOADFLTR
;
6169 if (val
& DF_1_INITFIRST
)
6171 printf (" INITFIRST");
6172 val
^= DF_1_INITFIRST
;
6174 if (val
& DF_1_NOOPEN
)
6179 if (val
& DF_1_ORIGIN
)
6184 if (val
& DF_1_DIRECT
)
6189 if (val
& DF_1_TRANS
)
6194 if (val
& DF_1_INTERPOSE
)
6196 printf (" INTERPOSE");
6197 val
^= DF_1_INTERPOSE
;
6199 if (val
& DF_1_NODEFLIB
)
6201 printf (" NODEFLIB");
6202 val
^= DF_1_NODEFLIB
;
6204 if (val
& DF_1_NODUMP
)
6209 if (val
& DF_1_CONLFAT
)
6211 printf (" CONLFAT");
6212 val
^= DF_1_CONLFAT
;
6215 printf (" %lx", val
);
6222 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6224 puts (get_dynamic_type (entry
->d_un
.d_val
));
6244 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6250 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6251 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6257 switch (entry
->d_tag
)
6260 printf (_("Shared library: [%s]"), name
);
6262 if (streq (name
, program_interpreter
))
6263 printf (_(" program interpreter"));
6267 printf (_("Library soname: [%s]"), name
);
6271 printf (_("Library rpath: [%s]"), name
);
6275 printf (_("Library runpath: [%s]"), name
);
6279 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6284 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6297 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6301 case DT_INIT_ARRAYSZ
:
6302 case DT_FINI_ARRAYSZ
:
6303 case DT_GNU_CONFLICTSZ
:
6304 case DT_GNU_LIBLISTSZ
:
6307 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6308 printf (" (bytes)\n");
6318 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6331 if (entry
->d_tag
== DT_USED
6332 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6334 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6338 printf (_("Not needed object: [%s]\n"), name
);
6343 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6349 /* The value of this entry is ignored. */
6354 case DT_GNU_PRELINKED
:
6358 time_t time
= entry
->d_un
.d_val
;
6360 tmp
= gmtime (&time
);
6361 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6362 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6363 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6369 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6372 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6378 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6379 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6384 switch (elf_header
.e_machine
)
6387 case EM_MIPS_RS3_LE
:
6388 dynamic_section_mips_val (entry
);
6391 dynamic_section_parisc_val (entry
);
6394 dynamic_section_ia64_val (entry
);
6397 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6409 get_ver_flags (unsigned int flags
)
6411 static char buff
[32];
6418 if (flags
& VER_FLG_BASE
)
6419 strcat (buff
, "BASE ");
6421 if (flags
& VER_FLG_WEAK
)
6423 if (flags
& VER_FLG_BASE
)
6424 strcat (buff
, "| ");
6426 strcat (buff
, "WEAK ");
6429 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6430 strcat (buff
, "| <unknown>");
6435 /* Display the contents of the version sections. */
6437 process_version_sections (FILE *file
)
6439 Elf_Internal_Shdr
*section
;
6446 for (i
= 0, section
= section_headers
;
6447 i
< elf_header
.e_shnum
;
6450 switch (section
->sh_type
)
6452 case SHT_GNU_verdef
:
6454 Elf_External_Verdef
*edefs
;
6461 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6462 SECTION_NAME (section
), section
->sh_info
);
6464 printf (_(" Addr: 0x"));
6465 printf_vma (section
->sh_addr
);
6466 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6467 (unsigned long) section
->sh_offset
, section
->sh_link
,
6468 SECTION_HEADER_INDEX (section
->sh_link
)
6469 < elf_header
.e_shnum
6470 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6473 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6475 _("version definition section"));
6479 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6482 Elf_External_Verdef
*edef
;
6483 Elf_Internal_Verdef ent
;
6484 Elf_External_Verdaux
*eaux
;
6485 Elf_Internal_Verdaux aux
;
6489 vstart
= ((char *) edefs
) + idx
;
6491 edef
= (Elf_External_Verdef
*) vstart
;
6493 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6494 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6495 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6496 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6497 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6498 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6499 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6501 printf (_(" %#06x: Rev: %d Flags: %s"),
6502 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6504 printf (_(" Index: %d Cnt: %d "),
6505 ent
.vd_ndx
, ent
.vd_cnt
);
6507 vstart
+= ent
.vd_aux
;
6509 eaux
= (Elf_External_Verdaux
*) vstart
;
6511 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6512 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6514 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6515 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6517 printf (_("Name index: %ld\n"), aux
.vda_name
);
6519 isum
= idx
+ ent
.vd_aux
;
6521 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6523 isum
+= aux
.vda_next
;
6524 vstart
+= aux
.vda_next
;
6526 eaux
= (Elf_External_Verdaux
*) vstart
;
6528 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6529 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6531 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6532 printf (_(" %#06x: Parent %d: %s\n"),
6533 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6535 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6536 isum
, j
, aux
.vda_name
);
6546 case SHT_GNU_verneed
:
6548 Elf_External_Verneed
*eneed
;
6554 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6555 SECTION_NAME (section
), section
->sh_info
);
6557 printf (_(" Addr: 0x"));
6558 printf_vma (section
->sh_addr
);
6559 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6560 (unsigned long) section
->sh_offset
, section
->sh_link
,
6561 SECTION_HEADER_INDEX (section
->sh_link
)
6562 < elf_header
.e_shnum
6563 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6566 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6568 _("version need section"));
6572 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6574 Elf_External_Verneed
*entry
;
6575 Elf_Internal_Verneed ent
;
6580 vstart
= ((char *) eneed
) + idx
;
6582 entry
= (Elf_External_Verneed
*) vstart
;
6584 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6585 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6586 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6587 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6588 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6590 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6592 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6593 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6595 printf (_(" File: %lx"), ent
.vn_file
);
6597 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6599 vstart
+= ent
.vn_aux
;
6601 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6603 Elf_External_Vernaux
*eaux
;
6604 Elf_Internal_Vernaux aux
;
6606 eaux
= (Elf_External_Vernaux
*) vstart
;
6608 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6609 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6610 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6611 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6612 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6614 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6615 printf (_(" %#06x: Name: %s"),
6616 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6618 printf (_(" %#06x: Name index: %lx"),
6619 isum
, aux
.vna_name
);
6621 printf (_(" Flags: %s Version: %d\n"),
6622 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6624 isum
+= aux
.vna_next
;
6625 vstart
+= aux
.vna_next
;
6635 case SHT_GNU_versym
:
6637 Elf_Internal_Shdr
*link_section
;
6640 unsigned char *edata
;
6641 unsigned short *data
;
6643 Elf_Internal_Sym
*symbols
;
6644 Elf_Internal_Shdr
*string_sec
;
6647 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6650 link_section
= SECTION_HEADER (section
->sh_link
);
6651 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6653 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6654 >= elf_header
.e_shnum
)
6659 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6661 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6663 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6664 string_sec
->sh_size
, _("version string table"));
6668 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6669 SECTION_NAME (section
), total
);
6671 printf (_(" Addr: "));
6672 printf_vma (section
->sh_addr
);
6673 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6674 (unsigned long) section
->sh_offset
, section
->sh_link
,
6675 SECTION_NAME (link_section
));
6677 off
= offset_from_vma (file
,
6678 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6679 total
* sizeof (short));
6680 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6681 _("version symbol data"));
6688 data
= cmalloc (total
, sizeof (short));
6690 for (cnt
= total
; cnt
--;)
6691 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6696 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6699 int check_def
, check_need
;
6702 printf (" %03x:", cnt
);
6704 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6705 switch (data
[cnt
+ j
])
6708 fputs (_(" 0 (*local*) "), stdout
);
6712 fputs (_(" 1 (*global*) "), stdout
);
6716 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6717 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6721 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6722 >= elf_header
.e_shnum
6723 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6726 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6733 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6735 Elf_Internal_Verneed ivn
;
6736 unsigned long offset
;
6738 offset
= offset_from_vma
6739 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6740 sizeof (Elf_External_Verneed
));
6744 Elf_Internal_Vernaux ivna
;
6745 Elf_External_Verneed evn
;
6746 Elf_External_Vernaux evna
;
6747 unsigned long a_off
;
6749 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6752 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6753 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6755 a_off
= offset
+ ivn
.vn_aux
;
6759 get_data (&evna
, file
, a_off
, sizeof (evna
),
6760 1, _("version need aux (2)"));
6762 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6763 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6765 a_off
+= ivna
.vna_next
;
6767 while (ivna
.vna_other
!= data
[cnt
+ j
]
6768 && ivna
.vna_next
!= 0);
6770 if (ivna
.vna_other
== data
[cnt
+ j
])
6772 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6774 name
= strtab
+ ivna
.vna_name
;
6775 nn
+= printf ("(%s%-*s",
6777 12 - (int) strlen (name
),
6783 offset
+= ivn
.vn_next
;
6785 while (ivn
.vn_next
);
6788 if (check_def
&& data
[cnt
+ j
] != 0x8001
6789 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6791 Elf_Internal_Verdef ivd
;
6792 Elf_External_Verdef evd
;
6793 unsigned long offset
;
6795 offset
= offset_from_vma
6796 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6801 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6804 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6805 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6807 offset
+= ivd
.vd_next
;
6809 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6810 && ivd
.vd_next
!= 0);
6812 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6814 Elf_External_Verdaux evda
;
6815 Elf_Internal_Verdaux ivda
;
6817 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6819 get_data (&evda
, file
,
6820 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6822 _("version def aux"));
6824 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6826 name
= strtab
+ ivda
.vda_name
;
6827 nn
+= printf ("(%s%-*s",
6829 12 - (int) strlen (name
),
6835 printf ("%*c", 18 - nn
, ' ');
6853 printf (_("\nNo version information found in this file.\n"));
6859 get_symbol_binding (unsigned int binding
)
6861 static char buff
[32];
6865 case STB_LOCAL
: return "LOCAL";
6866 case STB_GLOBAL
: return "GLOBAL";
6867 case STB_WEAK
: return "WEAK";
6869 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6870 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6872 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6873 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6875 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6881 get_symbol_type (unsigned int type
)
6883 static char buff
[32];
6887 case STT_NOTYPE
: return "NOTYPE";
6888 case STT_OBJECT
: return "OBJECT";
6889 case STT_FUNC
: return "FUNC";
6890 case STT_SECTION
: return "SECTION";
6891 case STT_FILE
: return "FILE";
6892 case STT_COMMON
: return "COMMON";
6893 case STT_TLS
: return "TLS";
6894 case STT_RELC
: return "RELC";
6895 case STT_SRELC
: return "SRELC";
6897 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6899 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6900 return "THUMB_FUNC";
6902 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6905 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6906 return "PARISC_MILLI";
6908 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6910 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6912 if (elf_header
.e_machine
== EM_PARISC
)
6914 if (type
== STT_HP_OPAQUE
)
6916 if (type
== STT_HP_STUB
)
6920 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6923 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6929 get_symbol_visibility (unsigned int visibility
)
6933 case STV_DEFAULT
: return "DEFAULT";
6934 case STV_INTERNAL
: return "INTERNAL";
6935 case STV_HIDDEN
: return "HIDDEN";
6936 case STV_PROTECTED
: return "PROTECTED";
6942 get_mips_symbol_other (unsigned int other
)
6946 case STO_OPTIONAL
: return "OPTIONAL";
6947 case STO_MIPS16
: return "MIPS16";
6948 default: return NULL
;
6953 get_symbol_other (unsigned int other
)
6955 const char * result
= NULL
;
6956 static char buff
[32];
6961 switch (elf_header
.e_machine
)
6964 result
= get_mips_symbol_other (other
);
6972 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
6977 get_symbol_index_type (unsigned int type
)
6979 static char buff
[32];
6983 case SHN_UNDEF
: return "UND";
6984 case SHN_ABS
: return "ABS";
6985 case SHN_COMMON
: return "COM";
6987 if (type
== SHN_IA_64_ANSI_COMMON
6988 && elf_header
.e_machine
== EM_IA_64
6989 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6991 else if (elf_header
.e_machine
== EM_X86_64
6992 && type
== SHN_X86_64_LCOMMON
)
6994 else if (type
== SHN_MIPS_SCOMMON
6995 && elf_header
.e_machine
== EM_MIPS
)
6997 else if (type
== SHN_MIPS_SUNDEFINED
6998 && elf_header
.e_machine
== EM_MIPS
)
7000 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
7001 sprintf (buff
, "PRC[0x%04x]", type
);
7002 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
7003 sprintf (buff
, "OS [0x%04x]", type
);
7004 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
7005 sprintf (buff
, "RSV[0x%04x]", type
);
7007 sprintf (buff
, "%3d", type
);
7015 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
7017 unsigned char *e_data
;
7020 e_data
= cmalloc (number
, ent_size
);
7024 error (_("Out of memory\n"));
7028 if (fread (e_data
, ent_size
, number
, file
) != number
)
7030 error (_("Unable to read in dynamic data\n"));
7034 i_data
= cmalloc (number
, sizeof (*i_data
));
7038 error (_("Out of memory\n"));
7044 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7051 /* Dump the symbol table. */
7053 process_symbol_table (FILE *file
)
7055 Elf_Internal_Shdr
*section
;
7056 bfd_vma nbuckets
= 0;
7057 bfd_vma nchains
= 0;
7058 bfd_vma
*buckets
= NULL
;
7059 bfd_vma
*chains
= NULL
;
7060 bfd_vma ngnubuckets
= 0;
7061 bfd_vma
*gnubuckets
= NULL
;
7062 bfd_vma
*gnuchains
= NULL
;
7064 if (! do_syms
&& !do_histogram
)
7067 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
7070 unsigned char nb
[8];
7071 unsigned char nc
[8];
7072 int hash_ent_size
= 4;
7074 if ((elf_header
.e_machine
== EM_ALPHA
7075 || elf_header
.e_machine
== EM_S390
7076 || elf_header
.e_machine
== EM_S390_OLD
)
7077 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7081 (archive_file_offset
7082 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7083 sizeof nb
+ sizeof nc
)),
7086 error (_("Unable to seek to start of dynamic information\n"));
7090 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7092 error (_("Failed to read in number of buckets\n"));
7096 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7098 error (_("Failed to read in number of chains\n"));
7102 nbuckets
= byte_get (nb
, hash_ent_size
);
7103 nchains
= byte_get (nc
, hash_ent_size
);
7105 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7106 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7108 if (buckets
== NULL
|| chains
== NULL
)
7113 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
7118 printf (_("\nSymbol table for image:\n"));
7120 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7122 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7124 for (hn
= 0; hn
< nbuckets
; hn
++)
7129 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7131 Elf_Internal_Sym
*psym
;
7134 psym
= dynamic_symbols
+ si
;
7136 n
= print_vma (si
, DEC_5
);
7138 fputs (" " + n
, stdout
);
7139 printf (" %3lu: ", hn
);
7140 print_vma (psym
->st_value
, LONG_HEX
);
7142 print_vma (psym
->st_size
, DEC_5
);
7144 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7145 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7146 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7147 /* Check to see if any other bits in the st_other field are set.
7148 Note - displaying this information disrupts the layout of the
7149 table being generated, but for the moment this case is very rare. */
7150 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7151 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7152 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7153 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7154 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7156 printf (" <corrupt: %14ld>", psym
->st_name
);
7161 else if (do_syms
&& !do_using_dynamic
)
7165 for (i
= 0, section
= section_headers
;
7166 i
< elf_header
.e_shnum
;
7170 char *strtab
= NULL
;
7171 unsigned long int strtab_size
= 0;
7172 Elf_Internal_Sym
*symtab
;
7173 Elf_Internal_Sym
*psym
;
7176 if ( section
->sh_type
!= SHT_SYMTAB
7177 && section
->sh_type
!= SHT_DYNSYM
)
7180 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7181 SECTION_NAME (section
),
7182 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7184 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7186 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7188 symtab
= GET_ELF_SYMBOLS (file
, section
);
7192 if (section
->sh_link
== elf_header
.e_shstrndx
)
7194 strtab
= string_table
;
7195 strtab_size
= string_table_length
;
7197 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
7199 Elf_Internal_Shdr
*string_sec
;
7201 string_sec
= SECTION_HEADER (section
->sh_link
);
7203 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
7204 1, string_sec
->sh_size
, _("string table"));
7205 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7208 for (si
= 0, psym
= symtab
;
7209 si
< section
->sh_size
/ section
->sh_entsize
;
7212 printf ("%6d: ", si
);
7213 print_vma (psym
->st_value
, LONG_HEX
);
7215 print_vma (psym
->st_size
, DEC_5
);
7216 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7217 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7218 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7219 /* Check to see if any other bits in the st_other field are set.
7220 Note - displaying this information disrupts the layout of the
7221 table being generated, but for the moment this case is very rare. */
7222 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7223 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7224 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7225 print_symbol (25, psym
->st_name
< strtab_size
7226 ? strtab
+ psym
->st_name
: "<corrupt>");
7228 if (section
->sh_type
== SHT_DYNSYM
&&
7229 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7231 unsigned char data
[2];
7232 unsigned short vers_data
;
7233 unsigned long offset
;
7237 offset
= offset_from_vma
7238 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7239 sizeof data
+ si
* sizeof (vers_data
));
7241 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7242 sizeof (data
), 1, _("version data"));
7244 vers_data
= byte_get (data
, 2);
7246 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7247 < elf_header
.e_shnum
7248 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7251 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7253 if ((vers_data
& 0x8000) || vers_data
> 1)
7255 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7256 && (is_nobits
|| ! check_def
))
7258 Elf_External_Verneed evn
;
7259 Elf_Internal_Verneed ivn
;
7260 Elf_Internal_Vernaux ivna
;
7262 /* We must test both. */
7263 offset
= offset_from_vma
7264 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7269 unsigned long vna_off
;
7271 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7274 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7275 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7277 vna_off
= offset
+ ivn
.vn_aux
;
7281 Elf_External_Vernaux evna
;
7283 get_data (&evna
, file
, vna_off
,
7285 _("version need aux (3)"));
7287 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7288 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7289 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7291 vna_off
+= ivna
.vna_next
;
7293 while (ivna
.vna_other
!= vers_data
7294 && ivna
.vna_next
!= 0);
7296 if (ivna
.vna_other
== vers_data
)
7299 offset
+= ivn
.vn_next
;
7301 while (ivn
.vn_next
!= 0);
7303 if (ivna
.vna_other
== vers_data
)
7306 ivna
.vna_name
< strtab_size
7307 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7311 else if (! is_nobits
)
7312 error (_("bad dynamic symbol\n"));
7319 if (vers_data
!= 0x8001
7320 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7322 Elf_Internal_Verdef ivd
;
7323 Elf_Internal_Verdaux ivda
;
7324 Elf_External_Verdaux evda
;
7325 unsigned long offset
;
7327 offset
= offset_from_vma
7329 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7330 sizeof (Elf_External_Verdef
));
7334 Elf_External_Verdef evd
;
7336 get_data (&evd
, file
, offset
, sizeof (evd
),
7337 1, _("version def"));
7339 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7340 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7341 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7343 offset
+= ivd
.vd_next
;
7345 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7346 && ivd
.vd_next
!= 0);
7348 offset
-= ivd
.vd_next
;
7349 offset
+= ivd
.vd_aux
;
7351 get_data (&evda
, file
, offset
, sizeof (evda
),
7352 1, _("version def aux"));
7354 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7356 if (psym
->st_name
!= ivda
.vda_name
)
7357 printf ((vers_data
& 0x8000)
7359 ivda
.vda_name
< strtab_size
7360 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7370 if (strtab
!= string_table
)
7376 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7378 if (do_histogram
&& buckets
!= NULL
)
7380 unsigned long *lengths
;
7381 unsigned long *counts
;
7384 unsigned long maxlength
= 0;
7385 unsigned long nzero_counts
= 0;
7386 unsigned long nsyms
= 0;
7388 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7389 (unsigned long) nbuckets
);
7390 printf (_(" Length Number %% of total Coverage\n"));
7392 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7393 if (lengths
== NULL
)
7395 error (_("Out of memory\n"));
7398 for (hn
= 0; hn
< nbuckets
; ++hn
)
7400 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7403 if (maxlength
< ++lengths
[hn
])
7408 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7411 error (_("Out of memory\n"));
7415 for (hn
= 0; hn
< nbuckets
; ++hn
)
7416 ++counts
[lengths
[hn
]];
7421 printf (" 0 %-10lu (%5.1f%%)\n",
7422 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7423 for (i
= 1; i
<= maxlength
; ++i
)
7425 nzero_counts
+= counts
[i
] * i
;
7426 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7427 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7428 (nzero_counts
* 100.0) / nsyms
);
7436 if (buckets
!= NULL
)
7442 if (do_histogram
&& dynamic_info_DT_GNU_HASH
)
7444 unsigned char nb
[16];
7445 bfd_vma i
, maxchain
= 0xffffffff, symidx
, bitmaskwords
;
7446 unsigned long *lengths
;
7447 unsigned long *counts
;
7449 unsigned long maxlength
= 0;
7450 unsigned long nzero_counts
= 0;
7451 unsigned long nsyms
= 0;
7452 bfd_vma buckets_vma
;
7455 (archive_file_offset
7456 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7460 error (_("Unable to seek to start of dynamic information\n"));
7464 if (fread (nb
, 16, 1, file
) != 1)
7466 error (_("Failed to read in number of buckets\n"));
7470 ngnubuckets
= byte_get (nb
, 4);
7471 symidx
= byte_get (nb
+ 4, 4);
7472 bitmaskwords
= byte_get (nb
+ 8, 4);
7473 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7475 buckets_vma
+= bitmaskwords
* 4;
7477 buckets_vma
+= bitmaskwords
* 8;
7480 (archive_file_offset
7481 + offset_from_vma (file
, buckets_vma
, 4)),
7484 error (_("Unable to seek to start of dynamic information\n"));
7488 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7490 if (gnubuckets
== NULL
)
7493 for (i
= 0; i
< ngnubuckets
; i
++)
7494 if (gnubuckets
[i
] != 0)
7496 if (gnubuckets
[i
] < symidx
)
7499 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7500 maxchain
= gnubuckets
[i
];
7503 if (maxchain
== 0xffffffff)
7509 (archive_file_offset
7510 + offset_from_vma (file
, buckets_vma
7511 + 4 * (ngnubuckets
+ maxchain
), 4)),
7514 error (_("Unable to seek to start of dynamic information\n"));
7520 if (fread (nb
, 4, 1, file
) != 1)
7522 error (_("Failed to determine last chain length\n"));
7526 if (maxchain
+ 1 == 0)
7531 while ((byte_get (nb
, 4) & 1) == 0);
7534 (archive_file_offset
7535 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7538 error (_("Unable to seek to start of dynamic information\n"));
7542 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7544 if (gnuchains
== NULL
)
7547 lengths
= calloc (ngnubuckets
, sizeof (*lengths
));
7548 if (lengths
== NULL
)
7550 error (_("Out of memory\n"));
7554 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7555 (unsigned long) ngnubuckets
);
7556 printf (_(" Length Number %% of total Coverage\n"));
7558 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7559 if (gnubuckets
[hn
] != 0)
7561 bfd_vma off
, length
= 1;
7563 for (off
= gnubuckets
[hn
] - symidx
;
7564 (gnuchains
[off
] & 1) == 0; ++off
)
7566 lengths
[hn
] = length
;
7567 if (length
> maxlength
)
7572 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7575 error (_("Out of memory\n"));
7579 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7580 ++counts
[lengths
[hn
]];
7582 if (ngnubuckets
> 0)
7585 printf (" 0 %-10lu (%5.1f%%)\n",
7586 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7587 for (j
= 1; j
<= maxlength
; ++j
)
7589 nzero_counts
+= counts
[j
] * j
;
7590 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7591 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7592 (nzero_counts
* 100.0) / nsyms
);
7606 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7610 if (dynamic_syminfo
== NULL
7612 /* No syminfo, this is ok. */
7615 /* There better should be a dynamic symbol section. */
7616 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7620 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7621 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7623 printf (_(" Num: Name BoundTo Flags\n"));
7624 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7626 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7628 printf ("%4d: ", i
);
7629 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7630 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7632 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7635 switch (dynamic_syminfo
[i
].si_boundto
)
7637 case SYMINFO_BT_SELF
:
7638 fputs ("SELF ", stdout
);
7640 case SYMINFO_BT_PARENT
:
7641 fputs ("PARENT ", stdout
);
7644 if (dynamic_syminfo
[i
].si_boundto
> 0
7645 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7646 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7648 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7652 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7656 if (flags
& SYMINFO_FLG_DIRECT
)
7658 if (flags
& SYMINFO_FLG_PASSTHRU
)
7659 printf (" PASSTHRU");
7660 if (flags
& SYMINFO_FLG_COPY
)
7662 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7663 printf (" LAZYLOAD");
7671 #ifdef SUPPORT_DISASSEMBLY
7673 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7675 printf (_("\nAssembly dump of section %s\n"),
7676 SECTION_NAME (section
));
7678 /* XXX -- to be done --- XXX */
7685 dump_section_as_strings (Elf_Internal_Shdr
*section
, FILE *file
)
7687 Elf_Internal_Shdr
*relsec
;
7688 bfd_size_type num_bytes
;
7693 char *name
= SECTION_NAME (section
);
7694 bfd_boolean some_strings_shown
;
7696 num_bytes
= section
->sh_size
;
7698 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7700 printf (_("\nSection '%s' has no data to dump.\n"), name
);
7704 addr
= section
->sh_addr
;
7706 start
= get_data (NULL
, file
, section
->sh_offset
, 1, num_bytes
,
7711 printf (_("\nString dump of section '%s':\n"), name
);
7713 /* If the section being dumped has relocations against it the user might
7714 be expecting these relocations to have been applied. Check for this
7715 case and issue a warning message in order to avoid confusion.
7716 FIXME: Maybe we ought to have an option that dumps a section with
7718 for (relsec
= section_headers
;
7719 relsec
< section_headers
+ elf_header
.e_shnum
;
7722 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
7723 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7724 || SECTION_HEADER (relsec
->sh_info
) != section
7725 || relsec
->sh_size
== 0
7726 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7729 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
7734 end
= start
+ num_bytes
;
7735 some_strings_shown
= FALSE
;
7739 while (!ISPRINT (* data
))
7745 printf (" [%6zx] %s\n", data
- start
, data
);
7746 data
+= strlen (data
);
7747 some_strings_shown
= TRUE
;
7751 if (! some_strings_shown
)
7752 printf (_(" No strings found in this section."));
7762 dump_section_as_bytes (Elf_Internal_Shdr
*section
, FILE *file
)
7764 Elf_Internal_Shdr
*relsec
;
7765 bfd_size_type bytes
;
7767 unsigned char *data
;
7768 unsigned char *start
;
7770 bytes
= section
->sh_size
;
7772 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7774 printf (_("\nSection '%s' has no data to dump.\n"),
7775 SECTION_NAME (section
));
7779 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7781 addr
= section
->sh_addr
;
7783 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7788 /* If the section being dumped has relocations against it the user might
7789 be expecting these relocations to have been applied. Check for this
7790 case and issue a warning message in order to avoid confusion.
7791 FIXME: Maybe we ought to have an option that dumps a section with
7793 for (relsec
= section_headers
;
7794 relsec
< section_headers
+ elf_header
.e_shnum
;
7797 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
7798 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7799 || SECTION_HEADER (relsec
->sh_info
) != section
7800 || relsec
->sh_size
== 0
7801 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7804 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
7816 lbytes
= (bytes
> 16 ? 16 : bytes
);
7818 printf (" 0x%8.8lx ", (unsigned long) addr
);
7820 for (j
= 0; j
< 16; j
++)
7823 printf ("%2.2x", data
[j
]);
7831 for (j
= 0; j
< lbytes
; j
++)
7834 if (k
>= ' ' && k
< 0x7f)
7853 /* Return the number of bytes affected by a given reloc.
7854 This information is architecture and reloc dependent.
7855 Returns 4 by default, although this is not always correct.
7856 It should return 0 if a decision cannot be made.
7857 FIXME: This is not the correct way to solve this problem.
7858 The proper way is to have target specific reloc sizing functions
7859 created by the reloc-macros.h header, in the same way that it
7860 already creates the reloc naming functions. */
7863 get_reloc_size (Elf_Internal_Rela
* reloc
)
7865 switch (elf_header
.e_machine
)
7871 switch (ELF32_R_TYPE (reloc
->r_info
))
7873 /* PR gas/3800 - without this information we do not correctly
7874 decode the debug information generated by the h8300 assembler. */
7881 /* FIXME: We need to extend this switch statement to cope with other
7882 architecture's relocs. (When those relocs are used against debug
7883 sections, and when their size is not 4). But see the multiple
7884 inclusions of <elf/h8.h> for an example of the hoops that we need
7885 to jump through in order to obtain the reloc numbers. */
7890 /* Apply addends of RELA relocations. */
7893 debug_apply_rela_addends (void *file
,
7894 Elf_Internal_Shdr
*section
,
7895 unsigned char *start
)
7897 Elf_Internal_Shdr
*relsec
;
7898 unsigned char *end
= start
+ section
->sh_size
;
7900 if (!is_relocatable
)
7903 /* SH uses RELA but uses in place value instead of the addend field. */
7904 if (elf_header
.e_machine
== EM_SH
)
7907 for (relsec
= section_headers
;
7908 relsec
< section_headers
+ elf_header
.e_shnum
;
7911 unsigned long nrelas
;
7912 Elf_Internal_Rela
*rela
, *rp
;
7913 Elf_Internal_Shdr
*symsec
;
7914 Elf_Internal_Sym
*symtab
;
7915 Elf_Internal_Sym
*sym
;
7917 if (relsec
->sh_type
!= SHT_RELA
7918 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7919 || SECTION_HEADER (relsec
->sh_info
) != section
7920 || relsec
->sh_size
== 0
7921 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7924 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7928 symsec
= SECTION_HEADER (relsec
->sh_link
);
7929 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7931 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7934 unsigned int reloc_size
;
7936 reloc_size
= get_reloc_size (rp
);
7937 if (reloc_size
== 0)
7939 warn (_("skipping relocation of unknown size against offset 0x%lx in section %s\n"),
7940 (unsigned long) rp
->r_offset
,
7941 SECTION_NAME (section
));
7945 loc
= start
+ rp
->r_offset
;
7946 if ((loc
+ reloc_size
) > end
)
7948 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7949 (unsigned long) rp
->r_offset
,
7950 SECTION_NAME (section
));
7956 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7958 if (ELF32_R_SYM (rp
->r_info
) != 0
7959 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7960 /* Relocations against symbols without type can happen.
7961 Gcc -feliminate-dwarf2-dups may generate symbols
7962 without type for debug info. */
7963 && ELF32_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7964 /* Relocations against object symbols can happen,
7965 eg when referencing a global array. For an
7966 example of this see the _clz.o binary in libgcc.a. */
7967 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7969 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7970 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7971 SECTION_NAME (section
));
7977 /* In MIPS little-endian objects, r_info isn't really a
7978 64-bit little-endian value: it has a 32-bit little-endian
7979 symbol index followed by four individual byte fields.
7980 Reorder INFO accordingly. */
7981 if (elf_header
.e_machine
== EM_MIPS
7982 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7983 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7984 | ((rp
->r_info
>> 56) & 0xff)
7985 | ((rp
->r_info
>> 40) & 0xff00)
7986 | ((rp
->r_info
>> 24) & 0xff0000)
7987 | ((rp
->r_info
>> 8) & 0xff000000));
7989 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7991 if (ELF64_R_SYM (rp
->r_info
) != 0
7992 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7993 && ELF64_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7994 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7996 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7997 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7998 SECTION_NAME (section
));
8003 byte_put (loc
, rp
->r_addend
, reloc_size
);
8014 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
8016 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
8017 Elf_Internal_Shdr
*sec
;
8020 /* If it is already loaded, do nothing. */
8021 if (section
->start
!= NULL
)
8024 /* Locate the debug section. */
8025 sec
= find_section (section
->name
);
8029 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
8030 section
->address
= sec
->sh_addr
;
8031 section
->size
= sec
->sh_size
;
8032 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
8035 if (debug_displays
[debug
].relocate
)
8036 debug_apply_rela_addends (file
, sec
, section
->start
);
8038 return section
->start
!= NULL
;
8042 free_debug_section (enum dwarf_section_display_enum debug
)
8044 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
8046 if (section
->start
== NULL
)
8049 free ((char *) section
->start
);
8050 section
->start
= NULL
;
8051 section
->address
= 0;
8056 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
8058 char *name
= SECTION_NAME (section
);
8059 bfd_size_type length
;
8061 enum dwarf_section_display_enum i
;
8063 length
= section
->sh_size
;
8066 printf (_("\nSection '%s' has no debugging data.\n"), name
);
8070 if (const_strneq (name
, ".gnu.linkonce.wi."))
8071 name
= ".debug_info";
8073 /* See if we know how to display the contents of this section. */
8074 for (i
= 0; i
< max
; i
++)
8075 if (streq (debug_displays
[i
].section
.name
, name
))
8077 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
8079 if (load_debug_section (i
, file
))
8081 result
&= debug_displays
[i
].display (sec
, file
);
8083 if (i
!= info
&& i
!= abbrev
)
8084 free_debug_section (i
);
8092 printf (_("Unrecognized debug section: %s\n"), name
);
8099 /* Set DUMP_SECTS for all sections where dumps were requested
8100 based on section name. */
8103 initialise_dumps_byname (void)
8105 struct dump_list_entry
*cur
;
8107 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
8112 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
8113 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
8115 request_dump_bynumber (i
, cur
->type
);
8120 warn (_("Section '%s' was not dumped because it does not exist!\n"),
8126 process_section_contents (FILE *file
)
8128 Elf_Internal_Shdr
*section
;
8134 initialise_dumps_byname ();
8136 for (i
= 0, section
= section_headers
;
8137 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8140 #ifdef SUPPORT_DISASSEMBLY
8141 if (dump_sects
[i
] & DISASS_DUMP
)
8142 disassemble_section (section
, file
);
8144 if (dump_sects
[i
] & HEX_DUMP
)
8145 dump_section_as_bytes (section
, file
);
8147 if (dump_sects
[i
] & DEBUG_DUMP
)
8148 display_debug_section (section
, file
);
8150 if (dump_sects
[i
] & STRING_DUMP
)
8151 dump_section_as_strings (section
, file
);
8154 /* Check to see if the user requested a
8155 dump of a section that does not exist. */
8156 while (i
++ < num_dump_sects
)
8158 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
8162 process_mips_fpe_exception (int mask
)
8167 if (mask
& OEX_FPU_INEX
)
8168 fputs ("INEX", stdout
), first
= 0;
8169 if (mask
& OEX_FPU_UFLO
)
8170 printf ("%sUFLO", first
? "" : "|"), first
= 0;
8171 if (mask
& OEX_FPU_OFLO
)
8172 printf ("%sOFLO", first
? "" : "|"), first
= 0;
8173 if (mask
& OEX_FPU_DIV0
)
8174 printf ("%sDIV0", first
? "" : "|"), first
= 0;
8175 if (mask
& OEX_FPU_INVAL
)
8176 printf ("%sINVAL", first
? "" : "|");
8179 fputs ("0", stdout
);
8182 /* ARM EABI attributes section. */
8187 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8190 } arm_attr_public_tag
;
8192 static const char *arm_attr_tag_CPU_arch
[] =
8193 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8195 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8196 static const char *arm_attr_tag_THUMB_ISA_use
[] =
8197 {"No", "Thumb-1", "Thumb-2"};
8198 /* FIXME: VFPv3 encoding was extrapolated! */
8199 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
8200 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
8201 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
8202 static const char *arm_attr_tag_ABI_PCS_config
[] =
8203 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8204 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8205 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
8206 {"V6", "SB", "TLS", "Unused"};
8207 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
8208 {"Absolute", "PC-relative", "SB-relative", "None"};
8209 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
8210 {"Absolute", "PC-relative", "None"};
8211 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
8212 {"None", "direct", "GOT-indirect"};
8213 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
8214 {"None", "??? 1", "2", "??? 3", "4"};
8215 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8216 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
8217 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8218 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8219 static const char *arm_attr_tag_ABI_FP_number_model
[] =
8220 {"Unused", "Finite", "RTABI", "IEEE 754"};
8221 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8222 static const char *arm_attr_tag_ABI_align8_preserved
[] =
8223 {"No", "Yes, except leaf SP", "Yes"};
8224 static const char *arm_attr_tag_ABI_enum_size
[] =
8225 {"Unused", "small", "int", "forced to int"};
8226 static const char *arm_attr_tag_ABI_HardFP_use
[] =
8227 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8228 static const char *arm_attr_tag_ABI_VFP_args
[] =
8229 {"AAPCS", "VFP registers", "custom"};
8230 static const char *arm_attr_tag_ABI_WMMX_args
[] =
8231 {"AAPCS", "WMMX registers", "custom"};
8232 static const char *arm_attr_tag_ABI_optimization_goals
[] =
8233 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8234 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8235 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
8236 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8237 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8239 #define LOOKUP(id, name) \
8240 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8241 static arm_attr_public_tag arm_attr_public_tags
[] =
8243 {4, "CPU_raw_name", 1, NULL
},
8244 {5, "CPU_name", 1, NULL
},
8245 LOOKUP(6, CPU_arch
),
8246 {7, "CPU_arch_profile", 0, NULL
},
8247 LOOKUP(8, ARM_ISA_use
),
8248 LOOKUP(9, THUMB_ISA_use
),
8249 LOOKUP(10, VFP_arch
),
8250 LOOKUP(11, WMMX_arch
),
8251 LOOKUP(12, NEON_arch
),
8252 LOOKUP(13, ABI_PCS_config
),
8253 LOOKUP(14, ABI_PCS_R9_use
),
8254 LOOKUP(15, ABI_PCS_RW_data
),
8255 LOOKUP(16, ABI_PCS_RO_DATA
),
8256 LOOKUP(17, ABI_PCS_GOT_use
),
8257 LOOKUP(18, ABI_PCS_wchar_t
),
8258 LOOKUP(19, ABI_FP_rounding
),
8259 LOOKUP(20, ABI_FP_denormal
),
8260 LOOKUP(21, ABI_FP_exceptions
),
8261 LOOKUP(22, ABI_FP_user_exceptions
),
8262 LOOKUP(23, ABI_FP_number_model
),
8263 LOOKUP(24, ABI_align8_needed
),
8264 LOOKUP(25, ABI_align8_preserved
),
8265 LOOKUP(26, ABI_enum_size
),
8266 LOOKUP(27, ABI_HardFP_use
),
8267 LOOKUP(28, ABI_VFP_args
),
8268 LOOKUP(29, ABI_WMMX_args
),
8269 LOOKUP(30, ABI_optimization_goals
),
8270 LOOKUP(31, ABI_FP_optimization_goals
),
8271 {32, "compatibility", 0, NULL
}
8275 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8278 read_uleb128 (unsigned char *p
, unsigned int *plen
)
8292 val
|= ((unsigned int)c
& 0x7f) << shift
;
8301 static unsigned char *
8302 display_arm_attribute (unsigned char *p
)
8307 arm_attr_public_tag
*attr
;
8311 tag
= read_uleb128 (p
, &len
);
8314 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
8316 if (arm_attr_public_tags
[i
].tag
== tag
)
8318 attr
= &arm_attr_public_tags
[i
];
8325 printf (" Tag_%s: ", attr
->name
);
8331 case 7: /* Tag_CPU_arch_profile. */
8332 val
= read_uleb128 (p
, &len
);
8336 case 0: printf ("None\n"); break;
8337 case 'A': printf ("Application\n"); break;
8338 case 'R': printf ("Realtime\n"); break;
8339 case 'M': printf ("Microcontroller\n"); break;
8340 default: printf ("??? (%d)\n", val
); break;
8344 case 32: /* Tag_compatibility. */
8345 val
= read_uleb128 (p
, &len
);
8347 printf ("flag = %d, vendor = %s\n", val
, p
);
8348 p
+= strlen((char *)p
) + 1;
8362 assert (attr
->type
& 0x80);
8363 val
= read_uleb128 (p
, &len
);
8365 type
= attr
->type
& 0x7f;
8367 printf ("??? (%d)\n", val
);
8369 printf ("%s\n", attr
->table
[val
]);
8376 type
= 1; /* String. */
8378 type
= 2; /* uleb128. */
8379 printf (" Tag_unknown_%d: ", tag
);
8384 printf ("\"%s\"\n", p
);
8385 p
+= strlen((char *)p
) + 1;
8389 val
= read_uleb128 (p
, &len
);
8391 printf ("%d (0x%x)\n", val
, val
);
8397 static unsigned char *
8398 display_gnu_attribute (unsigned char * p
,
8399 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8406 tag
= read_uleb128 (p
, &len
);
8409 /* Tag_compatibility is the only generic GNU attribute defined at
8413 val
= read_uleb128 (p
, &len
);
8415 printf ("flag = %d, vendor = %s\n", val
, p
);
8416 p
+= strlen ((char *) p
) + 1;
8420 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
8421 return display_proc_gnu_attribute (p
, tag
);
8424 type
= 1; /* String. */
8426 type
= 2; /* uleb128. */
8427 printf (" Tag_unknown_%d: ", tag
);
8431 printf ("\"%s\"\n", p
);
8432 p
+= strlen ((char *) p
) + 1;
8436 val
= read_uleb128 (p
, &len
);
8438 printf ("%d (0x%x)\n", val
, val
);
8444 static unsigned char *
8445 display_power_gnu_attribute (unsigned char *p
, int tag
)
8451 if (tag
== Tag_GNU_Power_ABI_FP
)
8453 val
= read_uleb128 (p
, &len
);
8455 printf (" Tag_GNU_Power_ABI_FP: ");
8460 printf ("Hard or soft float\n");
8463 printf ("Hard float\n");
8466 printf ("Soft float\n");
8469 printf ("??? (%d)\n", val
);
8476 type
= 1; /* String. */
8478 type
= 2; /* uleb128. */
8479 printf (" Tag_unknown_%d: ", tag
);
8483 printf ("\"%s\"\n", p
);
8484 p
+= strlen ((char *) p
) + 1;
8488 val
= read_uleb128 (p
, &len
);
8490 printf ("%d (0x%x)\n", val
, val
);
8496 static unsigned char *
8497 display_mips_gnu_attribute (unsigned char *p
, int tag
)
8503 if (tag
== Tag_GNU_MIPS_ABI_FP
)
8505 val
= read_uleb128 (p
, &len
);
8507 printf (" Tag_GNU_MIPS_ABI_FP: ");
8512 printf ("Hard or soft float\n");
8515 printf ("Hard float (-mdouble-float)\n");
8518 printf ("Hard float (-msingle-float)\n");
8521 printf ("Soft float\n");
8524 printf ("??? (%d)\n", val
);
8531 type
= 1; /* String. */
8533 type
= 2; /* uleb128. */
8534 printf (" Tag_unknown_%d: ", tag
);
8538 printf ("\"%s\"\n", p
);
8539 p
+= strlen ((char *) p
) + 1;
8543 val
= read_uleb128 (p
, &len
);
8545 printf ("%d (0x%x)\n", val
, val
);
8552 process_attributes (FILE * file
,
8553 const char * public_name
,
8554 unsigned int proc_type
,
8555 unsigned char * (* display_pub_attribute
) (unsigned char *),
8556 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8558 Elf_Internal_Shdr
*sect
;
8559 unsigned char *contents
;
8562 bfd_vma section_len
;
8566 /* Find the section header so that we get the size. */
8567 for (i
= 0, sect
= section_headers
;
8568 i
< elf_header
.e_shnum
;
8571 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
8574 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
8576 if (contents
== NULL
)
8582 len
= sect
->sh_size
- 1;
8588 bfd_boolean public_section
;
8589 bfd_boolean gnu_section
;
8591 section_len
= byte_get (p
, 4);
8594 if (section_len
> len
)
8596 printf (_("ERROR: Bad section length (%d > %d)\n"),
8597 (int) section_len
, (int) len
);
8602 printf ("Attribute Section: %s\n", p
);
8604 if (public_name
&& streq ((char *) p
, public_name
))
8605 public_section
= TRUE
;
8607 public_section
= FALSE
;
8609 if (streq ((char *) p
, "gnu"))
8612 gnu_section
= FALSE
;
8614 namelen
= strlen ((char *) p
) + 1;
8616 section_len
-= namelen
+ 4;
8618 while (section_len
> 0)
8624 size
= byte_get (p
, 4);
8625 if (size
> section_len
)
8627 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
8628 (int) size
, (int) section_len
);
8632 section_len
-= size
;
8639 printf ("File Attributes\n");
8642 printf ("Section Attributes:");
8645 printf ("Symbol Attributes:");
8651 val
= read_uleb128 (p
, &i
);
8655 printf (" %d", val
);
8660 printf ("Unknown tag: %d\n", tag
);
8661 public_section
= FALSE
;
8668 p
= display_pub_attribute (p
);
8670 else if (gnu_section
)
8673 p
= display_gnu_attribute (p
,
8674 display_proc_gnu_attribute
);
8678 /* ??? Do something sensible, like dump hex. */
8679 printf (" Unknown section contexts\n");
8686 printf (_("Unknown format '%c'\n"), *p
);
8694 process_arm_specific (FILE *file
)
8696 return process_attributes (file
, "aeabi", SHT_ARM_ATTRIBUTES
,
8697 display_arm_attribute
, NULL
);
8701 process_power_specific (FILE *file
)
8703 return process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
8704 display_power_gnu_attribute
);
8708 process_mips_specific (FILE *file
)
8710 Elf_Internal_Dyn
*entry
;
8711 size_t liblist_offset
= 0;
8712 size_t liblistno
= 0;
8713 size_t conflictsno
= 0;
8714 size_t options_offset
= 0;
8715 size_t conflicts_offset
= 0;
8717 process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
8718 display_mips_gnu_attribute
);
8720 /* We have a lot of special sections. Thanks SGI! */
8721 if (dynamic_section
== NULL
)
8722 /* No information available. */
8725 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
8726 switch (entry
->d_tag
)
8728 case DT_MIPS_LIBLIST
:
8730 = offset_from_vma (file
, entry
->d_un
.d_val
,
8731 liblistno
* sizeof (Elf32_External_Lib
));
8733 case DT_MIPS_LIBLISTNO
:
8734 liblistno
= entry
->d_un
.d_val
;
8736 case DT_MIPS_OPTIONS
:
8737 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
8739 case DT_MIPS_CONFLICT
:
8741 = offset_from_vma (file
, entry
->d_un
.d_val
,
8742 conflictsno
* sizeof (Elf32_External_Conflict
));
8744 case DT_MIPS_CONFLICTNO
:
8745 conflictsno
= entry
->d_un
.d_val
;
8751 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
8753 Elf32_External_Lib
*elib
;
8756 elib
= get_data (NULL
, file
, liblist_offset
,
8757 liblistno
, sizeof (Elf32_External_Lib
),
8761 printf ("\nSection '.liblist' contains %lu entries:\n",
8762 (unsigned long) liblistno
);
8763 fputs (" Library Time Stamp Checksum Version Flags\n",
8766 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
8773 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8774 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8775 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8776 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8777 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8779 tmp
= gmtime (&time
);
8780 snprintf (timebuf
, sizeof (timebuf
),
8781 "%04u-%02u-%02uT%02u:%02u:%02u",
8782 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8783 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8785 printf ("%3lu: ", (unsigned long) cnt
);
8786 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
8787 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
8789 printf ("<corrupt: %9ld>", liblist
.l_name
);
8790 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
8793 if (liblist
.l_flags
== 0)
8804 { " EXACT_MATCH", LL_EXACT_MATCH
},
8805 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
8806 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
8807 { " EXPORTS", LL_EXPORTS
},
8808 { " DELAY_LOAD", LL_DELAY_LOAD
},
8809 { " DELTA", LL_DELTA
}
8811 int flags
= liblist
.l_flags
;
8814 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
8815 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
8817 fputs (l_flags_vals
[fcnt
].name
, stdout
);
8818 flags
^= l_flags_vals
[fcnt
].bit
;
8821 printf (" %#x", (unsigned int) flags
);
8831 if (options_offset
!= 0)
8833 Elf_External_Options
*eopt
;
8834 Elf_Internal_Shdr
*sect
= section_headers
;
8835 Elf_Internal_Options
*iopt
;
8836 Elf_Internal_Options
*option
;
8840 /* Find the section header so that we get the size. */
8841 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
8844 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
8848 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
8851 error (_("Out of memory\n"));
8858 while (offset
< sect
->sh_size
)
8860 Elf_External_Options
*eoption
;
8862 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
8864 option
->kind
= BYTE_GET (eoption
->kind
);
8865 option
->size
= BYTE_GET (eoption
->size
);
8866 option
->section
= BYTE_GET (eoption
->section
);
8867 option
->info
= BYTE_GET (eoption
->info
);
8869 offset
+= option
->size
;
8875 printf (_("\nSection '%s' contains %d entries:\n"),
8876 SECTION_NAME (sect
), cnt
);
8884 switch (option
->kind
)
8887 /* This shouldn't happen. */
8888 printf (" NULL %d %lx", option
->section
, option
->info
);
8891 printf (" REGINFO ");
8892 if (elf_header
.e_machine
== EM_MIPS
)
8895 Elf32_External_RegInfo
*ereg
;
8896 Elf32_RegInfo reginfo
;
8898 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
8899 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8900 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8901 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8902 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8903 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8904 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8906 printf ("GPR %08lx GP 0x%lx\n",
8908 (unsigned long) reginfo
.ri_gp_value
);
8909 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8910 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8911 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8916 Elf64_External_RegInfo
*ereg
;
8917 Elf64_Internal_RegInfo reginfo
;
8919 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
8920 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8921 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8922 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8923 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8924 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8925 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8927 printf ("GPR %08lx GP 0x",
8928 reginfo
.ri_gprmask
);
8929 printf_vma (reginfo
.ri_gp_value
);
8932 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8933 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8934 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8938 case ODK_EXCEPTIONS
:
8939 fputs (" EXCEPTIONS fpe_min(", stdout
);
8940 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
8941 fputs (") fpe_max(", stdout
);
8942 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
8943 fputs (")", stdout
);
8945 if (option
->info
& OEX_PAGE0
)
8946 fputs (" PAGE0", stdout
);
8947 if (option
->info
& OEX_SMM
)
8948 fputs (" SMM", stdout
);
8949 if (option
->info
& OEX_FPDBUG
)
8950 fputs (" FPDBUG", stdout
);
8951 if (option
->info
& OEX_DISMISS
)
8952 fputs (" DISMISS", stdout
);
8955 fputs (" PAD ", stdout
);
8956 if (option
->info
& OPAD_PREFIX
)
8957 fputs (" PREFIX", stdout
);
8958 if (option
->info
& OPAD_POSTFIX
)
8959 fputs (" POSTFIX", stdout
);
8960 if (option
->info
& OPAD_SYMBOL
)
8961 fputs (" SYMBOL", stdout
);
8964 fputs (" HWPATCH ", stdout
);
8965 if (option
->info
& OHW_R4KEOP
)
8966 fputs (" R4KEOP", stdout
);
8967 if (option
->info
& OHW_R8KPFETCH
)
8968 fputs (" R8KPFETCH", stdout
);
8969 if (option
->info
& OHW_R5KEOP
)
8970 fputs (" R5KEOP", stdout
);
8971 if (option
->info
& OHW_R5KCVTL
)
8972 fputs (" R5KCVTL", stdout
);
8975 fputs (" FILL ", stdout
);
8976 /* XXX Print content of info word? */
8979 fputs (" TAGS ", stdout
);
8980 /* XXX Print content of info word? */
8983 fputs (" HWAND ", stdout
);
8984 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8985 fputs (" R4KEOP_CHECKED", stdout
);
8986 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8987 fputs (" R4KEOP_CLEAN", stdout
);
8990 fputs (" HWOR ", stdout
);
8991 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8992 fputs (" R4KEOP_CHECKED", stdout
);
8993 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8994 fputs (" R4KEOP_CLEAN", stdout
);
8997 printf (" GP_GROUP %#06lx self-contained %#06lx",
8998 option
->info
& OGP_GROUP
,
8999 (option
->info
& OGP_SELF
) >> 16);
9002 printf (" IDENT %#06lx self-contained %#06lx",
9003 option
->info
& OGP_GROUP
,
9004 (option
->info
& OGP_SELF
) >> 16);
9007 /* This shouldn't happen. */
9008 printf (" %3d ??? %d %lx",
9009 option
->kind
, option
->section
, option
->info
);
9013 len
= sizeof (*eopt
);
9014 while (len
< option
->size
)
9015 if (((char *) option
)[len
] >= ' '
9016 && ((char *) option
)[len
] < 0x7f)
9017 printf ("%c", ((char *) option
)[len
++]);
9019 printf ("\\%03o", ((char *) option
)[len
++]);
9021 fputs ("\n", stdout
);
9029 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9031 Elf32_Conflict
*iconf
;
9034 if (dynamic_symbols
== NULL
)
9036 error (_("conflict list found without a dynamic symbol table\n"));
9040 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
9043 error (_("Out of memory\n"));
9049 Elf32_External_Conflict
*econf32
;
9051 econf32
= get_data (NULL
, file
, conflicts_offset
,
9052 conflictsno
, sizeof (*econf32
), _("conflict"));
9056 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9057 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9063 Elf64_External_Conflict
*econf64
;
9065 econf64
= get_data (NULL
, file
, conflicts_offset
,
9066 conflictsno
, sizeof (*econf64
), _("conflict"));
9070 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9071 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9076 printf (_("\nSection '.conflict' contains %lu entries:\n"),
9077 (unsigned long) conflictsno
);
9078 puts (_(" Num: Index Value Name"));
9080 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9082 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
9084 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9085 print_vma (psym
->st_value
, FULL_HEX
);
9087 if (VALID_DYNAMIC_NAME (psym
->st_name
))
9088 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
9090 printf ("<corrupt: %14ld>", psym
->st_name
);
9101 process_gnu_liblist (FILE *file
)
9103 Elf_Internal_Shdr
*section
, *string_sec
;
9104 Elf32_External_Lib
*elib
;
9113 for (i
= 0, section
= section_headers
;
9114 i
< elf_header
.e_shnum
;
9117 switch (section
->sh_type
)
9119 case SHT_GNU_LIBLIST
:
9120 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
9123 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
9128 string_sec
= SECTION_HEADER (section
->sh_link
);
9130 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
9131 string_sec
->sh_size
, _("liblist string table"));
9132 strtab_size
= string_sec
->sh_size
;
9135 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9141 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9142 SECTION_NAME (section
),
9143 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9145 puts (" Library Time Stamp Checksum Version Flags");
9147 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9155 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9156 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9157 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9158 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9159 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9161 tmp
= gmtime (&time
);
9162 snprintf (timebuf
, sizeof (timebuf
),
9163 "%04u-%02u-%02uT%02u:%02u:%02u",
9164 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9165 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9167 printf ("%3lu: ", (unsigned long) cnt
);
9169 printf ("%-20s", liblist
.l_name
< strtab_size
9170 ? strtab
+ liblist
.l_name
: "<corrupt>");
9172 printf ("%-20.20s", liblist
.l_name
< strtab_size
9173 ? strtab
+ liblist
.l_name
: "<corrupt>");
9174 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9175 liblist
.l_version
, liblist
.l_flags
);
9186 get_note_type (unsigned e_type
)
9188 static char buff
[64];
9190 if (elf_header
.e_type
== ET_CORE
)
9194 return _("NT_AUXV (auxiliary vector)");
9196 return _("NT_PRSTATUS (prstatus structure)");
9198 return _("NT_FPREGSET (floating point registers)");
9200 return _("NT_PRPSINFO (prpsinfo structure)");
9202 return _("NT_TASKSTRUCT (task structure)");
9204 return _("NT_PRXFPREG (user_xfpregs structure)");
9206 return _("NT_PSTATUS (pstatus structure)");
9208 return _("NT_FPREGS (floating point registers)");
9210 return _("NT_PSINFO (psinfo structure)");
9212 return _("NT_LWPSTATUS (lwpstatus_t structure)");
9214 return _("NT_LWPSINFO (lwpsinfo_t structure)");
9215 case NT_WIN32PSTATUS
:
9216 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9224 return _("NT_VERSION (version)");
9226 return _("NT_ARCH (architecture)");
9231 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9236 get_gnu_elf_note_type (unsigned e_type
)
9238 static char buff
[64];
9242 case NT_GNU_ABI_TAG
:
9243 return _("NT_GNU_ABI_TAG (ABI version tag)");
9245 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
9246 case NT_GNU_BUILD_ID
:
9247 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
9252 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9257 get_netbsd_elfcore_note_type (unsigned e_type
)
9259 static char buff
[64];
9261 if (e_type
== NT_NETBSDCORE_PROCINFO
)
9263 /* NetBSD core "procinfo" structure. */
9264 return _("NetBSD procinfo structure");
9267 /* As of Jan 2002 there are no other machine-independent notes
9268 defined for NetBSD core files. If the note type is less
9269 than the start of the machine-dependent note types, we don't
9272 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
9274 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9278 switch (elf_header
.e_machine
)
9280 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9281 and PT_GETFPREGS == mach+2. */
9286 case EM_SPARC32PLUS
:
9290 case NT_NETBSDCORE_FIRSTMACH
+0:
9291 return _("PT_GETREGS (reg structure)");
9292 case NT_NETBSDCORE_FIRSTMACH
+2:
9293 return _("PT_GETFPREGS (fpreg structure)");
9299 /* On all other arch's, PT_GETREGS == mach+1 and
9300 PT_GETFPREGS == mach+3. */
9304 case NT_NETBSDCORE_FIRSTMACH
+1:
9305 return _("PT_GETREGS (reg structure)");
9306 case NT_NETBSDCORE_FIRSTMACH
+3:
9307 return _("PT_GETFPREGS (fpreg structure)");
9313 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
9314 e_type
- NT_NETBSDCORE_FIRSTMACH
);
9318 /* Note that by the ELF standard, the name field is already null byte
9319 terminated, and namesz includes the terminating null byte.
9320 I.E. the value of namesz for the name "FSF" is 4.
9322 If the value of namesz is zero, there is no name present. */
9324 process_note (Elf_Internal_Note
*pnote
)
9326 const char *name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
9329 if (pnote
->namesz
== 0)
9330 /* If there is no note name, then use the default set of
9331 note type strings. */
9332 nt
= get_note_type (pnote
->type
);
9334 else if (const_strneq (pnote
->namedata
, "GNU"))
9335 /* GNU-specific object file notes. */
9336 nt
= get_gnu_elf_note_type (pnote
->type
);
9338 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
9339 /* NetBSD-specific core file notes. */
9340 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
9342 else if (strneq (pnote
->namedata
, "SPU/", 4))
9344 /* SPU-specific core file notes. */
9345 nt
= pnote
->namedata
+ 4;
9350 /* Don't recognize this note name; just use the default set of
9351 note type strings. */
9352 nt
= get_note_type (pnote
->type
);
9354 printf (" %s\t\t0x%08lx\t%s\n", name
, pnote
->descsz
, nt
);
9360 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
9362 Elf_External_Note
*pnotes
;
9363 Elf_External_Note
*external
;
9369 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
9375 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9376 (unsigned long) offset
, (unsigned long) length
);
9377 printf (_(" Owner\t\tData size\tDescription\n"));
9379 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
9381 Elf_External_Note
*next
;
9382 Elf_Internal_Note inote
;
9385 inote
.type
= BYTE_GET (external
->type
);
9386 inote
.namesz
= BYTE_GET (external
->namesz
);
9387 inote
.namedata
= external
->name
;
9388 inote
.descsz
= BYTE_GET (external
->descsz
);
9389 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
9390 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
9392 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
9394 if (((char *) next
) > (((char *) pnotes
) + length
))
9396 warn (_("corrupt note found at offset %lx into core notes\n"),
9397 (long)((char *)external
- (char *)pnotes
));
9398 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
9399 inote
.type
, inote
.namesz
, inote
.descsz
);
9405 /* Verify that name is null terminated. It appears that at least
9406 one version of Linux (RedHat 6.0) generates corefiles that don't
9407 comply with the ELF spec by failing to include the null byte in
9409 if (inote
.namedata
[inote
.namesz
] != '\0')
9411 temp
= malloc (inote
.namesz
+ 1);
9415 error (_("Out of memory\n"));
9420 strncpy (temp
, inote
.namedata
, inote
.namesz
);
9421 temp
[inote
.namesz
] = 0;
9423 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9424 inote
.namedata
= temp
;
9427 res
&= process_note (& inote
);
9442 process_corefile_note_segments (FILE *file
)
9444 Elf_Internal_Phdr
*segment
;
9448 if (! get_program_headers (file
))
9451 for (i
= 0, segment
= program_headers
;
9452 i
< elf_header
.e_phnum
;
9455 if (segment
->p_type
== PT_NOTE
)
9456 res
&= process_corefile_note_segment (file
,
9457 (bfd_vma
) segment
->p_offset
,
9458 (bfd_vma
) segment
->p_filesz
);
9465 process_note_sections (FILE *file
)
9467 Elf_Internal_Shdr
*section
;
9471 for (i
= 0, section
= section_headers
;
9472 i
< elf_header
.e_shnum
;
9474 if (section
->sh_type
== SHT_NOTE
)
9475 res
&= process_corefile_note_segment (file
,
9476 (bfd_vma
) section
->sh_offset
,
9477 (bfd_vma
) section
->sh_size
);
9483 process_notes (FILE *file
)
9485 /* If we have not been asked to display the notes then do nothing. */
9489 if (elf_header
.e_type
!= ET_CORE
)
9490 return process_note_sections (file
);
9492 /* No program headers means no NOTE segment. */
9493 if (elf_header
.e_phnum
> 0)
9494 return process_corefile_note_segments (file
);
9496 printf (_("No note segments present in the core file.\n"));
9501 process_arch_specific (FILE *file
)
9506 switch (elf_header
.e_machine
)
9509 return process_arm_specific (file
);
9511 case EM_MIPS_RS3_LE
:
9512 return process_mips_specific (file
);
9515 return process_power_specific (file
);
9524 get_file_header (FILE *file
)
9526 /* Read in the identity array. */
9527 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
9530 /* Determine how to read the rest of the header. */
9531 switch (elf_header
.e_ident
[EI_DATA
])
9533 default: /* fall through */
9534 case ELFDATANONE
: /* fall through */
9536 byte_get
= byte_get_little_endian
;
9537 byte_put
= byte_put_little_endian
;
9540 byte_get
= byte_get_big_endian
;
9541 byte_put
= byte_put_big_endian
;
9545 /* For now we only support 32 bit and 64 bit ELF files. */
9546 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
9548 /* Read in the rest of the header. */
9551 Elf32_External_Ehdr ehdr32
;
9553 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
9556 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
9557 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
9558 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
9559 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
9560 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
9561 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
9562 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
9563 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
9564 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
9565 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
9566 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
9567 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
9568 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
9572 Elf64_External_Ehdr ehdr64
;
9574 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9575 we will not be able to cope with the 64bit data found in
9576 64 ELF files. Detect this now and abort before we start
9577 overwriting things. */
9578 if (sizeof (bfd_vma
) < 8)
9580 error (_("This instance of readelf has been built without support for a\n\
9581 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9585 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
9588 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
9589 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
9590 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
9591 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
9592 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
9593 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
9594 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
9595 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
9596 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
9597 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
9598 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
9599 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
9600 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
9603 if (elf_header
.e_shoff
)
9605 /* There may be some extensions in the first section header. Don't
9606 bomb if we can't read it. */
9608 get_32bit_section_headers (file
, 1);
9610 get_64bit_section_headers (file
, 1);
9613 is_relocatable
= elf_header
.e_type
== ET_REL
;
9618 /* Process one ELF object file according to the command line options.
9619 This file may actually be stored in an archive. The file is
9620 positioned at the start of the ELF object. */
9623 process_object (char *file_name
, FILE *file
)
9627 if (! get_file_header (file
))
9629 error (_("%s: Failed to read file header\n"), file_name
);
9633 /* Initialise per file variables. */
9634 for (i
= ARRAY_SIZE (version_info
); i
--;)
9635 version_info
[i
] = 0;
9637 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
9638 dynamic_info
[i
] = 0;
9640 /* Process the file. */
9642 printf (_("\nFile: %s\n"), file_name
);
9644 /* Initialise the dump_sects array from the cmdline_dump_sects array.
9645 Note we do this even if cmdline_dump_sects is empty because we
9646 must make sure that the dump_sets array is zeroed out before each
9647 object file is processed. */
9648 if (num_dump_sects
> num_cmdline_dump_sects
)
9649 memset (dump_sects
, 0, num_dump_sects
* sizeof (* dump_sects
));
9651 if (num_cmdline_dump_sects
> 0)
9653 if (num_dump_sects
== 0)
9654 /* A sneaky way of allocating the dump_sects array. */
9655 request_dump_bynumber (num_cmdline_dump_sects
, 0);
9657 assert (num_dump_sects
>= num_cmdline_dump_sects
);
9658 memcpy (dump_sects
, cmdline_dump_sects
,
9659 num_cmdline_dump_sects
* sizeof (* dump_sects
));
9662 if (! process_file_header ())
9665 if (! process_section_headers (file
))
9667 /* Without loaded section headers we cannot process lots of
9669 do_unwind
= do_version
= do_dump
= do_arch
= 0;
9671 if (! do_using_dynamic
)
9672 do_syms
= do_reloc
= 0;
9675 if (! process_section_groups (file
))
9677 /* Without loaded section groups we cannot process unwind. */
9681 if (process_program_headers (file
))
9682 process_dynamic_section (file
);
9684 process_relocs (file
);
9686 process_unwind (file
);
9688 process_symbol_table (file
);
9690 process_syminfo (file
);
9692 process_version_sections (file
);
9694 process_section_contents (file
);
9696 process_notes (file
);
9698 process_gnu_liblist (file
);
9700 process_arch_specific (file
);
9702 if (program_headers
)
9704 free (program_headers
);
9705 program_headers
= NULL
;
9708 if (section_headers
)
9710 free (section_headers
);
9711 section_headers
= NULL
;
9716 free (string_table
);
9717 string_table
= NULL
;
9718 string_table_length
= 0;
9721 if (dynamic_strings
)
9723 free (dynamic_strings
);
9724 dynamic_strings
= NULL
;
9725 dynamic_strings_length
= 0;
9728 if (dynamic_symbols
)
9730 free (dynamic_symbols
);
9731 dynamic_symbols
= NULL
;
9732 num_dynamic_syms
= 0;
9735 if (dynamic_syminfo
)
9737 free (dynamic_syminfo
);
9738 dynamic_syminfo
= NULL
;
9741 if (section_headers_groups
)
9743 free (section_headers_groups
);
9744 section_headers_groups
= NULL
;
9749 struct group_list
*g
, *next
;
9751 for (i
= 0; i
< group_count
; i
++)
9753 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
9760 free (section_groups
);
9761 section_groups
= NULL
;
9764 free_debug_memory ();
9769 /* Process an ELF archive. The file is positioned just after the
9773 process_archive (char *file_name
, FILE *file
)
9775 struct ar_hdr arhdr
;
9778 char *longnames
= NULL
;
9779 unsigned long longnames_size
= 0;
9780 size_t file_name_size
;
9785 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9786 if (got
!= sizeof arhdr
)
9791 error (_("%s: failed to read archive header\n"), file_name
);
9795 if (const_strneq (arhdr
.ar_name
, "/ ")
9796 || const_strneq (arhdr
.ar_name
, "/SYM64/ "))
9798 /* This is the archive symbol table. Skip it.
9799 FIXME: We should have an option to dump it. */
9800 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9801 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
9803 error (_("%s: failed to skip archive symbol table\n"), file_name
);
9807 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9808 if (got
!= sizeof arhdr
)
9813 error (_("%s: failed to read archive header\n"), file_name
);
9818 if (const_strneq (arhdr
.ar_name
, "// "))
9820 /* This is the archive string table holding long member
9823 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9825 longnames
= malloc (longnames_size
);
9826 if (longnames
== NULL
)
9828 error (_("Out of memory\n"));
9832 if (fread (longnames
, longnames_size
, 1, file
) != 1)
9835 error (_("%s: failed to read string table\n"), file_name
);
9839 if ((longnames_size
& 1) != 0)
9842 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9843 if (got
!= sizeof arhdr
)
9850 error (_("%s: failed to read archive header\n"), file_name
);
9855 file_name_size
= strlen (file_name
);
9864 if (arhdr
.ar_name
[0] == '/')
9868 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
9869 if (off
>= longnames_size
)
9871 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
9876 name
= longnames
+ off
;
9877 nameend
= memchr (name
, '/', longnames_size
- off
);
9881 name
= arhdr
.ar_name
;
9882 nameend
= memchr (name
, '/', 16);
9885 if (nameend
== NULL
)
9887 error (_("%s: bad archive file name\n"), file_name
);
9892 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
9893 if (namealc
== NULL
)
9895 error (_("Out of memory\n"));
9900 memcpy (namealc
, file_name
, file_name_size
);
9901 namealc
[file_name_size
] = '(';
9902 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
9903 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
9904 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
9906 archive_file_offset
= ftell (file
);
9907 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9909 ret
|= process_object (namealc
, file
);
9914 (archive_file_offset
9916 + (archive_file_size
& 1)),
9919 error (_("%s: failed to seek to next archive header\n"), file_name
);
9924 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9925 if (got
!= sizeof arhdr
)
9930 error (_("%s: failed to read archive header\n"), file_name
);
9943 process_file (char *file_name
)
9946 struct stat statbuf
;
9950 if (stat (file_name
, &statbuf
) < 0)
9952 if (errno
== ENOENT
)
9953 error (_("'%s': No such file\n"), file_name
);
9955 error (_("Could not locate '%s'. System error message: %s\n"),
9956 file_name
, strerror (errno
));
9960 if (! S_ISREG (statbuf
.st_mode
))
9962 error (_("'%s' is not an ordinary file\n"), file_name
);
9966 file
= fopen (file_name
, "rb");
9969 error (_("Input file '%s' is not readable.\n"), file_name
);
9973 if (fread (armag
, SARMAG
, 1, file
) != 1)
9975 error (_("%s: Failed to read file header\n"), file_name
);
9980 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
9981 ret
= process_archive (file_name
, file
);
9985 archive_file_size
= archive_file_offset
= 0;
9986 ret
= process_object (file_name
, file
);
9994 #ifdef SUPPORT_DISASSEMBLY
9995 /* Needed by the i386 disassembler. For extra credit, someone could
9996 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10000 print_address (unsigned int addr
, FILE *outfile
)
10002 fprintf (outfile
,"0x%8.8x", addr
);
10005 /* Needed by the i386 disassembler. */
10007 db_task_printsym (unsigned int addr
)
10009 print_address (addr
, stderr
);
10014 main (int argc
, char **argv
)
10018 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10019 setlocale (LC_MESSAGES
, "");
10021 #if defined (HAVE_SETLOCALE)
10022 setlocale (LC_CTYPE
, "");
10024 bindtextdomain (PACKAGE
, LOCALEDIR
);
10025 textdomain (PACKAGE
);
10027 expandargv (&argc
, &argv
);
10029 parse_args (argc
, argv
);
10031 if (num_dump_sects
> 0)
10033 /* Make a copy of the dump_sects array. */
10034 cmdline_dump_sects
= malloc (num_dump_sects
* sizeof (* dump_sects
));
10035 if (cmdline_dump_sects
== NULL
)
10036 error (_("Out of memory allocating dump request table.\n"));
10039 memcpy (cmdline_dump_sects
, dump_sects
,
10040 num_dump_sects
* sizeof (* dump_sects
));
10041 num_cmdline_dump_sects
= num_dump_sects
;
10045 if (optind
< (argc
- 1))
10049 while (optind
< argc
)
10050 err
|= process_file (argv
[optind
++]);
10052 if (dump_sects
!= NULL
)
10054 if (cmdline_dump_sects
!= NULL
)
10055 free (cmdline_dump_sects
);