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";
2365 case ELFOSABI_NACL
: return "NativeClient";
2367 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2373 get_arm_segment_type (unsigned long type
)
2387 get_mips_segment_type (unsigned long type
)
2391 case PT_MIPS_REGINFO
:
2393 case PT_MIPS_RTPROC
:
2395 case PT_MIPS_OPTIONS
:
2405 get_parisc_segment_type (unsigned long type
)
2409 case PT_HP_TLS
: return "HP_TLS";
2410 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2411 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2412 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2413 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2414 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2415 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2416 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2417 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2418 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2419 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2420 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2421 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2422 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2423 case PT_HP_STACK
: return "HP_STACK";
2424 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2425 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2426 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2427 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2436 get_ia64_segment_type (unsigned long type
)
2440 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2441 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2442 case PT_HP_TLS
: return "HP_TLS";
2443 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2444 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2445 case PT_IA_64_HP_STACK
: return "HP_STACK";
2454 get_segment_type (unsigned long p_type
)
2456 static char buff
[32];
2460 case PT_NULL
: return "NULL";
2461 case PT_LOAD
: return "LOAD";
2462 case PT_DYNAMIC
: return "DYNAMIC";
2463 case PT_INTERP
: return "INTERP";
2464 case PT_NOTE
: return "NOTE";
2465 case PT_SHLIB
: return "SHLIB";
2466 case PT_PHDR
: return "PHDR";
2467 case PT_TLS
: return "TLS";
2469 case PT_GNU_EH_FRAME
:
2470 return "GNU_EH_FRAME";
2471 case PT_GNU_STACK
: return "GNU_STACK";
2472 case PT_GNU_RELRO
: return "GNU_RELRO";
2475 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2479 switch (elf_header
.e_machine
)
2482 result
= get_arm_segment_type (p_type
);
2485 case EM_MIPS_RS3_LE
:
2486 result
= get_mips_segment_type (p_type
);
2489 result
= get_parisc_segment_type (p_type
);
2492 result
= get_ia64_segment_type (p_type
);
2502 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2504 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2508 switch (elf_header
.e_machine
)
2511 result
= get_parisc_segment_type (p_type
);
2514 result
= get_ia64_segment_type (p_type
);
2524 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2527 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2534 get_mips_section_type_name (unsigned int sh_type
)
2538 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2539 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2540 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2541 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2542 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2543 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2544 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2545 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2546 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2547 case SHT_MIPS_RELD
: return "MIPS_RELD";
2548 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2549 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2550 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2551 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2552 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2553 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2554 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2555 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2556 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2557 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2558 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2559 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2560 case SHT_MIPS_LINE
: return "MIPS_LINE";
2561 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2562 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2563 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2564 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2565 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2566 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2567 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2568 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2569 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2570 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2571 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2572 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2573 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2574 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2575 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2576 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2584 get_parisc_section_type_name (unsigned int sh_type
)
2588 case SHT_PARISC_EXT
: return "PARISC_EXT";
2589 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2590 case SHT_PARISC_DOC
: return "PARISC_DOC";
2591 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2592 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2593 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2594 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2602 get_ia64_section_type_name (unsigned int sh_type
)
2604 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2605 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2606 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2610 case SHT_IA_64_EXT
: return "IA_64_EXT";
2611 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2612 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2620 get_x86_64_section_type_name (unsigned int sh_type
)
2624 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2632 get_arm_section_type_name (unsigned int sh_type
)
2638 case SHT_ARM_PREEMPTMAP
:
2639 return "ARM_PREEMPTMAP";
2640 case SHT_ARM_ATTRIBUTES
:
2641 return "ARM_ATTRIBUTES";
2649 get_section_type_name (unsigned int sh_type
)
2651 static char buff
[32];
2655 case SHT_NULL
: return "NULL";
2656 case SHT_PROGBITS
: return "PROGBITS";
2657 case SHT_SYMTAB
: return "SYMTAB";
2658 case SHT_STRTAB
: return "STRTAB";
2659 case SHT_RELA
: return "RELA";
2660 case SHT_HASH
: return "HASH";
2661 case SHT_DYNAMIC
: return "DYNAMIC";
2662 case SHT_NOTE
: return "NOTE";
2663 case SHT_NOBITS
: return "NOBITS";
2664 case SHT_REL
: return "REL";
2665 case SHT_SHLIB
: return "SHLIB";
2666 case SHT_DYNSYM
: return "DYNSYM";
2667 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2668 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2669 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2670 case SHT_GNU_HASH
: return "GNU_HASH";
2671 case SHT_GROUP
: return "GROUP";
2672 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2673 case SHT_GNU_verdef
: return "VERDEF";
2674 case SHT_GNU_verneed
: return "VERNEED";
2675 case SHT_GNU_versym
: return "VERSYM";
2676 case 0x6ffffff0: return "VERSYM";
2677 case 0x6ffffffc: return "VERDEF";
2678 case 0x7ffffffd: return "AUXILIARY";
2679 case 0x7fffffff: return "FILTER";
2680 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2683 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2687 switch (elf_header
.e_machine
)
2690 case EM_MIPS_RS3_LE
:
2691 result
= get_mips_section_type_name (sh_type
);
2694 result
= get_parisc_section_type_name (sh_type
);
2697 result
= get_ia64_section_type_name (sh_type
);
2700 result
= get_x86_64_section_type_name (sh_type
);
2703 result
= get_arm_section_type_name (sh_type
);
2713 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2715 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2716 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2717 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2718 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2720 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2726 #define OPTION_DEBUG_DUMP 512
2728 static struct option options
[] =
2730 {"all", no_argument
, 0, 'a'},
2731 {"file-header", no_argument
, 0, 'h'},
2732 {"program-headers", no_argument
, 0, 'l'},
2733 {"headers", no_argument
, 0, 'e'},
2734 {"histogram", no_argument
, 0, 'I'},
2735 {"segments", no_argument
, 0, 'l'},
2736 {"sections", no_argument
, 0, 'S'},
2737 {"section-headers", no_argument
, 0, 'S'},
2738 {"section-groups", no_argument
, 0, 'g'},
2739 {"section-details", no_argument
, 0, 't'},
2740 {"full-section-name",no_argument
, 0, 'N'},
2741 {"symbols", no_argument
, 0, 's'},
2742 {"syms", no_argument
, 0, 's'},
2743 {"relocs", no_argument
, 0, 'r'},
2744 {"notes", no_argument
, 0, 'n'},
2745 {"dynamic", no_argument
, 0, 'd'},
2746 {"arch-specific", no_argument
, 0, 'A'},
2747 {"version-info", no_argument
, 0, 'V'},
2748 {"use-dynamic", no_argument
, 0, 'D'},
2749 {"hex-dump", required_argument
, 0, 'x'},
2750 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2751 {"unwind", no_argument
, 0, 'u'},
2752 #ifdef SUPPORT_DISASSEMBLY
2753 {"instruction-dump", required_argument
, 0, 'i'},
2756 {"version", no_argument
, 0, 'v'},
2757 {"wide", no_argument
, 0, 'W'},
2758 {"help", no_argument
, 0, 'H'},
2759 {0, no_argument
, 0, 0}
2763 usage (FILE *stream
)
2765 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2766 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
2767 fprintf (stream
, _(" Options are:\n\
2768 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2769 -h --file-header Display the ELF file header\n\
2770 -l --program-headers Display the program headers\n\
2771 --segments An alias for --program-headers\n\
2772 -S --section-headers Display the sections' header\n\
2773 --sections An alias for --section-headers\n\
2774 -g --section-groups Display the section groups\n\
2775 -t --section-details Display the section details\n\
2776 -e --headers Equivalent to: -h -l -S\n\
2777 -s --syms Display the symbol table\n\
2778 --symbols An alias for --syms\n\
2779 -n --notes Display the core notes (if present)\n\
2780 -r --relocs Display the relocations (if present)\n\
2781 -u --unwind Display the unwind info (if present)\n\
2782 -d --dynamic Display the dynamic section (if present)\n\
2783 -V --version-info Display the version sections (if present)\n\
2784 -A --arch-specific Display architecture specific information (if any).\n\
2785 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2786 -x --hex-dump=<number> Dump the contents of section <number>\n\
2787 -w[liaprmfFsoR] or\n\
2788 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2789 Display the contents of DWARF2 debug sections\n"));
2790 #ifdef SUPPORT_DISASSEMBLY
2791 fprintf (stream
, _("\
2792 -i --instruction-dump=<number>\n\
2793 Disassemble the contents of section <number>\n"));
2795 fprintf (stream
, _("\
2796 -I --histogram Display histogram of bucket list lengths\n\
2797 -W --wide Allow output width to exceed 80 characters\n\
2798 @<file> Read options from <file>\n\
2799 -H --help Display this information\n\
2800 -v --version Display the version number of readelf\n"));
2802 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2803 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2805 exit (stream
== stdout
? 0 : 1);
2808 /* Record the fact that the user wants the contents of section number
2809 SECTION to be displayed using the method(s) encoded as flags bits
2810 in TYPE. Note, TYPE can be zero if we are creating the array for
2814 request_dump (unsigned int section
, int type
)
2816 if (section
>= num_dump_sects
)
2818 char *new_dump_sects
;
2820 new_dump_sects
= calloc (section
+ 1, 1);
2822 if (new_dump_sects
== NULL
)
2823 error (_("Out of memory allocating dump request table.\n"));
2826 /* Copy current flag settings. */
2827 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2831 dump_sects
= new_dump_sects
;
2832 num_dump_sects
= section
+ 1;
2837 dump_sects
[section
] |= type
;
2842 /* Request a dump by section name. */
2845 request_dump_byname (const char *section
, int type
)
2847 struct dump_list_entry
*new_request
;
2849 new_request
= malloc (sizeof (struct dump_list_entry
));
2851 error (_("Out of memory allocating dump request table.\n"));
2853 new_request
->name
= strdup (section
);
2854 if (!new_request
->name
)
2855 error (_("Out of memory allocating dump request table.\n"));
2857 new_request
->type
= type
;
2859 new_request
->next
= dump_sects_byname
;
2860 dump_sects_byname
= new_request
;
2864 parse_args (int argc
, char **argv
)
2871 while ((c
= getopt_long
2872 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWH", options
, NULL
)) != EOF
)
2893 do_section_groups
++;
2901 do_section_groups
++;
2906 do_section_details
++;
2948 section
= strtoul (optarg
, & cp
, 0);
2949 if (! *cp
&& section
>= 0)
2950 request_dump (section
, HEX_DUMP
);
2952 request_dump_byname (optarg
, HEX_DUMP
);
2960 unsigned int index
= 0;
2964 while (optarg
[index
])
2965 switch (optarg
[index
++])
2974 do_debug_abbrevs
= 1;
2984 do_debug_pubnames
= 1;
2988 do_debug_aranges
= 1;
2992 do_debug_ranges
= 1;
2996 do_debug_frames_interp
= 1;
2998 do_debug_frames
= 1;
3003 do_debug_macinfo
= 1;
3017 warn (_("Unrecognized debug option '%s'\n"), optarg
);
3022 case OPTION_DEBUG_DUMP
:
3030 const char * option
;
3033 debug_dump_long_opts
;
3035 debug_dump_long_opts opts_table
[] =
3037 /* Please keep this table alpha- sorted. */
3038 { "Ranges", & do_debug_ranges
},
3039 { "abbrev", & do_debug_abbrevs
},
3040 { "aranges", & do_debug_aranges
},
3041 { "frames", & do_debug_frames
},
3042 { "frames-interp", & do_debug_frames_interp
},
3043 { "info", & do_debug_info
},
3044 { "line", & do_debug_lines
},
3045 { "loc", & do_debug_loc
},
3046 { "macro", & do_debug_macinfo
},
3047 { "pubnames", & do_debug_pubnames
},
3048 /* This entry is for compatability
3049 with earlier versions of readelf. */
3050 { "ranges", & do_debug_aranges
},
3051 { "str", & do_debug_str
},
3062 debug_dump_long_opts
* entry
;
3064 for (entry
= opts_table
; entry
->option
; entry
++)
3066 size_t len
= strlen (entry
->option
);
3068 if (strneq (p
, entry
->option
, len
)
3069 && (p
[len
] == ',' || p
[len
] == '\0'))
3071 * entry
->variable
= 1;
3073 /* The --debug-dump=frames-interp option also
3074 enables the --debug-dump=frames option. */
3075 if (do_debug_frames_interp
)
3076 do_debug_frames
= 1;
3083 if (entry
->option
== NULL
)
3085 warn (_("Unrecognized debug option '%s'\n"), p
);
3086 p
= strchr (p
, ',');
3096 #ifdef SUPPORT_DISASSEMBLY
3099 section
= strtoul (optarg
, & cp
, 0);
3100 if (! *cp
&& section
>= 0)
3102 request_dump (section
, DISASS_DUMP
);
3108 print_version (program_name
);
3117 #ifdef SUPPORT_DISASSEMBLY
3120 /* xgettext:c-format */
3121 error (_("Invalid option '-%c'\n"), c
);
3128 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3129 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3130 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3131 && !do_section_groups
)
3135 warn (_("Nothing to do.\n"));
3141 get_elf_class (unsigned int elf_class
)
3143 static char buff
[32];
3147 case ELFCLASSNONE
: return _("none");
3148 case ELFCLASS32
: return "ELF32";
3149 case ELFCLASS64
: return "ELF64";
3151 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3157 get_data_encoding (unsigned int encoding
)
3159 static char buff
[32];
3163 case ELFDATANONE
: return _("none");
3164 case ELFDATA2LSB
: return _("2's complement, little endian");
3165 case ELFDATA2MSB
: return _("2's complement, big endian");
3167 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3172 /* Decode the data held in 'elf_header'. */
3175 process_file_header (void)
3177 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3178 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3179 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3180 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3183 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3191 printf (_("ELF Header:\n"));
3192 printf (_(" Magic: "));
3193 for (i
= 0; i
< EI_NIDENT
; i
++)
3194 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3196 printf (_(" Class: %s\n"),
3197 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3198 printf (_(" Data: %s\n"),
3199 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3200 printf (_(" Version: %d %s\n"),
3201 elf_header
.e_ident
[EI_VERSION
],
3202 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3204 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3207 printf (_(" OS/ABI: %s\n"),
3208 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3209 printf (_(" ABI Version: %d\n"),
3210 elf_header
.e_ident
[EI_ABIVERSION
]);
3211 printf (_(" Type: %s\n"),
3212 get_file_type (elf_header
.e_type
));
3213 printf (_(" Machine: %s\n"),
3214 get_machine_name (elf_header
.e_machine
));
3215 printf (_(" Version: 0x%lx\n"),
3216 (unsigned long) elf_header
.e_version
);
3218 printf (_(" Entry point address: "));
3219 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3220 printf (_("\n Start of program headers: "));
3221 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3222 printf (_(" (bytes into file)\n Start of section headers: "));
3223 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3224 printf (_(" (bytes into file)\n"));
3226 printf (_(" Flags: 0x%lx%s\n"),
3227 (unsigned long) elf_header
.e_flags
,
3228 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3229 printf (_(" Size of this header: %ld (bytes)\n"),
3230 (long) elf_header
.e_ehsize
);
3231 printf (_(" Size of program headers: %ld (bytes)\n"),
3232 (long) elf_header
.e_phentsize
);
3233 printf (_(" Number of program headers: %ld\n"),
3234 (long) elf_header
.e_phnum
);
3235 printf (_(" Size of section headers: %ld (bytes)\n"),
3236 (long) elf_header
.e_shentsize
);
3237 printf (_(" Number of section headers: %ld"),
3238 (long) elf_header
.e_shnum
);
3239 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3240 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3241 putc ('\n', stdout
);
3242 printf (_(" Section header string table index: %ld"),
3243 (long) elf_header
.e_shstrndx
);
3244 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3245 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3246 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3247 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3248 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3249 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3250 printf (" <corrupt: out of range>");
3251 putc ('\n', stdout
);
3254 if (section_headers
!= NULL
)
3256 if (elf_header
.e_shnum
== 0)
3257 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3258 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3259 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3260 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3261 && (elf_header
.e_shstrndx
>= elf_header
.e_shnum
3262 || (elf_header
.e_shstrndx
>= SHN_LORESERVE
3263 && elf_header
.e_shstrndx
<= SHN_HIRESERVE
)))
3264 elf_header
.e_shstrndx
= SHN_UNDEF
;
3265 free (section_headers
);
3266 section_headers
= NULL
;
3274 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3276 Elf32_External_Phdr
*phdrs
;
3277 Elf32_External_Phdr
*external
;
3278 Elf_Internal_Phdr
*internal
;
3281 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3282 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3283 _("program headers"));
3287 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3288 i
< elf_header
.e_phnum
;
3289 i
++, internal
++, external
++)
3291 internal
->p_type
= BYTE_GET (external
->p_type
);
3292 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3293 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3294 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3295 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3296 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3297 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3298 internal
->p_align
= BYTE_GET (external
->p_align
);
3307 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3309 Elf64_External_Phdr
*phdrs
;
3310 Elf64_External_Phdr
*external
;
3311 Elf_Internal_Phdr
*internal
;
3314 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3315 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3316 _("program headers"));
3320 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3321 i
< elf_header
.e_phnum
;
3322 i
++, internal
++, external
++)
3324 internal
->p_type
= BYTE_GET (external
->p_type
);
3325 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3326 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3327 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3328 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3329 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3330 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3331 internal
->p_align
= BYTE_GET (external
->p_align
);
3339 /* Returns 1 if the program headers were read into `program_headers'. */
3342 get_program_headers (FILE *file
)
3344 Elf_Internal_Phdr
*phdrs
;
3346 /* Check cache of prior read. */
3347 if (program_headers
!= NULL
)
3350 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3354 error (_("Out of memory\n"));
3359 ? get_32bit_program_headers (file
, phdrs
)
3360 : get_64bit_program_headers (file
, phdrs
))
3362 program_headers
= phdrs
;
3370 /* Returns 1 if the program headers were loaded. */
3373 process_program_headers (FILE *file
)
3375 Elf_Internal_Phdr
*segment
;
3378 if (elf_header
.e_phnum
== 0)
3381 printf (_("\nThere are no program headers in this file.\n"));
3385 if (do_segments
&& !do_header
)
3387 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3388 printf (_("Entry point "));
3389 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3390 printf (_("\nThere are %d program headers, starting at offset "),
3391 elf_header
.e_phnum
);
3392 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3396 if (! get_program_headers (file
))
3401 if (elf_header
.e_phnum
> 1)
3402 printf (_("\nProgram Headers:\n"));
3404 printf (_("\nProgram Headers:\n"));
3408 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3411 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3415 (_(" Type Offset VirtAddr PhysAddr\n"));
3417 (_(" FileSiz MemSiz Flags Align\n"));
3424 for (i
= 0, segment
= program_headers
;
3425 i
< elf_header
.e_phnum
;
3430 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3434 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3435 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3436 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3437 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3438 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3440 (segment
->p_flags
& PF_R
? 'R' : ' '),
3441 (segment
->p_flags
& PF_W
? 'W' : ' '),
3442 (segment
->p_flags
& PF_X
? 'E' : ' '));
3443 printf ("%#lx", (unsigned long) segment
->p_align
);
3447 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3448 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3451 print_vma (segment
->p_offset
, FULL_HEX
);
3455 print_vma (segment
->p_vaddr
, FULL_HEX
);
3457 print_vma (segment
->p_paddr
, FULL_HEX
);
3460 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3461 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3464 print_vma (segment
->p_filesz
, FULL_HEX
);
3468 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3469 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3472 print_vma (segment
->p_offset
, FULL_HEX
);
3476 (segment
->p_flags
& PF_R
? 'R' : ' '),
3477 (segment
->p_flags
& PF_W
? 'W' : ' '),
3478 (segment
->p_flags
& PF_X
? 'E' : ' '));
3480 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3481 printf ("%#lx", (unsigned long) segment
->p_align
);
3484 print_vma (segment
->p_align
, PREFIX_HEX
);
3489 print_vma (segment
->p_offset
, FULL_HEX
);
3491 print_vma (segment
->p_vaddr
, FULL_HEX
);
3493 print_vma (segment
->p_paddr
, FULL_HEX
);
3495 print_vma (segment
->p_filesz
, FULL_HEX
);
3497 print_vma (segment
->p_memsz
, FULL_HEX
);
3499 (segment
->p_flags
& PF_R
? 'R' : ' '),
3500 (segment
->p_flags
& PF_W
? 'W' : ' '),
3501 (segment
->p_flags
& PF_X
? 'E' : ' '));
3502 print_vma (segment
->p_align
, HEX
);
3506 switch (segment
->p_type
)
3510 error (_("more than one dynamic segment\n"));
3512 /* Try to locate the .dynamic section. If there is
3513 a section header table, we can easily locate it. */
3514 if (section_headers
!= NULL
)
3516 Elf_Internal_Shdr
*sec
;
3518 sec
= find_section (".dynamic");
3519 if (sec
== NULL
|| sec
->sh_size
== 0)
3521 error (_("no .dynamic section in the dynamic segment\n"));
3525 if (sec
->sh_type
== SHT_NOBITS
)
3528 dynamic_addr
= sec
->sh_offset
;
3529 dynamic_size
= sec
->sh_size
;
3531 if (dynamic_addr
< segment
->p_offset
3532 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3533 warn (_("the .dynamic section is not contained within the dynamic segment\n"));
3534 else if (dynamic_addr
> segment
->p_offset
)
3535 warn (_("the .dynamic section is not the first section in the dynamic segment.\n"));
3539 /* Otherwise, we can only assume that the .dynamic
3540 section is the first section in the DYNAMIC segment. */
3541 dynamic_addr
= segment
->p_offset
;
3542 dynamic_size
= segment
->p_filesz
;
3547 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3549 error (_("Unable to find program interpreter name\n"));
3553 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3555 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3556 error (_("Internal error: failed to create format string to display program interpreter\n"));
3558 program_interpreter
[0] = 0;
3559 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3560 error (_("Unable to read program interpreter name\n"));
3563 printf (_("\n [Requesting program interpreter: %s]"),
3564 program_interpreter
);
3570 putc ('\n', stdout
);
3573 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3575 printf (_("\n Section to Segment mapping:\n"));
3576 printf (_(" Segment Sections...\n"));
3578 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3581 Elf_Internal_Shdr
*section
;
3583 segment
= program_headers
+ i
;
3584 section
= section_headers
;
3586 printf (" %2.2d ", i
);
3588 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3590 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section
, segment
))
3591 printf ("%s ", SECTION_NAME (section
));
3602 /* Find the file offset corresponding to VMA by using the program headers. */
3605 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3607 Elf_Internal_Phdr
*seg
;
3609 if (! get_program_headers (file
))
3611 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3615 for (seg
= program_headers
;
3616 seg
< program_headers
+ elf_header
.e_phnum
;
3619 if (seg
->p_type
!= PT_LOAD
)
3622 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3623 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3624 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3627 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3634 get_32bit_section_headers (FILE *file
, unsigned int num
)
3636 Elf32_External_Shdr
*shdrs
;
3637 Elf_Internal_Shdr
*internal
;
3640 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3641 elf_header
.e_shentsize
, num
, _("section headers"));
3645 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3647 if (section_headers
== NULL
)
3649 error (_("Out of memory\n"));
3653 for (i
= 0, internal
= section_headers
;
3657 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3658 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3659 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3660 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3661 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3662 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3663 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3664 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3665 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3666 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3675 get_64bit_section_headers (FILE *file
, unsigned int num
)
3677 Elf64_External_Shdr
*shdrs
;
3678 Elf_Internal_Shdr
*internal
;
3681 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3682 elf_header
.e_shentsize
, num
, _("section headers"));
3686 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3688 if (section_headers
== NULL
)
3690 error (_("Out of memory\n"));
3694 for (i
= 0, internal
= section_headers
;
3698 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3699 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3700 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3701 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3702 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3703 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3704 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3705 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3706 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3707 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3715 static Elf_Internal_Sym
*
3716 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3718 unsigned long number
;
3719 Elf32_External_Sym
*esyms
;
3720 Elf_External_Sym_Shndx
*shndx
;
3721 Elf_Internal_Sym
*isyms
;
3722 Elf_Internal_Sym
*psym
;
3725 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3731 if (symtab_shndx_hdr
!= NULL
3732 && (symtab_shndx_hdr
->sh_link
3733 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3735 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3736 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3744 number
= section
->sh_size
/ section
->sh_entsize
;
3745 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3749 error (_("Out of memory\n"));
3756 for (j
= 0, psym
= isyms
;
3760 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3761 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3762 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3763 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3764 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3766 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3767 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3768 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3778 static Elf_Internal_Sym
*
3779 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3781 unsigned long number
;
3782 Elf64_External_Sym
*esyms
;
3783 Elf_External_Sym_Shndx
*shndx
;
3784 Elf_Internal_Sym
*isyms
;
3785 Elf_Internal_Sym
*psym
;
3788 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3794 if (symtab_shndx_hdr
!= NULL
3795 && (symtab_shndx_hdr
->sh_link
3796 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3798 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3799 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3807 number
= section
->sh_size
/ section
->sh_entsize
;
3808 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3812 error (_("Out of memory\n"));
3819 for (j
= 0, psym
= isyms
;
3823 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3824 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3825 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3826 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3827 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3829 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3830 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3831 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3842 get_elf_section_flags (bfd_vma sh_flags
)
3844 static char buff
[1024];
3846 int field_size
= is_32bit_elf
? 8 : 16;
3847 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3848 bfd_vma os_flags
= 0;
3849 bfd_vma proc_flags
= 0;
3850 bfd_vma unknown_flags
= 0;
3864 { "LINK ORDER", 10 },
3865 { "OS NONCONF", 10 },
3870 if (do_section_details
)
3872 sprintf (buff
, "[%*.*lx]: ",
3873 field_size
, field_size
, (unsigned long) sh_flags
);
3874 p
+= field_size
+ 4;
3881 flag
= sh_flags
& - sh_flags
;
3884 if (do_section_details
)
3888 case SHF_WRITE
: index
= 0; break;
3889 case SHF_ALLOC
: index
= 1; break;
3890 case SHF_EXECINSTR
: index
= 2; break;
3891 case SHF_MERGE
: index
= 3; break;
3892 case SHF_STRINGS
: index
= 4; break;
3893 case SHF_INFO_LINK
: index
= 5; break;
3894 case SHF_LINK_ORDER
: index
= 6; break;
3895 case SHF_OS_NONCONFORMING
: index
= 7; break;
3896 case SHF_GROUP
: index
= 8; break;
3897 case SHF_TLS
: index
= 9; break;
3906 if (p
!= buff
+ field_size
+ 4)
3908 if (size
< (10 + 2))
3915 size
-= flags
[index
].len
;
3916 p
= stpcpy (p
, flags
[index
].str
);
3918 else if (flag
& SHF_MASKOS
)
3920 else if (flag
& SHF_MASKPROC
)
3923 unknown_flags
|= flag
;
3929 case SHF_WRITE
: *p
= 'W'; break;
3930 case SHF_ALLOC
: *p
= 'A'; break;
3931 case SHF_EXECINSTR
: *p
= 'X'; break;
3932 case SHF_MERGE
: *p
= 'M'; break;
3933 case SHF_STRINGS
: *p
= 'S'; break;
3934 case SHF_INFO_LINK
: *p
= 'I'; break;
3935 case SHF_LINK_ORDER
: *p
= 'L'; break;
3936 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3937 case SHF_GROUP
: *p
= 'G'; break;
3938 case SHF_TLS
: *p
= 'T'; break;
3941 if (elf_header
.e_machine
== EM_X86_64
3942 && flag
== SHF_X86_64_LARGE
)
3944 else if (flag
& SHF_MASKOS
)
3947 sh_flags
&= ~ SHF_MASKOS
;
3949 else if (flag
& SHF_MASKPROC
)
3952 sh_flags
&= ~ SHF_MASKPROC
;
3962 if (do_section_details
)
3966 size
-= 5 + field_size
;
3967 if (p
!= buff
+ field_size
+ 4)
3975 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3976 (unsigned long) os_flags
);
3977 p
+= 5 + field_size
;
3981 size
-= 7 + field_size
;
3982 if (p
!= buff
+ field_size
+ 4)
3990 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
3991 (unsigned long) proc_flags
);
3992 p
+= 7 + field_size
;
3996 size
-= 10 + field_size
;
3997 if (p
!= buff
+ field_size
+ 4)
4005 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
4006 (unsigned long) unknown_flags
);
4007 p
+= 10 + field_size
;
4016 process_section_headers (FILE *file
)
4018 Elf_Internal_Shdr
*section
;
4021 section_headers
= NULL
;
4023 if (elf_header
.e_shnum
== 0)
4026 printf (_("\nThere are no sections in this file.\n"));
4031 if (do_sections
&& !do_header
)
4032 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4033 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4037 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4040 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4043 /* Read in the string table, so that we have names to display. */
4044 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4045 && SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
4047 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
4049 if (section
->sh_size
!= 0)
4051 string_table
= get_data (NULL
, file
, section
->sh_offset
,
4052 1, section
->sh_size
, _("string table"));
4054 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4058 /* Scan the sections for the dynamic symbol table
4059 and dynamic string table and debug sections. */
4060 dynamic_symbols
= NULL
;
4061 dynamic_strings
= NULL
;
4062 dynamic_syminfo
= NULL
;
4063 symtab_shndx_hdr
= NULL
;
4065 eh_addr_size
= is_32bit_elf
? 4 : 8;
4066 switch (elf_header
.e_machine
)
4069 case EM_MIPS_RS3_LE
:
4070 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4071 FDE addresses. However, the ABI also has a semi-official ILP32
4072 variant for which the normal FDE address size rules apply.
4074 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4075 section, where XX is the size of longs in bits. Unfortunately,
4076 earlier compilers provided no way of distinguishing ILP32 objects
4077 from LP64 objects, so if there's any doubt, we should assume that
4078 the official LP64 form is being used. */
4079 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4080 && find_section (".gcc_compiled_long32") == NULL
)
4086 switch (elf_header
.e_flags
& EF_H8_MACH
)
4088 case E_H8_MACH_H8300
:
4089 case E_H8_MACH_H8300HN
:
4090 case E_H8_MACH_H8300SN
:
4091 case E_H8_MACH_H8300SXN
:
4094 case E_H8_MACH_H8300H
:
4095 case E_H8_MACH_H8300S
:
4096 case E_H8_MACH_H8300SX
:
4102 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4105 size_t expected_entsize \
4106 = is_32bit_elf ? size32 : size64; \
4107 if (section->sh_entsize != expected_entsize) \
4108 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4109 i, (unsigned long int) section->sh_entsize, \
4110 (unsigned long int) expected_entsize); \
4111 section->sh_entsize = expected_entsize; \
4114 #define CHECK_ENTSIZE(section, i, type) \
4115 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4116 sizeof (Elf64_External_##type))
4118 for (i
= 0, section
= section_headers
;
4119 i
< elf_header
.e_shnum
;
4122 char *name
= SECTION_NAME (section
);
4124 if (section
->sh_type
== SHT_DYNSYM
)
4126 if (dynamic_symbols
!= NULL
)
4128 error (_("File contains multiple dynamic symbol tables\n"));
4132 CHECK_ENTSIZE (section
, i
, Sym
);
4133 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4134 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4136 else if (section
->sh_type
== SHT_STRTAB
4137 && streq (name
, ".dynstr"))
4139 if (dynamic_strings
!= NULL
)
4141 error (_("File contains multiple dynamic string tables\n"));
4145 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
4146 1, section
->sh_size
, _("dynamic strings"));
4147 dynamic_strings_length
= section
->sh_size
;
4149 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4151 if (symtab_shndx_hdr
!= NULL
)
4153 error (_("File contains multiple symtab shndx tables\n"));
4156 symtab_shndx_hdr
= section
;
4158 else if (section
->sh_type
== SHT_SYMTAB
)
4159 CHECK_ENTSIZE (section
, i
, Sym
);
4160 else if (section
->sh_type
== SHT_GROUP
)
4161 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4162 else if (section
->sh_type
== SHT_REL
)
4163 CHECK_ENTSIZE (section
, i
, Rel
);
4164 else if (section
->sh_type
== SHT_RELA
)
4165 CHECK_ENTSIZE (section
, i
, Rela
);
4166 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4167 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
4168 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
4169 || do_debug_loc
|| do_debug_ranges
)
4170 && const_strneq (name
, ".debug_"))
4175 || (do_debug_info
&& streq (name
, "info"))
4176 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4177 || (do_debug_lines
&& streq (name
, "line"))
4178 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4179 || (do_debug_aranges
&& streq (name
, "aranges"))
4180 || (do_debug_ranges
&& streq (name
, "ranges"))
4181 || (do_debug_frames
&& streq (name
, "frame"))
4182 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4183 || (do_debug_str
&& streq (name
, "str"))
4184 || (do_debug_loc
&& streq (name
, "loc"))
4186 request_dump (i
, DEBUG_DUMP
);
4188 /* linkonce section to be combined with .debug_info at link time. */
4189 else if ((do_debugging
|| do_debug_info
)
4190 && const_strneq (name
, ".gnu.linkonce.wi."))
4191 request_dump (i
, DEBUG_DUMP
);
4192 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4193 request_dump (i
, DEBUG_DUMP
);
4199 if (elf_header
.e_shnum
> 1)
4200 printf (_("\nSection Headers:\n"));
4202 printf (_("\nSection Header:\n"));
4206 if (do_section_details
)
4208 printf (_(" [Nr] Name\n"));
4209 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4213 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4217 if (do_section_details
)
4219 printf (_(" [Nr] Name\n"));
4220 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4224 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4228 if (do_section_details
)
4230 printf (_(" [Nr] Name\n"));
4231 printf (_(" Type Address Offset Link\n"));
4232 printf (_(" Size EntSize Info Align\n"));
4236 printf (_(" [Nr] Name Type Address Offset\n"));
4237 printf (_(" Size EntSize Flags Link Info Align\n"));
4241 if (do_section_details
)
4242 printf (_(" Flags\n"));
4244 for (i
= 0, section
= section_headers
;
4245 i
< elf_header
.e_shnum
;
4248 if (do_section_details
)
4250 printf (" [%2u] %s\n",
4251 SECTION_HEADER_NUM (i
),
4252 SECTION_NAME (section
));
4253 if (is_32bit_elf
|| do_wide
)
4254 printf (" %-15.15s ",
4255 get_section_type_name (section
->sh_type
));
4258 printf (" [%2u] %-17.17s %-15.15s ",
4259 SECTION_HEADER_NUM (i
),
4260 SECTION_NAME (section
),
4261 get_section_type_name (section
->sh_type
));
4265 print_vma (section
->sh_addr
, LONG_HEX
);
4267 printf ( " %6.6lx %6.6lx %2.2lx",
4268 (unsigned long) section
->sh_offset
,
4269 (unsigned long) section
->sh_size
,
4270 (unsigned long) section
->sh_entsize
);
4272 if (do_section_details
)
4273 fputs (" ", stdout
);
4275 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4277 printf ("%2ld %3lu %2ld\n",
4278 (unsigned long) section
->sh_link
,
4279 (unsigned long) section
->sh_info
,
4280 (unsigned long) section
->sh_addralign
);
4284 print_vma (section
->sh_addr
, LONG_HEX
);
4286 if ((long) section
->sh_offset
== section
->sh_offset
)
4287 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4291 print_vma (section
->sh_offset
, LONG_HEX
);
4294 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4295 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4299 print_vma (section
->sh_size
, LONG_HEX
);
4302 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4303 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4307 print_vma (section
->sh_entsize
, LONG_HEX
);
4310 if (do_section_details
)
4311 fputs (" ", stdout
);
4313 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4315 printf ("%2ld %3lu ",
4316 (unsigned long) section
->sh_link
,
4317 (unsigned long) section
->sh_info
);
4319 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4320 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4323 print_vma (section
->sh_addralign
, DEC
);
4327 else if (do_section_details
)
4329 printf (" %-15.15s ",
4330 get_section_type_name (section
->sh_type
));
4331 print_vma (section
->sh_addr
, LONG_HEX
);
4332 if ((long) section
->sh_offset
== section
->sh_offset
)
4333 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4337 print_vma (section
->sh_offset
, LONG_HEX
);
4339 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4340 print_vma (section
->sh_size
, LONG_HEX
);
4342 print_vma (section
->sh_entsize
, LONG_HEX
);
4344 printf (" %-16lu %ld\n",
4345 (unsigned long) section
->sh_info
,
4346 (unsigned long) section
->sh_addralign
);
4351 print_vma (section
->sh_addr
, LONG_HEX
);
4352 if ((long) section
->sh_offset
== section
->sh_offset
)
4353 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4357 print_vma (section
->sh_offset
, LONG_HEX
);
4360 print_vma (section
->sh_size
, LONG_HEX
);
4362 print_vma (section
->sh_entsize
, LONG_HEX
);
4364 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4366 printf (" %2ld %3lu %ld\n",
4367 (unsigned long) section
->sh_link
,
4368 (unsigned long) section
->sh_info
,
4369 (unsigned long) section
->sh_addralign
);
4372 if (do_section_details
)
4373 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4376 if (!do_section_details
)
4377 printf (_("Key to Flags:\n\
4378 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4379 I (info), L (link order), G (group), x (unknown)\n\
4380 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4386 get_group_flags (unsigned int flags
)
4388 static char buff
[32];
4395 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4402 process_section_groups (FILE *file
)
4404 Elf_Internal_Shdr
*section
;
4406 struct group
*group
;
4407 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4408 Elf_Internal_Sym
*symtab
;
4412 /* Don't process section groups unless needed. */
4413 if (!do_unwind
&& !do_section_groups
)
4416 if (elf_header
.e_shnum
== 0)
4418 if (do_section_groups
)
4419 printf (_("\nThere are no sections in this file.\n"));
4424 if (section_headers
== NULL
)
4426 error (_("Section headers are not available!\n"));
4430 section_headers_groups
= calloc (elf_header
.e_shnum
,
4431 sizeof (struct group
*));
4433 if (section_headers_groups
== NULL
)
4435 error (_("Out of memory\n"));
4439 /* Scan the sections for the group section. */
4441 for (i
= 0, section
= section_headers
;
4442 i
< elf_header
.e_shnum
;
4444 if (section
->sh_type
== SHT_GROUP
)
4447 if (group_count
== 0)
4449 if (do_section_groups
)
4450 printf (_("\nThere are no section groups in this file.\n"));
4455 section_groups
= calloc (group_count
, sizeof (struct group
));
4457 if (section_groups
== NULL
)
4459 error (_("Out of memory\n"));
4468 for (i
= 0, section
= section_headers
, group
= section_groups
;
4469 i
< elf_header
.e_shnum
;
4472 if (section
->sh_type
== SHT_GROUP
)
4474 char *name
= SECTION_NAME (section
);
4476 unsigned char *start
, *indices
;
4477 unsigned int entry
, j
, size
;
4478 Elf_Internal_Shdr
*sec
;
4479 Elf_Internal_Sym
*sym
;
4481 /* Get the symbol table. */
4482 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4483 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4486 error (_("Bad sh_link in group section `%s'\n"), name
);
4490 if (symtab_sec
!= sec
)
4495 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4498 sym
= symtab
+ section
->sh_info
;
4500 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4502 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4505 error (_("Bad sh_info in group section `%s'\n"), name
);
4509 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4518 /* Get the string table. */
4519 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4520 >= elf_header
.e_shnum
)
4529 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4534 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4535 1, strtab_sec
->sh_size
,
4537 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4539 group_name
= sym
->st_name
< strtab_size
4540 ? strtab
+ sym
->st_name
: "<corrupt>";
4543 start
= get_data (NULL
, file
, section
->sh_offset
,
4544 1, section
->sh_size
, _("section data"));
4547 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4548 entry
= byte_get (indices
, 4);
4551 if (do_section_groups
)
4553 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4554 get_group_flags (entry
), i
, name
, group_name
, size
);
4556 printf (_(" [Index] Name\n"));
4559 group
->group_index
= i
;
4561 for (j
= 0; j
< size
; j
++)
4563 struct group_list
*g
;
4565 entry
= byte_get (indices
, 4);
4568 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4570 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4571 entry
, i
, elf_header
.e_shnum
- 1);
4574 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4576 error (_("invalid section [%5u] in group section [%5u]\n"),
4581 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4586 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4588 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4593 /* Intel C/C++ compiler may put section 0 in a
4594 section group. We just warn it the first time
4595 and ignore it afterwards. */
4596 static int warned
= 0;
4599 error (_("section 0 in group section [%5u]\n"),
4600 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4606 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4609 if (do_section_groups
)
4611 sec
= SECTION_HEADER (entry
);
4612 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4615 g
= xmalloc (sizeof (struct group_list
));
4616 g
->section_index
= entry
;
4617 g
->next
= group
->root
;
4641 } dynamic_relocations
[] =
4643 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4644 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4645 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4648 /* Process the reloc section. */
4651 process_relocs (FILE *file
)
4653 unsigned long rel_size
;
4654 unsigned long rel_offset
;
4660 if (do_using_dynamic
)
4664 int has_dynamic_reloc
;
4667 has_dynamic_reloc
= 0;
4669 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4671 is_rela
= dynamic_relocations
[i
].rela
;
4672 name
= dynamic_relocations
[i
].name
;
4673 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4674 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4676 has_dynamic_reloc
|= rel_size
;
4678 if (is_rela
== UNKNOWN
)
4680 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4681 switch (dynamic_info
[DT_PLTREL
])
4695 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4696 name
, rel_offset
, rel_size
);
4698 dump_relocations (file
,
4699 offset_from_vma (file
, rel_offset
, rel_size
),
4701 dynamic_symbols
, num_dynamic_syms
,
4702 dynamic_strings
, dynamic_strings_length
, is_rela
);
4706 if (! has_dynamic_reloc
)
4707 printf (_("\nThere are no dynamic relocations in this file.\n"));
4711 Elf_Internal_Shdr
*section
;
4715 for (i
= 0, section
= section_headers
;
4716 i
< elf_header
.e_shnum
;
4719 if ( section
->sh_type
!= SHT_RELA
4720 && section
->sh_type
!= SHT_REL
)
4723 rel_offset
= section
->sh_offset
;
4724 rel_size
= section
->sh_size
;
4728 Elf_Internal_Shdr
*strsec
;
4731 printf (_("\nRelocation section "));
4733 if (string_table
== NULL
)
4734 printf ("%d", section
->sh_name
);
4736 printf (_("'%s'"), SECTION_NAME (section
));
4738 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4739 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4741 is_rela
= section
->sh_type
== SHT_RELA
;
4743 if (section
->sh_link
4744 && SECTION_HEADER_INDEX (section
->sh_link
)
4745 < elf_header
.e_shnum
)
4747 Elf_Internal_Shdr
*symsec
;
4748 Elf_Internal_Sym
*symtab
;
4749 unsigned long nsyms
;
4750 unsigned long strtablen
= 0;
4751 char *strtab
= NULL
;
4753 symsec
= SECTION_HEADER (section
->sh_link
);
4754 if (symsec
->sh_type
!= SHT_SYMTAB
4755 && symsec
->sh_type
!= SHT_DYNSYM
)
4758 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4759 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4764 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4765 < elf_header
.e_shnum
)
4767 strsec
= SECTION_HEADER (symsec
->sh_link
);
4769 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4772 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4775 dump_relocations (file
, rel_offset
, rel_size
,
4776 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4782 dump_relocations (file
, rel_offset
, rel_size
,
4783 NULL
, 0, NULL
, 0, is_rela
);
4790 printf (_("\nThere are no relocations in this file.\n"));
4796 /* Process the unwind section. */
4798 #include "unwind-ia64.h"
4800 /* An absolute address consists of a section and an offset. If the
4801 section is NULL, the offset itself is the address, otherwise, the
4802 address equals to LOAD_ADDRESS(section) + offset. */
4806 unsigned short section
;
4810 #define ABSADDR(a) \
4812 ? section_headers [(a).section].sh_addr + (a).offset \
4815 struct ia64_unw_aux_info
4817 struct ia64_unw_table_entry
4819 struct absaddr start
;
4821 struct absaddr info
;
4823 *table
; /* Unwind table. */
4824 unsigned long table_len
; /* Length of unwind table. */
4825 unsigned char *info
; /* Unwind info. */
4826 unsigned long info_size
; /* Size of unwind info. */
4827 bfd_vma info_addr
; /* starting address of unwind info. */
4828 bfd_vma seg_base
; /* Starting address of segment. */
4829 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4830 unsigned long nsyms
; /* Number of symbols. */
4831 char *strtab
; /* The string table. */
4832 unsigned long strtab_size
; /* Size of string table. */
4836 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4837 unsigned long nsyms
,
4839 unsigned long strtab_size
,
4840 struct absaddr addr
,
4841 const char **symname
,
4844 bfd_vma dist
= 0x100000;
4845 Elf_Internal_Sym
*sym
, *best
= NULL
;
4848 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4850 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4851 && sym
->st_name
!= 0
4852 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4853 && addr
.offset
>= sym
->st_value
4854 && addr
.offset
- sym
->st_value
< dist
)
4857 dist
= addr
.offset
- sym
->st_value
;
4864 *symname
= (best
->st_name
>= strtab_size
4865 ? "<corrupt>" : strtab
+ best
->st_name
);
4870 *offset
= addr
.offset
;
4874 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4876 struct ia64_unw_table_entry
*tp
;
4879 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4883 const unsigned char *dp
;
4884 const unsigned char *head
;
4885 const char *procname
;
4887 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4888 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4890 fputs ("\n<", stdout
);
4894 fputs (procname
, stdout
);
4897 printf ("+%lx", (unsigned long) offset
);
4900 fputs (">: [", stdout
);
4901 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4902 fputc ('-', stdout
);
4903 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4904 printf ("], info at +0x%lx\n",
4905 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4907 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4908 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4910 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4911 (unsigned) UNW_VER (stamp
),
4912 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4913 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4914 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4915 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4917 if (UNW_VER (stamp
) != 1)
4919 printf ("\tUnknown version.\n");
4924 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4925 dp
= unw_decode (dp
, in_body
, & in_body
);
4930 slurp_ia64_unwind_table (FILE *file
,
4931 struct ia64_unw_aux_info
*aux
,
4932 Elf_Internal_Shdr
*sec
)
4934 unsigned long size
, nrelas
, i
;
4935 Elf_Internal_Phdr
*seg
;
4936 struct ia64_unw_table_entry
*tep
;
4937 Elf_Internal_Shdr
*relsec
;
4938 Elf_Internal_Rela
*rela
, *rp
;
4939 unsigned char *table
, *tp
;
4940 Elf_Internal_Sym
*sym
;
4941 const char *relname
;
4943 /* First, find the starting address of the segment that includes
4946 if (elf_header
.e_phnum
)
4948 if (! get_program_headers (file
))
4951 for (seg
= program_headers
;
4952 seg
< program_headers
+ elf_header
.e_phnum
;
4955 if (seg
->p_type
!= PT_LOAD
)
4958 if (sec
->sh_addr
>= seg
->p_vaddr
4959 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4961 aux
->seg_base
= seg
->p_vaddr
;
4967 /* Second, build the unwind table from the contents of the unwind section: */
4968 size
= sec
->sh_size
;
4969 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4973 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4975 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4977 tep
->start
.section
= SHN_UNDEF
;
4978 tep
->end
.section
= SHN_UNDEF
;
4979 tep
->info
.section
= SHN_UNDEF
;
4982 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4983 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4984 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4988 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
4989 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
4990 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
4992 tep
->start
.offset
+= aux
->seg_base
;
4993 tep
->end
.offset
+= aux
->seg_base
;
4994 tep
->info
.offset
+= aux
->seg_base
;
4998 /* Third, apply any relocations to the unwind table: */
5000 for (relsec
= section_headers
;
5001 relsec
< section_headers
+ elf_header
.e_shnum
;
5004 if (relsec
->sh_type
!= SHT_RELA
5005 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5006 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5009 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5013 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5017 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5018 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5022 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5023 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5026 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5028 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5032 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5034 switch (rp
->r_offset
/eh_addr_size
% 3)
5037 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5038 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5041 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5042 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5045 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5046 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5056 aux
->table_len
= size
/ (3 * eh_addr_size
);
5061 ia64_process_unwind (FILE *file
)
5063 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
5064 unsigned long i
, unwcount
= 0, unwstart
= 0;
5065 struct ia64_unw_aux_info aux
;
5067 memset (& aux
, 0, sizeof (aux
));
5069 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5071 if (sec
->sh_type
== SHT_SYMTAB
5072 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5074 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5075 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5077 strsec
= SECTION_HEADER (sec
->sh_link
);
5078 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5079 1, strsec
->sh_size
, _("string table"));
5080 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5082 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5087 printf (_("\nThere are no unwind sections in this file.\n"));
5089 while (unwcount
-- > 0)
5094 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5095 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5096 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5103 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5105 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5107 /* We need to find which section group it is in. */
5108 struct group_list
*g
= section_headers_groups
[i
]->root
;
5110 for (; g
!= NULL
; g
= g
->next
)
5112 sec
= SECTION_HEADER (g
->section_index
);
5114 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5119 i
= elf_header
.e_shnum
;
5121 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5123 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5124 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5125 suffix
= SECTION_NAME (unwsec
) + len
;
5126 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5128 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5129 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5134 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5135 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5136 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5137 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5139 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5140 suffix
= SECTION_NAME (unwsec
) + len
;
5141 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5143 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5144 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5148 if (i
== elf_header
.e_shnum
)
5150 printf (_("\nCould not find unwind info section for "));
5152 if (string_table
== NULL
)
5153 printf ("%d", unwsec
->sh_name
);
5155 printf (_("'%s'"), SECTION_NAME (unwsec
));
5159 aux
.info_size
= sec
->sh_size
;
5160 aux
.info_addr
= sec
->sh_addr
;
5161 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
5164 printf (_("\nUnwind section "));
5166 if (string_table
== NULL
)
5167 printf ("%d", unwsec
->sh_name
);
5169 printf (_("'%s'"), SECTION_NAME (unwsec
));
5171 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5172 (unsigned long) unwsec
->sh_offset
,
5173 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5175 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5177 if (aux
.table_len
> 0)
5178 dump_ia64_unwind (& aux
);
5181 free ((char *) aux
.table
);
5183 free ((char *) aux
.info
);
5192 free ((char *) aux
.strtab
);
5197 struct hppa_unw_aux_info
5199 struct hppa_unw_table_entry
5201 struct absaddr start
;
5203 unsigned int Cannot_unwind
:1; /* 0 */
5204 unsigned int Millicode
:1; /* 1 */
5205 unsigned int Millicode_save_sr0
:1; /* 2 */
5206 unsigned int Region_description
:2; /* 3..4 */
5207 unsigned int reserved1
:1; /* 5 */
5208 unsigned int Entry_SR
:1; /* 6 */
5209 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5210 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5211 unsigned int Args_stored
:1; /* 16 */
5212 unsigned int Variable_Frame
:1; /* 17 */
5213 unsigned int Separate_Package_Body
:1; /* 18 */
5214 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5215 unsigned int Stack_Overflow_Check
:1; /* 20 */
5216 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5217 unsigned int Ada_Region
:1; /* 22 */
5218 unsigned int cxx_info
:1; /* 23 */
5219 unsigned int cxx_try_catch
:1; /* 24 */
5220 unsigned int sched_entry_seq
:1; /* 25 */
5221 unsigned int reserved2
:1; /* 26 */
5222 unsigned int Save_SP
:1; /* 27 */
5223 unsigned int Save_RP
:1; /* 28 */
5224 unsigned int Save_MRP_in_frame
:1; /* 29 */
5225 unsigned int extn_ptr_defined
:1; /* 30 */
5226 unsigned int Cleanup_defined
:1; /* 31 */
5228 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5229 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5230 unsigned int Large_frame
:1; /* 2 */
5231 unsigned int Pseudo_SP_Set
:1; /* 3 */
5232 unsigned int reserved4
:1; /* 4 */
5233 unsigned int Total_frame_size
:27; /* 5..31 */
5235 *table
; /* Unwind table. */
5236 unsigned long table_len
; /* Length of unwind table. */
5237 bfd_vma seg_base
; /* Starting address of segment. */
5238 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5239 unsigned long nsyms
; /* Number of symbols. */
5240 char *strtab
; /* The string table. */
5241 unsigned long strtab_size
; /* Size of string table. */
5245 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5247 struct hppa_unw_table_entry
*tp
;
5249 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5252 const char *procname
;
5254 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5255 aux
->strtab_size
, tp
->start
, &procname
,
5258 fputs ("\n<", stdout
);
5262 fputs (procname
, stdout
);
5265 printf ("+%lx", (unsigned long) offset
);
5268 fputs (">: [", stdout
);
5269 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5270 fputc ('-', stdout
);
5271 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5274 #define PF(_m) if (tp->_m) printf (#_m " ");
5275 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5278 PF(Millicode_save_sr0
);
5279 /* PV(Region_description); */
5285 PF(Separate_Package_Body
);
5286 PF(Frame_Extension_Millicode
);
5287 PF(Stack_Overflow_Check
);
5288 PF(Two_Instruction_SP_Increment
);
5292 PF(sched_entry_seq
);
5295 PF(Save_MRP_in_frame
);
5296 PF(extn_ptr_defined
);
5297 PF(Cleanup_defined
);
5298 PF(MPE_XL_interrupt_marker
);
5299 PF(HP_UX_interrupt_marker
);
5302 PV(Total_frame_size
);
5311 slurp_hppa_unwind_table (FILE *file
,
5312 struct hppa_unw_aux_info
*aux
,
5313 Elf_Internal_Shdr
*sec
)
5315 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5316 Elf_Internal_Phdr
*seg
;
5317 struct hppa_unw_table_entry
*tep
;
5318 Elf_Internal_Shdr
*relsec
;
5319 Elf_Internal_Rela
*rela
, *rp
;
5320 unsigned char *table
, *tp
;
5321 Elf_Internal_Sym
*sym
;
5322 const char *relname
;
5324 /* First, find the starting address of the segment that includes
5327 if (elf_header
.e_phnum
)
5329 if (! get_program_headers (file
))
5332 for (seg
= program_headers
;
5333 seg
< program_headers
+ elf_header
.e_phnum
;
5336 if (seg
->p_type
!= PT_LOAD
)
5339 if (sec
->sh_addr
>= seg
->p_vaddr
5340 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5342 aux
->seg_base
= seg
->p_vaddr
;
5348 /* Second, build the unwind table from the contents of the unwind
5350 size
= sec
->sh_size
;
5351 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5356 nentries
= size
/ unw_ent_size
;
5357 size
= unw_ent_size
* nentries
;
5359 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5361 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5363 unsigned int tmp1
, tmp2
;
5365 tep
->start
.section
= SHN_UNDEF
;
5366 tep
->end
.section
= SHN_UNDEF
;
5368 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5369 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5370 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5371 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5373 tep
->start
.offset
+= aux
->seg_base
;
5374 tep
->end
.offset
+= aux
->seg_base
;
5376 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5377 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5378 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5379 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5380 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5381 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5382 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5383 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5384 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5385 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5386 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5387 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5388 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5389 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5390 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5391 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5392 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5393 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5394 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5395 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5396 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5397 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5398 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5399 tep
->Cleanup_defined
= tmp1
& 0x1;
5401 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5402 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5403 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5404 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5405 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5406 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5410 /* Third, apply any relocations to the unwind table. */
5412 for (relsec
= section_headers
;
5413 relsec
< section_headers
+ elf_header
.e_shnum
;
5416 if (relsec
->sh_type
!= SHT_RELA
5417 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5418 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5421 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5425 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5429 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5430 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5434 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5435 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5438 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5439 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5441 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5445 i
= rp
->r_offset
/ unw_ent_size
;
5447 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5450 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5451 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5454 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5455 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5465 aux
->table_len
= nentries
;
5471 hppa_process_unwind (FILE *file
)
5473 struct hppa_unw_aux_info aux
;
5474 Elf_Internal_Shdr
*unwsec
= NULL
;
5475 Elf_Internal_Shdr
*strsec
;
5476 Elf_Internal_Shdr
*sec
;
5479 memset (& aux
, 0, sizeof (aux
));
5481 if (string_table
== NULL
)
5484 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5486 if (sec
->sh_type
== SHT_SYMTAB
5487 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5489 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5490 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5492 strsec
= SECTION_HEADER (sec
->sh_link
);
5493 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5494 1, strsec
->sh_size
, _("string table"));
5495 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5497 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5502 printf (_("\nThere are no unwind sections in this file.\n"));
5504 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5506 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5508 printf (_("\nUnwind section "));
5509 printf (_("'%s'"), SECTION_NAME (sec
));
5511 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5512 (unsigned long) sec
->sh_offset
,
5513 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5515 slurp_hppa_unwind_table (file
, &aux
, sec
);
5516 if (aux
.table_len
> 0)
5517 dump_hppa_unwind (&aux
);
5520 free ((char *) aux
.table
);
5528 free ((char *) aux
.strtab
);
5534 process_unwind (FILE *file
)
5536 struct unwind_handler
{
5538 int (*handler
)(FILE *file
);
5540 { EM_IA_64
, ia64_process_unwind
},
5541 { EM_PARISC
, hppa_process_unwind
},
5549 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5550 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5551 return handlers
[i
].handler (file
);
5553 printf (_("\nThere are no unwind sections in this file.\n"));
5558 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5560 switch (entry
->d_tag
)
5563 if (entry
->d_un
.d_val
== 0)
5567 static const char * opts
[] =
5569 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5570 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5571 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5572 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5577 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
5578 if (entry
->d_un
.d_val
& (1 << cnt
))
5580 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5587 case DT_MIPS_IVERSION
:
5588 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5589 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5591 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5594 case DT_MIPS_TIME_STAMP
:
5599 time_t time
= entry
->d_un
.d_val
;
5600 tmp
= gmtime (&time
);
5601 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5602 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5603 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5604 printf ("Time Stamp: %s\n", timebuf
);
5608 case DT_MIPS_RLD_VERSION
:
5609 case DT_MIPS_LOCAL_GOTNO
:
5610 case DT_MIPS_CONFLICTNO
:
5611 case DT_MIPS_LIBLISTNO
:
5612 case DT_MIPS_SYMTABNO
:
5613 case DT_MIPS_UNREFEXTNO
:
5614 case DT_MIPS_HIPAGENO
:
5615 case DT_MIPS_DELTA_CLASS_NO
:
5616 case DT_MIPS_DELTA_INSTANCE_NO
:
5617 case DT_MIPS_DELTA_RELOC_NO
:
5618 case DT_MIPS_DELTA_SYM_NO
:
5619 case DT_MIPS_DELTA_CLASSSYM_NO
:
5620 case DT_MIPS_COMPACT_SIZE
:
5621 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5625 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5631 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5633 switch (entry
->d_tag
)
5635 case DT_HP_DLD_FLAGS
:
5644 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5645 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5646 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5647 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5648 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5649 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5650 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5651 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5652 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5653 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5654 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5655 { DT_HP_GST
, "HP_GST" },
5656 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5657 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5658 { DT_HP_NODELETE
, "HP_NODELETE" },
5659 { DT_HP_GROUP
, "HP_GROUP" },
5660 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5664 bfd_vma val
= entry
->d_un
.d_val
;
5666 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
5667 if (val
& flags
[cnt
].bit
)
5671 fputs (flags
[cnt
].str
, stdout
);
5673 val
^= flags
[cnt
].bit
;
5676 if (val
!= 0 || first
)
5680 print_vma (val
, HEX
);
5686 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5693 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5695 switch (entry
->d_tag
)
5697 case DT_IA_64_PLT_RESERVE
:
5698 /* First 3 slots reserved. */
5699 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5701 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5705 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5712 get_32bit_dynamic_section (FILE *file
)
5714 Elf32_External_Dyn
*edyn
, *ext
;
5715 Elf_Internal_Dyn
*entry
;
5717 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5718 _("dynamic section"));
5722 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5723 might not have the luxury of section headers. Look for the DT_NULL
5724 terminator to determine the number of entries. */
5725 for (ext
= edyn
, dynamic_nent
= 0;
5726 (char *) ext
< (char *) edyn
+ dynamic_size
;
5730 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5734 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5735 if (dynamic_section
== NULL
)
5737 error (_("Out of memory\n"));
5742 for (ext
= edyn
, entry
= dynamic_section
;
5743 entry
< dynamic_section
+ dynamic_nent
;
5746 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5747 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5756 get_64bit_dynamic_section (FILE *file
)
5758 Elf64_External_Dyn
*edyn
, *ext
;
5759 Elf_Internal_Dyn
*entry
;
5761 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5762 _("dynamic section"));
5766 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5767 might not have the luxury of section headers. Look for the DT_NULL
5768 terminator to determine the number of entries. */
5769 for (ext
= edyn
, dynamic_nent
= 0;
5770 (char *) ext
< (char *) edyn
+ dynamic_size
;
5774 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5778 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5779 if (dynamic_section
== NULL
)
5781 error (_("Out of memory\n"));
5786 for (ext
= edyn
, entry
= dynamic_section
;
5787 entry
< dynamic_section
+ dynamic_nent
;
5790 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5791 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5800 print_dynamic_flags (bfd_vma flags
)
5808 flag
= flags
& - flags
;
5818 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5819 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5820 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5821 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5822 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5823 default: fputs ("unknown", stdout
); break;
5829 /* Parse and display the contents of the dynamic section. */
5832 process_dynamic_section (FILE *file
)
5834 Elf_Internal_Dyn
*entry
;
5836 if (dynamic_size
== 0)
5839 printf (_("\nThere is no dynamic section in this file.\n"));
5846 if (! get_32bit_dynamic_section (file
))
5849 else if (! get_64bit_dynamic_section (file
))
5852 /* Find the appropriate symbol table. */
5853 if (dynamic_symbols
== NULL
)
5855 for (entry
= dynamic_section
;
5856 entry
< dynamic_section
+ dynamic_nent
;
5859 Elf_Internal_Shdr section
;
5861 if (entry
->d_tag
!= DT_SYMTAB
)
5864 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5866 /* Since we do not know how big the symbol table is,
5867 we default to reading in the entire file (!) and
5868 processing that. This is overkill, I know, but it
5870 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5872 if (archive_file_offset
!= 0)
5873 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5876 if (fseek (file
, 0, SEEK_END
))
5877 error (_("Unable to seek to end of file!\n"));
5879 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5883 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5885 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5887 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5888 if (num_dynamic_syms
< 1)
5890 error (_("Unable to determine the number of symbols to load\n"));
5894 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5898 /* Similarly find a string table. */
5899 if (dynamic_strings
== NULL
)
5901 for (entry
= dynamic_section
;
5902 entry
< dynamic_section
+ dynamic_nent
;
5905 unsigned long offset
;
5908 if (entry
->d_tag
!= DT_STRTAB
)
5911 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5913 /* Since we do not know how big the string table is,
5914 we default to reading in the entire file (!) and
5915 processing that. This is overkill, I know, but it
5918 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5920 if (archive_file_offset
!= 0)
5921 str_tab_len
= archive_file_size
- offset
;
5924 if (fseek (file
, 0, SEEK_END
))
5925 error (_("Unable to seek to end of file\n"));
5926 str_tab_len
= ftell (file
) - offset
;
5929 if (str_tab_len
< 1)
5932 (_("Unable to determine the length of the dynamic string table\n"));
5936 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5937 _("dynamic string table"));
5938 dynamic_strings_length
= str_tab_len
;
5943 /* And find the syminfo section if available. */
5944 if (dynamic_syminfo
== NULL
)
5946 unsigned long syminsz
= 0;
5948 for (entry
= dynamic_section
;
5949 entry
< dynamic_section
+ dynamic_nent
;
5952 if (entry
->d_tag
== DT_SYMINENT
)
5954 /* Note: these braces are necessary to avoid a syntax
5955 error from the SunOS4 C compiler. */
5956 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5958 else if (entry
->d_tag
== DT_SYMINSZ
)
5959 syminsz
= entry
->d_un
.d_val
;
5960 else if (entry
->d_tag
== DT_SYMINFO
)
5961 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5965 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5967 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5968 Elf_Internal_Syminfo
*syminfo
;
5970 /* There is a syminfo section. Read the data. */
5971 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5972 syminsz
, _("symbol information"));
5976 dynamic_syminfo
= malloc (syminsz
);
5977 if (dynamic_syminfo
== NULL
)
5979 error (_("Out of memory\n"));
5983 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5984 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5985 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5986 ++syminfo
, ++extsym
)
5988 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5989 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5996 if (do_dynamic
&& dynamic_addr
)
5997 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5998 dynamic_addr
, dynamic_nent
);
6000 printf (_(" Tag Type Name/Value\n"));
6002 for (entry
= dynamic_section
;
6003 entry
< dynamic_section
+ dynamic_nent
;
6011 print_vma (entry
->d_tag
, FULL_HEX
);
6012 dtype
= get_dynamic_type (entry
->d_tag
);
6013 printf (" (%s)%*s", dtype
,
6014 ((is_32bit_elf
? 27 : 19)
6015 - (int) strlen (dtype
)),
6019 switch (entry
->d_tag
)
6023 print_dynamic_flags (entry
->d_un
.d_val
);
6033 switch (entry
->d_tag
)
6036 printf (_("Auxiliary library"));
6040 printf (_("Filter library"));
6044 printf (_("Configuration file"));
6048 printf (_("Dependency audit library"));
6052 printf (_("Audit library"));
6056 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6057 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6061 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6070 printf (_("Flags:"));
6072 if (entry
->d_un
.d_val
== 0)
6073 printf (_(" None\n"));
6076 unsigned long int val
= entry
->d_un
.d_val
;
6078 if (val
& DTF_1_PARINIT
)
6080 printf (" PARINIT");
6081 val
^= DTF_1_PARINIT
;
6083 if (val
& DTF_1_CONFEXP
)
6085 printf (" CONFEXP");
6086 val
^= DTF_1_CONFEXP
;
6089 printf (" %lx", val
);
6098 printf (_("Flags:"));
6100 if (entry
->d_un
.d_val
== 0)
6101 printf (_(" None\n"));
6104 unsigned long int val
= entry
->d_un
.d_val
;
6106 if (val
& DF_P1_LAZYLOAD
)
6108 printf (" LAZYLOAD");
6109 val
^= DF_P1_LAZYLOAD
;
6111 if (val
& DF_P1_GROUPPERM
)
6113 printf (" GROUPPERM");
6114 val
^= DF_P1_GROUPPERM
;
6117 printf (" %lx", val
);
6126 printf (_("Flags:"));
6127 if (entry
->d_un
.d_val
== 0)
6128 printf (_(" None\n"));
6131 unsigned long int val
= entry
->d_un
.d_val
;
6138 if (val
& DF_1_GLOBAL
)
6143 if (val
& DF_1_GROUP
)
6148 if (val
& DF_1_NODELETE
)
6150 printf (" NODELETE");
6151 val
^= DF_1_NODELETE
;
6153 if (val
& DF_1_LOADFLTR
)
6155 printf (" LOADFLTR");
6156 val
^= DF_1_LOADFLTR
;
6158 if (val
& DF_1_INITFIRST
)
6160 printf (" INITFIRST");
6161 val
^= DF_1_INITFIRST
;
6163 if (val
& DF_1_NOOPEN
)
6168 if (val
& DF_1_ORIGIN
)
6173 if (val
& DF_1_DIRECT
)
6178 if (val
& DF_1_TRANS
)
6183 if (val
& DF_1_INTERPOSE
)
6185 printf (" INTERPOSE");
6186 val
^= DF_1_INTERPOSE
;
6188 if (val
& DF_1_NODEFLIB
)
6190 printf (" NODEFLIB");
6191 val
^= DF_1_NODEFLIB
;
6193 if (val
& DF_1_NODUMP
)
6198 if (val
& DF_1_CONLFAT
)
6200 printf (" CONLFAT");
6201 val
^= DF_1_CONLFAT
;
6204 printf (" %lx", val
);
6211 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6213 puts (get_dynamic_type (entry
->d_un
.d_val
));
6233 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6239 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6240 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6246 switch (entry
->d_tag
)
6249 printf (_("Shared library: [%s]"), name
);
6251 if (streq (name
, program_interpreter
))
6252 printf (_(" program interpreter"));
6256 printf (_("Library soname: [%s]"), name
);
6260 printf (_("Library rpath: [%s]"), name
);
6264 printf (_("Library runpath: [%s]"), name
);
6268 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6273 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6286 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6290 case DT_INIT_ARRAYSZ
:
6291 case DT_FINI_ARRAYSZ
:
6292 case DT_GNU_CONFLICTSZ
:
6293 case DT_GNU_LIBLISTSZ
:
6296 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6297 printf (" (bytes)\n");
6307 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6320 if (entry
->d_tag
== DT_USED
6321 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6323 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6327 printf (_("Not needed object: [%s]\n"), name
);
6332 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6338 /* The value of this entry is ignored. */
6343 case DT_GNU_PRELINKED
:
6347 time_t time
= entry
->d_un
.d_val
;
6349 tmp
= gmtime (&time
);
6350 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6351 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6352 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6358 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6361 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6367 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6368 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6373 switch (elf_header
.e_machine
)
6376 case EM_MIPS_RS3_LE
:
6377 dynamic_section_mips_val (entry
);
6380 dynamic_section_parisc_val (entry
);
6383 dynamic_section_ia64_val (entry
);
6386 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6398 get_ver_flags (unsigned int flags
)
6400 static char buff
[32];
6407 if (flags
& VER_FLG_BASE
)
6408 strcat (buff
, "BASE ");
6410 if (flags
& VER_FLG_WEAK
)
6412 if (flags
& VER_FLG_BASE
)
6413 strcat (buff
, "| ");
6415 strcat (buff
, "WEAK ");
6418 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6419 strcat (buff
, "| <unknown>");
6424 /* Display the contents of the version sections. */
6426 process_version_sections (FILE *file
)
6428 Elf_Internal_Shdr
*section
;
6435 for (i
= 0, section
= section_headers
;
6436 i
< elf_header
.e_shnum
;
6439 switch (section
->sh_type
)
6441 case SHT_GNU_verdef
:
6443 Elf_External_Verdef
*edefs
;
6450 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6451 SECTION_NAME (section
), section
->sh_info
);
6453 printf (_(" Addr: 0x"));
6454 printf_vma (section
->sh_addr
);
6455 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6456 (unsigned long) section
->sh_offset
, section
->sh_link
,
6457 SECTION_HEADER_INDEX (section
->sh_link
)
6458 < elf_header
.e_shnum
6459 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6462 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6464 _("version definition section"));
6468 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6471 Elf_External_Verdef
*edef
;
6472 Elf_Internal_Verdef ent
;
6473 Elf_External_Verdaux
*eaux
;
6474 Elf_Internal_Verdaux aux
;
6478 vstart
= ((char *) edefs
) + idx
;
6480 edef
= (Elf_External_Verdef
*) vstart
;
6482 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6483 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6484 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6485 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6486 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6487 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6488 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6490 printf (_(" %#06x: Rev: %d Flags: %s"),
6491 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6493 printf (_(" Index: %d Cnt: %d "),
6494 ent
.vd_ndx
, ent
.vd_cnt
);
6496 vstart
+= ent
.vd_aux
;
6498 eaux
= (Elf_External_Verdaux
*) vstart
;
6500 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6501 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6503 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6504 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6506 printf (_("Name index: %ld\n"), aux
.vda_name
);
6508 isum
= idx
+ ent
.vd_aux
;
6510 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6512 isum
+= aux
.vda_next
;
6513 vstart
+= aux
.vda_next
;
6515 eaux
= (Elf_External_Verdaux
*) vstart
;
6517 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6518 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6520 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6521 printf (_(" %#06x: Parent %d: %s\n"),
6522 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6524 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6525 isum
, j
, aux
.vda_name
);
6535 case SHT_GNU_verneed
:
6537 Elf_External_Verneed
*eneed
;
6543 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6544 SECTION_NAME (section
), section
->sh_info
);
6546 printf (_(" Addr: 0x"));
6547 printf_vma (section
->sh_addr
);
6548 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6549 (unsigned long) section
->sh_offset
, section
->sh_link
,
6550 SECTION_HEADER_INDEX (section
->sh_link
)
6551 < elf_header
.e_shnum
6552 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6555 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6557 _("version need section"));
6561 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6563 Elf_External_Verneed
*entry
;
6564 Elf_Internal_Verneed ent
;
6569 vstart
= ((char *) eneed
) + idx
;
6571 entry
= (Elf_External_Verneed
*) vstart
;
6573 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6574 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6575 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6576 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6577 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6579 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6581 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6582 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6584 printf (_(" File: %lx"), ent
.vn_file
);
6586 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6588 vstart
+= ent
.vn_aux
;
6590 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6592 Elf_External_Vernaux
*eaux
;
6593 Elf_Internal_Vernaux aux
;
6595 eaux
= (Elf_External_Vernaux
*) vstart
;
6597 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6598 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6599 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6600 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6601 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6603 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6604 printf (_(" %#06x: Name: %s"),
6605 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6607 printf (_(" %#06x: Name index: %lx"),
6608 isum
, aux
.vna_name
);
6610 printf (_(" Flags: %s Version: %d\n"),
6611 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6613 isum
+= aux
.vna_next
;
6614 vstart
+= aux
.vna_next
;
6624 case SHT_GNU_versym
:
6626 Elf_Internal_Shdr
*link_section
;
6629 unsigned char *edata
;
6630 unsigned short *data
;
6632 Elf_Internal_Sym
*symbols
;
6633 Elf_Internal_Shdr
*string_sec
;
6636 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6639 link_section
= SECTION_HEADER (section
->sh_link
);
6640 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6642 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6643 >= elf_header
.e_shnum
)
6648 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6650 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6652 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6653 string_sec
->sh_size
, _("version string table"));
6657 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6658 SECTION_NAME (section
), total
);
6660 printf (_(" Addr: "));
6661 printf_vma (section
->sh_addr
);
6662 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6663 (unsigned long) section
->sh_offset
, section
->sh_link
,
6664 SECTION_NAME (link_section
));
6666 off
= offset_from_vma (file
,
6667 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6668 total
* sizeof (short));
6669 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6670 _("version symbol data"));
6677 data
= cmalloc (total
, sizeof (short));
6679 for (cnt
= total
; cnt
--;)
6680 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6685 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6688 int check_def
, check_need
;
6691 printf (" %03x:", cnt
);
6693 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6694 switch (data
[cnt
+ j
])
6697 fputs (_(" 0 (*local*) "), stdout
);
6701 fputs (_(" 1 (*global*) "), stdout
);
6705 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6706 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6710 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6711 >= elf_header
.e_shnum
6712 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6715 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6722 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6724 Elf_Internal_Verneed ivn
;
6725 unsigned long offset
;
6727 offset
= offset_from_vma
6728 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6729 sizeof (Elf_External_Verneed
));
6733 Elf_Internal_Vernaux ivna
;
6734 Elf_External_Verneed evn
;
6735 Elf_External_Vernaux evna
;
6736 unsigned long a_off
;
6738 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6741 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6742 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6744 a_off
= offset
+ ivn
.vn_aux
;
6748 get_data (&evna
, file
, a_off
, sizeof (evna
),
6749 1, _("version need aux (2)"));
6751 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6752 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6754 a_off
+= ivna
.vna_next
;
6756 while (ivna
.vna_other
!= data
[cnt
+ j
]
6757 && ivna
.vna_next
!= 0);
6759 if (ivna
.vna_other
== data
[cnt
+ j
])
6761 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6763 name
= strtab
+ ivna
.vna_name
;
6764 nn
+= printf ("(%s%-*s",
6766 12 - (int) strlen (name
),
6772 offset
+= ivn
.vn_next
;
6774 while (ivn
.vn_next
);
6777 if (check_def
&& data
[cnt
+ j
] != 0x8001
6778 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6780 Elf_Internal_Verdef ivd
;
6781 Elf_External_Verdef evd
;
6782 unsigned long offset
;
6784 offset
= offset_from_vma
6785 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6790 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6793 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6794 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6796 offset
+= ivd
.vd_next
;
6798 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6799 && ivd
.vd_next
!= 0);
6801 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6803 Elf_External_Verdaux evda
;
6804 Elf_Internal_Verdaux ivda
;
6806 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6808 get_data (&evda
, file
,
6809 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6811 _("version def aux"));
6813 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6815 name
= strtab
+ ivda
.vda_name
;
6816 nn
+= printf ("(%s%-*s",
6818 12 - (int) strlen (name
),
6824 printf ("%*c", 18 - nn
, ' ');
6842 printf (_("\nNo version information found in this file.\n"));
6848 get_symbol_binding (unsigned int binding
)
6850 static char buff
[32];
6854 case STB_LOCAL
: return "LOCAL";
6855 case STB_GLOBAL
: return "GLOBAL";
6856 case STB_WEAK
: return "WEAK";
6858 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6859 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6861 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6862 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6864 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6870 get_symbol_type (unsigned int type
)
6872 static char buff
[32];
6876 case STT_NOTYPE
: return "NOTYPE";
6877 case STT_OBJECT
: return "OBJECT";
6878 case STT_FUNC
: return "FUNC";
6879 case STT_SECTION
: return "SECTION";
6880 case STT_FILE
: return "FILE";
6881 case STT_COMMON
: return "COMMON";
6882 case STT_TLS
: return "TLS";
6883 case STT_RELC
: return "RELC";
6884 case STT_SRELC
: return "SRELC";
6886 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6888 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6889 return "THUMB_FUNC";
6891 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6894 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6895 return "PARISC_MILLI";
6897 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6899 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6901 if (elf_header
.e_machine
== EM_PARISC
)
6903 if (type
== STT_HP_OPAQUE
)
6905 if (type
== STT_HP_STUB
)
6909 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6912 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6918 get_symbol_visibility (unsigned int visibility
)
6922 case STV_DEFAULT
: return "DEFAULT";
6923 case STV_INTERNAL
: return "INTERNAL";
6924 case STV_HIDDEN
: return "HIDDEN";
6925 case STV_PROTECTED
: return "PROTECTED";
6931 get_mips_symbol_other (unsigned int other
)
6935 case STO_OPTIONAL
: return "OPTIONAL";
6936 case STO_MIPS16
: return "MIPS16";
6937 default: return NULL
;
6942 get_symbol_other (unsigned int other
)
6944 const char * result
= NULL
;
6945 static char buff
[32];
6950 switch (elf_header
.e_machine
)
6953 result
= get_mips_symbol_other (other
);
6961 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
6966 get_symbol_index_type (unsigned int type
)
6968 static char buff
[32];
6972 case SHN_UNDEF
: return "UND";
6973 case SHN_ABS
: return "ABS";
6974 case SHN_COMMON
: return "COM";
6976 if (type
== SHN_IA_64_ANSI_COMMON
6977 && elf_header
.e_machine
== EM_IA_64
6978 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6980 else if (elf_header
.e_machine
== EM_X86_64
6981 && type
== SHN_X86_64_LCOMMON
)
6983 else if (type
== SHN_MIPS_SCOMMON
6984 && elf_header
.e_machine
== EM_MIPS
)
6986 else if (type
== SHN_MIPS_SUNDEFINED
6987 && elf_header
.e_machine
== EM_MIPS
)
6989 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6990 sprintf (buff
, "PRC[0x%04x]", type
);
6991 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6992 sprintf (buff
, "OS [0x%04x]", type
);
6993 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6994 sprintf (buff
, "RSV[0x%04x]", type
);
6996 sprintf (buff
, "%3d", type
);
7004 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
7006 unsigned char *e_data
;
7009 e_data
= cmalloc (number
, ent_size
);
7013 error (_("Out of memory\n"));
7017 if (fread (e_data
, ent_size
, number
, file
) != number
)
7019 error (_("Unable to read in dynamic data\n"));
7023 i_data
= cmalloc (number
, sizeof (*i_data
));
7027 error (_("Out of memory\n"));
7033 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7040 /* Dump the symbol table. */
7042 process_symbol_table (FILE *file
)
7044 Elf_Internal_Shdr
*section
;
7045 bfd_vma nbuckets
= 0;
7046 bfd_vma nchains
= 0;
7047 bfd_vma
*buckets
= NULL
;
7048 bfd_vma
*chains
= NULL
;
7049 bfd_vma ngnubuckets
= 0;
7050 bfd_vma
*gnubuckets
= NULL
;
7051 bfd_vma
*gnuchains
= NULL
;
7053 if (! do_syms
&& !do_histogram
)
7056 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
7059 unsigned char nb
[8];
7060 unsigned char nc
[8];
7061 int hash_ent_size
= 4;
7063 if ((elf_header
.e_machine
== EM_ALPHA
7064 || elf_header
.e_machine
== EM_S390
7065 || elf_header
.e_machine
== EM_S390_OLD
)
7066 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7070 (archive_file_offset
7071 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7072 sizeof nb
+ sizeof nc
)),
7075 error (_("Unable to seek to start of dynamic information\n"));
7079 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7081 error (_("Failed to read in number of buckets\n"));
7085 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7087 error (_("Failed to read in number of chains\n"));
7091 nbuckets
= byte_get (nb
, hash_ent_size
);
7092 nchains
= byte_get (nc
, hash_ent_size
);
7094 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7095 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7097 if (buckets
== NULL
|| chains
== NULL
)
7102 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
7107 printf (_("\nSymbol table for image:\n"));
7109 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7111 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7113 for (hn
= 0; hn
< nbuckets
; hn
++)
7118 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7120 Elf_Internal_Sym
*psym
;
7123 psym
= dynamic_symbols
+ si
;
7125 n
= print_vma (si
, DEC_5
);
7127 fputs (" " + n
, stdout
);
7128 printf (" %3lu: ", hn
);
7129 print_vma (psym
->st_value
, LONG_HEX
);
7131 print_vma (psym
->st_size
, DEC_5
);
7133 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7134 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7135 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7136 /* Check to see if any other bits in the st_other field are set.
7137 Note - displaying this information disrupts the layout of the
7138 table being generated, but for the moment this case is very rare. */
7139 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7140 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7141 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7142 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7143 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7145 printf (" <corrupt: %14ld>", psym
->st_name
);
7150 else if (do_syms
&& !do_using_dynamic
)
7154 for (i
= 0, section
= section_headers
;
7155 i
< elf_header
.e_shnum
;
7159 char *strtab
= NULL
;
7160 unsigned long int strtab_size
= 0;
7161 Elf_Internal_Sym
*symtab
;
7162 Elf_Internal_Sym
*psym
;
7165 if ( section
->sh_type
!= SHT_SYMTAB
7166 && section
->sh_type
!= SHT_DYNSYM
)
7169 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7170 SECTION_NAME (section
),
7171 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7173 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7175 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7177 symtab
= GET_ELF_SYMBOLS (file
, section
);
7181 if (section
->sh_link
== elf_header
.e_shstrndx
)
7183 strtab
= string_table
;
7184 strtab_size
= string_table_length
;
7186 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
7188 Elf_Internal_Shdr
*string_sec
;
7190 string_sec
= SECTION_HEADER (section
->sh_link
);
7192 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
7193 1, string_sec
->sh_size
, _("string table"));
7194 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7197 for (si
= 0, psym
= symtab
;
7198 si
< section
->sh_size
/ section
->sh_entsize
;
7201 printf ("%6d: ", si
);
7202 print_vma (psym
->st_value
, LONG_HEX
);
7204 print_vma (psym
->st_size
, DEC_5
);
7205 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7206 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7207 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7208 /* Check to see if any other bits in the st_other field are set.
7209 Note - displaying this information disrupts the layout of the
7210 table being generated, but for the moment this case is very rare. */
7211 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7212 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7213 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7214 print_symbol (25, psym
->st_name
< strtab_size
7215 ? strtab
+ psym
->st_name
: "<corrupt>");
7217 if (section
->sh_type
== SHT_DYNSYM
&&
7218 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7220 unsigned char data
[2];
7221 unsigned short vers_data
;
7222 unsigned long offset
;
7226 offset
= offset_from_vma
7227 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7228 sizeof data
+ si
* sizeof (vers_data
));
7230 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7231 sizeof (data
), 1, _("version data"));
7233 vers_data
= byte_get (data
, 2);
7235 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
7236 < elf_header
.e_shnum
7237 && SECTION_HEADER (psym
->st_shndx
)->sh_type
7240 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7242 if ((vers_data
& 0x8000) || vers_data
> 1)
7244 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7245 && (is_nobits
|| ! check_def
))
7247 Elf_External_Verneed evn
;
7248 Elf_Internal_Verneed ivn
;
7249 Elf_Internal_Vernaux ivna
;
7251 /* We must test both. */
7252 offset
= offset_from_vma
7253 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7258 unsigned long vna_off
;
7260 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7263 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7264 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7266 vna_off
= offset
+ ivn
.vn_aux
;
7270 Elf_External_Vernaux evna
;
7272 get_data (&evna
, file
, vna_off
,
7274 _("version need aux (3)"));
7276 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7277 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7278 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7280 vna_off
+= ivna
.vna_next
;
7282 while (ivna
.vna_other
!= vers_data
7283 && ivna
.vna_next
!= 0);
7285 if (ivna
.vna_other
== vers_data
)
7288 offset
+= ivn
.vn_next
;
7290 while (ivn
.vn_next
!= 0);
7292 if (ivna
.vna_other
== vers_data
)
7295 ivna
.vna_name
< strtab_size
7296 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7300 else if (! is_nobits
)
7301 error (_("bad dynamic symbol\n"));
7308 if (vers_data
!= 0x8001
7309 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7311 Elf_Internal_Verdef ivd
;
7312 Elf_Internal_Verdaux ivda
;
7313 Elf_External_Verdaux evda
;
7314 unsigned long offset
;
7316 offset
= offset_from_vma
7318 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7319 sizeof (Elf_External_Verdef
));
7323 Elf_External_Verdef evd
;
7325 get_data (&evd
, file
, offset
, sizeof (evd
),
7326 1, _("version def"));
7328 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7329 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7330 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7332 offset
+= ivd
.vd_next
;
7334 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7335 && ivd
.vd_next
!= 0);
7337 offset
-= ivd
.vd_next
;
7338 offset
+= ivd
.vd_aux
;
7340 get_data (&evda
, file
, offset
, sizeof (evda
),
7341 1, _("version def aux"));
7343 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7345 if (psym
->st_name
!= ivda
.vda_name
)
7346 printf ((vers_data
& 0x8000)
7348 ivda
.vda_name
< strtab_size
7349 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7359 if (strtab
!= string_table
)
7365 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7367 if (do_histogram
&& buckets
!= NULL
)
7369 unsigned long *lengths
;
7370 unsigned long *counts
;
7373 unsigned long maxlength
= 0;
7374 unsigned long nzero_counts
= 0;
7375 unsigned long nsyms
= 0;
7377 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7378 (unsigned long) nbuckets
);
7379 printf (_(" Length Number %% of total Coverage\n"));
7381 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7382 if (lengths
== NULL
)
7384 error (_("Out of memory\n"));
7387 for (hn
= 0; hn
< nbuckets
; ++hn
)
7389 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7392 if (maxlength
< ++lengths
[hn
])
7397 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7400 error (_("Out of memory\n"));
7404 for (hn
= 0; hn
< nbuckets
; ++hn
)
7405 ++counts
[lengths
[hn
]];
7410 printf (" 0 %-10lu (%5.1f%%)\n",
7411 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7412 for (i
= 1; i
<= maxlength
; ++i
)
7414 nzero_counts
+= counts
[i
] * i
;
7415 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7416 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7417 (nzero_counts
* 100.0) / nsyms
);
7425 if (buckets
!= NULL
)
7431 if (do_histogram
&& dynamic_info_DT_GNU_HASH
)
7433 unsigned char nb
[16];
7434 bfd_vma i
, maxchain
= 0xffffffff, symidx
, bitmaskwords
;
7435 unsigned long *lengths
;
7436 unsigned long *counts
;
7438 unsigned long maxlength
= 0;
7439 unsigned long nzero_counts
= 0;
7440 unsigned long nsyms
= 0;
7441 bfd_vma buckets_vma
;
7444 (archive_file_offset
7445 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7449 error (_("Unable to seek to start of dynamic information\n"));
7453 if (fread (nb
, 16, 1, file
) != 1)
7455 error (_("Failed to read in number of buckets\n"));
7459 ngnubuckets
= byte_get (nb
, 4);
7460 symidx
= byte_get (nb
+ 4, 4);
7461 bitmaskwords
= byte_get (nb
+ 8, 4);
7462 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7464 buckets_vma
+= bitmaskwords
* 4;
7466 buckets_vma
+= bitmaskwords
* 8;
7469 (archive_file_offset
7470 + offset_from_vma (file
, buckets_vma
, 4)),
7473 error (_("Unable to seek to start of dynamic information\n"));
7477 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7479 if (gnubuckets
== NULL
)
7482 for (i
= 0; i
< ngnubuckets
; i
++)
7483 if (gnubuckets
[i
] != 0)
7485 if (gnubuckets
[i
] < symidx
)
7488 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7489 maxchain
= gnubuckets
[i
];
7492 if (maxchain
== 0xffffffff)
7498 (archive_file_offset
7499 + offset_from_vma (file
, buckets_vma
7500 + 4 * (ngnubuckets
+ maxchain
), 4)),
7503 error (_("Unable to seek to start of dynamic information\n"));
7509 if (fread (nb
, 4, 1, file
) != 1)
7511 error (_("Failed to determine last chain length\n"));
7515 if (maxchain
+ 1 == 0)
7520 while ((byte_get (nb
, 4) & 1) == 0);
7523 (archive_file_offset
7524 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7527 error (_("Unable to seek to start of dynamic information\n"));
7531 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7533 if (gnuchains
== NULL
)
7536 lengths
= calloc (ngnubuckets
, sizeof (*lengths
));
7537 if (lengths
== NULL
)
7539 error (_("Out of memory\n"));
7543 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7544 (unsigned long) ngnubuckets
);
7545 printf (_(" Length Number %% of total Coverage\n"));
7547 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7548 if (gnubuckets
[hn
] != 0)
7550 bfd_vma off
, length
= 1;
7552 for (off
= gnubuckets
[hn
] - symidx
;
7553 (gnuchains
[off
] & 1) == 0; ++off
)
7555 lengths
[hn
] = length
;
7556 if (length
> maxlength
)
7561 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7564 error (_("Out of memory\n"));
7568 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7569 ++counts
[lengths
[hn
]];
7571 if (ngnubuckets
> 0)
7574 printf (" 0 %-10lu (%5.1f%%)\n",
7575 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7576 for (j
= 1; j
<= maxlength
; ++j
)
7578 nzero_counts
+= counts
[j
] * j
;
7579 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7580 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7581 (nzero_counts
* 100.0) / nsyms
);
7595 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7599 if (dynamic_syminfo
== NULL
7601 /* No syminfo, this is ok. */
7604 /* There better should be a dynamic symbol section. */
7605 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7609 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7610 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7612 printf (_(" Num: Name BoundTo Flags\n"));
7613 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7615 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7617 printf ("%4d: ", i
);
7618 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7619 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7621 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7624 switch (dynamic_syminfo
[i
].si_boundto
)
7626 case SYMINFO_BT_SELF
:
7627 fputs ("SELF ", stdout
);
7629 case SYMINFO_BT_PARENT
:
7630 fputs ("PARENT ", stdout
);
7633 if (dynamic_syminfo
[i
].si_boundto
> 0
7634 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7635 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7637 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7641 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7645 if (flags
& SYMINFO_FLG_DIRECT
)
7647 if (flags
& SYMINFO_FLG_PASSTHRU
)
7648 printf (" PASSTHRU");
7649 if (flags
& SYMINFO_FLG_COPY
)
7651 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7652 printf (" LAZYLOAD");
7660 #ifdef SUPPORT_DISASSEMBLY
7662 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7664 printf (_("\nAssembly dump of section %s\n"),
7665 SECTION_NAME (section
));
7667 /* XXX -- to be done --- XXX */
7674 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
7676 Elf_Internal_Shdr
*relsec
;
7677 bfd_size_type bytes
;
7679 unsigned char *data
;
7680 unsigned char *start
;
7682 bytes
= section
->sh_size
;
7684 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7686 printf (_("\nSection '%s' has no data to dump.\n"),
7687 SECTION_NAME (section
));
7691 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7693 addr
= section
->sh_addr
;
7695 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7700 /* If the section being dumped has relocations against it the user might
7701 be expecting these relocations to have been applied. Check for this
7702 case and issue a warning message in order to avoid confusion.
7703 FIXME: Maybe we ought to have an option that dumps a section with
7705 for (relsec
= section_headers
;
7706 relsec
< section_headers
+ elf_header
.e_shnum
;
7709 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
7710 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7711 || SECTION_HEADER (relsec
->sh_info
) != section
7712 || relsec
->sh_size
== 0
7713 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7716 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
7728 lbytes
= (bytes
> 16 ? 16 : bytes
);
7730 printf (" 0x%8.8lx ", (unsigned long) addr
);
7732 for (j
= 0; j
< 16; j
++)
7735 printf ("%2.2x", data
[j
]);
7743 for (j
= 0; j
< lbytes
; j
++)
7746 if (k
>= ' ' && k
< 0x7f)
7765 /* Return the number of bytes affected by a given reloc.
7766 This information is architecture and reloc dependent.
7767 Returns 4 by default, although this is not always correct.
7768 It should return 0 if a decision cannot be made.
7769 FIXME: This is not the correct way to solve this problem.
7770 The proper way is to have target specific reloc sizing functions
7771 created by the reloc-macros.h header, in the same way that it
7772 already creates the reloc naming functions. */
7775 get_reloc_size (Elf_Internal_Rela
* reloc
)
7777 switch (elf_header
.e_machine
)
7783 switch (ELF32_R_TYPE (reloc
->r_info
))
7785 /* PR gas/3800 - without this information we do not correctly
7786 decode the debug information generated by the h8300 assembler. */
7793 /* FIXME: We need to extend this switch statement to cope with other
7794 architecture's relocs. (When those relocs are used against debug
7795 sections, and when their size is not 4). But see the multiple
7796 inclusions of <elf/h8.h> for an example of the hoops that we need
7797 to jump through in order to obtain the reloc numbers. */
7802 /* Apply addends of RELA relocations. */
7805 debug_apply_rela_addends (void *file
,
7806 Elf_Internal_Shdr
*section
,
7807 unsigned char *start
)
7809 Elf_Internal_Shdr
*relsec
;
7810 unsigned char *end
= start
+ section
->sh_size
;
7812 if (!is_relocatable
)
7815 /* SH uses RELA but uses in place value instead of the addend field. */
7816 if (elf_header
.e_machine
== EM_SH
)
7819 for (relsec
= section_headers
;
7820 relsec
< section_headers
+ elf_header
.e_shnum
;
7823 unsigned long nrelas
;
7824 Elf_Internal_Rela
*rela
, *rp
;
7825 Elf_Internal_Shdr
*symsec
;
7826 Elf_Internal_Sym
*symtab
;
7827 Elf_Internal_Sym
*sym
;
7829 if (relsec
->sh_type
!= SHT_RELA
7830 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7831 || SECTION_HEADER (relsec
->sh_info
) != section
7832 || relsec
->sh_size
== 0
7833 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7836 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7840 symsec
= SECTION_HEADER (relsec
->sh_link
);
7841 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7843 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7846 unsigned int reloc_size
;
7848 reloc_size
= get_reloc_size (rp
);
7849 if (reloc_size
== 0)
7851 warn (_("skipping relocation of unknown size against offset 0x%lx in section %s\n"),
7852 (unsigned long) rp
->r_offset
,
7853 SECTION_NAME (section
));
7857 loc
= start
+ rp
->r_offset
;
7858 if ((loc
+ reloc_size
) > end
)
7860 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7861 (unsigned long) rp
->r_offset
,
7862 SECTION_NAME (section
));
7868 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7870 if (ELF32_R_SYM (rp
->r_info
) != 0
7871 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7872 /* Relocations against symbols without type can happen.
7873 Gcc -feliminate-dwarf2-dups may generate symbols
7874 without type for debug info. */
7875 && ELF32_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7876 /* Relocations against object symbols can happen,
7877 eg when referencing a global array. For an
7878 example of this see the _clz.o binary in libgcc.a. */
7879 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7881 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7882 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7883 SECTION_NAME (section
));
7889 /* In MIPS little-endian objects, r_info isn't really a
7890 64-bit little-endian value: it has a 32-bit little-endian
7891 symbol index followed by four individual byte fields.
7892 Reorder INFO accordingly. */
7893 if (elf_header
.e_machine
== EM_MIPS
7894 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7895 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7896 | ((rp
->r_info
>> 56) & 0xff)
7897 | ((rp
->r_info
>> 40) & 0xff00)
7898 | ((rp
->r_info
>> 24) & 0xff0000)
7899 | ((rp
->r_info
>> 8) & 0xff000000));
7901 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7903 if (ELF64_R_SYM (rp
->r_info
) != 0
7904 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7905 && ELF64_ST_TYPE (sym
->st_info
) != STT_NOTYPE
7906 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7908 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7909 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7910 SECTION_NAME (section
));
7915 byte_put (loc
, rp
->r_addend
, reloc_size
);
7926 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
7928 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7929 Elf_Internal_Shdr
*sec
;
7932 /* If it is already loaded, do nothing. */
7933 if (section
->start
!= NULL
)
7936 /* Locate the debug section. */
7937 sec
= find_section (section
->name
);
7941 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
7942 section
->address
= sec
->sh_addr
;
7943 section
->size
= sec
->sh_size
;
7944 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
7947 if (debug_displays
[debug
].relocate
)
7948 debug_apply_rela_addends (file
, sec
, section
->start
);
7950 return section
->start
!= NULL
;
7954 free_debug_section (enum dwarf_section_display_enum debug
)
7956 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7958 if (section
->start
== NULL
)
7961 free ((char *) section
->start
);
7962 section
->start
= NULL
;
7963 section
->address
= 0;
7968 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
7970 char *name
= SECTION_NAME (section
);
7971 bfd_size_type length
;
7973 enum dwarf_section_display_enum i
;
7975 length
= section
->sh_size
;
7978 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7982 if (const_strneq (name
, ".gnu.linkonce.wi."))
7983 name
= ".debug_info";
7985 /* See if we know how to display the contents of this section. */
7986 for (i
= 0; i
< max
; i
++)
7987 if (streq (debug_displays
[i
].section
.name
, name
))
7989 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
7991 if (load_debug_section (i
, file
))
7993 result
&= debug_displays
[i
].display (sec
, file
);
7995 if (i
!= info
&& i
!= abbrev
)
7996 free_debug_section (i
);
8004 printf (_("Unrecognized debug section: %s\n"), name
);
8011 /* Set DUMP_SECTS for all sections where dumps were requested
8012 based on section name. */
8015 initialise_dumps_byname (void)
8017 struct dump_list_entry
*cur
;
8019 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
8024 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
8025 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
8027 request_dump (i
, cur
->type
);
8032 warn (_("Section '%s' was not dumped because it does not exist!\n"),
8038 process_section_contents (FILE *file
)
8040 Elf_Internal_Shdr
*section
;
8046 initialise_dumps_byname ();
8048 for (i
= 0, section
= section_headers
;
8049 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8052 #ifdef SUPPORT_DISASSEMBLY
8053 if (dump_sects
[i
] & DISASS_DUMP
)
8054 disassemble_section (section
, file
);
8056 if (dump_sects
[i
] & HEX_DUMP
)
8057 dump_section (section
, file
);
8059 if (dump_sects
[i
] & DEBUG_DUMP
)
8060 display_debug_section (section
, file
);
8063 /* Check to see if the user requested a
8064 dump of a section that does not exist. */
8065 while (i
++ < num_dump_sects
)
8067 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
8071 process_mips_fpe_exception (int mask
)
8076 if (mask
& OEX_FPU_INEX
)
8077 fputs ("INEX", stdout
), first
= 0;
8078 if (mask
& OEX_FPU_UFLO
)
8079 printf ("%sUFLO", first
? "" : "|"), first
= 0;
8080 if (mask
& OEX_FPU_OFLO
)
8081 printf ("%sOFLO", first
? "" : "|"), first
= 0;
8082 if (mask
& OEX_FPU_DIV0
)
8083 printf ("%sDIV0", first
? "" : "|"), first
= 0;
8084 if (mask
& OEX_FPU_INVAL
)
8085 printf ("%sINVAL", first
? "" : "|");
8088 fputs ("0", stdout
);
8091 /* ARM EABI attributes section. */
8096 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8099 } arm_attr_public_tag
;
8101 static const char *arm_attr_tag_CPU_arch
[] =
8102 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8104 static const char *arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8105 static const char *arm_attr_tag_THUMB_ISA_use
[] =
8106 {"No", "Thumb-1", "Thumb-2"};
8107 /* FIXME: VFPv3 encoding was extrapolated! */
8108 static const char *arm_attr_tag_VFP_arch
[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
8109 static const char *arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1"};
8110 static const char *arm_attr_tag_NEON_arch
[] = {"No", "NEONv1"};
8111 static const char *arm_attr_tag_ABI_PCS_config
[] =
8112 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8113 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8114 static const char *arm_attr_tag_ABI_PCS_R9_use
[] =
8115 {"V6", "SB", "TLS", "Unused"};
8116 static const char *arm_attr_tag_ABI_PCS_RW_data
[] =
8117 {"Absolute", "PC-relative", "SB-relative", "None"};
8118 static const char *arm_attr_tag_ABI_PCS_RO_DATA
[] =
8119 {"Absolute", "PC-relative", "None"};
8120 static const char *arm_attr_tag_ABI_PCS_GOT_use
[] =
8121 {"None", "direct", "GOT-indirect"};
8122 static const char *arm_attr_tag_ABI_PCS_wchar_t
[] =
8123 {"None", "??? 1", "2", "??? 3", "4"};
8124 static const char *arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8125 static const char *arm_attr_tag_ABI_FP_denormal
[] = {"Unused", "Needed"};
8126 static const char *arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8127 static const char *arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8128 static const char *arm_attr_tag_ABI_FP_number_model
[] =
8129 {"Unused", "Finite", "RTABI", "IEEE 754"};
8130 static const char *arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8131 static const char *arm_attr_tag_ABI_align8_preserved
[] =
8132 {"No", "Yes, except leaf SP", "Yes"};
8133 static const char *arm_attr_tag_ABI_enum_size
[] =
8134 {"Unused", "small", "int", "forced to int"};
8135 static const char *arm_attr_tag_ABI_HardFP_use
[] =
8136 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8137 static const char *arm_attr_tag_ABI_VFP_args
[] =
8138 {"AAPCS", "VFP registers", "custom"};
8139 static const char *arm_attr_tag_ABI_WMMX_args
[] =
8140 {"AAPCS", "WMMX registers", "custom"};
8141 static const char *arm_attr_tag_ABI_optimization_goals
[] =
8142 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8143 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8144 static const char *arm_attr_tag_ABI_FP_optimization_goals
[] =
8145 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8146 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8148 #define LOOKUP(id, name) \
8149 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8150 static arm_attr_public_tag arm_attr_public_tags
[] =
8152 {4, "CPU_raw_name", 1, NULL
},
8153 {5, "CPU_name", 1, NULL
},
8154 LOOKUP(6, CPU_arch
),
8155 {7, "CPU_arch_profile", 0, NULL
},
8156 LOOKUP(8, ARM_ISA_use
),
8157 LOOKUP(9, THUMB_ISA_use
),
8158 LOOKUP(10, VFP_arch
),
8159 LOOKUP(11, WMMX_arch
),
8160 LOOKUP(12, NEON_arch
),
8161 LOOKUP(13, ABI_PCS_config
),
8162 LOOKUP(14, ABI_PCS_R9_use
),
8163 LOOKUP(15, ABI_PCS_RW_data
),
8164 LOOKUP(16, ABI_PCS_RO_DATA
),
8165 LOOKUP(17, ABI_PCS_GOT_use
),
8166 LOOKUP(18, ABI_PCS_wchar_t
),
8167 LOOKUP(19, ABI_FP_rounding
),
8168 LOOKUP(20, ABI_FP_denormal
),
8169 LOOKUP(21, ABI_FP_exceptions
),
8170 LOOKUP(22, ABI_FP_user_exceptions
),
8171 LOOKUP(23, ABI_FP_number_model
),
8172 LOOKUP(24, ABI_align8_needed
),
8173 LOOKUP(25, ABI_align8_preserved
),
8174 LOOKUP(26, ABI_enum_size
),
8175 LOOKUP(27, ABI_HardFP_use
),
8176 LOOKUP(28, ABI_VFP_args
),
8177 LOOKUP(29, ABI_WMMX_args
),
8178 LOOKUP(30, ABI_optimization_goals
),
8179 LOOKUP(31, ABI_FP_optimization_goals
),
8180 {32, "compatibility", 0, NULL
}
8184 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8187 read_uleb128 (unsigned char *p
, unsigned int *plen
)
8201 val
|= ((unsigned int)c
& 0x7f) << shift
;
8210 static unsigned char *
8211 display_arm_attribute (unsigned char *p
)
8216 arm_attr_public_tag
*attr
;
8220 tag
= read_uleb128 (p
, &len
);
8223 for (i
= 0; i
< ARRAY_SIZE(arm_attr_public_tags
); i
++)
8225 if (arm_attr_public_tags
[i
].tag
== tag
)
8227 attr
= &arm_attr_public_tags
[i
];
8234 printf (" Tag_%s: ", attr
->name
);
8240 case 7: /* Tag_CPU_arch_profile. */
8241 val
= read_uleb128 (p
, &len
);
8245 case 0: printf ("None\n"); break;
8246 case 'A': printf ("Application\n"); break;
8247 case 'R': printf ("Realtime\n"); break;
8248 case 'M': printf ("Microcontroller\n"); break;
8249 default: printf ("??? (%d)\n", val
); break;
8253 case 32: /* Tag_compatibility. */
8254 val
= read_uleb128 (p
, &len
);
8256 printf ("flag = %d, vendor = %s\n", val
, p
);
8257 p
+= strlen((char *)p
) + 1;
8271 assert (attr
->type
& 0x80);
8272 val
= read_uleb128 (p
, &len
);
8274 type
= attr
->type
& 0x7f;
8276 printf ("??? (%d)\n", val
);
8278 printf ("%s\n", attr
->table
[val
]);
8285 type
= 1; /* String. */
8287 type
= 2; /* uleb128. */
8288 printf (" Tag_unknown_%d: ", tag
);
8293 printf ("\"%s\"\n", p
);
8294 p
+= strlen((char *)p
) + 1;
8298 val
= read_uleb128 (p
, &len
);
8300 printf ("%d (0x%x)\n", val
, val
);
8306 static unsigned char *
8307 display_gnu_attribute (unsigned char * p
,
8308 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8315 tag
= read_uleb128 (p
, &len
);
8318 /* Tag_compatibility is the only generic GNU attribute defined at
8322 val
= read_uleb128 (p
, &len
);
8324 printf ("flag = %d, vendor = %s\n", val
, p
);
8325 p
+= strlen ((char *) p
) + 1;
8329 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
8330 return display_proc_gnu_attribute (p
, tag
);
8333 type
= 1; /* String. */
8335 type
= 2; /* uleb128. */
8336 printf (" Tag_unknown_%d: ", tag
);
8340 printf ("\"%s\"\n", p
);
8341 p
+= strlen ((char *) p
) + 1;
8345 val
= read_uleb128 (p
, &len
);
8347 printf ("%d (0x%x)\n", val
, val
);
8353 static unsigned char *
8354 display_power_gnu_attribute (unsigned char *p
, int tag
)
8360 if (tag
== Tag_GNU_Power_ABI_FP
)
8362 val
= read_uleb128 (p
, &len
);
8364 printf (" Tag_GNU_Power_ABI_FP: ");
8369 printf ("Hard or soft float\n");
8372 printf ("Hard float\n");
8375 printf ("Soft float\n");
8378 printf ("??? (%d)\n", val
);
8385 type
= 1; /* String. */
8387 type
= 2; /* uleb128. */
8388 printf (" Tag_unknown_%d: ", tag
);
8392 printf ("\"%s\"\n", p
);
8393 p
+= strlen ((char *) p
) + 1;
8397 val
= read_uleb128 (p
, &len
);
8399 printf ("%d (0x%x)\n", val
, val
);
8405 static unsigned char *
8406 display_mips_gnu_attribute (unsigned char *p
, int tag
)
8412 if (tag
== Tag_GNU_MIPS_ABI_FP
)
8414 val
= read_uleb128 (p
, &len
);
8416 printf (" Tag_GNU_MIPS_ABI_FP: ");
8421 printf ("Hard or soft float\n");
8424 printf ("Hard float (-mdouble-float)\n");
8427 printf ("Hard float (-msingle-float)\n");
8430 printf ("Soft float\n");
8433 printf ("??? (%d)\n", val
);
8440 type
= 1; /* String. */
8442 type
= 2; /* uleb128. */
8443 printf (" Tag_unknown_%d: ", tag
);
8447 printf ("\"%s\"\n", p
);
8448 p
+= strlen ((char *) p
) + 1;
8452 val
= read_uleb128 (p
, &len
);
8454 printf ("%d (0x%x)\n", val
, val
);
8461 process_attributes (FILE * file
,
8462 const char * public_name
,
8463 unsigned int proc_type
,
8464 unsigned char * (* display_pub_attribute
) (unsigned char *),
8465 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
8467 Elf_Internal_Shdr
*sect
;
8468 unsigned char *contents
;
8471 bfd_vma section_len
;
8475 /* Find the section header so that we get the size. */
8476 for (i
= 0, sect
= section_headers
;
8477 i
< elf_header
.e_shnum
;
8480 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
8483 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
8485 if (contents
== NULL
)
8491 len
= sect
->sh_size
- 1;
8497 bfd_boolean public_section
;
8498 bfd_boolean gnu_section
;
8500 section_len
= byte_get (p
, 4);
8503 if (section_len
> len
)
8505 printf (_("ERROR: Bad section length (%d > %d)\n"),
8506 (int) section_len
, (int) len
);
8511 printf ("Attribute Section: %s\n", p
);
8513 if (public_name
&& streq ((char *) p
, public_name
))
8514 public_section
= TRUE
;
8516 public_section
= FALSE
;
8518 if (streq ((char *) p
, "gnu"))
8521 gnu_section
= FALSE
;
8523 namelen
= strlen ((char *) p
) + 1;
8525 section_len
-= namelen
+ 4;
8527 while (section_len
> 0)
8533 size
= byte_get (p
, 4);
8534 if (size
> section_len
)
8536 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
8537 (int) size
, (int) section_len
);
8541 section_len
-= size
;
8548 printf ("File Attributes\n");
8551 printf ("Section Attributes:");
8554 printf ("Symbol Attributes:");
8560 val
= read_uleb128 (p
, &i
);
8564 printf (" %d", val
);
8569 printf ("Unknown tag: %d\n", tag
);
8570 public_section
= FALSE
;
8577 p
= display_pub_attribute (p
);
8579 else if (gnu_section
)
8582 p
= display_gnu_attribute (p
,
8583 display_proc_gnu_attribute
);
8587 /* ??? Do something sensible, like dump hex. */
8588 printf (" Unknown section contexts\n");
8595 printf (_("Unknown format '%c'\n"), *p
);
8603 process_arm_specific (FILE *file
)
8605 return process_attributes (file
, "aeabi", SHT_ARM_ATTRIBUTES
,
8606 display_arm_attribute
, NULL
);
8610 process_power_specific (FILE *file
)
8612 return process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
8613 display_power_gnu_attribute
);
8617 process_mips_specific (FILE *file
)
8619 Elf_Internal_Dyn
*entry
;
8620 size_t liblist_offset
= 0;
8621 size_t liblistno
= 0;
8622 size_t conflictsno
= 0;
8623 size_t options_offset
= 0;
8624 size_t conflicts_offset
= 0;
8626 process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
8627 display_mips_gnu_attribute
);
8629 /* We have a lot of special sections. Thanks SGI! */
8630 if (dynamic_section
== NULL
)
8631 /* No information available. */
8634 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
8635 switch (entry
->d_tag
)
8637 case DT_MIPS_LIBLIST
:
8639 = offset_from_vma (file
, entry
->d_un
.d_val
,
8640 liblistno
* sizeof (Elf32_External_Lib
));
8642 case DT_MIPS_LIBLISTNO
:
8643 liblistno
= entry
->d_un
.d_val
;
8645 case DT_MIPS_OPTIONS
:
8646 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
8648 case DT_MIPS_CONFLICT
:
8650 = offset_from_vma (file
, entry
->d_un
.d_val
,
8651 conflictsno
* sizeof (Elf32_External_Conflict
));
8653 case DT_MIPS_CONFLICTNO
:
8654 conflictsno
= entry
->d_un
.d_val
;
8660 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
8662 Elf32_External_Lib
*elib
;
8665 elib
= get_data (NULL
, file
, liblist_offset
,
8666 liblistno
, sizeof (Elf32_External_Lib
),
8670 printf ("\nSection '.liblist' contains %lu entries:\n",
8671 (unsigned long) liblistno
);
8672 fputs (" Library Time Stamp Checksum Version Flags\n",
8675 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
8682 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
8683 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8684 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8685 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8686 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8688 tmp
= gmtime (&time
);
8689 snprintf (timebuf
, sizeof (timebuf
),
8690 "%04u-%02u-%02uT%02u:%02u:%02u",
8691 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8692 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8694 printf ("%3lu: ", (unsigned long) cnt
);
8695 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
8696 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
8698 printf ("<corrupt: %9ld>", liblist
.l_name
);
8699 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
8702 if (liblist
.l_flags
== 0)
8713 { " EXACT_MATCH", LL_EXACT_MATCH
},
8714 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
8715 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
8716 { " EXPORTS", LL_EXPORTS
},
8717 { " DELAY_LOAD", LL_DELAY_LOAD
},
8718 { " DELTA", LL_DELTA
}
8720 int flags
= liblist
.l_flags
;
8723 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
8724 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
8726 fputs (l_flags_vals
[fcnt
].name
, stdout
);
8727 flags
^= l_flags_vals
[fcnt
].bit
;
8730 printf (" %#x", (unsigned int) flags
);
8740 if (options_offset
!= 0)
8742 Elf_External_Options
*eopt
;
8743 Elf_Internal_Shdr
*sect
= section_headers
;
8744 Elf_Internal_Options
*iopt
;
8745 Elf_Internal_Options
*option
;
8749 /* Find the section header so that we get the size. */
8750 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
8753 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
8757 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
8760 error (_("Out of memory\n"));
8767 while (offset
< sect
->sh_size
)
8769 Elf_External_Options
*eoption
;
8771 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
8773 option
->kind
= BYTE_GET (eoption
->kind
);
8774 option
->size
= BYTE_GET (eoption
->size
);
8775 option
->section
= BYTE_GET (eoption
->section
);
8776 option
->info
= BYTE_GET (eoption
->info
);
8778 offset
+= option
->size
;
8784 printf (_("\nSection '%s' contains %d entries:\n"),
8785 SECTION_NAME (sect
), cnt
);
8793 switch (option
->kind
)
8796 /* This shouldn't happen. */
8797 printf (" NULL %d %lx", option
->section
, option
->info
);
8800 printf (" REGINFO ");
8801 if (elf_header
.e_machine
== EM_MIPS
)
8804 Elf32_External_RegInfo
*ereg
;
8805 Elf32_RegInfo reginfo
;
8807 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
8808 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8809 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8810 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8811 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8812 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8813 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8815 printf ("GPR %08lx GP 0x%lx\n",
8817 (unsigned long) reginfo
.ri_gp_value
);
8818 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8819 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8820 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8825 Elf64_External_RegInfo
*ereg
;
8826 Elf64_Internal_RegInfo reginfo
;
8828 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
8829 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
8830 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
8831 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
8832 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
8833 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
8834 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
8836 printf ("GPR %08lx GP 0x",
8837 reginfo
.ri_gprmask
);
8838 printf_vma (reginfo
.ri_gp_value
);
8841 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8842 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
8843 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
8847 case ODK_EXCEPTIONS
:
8848 fputs (" EXCEPTIONS fpe_min(", stdout
);
8849 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
8850 fputs (") fpe_max(", stdout
);
8851 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
8852 fputs (")", stdout
);
8854 if (option
->info
& OEX_PAGE0
)
8855 fputs (" PAGE0", stdout
);
8856 if (option
->info
& OEX_SMM
)
8857 fputs (" SMM", stdout
);
8858 if (option
->info
& OEX_FPDBUG
)
8859 fputs (" FPDBUG", stdout
);
8860 if (option
->info
& OEX_DISMISS
)
8861 fputs (" DISMISS", stdout
);
8864 fputs (" PAD ", stdout
);
8865 if (option
->info
& OPAD_PREFIX
)
8866 fputs (" PREFIX", stdout
);
8867 if (option
->info
& OPAD_POSTFIX
)
8868 fputs (" POSTFIX", stdout
);
8869 if (option
->info
& OPAD_SYMBOL
)
8870 fputs (" SYMBOL", stdout
);
8873 fputs (" HWPATCH ", stdout
);
8874 if (option
->info
& OHW_R4KEOP
)
8875 fputs (" R4KEOP", stdout
);
8876 if (option
->info
& OHW_R8KPFETCH
)
8877 fputs (" R8KPFETCH", stdout
);
8878 if (option
->info
& OHW_R5KEOP
)
8879 fputs (" R5KEOP", stdout
);
8880 if (option
->info
& OHW_R5KCVTL
)
8881 fputs (" R5KCVTL", stdout
);
8884 fputs (" FILL ", stdout
);
8885 /* XXX Print content of info word? */
8888 fputs (" TAGS ", stdout
);
8889 /* XXX Print content of info word? */
8892 fputs (" HWAND ", stdout
);
8893 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8894 fputs (" R4KEOP_CHECKED", stdout
);
8895 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8896 fputs (" R4KEOP_CLEAN", stdout
);
8899 fputs (" HWOR ", stdout
);
8900 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
8901 fputs (" R4KEOP_CHECKED", stdout
);
8902 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
8903 fputs (" R4KEOP_CLEAN", stdout
);
8906 printf (" GP_GROUP %#06lx self-contained %#06lx",
8907 option
->info
& OGP_GROUP
,
8908 (option
->info
& OGP_SELF
) >> 16);
8911 printf (" IDENT %#06lx self-contained %#06lx",
8912 option
->info
& OGP_GROUP
,
8913 (option
->info
& OGP_SELF
) >> 16);
8916 /* This shouldn't happen. */
8917 printf (" %3d ??? %d %lx",
8918 option
->kind
, option
->section
, option
->info
);
8922 len
= sizeof (*eopt
);
8923 while (len
< option
->size
)
8924 if (((char *) option
)[len
] >= ' '
8925 && ((char *) option
)[len
] < 0x7f)
8926 printf ("%c", ((char *) option
)[len
++]);
8928 printf ("\\%03o", ((char *) option
)[len
++]);
8930 fputs ("\n", stdout
);
8938 if (conflicts_offset
!= 0 && conflictsno
!= 0)
8940 Elf32_Conflict
*iconf
;
8943 if (dynamic_symbols
== NULL
)
8945 error (_("conflict list found without a dynamic symbol table\n"));
8949 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
8952 error (_("Out of memory\n"));
8958 Elf32_External_Conflict
*econf32
;
8960 econf32
= get_data (NULL
, file
, conflicts_offset
,
8961 conflictsno
, sizeof (*econf32
), _("conflict"));
8965 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8966 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
8972 Elf64_External_Conflict
*econf64
;
8974 econf64
= get_data (NULL
, file
, conflicts_offset
,
8975 conflictsno
, sizeof (*econf64
), _("conflict"));
8979 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8980 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
8985 printf (_("\nSection '.conflict' contains %lu entries:\n"),
8986 (unsigned long) conflictsno
);
8987 puts (_(" Num: Index Value Name"));
8989 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
8991 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
8993 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
8994 print_vma (psym
->st_value
, FULL_HEX
);
8996 if (VALID_DYNAMIC_NAME (psym
->st_name
))
8997 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
8999 printf ("<corrupt: %14ld>", psym
->st_name
);
9010 process_gnu_liblist (FILE *file
)
9012 Elf_Internal_Shdr
*section
, *string_sec
;
9013 Elf32_External_Lib
*elib
;
9022 for (i
= 0, section
= section_headers
;
9023 i
< elf_header
.e_shnum
;
9026 switch (section
->sh_type
)
9028 case SHT_GNU_LIBLIST
:
9029 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
9032 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
9037 string_sec
= SECTION_HEADER (section
->sh_link
);
9039 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
9040 string_sec
->sh_size
, _("liblist string table"));
9041 strtab_size
= string_sec
->sh_size
;
9044 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
9050 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
9051 SECTION_NAME (section
),
9052 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
9054 puts (" Library Time Stamp Checksum Version Flags");
9056 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
9064 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9065 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9066 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9067 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9068 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9070 tmp
= gmtime (&time
);
9071 snprintf (timebuf
, sizeof (timebuf
),
9072 "%04u-%02u-%02uT%02u:%02u:%02u",
9073 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9074 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9076 printf ("%3lu: ", (unsigned long) cnt
);
9078 printf ("%-20s", liblist
.l_name
< strtab_size
9079 ? strtab
+ liblist
.l_name
: "<corrupt>");
9081 printf ("%-20.20s", liblist
.l_name
< strtab_size
9082 ? strtab
+ liblist
.l_name
: "<corrupt>");
9083 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
9084 liblist
.l_version
, liblist
.l_flags
);
9095 get_note_type (unsigned e_type
)
9097 static char buff
[64];
9099 if (elf_header
.e_type
== ET_CORE
)
9103 return _("NT_AUXV (auxiliary vector)");
9105 return _("NT_PRSTATUS (prstatus structure)");
9107 return _("NT_FPREGSET (floating point registers)");
9109 return _("NT_PRPSINFO (prpsinfo structure)");
9111 return _("NT_TASKSTRUCT (task structure)");
9113 return _("NT_PRXFPREG (user_xfpregs structure)");
9115 return _("NT_PSTATUS (pstatus structure)");
9117 return _("NT_FPREGS (floating point registers)");
9119 return _("NT_PSINFO (psinfo structure)");
9121 return _("NT_LWPSTATUS (lwpstatus_t structure)");
9123 return _("NT_LWPSINFO (lwpsinfo_t structure)");
9124 case NT_WIN32PSTATUS
:
9125 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9133 return _("NT_VERSION (version)");
9135 return _("NT_ARCH (architecture)");
9140 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9145 get_gnu_elf_note_type (unsigned e_type
)
9147 static char buff
[64];
9151 case NT_GNU_ABI_TAG
:
9152 return _("NT_GNU_ABI_TAG (ABI version tag)");
9154 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
9155 case NT_GNU_BUILD_ID
:
9156 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
9161 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9166 get_netbsd_elfcore_note_type (unsigned e_type
)
9168 static char buff
[64];
9170 if (e_type
== NT_NETBSDCORE_PROCINFO
)
9172 /* NetBSD core "procinfo" structure. */
9173 return _("NetBSD procinfo structure");
9176 /* As of Jan 2002 there are no other machine-independent notes
9177 defined for NetBSD core files. If the note type is less
9178 than the start of the machine-dependent note types, we don't
9181 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
9183 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
9187 switch (elf_header
.e_machine
)
9189 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9190 and PT_GETFPREGS == mach+2. */
9195 case EM_SPARC32PLUS
:
9199 case NT_NETBSDCORE_FIRSTMACH
+0:
9200 return _("PT_GETREGS (reg structure)");
9201 case NT_NETBSDCORE_FIRSTMACH
+2:
9202 return _("PT_GETFPREGS (fpreg structure)");
9208 /* On all other arch's, PT_GETREGS == mach+1 and
9209 PT_GETFPREGS == mach+3. */
9213 case NT_NETBSDCORE_FIRSTMACH
+1:
9214 return _("PT_GETREGS (reg structure)");
9215 case NT_NETBSDCORE_FIRSTMACH
+3:
9216 return _("PT_GETFPREGS (fpreg structure)");
9222 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
9223 e_type
- NT_NETBSDCORE_FIRSTMACH
);
9227 /* Note that by the ELF standard, the name field is already null byte
9228 terminated, and namesz includes the terminating null byte.
9229 I.E. the value of namesz for the name "FSF" is 4.
9231 If the value of namesz is zero, there is no name present. */
9233 process_note (Elf_Internal_Note
*pnote
)
9235 const char *name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
9238 if (pnote
->namesz
== 0)
9239 /* If there is no note name, then use the default set of
9240 note type strings. */
9241 nt
= get_note_type (pnote
->type
);
9243 else if (const_strneq (pnote
->namedata
, "GNU"))
9244 /* GNU-specific object file notes. */
9245 nt
= get_gnu_elf_note_type (pnote
->type
);
9247 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
9248 /* NetBSD-specific core file notes. */
9249 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
9251 else if (strneq (pnote
->namedata
, "SPU/", 4))
9253 /* SPU-specific core file notes. */
9254 nt
= pnote
->namedata
+ 4;
9259 /* Don't recognize this note name; just use the default set of
9260 note type strings. */
9261 nt
= get_note_type (pnote
->type
);
9263 printf (" %s\t\t0x%08lx\t%s\n", name
, pnote
->descsz
, nt
);
9269 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
9271 Elf_External_Note
*pnotes
;
9272 Elf_External_Note
*external
;
9278 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
9284 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9285 (unsigned long) offset
, (unsigned long) length
);
9286 printf (_(" Owner\t\tData size\tDescription\n"));
9288 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
9290 Elf_External_Note
*next
;
9291 Elf_Internal_Note inote
;
9294 inote
.type
= BYTE_GET (external
->type
);
9295 inote
.namesz
= BYTE_GET (external
->namesz
);
9296 inote
.namedata
= external
->name
;
9297 inote
.descsz
= BYTE_GET (external
->descsz
);
9298 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
9299 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
9301 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
9303 if (((char *) next
) > (((char *) pnotes
) + length
))
9305 warn (_("corrupt note found at offset %lx into core notes\n"),
9306 (long)((char *)external
- (char *)pnotes
));
9307 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
9308 inote
.type
, inote
.namesz
, inote
.descsz
);
9314 /* Verify that name is null terminated. It appears that at least
9315 one version of Linux (RedHat 6.0) generates corefiles that don't
9316 comply with the ELF spec by failing to include the null byte in
9318 if (inote
.namedata
[inote
.namesz
] != '\0')
9320 temp
= malloc (inote
.namesz
+ 1);
9324 error (_("Out of memory\n"));
9329 strncpy (temp
, inote
.namedata
, inote
.namesz
);
9330 temp
[inote
.namesz
] = 0;
9332 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9333 inote
.namedata
= temp
;
9336 res
&= process_note (& inote
);
9351 process_corefile_note_segments (FILE *file
)
9353 Elf_Internal_Phdr
*segment
;
9357 if (! get_program_headers (file
))
9360 for (i
= 0, segment
= program_headers
;
9361 i
< elf_header
.e_phnum
;
9364 if (segment
->p_type
== PT_NOTE
)
9365 res
&= process_corefile_note_segment (file
,
9366 (bfd_vma
) segment
->p_offset
,
9367 (bfd_vma
) segment
->p_filesz
);
9374 process_note_sections (FILE *file
)
9376 Elf_Internal_Shdr
*section
;
9380 for (i
= 0, section
= section_headers
;
9381 i
< elf_header
.e_shnum
;
9383 if (section
->sh_type
== SHT_NOTE
)
9384 res
&= process_corefile_note_segment (file
,
9385 (bfd_vma
) section
->sh_offset
,
9386 (bfd_vma
) section
->sh_size
);
9392 process_notes (FILE *file
)
9394 /* If we have not been asked to display the notes then do nothing. */
9398 if (elf_header
.e_type
!= ET_CORE
)
9399 return process_note_sections (file
);
9401 /* No program headers means no NOTE segment. */
9402 if (elf_header
.e_phnum
> 0)
9403 return process_corefile_note_segments (file
);
9405 printf (_("No note segments present in the core file.\n"));
9410 process_arch_specific (FILE *file
)
9415 switch (elf_header
.e_machine
)
9418 return process_arm_specific (file
);
9420 case EM_MIPS_RS3_LE
:
9421 return process_mips_specific (file
);
9424 return process_power_specific (file
);
9433 get_file_header (FILE *file
)
9435 /* Read in the identity array. */
9436 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
9439 /* Determine how to read the rest of the header. */
9440 switch (elf_header
.e_ident
[EI_DATA
])
9442 default: /* fall through */
9443 case ELFDATANONE
: /* fall through */
9445 byte_get
= byte_get_little_endian
;
9446 byte_put
= byte_put_little_endian
;
9449 byte_get
= byte_get_big_endian
;
9450 byte_put
= byte_put_big_endian
;
9454 /* For now we only support 32 bit and 64 bit ELF files. */
9455 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
9457 /* Read in the rest of the header. */
9460 Elf32_External_Ehdr ehdr32
;
9462 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
9465 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
9466 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
9467 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
9468 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
9469 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
9470 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
9471 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
9472 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
9473 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
9474 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
9475 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
9476 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
9477 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
9481 Elf64_External_Ehdr ehdr64
;
9483 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9484 we will not be able to cope with the 64bit data found in
9485 64 ELF files. Detect this now and abort before we start
9486 overwriting things. */
9487 if (sizeof (bfd_vma
) < 8)
9489 error (_("This instance of readelf has been built without support for a\n\
9490 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9494 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
9497 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
9498 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
9499 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
9500 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
9501 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
9502 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
9503 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
9504 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
9505 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
9506 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
9507 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
9508 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
9509 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
9512 if (elf_header
.e_shoff
)
9514 /* There may be some extensions in the first section header. Don't
9515 bomb if we can't read it. */
9517 get_32bit_section_headers (file
, 1);
9519 get_64bit_section_headers (file
, 1);
9522 is_relocatable
= elf_header
.e_type
== ET_REL
;
9527 /* Process one ELF object file according to the command line options.
9528 This file may actually be stored in an archive. The file is
9529 positioned at the start of the ELF object. */
9532 process_object (char *file_name
, FILE *file
)
9536 if (! get_file_header (file
))
9538 error (_("%s: Failed to read file header\n"), file_name
);
9542 /* Initialise per file variables. */
9543 for (i
= ARRAY_SIZE (version_info
); i
--;)
9544 version_info
[i
] = 0;
9546 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
9547 dynamic_info
[i
] = 0;
9549 /* Process the file. */
9551 printf (_("\nFile: %s\n"), file_name
);
9553 /* Initialise the dump_sects array from the cmdline_dump_sects array.
9554 Note we do this even if cmdline_dump_sects is empty because we
9555 must make sure that the dump_sets array is zeroed out before each
9556 object file is processed. */
9557 if (num_dump_sects
> num_cmdline_dump_sects
)
9558 memset (dump_sects
, 0, num_dump_sects
);
9560 if (num_cmdline_dump_sects
> 0)
9562 if (num_dump_sects
== 0)
9563 /* A sneaky way of allocating the dump_sects array. */
9564 request_dump (num_cmdline_dump_sects
, 0);
9566 assert (num_dump_sects
>= num_cmdline_dump_sects
);
9567 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
9570 if (! process_file_header ())
9573 if (! process_section_headers (file
))
9575 /* Without loaded section headers we cannot process lots of
9577 do_unwind
= do_version
= do_dump
= do_arch
= 0;
9579 if (! do_using_dynamic
)
9580 do_syms
= do_reloc
= 0;
9583 if (! process_section_groups (file
))
9585 /* Without loaded section groups we cannot process unwind. */
9589 if (process_program_headers (file
))
9590 process_dynamic_section (file
);
9592 process_relocs (file
);
9594 process_unwind (file
);
9596 process_symbol_table (file
);
9598 process_syminfo (file
);
9600 process_version_sections (file
);
9602 process_section_contents (file
);
9604 process_notes (file
);
9606 process_gnu_liblist (file
);
9608 process_arch_specific (file
);
9610 if (program_headers
)
9612 free (program_headers
);
9613 program_headers
= NULL
;
9616 if (section_headers
)
9618 free (section_headers
);
9619 section_headers
= NULL
;
9624 free (string_table
);
9625 string_table
= NULL
;
9626 string_table_length
= 0;
9629 if (dynamic_strings
)
9631 free (dynamic_strings
);
9632 dynamic_strings
= NULL
;
9633 dynamic_strings_length
= 0;
9636 if (dynamic_symbols
)
9638 free (dynamic_symbols
);
9639 dynamic_symbols
= NULL
;
9640 num_dynamic_syms
= 0;
9643 if (dynamic_syminfo
)
9645 free (dynamic_syminfo
);
9646 dynamic_syminfo
= NULL
;
9649 if (section_headers_groups
)
9651 free (section_headers_groups
);
9652 section_headers_groups
= NULL
;
9657 struct group_list
*g
, *next
;
9659 for (i
= 0; i
< group_count
; i
++)
9661 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
9668 free (section_groups
);
9669 section_groups
= NULL
;
9672 free_debug_memory ();
9677 /* Process an ELF archive. The file is positioned just after the
9681 process_archive (char *file_name
, FILE *file
)
9683 struct ar_hdr arhdr
;
9686 char *longnames
= NULL
;
9687 unsigned long longnames_size
= 0;
9688 size_t file_name_size
;
9693 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9694 if (got
!= sizeof arhdr
)
9699 error (_("%s: failed to read archive header\n"), file_name
);
9703 if (const_strneq (arhdr
.ar_name
, "/ ")
9704 || const_strneq (arhdr
.ar_name
, "/SYM64/ "))
9706 /* This is the archive symbol table. Skip it.
9707 FIXME: We should have an option to dump it. */
9708 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9709 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
9711 error (_("%s: failed to skip archive symbol table\n"), file_name
);
9715 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9716 if (got
!= sizeof arhdr
)
9721 error (_("%s: failed to read archive header\n"), file_name
);
9726 if (const_strneq (arhdr
.ar_name
, "// "))
9728 /* This is the archive string table holding long member
9731 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9733 longnames
= malloc (longnames_size
);
9734 if (longnames
== NULL
)
9736 error (_("Out of memory\n"));
9740 if (fread (longnames
, longnames_size
, 1, file
) != 1)
9743 error (_("%s: failed to read string table\n"), file_name
);
9747 if ((longnames_size
& 1) != 0)
9750 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9751 if (got
!= sizeof arhdr
)
9758 error (_("%s: failed to read archive header\n"), file_name
);
9763 file_name_size
= strlen (file_name
);
9772 if (arhdr
.ar_name
[0] == '/')
9776 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
9777 if (off
>= longnames_size
)
9779 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
9784 name
= longnames
+ off
;
9785 nameend
= memchr (name
, '/', longnames_size
- off
);
9789 name
= arhdr
.ar_name
;
9790 nameend
= memchr (name
, '/', 16);
9793 if (nameend
== NULL
)
9795 error (_("%s: bad archive file name\n"), file_name
);
9800 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
9801 if (namealc
== NULL
)
9803 error (_("Out of memory\n"));
9808 memcpy (namealc
, file_name
, file_name_size
);
9809 namealc
[file_name_size
] = '(';
9810 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
9811 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
9812 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
9814 archive_file_offset
= ftell (file
);
9815 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
9817 ret
|= process_object (namealc
, file
);
9822 (archive_file_offset
9824 + (archive_file_size
& 1)),
9827 error (_("%s: failed to seek to next archive header\n"), file_name
);
9832 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
9833 if (got
!= sizeof arhdr
)
9838 error (_("%s: failed to read archive header\n"), file_name
);
9851 process_file (char *file_name
)
9854 struct stat statbuf
;
9858 if (stat (file_name
, &statbuf
) < 0)
9860 if (errno
== ENOENT
)
9861 error (_("'%s': No such file\n"), file_name
);
9863 error (_("Could not locate '%s'. System error message: %s\n"),
9864 file_name
, strerror (errno
));
9868 if (! S_ISREG (statbuf
.st_mode
))
9870 error (_("'%s' is not an ordinary file\n"), file_name
);
9874 file
= fopen (file_name
, "rb");
9877 error (_("Input file '%s' is not readable.\n"), file_name
);
9881 if (fread (armag
, SARMAG
, 1, file
) != 1)
9883 error (_("%s: Failed to read file header\n"), file_name
);
9888 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
9889 ret
= process_archive (file_name
, file
);
9893 archive_file_size
= archive_file_offset
= 0;
9894 ret
= process_object (file_name
, file
);
9902 #ifdef SUPPORT_DISASSEMBLY
9903 /* Needed by the i386 disassembler. For extra credit, someone could
9904 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9908 print_address (unsigned int addr
, FILE *outfile
)
9910 fprintf (outfile
,"0x%8.8x", addr
);
9913 /* Needed by the i386 disassembler. */
9915 db_task_printsym (unsigned int addr
)
9917 print_address (addr
, stderr
);
9922 main (int argc
, char **argv
)
9926 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9927 setlocale (LC_MESSAGES
, "");
9929 #if defined (HAVE_SETLOCALE)
9930 setlocale (LC_CTYPE
, "");
9932 bindtextdomain (PACKAGE
, LOCALEDIR
);
9933 textdomain (PACKAGE
);
9935 expandargv (&argc
, &argv
);
9937 parse_args (argc
, argv
);
9939 if (num_dump_sects
> 0)
9941 /* Make a copy of the dump_sects array. */
9942 cmdline_dump_sects
= malloc (num_dump_sects
);
9943 if (cmdline_dump_sects
== NULL
)
9944 error (_("Out of memory allocating dump request table.\n"));
9947 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
9948 num_cmdline_dump_sects
= num_dump_sects
;
9952 if (optind
< (argc
- 1))
9956 while (optind
< argc
)
9957 err
|= process_file (argv
[optind
++]);
9959 if (dump_sects
!= NULL
)
9961 if (cmdline_dump_sects
!= NULL
)
9962 free (cmdline_dump_sects
);