1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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"
83 /* The following headers use the elf/reloc-macros.h file to
84 automatically generate relocation recognition functions
85 such as elf_mips_reloc_type() */
87 #define RELOC_MACROS_GEN_FUNC
89 #include "elf/alpha.h"
102 #include "elf/hppa.h"
103 #include "elf/i386.h"
104 #include "elf/i370.h"
105 #include "elf/i860.h"
106 #include "elf/i960.h"
107 #include "elf/ia64.h"
108 #include "elf/ip2k.h"
109 #include "elf/iq2000.h"
110 #include "elf/m32c.h"
111 #include "elf/m32r.h"
112 #include "elf/m68k.h"
113 #include "elf/m68hc11.h"
114 #include "elf/mcore.h"
116 #include "elf/mips.h"
117 #include "elf/mmix.h"
118 #include "elf/mn10200.h"
119 #include "elf/mn10300.h"
121 #include "elf/msp430.h"
122 #include "elf/or32.h"
125 #include "elf/ppc64.h"
126 #include "elf/s390.h"
127 #include "elf/score.h"
129 #include "elf/sparc.h"
131 #include "elf/v850.h"
133 #include "elf/x86-64.h"
134 #include "elf/xstormy16.h"
135 #include "elf/xtensa.h"
141 #include "libiberty.h"
143 char *program_name
= "readelf";
144 static long archive_file_offset
;
145 static unsigned long archive_file_size
;
146 static unsigned long dynamic_addr
;
147 static bfd_size_type dynamic_size
;
148 static unsigned int dynamic_nent
;
149 static char *dynamic_strings
;
150 static unsigned long dynamic_strings_length
;
151 static char *string_table
;
152 static unsigned long string_table_length
;
153 static unsigned long num_dynamic_syms
;
154 static Elf_Internal_Sym
*dynamic_symbols
;
155 static Elf_Internal_Syminfo
*dynamic_syminfo
;
156 static unsigned long dynamic_syminfo_offset
;
157 static unsigned int dynamic_syminfo_nent
;
158 static char program_interpreter
[PATH_MAX
];
159 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
160 static bfd_vma dynamic_info_DT_GNU_HASH
;
161 static bfd_vma version_info
[16];
162 static Elf_Internal_Ehdr elf_header
;
163 static Elf_Internal_Shdr
*section_headers
;
164 static Elf_Internal_Phdr
*program_headers
;
165 static Elf_Internal_Dyn
*dynamic_section
;
166 static Elf_Internal_Shdr
*symtab_shndx_hdr
;
167 static int show_name
;
168 static int do_dynamic
;
171 static int do_sections
;
172 static int do_section_groups
;
173 static int do_section_details
;
174 static int do_segments
;
175 static int do_unwind
;
176 static int do_using_dynamic
;
177 static int do_header
;
179 static int do_version
;
181 static int do_histogram
;
182 static int do_debugging
;
185 static int is_32bit_elf
;
189 struct group_list
*next
;
190 unsigned int section_index
;
195 struct group_list
*root
;
196 unsigned int group_index
;
199 static size_t group_count
;
200 static struct group
*section_groups
;
201 static struct group
**section_headers_groups
;
203 /* A linked list of the section names for which dumps were requested
205 struct dump_list_entry
209 struct dump_list_entry
*next
;
211 static struct dump_list_entry
*dump_sects_byname
;
213 /* A dynamic array of flags indicating for which sections a hex dump
214 has been requested (via the -x switch) and/or a disassembly dump
215 (via the -i switch). */
216 char *cmdline_dump_sects
= NULL
;
217 unsigned num_cmdline_dump_sects
= 0;
219 /* A dynamic array of flags indicating for which sections a dump of
220 some kind has been requested. It is reset on a per-object file
221 basis and then initialised from the cmdline_dump_sects array,
222 the results of interpreting the -w switch, and the
223 dump_sects_byname list. */
224 char *dump_sects
= NULL
;
225 unsigned int num_dump_sects
= 0;
227 #define HEX_DUMP (1 << 0)
228 #define DISASS_DUMP (1 << 1)
229 #define DEBUG_DUMP (1 << 2)
231 /* How to print a vma value. */
232 typedef enum print_mode
244 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
248 #define SECTION_NAME(X) \
249 ((X) == NULL ? "<none>" \
250 : string_table == NULL ? "<no-name>" \
251 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
252 : string_table + (X)->sh_name))
254 /* Given st_shndx I, map to section_headers index. */
255 #define SECTION_HEADER_INDEX(I) \
256 ((I) < SHN_LORESERVE \
258 : ((I) <= SHN_HIRESERVE \
260 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
262 /* Reverse of the above. */
263 #define SECTION_HEADER_NUM(N) \
264 ((N) < SHN_LORESERVE \
266 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
268 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
270 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
272 #define BYTE_GET(field) byte_get (field, sizeof (field))
274 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
276 #define GET_ELF_SYMBOLS(file, section) \
277 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
278 : get_64bit_elf_symbols (file, section))
280 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
281 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
282 already been called and verified that the string exists. */
283 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
285 /* This is just a bit of syntatic sugar. */
286 #define streq(a,b) (strcmp ((a), (b)) == 0)
287 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
288 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
291 get_data (void *var
, FILE *file
, long offset
, size_t size
, size_t nmemb
,
296 if (size
== 0 || nmemb
== 0)
299 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
301 error (_("Unable to seek to 0x%lx for %s\n"),
302 archive_file_offset
+ offset
, reason
);
309 /* Check for overflow. */
310 if (nmemb
< (~(size_t) 0 - 1) / size
)
311 /* + 1 so that we can '\0' terminate invalid string table sections. */
312 mvar
= malloc (size
* nmemb
+ 1);
316 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
317 (unsigned long)(size
* nmemb
), reason
);
321 ((char *) mvar
)[size
* nmemb
] = '\0';
324 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
326 error (_("Unable to read in 0x%lx bytes of %s\n"),
327 (unsigned long)(size
* nmemb
), reason
);
337 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
342 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
343 field
[6] = ((value
>> 24) >> 24) & 0xff;
344 field
[5] = ((value
>> 24) >> 16) & 0xff;
345 field
[4] = ((value
>> 24) >> 8) & 0xff;
348 field
[3] = (value
>> 24) & 0xff;
349 field
[2] = (value
>> 16) & 0xff;
352 field
[1] = (value
>> 8) & 0xff;
355 field
[0] = value
& 0xff;
359 error (_("Unhandled data length: %d\n"), size
);
364 #if defined BFD64 && !BFD_HOST_64BIT_LONG
366 print_dec_vma (bfd_vma vma
, int is_signed
)
372 if (is_signed
&& (bfd_signed_vma
) vma
< 0)
381 *bufp
++ = '0' + vma
% 10;
393 print_hex_vma (bfd_vma vma
)
401 char digit
= '0' + (vma
& 0x0f);
403 digit
+= 'a' - '0' - 10;
416 /* Print a VMA value. */
418 print_vma (bfd_vma vma
, print_mode mode
)
427 return printf ("0x%8.8lx", (unsigned long) vma
);
430 return printf ("%8.8lx", (unsigned long) vma
);
434 return printf ("%5ld", (long) vma
);
438 return printf ("0x%lx", (unsigned long) vma
);
441 return printf ("%lx", (unsigned long) vma
);
444 return printf ("%ld", (unsigned long) vma
);
447 return printf ("%lu", (unsigned long) vma
);
470 #if BFD_HOST_64BIT_LONG
471 return nc
+ printf ("%lx", vma
);
473 return nc
+ print_hex_vma (vma
);
477 #if BFD_HOST_64BIT_LONG
478 return printf ("%ld", vma
);
480 return print_dec_vma (vma
, 1);
484 #if BFD_HOST_64BIT_LONG
486 return printf ("%5ld", vma
);
488 return printf ("%#lx", vma
);
491 return printf ("%5ld", _bfd_int64_low (vma
));
493 return print_hex_vma (vma
);
497 #if BFD_HOST_64BIT_LONG
498 return printf ("%lu", vma
);
500 return print_dec_vma (vma
, 0);
508 /* Display a symbol on stdout. If do_wide is not true then
509 format the symbol to be at most WIDTH characters,
510 truncating as necessary. If WIDTH is negative then
511 format the string to be exactly - WIDTH characters,
512 truncating or padding as necessary. */
515 print_symbol (int width
, const char *symbol
)
518 printf ("%s", symbol
);
520 printf ("%-*.*s", width
, width
, symbol
);
522 printf ("%-.*s", width
, symbol
);
526 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
531 field
[7] = value
& 0xff;
532 field
[6] = (value
>> 8) & 0xff;
533 field
[5] = (value
>> 16) & 0xff;
534 field
[4] = (value
>> 24) & 0xff;
539 field
[3] = value
& 0xff;
540 field
[2] = (value
>> 8) & 0xff;
544 field
[1] = value
& 0xff;
548 field
[0] = value
& 0xff;
552 error (_("Unhandled data length: %d\n"), size
);
557 /* Return a pointer to section NAME, or NULL if no such section exists. */
559 static Elf_Internal_Shdr
*
560 find_section (const char *name
)
564 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
565 if (streq (SECTION_NAME (section_headers
+ i
), name
))
566 return section_headers
+ i
;
571 /* Guess the relocation size commonly used by the specific machines. */
574 guess_is_rela (unsigned long e_machine
)
578 /* Targets that use REL relocations. */
594 /* Targets that use RELA relocations. */
598 case EM_ALTERA_NIOS2
:
622 case EM_CYGNUS_MN10200
:
624 case EM_CYGNUS_MN10300
:
665 warn (_("Don't know about relocations on this machine architecture\n"));
671 slurp_rela_relocs (FILE *file
,
672 unsigned long rel_offset
,
673 unsigned long rel_size
,
674 Elf_Internal_Rela
**relasp
,
675 unsigned long *nrelasp
)
677 Elf_Internal_Rela
*relas
;
678 unsigned long nrelas
;
683 Elf32_External_Rela
*erelas
;
685 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
689 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
691 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
696 error (_("out of memory parsing relocs"));
700 for (i
= 0; i
< nrelas
; i
++)
702 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
703 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
704 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
711 Elf64_External_Rela
*erelas
;
713 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
717 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
719 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
724 error (_("out of memory parsing relocs"));
728 for (i
= 0; i
< nrelas
; i
++)
730 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
731 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
732 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
743 slurp_rel_relocs (FILE *file
,
744 unsigned long rel_offset
,
745 unsigned long rel_size
,
746 Elf_Internal_Rela
**relsp
,
747 unsigned long *nrelsp
)
749 Elf_Internal_Rela
*rels
;
755 Elf32_External_Rel
*erels
;
757 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
761 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
763 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
768 error (_("out of memory parsing relocs"));
772 for (i
= 0; i
< nrels
; i
++)
774 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
775 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
776 rels
[i
].r_addend
= 0;
783 Elf64_External_Rel
*erels
;
785 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
789 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
791 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
796 error (_("out of memory parsing relocs"));
800 for (i
= 0; i
< nrels
; i
++)
802 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
803 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
804 rels
[i
].r_addend
= 0;
814 /* Display the contents of the relocation data found at the specified
818 dump_relocations (FILE *file
,
819 unsigned long rel_offset
,
820 unsigned long rel_size
,
821 Elf_Internal_Sym
*symtab
,
824 unsigned long strtablen
,
828 Elf_Internal_Rela
*rels
;
831 if (is_rela
== UNKNOWN
)
832 is_rela
= guess_is_rela (elf_header
.e_machine
);
836 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
841 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
850 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
852 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
857 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
859 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
867 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
869 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
874 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
876 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
880 for (i
= 0; i
< rel_size
; i
++)
883 const char *rtype2
= NULL
;
884 const char *rtype3
= NULL
;
887 bfd_vma symtab_index
;
892 offset
= rels
[i
].r_offset
;
893 info
= rels
[i
].r_info
;
897 type
= ELF32_R_TYPE (info
);
898 symtab_index
= ELF32_R_SYM (info
);
902 /* The #ifdef BFD64 below is to prevent a compile time warning.
903 We know that if we do not have a 64 bit data type that we
904 will never execute this code anyway. */
906 if (elf_header
.e_machine
== EM_MIPS
)
908 /* In little-endian objects, r_info isn't really a 64-bit
909 little-endian value: it has a 32-bit little-endian
910 symbol index followed by four individual byte fields.
911 Reorder INFO accordingly. */
912 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
913 info
= (((info
& 0xffffffff) << 32)
914 | ((info
>> 56) & 0xff)
915 | ((info
>> 40) & 0xff00)
916 | ((info
>> 24) & 0xff0000)
917 | ((info
>> 8) & 0xff000000));
918 type
= ELF64_MIPS_R_TYPE (info
);
919 type2
= ELF64_MIPS_R_TYPE2 (info
);
920 type3
= ELF64_MIPS_R_TYPE3 (info
);
922 else if (elf_header
.e_machine
== EM_SPARCV9
)
923 type
= ELF64_R_TYPE_ID (info
);
925 type
= ELF64_R_TYPE (info
);
927 symtab_index
= ELF64_R_SYM (info
);
933 #ifdef _bfd_int64_low
934 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
936 printf ("%8.8lx %8.8lx ", offset
, info
);
941 #ifdef _bfd_int64_low
943 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
944 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
945 _bfd_int64_high (offset
),
946 _bfd_int64_low (offset
),
947 _bfd_int64_high (info
),
948 _bfd_int64_low (info
));
951 ? "%16.16lx %16.16lx "
952 : "%12.12lx %12.12lx ",
957 switch (elf_header
.e_machine
)
965 rtype
= elf_m32r_reloc_type (type
);
970 rtype
= elf_i386_reloc_type (type
);
975 rtype
= elf_m68hc11_reloc_type (type
);
979 rtype
= elf_m68k_reloc_type (type
);
983 rtype
= elf_i960_reloc_type (type
);
988 rtype
= elf_avr_reloc_type (type
);
995 rtype
= elf_sparc_reloc_type (type
);
999 rtype
= elf_spu_reloc_type (type
);
1003 case EM_CYGNUS_V850
:
1004 rtype
= v850_reloc_type (type
);
1008 case EM_CYGNUS_D10V
:
1009 rtype
= elf_d10v_reloc_type (type
);
1013 case EM_CYGNUS_D30V
:
1014 rtype
= elf_d30v_reloc_type (type
);
1018 rtype
= elf_dlx_reloc_type (type
);
1022 rtype
= elf_sh_reloc_type (type
);
1026 case EM_CYGNUS_MN10300
:
1027 rtype
= elf_mn10300_reloc_type (type
);
1031 case EM_CYGNUS_MN10200
:
1032 rtype
= elf_mn10200_reloc_type (type
);
1036 case EM_CYGNUS_FR30
:
1037 rtype
= elf_fr30_reloc_type (type
);
1041 rtype
= elf_frv_reloc_type (type
);
1045 rtype
= elf_mcore_reloc_type (type
);
1049 rtype
= elf_mmix_reloc_type (type
);
1054 rtype
= elf_msp430_reloc_type (type
);
1058 rtype
= elf_ppc_reloc_type (type
);
1062 rtype
= elf_ppc64_reloc_type (type
);
1066 case EM_MIPS_RS3_LE
:
1067 rtype
= elf_mips_reloc_type (type
);
1070 rtype2
= elf_mips_reloc_type (type2
);
1071 rtype3
= elf_mips_reloc_type (type3
);
1076 rtype
= elf_alpha_reloc_type (type
);
1080 rtype
= elf_arm_reloc_type (type
);
1084 rtype
= elf_arc_reloc_type (type
);
1088 rtype
= elf_hppa_reloc_type (type
);
1094 rtype
= elf_h8_reloc_type (type
);
1099 rtype
= elf_or32_reloc_type (type
);
1104 rtype
= elf_pj_reloc_type (type
);
1107 rtype
= elf_ia64_reloc_type (type
);
1111 rtype
= elf_cris_reloc_type (type
);
1115 rtype
= elf_i860_reloc_type (type
);
1119 rtype
= elf_x86_64_reloc_type (type
);
1123 rtype
= i370_reloc_type (type
);
1128 rtype
= elf_s390_reloc_type (type
);
1132 rtype
= elf_score_reloc_type (type
);
1136 rtype
= elf_xstormy16_reloc_type (type
);
1140 rtype
= elf_crx_reloc_type (type
);
1144 rtype
= elf_vax_reloc_type (type
);
1149 rtype
= elf_ip2k_reloc_type (type
);
1153 rtype
= elf_iq2000_reloc_type (type
);
1158 rtype
= elf_xtensa_reloc_type (type
);
1162 rtype
= elf_m32c_reloc_type (type
);
1166 rtype
= elf_mt_reloc_type (type
);
1170 rtype
= elf_bfin_reloc_type (type
);
1174 rtype
= elf_mep_reloc_type (type
);
1179 #ifdef _bfd_int64_low
1180 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1182 printf (_("unrecognized: %-7lx"), type
);
1185 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1187 if (elf_header
.e_machine
== EM_ALPHA
1189 && streq (rtype
, "R_ALPHA_LITUSE")
1192 switch (rels
[i
].r_addend
)
1194 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1195 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1196 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1197 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1198 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1199 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1200 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1201 default: rtype
= NULL
;
1204 printf (" (%s)", rtype
);
1208 printf (_("<unknown addend: %lx>"),
1209 (unsigned long) rels
[i
].r_addend
);
1212 else if (symtab_index
)
1214 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1215 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1218 Elf_Internal_Sym
*psym
;
1220 psym
= symtab
+ symtab_index
;
1223 print_vma (psym
->st_value
, LONG_HEX
);
1224 printf (is_32bit_elf
? " " : " ");
1226 if (psym
->st_name
== 0)
1228 const char *sec_name
= "<null>";
1231 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1233 bfd_vma sec_index
= (bfd_vma
) -1;
1235 if (psym
->st_shndx
< SHN_LORESERVE
)
1236 sec_index
= psym
->st_shndx
;
1237 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1238 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1241 if (sec_index
!= (bfd_vma
) -1)
1242 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1243 else if (psym
->st_shndx
== SHN_ABS
)
1245 else if (psym
->st_shndx
== SHN_COMMON
)
1246 sec_name
= "COMMON";
1247 else if (elf_header
.e_machine
== EM_MIPS
1248 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1249 sec_name
= "SCOMMON";
1250 else if (elf_header
.e_machine
== EM_MIPS
1251 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1252 sec_name
= "SUNDEF";
1253 else if (elf_header
.e_machine
== EM_X86_64
1254 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1255 sec_name
= "LARGE_COMMON";
1256 else if (elf_header
.e_machine
== EM_IA_64
1257 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1258 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1259 sec_name
= "ANSI_COM";
1262 sprintf (name_buf
, "<section 0x%x>",
1263 (unsigned int) psym
->st_shndx
);
1264 sec_name
= name_buf
;
1267 print_symbol (22, sec_name
);
1269 else if (strtab
== NULL
)
1270 printf (_("<string table index: %3ld>"), psym
->st_name
);
1271 else if (psym
->st_name
>= strtablen
)
1272 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1274 print_symbol (22, strtab
+ psym
->st_name
);
1277 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1282 printf ("%*c", is_32bit_elf
?
1283 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1284 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1287 if (elf_header
.e_machine
== EM_SPARCV9
1289 && streq (rtype
, "R_SPARC_OLO10"))
1290 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1294 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1296 printf (" Type2: ");
1299 #ifdef _bfd_int64_low
1300 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1302 printf (_("unrecognized: %-7lx"), type2
);
1305 printf ("%-17.17s", rtype2
);
1307 printf ("\n Type3: ");
1310 #ifdef _bfd_int64_low
1311 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1313 printf (_("unrecognized: %-7lx"), type3
);
1316 printf ("%-17.17s", rtype3
);
1328 get_mips_dynamic_type (unsigned long type
)
1332 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1333 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1334 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1335 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1336 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1337 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1338 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1339 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1340 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1341 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1342 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1343 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1344 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1345 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1346 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1347 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1348 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1349 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1350 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1351 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1352 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1353 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1354 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1355 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1356 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1357 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1358 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1359 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1360 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1361 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1362 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1363 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1364 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1365 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1366 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1367 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1368 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1369 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1370 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1371 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1372 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1373 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1374 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1381 get_sparc64_dynamic_type (unsigned long type
)
1385 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1392 get_ppc_dynamic_type (unsigned long type
)
1396 case DT_PPC_GOT
: return "PPC_GOT";
1403 get_ppc64_dynamic_type (unsigned long type
)
1407 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1408 case DT_PPC64_OPD
: return "PPC64_OPD";
1409 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1416 get_parisc_dynamic_type (unsigned long type
)
1420 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1421 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1422 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1423 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1424 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1425 case DT_HP_PREINIT
: return "HP_PREINIT";
1426 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1427 case DT_HP_NEEDED
: return "HP_NEEDED";
1428 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1429 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1430 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1431 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1432 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1433 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1434 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1435 case DT_HP_FILTERED
: return "HP_FILTERED";
1436 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1437 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1438 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1439 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1440 case DT_PLT
: return "PLT";
1441 case DT_PLT_SIZE
: return "PLT_SIZE";
1442 case DT_DLT
: return "DLT";
1443 case DT_DLT_SIZE
: return "DLT_SIZE";
1450 get_ia64_dynamic_type (unsigned long type
)
1454 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1461 get_alpha_dynamic_type (unsigned long type
)
1465 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1472 get_score_dynamic_type (unsigned long type
)
1476 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1477 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1478 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1479 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1480 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1481 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1489 get_dynamic_type (unsigned long type
)
1491 static char buff
[64];
1495 case DT_NULL
: return "NULL";
1496 case DT_NEEDED
: return "NEEDED";
1497 case DT_PLTRELSZ
: return "PLTRELSZ";
1498 case DT_PLTGOT
: return "PLTGOT";
1499 case DT_HASH
: return "HASH";
1500 case DT_STRTAB
: return "STRTAB";
1501 case DT_SYMTAB
: return "SYMTAB";
1502 case DT_RELA
: return "RELA";
1503 case DT_RELASZ
: return "RELASZ";
1504 case DT_RELAENT
: return "RELAENT";
1505 case DT_STRSZ
: return "STRSZ";
1506 case DT_SYMENT
: return "SYMENT";
1507 case DT_INIT
: return "INIT";
1508 case DT_FINI
: return "FINI";
1509 case DT_SONAME
: return "SONAME";
1510 case DT_RPATH
: return "RPATH";
1511 case DT_SYMBOLIC
: return "SYMBOLIC";
1512 case DT_REL
: return "REL";
1513 case DT_RELSZ
: return "RELSZ";
1514 case DT_RELENT
: return "RELENT";
1515 case DT_PLTREL
: return "PLTREL";
1516 case DT_DEBUG
: return "DEBUG";
1517 case DT_TEXTREL
: return "TEXTREL";
1518 case DT_JMPREL
: return "JMPREL";
1519 case DT_BIND_NOW
: return "BIND_NOW";
1520 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1521 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1522 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1523 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1524 case DT_RUNPATH
: return "RUNPATH";
1525 case DT_FLAGS
: return "FLAGS";
1527 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1528 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1530 case DT_CHECKSUM
: return "CHECKSUM";
1531 case DT_PLTPADSZ
: return "PLTPADSZ";
1532 case DT_MOVEENT
: return "MOVEENT";
1533 case DT_MOVESZ
: return "MOVESZ";
1534 case DT_FEATURE
: return "FEATURE";
1535 case DT_POSFLAG_1
: return "POSFLAG_1";
1536 case DT_SYMINSZ
: return "SYMINSZ";
1537 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1539 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1540 case DT_CONFIG
: return "CONFIG";
1541 case DT_DEPAUDIT
: return "DEPAUDIT";
1542 case DT_AUDIT
: return "AUDIT";
1543 case DT_PLTPAD
: return "PLTPAD";
1544 case DT_MOVETAB
: return "MOVETAB";
1545 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1547 case DT_VERSYM
: return "VERSYM";
1549 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1550 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1551 case DT_RELACOUNT
: return "RELACOUNT";
1552 case DT_RELCOUNT
: return "RELCOUNT";
1553 case DT_FLAGS_1
: return "FLAGS_1";
1554 case DT_VERDEF
: return "VERDEF";
1555 case DT_VERDEFNUM
: return "VERDEFNUM";
1556 case DT_VERNEED
: return "VERNEED";
1557 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1559 case DT_AUXILIARY
: return "AUXILIARY";
1560 case DT_USED
: return "USED";
1561 case DT_FILTER
: return "FILTER";
1563 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1564 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1565 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1566 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1567 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1568 case DT_GNU_HASH
: return "GNU_HASH";
1571 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1575 switch (elf_header
.e_machine
)
1578 case EM_MIPS_RS3_LE
:
1579 result
= get_mips_dynamic_type (type
);
1582 result
= get_sparc64_dynamic_type (type
);
1585 result
= get_ppc_dynamic_type (type
);
1588 result
= get_ppc64_dynamic_type (type
);
1591 result
= get_ia64_dynamic_type (type
);
1594 result
= get_alpha_dynamic_type (type
);
1597 result
= get_score_dynamic_type (type
);
1607 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1609 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1610 || (elf_header
.e_machine
== EM_PARISC
1611 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1615 switch (elf_header
.e_machine
)
1618 result
= get_parisc_dynamic_type (type
);
1628 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1632 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1639 get_file_type (unsigned e_type
)
1641 static char buff
[32];
1645 case ET_NONE
: return _("NONE (None)");
1646 case ET_REL
: return _("REL (Relocatable file)");
1647 case ET_EXEC
: return _("EXEC (Executable file)");
1648 case ET_DYN
: return _("DYN (Shared object file)");
1649 case ET_CORE
: return _("CORE (Core file)");
1652 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1653 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1654 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1655 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1657 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1663 get_machine_name (unsigned e_machine
)
1665 static char buff
[64]; /* XXX */
1669 case EM_NONE
: return _("None");
1670 case EM_M32
: return "WE32100";
1671 case EM_SPARC
: return "Sparc";
1672 case EM_SPU
: return "SPU";
1673 case EM_386
: return "Intel 80386";
1674 case EM_68K
: return "MC68000";
1675 case EM_88K
: return "MC88000";
1676 case EM_486
: return "Intel 80486";
1677 case EM_860
: return "Intel 80860";
1678 case EM_MIPS
: return "MIPS R3000";
1679 case EM_S370
: return "IBM System/370";
1680 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1681 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1682 case EM_PARISC
: return "HPPA";
1683 case EM_PPC_OLD
: return "Power PC (old)";
1684 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1685 case EM_960
: return "Intel 90860";
1686 case EM_PPC
: return "PowerPC";
1687 case EM_PPC64
: return "PowerPC64";
1688 case EM_V800
: return "NEC V800";
1689 case EM_FR20
: return "Fujitsu FR20";
1690 case EM_RH32
: return "TRW RH32";
1691 case EM_MCORE
: return "MCORE";
1692 case EM_ARM
: return "ARM";
1693 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1694 case EM_SH
: return "Renesas / SuperH SH";
1695 case EM_SPARCV9
: return "Sparc v9";
1696 case EM_TRICORE
: return "Siemens Tricore";
1697 case EM_ARC
: return "ARC";
1698 case EM_H8_300
: return "Renesas H8/300";
1699 case EM_H8_300H
: return "Renesas H8/300H";
1700 case EM_H8S
: return "Renesas H8S";
1701 case EM_H8_500
: return "Renesas H8/500";
1702 case EM_IA_64
: return "Intel IA-64";
1703 case EM_MIPS_X
: return "Stanford MIPS-X";
1704 case EM_COLDFIRE
: return "Motorola Coldfire";
1705 case EM_68HC12
: return "Motorola M68HC12";
1706 case EM_ALPHA
: return "Alpha";
1707 case EM_CYGNUS_D10V
:
1708 case EM_D10V
: return "d10v";
1709 case EM_CYGNUS_D30V
:
1710 case EM_D30V
: return "d30v";
1711 case EM_CYGNUS_M32R
:
1712 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1713 case EM_CYGNUS_V850
:
1714 case EM_V850
: return "NEC v850";
1715 case EM_CYGNUS_MN10300
:
1716 case EM_MN10300
: return "mn10300";
1717 case EM_CYGNUS_MN10200
:
1718 case EM_MN10200
: return "mn10200";
1719 case EM_CYGNUS_FR30
:
1720 case EM_FR30
: return "Fujitsu FR30";
1721 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1723 case EM_PJ
: return "picoJava";
1724 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1725 case EM_PCP
: return "Siemens PCP";
1726 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1727 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1728 case EM_STARCORE
: return "Motorola Star*Core processor";
1729 case EM_ME16
: return "Toyota ME16 processor";
1730 case EM_ST100
: return "STMicroelectronics ST100 processor";
1731 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1732 case EM_FX66
: return "Siemens FX66 microcontroller";
1733 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1734 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1735 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1736 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1737 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1738 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1739 case EM_SVX
: return "Silicon Graphics SVx";
1740 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1741 case EM_VAX
: return "Digital VAX";
1743 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1744 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1745 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1746 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1747 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1748 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1749 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1750 case EM_PRISM
: return "Vitesse Prism";
1751 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1753 case EM_S390
: return "IBM S/390";
1754 case EM_SCORE
: return "SUNPLUS S+Core";
1755 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1757 case EM_OR32
: return "OpenRISC";
1758 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1759 case EM_DLX
: return "OpenDLX";
1761 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1762 case EM_IQ2000
: return "Vitesse IQ2000";
1764 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1765 case EM_M32C
: return "Renesas M32c";
1766 case EM_MT
: return "Morpho Techologies MT processor";
1767 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1768 case EM_NIOS32
: return "Altera Nios";
1769 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1770 case EM_XC16X
: return "Infineon Technologies xc16x";
1771 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1773 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_machine
);
1779 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1784 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1785 e_flags
&= ~ EF_ARM_EABIMASK
;
1787 /* Handle "generic" ARM flags. */
1788 if (e_flags
& EF_ARM_RELEXEC
)
1790 strcat (buf
, ", relocatable executable");
1791 e_flags
&= ~ EF_ARM_RELEXEC
;
1794 if (e_flags
& EF_ARM_HASENTRY
)
1796 strcat (buf
, ", has entry point");
1797 e_flags
&= ~ EF_ARM_HASENTRY
;
1800 /* Now handle EABI specific flags. */
1804 strcat (buf
, ", <unrecognized EABI>");
1809 case EF_ARM_EABI_VER1
:
1810 strcat (buf
, ", Version1 EABI");
1815 /* Process flags one bit at a time. */
1816 flag
= e_flags
& - e_flags
;
1821 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1822 strcat (buf
, ", sorted symbol tables");
1832 case EF_ARM_EABI_VER2
:
1833 strcat (buf
, ", Version2 EABI");
1838 /* Process flags one bit at a time. */
1839 flag
= e_flags
& - e_flags
;
1844 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1845 strcat (buf
, ", sorted symbol tables");
1848 case EF_ARM_DYNSYMSUSESEGIDX
:
1849 strcat (buf
, ", dynamic symbols use segment index");
1852 case EF_ARM_MAPSYMSFIRST
:
1853 strcat (buf
, ", mapping symbols precede others");
1863 case EF_ARM_EABI_VER3
:
1864 strcat (buf
, ", Version3 EABI");
1867 case EF_ARM_EABI_VER4
:
1868 strcat (buf
, ", Version4 EABI");
1871 case EF_ARM_EABI_VER5
:
1872 strcat (buf
, ", Version5 EABI");
1878 /* Process flags one bit at a time. */
1879 flag
= e_flags
& - e_flags
;
1885 strcat (buf
, ", BE8");
1889 strcat (buf
, ", LE8");
1899 case EF_ARM_EABI_UNKNOWN
:
1900 strcat (buf
, ", GNU EABI");
1905 /* Process flags one bit at a time. */
1906 flag
= e_flags
& - e_flags
;
1911 case EF_ARM_INTERWORK
:
1912 strcat (buf
, ", interworking enabled");
1915 case EF_ARM_APCS_26
:
1916 strcat (buf
, ", uses APCS/26");
1919 case EF_ARM_APCS_FLOAT
:
1920 strcat (buf
, ", uses APCS/float");
1924 strcat (buf
, ", position independent");
1928 strcat (buf
, ", 8 bit structure alignment");
1931 case EF_ARM_NEW_ABI
:
1932 strcat (buf
, ", uses new ABI");
1935 case EF_ARM_OLD_ABI
:
1936 strcat (buf
, ", uses old ABI");
1939 case EF_ARM_SOFT_FLOAT
:
1940 strcat (buf
, ", software FP");
1943 case EF_ARM_VFP_FLOAT
:
1944 strcat (buf
, ", VFP");
1947 case EF_ARM_MAVERICK_FLOAT
:
1948 strcat (buf
, ", Maverick FP");
1959 strcat (buf
,", <unknown>");
1963 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1965 static char buf
[1024];
1977 decode_ARM_machine_flags (e_flags
, buf
);
1981 switch (e_flags
& EF_FRV_CPU_MASK
)
1983 case EF_FRV_CPU_GENERIC
:
1987 strcat (buf
, ", fr???");
1990 case EF_FRV_CPU_FR300
:
1991 strcat (buf
, ", fr300");
1994 case EF_FRV_CPU_FR400
:
1995 strcat (buf
, ", fr400");
1997 case EF_FRV_CPU_FR405
:
1998 strcat (buf
, ", fr405");
2001 case EF_FRV_CPU_FR450
:
2002 strcat (buf
, ", fr450");
2005 case EF_FRV_CPU_FR500
:
2006 strcat (buf
, ", fr500");
2008 case EF_FRV_CPU_FR550
:
2009 strcat (buf
, ", fr550");
2012 case EF_FRV_CPU_SIMPLE
:
2013 strcat (buf
, ", simple");
2015 case EF_FRV_CPU_TOMCAT
:
2016 strcat (buf
, ", tomcat");
2022 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2023 strcat (buf
, ", m68000");
2024 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2025 strcat (buf
, ", cpu32");
2026 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2027 strcat (buf
, ", fido_a");
2030 char const *isa
= _("unknown");
2031 char const *mac
= _("unknown mac");
2032 char const *additional
= NULL
;
2034 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2036 case EF_M68K_CF_ISA_A_NODIV
:
2038 additional
= ", nodiv";
2040 case EF_M68K_CF_ISA_A
:
2043 case EF_M68K_CF_ISA_A_PLUS
:
2046 case EF_M68K_CF_ISA_B_NOUSP
:
2048 additional
= ", nousp";
2050 case EF_M68K_CF_ISA_B
:
2054 strcat (buf
, ", cf, isa ");
2057 strcat (buf
, additional
);
2058 if (e_flags
& EF_M68K_CF_FLOAT
)
2059 strcat (buf
, ", float");
2060 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2065 case EF_M68K_CF_MAC
:
2068 case EF_M68K_CF_EMAC
:
2081 if (e_flags
& EF_PPC_EMB
)
2082 strcat (buf
, ", emb");
2084 if (e_flags
& EF_PPC_RELOCATABLE
)
2085 strcat (buf
, ", relocatable");
2087 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2088 strcat (buf
, ", relocatable-lib");
2092 case EM_CYGNUS_V850
:
2093 switch (e_flags
& EF_V850_ARCH
)
2096 strcat (buf
, ", v850e1");
2099 strcat (buf
, ", v850e");
2102 strcat (buf
, ", v850");
2105 strcat (buf
, ", unknown v850 architecture variant");
2111 case EM_CYGNUS_M32R
:
2112 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2113 strcat (buf
, ", m32r");
2117 case EM_MIPS_RS3_LE
:
2118 if (e_flags
& EF_MIPS_NOREORDER
)
2119 strcat (buf
, ", noreorder");
2121 if (e_flags
& EF_MIPS_PIC
)
2122 strcat (buf
, ", pic");
2124 if (e_flags
& EF_MIPS_CPIC
)
2125 strcat (buf
, ", cpic");
2127 if (e_flags
& EF_MIPS_UCODE
)
2128 strcat (buf
, ", ugen_reserved");
2130 if (e_flags
& EF_MIPS_ABI2
)
2131 strcat (buf
, ", abi2");
2133 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2134 strcat (buf
, ", odk first");
2136 if (e_flags
& EF_MIPS_32BITMODE
)
2137 strcat (buf
, ", 32bitmode");
2139 switch ((e_flags
& EF_MIPS_MACH
))
2141 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2142 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2143 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2144 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2145 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2146 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2147 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2148 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2149 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2150 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2152 /* We simply ignore the field in this case to avoid confusion:
2153 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2156 default: strcat (buf
, ", unknown CPU"); break;
2159 switch ((e_flags
& EF_MIPS_ABI
))
2161 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2162 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2163 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2164 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2166 /* We simply ignore the field in this case to avoid confusion:
2167 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2168 This means it is likely to be an o32 file, but not for
2171 default: strcat (buf
, ", unknown ABI"); break;
2174 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2175 strcat (buf
, ", mdmx");
2177 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2178 strcat (buf
, ", mips16");
2180 switch ((e_flags
& EF_MIPS_ARCH
))
2182 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2183 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2184 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2185 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2186 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2187 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2188 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2189 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2190 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2191 default: strcat (buf
, ", unknown ISA"); break;
2197 switch ((e_flags
& EF_SH_MACH_MASK
))
2199 case EF_SH1
: strcat (buf
, ", sh1"); break;
2200 case EF_SH2
: strcat (buf
, ", sh2"); break;
2201 case EF_SH3
: strcat (buf
, ", sh3"); break;
2202 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2203 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2204 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2205 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2206 case EF_SH4
: strcat (buf
, ", sh4"); break;
2207 case EF_SH5
: strcat (buf
, ", sh5"); break;
2208 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2209 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2210 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2211 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2212 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2213 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2214 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2215 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2216 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2217 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2218 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2219 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2220 default: strcat (buf
, ", unknown ISA"); break;
2226 if (e_flags
& EF_SPARC_32PLUS
)
2227 strcat (buf
, ", v8+");
2229 if (e_flags
& EF_SPARC_SUN_US1
)
2230 strcat (buf
, ", ultrasparcI");
2232 if (e_flags
& EF_SPARC_SUN_US3
)
2233 strcat (buf
, ", ultrasparcIII");
2235 if (e_flags
& EF_SPARC_HAL_R1
)
2236 strcat (buf
, ", halr1");
2238 if (e_flags
& EF_SPARC_LEDATA
)
2239 strcat (buf
, ", ledata");
2241 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2242 strcat (buf
, ", tso");
2244 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2245 strcat (buf
, ", pso");
2247 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2248 strcat (buf
, ", rmo");
2252 switch (e_flags
& EF_PARISC_ARCH
)
2254 case EFA_PARISC_1_0
:
2255 strcpy (buf
, ", PA-RISC 1.0");
2257 case EFA_PARISC_1_1
:
2258 strcpy (buf
, ", PA-RISC 1.1");
2260 case EFA_PARISC_2_0
:
2261 strcpy (buf
, ", PA-RISC 2.0");
2266 if (e_flags
& EF_PARISC_TRAPNIL
)
2267 strcat (buf
, ", trapnil");
2268 if (e_flags
& EF_PARISC_EXT
)
2269 strcat (buf
, ", ext");
2270 if (e_flags
& EF_PARISC_LSB
)
2271 strcat (buf
, ", lsb");
2272 if (e_flags
& EF_PARISC_WIDE
)
2273 strcat (buf
, ", wide");
2274 if (e_flags
& EF_PARISC_NO_KABP
)
2275 strcat (buf
, ", no kabp");
2276 if (e_flags
& EF_PARISC_LAZYSWAP
)
2277 strcat (buf
, ", lazyswap");
2282 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2283 strcat (buf
, ", new calling convention");
2285 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2286 strcat (buf
, ", gnu calling convention");
2290 if ((e_flags
& EF_IA_64_ABI64
))
2291 strcat (buf
, ", 64-bit");
2293 strcat (buf
, ", 32-bit");
2294 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2295 strcat (buf
, ", reduced fp model");
2296 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2297 strcat (buf
, ", no function descriptors, constant gp");
2298 else if ((e_flags
& EF_IA_64_CONS_GP
))
2299 strcat (buf
, ", constant gp");
2300 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2301 strcat (buf
, ", absolute");
2305 if ((e_flags
& EF_VAX_NONPIC
))
2306 strcat (buf
, ", non-PIC");
2307 if ((e_flags
& EF_VAX_DFLOAT
))
2308 strcat (buf
, ", D-Float");
2309 if ((e_flags
& EF_VAX_GFLOAT
))
2310 strcat (buf
, ", G-Float");
2319 get_osabi_name (unsigned int osabi
)
2321 static char buff
[32];
2325 case ELFOSABI_NONE
: return "UNIX - System V";
2326 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2327 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2328 case ELFOSABI_LINUX
: return "UNIX - Linux";
2329 case ELFOSABI_HURD
: return "GNU/Hurd";
2330 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2331 case ELFOSABI_AIX
: return "UNIX - AIX";
2332 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2333 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2334 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2335 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2336 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2337 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2338 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2339 case ELFOSABI_AROS
: return "Amiga Research OS";
2340 case ELFOSABI_STANDALONE
: return _("Standalone App");
2341 case ELFOSABI_ARM
: return "ARM";
2343 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2349 get_arm_segment_type (unsigned long type
)
2363 get_mips_segment_type (unsigned long type
)
2367 case PT_MIPS_REGINFO
:
2369 case PT_MIPS_RTPROC
:
2371 case PT_MIPS_OPTIONS
:
2381 get_parisc_segment_type (unsigned long type
)
2385 case PT_HP_TLS
: return "HP_TLS";
2386 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2387 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2388 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2389 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2390 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2391 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2392 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2393 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2394 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2395 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2396 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2397 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2398 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2399 case PT_HP_STACK
: return "HP_STACK";
2400 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2401 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2402 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2403 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2412 get_ia64_segment_type (unsigned long type
)
2416 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2417 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2418 case PT_HP_TLS
: return "HP_TLS";
2419 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2420 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2421 case PT_IA_64_HP_STACK
: return "HP_STACK";
2430 get_segment_type (unsigned long p_type
)
2432 static char buff
[32];
2436 case PT_NULL
: return "NULL";
2437 case PT_LOAD
: return "LOAD";
2438 case PT_DYNAMIC
: return "DYNAMIC";
2439 case PT_INTERP
: return "INTERP";
2440 case PT_NOTE
: return "NOTE";
2441 case PT_SHLIB
: return "SHLIB";
2442 case PT_PHDR
: return "PHDR";
2443 case PT_TLS
: return "TLS";
2445 case PT_GNU_EH_FRAME
:
2446 return "GNU_EH_FRAME";
2447 case PT_GNU_STACK
: return "GNU_STACK";
2448 case PT_GNU_RELRO
: return "GNU_RELRO";
2451 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2455 switch (elf_header
.e_machine
)
2458 result
= get_arm_segment_type (p_type
);
2461 case EM_MIPS_RS3_LE
:
2462 result
= get_mips_segment_type (p_type
);
2465 result
= get_parisc_segment_type (p_type
);
2468 result
= get_ia64_segment_type (p_type
);
2478 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2480 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2484 switch (elf_header
.e_machine
)
2487 result
= get_parisc_segment_type (p_type
);
2490 result
= get_ia64_segment_type (p_type
);
2500 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2503 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2510 get_mips_section_type_name (unsigned int sh_type
)
2514 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2515 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2516 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2517 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2518 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2519 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2520 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2521 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2522 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2523 case SHT_MIPS_RELD
: return "MIPS_RELD";
2524 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2525 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2526 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2527 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2528 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2529 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2530 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2531 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2532 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2533 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2534 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2535 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2536 case SHT_MIPS_LINE
: return "MIPS_LINE";
2537 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2538 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2539 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2540 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2541 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2542 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2543 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2544 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2545 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2546 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2547 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2548 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2549 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2550 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2551 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2552 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2560 get_parisc_section_type_name (unsigned int sh_type
)
2564 case SHT_PARISC_EXT
: return "PARISC_EXT";
2565 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2566 case SHT_PARISC_DOC
: return "PARISC_DOC";
2567 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2568 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2569 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2570 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2578 get_ia64_section_type_name (unsigned int sh_type
)
2580 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2581 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2582 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2586 case SHT_IA_64_EXT
: return "IA_64_EXT";
2587 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2588 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2596 get_x86_64_section_type_name (unsigned int sh_type
)
2600 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2608 get_arm_section_type_name (unsigned int sh_type
)
2614 case SHT_ARM_PREEMPTMAP
:
2615 return "ARM_PREEMPTMAP";
2616 case SHT_ARM_ATTRIBUTES
:
2617 return "ARM_ATTRIBUTES";
2625 get_section_type_name (unsigned int sh_type
)
2627 static char buff
[32];
2631 case SHT_NULL
: return "NULL";
2632 case SHT_PROGBITS
: return "PROGBITS";
2633 case SHT_SYMTAB
: return "SYMTAB";
2634 case SHT_STRTAB
: return "STRTAB";
2635 case SHT_RELA
: return "RELA";
2636 case SHT_HASH
: return "HASH";
2637 case SHT_DYNAMIC
: return "DYNAMIC";
2638 case SHT_NOTE
: return "NOTE";
2639 case SHT_NOBITS
: return "NOBITS";
2640 case SHT_REL
: return "REL";
2641 case SHT_SHLIB
: return "SHLIB";
2642 case SHT_DYNSYM
: return "DYNSYM";
2643 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2644 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2645 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2646 case SHT_GNU_HASH
: return "GNU_HASH";
2647 case SHT_GROUP
: return "GROUP";
2648 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2649 case SHT_GNU_verdef
: return "VERDEF";
2650 case SHT_GNU_verneed
: return "VERNEED";
2651 case SHT_GNU_versym
: return "VERSYM";
2652 case 0x6ffffff0: return "VERSYM";
2653 case 0x6ffffffc: return "VERDEF";
2654 case 0x7ffffffd: return "AUXILIARY";
2655 case 0x7fffffff: return "FILTER";
2656 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2659 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2663 switch (elf_header
.e_machine
)
2666 case EM_MIPS_RS3_LE
:
2667 result
= get_mips_section_type_name (sh_type
);
2670 result
= get_parisc_section_type_name (sh_type
);
2673 result
= get_ia64_section_type_name (sh_type
);
2676 result
= get_x86_64_section_type_name (sh_type
);
2679 result
= get_arm_section_type_name (sh_type
);
2689 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2691 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2692 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2693 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2694 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2696 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2702 #define OPTION_DEBUG_DUMP 512
2704 static struct option options
[] =
2706 {"all", no_argument
, 0, 'a'},
2707 {"file-header", no_argument
, 0, 'h'},
2708 {"program-headers", no_argument
, 0, 'l'},
2709 {"headers", no_argument
, 0, 'e'},
2710 {"histogram", no_argument
, 0, 'I'},
2711 {"segments", no_argument
, 0, 'l'},
2712 {"sections", no_argument
, 0, 'S'},
2713 {"section-headers", no_argument
, 0, 'S'},
2714 {"section-groups", no_argument
, 0, 'g'},
2715 {"section-details", no_argument
, 0, 't'},
2716 {"full-section-name",no_argument
, 0, 'N'},
2717 {"symbols", no_argument
, 0, 's'},
2718 {"syms", no_argument
, 0, 's'},
2719 {"relocs", no_argument
, 0, 'r'},
2720 {"notes", no_argument
, 0, 'n'},
2721 {"dynamic", no_argument
, 0, 'd'},
2722 {"arch-specific", no_argument
, 0, 'A'},
2723 {"version-info", no_argument
, 0, 'V'},
2724 {"use-dynamic", no_argument
, 0, 'D'},
2725 {"hex-dump", required_argument
, 0, 'x'},
2726 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2727 {"unwind", no_argument
, 0, 'u'},
2728 #ifdef SUPPORT_DISASSEMBLY
2729 {"instruction-dump", required_argument
, 0, 'i'},
2732 {"version", no_argument
, 0, 'v'},
2733 {"wide", no_argument
, 0, 'W'},
2734 {"help", no_argument
, 0, 'H'},
2735 {0, no_argument
, 0, 0}
2741 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2742 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2743 fprintf (stdout
, _(" Options are:\n\
2744 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2745 -h --file-header Display the ELF file header\n\
2746 -l --program-headers Display the program headers\n\
2747 --segments An alias for --program-headers\n\
2748 -S --section-headers Display the sections' header\n\
2749 --sections An alias for --section-headers\n\
2750 -g --section-groups Display the section groups\n\
2751 -t --section-details Display the section details\n\
2752 -e --headers Equivalent to: -h -l -S\n\
2753 -s --syms Display the symbol table\n\
2754 --symbols An alias for --syms\n\
2755 -n --notes Display the core notes (if present)\n\
2756 -r --relocs Display the relocations (if present)\n\
2757 -u --unwind Display the unwind info (if present)\n\
2758 -d --dynamic Display the dynamic section (if present)\n\
2759 -V --version-info Display the version sections (if present)\n\
2760 -A --arch-specific Display architecture specific information (if any).\n\
2761 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2762 -x --hex-dump=<number> Dump the contents of section <number>\n\
2763 -w[liaprmfFsoR] or\n\
2764 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2765 Display the contents of DWARF2 debug sections\n"));
2766 #ifdef SUPPORT_DISASSEMBLY
2767 fprintf (stdout
, _("\
2768 -i --instruction-dump=<number>\n\
2769 Disassemble the contents of section <number>\n"));
2771 fprintf (stdout
, _("\
2772 -I --histogram Display histogram of bucket list lengths\n\
2773 -W --wide Allow output width to exceed 80 characters\n\
2774 @<file> Read options from <file>\n\
2775 -H --help Display this information\n\
2776 -v --version Display the version number of readelf\n"));
2777 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2782 /* Record the fact that the user wants the contents of section number
2783 SECTION to be displayed using the method(s) encoded as flags bits
2784 in TYPE. Note, TYPE can be zero if we are creating the array for
2788 request_dump (unsigned int section
, int type
)
2790 if (section
>= num_dump_sects
)
2792 char *new_dump_sects
;
2794 new_dump_sects
= calloc (section
+ 1, 1);
2796 if (new_dump_sects
== NULL
)
2797 error (_("Out of memory allocating dump request table."));
2800 /* Copy current flag settings. */
2801 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2805 dump_sects
= new_dump_sects
;
2806 num_dump_sects
= section
+ 1;
2811 dump_sects
[section
] |= type
;
2816 /* Request a dump by section name. */
2819 request_dump_byname (const char *section
, int type
)
2821 struct dump_list_entry
*new_request
;
2823 new_request
= malloc (sizeof (struct dump_list_entry
));
2825 error (_("Out of memory allocating dump request table."));
2827 new_request
->name
= strdup (section
);
2828 if (!new_request
->name
)
2829 error (_("Out of memory allocating dump request table."));
2831 new_request
->type
= type
;
2833 new_request
->next
= dump_sects_byname
;
2834 dump_sects_byname
= new_request
;
2838 parse_args (int argc
, char **argv
)
2845 while ((c
= getopt_long
2846 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWH", options
, NULL
)) != EOF
)
2867 do_section_groups
++;
2875 do_section_groups
++;
2880 do_section_details
++;
2922 section
= strtoul (optarg
, & cp
, 0);
2923 if (! *cp
&& section
>= 0)
2924 request_dump (section
, HEX_DUMP
);
2926 request_dump_byname (optarg
, HEX_DUMP
);
2934 unsigned int index
= 0;
2938 while (optarg
[index
])
2939 switch (optarg
[index
++])
2948 do_debug_abbrevs
= 1;
2958 do_debug_pubnames
= 1;
2962 do_debug_aranges
= 1;
2966 do_debug_ranges
= 1;
2970 do_debug_frames_interp
= 1;
2972 do_debug_frames
= 1;
2977 do_debug_macinfo
= 1;
2991 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2996 case OPTION_DEBUG_DUMP
:
3004 const char * option
;
3007 debug_dump_long_opts
;
3009 debug_dump_long_opts opts_table
[] =
3011 /* Please keep this table alpha- sorted. */
3012 { "Ranges", & do_debug_ranges
},
3013 { "abbrev", & do_debug_abbrevs
},
3014 { "aranges", & do_debug_aranges
},
3015 { "frames", & do_debug_frames
},
3016 { "frames-interp", & do_debug_frames_interp
},
3017 { "info", & do_debug_info
},
3018 { "line", & do_debug_lines
},
3019 { "loc", & do_debug_loc
},
3020 { "macro", & do_debug_macinfo
},
3021 { "pubnames", & do_debug_pubnames
},
3022 /* This entry is for compatability
3023 with earlier versions of readelf. */
3024 { "ranges", & do_debug_aranges
},
3025 { "str", & do_debug_str
},
3036 debug_dump_long_opts
* entry
;
3038 for (entry
= opts_table
; entry
->option
; entry
++)
3040 size_t len
= strlen (entry
->option
);
3042 if (strneq (p
, entry
->option
, len
)
3043 && (p
[len
] == ',' || p
[len
] == '\0'))
3045 * entry
->variable
= 1;
3047 /* The --debug-dump=frames-interp option also
3048 enables the --debug-dump=frames option. */
3049 if (do_debug_frames_interp
)
3050 do_debug_frames
= 1;
3057 if (entry
->option
== NULL
)
3059 warn (_("Unrecognized debug option '%s'\n"), p
);
3060 p
= strchr (p
, ',');
3070 #ifdef SUPPORT_DISASSEMBLY
3073 section
= strtoul (optarg
, & cp
, 0);
3074 if (! *cp
&& section
>= 0)
3076 request_dump (section
, DISASS_DUMP
);
3082 print_version (program_name
);
3091 #ifdef SUPPORT_DISASSEMBLY
3094 /* xgettext:c-format */
3095 error (_("Invalid option '-%c'\n"), c
);
3102 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3103 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3104 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3105 && !do_section_groups
)
3109 warn (_("Nothing to do.\n"));
3115 get_elf_class (unsigned int elf_class
)
3117 static char buff
[32];
3121 case ELFCLASSNONE
: return _("none");
3122 case ELFCLASS32
: return "ELF32";
3123 case ELFCLASS64
: return "ELF64";
3125 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3131 get_data_encoding (unsigned int encoding
)
3133 static char buff
[32];
3137 case ELFDATANONE
: return _("none");
3138 case ELFDATA2LSB
: return _("2's complement, little endian");
3139 case ELFDATA2MSB
: return _("2's complement, big endian");
3141 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3146 /* Decode the data held in 'elf_header'. */
3149 process_file_header (void)
3151 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3152 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3153 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3154 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3157 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3165 printf (_("ELF Header:\n"));
3166 printf (_(" Magic: "));
3167 for (i
= 0; i
< EI_NIDENT
; i
++)
3168 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3170 printf (_(" Class: %s\n"),
3171 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3172 printf (_(" Data: %s\n"),
3173 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3174 printf (_(" Version: %d %s\n"),
3175 elf_header
.e_ident
[EI_VERSION
],
3176 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3178 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3181 printf (_(" OS/ABI: %s\n"),
3182 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3183 printf (_(" ABI Version: %d\n"),
3184 elf_header
.e_ident
[EI_ABIVERSION
]);
3185 printf (_(" Type: %s\n"),
3186 get_file_type (elf_header
.e_type
));
3187 printf (_(" Machine: %s\n"),
3188 get_machine_name (elf_header
.e_machine
));
3189 printf (_(" Version: 0x%lx\n"),
3190 (unsigned long) elf_header
.e_version
);
3192 printf (_(" Entry point address: "));
3193 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3194 printf (_("\n Start of program headers: "));
3195 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3196 printf (_(" (bytes into file)\n Start of section headers: "));
3197 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3198 printf (_(" (bytes into file)\n"));
3200 printf (_(" Flags: 0x%lx%s\n"),
3201 (unsigned long) elf_header
.e_flags
,
3202 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3203 printf (_(" Size of this header: %ld (bytes)\n"),
3204 (long) elf_header
.e_ehsize
);
3205 printf (_(" Size of program headers: %ld (bytes)\n"),
3206 (long) elf_header
.e_phentsize
);
3207 printf (_(" Number of program headers: %ld\n"),
3208 (long) elf_header
.e_phnum
);
3209 printf (_(" Size of section headers: %ld (bytes)\n"),
3210 (long) elf_header
.e_shentsize
);
3211 printf (_(" Number of section headers: %ld"),
3212 (long) elf_header
.e_shnum
);
3213 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3214 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3215 putc ('\n', stdout
);
3216 printf (_(" Section header string table index: %ld"),
3217 (long) elf_header
.e_shstrndx
);
3218 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3219 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3220 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3221 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3222 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3223 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3224 printf (" <corrupt: out of range>");
3225 putc ('\n', stdout
);
3228 if (section_headers
!= NULL
)
3230 if (elf_header
.e_shnum
== 0)
3231 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3232 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3233 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3234 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3235 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3236 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3237 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3238 elf_header
.e_shstrndx
= SHN_UNDEF
;
3239 free (section_headers
);
3240 section_headers
= NULL
;
3248 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3250 Elf32_External_Phdr
*phdrs
;
3251 Elf32_External_Phdr
*external
;
3252 Elf_Internal_Phdr
*internal
;
3255 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3256 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3257 _("program headers"));
3261 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3262 i
< elf_header
.e_phnum
;
3263 i
++, internal
++, external
++)
3265 internal
->p_type
= BYTE_GET (external
->p_type
);
3266 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3267 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3268 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3269 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3270 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3271 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3272 internal
->p_align
= BYTE_GET (external
->p_align
);
3281 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3283 Elf64_External_Phdr
*phdrs
;
3284 Elf64_External_Phdr
*external
;
3285 Elf_Internal_Phdr
*internal
;
3288 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3289 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3290 _("program headers"));
3294 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3295 i
< elf_header
.e_phnum
;
3296 i
++, internal
++, external
++)
3298 internal
->p_type
= BYTE_GET (external
->p_type
);
3299 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3300 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3301 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3302 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3303 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3304 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3305 internal
->p_align
= BYTE_GET (external
->p_align
);
3313 /* Returns 1 if the program headers were read into `program_headers'. */
3316 get_program_headers (FILE *file
)
3318 Elf_Internal_Phdr
*phdrs
;
3320 /* Check cache of prior read. */
3321 if (program_headers
!= NULL
)
3324 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3328 error (_("Out of memory\n"));
3333 ? get_32bit_program_headers (file
, phdrs
)
3334 : get_64bit_program_headers (file
, phdrs
))
3336 program_headers
= phdrs
;
3344 /* Returns 1 if the program headers were loaded. */
3347 process_program_headers (FILE *file
)
3349 Elf_Internal_Phdr
*segment
;
3352 if (elf_header
.e_phnum
== 0)
3355 printf (_("\nThere are no program headers in this file.\n"));
3359 if (do_segments
&& !do_header
)
3361 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3362 printf (_("Entry point "));
3363 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3364 printf (_("\nThere are %d program headers, starting at offset "),
3365 elf_header
.e_phnum
);
3366 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3370 if (! get_program_headers (file
))
3375 if (elf_header
.e_phnum
> 1)
3376 printf (_("\nProgram Headers:\n"));
3378 printf (_("\nProgram Headers:\n"));
3382 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3385 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3389 (_(" Type Offset VirtAddr PhysAddr\n"));
3391 (_(" FileSiz MemSiz Flags Align\n"));
3398 for (i
= 0, segment
= program_headers
;
3399 i
< elf_header
.e_phnum
;
3404 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3408 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3409 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3410 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3411 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3412 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3414 (segment
->p_flags
& PF_R
? 'R' : ' '),
3415 (segment
->p_flags
& PF_W
? 'W' : ' '),
3416 (segment
->p_flags
& PF_X
? 'E' : ' '));
3417 printf ("%#lx", (unsigned long) segment
->p_align
);
3421 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3422 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3425 print_vma (segment
->p_offset
, FULL_HEX
);
3429 print_vma (segment
->p_vaddr
, FULL_HEX
);
3431 print_vma (segment
->p_paddr
, FULL_HEX
);
3434 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3435 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3438 print_vma (segment
->p_filesz
, FULL_HEX
);
3442 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3443 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3446 print_vma (segment
->p_offset
, FULL_HEX
);
3450 (segment
->p_flags
& PF_R
? 'R' : ' '),
3451 (segment
->p_flags
& PF_W
? 'W' : ' '),
3452 (segment
->p_flags
& PF_X
? 'E' : ' '));
3454 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3455 printf ("%#lx", (unsigned long) segment
->p_align
);
3458 print_vma (segment
->p_align
, PREFIX_HEX
);
3463 print_vma (segment
->p_offset
, FULL_HEX
);
3465 print_vma (segment
->p_vaddr
, FULL_HEX
);
3467 print_vma (segment
->p_paddr
, FULL_HEX
);
3469 print_vma (segment
->p_filesz
, FULL_HEX
);
3471 print_vma (segment
->p_memsz
, FULL_HEX
);
3473 (segment
->p_flags
& PF_R
? 'R' : ' '),
3474 (segment
->p_flags
& PF_W
? 'W' : ' '),
3475 (segment
->p_flags
& PF_X
? 'E' : ' '));
3476 print_vma (segment
->p_align
, HEX
);
3480 switch (segment
->p_type
)
3484 error (_("more than one dynamic segment\n"));
3486 /* Try to locate the .dynamic section. If there is
3487 a section header table, we can easily locate it. */
3488 if (section_headers
!= NULL
)
3490 Elf_Internal_Shdr
*sec
;
3492 sec
= find_section (".dynamic");
3493 if (sec
== NULL
|| sec
->sh_size
== 0)
3495 error (_("no .dynamic section in the dynamic segment"));
3499 dynamic_addr
= sec
->sh_offset
;
3500 dynamic_size
= sec
->sh_size
;
3502 if (dynamic_addr
< segment
->p_offset
3503 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3504 warn (_("the .dynamic section is not contained within the dynamic segment"));
3505 else if (dynamic_addr
> segment
->p_offset
)
3506 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3510 /* Otherwise, we can only assume that the .dynamic
3511 section is the first section in the DYNAMIC segment. */
3512 dynamic_addr
= segment
->p_offset
;
3513 dynamic_size
= segment
->p_filesz
;
3518 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3520 error (_("Unable to find program interpreter name\n"));
3524 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3526 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3527 error (_("Internal error: failed to create format string to display program interpreter"));
3529 program_interpreter
[0] = 0;
3530 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3531 error (_("Unable to read program interpreter name\n"));
3534 printf (_("\n [Requesting program interpreter: %s]"),
3535 program_interpreter
);
3541 putc ('\n', stdout
);
3544 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3546 printf (_("\n Section to Segment mapping:\n"));
3547 printf (_(" Segment Sections...\n"));
3549 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3552 Elf_Internal_Shdr
*section
;
3554 segment
= program_headers
+ i
;
3555 section
= section_headers
;
3557 printf (" %2.2d ", i
);
3559 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3561 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section
, segment
))
3562 printf ("%s ", SECTION_NAME (section
));
3573 /* Find the file offset corresponding to VMA by using the program headers. */
3576 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3578 Elf_Internal_Phdr
*seg
;
3580 if (! get_program_headers (file
))
3582 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3586 for (seg
= program_headers
;
3587 seg
< program_headers
+ elf_header
.e_phnum
;
3590 if (seg
->p_type
!= PT_LOAD
)
3593 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3594 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3595 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3598 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3605 get_32bit_section_headers (FILE *file
, unsigned int num
)
3607 Elf32_External_Shdr
*shdrs
;
3608 Elf_Internal_Shdr
*internal
;
3611 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3612 elf_header
.e_shentsize
, num
, _("section headers"));
3616 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3618 if (section_headers
== NULL
)
3620 error (_("Out of memory\n"));
3624 for (i
= 0, internal
= section_headers
;
3628 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3629 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3630 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3631 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3632 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3633 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3634 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3635 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3636 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3637 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3646 get_64bit_section_headers (FILE *file
, unsigned int num
)
3648 Elf64_External_Shdr
*shdrs
;
3649 Elf_Internal_Shdr
*internal
;
3652 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3653 elf_header
.e_shentsize
, num
, _("section headers"));
3657 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3659 if (section_headers
== NULL
)
3661 error (_("Out of memory\n"));
3665 for (i
= 0, internal
= section_headers
;
3669 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3670 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3671 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3672 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3673 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3674 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3675 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3676 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3677 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3678 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3686 static Elf_Internal_Sym
*
3687 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3689 unsigned long number
;
3690 Elf32_External_Sym
*esyms
;
3691 Elf_External_Sym_Shndx
*shndx
;
3692 Elf_Internal_Sym
*isyms
;
3693 Elf_Internal_Sym
*psym
;
3696 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3702 if (symtab_shndx_hdr
!= NULL
3703 && (symtab_shndx_hdr
->sh_link
3704 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3706 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3707 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3715 number
= section
->sh_size
/ section
->sh_entsize
;
3716 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3720 error (_("Out of memory\n"));
3727 for (j
= 0, psym
= isyms
;
3731 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3732 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3733 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3734 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3735 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3737 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3738 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3739 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3749 static Elf_Internal_Sym
*
3750 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3752 unsigned long number
;
3753 Elf64_External_Sym
*esyms
;
3754 Elf_External_Sym_Shndx
*shndx
;
3755 Elf_Internal_Sym
*isyms
;
3756 Elf_Internal_Sym
*psym
;
3759 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3765 if (symtab_shndx_hdr
!= NULL
3766 && (symtab_shndx_hdr
->sh_link
3767 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3769 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3770 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3778 number
= section
->sh_size
/ section
->sh_entsize
;
3779 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3783 error (_("Out of memory\n"));
3790 for (j
= 0, psym
= isyms
;
3794 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3795 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3796 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3797 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3798 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3800 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3801 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3802 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3813 get_elf_section_flags (bfd_vma sh_flags
)
3815 static char buff
[1024];
3817 int field_size
= is_32bit_elf
? 8 : 16;
3818 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3819 bfd_vma os_flags
= 0;
3820 bfd_vma proc_flags
= 0;
3821 bfd_vma unknown_flags
= 0;
3835 { "LINK ORDER", 10 },
3836 { "OS NONCONF", 10 },
3841 if (do_section_details
)
3843 sprintf (buff
, "[%*.*lx]: ",
3844 field_size
, field_size
, (unsigned long) sh_flags
);
3845 p
+= field_size
+ 4;
3852 flag
= sh_flags
& - sh_flags
;
3855 if (do_section_details
)
3859 case SHF_WRITE
: index
= 0; break;
3860 case SHF_ALLOC
: index
= 1; break;
3861 case SHF_EXECINSTR
: index
= 2; break;
3862 case SHF_MERGE
: index
= 3; break;
3863 case SHF_STRINGS
: index
= 4; break;
3864 case SHF_INFO_LINK
: index
= 5; break;
3865 case SHF_LINK_ORDER
: index
= 6; break;
3866 case SHF_OS_NONCONFORMING
: index
= 7; break;
3867 case SHF_GROUP
: index
= 8; break;
3868 case SHF_TLS
: index
= 9; break;
3877 if (p
!= buff
+ field_size
+ 4)
3879 if (size
< (10 + 2))
3886 size
-= flags
[index
].len
;
3887 p
= stpcpy (p
, flags
[index
].str
);
3889 else if (flag
& SHF_MASKOS
)
3891 else if (flag
& SHF_MASKPROC
)
3894 unknown_flags
|= flag
;
3900 case SHF_WRITE
: *p
= 'W'; break;
3901 case SHF_ALLOC
: *p
= 'A'; break;
3902 case SHF_EXECINSTR
: *p
= 'X'; break;
3903 case SHF_MERGE
: *p
= 'M'; break;
3904 case SHF_STRINGS
: *p
= 'S'; break;
3905 case SHF_INFO_LINK
: *p
= 'I'; break;
3906 case SHF_LINK_ORDER
: *p
= 'L'; break;
3907 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3908 case SHF_GROUP
: *p
= 'G'; break;
3909 case SHF_TLS
: *p
= 'T'; break;
3912 if (elf_header
.e_machine
== EM_X86_64
3913 && flag
== SHF_X86_64_LARGE
)
3915 else if (flag
& SHF_MASKOS
)
3918 sh_flags
&= ~ SHF_MASKOS
;
3920 else if (flag
& SHF_MASKPROC
)
3923 sh_flags
&= ~ SHF_MASKPROC
;
3933 if (do_section_details
)
3937 size
-= 5 + field_size
;
3938 if (p
!= buff
+ field_size
+ 4)
3946 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3947 (unsigned long) os_flags
);
3948 p
+= 5 + field_size
;
3952 size
-= 7 + field_size
;
3953 if (p
!= buff
+ field_size
+ 4)
3961 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
3962 (unsigned long) proc_flags
);
3963 p
+= 7 + field_size
;
3967 size
-= 10 + field_size
;
3968 if (p
!= buff
+ field_size
+ 4)
3976 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
3977 (unsigned long) unknown_flags
);
3978 p
+= 10 + field_size
;
3987 process_section_headers (FILE *file
)
3989 Elf_Internal_Shdr
*section
;
3992 section_headers
= NULL
;
3994 if (elf_header
.e_shnum
== 0)
3997 printf (_("\nThere are no sections in this file.\n"));
4002 if (do_sections
&& !do_header
)
4003 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4004 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4008 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4011 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4014 /* Read in the string table, so that we have names to display. */
4015 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4016 && SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
4018 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
4020 if (section
->sh_size
!= 0)
4022 string_table
= get_data (NULL
, file
, section
->sh_offset
,
4023 1, section
->sh_size
, _("string table"));
4025 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4029 /* Scan the sections for the dynamic symbol table
4030 and dynamic string table and debug sections. */
4031 dynamic_symbols
= NULL
;
4032 dynamic_strings
= NULL
;
4033 dynamic_syminfo
= NULL
;
4034 symtab_shndx_hdr
= NULL
;
4036 eh_addr_size
= is_32bit_elf
? 4 : 8;
4037 switch (elf_header
.e_machine
)
4040 case EM_MIPS_RS3_LE
:
4041 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4042 FDE addresses. However, the ABI also has a semi-official ILP32
4043 variant for which the normal FDE address size rules apply.
4045 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4046 section, where XX is the size of longs in bits. Unfortunately,
4047 earlier compilers provided no way of distinguishing ILP32 objects
4048 from LP64 objects, so if there's any doubt, we should assume that
4049 the official LP64 form is being used. */
4050 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4051 && find_section (".gcc_compiled_long32") == NULL
)
4057 switch (elf_header
.e_flags
& EF_H8_MACH
)
4059 case E_H8_MACH_H8300
:
4060 case E_H8_MACH_H8300HN
:
4061 case E_H8_MACH_H8300SN
:
4062 case E_H8_MACH_H8300SXN
:
4065 case E_H8_MACH_H8300H
:
4066 case E_H8_MACH_H8300S
:
4067 case E_H8_MACH_H8300SX
:
4073 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4076 size_t expected_entsize \
4077 = is_32bit_elf ? size32 : size64; \
4078 if (section->sh_entsize != expected_entsize) \
4079 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4080 i, (unsigned long int) section->sh_entsize, \
4081 (unsigned long int) expected_entsize); \
4082 section->sh_entsize = expected_entsize; \
4085 #define CHECK_ENTSIZE(section, i, type) \
4086 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4087 sizeof (Elf64_External_##type))
4089 for (i
= 0, section
= section_headers
;
4090 i
< elf_header
.e_shnum
;
4093 char *name
= SECTION_NAME (section
);
4095 if (section
->sh_type
== SHT_DYNSYM
)
4097 if (dynamic_symbols
!= NULL
)
4099 error (_("File contains multiple dynamic symbol tables\n"));
4103 CHECK_ENTSIZE (section
, i
, Sym
);
4104 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4105 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4107 else if (section
->sh_type
== SHT_STRTAB
4108 && streq (name
, ".dynstr"))
4110 if (dynamic_strings
!= NULL
)
4112 error (_("File contains multiple dynamic string tables\n"));
4116 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
4117 1, section
->sh_size
, _("dynamic strings"));
4118 dynamic_strings_length
= section
->sh_size
;
4120 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4122 if (symtab_shndx_hdr
!= NULL
)
4124 error (_("File contains multiple symtab shndx tables\n"));
4127 symtab_shndx_hdr
= section
;
4129 else if (section
->sh_type
== SHT_SYMTAB
)
4130 CHECK_ENTSIZE (section
, i
, Sym
);
4131 else if (section
->sh_type
== SHT_GROUP
)
4132 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4133 else if (section
->sh_type
== SHT_REL
)
4134 CHECK_ENTSIZE (section
, i
, Rel
);
4135 else if (section
->sh_type
== SHT_RELA
)
4136 CHECK_ENTSIZE (section
, i
, Rela
);
4137 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4138 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
4139 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
4140 || do_debug_loc
|| do_debug_ranges
)
4141 && const_strneq (name
, ".debug_"))
4146 || (do_debug_info
&& streq (name
, "info"))
4147 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4148 || (do_debug_lines
&& streq (name
, "line"))
4149 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4150 || (do_debug_aranges
&& streq (name
, "aranges"))
4151 || (do_debug_ranges
&& streq (name
, "ranges"))
4152 || (do_debug_frames
&& streq (name
, "frame"))
4153 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4154 || (do_debug_str
&& streq (name
, "str"))
4155 || (do_debug_loc
&& streq (name
, "loc"))
4157 request_dump (i
, DEBUG_DUMP
);
4159 /* linkonce section to be combined with .debug_info at link time. */
4160 else if ((do_debugging
|| do_debug_info
)
4161 && const_strneq (name
, ".gnu.linkonce.wi."))
4162 request_dump (i
, DEBUG_DUMP
);
4163 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4164 request_dump (i
, DEBUG_DUMP
);
4170 if (elf_header
.e_shnum
> 1)
4171 printf (_("\nSection Headers:\n"));
4173 printf (_("\nSection Header:\n"));
4177 if (do_section_details
)
4179 printf (_(" [Nr] Name\n"));
4180 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4184 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4188 if (do_section_details
)
4190 printf (_(" [Nr] Name\n"));
4191 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4195 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4199 if (do_section_details
)
4201 printf (_(" [Nr] Name\n"));
4202 printf (_(" Type Address Offset Link\n"));
4203 printf (_(" Size EntSize Info Align\n"));
4207 printf (_(" [Nr] Name Type Address Offset\n"));
4208 printf (_(" Size EntSize Flags Link Info Align\n"));
4212 if (do_section_details
)
4213 printf (_(" Flags\n"));
4215 for (i
= 0, section
= section_headers
;
4216 i
< elf_header
.e_shnum
;
4219 if (do_section_details
)
4221 printf (" [%2u] %s\n",
4222 SECTION_HEADER_NUM (i
),
4223 SECTION_NAME (section
));
4224 if (is_32bit_elf
|| do_wide
)
4225 printf (" %-15.15s ",
4226 get_section_type_name (section
->sh_type
));
4229 printf (" [%2u] %-17.17s %-15.15s ",
4230 SECTION_HEADER_NUM (i
),
4231 SECTION_NAME (section
),
4232 get_section_type_name (section
->sh_type
));
4236 print_vma (section
->sh_addr
, LONG_HEX
);
4238 printf ( " %6.6lx %6.6lx %2.2lx",
4239 (unsigned long) section
->sh_offset
,
4240 (unsigned long) section
->sh_size
,
4241 (unsigned long) section
->sh_entsize
);
4243 if (do_section_details
)
4244 fputs (" ", stdout
);
4246 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4248 printf ("%2ld %3lu %2ld\n",
4249 (unsigned long) section
->sh_link
,
4250 (unsigned long) section
->sh_info
,
4251 (unsigned long) section
->sh_addralign
);
4255 print_vma (section
->sh_addr
, LONG_HEX
);
4257 if ((long) section
->sh_offset
== section
->sh_offset
)
4258 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4262 print_vma (section
->sh_offset
, LONG_HEX
);
4265 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4266 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4270 print_vma (section
->sh_size
, LONG_HEX
);
4273 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4274 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4278 print_vma (section
->sh_entsize
, LONG_HEX
);
4281 if (do_section_details
)
4282 fputs (" ", stdout
);
4284 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4286 printf ("%2ld %3lu ",
4287 (unsigned long) section
->sh_link
,
4288 (unsigned long) section
->sh_info
);
4290 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4291 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4294 print_vma (section
->sh_addralign
, DEC
);
4298 else if (do_section_details
)
4300 printf (" %-15.15s ",
4301 get_section_type_name (section
->sh_type
));
4302 print_vma (section
->sh_addr
, LONG_HEX
);
4303 if ((long) section
->sh_offset
== section
->sh_offset
)
4304 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4308 print_vma (section
->sh_offset
, LONG_HEX
);
4310 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4311 print_vma (section
->sh_size
, LONG_HEX
);
4313 print_vma (section
->sh_entsize
, LONG_HEX
);
4315 printf (" %-16lu %ld\n",
4316 (unsigned long) section
->sh_info
,
4317 (unsigned long) section
->sh_addralign
);
4322 print_vma (section
->sh_addr
, LONG_HEX
);
4323 if ((long) section
->sh_offset
== section
->sh_offset
)
4324 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4328 print_vma (section
->sh_offset
, LONG_HEX
);
4331 print_vma (section
->sh_size
, LONG_HEX
);
4333 print_vma (section
->sh_entsize
, LONG_HEX
);
4335 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4337 printf (" %2ld %3lu %ld\n",
4338 (unsigned long) section
->sh_link
,
4339 (unsigned long) section
->sh_info
,
4340 (unsigned long) section
->sh_addralign
);
4343 if (do_section_details
)
4344 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4347 if (!do_section_details
)
4348 printf (_("Key to Flags:\n\
4349 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4350 I (info), L (link order), G (group), x (unknown)\n\
4351 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4357 get_group_flags (unsigned int flags
)
4359 static char buff
[32];
4366 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4373 process_section_groups (FILE *file
)
4375 Elf_Internal_Shdr
*section
;
4377 struct group
*group
;
4378 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4379 Elf_Internal_Sym
*symtab
;
4383 /* Don't process section groups unless needed. */
4384 if (!do_unwind
&& !do_section_groups
)
4387 if (elf_header
.e_shnum
== 0)
4389 if (do_section_groups
)
4390 printf (_("\nThere are no sections in this file.\n"));
4395 if (section_headers
== NULL
)
4397 error (_("Section headers are not available!\n"));
4401 section_headers_groups
= calloc (elf_header
.e_shnum
,
4402 sizeof (struct group
*));
4404 if (section_headers_groups
== NULL
)
4406 error (_("Out of memory\n"));
4410 /* Scan the sections for the group section. */
4412 for (i
= 0, section
= section_headers
;
4413 i
< elf_header
.e_shnum
;
4415 if (section
->sh_type
== SHT_GROUP
)
4418 if (group_count
== 0)
4420 if (do_section_groups
)
4421 printf (_("\nThere are no section groups in this file.\n"));
4426 section_groups
= calloc (group_count
, sizeof (struct group
));
4428 if (section_groups
== NULL
)
4430 error (_("Out of memory\n"));
4439 for (i
= 0, section
= section_headers
, group
= section_groups
;
4440 i
< elf_header
.e_shnum
;
4443 if (section
->sh_type
== SHT_GROUP
)
4445 char *name
= SECTION_NAME (section
);
4447 unsigned char *start
, *indices
;
4448 unsigned int entry
, j
, size
;
4449 Elf_Internal_Shdr
*sec
;
4450 Elf_Internal_Sym
*sym
;
4452 /* Get the symbol table. */
4453 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4454 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4457 error (_("Bad sh_link in group section `%s'\n"), name
);
4461 if (symtab_sec
!= sec
)
4466 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4469 sym
= symtab
+ section
->sh_info
;
4471 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4473 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4476 error (_("Bad sh_info in group section `%s'\n"), name
);
4480 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4489 /* Get the string table. */
4490 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4491 >= elf_header
.e_shnum
)
4500 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4505 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4506 1, strtab_sec
->sh_size
,
4508 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4510 group_name
= sym
->st_name
< strtab_size
4511 ? strtab
+ sym
->st_name
: "<corrupt>";
4514 start
= get_data (NULL
, file
, section
->sh_offset
,
4515 1, section
->sh_size
, _("section data"));
4518 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4519 entry
= byte_get (indices
, 4);
4522 if (do_section_groups
)
4524 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4525 get_group_flags (entry
), i
, name
, group_name
, size
);
4527 printf (_(" [Index] Name\n"));
4530 group
->group_index
= i
;
4532 for (j
= 0; j
< size
; j
++)
4534 struct group_list
*g
;
4536 entry
= byte_get (indices
, 4);
4539 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4541 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4542 entry
, i
, elf_header
.e_shnum
- 1);
4545 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4547 error (_("invalid section [%5u] in group section [%5u]\n"),
4552 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4557 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4559 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4564 /* Intel C/C++ compiler may put section 0 in a
4565 section group. We just warn it the first time
4566 and ignore it afterwards. */
4567 static int warned
= 0;
4570 error (_("section 0 in group section [%5u]\n"),
4571 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4577 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4580 if (do_section_groups
)
4582 sec
= SECTION_HEADER (entry
);
4583 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4586 g
= xmalloc (sizeof (struct group_list
));
4587 g
->section_index
= entry
;
4588 g
->next
= group
->root
;
4612 } dynamic_relocations
[] =
4614 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4615 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4616 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4619 /* Process the reloc section. */
4622 process_relocs (FILE *file
)
4624 unsigned long rel_size
;
4625 unsigned long rel_offset
;
4631 if (do_using_dynamic
)
4635 int has_dynamic_reloc
;
4638 has_dynamic_reloc
= 0;
4640 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4642 is_rela
= dynamic_relocations
[i
].rela
;
4643 name
= dynamic_relocations
[i
].name
;
4644 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4645 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4647 has_dynamic_reloc
|= rel_size
;
4649 if (is_rela
== UNKNOWN
)
4651 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4652 switch (dynamic_info
[DT_PLTREL
])
4666 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4667 name
, rel_offset
, rel_size
);
4669 dump_relocations (file
,
4670 offset_from_vma (file
, rel_offset
, rel_size
),
4672 dynamic_symbols
, num_dynamic_syms
,
4673 dynamic_strings
, dynamic_strings_length
, is_rela
);
4677 if (! has_dynamic_reloc
)
4678 printf (_("\nThere are no dynamic relocations in this file.\n"));
4682 Elf_Internal_Shdr
*section
;
4686 for (i
= 0, section
= section_headers
;
4687 i
< elf_header
.e_shnum
;
4690 if ( section
->sh_type
!= SHT_RELA
4691 && section
->sh_type
!= SHT_REL
)
4694 rel_offset
= section
->sh_offset
;
4695 rel_size
= section
->sh_size
;
4699 Elf_Internal_Shdr
*strsec
;
4702 printf (_("\nRelocation section "));
4704 if (string_table
== NULL
)
4705 printf ("%d", section
->sh_name
);
4707 printf (_("'%s'"), SECTION_NAME (section
));
4709 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4710 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4712 is_rela
= section
->sh_type
== SHT_RELA
;
4714 if (section
->sh_link
4715 && SECTION_HEADER_INDEX (section
->sh_link
)
4716 < elf_header
.e_shnum
)
4718 Elf_Internal_Shdr
*symsec
;
4719 Elf_Internal_Sym
*symtab
;
4720 unsigned long nsyms
;
4721 unsigned long strtablen
= 0;
4722 char *strtab
= NULL
;
4724 symsec
= SECTION_HEADER (section
->sh_link
);
4725 if (symsec
->sh_type
!= SHT_SYMTAB
4726 && symsec
->sh_type
!= SHT_DYNSYM
)
4729 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4730 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4735 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4736 < elf_header
.e_shnum
)
4738 strsec
= SECTION_HEADER (symsec
->sh_link
);
4740 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4743 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4746 dump_relocations (file
, rel_offset
, rel_size
,
4747 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4753 dump_relocations (file
, rel_offset
, rel_size
,
4754 NULL
, 0, NULL
, 0, is_rela
);
4761 printf (_("\nThere are no relocations in this file.\n"));
4767 /* Process the unwind section. */
4769 #include "unwind-ia64.h"
4771 /* An absolute address consists of a section and an offset. If the
4772 section is NULL, the offset itself is the address, otherwise, the
4773 address equals to LOAD_ADDRESS(section) + offset. */
4777 unsigned short section
;
4781 #define ABSADDR(a) \
4783 ? section_headers [(a).section].sh_addr + (a).offset \
4786 struct ia64_unw_aux_info
4788 struct ia64_unw_table_entry
4790 struct absaddr start
;
4792 struct absaddr info
;
4794 *table
; /* Unwind table. */
4795 unsigned long table_len
; /* Length of unwind table. */
4796 unsigned char *info
; /* Unwind info. */
4797 unsigned long info_size
; /* Size of unwind info. */
4798 bfd_vma info_addr
; /* starting address of unwind info. */
4799 bfd_vma seg_base
; /* Starting address of segment. */
4800 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4801 unsigned long nsyms
; /* Number of symbols. */
4802 char *strtab
; /* The string table. */
4803 unsigned long strtab_size
; /* Size of string table. */
4807 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4808 unsigned long nsyms
,
4810 unsigned long strtab_size
,
4811 struct absaddr addr
,
4812 const char **symname
,
4815 bfd_vma dist
= 0x100000;
4816 Elf_Internal_Sym
*sym
, *best
= NULL
;
4819 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4821 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4822 && sym
->st_name
!= 0
4823 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4824 && addr
.offset
>= sym
->st_value
4825 && addr
.offset
- sym
->st_value
< dist
)
4828 dist
= addr
.offset
- sym
->st_value
;
4835 *symname
= (best
->st_name
>= strtab_size
4836 ? "<corrupt>" : strtab
+ best
->st_name
);
4841 *offset
= addr
.offset
;
4845 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4847 struct ia64_unw_table_entry
*tp
;
4850 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4854 const unsigned char *dp
;
4855 const unsigned char *head
;
4856 const char *procname
;
4858 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4859 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4861 fputs ("\n<", stdout
);
4865 fputs (procname
, stdout
);
4868 printf ("+%lx", (unsigned long) offset
);
4871 fputs (">: [", stdout
);
4872 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4873 fputc ('-', stdout
);
4874 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4875 printf ("], info at +0x%lx\n",
4876 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4878 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4879 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4881 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4882 (unsigned) UNW_VER (stamp
),
4883 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4884 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4885 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4886 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4888 if (UNW_VER (stamp
) != 1)
4890 printf ("\tUnknown version.\n");
4895 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4896 dp
= unw_decode (dp
, in_body
, & in_body
);
4901 slurp_ia64_unwind_table (FILE *file
,
4902 struct ia64_unw_aux_info
*aux
,
4903 Elf_Internal_Shdr
*sec
)
4905 unsigned long size
, nrelas
, i
;
4906 Elf_Internal_Phdr
*seg
;
4907 struct ia64_unw_table_entry
*tep
;
4908 Elf_Internal_Shdr
*relsec
;
4909 Elf_Internal_Rela
*rela
, *rp
;
4910 unsigned char *table
, *tp
;
4911 Elf_Internal_Sym
*sym
;
4912 const char *relname
;
4914 /* First, find the starting address of the segment that includes
4917 if (elf_header
.e_phnum
)
4919 if (! get_program_headers (file
))
4922 for (seg
= program_headers
;
4923 seg
< program_headers
+ elf_header
.e_phnum
;
4926 if (seg
->p_type
!= PT_LOAD
)
4929 if (sec
->sh_addr
>= seg
->p_vaddr
4930 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4932 aux
->seg_base
= seg
->p_vaddr
;
4938 /* Second, build the unwind table from the contents of the unwind section: */
4939 size
= sec
->sh_size
;
4940 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4944 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4946 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4948 tep
->start
.section
= SHN_UNDEF
;
4949 tep
->end
.section
= SHN_UNDEF
;
4950 tep
->info
.section
= SHN_UNDEF
;
4953 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4954 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4955 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4959 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
4960 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
4961 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
4963 tep
->start
.offset
+= aux
->seg_base
;
4964 tep
->end
.offset
+= aux
->seg_base
;
4965 tep
->info
.offset
+= aux
->seg_base
;
4969 /* Third, apply any relocations to the unwind table: */
4971 for (relsec
= section_headers
;
4972 relsec
< section_headers
+ elf_header
.e_shnum
;
4975 if (relsec
->sh_type
!= SHT_RELA
4976 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
4977 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4980 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4984 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4988 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4989 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4993 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4994 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4997 if (! const_strneq (relname
, "R_IA64_SEGREL"))
4999 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5003 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5005 switch (rp
->r_offset
/eh_addr_size
% 3)
5008 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5009 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5012 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5013 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5016 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5017 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5027 aux
->table_len
= size
/ (3 * eh_addr_size
);
5032 ia64_process_unwind (FILE *file
)
5034 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
5035 unsigned long i
, unwcount
= 0, unwstart
= 0;
5036 struct ia64_unw_aux_info aux
;
5038 memset (& aux
, 0, sizeof (aux
));
5040 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5042 if (sec
->sh_type
== SHT_SYMTAB
5043 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5045 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5046 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5048 strsec
= SECTION_HEADER (sec
->sh_link
);
5049 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5050 1, strsec
->sh_size
, _("string table"));
5051 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5053 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5058 printf (_("\nThere are no unwind sections in this file.\n"));
5060 while (unwcount
-- > 0)
5065 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5066 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5067 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5074 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5076 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5078 /* We need to find which section group it is in. */
5079 struct group_list
*g
= section_headers_groups
[i
]->root
;
5081 for (; g
!= NULL
; g
= g
->next
)
5083 sec
= SECTION_HEADER (g
->section_index
);
5085 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5090 i
= elf_header
.e_shnum
;
5092 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5094 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5095 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5096 suffix
= SECTION_NAME (unwsec
) + len
;
5097 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5099 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5100 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5105 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5106 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5107 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5108 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5110 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5111 suffix
= SECTION_NAME (unwsec
) + len
;
5112 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5114 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5115 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5119 if (i
== elf_header
.e_shnum
)
5121 printf (_("\nCould not find unwind info section for "));
5123 if (string_table
== NULL
)
5124 printf ("%d", unwsec
->sh_name
);
5126 printf (_("'%s'"), SECTION_NAME (unwsec
));
5130 aux
.info_size
= sec
->sh_size
;
5131 aux
.info_addr
= sec
->sh_addr
;
5132 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
5135 printf (_("\nUnwind section "));
5137 if (string_table
== NULL
)
5138 printf ("%d", unwsec
->sh_name
);
5140 printf (_("'%s'"), SECTION_NAME (unwsec
));
5142 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5143 (unsigned long) unwsec
->sh_offset
,
5144 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5146 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5148 if (aux
.table_len
> 0)
5149 dump_ia64_unwind (& aux
);
5152 free ((char *) aux
.table
);
5154 free ((char *) aux
.info
);
5163 free ((char *) aux
.strtab
);
5168 struct hppa_unw_aux_info
5170 struct hppa_unw_table_entry
5172 struct absaddr start
;
5174 unsigned int Cannot_unwind
:1; /* 0 */
5175 unsigned int Millicode
:1; /* 1 */
5176 unsigned int Millicode_save_sr0
:1; /* 2 */
5177 unsigned int Region_description
:2; /* 3..4 */
5178 unsigned int reserved1
:1; /* 5 */
5179 unsigned int Entry_SR
:1; /* 6 */
5180 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5181 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5182 unsigned int Args_stored
:1; /* 16 */
5183 unsigned int Variable_Frame
:1; /* 17 */
5184 unsigned int Separate_Package_Body
:1; /* 18 */
5185 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5186 unsigned int Stack_Overflow_Check
:1; /* 20 */
5187 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5188 unsigned int Ada_Region
:1; /* 22 */
5189 unsigned int cxx_info
:1; /* 23 */
5190 unsigned int cxx_try_catch
:1; /* 24 */
5191 unsigned int sched_entry_seq
:1; /* 25 */
5192 unsigned int reserved2
:1; /* 26 */
5193 unsigned int Save_SP
:1; /* 27 */
5194 unsigned int Save_RP
:1; /* 28 */
5195 unsigned int Save_MRP_in_frame
:1; /* 29 */
5196 unsigned int extn_ptr_defined
:1; /* 30 */
5197 unsigned int Cleanup_defined
:1; /* 31 */
5199 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5200 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5201 unsigned int Large_frame
:1; /* 2 */
5202 unsigned int Pseudo_SP_Set
:1; /* 3 */
5203 unsigned int reserved4
:1; /* 4 */
5204 unsigned int Total_frame_size
:27; /* 5..31 */
5206 *table
; /* Unwind table. */
5207 unsigned long table_len
; /* Length of unwind table. */
5208 bfd_vma seg_base
; /* Starting address of segment. */
5209 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5210 unsigned long nsyms
; /* Number of symbols. */
5211 char *strtab
; /* The string table. */
5212 unsigned long strtab_size
; /* Size of string table. */
5216 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5218 struct hppa_unw_table_entry
*tp
;
5220 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5223 const char *procname
;
5225 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5226 aux
->strtab_size
, tp
->start
, &procname
,
5229 fputs ("\n<", stdout
);
5233 fputs (procname
, stdout
);
5236 printf ("+%lx", (unsigned long) offset
);
5239 fputs (">: [", stdout
);
5240 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5241 fputc ('-', stdout
);
5242 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5245 #define PF(_m) if (tp->_m) printf (#_m " ");
5246 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5249 PF(Millicode_save_sr0
);
5250 /* PV(Region_description); */
5256 PF(Separate_Package_Body
);
5257 PF(Frame_Extension_Millicode
);
5258 PF(Stack_Overflow_Check
);
5259 PF(Two_Instruction_SP_Increment
);
5263 PF(sched_entry_seq
);
5266 PF(Save_MRP_in_frame
);
5267 PF(extn_ptr_defined
);
5268 PF(Cleanup_defined
);
5269 PF(MPE_XL_interrupt_marker
);
5270 PF(HP_UX_interrupt_marker
);
5273 PV(Total_frame_size
);
5282 slurp_hppa_unwind_table (FILE *file
,
5283 struct hppa_unw_aux_info
*aux
,
5284 Elf_Internal_Shdr
*sec
)
5286 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5287 Elf_Internal_Phdr
*seg
;
5288 struct hppa_unw_table_entry
*tep
;
5289 Elf_Internal_Shdr
*relsec
;
5290 Elf_Internal_Rela
*rela
, *rp
;
5291 unsigned char *table
, *tp
;
5292 Elf_Internal_Sym
*sym
;
5293 const char *relname
;
5295 /* First, find the starting address of the segment that includes
5298 if (elf_header
.e_phnum
)
5300 if (! get_program_headers (file
))
5303 for (seg
= program_headers
;
5304 seg
< program_headers
+ elf_header
.e_phnum
;
5307 if (seg
->p_type
!= PT_LOAD
)
5310 if (sec
->sh_addr
>= seg
->p_vaddr
5311 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5313 aux
->seg_base
= seg
->p_vaddr
;
5319 /* Second, build the unwind table from the contents of the unwind
5321 size
= sec
->sh_size
;
5322 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5327 nentries
= size
/ unw_ent_size
;
5328 size
= unw_ent_size
* nentries
;
5330 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5332 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5334 unsigned int tmp1
, tmp2
;
5336 tep
->start
.section
= SHN_UNDEF
;
5337 tep
->end
.section
= SHN_UNDEF
;
5339 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5340 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5341 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5342 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5344 tep
->start
.offset
+= aux
->seg_base
;
5345 tep
->end
.offset
+= aux
->seg_base
;
5347 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5348 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5349 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5350 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5351 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5352 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5353 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5354 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5355 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5356 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5357 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5358 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5359 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5360 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5361 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5362 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5363 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5364 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5365 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5366 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5367 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5368 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5369 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5370 tep
->Cleanup_defined
= tmp1
& 0x1;
5372 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5373 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5374 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5375 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5376 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5377 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5381 /* Third, apply any relocations to the unwind table. */
5383 for (relsec
= section_headers
;
5384 relsec
< section_headers
+ elf_header
.e_shnum
;
5387 if (relsec
->sh_type
!= SHT_RELA
5388 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5389 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5392 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5396 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5400 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5401 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5405 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5406 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5409 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5410 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5412 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5416 i
= rp
->r_offset
/ unw_ent_size
;
5418 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5421 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5422 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5425 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5426 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5436 aux
->table_len
= nentries
;
5442 hppa_process_unwind (FILE *file
)
5444 struct hppa_unw_aux_info aux
;
5445 Elf_Internal_Shdr
*unwsec
= NULL
;
5446 Elf_Internal_Shdr
*strsec
;
5447 Elf_Internal_Shdr
*sec
;
5450 memset (& aux
, 0, sizeof (aux
));
5452 if (string_table
== NULL
)
5455 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5457 if (sec
->sh_type
== SHT_SYMTAB
5458 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5460 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5461 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5463 strsec
= SECTION_HEADER (sec
->sh_link
);
5464 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5465 1, strsec
->sh_size
, _("string table"));
5466 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5468 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5473 printf (_("\nThere are no unwind sections in this file.\n"));
5475 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5477 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5479 printf (_("\nUnwind section "));
5480 printf (_("'%s'"), SECTION_NAME (sec
));
5482 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5483 (unsigned long) sec
->sh_offset
,
5484 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5486 slurp_hppa_unwind_table (file
, &aux
, sec
);
5487 if (aux
.table_len
> 0)
5488 dump_hppa_unwind (&aux
);
5491 free ((char *) aux
.table
);
5499 free ((char *) aux
.strtab
);
5505 process_unwind (FILE *file
)
5507 struct unwind_handler
{
5509 int (*handler
)(FILE *file
);
5511 { EM_IA_64
, ia64_process_unwind
},
5512 { EM_PARISC
, hppa_process_unwind
},
5520 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5521 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5522 return handlers
[i
].handler (file
);
5524 printf (_("\nThere are no unwind sections in this file.\n"));
5529 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5531 switch (entry
->d_tag
)
5534 if (entry
->d_un
.d_val
== 0)
5538 static const char * opts
[] =
5540 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5541 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5542 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5543 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5548 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
5549 if (entry
->d_un
.d_val
& (1 << cnt
))
5551 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5558 case DT_MIPS_IVERSION
:
5559 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5560 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5562 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5565 case DT_MIPS_TIME_STAMP
:
5570 time_t time
= entry
->d_un
.d_val
;
5571 tmp
= gmtime (&time
);
5572 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5573 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5574 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5575 printf ("Time Stamp: %s\n", timebuf
);
5579 case DT_MIPS_RLD_VERSION
:
5580 case DT_MIPS_LOCAL_GOTNO
:
5581 case DT_MIPS_CONFLICTNO
:
5582 case DT_MIPS_LIBLISTNO
:
5583 case DT_MIPS_SYMTABNO
:
5584 case DT_MIPS_UNREFEXTNO
:
5585 case DT_MIPS_HIPAGENO
:
5586 case DT_MIPS_DELTA_CLASS_NO
:
5587 case DT_MIPS_DELTA_INSTANCE_NO
:
5588 case DT_MIPS_DELTA_RELOC_NO
:
5589 case DT_MIPS_DELTA_SYM_NO
:
5590 case DT_MIPS_DELTA_CLASSSYM_NO
:
5591 case DT_MIPS_COMPACT_SIZE
:
5592 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5596 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5602 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5604 switch (entry
->d_tag
)
5606 case DT_HP_DLD_FLAGS
:
5615 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5616 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5617 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5618 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5619 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5620 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5621 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5622 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5623 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5624 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5625 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5626 { DT_HP_GST
, "HP_GST" },
5627 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5628 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5629 { DT_HP_NODELETE
, "HP_NODELETE" },
5630 { DT_HP_GROUP
, "HP_GROUP" },
5631 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5635 bfd_vma val
= entry
->d_un
.d_val
;
5637 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
5638 if (val
& flags
[cnt
].bit
)
5642 fputs (flags
[cnt
].str
, stdout
);
5644 val
^= flags
[cnt
].bit
;
5647 if (val
!= 0 || first
)
5651 print_vma (val
, HEX
);
5657 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5664 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5666 switch (entry
->d_tag
)
5668 case DT_IA_64_PLT_RESERVE
:
5669 /* First 3 slots reserved. */
5670 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5672 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5676 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5683 get_32bit_dynamic_section (FILE *file
)
5685 Elf32_External_Dyn
*edyn
, *ext
;
5686 Elf_Internal_Dyn
*entry
;
5688 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5689 _("dynamic section"));
5693 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5694 might not have the luxury of section headers. Look for the DT_NULL
5695 terminator to determine the number of entries. */
5696 for (ext
= edyn
, dynamic_nent
= 0;
5697 (char *) ext
< (char *) edyn
+ dynamic_size
;
5701 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5705 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5706 if (dynamic_section
== NULL
)
5708 error (_("Out of memory\n"));
5713 for (ext
= edyn
, entry
= dynamic_section
;
5714 entry
< dynamic_section
+ dynamic_nent
;
5717 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5718 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5727 get_64bit_dynamic_section (FILE *file
)
5729 Elf64_External_Dyn
*edyn
, *ext
;
5730 Elf_Internal_Dyn
*entry
;
5732 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5733 _("dynamic section"));
5737 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5738 might not have the luxury of section headers. Look for the DT_NULL
5739 terminator to determine the number of entries. */
5740 for (ext
= edyn
, dynamic_nent
= 0;
5741 (char *) ext
< (char *) edyn
+ dynamic_size
;
5745 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5749 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5750 if (dynamic_section
== NULL
)
5752 error (_("Out of memory\n"));
5757 for (ext
= edyn
, entry
= dynamic_section
;
5758 entry
< dynamic_section
+ dynamic_nent
;
5761 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5762 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5771 print_dynamic_flags (bfd_vma flags
)
5779 flag
= flags
& - flags
;
5789 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5790 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5791 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5792 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5793 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5794 default: fputs ("unknown", stdout
); break;
5800 /* Parse and display the contents of the dynamic section. */
5803 process_dynamic_section (FILE *file
)
5805 Elf_Internal_Dyn
*entry
;
5807 if (dynamic_size
== 0)
5810 printf (_("\nThere is no dynamic section in this file.\n"));
5817 if (! get_32bit_dynamic_section (file
))
5820 else if (! get_64bit_dynamic_section (file
))
5823 /* Find the appropriate symbol table. */
5824 if (dynamic_symbols
== NULL
)
5826 for (entry
= dynamic_section
;
5827 entry
< dynamic_section
+ dynamic_nent
;
5830 Elf_Internal_Shdr section
;
5832 if (entry
->d_tag
!= DT_SYMTAB
)
5835 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5837 /* Since we do not know how big the symbol table is,
5838 we default to reading in the entire file (!) and
5839 processing that. This is overkill, I know, but it
5841 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5843 if (archive_file_offset
!= 0)
5844 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5847 if (fseek (file
, 0, SEEK_END
))
5848 error (_("Unable to seek to end of file!"));
5850 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5854 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5856 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5858 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5859 if (num_dynamic_syms
< 1)
5861 error (_("Unable to determine the number of symbols to load\n"));
5865 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5869 /* Similarly find a string table. */
5870 if (dynamic_strings
== NULL
)
5872 for (entry
= dynamic_section
;
5873 entry
< dynamic_section
+ dynamic_nent
;
5876 unsigned long offset
;
5879 if (entry
->d_tag
!= DT_STRTAB
)
5882 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5884 /* Since we do not know how big the string table is,
5885 we default to reading in the entire file (!) and
5886 processing that. This is overkill, I know, but it
5889 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5891 if (archive_file_offset
!= 0)
5892 str_tab_len
= archive_file_size
- offset
;
5895 if (fseek (file
, 0, SEEK_END
))
5896 error (_("Unable to seek to end of file\n"));
5897 str_tab_len
= ftell (file
) - offset
;
5900 if (str_tab_len
< 1)
5903 (_("Unable to determine the length of the dynamic string table\n"));
5907 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5908 _("dynamic string table"));
5909 dynamic_strings_length
= str_tab_len
;
5914 /* And find the syminfo section if available. */
5915 if (dynamic_syminfo
== NULL
)
5917 unsigned long syminsz
= 0;
5919 for (entry
= dynamic_section
;
5920 entry
< dynamic_section
+ dynamic_nent
;
5923 if (entry
->d_tag
== DT_SYMINENT
)
5925 /* Note: these braces are necessary to avoid a syntax
5926 error from the SunOS4 C compiler. */
5927 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5929 else if (entry
->d_tag
== DT_SYMINSZ
)
5930 syminsz
= entry
->d_un
.d_val
;
5931 else if (entry
->d_tag
== DT_SYMINFO
)
5932 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5936 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5938 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5939 Elf_Internal_Syminfo
*syminfo
;
5941 /* There is a syminfo section. Read the data. */
5942 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5943 syminsz
, _("symbol information"));
5947 dynamic_syminfo
= malloc (syminsz
);
5948 if (dynamic_syminfo
== NULL
)
5950 error (_("Out of memory\n"));
5954 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5955 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5956 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5957 ++syminfo
, ++extsym
)
5959 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5960 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5967 if (do_dynamic
&& dynamic_addr
)
5968 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5969 dynamic_addr
, dynamic_nent
);
5971 printf (_(" Tag Type Name/Value\n"));
5973 for (entry
= dynamic_section
;
5974 entry
< dynamic_section
+ dynamic_nent
;
5982 print_vma (entry
->d_tag
, FULL_HEX
);
5983 dtype
= get_dynamic_type (entry
->d_tag
);
5984 printf (" (%s)%*s", dtype
,
5985 ((is_32bit_elf
? 27 : 19)
5986 - (int) strlen (dtype
)),
5990 switch (entry
->d_tag
)
5994 print_dynamic_flags (entry
->d_un
.d_val
);
6004 switch (entry
->d_tag
)
6007 printf (_("Auxiliary library"));
6011 printf (_("Filter library"));
6015 printf (_("Configuration file"));
6019 printf (_("Dependency audit library"));
6023 printf (_("Audit library"));
6027 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6028 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6032 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6041 printf (_("Flags:"));
6043 if (entry
->d_un
.d_val
== 0)
6044 printf (_(" None\n"));
6047 unsigned long int val
= entry
->d_un
.d_val
;
6049 if (val
& DTF_1_PARINIT
)
6051 printf (" PARINIT");
6052 val
^= DTF_1_PARINIT
;
6054 if (val
& DTF_1_CONFEXP
)
6056 printf (" CONFEXP");
6057 val
^= DTF_1_CONFEXP
;
6060 printf (" %lx", val
);
6069 printf (_("Flags:"));
6071 if (entry
->d_un
.d_val
== 0)
6072 printf (_(" None\n"));
6075 unsigned long int val
= entry
->d_un
.d_val
;
6077 if (val
& DF_P1_LAZYLOAD
)
6079 printf (" LAZYLOAD");
6080 val
^= DF_P1_LAZYLOAD
;
6082 if (val
& DF_P1_GROUPPERM
)
6084 printf (" GROUPPERM");
6085 val
^= DF_P1_GROUPPERM
;
6088 printf (" %lx", val
);
6097 printf (_("Flags:"));
6098 if (entry
->d_un
.d_val
== 0)
6099 printf (_(" None\n"));
6102 unsigned long int val
= entry
->d_un
.d_val
;
6109 if (val
& DF_1_GLOBAL
)
6114 if (val
& DF_1_GROUP
)
6119 if (val
& DF_1_NODELETE
)
6121 printf (" NODELETE");
6122 val
^= DF_1_NODELETE
;
6124 if (val
& DF_1_LOADFLTR
)
6126 printf (" LOADFLTR");
6127 val
^= DF_1_LOADFLTR
;
6129 if (val
& DF_1_INITFIRST
)
6131 printf (" INITFIRST");
6132 val
^= DF_1_INITFIRST
;
6134 if (val
& DF_1_NOOPEN
)
6139 if (val
& DF_1_ORIGIN
)
6144 if (val
& DF_1_DIRECT
)
6149 if (val
& DF_1_TRANS
)
6154 if (val
& DF_1_INTERPOSE
)
6156 printf (" INTERPOSE");
6157 val
^= DF_1_INTERPOSE
;
6159 if (val
& DF_1_NODEFLIB
)
6161 printf (" NODEFLIB");
6162 val
^= DF_1_NODEFLIB
;
6164 if (val
& DF_1_NODUMP
)
6169 if (val
& DF_1_CONLFAT
)
6171 printf (" CONLFAT");
6172 val
^= DF_1_CONLFAT
;
6175 printf (" %lx", val
);
6182 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6184 puts (get_dynamic_type (entry
->d_un
.d_val
));
6204 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6210 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6211 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6217 switch (entry
->d_tag
)
6220 printf (_("Shared library: [%s]"), name
);
6222 if (streq (name
, program_interpreter
))
6223 printf (_(" program interpreter"));
6227 printf (_("Library soname: [%s]"), name
);
6231 printf (_("Library rpath: [%s]"), name
);
6235 printf (_("Library runpath: [%s]"), name
);
6239 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6244 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6257 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6261 case DT_INIT_ARRAYSZ
:
6262 case DT_FINI_ARRAYSZ
:
6263 case DT_GNU_CONFLICTSZ
:
6264 case DT_GNU_LIBLISTSZ
:
6267 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6268 printf (" (bytes)\n");
6278 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6291 if (entry
->d_tag
== DT_USED
6292 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6294 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6298 printf (_("Not needed object: [%s]\n"), name
);
6303 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6309 /* The value of this entry is ignored. */
6314 case DT_GNU_PRELINKED
:
6318 time_t time
= entry
->d_un
.d_val
;
6320 tmp
= gmtime (&time
);
6321 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6322 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6323 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6329 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6332 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6338 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6339 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6344 switch (elf_header
.e_machine
)
6347 case EM_MIPS_RS3_LE
:
6348 dynamic_section_mips_val (entry
);
6351 dynamic_section_parisc_val (entry
);
6354 dynamic_section_ia64_val (entry
);
6357 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6369 get_ver_flags (unsigned int flags
)
6371 static char buff
[32];
6378 if (flags
& VER_FLG_BASE
)
6379 strcat (buff
, "BASE ");
6381 if (flags
& VER_FLG_WEAK
)
6383 if (flags
& VER_FLG_BASE
)
6384 strcat (buff
, "| ");
6386 strcat (buff
, "WEAK ");
6389 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6390 strcat (buff
, "| <unknown>");
6395 /* Display the contents of the version sections. */
6397 process_version_sections (FILE *file
)
6399 Elf_Internal_Shdr
*section
;
6406 for (i
= 0, section
= section_headers
;
6407 i
< elf_header
.e_shnum
;
6410 switch (section
->sh_type
)
6412 case SHT_GNU_verdef
:
6414 Elf_External_Verdef
*edefs
;
6421 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6422 SECTION_NAME (section
), section
->sh_info
);
6424 printf (_(" Addr: 0x"));
6425 printf_vma (section
->sh_addr
);
6426 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6427 (unsigned long) section
->sh_offset
, section
->sh_link
,
6428 SECTION_HEADER_INDEX (section
->sh_link
)
6429 < elf_header
.e_shnum
6430 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6433 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6435 _("version definition section"));
6439 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6442 Elf_External_Verdef
*edef
;
6443 Elf_Internal_Verdef ent
;
6444 Elf_External_Verdaux
*eaux
;
6445 Elf_Internal_Verdaux aux
;
6449 vstart
= ((char *) edefs
) + idx
;
6451 edef
= (Elf_External_Verdef
*) vstart
;
6453 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6454 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6455 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6456 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6457 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6458 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6459 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6461 printf (_(" %#06x: Rev: %d Flags: %s"),
6462 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6464 printf (_(" Index: %d Cnt: %d "),
6465 ent
.vd_ndx
, ent
.vd_cnt
);
6467 vstart
+= ent
.vd_aux
;
6469 eaux
= (Elf_External_Verdaux
*) vstart
;
6471 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6472 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6474 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6475 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6477 printf (_("Name index: %ld\n"), aux
.vda_name
);
6479 isum
= idx
+ ent
.vd_aux
;
6481 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6483 isum
+= aux
.vda_next
;
6484 vstart
+= aux
.vda_next
;
6486 eaux
= (Elf_External_Verdaux
*) vstart
;
6488 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6489 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6491 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6492 printf (_(" %#06x: Parent %d: %s\n"),
6493 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6495 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6496 isum
, j
, aux
.vda_name
);
6506 case SHT_GNU_verneed
:
6508 Elf_External_Verneed
*eneed
;
6514 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6515 SECTION_NAME (section
), section
->sh_info
);
6517 printf (_(" Addr: 0x"));
6518 printf_vma (section
->sh_addr
);
6519 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6520 (unsigned long) section
->sh_offset
, section
->sh_link
,
6521 SECTION_HEADER_INDEX (section
->sh_link
)
6522 < elf_header
.e_shnum
6523 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6526 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6528 _("version need section"));
6532 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6534 Elf_External_Verneed
*entry
;
6535 Elf_Internal_Verneed ent
;
6540 vstart
= ((char *) eneed
) + idx
;
6542 entry
= (Elf_External_Verneed
*) vstart
;
6544 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6545 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6546 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6547 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6548 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6550 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6552 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6553 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6555 printf (_(" File: %lx"), ent
.vn_file
);
6557 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6559 vstart
+= ent
.vn_aux
;
6561 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6563 Elf_External_Vernaux
*eaux
;
6564 Elf_Internal_Vernaux aux
;
6566 eaux
= (Elf_External_Vernaux
*) vstart
;
6568 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6569 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6570 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6571 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6572 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6574 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6575 printf (_(" %#06x: Name: %s"),
6576 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6578 printf (_(" %#06x: Name index: %lx"),
6579 isum
, aux
.vna_name
);
6581 printf (_(" Flags: %s Version: %d\n"),
6582 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6584 isum
+= aux
.vna_next
;
6585 vstart
+= aux
.vna_next
;
6595 case SHT_GNU_versym
:
6597 Elf_Internal_Shdr
*link_section
;
6600 unsigned char *edata
;
6601 unsigned short *data
;
6603 Elf_Internal_Sym
*symbols
;
6604 Elf_Internal_Shdr
*string_sec
;
6607 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6610 link_section
= SECTION_HEADER (section
->sh_link
);
6611 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6613 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6614 >= elf_header
.e_shnum
)
6619 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6621 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6623 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6624 string_sec
->sh_size
, _("version string table"));
6628 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6629 SECTION_NAME (section
), total
);
6631 printf (_(" Addr: "));
6632 printf_vma (section
->sh_addr
);
6633 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6634 (unsigned long) section
->sh_offset
, section
->sh_link
,
6635 SECTION_NAME (link_section
));
6637 off
= offset_from_vma (file
,
6638 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6639 total
* sizeof (short));
6640 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6641 _("version symbol data"));
6648 data
= cmalloc (total
, sizeof (short));
6650 for (cnt
= total
; cnt
--;)
6651 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6656 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6659 int check_def
, check_need
;
6662 printf (" %03x:", cnt
);
6664 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6665 switch (data
[cnt
+ j
])
6668 fputs (_(" 0 (*local*) "), stdout
);
6672 fputs (_(" 1 (*global*) "), stdout
);
6676 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6677 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6681 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6682 >= elf_header
.e_shnum
6683 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6686 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6693 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6695 Elf_Internal_Verneed ivn
;
6696 unsigned long offset
;
6698 offset
= offset_from_vma
6699 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6700 sizeof (Elf_External_Verneed
));
6704 Elf_Internal_Vernaux ivna
;
6705 Elf_External_Verneed evn
;
6706 Elf_External_Vernaux evna
;
6707 unsigned long a_off
;
6709 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6712 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6713 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6715 a_off
= offset
+ ivn
.vn_aux
;
6719 get_data (&evna
, file
, a_off
, sizeof (evna
),
6720 1, _("version need aux (2)"));
6722 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6723 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6725 a_off
+= ivna
.vna_next
;
6727 while (ivna
.vna_other
!= data
[cnt
+ j
]
6728 && ivna
.vna_next
!= 0);
6730 if (ivna
.vna_other
== data
[cnt
+ j
])
6732 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6734 name
= strtab
+ ivna
.vna_name
;
6735 nn
+= printf ("(%s%-*s",
6737 12 - (int) strlen (name
),
6743 offset
+= ivn
.vn_next
;
6745 while (ivn
.vn_next
);
6748 if (check_def
&& data
[cnt
+ j
] != 0x8001
6749 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6751 Elf_Internal_Verdef ivd
;
6752 Elf_External_Verdef evd
;
6753 unsigned long offset
;
6755 offset
= offset_from_vma
6756 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6761 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6764 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6765 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6767 offset
+= ivd
.vd_next
;
6769 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6770 && ivd
.vd_next
!= 0);
6772 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6774 Elf_External_Verdaux evda
;
6775 Elf_Internal_Verdaux ivda
;
6777 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6779 get_data (&evda
, file
,
6780 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6782 _("version def aux"));
6784 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6786 name
= strtab
+ ivda
.vda_name
;
6787 nn
+= printf ("(%s%-*s",
6789 12 - (int) strlen (name
),
6795 printf ("%*c", 18 - nn
, ' ');
6813 printf (_("\nNo version information found in this file.\n"));
6819 get_symbol_binding (unsigned int binding
)
6821 static char buff
[32];
6825 case STB_LOCAL
: return "LOCAL";
6826 case STB_GLOBAL
: return "GLOBAL";
6827 case STB_WEAK
: return "WEAK";
6829 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6830 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6832 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6833 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6835 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6841 get_symbol_type (unsigned int type
)
6843 static char buff
[32];
6847 case STT_NOTYPE
: return "NOTYPE";
6848 case STT_OBJECT
: return "OBJECT";
6849 case STT_FUNC
: return "FUNC";
6850 case STT_SECTION
: return "SECTION";
6851 case STT_FILE
: return "FILE";
6852 case STT_COMMON
: return "COMMON";
6853 case STT_TLS
: return "TLS";
6854 case STT_RELC
: return "RELC";
6855 case STT_SRELC
: return "SRELC";
6857 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6859 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6860 return "THUMB_FUNC";
6862 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6865 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6866 return "PARISC_MILLI";
6868 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6870 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6872 if (elf_header
.e_machine
== EM_PARISC
)
6874 if (type
== STT_HP_OPAQUE
)
6876 if (type
== STT_HP_STUB
)
6880 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6883 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6889 get_symbol_visibility (unsigned int visibility
)
6893 case STV_DEFAULT
: return "DEFAULT";
6894 case STV_INTERNAL
: return "INTERNAL";
6895 case STV_HIDDEN
: return "HIDDEN";
6896 case STV_PROTECTED
: return "PROTECTED";
6902 get_mips_symbol_other (unsigned int other
)
6906 case STO_OPTIONAL
: return "OPTIONAL";
6907 case STO_MIPS16
: return "MIPS16";
6908 default: return NULL
;
6913 get_symbol_other (unsigned int other
)
6915 const char * result
= NULL
;
6916 static char buff
[32];
6921 switch (elf_header
.e_machine
)
6924 result
= get_mips_symbol_other (other
);
6932 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
6937 get_symbol_index_type (unsigned int type
)
6939 static char buff
[32];
6943 case SHN_UNDEF
: return "UND";
6944 case SHN_ABS
: return "ABS";
6945 case SHN_COMMON
: return "COM";
6947 if (type
== SHN_IA_64_ANSI_COMMON
6948 && elf_header
.e_machine
== EM_IA_64
6949 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6951 else if (elf_header
.e_machine
== EM_X86_64
6952 && type
== SHN_X86_64_LCOMMON
)
6954 else if (type
== SHN_MIPS_SCOMMON
6955 && elf_header
.e_machine
== EM_MIPS
)
6957 else if (type
== SHN_MIPS_SUNDEFINED
6958 && elf_header
.e_machine
== EM_MIPS
)
6960 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6961 sprintf (buff
, "PRC[0x%04x]", type
);
6962 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6963 sprintf (buff
, "OS [0x%04x]", type
);
6964 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6965 sprintf (buff
, "RSV[0x%04x]", type
);
6967 sprintf (buff
, "%3d", type
);
6975 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
6977 unsigned char *e_data
;
6980 e_data
= cmalloc (number
, ent_size
);
6984 error (_("Out of memory\n"));
6988 if (fread (e_data
, ent_size
, number
, file
) != number
)
6990 error (_("Unable to read in dynamic data\n"));
6994 i_data
= cmalloc (number
, sizeof (*i_data
));
6998 error (_("Out of memory\n"));
7004 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7011 /* Dump the symbol table. */
7013 process_symbol_table (FILE *file
)
7015 Elf_Internal_Shdr
*section
;
7016 bfd_vma nbuckets
= 0;
7017 bfd_vma nchains
= 0;
7018 bfd_vma
*buckets
= NULL
;
7019 bfd_vma
*chains
= NULL
;
7020 bfd_vma ngnubuckets
= 0;
7021 bfd_vma
*gnubuckets
= NULL
;
7022 bfd_vma
*gnuchains
= NULL
;
7024 if (! do_syms
&& !do_histogram
)
7027 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
7030 unsigned char nb
[8];
7031 unsigned char nc
[8];
7032 int hash_ent_size
= 4;
7034 if ((elf_header
.e_machine
== EM_ALPHA
7035 || elf_header
.e_machine
== EM_S390
7036 || elf_header
.e_machine
== EM_S390_OLD
)
7037 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7041 (archive_file_offset
7042 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7043 sizeof nb
+ sizeof nc
)),
7046 error (_("Unable to seek to start of dynamic information"));
7050 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7052 error (_("Failed to read in number of buckets\n"));
7056 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7058 error (_("Failed to read in number of chains\n"));
7062 nbuckets
= byte_get (nb
, hash_ent_size
);
7063 nchains
= byte_get (nc
, hash_ent_size
);
7065 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7066 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7068 if (buckets
== NULL
|| chains
== NULL
)
7073 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
7078 printf (_("\nSymbol table for image:\n"));
7080 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7082 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7084 for (hn
= 0; hn
< nbuckets
; hn
++)
7089 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7091 Elf_Internal_Sym
*psym
;
7094 psym
= dynamic_symbols
+ si
;
7096 n
= print_vma (si
, DEC_5
);
7098 fputs (" " + n
, stdout
);
7099 printf (" %3lu: ", hn
);
7100 print_vma (psym
->st_value
, LONG_HEX
);
7102 print_vma (psym
->st_size
, DEC_5
);
7104 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7105 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7106 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7107 /* Check to see if any other bits in the st_other field are set.
7108 Note - displaying this information disrupts the layout of the
7109 table being generated, but for the moment this case is very rare. */
7110 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7111 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7112 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7113 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7114 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7116 printf (" <corrupt: %14ld>", psym
->st_name
);
7121 else if (do_syms
&& !do_using_dynamic
)
7125 for (i
= 0, section
= section_headers
;
7126 i
< elf_header
.e_shnum
;
7130 char *strtab
= NULL
;
7131 unsigned long int strtab_size
= 0;
7132 Elf_Internal_Sym
*symtab
;
7133 Elf_Internal_Sym
*psym
;
7136 if ( section
->sh_type
!= SHT_SYMTAB
7137 && section
->sh_type
!= SHT_DYNSYM
)
7140 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7141 SECTION_NAME (section
),
7142 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7144 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7146 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7148 symtab
= GET_ELF_SYMBOLS (file
, section
);
7152 if (section
->sh_link
== elf_header
.e_shstrndx
)
7154 strtab
= string_table
;
7155 strtab_size
= string_table_length
;
7157 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
7159 Elf_Internal_Shdr
*string_sec
;
7161 string_sec
= SECTION_HEADER (section
->sh_link
);
7163 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
7164 1, string_sec
->sh_size
, _("string table"));
7165 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7168 for (si
= 0, psym
= symtab
;
7169 si
< section
->sh_size
/ section
->sh_entsize
;
7172 printf ("%6d: ", si
);
7173 print_vma (psym
->st_value
, LONG_HEX
);
7175 print_vma (psym
->st_size
, DEC_5
);
7176 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7177 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7178 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7179 /* Check to see if any other bits in the st_other field are set.
7180 Note - displaying this information disrupts the layout of the
7181 table being generated, but for the moment this case is very rare. */
7182 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7183 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7184 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7185 print_symbol (25, psym
->st_name
< strtab_size
7186 ? strtab
+ psym
->st_name
: "<corrupt>");
7188 if (section
->sh_type
== SHT_DYNSYM
&&
7189 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7191 unsigned char data
[2];
7192 unsigned short vers_data
;
7193 unsigned long offset
;
7197 offset
= offset_from_vma
7198 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7199 sizeof data
+ si
* sizeof (vers_data
));
7201 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7202 sizeof (data
), 1, _("version data"));
7204 vers_data
= byte_get (data
, 2);
7206 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7207 < elf_header
.e_shnum
7208 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7211 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7213 if ((vers_data
& 0x8000) || vers_data
> 1)
7215 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7216 && (is_nobits
|| ! check_def
))
7218 Elf_External_Verneed evn
;
7219 Elf_Internal_Verneed ivn
;
7220 Elf_Internal_Vernaux ivna
;
7222 /* We must test both. */
7223 offset
= offset_from_vma
7224 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7229 unsigned long vna_off
;
7231 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7234 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7235 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7237 vna_off
= offset
+ ivn
.vn_aux
;
7241 Elf_External_Vernaux evna
;
7243 get_data (&evna
, file
, vna_off
,
7245 _("version need aux (3)"));
7247 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7248 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7249 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7251 vna_off
+= ivna
.vna_next
;
7253 while (ivna
.vna_other
!= vers_data
7254 && ivna
.vna_next
!= 0);
7256 if (ivna
.vna_other
== vers_data
)
7259 offset
+= ivn
.vn_next
;
7261 while (ivn
.vn_next
!= 0);
7263 if (ivna
.vna_other
== vers_data
)
7266 ivna
.vna_name
< strtab_size
7267 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7271 else if (! is_nobits
)
7272 error (_("bad dynamic symbol"));
7279 if (vers_data
!= 0x8001
7280 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7282 Elf_Internal_Verdef ivd
;
7283 Elf_Internal_Verdaux ivda
;
7284 Elf_External_Verdaux evda
;
7285 unsigned long offset
;
7287 offset
= offset_from_vma
7289 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7290 sizeof (Elf_External_Verdef
));
7294 Elf_External_Verdef evd
;
7296 get_data (&evd
, file
, offset
, sizeof (evd
),
7297 1, _("version def"));
7299 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7300 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7301 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7303 offset
+= ivd
.vd_next
;
7305 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7306 && ivd
.vd_next
!= 0);
7308 offset
-= ivd
.vd_next
;
7309 offset
+= ivd
.vd_aux
;
7311 get_data (&evda
, file
, offset
, sizeof (evda
),
7312 1, _("version def aux"));
7314 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7316 if (psym
->st_name
!= ivda
.vda_name
)
7317 printf ((vers_data
& 0x8000)
7319 ivda
.vda_name
< strtab_size
7320 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7330 if (strtab
!= string_table
)
7336 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7338 if (do_histogram
&& buckets
!= NULL
)
7340 unsigned long *lengths
;
7341 unsigned long *counts
;
7344 unsigned long maxlength
= 0;
7345 unsigned long nzero_counts
= 0;
7346 unsigned long nsyms
= 0;
7348 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7349 (unsigned long) nbuckets
);
7350 printf (_(" Length Number %% of total Coverage\n"));
7352 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7353 if (lengths
== NULL
)
7355 error (_("Out of memory"));
7358 for (hn
= 0; hn
< nbuckets
; ++hn
)
7360 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7363 if (maxlength
< ++lengths
[hn
])
7368 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7371 error (_("Out of memory"));
7375 for (hn
= 0; hn
< nbuckets
; ++hn
)
7376 ++counts
[lengths
[hn
]];
7381 printf (" 0 %-10lu (%5.1f%%)\n",
7382 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7383 for (i
= 1; i
<= maxlength
; ++i
)
7385 nzero_counts
+= counts
[i
] * i
;
7386 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7387 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7388 (nzero_counts
* 100.0) / nsyms
);
7396 if (buckets
!= NULL
)
7402 if (do_histogram
&& dynamic_info_DT_GNU_HASH
)
7404 unsigned char nb
[16];
7405 bfd_vma i
, maxchain
= 0xffffffff, symidx
, bitmaskwords
;
7406 unsigned long *lengths
;
7407 unsigned long *counts
;
7409 unsigned long maxlength
= 0;
7410 unsigned long nzero_counts
= 0;
7411 unsigned long nsyms
= 0;
7412 bfd_vma buckets_vma
;
7415 (archive_file_offset
7416 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7420 error (_("Unable to seek to start of dynamic information"));
7424 if (fread (nb
, 16, 1, file
) != 1)
7426 error (_("Failed to read in number of buckets\n"));
7430 ngnubuckets
= byte_get (nb
, 4);
7431 symidx
= byte_get (nb
+ 4, 4);
7432 bitmaskwords
= byte_get (nb
+ 8, 4);
7433 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7435 buckets_vma
+= bitmaskwords
* 4;
7437 buckets_vma
+= bitmaskwords
* 8;
7440 (archive_file_offset
7441 + offset_from_vma (file
, buckets_vma
, 4)),
7444 error (_("Unable to seek to start of dynamic information"));
7448 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7450 if (gnubuckets
== NULL
)
7453 for (i
= 0; i
< ngnubuckets
; i
++)
7454 if (gnubuckets
[i
] != 0)
7456 if (gnubuckets
[i
] < symidx
)
7459 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7460 maxchain
= gnubuckets
[i
];
7463 if (maxchain
== 0xffffffff)
7469 (archive_file_offset
7470 + offset_from_vma (file
, buckets_vma
7471 + 4 * (ngnubuckets
+ maxchain
), 4)),
7474 error (_("Unable to seek to start of dynamic information"));
7480 if (fread (nb
, 4, 1, file
) != 1)
7482 error (_("Failed to determine last chain length\n"));
7486 if (maxchain
+ 1 == 0)
7491 while ((byte_get (nb
, 4) & 1) == 0);
7494 (archive_file_offset
7495 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7498 error (_("Unable to seek to start of dynamic information"));
7502 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7504 if (gnuchains
== NULL
)
7507 lengths
= calloc (ngnubuckets
, sizeof (*lengths
));
7508 if (lengths
== NULL
)
7510 error (_("Out of memory"));
7514 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7515 (unsigned long) ngnubuckets
);
7516 printf (_(" Length Number %% of total Coverage\n"));
7518 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7519 if (gnubuckets
[hn
] != 0)
7521 bfd_vma off
, length
= 1;
7523 for (off
= gnubuckets
[hn
] - symidx
;
7524 (gnuchains
[off
] & 1) == 0; ++off
)
7526 lengths
[hn
] = length
;
7527 if (length
> maxlength
)
7532 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7535 error (_("Out of memory"));
7539 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7540 ++counts
[lengths
[hn
]];
7542 if (ngnubuckets
> 0)
7545 printf (" 0 %-10lu (%5.1f%%)\n",
7546 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7547 for (j
= 1; j
<= maxlength
; ++j
)
7549 nzero_counts
+= counts
[j
] * j
;
7550 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7551 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7552 (nzero_counts
* 100.0) / nsyms
);
7566 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7570 if (dynamic_syminfo
== NULL
7572 /* No syminfo, this is ok. */
7575 /* There better should be a dynamic symbol section. */
7576 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7580 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7581 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7583 printf (_(" Num: Name BoundTo Flags\n"));
7584 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7586 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7588 printf ("%4d: ", i
);
7589 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7590 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7592 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7595 switch (dynamic_syminfo
[i
].si_boundto
)
7597 case SYMINFO_BT_SELF
:
7598 fputs ("SELF ", stdout
);
7600 case SYMINFO_BT_PARENT
:
7601 fputs ("PARENT ", stdout
);
7604 if (dynamic_syminfo
[i
].si_boundto
> 0
7605 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7606 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7608 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7612 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7616 if (flags
& SYMINFO_FLG_DIRECT
)
7618 if (flags
& SYMINFO_FLG_PASSTHRU
)
7619 printf (" PASSTHRU");
7620 if (flags
& SYMINFO_FLG_COPY
)
7622 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7623 printf (" LAZYLOAD");
7631 #ifdef SUPPORT_DISASSEMBLY
7633 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7635 printf (_("\nAssembly dump of section %s\n"),
7636 SECTION_NAME (section
));
7638 /* XXX -- to be done --- XXX */
7645 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
7647 bfd_size_type bytes
;
7649 unsigned char *data
;
7650 unsigned char *start
;
7652 bytes
= section
->sh_size
;
7654 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7656 printf (_("\nSection '%s' has no data to dump.\n"),
7657 SECTION_NAME (section
));
7661 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7663 addr
= section
->sh_addr
;
7665 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7678 lbytes
= (bytes
> 16 ? 16 : bytes
);
7680 printf (" 0x%8.8lx ", (unsigned long) addr
);
7682 for (j
= 0; j
< 16; j
++)
7685 printf ("%2.2x", data
[j
]);
7693 for (j
= 0; j
< lbytes
; j
++)
7696 if (k
>= ' ' && k
< 0x7f)
7714 /* Apply addends of RELA relocations. */
7717 debug_apply_rela_addends (void *file
,
7718 Elf_Internal_Shdr
*section
,
7719 unsigned char *start
)
7721 Elf_Internal_Shdr
*relsec
;
7722 unsigned char *end
= start
+ section
->sh_size
;
7723 /* FIXME: The relocation field size is relocation type dependent. */
7724 unsigned int reloc_size
= 4;
7726 if (!is_relocatable
)
7729 if (section
->sh_size
< reloc_size
)
7732 for (relsec
= section_headers
;
7733 relsec
< section_headers
+ elf_header
.e_shnum
;
7736 unsigned long nrelas
;
7737 Elf_Internal_Rela
*rela
, *rp
;
7738 Elf_Internal_Shdr
*symsec
;
7739 Elf_Internal_Sym
*symtab
;
7740 Elf_Internal_Sym
*sym
;
7742 if (relsec
->sh_type
!= SHT_RELA
7743 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7744 || SECTION_HEADER (relsec
->sh_info
) != section
7745 || relsec
->sh_size
== 0
7746 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7749 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7753 symsec
= SECTION_HEADER (relsec
->sh_link
);
7754 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7756 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7760 loc
= start
+ rp
->r_offset
;
7761 if ((loc
+ reloc_size
) > end
)
7763 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7764 (unsigned long) rp
->r_offset
,
7765 SECTION_NAME (section
));
7771 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7773 if (ELF32_R_SYM (rp
->r_info
) != 0
7774 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7775 /* Relocations against symbols without type can happen.
7776 Gcc -feliminate-dwarf2-dups may generate symbols
7777 without type for debug info. */
7778 && ELF32_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7779 /* Relocations against object symbols can happen,
7780 eg when referencing a global array. For an
7781 example of this see the _clz.o binary in libgcc.a. */
7782 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7784 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7785 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7786 SECTION_NAME (section
));
7792 /* In MIPS little-endian objects, r_info isn't really a
7793 64-bit little-endian value: it has a 32-bit little-endian
7794 symbol index followed by four individual byte fields.
7795 Reorder INFO accordingly. */
7796 if (elf_header
.e_machine
== EM_MIPS
7797 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7798 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7799 | ((rp
->r_info
>> 56) & 0xff)
7800 | ((rp
->r_info
>> 40) & 0xff00)
7801 | ((rp
->r_info
>> 24) & 0xff0000)
7802 | ((rp
->r_info
>> 8) & 0xff000000));
7804 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7806 if (ELF64_R_SYM (rp
->r_info
) != 0
7807 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7808 && ELF64_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7809 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7811 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7812 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7813 SECTION_NAME (section
));
7818 byte_put (loc
, rp
->r_addend
, reloc_size
);
7829 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
7831 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7832 Elf_Internal_Shdr
*sec
;
7835 /* If it is already loaded, do nothing. */
7836 if (section
->start
!= NULL
)
7839 /* Locate the debug section. */
7840 sec
= find_section (section
->name
);
7844 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
7845 section
->address
= sec
->sh_addr
;
7846 section
->size
= sec
->sh_size
;
7847 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
7850 if (debug_displays
[debug
].relocate
)
7851 debug_apply_rela_addends (file
, sec
, section
->start
);
7853 return section
->start
!= NULL
;
7857 free_debug_section (enum dwarf_section_display_enum debug
)
7859 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7861 if (section
->start
== NULL
)
7864 free ((char *) section
->start
);
7865 section
->start
= NULL
;
7866 section
->address
= 0;
7871 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
7873 char *name
= SECTION_NAME (section
);
7874 bfd_size_type length
;
7876 enum dwarf_section_display_enum i
;
7878 length
= section
->sh_size
;
7881 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7885 if (const_strneq (name
, ".gnu.linkonce.wi."))
7886 name
= ".debug_info";
7888 /* See if we know how to display the contents of this section. */
7889 for (i
= 0; i
< max
; i
++)
7890 if (streq (debug_displays
[i
].section
.name
, name
))
7892 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
7894 if (load_debug_section (i
, file
))
7896 result
&= debug_displays
[i
].display (sec
, file
);
7898 if (i
!= info
&& i
!= abbrev
)
7899 free_debug_section (i
);
7907 printf (_("Unrecognized debug section: %s\n"), name
);
7914 /* Set DUMP_SECTS for all sections where dumps were requested
7915 based on section name. */
7918 initialise_dumps_byname (void)
7920 struct dump_list_entry
*cur
;
7922 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
7927 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
7928 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
7930 request_dump (i
, cur
->type
);
7935 warn (_("Section '%s' was not dumped because it does not exist!\n"),
7941 process_section_contents (FILE *file
)
7943 Elf_Internal_Shdr
*section
;
7949 initialise_dumps_byname ();
7951 for (i
= 0, section
= section_headers
;
7952 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
7955 #ifdef SUPPORT_DISASSEMBLY
7956 if (dump_sects
[i
] & DISASS_DUMP
)
7957 disassemble_section (section
, file
);
7959 if (dump_sects
[i
] & HEX_DUMP
)
7960 dump_section (section
, file
);
7962 if (dump_sects
[i
] & DEBUG_DUMP
)
7963 display_debug_section (section
, file
);
7966 /* Check to see if the user requested a
7967 dump of a section that does not exist. */
7968 while (i
++ < num_dump_sects
)
7970 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
7974 process_mips_fpe_exception (int mask
)
7979 if (mask
& OEX_FPU_INEX
)
7980 fputs ("INEX", stdout
), first
= 0;
7981 if (mask
& OEX_FPU_UFLO
)
7982 printf ("%sUFLO", first
? "" : "|"), first
= 0;
7983 if (mask
& OEX_FPU_OFLO
)
7984 printf ("%sOFLO", first
? "" : "|"), first
= 0;
7985 if (mask
& OEX_FPU_DIV0
)
7986 printf ("%sDIV0", first
? "" : "|"), first
= 0;
7987 if (mask
& OEX_FPU_INVAL
)
7988 printf ("%sINVAL", first
? "" : "|");
7991 fputs ("0", stdout
);
7994 /* ARM EABI attributes section. */
7999 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8002 } arm_attr_public_tag
;
8004 static const char *arm_attr_tag_CPU_arch
[] =
8005 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8007 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8008 static const char *arm_attr_tag_THUMB_ISA_use
[] =
8009 {"No", "Thumb-1", "Thumb-2"};
8010 /* FIXME: VFPv3 encoding was extrapolated! */
8011 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
8012 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
8013 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
8014 static const char *arm_attr_tag_ABI_PCS_config
[] =
8015 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8016 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8017 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
8018 {"V6", "SB", "TLS", "Unused"};
8019 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
8020 {"Absolute", "PC-relative", "SB-relative", "None"};
8021 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
8022 {"Absolute", "PC-relative", "None"};
8023 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
8024 {"None", "direct", "GOT-indirect"};
8025 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
8026 {"None", "??? 1", "2", "??? 3", "4"};
8027 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8028 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
8029 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8030 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8031 static const char *arm_attr_tag_ABI_FP_number_model
[] =
8032 {"Unused", "Finite", "RTABI", "IEEE 754"};
8033 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8034 static const char *arm_attr_tag_ABI_align8_preserved
[] =
8035 {"No", "Yes, except leaf SP", "Yes"};
8036 static const char *arm_attr_tag_ABI_enum_size
[] =
8037 {"Unused", "small", "int", "forced to int"};
8038 static const char *arm_attr_tag_ABI_HardFP_use
[] =
8039 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8040 static const char *arm_attr_tag_ABI_VFP_args
[] =
8041 {"AAPCS", "VFP registers", "custom"};
8042 static const char *arm_attr_tag_ABI_WMMX_args
[] =
8043 {"AAPCS", "WMMX registers", "custom"};
8044 static const char *arm_attr_tag_ABI_optimization_goals
[] =
8045 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8046 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8047 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
8048 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8049 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8051 #define LOOKUP(id, name) \
8052 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8053 static arm_attr_public_tag arm_attr_public_tags
[] =
8055 {4, "CPU_raw_name", 1, NULL
},
8056 {5, "CPU_name", 1, NULL
},
8057 LOOKUP(6, CPU_arch
),
8058 {7, "CPU_arch_profile", 0, NULL
},
8059 LOOKUP(8, ARM_ISA_use
),
8060 LOOKUP(9, THUMB_ISA_use
),
8061 LOOKUP(10, VFP_arch
),
8062 LOOKUP(11, WMMX_arch
),
8063 LOOKUP(12, NEON_arch
),
8064 LOOKUP(13, ABI_PCS_config
),
8065 LOOKUP(14, ABI_PCS_R9_use
),
8066 LOOKUP(15, ABI_PCS_RW_data
),
8067 LOOKUP(16, ABI_PCS_RO_DATA
),
8068 LOOKUP(17, ABI_PCS_GOT_use
),
8069 LOOKUP(18, ABI_PCS_wchar_t
),
8070 LOOKUP(19, ABI_FP_rounding
),
8071 LOOKUP(20, ABI_FP_denormal
),
8072 LOOKUP(21, ABI_FP_exceptions
),
8073 LOOKUP(22, ABI_FP_user_exceptions
),
8074 LOOKUP(23, ABI_FP_number_model
),
8075 LOOKUP(24, ABI_align8_needed
),
8076 LOOKUP(25, ABI_align8_preserved
),
8077 LOOKUP(26, ABI_enum_size
),
8078 LOOKUP(27, ABI_HardFP_use
),
8079 LOOKUP(28, ABI_VFP_args
),
8080 LOOKUP(29, ABI_WMMX_args
),
8081 LOOKUP(30, ABI_optimization_goals
),
8082 LOOKUP(31, ABI_FP_optimization_goals
),
8083 {32, "compatibility", 0, NULL
}
8087 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8090 read_uleb128 (unsigned char *p
, unsigned int *plen
)
8104 val
|= ((unsigned int)c
& 0x7f) << shift
;
8113 static unsigned char *
8114 display_arm_attribute (unsigned char *p
)
8119 arm_attr_public_tag
*attr
;
8123 tag
= read_uleb128 (p
, &len
);
8126 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
8128 if (arm_attr_public_tags
[i
].tag
== tag
)
8130 attr
= &arm_attr_public_tags
[i
];
8137 printf (" Tag_%s: ", attr
->name
);
8143 case 7: /* Tag_CPU_arch_profile. */
8144 val
= read_uleb128 (p
, &len
);
8148 case 0: printf ("None\n"); break;
8149 case 'A': printf ("Application\n"); break;
8150 case 'R': printf ("Realtime\n"); break;
8151 case 'M': printf ("Microcontroller\n"); break;
8152 default: printf ("??? (%d)\n", val
); break;
8156 case 32: /* Tag_compatibility. */
8157 val
= read_uleb128 (p
, &len
);
8159 printf ("flag = %d, vendor = %s\n", val
, p
);
8160 p
+= strlen((char *)p
) + 1;
8174 assert (attr
->type
& 0x80);
8175 val
= read_uleb128 (p
, &len
);
8177 type
= attr
->type
& 0x7f;
8179 printf ("??? (%d)\n", val
);
8181 printf ("%s\n", attr
->table
[val
]);
8188 type
= 1; /* String. */
8190 type
= 2; /* uleb128. */
8191 printf (" Tag_unknown_%d: ", tag
);
8196 printf ("\"%s\"\n", p
);
8197 p
+= strlen((char *)p
) + 1;
8201 val
= read_uleb128 (p
, &len
);
8203 printf ("%d (0x%x)\n", val
, val
);
8210 process_arm_specific (FILE *file
)
8212 Elf_Internal_Shdr
*sect
;
8213 unsigned char *contents
;
8216 bfd_vma section_len
;
8220 /* Find the section header so that we get the size. */
8221 for (i
= 0, sect
= section_headers
;
8222 i
< elf_header
.e_shnum
;
8225 if (sect
->sh_type
!= SHT_ARM_ATTRIBUTES
)
8228 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
8236 len
= sect
->sh_size
- 1;
8241 bfd_boolean public_section
;
8243 section_len
= byte_get (p
, 4);
8245 if (section_len
> len
)
8247 printf (_("ERROR: Bad section length (%d > %d)\n"),
8248 (int)section_len
, (int)len
);
8252 printf ("Attribute Section: %s\n", p
);
8253 if (strcmp ((char *)p
, "aeabi") == 0)
8254 public_section
= TRUE
;
8256 public_section
= FALSE
;
8257 namelen
= strlen ((char *)p
) + 1;
8259 section_len
-= namelen
+ 4;
8260 while (section_len
> 0)
8265 size
= byte_get (p
, 4);
8266 if (size
> section_len
)
8268 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
8269 (int)size
, (int)section_len
);
8272 section_len
-= size
;
8278 printf ("File Attributes\n");
8281 printf ("Section Attributes:");
8284 printf ("Symbol Attributes:");
8289 val
= read_uleb128 (p
, &i
);
8293 printf (" %d", val
);
8298 printf ("Unknown tag: %d\n", tag
);
8299 public_section
= FALSE
;
8305 p
= display_arm_attribute(p
);
8309 /* ??? Do something sensible, like dump hex. */
8310 printf (" Unknown section contexts\n");
8318 printf (_("Unknown format '%c'\n"), *p
);
8327 process_mips_specific (FILE *file
)
8329 Elf_Internal_Dyn
*entry
;
8330 size_t liblist_offset
= 0;
8331 size_t liblistno
= 0;
8332 size_t conflictsno
= 0;
8333 size_t options_offset
= 0;
8334 size_t conflicts_offset
= 0;
8336 /* We have a lot of special sections. Thanks SGI! */
8337 if (dynamic_section
== NULL
)
8338 /* No information available. */
8341 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
8342 switch (entry
->d_tag
)
8344 case DT_MIPS_LIBLIST
:
8346 = offset_from_vma (file
, entry
->d_un
.d_val
,
8347 liblistno
* sizeof (Elf32_External_Lib
));
8349 case DT_MIPS_LIBLISTNO
:
8350 liblistno
= entry
->d_un
.d_val
;
8352 case DT_MIPS_OPTIONS
:
8353 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
8355 case DT_MIPS_CONFLICT
:
8357 = offset_from_vma (file
, entry
->d_un
.d_val
,
8358 conflictsno
* sizeof (Elf32_External_Conflict
));
8360 case DT_MIPS_CONFLICTNO
:
8361 conflictsno
= entry
->d_un
.d_val
;
8367 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
8369 Elf32_External_Lib
*elib
;
8372 elib
= get_data (NULL
, file
, liblist_offset
,
8373 liblistno
, sizeof (Elf32_External_Lib
),
8377 printf ("\nSection '.liblist' contains %lu entries:\n",
8378 (unsigned long) liblistno
);
8379 fputs (" Library Time Stamp Checksum Version Flags\n",
8382 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
8389 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8390 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8391 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8392 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8393 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8395 tmp
= gmtime (&time
);
8396 snprintf (timebuf
, sizeof (timebuf
),
8397 "%04u-%02u-%02uT%02u:%02u:%02u",
8398 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8399 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8401 printf ("%3lu: ", (unsigned long) cnt
);
8402 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
8403 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
8405 printf ("<corrupt: %9ld>", liblist
.l_name
);
8406 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
8409 if (liblist
.l_flags
== 0)
8420 { " EXACT_MATCH", LL_EXACT_MATCH
},
8421 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
8422 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
8423 { " EXPORTS", LL_EXPORTS
},
8424 { " DELAY_LOAD", LL_DELAY_LOAD
},
8425 { " DELTA", LL_DELTA
}
8427 int flags
= liblist
.l_flags
;
8431 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
8433 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
8435 fputs (l_flags_vals
[fcnt
].name
, stdout
);
8436 flags
^= l_flags_vals
[fcnt
].bit
;
8439 printf (" %#x", (unsigned int) flags
);
8449 if (options_offset
!= 0)
8451 Elf_External_Options
*eopt
;
8452 Elf_Internal_Shdr
*sect
= section_headers
;
8453 Elf_Internal_Options
*iopt
;
8454 Elf_Internal_Options
*option
;
8458 /* Find the section header so that we get the size. */
8459 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
8462 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
8466 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
8469 error (_("Out of memory"));
8476 while (offset
< sect
->sh_size
)
8478 Elf_External_Options
*eoption
;
8480 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
8482 option
->kind
= BYTE_GET (eoption
->kind
);
8483 option
->size
= BYTE_GET (eoption
->size
);
8484 option
->section
= BYTE_GET (eoption
->section
);
8485 option
->info
= BYTE_GET (eoption
->info
);
8487 offset
+= option
->size
;
8493 printf (_("\nSection '%s' contains %d entries:\n"),
8494 SECTION_NAME (sect
), cnt
);
8502 switch (option
->kind
)
8505 /* This shouldn't happen. */
8506 printf (" NULL %d %lx", option
->section
, option
->info
);
8509 printf (" REGINFO ");
8510 if (elf_header
.e_machine
== EM_MIPS
)
8513 Elf32_External_RegInfo
*ereg
;
8514 Elf32_RegInfo reginfo
;
8516 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
8517 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8518 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8519 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8520 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8521 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8522 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8524 printf ("GPR %08lx GP 0x%lx\n",
8526 (unsigned long) reginfo
.ri_gp_value
);
8527 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8528 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8529 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8534 Elf64_External_RegInfo
*ereg
;
8535 Elf64_Internal_RegInfo reginfo
;
8537 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
8538 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8539 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8540 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8541 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8542 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8543 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8545 printf ("GPR %08lx GP 0x",
8546 reginfo
.ri_gprmask
);
8547 printf_vma (reginfo
.ri_gp_value
);
8550 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8551 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8552 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8556 case ODK_EXCEPTIONS
:
8557 fputs (" EXCEPTIONS fpe_min(", stdout
);
8558 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
8559 fputs (") fpe_max(", stdout
);
8560 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
8561 fputs (")", stdout
);
8563 if (option
->info
& OEX_PAGE0
)
8564 fputs (" PAGE0", stdout
);
8565 if (option
->info
& OEX_SMM
)
8566 fputs (" SMM", stdout
);
8567 if (option
->info
& OEX_FPDBUG
)
8568 fputs (" FPDBUG", stdout
);
8569 if (option
->info
& OEX_DISMISS
)
8570 fputs (" DISMISS", stdout
);
8573 fputs (" PAD ", stdout
);
8574 if (option
->info
& OPAD_PREFIX
)
8575 fputs (" PREFIX", stdout
);
8576 if (option
->info
& OPAD_POSTFIX
)
8577 fputs (" POSTFIX", stdout
);
8578 if (option
->info
& OPAD_SYMBOL
)
8579 fputs (" SYMBOL", stdout
);
8582 fputs (" HWPATCH ", stdout
);
8583 if (option
->info
& OHW_R4KEOP
)
8584 fputs (" R4KEOP", stdout
);
8585 if (option
->info
& OHW_R8KPFETCH
)
8586 fputs (" R8KPFETCH", stdout
);
8587 if (option
->info
& OHW_R5KEOP
)
8588 fputs (" R5KEOP", stdout
);
8589 if (option
->info
& OHW_R5KCVTL
)
8590 fputs (" R5KCVTL", stdout
);
8593 fputs (" FILL ", stdout
);
8594 /* XXX Print content of info word? */
8597 fputs (" TAGS ", stdout
);
8598 /* XXX Print content of info word? */
8601 fputs (" HWAND ", stdout
);
8602 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8603 fputs (" R4KEOP_CHECKED", stdout
);
8604 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8605 fputs (" R4KEOP_CLEAN", stdout
);
8608 fputs (" HWOR ", stdout
);
8609 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8610 fputs (" R4KEOP_CHECKED", stdout
);
8611 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8612 fputs (" R4KEOP_CLEAN", stdout
);
8615 printf (" GP_GROUP %#06lx self-contained %#06lx",
8616 option
->info
& OGP_GROUP
,
8617 (option
->info
& OGP_SELF
) >> 16);
8620 printf (" IDENT %#06lx self-contained %#06lx",
8621 option
->info
& OGP_GROUP
,
8622 (option
->info
& OGP_SELF
) >> 16);
8625 /* This shouldn't happen. */
8626 printf (" %3d ??? %d %lx",
8627 option
->kind
, option
->section
, option
->info
);
8631 len
= sizeof (*eopt
);
8632 while (len
< option
->size
)
8633 if (((char *) option
)[len
] >= ' '
8634 && ((char *) option
)[len
] < 0x7f)
8635 printf ("%c", ((char *) option
)[len
++]);
8637 printf ("\\%03o", ((char *) option
)[len
++]);
8639 fputs ("\n", stdout
);
8647 if (conflicts_offset
!= 0 && conflictsno
!= 0)
8649 Elf32_Conflict
*iconf
;
8652 if (dynamic_symbols
== NULL
)
8654 error (_("conflict list found without a dynamic symbol table"));
8658 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
8661 error (_("Out of memory"));
8667 Elf32_External_Conflict
*econf32
;
8669 econf32
= get_data (NULL
, file
, conflicts_offset
,
8670 conflictsno
, sizeof (*econf32
), _("conflict"));
8674 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8675 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
8681 Elf64_External_Conflict
*econf64
;
8683 econf64
= get_data (NULL
, file
, conflicts_offset
,
8684 conflictsno
, sizeof (*econf64
), _("conflict"));
8688 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8689 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
8694 printf (_("\nSection '.conflict' contains %lu entries:\n"),
8695 (unsigned long) conflictsno
);
8696 puts (_(" Num: Index Value Name"));
8698 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8700 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
8702 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
8703 print_vma (psym
->st_value
, FULL_HEX
);
8705 if (VALID_DYNAMIC_NAME (psym
->st_name
))
8706 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
8708 printf ("<corrupt: %14ld>", psym
->st_name
);
8719 process_gnu_liblist (FILE *file
)
8721 Elf_Internal_Shdr
*section
, *string_sec
;
8722 Elf32_External_Lib
*elib
;
8731 for (i
= 0, section
= section_headers
;
8732 i
< elf_header
.e_shnum
;
8735 switch (section
->sh_type
)
8737 case SHT_GNU_LIBLIST
:
8738 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
8741 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
8746 string_sec
= SECTION_HEADER (section
->sh_link
);
8748 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
8749 string_sec
->sh_size
, _("liblist string table"));
8750 strtab_size
= string_sec
->sh_size
;
8753 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
8759 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
8760 SECTION_NAME (section
),
8761 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
8763 puts (" Library Time Stamp Checksum Version Flags");
8765 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
8773 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8774 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8775 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8776 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8777 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8779 tmp
= gmtime (&time
);
8780 snprintf (timebuf
, sizeof (timebuf
),
8781 "%04u-%02u-%02uT%02u:%02u:%02u",
8782 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8783 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8785 printf ("%3lu: ", (unsigned long) cnt
);
8787 printf ("%-20s", liblist
.l_name
< strtab_size
8788 ? strtab
+ liblist
.l_name
: "<corrupt>");
8790 printf ("%-20.20s", liblist
.l_name
< strtab_size
8791 ? strtab
+ liblist
.l_name
: "<corrupt>");
8792 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
8793 liblist
.l_version
, liblist
.l_flags
);
8804 get_note_type (unsigned e_type
)
8806 static char buff
[64];
8808 if (elf_header
.e_type
== ET_CORE
)
8812 return _("NT_AUXV (auxiliary vector)");
8814 return _("NT_PRSTATUS (prstatus structure)");
8816 return _("NT_FPREGSET (floating point registers)");
8818 return _("NT_PRPSINFO (prpsinfo structure)");
8820 return _("NT_TASKSTRUCT (task structure)");
8822 return _("NT_PRXFPREG (user_xfpregs structure)");
8824 return _("NT_PSTATUS (pstatus structure)");
8826 return _("NT_FPREGS (floating point registers)");
8828 return _("NT_PSINFO (psinfo structure)");
8830 return _("NT_LWPSTATUS (lwpstatus_t structure)");
8832 return _("NT_LWPSINFO (lwpsinfo_t structure)");
8833 case NT_WIN32PSTATUS
:
8834 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8842 return _("NT_VERSION (version)");
8844 return _("NT_ARCH (architecture)");
8849 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8854 get_netbsd_elfcore_note_type (unsigned e_type
)
8856 static char buff
[64];
8858 if (e_type
== NT_NETBSDCORE_PROCINFO
)
8860 /* NetBSD core "procinfo" structure. */
8861 return _("NetBSD procinfo structure");
8864 /* As of Jan 2002 there are no other machine-independent notes
8865 defined for NetBSD core files. If the note type is less
8866 than the start of the machine-dependent note types, we don't
8869 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
8871 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8875 switch (elf_header
.e_machine
)
8877 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8878 and PT_GETFPREGS == mach+2. */
8883 case EM_SPARC32PLUS
:
8887 case NT_NETBSDCORE_FIRSTMACH
+0:
8888 return _("PT_GETREGS (reg structure)");
8889 case NT_NETBSDCORE_FIRSTMACH
+2:
8890 return _("PT_GETFPREGS (fpreg structure)");
8896 /* On all other arch's, PT_GETREGS == mach+1 and
8897 PT_GETFPREGS == mach+3. */
8901 case NT_NETBSDCORE_FIRSTMACH
+1:
8902 return _("PT_GETREGS (reg structure)");
8903 case NT_NETBSDCORE_FIRSTMACH
+3:
8904 return _("PT_GETFPREGS (fpreg structure)");
8910 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
8911 e_type
- NT_NETBSDCORE_FIRSTMACH
);
8915 /* Note that by the ELF standard, the name field is already null byte
8916 terminated, and namesz includes the terminating null byte.
8917 I.E. the value of namesz for the name "FSF" is 4.
8919 If the value of namesz is zero, there is no name present. */
8921 process_note (Elf_Internal_Note
*pnote
)
8925 if (pnote
->namesz
== 0)
8926 /* If there is no note name, then use the default set of
8927 note type strings. */
8928 nt
= get_note_type (pnote
->type
);
8930 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
8931 /* NetBSD-specific core file notes. */
8932 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
8935 /* Don't recognize this note name; just use the default set of
8936 note type strings. */
8937 nt
= get_note_type (pnote
->type
);
8939 printf (" %s\t\t0x%08lx\t%s\n",
8940 pnote
->namesz
? pnote
->namedata
: "(NONE)",
8947 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
8949 Elf_External_Note
*pnotes
;
8950 Elf_External_Note
*external
;
8956 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
8962 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8963 (unsigned long) offset
, (unsigned long) length
);
8964 printf (_(" Owner\t\tData size\tDescription\n"));
8966 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
8968 Elf_External_Note
*next
;
8969 Elf_Internal_Note inote
;
8972 inote
.type
= BYTE_GET (external
->type
);
8973 inote
.namesz
= BYTE_GET (external
->namesz
);
8974 inote
.namedata
= external
->name
;
8975 inote
.descsz
= BYTE_GET (external
->descsz
);
8976 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
8977 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
8979 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
8981 if (((char *) next
) > (((char *) pnotes
) + length
))
8983 warn (_("corrupt note found at offset %lx into core notes\n"),
8984 (long)((char *)external
- (char *)pnotes
));
8985 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
8986 inote
.type
, inote
.namesz
, inote
.descsz
);
8992 /* Verify that name is null terminated. It appears that at least
8993 one version of Linux (RedHat 6.0) generates corefiles that don't
8994 comply with the ELF spec by failing to include the null byte in
8996 if (inote
.namedata
[inote
.namesz
] != '\0')
8998 temp
= malloc (inote
.namesz
+ 1);
9002 error (_("Out of memory\n"));
9007 strncpy (temp
, inote
.namedata
, inote
.namesz
);
9008 temp
[inote
.namesz
] = 0;
9010 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9011 inote
.namedata
= temp
;
9014 res
&= process_note (& inote
);
9029 process_corefile_note_segments (FILE *file
)
9031 Elf_Internal_Phdr
*segment
;
9035 if (! get_program_headers (file
))
9038 for (i
= 0, segment
= program_headers
;
9039 i
< elf_header
.e_phnum
;
9042 if (segment
->p_type
== PT_NOTE
)
9043 res
&= process_corefile_note_segment (file
,
9044 (bfd_vma
) segment
->p_offset
,
9045 (bfd_vma
) segment
->p_filesz
);
9052 process_note_sections (FILE *file
)
9054 Elf_Internal_Shdr
*section
;
9058 for (i
= 0, section
= section_headers
;
9059 i
< elf_header
.e_shnum
;
9061 if (section
->sh_type
== SHT_NOTE
)
9062 res
&= process_corefile_note_segment (file
,
9063 (bfd_vma
) section
->sh_offset
,
9064 (bfd_vma
) section
->sh_size
);
9070 process_notes (FILE *file
)
9072 /* If we have not been asked to display the notes then do nothing. */
9076 if (elf_header
.e_type
!= ET_CORE
)
9077 return process_note_sections (file
);
9079 /* No program headers means no NOTE segment. */
9080 if (elf_header
.e_phnum
> 0)
9081 return process_corefile_note_segments (file
);
9083 printf (_("No note segments present in the core file.\n"));
9088 process_arch_specific (FILE *file
)
9093 switch (elf_header
.e_machine
)
9096 return process_arm_specific (file
);
9098 case EM_MIPS_RS3_LE
:
9099 return process_mips_specific (file
);
9108 get_file_header (FILE *file
)
9110 /* Read in the identity array. */
9111 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
9114 /* Determine how to read the rest of the header. */
9115 switch (elf_header
.e_ident
[EI_DATA
])
9117 default: /* fall through */
9118 case ELFDATANONE
: /* fall through */
9120 byte_get
= byte_get_little_endian
;
9121 byte_put
= byte_put_little_endian
;
9124 byte_get
= byte_get_big_endian
;
9125 byte_put
= byte_put_big_endian
;
9129 /* For now we only support 32 bit and 64 bit ELF files. */
9130 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
9132 /* Read in the rest of the header. */
9135 Elf32_External_Ehdr ehdr32
;
9137 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
9140 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
9141 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
9142 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
9143 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
9144 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
9145 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
9146 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
9147 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
9148 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
9149 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
9150 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
9151 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
9152 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
9156 Elf64_External_Ehdr ehdr64
;
9158 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9159 we will not be able to cope with the 64bit data found in
9160 64 ELF files. Detect this now and abort before we start
9161 overwriting things. */
9162 if (sizeof (bfd_vma
) < 8)
9164 error (_("This instance of readelf has been built without support for a\n\
9165 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9169 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
9172 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
9173 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
9174 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
9175 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
9176 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
9177 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
9178 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
9179 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
9180 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
9181 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
9182 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
9183 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
9184 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
9187 if (elf_header
.e_shoff
)
9189 /* There may be some extensions in the first section header. Don't
9190 bomb if we can't read it. */
9192 get_32bit_section_headers (file
, 1);
9194 get_64bit_section_headers (file
, 1);
9197 is_relocatable
= elf_header
.e_type
== ET_REL
;
9202 /* Process one ELF object file according to the command line options.
9203 This file may actually be stored in an archive. The file is
9204 positioned at the start of the ELF object. */
9207 process_object (char *file_name
, FILE *file
)
9211 if (! get_file_header (file
))
9213 error (_("%s: Failed to read file header\n"), file_name
);
9217 /* Initialise per file variables. */
9218 for (i
= NUM_ELEM (version_info
); i
--;)
9219 version_info
[i
] = 0;
9221 for (i
= NUM_ELEM (dynamic_info
); i
--;)
9222 dynamic_info
[i
] = 0;
9224 /* Process the file. */
9226 printf (_("\nFile: %s\n"), file_name
);
9228 /* Initialise the dump_sects array from the cmdline_dump_sects array.
9229 Note we do this even if cmdline_dump_sects is empty because we
9230 must make sure that the dump_sets array is zeroed out before each
9231 object file is processed. */
9232 if (num_dump_sects
> num_cmdline_dump_sects
)
9233 memset (dump_sects
, 0, num_dump_sects
);
9235 if (num_cmdline_dump_sects
> 0)
9237 if (num_dump_sects
== 0)
9238 /* A sneaky way of allocating the dump_sects array. */
9239 request_dump (num_cmdline_dump_sects
, 0);
9241 assert (num_dump_sects
>= num_cmdline_dump_sects
);
9242 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
9245 if (! process_file_header ())
9248 if (! process_section_headers (file
))
9250 /* Without loaded section headers we cannot process lots of
9252 do_unwind
= do_version
= do_dump
= do_arch
= 0;
9254 if (! do_using_dynamic
)
9255 do_syms
= do_reloc
= 0;
9258 if (! process_section_groups (file
))
9260 /* Without loaded section groups we cannot process unwind. */
9264 if (process_program_headers (file
))
9265 process_dynamic_section (file
);
9267 process_relocs (file
);
9269 process_unwind (file
);
9271 process_symbol_table (file
);
9273 process_syminfo (file
);
9275 process_version_sections (file
);
9277 process_section_contents (file
);
9279 process_notes (file
);
9281 process_gnu_liblist (file
);
9283 process_arch_specific (file
);
9285 if (program_headers
)
9287 free (program_headers
);
9288 program_headers
= NULL
;
9291 if (section_headers
)
9293 free (section_headers
);
9294 section_headers
= NULL
;
9299 free (string_table
);
9300 string_table
= NULL
;
9301 string_table_length
= 0;
9304 if (dynamic_strings
)
9306 free (dynamic_strings
);
9307 dynamic_strings
= NULL
;
9308 dynamic_strings_length
= 0;
9311 if (dynamic_symbols
)
9313 free (dynamic_symbols
);
9314 dynamic_symbols
= NULL
;
9315 num_dynamic_syms
= 0;
9318 if (dynamic_syminfo
)
9320 free (dynamic_syminfo
);
9321 dynamic_syminfo
= NULL
;
9324 if (section_headers_groups
)
9326 free (section_headers_groups
);
9327 section_headers_groups
= NULL
;
9332 struct group_list
*g
, *next
;
9334 for (i
= 0; i
< group_count
; i
++)
9336 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
9343 free (section_groups
);
9344 section_groups
= NULL
;
9347 free_debug_memory ();
9352 /* Process an ELF archive. The file is positioned just after the
9356 process_archive (char *file_name
, FILE *file
)
9358 struct ar_hdr arhdr
;
9361 char *longnames
= NULL
;
9362 unsigned long longnames_size
= 0;
9363 size_t file_name_size
;
9368 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9369 if (got
!= sizeof arhdr
)
9374 error (_("%s: failed to read archive header\n"), file_name
);
9378 if (const_strneq (arhdr
.ar_name
, "/ "))
9380 /* This is the archive symbol table. Skip it.
9381 FIXME: We should have an option to dump it. */
9382 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9383 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
9385 error (_("%s: failed to skip archive symbol table\n"), file_name
);
9389 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9390 if (got
!= sizeof arhdr
)
9395 error (_("%s: failed to read archive header\n"), file_name
);
9400 if (const_strneq (arhdr
.ar_name
, "// "))
9402 /* This is the archive string table holding long member
9405 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9407 longnames
= malloc (longnames_size
);
9408 if (longnames
== NULL
)
9410 error (_("Out of memory\n"));
9414 if (fread (longnames
, longnames_size
, 1, file
) != 1)
9417 error (_("%s: failed to read string table\n"), file_name
);
9421 if ((longnames_size
& 1) != 0)
9424 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9425 if (got
!= sizeof arhdr
)
9432 error (_("%s: failed to read archive header\n"), file_name
);
9437 file_name_size
= strlen (file_name
);
9446 if (arhdr
.ar_name
[0] == '/')
9450 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
9451 if (off
>= longnames_size
)
9453 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
9458 name
= longnames
+ off
;
9459 nameend
= memchr (name
, '/', longnames_size
- off
);
9463 name
= arhdr
.ar_name
;
9464 nameend
= memchr (name
, '/', 16);
9467 if (nameend
== NULL
)
9469 error (_("%s: bad archive file name\n"), file_name
);
9474 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
9475 if (namealc
== NULL
)
9477 error (_("Out of memory\n"));
9482 memcpy (namealc
, file_name
, file_name_size
);
9483 namealc
[file_name_size
] = '(';
9484 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
9485 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
9486 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
9488 archive_file_offset
= ftell (file
);
9489 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9491 ret
|= process_object (namealc
, file
);
9496 (archive_file_offset
9498 + (archive_file_size
& 1)),
9501 error (_("%s: failed to seek to next archive header\n"), file_name
);
9506 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9507 if (got
!= sizeof arhdr
)
9512 error (_("%s: failed to read archive header\n"), file_name
);
9525 process_file (char *file_name
)
9528 struct stat statbuf
;
9532 if (stat (file_name
, &statbuf
) < 0)
9534 if (errno
== ENOENT
)
9535 error (_("'%s': No such file\n"), file_name
);
9537 error (_("Could not locate '%s'. System error message: %s\n"),
9538 file_name
, strerror (errno
));
9542 if (! S_ISREG (statbuf
.st_mode
))
9544 error (_("'%s' is not an ordinary file\n"), file_name
);
9548 file
= fopen (file_name
, "rb");
9551 error (_("Input file '%s' is not readable.\n"), file_name
);
9555 if (fread (armag
, SARMAG
, 1, file
) != 1)
9557 error (_("%s: Failed to read file header\n"), file_name
);
9562 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
9563 ret
= process_archive (file_name
, file
);
9567 archive_file_size
= archive_file_offset
= 0;
9568 ret
= process_object (file_name
, file
);
9576 #ifdef SUPPORT_DISASSEMBLY
9577 /* Needed by the i386 disassembler. For extra credit, someone could
9578 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9582 print_address (unsigned int addr
, FILE *outfile
)
9584 fprintf (outfile
,"0x%8.8x", addr
);
9587 /* Needed by the i386 disassembler. */
9589 db_task_printsym (unsigned int addr
)
9591 print_address (addr
, stderr
);
9596 main (int argc
, char **argv
)
9600 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9601 setlocale (LC_MESSAGES
, "");
9603 #if defined (HAVE_SETLOCALE)
9604 setlocale (LC_CTYPE
, "");
9606 bindtextdomain (PACKAGE
, LOCALEDIR
);
9607 textdomain (PACKAGE
);
9609 expandargv (&argc
, &argv
);
9611 parse_args (argc
, argv
);
9613 if (num_dump_sects
> 0)
9615 /* Make a copy of the dump_sects array. */
9616 cmdline_dump_sects
= malloc (num_dump_sects
);
9617 if (cmdline_dump_sects
== NULL
)
9618 error (_("Out of memory allocating dump request table."));
9621 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
9622 num_cmdline_dump_sects
= num_dump_sects
;
9626 if (optind
< (argc
- 1))
9630 while (optind
< argc
)
9631 err
|= process_file (argv
[optind
++]);
9633 if (dump_sects
!= NULL
)
9635 if (cmdline_dump_sects
!= NULL
)
9636 free (cmdline_dump_sects
);