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 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 /* The difference between readelf and objdump:
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
45 #include <sys/types.h>
57 # ifdef HAVE_SYS_PARAM_H
58 # include <sys/param.h>
62 # define PATH_MAX MAXPATHLEN
64 # define PATH_MAX 1024
70 /* Define BFD64 here, even if our default architecture is 32 bit ELF
71 as this will allow us to read in and parse 64bit and 32bit ELF files.
72 Only do this if we believe that the compiler can support a 64 bit
73 data type. For now we only rely on GCC being able to do this. */
79 #include "elf/common.h"
80 #include "elf/external.h"
81 #include "elf/internal.h"
84 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
85 we can obtain the H8 reloc numbers. We need these for the
86 get_reloc_size() function. We include h8.h again after defining
87 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
92 /* Undo the effects of #including reloc-macros.h. */
94 #undef START_RELOC_NUMBERS
98 #undef END_RELOC_NUMBERS
99 #undef _RELOC_MACROS_H
101 /* The following headers use the elf/reloc-macros.h file to
102 automatically generate relocation recognition functions
103 such as elf_mips_reloc_type() */
105 #define RELOC_MACROS_GEN_FUNC
107 #include "elf/alpha.h"
111 #include "elf/bfin.h"
112 #include "elf/cris.h"
114 #include "elf/d10v.h"
115 #include "elf/d30v.h"
117 #include "elf/fr30.h"
120 #include "elf/hppa.h"
121 #include "elf/i386.h"
122 #include "elf/i370.h"
123 #include "elf/i860.h"
124 #include "elf/i960.h"
125 #include "elf/ia64.h"
126 #include "elf/ip2k.h"
127 #include "elf/iq2000.h"
128 #include "elf/m32c.h"
129 #include "elf/m32r.h"
130 #include "elf/m68k.h"
131 #include "elf/m68hc11.h"
132 #include "elf/mcore.h"
134 #include "elf/mips.h"
135 #include "elf/mmix.h"
136 #include "elf/mn10200.h"
137 #include "elf/mn10300.h"
139 #include "elf/msp430.h"
140 #include "elf/or32.h"
143 #include "elf/ppc64.h"
144 #include "elf/s390.h"
145 #include "elf/score.h"
147 #include "elf/sparc.h"
149 #include "elf/v850.h"
151 #include "elf/x86-64.h"
152 #include "elf/xstormy16.h"
153 #include "elf/xtensa.h"
159 #include "libiberty.h"
161 char *program_name
= "readelf";
162 static long archive_file_offset
;
163 static unsigned long archive_file_size
;
164 static unsigned long dynamic_addr
;
165 static bfd_size_type dynamic_size
;
166 static unsigned int dynamic_nent
;
167 static char *dynamic_strings
;
168 static unsigned long dynamic_strings_length
;
169 static char *string_table
;
170 static unsigned long string_table_length
;
171 static unsigned long num_dynamic_syms
;
172 static Elf_Internal_Sym
*dynamic_symbols
;
173 static Elf_Internal_Syminfo
*dynamic_syminfo
;
174 static unsigned long dynamic_syminfo_offset
;
175 static unsigned int dynamic_syminfo_nent
;
176 static char program_interpreter
[PATH_MAX
];
177 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
178 static bfd_vma dynamic_info_DT_GNU_HASH
;
179 static bfd_vma version_info
[16];
180 static Elf_Internal_Ehdr elf_header
;
181 static Elf_Internal_Shdr
*section_headers
;
182 static Elf_Internal_Phdr
*program_headers
;
183 static Elf_Internal_Dyn
*dynamic_section
;
184 static Elf_Internal_Shdr
*symtab_shndx_hdr
;
185 static int show_name
;
186 static int do_dynamic
;
189 static int do_sections
;
190 static int do_section_groups
;
191 static int do_section_details
;
192 static int do_segments
;
193 static int do_unwind
;
194 static int do_using_dynamic
;
195 static int do_header
;
197 static int do_version
;
199 static int do_histogram
;
200 static int do_debugging
;
203 static int is_32bit_elf
;
207 struct group_list
*next
;
208 unsigned int section_index
;
213 struct group_list
*root
;
214 unsigned int group_index
;
217 static size_t group_count
;
218 static struct group
*section_groups
;
219 static struct group
**section_headers_groups
;
221 /* A linked list of the section names for which dumps were requested
223 struct dump_list_entry
227 struct dump_list_entry
*next
;
229 static struct dump_list_entry
*dump_sects_byname
;
231 /* A dynamic array of flags indicating for which sections a hex dump
232 has been requested (via the -x switch) and/or a disassembly dump
233 (via the -i switch). */
234 char *cmdline_dump_sects
= NULL
;
235 unsigned num_cmdline_dump_sects
= 0;
237 /* A dynamic array of flags indicating for which sections a dump of
238 some kind has been requested. It is reset on a per-object file
239 basis and then initialised from the cmdline_dump_sects array,
240 the results of interpreting the -w switch, and the
241 dump_sects_byname list. */
242 char *dump_sects
= NULL
;
243 unsigned int num_dump_sects
= 0;
245 #define HEX_DUMP (1 << 0)
246 #define DISASS_DUMP (1 << 1)
247 #define DEBUG_DUMP (1 << 2)
249 /* How to print a vma value. */
250 typedef enum print_mode
262 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
266 #define SECTION_NAME(X) \
267 ((X) == NULL ? "<none>" \
268 : string_table == NULL ? "<no-name>" \
269 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
270 : string_table + (X)->sh_name))
272 /* Given st_shndx I, map to section_headers index. */
273 #define SECTION_HEADER_INDEX(I) \
274 ((I) < SHN_LORESERVE \
276 : ((I) <= SHN_HIRESERVE \
278 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
280 /* Reverse of the above. */
281 #define SECTION_HEADER_NUM(N) \
282 ((N) < SHN_LORESERVE \
284 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
286 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
288 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
290 #define BYTE_GET(field) byte_get (field, sizeof (field))
292 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
294 #define GET_ELF_SYMBOLS(file, section) \
295 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
296 : get_64bit_elf_symbols (file, section))
298 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
299 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
300 already been called and verified that the string exists. */
301 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
303 /* This is just a bit of syntatic sugar. */
304 #define streq(a,b) (strcmp ((a), (b)) == 0)
305 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
306 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
309 get_data (void *var
, FILE *file
, long offset
, size_t size
, size_t nmemb
,
314 if (size
== 0 || nmemb
== 0)
317 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
319 error (_("Unable to seek to 0x%lx for %s\n"),
320 archive_file_offset
+ offset
, reason
);
327 /* Check for overflow. */
328 if (nmemb
< (~(size_t) 0 - 1) / size
)
329 /* + 1 so that we can '\0' terminate invalid string table sections. */
330 mvar
= malloc (size
* nmemb
+ 1);
334 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
335 (unsigned long)(size
* nmemb
), reason
);
339 ((char *) mvar
)[size
* nmemb
] = '\0';
342 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
344 error (_("Unable to read in 0x%lx bytes of %s\n"),
345 (unsigned long)(size
* nmemb
), reason
);
355 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
360 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
361 field
[6] = ((value
>> 24) >> 24) & 0xff;
362 field
[5] = ((value
>> 24) >> 16) & 0xff;
363 field
[4] = ((value
>> 24) >> 8) & 0xff;
366 field
[3] = (value
>> 24) & 0xff;
367 field
[2] = (value
>> 16) & 0xff;
370 field
[1] = (value
>> 8) & 0xff;
373 field
[0] = value
& 0xff;
377 error (_("Unhandled data length: %d\n"), size
);
382 #if defined BFD64 && !BFD_HOST_64BIT_LONG
384 print_dec_vma (bfd_vma vma
, int is_signed
)
390 if (is_signed
&& (bfd_signed_vma
) vma
< 0)
399 *bufp
++ = '0' + vma
% 10;
411 print_hex_vma (bfd_vma vma
)
419 char digit
= '0' + (vma
& 0x0f);
421 digit
+= 'a' - '0' - 10;
434 /* Print a VMA value. */
436 print_vma (bfd_vma vma
, print_mode mode
)
445 return printf ("0x%8.8lx", (unsigned long) vma
);
448 return printf ("%8.8lx", (unsigned long) vma
);
452 return printf ("%5ld", (long) vma
);
456 return printf ("0x%lx", (unsigned long) vma
);
459 return printf ("%lx", (unsigned long) vma
);
462 return printf ("%ld", (unsigned long) vma
);
465 return printf ("%lu", (unsigned long) vma
);
488 #if BFD_HOST_64BIT_LONG
489 return nc
+ printf ("%lx", vma
);
491 return nc
+ print_hex_vma (vma
);
495 #if BFD_HOST_64BIT_LONG
496 return printf ("%ld", vma
);
498 return print_dec_vma (vma
, 1);
502 #if BFD_HOST_64BIT_LONG
504 return printf ("%5ld", vma
);
506 return printf ("%#lx", vma
);
509 return printf ("%5ld", _bfd_int64_low (vma
));
511 return print_hex_vma (vma
);
515 #if BFD_HOST_64BIT_LONG
516 return printf ("%lu", vma
);
518 return print_dec_vma (vma
, 0);
526 /* Display a symbol on stdout. If do_wide is not true then
527 format the symbol to be at most WIDTH characters,
528 truncating as necessary. If WIDTH is negative then
529 format the string to be exactly - WIDTH characters,
530 truncating or padding as necessary. */
533 print_symbol (int width
, const char *symbol
)
536 printf ("%s", symbol
);
538 printf ("%-*.*s", width
, width
, symbol
);
540 printf ("%-.*s", width
, symbol
);
544 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
549 field
[7] = value
& 0xff;
550 field
[6] = (value
>> 8) & 0xff;
551 field
[5] = (value
>> 16) & 0xff;
552 field
[4] = (value
>> 24) & 0xff;
557 field
[3] = value
& 0xff;
558 field
[2] = (value
>> 8) & 0xff;
562 field
[1] = value
& 0xff;
566 field
[0] = value
& 0xff;
570 error (_("Unhandled data length: %d\n"), size
);
575 /* Return a pointer to section NAME, or NULL if no such section exists. */
577 static Elf_Internal_Shdr
*
578 find_section (const char *name
)
582 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
583 if (streq (SECTION_NAME (section_headers
+ i
), name
))
584 return section_headers
+ i
;
589 /* Guess the relocation size commonly used by the specific machines. */
592 guess_is_rela (unsigned long e_machine
)
596 /* Targets that use REL relocations. */
612 /* Targets that use RELA relocations. */
616 case EM_ALTERA_NIOS2
:
640 case EM_CYGNUS_MN10200
:
642 case EM_CYGNUS_MN10300
:
683 warn (_("Don't know about relocations on this machine architecture\n"));
689 slurp_rela_relocs (FILE *file
,
690 unsigned long rel_offset
,
691 unsigned long rel_size
,
692 Elf_Internal_Rela
**relasp
,
693 unsigned long *nrelasp
)
695 Elf_Internal_Rela
*relas
;
696 unsigned long nrelas
;
701 Elf32_External_Rela
*erelas
;
703 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
707 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
709 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
714 error (_("out of memory parsing relocs\n"));
718 for (i
= 0; i
< nrelas
; i
++)
720 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
721 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
722 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
729 Elf64_External_Rela
*erelas
;
731 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
735 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
737 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
742 error (_("out of memory parsing relocs\n"));
746 for (i
= 0; i
< nrelas
; i
++)
748 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
749 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
750 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
761 slurp_rel_relocs (FILE *file
,
762 unsigned long rel_offset
,
763 unsigned long rel_size
,
764 Elf_Internal_Rela
**relsp
,
765 unsigned long *nrelsp
)
767 Elf_Internal_Rela
*rels
;
773 Elf32_External_Rel
*erels
;
775 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
779 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
781 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
786 error (_("out of memory parsing relocs\n"));
790 for (i
= 0; i
< nrels
; i
++)
792 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
793 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
794 rels
[i
].r_addend
= 0;
801 Elf64_External_Rel
*erels
;
803 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
807 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
809 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
814 error (_("out of memory parsing relocs\n"));
818 for (i
= 0; i
< nrels
; i
++)
820 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
821 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
822 rels
[i
].r_addend
= 0;
832 /* Display the contents of the relocation data found at the specified
836 dump_relocations (FILE *file
,
837 unsigned long rel_offset
,
838 unsigned long rel_size
,
839 Elf_Internal_Sym
*symtab
,
842 unsigned long strtablen
,
846 Elf_Internal_Rela
*rels
;
849 if (is_rela
== UNKNOWN
)
850 is_rela
= guess_is_rela (elf_header
.e_machine
);
854 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
859 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
868 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
870 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
875 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
877 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
885 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
887 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
892 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
894 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
898 for (i
= 0; i
< rel_size
; i
++)
901 const char *rtype2
= NULL
;
902 const char *rtype3
= NULL
;
905 bfd_vma symtab_index
;
910 offset
= rels
[i
].r_offset
;
911 info
= rels
[i
].r_info
;
915 type
= ELF32_R_TYPE (info
);
916 symtab_index
= ELF32_R_SYM (info
);
920 /* The #ifdef BFD64 below is to prevent a compile time warning.
921 We know that if we do not have a 64 bit data type that we
922 will never execute this code anyway. */
924 if (elf_header
.e_machine
== EM_MIPS
)
926 /* In little-endian objects, r_info isn't really a 64-bit
927 little-endian value: it has a 32-bit little-endian
928 symbol index followed by four individual byte fields.
929 Reorder INFO accordingly. */
930 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
931 info
= (((info
& 0xffffffff) << 32)
932 | ((info
>> 56) & 0xff)
933 | ((info
>> 40) & 0xff00)
934 | ((info
>> 24) & 0xff0000)
935 | ((info
>> 8) & 0xff000000));
936 type
= ELF64_MIPS_R_TYPE (info
);
937 type2
= ELF64_MIPS_R_TYPE2 (info
);
938 type3
= ELF64_MIPS_R_TYPE3 (info
);
940 else if (elf_header
.e_machine
== EM_SPARCV9
)
941 type
= ELF64_R_TYPE_ID (info
);
943 type
= ELF64_R_TYPE (info
);
945 symtab_index
= ELF64_R_SYM (info
);
951 #ifdef _bfd_int64_low
952 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
954 printf ("%8.8lx %8.8lx ", offset
, info
);
959 #ifdef _bfd_int64_low
961 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
962 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
963 _bfd_int64_high (offset
),
964 _bfd_int64_low (offset
),
965 _bfd_int64_high (info
),
966 _bfd_int64_low (info
));
969 ? "%16.16lx %16.16lx "
970 : "%12.12lx %12.12lx ",
975 switch (elf_header
.e_machine
)
983 rtype
= elf_m32r_reloc_type (type
);
988 rtype
= elf_i386_reloc_type (type
);
993 rtype
= elf_m68hc11_reloc_type (type
);
997 rtype
= elf_m68k_reloc_type (type
);
1001 rtype
= elf_i960_reloc_type (type
);
1006 rtype
= elf_avr_reloc_type (type
);
1009 case EM_OLD_SPARCV9
:
1010 case EM_SPARC32PLUS
:
1013 rtype
= elf_sparc_reloc_type (type
);
1017 rtype
= elf_spu_reloc_type (type
);
1021 case EM_CYGNUS_V850
:
1022 rtype
= v850_reloc_type (type
);
1026 case EM_CYGNUS_D10V
:
1027 rtype
= elf_d10v_reloc_type (type
);
1031 case EM_CYGNUS_D30V
:
1032 rtype
= elf_d30v_reloc_type (type
);
1036 rtype
= elf_dlx_reloc_type (type
);
1040 rtype
= elf_sh_reloc_type (type
);
1044 case EM_CYGNUS_MN10300
:
1045 rtype
= elf_mn10300_reloc_type (type
);
1049 case EM_CYGNUS_MN10200
:
1050 rtype
= elf_mn10200_reloc_type (type
);
1054 case EM_CYGNUS_FR30
:
1055 rtype
= elf_fr30_reloc_type (type
);
1059 rtype
= elf_frv_reloc_type (type
);
1063 rtype
= elf_mcore_reloc_type (type
);
1067 rtype
= elf_mmix_reloc_type (type
);
1072 rtype
= elf_msp430_reloc_type (type
);
1076 rtype
= elf_ppc_reloc_type (type
);
1080 rtype
= elf_ppc64_reloc_type (type
);
1084 case EM_MIPS_RS3_LE
:
1085 rtype
= elf_mips_reloc_type (type
);
1088 rtype2
= elf_mips_reloc_type (type2
);
1089 rtype3
= elf_mips_reloc_type (type3
);
1094 rtype
= elf_alpha_reloc_type (type
);
1098 rtype
= elf_arm_reloc_type (type
);
1102 rtype
= elf_arc_reloc_type (type
);
1106 rtype
= elf_hppa_reloc_type (type
);
1112 rtype
= elf_h8_reloc_type (type
);
1117 rtype
= elf_or32_reloc_type (type
);
1122 rtype
= elf_pj_reloc_type (type
);
1125 rtype
= elf_ia64_reloc_type (type
);
1129 rtype
= elf_cris_reloc_type (type
);
1133 rtype
= elf_i860_reloc_type (type
);
1137 rtype
= elf_x86_64_reloc_type (type
);
1141 rtype
= i370_reloc_type (type
);
1146 rtype
= elf_s390_reloc_type (type
);
1150 rtype
= elf_score_reloc_type (type
);
1154 rtype
= elf_xstormy16_reloc_type (type
);
1158 rtype
= elf_crx_reloc_type (type
);
1162 rtype
= elf_vax_reloc_type (type
);
1167 rtype
= elf_ip2k_reloc_type (type
);
1171 rtype
= elf_iq2000_reloc_type (type
);
1176 rtype
= elf_xtensa_reloc_type (type
);
1180 rtype
= elf_m32c_reloc_type (type
);
1184 rtype
= elf_mt_reloc_type (type
);
1188 rtype
= elf_bfin_reloc_type (type
);
1192 rtype
= elf_mep_reloc_type (type
);
1197 #ifdef _bfd_int64_low
1198 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1200 printf (_("unrecognized: %-7lx"), type
);
1203 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1205 if (elf_header
.e_machine
== EM_ALPHA
1207 && streq (rtype
, "R_ALPHA_LITUSE")
1210 switch (rels
[i
].r_addend
)
1212 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1213 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1214 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1215 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1216 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1217 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1218 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1219 default: rtype
= NULL
;
1222 printf (" (%s)", rtype
);
1226 printf (_("<unknown addend: %lx>"),
1227 (unsigned long) rels
[i
].r_addend
);
1230 else if (symtab_index
)
1232 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1233 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1236 Elf_Internal_Sym
*psym
;
1238 psym
= symtab
+ symtab_index
;
1241 print_vma (psym
->st_value
, LONG_HEX
);
1242 printf (is_32bit_elf
? " " : " ");
1244 if (psym
->st_name
== 0)
1246 const char *sec_name
= "<null>";
1249 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1251 bfd_vma sec_index
= (bfd_vma
) -1;
1253 if (psym
->st_shndx
< SHN_LORESERVE
)
1254 sec_index
= psym
->st_shndx
;
1255 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1256 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1259 if (sec_index
!= (bfd_vma
) -1)
1260 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1261 else if (psym
->st_shndx
== SHN_ABS
)
1263 else if (psym
->st_shndx
== SHN_COMMON
)
1264 sec_name
= "COMMON";
1265 else if (elf_header
.e_machine
== EM_MIPS
1266 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1267 sec_name
= "SCOMMON";
1268 else if (elf_header
.e_machine
== EM_MIPS
1269 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1270 sec_name
= "SUNDEF";
1271 else if (elf_header
.e_machine
== EM_X86_64
1272 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1273 sec_name
= "LARGE_COMMON";
1274 else if (elf_header
.e_machine
== EM_IA_64
1275 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1276 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1277 sec_name
= "ANSI_COM";
1280 sprintf (name_buf
, "<section 0x%x>",
1281 (unsigned int) psym
->st_shndx
);
1282 sec_name
= name_buf
;
1285 print_symbol (22, sec_name
);
1287 else if (strtab
== NULL
)
1288 printf (_("<string table index: %3ld>"), psym
->st_name
);
1289 else if (psym
->st_name
>= strtablen
)
1290 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1292 print_symbol (22, strtab
+ psym
->st_name
);
1295 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1300 printf ("%*c", is_32bit_elf
?
1301 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1302 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1305 if (elf_header
.e_machine
== EM_SPARCV9
1307 && streq (rtype
, "R_SPARC_OLO10"))
1308 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1312 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1314 printf (" Type2: ");
1317 #ifdef _bfd_int64_low
1318 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1320 printf (_("unrecognized: %-7lx"), type2
);
1323 printf ("%-17.17s", rtype2
);
1325 printf ("\n Type3: ");
1328 #ifdef _bfd_int64_low
1329 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1331 printf (_("unrecognized: %-7lx"), type3
);
1334 printf ("%-17.17s", rtype3
);
1346 get_mips_dynamic_type (unsigned long type
)
1350 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1351 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1352 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1353 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1354 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1355 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1356 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1357 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1358 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1359 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1360 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1361 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1362 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1363 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1364 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1365 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1366 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1367 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1368 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1369 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1370 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1371 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1372 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1373 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1374 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1375 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1376 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1377 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1378 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1379 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1380 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1381 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1382 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1383 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1384 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1385 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1386 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1387 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1388 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1389 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1390 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1391 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1392 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1399 get_sparc64_dynamic_type (unsigned long type
)
1403 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1410 get_ppc_dynamic_type (unsigned long type
)
1414 case DT_PPC_GOT
: return "PPC_GOT";
1421 get_ppc64_dynamic_type (unsigned long type
)
1425 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1426 case DT_PPC64_OPD
: return "PPC64_OPD";
1427 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1434 get_parisc_dynamic_type (unsigned long type
)
1438 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1439 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1440 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1441 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1442 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1443 case DT_HP_PREINIT
: return "HP_PREINIT";
1444 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1445 case DT_HP_NEEDED
: return "HP_NEEDED";
1446 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1447 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1448 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1449 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1450 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1451 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1452 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1453 case DT_HP_FILTERED
: return "HP_FILTERED";
1454 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1455 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1456 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1457 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1458 case DT_PLT
: return "PLT";
1459 case DT_PLT_SIZE
: return "PLT_SIZE";
1460 case DT_DLT
: return "DLT";
1461 case DT_DLT_SIZE
: return "DLT_SIZE";
1468 get_ia64_dynamic_type (unsigned long type
)
1472 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1479 get_alpha_dynamic_type (unsigned long type
)
1483 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1490 get_score_dynamic_type (unsigned long type
)
1494 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1495 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1496 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1497 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1498 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1499 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1507 get_dynamic_type (unsigned long type
)
1509 static char buff
[64];
1513 case DT_NULL
: return "NULL";
1514 case DT_NEEDED
: return "NEEDED";
1515 case DT_PLTRELSZ
: return "PLTRELSZ";
1516 case DT_PLTGOT
: return "PLTGOT";
1517 case DT_HASH
: return "HASH";
1518 case DT_STRTAB
: return "STRTAB";
1519 case DT_SYMTAB
: return "SYMTAB";
1520 case DT_RELA
: return "RELA";
1521 case DT_RELASZ
: return "RELASZ";
1522 case DT_RELAENT
: return "RELAENT";
1523 case DT_STRSZ
: return "STRSZ";
1524 case DT_SYMENT
: return "SYMENT";
1525 case DT_INIT
: return "INIT";
1526 case DT_FINI
: return "FINI";
1527 case DT_SONAME
: return "SONAME";
1528 case DT_RPATH
: return "RPATH";
1529 case DT_SYMBOLIC
: return "SYMBOLIC";
1530 case DT_REL
: return "REL";
1531 case DT_RELSZ
: return "RELSZ";
1532 case DT_RELENT
: return "RELENT";
1533 case DT_PLTREL
: return "PLTREL";
1534 case DT_DEBUG
: return "DEBUG";
1535 case DT_TEXTREL
: return "TEXTREL";
1536 case DT_JMPREL
: return "JMPREL";
1537 case DT_BIND_NOW
: return "BIND_NOW";
1538 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1539 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1540 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1541 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1542 case DT_RUNPATH
: return "RUNPATH";
1543 case DT_FLAGS
: return "FLAGS";
1545 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1546 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1548 case DT_CHECKSUM
: return "CHECKSUM";
1549 case DT_PLTPADSZ
: return "PLTPADSZ";
1550 case DT_MOVEENT
: return "MOVEENT";
1551 case DT_MOVESZ
: return "MOVESZ";
1552 case DT_FEATURE
: return "FEATURE";
1553 case DT_POSFLAG_1
: return "POSFLAG_1";
1554 case DT_SYMINSZ
: return "SYMINSZ";
1555 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1557 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1558 case DT_CONFIG
: return "CONFIG";
1559 case DT_DEPAUDIT
: return "DEPAUDIT";
1560 case DT_AUDIT
: return "AUDIT";
1561 case DT_PLTPAD
: return "PLTPAD";
1562 case DT_MOVETAB
: return "MOVETAB";
1563 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1565 case DT_VERSYM
: return "VERSYM";
1567 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1568 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1569 case DT_RELACOUNT
: return "RELACOUNT";
1570 case DT_RELCOUNT
: return "RELCOUNT";
1571 case DT_FLAGS_1
: return "FLAGS_1";
1572 case DT_VERDEF
: return "VERDEF";
1573 case DT_VERDEFNUM
: return "VERDEFNUM";
1574 case DT_VERNEED
: return "VERNEED";
1575 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1577 case DT_AUXILIARY
: return "AUXILIARY";
1578 case DT_USED
: return "USED";
1579 case DT_FILTER
: return "FILTER";
1581 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1582 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1583 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1584 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1585 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1586 case DT_GNU_HASH
: return "GNU_HASH";
1589 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1593 switch (elf_header
.e_machine
)
1596 case EM_MIPS_RS3_LE
:
1597 result
= get_mips_dynamic_type (type
);
1600 result
= get_sparc64_dynamic_type (type
);
1603 result
= get_ppc_dynamic_type (type
);
1606 result
= get_ppc64_dynamic_type (type
);
1609 result
= get_ia64_dynamic_type (type
);
1612 result
= get_alpha_dynamic_type (type
);
1615 result
= get_score_dynamic_type (type
);
1625 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1627 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1628 || (elf_header
.e_machine
== EM_PARISC
1629 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1633 switch (elf_header
.e_machine
)
1636 result
= get_parisc_dynamic_type (type
);
1646 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1650 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1657 get_file_type (unsigned e_type
)
1659 static char buff
[32];
1663 case ET_NONE
: return _("NONE (None)");
1664 case ET_REL
: return _("REL (Relocatable file)");
1665 case ET_EXEC
: return _("EXEC (Executable file)");
1666 case ET_DYN
: return _("DYN (Shared object file)");
1667 case ET_CORE
: return _("CORE (Core file)");
1670 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1671 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1672 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1673 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1675 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1681 get_machine_name (unsigned e_machine
)
1683 static char buff
[64]; /* XXX */
1687 case EM_NONE
: return _("None");
1688 case EM_M32
: return "WE32100";
1689 case EM_SPARC
: return "Sparc";
1690 case EM_SPU
: return "SPU";
1691 case EM_386
: return "Intel 80386";
1692 case EM_68K
: return "MC68000";
1693 case EM_88K
: return "MC88000";
1694 case EM_486
: return "Intel 80486";
1695 case EM_860
: return "Intel 80860";
1696 case EM_MIPS
: return "MIPS R3000";
1697 case EM_S370
: return "IBM System/370";
1698 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1699 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1700 case EM_PARISC
: return "HPPA";
1701 case EM_PPC_OLD
: return "Power PC (old)";
1702 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1703 case EM_960
: return "Intel 90860";
1704 case EM_PPC
: return "PowerPC";
1705 case EM_PPC64
: return "PowerPC64";
1706 case EM_V800
: return "NEC V800";
1707 case EM_FR20
: return "Fujitsu FR20";
1708 case EM_RH32
: return "TRW RH32";
1709 case EM_MCORE
: return "MCORE";
1710 case EM_ARM
: return "ARM";
1711 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1712 case EM_SH
: return "Renesas / SuperH SH";
1713 case EM_SPARCV9
: return "Sparc v9";
1714 case EM_TRICORE
: return "Siemens Tricore";
1715 case EM_ARC
: return "ARC";
1716 case EM_H8_300
: return "Renesas H8/300";
1717 case EM_H8_300H
: return "Renesas H8/300H";
1718 case EM_H8S
: return "Renesas H8S";
1719 case EM_H8_500
: return "Renesas H8/500";
1720 case EM_IA_64
: return "Intel IA-64";
1721 case EM_MIPS_X
: return "Stanford MIPS-X";
1722 case EM_COLDFIRE
: return "Motorola Coldfire";
1723 case EM_68HC12
: return "Motorola M68HC12";
1724 case EM_ALPHA
: return "Alpha";
1725 case EM_CYGNUS_D10V
:
1726 case EM_D10V
: return "d10v";
1727 case EM_CYGNUS_D30V
:
1728 case EM_D30V
: return "d30v";
1729 case EM_CYGNUS_M32R
:
1730 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1731 case EM_CYGNUS_V850
:
1732 case EM_V850
: return "NEC v850";
1733 case EM_CYGNUS_MN10300
:
1734 case EM_MN10300
: return "mn10300";
1735 case EM_CYGNUS_MN10200
:
1736 case EM_MN10200
: return "mn10200";
1737 case EM_CYGNUS_FR30
:
1738 case EM_FR30
: return "Fujitsu FR30";
1739 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1741 case EM_PJ
: return "picoJava";
1742 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1743 case EM_PCP
: return "Siemens PCP";
1744 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1745 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1746 case EM_STARCORE
: return "Motorola Star*Core processor";
1747 case EM_ME16
: return "Toyota ME16 processor";
1748 case EM_ST100
: return "STMicroelectronics ST100 processor";
1749 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1750 case EM_FX66
: return "Siemens FX66 microcontroller";
1751 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1752 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1753 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1754 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1755 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1756 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1757 case EM_SVX
: return "Silicon Graphics SVx";
1758 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1759 case EM_VAX
: return "Digital VAX";
1761 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1762 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1763 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1764 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1765 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1766 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1767 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1768 case EM_PRISM
: return "Vitesse Prism";
1769 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1771 case EM_S390
: return "IBM S/390";
1772 case EM_SCORE
: return "SUNPLUS S+Core";
1773 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1775 case EM_OR32
: return "OpenRISC";
1776 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1777 case EM_DLX
: return "OpenDLX";
1779 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1780 case EM_IQ2000
: return "Vitesse IQ2000";
1782 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1783 case EM_M32C
: return "Renesas M32c";
1784 case EM_MT
: return "Morpho Techologies MT processor";
1785 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1786 case EM_NIOS32
: return "Altera Nios";
1787 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1788 case EM_XC16X
: return "Infineon Technologies xc16x";
1789 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1791 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
1797 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1802 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1803 e_flags
&= ~ EF_ARM_EABIMASK
;
1805 /* Handle "generic" ARM flags. */
1806 if (e_flags
& EF_ARM_RELEXEC
)
1808 strcat (buf
, ", relocatable executable");
1809 e_flags
&= ~ EF_ARM_RELEXEC
;
1812 if (e_flags
& EF_ARM_HASENTRY
)
1814 strcat (buf
, ", has entry point");
1815 e_flags
&= ~ EF_ARM_HASENTRY
;
1818 /* Now handle EABI specific flags. */
1822 strcat (buf
, ", <unrecognized EABI>");
1827 case EF_ARM_EABI_VER1
:
1828 strcat (buf
, ", Version1 EABI");
1833 /* Process flags one bit at a time. */
1834 flag
= e_flags
& - e_flags
;
1839 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1840 strcat (buf
, ", sorted symbol tables");
1850 case EF_ARM_EABI_VER2
:
1851 strcat (buf
, ", Version2 EABI");
1856 /* Process flags one bit at a time. */
1857 flag
= e_flags
& - e_flags
;
1862 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1863 strcat (buf
, ", sorted symbol tables");
1866 case EF_ARM_DYNSYMSUSESEGIDX
:
1867 strcat (buf
, ", dynamic symbols use segment index");
1870 case EF_ARM_MAPSYMSFIRST
:
1871 strcat (buf
, ", mapping symbols precede others");
1881 case EF_ARM_EABI_VER3
:
1882 strcat (buf
, ", Version3 EABI");
1885 case EF_ARM_EABI_VER4
:
1886 strcat (buf
, ", Version4 EABI");
1889 case EF_ARM_EABI_VER5
:
1890 strcat (buf
, ", Version5 EABI");
1896 /* Process flags one bit at a time. */
1897 flag
= e_flags
& - e_flags
;
1903 strcat (buf
, ", BE8");
1907 strcat (buf
, ", LE8");
1917 case EF_ARM_EABI_UNKNOWN
:
1918 strcat (buf
, ", GNU EABI");
1923 /* Process flags one bit at a time. */
1924 flag
= e_flags
& - e_flags
;
1929 case EF_ARM_INTERWORK
:
1930 strcat (buf
, ", interworking enabled");
1933 case EF_ARM_APCS_26
:
1934 strcat (buf
, ", uses APCS/26");
1937 case EF_ARM_APCS_FLOAT
:
1938 strcat (buf
, ", uses APCS/float");
1942 strcat (buf
, ", position independent");
1946 strcat (buf
, ", 8 bit structure alignment");
1949 case EF_ARM_NEW_ABI
:
1950 strcat (buf
, ", uses new ABI");
1953 case EF_ARM_OLD_ABI
:
1954 strcat (buf
, ", uses old ABI");
1957 case EF_ARM_SOFT_FLOAT
:
1958 strcat (buf
, ", software FP");
1961 case EF_ARM_VFP_FLOAT
:
1962 strcat (buf
, ", VFP");
1965 case EF_ARM_MAVERICK_FLOAT
:
1966 strcat (buf
, ", Maverick FP");
1977 strcat (buf
,", <unknown>");
1981 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1983 static char buf
[1024];
1995 decode_ARM_machine_flags (e_flags
, buf
);
1999 switch (e_flags
& EF_FRV_CPU_MASK
)
2001 case EF_FRV_CPU_GENERIC
:
2005 strcat (buf
, ", fr???");
2008 case EF_FRV_CPU_FR300
:
2009 strcat (buf
, ", fr300");
2012 case EF_FRV_CPU_FR400
:
2013 strcat (buf
, ", fr400");
2015 case EF_FRV_CPU_FR405
:
2016 strcat (buf
, ", fr405");
2019 case EF_FRV_CPU_FR450
:
2020 strcat (buf
, ", fr450");
2023 case EF_FRV_CPU_FR500
:
2024 strcat (buf
, ", fr500");
2026 case EF_FRV_CPU_FR550
:
2027 strcat (buf
, ", fr550");
2030 case EF_FRV_CPU_SIMPLE
:
2031 strcat (buf
, ", simple");
2033 case EF_FRV_CPU_TOMCAT
:
2034 strcat (buf
, ", tomcat");
2040 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2041 strcat (buf
, ", m68000");
2042 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2043 strcat (buf
, ", cpu32");
2044 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2045 strcat (buf
, ", fido_a");
2048 char const *isa
= _("unknown");
2049 char const *mac
= _("unknown mac");
2050 char const *additional
= NULL
;
2052 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2054 case EF_M68K_CF_ISA_A_NODIV
:
2056 additional
= ", nodiv";
2058 case EF_M68K_CF_ISA_A
:
2061 case EF_M68K_CF_ISA_A_PLUS
:
2064 case EF_M68K_CF_ISA_B_NOUSP
:
2066 additional
= ", nousp";
2068 case EF_M68K_CF_ISA_B
:
2072 strcat (buf
, ", cf, isa ");
2075 strcat (buf
, additional
);
2076 if (e_flags
& EF_M68K_CF_FLOAT
)
2077 strcat (buf
, ", float");
2078 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2083 case EF_M68K_CF_MAC
:
2086 case EF_M68K_CF_EMAC
:
2099 if (e_flags
& EF_PPC_EMB
)
2100 strcat (buf
, ", emb");
2102 if (e_flags
& EF_PPC_RELOCATABLE
)
2103 strcat (buf
, ", relocatable");
2105 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2106 strcat (buf
, ", relocatable-lib");
2110 case EM_CYGNUS_V850
:
2111 switch (e_flags
& EF_V850_ARCH
)
2114 strcat (buf
, ", v850e1");
2117 strcat (buf
, ", v850e");
2120 strcat (buf
, ", v850");
2123 strcat (buf
, ", unknown v850 architecture variant");
2129 case EM_CYGNUS_M32R
:
2130 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2131 strcat (buf
, ", m32r");
2135 case EM_MIPS_RS3_LE
:
2136 if (e_flags
& EF_MIPS_NOREORDER
)
2137 strcat (buf
, ", noreorder");
2139 if (e_flags
& EF_MIPS_PIC
)
2140 strcat (buf
, ", pic");
2142 if (e_flags
& EF_MIPS_CPIC
)
2143 strcat (buf
, ", cpic");
2145 if (e_flags
& EF_MIPS_UCODE
)
2146 strcat (buf
, ", ugen_reserved");
2148 if (e_flags
& EF_MIPS_ABI2
)
2149 strcat (buf
, ", abi2");
2151 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2152 strcat (buf
, ", odk first");
2154 if (e_flags
& EF_MIPS_32BITMODE
)
2155 strcat (buf
, ", 32bitmode");
2157 switch ((e_flags
& EF_MIPS_MACH
))
2159 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2160 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2161 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2162 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2163 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2164 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2165 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2166 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2167 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2168 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2170 /* We simply ignore the field in this case to avoid confusion:
2171 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2174 default: strcat (buf
, ", unknown CPU"); break;
2177 switch ((e_flags
& EF_MIPS_ABI
))
2179 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2180 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2181 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2182 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2184 /* We simply ignore the field in this case to avoid confusion:
2185 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2186 This means it is likely to be an o32 file, but not for
2189 default: strcat (buf
, ", unknown ABI"); break;
2192 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2193 strcat (buf
, ", mdmx");
2195 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2196 strcat (buf
, ", mips16");
2198 switch ((e_flags
& EF_MIPS_ARCH
))
2200 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2201 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2202 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2203 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2204 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2205 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2206 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2207 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2208 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2209 default: strcat (buf
, ", unknown ISA"); break;
2215 switch ((e_flags
& EF_SH_MACH_MASK
))
2217 case EF_SH1
: strcat (buf
, ", sh1"); break;
2218 case EF_SH2
: strcat (buf
, ", sh2"); break;
2219 case EF_SH3
: strcat (buf
, ", sh3"); break;
2220 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2221 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2222 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2223 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2224 case EF_SH4
: strcat (buf
, ", sh4"); break;
2225 case EF_SH5
: strcat (buf
, ", sh5"); break;
2226 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2227 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2228 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2229 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2230 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2231 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2232 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2233 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2234 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2235 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2236 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2237 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2238 default: strcat (buf
, ", unknown ISA"); break;
2244 if (e_flags
& EF_SPARC_32PLUS
)
2245 strcat (buf
, ", v8+");
2247 if (e_flags
& EF_SPARC_SUN_US1
)
2248 strcat (buf
, ", ultrasparcI");
2250 if (e_flags
& EF_SPARC_SUN_US3
)
2251 strcat (buf
, ", ultrasparcIII");
2253 if (e_flags
& EF_SPARC_HAL_R1
)
2254 strcat (buf
, ", halr1");
2256 if (e_flags
& EF_SPARC_LEDATA
)
2257 strcat (buf
, ", ledata");
2259 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2260 strcat (buf
, ", tso");
2262 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2263 strcat (buf
, ", pso");
2265 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2266 strcat (buf
, ", rmo");
2270 switch (e_flags
& EF_PARISC_ARCH
)
2272 case EFA_PARISC_1_0
:
2273 strcpy (buf
, ", PA-RISC 1.0");
2275 case EFA_PARISC_1_1
:
2276 strcpy (buf
, ", PA-RISC 1.1");
2278 case EFA_PARISC_2_0
:
2279 strcpy (buf
, ", PA-RISC 2.0");
2284 if (e_flags
& EF_PARISC_TRAPNIL
)
2285 strcat (buf
, ", trapnil");
2286 if (e_flags
& EF_PARISC_EXT
)
2287 strcat (buf
, ", ext");
2288 if (e_flags
& EF_PARISC_LSB
)
2289 strcat (buf
, ", lsb");
2290 if (e_flags
& EF_PARISC_WIDE
)
2291 strcat (buf
, ", wide");
2292 if (e_flags
& EF_PARISC_NO_KABP
)
2293 strcat (buf
, ", no kabp");
2294 if (e_flags
& EF_PARISC_LAZYSWAP
)
2295 strcat (buf
, ", lazyswap");
2300 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2301 strcat (buf
, ", new calling convention");
2303 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2304 strcat (buf
, ", gnu calling convention");
2308 if ((e_flags
& EF_IA_64_ABI64
))
2309 strcat (buf
, ", 64-bit");
2311 strcat (buf
, ", 32-bit");
2312 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2313 strcat (buf
, ", reduced fp model");
2314 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2315 strcat (buf
, ", no function descriptors, constant gp");
2316 else if ((e_flags
& EF_IA_64_CONS_GP
))
2317 strcat (buf
, ", constant gp");
2318 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2319 strcat (buf
, ", absolute");
2323 if ((e_flags
& EF_VAX_NONPIC
))
2324 strcat (buf
, ", non-PIC");
2325 if ((e_flags
& EF_VAX_DFLOAT
))
2326 strcat (buf
, ", D-Float");
2327 if ((e_flags
& EF_VAX_GFLOAT
))
2328 strcat (buf
, ", G-Float");
2337 get_osabi_name (unsigned int osabi
)
2339 static char buff
[32];
2343 case ELFOSABI_NONE
: return "UNIX - System V";
2344 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2345 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2346 case ELFOSABI_LINUX
: return "UNIX - Linux";
2347 case ELFOSABI_HURD
: return "GNU/Hurd";
2348 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2349 case ELFOSABI_AIX
: return "UNIX - AIX";
2350 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2351 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2352 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2353 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2354 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2355 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2356 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2357 case ELFOSABI_AROS
: return "Amiga Research OS";
2358 case ELFOSABI_STANDALONE
: return _("Standalone App");
2359 case ELFOSABI_ARM
: return "ARM";
2361 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2367 get_arm_segment_type (unsigned long type
)
2381 get_mips_segment_type (unsigned long type
)
2385 case PT_MIPS_REGINFO
:
2387 case PT_MIPS_RTPROC
:
2389 case PT_MIPS_OPTIONS
:
2399 get_parisc_segment_type (unsigned long type
)
2403 case PT_HP_TLS
: return "HP_TLS";
2404 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2405 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2406 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2407 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2408 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2409 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2410 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2411 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2412 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2413 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2414 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2415 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2416 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2417 case PT_HP_STACK
: return "HP_STACK";
2418 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2419 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2420 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2421 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2430 get_ia64_segment_type (unsigned long type
)
2434 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2435 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2436 case PT_HP_TLS
: return "HP_TLS";
2437 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2438 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2439 case PT_IA_64_HP_STACK
: return "HP_STACK";
2448 get_segment_type (unsigned long p_type
)
2450 static char buff
[32];
2454 case PT_NULL
: return "NULL";
2455 case PT_LOAD
: return "LOAD";
2456 case PT_DYNAMIC
: return "DYNAMIC";
2457 case PT_INTERP
: return "INTERP";
2458 case PT_NOTE
: return "NOTE";
2459 case PT_SHLIB
: return "SHLIB";
2460 case PT_PHDR
: return "PHDR";
2461 case PT_TLS
: return "TLS";
2463 case PT_GNU_EH_FRAME
:
2464 return "GNU_EH_FRAME";
2465 case PT_GNU_STACK
: return "GNU_STACK";
2466 case PT_GNU_RELRO
: return "GNU_RELRO";
2469 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2473 switch (elf_header
.e_machine
)
2476 result
= get_arm_segment_type (p_type
);
2479 case EM_MIPS_RS3_LE
:
2480 result
= get_mips_segment_type (p_type
);
2483 result
= get_parisc_segment_type (p_type
);
2486 result
= get_ia64_segment_type (p_type
);
2496 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2498 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2502 switch (elf_header
.e_machine
)
2505 result
= get_parisc_segment_type (p_type
);
2508 result
= get_ia64_segment_type (p_type
);
2518 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2521 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2528 get_mips_section_type_name (unsigned int sh_type
)
2532 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2533 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2534 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2535 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2536 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2537 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2538 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2539 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2540 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2541 case SHT_MIPS_RELD
: return "MIPS_RELD";
2542 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2543 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2544 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2545 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2546 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2547 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2548 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2549 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2550 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2551 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2552 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2553 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2554 case SHT_MIPS_LINE
: return "MIPS_LINE";
2555 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2556 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2557 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2558 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2559 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2560 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2561 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2562 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2563 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2564 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2565 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2566 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2567 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2568 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2569 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2570 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2578 get_parisc_section_type_name (unsigned int sh_type
)
2582 case SHT_PARISC_EXT
: return "PARISC_EXT";
2583 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2584 case SHT_PARISC_DOC
: return "PARISC_DOC";
2585 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2586 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2587 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2588 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2596 get_ia64_section_type_name (unsigned int sh_type
)
2598 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2599 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2600 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2604 case SHT_IA_64_EXT
: return "IA_64_EXT";
2605 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2606 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2614 get_x86_64_section_type_name (unsigned int sh_type
)
2618 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2626 get_arm_section_type_name (unsigned int sh_type
)
2632 case SHT_ARM_PREEMPTMAP
:
2633 return "ARM_PREEMPTMAP";
2634 case SHT_ARM_ATTRIBUTES
:
2635 return "ARM_ATTRIBUTES";
2643 get_section_type_name (unsigned int sh_type
)
2645 static char buff
[32];
2649 case SHT_NULL
: return "NULL";
2650 case SHT_PROGBITS
: return "PROGBITS";
2651 case SHT_SYMTAB
: return "SYMTAB";
2652 case SHT_STRTAB
: return "STRTAB";
2653 case SHT_RELA
: return "RELA";
2654 case SHT_HASH
: return "HASH";
2655 case SHT_DYNAMIC
: return "DYNAMIC";
2656 case SHT_NOTE
: return "NOTE";
2657 case SHT_NOBITS
: return "NOBITS";
2658 case SHT_REL
: return "REL";
2659 case SHT_SHLIB
: return "SHLIB";
2660 case SHT_DYNSYM
: return "DYNSYM";
2661 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2662 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2663 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2664 case SHT_GNU_HASH
: return "GNU_HASH";
2665 case SHT_GROUP
: return "GROUP";
2666 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2667 case SHT_GNU_verdef
: return "VERDEF";
2668 case SHT_GNU_verneed
: return "VERNEED";
2669 case SHT_GNU_versym
: return "VERSYM";
2670 case 0x6ffffff0: return "VERSYM";
2671 case 0x6ffffffc: return "VERDEF";
2672 case 0x7ffffffd: return "AUXILIARY";
2673 case 0x7fffffff: return "FILTER";
2674 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2677 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2681 switch (elf_header
.e_machine
)
2684 case EM_MIPS_RS3_LE
:
2685 result
= get_mips_section_type_name (sh_type
);
2688 result
= get_parisc_section_type_name (sh_type
);
2691 result
= get_ia64_section_type_name (sh_type
);
2694 result
= get_x86_64_section_type_name (sh_type
);
2697 result
= get_arm_section_type_name (sh_type
);
2707 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2709 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2710 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2711 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2712 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2714 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2720 #define OPTION_DEBUG_DUMP 512
2722 static struct option options
[] =
2724 {"all", no_argument
, 0, 'a'},
2725 {"file-header", no_argument
, 0, 'h'},
2726 {"program-headers", no_argument
, 0, 'l'},
2727 {"headers", no_argument
, 0, 'e'},
2728 {"histogram", no_argument
, 0, 'I'},
2729 {"segments", no_argument
, 0, 'l'},
2730 {"sections", no_argument
, 0, 'S'},
2731 {"section-headers", no_argument
, 0, 'S'},
2732 {"section-groups", no_argument
, 0, 'g'},
2733 {"section-details", no_argument
, 0, 't'},
2734 {"full-section-name",no_argument
, 0, 'N'},
2735 {"symbols", no_argument
, 0, 's'},
2736 {"syms", no_argument
, 0, 's'},
2737 {"relocs", no_argument
, 0, 'r'},
2738 {"notes", no_argument
, 0, 'n'},
2739 {"dynamic", no_argument
, 0, 'd'},
2740 {"arch-specific", no_argument
, 0, 'A'},
2741 {"version-info", no_argument
, 0, 'V'},
2742 {"use-dynamic", no_argument
, 0, 'D'},
2743 {"hex-dump", required_argument
, 0, 'x'},
2744 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2745 {"unwind", no_argument
, 0, 'u'},
2746 #ifdef SUPPORT_DISASSEMBLY
2747 {"instruction-dump", required_argument
, 0, 'i'},
2750 {"version", no_argument
, 0, 'v'},
2751 {"wide", no_argument
, 0, 'W'},
2752 {"help", no_argument
, 0, 'H'},
2753 {0, no_argument
, 0, 0}
2757 usage (FILE *stream
)
2759 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2760 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
2761 fprintf (stream
, _(" Options are:\n\
2762 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2763 -h --file-header Display the ELF file header\n\
2764 -l --program-headers Display the program headers\n\
2765 --segments An alias for --program-headers\n\
2766 -S --section-headers Display the sections' header\n\
2767 --sections An alias for --section-headers\n\
2768 -g --section-groups Display the section groups\n\
2769 -t --section-details Display the section details\n\
2770 -e --headers Equivalent to: -h -l -S\n\
2771 -s --syms Display the symbol table\n\
2772 --symbols An alias for --syms\n\
2773 -n --notes Display the core notes (if present)\n\
2774 -r --relocs Display the relocations (if present)\n\
2775 -u --unwind Display the unwind info (if present)\n\
2776 -d --dynamic Display the dynamic section (if present)\n\
2777 -V --version-info Display the version sections (if present)\n\
2778 -A --arch-specific Display architecture specific information (if any).\n\
2779 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2780 -x --hex-dump=<number> Dump the contents of section <number>\n\
2781 -w[liaprmfFsoR] or\n\
2782 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2783 Display the contents of DWARF2 debug sections\n"));
2784 #ifdef SUPPORT_DISASSEMBLY
2785 fprintf (stream
, _("\
2786 -i --instruction-dump=<number>\n\
2787 Disassemble the contents of section <number>\n"));
2789 fprintf (stream
, _("\
2790 -I --histogram Display histogram of bucket list lengths\n\
2791 -W --wide Allow output width to exceed 80 characters\n\
2792 @<file> Read options from <file>\n\
2793 -H --help Display this information\n\
2794 -v --version Display the version number of readelf\n"));
2796 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2797 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2799 exit (stream
== stdout
? 0 : 1);
2802 /* Record the fact that the user wants the contents of section number
2803 SECTION to be displayed using the method(s) encoded as flags bits
2804 in TYPE. Note, TYPE can be zero if we are creating the array for
2808 request_dump (unsigned int section
, int type
)
2810 if (section
>= num_dump_sects
)
2812 char *new_dump_sects
;
2814 new_dump_sects
= calloc (section
+ 1, 1);
2816 if (new_dump_sects
== NULL
)
2817 error (_("Out of memory allocating dump request table.\n"));
2820 /* Copy current flag settings. */
2821 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2825 dump_sects
= new_dump_sects
;
2826 num_dump_sects
= section
+ 1;
2831 dump_sects
[section
] |= type
;
2836 /* Request a dump by section name. */
2839 request_dump_byname (const char *section
, int type
)
2841 struct dump_list_entry
*new_request
;
2843 new_request
= malloc (sizeof (struct dump_list_entry
));
2845 error (_("Out of memory allocating dump request table.\n"));
2847 new_request
->name
= strdup (section
);
2848 if (!new_request
->name
)
2849 error (_("Out of memory allocating dump request table.\n"));
2851 new_request
->type
= type
;
2853 new_request
->next
= dump_sects_byname
;
2854 dump_sects_byname
= new_request
;
2858 parse_args (int argc
, char **argv
)
2865 while ((c
= getopt_long
2866 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWH", options
, NULL
)) != EOF
)
2887 do_section_groups
++;
2895 do_section_groups
++;
2900 do_section_details
++;
2942 section
= strtoul (optarg
, & cp
, 0);
2943 if (! *cp
&& section
>= 0)
2944 request_dump (section
, HEX_DUMP
);
2946 request_dump_byname (optarg
, HEX_DUMP
);
2954 unsigned int index
= 0;
2958 while (optarg
[index
])
2959 switch (optarg
[index
++])
2968 do_debug_abbrevs
= 1;
2978 do_debug_pubnames
= 1;
2982 do_debug_aranges
= 1;
2986 do_debug_ranges
= 1;
2990 do_debug_frames_interp
= 1;
2992 do_debug_frames
= 1;
2997 do_debug_macinfo
= 1;
3011 warn (_("Unrecognized debug option '%s'\n"), optarg
);
3016 case OPTION_DEBUG_DUMP
:
3024 const char * option
;
3027 debug_dump_long_opts
;
3029 debug_dump_long_opts opts_table
[] =
3031 /* Please keep this table alpha- sorted. */
3032 { "Ranges", & do_debug_ranges
},
3033 { "abbrev", & do_debug_abbrevs
},
3034 { "aranges", & do_debug_aranges
},
3035 { "frames", & do_debug_frames
},
3036 { "frames-interp", & do_debug_frames_interp
},
3037 { "info", & do_debug_info
},
3038 { "line", & do_debug_lines
},
3039 { "loc", & do_debug_loc
},
3040 { "macro", & do_debug_macinfo
},
3041 { "pubnames", & do_debug_pubnames
},
3042 /* This entry is for compatability
3043 with earlier versions of readelf. */
3044 { "ranges", & do_debug_aranges
},
3045 { "str", & do_debug_str
},
3056 debug_dump_long_opts
* entry
;
3058 for (entry
= opts_table
; entry
->option
; entry
++)
3060 size_t len
= strlen (entry
->option
);
3062 if (strneq (p
, entry
->option
, len
)
3063 && (p
[len
] == ',' || p
[len
] == '\0'))
3065 * entry
->variable
= 1;
3067 /* The --debug-dump=frames-interp option also
3068 enables the --debug-dump=frames option. */
3069 if (do_debug_frames_interp
)
3070 do_debug_frames
= 1;
3077 if (entry
->option
== NULL
)
3079 warn (_("Unrecognized debug option '%s'\n"), p
);
3080 p
= strchr (p
, ',');
3090 #ifdef SUPPORT_DISASSEMBLY
3093 section
= strtoul (optarg
, & cp
, 0);
3094 if (! *cp
&& section
>= 0)
3096 request_dump (section
, DISASS_DUMP
);
3102 print_version (program_name
);
3111 #ifdef SUPPORT_DISASSEMBLY
3114 /* xgettext:c-format */
3115 error (_("Invalid option '-%c'\n"), c
);
3122 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3123 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3124 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3125 && !do_section_groups
)
3129 warn (_("Nothing to do.\n"));
3135 get_elf_class (unsigned int elf_class
)
3137 static char buff
[32];
3141 case ELFCLASSNONE
: return _("none");
3142 case ELFCLASS32
: return "ELF32";
3143 case ELFCLASS64
: return "ELF64";
3145 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3151 get_data_encoding (unsigned int encoding
)
3153 static char buff
[32];
3157 case ELFDATANONE
: return _("none");
3158 case ELFDATA2LSB
: return _("2's complement, little endian");
3159 case ELFDATA2MSB
: return _("2's complement, big endian");
3161 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3166 /* Decode the data held in 'elf_header'. */
3169 process_file_header (void)
3171 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3172 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3173 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3174 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3177 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3185 printf (_("ELF Header:\n"));
3186 printf (_(" Magic: "));
3187 for (i
= 0; i
< EI_NIDENT
; i
++)
3188 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3190 printf (_(" Class: %s\n"),
3191 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3192 printf (_(" Data: %s\n"),
3193 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3194 printf (_(" Version: %d %s\n"),
3195 elf_header
.e_ident
[EI_VERSION
],
3196 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3198 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3201 printf (_(" OS/ABI: %s\n"),
3202 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3203 printf (_(" ABI Version: %d\n"),
3204 elf_header
.e_ident
[EI_ABIVERSION
]);
3205 printf (_(" Type: %s\n"),
3206 get_file_type (elf_header
.e_type
));
3207 printf (_(" Machine: %s\n"),
3208 get_machine_name (elf_header
.e_machine
));
3209 printf (_(" Version: 0x%lx\n"),
3210 (unsigned long) elf_header
.e_version
);
3212 printf (_(" Entry point address: "));
3213 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3214 printf (_("\n Start of program headers: "));
3215 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3216 printf (_(" (bytes into file)\n Start of section headers: "));
3217 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3218 printf (_(" (bytes into file)\n"));
3220 printf (_(" Flags: 0x%lx%s\n"),
3221 (unsigned long) elf_header
.e_flags
,
3222 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3223 printf (_(" Size of this header: %ld (bytes)\n"),
3224 (long) elf_header
.e_ehsize
);
3225 printf (_(" Size of program headers: %ld (bytes)\n"),
3226 (long) elf_header
.e_phentsize
);
3227 printf (_(" Number of program headers: %ld\n"),
3228 (long) elf_header
.e_phnum
);
3229 printf (_(" Size of section headers: %ld (bytes)\n"),
3230 (long) elf_header
.e_shentsize
);
3231 printf (_(" Number of section headers: %ld"),
3232 (long) elf_header
.e_shnum
);
3233 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3234 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3235 putc ('\n', stdout
);
3236 printf (_(" Section header string table index: %ld"),
3237 (long) elf_header
.e_shstrndx
);
3238 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3239 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3240 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3241 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3242 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3243 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3244 printf (" <corrupt: out of range>");
3245 putc ('\n', stdout
);
3248 if (section_headers
!= NULL
)
3250 if (elf_header
.e_shnum
== 0)
3251 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3252 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3253 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3254 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3255 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3256 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3257 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3258 elf_header
.e_shstrndx
= SHN_UNDEF
;
3259 free (section_headers
);
3260 section_headers
= NULL
;
3268 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3270 Elf32_External_Phdr
*phdrs
;
3271 Elf32_External_Phdr
*external
;
3272 Elf_Internal_Phdr
*internal
;
3275 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3276 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3277 _("program headers"));
3281 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3282 i
< elf_header
.e_phnum
;
3283 i
++, internal
++, external
++)
3285 internal
->p_type
= BYTE_GET (external
->p_type
);
3286 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3287 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3288 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3289 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3290 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3291 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3292 internal
->p_align
= BYTE_GET (external
->p_align
);
3301 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3303 Elf64_External_Phdr
*phdrs
;
3304 Elf64_External_Phdr
*external
;
3305 Elf_Internal_Phdr
*internal
;
3308 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3309 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3310 _("program headers"));
3314 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3315 i
< elf_header
.e_phnum
;
3316 i
++, internal
++, external
++)
3318 internal
->p_type
= BYTE_GET (external
->p_type
);
3319 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3320 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3321 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3322 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3323 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3324 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3325 internal
->p_align
= BYTE_GET (external
->p_align
);
3333 /* Returns 1 if the program headers were read into `program_headers'. */
3336 get_program_headers (FILE *file
)
3338 Elf_Internal_Phdr
*phdrs
;
3340 /* Check cache of prior read. */
3341 if (program_headers
!= NULL
)
3344 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3348 error (_("Out of memory\n"));
3353 ? get_32bit_program_headers (file
, phdrs
)
3354 : get_64bit_program_headers (file
, phdrs
))
3356 program_headers
= phdrs
;
3364 /* Returns 1 if the program headers were loaded. */
3367 process_program_headers (FILE *file
)
3369 Elf_Internal_Phdr
*segment
;
3372 if (elf_header
.e_phnum
== 0)
3375 printf (_("\nThere are no program headers in this file.\n"));
3379 if (do_segments
&& !do_header
)
3381 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3382 printf (_("Entry point "));
3383 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3384 printf (_("\nThere are %d program headers, starting at offset "),
3385 elf_header
.e_phnum
);
3386 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3390 if (! get_program_headers (file
))
3395 if (elf_header
.e_phnum
> 1)
3396 printf (_("\nProgram Headers:\n"));
3398 printf (_("\nProgram Headers:\n"));
3402 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3405 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3409 (_(" Type Offset VirtAddr PhysAddr\n"));
3411 (_(" FileSiz MemSiz Flags Align\n"));
3418 for (i
= 0, segment
= program_headers
;
3419 i
< elf_header
.e_phnum
;
3424 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3428 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3429 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3430 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3431 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3432 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3434 (segment
->p_flags
& PF_R
? 'R' : ' '),
3435 (segment
->p_flags
& PF_W
? 'W' : ' '),
3436 (segment
->p_flags
& PF_X
? 'E' : ' '));
3437 printf ("%#lx", (unsigned long) segment
->p_align
);
3441 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3442 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3445 print_vma (segment
->p_offset
, FULL_HEX
);
3449 print_vma (segment
->p_vaddr
, FULL_HEX
);
3451 print_vma (segment
->p_paddr
, FULL_HEX
);
3454 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3455 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3458 print_vma (segment
->p_filesz
, FULL_HEX
);
3462 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3463 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3466 print_vma (segment
->p_offset
, FULL_HEX
);
3470 (segment
->p_flags
& PF_R
? 'R' : ' '),
3471 (segment
->p_flags
& PF_W
? 'W' : ' '),
3472 (segment
->p_flags
& PF_X
? 'E' : ' '));
3474 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3475 printf ("%#lx", (unsigned long) segment
->p_align
);
3478 print_vma (segment
->p_align
, PREFIX_HEX
);
3483 print_vma (segment
->p_offset
, FULL_HEX
);
3485 print_vma (segment
->p_vaddr
, FULL_HEX
);
3487 print_vma (segment
->p_paddr
, FULL_HEX
);
3489 print_vma (segment
->p_filesz
, FULL_HEX
);
3491 print_vma (segment
->p_memsz
, FULL_HEX
);
3493 (segment
->p_flags
& PF_R
? 'R' : ' '),
3494 (segment
->p_flags
& PF_W
? 'W' : ' '),
3495 (segment
->p_flags
& PF_X
? 'E' : ' '));
3496 print_vma (segment
->p_align
, HEX
);
3500 switch (segment
->p_type
)
3504 error (_("more than one dynamic segment\n"));
3506 /* Try to locate the .dynamic section. If there is
3507 a section header table, we can easily locate it. */
3508 if (section_headers
!= NULL
)
3510 Elf_Internal_Shdr
*sec
;
3512 sec
= find_section (".dynamic");
3513 if (sec
== NULL
|| sec
->sh_size
== 0)
3515 error (_("no .dynamic section in the dynamic segment\n"));
3519 dynamic_addr
= sec
->sh_offset
;
3520 dynamic_size
= sec
->sh_size
;
3522 if (dynamic_addr
< segment
->p_offset
3523 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3524 warn (_("the .dynamic section is not contained within the dynamic segment\n"));
3525 else if (dynamic_addr
> segment
->p_offset
)
3526 warn (_("the .dynamic section is not the first section in the dynamic segment.\n"));
3530 /* Otherwise, we can only assume that the .dynamic
3531 section is the first section in the DYNAMIC segment. */
3532 dynamic_addr
= segment
->p_offset
;
3533 dynamic_size
= segment
->p_filesz
;
3538 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3540 error (_("Unable to find program interpreter name\n"));
3544 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3546 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3547 error (_("Internal error: failed to create format string to display program interpreter\n"));
3549 program_interpreter
[0] = 0;
3550 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3551 error (_("Unable to read program interpreter name\n"));
3554 printf (_("\n [Requesting program interpreter: %s]"),
3555 program_interpreter
);
3561 putc ('\n', stdout
);
3564 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3566 printf (_("\n Section to Segment mapping:\n"));
3567 printf (_(" Segment Sections...\n"));
3569 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3572 Elf_Internal_Shdr
*section
;
3574 segment
= program_headers
+ i
;
3575 section
= section_headers
;
3577 printf (" %2.2d ", i
);
3579 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3581 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section
, segment
))
3582 printf ("%s ", SECTION_NAME (section
));
3593 /* Find the file offset corresponding to VMA by using the program headers. */
3596 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3598 Elf_Internal_Phdr
*seg
;
3600 if (! get_program_headers (file
))
3602 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3606 for (seg
= program_headers
;
3607 seg
< program_headers
+ elf_header
.e_phnum
;
3610 if (seg
->p_type
!= PT_LOAD
)
3613 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3614 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3615 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3618 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3625 get_32bit_section_headers (FILE *file
, unsigned int num
)
3627 Elf32_External_Shdr
*shdrs
;
3628 Elf_Internal_Shdr
*internal
;
3631 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3632 elf_header
.e_shentsize
, num
, _("section headers"));
3636 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3638 if (section_headers
== NULL
)
3640 error (_("Out of memory\n"));
3644 for (i
= 0, internal
= section_headers
;
3648 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3649 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3650 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3651 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3652 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3653 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3654 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3655 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3656 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3657 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3666 get_64bit_section_headers (FILE *file
, unsigned int num
)
3668 Elf64_External_Shdr
*shdrs
;
3669 Elf_Internal_Shdr
*internal
;
3672 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3673 elf_header
.e_shentsize
, num
, _("section headers"));
3677 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3679 if (section_headers
== NULL
)
3681 error (_("Out of memory\n"));
3685 for (i
= 0, internal
= section_headers
;
3689 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3690 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3691 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3692 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3693 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3694 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3695 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3696 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3697 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3698 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3706 static Elf_Internal_Sym
*
3707 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3709 unsigned long number
;
3710 Elf32_External_Sym
*esyms
;
3711 Elf_External_Sym_Shndx
*shndx
;
3712 Elf_Internal_Sym
*isyms
;
3713 Elf_Internal_Sym
*psym
;
3716 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3722 if (symtab_shndx_hdr
!= NULL
3723 && (symtab_shndx_hdr
->sh_link
3724 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3726 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3727 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3735 number
= section
->sh_size
/ section
->sh_entsize
;
3736 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3740 error (_("Out of memory\n"));
3747 for (j
= 0, psym
= isyms
;
3751 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3752 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3753 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3754 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3755 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3757 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3758 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3759 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3769 static Elf_Internal_Sym
*
3770 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3772 unsigned long number
;
3773 Elf64_External_Sym
*esyms
;
3774 Elf_External_Sym_Shndx
*shndx
;
3775 Elf_Internal_Sym
*isyms
;
3776 Elf_Internal_Sym
*psym
;
3779 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3785 if (symtab_shndx_hdr
!= NULL
3786 && (symtab_shndx_hdr
->sh_link
3787 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3789 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3790 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3798 number
= section
->sh_size
/ section
->sh_entsize
;
3799 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3803 error (_("Out of memory\n"));
3810 for (j
= 0, psym
= isyms
;
3814 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3815 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3816 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3817 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3818 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3820 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3821 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3822 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3833 get_elf_section_flags (bfd_vma sh_flags
)
3835 static char buff
[1024];
3837 int field_size
= is_32bit_elf
? 8 : 16;
3838 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3839 bfd_vma os_flags
= 0;
3840 bfd_vma proc_flags
= 0;
3841 bfd_vma unknown_flags
= 0;
3855 { "LINK ORDER", 10 },
3856 { "OS NONCONF", 10 },
3861 if (do_section_details
)
3863 sprintf (buff
, "[%*.*lx]: ",
3864 field_size
, field_size
, (unsigned long) sh_flags
);
3865 p
+= field_size
+ 4;
3872 flag
= sh_flags
& - sh_flags
;
3875 if (do_section_details
)
3879 case SHF_WRITE
: index
= 0; break;
3880 case SHF_ALLOC
: index
= 1; break;
3881 case SHF_EXECINSTR
: index
= 2; break;
3882 case SHF_MERGE
: index
= 3; break;
3883 case SHF_STRINGS
: index
= 4; break;
3884 case SHF_INFO_LINK
: index
= 5; break;
3885 case SHF_LINK_ORDER
: index
= 6; break;
3886 case SHF_OS_NONCONFORMING
: index
= 7; break;
3887 case SHF_GROUP
: index
= 8; break;
3888 case SHF_TLS
: index
= 9; break;
3897 if (p
!= buff
+ field_size
+ 4)
3899 if (size
< (10 + 2))
3906 size
-= flags
[index
].len
;
3907 p
= stpcpy (p
, flags
[index
].str
);
3909 else if (flag
& SHF_MASKOS
)
3911 else if (flag
& SHF_MASKPROC
)
3914 unknown_flags
|= flag
;
3920 case SHF_WRITE
: *p
= 'W'; break;
3921 case SHF_ALLOC
: *p
= 'A'; break;
3922 case SHF_EXECINSTR
: *p
= 'X'; break;
3923 case SHF_MERGE
: *p
= 'M'; break;
3924 case SHF_STRINGS
: *p
= 'S'; break;
3925 case SHF_INFO_LINK
: *p
= 'I'; break;
3926 case SHF_LINK_ORDER
: *p
= 'L'; break;
3927 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3928 case SHF_GROUP
: *p
= 'G'; break;
3929 case SHF_TLS
: *p
= 'T'; break;
3932 if (elf_header
.e_machine
== EM_X86_64
3933 && flag
== SHF_X86_64_LARGE
)
3935 else if (flag
& SHF_MASKOS
)
3938 sh_flags
&= ~ SHF_MASKOS
;
3940 else if (flag
& SHF_MASKPROC
)
3943 sh_flags
&= ~ SHF_MASKPROC
;
3953 if (do_section_details
)
3957 size
-= 5 + field_size
;
3958 if (p
!= buff
+ field_size
+ 4)
3966 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3967 (unsigned long) os_flags
);
3968 p
+= 5 + field_size
;
3972 size
-= 7 + field_size
;
3973 if (p
!= buff
+ field_size
+ 4)
3981 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
3982 (unsigned long) proc_flags
);
3983 p
+= 7 + field_size
;
3987 size
-= 10 + field_size
;
3988 if (p
!= buff
+ field_size
+ 4)
3996 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
3997 (unsigned long) unknown_flags
);
3998 p
+= 10 + field_size
;
4007 process_section_headers (FILE *file
)
4009 Elf_Internal_Shdr
*section
;
4012 section_headers
= NULL
;
4014 if (elf_header
.e_shnum
== 0)
4017 printf (_("\nThere are no sections in this file.\n"));
4022 if (do_sections
&& !do_header
)
4023 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4024 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4028 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4031 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4034 /* Read in the string table, so that we have names to display. */
4035 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4036 && SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
4038 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
4040 if (section
->sh_size
!= 0)
4042 string_table
= get_data (NULL
, file
, section
->sh_offset
,
4043 1, section
->sh_size
, _("string table"));
4045 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4049 /* Scan the sections for the dynamic symbol table
4050 and dynamic string table and debug sections. */
4051 dynamic_symbols
= NULL
;
4052 dynamic_strings
= NULL
;
4053 dynamic_syminfo
= NULL
;
4054 symtab_shndx_hdr
= NULL
;
4056 eh_addr_size
= is_32bit_elf
? 4 : 8;
4057 switch (elf_header
.e_machine
)
4060 case EM_MIPS_RS3_LE
:
4061 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4062 FDE addresses. However, the ABI also has a semi-official ILP32
4063 variant for which the normal FDE address size rules apply.
4065 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4066 section, where XX is the size of longs in bits. Unfortunately,
4067 earlier compilers provided no way of distinguishing ILP32 objects
4068 from LP64 objects, so if there's any doubt, we should assume that
4069 the official LP64 form is being used. */
4070 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4071 && find_section (".gcc_compiled_long32") == NULL
)
4077 switch (elf_header
.e_flags
& EF_H8_MACH
)
4079 case E_H8_MACH_H8300
:
4080 case E_H8_MACH_H8300HN
:
4081 case E_H8_MACH_H8300SN
:
4082 case E_H8_MACH_H8300SXN
:
4085 case E_H8_MACH_H8300H
:
4086 case E_H8_MACH_H8300S
:
4087 case E_H8_MACH_H8300SX
:
4093 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4096 size_t expected_entsize \
4097 = is_32bit_elf ? size32 : size64; \
4098 if (section->sh_entsize != expected_entsize) \
4099 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4100 i, (unsigned long int) section->sh_entsize, \
4101 (unsigned long int) expected_entsize); \
4102 section->sh_entsize = expected_entsize; \
4105 #define CHECK_ENTSIZE(section, i, type) \
4106 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4107 sizeof (Elf64_External_##type))
4109 for (i
= 0, section
= section_headers
;
4110 i
< elf_header
.e_shnum
;
4113 char *name
= SECTION_NAME (section
);
4115 if (section
->sh_type
== SHT_DYNSYM
)
4117 if (dynamic_symbols
!= NULL
)
4119 error (_("File contains multiple dynamic symbol tables\n"));
4123 CHECK_ENTSIZE (section
, i
, Sym
);
4124 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4125 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4127 else if (section
->sh_type
== SHT_STRTAB
4128 && streq (name
, ".dynstr"))
4130 if (dynamic_strings
!= NULL
)
4132 error (_("File contains multiple dynamic string tables\n"));
4136 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
4137 1, section
->sh_size
, _("dynamic strings"));
4138 dynamic_strings_length
= section
->sh_size
;
4140 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4142 if (symtab_shndx_hdr
!= NULL
)
4144 error (_("File contains multiple symtab shndx tables\n"));
4147 symtab_shndx_hdr
= section
;
4149 else if (section
->sh_type
== SHT_SYMTAB
)
4150 CHECK_ENTSIZE (section
, i
, Sym
);
4151 else if (section
->sh_type
== SHT_GROUP
)
4152 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4153 else if (section
->sh_type
== SHT_REL
)
4154 CHECK_ENTSIZE (section
, i
, Rel
);
4155 else if (section
->sh_type
== SHT_RELA
)
4156 CHECK_ENTSIZE (section
, i
, Rela
);
4157 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4158 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
4159 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
4160 || do_debug_loc
|| do_debug_ranges
)
4161 && const_strneq (name
, ".debug_"))
4166 || (do_debug_info
&& streq (name
, "info"))
4167 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4168 || (do_debug_lines
&& streq (name
, "line"))
4169 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4170 || (do_debug_aranges
&& streq (name
, "aranges"))
4171 || (do_debug_ranges
&& streq (name
, "ranges"))
4172 || (do_debug_frames
&& streq (name
, "frame"))
4173 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4174 || (do_debug_str
&& streq (name
, "str"))
4175 || (do_debug_loc
&& streq (name
, "loc"))
4177 request_dump (i
, DEBUG_DUMP
);
4179 /* linkonce section to be combined with .debug_info at link time. */
4180 else if ((do_debugging
|| do_debug_info
)
4181 && const_strneq (name
, ".gnu.linkonce.wi."))
4182 request_dump (i
, DEBUG_DUMP
);
4183 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4184 request_dump (i
, DEBUG_DUMP
);
4190 if (elf_header
.e_shnum
> 1)
4191 printf (_("\nSection Headers:\n"));
4193 printf (_("\nSection Header:\n"));
4197 if (do_section_details
)
4199 printf (_(" [Nr] Name\n"));
4200 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4204 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4208 if (do_section_details
)
4210 printf (_(" [Nr] Name\n"));
4211 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4215 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4219 if (do_section_details
)
4221 printf (_(" [Nr] Name\n"));
4222 printf (_(" Type Address Offset Link\n"));
4223 printf (_(" Size EntSize Info Align\n"));
4227 printf (_(" [Nr] Name Type Address Offset\n"));
4228 printf (_(" Size EntSize Flags Link Info Align\n"));
4232 if (do_section_details
)
4233 printf (_(" Flags\n"));
4235 for (i
= 0, section
= section_headers
;
4236 i
< elf_header
.e_shnum
;
4239 if (do_section_details
)
4241 printf (" [%2u] %s\n",
4242 SECTION_HEADER_NUM (i
),
4243 SECTION_NAME (section
));
4244 if (is_32bit_elf
|| do_wide
)
4245 printf (" %-15.15s ",
4246 get_section_type_name (section
->sh_type
));
4249 printf (" [%2u] %-17.17s %-15.15s ",
4250 SECTION_HEADER_NUM (i
),
4251 SECTION_NAME (section
),
4252 get_section_type_name (section
->sh_type
));
4256 print_vma (section
->sh_addr
, LONG_HEX
);
4258 printf ( " %6.6lx %6.6lx %2.2lx",
4259 (unsigned long) section
->sh_offset
,
4260 (unsigned long) section
->sh_size
,
4261 (unsigned long) section
->sh_entsize
);
4263 if (do_section_details
)
4264 fputs (" ", stdout
);
4266 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4268 printf ("%2ld %3lu %2ld\n",
4269 (unsigned long) section
->sh_link
,
4270 (unsigned long) section
->sh_info
,
4271 (unsigned long) section
->sh_addralign
);
4275 print_vma (section
->sh_addr
, LONG_HEX
);
4277 if ((long) section
->sh_offset
== section
->sh_offset
)
4278 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4282 print_vma (section
->sh_offset
, LONG_HEX
);
4285 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4286 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4290 print_vma (section
->sh_size
, LONG_HEX
);
4293 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4294 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4298 print_vma (section
->sh_entsize
, LONG_HEX
);
4301 if (do_section_details
)
4302 fputs (" ", stdout
);
4304 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4306 printf ("%2ld %3lu ",
4307 (unsigned long) section
->sh_link
,
4308 (unsigned long) section
->sh_info
);
4310 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4311 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4314 print_vma (section
->sh_addralign
, DEC
);
4318 else if (do_section_details
)
4320 printf (" %-15.15s ",
4321 get_section_type_name (section
->sh_type
));
4322 print_vma (section
->sh_addr
, LONG_HEX
);
4323 if ((long) section
->sh_offset
== section
->sh_offset
)
4324 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4328 print_vma (section
->sh_offset
, LONG_HEX
);
4330 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4331 print_vma (section
->sh_size
, LONG_HEX
);
4333 print_vma (section
->sh_entsize
, LONG_HEX
);
4335 printf (" %-16lu %ld\n",
4336 (unsigned long) section
->sh_info
,
4337 (unsigned long) section
->sh_addralign
);
4342 print_vma (section
->sh_addr
, LONG_HEX
);
4343 if ((long) section
->sh_offset
== section
->sh_offset
)
4344 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4348 print_vma (section
->sh_offset
, LONG_HEX
);
4351 print_vma (section
->sh_size
, LONG_HEX
);
4353 print_vma (section
->sh_entsize
, LONG_HEX
);
4355 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4357 printf (" %2ld %3lu %ld\n",
4358 (unsigned long) section
->sh_link
,
4359 (unsigned long) section
->sh_info
,
4360 (unsigned long) section
->sh_addralign
);
4363 if (do_section_details
)
4364 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4367 if (!do_section_details
)
4368 printf (_("Key to Flags:\n\
4369 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4370 I (info), L (link order), G (group), x (unknown)\n\
4371 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4377 get_group_flags (unsigned int flags
)
4379 static char buff
[32];
4386 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4393 process_section_groups (FILE *file
)
4395 Elf_Internal_Shdr
*section
;
4397 struct group
*group
;
4398 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4399 Elf_Internal_Sym
*symtab
;
4403 /* Don't process section groups unless needed. */
4404 if (!do_unwind
&& !do_section_groups
)
4407 if (elf_header
.e_shnum
== 0)
4409 if (do_section_groups
)
4410 printf (_("\nThere are no sections in this file.\n"));
4415 if (section_headers
== NULL
)
4417 error (_("Section headers are not available!\n"));
4421 section_headers_groups
= calloc (elf_header
.e_shnum
,
4422 sizeof (struct group
*));
4424 if (section_headers_groups
== NULL
)
4426 error (_("Out of memory\n"));
4430 /* Scan the sections for the group section. */
4432 for (i
= 0, section
= section_headers
;
4433 i
< elf_header
.e_shnum
;
4435 if (section
->sh_type
== SHT_GROUP
)
4438 if (group_count
== 0)
4440 if (do_section_groups
)
4441 printf (_("\nThere are no section groups in this file.\n"));
4446 section_groups
= calloc (group_count
, sizeof (struct group
));
4448 if (section_groups
== NULL
)
4450 error (_("Out of memory\n"));
4459 for (i
= 0, section
= section_headers
, group
= section_groups
;
4460 i
< elf_header
.e_shnum
;
4463 if (section
->sh_type
== SHT_GROUP
)
4465 char *name
= SECTION_NAME (section
);
4467 unsigned char *start
, *indices
;
4468 unsigned int entry
, j
, size
;
4469 Elf_Internal_Shdr
*sec
;
4470 Elf_Internal_Sym
*sym
;
4472 /* Get the symbol table. */
4473 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4474 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4477 error (_("Bad sh_link in group section `%s'\n"), name
);
4481 if (symtab_sec
!= sec
)
4486 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4489 sym
= symtab
+ section
->sh_info
;
4491 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4493 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4496 error (_("Bad sh_info in group section `%s'\n"), name
);
4500 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4509 /* Get the string table. */
4510 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4511 >= elf_header
.e_shnum
)
4520 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4525 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4526 1, strtab_sec
->sh_size
,
4528 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4530 group_name
= sym
->st_name
< strtab_size
4531 ? strtab
+ sym
->st_name
: "<corrupt>";
4534 start
= get_data (NULL
, file
, section
->sh_offset
,
4535 1, section
->sh_size
, _("section data"));
4538 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4539 entry
= byte_get (indices
, 4);
4542 if (do_section_groups
)
4544 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4545 get_group_flags (entry
), i
, name
, group_name
, size
);
4547 printf (_(" [Index] Name\n"));
4550 group
->group_index
= i
;
4552 for (j
= 0; j
< size
; j
++)
4554 struct group_list
*g
;
4556 entry
= byte_get (indices
, 4);
4559 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4561 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4562 entry
, i
, elf_header
.e_shnum
- 1);
4565 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4567 error (_("invalid section [%5u] in group section [%5u]\n"),
4572 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4577 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4579 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4584 /* Intel C/C++ compiler may put section 0 in a
4585 section group. We just warn it the first time
4586 and ignore it afterwards. */
4587 static int warned
= 0;
4590 error (_("section 0 in group section [%5u]\n"),
4591 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4597 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4600 if (do_section_groups
)
4602 sec
= SECTION_HEADER (entry
);
4603 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4606 g
= xmalloc (sizeof (struct group_list
));
4607 g
->section_index
= entry
;
4608 g
->next
= group
->root
;
4632 } dynamic_relocations
[] =
4634 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4635 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4636 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4639 /* Process the reloc section. */
4642 process_relocs (FILE *file
)
4644 unsigned long rel_size
;
4645 unsigned long rel_offset
;
4651 if (do_using_dynamic
)
4655 int has_dynamic_reloc
;
4658 has_dynamic_reloc
= 0;
4660 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4662 is_rela
= dynamic_relocations
[i
].rela
;
4663 name
= dynamic_relocations
[i
].name
;
4664 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4665 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4667 has_dynamic_reloc
|= rel_size
;
4669 if (is_rela
== UNKNOWN
)
4671 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4672 switch (dynamic_info
[DT_PLTREL
])
4686 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4687 name
, rel_offset
, rel_size
);
4689 dump_relocations (file
,
4690 offset_from_vma (file
, rel_offset
, rel_size
),
4692 dynamic_symbols
, num_dynamic_syms
,
4693 dynamic_strings
, dynamic_strings_length
, is_rela
);
4697 if (! has_dynamic_reloc
)
4698 printf (_("\nThere are no dynamic relocations in this file.\n"));
4702 Elf_Internal_Shdr
*section
;
4706 for (i
= 0, section
= section_headers
;
4707 i
< elf_header
.e_shnum
;
4710 if ( section
->sh_type
!= SHT_RELA
4711 && section
->sh_type
!= SHT_REL
)
4714 rel_offset
= section
->sh_offset
;
4715 rel_size
= section
->sh_size
;
4719 Elf_Internal_Shdr
*strsec
;
4722 printf (_("\nRelocation section "));
4724 if (string_table
== NULL
)
4725 printf ("%d", section
->sh_name
);
4727 printf (_("'%s'"), SECTION_NAME (section
));
4729 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4730 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4732 is_rela
= section
->sh_type
== SHT_RELA
;
4734 if (section
->sh_link
4735 && SECTION_HEADER_INDEX (section
->sh_link
)
4736 < elf_header
.e_shnum
)
4738 Elf_Internal_Shdr
*symsec
;
4739 Elf_Internal_Sym
*symtab
;
4740 unsigned long nsyms
;
4741 unsigned long strtablen
= 0;
4742 char *strtab
= NULL
;
4744 symsec
= SECTION_HEADER (section
->sh_link
);
4745 if (symsec
->sh_type
!= SHT_SYMTAB
4746 && symsec
->sh_type
!= SHT_DYNSYM
)
4749 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4750 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4755 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4756 < elf_header
.e_shnum
)
4758 strsec
= SECTION_HEADER (symsec
->sh_link
);
4760 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4763 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4766 dump_relocations (file
, rel_offset
, rel_size
,
4767 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4773 dump_relocations (file
, rel_offset
, rel_size
,
4774 NULL
, 0, NULL
, 0, is_rela
);
4781 printf (_("\nThere are no relocations in this file.\n"));
4787 /* Process the unwind section. */
4789 #include "unwind-ia64.h"
4791 /* An absolute address consists of a section and an offset. If the
4792 section is NULL, the offset itself is the address, otherwise, the
4793 address equals to LOAD_ADDRESS(section) + offset. */
4797 unsigned short section
;
4801 #define ABSADDR(a) \
4803 ? section_headers [(a).section].sh_addr + (a).offset \
4806 struct ia64_unw_aux_info
4808 struct ia64_unw_table_entry
4810 struct absaddr start
;
4812 struct absaddr info
;
4814 *table
; /* Unwind table. */
4815 unsigned long table_len
; /* Length of unwind table. */
4816 unsigned char *info
; /* Unwind info. */
4817 unsigned long info_size
; /* Size of unwind info. */
4818 bfd_vma info_addr
; /* starting address of unwind info. */
4819 bfd_vma seg_base
; /* Starting address of segment. */
4820 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4821 unsigned long nsyms
; /* Number of symbols. */
4822 char *strtab
; /* The string table. */
4823 unsigned long strtab_size
; /* Size of string table. */
4827 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4828 unsigned long nsyms
,
4830 unsigned long strtab_size
,
4831 struct absaddr addr
,
4832 const char **symname
,
4835 bfd_vma dist
= 0x100000;
4836 Elf_Internal_Sym
*sym
, *best
= NULL
;
4839 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4841 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4842 && sym
->st_name
!= 0
4843 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4844 && addr
.offset
>= sym
->st_value
4845 && addr
.offset
- sym
->st_value
< dist
)
4848 dist
= addr
.offset
- sym
->st_value
;
4855 *symname
= (best
->st_name
>= strtab_size
4856 ? "<corrupt>" : strtab
+ best
->st_name
);
4861 *offset
= addr
.offset
;
4865 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4867 struct ia64_unw_table_entry
*tp
;
4870 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4874 const unsigned char *dp
;
4875 const unsigned char *head
;
4876 const char *procname
;
4878 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4879 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4881 fputs ("\n<", stdout
);
4885 fputs (procname
, stdout
);
4888 printf ("+%lx", (unsigned long) offset
);
4891 fputs (">: [", stdout
);
4892 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4893 fputc ('-', stdout
);
4894 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4895 printf ("], info at +0x%lx\n",
4896 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4898 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4899 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4901 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4902 (unsigned) UNW_VER (stamp
),
4903 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4904 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4905 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4906 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4908 if (UNW_VER (stamp
) != 1)
4910 printf ("\tUnknown version.\n");
4915 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4916 dp
= unw_decode (dp
, in_body
, & in_body
);
4921 slurp_ia64_unwind_table (FILE *file
,
4922 struct ia64_unw_aux_info
*aux
,
4923 Elf_Internal_Shdr
*sec
)
4925 unsigned long size
, nrelas
, i
;
4926 Elf_Internal_Phdr
*seg
;
4927 struct ia64_unw_table_entry
*tep
;
4928 Elf_Internal_Shdr
*relsec
;
4929 Elf_Internal_Rela
*rela
, *rp
;
4930 unsigned char *table
, *tp
;
4931 Elf_Internal_Sym
*sym
;
4932 const char *relname
;
4934 /* First, find the starting address of the segment that includes
4937 if (elf_header
.e_phnum
)
4939 if (! get_program_headers (file
))
4942 for (seg
= program_headers
;
4943 seg
< program_headers
+ elf_header
.e_phnum
;
4946 if (seg
->p_type
!= PT_LOAD
)
4949 if (sec
->sh_addr
>= seg
->p_vaddr
4950 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4952 aux
->seg_base
= seg
->p_vaddr
;
4958 /* Second, build the unwind table from the contents of the unwind section: */
4959 size
= sec
->sh_size
;
4960 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4964 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4966 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4968 tep
->start
.section
= SHN_UNDEF
;
4969 tep
->end
.section
= SHN_UNDEF
;
4970 tep
->info
.section
= SHN_UNDEF
;
4973 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4974 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4975 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4979 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
4980 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
4981 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
4983 tep
->start
.offset
+= aux
->seg_base
;
4984 tep
->end
.offset
+= aux
->seg_base
;
4985 tep
->info
.offset
+= aux
->seg_base
;
4989 /* Third, apply any relocations to the unwind table: */
4991 for (relsec
= section_headers
;
4992 relsec
< section_headers
+ elf_header
.e_shnum
;
4995 if (relsec
->sh_type
!= SHT_RELA
4996 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
4997 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5000 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5004 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5008 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5009 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5013 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5014 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5017 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5019 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5023 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5025 switch (rp
->r_offset
/eh_addr_size
% 3)
5028 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5029 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5032 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5033 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5036 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5037 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5047 aux
->table_len
= size
/ (3 * eh_addr_size
);
5052 ia64_process_unwind (FILE *file
)
5054 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
5055 unsigned long i
, unwcount
= 0, unwstart
= 0;
5056 struct ia64_unw_aux_info aux
;
5058 memset (& aux
, 0, sizeof (aux
));
5060 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5062 if (sec
->sh_type
== SHT_SYMTAB
5063 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5065 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5066 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5068 strsec
= SECTION_HEADER (sec
->sh_link
);
5069 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5070 1, strsec
->sh_size
, _("string table"));
5071 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5073 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5078 printf (_("\nThere are no unwind sections in this file.\n"));
5080 while (unwcount
-- > 0)
5085 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5086 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5087 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5094 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5096 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5098 /* We need to find which section group it is in. */
5099 struct group_list
*g
= section_headers_groups
[i
]->root
;
5101 for (; g
!= NULL
; g
= g
->next
)
5103 sec
= SECTION_HEADER (g
->section_index
);
5105 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5110 i
= elf_header
.e_shnum
;
5112 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5114 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5115 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5116 suffix
= SECTION_NAME (unwsec
) + len
;
5117 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5119 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5120 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5125 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5126 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5127 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5128 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5130 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5131 suffix
= SECTION_NAME (unwsec
) + len
;
5132 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5134 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5135 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5139 if (i
== elf_header
.e_shnum
)
5141 printf (_("\nCould not find unwind info section for "));
5143 if (string_table
== NULL
)
5144 printf ("%d", unwsec
->sh_name
);
5146 printf (_("'%s'"), SECTION_NAME (unwsec
));
5150 aux
.info_size
= sec
->sh_size
;
5151 aux
.info_addr
= sec
->sh_addr
;
5152 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
5155 printf (_("\nUnwind section "));
5157 if (string_table
== NULL
)
5158 printf ("%d", unwsec
->sh_name
);
5160 printf (_("'%s'"), SECTION_NAME (unwsec
));
5162 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5163 (unsigned long) unwsec
->sh_offset
,
5164 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5166 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5168 if (aux
.table_len
> 0)
5169 dump_ia64_unwind (& aux
);
5172 free ((char *) aux
.table
);
5174 free ((char *) aux
.info
);
5183 free ((char *) aux
.strtab
);
5188 struct hppa_unw_aux_info
5190 struct hppa_unw_table_entry
5192 struct absaddr start
;
5194 unsigned int Cannot_unwind
:1; /* 0 */
5195 unsigned int Millicode
:1; /* 1 */
5196 unsigned int Millicode_save_sr0
:1; /* 2 */
5197 unsigned int Region_description
:2; /* 3..4 */
5198 unsigned int reserved1
:1; /* 5 */
5199 unsigned int Entry_SR
:1; /* 6 */
5200 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5201 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5202 unsigned int Args_stored
:1; /* 16 */
5203 unsigned int Variable_Frame
:1; /* 17 */
5204 unsigned int Separate_Package_Body
:1; /* 18 */
5205 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5206 unsigned int Stack_Overflow_Check
:1; /* 20 */
5207 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5208 unsigned int Ada_Region
:1; /* 22 */
5209 unsigned int cxx_info
:1; /* 23 */
5210 unsigned int cxx_try_catch
:1; /* 24 */
5211 unsigned int sched_entry_seq
:1; /* 25 */
5212 unsigned int reserved2
:1; /* 26 */
5213 unsigned int Save_SP
:1; /* 27 */
5214 unsigned int Save_RP
:1; /* 28 */
5215 unsigned int Save_MRP_in_frame
:1; /* 29 */
5216 unsigned int extn_ptr_defined
:1; /* 30 */
5217 unsigned int Cleanup_defined
:1; /* 31 */
5219 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5220 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5221 unsigned int Large_frame
:1; /* 2 */
5222 unsigned int Pseudo_SP_Set
:1; /* 3 */
5223 unsigned int reserved4
:1; /* 4 */
5224 unsigned int Total_frame_size
:27; /* 5..31 */
5226 *table
; /* Unwind table. */
5227 unsigned long table_len
; /* Length of unwind table. */
5228 bfd_vma seg_base
; /* Starting address of segment. */
5229 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5230 unsigned long nsyms
; /* Number of symbols. */
5231 char *strtab
; /* The string table. */
5232 unsigned long strtab_size
; /* Size of string table. */
5236 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5238 struct hppa_unw_table_entry
*tp
;
5240 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5243 const char *procname
;
5245 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5246 aux
->strtab_size
, tp
->start
, &procname
,
5249 fputs ("\n<", stdout
);
5253 fputs (procname
, stdout
);
5256 printf ("+%lx", (unsigned long) offset
);
5259 fputs (">: [", stdout
);
5260 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5261 fputc ('-', stdout
);
5262 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5265 #define PF(_m) if (tp->_m) printf (#_m " ");
5266 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5269 PF(Millicode_save_sr0
);
5270 /* PV(Region_description); */
5276 PF(Separate_Package_Body
);
5277 PF(Frame_Extension_Millicode
);
5278 PF(Stack_Overflow_Check
);
5279 PF(Two_Instruction_SP_Increment
);
5283 PF(sched_entry_seq
);
5286 PF(Save_MRP_in_frame
);
5287 PF(extn_ptr_defined
);
5288 PF(Cleanup_defined
);
5289 PF(MPE_XL_interrupt_marker
);
5290 PF(HP_UX_interrupt_marker
);
5293 PV(Total_frame_size
);
5302 slurp_hppa_unwind_table (FILE *file
,
5303 struct hppa_unw_aux_info
*aux
,
5304 Elf_Internal_Shdr
*sec
)
5306 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5307 Elf_Internal_Phdr
*seg
;
5308 struct hppa_unw_table_entry
*tep
;
5309 Elf_Internal_Shdr
*relsec
;
5310 Elf_Internal_Rela
*rela
, *rp
;
5311 unsigned char *table
, *tp
;
5312 Elf_Internal_Sym
*sym
;
5313 const char *relname
;
5315 /* First, find the starting address of the segment that includes
5318 if (elf_header
.e_phnum
)
5320 if (! get_program_headers (file
))
5323 for (seg
= program_headers
;
5324 seg
< program_headers
+ elf_header
.e_phnum
;
5327 if (seg
->p_type
!= PT_LOAD
)
5330 if (sec
->sh_addr
>= seg
->p_vaddr
5331 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5333 aux
->seg_base
= seg
->p_vaddr
;
5339 /* Second, build the unwind table from the contents of the unwind
5341 size
= sec
->sh_size
;
5342 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5347 nentries
= size
/ unw_ent_size
;
5348 size
= unw_ent_size
* nentries
;
5350 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5352 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5354 unsigned int tmp1
, tmp2
;
5356 tep
->start
.section
= SHN_UNDEF
;
5357 tep
->end
.section
= SHN_UNDEF
;
5359 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5360 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5361 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5362 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5364 tep
->start
.offset
+= aux
->seg_base
;
5365 tep
->end
.offset
+= aux
->seg_base
;
5367 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5368 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5369 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5370 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5371 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5372 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5373 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5374 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5375 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5376 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5377 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5378 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5379 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5380 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5381 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5382 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5383 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5384 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5385 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5386 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5387 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5388 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5389 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5390 tep
->Cleanup_defined
= tmp1
& 0x1;
5392 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5393 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5394 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5395 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5396 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5397 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5401 /* Third, apply any relocations to the unwind table. */
5403 for (relsec
= section_headers
;
5404 relsec
< section_headers
+ elf_header
.e_shnum
;
5407 if (relsec
->sh_type
!= SHT_RELA
5408 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5409 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5412 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5416 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5420 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5421 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5425 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5426 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5429 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5430 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5432 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5436 i
= rp
->r_offset
/ unw_ent_size
;
5438 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5441 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5442 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5445 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5446 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5456 aux
->table_len
= nentries
;
5462 hppa_process_unwind (FILE *file
)
5464 struct hppa_unw_aux_info aux
;
5465 Elf_Internal_Shdr
*unwsec
= NULL
;
5466 Elf_Internal_Shdr
*strsec
;
5467 Elf_Internal_Shdr
*sec
;
5470 memset (& aux
, 0, sizeof (aux
));
5472 if (string_table
== NULL
)
5475 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5477 if (sec
->sh_type
== SHT_SYMTAB
5478 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5480 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5481 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5483 strsec
= SECTION_HEADER (sec
->sh_link
);
5484 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5485 1, strsec
->sh_size
, _("string table"));
5486 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5488 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5493 printf (_("\nThere are no unwind sections in this file.\n"));
5495 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5497 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5499 printf (_("\nUnwind section "));
5500 printf (_("'%s'"), SECTION_NAME (sec
));
5502 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5503 (unsigned long) sec
->sh_offset
,
5504 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5506 slurp_hppa_unwind_table (file
, &aux
, sec
);
5507 if (aux
.table_len
> 0)
5508 dump_hppa_unwind (&aux
);
5511 free ((char *) aux
.table
);
5519 free ((char *) aux
.strtab
);
5525 process_unwind (FILE *file
)
5527 struct unwind_handler
{
5529 int (*handler
)(FILE *file
);
5531 { EM_IA_64
, ia64_process_unwind
},
5532 { EM_PARISC
, hppa_process_unwind
},
5540 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5541 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5542 return handlers
[i
].handler (file
);
5544 printf (_("\nThere are no unwind sections in this file.\n"));
5549 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5551 switch (entry
->d_tag
)
5554 if (entry
->d_un
.d_val
== 0)
5558 static const char * opts
[] =
5560 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5561 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5562 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5563 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5568 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
5569 if (entry
->d_un
.d_val
& (1 << cnt
))
5571 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5578 case DT_MIPS_IVERSION
:
5579 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5580 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5582 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5585 case DT_MIPS_TIME_STAMP
:
5590 time_t time
= entry
->d_un
.d_val
;
5591 tmp
= gmtime (&time
);
5592 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5593 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5594 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5595 printf ("Time Stamp: %s\n", timebuf
);
5599 case DT_MIPS_RLD_VERSION
:
5600 case DT_MIPS_LOCAL_GOTNO
:
5601 case DT_MIPS_CONFLICTNO
:
5602 case DT_MIPS_LIBLISTNO
:
5603 case DT_MIPS_SYMTABNO
:
5604 case DT_MIPS_UNREFEXTNO
:
5605 case DT_MIPS_HIPAGENO
:
5606 case DT_MIPS_DELTA_CLASS_NO
:
5607 case DT_MIPS_DELTA_INSTANCE_NO
:
5608 case DT_MIPS_DELTA_RELOC_NO
:
5609 case DT_MIPS_DELTA_SYM_NO
:
5610 case DT_MIPS_DELTA_CLASSSYM_NO
:
5611 case DT_MIPS_COMPACT_SIZE
:
5612 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5616 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5622 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5624 switch (entry
->d_tag
)
5626 case DT_HP_DLD_FLAGS
:
5635 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5636 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5637 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5638 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5639 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5640 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5641 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5642 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5643 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5644 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5645 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5646 { DT_HP_GST
, "HP_GST" },
5647 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5648 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5649 { DT_HP_NODELETE
, "HP_NODELETE" },
5650 { DT_HP_GROUP
, "HP_GROUP" },
5651 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5655 bfd_vma val
= entry
->d_un
.d_val
;
5657 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
5658 if (val
& flags
[cnt
].bit
)
5662 fputs (flags
[cnt
].str
, stdout
);
5664 val
^= flags
[cnt
].bit
;
5667 if (val
!= 0 || first
)
5671 print_vma (val
, HEX
);
5677 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5684 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5686 switch (entry
->d_tag
)
5688 case DT_IA_64_PLT_RESERVE
:
5689 /* First 3 slots reserved. */
5690 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5692 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5696 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5703 get_32bit_dynamic_section (FILE *file
)
5705 Elf32_External_Dyn
*edyn
, *ext
;
5706 Elf_Internal_Dyn
*entry
;
5708 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5709 _("dynamic section"));
5713 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5714 might not have the luxury of section headers. Look for the DT_NULL
5715 terminator to determine the number of entries. */
5716 for (ext
= edyn
, dynamic_nent
= 0;
5717 (char *) ext
< (char *) edyn
+ dynamic_size
;
5721 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5725 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5726 if (dynamic_section
== NULL
)
5728 error (_("Out of memory\n"));
5733 for (ext
= edyn
, entry
= dynamic_section
;
5734 entry
< dynamic_section
+ dynamic_nent
;
5737 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5738 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5747 get_64bit_dynamic_section (FILE *file
)
5749 Elf64_External_Dyn
*edyn
, *ext
;
5750 Elf_Internal_Dyn
*entry
;
5752 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5753 _("dynamic section"));
5757 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5758 might not have the luxury of section headers. Look for the DT_NULL
5759 terminator to determine the number of entries. */
5760 for (ext
= edyn
, dynamic_nent
= 0;
5761 (char *) ext
< (char *) edyn
+ dynamic_size
;
5765 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5769 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5770 if (dynamic_section
== NULL
)
5772 error (_("Out of memory\n"));
5777 for (ext
= edyn
, entry
= dynamic_section
;
5778 entry
< dynamic_section
+ dynamic_nent
;
5781 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5782 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5791 print_dynamic_flags (bfd_vma flags
)
5799 flag
= flags
& - flags
;
5809 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5810 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5811 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5812 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5813 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5814 default: fputs ("unknown", stdout
); break;
5820 /* Parse and display the contents of the dynamic section. */
5823 process_dynamic_section (FILE *file
)
5825 Elf_Internal_Dyn
*entry
;
5827 if (dynamic_size
== 0)
5830 printf (_("\nThere is no dynamic section in this file.\n"));
5837 if (! get_32bit_dynamic_section (file
))
5840 else if (! get_64bit_dynamic_section (file
))
5843 /* Find the appropriate symbol table. */
5844 if (dynamic_symbols
== NULL
)
5846 for (entry
= dynamic_section
;
5847 entry
< dynamic_section
+ dynamic_nent
;
5850 Elf_Internal_Shdr section
;
5852 if (entry
->d_tag
!= DT_SYMTAB
)
5855 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5857 /* Since we do not know how big the symbol table is,
5858 we default to reading in the entire file (!) and
5859 processing that. This is overkill, I know, but it
5861 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5863 if (archive_file_offset
!= 0)
5864 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5867 if (fseek (file
, 0, SEEK_END
))
5868 error (_("Unable to seek to end of file!\n"));
5870 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5874 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5876 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5878 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5879 if (num_dynamic_syms
< 1)
5881 error (_("Unable to determine the number of symbols to load\n"));
5885 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5889 /* Similarly find a string table. */
5890 if (dynamic_strings
== NULL
)
5892 for (entry
= dynamic_section
;
5893 entry
< dynamic_section
+ dynamic_nent
;
5896 unsigned long offset
;
5899 if (entry
->d_tag
!= DT_STRTAB
)
5902 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5904 /* Since we do not know how big the string table is,
5905 we default to reading in the entire file (!) and
5906 processing that. This is overkill, I know, but it
5909 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5911 if (archive_file_offset
!= 0)
5912 str_tab_len
= archive_file_size
- offset
;
5915 if (fseek (file
, 0, SEEK_END
))
5916 error (_("Unable to seek to end of file\n"));
5917 str_tab_len
= ftell (file
) - offset
;
5920 if (str_tab_len
< 1)
5923 (_("Unable to determine the length of the dynamic string table\n"));
5927 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5928 _("dynamic string table"));
5929 dynamic_strings_length
= str_tab_len
;
5934 /* And find the syminfo section if available. */
5935 if (dynamic_syminfo
== NULL
)
5937 unsigned long syminsz
= 0;
5939 for (entry
= dynamic_section
;
5940 entry
< dynamic_section
+ dynamic_nent
;
5943 if (entry
->d_tag
== DT_SYMINENT
)
5945 /* Note: these braces are necessary to avoid a syntax
5946 error from the SunOS4 C compiler. */
5947 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5949 else if (entry
->d_tag
== DT_SYMINSZ
)
5950 syminsz
= entry
->d_un
.d_val
;
5951 else if (entry
->d_tag
== DT_SYMINFO
)
5952 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5956 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5958 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5959 Elf_Internal_Syminfo
*syminfo
;
5961 /* There is a syminfo section. Read the data. */
5962 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5963 syminsz
, _("symbol information"));
5967 dynamic_syminfo
= malloc (syminsz
);
5968 if (dynamic_syminfo
== NULL
)
5970 error (_("Out of memory\n"));
5974 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5975 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5976 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5977 ++syminfo
, ++extsym
)
5979 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5980 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5987 if (do_dynamic
&& dynamic_addr
)
5988 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5989 dynamic_addr
, dynamic_nent
);
5991 printf (_(" Tag Type Name/Value\n"));
5993 for (entry
= dynamic_section
;
5994 entry
< dynamic_section
+ dynamic_nent
;
6002 print_vma (entry
->d_tag
, FULL_HEX
);
6003 dtype
= get_dynamic_type (entry
->d_tag
);
6004 printf (" (%s)%*s", dtype
,
6005 ((is_32bit_elf
? 27 : 19)
6006 - (int) strlen (dtype
)),
6010 switch (entry
->d_tag
)
6014 print_dynamic_flags (entry
->d_un
.d_val
);
6024 switch (entry
->d_tag
)
6027 printf (_("Auxiliary library"));
6031 printf (_("Filter library"));
6035 printf (_("Configuration file"));
6039 printf (_("Dependency audit library"));
6043 printf (_("Audit library"));
6047 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6048 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6052 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6061 printf (_("Flags:"));
6063 if (entry
->d_un
.d_val
== 0)
6064 printf (_(" None\n"));
6067 unsigned long int val
= entry
->d_un
.d_val
;
6069 if (val
& DTF_1_PARINIT
)
6071 printf (" PARINIT");
6072 val
^= DTF_1_PARINIT
;
6074 if (val
& DTF_1_CONFEXP
)
6076 printf (" CONFEXP");
6077 val
^= DTF_1_CONFEXP
;
6080 printf (" %lx", val
);
6089 printf (_("Flags:"));
6091 if (entry
->d_un
.d_val
== 0)
6092 printf (_(" None\n"));
6095 unsigned long int val
= entry
->d_un
.d_val
;
6097 if (val
& DF_P1_LAZYLOAD
)
6099 printf (" LAZYLOAD");
6100 val
^= DF_P1_LAZYLOAD
;
6102 if (val
& DF_P1_GROUPPERM
)
6104 printf (" GROUPPERM");
6105 val
^= DF_P1_GROUPPERM
;
6108 printf (" %lx", val
);
6117 printf (_("Flags:"));
6118 if (entry
->d_un
.d_val
== 0)
6119 printf (_(" None\n"));
6122 unsigned long int val
= entry
->d_un
.d_val
;
6129 if (val
& DF_1_GLOBAL
)
6134 if (val
& DF_1_GROUP
)
6139 if (val
& DF_1_NODELETE
)
6141 printf (" NODELETE");
6142 val
^= DF_1_NODELETE
;
6144 if (val
& DF_1_LOADFLTR
)
6146 printf (" LOADFLTR");
6147 val
^= DF_1_LOADFLTR
;
6149 if (val
& DF_1_INITFIRST
)
6151 printf (" INITFIRST");
6152 val
^= DF_1_INITFIRST
;
6154 if (val
& DF_1_NOOPEN
)
6159 if (val
& DF_1_ORIGIN
)
6164 if (val
& DF_1_DIRECT
)
6169 if (val
& DF_1_TRANS
)
6174 if (val
& DF_1_INTERPOSE
)
6176 printf (" INTERPOSE");
6177 val
^= DF_1_INTERPOSE
;
6179 if (val
& DF_1_NODEFLIB
)
6181 printf (" NODEFLIB");
6182 val
^= DF_1_NODEFLIB
;
6184 if (val
& DF_1_NODUMP
)
6189 if (val
& DF_1_CONLFAT
)
6191 printf (" CONLFAT");
6192 val
^= DF_1_CONLFAT
;
6195 printf (" %lx", val
);
6202 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6204 puts (get_dynamic_type (entry
->d_un
.d_val
));
6224 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6230 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6231 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6237 switch (entry
->d_tag
)
6240 printf (_("Shared library: [%s]"), name
);
6242 if (streq (name
, program_interpreter
))
6243 printf (_(" program interpreter"));
6247 printf (_("Library soname: [%s]"), name
);
6251 printf (_("Library rpath: [%s]"), name
);
6255 printf (_("Library runpath: [%s]"), name
);
6259 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6264 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6277 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6281 case DT_INIT_ARRAYSZ
:
6282 case DT_FINI_ARRAYSZ
:
6283 case DT_GNU_CONFLICTSZ
:
6284 case DT_GNU_LIBLISTSZ
:
6287 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6288 printf (" (bytes)\n");
6298 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6311 if (entry
->d_tag
== DT_USED
6312 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6314 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6318 printf (_("Not needed object: [%s]\n"), name
);
6323 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6329 /* The value of this entry is ignored. */
6334 case DT_GNU_PRELINKED
:
6338 time_t time
= entry
->d_un
.d_val
;
6340 tmp
= gmtime (&time
);
6341 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6342 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6343 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6349 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6352 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6358 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6359 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6364 switch (elf_header
.e_machine
)
6367 case EM_MIPS_RS3_LE
:
6368 dynamic_section_mips_val (entry
);
6371 dynamic_section_parisc_val (entry
);
6374 dynamic_section_ia64_val (entry
);
6377 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6389 get_ver_flags (unsigned int flags
)
6391 static char buff
[32];
6398 if (flags
& VER_FLG_BASE
)
6399 strcat (buff
, "BASE ");
6401 if (flags
& VER_FLG_WEAK
)
6403 if (flags
& VER_FLG_BASE
)
6404 strcat (buff
, "| ");
6406 strcat (buff
, "WEAK ");
6409 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6410 strcat (buff
, "| <unknown>");
6415 /* Display the contents of the version sections. */
6417 process_version_sections (FILE *file
)
6419 Elf_Internal_Shdr
*section
;
6426 for (i
= 0, section
= section_headers
;
6427 i
< elf_header
.e_shnum
;
6430 switch (section
->sh_type
)
6432 case SHT_GNU_verdef
:
6434 Elf_External_Verdef
*edefs
;
6441 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6442 SECTION_NAME (section
), section
->sh_info
);
6444 printf (_(" Addr: 0x"));
6445 printf_vma (section
->sh_addr
);
6446 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6447 (unsigned long) section
->sh_offset
, section
->sh_link
,
6448 SECTION_HEADER_INDEX (section
->sh_link
)
6449 < elf_header
.e_shnum
6450 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6453 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6455 _("version definition section"));
6459 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6462 Elf_External_Verdef
*edef
;
6463 Elf_Internal_Verdef ent
;
6464 Elf_External_Verdaux
*eaux
;
6465 Elf_Internal_Verdaux aux
;
6469 vstart
= ((char *) edefs
) + idx
;
6471 edef
= (Elf_External_Verdef
*) vstart
;
6473 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6474 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6475 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6476 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6477 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6478 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6479 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6481 printf (_(" %#06x: Rev: %d Flags: %s"),
6482 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6484 printf (_(" Index: %d Cnt: %d "),
6485 ent
.vd_ndx
, ent
.vd_cnt
);
6487 vstart
+= ent
.vd_aux
;
6489 eaux
= (Elf_External_Verdaux
*) vstart
;
6491 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6492 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6494 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6495 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6497 printf (_("Name index: %ld\n"), aux
.vda_name
);
6499 isum
= idx
+ ent
.vd_aux
;
6501 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6503 isum
+= aux
.vda_next
;
6504 vstart
+= aux
.vda_next
;
6506 eaux
= (Elf_External_Verdaux
*) vstart
;
6508 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6509 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6511 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6512 printf (_(" %#06x: Parent %d: %s\n"),
6513 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6515 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6516 isum
, j
, aux
.vda_name
);
6526 case SHT_GNU_verneed
:
6528 Elf_External_Verneed
*eneed
;
6534 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6535 SECTION_NAME (section
), section
->sh_info
);
6537 printf (_(" Addr: 0x"));
6538 printf_vma (section
->sh_addr
);
6539 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6540 (unsigned long) section
->sh_offset
, section
->sh_link
,
6541 SECTION_HEADER_INDEX (section
->sh_link
)
6542 < elf_header
.e_shnum
6543 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6546 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6548 _("version need section"));
6552 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6554 Elf_External_Verneed
*entry
;
6555 Elf_Internal_Verneed ent
;
6560 vstart
= ((char *) eneed
) + idx
;
6562 entry
= (Elf_External_Verneed
*) vstart
;
6564 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6565 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6566 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6567 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6568 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6570 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6572 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6573 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6575 printf (_(" File: %lx"), ent
.vn_file
);
6577 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6579 vstart
+= ent
.vn_aux
;
6581 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6583 Elf_External_Vernaux
*eaux
;
6584 Elf_Internal_Vernaux aux
;
6586 eaux
= (Elf_External_Vernaux
*) vstart
;
6588 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6589 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6590 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6591 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6592 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6594 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6595 printf (_(" %#06x: Name: %s"),
6596 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6598 printf (_(" %#06x: Name index: %lx"),
6599 isum
, aux
.vna_name
);
6601 printf (_(" Flags: %s Version: %d\n"),
6602 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6604 isum
+= aux
.vna_next
;
6605 vstart
+= aux
.vna_next
;
6615 case SHT_GNU_versym
:
6617 Elf_Internal_Shdr
*link_section
;
6620 unsigned char *edata
;
6621 unsigned short *data
;
6623 Elf_Internal_Sym
*symbols
;
6624 Elf_Internal_Shdr
*string_sec
;
6627 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6630 link_section
= SECTION_HEADER (section
->sh_link
);
6631 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6633 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6634 >= elf_header
.e_shnum
)
6639 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6641 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6643 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6644 string_sec
->sh_size
, _("version string table"));
6648 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6649 SECTION_NAME (section
), total
);
6651 printf (_(" Addr: "));
6652 printf_vma (section
->sh_addr
);
6653 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6654 (unsigned long) section
->sh_offset
, section
->sh_link
,
6655 SECTION_NAME (link_section
));
6657 off
= offset_from_vma (file
,
6658 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6659 total
* sizeof (short));
6660 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6661 _("version symbol data"));
6668 data
= cmalloc (total
, sizeof (short));
6670 for (cnt
= total
; cnt
--;)
6671 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6676 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6679 int check_def
, check_need
;
6682 printf (" %03x:", cnt
);
6684 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6685 switch (data
[cnt
+ j
])
6688 fputs (_(" 0 (*local*) "), stdout
);
6692 fputs (_(" 1 (*global*) "), stdout
);
6696 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6697 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6701 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6702 >= elf_header
.e_shnum
6703 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6706 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6713 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6715 Elf_Internal_Verneed ivn
;
6716 unsigned long offset
;
6718 offset
= offset_from_vma
6719 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6720 sizeof (Elf_External_Verneed
));
6724 Elf_Internal_Vernaux ivna
;
6725 Elf_External_Verneed evn
;
6726 Elf_External_Vernaux evna
;
6727 unsigned long a_off
;
6729 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6732 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6733 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6735 a_off
= offset
+ ivn
.vn_aux
;
6739 get_data (&evna
, file
, a_off
, sizeof (evna
),
6740 1, _("version need aux (2)"));
6742 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6743 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6745 a_off
+= ivna
.vna_next
;
6747 while (ivna
.vna_other
!= data
[cnt
+ j
]
6748 && ivna
.vna_next
!= 0);
6750 if (ivna
.vna_other
== data
[cnt
+ j
])
6752 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6754 name
= strtab
+ ivna
.vna_name
;
6755 nn
+= printf ("(%s%-*s",
6757 12 - (int) strlen (name
),
6763 offset
+= ivn
.vn_next
;
6765 while (ivn
.vn_next
);
6768 if (check_def
&& data
[cnt
+ j
] != 0x8001
6769 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6771 Elf_Internal_Verdef ivd
;
6772 Elf_External_Verdef evd
;
6773 unsigned long offset
;
6775 offset
= offset_from_vma
6776 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6781 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6784 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6785 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6787 offset
+= ivd
.vd_next
;
6789 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6790 && ivd
.vd_next
!= 0);
6792 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6794 Elf_External_Verdaux evda
;
6795 Elf_Internal_Verdaux ivda
;
6797 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6799 get_data (&evda
, file
,
6800 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6802 _("version def aux"));
6804 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6806 name
= strtab
+ ivda
.vda_name
;
6807 nn
+= printf ("(%s%-*s",
6809 12 - (int) strlen (name
),
6815 printf ("%*c", 18 - nn
, ' ');
6833 printf (_("\nNo version information found in this file.\n"));
6839 get_symbol_binding (unsigned int binding
)
6841 static char buff
[32];
6845 case STB_LOCAL
: return "LOCAL";
6846 case STB_GLOBAL
: return "GLOBAL";
6847 case STB_WEAK
: return "WEAK";
6849 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6850 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6852 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6853 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6855 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6861 get_symbol_type (unsigned int type
)
6863 static char buff
[32];
6867 case STT_NOTYPE
: return "NOTYPE";
6868 case STT_OBJECT
: return "OBJECT";
6869 case STT_FUNC
: return "FUNC";
6870 case STT_SECTION
: return "SECTION";
6871 case STT_FILE
: return "FILE";
6872 case STT_COMMON
: return "COMMON";
6873 case STT_TLS
: return "TLS";
6874 case STT_RELC
: return "RELC";
6875 case STT_SRELC
: return "SRELC";
6877 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6879 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6880 return "THUMB_FUNC";
6882 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6885 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6886 return "PARISC_MILLI";
6888 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6890 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6892 if (elf_header
.e_machine
== EM_PARISC
)
6894 if (type
== STT_HP_OPAQUE
)
6896 if (type
== STT_HP_STUB
)
6900 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6903 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6909 get_symbol_visibility (unsigned int visibility
)
6913 case STV_DEFAULT
: return "DEFAULT";
6914 case STV_INTERNAL
: return "INTERNAL";
6915 case STV_HIDDEN
: return "HIDDEN";
6916 case STV_PROTECTED
: return "PROTECTED";
6922 get_mips_symbol_other (unsigned int other
)
6926 case STO_OPTIONAL
: return "OPTIONAL";
6927 case STO_MIPS16
: return "MIPS16";
6928 default: return NULL
;
6933 get_symbol_other (unsigned int other
)
6935 const char * result
= NULL
;
6936 static char buff
[32];
6941 switch (elf_header
.e_machine
)
6944 result
= get_mips_symbol_other (other
);
6952 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
6957 get_symbol_index_type (unsigned int type
)
6959 static char buff
[32];
6963 case SHN_UNDEF
: return "UND";
6964 case SHN_ABS
: return "ABS";
6965 case SHN_COMMON
: return "COM";
6967 if (type
== SHN_IA_64_ANSI_COMMON
6968 && elf_header
.e_machine
== EM_IA_64
6969 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6971 else if (elf_header
.e_machine
== EM_X86_64
6972 && type
== SHN_X86_64_LCOMMON
)
6974 else if (type
== SHN_MIPS_SCOMMON
6975 && elf_header
.e_machine
== EM_MIPS
)
6977 else if (type
== SHN_MIPS_SUNDEFINED
6978 && elf_header
.e_machine
== EM_MIPS
)
6980 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6981 sprintf (buff
, "PRC[0x%04x]", type
);
6982 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6983 sprintf (buff
, "OS [0x%04x]", type
);
6984 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6985 sprintf (buff
, "RSV[0x%04x]", type
);
6987 sprintf (buff
, "%3d", type
);
6995 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
6997 unsigned char *e_data
;
7000 e_data
= cmalloc (number
, ent_size
);
7004 error (_("Out of memory\n"));
7008 if (fread (e_data
, ent_size
, number
, file
) != number
)
7010 error (_("Unable to read in dynamic data\n"));
7014 i_data
= cmalloc (number
, sizeof (*i_data
));
7018 error (_("Out of memory\n"));
7024 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7031 /* Dump the symbol table. */
7033 process_symbol_table (FILE *file
)
7035 Elf_Internal_Shdr
*section
;
7036 bfd_vma nbuckets
= 0;
7037 bfd_vma nchains
= 0;
7038 bfd_vma
*buckets
= NULL
;
7039 bfd_vma
*chains
= NULL
;
7040 bfd_vma ngnubuckets
= 0;
7041 bfd_vma
*gnubuckets
= NULL
;
7042 bfd_vma
*gnuchains
= NULL
;
7044 if (! do_syms
&& !do_histogram
)
7047 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
7050 unsigned char nb
[8];
7051 unsigned char nc
[8];
7052 int hash_ent_size
= 4;
7054 if ((elf_header
.e_machine
== EM_ALPHA
7055 || elf_header
.e_machine
== EM_S390
7056 || elf_header
.e_machine
== EM_S390_OLD
)
7057 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7061 (archive_file_offset
7062 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7063 sizeof nb
+ sizeof nc
)),
7066 error (_("Unable to seek to start of dynamic information\n"));
7070 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7072 error (_("Failed to read in number of buckets\n"));
7076 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7078 error (_("Failed to read in number of chains\n"));
7082 nbuckets
= byte_get (nb
, hash_ent_size
);
7083 nchains
= byte_get (nc
, hash_ent_size
);
7085 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7086 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7088 if (buckets
== NULL
|| chains
== NULL
)
7093 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
7098 printf (_("\nSymbol table for image:\n"));
7100 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7102 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7104 for (hn
= 0; hn
< nbuckets
; hn
++)
7109 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7111 Elf_Internal_Sym
*psym
;
7114 psym
= dynamic_symbols
+ si
;
7116 n
= print_vma (si
, DEC_5
);
7118 fputs (" " + n
, stdout
);
7119 printf (" %3lu: ", hn
);
7120 print_vma (psym
->st_value
, LONG_HEX
);
7122 print_vma (psym
->st_size
, DEC_5
);
7124 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7125 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7126 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7127 /* Check to see if any other bits in the st_other field are set.
7128 Note - displaying this information disrupts the layout of the
7129 table being generated, but for the moment this case is very rare. */
7130 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7131 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7132 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7133 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7134 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7136 printf (" <corrupt: %14ld>", psym
->st_name
);
7141 else if (do_syms
&& !do_using_dynamic
)
7145 for (i
= 0, section
= section_headers
;
7146 i
< elf_header
.e_shnum
;
7150 char *strtab
= NULL
;
7151 unsigned long int strtab_size
= 0;
7152 Elf_Internal_Sym
*symtab
;
7153 Elf_Internal_Sym
*psym
;
7156 if ( section
->sh_type
!= SHT_SYMTAB
7157 && section
->sh_type
!= SHT_DYNSYM
)
7160 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7161 SECTION_NAME (section
),
7162 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7164 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7166 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7168 symtab
= GET_ELF_SYMBOLS (file
, section
);
7172 if (section
->sh_link
== elf_header
.e_shstrndx
)
7174 strtab
= string_table
;
7175 strtab_size
= string_table_length
;
7177 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
7179 Elf_Internal_Shdr
*string_sec
;
7181 string_sec
= SECTION_HEADER (section
->sh_link
);
7183 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
7184 1, string_sec
->sh_size
, _("string table"));
7185 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7188 for (si
= 0, psym
= symtab
;
7189 si
< section
->sh_size
/ section
->sh_entsize
;
7192 printf ("%6d: ", si
);
7193 print_vma (psym
->st_value
, LONG_HEX
);
7195 print_vma (psym
->st_size
, DEC_5
);
7196 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7197 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7198 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7199 /* Check to see if any other bits in the st_other field are set.
7200 Note - displaying this information disrupts the layout of the
7201 table being generated, but for the moment this case is very rare. */
7202 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7203 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7204 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7205 print_symbol (25, psym
->st_name
< strtab_size
7206 ? strtab
+ psym
->st_name
: "<corrupt>");
7208 if (section
->sh_type
== SHT_DYNSYM
&&
7209 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7211 unsigned char data
[2];
7212 unsigned short vers_data
;
7213 unsigned long offset
;
7217 offset
= offset_from_vma
7218 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7219 sizeof data
+ si
* sizeof (vers_data
));
7221 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7222 sizeof (data
), 1, _("version data"));
7224 vers_data
= byte_get (data
, 2);
7226 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7227 < elf_header
.e_shnum
7228 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7231 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7233 if ((vers_data
& 0x8000) || vers_data
> 1)
7235 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7236 && (is_nobits
|| ! check_def
))
7238 Elf_External_Verneed evn
;
7239 Elf_Internal_Verneed ivn
;
7240 Elf_Internal_Vernaux ivna
;
7242 /* We must test both. */
7243 offset
= offset_from_vma
7244 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7249 unsigned long vna_off
;
7251 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7254 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7255 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7257 vna_off
= offset
+ ivn
.vn_aux
;
7261 Elf_External_Vernaux evna
;
7263 get_data (&evna
, file
, vna_off
,
7265 _("version need aux (3)"));
7267 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7268 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7269 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7271 vna_off
+= ivna
.vna_next
;
7273 while (ivna
.vna_other
!= vers_data
7274 && ivna
.vna_next
!= 0);
7276 if (ivna
.vna_other
== vers_data
)
7279 offset
+= ivn
.vn_next
;
7281 while (ivn
.vn_next
!= 0);
7283 if (ivna
.vna_other
== vers_data
)
7286 ivna
.vna_name
< strtab_size
7287 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7291 else if (! is_nobits
)
7292 error (_("bad dynamic symbol\n"));
7299 if (vers_data
!= 0x8001
7300 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7302 Elf_Internal_Verdef ivd
;
7303 Elf_Internal_Verdaux ivda
;
7304 Elf_External_Verdaux evda
;
7305 unsigned long offset
;
7307 offset
= offset_from_vma
7309 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7310 sizeof (Elf_External_Verdef
));
7314 Elf_External_Verdef evd
;
7316 get_data (&evd
, file
, offset
, sizeof (evd
),
7317 1, _("version def"));
7319 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7320 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7321 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7323 offset
+= ivd
.vd_next
;
7325 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7326 && ivd
.vd_next
!= 0);
7328 offset
-= ivd
.vd_next
;
7329 offset
+= ivd
.vd_aux
;
7331 get_data (&evda
, file
, offset
, sizeof (evda
),
7332 1, _("version def aux"));
7334 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7336 if (psym
->st_name
!= ivda
.vda_name
)
7337 printf ((vers_data
& 0x8000)
7339 ivda
.vda_name
< strtab_size
7340 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7350 if (strtab
!= string_table
)
7356 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7358 if (do_histogram
&& buckets
!= NULL
)
7360 unsigned long *lengths
;
7361 unsigned long *counts
;
7364 unsigned long maxlength
= 0;
7365 unsigned long nzero_counts
= 0;
7366 unsigned long nsyms
= 0;
7368 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7369 (unsigned long) nbuckets
);
7370 printf (_(" Length Number %% of total Coverage\n"));
7372 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7373 if (lengths
== NULL
)
7375 error (_("Out of memory\n"));
7378 for (hn
= 0; hn
< nbuckets
; ++hn
)
7380 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7383 if (maxlength
< ++lengths
[hn
])
7388 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7391 error (_("Out of memory\n"));
7395 for (hn
= 0; hn
< nbuckets
; ++hn
)
7396 ++counts
[lengths
[hn
]];
7401 printf (" 0 %-10lu (%5.1f%%)\n",
7402 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7403 for (i
= 1; i
<= maxlength
; ++i
)
7405 nzero_counts
+= counts
[i
] * i
;
7406 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7407 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7408 (nzero_counts
* 100.0) / nsyms
);
7416 if (buckets
!= NULL
)
7422 if (do_histogram
&& dynamic_info_DT_GNU_HASH
)
7424 unsigned char nb
[16];
7425 bfd_vma i
, maxchain
= 0xffffffff, symidx
, bitmaskwords
;
7426 unsigned long *lengths
;
7427 unsigned long *counts
;
7429 unsigned long maxlength
= 0;
7430 unsigned long nzero_counts
= 0;
7431 unsigned long nsyms
= 0;
7432 bfd_vma buckets_vma
;
7435 (archive_file_offset
7436 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7440 error (_("Unable to seek to start of dynamic information\n"));
7444 if (fread (nb
, 16, 1, file
) != 1)
7446 error (_("Failed to read in number of buckets\n"));
7450 ngnubuckets
= byte_get (nb
, 4);
7451 symidx
= byte_get (nb
+ 4, 4);
7452 bitmaskwords
= byte_get (nb
+ 8, 4);
7453 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7455 buckets_vma
+= bitmaskwords
* 4;
7457 buckets_vma
+= bitmaskwords
* 8;
7460 (archive_file_offset
7461 + offset_from_vma (file
, buckets_vma
, 4)),
7464 error (_("Unable to seek to start of dynamic information\n"));
7468 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7470 if (gnubuckets
== NULL
)
7473 for (i
= 0; i
< ngnubuckets
; i
++)
7474 if (gnubuckets
[i
] != 0)
7476 if (gnubuckets
[i
] < symidx
)
7479 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7480 maxchain
= gnubuckets
[i
];
7483 if (maxchain
== 0xffffffff)
7489 (archive_file_offset
7490 + offset_from_vma (file
, buckets_vma
7491 + 4 * (ngnubuckets
+ maxchain
), 4)),
7494 error (_("Unable to seek to start of dynamic information\n"));
7500 if (fread (nb
, 4, 1, file
) != 1)
7502 error (_("Failed to determine last chain length\n"));
7506 if (maxchain
+ 1 == 0)
7511 while ((byte_get (nb
, 4) & 1) == 0);
7514 (archive_file_offset
7515 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7518 error (_("Unable to seek to start of dynamic information\n"));
7522 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7524 if (gnuchains
== NULL
)
7527 lengths
= calloc (ngnubuckets
, sizeof (*lengths
));
7528 if (lengths
== NULL
)
7530 error (_("Out of memory\n"));
7534 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7535 (unsigned long) ngnubuckets
);
7536 printf (_(" Length Number %% of total Coverage\n"));
7538 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7539 if (gnubuckets
[hn
] != 0)
7541 bfd_vma off
, length
= 1;
7543 for (off
= gnubuckets
[hn
] - symidx
;
7544 (gnuchains
[off
] & 1) == 0; ++off
)
7546 lengths
[hn
] = length
;
7547 if (length
> maxlength
)
7552 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7555 error (_("Out of memory\n"));
7559 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7560 ++counts
[lengths
[hn
]];
7562 if (ngnubuckets
> 0)
7565 printf (" 0 %-10lu (%5.1f%%)\n",
7566 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7567 for (j
= 1; j
<= maxlength
; ++j
)
7569 nzero_counts
+= counts
[j
] * j
;
7570 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7571 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7572 (nzero_counts
* 100.0) / nsyms
);
7586 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7590 if (dynamic_syminfo
== NULL
7592 /* No syminfo, this is ok. */
7595 /* There better should be a dynamic symbol section. */
7596 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7600 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7601 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7603 printf (_(" Num: Name BoundTo Flags\n"));
7604 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7606 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7608 printf ("%4d: ", i
);
7609 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7610 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7612 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7615 switch (dynamic_syminfo
[i
].si_boundto
)
7617 case SYMINFO_BT_SELF
:
7618 fputs ("SELF ", stdout
);
7620 case SYMINFO_BT_PARENT
:
7621 fputs ("PARENT ", stdout
);
7624 if (dynamic_syminfo
[i
].si_boundto
> 0
7625 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7626 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7628 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7632 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7636 if (flags
& SYMINFO_FLG_DIRECT
)
7638 if (flags
& SYMINFO_FLG_PASSTHRU
)
7639 printf (" PASSTHRU");
7640 if (flags
& SYMINFO_FLG_COPY
)
7642 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7643 printf (" LAZYLOAD");
7651 #ifdef SUPPORT_DISASSEMBLY
7653 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7655 printf (_("\nAssembly dump of section %s\n"),
7656 SECTION_NAME (section
));
7658 /* XXX -- to be done --- XXX */
7665 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
7667 Elf_Internal_Shdr
*relsec
;
7668 bfd_size_type bytes
;
7670 unsigned char *data
;
7671 unsigned char *start
;
7673 bytes
= section
->sh_size
;
7675 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7677 printf (_("\nSection '%s' has no data to dump.\n"),
7678 SECTION_NAME (section
));
7682 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7684 addr
= section
->sh_addr
;
7686 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7691 /* If the section being dumped has relocations against it the user might
7692 be expecting these relocations to have been applied. Check for this
7693 case and issue a warning message in order to avoid confusion.
7694 FIXME: Maybe we ought to have an option that dumps a section with
7696 for (relsec
= section_headers
;
7697 relsec
< section_headers
+ elf_header
.e_shnum
;
7700 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
7701 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7702 || SECTION_HEADER (relsec
->sh_info
) != section
7703 || relsec
->sh_size
== 0
7704 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7707 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
7719 lbytes
= (bytes
> 16 ? 16 : bytes
);
7721 printf (" 0x%8.8lx ", (unsigned long) addr
);
7723 for (j
= 0; j
< 16; j
++)
7726 printf ("%2.2x", data
[j
]);
7734 for (j
= 0; j
< lbytes
; j
++)
7737 if (k
>= ' ' && k
< 0x7f)
7756 /* Return the number of bytes affected by a given reloc.
7757 This information is architecture and reloc dependent.
7758 Returns 4 by default, although this is not always correct.
7759 It should return 0 if a decision cannot be made.
7760 FIXME: This is not the correct way to solve this problem.
7761 The proper way is to have target specific reloc sizing functions
7762 created by the reloc-macros.h header, in the same way that it
7763 already creates the reloc naming functions. */
7766 get_reloc_size (Elf_Internal_Rela
* reloc
)
7768 switch (elf_header
.e_machine
)
7774 switch (ELF32_R_TYPE (reloc
->r_info
))
7776 /* PR gas/3800 - without this information we do not correctly
7777 decode the debug information generated by the h8300 assembler. */
7784 /* FIXME: We need to extend this switch statement to cope with other
7785 architecture's relocs. (When those relocs are used against debug
7786 sections, and when their size is not 4). But see the multiple
7787 inclusions of <elf/h8.h> for an example of the hoops that we need
7788 to jump through in order to obtain the reloc numbers. */
7793 /* Apply addends of RELA relocations. */
7796 debug_apply_rela_addends (void *file
,
7797 Elf_Internal_Shdr
*section
,
7798 unsigned char *start
)
7800 Elf_Internal_Shdr
*relsec
;
7801 unsigned char *end
= start
+ section
->sh_size
;
7803 if (!is_relocatable
)
7806 /* SH uses RELA but uses in place value instead of the addend field. */
7807 if (elf_header
.e_machine
== EM_SH
)
7810 for (relsec
= section_headers
;
7811 relsec
< section_headers
+ elf_header
.e_shnum
;
7814 unsigned long nrelas
;
7815 Elf_Internal_Rela
*rela
, *rp
;
7816 Elf_Internal_Shdr
*symsec
;
7817 Elf_Internal_Sym
*symtab
;
7818 Elf_Internal_Sym
*sym
;
7820 if (relsec
->sh_type
!= SHT_RELA
7821 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7822 || SECTION_HEADER (relsec
->sh_info
) != section
7823 || relsec
->sh_size
== 0
7824 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7827 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7831 symsec
= SECTION_HEADER (relsec
->sh_link
);
7832 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7834 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7837 unsigned int reloc_size
;
7839 reloc_size
= get_reloc_size (rp
);
7840 if (reloc_size
== 0)
7842 warn (_("skipping relocation of unknown size against offset 0x%lx in section %s\n"),
7843 (unsigned long) rp
->r_offset
,
7844 SECTION_NAME (section
));
7848 loc
= start
+ rp
->r_offset
;
7849 if ((loc
+ reloc_size
) > end
)
7851 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7852 (unsigned long) rp
->r_offset
,
7853 SECTION_NAME (section
));
7859 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7861 if (ELF32_R_SYM (rp
->r_info
) != 0
7862 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7863 /* Relocations against symbols without type can happen.
7864 Gcc -feliminate-dwarf2-dups may generate symbols
7865 without type for debug info. */
7866 && ELF32_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7867 /* Relocations against object symbols can happen,
7868 eg when referencing a global array. For an
7869 example of this see the _clz.o binary in libgcc.a. */
7870 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7872 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7873 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7874 SECTION_NAME (section
));
7880 /* In MIPS little-endian objects, r_info isn't really a
7881 64-bit little-endian value: it has a 32-bit little-endian
7882 symbol index followed by four individual byte fields.
7883 Reorder INFO accordingly. */
7884 if (elf_header
.e_machine
== EM_MIPS
7885 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7886 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7887 | ((rp
->r_info
>> 56) & 0xff)
7888 | ((rp
->r_info
>> 40) & 0xff00)
7889 | ((rp
->r_info
>> 24) & 0xff0000)
7890 | ((rp
->r_info
>> 8) & 0xff000000));
7892 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7894 if (ELF64_R_SYM (rp
->r_info
) != 0
7895 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7896 && ELF64_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7897 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7899 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7900 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7901 SECTION_NAME (section
));
7906 byte_put (loc
, rp
->r_addend
, reloc_size
);
7917 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
7919 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7920 Elf_Internal_Shdr
*sec
;
7923 /* If it is already loaded, do nothing. */
7924 if (section
->start
!= NULL
)
7927 /* Locate the debug section. */
7928 sec
= find_section (section
->name
);
7932 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
7933 section
->address
= sec
->sh_addr
;
7934 section
->size
= sec
->sh_size
;
7935 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
7938 if (debug_displays
[debug
].relocate
)
7939 debug_apply_rela_addends (file
, sec
, section
->start
);
7941 return section
->start
!= NULL
;
7945 free_debug_section (enum dwarf_section_display_enum debug
)
7947 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7949 if (section
->start
== NULL
)
7952 free ((char *) section
->start
);
7953 section
->start
= NULL
;
7954 section
->address
= 0;
7959 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
7961 char *name
= SECTION_NAME (section
);
7962 bfd_size_type length
;
7964 enum dwarf_section_display_enum i
;
7966 length
= section
->sh_size
;
7969 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7973 if (const_strneq (name
, ".gnu.linkonce.wi."))
7974 name
= ".debug_info";
7976 /* See if we know how to display the contents of this section. */
7977 for (i
= 0; i
< max
; i
++)
7978 if (streq (debug_displays
[i
].section
.name
, name
))
7980 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
7982 if (load_debug_section (i
, file
))
7984 result
&= debug_displays
[i
].display (sec
, file
);
7986 if (i
!= info
&& i
!= abbrev
)
7987 free_debug_section (i
);
7995 printf (_("Unrecognized debug section: %s\n"), name
);
8002 /* Set DUMP_SECTS for all sections where dumps were requested
8003 based on section name. */
8006 initialise_dumps_byname (void)
8008 struct dump_list_entry
*cur
;
8010 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
8015 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
8016 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
8018 request_dump (i
, cur
->type
);
8023 warn (_("Section '%s' was not dumped because it does not exist!\n"),
8029 process_section_contents (FILE *file
)
8031 Elf_Internal_Shdr
*section
;
8037 initialise_dumps_byname ();
8039 for (i
= 0, section
= section_headers
;
8040 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8043 #ifdef SUPPORT_DISASSEMBLY
8044 if (dump_sects
[i
] & DISASS_DUMP
)
8045 disassemble_section (section
, file
);
8047 if (dump_sects
[i
] & HEX_DUMP
)
8048 dump_section (section
, file
);
8050 if (dump_sects
[i
] & DEBUG_DUMP
)
8051 display_debug_section (section
, file
);
8054 /* Check to see if the user requested a
8055 dump of a section that does not exist. */
8056 while (i
++ < num_dump_sects
)
8058 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
8062 process_mips_fpe_exception (int mask
)
8067 if (mask
& OEX_FPU_INEX
)
8068 fputs ("INEX", stdout
), first
= 0;
8069 if (mask
& OEX_FPU_UFLO
)
8070 printf ("%sUFLO", first
? "" : "|"), first
= 0;
8071 if (mask
& OEX_FPU_OFLO
)
8072 printf ("%sOFLO", first
? "" : "|"), first
= 0;
8073 if (mask
& OEX_FPU_DIV0
)
8074 printf ("%sDIV0", first
? "" : "|"), first
= 0;
8075 if (mask
& OEX_FPU_INVAL
)
8076 printf ("%sINVAL", first
? "" : "|");
8079 fputs ("0", stdout
);
8082 /* ARM EABI attributes section. */
8087 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8090 } arm_attr_public_tag
;
8092 static const char *arm_attr_tag_CPU_arch
[] =
8093 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8095 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8096 static const char *arm_attr_tag_THUMB_ISA_use
[] =
8097 {"No", "Thumb-1", "Thumb-2"};
8098 /* FIXME: VFPv3 encoding was extrapolated! */
8099 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
8100 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
8101 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
8102 static const char *arm_attr_tag_ABI_PCS_config
[] =
8103 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8104 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8105 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
8106 {"V6", "SB", "TLS", "Unused"};
8107 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
8108 {"Absolute", "PC-relative", "SB-relative", "None"};
8109 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
8110 {"Absolute", "PC-relative", "None"};
8111 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
8112 {"None", "direct", "GOT-indirect"};
8113 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
8114 {"None", "??? 1", "2", "??? 3", "4"};
8115 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8116 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
8117 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8118 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8119 static const char *arm_attr_tag_ABI_FP_number_model
[] =
8120 {"Unused", "Finite", "RTABI", "IEEE 754"};
8121 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8122 static const char *arm_attr_tag_ABI_align8_preserved
[] =
8123 {"No", "Yes, except leaf SP", "Yes"};
8124 static const char *arm_attr_tag_ABI_enum_size
[] =
8125 {"Unused", "small", "int", "forced to int"};
8126 static const char *arm_attr_tag_ABI_HardFP_use
[] =
8127 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8128 static const char *arm_attr_tag_ABI_VFP_args
[] =
8129 {"AAPCS", "VFP registers", "custom"};
8130 static const char *arm_attr_tag_ABI_WMMX_args
[] =
8131 {"AAPCS", "WMMX registers", "custom"};
8132 static const char *arm_attr_tag_ABI_optimization_goals
[] =
8133 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8134 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8135 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
8136 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8137 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8139 #define LOOKUP(id, name) \
8140 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8141 static arm_attr_public_tag arm_attr_public_tags
[] =
8143 {4, "CPU_raw_name", 1, NULL
},
8144 {5, "CPU_name", 1, NULL
},
8145 LOOKUP(6, CPU_arch
),
8146 {7, "CPU_arch_profile", 0, NULL
},
8147 LOOKUP(8, ARM_ISA_use
),
8148 LOOKUP(9, THUMB_ISA_use
),
8149 LOOKUP(10, VFP_arch
),
8150 LOOKUP(11, WMMX_arch
),
8151 LOOKUP(12, NEON_arch
),
8152 LOOKUP(13, ABI_PCS_config
),
8153 LOOKUP(14, ABI_PCS_R9_use
),
8154 LOOKUP(15, ABI_PCS_RW_data
),
8155 LOOKUP(16, ABI_PCS_RO_DATA
),
8156 LOOKUP(17, ABI_PCS_GOT_use
),
8157 LOOKUP(18, ABI_PCS_wchar_t
),
8158 LOOKUP(19, ABI_FP_rounding
),
8159 LOOKUP(20, ABI_FP_denormal
),
8160 LOOKUP(21, ABI_FP_exceptions
),
8161 LOOKUP(22, ABI_FP_user_exceptions
),
8162 LOOKUP(23, ABI_FP_number_model
),
8163 LOOKUP(24, ABI_align8_needed
),
8164 LOOKUP(25, ABI_align8_preserved
),
8165 LOOKUP(26, ABI_enum_size
),
8166 LOOKUP(27, ABI_HardFP_use
),
8167 LOOKUP(28, ABI_VFP_args
),
8168 LOOKUP(29, ABI_WMMX_args
),
8169 LOOKUP(30, ABI_optimization_goals
),
8170 LOOKUP(31, ABI_FP_optimization_goals
),
8171 {32, "compatibility", 0, NULL
}
8175 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8178 read_uleb128 (unsigned char *p
, unsigned int *plen
)
8192 val
|= ((unsigned int)c
& 0x7f) << shift
;
8201 static unsigned char *
8202 display_arm_attribute (unsigned char *p
)
8207 arm_attr_public_tag
*attr
;
8211 tag
= read_uleb128 (p
, &len
);
8214 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
8216 if (arm_attr_public_tags
[i
].tag
== tag
)
8218 attr
= &arm_attr_public_tags
[i
];
8225 printf (" Tag_%s: ", attr
->name
);
8231 case 7: /* Tag_CPU_arch_profile. */
8232 val
= read_uleb128 (p
, &len
);
8236 case 0: printf ("None\n"); break;
8237 case 'A': printf ("Application\n"); break;
8238 case 'R': printf ("Realtime\n"); break;
8239 case 'M': printf ("Microcontroller\n"); break;
8240 default: printf ("??? (%d)\n", val
); break;
8244 case 32: /* Tag_compatibility. */
8245 val
= read_uleb128 (p
, &len
);
8247 printf ("flag = %d, vendor = %s\n", val
, p
);
8248 p
+= strlen((char *)p
) + 1;
8262 assert (attr
->type
& 0x80);
8263 val
= read_uleb128 (p
, &len
);
8265 type
= attr
->type
& 0x7f;
8267 printf ("??? (%d)\n", val
);
8269 printf ("%s\n", attr
->table
[val
]);
8276 type
= 1; /* String. */
8278 type
= 2; /* uleb128. */
8279 printf (" Tag_unknown_%d: ", tag
);
8284 printf ("\"%s\"\n", p
);
8285 p
+= strlen((char *)p
) + 1;
8289 val
= read_uleb128 (p
, &len
);
8291 printf ("%d (0x%x)\n", val
, val
);
8298 process_arm_specific (FILE *file
)
8300 Elf_Internal_Shdr
*sect
;
8301 unsigned char *contents
;
8304 bfd_vma section_len
;
8308 /* Find the section header so that we get the size. */
8309 for (i
= 0, sect
= section_headers
;
8310 i
< elf_header
.e_shnum
;
8313 if (sect
->sh_type
!= SHT_ARM_ATTRIBUTES
)
8316 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
8324 len
= sect
->sh_size
- 1;
8329 bfd_boolean public_section
;
8331 section_len
= byte_get (p
, 4);
8333 if (section_len
> len
)
8335 printf (_("ERROR: Bad section length (%d > %d)\n"),
8336 (int)section_len
, (int)len
);
8340 printf ("Attribute Section: %s\n", p
);
8341 if (strcmp ((char *)p
, "aeabi") == 0)
8342 public_section
= TRUE
;
8344 public_section
= FALSE
;
8345 namelen
= strlen ((char *)p
) + 1;
8347 section_len
-= namelen
+ 4;
8348 while (section_len
> 0)
8353 size
= byte_get (p
, 4);
8354 if (size
> section_len
)
8356 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
8357 (int)size
, (int)section_len
);
8360 section_len
-= size
;
8366 printf ("File Attributes\n");
8369 printf ("Section Attributes:");
8372 printf ("Symbol Attributes:");
8377 val
= read_uleb128 (p
, &i
);
8381 printf (" %d", val
);
8386 printf ("Unknown tag: %d\n", tag
);
8387 public_section
= FALSE
;
8393 p
= display_arm_attribute(p
);
8397 /* ??? Do something sensible, like dump hex. */
8398 printf (" Unknown section contexts\n");
8406 printf (_("Unknown format '%c'\n"), *p
);
8415 process_mips_specific (FILE *file
)
8417 Elf_Internal_Dyn
*entry
;
8418 size_t liblist_offset
= 0;
8419 size_t liblistno
= 0;
8420 size_t conflictsno
= 0;
8421 size_t options_offset
= 0;
8422 size_t conflicts_offset
= 0;
8424 /* We have a lot of special sections. Thanks SGI! */
8425 if (dynamic_section
== NULL
)
8426 /* No information available. */
8429 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
8430 switch (entry
->d_tag
)
8432 case DT_MIPS_LIBLIST
:
8434 = offset_from_vma (file
, entry
->d_un
.d_val
,
8435 liblistno
* sizeof (Elf32_External_Lib
));
8437 case DT_MIPS_LIBLISTNO
:
8438 liblistno
= entry
->d_un
.d_val
;
8440 case DT_MIPS_OPTIONS
:
8441 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
8443 case DT_MIPS_CONFLICT
:
8445 = offset_from_vma (file
, entry
->d_un
.d_val
,
8446 conflictsno
* sizeof (Elf32_External_Conflict
));
8448 case DT_MIPS_CONFLICTNO
:
8449 conflictsno
= entry
->d_un
.d_val
;
8455 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
8457 Elf32_External_Lib
*elib
;
8460 elib
= get_data (NULL
, file
, liblist_offset
,
8461 liblistno
, sizeof (Elf32_External_Lib
),
8465 printf ("\nSection '.liblist' contains %lu entries:\n",
8466 (unsigned long) liblistno
);
8467 fputs (" Library Time Stamp Checksum Version Flags\n",
8470 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
8477 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8478 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8479 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8480 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8481 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8483 tmp
= gmtime (&time
);
8484 snprintf (timebuf
, sizeof (timebuf
),
8485 "%04u-%02u-%02uT%02u:%02u:%02u",
8486 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8487 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8489 printf ("%3lu: ", (unsigned long) cnt
);
8490 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
8491 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
8493 printf ("<corrupt: %9ld>", liblist
.l_name
);
8494 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
8497 if (liblist
.l_flags
== 0)
8508 { " EXACT_MATCH", LL_EXACT_MATCH
},
8509 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
8510 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
8511 { " EXPORTS", LL_EXPORTS
},
8512 { " DELAY_LOAD", LL_DELAY_LOAD
},
8513 { " DELTA", LL_DELTA
}
8515 int flags
= liblist
.l_flags
;
8519 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
8521 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
8523 fputs (l_flags_vals
[fcnt
].name
, stdout
);
8524 flags
^= l_flags_vals
[fcnt
].bit
;
8527 printf (" %#x", (unsigned int) flags
);
8537 if (options_offset
!= 0)
8539 Elf_External_Options
*eopt
;
8540 Elf_Internal_Shdr
*sect
= section_headers
;
8541 Elf_Internal_Options
*iopt
;
8542 Elf_Internal_Options
*option
;
8546 /* Find the section header so that we get the size. */
8547 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
8550 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
8554 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
8557 error (_("Out of memory\n"));
8564 while (offset
< sect
->sh_size
)
8566 Elf_External_Options
*eoption
;
8568 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
8570 option
->kind
= BYTE_GET (eoption
->kind
);
8571 option
->size
= BYTE_GET (eoption
->size
);
8572 option
->section
= BYTE_GET (eoption
->section
);
8573 option
->info
= BYTE_GET (eoption
->info
);
8575 offset
+= option
->size
;
8581 printf (_("\nSection '%s' contains %d entries:\n"),
8582 SECTION_NAME (sect
), cnt
);
8590 switch (option
->kind
)
8593 /* This shouldn't happen. */
8594 printf (" NULL %d %lx", option
->section
, option
->info
);
8597 printf (" REGINFO ");
8598 if (elf_header
.e_machine
== EM_MIPS
)
8601 Elf32_External_RegInfo
*ereg
;
8602 Elf32_RegInfo reginfo
;
8604 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
8605 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8606 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8607 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8608 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8609 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8610 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8612 printf ("GPR %08lx GP 0x%lx\n",
8614 (unsigned long) reginfo
.ri_gp_value
);
8615 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8616 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8617 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8622 Elf64_External_RegInfo
*ereg
;
8623 Elf64_Internal_RegInfo reginfo
;
8625 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
8626 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8627 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8628 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8629 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8630 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8631 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8633 printf ("GPR %08lx GP 0x",
8634 reginfo
.ri_gprmask
);
8635 printf_vma (reginfo
.ri_gp_value
);
8638 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8639 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8640 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8644 case ODK_EXCEPTIONS
:
8645 fputs (" EXCEPTIONS fpe_min(", stdout
);
8646 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
8647 fputs (") fpe_max(", stdout
);
8648 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
8649 fputs (")", stdout
);
8651 if (option
->info
& OEX_PAGE0
)
8652 fputs (" PAGE0", stdout
);
8653 if (option
->info
& OEX_SMM
)
8654 fputs (" SMM", stdout
);
8655 if (option
->info
& OEX_FPDBUG
)
8656 fputs (" FPDBUG", stdout
);
8657 if (option
->info
& OEX_DISMISS
)
8658 fputs (" DISMISS", stdout
);
8661 fputs (" PAD ", stdout
);
8662 if (option
->info
& OPAD_PREFIX
)
8663 fputs (" PREFIX", stdout
);
8664 if (option
->info
& OPAD_POSTFIX
)
8665 fputs (" POSTFIX", stdout
);
8666 if (option
->info
& OPAD_SYMBOL
)
8667 fputs (" SYMBOL", stdout
);
8670 fputs (" HWPATCH ", stdout
);
8671 if (option
->info
& OHW_R4KEOP
)
8672 fputs (" R4KEOP", stdout
);
8673 if (option
->info
& OHW_R8KPFETCH
)
8674 fputs (" R8KPFETCH", stdout
);
8675 if (option
->info
& OHW_R5KEOP
)
8676 fputs (" R5KEOP", stdout
);
8677 if (option
->info
& OHW_R5KCVTL
)
8678 fputs (" R5KCVTL", stdout
);
8681 fputs (" FILL ", stdout
);
8682 /* XXX Print content of info word? */
8685 fputs (" TAGS ", stdout
);
8686 /* XXX Print content of info word? */
8689 fputs (" HWAND ", stdout
);
8690 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8691 fputs (" R4KEOP_CHECKED", stdout
);
8692 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8693 fputs (" R4KEOP_CLEAN", stdout
);
8696 fputs (" HWOR ", stdout
);
8697 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8698 fputs (" R4KEOP_CHECKED", stdout
);
8699 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8700 fputs (" R4KEOP_CLEAN", stdout
);
8703 printf (" GP_GROUP %#06lx self-contained %#06lx",
8704 option
->info
& OGP_GROUP
,
8705 (option
->info
& OGP_SELF
) >> 16);
8708 printf (" IDENT %#06lx self-contained %#06lx",
8709 option
->info
& OGP_GROUP
,
8710 (option
->info
& OGP_SELF
) >> 16);
8713 /* This shouldn't happen. */
8714 printf (" %3d ??? %d %lx",
8715 option
->kind
, option
->section
, option
->info
);
8719 len
= sizeof (*eopt
);
8720 while (len
< option
->size
)
8721 if (((char *) option
)[len
] >= ' '
8722 && ((char *) option
)[len
] < 0x7f)
8723 printf ("%c", ((char *) option
)[len
++]);
8725 printf ("\\%03o", ((char *) option
)[len
++]);
8727 fputs ("\n", stdout
);
8735 if (conflicts_offset
!= 0 && conflictsno
!= 0)
8737 Elf32_Conflict
*iconf
;
8740 if (dynamic_symbols
== NULL
)
8742 error (_("conflict list found without a dynamic symbol table\n"));
8746 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
8749 error (_("Out of memory\n"));
8755 Elf32_External_Conflict
*econf32
;
8757 econf32
= get_data (NULL
, file
, conflicts_offset
,
8758 conflictsno
, sizeof (*econf32
), _("conflict"));
8762 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8763 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
8769 Elf64_External_Conflict
*econf64
;
8771 econf64
= get_data (NULL
, file
, conflicts_offset
,
8772 conflictsno
, sizeof (*econf64
), _("conflict"));
8776 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8777 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
8782 printf (_("\nSection '.conflict' contains %lu entries:\n"),
8783 (unsigned long) conflictsno
);
8784 puts (_(" Num: Index Value Name"));
8786 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8788 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
8790 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
8791 print_vma (psym
->st_value
, FULL_HEX
);
8793 if (VALID_DYNAMIC_NAME (psym
->st_name
))
8794 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
8796 printf ("<corrupt: %14ld>", psym
->st_name
);
8807 process_gnu_liblist (FILE *file
)
8809 Elf_Internal_Shdr
*section
, *string_sec
;
8810 Elf32_External_Lib
*elib
;
8819 for (i
= 0, section
= section_headers
;
8820 i
< elf_header
.e_shnum
;
8823 switch (section
->sh_type
)
8825 case SHT_GNU_LIBLIST
:
8826 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
8829 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
8834 string_sec
= SECTION_HEADER (section
->sh_link
);
8836 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
8837 string_sec
->sh_size
, _("liblist string table"));
8838 strtab_size
= string_sec
->sh_size
;
8841 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
8847 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
8848 SECTION_NAME (section
),
8849 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
8851 puts (" Library Time Stamp Checksum Version Flags");
8853 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
8861 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8862 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8863 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8864 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8865 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8867 tmp
= gmtime (&time
);
8868 snprintf (timebuf
, sizeof (timebuf
),
8869 "%04u-%02u-%02uT%02u:%02u:%02u",
8870 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8871 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8873 printf ("%3lu: ", (unsigned long) cnt
);
8875 printf ("%-20s", liblist
.l_name
< strtab_size
8876 ? strtab
+ liblist
.l_name
: "<corrupt>");
8878 printf ("%-20.20s", liblist
.l_name
< strtab_size
8879 ? strtab
+ liblist
.l_name
: "<corrupt>");
8880 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
8881 liblist
.l_version
, liblist
.l_flags
);
8892 get_note_type (unsigned e_type
)
8894 static char buff
[64];
8896 if (elf_header
.e_type
== ET_CORE
)
8900 return _("NT_AUXV (auxiliary vector)");
8902 return _("NT_PRSTATUS (prstatus structure)");
8904 return _("NT_FPREGSET (floating point registers)");
8906 return _("NT_PRPSINFO (prpsinfo structure)");
8908 return _("NT_TASKSTRUCT (task structure)");
8910 return _("NT_PRXFPREG (user_xfpregs structure)");
8912 return _("NT_PSTATUS (pstatus structure)");
8914 return _("NT_FPREGS (floating point registers)");
8916 return _("NT_PSINFO (psinfo structure)");
8918 return _("NT_LWPSTATUS (lwpstatus_t structure)");
8920 return _("NT_LWPSINFO (lwpsinfo_t structure)");
8921 case NT_WIN32PSTATUS
:
8922 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8930 return _("NT_VERSION (version)");
8932 return _("NT_ARCH (architecture)");
8937 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8942 get_netbsd_elfcore_note_type (unsigned e_type
)
8944 static char buff
[64];
8946 if (e_type
== NT_NETBSDCORE_PROCINFO
)
8948 /* NetBSD core "procinfo" structure. */
8949 return _("NetBSD procinfo structure");
8952 /* As of Jan 2002 there are no other machine-independent notes
8953 defined for NetBSD core files. If the note type is less
8954 than the start of the machine-dependent note types, we don't
8957 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
8959 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8963 switch (elf_header
.e_machine
)
8965 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8966 and PT_GETFPREGS == mach+2. */
8971 case EM_SPARC32PLUS
:
8975 case NT_NETBSDCORE_FIRSTMACH
+0:
8976 return _("PT_GETREGS (reg structure)");
8977 case NT_NETBSDCORE_FIRSTMACH
+2:
8978 return _("PT_GETFPREGS (fpreg structure)");
8984 /* On all other arch's, PT_GETREGS == mach+1 and
8985 PT_GETFPREGS == mach+3. */
8989 case NT_NETBSDCORE_FIRSTMACH
+1:
8990 return _("PT_GETREGS (reg structure)");
8991 case NT_NETBSDCORE_FIRSTMACH
+3:
8992 return _("PT_GETFPREGS (fpreg structure)");
8998 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
8999 e_type
- NT_NETBSDCORE_FIRSTMACH
);
9003 /* Note that by the ELF standard, the name field is already null byte
9004 terminated, and namesz includes the terminating null byte.
9005 I.E. the value of namesz for the name "FSF" is 4.
9007 If the value of namesz is zero, there is no name present. */
9009 process_note (Elf_Internal_Note
*pnote
)
9013 if (pnote
->namesz
== 0)
9014 /* If there is no note name, then use the default set of
9015 note type strings. */
9016 nt
= get_note_type (pnote
->type
);
9018 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
9019 /* NetBSD-specific core file notes. */
9020 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
9023 /* Don't recognize this note name; just use the default set of
9024 note type strings. */
9025 nt
= get_note_type (pnote
->type
);
9027 printf (" %s\t\t0x%08lx\t%s\n",
9028 pnote
->namesz
? pnote
->namedata
: "(NONE)",
9035 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
9037 Elf_External_Note
*pnotes
;
9038 Elf_External_Note
*external
;
9044 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
9050 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9051 (unsigned long) offset
, (unsigned long) length
);
9052 printf (_(" Owner\t\tData size\tDescription\n"));
9054 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
9056 Elf_External_Note
*next
;
9057 Elf_Internal_Note inote
;
9060 inote
.type
= BYTE_GET (external
->type
);
9061 inote
.namesz
= BYTE_GET (external
->namesz
);
9062 inote
.namedata
= external
->name
;
9063 inote
.descsz
= BYTE_GET (external
->descsz
);
9064 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
9065 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
9067 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
9069 if (((char *) next
) > (((char *) pnotes
) + length
))
9071 warn (_("corrupt note found at offset %lx into core notes\n"),
9072 (long)((char *)external
- (char *)pnotes
));
9073 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
9074 inote
.type
, inote
.namesz
, inote
.descsz
);
9080 /* Verify that name is null terminated. It appears that at least
9081 one version of Linux (RedHat 6.0) generates corefiles that don't
9082 comply with the ELF spec by failing to include the null byte in
9084 if (inote
.namedata
[inote
.namesz
] != '\0')
9086 temp
= malloc (inote
.namesz
+ 1);
9090 error (_("Out of memory\n"));
9095 strncpy (temp
, inote
.namedata
, inote
.namesz
);
9096 temp
[inote
.namesz
] = 0;
9098 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9099 inote
.namedata
= temp
;
9102 res
&= process_note (& inote
);
9117 process_corefile_note_segments (FILE *file
)
9119 Elf_Internal_Phdr
*segment
;
9123 if (! get_program_headers (file
))
9126 for (i
= 0, segment
= program_headers
;
9127 i
< elf_header
.e_phnum
;
9130 if (segment
->p_type
== PT_NOTE
)
9131 res
&= process_corefile_note_segment (file
,
9132 (bfd_vma
) segment
->p_offset
,
9133 (bfd_vma
) segment
->p_filesz
);
9140 process_note_sections (FILE *file
)
9142 Elf_Internal_Shdr
*section
;
9146 for (i
= 0, section
= section_headers
;
9147 i
< elf_header
.e_shnum
;
9149 if (section
->sh_type
== SHT_NOTE
)
9150 res
&= process_corefile_note_segment (file
,
9151 (bfd_vma
) section
->sh_offset
,
9152 (bfd_vma
) section
->sh_size
);
9158 process_notes (FILE *file
)
9160 /* If we have not been asked to display the notes then do nothing. */
9164 if (elf_header
.e_type
!= ET_CORE
)
9165 return process_note_sections (file
);
9167 /* No program headers means no NOTE segment. */
9168 if (elf_header
.e_phnum
> 0)
9169 return process_corefile_note_segments (file
);
9171 printf (_("No note segments present in the core file.\n"));
9176 process_arch_specific (FILE *file
)
9181 switch (elf_header
.e_machine
)
9184 return process_arm_specific (file
);
9186 case EM_MIPS_RS3_LE
:
9187 return process_mips_specific (file
);
9196 get_file_header (FILE *file
)
9198 /* Read in the identity array. */
9199 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
9202 /* Determine how to read the rest of the header. */
9203 switch (elf_header
.e_ident
[EI_DATA
])
9205 default: /* fall through */
9206 case ELFDATANONE
: /* fall through */
9208 byte_get
= byte_get_little_endian
;
9209 byte_put
= byte_put_little_endian
;
9212 byte_get
= byte_get_big_endian
;
9213 byte_put
= byte_put_big_endian
;
9217 /* For now we only support 32 bit and 64 bit ELF files. */
9218 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
9220 /* Read in the rest of the header. */
9223 Elf32_External_Ehdr ehdr32
;
9225 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
9228 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
9229 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
9230 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
9231 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
9232 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
9233 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
9234 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
9235 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
9236 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
9237 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
9238 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
9239 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
9240 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
9244 Elf64_External_Ehdr ehdr64
;
9246 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9247 we will not be able to cope with the 64bit data found in
9248 64 ELF files. Detect this now and abort before we start
9249 overwriting things. */
9250 if (sizeof (bfd_vma
) < 8)
9252 error (_("This instance of readelf has been built without support for a\n\
9253 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9257 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
9260 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
9261 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
9262 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
9263 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
9264 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
9265 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
9266 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
9267 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
9268 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
9269 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
9270 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
9271 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
9272 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
9275 if (elf_header
.e_shoff
)
9277 /* There may be some extensions in the first section header. Don't
9278 bomb if we can't read it. */
9280 get_32bit_section_headers (file
, 1);
9282 get_64bit_section_headers (file
, 1);
9285 is_relocatable
= elf_header
.e_type
== ET_REL
;
9290 /* Process one ELF object file according to the command line options.
9291 This file may actually be stored in an archive. The file is
9292 positioned at the start of the ELF object. */
9295 process_object (char *file_name
, FILE *file
)
9299 if (! get_file_header (file
))
9301 error (_("%s: Failed to read file header\n"), file_name
);
9305 /* Initialise per file variables. */
9306 for (i
= NUM_ELEM (version_info
); i
--;)
9307 version_info
[i
] = 0;
9309 for (i
= NUM_ELEM (dynamic_info
); i
--;)
9310 dynamic_info
[i
] = 0;
9312 /* Process the file. */
9314 printf (_("\nFile: %s\n"), file_name
);
9316 /* Initialise the dump_sects array from the cmdline_dump_sects array.
9317 Note we do this even if cmdline_dump_sects is empty because we
9318 must make sure that the dump_sets array is zeroed out before each
9319 object file is processed. */
9320 if (num_dump_sects
> num_cmdline_dump_sects
)
9321 memset (dump_sects
, 0, num_dump_sects
);
9323 if (num_cmdline_dump_sects
> 0)
9325 if (num_dump_sects
== 0)
9326 /* A sneaky way of allocating the dump_sects array. */
9327 request_dump (num_cmdline_dump_sects
, 0);
9329 assert (num_dump_sects
>= num_cmdline_dump_sects
);
9330 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
9333 if (! process_file_header ())
9336 if (! process_section_headers (file
))
9338 /* Without loaded section headers we cannot process lots of
9340 do_unwind
= do_version
= do_dump
= do_arch
= 0;
9342 if (! do_using_dynamic
)
9343 do_syms
= do_reloc
= 0;
9346 if (! process_section_groups (file
))
9348 /* Without loaded section groups we cannot process unwind. */
9352 if (process_program_headers (file
))
9353 process_dynamic_section (file
);
9355 process_relocs (file
);
9357 process_unwind (file
);
9359 process_symbol_table (file
);
9361 process_syminfo (file
);
9363 process_version_sections (file
);
9365 process_section_contents (file
);
9367 process_notes (file
);
9369 process_gnu_liblist (file
);
9371 process_arch_specific (file
);
9373 if (program_headers
)
9375 free (program_headers
);
9376 program_headers
= NULL
;
9379 if (section_headers
)
9381 free (section_headers
);
9382 section_headers
= NULL
;
9387 free (string_table
);
9388 string_table
= NULL
;
9389 string_table_length
= 0;
9392 if (dynamic_strings
)
9394 free (dynamic_strings
);
9395 dynamic_strings
= NULL
;
9396 dynamic_strings_length
= 0;
9399 if (dynamic_symbols
)
9401 free (dynamic_symbols
);
9402 dynamic_symbols
= NULL
;
9403 num_dynamic_syms
= 0;
9406 if (dynamic_syminfo
)
9408 free (dynamic_syminfo
);
9409 dynamic_syminfo
= NULL
;
9412 if (section_headers_groups
)
9414 free (section_headers_groups
);
9415 section_headers_groups
= NULL
;
9420 struct group_list
*g
, *next
;
9422 for (i
= 0; i
< group_count
; i
++)
9424 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
9431 free (section_groups
);
9432 section_groups
= NULL
;
9435 free_debug_memory ();
9440 /* Process an ELF archive. The file is positioned just after the
9444 process_archive (char *file_name
, FILE *file
)
9446 struct ar_hdr arhdr
;
9449 char *longnames
= NULL
;
9450 unsigned long longnames_size
= 0;
9451 size_t file_name_size
;
9456 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9457 if (got
!= sizeof arhdr
)
9462 error (_("%s: failed to read archive header\n"), file_name
);
9466 if (const_strneq (arhdr
.ar_name
, "/ "))
9468 /* This is the archive symbol table. Skip it.
9469 FIXME: We should have an option to dump it. */
9470 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9471 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
9473 error (_("%s: failed to skip archive symbol table\n"), file_name
);
9477 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9478 if (got
!= sizeof arhdr
)
9483 error (_("%s: failed to read archive header\n"), file_name
);
9488 if (const_strneq (arhdr
.ar_name
, "// "))
9490 /* This is the archive string table holding long member
9493 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9495 longnames
= malloc (longnames_size
);
9496 if (longnames
== NULL
)
9498 error (_("Out of memory\n"));
9502 if (fread (longnames
, longnames_size
, 1, file
) != 1)
9505 error (_("%s: failed to read string table\n"), file_name
);
9509 if ((longnames_size
& 1) != 0)
9512 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9513 if (got
!= sizeof arhdr
)
9520 error (_("%s: failed to read archive header\n"), file_name
);
9525 file_name_size
= strlen (file_name
);
9534 if (arhdr
.ar_name
[0] == '/')
9538 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
9539 if (off
>= longnames_size
)
9541 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
9546 name
= longnames
+ off
;
9547 nameend
= memchr (name
, '/', longnames_size
- off
);
9551 name
= arhdr
.ar_name
;
9552 nameend
= memchr (name
, '/', 16);
9555 if (nameend
== NULL
)
9557 error (_("%s: bad archive file name\n"), file_name
);
9562 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
9563 if (namealc
== NULL
)
9565 error (_("Out of memory\n"));
9570 memcpy (namealc
, file_name
, file_name_size
);
9571 namealc
[file_name_size
] = '(';
9572 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
9573 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
9574 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
9576 archive_file_offset
= ftell (file
);
9577 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9579 ret
|= process_object (namealc
, file
);
9584 (archive_file_offset
9586 + (archive_file_size
& 1)),
9589 error (_("%s: failed to seek to next archive header\n"), file_name
);
9594 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9595 if (got
!= sizeof arhdr
)
9600 error (_("%s: failed to read archive header\n"), file_name
);
9613 process_file (char *file_name
)
9616 struct stat statbuf
;
9620 if (stat (file_name
, &statbuf
) < 0)
9622 if (errno
== ENOENT
)
9623 error (_("'%s': No such file\n"), file_name
);
9625 error (_("Could not locate '%s'. System error message: %s\n"),
9626 file_name
, strerror (errno
));
9630 if (! S_ISREG (statbuf
.st_mode
))
9632 error (_("'%s' is not an ordinary file\n"), file_name
);
9636 file
= fopen (file_name
, "rb");
9639 error (_("Input file '%s' is not readable.\n"), file_name
);
9643 if (fread (armag
, SARMAG
, 1, file
) != 1)
9645 error (_("%s: Failed to read file header\n"), file_name
);
9650 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
9651 ret
= process_archive (file_name
, file
);
9655 archive_file_size
= archive_file_offset
= 0;
9656 ret
= process_object (file_name
, file
);
9664 #ifdef SUPPORT_DISASSEMBLY
9665 /* Needed by the i386 disassembler. For extra credit, someone could
9666 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9670 print_address (unsigned int addr
, FILE *outfile
)
9672 fprintf (outfile
,"0x%8.8x", addr
);
9675 /* Needed by the i386 disassembler. */
9677 db_task_printsym (unsigned int addr
)
9679 print_address (addr
, stderr
);
9684 main (int argc
, char **argv
)
9688 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9689 setlocale (LC_MESSAGES
, "");
9691 #if defined (HAVE_SETLOCALE)
9692 setlocale (LC_CTYPE
, "");
9694 bindtextdomain (PACKAGE
, LOCALEDIR
);
9695 textdomain (PACKAGE
);
9697 expandargv (&argc
, &argv
);
9699 parse_args (argc
, argv
);
9701 if (num_dump_sects
> 0)
9703 /* Make a copy of the dump_sects array. */
9704 cmdline_dump_sects
= malloc (num_dump_sects
);
9705 if (cmdline_dump_sects
== NULL
)
9706 error (_("Out of memory allocating dump request table.\n"));
9709 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
9710 num_cmdline_dump_sects
= num_dump_sects
;
9714 if (optind
< (argc
- 1))
9718 while (optind
< argc
)
9719 err
|= process_file (argv
[optind
++]);
9721 if (dump_sects
!= NULL
)
9723 if (cmdline_dump_sects
!= NULL
)
9724 free (cmdline_dump_sects
);