1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 /* The difference between readelf and objdump:
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
56 # ifdef HAVE_SYS_PARAM_H
57 # include <sys/param.h>
61 # define PATH_MAX MAXPATHLEN
63 # define PATH_MAX 1024
69 /* Define BFD64 here, even if our default architecture is 32 bit ELF
70 as this will allow us to read in and parse 64bit and 32bit ELF files.
71 Only do this if we believe that the compiler can support a 64 bit
72 data type. For now we only rely on GCC being able to do this. */
80 #include "elf/common.h"
81 #include "elf/external.h"
82 #include "elf/internal.h"
85 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
86 we can obtain the H8 reloc numbers. We need these for the
87 get_reloc_size() function. We include h8.h again after defining
88 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
93 /* Undo the effects of #including reloc-macros.h. */
95 #undef START_RELOC_NUMBERS
99 #undef END_RELOC_NUMBERS
100 #undef _RELOC_MACROS_H
102 /* The following headers use the elf/reloc-macros.h file to
103 automatically generate relocation recognition functions
104 such as elf_mips_reloc_type() */
106 #define RELOC_MACROS_GEN_FUNC
108 #include "elf/alpha.h"
112 #include "elf/bfin.h"
113 #include "elf/cr16.h"
114 #include "elf/cris.h"
116 #include "elf/d10v.h"
117 #include "elf/d30v.h"
119 #include "elf/fr30.h"
122 #include "elf/hppa.h"
123 #include "elf/i386.h"
124 #include "elf/i370.h"
125 #include "elf/i860.h"
126 #include "elf/i960.h"
127 #include "elf/ia64.h"
128 #include "elf/ip2k.h"
129 #include "elf/iq2000.h"
130 #include "elf/m32c.h"
131 #include "elf/m32r.h"
132 #include "elf/m68k.h"
133 #include "elf/m68hc11.h"
134 #include "elf/mcore.h"
136 #include "elf/mips.h"
137 #include "elf/mmix.h"
138 #include "elf/mn10200.h"
139 #include "elf/mn10300.h"
141 #include "elf/msp430.h"
142 #include "elf/or32.h"
145 #include "elf/ppc64.h"
146 #include "elf/s390.h"
147 #include "elf/score.h"
149 #include "elf/sparc.h"
151 #include "elf/v850.h"
153 #include "elf/x86-64.h"
154 #include "elf/xstormy16.h"
155 #include "elf/xtensa.h"
160 #include "libiberty.h"
162 char *program_name
= "readelf";
163 static long archive_file_offset
;
164 static unsigned long archive_file_size
;
165 static unsigned long dynamic_addr
;
166 static bfd_size_type dynamic_size
;
167 static unsigned int dynamic_nent
;
168 static char *dynamic_strings
;
169 static unsigned long dynamic_strings_length
;
170 static char *string_table
;
171 static unsigned long string_table_length
;
172 static unsigned long num_dynamic_syms
;
173 static Elf_Internal_Sym
*dynamic_symbols
;
174 static Elf_Internal_Syminfo
*dynamic_syminfo
;
175 static unsigned long dynamic_syminfo_offset
;
176 static unsigned int dynamic_syminfo_nent
;
177 static char program_interpreter
[PATH_MAX
];
178 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
179 static bfd_vma dynamic_info_DT_GNU_HASH
;
180 static bfd_vma version_info
[16];
181 static Elf_Internal_Ehdr elf_header
;
182 static Elf_Internal_Shdr
*section_headers
;
183 static Elf_Internal_Phdr
*program_headers
;
184 static Elf_Internal_Dyn
*dynamic_section
;
185 static Elf_Internal_Shdr
*symtab_shndx_hdr
;
186 static int show_name
;
187 static int do_dynamic
;
190 static int do_sections
;
191 static int do_section_groups
;
192 static int do_section_details
;
193 static int do_segments
;
194 static int do_unwind
;
195 static int do_using_dynamic
;
196 static int do_header
;
198 static int do_version
;
200 static int do_histogram
;
201 static int do_debugging
;
204 static int is_32bit_elf
;
208 struct group_list
*next
;
209 unsigned int section_index
;
214 struct group_list
*root
;
215 unsigned int group_index
;
218 static size_t group_count
;
219 static struct group
*section_groups
;
220 static struct group
**section_headers_groups
;
222 /* A linked list of the section names for which dumps were requested
224 struct dump_list_entry
228 struct dump_list_entry
*next
;
230 static struct dump_list_entry
*dump_sects_byname
;
232 /* A dynamic array of flags indicating for which sections a hex dump
233 has been requested (via the -x switch) and/or a disassembly dump
234 (via the -i switch). */
235 char *cmdline_dump_sects
= NULL
;
236 unsigned num_cmdline_dump_sects
= 0;
238 /* A dynamic array of flags indicating for which sections a dump of
239 some kind has been requested. It is reset on a per-object file
240 basis and then initialised from the cmdline_dump_sects array,
241 the results of interpreting the -w switch, and the
242 dump_sects_byname list. */
243 char *dump_sects
= NULL
;
244 unsigned int num_dump_sects
= 0;
246 #define HEX_DUMP (1 << 0)
247 #define DISASS_DUMP (1 << 1)
248 #define DEBUG_DUMP (1 << 2)
250 /* How to print a vma value. */
251 typedef enum print_mode
263 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
267 #define SECTION_NAME(X) \
268 ((X) == NULL ? "<none>" \
269 : string_table == NULL ? "<no-name>" \
270 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
271 : string_table + (X)->sh_name))
273 /* Given st_shndx I, map to section_headers index. */
274 #define SECTION_HEADER_INDEX(I) \
275 ((I) < SHN_LORESERVE \
277 : ((I) <= SHN_HIRESERVE \
279 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
281 /* Reverse of the above. */
282 #define SECTION_HEADER_NUM(N) \
283 ((N) < SHN_LORESERVE \
285 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
287 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
289 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
291 #define BYTE_GET(field) byte_get (field, sizeof (field))
293 #define GET_ELF_SYMBOLS(file, section) \
294 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
295 : get_64bit_elf_symbols (file, section))
297 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
298 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
299 already been called and verified that the string exists. */
300 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
302 /* This is just a bit of syntatic sugar. */
303 #define streq(a,b) (strcmp ((a), (b)) == 0)
304 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
305 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
308 get_data (void *var
, FILE *file
, long offset
, size_t size
, size_t nmemb
,
313 if (size
== 0 || nmemb
== 0)
316 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
318 error (_("Unable to seek to 0x%lx for %s\n"),
319 archive_file_offset
+ offset
, reason
);
326 /* Check for overflow. */
327 if (nmemb
< (~(size_t) 0 - 1) / size
)
328 /* + 1 so that we can '\0' terminate invalid string table sections. */
329 mvar
= malloc (size
* nmemb
+ 1);
333 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
334 (unsigned long)(size
* nmemb
), reason
);
338 ((char *) mvar
)[size
* nmemb
] = '\0';
341 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
343 error (_("Unable to read in 0x%lx bytes of %s\n"),
344 (unsigned long)(size
* nmemb
), reason
);
354 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
359 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
360 field
[6] = ((value
>> 24) >> 24) & 0xff;
361 field
[5] = ((value
>> 24) >> 16) & 0xff;
362 field
[4] = ((value
>> 24) >> 8) & 0xff;
365 field
[3] = (value
>> 24) & 0xff;
366 field
[2] = (value
>> 16) & 0xff;
369 field
[1] = (value
>> 8) & 0xff;
372 field
[0] = value
& 0xff;
376 error (_("Unhandled data length: %d\n"), size
);
381 #if defined BFD64 && !BFD_HOST_64BIT_LONG
383 print_dec_vma (bfd_vma vma
, int is_signed
)
389 if (is_signed
&& (bfd_signed_vma
) vma
< 0)
398 *bufp
++ = '0' + vma
% 10;
410 print_hex_vma (bfd_vma vma
)
418 char digit
= '0' + (vma
& 0x0f);
420 digit
+= 'a' - '0' - 10;
433 /* Print a VMA value. */
435 print_vma (bfd_vma vma
, print_mode mode
)
444 return printf ("0x%8.8lx", (unsigned long) vma
);
447 return printf ("%8.8lx", (unsigned long) vma
);
451 return printf ("%5ld", (long) vma
);
455 return printf ("0x%lx", (unsigned long) vma
);
458 return printf ("%lx", (unsigned long) vma
);
461 return printf ("%ld", (unsigned long) vma
);
464 return printf ("%lu", (unsigned long) vma
);
487 #if BFD_HOST_64BIT_LONG
488 return nc
+ printf ("%lx", vma
);
490 return nc
+ print_hex_vma (vma
);
494 #if BFD_HOST_64BIT_LONG
495 return printf ("%ld", vma
);
497 return print_dec_vma (vma
, 1);
501 #if BFD_HOST_64BIT_LONG
503 return printf ("%5ld", vma
);
505 return printf ("%#lx", vma
);
508 return printf ("%5ld", _bfd_int64_low (vma
));
510 return print_hex_vma (vma
);
514 #if BFD_HOST_64BIT_LONG
515 return printf ("%lu", vma
);
517 return print_dec_vma (vma
, 0);
525 /* Display a symbol on stdout. If do_wide is not true then
526 format the symbol to be at most WIDTH characters,
527 truncating as necessary. If WIDTH is negative then
528 format the string to be exactly - WIDTH characters,
529 truncating or padding as necessary. */
532 print_symbol (int width
, const char *symbol
)
535 printf ("%s", symbol
);
537 printf ("%-*.*s", width
, width
, symbol
);
539 printf ("%-.*s", width
, symbol
);
543 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
548 field
[7] = value
& 0xff;
549 field
[6] = (value
>> 8) & 0xff;
550 field
[5] = (value
>> 16) & 0xff;
551 field
[4] = (value
>> 24) & 0xff;
556 field
[3] = value
& 0xff;
557 field
[2] = (value
>> 8) & 0xff;
561 field
[1] = value
& 0xff;
565 field
[0] = value
& 0xff;
569 error (_("Unhandled data length: %d\n"), size
);
574 /* Return a pointer to section NAME, or NULL if no such section exists. */
576 static Elf_Internal_Shdr
*
577 find_section (const char *name
)
581 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
582 if (streq (SECTION_NAME (section_headers
+ i
), name
))
583 return section_headers
+ i
;
588 /* Guess the relocation size commonly used by the specific machines. */
591 guess_is_rela (unsigned long e_machine
)
595 /* Targets that use REL relocations. */
611 /* Targets that use RELA relocations. */
615 case EM_ALTERA_NIOS2
:
640 case EM_CYGNUS_MN10200
:
642 case EM_CYGNUS_MN10300
:
683 warn (_("Don't know about relocations on this machine architecture\n"));
689 slurp_rela_relocs (FILE *file
,
690 unsigned long rel_offset
,
691 unsigned long rel_size
,
692 Elf_Internal_Rela
**relasp
,
693 unsigned long *nrelasp
)
695 Elf_Internal_Rela
*relas
;
696 unsigned long nrelas
;
701 Elf32_External_Rela
*erelas
;
703 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
707 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
709 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
714 error (_("out of memory parsing relocs\n"));
718 for (i
= 0; i
< nrelas
; i
++)
720 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
721 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
722 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
729 Elf64_External_Rela
*erelas
;
731 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
735 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
737 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
742 error (_("out of memory parsing relocs\n"));
746 for (i
= 0; i
< nrelas
; i
++)
748 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
749 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
750 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
761 slurp_rel_relocs (FILE *file
,
762 unsigned long rel_offset
,
763 unsigned long rel_size
,
764 Elf_Internal_Rela
**relsp
,
765 unsigned long *nrelsp
)
767 Elf_Internal_Rela
*rels
;
773 Elf32_External_Rel
*erels
;
775 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
779 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
781 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
786 error (_("out of memory parsing relocs\n"));
790 for (i
= 0; i
< nrels
; i
++)
792 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
793 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
794 rels
[i
].r_addend
= 0;
801 Elf64_External_Rel
*erels
;
803 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
807 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
809 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
814 error (_("out of memory parsing relocs\n"));
818 for (i
= 0; i
< nrels
; i
++)
820 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
821 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
822 rels
[i
].r_addend
= 0;
832 /* Display the contents of the relocation data found at the specified
836 dump_relocations (FILE *file
,
837 unsigned long rel_offset
,
838 unsigned long rel_size
,
839 Elf_Internal_Sym
*symtab
,
842 unsigned long strtablen
,
846 Elf_Internal_Rela
*rels
;
849 if (is_rela
== UNKNOWN
)
850 is_rela
= guess_is_rela (elf_header
.e_machine
);
854 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
859 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
868 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
870 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
875 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
877 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
885 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
887 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
892 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
894 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
898 for (i
= 0; i
< rel_size
; i
++)
901 const char *rtype2
= NULL
;
902 const char *rtype3
= NULL
;
905 bfd_vma symtab_index
;
910 offset
= rels
[i
].r_offset
;
911 info
= rels
[i
].r_info
;
915 type
= ELF32_R_TYPE (info
);
916 symtab_index
= ELF32_R_SYM (info
);
920 /* The #ifdef BFD64 below is to prevent a compile time warning.
921 We know that if we do not have a 64 bit data type that we
922 will never execute this code anyway. */
924 if (elf_header
.e_machine
== EM_MIPS
)
926 /* In little-endian objects, r_info isn't really a 64-bit
927 little-endian value: it has a 32-bit little-endian
928 symbol index followed by four individual byte fields.
929 Reorder INFO accordingly. */
930 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
931 info
= (((info
& 0xffffffff) << 32)
932 | ((info
>> 56) & 0xff)
933 | ((info
>> 40) & 0xff00)
934 | ((info
>> 24) & 0xff0000)
935 | ((info
>> 8) & 0xff000000));
936 type
= ELF64_MIPS_R_TYPE (info
);
937 type2
= ELF64_MIPS_R_TYPE2 (info
);
938 type3
= ELF64_MIPS_R_TYPE3 (info
);
940 else if (elf_header
.e_machine
== EM_SPARCV9
)
941 type
= ELF64_R_TYPE_ID (info
);
943 type
= ELF64_R_TYPE (info
);
945 symtab_index
= ELF64_R_SYM (info
);
951 #ifdef _bfd_int64_low
952 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
954 printf ("%8.8lx %8.8lx ", offset
, info
);
959 #ifdef _bfd_int64_low
961 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
962 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
963 _bfd_int64_high (offset
),
964 _bfd_int64_low (offset
),
965 _bfd_int64_high (info
),
966 _bfd_int64_low (info
));
969 ? "%16.16lx %16.16lx "
970 : "%12.12lx %12.12lx ",
975 switch (elf_header
.e_machine
)
983 rtype
= elf_m32r_reloc_type (type
);
988 rtype
= elf_i386_reloc_type (type
);
993 rtype
= elf_m68hc11_reloc_type (type
);
997 rtype
= elf_m68k_reloc_type (type
);
1001 rtype
= elf_i960_reloc_type (type
);
1006 rtype
= elf_avr_reloc_type (type
);
1009 case EM_OLD_SPARCV9
:
1010 case EM_SPARC32PLUS
:
1013 rtype
= elf_sparc_reloc_type (type
);
1017 rtype
= elf_spu_reloc_type (type
);
1021 case EM_CYGNUS_V850
:
1022 rtype
= v850_reloc_type (type
);
1026 case EM_CYGNUS_D10V
:
1027 rtype
= elf_d10v_reloc_type (type
);
1031 case EM_CYGNUS_D30V
:
1032 rtype
= elf_d30v_reloc_type (type
);
1036 rtype
= elf_dlx_reloc_type (type
);
1040 rtype
= elf_sh_reloc_type (type
);
1044 case EM_CYGNUS_MN10300
:
1045 rtype
= elf_mn10300_reloc_type (type
);
1049 case EM_CYGNUS_MN10200
:
1050 rtype
= elf_mn10200_reloc_type (type
);
1054 case EM_CYGNUS_FR30
:
1055 rtype
= elf_fr30_reloc_type (type
);
1059 rtype
= elf_frv_reloc_type (type
);
1063 rtype
= elf_mcore_reloc_type (type
);
1067 rtype
= elf_mmix_reloc_type (type
);
1072 rtype
= elf_msp430_reloc_type (type
);
1076 rtype
= elf_ppc_reloc_type (type
);
1080 rtype
= elf_ppc64_reloc_type (type
);
1084 case EM_MIPS_RS3_LE
:
1085 rtype
= elf_mips_reloc_type (type
);
1088 rtype2
= elf_mips_reloc_type (type2
);
1089 rtype3
= elf_mips_reloc_type (type3
);
1094 rtype
= elf_alpha_reloc_type (type
);
1098 rtype
= elf_arm_reloc_type (type
);
1102 rtype
= elf_arc_reloc_type (type
);
1106 rtype
= elf_hppa_reloc_type (type
);
1112 rtype
= elf_h8_reloc_type (type
);
1117 rtype
= elf_or32_reloc_type (type
);
1122 rtype
= elf_pj_reloc_type (type
);
1125 rtype
= elf_ia64_reloc_type (type
);
1129 rtype
= elf_cris_reloc_type (type
);
1133 rtype
= elf_i860_reloc_type (type
);
1137 rtype
= elf_x86_64_reloc_type (type
);
1141 rtype
= i370_reloc_type (type
);
1146 rtype
= elf_s390_reloc_type (type
);
1150 rtype
= elf_score_reloc_type (type
);
1154 rtype
= elf_xstormy16_reloc_type (type
);
1158 rtype
= elf_crx_reloc_type (type
);
1162 rtype
= elf_vax_reloc_type (type
);
1167 rtype
= elf_ip2k_reloc_type (type
);
1171 rtype
= elf_iq2000_reloc_type (type
);
1176 rtype
= elf_xtensa_reloc_type (type
);
1180 rtype
= elf_m32c_reloc_type (type
);
1184 rtype
= elf_mt_reloc_type (type
);
1188 rtype
= elf_bfin_reloc_type (type
);
1192 rtype
= elf_mep_reloc_type (type
);
1196 rtype
= elf_cr16_reloc_type (type
);
1201 #ifdef _bfd_int64_low
1202 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1204 printf (_("unrecognized: %-7lx"), type
);
1207 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1209 if (elf_header
.e_machine
== EM_ALPHA
1211 && streq (rtype
, "R_ALPHA_LITUSE")
1214 switch (rels
[i
].r_addend
)
1216 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1217 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1218 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1219 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1220 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1221 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1222 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1223 default: rtype
= NULL
;
1226 printf (" (%s)", rtype
);
1230 printf (_("<unknown addend: %lx>"),
1231 (unsigned long) rels
[i
].r_addend
);
1234 else if (symtab_index
)
1236 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1237 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1240 Elf_Internal_Sym
*psym
;
1242 psym
= symtab
+ symtab_index
;
1245 print_vma (psym
->st_value
, LONG_HEX
);
1246 printf (is_32bit_elf
? " " : " ");
1248 if (psym
->st_name
== 0)
1250 const char *sec_name
= "<null>";
1253 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1255 bfd_vma sec_index
= (bfd_vma
) -1;
1257 if (psym
->st_shndx
< SHN_LORESERVE
)
1258 sec_index
= psym
->st_shndx
;
1259 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1260 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1263 if (sec_index
!= (bfd_vma
) -1)
1264 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1265 else if (psym
->st_shndx
== SHN_ABS
)
1267 else if (psym
->st_shndx
== SHN_COMMON
)
1268 sec_name
= "COMMON";
1269 else if (elf_header
.e_machine
== EM_MIPS
1270 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1271 sec_name
= "SCOMMON";
1272 else if (elf_header
.e_machine
== EM_MIPS
1273 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1274 sec_name
= "SUNDEF";
1275 else if (elf_header
.e_machine
== EM_X86_64
1276 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1277 sec_name
= "LARGE_COMMON";
1278 else if (elf_header
.e_machine
== EM_IA_64
1279 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1280 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1281 sec_name
= "ANSI_COM";
1284 sprintf (name_buf
, "<section 0x%x>",
1285 (unsigned int) psym
->st_shndx
);
1286 sec_name
= name_buf
;
1289 print_symbol (22, sec_name
);
1291 else if (strtab
== NULL
)
1292 printf (_("<string table index: %3ld>"), psym
->st_name
);
1293 else if (psym
->st_name
>= strtablen
)
1294 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1296 print_symbol (22, strtab
+ psym
->st_name
);
1299 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1304 printf ("%*c", is_32bit_elf
?
1305 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1306 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1309 if (elf_header
.e_machine
== EM_SPARCV9
1311 && streq (rtype
, "R_SPARC_OLO10"))
1312 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1316 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1318 printf (" Type2: ");
1321 #ifdef _bfd_int64_low
1322 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1324 printf (_("unrecognized: %-7lx"), type2
);
1327 printf ("%-17.17s", rtype2
);
1329 printf ("\n Type3: ");
1332 #ifdef _bfd_int64_low
1333 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1335 printf (_("unrecognized: %-7lx"), type3
);
1338 printf ("%-17.17s", rtype3
);
1350 get_mips_dynamic_type (unsigned long type
)
1354 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1355 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1356 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1357 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1358 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1359 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1360 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1361 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1362 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1363 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1364 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1365 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1366 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1367 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1368 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1369 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1370 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1371 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1372 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1373 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1374 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1375 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1376 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1377 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1378 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1379 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1380 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1381 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1382 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1383 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1384 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1385 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1386 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1387 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1388 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1389 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1390 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1391 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1392 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1393 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1394 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1395 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1396 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1403 get_sparc64_dynamic_type (unsigned long type
)
1407 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1414 get_ppc_dynamic_type (unsigned long type
)
1418 case DT_PPC_GOT
: return "PPC_GOT";
1425 get_ppc64_dynamic_type (unsigned long type
)
1429 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1430 case DT_PPC64_OPD
: return "PPC64_OPD";
1431 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1438 get_parisc_dynamic_type (unsigned long type
)
1442 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1443 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1444 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1445 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1446 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1447 case DT_HP_PREINIT
: return "HP_PREINIT";
1448 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1449 case DT_HP_NEEDED
: return "HP_NEEDED";
1450 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1451 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1452 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1453 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1454 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1455 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1456 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1457 case DT_HP_FILTERED
: return "HP_FILTERED";
1458 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1459 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1460 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1461 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1462 case DT_PLT
: return "PLT";
1463 case DT_PLT_SIZE
: return "PLT_SIZE";
1464 case DT_DLT
: return "DLT";
1465 case DT_DLT_SIZE
: return "DLT_SIZE";
1472 get_ia64_dynamic_type (unsigned long type
)
1476 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1483 get_alpha_dynamic_type (unsigned long type
)
1487 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1494 get_score_dynamic_type (unsigned long type
)
1498 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1499 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1500 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1501 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1502 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1503 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1511 get_dynamic_type (unsigned long type
)
1513 static char buff
[64];
1517 case DT_NULL
: return "NULL";
1518 case DT_NEEDED
: return "NEEDED";
1519 case DT_PLTRELSZ
: return "PLTRELSZ";
1520 case DT_PLTGOT
: return "PLTGOT";
1521 case DT_HASH
: return "HASH";
1522 case DT_STRTAB
: return "STRTAB";
1523 case DT_SYMTAB
: return "SYMTAB";
1524 case DT_RELA
: return "RELA";
1525 case DT_RELASZ
: return "RELASZ";
1526 case DT_RELAENT
: return "RELAENT";
1527 case DT_STRSZ
: return "STRSZ";
1528 case DT_SYMENT
: return "SYMENT";
1529 case DT_INIT
: return "INIT";
1530 case DT_FINI
: return "FINI";
1531 case DT_SONAME
: return "SONAME";
1532 case DT_RPATH
: return "RPATH";
1533 case DT_SYMBOLIC
: return "SYMBOLIC";
1534 case DT_REL
: return "REL";
1535 case DT_RELSZ
: return "RELSZ";
1536 case DT_RELENT
: return "RELENT";
1537 case DT_PLTREL
: return "PLTREL";
1538 case DT_DEBUG
: return "DEBUG";
1539 case DT_TEXTREL
: return "TEXTREL";
1540 case DT_JMPREL
: return "JMPREL";
1541 case DT_BIND_NOW
: return "BIND_NOW";
1542 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1543 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1544 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1545 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1546 case DT_RUNPATH
: return "RUNPATH";
1547 case DT_FLAGS
: return "FLAGS";
1549 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1550 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1552 case DT_CHECKSUM
: return "CHECKSUM";
1553 case DT_PLTPADSZ
: return "PLTPADSZ";
1554 case DT_MOVEENT
: return "MOVEENT";
1555 case DT_MOVESZ
: return "MOVESZ";
1556 case DT_FEATURE
: return "FEATURE";
1557 case DT_POSFLAG_1
: return "POSFLAG_1";
1558 case DT_SYMINSZ
: return "SYMINSZ";
1559 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1561 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1562 case DT_CONFIG
: return "CONFIG";
1563 case DT_DEPAUDIT
: return "DEPAUDIT";
1564 case DT_AUDIT
: return "AUDIT";
1565 case DT_PLTPAD
: return "PLTPAD";
1566 case DT_MOVETAB
: return "MOVETAB";
1567 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1569 case DT_VERSYM
: return "VERSYM";
1571 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1572 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1573 case DT_RELACOUNT
: return "RELACOUNT";
1574 case DT_RELCOUNT
: return "RELCOUNT";
1575 case DT_FLAGS_1
: return "FLAGS_1";
1576 case DT_VERDEF
: return "VERDEF";
1577 case DT_VERDEFNUM
: return "VERDEFNUM";
1578 case DT_VERNEED
: return "VERNEED";
1579 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1581 case DT_AUXILIARY
: return "AUXILIARY";
1582 case DT_USED
: return "USED";
1583 case DT_FILTER
: return "FILTER";
1585 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1586 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1587 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1588 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1589 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1590 case DT_GNU_HASH
: return "GNU_HASH";
1593 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1597 switch (elf_header
.e_machine
)
1600 case EM_MIPS_RS3_LE
:
1601 result
= get_mips_dynamic_type (type
);
1604 result
= get_sparc64_dynamic_type (type
);
1607 result
= get_ppc_dynamic_type (type
);
1610 result
= get_ppc64_dynamic_type (type
);
1613 result
= get_ia64_dynamic_type (type
);
1616 result
= get_alpha_dynamic_type (type
);
1619 result
= get_score_dynamic_type (type
);
1629 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1631 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1632 || (elf_header
.e_machine
== EM_PARISC
1633 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1637 switch (elf_header
.e_machine
)
1640 result
= get_parisc_dynamic_type (type
);
1650 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1654 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1661 get_file_type (unsigned e_type
)
1663 static char buff
[32];
1667 case ET_NONE
: return _("NONE (None)");
1668 case ET_REL
: return _("REL (Relocatable file)");
1669 case ET_EXEC
: return _("EXEC (Executable file)");
1670 case ET_DYN
: return _("DYN (Shared object file)");
1671 case ET_CORE
: return _("CORE (Core file)");
1674 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1675 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1676 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1677 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1679 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1685 get_machine_name (unsigned e_machine
)
1687 static char buff
[64]; /* XXX */
1691 case EM_NONE
: return _("None");
1692 case EM_M32
: return "WE32100";
1693 case EM_SPARC
: return "Sparc";
1694 case EM_SPU
: return "SPU";
1695 case EM_386
: return "Intel 80386";
1696 case EM_68K
: return "MC68000";
1697 case EM_88K
: return "MC88000";
1698 case EM_486
: return "Intel 80486";
1699 case EM_860
: return "Intel 80860";
1700 case EM_MIPS
: return "MIPS R3000";
1701 case EM_S370
: return "IBM System/370";
1702 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1703 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1704 case EM_PARISC
: return "HPPA";
1705 case EM_PPC_OLD
: return "Power PC (old)";
1706 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1707 case EM_960
: return "Intel 90860";
1708 case EM_PPC
: return "PowerPC";
1709 case EM_PPC64
: return "PowerPC64";
1710 case EM_V800
: return "NEC V800";
1711 case EM_FR20
: return "Fujitsu FR20";
1712 case EM_RH32
: return "TRW RH32";
1713 case EM_MCORE
: return "MCORE";
1714 case EM_ARM
: return "ARM";
1715 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1716 case EM_SH
: return "Renesas / SuperH SH";
1717 case EM_SPARCV9
: return "Sparc v9";
1718 case EM_TRICORE
: return "Siemens Tricore";
1719 case EM_ARC
: return "ARC";
1720 case EM_H8_300
: return "Renesas H8/300";
1721 case EM_H8_300H
: return "Renesas H8/300H";
1722 case EM_H8S
: return "Renesas H8S";
1723 case EM_H8_500
: return "Renesas H8/500";
1724 case EM_IA_64
: return "Intel IA-64";
1725 case EM_MIPS_X
: return "Stanford MIPS-X";
1726 case EM_COLDFIRE
: return "Motorola Coldfire";
1727 case EM_68HC12
: return "Motorola M68HC12";
1728 case EM_ALPHA
: return "Alpha";
1729 case EM_CYGNUS_D10V
:
1730 case EM_D10V
: return "d10v";
1731 case EM_CYGNUS_D30V
:
1732 case EM_D30V
: return "d30v";
1733 case EM_CYGNUS_M32R
:
1734 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1735 case EM_CYGNUS_V850
:
1736 case EM_V850
: return "NEC v850";
1737 case EM_CYGNUS_MN10300
:
1738 case EM_MN10300
: return "mn10300";
1739 case EM_CYGNUS_MN10200
:
1740 case EM_MN10200
: return "mn10200";
1741 case EM_CYGNUS_FR30
:
1742 case EM_FR30
: return "Fujitsu FR30";
1743 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1745 case EM_PJ
: return "picoJava";
1746 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1747 case EM_PCP
: return "Siemens PCP";
1748 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1749 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1750 case EM_STARCORE
: return "Motorola Star*Core processor";
1751 case EM_ME16
: return "Toyota ME16 processor";
1752 case EM_ST100
: return "STMicroelectronics ST100 processor";
1753 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1754 case EM_FX66
: return "Siemens FX66 microcontroller";
1755 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1756 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1757 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1758 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1759 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1760 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1761 case EM_SVX
: return "Silicon Graphics SVx";
1762 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1763 case EM_VAX
: return "Digital VAX";
1765 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1766 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1767 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1768 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1769 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1770 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1771 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1772 case EM_PRISM
: return "Vitesse Prism";
1773 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1775 case EM_S390
: return "IBM S/390";
1776 case EM_SCORE
: return "SUNPLUS S+Core";
1777 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1779 case EM_OR32
: return "OpenRISC";
1780 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1781 case EM_DLX
: return "OpenDLX";
1783 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1784 case EM_IQ2000
: return "Vitesse IQ2000";
1786 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1787 case EM_M32C
: return "Renesas M32c";
1788 case EM_MT
: return "Morpho Techologies MT processor";
1789 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1790 case EM_NIOS32
: return "Altera Nios";
1791 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1792 case EM_XC16X
: return "Infineon Technologies xc16x";
1793 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1794 case EM_CR16
: return "National Semiconductor's CR16";
1796 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
1802 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1807 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1808 e_flags
&= ~ EF_ARM_EABIMASK
;
1810 /* Handle "generic" ARM flags. */
1811 if (e_flags
& EF_ARM_RELEXEC
)
1813 strcat (buf
, ", relocatable executable");
1814 e_flags
&= ~ EF_ARM_RELEXEC
;
1817 if (e_flags
& EF_ARM_HASENTRY
)
1819 strcat (buf
, ", has entry point");
1820 e_flags
&= ~ EF_ARM_HASENTRY
;
1823 /* Now handle EABI specific flags. */
1827 strcat (buf
, ", <unrecognized EABI>");
1832 case EF_ARM_EABI_VER1
:
1833 strcat (buf
, ", Version1 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");
1855 case EF_ARM_EABI_VER2
:
1856 strcat (buf
, ", Version2 EABI");
1861 /* Process flags one bit at a time. */
1862 flag
= e_flags
& - e_flags
;
1867 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1868 strcat (buf
, ", sorted symbol tables");
1871 case EF_ARM_DYNSYMSUSESEGIDX
:
1872 strcat (buf
, ", dynamic symbols use segment index");
1875 case EF_ARM_MAPSYMSFIRST
:
1876 strcat (buf
, ", mapping symbols precede others");
1886 case EF_ARM_EABI_VER3
:
1887 strcat (buf
, ", Version3 EABI");
1890 case EF_ARM_EABI_VER4
:
1891 strcat (buf
, ", Version4 EABI");
1894 case EF_ARM_EABI_VER5
:
1895 strcat (buf
, ", Version5 EABI");
1901 /* Process flags one bit at a time. */
1902 flag
= e_flags
& - e_flags
;
1908 strcat (buf
, ", BE8");
1912 strcat (buf
, ", LE8");
1922 case EF_ARM_EABI_UNKNOWN
:
1923 strcat (buf
, ", GNU EABI");
1928 /* Process flags one bit at a time. */
1929 flag
= e_flags
& - e_flags
;
1934 case EF_ARM_INTERWORK
:
1935 strcat (buf
, ", interworking enabled");
1938 case EF_ARM_APCS_26
:
1939 strcat (buf
, ", uses APCS/26");
1942 case EF_ARM_APCS_FLOAT
:
1943 strcat (buf
, ", uses APCS/float");
1947 strcat (buf
, ", position independent");
1951 strcat (buf
, ", 8 bit structure alignment");
1954 case EF_ARM_NEW_ABI
:
1955 strcat (buf
, ", uses new ABI");
1958 case EF_ARM_OLD_ABI
:
1959 strcat (buf
, ", uses old ABI");
1962 case EF_ARM_SOFT_FLOAT
:
1963 strcat (buf
, ", software FP");
1966 case EF_ARM_VFP_FLOAT
:
1967 strcat (buf
, ", VFP");
1970 case EF_ARM_MAVERICK_FLOAT
:
1971 strcat (buf
, ", Maverick FP");
1982 strcat (buf
,", <unknown>");
1986 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1988 static char buf
[1024];
2000 decode_ARM_machine_flags (e_flags
, buf
);
2004 switch (e_flags
& EF_FRV_CPU_MASK
)
2006 case EF_FRV_CPU_GENERIC
:
2010 strcat (buf
, ", fr???");
2013 case EF_FRV_CPU_FR300
:
2014 strcat (buf
, ", fr300");
2017 case EF_FRV_CPU_FR400
:
2018 strcat (buf
, ", fr400");
2020 case EF_FRV_CPU_FR405
:
2021 strcat (buf
, ", fr405");
2024 case EF_FRV_CPU_FR450
:
2025 strcat (buf
, ", fr450");
2028 case EF_FRV_CPU_FR500
:
2029 strcat (buf
, ", fr500");
2031 case EF_FRV_CPU_FR550
:
2032 strcat (buf
, ", fr550");
2035 case EF_FRV_CPU_SIMPLE
:
2036 strcat (buf
, ", simple");
2038 case EF_FRV_CPU_TOMCAT
:
2039 strcat (buf
, ", tomcat");
2045 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2046 strcat (buf
, ", m68000");
2047 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2048 strcat (buf
, ", cpu32");
2049 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2050 strcat (buf
, ", fido_a");
2053 char const *isa
= _("unknown");
2054 char const *mac
= _("unknown mac");
2055 char const *additional
= NULL
;
2057 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2059 case EF_M68K_CF_ISA_A_NODIV
:
2061 additional
= ", nodiv";
2063 case EF_M68K_CF_ISA_A
:
2066 case EF_M68K_CF_ISA_A_PLUS
:
2069 case EF_M68K_CF_ISA_B_NOUSP
:
2071 additional
= ", nousp";
2073 case EF_M68K_CF_ISA_B
:
2077 strcat (buf
, ", cf, isa ");
2080 strcat (buf
, additional
);
2081 if (e_flags
& EF_M68K_CF_FLOAT
)
2082 strcat (buf
, ", float");
2083 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2088 case EF_M68K_CF_MAC
:
2091 case EF_M68K_CF_EMAC
:
2104 if (e_flags
& EF_PPC_EMB
)
2105 strcat (buf
, ", emb");
2107 if (e_flags
& EF_PPC_RELOCATABLE
)
2108 strcat (buf
, ", relocatable");
2110 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2111 strcat (buf
, ", relocatable-lib");
2115 case EM_CYGNUS_V850
:
2116 switch (e_flags
& EF_V850_ARCH
)
2119 strcat (buf
, ", v850e1");
2122 strcat (buf
, ", v850e");
2125 strcat (buf
, ", v850");
2128 strcat (buf
, ", unknown v850 architecture variant");
2134 case EM_CYGNUS_M32R
:
2135 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2136 strcat (buf
, ", m32r");
2140 case EM_MIPS_RS3_LE
:
2141 if (e_flags
& EF_MIPS_NOREORDER
)
2142 strcat (buf
, ", noreorder");
2144 if (e_flags
& EF_MIPS_PIC
)
2145 strcat (buf
, ", pic");
2147 if (e_flags
& EF_MIPS_CPIC
)
2148 strcat (buf
, ", cpic");
2150 if (e_flags
& EF_MIPS_UCODE
)
2151 strcat (buf
, ", ugen_reserved");
2153 if (e_flags
& EF_MIPS_ABI2
)
2154 strcat (buf
, ", abi2");
2156 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2157 strcat (buf
, ", odk first");
2159 if (e_flags
& EF_MIPS_32BITMODE
)
2160 strcat (buf
, ", 32bitmode");
2162 switch ((e_flags
& EF_MIPS_MACH
))
2164 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2165 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2166 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2167 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2168 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2169 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2170 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2171 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2172 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2173 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2175 /* We simply ignore the field in this case to avoid confusion:
2176 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2179 default: strcat (buf
, ", unknown CPU"); break;
2182 switch ((e_flags
& EF_MIPS_ABI
))
2184 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2185 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2186 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2187 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2189 /* We simply ignore the field in this case to avoid confusion:
2190 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2191 This means it is likely to be an o32 file, but not for
2194 default: strcat (buf
, ", unknown ABI"); break;
2197 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2198 strcat (buf
, ", mdmx");
2200 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2201 strcat (buf
, ", mips16");
2203 switch ((e_flags
& EF_MIPS_ARCH
))
2205 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2206 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2207 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2208 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2209 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2210 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2211 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2212 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2213 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2214 default: strcat (buf
, ", unknown ISA"); break;
2220 switch ((e_flags
& EF_SH_MACH_MASK
))
2222 case EF_SH1
: strcat (buf
, ", sh1"); break;
2223 case EF_SH2
: strcat (buf
, ", sh2"); break;
2224 case EF_SH3
: strcat (buf
, ", sh3"); break;
2225 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2226 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2227 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2228 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2229 case EF_SH4
: strcat (buf
, ", sh4"); break;
2230 case EF_SH5
: strcat (buf
, ", sh5"); break;
2231 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2232 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2233 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2234 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2235 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2236 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2237 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2238 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2239 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2240 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2241 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2242 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2243 default: strcat (buf
, ", unknown ISA"); break;
2249 if (e_flags
& EF_SPARC_32PLUS
)
2250 strcat (buf
, ", v8+");
2252 if (e_flags
& EF_SPARC_SUN_US1
)
2253 strcat (buf
, ", ultrasparcI");
2255 if (e_flags
& EF_SPARC_SUN_US3
)
2256 strcat (buf
, ", ultrasparcIII");
2258 if (e_flags
& EF_SPARC_HAL_R1
)
2259 strcat (buf
, ", halr1");
2261 if (e_flags
& EF_SPARC_LEDATA
)
2262 strcat (buf
, ", ledata");
2264 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2265 strcat (buf
, ", tso");
2267 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2268 strcat (buf
, ", pso");
2270 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2271 strcat (buf
, ", rmo");
2275 switch (e_flags
& EF_PARISC_ARCH
)
2277 case EFA_PARISC_1_0
:
2278 strcpy (buf
, ", PA-RISC 1.0");
2280 case EFA_PARISC_1_1
:
2281 strcpy (buf
, ", PA-RISC 1.1");
2283 case EFA_PARISC_2_0
:
2284 strcpy (buf
, ", PA-RISC 2.0");
2289 if (e_flags
& EF_PARISC_TRAPNIL
)
2290 strcat (buf
, ", trapnil");
2291 if (e_flags
& EF_PARISC_EXT
)
2292 strcat (buf
, ", ext");
2293 if (e_flags
& EF_PARISC_LSB
)
2294 strcat (buf
, ", lsb");
2295 if (e_flags
& EF_PARISC_WIDE
)
2296 strcat (buf
, ", wide");
2297 if (e_flags
& EF_PARISC_NO_KABP
)
2298 strcat (buf
, ", no kabp");
2299 if (e_flags
& EF_PARISC_LAZYSWAP
)
2300 strcat (buf
, ", lazyswap");
2305 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2306 strcat (buf
, ", new calling convention");
2308 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2309 strcat (buf
, ", gnu calling convention");
2313 if ((e_flags
& EF_IA_64_ABI64
))
2314 strcat (buf
, ", 64-bit");
2316 strcat (buf
, ", 32-bit");
2317 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2318 strcat (buf
, ", reduced fp model");
2319 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2320 strcat (buf
, ", no function descriptors, constant gp");
2321 else if ((e_flags
& EF_IA_64_CONS_GP
))
2322 strcat (buf
, ", constant gp");
2323 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2324 strcat (buf
, ", absolute");
2328 if ((e_flags
& EF_VAX_NONPIC
))
2329 strcat (buf
, ", non-PIC");
2330 if ((e_flags
& EF_VAX_DFLOAT
))
2331 strcat (buf
, ", D-Float");
2332 if ((e_flags
& EF_VAX_GFLOAT
))
2333 strcat (buf
, ", G-Float");
2342 get_osabi_name (unsigned int osabi
)
2344 static char buff
[32];
2348 case ELFOSABI_NONE
: return "UNIX - System V";
2349 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2350 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2351 case ELFOSABI_LINUX
: return "UNIX - Linux";
2352 case ELFOSABI_HURD
: return "GNU/Hurd";
2353 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2354 case ELFOSABI_AIX
: return "UNIX - AIX";
2355 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2356 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2357 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2358 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2359 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2360 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2361 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2362 case ELFOSABI_AROS
: return "Amiga Research OS";
2363 case ELFOSABI_STANDALONE
: return _("Standalone App");
2364 case ELFOSABI_ARM
: return "ARM";
2366 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2372 get_arm_segment_type (unsigned long type
)
2386 get_mips_segment_type (unsigned long type
)
2390 case PT_MIPS_REGINFO
:
2392 case PT_MIPS_RTPROC
:
2394 case PT_MIPS_OPTIONS
:
2404 get_parisc_segment_type (unsigned long type
)
2408 case PT_HP_TLS
: return "HP_TLS";
2409 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2410 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2411 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2412 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2413 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2414 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2415 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2416 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2417 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2418 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2419 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2420 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2421 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2422 case PT_HP_STACK
: return "HP_STACK";
2423 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2424 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2425 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2426 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2435 get_ia64_segment_type (unsigned long type
)
2439 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2440 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2441 case PT_HP_TLS
: return "HP_TLS";
2442 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2443 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2444 case PT_IA_64_HP_STACK
: return "HP_STACK";
2453 get_segment_type (unsigned long p_type
)
2455 static char buff
[32];
2459 case PT_NULL
: return "NULL";
2460 case PT_LOAD
: return "LOAD";
2461 case PT_DYNAMIC
: return "DYNAMIC";
2462 case PT_INTERP
: return "INTERP";
2463 case PT_NOTE
: return "NOTE";
2464 case PT_SHLIB
: return "SHLIB";
2465 case PT_PHDR
: return "PHDR";
2466 case PT_TLS
: return "TLS";
2468 case PT_GNU_EH_FRAME
:
2469 return "GNU_EH_FRAME";
2470 case PT_GNU_STACK
: return "GNU_STACK";
2471 case PT_GNU_RELRO
: return "GNU_RELRO";
2474 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2478 switch (elf_header
.e_machine
)
2481 result
= get_arm_segment_type (p_type
);
2484 case EM_MIPS_RS3_LE
:
2485 result
= get_mips_segment_type (p_type
);
2488 result
= get_parisc_segment_type (p_type
);
2491 result
= get_ia64_segment_type (p_type
);
2501 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2503 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2507 switch (elf_header
.e_machine
)
2510 result
= get_parisc_segment_type (p_type
);
2513 result
= get_ia64_segment_type (p_type
);
2523 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2526 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2533 get_mips_section_type_name (unsigned int sh_type
)
2537 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2538 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2539 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2540 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2541 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2542 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2543 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2544 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2545 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2546 case SHT_MIPS_RELD
: return "MIPS_RELD";
2547 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2548 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2549 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2550 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2551 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2552 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2553 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2554 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2555 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2556 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2557 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2558 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2559 case SHT_MIPS_LINE
: return "MIPS_LINE";
2560 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2561 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2562 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2563 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2564 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2565 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2566 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2567 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2568 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2569 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2570 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2571 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2572 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2573 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2574 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2575 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2583 get_parisc_section_type_name (unsigned int sh_type
)
2587 case SHT_PARISC_EXT
: return "PARISC_EXT";
2588 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2589 case SHT_PARISC_DOC
: return "PARISC_DOC";
2590 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2591 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2592 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2593 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2601 get_ia64_section_type_name (unsigned int sh_type
)
2603 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2604 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2605 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2609 case SHT_IA_64_EXT
: return "IA_64_EXT";
2610 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2611 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2619 get_x86_64_section_type_name (unsigned int sh_type
)
2623 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2631 get_arm_section_type_name (unsigned int sh_type
)
2637 case SHT_ARM_PREEMPTMAP
:
2638 return "ARM_PREEMPTMAP";
2639 case SHT_ARM_ATTRIBUTES
:
2640 return "ARM_ATTRIBUTES";
2648 get_section_type_name (unsigned int sh_type
)
2650 static char buff
[32];
2654 case SHT_NULL
: return "NULL";
2655 case SHT_PROGBITS
: return "PROGBITS";
2656 case SHT_SYMTAB
: return "SYMTAB";
2657 case SHT_STRTAB
: return "STRTAB";
2658 case SHT_RELA
: return "RELA";
2659 case SHT_HASH
: return "HASH";
2660 case SHT_DYNAMIC
: return "DYNAMIC";
2661 case SHT_NOTE
: return "NOTE";
2662 case SHT_NOBITS
: return "NOBITS";
2663 case SHT_REL
: return "REL";
2664 case SHT_SHLIB
: return "SHLIB";
2665 case SHT_DYNSYM
: return "DYNSYM";
2666 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2667 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2668 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2669 case SHT_GNU_HASH
: return "GNU_HASH";
2670 case SHT_GROUP
: return "GROUP";
2671 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2672 case SHT_GNU_verdef
: return "VERDEF";
2673 case SHT_GNU_verneed
: return "VERNEED";
2674 case SHT_GNU_versym
: return "VERSYM";
2675 case 0x6ffffff0: return "VERSYM";
2676 case 0x6ffffffc: return "VERDEF";
2677 case 0x7ffffffd: return "AUXILIARY";
2678 case 0x7fffffff: return "FILTER";
2679 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2682 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2686 switch (elf_header
.e_machine
)
2689 case EM_MIPS_RS3_LE
:
2690 result
= get_mips_section_type_name (sh_type
);
2693 result
= get_parisc_section_type_name (sh_type
);
2696 result
= get_ia64_section_type_name (sh_type
);
2699 result
= get_x86_64_section_type_name (sh_type
);
2702 result
= get_arm_section_type_name (sh_type
);
2712 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2714 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2715 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2716 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2717 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2719 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2725 #define OPTION_DEBUG_DUMP 512
2727 static struct option options
[] =
2729 {"all", no_argument
, 0, 'a'},
2730 {"file-header", no_argument
, 0, 'h'},
2731 {"program-headers", no_argument
, 0, 'l'},
2732 {"headers", no_argument
, 0, 'e'},
2733 {"histogram", no_argument
, 0, 'I'},
2734 {"segments", no_argument
, 0, 'l'},
2735 {"sections", no_argument
, 0, 'S'},
2736 {"section-headers", no_argument
, 0, 'S'},
2737 {"section-groups", no_argument
, 0, 'g'},
2738 {"section-details", no_argument
, 0, 't'},
2739 {"full-section-name",no_argument
, 0, 'N'},
2740 {"symbols", no_argument
, 0, 's'},
2741 {"syms", no_argument
, 0, 's'},
2742 {"relocs", no_argument
, 0, 'r'},
2743 {"notes", no_argument
, 0, 'n'},
2744 {"dynamic", no_argument
, 0, 'd'},
2745 {"arch-specific", no_argument
, 0, 'A'},
2746 {"version-info", no_argument
, 0, 'V'},
2747 {"use-dynamic", no_argument
, 0, 'D'},
2748 {"hex-dump", required_argument
, 0, 'x'},
2749 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2750 {"unwind", no_argument
, 0, 'u'},
2751 #ifdef SUPPORT_DISASSEMBLY
2752 {"instruction-dump", required_argument
, 0, 'i'},
2755 {"version", no_argument
, 0, 'v'},
2756 {"wide", no_argument
, 0, 'W'},
2757 {"help", no_argument
, 0, 'H'},
2758 {0, no_argument
, 0, 0}
2762 usage (FILE *stream
)
2764 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2765 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
2766 fprintf (stream
, _(" Options are:\n\
2767 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2768 -h --file-header Display the ELF file header\n\
2769 -l --program-headers Display the program headers\n\
2770 --segments An alias for --program-headers\n\
2771 -S --section-headers Display the sections' header\n\
2772 --sections An alias for --section-headers\n\
2773 -g --section-groups Display the section groups\n\
2774 -t --section-details Display the section details\n\
2775 -e --headers Equivalent to: -h -l -S\n\
2776 -s --syms Display the symbol table\n\
2777 --symbols An alias for --syms\n\
2778 -n --notes Display the core notes (if present)\n\
2779 -r --relocs Display the relocations (if present)\n\
2780 -u --unwind Display the unwind info (if present)\n\
2781 -d --dynamic Display the dynamic section (if present)\n\
2782 -V --version-info Display the version sections (if present)\n\
2783 -A --arch-specific Display architecture specific information (if any).\n\
2784 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2785 -x --hex-dump=<number> Dump the contents of section <number>\n\
2786 -w[liaprmfFsoR] or\n\
2787 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2788 Display the contents of DWARF2 debug sections\n"));
2789 #ifdef SUPPORT_DISASSEMBLY
2790 fprintf (stream
, _("\
2791 -i --instruction-dump=<number>\n\
2792 Disassemble the contents of section <number>\n"));
2794 fprintf (stream
, _("\
2795 -I --histogram Display histogram of bucket list lengths\n\
2796 -W --wide Allow output width to exceed 80 characters\n\
2797 @<file> Read options from <file>\n\
2798 -H --help Display this information\n\
2799 -v --version Display the version number of readelf\n"));
2801 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2802 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2804 exit (stream
== stdout
? 0 : 1);
2807 /* Record the fact that the user wants the contents of section number
2808 SECTION to be displayed using the method(s) encoded as flags bits
2809 in TYPE. Note, TYPE can be zero if we are creating the array for
2813 request_dump (unsigned int section
, int type
)
2815 if (section
>= num_dump_sects
)
2817 char *new_dump_sects
;
2819 new_dump_sects
= calloc (section
+ 1, 1);
2821 if (new_dump_sects
== NULL
)
2822 error (_("Out of memory allocating dump request table.\n"));
2825 /* Copy current flag settings. */
2826 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2830 dump_sects
= new_dump_sects
;
2831 num_dump_sects
= section
+ 1;
2836 dump_sects
[section
] |= type
;
2841 /* Request a dump by section name. */
2844 request_dump_byname (const char *section
, int type
)
2846 struct dump_list_entry
*new_request
;
2848 new_request
= malloc (sizeof (struct dump_list_entry
));
2850 error (_("Out of memory allocating dump request table.\n"));
2852 new_request
->name
= strdup (section
);
2853 if (!new_request
->name
)
2854 error (_("Out of memory allocating dump request table.\n"));
2856 new_request
->type
= type
;
2858 new_request
->next
= dump_sects_byname
;
2859 dump_sects_byname
= new_request
;
2863 parse_args (int argc
, char **argv
)
2870 while ((c
= getopt_long
2871 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWH", options
, NULL
)) != EOF
)
2892 do_section_groups
++;
2900 do_section_groups
++;
2905 do_section_details
++;
2947 section
= strtoul (optarg
, & cp
, 0);
2948 if (! *cp
&& section
>= 0)
2949 request_dump (section
, HEX_DUMP
);
2951 request_dump_byname (optarg
, HEX_DUMP
);
2959 unsigned int index
= 0;
2963 while (optarg
[index
])
2964 switch (optarg
[index
++])
2973 do_debug_abbrevs
= 1;
2983 do_debug_pubnames
= 1;
2987 do_debug_aranges
= 1;
2991 do_debug_ranges
= 1;
2995 do_debug_frames_interp
= 1;
2997 do_debug_frames
= 1;
3002 do_debug_macinfo
= 1;
3016 warn (_("Unrecognized debug option '%s'\n"), optarg
);
3021 case OPTION_DEBUG_DUMP
:
3029 const char * option
;
3032 debug_dump_long_opts
;
3034 debug_dump_long_opts opts_table
[] =
3036 /* Please keep this table alpha- sorted. */
3037 { "Ranges", & do_debug_ranges
},
3038 { "abbrev", & do_debug_abbrevs
},
3039 { "aranges", & do_debug_aranges
},
3040 { "frames", & do_debug_frames
},
3041 { "frames-interp", & do_debug_frames_interp
},
3042 { "info", & do_debug_info
},
3043 { "line", & do_debug_lines
},
3044 { "loc", & do_debug_loc
},
3045 { "macro", & do_debug_macinfo
},
3046 { "pubnames", & do_debug_pubnames
},
3047 /* This entry is for compatability
3048 with earlier versions of readelf. */
3049 { "ranges", & do_debug_aranges
},
3050 { "str", & do_debug_str
},
3061 debug_dump_long_opts
* entry
;
3063 for (entry
= opts_table
; entry
->option
; entry
++)
3065 size_t len
= strlen (entry
->option
);
3067 if (strneq (p
, entry
->option
, len
)
3068 && (p
[len
] == ',' || p
[len
] == '\0'))
3070 * entry
->variable
= 1;
3072 /* The --debug-dump=frames-interp option also
3073 enables the --debug-dump=frames option. */
3074 if (do_debug_frames_interp
)
3075 do_debug_frames
= 1;
3082 if (entry
->option
== NULL
)
3084 warn (_("Unrecognized debug option '%s'\n"), p
);
3085 p
= strchr (p
, ',');
3095 #ifdef SUPPORT_DISASSEMBLY
3098 section
= strtoul (optarg
, & cp
, 0);
3099 if (! *cp
&& section
>= 0)
3101 request_dump (section
, DISASS_DUMP
);
3107 print_version (program_name
);
3116 #ifdef SUPPORT_DISASSEMBLY
3119 /* xgettext:c-format */
3120 error (_("Invalid option '-%c'\n"), c
);
3127 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3128 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3129 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3130 && !do_section_groups
)
3134 warn (_("Nothing to do.\n"));
3140 get_elf_class (unsigned int elf_class
)
3142 static char buff
[32];
3146 case ELFCLASSNONE
: return _("none");
3147 case ELFCLASS32
: return "ELF32";
3148 case ELFCLASS64
: return "ELF64";
3150 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3156 get_data_encoding (unsigned int encoding
)
3158 static char buff
[32];
3162 case ELFDATANONE
: return _("none");
3163 case ELFDATA2LSB
: return _("2's complement, little endian");
3164 case ELFDATA2MSB
: return _("2's complement, big endian");
3166 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3171 /* Decode the data held in 'elf_header'. */
3174 process_file_header (void)
3176 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3177 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3178 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3179 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3182 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3190 printf (_("ELF Header:\n"));
3191 printf (_(" Magic: "));
3192 for (i
= 0; i
< EI_NIDENT
; i
++)
3193 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3195 printf (_(" Class: %s\n"),
3196 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3197 printf (_(" Data: %s\n"),
3198 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3199 printf (_(" Version: %d %s\n"),
3200 elf_header
.e_ident
[EI_VERSION
],
3201 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3203 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3206 printf (_(" OS/ABI: %s\n"),
3207 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3208 printf (_(" ABI Version: %d\n"),
3209 elf_header
.e_ident
[EI_ABIVERSION
]);
3210 printf (_(" Type: %s\n"),
3211 get_file_type (elf_header
.e_type
));
3212 printf (_(" Machine: %s\n"),
3213 get_machine_name (elf_header
.e_machine
));
3214 printf (_(" Version: 0x%lx\n"),
3215 (unsigned long) elf_header
.e_version
);
3217 printf (_(" Entry point address: "));
3218 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3219 printf (_("\n Start of program headers: "));
3220 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3221 printf (_(" (bytes into file)\n Start of section headers: "));
3222 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3223 printf (_(" (bytes into file)\n"));
3225 printf (_(" Flags: 0x%lx%s\n"),
3226 (unsigned long) elf_header
.e_flags
,
3227 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3228 printf (_(" Size of this header: %ld (bytes)\n"),
3229 (long) elf_header
.e_ehsize
);
3230 printf (_(" Size of program headers: %ld (bytes)\n"),
3231 (long) elf_header
.e_phentsize
);
3232 printf (_(" Number of program headers: %ld\n"),
3233 (long) elf_header
.e_phnum
);
3234 printf (_(" Size of section headers: %ld (bytes)\n"),
3235 (long) elf_header
.e_shentsize
);
3236 printf (_(" Number of section headers: %ld"),
3237 (long) elf_header
.e_shnum
);
3238 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3239 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3240 putc ('\n', stdout
);
3241 printf (_(" Section header string table index: %ld"),
3242 (long) elf_header
.e_shstrndx
);
3243 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3244 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3245 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3246 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3247 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3248 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3249 printf (" <corrupt: out of range>");
3250 putc ('\n', stdout
);
3253 if (section_headers
!= NULL
)
3255 if (elf_header
.e_shnum
== 0)
3256 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3257 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3258 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3259 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3260 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3261 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3262 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3263 elf_header
.e_shstrndx
= SHN_UNDEF
;
3264 free (section_headers
);
3265 section_headers
= NULL
;
3273 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3275 Elf32_External_Phdr
*phdrs
;
3276 Elf32_External_Phdr
*external
;
3277 Elf_Internal_Phdr
*internal
;
3280 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3281 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3282 _("program headers"));
3286 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3287 i
< elf_header
.e_phnum
;
3288 i
++, internal
++, external
++)
3290 internal
->p_type
= BYTE_GET (external
->p_type
);
3291 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3292 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3293 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3294 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3295 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3296 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3297 internal
->p_align
= BYTE_GET (external
->p_align
);
3306 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3308 Elf64_External_Phdr
*phdrs
;
3309 Elf64_External_Phdr
*external
;
3310 Elf_Internal_Phdr
*internal
;
3313 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3314 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3315 _("program headers"));
3319 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3320 i
< elf_header
.e_phnum
;
3321 i
++, internal
++, external
++)
3323 internal
->p_type
= BYTE_GET (external
->p_type
);
3324 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3325 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3326 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3327 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3328 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3329 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3330 internal
->p_align
= BYTE_GET (external
->p_align
);
3338 /* Returns 1 if the program headers were read into `program_headers'. */
3341 get_program_headers (FILE *file
)
3343 Elf_Internal_Phdr
*phdrs
;
3345 /* Check cache of prior read. */
3346 if (program_headers
!= NULL
)
3349 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3353 error (_("Out of memory\n"));
3358 ? get_32bit_program_headers (file
, phdrs
)
3359 : get_64bit_program_headers (file
, phdrs
))
3361 program_headers
= phdrs
;
3369 /* Returns 1 if the program headers were loaded. */
3372 process_program_headers (FILE *file
)
3374 Elf_Internal_Phdr
*segment
;
3377 if (elf_header
.e_phnum
== 0)
3380 printf (_("\nThere are no program headers in this file.\n"));
3384 if (do_segments
&& !do_header
)
3386 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3387 printf (_("Entry point "));
3388 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3389 printf (_("\nThere are %d program headers, starting at offset "),
3390 elf_header
.e_phnum
);
3391 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3395 if (! get_program_headers (file
))
3400 if (elf_header
.e_phnum
> 1)
3401 printf (_("\nProgram Headers:\n"));
3403 printf (_("\nProgram Headers:\n"));
3407 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3410 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3414 (_(" Type Offset VirtAddr PhysAddr\n"));
3416 (_(" FileSiz MemSiz Flags Align\n"));
3423 for (i
= 0, segment
= program_headers
;
3424 i
< elf_header
.e_phnum
;
3429 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3433 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3434 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3435 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3436 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3437 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3439 (segment
->p_flags
& PF_R
? 'R' : ' '),
3440 (segment
->p_flags
& PF_W
? 'W' : ' '),
3441 (segment
->p_flags
& PF_X
? 'E' : ' '));
3442 printf ("%#lx", (unsigned long) segment
->p_align
);
3446 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3447 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3450 print_vma (segment
->p_offset
, FULL_HEX
);
3454 print_vma (segment
->p_vaddr
, FULL_HEX
);
3456 print_vma (segment
->p_paddr
, FULL_HEX
);
3459 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3460 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3463 print_vma (segment
->p_filesz
, FULL_HEX
);
3467 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3468 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3471 print_vma (segment
->p_offset
, FULL_HEX
);
3475 (segment
->p_flags
& PF_R
? 'R' : ' '),
3476 (segment
->p_flags
& PF_W
? 'W' : ' '),
3477 (segment
->p_flags
& PF_X
? 'E' : ' '));
3479 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3480 printf ("%#lx", (unsigned long) segment
->p_align
);
3483 print_vma (segment
->p_align
, PREFIX_HEX
);
3488 print_vma (segment
->p_offset
, FULL_HEX
);
3490 print_vma (segment
->p_vaddr
, FULL_HEX
);
3492 print_vma (segment
->p_paddr
, FULL_HEX
);
3494 print_vma (segment
->p_filesz
, FULL_HEX
);
3496 print_vma (segment
->p_memsz
, FULL_HEX
);
3498 (segment
->p_flags
& PF_R
? 'R' : ' '),
3499 (segment
->p_flags
& PF_W
? 'W' : ' '),
3500 (segment
->p_flags
& PF_X
? 'E' : ' '));
3501 print_vma (segment
->p_align
, HEX
);
3505 switch (segment
->p_type
)
3509 error (_("more than one dynamic segment\n"));
3511 /* Try to locate the .dynamic section. If there is
3512 a section header table, we can easily locate it. */
3513 if (section_headers
!= NULL
)
3515 Elf_Internal_Shdr
*sec
;
3517 sec
= find_section (".dynamic");
3518 if (sec
== NULL
|| sec
->sh_size
== 0)
3520 error (_("no .dynamic section in the dynamic segment\n"));
3524 if (sec
->sh_type
== SHT_NOBITS
)
3527 dynamic_addr
= sec
->sh_offset
;
3528 dynamic_size
= sec
->sh_size
;
3530 if (dynamic_addr
< segment
->p_offset
3531 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3532 warn (_("the .dynamic section is not contained within the dynamic segment\n"));
3533 else if (dynamic_addr
> segment
->p_offset
)
3534 warn (_("the .dynamic section is not the first section in the dynamic segment.\n"));
3538 /* Otherwise, we can only assume that the .dynamic
3539 section is the first section in the DYNAMIC segment. */
3540 dynamic_addr
= segment
->p_offset
;
3541 dynamic_size
= segment
->p_filesz
;
3546 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3548 error (_("Unable to find program interpreter name\n"));
3552 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3554 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3555 error (_("Internal error: failed to create format string to display program interpreter\n"));
3557 program_interpreter
[0] = 0;
3558 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3559 error (_("Unable to read program interpreter name\n"));
3562 printf (_("\n [Requesting program interpreter: %s]"),
3563 program_interpreter
);
3569 putc ('\n', stdout
);
3572 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3574 printf (_("\n Section to Segment mapping:\n"));
3575 printf (_(" Segment Sections...\n"));
3577 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3580 Elf_Internal_Shdr
*section
;
3582 segment
= program_headers
+ i
;
3583 section
= section_headers
;
3585 printf (" %2.2d ", i
);
3587 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3589 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section
, segment
))
3590 printf ("%s ", SECTION_NAME (section
));
3601 /* Find the file offset corresponding to VMA by using the program headers. */
3604 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3606 Elf_Internal_Phdr
*seg
;
3608 if (! get_program_headers (file
))
3610 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3614 for (seg
= program_headers
;
3615 seg
< program_headers
+ elf_header
.e_phnum
;
3618 if (seg
->p_type
!= PT_LOAD
)
3621 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3622 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3623 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3626 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3633 get_32bit_section_headers (FILE *file
, unsigned int num
)
3635 Elf32_External_Shdr
*shdrs
;
3636 Elf_Internal_Shdr
*internal
;
3639 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3640 elf_header
.e_shentsize
, num
, _("section headers"));
3644 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3646 if (section_headers
== NULL
)
3648 error (_("Out of memory\n"));
3652 for (i
= 0, internal
= section_headers
;
3656 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3657 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3658 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3659 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3660 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3661 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3662 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3663 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3664 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3665 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3674 get_64bit_section_headers (FILE *file
, unsigned int num
)
3676 Elf64_External_Shdr
*shdrs
;
3677 Elf_Internal_Shdr
*internal
;
3680 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3681 elf_header
.e_shentsize
, num
, _("section headers"));
3685 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3687 if (section_headers
== NULL
)
3689 error (_("Out of memory\n"));
3693 for (i
= 0, internal
= section_headers
;
3697 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3698 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3699 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3700 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3701 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3702 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3703 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3704 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3705 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3706 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3714 static Elf_Internal_Sym
*
3715 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3717 unsigned long number
;
3718 Elf32_External_Sym
*esyms
;
3719 Elf_External_Sym_Shndx
*shndx
;
3720 Elf_Internal_Sym
*isyms
;
3721 Elf_Internal_Sym
*psym
;
3724 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3730 if (symtab_shndx_hdr
!= NULL
3731 && (symtab_shndx_hdr
->sh_link
3732 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3734 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3735 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3743 number
= section
->sh_size
/ section
->sh_entsize
;
3744 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3748 error (_("Out of memory\n"));
3755 for (j
= 0, psym
= isyms
;
3759 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3760 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3761 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3762 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3763 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3765 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3766 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3767 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3777 static Elf_Internal_Sym
*
3778 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3780 unsigned long number
;
3781 Elf64_External_Sym
*esyms
;
3782 Elf_External_Sym_Shndx
*shndx
;
3783 Elf_Internal_Sym
*isyms
;
3784 Elf_Internal_Sym
*psym
;
3787 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3793 if (symtab_shndx_hdr
!= NULL
3794 && (symtab_shndx_hdr
->sh_link
3795 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3797 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3798 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3806 number
= section
->sh_size
/ section
->sh_entsize
;
3807 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3811 error (_("Out of memory\n"));
3818 for (j
= 0, psym
= isyms
;
3822 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3823 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3824 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3825 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3826 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3828 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3829 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3830 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3841 get_elf_section_flags (bfd_vma sh_flags
)
3843 static char buff
[1024];
3845 int field_size
= is_32bit_elf
? 8 : 16;
3846 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3847 bfd_vma os_flags
= 0;
3848 bfd_vma proc_flags
= 0;
3849 bfd_vma unknown_flags
= 0;
3863 { "LINK ORDER", 10 },
3864 { "OS NONCONF", 10 },
3869 if (do_section_details
)
3871 sprintf (buff
, "[%*.*lx]: ",
3872 field_size
, field_size
, (unsigned long) sh_flags
);
3873 p
+= field_size
+ 4;
3880 flag
= sh_flags
& - sh_flags
;
3883 if (do_section_details
)
3887 case SHF_WRITE
: index
= 0; break;
3888 case SHF_ALLOC
: index
= 1; break;
3889 case SHF_EXECINSTR
: index
= 2; break;
3890 case SHF_MERGE
: index
= 3; break;
3891 case SHF_STRINGS
: index
= 4; break;
3892 case SHF_INFO_LINK
: index
= 5; break;
3893 case SHF_LINK_ORDER
: index
= 6; break;
3894 case SHF_OS_NONCONFORMING
: index
= 7; break;
3895 case SHF_GROUP
: index
= 8; break;
3896 case SHF_TLS
: index
= 9; break;
3905 if (p
!= buff
+ field_size
+ 4)
3907 if (size
< (10 + 2))
3914 size
-= flags
[index
].len
;
3915 p
= stpcpy (p
, flags
[index
].str
);
3917 else if (flag
& SHF_MASKOS
)
3919 else if (flag
& SHF_MASKPROC
)
3922 unknown_flags
|= flag
;
3928 case SHF_WRITE
: *p
= 'W'; break;
3929 case SHF_ALLOC
: *p
= 'A'; break;
3930 case SHF_EXECINSTR
: *p
= 'X'; break;
3931 case SHF_MERGE
: *p
= 'M'; break;
3932 case SHF_STRINGS
: *p
= 'S'; break;
3933 case SHF_INFO_LINK
: *p
= 'I'; break;
3934 case SHF_LINK_ORDER
: *p
= 'L'; break;
3935 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3936 case SHF_GROUP
: *p
= 'G'; break;
3937 case SHF_TLS
: *p
= 'T'; break;
3940 if (elf_header
.e_machine
== EM_X86_64
3941 && flag
== SHF_X86_64_LARGE
)
3943 else if (flag
& SHF_MASKOS
)
3946 sh_flags
&= ~ SHF_MASKOS
;
3948 else if (flag
& SHF_MASKPROC
)
3951 sh_flags
&= ~ SHF_MASKPROC
;
3961 if (do_section_details
)
3965 size
-= 5 + field_size
;
3966 if (p
!= buff
+ field_size
+ 4)
3974 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3975 (unsigned long) os_flags
);
3976 p
+= 5 + field_size
;
3980 size
-= 7 + field_size
;
3981 if (p
!= buff
+ field_size
+ 4)
3989 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
3990 (unsigned long) proc_flags
);
3991 p
+= 7 + field_size
;
3995 size
-= 10 + field_size
;
3996 if (p
!= buff
+ field_size
+ 4)
4004 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
4005 (unsigned long) unknown_flags
);
4006 p
+= 10 + field_size
;
4015 process_section_headers (FILE *file
)
4017 Elf_Internal_Shdr
*section
;
4020 section_headers
= NULL
;
4022 if (elf_header
.e_shnum
== 0)
4025 printf (_("\nThere are no sections in this file.\n"));
4030 if (do_sections
&& !do_header
)
4031 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4032 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4036 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4039 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4042 /* Read in the string table, so that we have names to display. */
4043 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4044 && SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
4046 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
4048 if (section
->sh_size
!= 0)
4050 string_table
= get_data (NULL
, file
, section
->sh_offset
,
4051 1, section
->sh_size
, _("string table"));
4053 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4057 /* Scan the sections for the dynamic symbol table
4058 and dynamic string table and debug sections. */
4059 dynamic_symbols
= NULL
;
4060 dynamic_strings
= NULL
;
4061 dynamic_syminfo
= NULL
;
4062 symtab_shndx_hdr
= NULL
;
4064 eh_addr_size
= is_32bit_elf
? 4 : 8;
4065 switch (elf_header
.e_machine
)
4068 case EM_MIPS_RS3_LE
:
4069 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4070 FDE addresses. However, the ABI also has a semi-official ILP32
4071 variant for which the normal FDE address size rules apply.
4073 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4074 section, where XX is the size of longs in bits. Unfortunately,
4075 earlier compilers provided no way of distinguishing ILP32 objects
4076 from LP64 objects, so if there's any doubt, we should assume that
4077 the official LP64 form is being used. */
4078 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4079 && find_section (".gcc_compiled_long32") == NULL
)
4085 switch (elf_header
.e_flags
& EF_H8_MACH
)
4087 case E_H8_MACH_H8300
:
4088 case E_H8_MACH_H8300HN
:
4089 case E_H8_MACH_H8300SN
:
4090 case E_H8_MACH_H8300SXN
:
4093 case E_H8_MACH_H8300H
:
4094 case E_H8_MACH_H8300S
:
4095 case E_H8_MACH_H8300SX
:
4101 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4104 size_t expected_entsize \
4105 = is_32bit_elf ? size32 : size64; \
4106 if (section->sh_entsize != expected_entsize) \
4107 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4108 i, (unsigned long int) section->sh_entsize, \
4109 (unsigned long int) expected_entsize); \
4110 section->sh_entsize = expected_entsize; \
4113 #define CHECK_ENTSIZE(section, i, type) \
4114 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4115 sizeof (Elf64_External_##type))
4117 for (i
= 0, section
= section_headers
;
4118 i
< elf_header
.e_shnum
;
4121 char *name
= SECTION_NAME (section
);
4123 if (section
->sh_type
== SHT_DYNSYM
)
4125 if (dynamic_symbols
!= NULL
)
4127 error (_("File contains multiple dynamic symbol tables\n"));
4131 CHECK_ENTSIZE (section
, i
, Sym
);
4132 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4133 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4135 else if (section
->sh_type
== SHT_STRTAB
4136 && streq (name
, ".dynstr"))
4138 if (dynamic_strings
!= NULL
)
4140 error (_("File contains multiple dynamic string tables\n"));
4144 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
4145 1, section
->sh_size
, _("dynamic strings"));
4146 dynamic_strings_length
= section
->sh_size
;
4148 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4150 if (symtab_shndx_hdr
!= NULL
)
4152 error (_("File contains multiple symtab shndx tables\n"));
4155 symtab_shndx_hdr
= section
;
4157 else if (section
->sh_type
== SHT_SYMTAB
)
4158 CHECK_ENTSIZE (section
, i
, Sym
);
4159 else if (section
->sh_type
== SHT_GROUP
)
4160 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4161 else if (section
->sh_type
== SHT_REL
)
4162 CHECK_ENTSIZE (section
, i
, Rel
);
4163 else if (section
->sh_type
== SHT_RELA
)
4164 CHECK_ENTSIZE (section
, i
, Rela
);
4165 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4166 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
4167 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
4168 || do_debug_loc
|| do_debug_ranges
)
4169 && const_strneq (name
, ".debug_"))
4174 || (do_debug_info
&& streq (name
, "info"))
4175 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4176 || (do_debug_lines
&& streq (name
, "line"))
4177 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4178 || (do_debug_aranges
&& streq (name
, "aranges"))
4179 || (do_debug_ranges
&& streq (name
, "ranges"))
4180 || (do_debug_frames
&& streq (name
, "frame"))
4181 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4182 || (do_debug_str
&& streq (name
, "str"))
4183 || (do_debug_loc
&& streq (name
, "loc"))
4185 request_dump (i
, DEBUG_DUMP
);
4187 /* linkonce section to be combined with .debug_info at link time. */
4188 else if ((do_debugging
|| do_debug_info
)
4189 && const_strneq (name
, ".gnu.linkonce.wi."))
4190 request_dump (i
, DEBUG_DUMP
);
4191 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4192 request_dump (i
, DEBUG_DUMP
);
4198 if (elf_header
.e_shnum
> 1)
4199 printf (_("\nSection Headers:\n"));
4201 printf (_("\nSection Header:\n"));
4205 if (do_section_details
)
4207 printf (_(" [Nr] Name\n"));
4208 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4212 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4216 if (do_section_details
)
4218 printf (_(" [Nr] Name\n"));
4219 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4223 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4227 if (do_section_details
)
4229 printf (_(" [Nr] Name\n"));
4230 printf (_(" Type Address Offset Link\n"));
4231 printf (_(" Size EntSize Info Align\n"));
4235 printf (_(" [Nr] Name Type Address Offset\n"));
4236 printf (_(" Size EntSize Flags Link Info Align\n"));
4240 if (do_section_details
)
4241 printf (_(" Flags\n"));
4243 for (i
= 0, section
= section_headers
;
4244 i
< elf_header
.e_shnum
;
4247 if (do_section_details
)
4249 printf (" [%2u] %s\n",
4250 SECTION_HEADER_NUM (i
),
4251 SECTION_NAME (section
));
4252 if (is_32bit_elf
|| do_wide
)
4253 printf (" %-15.15s ",
4254 get_section_type_name (section
->sh_type
));
4257 printf (" [%2u] %-17.17s %-15.15s ",
4258 SECTION_HEADER_NUM (i
),
4259 SECTION_NAME (section
),
4260 get_section_type_name (section
->sh_type
));
4264 print_vma (section
->sh_addr
, LONG_HEX
);
4266 printf ( " %6.6lx %6.6lx %2.2lx",
4267 (unsigned long) section
->sh_offset
,
4268 (unsigned long) section
->sh_size
,
4269 (unsigned long) section
->sh_entsize
);
4271 if (do_section_details
)
4272 fputs (" ", stdout
);
4274 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4276 printf ("%2ld %3lu %2ld\n",
4277 (unsigned long) section
->sh_link
,
4278 (unsigned long) section
->sh_info
,
4279 (unsigned long) section
->sh_addralign
);
4283 print_vma (section
->sh_addr
, LONG_HEX
);
4285 if ((long) section
->sh_offset
== section
->sh_offset
)
4286 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4290 print_vma (section
->sh_offset
, LONG_HEX
);
4293 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4294 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4298 print_vma (section
->sh_size
, LONG_HEX
);
4301 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4302 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4306 print_vma (section
->sh_entsize
, LONG_HEX
);
4309 if (do_section_details
)
4310 fputs (" ", stdout
);
4312 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4314 printf ("%2ld %3lu ",
4315 (unsigned long) section
->sh_link
,
4316 (unsigned long) section
->sh_info
);
4318 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4319 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4322 print_vma (section
->sh_addralign
, DEC
);
4326 else if (do_section_details
)
4328 printf (" %-15.15s ",
4329 get_section_type_name (section
->sh_type
));
4330 print_vma (section
->sh_addr
, LONG_HEX
);
4331 if ((long) section
->sh_offset
== section
->sh_offset
)
4332 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4336 print_vma (section
->sh_offset
, LONG_HEX
);
4338 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4339 print_vma (section
->sh_size
, LONG_HEX
);
4341 print_vma (section
->sh_entsize
, LONG_HEX
);
4343 printf (" %-16lu %ld\n",
4344 (unsigned long) section
->sh_info
,
4345 (unsigned long) section
->sh_addralign
);
4350 print_vma (section
->sh_addr
, LONG_HEX
);
4351 if ((long) section
->sh_offset
== section
->sh_offset
)
4352 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4356 print_vma (section
->sh_offset
, LONG_HEX
);
4359 print_vma (section
->sh_size
, LONG_HEX
);
4361 print_vma (section
->sh_entsize
, LONG_HEX
);
4363 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4365 printf (" %2ld %3lu %ld\n",
4366 (unsigned long) section
->sh_link
,
4367 (unsigned long) section
->sh_info
,
4368 (unsigned long) section
->sh_addralign
);
4371 if (do_section_details
)
4372 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4375 if (!do_section_details
)
4376 printf (_("Key to Flags:\n\
4377 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4378 I (info), L (link order), G (group), x (unknown)\n\
4379 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4385 get_group_flags (unsigned int flags
)
4387 static char buff
[32];
4394 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4401 process_section_groups (FILE *file
)
4403 Elf_Internal_Shdr
*section
;
4405 struct group
*group
;
4406 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4407 Elf_Internal_Sym
*symtab
;
4411 /* Don't process section groups unless needed. */
4412 if (!do_unwind
&& !do_section_groups
)
4415 if (elf_header
.e_shnum
== 0)
4417 if (do_section_groups
)
4418 printf (_("\nThere are no sections in this file.\n"));
4423 if (section_headers
== NULL
)
4425 error (_("Section headers are not available!\n"));
4429 section_headers_groups
= calloc (elf_header
.e_shnum
,
4430 sizeof (struct group
*));
4432 if (section_headers_groups
== NULL
)
4434 error (_("Out of memory\n"));
4438 /* Scan the sections for the group section. */
4440 for (i
= 0, section
= section_headers
;
4441 i
< elf_header
.e_shnum
;
4443 if (section
->sh_type
== SHT_GROUP
)
4446 if (group_count
== 0)
4448 if (do_section_groups
)
4449 printf (_("\nThere are no section groups in this file.\n"));
4454 section_groups
= calloc (group_count
, sizeof (struct group
));
4456 if (section_groups
== NULL
)
4458 error (_("Out of memory\n"));
4467 for (i
= 0, section
= section_headers
, group
= section_groups
;
4468 i
< elf_header
.e_shnum
;
4471 if (section
->sh_type
== SHT_GROUP
)
4473 char *name
= SECTION_NAME (section
);
4475 unsigned char *start
, *indices
;
4476 unsigned int entry
, j
, size
;
4477 Elf_Internal_Shdr
*sec
;
4478 Elf_Internal_Sym
*sym
;
4480 /* Get the symbol table. */
4481 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4482 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4485 error (_("Bad sh_link in group section `%s'\n"), name
);
4489 if (symtab_sec
!= sec
)
4494 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4497 sym
= symtab
+ section
->sh_info
;
4499 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4501 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4504 error (_("Bad sh_info in group section `%s'\n"), name
);
4508 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4517 /* Get the string table. */
4518 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4519 >= elf_header
.e_shnum
)
4528 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4533 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4534 1, strtab_sec
->sh_size
,
4536 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4538 group_name
= sym
->st_name
< strtab_size
4539 ? strtab
+ sym
->st_name
: "<corrupt>";
4542 start
= get_data (NULL
, file
, section
->sh_offset
,
4543 1, section
->sh_size
, _("section data"));
4546 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4547 entry
= byte_get (indices
, 4);
4550 if (do_section_groups
)
4552 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4553 get_group_flags (entry
), i
, name
, group_name
, size
);
4555 printf (_(" [Index] Name\n"));
4558 group
->group_index
= i
;
4560 for (j
= 0; j
< size
; j
++)
4562 struct group_list
*g
;
4564 entry
= byte_get (indices
, 4);
4567 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4569 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4570 entry
, i
, elf_header
.e_shnum
- 1);
4573 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4575 error (_("invalid section [%5u] in group section [%5u]\n"),
4580 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4585 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4587 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4592 /* Intel C/C++ compiler may put section 0 in a
4593 section group. We just warn it the first time
4594 and ignore it afterwards. */
4595 static int warned
= 0;
4598 error (_("section 0 in group section [%5u]\n"),
4599 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4605 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4608 if (do_section_groups
)
4610 sec
= SECTION_HEADER (entry
);
4611 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4614 g
= xmalloc (sizeof (struct group_list
));
4615 g
->section_index
= entry
;
4616 g
->next
= group
->root
;
4640 } dynamic_relocations
[] =
4642 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4643 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4644 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4647 /* Process the reloc section. */
4650 process_relocs (FILE *file
)
4652 unsigned long rel_size
;
4653 unsigned long rel_offset
;
4659 if (do_using_dynamic
)
4663 int has_dynamic_reloc
;
4666 has_dynamic_reloc
= 0;
4668 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4670 is_rela
= dynamic_relocations
[i
].rela
;
4671 name
= dynamic_relocations
[i
].name
;
4672 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4673 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4675 has_dynamic_reloc
|= rel_size
;
4677 if (is_rela
== UNKNOWN
)
4679 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4680 switch (dynamic_info
[DT_PLTREL
])
4694 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4695 name
, rel_offset
, rel_size
);
4697 dump_relocations (file
,
4698 offset_from_vma (file
, rel_offset
, rel_size
),
4700 dynamic_symbols
, num_dynamic_syms
,
4701 dynamic_strings
, dynamic_strings_length
, is_rela
);
4705 if (! has_dynamic_reloc
)
4706 printf (_("\nThere are no dynamic relocations in this file.\n"));
4710 Elf_Internal_Shdr
*section
;
4714 for (i
= 0, section
= section_headers
;
4715 i
< elf_header
.e_shnum
;
4718 if ( section
->sh_type
!= SHT_RELA
4719 && section
->sh_type
!= SHT_REL
)
4722 rel_offset
= section
->sh_offset
;
4723 rel_size
= section
->sh_size
;
4727 Elf_Internal_Shdr
*strsec
;
4730 printf (_("\nRelocation section "));
4732 if (string_table
== NULL
)
4733 printf ("%d", section
->sh_name
);
4735 printf (_("'%s'"), SECTION_NAME (section
));
4737 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4738 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4740 is_rela
= section
->sh_type
== SHT_RELA
;
4742 if (section
->sh_link
4743 && SECTION_HEADER_INDEX (section
->sh_link
)
4744 < elf_header
.e_shnum
)
4746 Elf_Internal_Shdr
*symsec
;
4747 Elf_Internal_Sym
*symtab
;
4748 unsigned long nsyms
;
4749 unsigned long strtablen
= 0;
4750 char *strtab
= NULL
;
4752 symsec
= SECTION_HEADER (section
->sh_link
);
4753 if (symsec
->sh_type
!= SHT_SYMTAB
4754 && symsec
->sh_type
!= SHT_DYNSYM
)
4757 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4758 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4763 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4764 < elf_header
.e_shnum
)
4766 strsec
= SECTION_HEADER (symsec
->sh_link
);
4768 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4771 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4774 dump_relocations (file
, rel_offset
, rel_size
,
4775 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4781 dump_relocations (file
, rel_offset
, rel_size
,
4782 NULL
, 0, NULL
, 0, is_rela
);
4789 printf (_("\nThere are no relocations in this file.\n"));
4795 /* Process the unwind section. */
4797 #include "unwind-ia64.h"
4799 /* An absolute address consists of a section and an offset. If the
4800 section is NULL, the offset itself is the address, otherwise, the
4801 address equals to LOAD_ADDRESS(section) + offset. */
4805 unsigned short section
;
4809 #define ABSADDR(a) \
4811 ? section_headers [(a).section].sh_addr + (a).offset \
4814 struct ia64_unw_aux_info
4816 struct ia64_unw_table_entry
4818 struct absaddr start
;
4820 struct absaddr info
;
4822 *table
; /* Unwind table. */
4823 unsigned long table_len
; /* Length of unwind table. */
4824 unsigned char *info
; /* Unwind info. */
4825 unsigned long info_size
; /* Size of unwind info. */
4826 bfd_vma info_addr
; /* starting address of unwind info. */
4827 bfd_vma seg_base
; /* Starting address of segment. */
4828 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4829 unsigned long nsyms
; /* Number of symbols. */
4830 char *strtab
; /* The string table. */
4831 unsigned long strtab_size
; /* Size of string table. */
4835 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4836 unsigned long nsyms
,
4838 unsigned long strtab_size
,
4839 struct absaddr addr
,
4840 const char **symname
,
4843 bfd_vma dist
= 0x100000;
4844 Elf_Internal_Sym
*sym
, *best
= NULL
;
4847 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4849 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4850 && sym
->st_name
!= 0
4851 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4852 && addr
.offset
>= sym
->st_value
4853 && addr
.offset
- sym
->st_value
< dist
)
4856 dist
= addr
.offset
- sym
->st_value
;
4863 *symname
= (best
->st_name
>= strtab_size
4864 ? "<corrupt>" : strtab
+ best
->st_name
);
4869 *offset
= addr
.offset
;
4873 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4875 struct ia64_unw_table_entry
*tp
;
4878 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4882 const unsigned char *dp
;
4883 const unsigned char *head
;
4884 const char *procname
;
4886 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4887 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4889 fputs ("\n<", stdout
);
4893 fputs (procname
, stdout
);
4896 printf ("+%lx", (unsigned long) offset
);
4899 fputs (">: [", stdout
);
4900 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4901 fputc ('-', stdout
);
4902 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4903 printf ("], info at +0x%lx\n",
4904 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4906 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4907 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4909 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4910 (unsigned) UNW_VER (stamp
),
4911 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4912 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4913 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4914 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4916 if (UNW_VER (stamp
) != 1)
4918 printf ("\tUnknown version.\n");
4923 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4924 dp
= unw_decode (dp
, in_body
, & in_body
);
4929 slurp_ia64_unwind_table (FILE *file
,
4930 struct ia64_unw_aux_info
*aux
,
4931 Elf_Internal_Shdr
*sec
)
4933 unsigned long size
, nrelas
, i
;
4934 Elf_Internal_Phdr
*seg
;
4935 struct ia64_unw_table_entry
*tep
;
4936 Elf_Internal_Shdr
*relsec
;
4937 Elf_Internal_Rela
*rela
, *rp
;
4938 unsigned char *table
, *tp
;
4939 Elf_Internal_Sym
*sym
;
4940 const char *relname
;
4942 /* First, find the starting address of the segment that includes
4945 if (elf_header
.e_phnum
)
4947 if (! get_program_headers (file
))
4950 for (seg
= program_headers
;
4951 seg
< program_headers
+ elf_header
.e_phnum
;
4954 if (seg
->p_type
!= PT_LOAD
)
4957 if (sec
->sh_addr
>= seg
->p_vaddr
4958 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4960 aux
->seg_base
= seg
->p_vaddr
;
4966 /* Second, build the unwind table from the contents of the unwind section: */
4967 size
= sec
->sh_size
;
4968 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4972 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4974 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4976 tep
->start
.section
= SHN_UNDEF
;
4977 tep
->end
.section
= SHN_UNDEF
;
4978 tep
->info
.section
= SHN_UNDEF
;
4981 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4982 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4983 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4987 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
4988 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
4989 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
4991 tep
->start
.offset
+= aux
->seg_base
;
4992 tep
->end
.offset
+= aux
->seg_base
;
4993 tep
->info
.offset
+= aux
->seg_base
;
4997 /* Third, apply any relocations to the unwind table: */
4999 for (relsec
= section_headers
;
5000 relsec
< section_headers
+ elf_header
.e_shnum
;
5003 if (relsec
->sh_type
!= SHT_RELA
5004 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5005 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5008 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5012 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5016 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5017 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5021 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5022 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5025 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5027 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5031 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5033 switch (rp
->r_offset
/eh_addr_size
% 3)
5036 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5037 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5040 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5041 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5044 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5045 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5055 aux
->table_len
= size
/ (3 * eh_addr_size
);
5060 ia64_process_unwind (FILE *file
)
5062 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
5063 unsigned long i
, unwcount
= 0, unwstart
= 0;
5064 struct ia64_unw_aux_info aux
;
5066 memset (& aux
, 0, sizeof (aux
));
5068 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5070 if (sec
->sh_type
== SHT_SYMTAB
5071 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5073 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5074 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5076 strsec
= SECTION_HEADER (sec
->sh_link
);
5077 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5078 1, strsec
->sh_size
, _("string table"));
5079 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5081 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5086 printf (_("\nThere are no unwind sections in this file.\n"));
5088 while (unwcount
-- > 0)
5093 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5094 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5095 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5102 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5104 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5106 /* We need to find which section group it is in. */
5107 struct group_list
*g
= section_headers_groups
[i
]->root
;
5109 for (; g
!= NULL
; g
= g
->next
)
5111 sec
= SECTION_HEADER (g
->section_index
);
5113 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5118 i
= elf_header
.e_shnum
;
5120 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5122 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5123 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5124 suffix
= SECTION_NAME (unwsec
) + len
;
5125 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5127 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5128 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5133 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5134 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5135 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5136 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5138 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5139 suffix
= SECTION_NAME (unwsec
) + len
;
5140 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5142 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5143 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5147 if (i
== elf_header
.e_shnum
)
5149 printf (_("\nCould not find unwind info section for "));
5151 if (string_table
== NULL
)
5152 printf ("%d", unwsec
->sh_name
);
5154 printf (_("'%s'"), SECTION_NAME (unwsec
));
5158 aux
.info_size
= sec
->sh_size
;
5159 aux
.info_addr
= sec
->sh_addr
;
5160 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
5163 printf (_("\nUnwind section "));
5165 if (string_table
== NULL
)
5166 printf ("%d", unwsec
->sh_name
);
5168 printf (_("'%s'"), SECTION_NAME (unwsec
));
5170 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5171 (unsigned long) unwsec
->sh_offset
,
5172 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5174 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5176 if (aux
.table_len
> 0)
5177 dump_ia64_unwind (& aux
);
5180 free ((char *) aux
.table
);
5182 free ((char *) aux
.info
);
5191 free ((char *) aux
.strtab
);
5196 struct hppa_unw_aux_info
5198 struct hppa_unw_table_entry
5200 struct absaddr start
;
5202 unsigned int Cannot_unwind
:1; /* 0 */
5203 unsigned int Millicode
:1; /* 1 */
5204 unsigned int Millicode_save_sr0
:1; /* 2 */
5205 unsigned int Region_description
:2; /* 3..4 */
5206 unsigned int reserved1
:1; /* 5 */
5207 unsigned int Entry_SR
:1; /* 6 */
5208 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5209 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5210 unsigned int Args_stored
:1; /* 16 */
5211 unsigned int Variable_Frame
:1; /* 17 */
5212 unsigned int Separate_Package_Body
:1; /* 18 */
5213 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5214 unsigned int Stack_Overflow_Check
:1; /* 20 */
5215 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5216 unsigned int Ada_Region
:1; /* 22 */
5217 unsigned int cxx_info
:1; /* 23 */
5218 unsigned int cxx_try_catch
:1; /* 24 */
5219 unsigned int sched_entry_seq
:1; /* 25 */
5220 unsigned int reserved2
:1; /* 26 */
5221 unsigned int Save_SP
:1; /* 27 */
5222 unsigned int Save_RP
:1; /* 28 */
5223 unsigned int Save_MRP_in_frame
:1; /* 29 */
5224 unsigned int extn_ptr_defined
:1; /* 30 */
5225 unsigned int Cleanup_defined
:1; /* 31 */
5227 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5228 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5229 unsigned int Large_frame
:1; /* 2 */
5230 unsigned int Pseudo_SP_Set
:1; /* 3 */
5231 unsigned int reserved4
:1; /* 4 */
5232 unsigned int Total_frame_size
:27; /* 5..31 */
5234 *table
; /* Unwind table. */
5235 unsigned long table_len
; /* Length of unwind table. */
5236 bfd_vma seg_base
; /* Starting address of segment. */
5237 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5238 unsigned long nsyms
; /* Number of symbols. */
5239 char *strtab
; /* The string table. */
5240 unsigned long strtab_size
; /* Size of string table. */
5244 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5246 struct hppa_unw_table_entry
*tp
;
5248 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5251 const char *procname
;
5253 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5254 aux
->strtab_size
, tp
->start
, &procname
,
5257 fputs ("\n<", stdout
);
5261 fputs (procname
, stdout
);
5264 printf ("+%lx", (unsigned long) offset
);
5267 fputs (">: [", stdout
);
5268 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5269 fputc ('-', stdout
);
5270 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5273 #define PF(_m) if (tp->_m) printf (#_m " ");
5274 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5277 PF(Millicode_save_sr0
);
5278 /* PV(Region_description); */
5284 PF(Separate_Package_Body
);
5285 PF(Frame_Extension_Millicode
);
5286 PF(Stack_Overflow_Check
);
5287 PF(Two_Instruction_SP_Increment
);
5291 PF(sched_entry_seq
);
5294 PF(Save_MRP_in_frame
);
5295 PF(extn_ptr_defined
);
5296 PF(Cleanup_defined
);
5297 PF(MPE_XL_interrupt_marker
);
5298 PF(HP_UX_interrupt_marker
);
5301 PV(Total_frame_size
);
5310 slurp_hppa_unwind_table (FILE *file
,
5311 struct hppa_unw_aux_info
*aux
,
5312 Elf_Internal_Shdr
*sec
)
5314 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5315 Elf_Internal_Phdr
*seg
;
5316 struct hppa_unw_table_entry
*tep
;
5317 Elf_Internal_Shdr
*relsec
;
5318 Elf_Internal_Rela
*rela
, *rp
;
5319 unsigned char *table
, *tp
;
5320 Elf_Internal_Sym
*sym
;
5321 const char *relname
;
5323 /* First, find the starting address of the segment that includes
5326 if (elf_header
.e_phnum
)
5328 if (! get_program_headers (file
))
5331 for (seg
= program_headers
;
5332 seg
< program_headers
+ elf_header
.e_phnum
;
5335 if (seg
->p_type
!= PT_LOAD
)
5338 if (sec
->sh_addr
>= seg
->p_vaddr
5339 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5341 aux
->seg_base
= seg
->p_vaddr
;
5347 /* Second, build the unwind table from the contents of the unwind
5349 size
= sec
->sh_size
;
5350 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5355 nentries
= size
/ unw_ent_size
;
5356 size
= unw_ent_size
* nentries
;
5358 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5360 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5362 unsigned int tmp1
, tmp2
;
5364 tep
->start
.section
= SHN_UNDEF
;
5365 tep
->end
.section
= SHN_UNDEF
;
5367 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5368 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5369 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5370 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5372 tep
->start
.offset
+= aux
->seg_base
;
5373 tep
->end
.offset
+= aux
->seg_base
;
5375 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5376 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5377 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5378 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5379 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5380 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5381 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5382 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5383 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5384 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5385 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5386 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5387 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5388 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5389 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5390 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5391 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5392 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5393 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5394 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5395 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5396 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5397 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5398 tep
->Cleanup_defined
= tmp1
& 0x1;
5400 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5401 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5402 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5403 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5404 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5405 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5409 /* Third, apply any relocations to the unwind table. */
5411 for (relsec
= section_headers
;
5412 relsec
< section_headers
+ elf_header
.e_shnum
;
5415 if (relsec
->sh_type
!= SHT_RELA
5416 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5417 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5420 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5424 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5428 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5429 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5433 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5434 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5437 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5438 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5440 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5444 i
= rp
->r_offset
/ unw_ent_size
;
5446 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5449 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5450 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5453 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5454 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5464 aux
->table_len
= nentries
;
5470 hppa_process_unwind (FILE *file
)
5472 struct hppa_unw_aux_info aux
;
5473 Elf_Internal_Shdr
*unwsec
= NULL
;
5474 Elf_Internal_Shdr
*strsec
;
5475 Elf_Internal_Shdr
*sec
;
5478 memset (& aux
, 0, sizeof (aux
));
5480 if (string_table
== NULL
)
5483 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5485 if (sec
->sh_type
== SHT_SYMTAB
5486 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5488 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5489 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5491 strsec
= SECTION_HEADER (sec
->sh_link
);
5492 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5493 1, strsec
->sh_size
, _("string table"));
5494 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5496 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5501 printf (_("\nThere are no unwind sections in this file.\n"));
5503 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5505 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5507 printf (_("\nUnwind section "));
5508 printf (_("'%s'"), SECTION_NAME (sec
));
5510 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5511 (unsigned long) sec
->sh_offset
,
5512 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5514 slurp_hppa_unwind_table (file
, &aux
, sec
);
5515 if (aux
.table_len
> 0)
5516 dump_hppa_unwind (&aux
);
5519 free ((char *) aux
.table
);
5527 free ((char *) aux
.strtab
);
5533 process_unwind (FILE *file
)
5535 struct unwind_handler
{
5537 int (*handler
)(FILE *file
);
5539 { EM_IA_64
, ia64_process_unwind
},
5540 { EM_PARISC
, hppa_process_unwind
},
5548 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5549 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5550 return handlers
[i
].handler (file
);
5552 printf (_("\nThere are no unwind sections in this file.\n"));
5557 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5559 switch (entry
->d_tag
)
5562 if (entry
->d_un
.d_val
== 0)
5566 static const char * opts
[] =
5568 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5569 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5570 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5571 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5576 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
5577 if (entry
->d_un
.d_val
& (1 << cnt
))
5579 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5586 case DT_MIPS_IVERSION
:
5587 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5588 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5590 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5593 case DT_MIPS_TIME_STAMP
:
5598 time_t time
= entry
->d_un
.d_val
;
5599 tmp
= gmtime (&time
);
5600 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5601 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5602 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5603 printf ("Time Stamp: %s\n", timebuf
);
5607 case DT_MIPS_RLD_VERSION
:
5608 case DT_MIPS_LOCAL_GOTNO
:
5609 case DT_MIPS_CONFLICTNO
:
5610 case DT_MIPS_LIBLISTNO
:
5611 case DT_MIPS_SYMTABNO
:
5612 case DT_MIPS_UNREFEXTNO
:
5613 case DT_MIPS_HIPAGENO
:
5614 case DT_MIPS_DELTA_CLASS_NO
:
5615 case DT_MIPS_DELTA_INSTANCE_NO
:
5616 case DT_MIPS_DELTA_RELOC_NO
:
5617 case DT_MIPS_DELTA_SYM_NO
:
5618 case DT_MIPS_DELTA_CLASSSYM_NO
:
5619 case DT_MIPS_COMPACT_SIZE
:
5620 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5624 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5630 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5632 switch (entry
->d_tag
)
5634 case DT_HP_DLD_FLAGS
:
5643 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5644 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5645 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5646 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5647 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5648 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5649 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5650 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5651 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5652 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5653 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5654 { DT_HP_GST
, "HP_GST" },
5655 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5656 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5657 { DT_HP_NODELETE
, "HP_NODELETE" },
5658 { DT_HP_GROUP
, "HP_GROUP" },
5659 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5663 bfd_vma val
= entry
->d_un
.d_val
;
5665 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
5666 if (val
& flags
[cnt
].bit
)
5670 fputs (flags
[cnt
].str
, stdout
);
5672 val
^= flags
[cnt
].bit
;
5675 if (val
!= 0 || first
)
5679 print_vma (val
, HEX
);
5685 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5692 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5694 switch (entry
->d_tag
)
5696 case DT_IA_64_PLT_RESERVE
:
5697 /* First 3 slots reserved. */
5698 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5700 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5704 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5711 get_32bit_dynamic_section (FILE *file
)
5713 Elf32_External_Dyn
*edyn
, *ext
;
5714 Elf_Internal_Dyn
*entry
;
5716 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5717 _("dynamic section"));
5721 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5722 might not have the luxury of section headers. Look for the DT_NULL
5723 terminator to determine the number of entries. */
5724 for (ext
= edyn
, dynamic_nent
= 0;
5725 (char *) ext
< (char *) edyn
+ dynamic_size
;
5729 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5733 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5734 if (dynamic_section
== NULL
)
5736 error (_("Out of memory\n"));
5741 for (ext
= edyn
, entry
= dynamic_section
;
5742 entry
< dynamic_section
+ dynamic_nent
;
5745 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5746 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5755 get_64bit_dynamic_section (FILE *file
)
5757 Elf64_External_Dyn
*edyn
, *ext
;
5758 Elf_Internal_Dyn
*entry
;
5760 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5761 _("dynamic section"));
5765 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5766 might not have the luxury of section headers. Look for the DT_NULL
5767 terminator to determine the number of entries. */
5768 for (ext
= edyn
, dynamic_nent
= 0;
5769 (char *) ext
< (char *) edyn
+ dynamic_size
;
5773 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5777 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5778 if (dynamic_section
== NULL
)
5780 error (_("Out of memory\n"));
5785 for (ext
= edyn
, entry
= dynamic_section
;
5786 entry
< dynamic_section
+ dynamic_nent
;
5789 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5790 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5799 print_dynamic_flags (bfd_vma flags
)
5807 flag
= flags
& - flags
;
5817 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5818 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5819 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5820 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5821 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5822 default: fputs ("unknown", stdout
); break;
5828 /* Parse and display the contents of the dynamic section. */
5831 process_dynamic_section (FILE *file
)
5833 Elf_Internal_Dyn
*entry
;
5835 if (dynamic_size
== 0)
5838 printf (_("\nThere is no dynamic section in this file.\n"));
5845 if (! get_32bit_dynamic_section (file
))
5848 else if (! get_64bit_dynamic_section (file
))
5851 /* Find the appropriate symbol table. */
5852 if (dynamic_symbols
== NULL
)
5854 for (entry
= dynamic_section
;
5855 entry
< dynamic_section
+ dynamic_nent
;
5858 Elf_Internal_Shdr section
;
5860 if (entry
->d_tag
!= DT_SYMTAB
)
5863 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5865 /* Since we do not know how big the symbol table is,
5866 we default to reading in the entire file (!) and
5867 processing that. This is overkill, I know, but it
5869 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5871 if (archive_file_offset
!= 0)
5872 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5875 if (fseek (file
, 0, SEEK_END
))
5876 error (_("Unable to seek to end of file!\n"));
5878 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5882 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5884 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5886 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5887 if (num_dynamic_syms
< 1)
5889 error (_("Unable to determine the number of symbols to load\n"));
5893 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5897 /* Similarly find a string table. */
5898 if (dynamic_strings
== NULL
)
5900 for (entry
= dynamic_section
;
5901 entry
< dynamic_section
+ dynamic_nent
;
5904 unsigned long offset
;
5907 if (entry
->d_tag
!= DT_STRTAB
)
5910 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5912 /* Since we do not know how big the string table is,
5913 we default to reading in the entire file (!) and
5914 processing that. This is overkill, I know, but it
5917 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5919 if (archive_file_offset
!= 0)
5920 str_tab_len
= archive_file_size
- offset
;
5923 if (fseek (file
, 0, SEEK_END
))
5924 error (_("Unable to seek to end of file\n"));
5925 str_tab_len
= ftell (file
) - offset
;
5928 if (str_tab_len
< 1)
5931 (_("Unable to determine the length of the dynamic string table\n"));
5935 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5936 _("dynamic string table"));
5937 dynamic_strings_length
= str_tab_len
;
5942 /* And find the syminfo section if available. */
5943 if (dynamic_syminfo
== NULL
)
5945 unsigned long syminsz
= 0;
5947 for (entry
= dynamic_section
;
5948 entry
< dynamic_section
+ dynamic_nent
;
5951 if (entry
->d_tag
== DT_SYMINENT
)
5953 /* Note: these braces are necessary to avoid a syntax
5954 error from the SunOS4 C compiler. */
5955 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5957 else if (entry
->d_tag
== DT_SYMINSZ
)
5958 syminsz
= entry
->d_un
.d_val
;
5959 else if (entry
->d_tag
== DT_SYMINFO
)
5960 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5964 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5966 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5967 Elf_Internal_Syminfo
*syminfo
;
5969 /* There is a syminfo section. Read the data. */
5970 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5971 syminsz
, _("symbol information"));
5975 dynamic_syminfo
= malloc (syminsz
);
5976 if (dynamic_syminfo
== NULL
)
5978 error (_("Out of memory\n"));
5982 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5983 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5984 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5985 ++syminfo
, ++extsym
)
5987 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5988 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5995 if (do_dynamic
&& dynamic_addr
)
5996 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5997 dynamic_addr
, dynamic_nent
);
5999 printf (_(" Tag Type Name/Value\n"));
6001 for (entry
= dynamic_section
;
6002 entry
< dynamic_section
+ dynamic_nent
;
6010 print_vma (entry
->d_tag
, FULL_HEX
);
6011 dtype
= get_dynamic_type (entry
->d_tag
);
6012 printf (" (%s)%*s", dtype
,
6013 ((is_32bit_elf
? 27 : 19)
6014 - (int) strlen (dtype
)),
6018 switch (entry
->d_tag
)
6022 print_dynamic_flags (entry
->d_un
.d_val
);
6032 switch (entry
->d_tag
)
6035 printf (_("Auxiliary library"));
6039 printf (_("Filter library"));
6043 printf (_("Configuration file"));
6047 printf (_("Dependency audit library"));
6051 printf (_("Audit library"));
6055 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6056 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6060 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
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
& DTF_1_PARINIT
)
6079 printf (" PARINIT");
6080 val
^= DTF_1_PARINIT
;
6082 if (val
& DTF_1_CONFEXP
)
6084 printf (" CONFEXP");
6085 val
^= DTF_1_CONFEXP
;
6088 printf (" %lx", val
);
6097 printf (_("Flags:"));
6099 if (entry
->d_un
.d_val
== 0)
6100 printf (_(" None\n"));
6103 unsigned long int val
= entry
->d_un
.d_val
;
6105 if (val
& DF_P1_LAZYLOAD
)
6107 printf (" LAZYLOAD");
6108 val
^= DF_P1_LAZYLOAD
;
6110 if (val
& DF_P1_GROUPPERM
)
6112 printf (" GROUPPERM");
6113 val
^= DF_P1_GROUPPERM
;
6116 printf (" %lx", val
);
6125 printf (_("Flags:"));
6126 if (entry
->d_un
.d_val
== 0)
6127 printf (_(" None\n"));
6130 unsigned long int val
= entry
->d_un
.d_val
;
6137 if (val
& DF_1_GLOBAL
)
6142 if (val
& DF_1_GROUP
)
6147 if (val
& DF_1_NODELETE
)
6149 printf (" NODELETE");
6150 val
^= DF_1_NODELETE
;
6152 if (val
& DF_1_LOADFLTR
)
6154 printf (" LOADFLTR");
6155 val
^= DF_1_LOADFLTR
;
6157 if (val
& DF_1_INITFIRST
)
6159 printf (" INITFIRST");
6160 val
^= DF_1_INITFIRST
;
6162 if (val
& DF_1_NOOPEN
)
6167 if (val
& DF_1_ORIGIN
)
6172 if (val
& DF_1_DIRECT
)
6177 if (val
& DF_1_TRANS
)
6182 if (val
& DF_1_INTERPOSE
)
6184 printf (" INTERPOSE");
6185 val
^= DF_1_INTERPOSE
;
6187 if (val
& DF_1_NODEFLIB
)
6189 printf (" NODEFLIB");
6190 val
^= DF_1_NODEFLIB
;
6192 if (val
& DF_1_NODUMP
)
6197 if (val
& DF_1_CONLFAT
)
6199 printf (" CONLFAT");
6200 val
^= DF_1_CONLFAT
;
6203 printf (" %lx", val
);
6210 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6212 puts (get_dynamic_type (entry
->d_un
.d_val
));
6232 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6238 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6239 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6245 switch (entry
->d_tag
)
6248 printf (_("Shared library: [%s]"), name
);
6250 if (streq (name
, program_interpreter
))
6251 printf (_(" program interpreter"));
6255 printf (_("Library soname: [%s]"), name
);
6259 printf (_("Library rpath: [%s]"), name
);
6263 printf (_("Library runpath: [%s]"), name
);
6267 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6272 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6285 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6289 case DT_INIT_ARRAYSZ
:
6290 case DT_FINI_ARRAYSZ
:
6291 case DT_GNU_CONFLICTSZ
:
6292 case DT_GNU_LIBLISTSZ
:
6295 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6296 printf (" (bytes)\n");
6306 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6319 if (entry
->d_tag
== DT_USED
6320 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6322 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6326 printf (_("Not needed object: [%s]\n"), name
);
6331 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6337 /* The value of this entry is ignored. */
6342 case DT_GNU_PRELINKED
:
6346 time_t time
= entry
->d_un
.d_val
;
6348 tmp
= gmtime (&time
);
6349 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6350 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6351 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6357 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6360 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6366 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6367 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6372 switch (elf_header
.e_machine
)
6375 case EM_MIPS_RS3_LE
:
6376 dynamic_section_mips_val (entry
);
6379 dynamic_section_parisc_val (entry
);
6382 dynamic_section_ia64_val (entry
);
6385 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6397 get_ver_flags (unsigned int flags
)
6399 static char buff
[32];
6406 if (flags
& VER_FLG_BASE
)
6407 strcat (buff
, "BASE ");
6409 if (flags
& VER_FLG_WEAK
)
6411 if (flags
& VER_FLG_BASE
)
6412 strcat (buff
, "| ");
6414 strcat (buff
, "WEAK ");
6417 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6418 strcat (buff
, "| <unknown>");
6423 /* Display the contents of the version sections. */
6425 process_version_sections (FILE *file
)
6427 Elf_Internal_Shdr
*section
;
6434 for (i
= 0, section
= section_headers
;
6435 i
< elf_header
.e_shnum
;
6438 switch (section
->sh_type
)
6440 case SHT_GNU_verdef
:
6442 Elf_External_Verdef
*edefs
;
6449 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6450 SECTION_NAME (section
), section
->sh_info
);
6452 printf (_(" Addr: 0x"));
6453 printf_vma (section
->sh_addr
);
6454 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6455 (unsigned long) section
->sh_offset
, section
->sh_link
,
6456 SECTION_HEADER_INDEX (section
->sh_link
)
6457 < elf_header
.e_shnum
6458 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6461 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6463 _("version definition section"));
6467 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6470 Elf_External_Verdef
*edef
;
6471 Elf_Internal_Verdef ent
;
6472 Elf_External_Verdaux
*eaux
;
6473 Elf_Internal_Verdaux aux
;
6477 vstart
= ((char *) edefs
) + idx
;
6479 edef
= (Elf_External_Verdef
*) vstart
;
6481 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6482 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6483 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6484 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6485 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6486 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6487 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6489 printf (_(" %#06x: Rev: %d Flags: %s"),
6490 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6492 printf (_(" Index: %d Cnt: %d "),
6493 ent
.vd_ndx
, ent
.vd_cnt
);
6495 vstart
+= ent
.vd_aux
;
6497 eaux
= (Elf_External_Verdaux
*) vstart
;
6499 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6500 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6502 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6503 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6505 printf (_("Name index: %ld\n"), aux
.vda_name
);
6507 isum
= idx
+ ent
.vd_aux
;
6509 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6511 isum
+= aux
.vda_next
;
6512 vstart
+= aux
.vda_next
;
6514 eaux
= (Elf_External_Verdaux
*) vstart
;
6516 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6517 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6519 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6520 printf (_(" %#06x: Parent %d: %s\n"),
6521 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6523 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6524 isum
, j
, aux
.vda_name
);
6534 case SHT_GNU_verneed
:
6536 Elf_External_Verneed
*eneed
;
6542 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6543 SECTION_NAME (section
), section
->sh_info
);
6545 printf (_(" Addr: 0x"));
6546 printf_vma (section
->sh_addr
);
6547 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6548 (unsigned long) section
->sh_offset
, section
->sh_link
,
6549 SECTION_HEADER_INDEX (section
->sh_link
)
6550 < elf_header
.e_shnum
6551 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6554 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6556 _("version need section"));
6560 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6562 Elf_External_Verneed
*entry
;
6563 Elf_Internal_Verneed ent
;
6568 vstart
= ((char *) eneed
) + idx
;
6570 entry
= (Elf_External_Verneed
*) vstart
;
6572 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6573 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6574 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6575 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6576 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6578 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6580 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6581 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6583 printf (_(" File: %lx"), ent
.vn_file
);
6585 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6587 vstart
+= ent
.vn_aux
;
6589 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6591 Elf_External_Vernaux
*eaux
;
6592 Elf_Internal_Vernaux aux
;
6594 eaux
= (Elf_External_Vernaux
*) vstart
;
6596 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6597 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6598 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6599 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6600 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6602 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6603 printf (_(" %#06x: Name: %s"),
6604 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6606 printf (_(" %#06x: Name index: %lx"),
6607 isum
, aux
.vna_name
);
6609 printf (_(" Flags: %s Version: %d\n"),
6610 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6612 isum
+= aux
.vna_next
;
6613 vstart
+= aux
.vna_next
;
6623 case SHT_GNU_versym
:
6625 Elf_Internal_Shdr
*link_section
;
6628 unsigned char *edata
;
6629 unsigned short *data
;
6631 Elf_Internal_Sym
*symbols
;
6632 Elf_Internal_Shdr
*string_sec
;
6635 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6638 link_section
= SECTION_HEADER (section
->sh_link
);
6639 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6641 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6642 >= elf_header
.e_shnum
)
6647 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6649 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6651 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6652 string_sec
->sh_size
, _("version string table"));
6656 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6657 SECTION_NAME (section
), total
);
6659 printf (_(" Addr: "));
6660 printf_vma (section
->sh_addr
);
6661 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6662 (unsigned long) section
->sh_offset
, section
->sh_link
,
6663 SECTION_NAME (link_section
));
6665 off
= offset_from_vma (file
,
6666 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6667 total
* sizeof (short));
6668 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6669 _("version symbol data"));
6676 data
= cmalloc (total
, sizeof (short));
6678 for (cnt
= total
; cnt
--;)
6679 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6684 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6687 int check_def
, check_need
;
6690 printf (" %03x:", cnt
);
6692 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6693 switch (data
[cnt
+ j
])
6696 fputs (_(" 0 (*local*) "), stdout
);
6700 fputs (_(" 1 (*global*) "), stdout
);
6704 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6705 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6709 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6710 >= elf_header
.e_shnum
6711 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6714 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6721 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6723 Elf_Internal_Verneed ivn
;
6724 unsigned long offset
;
6726 offset
= offset_from_vma
6727 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6728 sizeof (Elf_External_Verneed
));
6732 Elf_Internal_Vernaux ivna
;
6733 Elf_External_Verneed evn
;
6734 Elf_External_Vernaux evna
;
6735 unsigned long a_off
;
6737 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6740 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6741 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6743 a_off
= offset
+ ivn
.vn_aux
;
6747 get_data (&evna
, file
, a_off
, sizeof (evna
),
6748 1, _("version need aux (2)"));
6750 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6751 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6753 a_off
+= ivna
.vna_next
;
6755 while (ivna
.vna_other
!= data
[cnt
+ j
]
6756 && ivna
.vna_next
!= 0);
6758 if (ivna
.vna_other
== data
[cnt
+ j
])
6760 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6762 name
= strtab
+ ivna
.vna_name
;
6763 nn
+= printf ("(%s%-*s",
6765 12 - (int) strlen (name
),
6771 offset
+= ivn
.vn_next
;
6773 while (ivn
.vn_next
);
6776 if (check_def
&& data
[cnt
+ j
] != 0x8001
6777 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6779 Elf_Internal_Verdef ivd
;
6780 Elf_External_Verdef evd
;
6781 unsigned long offset
;
6783 offset
= offset_from_vma
6784 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6789 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6792 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6793 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6795 offset
+= ivd
.vd_next
;
6797 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6798 && ivd
.vd_next
!= 0);
6800 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6802 Elf_External_Verdaux evda
;
6803 Elf_Internal_Verdaux ivda
;
6805 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6807 get_data (&evda
, file
,
6808 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6810 _("version def aux"));
6812 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6814 name
= strtab
+ ivda
.vda_name
;
6815 nn
+= printf ("(%s%-*s",
6817 12 - (int) strlen (name
),
6823 printf ("%*c", 18 - nn
, ' ');
6841 printf (_("\nNo version information found in this file.\n"));
6847 get_symbol_binding (unsigned int binding
)
6849 static char buff
[32];
6853 case STB_LOCAL
: return "LOCAL";
6854 case STB_GLOBAL
: return "GLOBAL";
6855 case STB_WEAK
: return "WEAK";
6857 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6858 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6860 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6861 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6863 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6869 get_symbol_type (unsigned int type
)
6871 static char buff
[32];
6875 case STT_NOTYPE
: return "NOTYPE";
6876 case STT_OBJECT
: return "OBJECT";
6877 case STT_FUNC
: return "FUNC";
6878 case STT_SECTION
: return "SECTION";
6879 case STT_FILE
: return "FILE";
6880 case STT_COMMON
: return "COMMON";
6881 case STT_TLS
: return "TLS";
6882 case STT_RELC
: return "RELC";
6883 case STT_SRELC
: return "SRELC";
6885 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6887 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6888 return "THUMB_FUNC";
6890 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6893 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6894 return "PARISC_MILLI";
6896 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6898 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6900 if (elf_header
.e_machine
== EM_PARISC
)
6902 if (type
== STT_HP_OPAQUE
)
6904 if (type
== STT_HP_STUB
)
6908 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6911 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6917 get_symbol_visibility (unsigned int visibility
)
6921 case STV_DEFAULT
: return "DEFAULT";
6922 case STV_INTERNAL
: return "INTERNAL";
6923 case STV_HIDDEN
: return "HIDDEN";
6924 case STV_PROTECTED
: return "PROTECTED";
6930 get_mips_symbol_other (unsigned int other
)
6934 case STO_OPTIONAL
: return "OPTIONAL";
6935 case STO_MIPS16
: return "MIPS16";
6936 default: return NULL
;
6941 get_symbol_other (unsigned int other
)
6943 const char * result
= NULL
;
6944 static char buff
[32];
6949 switch (elf_header
.e_machine
)
6952 result
= get_mips_symbol_other (other
);
6960 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
6965 get_symbol_index_type (unsigned int type
)
6967 static char buff
[32];
6971 case SHN_UNDEF
: return "UND";
6972 case SHN_ABS
: return "ABS";
6973 case SHN_COMMON
: return "COM";
6975 if (type
== SHN_IA_64_ANSI_COMMON
6976 && elf_header
.e_machine
== EM_IA_64
6977 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6979 else if (elf_header
.e_machine
== EM_X86_64
6980 && type
== SHN_X86_64_LCOMMON
)
6982 else if (type
== SHN_MIPS_SCOMMON
6983 && elf_header
.e_machine
== EM_MIPS
)
6985 else if (type
== SHN_MIPS_SUNDEFINED
6986 && elf_header
.e_machine
== EM_MIPS
)
6988 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6989 sprintf (buff
, "PRC[0x%04x]", type
);
6990 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6991 sprintf (buff
, "OS [0x%04x]", type
);
6992 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6993 sprintf (buff
, "RSV[0x%04x]", type
);
6995 sprintf (buff
, "%3d", type
);
7003 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
7005 unsigned char *e_data
;
7008 e_data
= cmalloc (number
, ent_size
);
7012 error (_("Out of memory\n"));
7016 if (fread (e_data
, ent_size
, number
, file
) != number
)
7018 error (_("Unable to read in dynamic data\n"));
7022 i_data
= cmalloc (number
, sizeof (*i_data
));
7026 error (_("Out of memory\n"));
7032 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7039 /* Dump the symbol table. */
7041 process_symbol_table (FILE *file
)
7043 Elf_Internal_Shdr
*section
;
7044 bfd_vma nbuckets
= 0;
7045 bfd_vma nchains
= 0;
7046 bfd_vma
*buckets
= NULL
;
7047 bfd_vma
*chains
= NULL
;
7048 bfd_vma ngnubuckets
= 0;
7049 bfd_vma
*gnubuckets
= NULL
;
7050 bfd_vma
*gnuchains
= NULL
;
7052 if (! do_syms
&& !do_histogram
)
7055 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
7058 unsigned char nb
[8];
7059 unsigned char nc
[8];
7060 int hash_ent_size
= 4;
7062 if ((elf_header
.e_machine
== EM_ALPHA
7063 || elf_header
.e_machine
== EM_S390
7064 || elf_header
.e_machine
== EM_S390_OLD
)
7065 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7069 (archive_file_offset
7070 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7071 sizeof nb
+ sizeof nc
)),
7074 error (_("Unable to seek to start of dynamic information\n"));
7078 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7080 error (_("Failed to read in number of buckets\n"));
7084 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7086 error (_("Failed to read in number of chains\n"));
7090 nbuckets
= byte_get (nb
, hash_ent_size
);
7091 nchains
= byte_get (nc
, hash_ent_size
);
7093 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7094 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7096 if (buckets
== NULL
|| chains
== NULL
)
7101 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
7106 printf (_("\nSymbol table for image:\n"));
7108 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7110 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7112 for (hn
= 0; hn
< nbuckets
; hn
++)
7117 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7119 Elf_Internal_Sym
*psym
;
7122 psym
= dynamic_symbols
+ si
;
7124 n
= print_vma (si
, DEC_5
);
7126 fputs (" " + n
, stdout
);
7127 printf (" %3lu: ", hn
);
7128 print_vma (psym
->st_value
, LONG_HEX
);
7130 print_vma (psym
->st_size
, DEC_5
);
7132 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7133 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7134 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7135 /* Check to see if any other bits in the st_other field are set.
7136 Note - displaying this information disrupts the layout of the
7137 table being generated, but for the moment this case is very rare. */
7138 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7139 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7140 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7141 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7142 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7144 printf (" <corrupt: %14ld>", psym
->st_name
);
7149 else if (do_syms
&& !do_using_dynamic
)
7153 for (i
= 0, section
= section_headers
;
7154 i
< elf_header
.e_shnum
;
7158 char *strtab
= NULL
;
7159 unsigned long int strtab_size
= 0;
7160 Elf_Internal_Sym
*symtab
;
7161 Elf_Internal_Sym
*psym
;
7164 if ( section
->sh_type
!= SHT_SYMTAB
7165 && section
->sh_type
!= SHT_DYNSYM
)
7168 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7169 SECTION_NAME (section
),
7170 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7172 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7174 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7176 symtab
= GET_ELF_SYMBOLS (file
, section
);
7180 if (section
->sh_link
== elf_header
.e_shstrndx
)
7182 strtab
= string_table
;
7183 strtab_size
= string_table_length
;
7185 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
7187 Elf_Internal_Shdr
*string_sec
;
7189 string_sec
= SECTION_HEADER (section
->sh_link
);
7191 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
7192 1, string_sec
->sh_size
, _("string table"));
7193 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7196 for (si
= 0, psym
= symtab
;
7197 si
< section
->sh_size
/ section
->sh_entsize
;
7200 printf ("%6d: ", si
);
7201 print_vma (psym
->st_value
, LONG_HEX
);
7203 print_vma (psym
->st_size
, DEC_5
);
7204 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7205 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7206 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7207 /* Check to see if any other bits in the st_other field are set.
7208 Note - displaying this information disrupts the layout of the
7209 table being generated, but for the moment this case is very rare. */
7210 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7211 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7212 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7213 print_symbol (25, psym
->st_name
< strtab_size
7214 ? strtab
+ psym
->st_name
: "<corrupt>");
7216 if (section
->sh_type
== SHT_DYNSYM
&&
7217 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7219 unsigned char data
[2];
7220 unsigned short vers_data
;
7221 unsigned long offset
;
7225 offset
= offset_from_vma
7226 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7227 sizeof data
+ si
* sizeof (vers_data
));
7229 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7230 sizeof (data
), 1, _("version data"));
7232 vers_data
= byte_get (data
, 2);
7234 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7235 < elf_header
.e_shnum
7236 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7239 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7241 if ((vers_data
& 0x8000) || vers_data
> 1)
7243 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7244 && (is_nobits
|| ! check_def
))
7246 Elf_External_Verneed evn
;
7247 Elf_Internal_Verneed ivn
;
7248 Elf_Internal_Vernaux ivna
;
7250 /* We must test both. */
7251 offset
= offset_from_vma
7252 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7257 unsigned long vna_off
;
7259 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7262 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7263 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7265 vna_off
= offset
+ ivn
.vn_aux
;
7269 Elf_External_Vernaux evna
;
7271 get_data (&evna
, file
, vna_off
,
7273 _("version need aux (3)"));
7275 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7276 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7277 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7279 vna_off
+= ivna
.vna_next
;
7281 while (ivna
.vna_other
!= vers_data
7282 && ivna
.vna_next
!= 0);
7284 if (ivna
.vna_other
== vers_data
)
7287 offset
+= ivn
.vn_next
;
7289 while (ivn
.vn_next
!= 0);
7291 if (ivna
.vna_other
== vers_data
)
7294 ivna
.vna_name
< strtab_size
7295 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7299 else if (! is_nobits
)
7300 error (_("bad dynamic symbol\n"));
7307 if (vers_data
!= 0x8001
7308 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7310 Elf_Internal_Verdef ivd
;
7311 Elf_Internal_Verdaux ivda
;
7312 Elf_External_Verdaux evda
;
7313 unsigned long offset
;
7315 offset
= offset_from_vma
7317 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7318 sizeof (Elf_External_Verdef
));
7322 Elf_External_Verdef evd
;
7324 get_data (&evd
, file
, offset
, sizeof (evd
),
7325 1, _("version def"));
7327 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7328 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7329 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7331 offset
+= ivd
.vd_next
;
7333 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7334 && ivd
.vd_next
!= 0);
7336 offset
-= ivd
.vd_next
;
7337 offset
+= ivd
.vd_aux
;
7339 get_data (&evda
, file
, offset
, sizeof (evda
),
7340 1, _("version def aux"));
7342 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7344 if (psym
->st_name
!= ivda
.vda_name
)
7345 printf ((vers_data
& 0x8000)
7347 ivda
.vda_name
< strtab_size
7348 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7358 if (strtab
!= string_table
)
7364 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7366 if (do_histogram
&& buckets
!= NULL
)
7368 unsigned long *lengths
;
7369 unsigned long *counts
;
7372 unsigned long maxlength
= 0;
7373 unsigned long nzero_counts
= 0;
7374 unsigned long nsyms
= 0;
7376 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7377 (unsigned long) nbuckets
);
7378 printf (_(" Length Number %% of total Coverage\n"));
7380 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7381 if (lengths
== NULL
)
7383 error (_("Out of memory\n"));
7386 for (hn
= 0; hn
< nbuckets
; ++hn
)
7388 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7391 if (maxlength
< ++lengths
[hn
])
7396 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7399 error (_("Out of memory\n"));
7403 for (hn
= 0; hn
< nbuckets
; ++hn
)
7404 ++counts
[lengths
[hn
]];
7409 printf (" 0 %-10lu (%5.1f%%)\n",
7410 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7411 for (i
= 1; i
<= maxlength
; ++i
)
7413 nzero_counts
+= counts
[i
] * i
;
7414 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7415 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7416 (nzero_counts
* 100.0) / nsyms
);
7424 if (buckets
!= NULL
)
7430 if (do_histogram
&& dynamic_info_DT_GNU_HASH
)
7432 unsigned char nb
[16];
7433 bfd_vma i
, maxchain
= 0xffffffff, symidx
, bitmaskwords
;
7434 unsigned long *lengths
;
7435 unsigned long *counts
;
7437 unsigned long maxlength
= 0;
7438 unsigned long nzero_counts
= 0;
7439 unsigned long nsyms
= 0;
7440 bfd_vma buckets_vma
;
7443 (archive_file_offset
7444 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7448 error (_("Unable to seek to start of dynamic information\n"));
7452 if (fread (nb
, 16, 1, file
) != 1)
7454 error (_("Failed to read in number of buckets\n"));
7458 ngnubuckets
= byte_get (nb
, 4);
7459 symidx
= byte_get (nb
+ 4, 4);
7460 bitmaskwords
= byte_get (nb
+ 8, 4);
7461 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7463 buckets_vma
+= bitmaskwords
* 4;
7465 buckets_vma
+= bitmaskwords
* 8;
7468 (archive_file_offset
7469 + offset_from_vma (file
, buckets_vma
, 4)),
7472 error (_("Unable to seek to start of dynamic information\n"));
7476 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7478 if (gnubuckets
== NULL
)
7481 for (i
= 0; i
< ngnubuckets
; i
++)
7482 if (gnubuckets
[i
] != 0)
7484 if (gnubuckets
[i
] < symidx
)
7487 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7488 maxchain
= gnubuckets
[i
];
7491 if (maxchain
== 0xffffffff)
7497 (archive_file_offset
7498 + offset_from_vma (file
, buckets_vma
7499 + 4 * (ngnubuckets
+ maxchain
), 4)),
7502 error (_("Unable to seek to start of dynamic information\n"));
7508 if (fread (nb
, 4, 1, file
) != 1)
7510 error (_("Failed to determine last chain length\n"));
7514 if (maxchain
+ 1 == 0)
7519 while ((byte_get (nb
, 4) & 1) == 0);
7522 (archive_file_offset
7523 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7526 error (_("Unable to seek to start of dynamic information\n"));
7530 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7532 if (gnuchains
== NULL
)
7535 lengths
= calloc (ngnubuckets
, sizeof (*lengths
));
7536 if (lengths
== NULL
)
7538 error (_("Out of memory\n"));
7542 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7543 (unsigned long) ngnubuckets
);
7544 printf (_(" Length Number %% of total Coverage\n"));
7546 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7547 if (gnubuckets
[hn
] != 0)
7549 bfd_vma off
, length
= 1;
7551 for (off
= gnubuckets
[hn
] - symidx
;
7552 (gnuchains
[off
] & 1) == 0; ++off
)
7554 lengths
[hn
] = length
;
7555 if (length
> maxlength
)
7560 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7563 error (_("Out of memory\n"));
7567 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7568 ++counts
[lengths
[hn
]];
7570 if (ngnubuckets
> 0)
7573 printf (" 0 %-10lu (%5.1f%%)\n",
7574 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7575 for (j
= 1; j
<= maxlength
; ++j
)
7577 nzero_counts
+= counts
[j
] * j
;
7578 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7579 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7580 (nzero_counts
* 100.0) / nsyms
);
7594 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7598 if (dynamic_syminfo
== NULL
7600 /* No syminfo, this is ok. */
7603 /* There better should be a dynamic symbol section. */
7604 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7608 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7609 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7611 printf (_(" Num: Name BoundTo Flags\n"));
7612 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7614 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7616 printf ("%4d: ", i
);
7617 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7618 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7620 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7623 switch (dynamic_syminfo
[i
].si_boundto
)
7625 case SYMINFO_BT_SELF
:
7626 fputs ("SELF ", stdout
);
7628 case SYMINFO_BT_PARENT
:
7629 fputs ("PARENT ", stdout
);
7632 if (dynamic_syminfo
[i
].si_boundto
> 0
7633 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7634 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7636 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7640 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7644 if (flags
& SYMINFO_FLG_DIRECT
)
7646 if (flags
& SYMINFO_FLG_PASSTHRU
)
7647 printf (" PASSTHRU");
7648 if (flags
& SYMINFO_FLG_COPY
)
7650 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7651 printf (" LAZYLOAD");
7659 #ifdef SUPPORT_DISASSEMBLY
7661 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7663 printf (_("\nAssembly dump of section %s\n"),
7664 SECTION_NAME (section
));
7666 /* XXX -- to be done --- XXX */
7673 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
7675 Elf_Internal_Shdr
*relsec
;
7676 bfd_size_type bytes
;
7678 unsigned char *data
;
7679 unsigned char *start
;
7681 bytes
= section
->sh_size
;
7683 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7685 printf (_("\nSection '%s' has no data to dump.\n"),
7686 SECTION_NAME (section
));
7690 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7692 addr
= section
->sh_addr
;
7694 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7699 /* If the section being dumped has relocations against it the user might
7700 be expecting these relocations to have been applied. Check for this
7701 case and issue a warning message in order to avoid confusion.
7702 FIXME: Maybe we ought to have an option that dumps a section with
7704 for (relsec
= section_headers
;
7705 relsec
< section_headers
+ elf_header
.e_shnum
;
7708 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
7709 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7710 || SECTION_HEADER (relsec
->sh_info
) != section
7711 || relsec
->sh_size
== 0
7712 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7715 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
7727 lbytes
= (bytes
> 16 ? 16 : bytes
);
7729 printf (" 0x%8.8lx ", (unsigned long) addr
);
7731 for (j
= 0; j
< 16; j
++)
7734 printf ("%2.2x", data
[j
]);
7742 for (j
= 0; j
< lbytes
; j
++)
7745 if (k
>= ' ' && k
< 0x7f)
7764 /* Return the number of bytes affected by a given reloc.
7765 This information is architecture and reloc dependent.
7766 Returns 4 by default, although this is not always correct.
7767 It should return 0 if a decision cannot be made.
7768 FIXME: This is not the correct way to solve this problem.
7769 The proper way is to have target specific reloc sizing functions
7770 created by the reloc-macros.h header, in the same way that it
7771 already creates the reloc naming functions. */
7774 get_reloc_size (Elf_Internal_Rela
* reloc
)
7776 switch (elf_header
.e_machine
)
7782 switch (ELF32_R_TYPE (reloc
->r_info
))
7784 /* PR gas/3800 - without this information we do not correctly
7785 decode the debug information generated by the h8300 assembler. */
7792 /* FIXME: We need to extend this switch statement to cope with other
7793 architecture's relocs. (When those relocs are used against debug
7794 sections, and when their size is not 4). But see the multiple
7795 inclusions of <elf/h8.h> for an example of the hoops that we need
7796 to jump through in order to obtain the reloc numbers. */
7801 /* Apply addends of RELA relocations. */
7804 debug_apply_rela_addends (void *file
,
7805 Elf_Internal_Shdr
*section
,
7806 unsigned char *start
)
7808 Elf_Internal_Shdr
*relsec
;
7809 unsigned char *end
= start
+ section
->sh_size
;
7811 if (!is_relocatable
)
7814 /* SH uses RELA but uses in place value instead of the addend field. */
7815 if (elf_header
.e_machine
== EM_SH
)
7818 for (relsec
= section_headers
;
7819 relsec
< section_headers
+ elf_header
.e_shnum
;
7822 unsigned long nrelas
;
7823 Elf_Internal_Rela
*rela
, *rp
;
7824 Elf_Internal_Shdr
*symsec
;
7825 Elf_Internal_Sym
*symtab
;
7826 Elf_Internal_Sym
*sym
;
7828 if (relsec
->sh_type
!= SHT_RELA
7829 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7830 || SECTION_HEADER (relsec
->sh_info
) != section
7831 || relsec
->sh_size
== 0
7832 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7835 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7839 symsec
= SECTION_HEADER (relsec
->sh_link
);
7840 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7842 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7845 unsigned int reloc_size
;
7847 reloc_size
= get_reloc_size (rp
);
7848 if (reloc_size
== 0)
7850 warn (_("skipping relocation of unknown size against offset 0x%lx in section %s\n"),
7851 (unsigned long) rp
->r_offset
,
7852 SECTION_NAME (section
));
7856 loc
= start
+ rp
->r_offset
;
7857 if ((loc
+ reloc_size
) > end
)
7859 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7860 (unsigned long) rp
->r_offset
,
7861 SECTION_NAME (section
));
7867 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7869 if (ELF32_R_SYM (rp
->r_info
) != 0
7870 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7871 /* Relocations against symbols without type can happen.
7872 Gcc -feliminate-dwarf2-dups may generate symbols
7873 without type for debug info. */
7874 && ELF32_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7875 /* Relocations against object symbols can happen,
7876 eg when referencing a global array. For an
7877 example of this see the _clz.o binary in libgcc.a. */
7878 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7880 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7881 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7882 SECTION_NAME (section
));
7888 /* In MIPS little-endian objects, r_info isn't really a
7889 64-bit little-endian value: it has a 32-bit little-endian
7890 symbol index followed by four individual byte fields.
7891 Reorder INFO accordingly. */
7892 if (elf_header
.e_machine
== EM_MIPS
7893 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7894 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7895 | ((rp
->r_info
>> 56) & 0xff)
7896 | ((rp
->r_info
>> 40) & 0xff00)
7897 | ((rp
->r_info
>> 24) & 0xff0000)
7898 | ((rp
->r_info
>> 8) & 0xff000000));
7900 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7902 if (ELF64_R_SYM (rp
->r_info
) != 0
7903 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7904 && ELF64_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7905 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7907 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7908 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7909 SECTION_NAME (section
));
7914 byte_put (loc
, rp
->r_addend
, reloc_size
);
7925 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
7927 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7928 Elf_Internal_Shdr
*sec
;
7931 /* If it is already loaded, do nothing. */
7932 if (section
->start
!= NULL
)
7935 /* Locate the debug section. */
7936 sec
= find_section (section
->name
);
7940 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
7941 section
->address
= sec
->sh_addr
;
7942 section
->size
= sec
->sh_size
;
7943 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
7946 if (debug_displays
[debug
].relocate
)
7947 debug_apply_rela_addends (file
, sec
, section
->start
);
7949 return section
->start
!= NULL
;
7953 free_debug_section (enum dwarf_section_display_enum debug
)
7955 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7957 if (section
->start
== NULL
)
7960 free ((char *) section
->start
);
7961 section
->start
= NULL
;
7962 section
->address
= 0;
7967 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
7969 char *name
= SECTION_NAME (section
);
7970 bfd_size_type length
;
7972 enum dwarf_section_display_enum i
;
7974 length
= section
->sh_size
;
7977 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7981 if (const_strneq (name
, ".gnu.linkonce.wi."))
7982 name
= ".debug_info";
7984 /* See if we know how to display the contents of this section. */
7985 for (i
= 0; i
< max
; i
++)
7986 if (streq (debug_displays
[i
].section
.name
, name
))
7988 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
7990 if (load_debug_section (i
, file
))
7992 result
&= debug_displays
[i
].display (sec
, file
);
7994 if (i
!= info
&& i
!= abbrev
)
7995 free_debug_section (i
);
8003 printf (_("Unrecognized debug section: %s\n"), name
);
8010 /* Set DUMP_SECTS for all sections where dumps were requested
8011 based on section name. */
8014 initialise_dumps_byname (void)
8016 struct dump_list_entry
*cur
;
8018 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
8023 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
8024 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
8026 request_dump (i
, cur
->type
);
8031 warn (_("Section '%s' was not dumped because it does not exist!\n"),
8037 process_section_contents (FILE *file
)
8039 Elf_Internal_Shdr
*section
;
8045 initialise_dumps_byname ();
8047 for (i
= 0, section
= section_headers
;
8048 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8051 #ifdef SUPPORT_DISASSEMBLY
8052 if (dump_sects
[i
] & DISASS_DUMP
)
8053 disassemble_section (section
, file
);
8055 if (dump_sects
[i
] & HEX_DUMP
)
8056 dump_section (section
, file
);
8058 if (dump_sects
[i
] & DEBUG_DUMP
)
8059 display_debug_section (section
, file
);
8062 /* Check to see if the user requested a
8063 dump of a section that does not exist. */
8064 while (i
++ < num_dump_sects
)
8066 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
8070 process_mips_fpe_exception (int mask
)
8075 if (mask
& OEX_FPU_INEX
)
8076 fputs ("INEX", stdout
), first
= 0;
8077 if (mask
& OEX_FPU_UFLO
)
8078 printf ("%sUFLO", first
? "" : "|"), first
= 0;
8079 if (mask
& OEX_FPU_OFLO
)
8080 printf ("%sOFLO", first
? "" : "|"), first
= 0;
8081 if (mask
& OEX_FPU_DIV0
)
8082 printf ("%sDIV0", first
? "" : "|"), first
= 0;
8083 if (mask
& OEX_FPU_INVAL
)
8084 printf ("%sINVAL", first
? "" : "|");
8087 fputs ("0", stdout
);
8090 /* ARM EABI attributes section. */
8095 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8098 } arm_attr_public_tag
;
8100 static const char *arm_attr_tag_CPU_arch
[] =
8101 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8103 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8104 static const char *arm_attr_tag_THUMB_ISA_use
[] =
8105 {"No", "Thumb-1", "Thumb-2"};
8106 /* FIXME: VFPv3 encoding was extrapolated! */
8107 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
8108 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
8109 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
8110 static const char *arm_attr_tag_ABI_PCS_config
[] =
8111 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8112 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8113 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
8114 {"V6", "SB", "TLS", "Unused"};
8115 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
8116 {"Absolute", "PC-relative", "SB-relative", "None"};
8117 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
8118 {"Absolute", "PC-relative", "None"};
8119 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
8120 {"None", "direct", "GOT-indirect"};
8121 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
8122 {"None", "??? 1", "2", "??? 3", "4"};
8123 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8124 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
8125 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8126 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8127 static const char *arm_attr_tag_ABI_FP_number_model
[] =
8128 {"Unused", "Finite", "RTABI", "IEEE 754"};
8129 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8130 static const char *arm_attr_tag_ABI_align8_preserved
[] =
8131 {"No", "Yes, except leaf SP", "Yes"};
8132 static const char *arm_attr_tag_ABI_enum_size
[] =
8133 {"Unused", "small", "int", "forced to int"};
8134 static const char *arm_attr_tag_ABI_HardFP_use
[] =
8135 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8136 static const char *arm_attr_tag_ABI_VFP_args
[] =
8137 {"AAPCS", "VFP registers", "custom"};
8138 static const char *arm_attr_tag_ABI_WMMX_args
[] =
8139 {"AAPCS", "WMMX registers", "custom"};
8140 static const char *arm_attr_tag_ABI_optimization_goals
[] =
8141 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8142 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8143 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
8144 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8145 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8147 #define LOOKUP(id, name) \
8148 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8149 static arm_attr_public_tag arm_attr_public_tags
[] =
8151 {4, "CPU_raw_name", 1, NULL
},
8152 {5, "CPU_name", 1, NULL
},
8153 LOOKUP(6, CPU_arch
),
8154 {7, "CPU_arch_profile", 0, NULL
},
8155 LOOKUP(8, ARM_ISA_use
),
8156 LOOKUP(9, THUMB_ISA_use
),
8157 LOOKUP(10, VFP_arch
),
8158 LOOKUP(11, WMMX_arch
),
8159 LOOKUP(12, NEON_arch
),
8160 LOOKUP(13, ABI_PCS_config
),
8161 LOOKUP(14, ABI_PCS_R9_use
),
8162 LOOKUP(15, ABI_PCS_RW_data
),
8163 LOOKUP(16, ABI_PCS_RO_DATA
),
8164 LOOKUP(17, ABI_PCS_GOT_use
),
8165 LOOKUP(18, ABI_PCS_wchar_t
),
8166 LOOKUP(19, ABI_FP_rounding
),
8167 LOOKUP(20, ABI_FP_denormal
),
8168 LOOKUP(21, ABI_FP_exceptions
),
8169 LOOKUP(22, ABI_FP_user_exceptions
),
8170 LOOKUP(23, ABI_FP_number_model
),
8171 LOOKUP(24, ABI_align8_needed
),
8172 LOOKUP(25, ABI_align8_preserved
),
8173 LOOKUP(26, ABI_enum_size
),
8174 LOOKUP(27, ABI_HardFP_use
),
8175 LOOKUP(28, ABI_VFP_args
),
8176 LOOKUP(29, ABI_WMMX_args
),
8177 LOOKUP(30, ABI_optimization_goals
),
8178 LOOKUP(31, ABI_FP_optimization_goals
),
8179 {32, "compatibility", 0, NULL
}
8183 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8186 read_uleb128 (unsigned char *p
, unsigned int *plen
)
8200 val
|= ((unsigned int)c
& 0x7f) << shift
;
8209 static unsigned char *
8210 display_arm_attribute (unsigned char *p
)
8215 arm_attr_public_tag
*attr
;
8219 tag
= read_uleb128 (p
, &len
);
8222 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
8224 if (arm_attr_public_tags
[i
].tag
== tag
)
8226 attr
= &arm_attr_public_tags
[i
];
8233 printf (" Tag_%s: ", attr
->name
);
8239 case 7: /* Tag_CPU_arch_profile. */
8240 val
= read_uleb128 (p
, &len
);
8244 case 0: printf ("None\n"); break;
8245 case 'A': printf ("Application\n"); break;
8246 case 'R': printf ("Realtime\n"); break;
8247 case 'M': printf ("Microcontroller\n"); break;
8248 default: printf ("??? (%d)\n", val
); break;
8252 case 32: /* Tag_compatibility. */
8253 val
= read_uleb128 (p
, &len
);
8255 printf ("flag = %d, vendor = %s\n", val
, p
);
8256 p
+= strlen((char *)p
) + 1;
8270 assert (attr
->type
& 0x80);
8271 val
= read_uleb128 (p
, &len
);
8273 type
= attr
->type
& 0x7f;
8275 printf ("??? (%d)\n", val
);
8277 printf ("%s\n", attr
->table
[val
]);
8284 type
= 1; /* String. */
8286 type
= 2; /* uleb128. */
8287 printf (" Tag_unknown_%d: ", tag
);
8292 printf ("\"%s\"\n", p
);
8293 p
+= strlen((char *)p
) + 1;
8297 val
= read_uleb128 (p
, &len
);
8299 printf ("%d (0x%x)\n", val
, val
);
8305 static unsigned char *
8306 display_gnu_attribute (unsigned char * p
,
8307 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8314 tag
= read_uleb128 (p
, &len
);
8317 /* Tag_compatibility is the only generic GNU attribute defined at
8321 val
= read_uleb128 (p
, &len
);
8323 printf ("flag = %d, vendor = %s\n", val
, p
);
8324 p
+= strlen ((char *) p
) + 1;
8328 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
8329 return display_proc_gnu_attribute (p
, tag
);
8332 type
= 1; /* String. */
8334 type
= 2; /* uleb128. */
8335 printf (" Tag_unknown_%d: ", tag
);
8339 printf ("\"%s\"\n", p
);
8340 p
+= strlen ((char *) p
) + 1;
8344 val
= read_uleb128 (p
, &len
);
8346 printf ("%d (0x%x)\n", val
, val
);
8352 static unsigned char *
8353 display_power_gnu_attribute (unsigned char *p
, int tag
)
8359 if (tag
== Tag_GNU_Power_ABI_FP
)
8361 val
= read_uleb128 (p
, &len
);
8363 printf (" Tag_GNU_Power_ABI_FP: ");
8368 printf ("Hard or soft float\n");
8371 printf ("Hard float\n");
8374 printf ("Soft float\n");
8377 printf ("??? (%d)\n", val
);
8384 type
= 1; /* String. */
8386 type
= 2; /* uleb128. */
8387 printf (" Tag_unknown_%d: ", tag
);
8391 printf ("\"%s\"\n", p
);
8392 p
+= strlen ((char *) p
) + 1;
8396 val
= read_uleb128 (p
, &len
);
8398 printf ("%d (0x%x)\n", val
, val
);
8404 static unsigned char *
8405 display_mips_gnu_attribute (unsigned char *p
, int tag
)
8411 if (tag
== Tag_GNU_MIPS_ABI_FP
)
8413 val
= read_uleb128 (p
, &len
);
8415 printf (" Tag_GNU_MIPS_ABI_FP: ");
8420 printf ("Hard or soft float\n");
8423 printf ("Hard float (-mdouble-float)\n");
8426 printf ("Hard float (-msingle-float)\n");
8429 printf ("Soft float\n");
8432 printf ("??? (%d)\n", val
);
8439 type
= 1; /* String. */
8441 type
= 2; /* uleb128. */
8442 printf (" Tag_unknown_%d: ", tag
);
8446 printf ("\"%s\"\n", p
);
8447 p
+= strlen ((char *) p
) + 1;
8451 val
= read_uleb128 (p
, &len
);
8453 printf ("%d (0x%x)\n", val
, val
);
8460 process_attributes (FILE * file
,
8461 const char * public_name
,
8462 unsigned int proc_type
,
8463 unsigned char * (* display_pub_attribute
) (unsigned char *),
8464 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8466 Elf_Internal_Shdr
*sect
;
8467 unsigned char *contents
;
8470 bfd_vma section_len
;
8474 /* Find the section header so that we get the size. */
8475 for (i
= 0, sect
= section_headers
;
8476 i
< elf_header
.e_shnum
;
8479 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
8482 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
8484 if (contents
== NULL
)
8490 len
= sect
->sh_size
- 1;
8496 bfd_boolean public_section
;
8497 bfd_boolean gnu_section
;
8499 section_len
= byte_get (p
, 4);
8502 if (section_len
> len
)
8504 printf (_("ERROR: Bad section length (%d > %d)\n"),
8505 (int) section_len
, (int) len
);
8510 printf ("Attribute Section: %s\n", p
);
8512 if (public_name
&& streq ((char *) p
, public_name
))
8513 public_section
= TRUE
;
8515 public_section
= FALSE
;
8517 if (streq ((char *) p
, "gnu"))
8520 gnu_section
= FALSE
;
8522 namelen
= strlen ((char *) p
) + 1;
8524 section_len
-= namelen
+ 4;
8526 while (section_len
> 0)
8532 size
= byte_get (p
, 4);
8533 if (size
> section_len
)
8535 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
8536 (int) size
, (int) section_len
);
8540 section_len
-= size
;
8547 printf ("File Attributes\n");
8550 printf ("Section Attributes:");
8553 printf ("Symbol Attributes:");
8559 val
= read_uleb128 (p
, &i
);
8563 printf (" %d", val
);
8568 printf ("Unknown tag: %d\n", tag
);
8569 public_section
= FALSE
;
8576 p
= display_pub_attribute (p
);
8578 else if (gnu_section
)
8581 p
= display_gnu_attribute (p
,
8582 display_proc_gnu_attribute
);
8586 /* ??? Do something sensible, like dump hex. */
8587 printf (" Unknown section contexts\n");
8594 printf (_("Unknown format '%c'\n"), *p
);
8602 process_arm_specific (FILE *file
)
8604 return process_attributes (file
, "aeabi", SHT_ARM_ATTRIBUTES
,
8605 display_arm_attribute
, NULL
);
8609 process_power_specific (FILE *file
)
8611 return process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
8612 display_power_gnu_attribute
);
8616 process_mips_specific (FILE *file
)
8618 Elf_Internal_Dyn
*entry
;
8619 size_t liblist_offset
= 0;
8620 size_t liblistno
= 0;
8621 size_t conflictsno
= 0;
8622 size_t options_offset
= 0;
8623 size_t conflicts_offset
= 0;
8625 process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
8626 display_mips_gnu_attribute
);
8628 /* We have a lot of special sections. Thanks SGI! */
8629 if (dynamic_section
== NULL
)
8630 /* No information available. */
8633 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
8634 switch (entry
->d_tag
)
8636 case DT_MIPS_LIBLIST
:
8638 = offset_from_vma (file
, entry
->d_un
.d_val
,
8639 liblistno
* sizeof (Elf32_External_Lib
));
8641 case DT_MIPS_LIBLISTNO
:
8642 liblistno
= entry
->d_un
.d_val
;
8644 case DT_MIPS_OPTIONS
:
8645 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
8647 case DT_MIPS_CONFLICT
:
8649 = offset_from_vma (file
, entry
->d_un
.d_val
,
8650 conflictsno
* sizeof (Elf32_External_Conflict
));
8652 case DT_MIPS_CONFLICTNO
:
8653 conflictsno
= entry
->d_un
.d_val
;
8659 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
8661 Elf32_External_Lib
*elib
;
8664 elib
= get_data (NULL
, file
, liblist_offset
,
8665 liblistno
, sizeof (Elf32_External_Lib
),
8669 printf ("\nSection '.liblist' contains %lu entries:\n",
8670 (unsigned long) liblistno
);
8671 fputs (" Library Time Stamp Checksum Version Flags\n",
8674 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
8681 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8682 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8683 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8684 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8685 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8687 tmp
= gmtime (&time
);
8688 snprintf (timebuf
, sizeof (timebuf
),
8689 "%04u-%02u-%02uT%02u:%02u:%02u",
8690 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8691 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8693 printf ("%3lu: ", (unsigned long) cnt
);
8694 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
8695 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
8697 printf ("<corrupt: %9ld>", liblist
.l_name
);
8698 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
8701 if (liblist
.l_flags
== 0)
8712 { " EXACT_MATCH", LL_EXACT_MATCH
},
8713 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
8714 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
8715 { " EXPORTS", LL_EXPORTS
},
8716 { " DELAY_LOAD", LL_DELAY_LOAD
},
8717 { " DELTA", LL_DELTA
}
8719 int flags
= liblist
.l_flags
;
8722 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
8723 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
8725 fputs (l_flags_vals
[fcnt
].name
, stdout
);
8726 flags
^= l_flags_vals
[fcnt
].bit
;
8729 printf (" %#x", (unsigned int) flags
);
8739 if (options_offset
!= 0)
8741 Elf_External_Options
*eopt
;
8742 Elf_Internal_Shdr
*sect
= section_headers
;
8743 Elf_Internal_Options
*iopt
;
8744 Elf_Internal_Options
*option
;
8748 /* Find the section header so that we get the size. */
8749 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
8752 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
8756 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
8759 error (_("Out of memory\n"));
8766 while (offset
< sect
->sh_size
)
8768 Elf_External_Options
*eoption
;
8770 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
8772 option
->kind
= BYTE_GET (eoption
->kind
);
8773 option
->size
= BYTE_GET (eoption
->size
);
8774 option
->section
= BYTE_GET (eoption
->section
);
8775 option
->info
= BYTE_GET (eoption
->info
);
8777 offset
+= option
->size
;
8783 printf (_("\nSection '%s' contains %d entries:\n"),
8784 SECTION_NAME (sect
), cnt
);
8792 switch (option
->kind
)
8795 /* This shouldn't happen. */
8796 printf (" NULL %d %lx", option
->section
, option
->info
);
8799 printf (" REGINFO ");
8800 if (elf_header
.e_machine
== EM_MIPS
)
8803 Elf32_External_RegInfo
*ereg
;
8804 Elf32_RegInfo reginfo
;
8806 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
8807 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8808 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8809 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8810 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8811 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8812 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8814 printf ("GPR %08lx GP 0x%lx\n",
8816 (unsigned long) reginfo
.ri_gp_value
);
8817 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8818 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8819 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8824 Elf64_External_RegInfo
*ereg
;
8825 Elf64_Internal_RegInfo reginfo
;
8827 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
8828 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8829 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8830 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8831 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8832 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8833 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8835 printf ("GPR %08lx GP 0x",
8836 reginfo
.ri_gprmask
);
8837 printf_vma (reginfo
.ri_gp_value
);
8840 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8841 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8842 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8846 case ODK_EXCEPTIONS
:
8847 fputs (" EXCEPTIONS fpe_min(", stdout
);
8848 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
8849 fputs (") fpe_max(", stdout
);
8850 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
8851 fputs (")", stdout
);
8853 if (option
->info
& OEX_PAGE0
)
8854 fputs (" PAGE0", stdout
);
8855 if (option
->info
& OEX_SMM
)
8856 fputs (" SMM", stdout
);
8857 if (option
->info
& OEX_FPDBUG
)
8858 fputs (" FPDBUG", stdout
);
8859 if (option
->info
& OEX_DISMISS
)
8860 fputs (" DISMISS", stdout
);
8863 fputs (" PAD ", stdout
);
8864 if (option
->info
& OPAD_PREFIX
)
8865 fputs (" PREFIX", stdout
);
8866 if (option
->info
& OPAD_POSTFIX
)
8867 fputs (" POSTFIX", stdout
);
8868 if (option
->info
& OPAD_SYMBOL
)
8869 fputs (" SYMBOL", stdout
);
8872 fputs (" HWPATCH ", stdout
);
8873 if (option
->info
& OHW_R4KEOP
)
8874 fputs (" R4KEOP", stdout
);
8875 if (option
->info
& OHW_R8KPFETCH
)
8876 fputs (" R8KPFETCH", stdout
);
8877 if (option
->info
& OHW_R5KEOP
)
8878 fputs (" R5KEOP", stdout
);
8879 if (option
->info
& OHW_R5KCVTL
)
8880 fputs (" R5KCVTL", stdout
);
8883 fputs (" FILL ", stdout
);
8884 /* XXX Print content of info word? */
8887 fputs (" TAGS ", stdout
);
8888 /* XXX Print content of info word? */
8891 fputs (" HWAND ", stdout
);
8892 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8893 fputs (" R4KEOP_CHECKED", stdout
);
8894 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8895 fputs (" R4KEOP_CLEAN", stdout
);
8898 fputs (" HWOR ", stdout
);
8899 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8900 fputs (" R4KEOP_CHECKED", stdout
);
8901 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8902 fputs (" R4KEOP_CLEAN", stdout
);
8905 printf (" GP_GROUP %#06lx self-contained %#06lx",
8906 option
->info
& OGP_GROUP
,
8907 (option
->info
& OGP_SELF
) >> 16);
8910 printf (" IDENT %#06lx self-contained %#06lx",
8911 option
->info
& OGP_GROUP
,
8912 (option
->info
& OGP_SELF
) >> 16);
8915 /* This shouldn't happen. */
8916 printf (" %3d ??? %d %lx",
8917 option
->kind
, option
->section
, option
->info
);
8921 len
= sizeof (*eopt
);
8922 while (len
< option
->size
)
8923 if (((char *) option
)[len
] >= ' '
8924 && ((char *) option
)[len
] < 0x7f)
8925 printf ("%c", ((char *) option
)[len
++]);
8927 printf ("\\%03o", ((char *) option
)[len
++]);
8929 fputs ("\n", stdout
);
8937 if (conflicts_offset
!= 0 && conflictsno
!= 0)
8939 Elf32_Conflict
*iconf
;
8942 if (dynamic_symbols
== NULL
)
8944 error (_("conflict list found without a dynamic symbol table\n"));
8948 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
8951 error (_("Out of memory\n"));
8957 Elf32_External_Conflict
*econf32
;
8959 econf32
= get_data (NULL
, file
, conflicts_offset
,
8960 conflictsno
, sizeof (*econf32
), _("conflict"));
8964 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8965 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
8971 Elf64_External_Conflict
*econf64
;
8973 econf64
= get_data (NULL
, file
, conflicts_offset
,
8974 conflictsno
, sizeof (*econf64
), _("conflict"));
8978 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8979 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
8984 printf (_("\nSection '.conflict' contains %lu entries:\n"),
8985 (unsigned long) conflictsno
);
8986 puts (_(" Num: Index Value Name"));
8988 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8990 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
8992 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
8993 print_vma (psym
->st_value
, FULL_HEX
);
8995 if (VALID_DYNAMIC_NAME (psym
->st_name
))
8996 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
8998 printf ("<corrupt: %14ld>", psym
->st_name
);
9009 process_gnu_liblist (FILE *file
)
9011 Elf_Internal_Shdr
*section
, *string_sec
;
9012 Elf32_External_Lib
*elib
;
9021 for (i
= 0, section
= section_headers
;
9022 i
< elf_header
.e_shnum
;
9025 switch (section
->sh_type
)
9027 case SHT_GNU_LIBLIST
:
9028 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
9031 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
9036 string_sec
= SECTION_HEADER (section
->sh_link
);
9038 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
9039 string_sec
->sh_size
, _("liblist string table"));
9040 strtab_size
= string_sec
->sh_size
;
9043 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9049 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9050 SECTION_NAME (section
),
9051 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9053 puts (" Library Time Stamp Checksum Version Flags");
9055 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9063 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9064 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9065 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9066 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9067 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9069 tmp
= gmtime (&time
);
9070 snprintf (timebuf
, sizeof (timebuf
),
9071 "%04u-%02u-%02uT%02u:%02u:%02u",
9072 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9073 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9075 printf ("%3lu: ", (unsigned long) cnt
);
9077 printf ("%-20s", liblist
.l_name
< strtab_size
9078 ? strtab
+ liblist
.l_name
: "<corrupt>");
9080 printf ("%-20.20s", liblist
.l_name
< strtab_size
9081 ? strtab
+ liblist
.l_name
: "<corrupt>");
9082 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9083 liblist
.l_version
, liblist
.l_flags
);
9094 get_note_type (unsigned e_type
)
9096 static char buff
[64];
9098 if (elf_header
.e_type
== ET_CORE
)
9102 return _("NT_AUXV (auxiliary vector)");
9104 return _("NT_PRSTATUS (prstatus structure)");
9106 return _("NT_FPREGSET (floating point registers)");
9108 return _("NT_PRPSINFO (prpsinfo structure)");
9110 return _("NT_TASKSTRUCT (task structure)");
9112 return _("NT_PRXFPREG (user_xfpregs structure)");
9114 return _("NT_PSTATUS (pstatus structure)");
9116 return _("NT_FPREGS (floating point registers)");
9118 return _("NT_PSINFO (psinfo structure)");
9120 return _("NT_LWPSTATUS (lwpstatus_t structure)");
9122 return _("NT_LWPSINFO (lwpsinfo_t structure)");
9123 case NT_WIN32PSTATUS
:
9124 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9132 return _("NT_VERSION (version)");
9134 return _("NT_ARCH (architecture)");
9139 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9144 get_gnu_elf_note_type (unsigned e_type
)
9146 static char buff
[64];
9150 case NT_GNU_ABI_TAG
:
9151 return _("NT_GNU_ABI_TAG (ABI version tag)");
9153 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
9154 case NT_GNU_BUILD_ID
:
9155 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
9160 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9165 get_netbsd_elfcore_note_type (unsigned e_type
)
9167 static char buff
[64];
9169 if (e_type
== NT_NETBSDCORE_PROCINFO
)
9171 /* NetBSD core "procinfo" structure. */
9172 return _("NetBSD procinfo structure");
9175 /* As of Jan 2002 there are no other machine-independent notes
9176 defined for NetBSD core files. If the note type is less
9177 than the start of the machine-dependent note types, we don't
9180 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
9182 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9186 switch (elf_header
.e_machine
)
9188 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9189 and PT_GETFPREGS == mach+2. */
9194 case EM_SPARC32PLUS
:
9198 case NT_NETBSDCORE_FIRSTMACH
+0:
9199 return _("PT_GETREGS (reg structure)");
9200 case NT_NETBSDCORE_FIRSTMACH
+2:
9201 return _("PT_GETFPREGS (fpreg structure)");
9207 /* On all other arch's, PT_GETREGS == mach+1 and
9208 PT_GETFPREGS == mach+3. */
9212 case NT_NETBSDCORE_FIRSTMACH
+1:
9213 return _("PT_GETREGS (reg structure)");
9214 case NT_NETBSDCORE_FIRSTMACH
+3:
9215 return _("PT_GETFPREGS (fpreg structure)");
9221 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
9222 e_type
- NT_NETBSDCORE_FIRSTMACH
);
9226 /* Note that by the ELF standard, the name field is already null byte
9227 terminated, and namesz includes the terminating null byte.
9228 I.E. the value of namesz for the name "FSF" is 4.
9230 If the value of namesz is zero, there is no name present. */
9232 process_note (Elf_Internal_Note
*pnote
)
9236 if (pnote
->namesz
== 0)
9237 /* If there is no note name, then use the default set of
9238 note type strings. */
9239 nt
= get_note_type (pnote
->type
);
9241 else if (const_strneq (pnote
->namedata
, "GNU"))
9242 /* GNU-specific object file notes. */
9243 nt
= get_gnu_elf_note_type (pnote
->type
);
9245 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
9246 /* NetBSD-specific core file notes. */
9247 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
9250 /* Don't recognize this note name; just use the default set of
9251 note type strings. */
9252 nt
= get_note_type (pnote
->type
);
9254 printf (" %s\t\t0x%08lx\t%s\n",
9255 pnote
->namesz
? pnote
->namedata
: "(NONE)",
9262 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
9264 Elf_External_Note
*pnotes
;
9265 Elf_External_Note
*external
;
9271 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
9277 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9278 (unsigned long) offset
, (unsigned long) length
);
9279 printf (_(" Owner\t\tData size\tDescription\n"));
9281 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
9283 Elf_External_Note
*next
;
9284 Elf_Internal_Note inote
;
9287 inote
.type
= BYTE_GET (external
->type
);
9288 inote
.namesz
= BYTE_GET (external
->namesz
);
9289 inote
.namedata
= external
->name
;
9290 inote
.descsz
= BYTE_GET (external
->descsz
);
9291 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
9292 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
9294 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
9296 if (((char *) next
) > (((char *) pnotes
) + length
))
9298 warn (_("corrupt note found at offset %lx into core notes\n"),
9299 (long)((char *)external
- (char *)pnotes
));
9300 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
9301 inote
.type
, inote
.namesz
, inote
.descsz
);
9307 /* Verify that name is null terminated. It appears that at least
9308 one version of Linux (RedHat 6.0) generates corefiles that don't
9309 comply with the ELF spec by failing to include the null byte in
9311 if (inote
.namedata
[inote
.namesz
] != '\0')
9313 temp
= malloc (inote
.namesz
+ 1);
9317 error (_("Out of memory\n"));
9322 strncpy (temp
, inote
.namedata
, inote
.namesz
);
9323 temp
[inote
.namesz
] = 0;
9325 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9326 inote
.namedata
= temp
;
9329 res
&= process_note (& inote
);
9344 process_corefile_note_segments (FILE *file
)
9346 Elf_Internal_Phdr
*segment
;
9350 if (! get_program_headers (file
))
9353 for (i
= 0, segment
= program_headers
;
9354 i
< elf_header
.e_phnum
;
9357 if (segment
->p_type
== PT_NOTE
)
9358 res
&= process_corefile_note_segment (file
,
9359 (bfd_vma
) segment
->p_offset
,
9360 (bfd_vma
) segment
->p_filesz
);
9367 process_note_sections (FILE *file
)
9369 Elf_Internal_Shdr
*section
;
9373 for (i
= 0, section
= section_headers
;
9374 i
< elf_header
.e_shnum
;
9376 if (section
->sh_type
== SHT_NOTE
)
9377 res
&= process_corefile_note_segment (file
,
9378 (bfd_vma
) section
->sh_offset
,
9379 (bfd_vma
) section
->sh_size
);
9385 process_notes (FILE *file
)
9387 /* If we have not been asked to display the notes then do nothing. */
9391 if (elf_header
.e_type
!= ET_CORE
)
9392 return process_note_sections (file
);
9394 /* No program headers means no NOTE segment. */
9395 if (elf_header
.e_phnum
> 0)
9396 return process_corefile_note_segments (file
);
9398 printf (_("No note segments present in the core file.\n"));
9403 process_arch_specific (FILE *file
)
9408 switch (elf_header
.e_machine
)
9411 return process_arm_specific (file
);
9413 case EM_MIPS_RS3_LE
:
9414 return process_mips_specific (file
);
9417 return process_power_specific (file
);
9426 get_file_header (FILE *file
)
9428 /* Read in the identity array. */
9429 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
9432 /* Determine how to read the rest of the header. */
9433 switch (elf_header
.e_ident
[EI_DATA
])
9435 default: /* fall through */
9436 case ELFDATANONE
: /* fall through */
9438 byte_get
= byte_get_little_endian
;
9439 byte_put
= byte_put_little_endian
;
9442 byte_get
= byte_get_big_endian
;
9443 byte_put
= byte_put_big_endian
;
9447 /* For now we only support 32 bit and 64 bit ELF files. */
9448 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
9450 /* Read in the rest of the header. */
9453 Elf32_External_Ehdr ehdr32
;
9455 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
9458 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
9459 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
9460 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
9461 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
9462 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
9463 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
9464 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
9465 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
9466 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
9467 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
9468 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
9469 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
9470 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
9474 Elf64_External_Ehdr ehdr64
;
9476 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9477 we will not be able to cope with the 64bit data found in
9478 64 ELF files. Detect this now and abort before we start
9479 overwriting things. */
9480 if (sizeof (bfd_vma
) < 8)
9482 error (_("This instance of readelf has been built without support for a\n\
9483 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9487 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
9490 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
9491 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
9492 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
9493 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
9494 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
9495 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
9496 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
9497 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
9498 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
9499 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
9500 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
9501 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
9502 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
9505 if (elf_header
.e_shoff
)
9507 /* There may be some extensions in the first section header. Don't
9508 bomb if we can't read it. */
9510 get_32bit_section_headers (file
, 1);
9512 get_64bit_section_headers (file
, 1);
9515 is_relocatable
= elf_header
.e_type
== ET_REL
;
9520 /* Process one ELF object file according to the command line options.
9521 This file may actually be stored in an archive. The file is
9522 positioned at the start of the ELF object. */
9525 process_object (char *file_name
, FILE *file
)
9529 if (! get_file_header (file
))
9531 error (_("%s: Failed to read file header\n"), file_name
);
9535 /* Initialise per file variables. */
9536 for (i
= ARRAY_SIZE (version_info
); i
--;)
9537 version_info
[i
] = 0;
9539 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
9540 dynamic_info
[i
] = 0;
9542 /* Process the file. */
9544 printf (_("\nFile: %s\n"), file_name
);
9546 /* Initialise the dump_sects array from the cmdline_dump_sects array.
9547 Note we do this even if cmdline_dump_sects is empty because we
9548 must make sure that the dump_sets array is zeroed out before each
9549 object file is processed. */
9550 if (num_dump_sects
> num_cmdline_dump_sects
)
9551 memset (dump_sects
, 0, num_dump_sects
);
9553 if (num_cmdline_dump_sects
> 0)
9555 if (num_dump_sects
== 0)
9556 /* A sneaky way of allocating the dump_sects array. */
9557 request_dump (num_cmdline_dump_sects
, 0);
9559 assert (num_dump_sects
>= num_cmdline_dump_sects
);
9560 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
9563 if (! process_file_header ())
9566 if (! process_section_headers (file
))
9568 /* Without loaded section headers we cannot process lots of
9570 do_unwind
= do_version
= do_dump
= do_arch
= 0;
9572 if (! do_using_dynamic
)
9573 do_syms
= do_reloc
= 0;
9576 if (! process_section_groups (file
))
9578 /* Without loaded section groups we cannot process unwind. */
9582 if (process_program_headers (file
))
9583 process_dynamic_section (file
);
9585 process_relocs (file
);
9587 process_unwind (file
);
9589 process_symbol_table (file
);
9591 process_syminfo (file
);
9593 process_version_sections (file
);
9595 process_section_contents (file
);
9597 process_notes (file
);
9599 process_gnu_liblist (file
);
9601 process_arch_specific (file
);
9603 if (program_headers
)
9605 free (program_headers
);
9606 program_headers
= NULL
;
9609 if (section_headers
)
9611 free (section_headers
);
9612 section_headers
= NULL
;
9617 free (string_table
);
9618 string_table
= NULL
;
9619 string_table_length
= 0;
9622 if (dynamic_strings
)
9624 free (dynamic_strings
);
9625 dynamic_strings
= NULL
;
9626 dynamic_strings_length
= 0;
9629 if (dynamic_symbols
)
9631 free (dynamic_symbols
);
9632 dynamic_symbols
= NULL
;
9633 num_dynamic_syms
= 0;
9636 if (dynamic_syminfo
)
9638 free (dynamic_syminfo
);
9639 dynamic_syminfo
= NULL
;
9642 if (section_headers_groups
)
9644 free (section_headers_groups
);
9645 section_headers_groups
= NULL
;
9650 struct group_list
*g
, *next
;
9652 for (i
= 0; i
< group_count
; i
++)
9654 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
9661 free (section_groups
);
9662 section_groups
= NULL
;
9665 free_debug_memory ();
9670 /* Process an ELF archive. The file is positioned just after the
9674 process_archive (char *file_name
, FILE *file
)
9676 struct ar_hdr arhdr
;
9679 char *longnames
= NULL
;
9680 unsigned long longnames_size
= 0;
9681 size_t file_name_size
;
9686 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9687 if (got
!= sizeof arhdr
)
9692 error (_("%s: failed to read archive header\n"), file_name
);
9696 if (const_strneq (arhdr
.ar_name
, "/ "))
9698 /* This is the archive symbol table. Skip it.
9699 FIXME: We should have an option to dump it. */
9700 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9701 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
9703 error (_("%s: failed to skip archive symbol table\n"), file_name
);
9707 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9708 if (got
!= sizeof arhdr
)
9713 error (_("%s: failed to read archive header\n"), file_name
);
9718 if (const_strneq (arhdr
.ar_name
, "// "))
9720 /* This is the archive string table holding long member
9723 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9725 longnames
= malloc (longnames_size
);
9726 if (longnames
== NULL
)
9728 error (_("Out of memory\n"));
9732 if (fread (longnames
, longnames_size
, 1, file
) != 1)
9735 error (_("%s: failed to read string table\n"), file_name
);
9739 if ((longnames_size
& 1) != 0)
9742 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9743 if (got
!= sizeof arhdr
)
9750 error (_("%s: failed to read archive header\n"), file_name
);
9755 file_name_size
= strlen (file_name
);
9764 if (arhdr
.ar_name
[0] == '/')
9768 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
9769 if (off
>= longnames_size
)
9771 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
9776 name
= longnames
+ off
;
9777 nameend
= memchr (name
, '/', longnames_size
- off
);
9781 name
= arhdr
.ar_name
;
9782 nameend
= memchr (name
, '/', 16);
9785 if (nameend
== NULL
)
9787 error (_("%s: bad archive file name\n"), file_name
);
9792 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
9793 if (namealc
== NULL
)
9795 error (_("Out of memory\n"));
9800 memcpy (namealc
, file_name
, file_name_size
);
9801 namealc
[file_name_size
] = '(';
9802 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
9803 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
9804 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
9806 archive_file_offset
= ftell (file
);
9807 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9809 ret
|= process_object (namealc
, file
);
9814 (archive_file_offset
9816 + (archive_file_size
& 1)),
9819 error (_("%s: failed to seek to next archive header\n"), file_name
);
9824 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9825 if (got
!= sizeof arhdr
)
9830 error (_("%s: failed to read archive header\n"), file_name
);
9843 process_file (char *file_name
)
9846 struct stat statbuf
;
9850 if (stat (file_name
, &statbuf
) < 0)
9852 if (errno
== ENOENT
)
9853 error (_("'%s': No such file\n"), file_name
);
9855 error (_("Could not locate '%s'. System error message: %s\n"),
9856 file_name
, strerror (errno
));
9860 if (! S_ISREG (statbuf
.st_mode
))
9862 error (_("'%s' is not an ordinary file\n"), file_name
);
9866 file
= fopen (file_name
, "rb");
9869 error (_("Input file '%s' is not readable.\n"), file_name
);
9873 if (fread (armag
, SARMAG
, 1, file
) != 1)
9875 error (_("%s: Failed to read file header\n"), file_name
);
9880 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
9881 ret
= process_archive (file_name
, file
);
9885 archive_file_size
= archive_file_offset
= 0;
9886 ret
= process_object (file_name
, file
);
9894 #ifdef SUPPORT_DISASSEMBLY
9895 /* Needed by the i386 disassembler. For extra credit, someone could
9896 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9900 print_address (unsigned int addr
, FILE *outfile
)
9902 fprintf (outfile
,"0x%8.8x", addr
);
9905 /* Needed by the i386 disassembler. */
9907 db_task_printsym (unsigned int addr
)
9909 print_address (addr
, stderr
);
9914 main (int argc
, char **argv
)
9918 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9919 setlocale (LC_MESSAGES
, "");
9921 #if defined (HAVE_SETLOCALE)
9922 setlocale (LC_CTYPE
, "");
9924 bindtextdomain (PACKAGE
, LOCALEDIR
);
9925 textdomain (PACKAGE
);
9927 expandargv (&argc
, &argv
);
9929 parse_args (argc
, argv
);
9931 if (num_dump_sects
> 0)
9933 /* Make a copy of the dump_sects array. */
9934 cmdline_dump_sects
= malloc (num_dump_sects
);
9935 if (cmdline_dump_sects
== NULL
)
9936 error (_("Out of memory allocating dump request table.\n"));
9939 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
9940 num_cmdline_dump_sects
= num_dump_sects
;
9944 if (optind
< (argc
- 1))
9948 while (optind
< argc
)
9949 err
|= process_file (argv
[optind
++]);
9951 if (dump_sects
!= NULL
)
9953 if (cmdline_dump_sects
!= NULL
)
9954 free (cmdline_dump_sects
);