1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009 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. */
54 /* Define BFD64 here, even if our default architecture is 32 bit ELF
55 as this will allow us to read in and parse 64bit and 32bit ELF files.
56 Only do this if we believe that the compiler can support a 64 bit
57 data type. For now we only rely on GCC being able to do this. */
65 #include "elf/common.h"
66 #include "elf/external.h"
67 #include "elf/internal.h"
70 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
71 we can obtain the H8 reloc numbers. We need these for the
72 get_reloc_size() function. We include h8.h again after defining
73 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
78 /* Undo the effects of #including reloc-macros.h. */
80 #undef START_RELOC_NUMBERS
84 #undef END_RELOC_NUMBERS
85 #undef _RELOC_MACROS_H
87 /* The following headers use the elf/reloc-macros.h file to
88 automatically generate relocation recognition functions
89 such as elf_mips_reloc_type() */
91 #define RELOC_MACROS_GEN_FUNC
93 #include "elf/alpha.h"
101 #include "elf/d10v.h"
102 #include "elf/d30v.h"
104 #include "elf/fr30.h"
107 #include "elf/hppa.h"
108 #include "elf/i386.h"
109 #include "elf/i370.h"
110 #include "elf/i860.h"
111 #include "elf/i960.h"
112 #include "elf/ia64.h"
113 #include "elf/ip2k.h"
114 #include "elf/lm32.h"
115 #include "elf/iq2000.h"
116 #include "elf/m32c.h"
117 #include "elf/m32r.h"
118 #include "elf/m68k.h"
119 #include "elf/m68hc11.h"
120 #include "elf/mcore.h"
122 #include "elf/mips.h"
123 #include "elf/mmix.h"
124 #include "elf/mn10200.h"
125 #include "elf/mn10300.h"
127 #include "elf/msp430.h"
128 #include "elf/or32.h"
131 #include "elf/ppc64.h"
132 #include "elf/s390.h"
133 #include "elf/score.h"
135 #include "elf/sparc.h"
137 #include "elf/v850.h"
139 #include "elf/x86-64.h"
140 #include "elf/xstormy16.h"
141 #include "elf/xtensa.h"
146 #include "libiberty.h"
147 #include "safe-ctype.h"
148 #include "filenames.h"
150 char * program_name
= "readelf";
152 static long archive_file_offset
;
153 static unsigned long archive_file_size
;
154 static unsigned long dynamic_addr
;
155 static bfd_size_type dynamic_size
;
156 static unsigned int dynamic_nent
;
157 static char * dynamic_strings
;
158 static unsigned long dynamic_strings_length
;
159 static char * string_table
;
160 static unsigned long string_table_length
;
161 static unsigned long num_dynamic_syms
;
162 static Elf_Internal_Sym
* dynamic_symbols
;
163 static Elf_Internal_Syminfo
* dynamic_syminfo
;
164 static unsigned long dynamic_syminfo_offset
;
165 static unsigned int dynamic_syminfo_nent
;
166 static char program_interpreter
[PATH_MAX
];
167 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
168 static bfd_vma dynamic_info_DT_GNU_HASH
;
169 static bfd_vma version_info
[16];
170 static Elf_Internal_Ehdr elf_header
;
171 static Elf_Internal_Shdr
* section_headers
;
172 static Elf_Internal_Phdr
* program_headers
;
173 static Elf_Internal_Dyn
* dynamic_section
;
174 static Elf_Internal_Shdr
* symtab_shndx_hdr
;
175 static int show_name
;
176 static int do_dynamic
;
179 static int do_sections
;
180 static int do_section_groups
;
181 static int do_section_details
;
182 static int do_segments
;
183 static int do_unwind
;
184 static int do_using_dynamic
;
185 static int do_header
;
187 static int do_version
;
188 static int do_histogram
;
189 static int do_debugging
;
192 static int do_archive_index
;
193 static int is_32bit_elf
;
197 struct group_list
* next
;
198 unsigned int section_index
;
203 struct group_list
* root
;
204 unsigned int group_index
;
207 static size_t group_count
;
208 static struct group
* section_groups
;
209 static struct group
** section_headers_groups
;
212 /* Flag bits indicating particular types of dump. */
213 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
214 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
215 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
216 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
217 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
219 typedef unsigned char dump_type
;
221 /* A linked list of the section names for which dumps were requested. */
222 struct dump_list_entry
226 struct dump_list_entry
* next
;
228 static struct dump_list_entry
* dump_sects_byname
;
230 /* A dynamic array of flags indicating for which sections a dump
231 has been requested via command line switches. */
232 static dump_type
* cmdline_dump_sects
= NULL
;
233 static unsigned int num_cmdline_dump_sects
= 0;
235 /* A dynamic array of flags indicating for which sections a dump of
236 some kind has been requested. It is reset on a per-object file
237 basis and then initialised from the cmdline_dump_sects array,
238 the results of interpreting the -w switch, and the
239 dump_sects_byname list. */
240 static dump_type
* dump_sects
= NULL
;
241 static unsigned int num_dump_sects
= 0;
244 /* How to print a vma value. */
245 typedef enum print_mode
257 static void (* byte_put
) (unsigned char *, bfd_vma
, int);
261 #define SECTION_NAME(X) \
262 ((X) == NULL ? "<none>" \
263 : string_table == NULL ? "<no-name>" \
264 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
265 : string_table + (X)->sh_name))
267 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
269 #define BYTE_GET(field) byte_get (field, sizeof (field))
271 #define GET_ELF_SYMBOLS(file, section) \
272 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
273 : get_64bit_elf_symbols (file, section))
275 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
276 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
277 already been called and verified that the string exists. */
278 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
280 /* This is just a bit of syntatic sugar. */
281 #define streq(a,b) (strcmp ((a), (b)) == 0)
282 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
283 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
286 get_data (void * var
, FILE * file
, long offset
, size_t size
, size_t nmemb
,
291 if (size
== 0 || nmemb
== 0)
294 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
296 error (_("Unable to seek to 0x%lx for %s\n"),
297 (unsigned long) archive_file_offset
+ offset
, reason
);
304 /* Check for overflow. */
305 if (nmemb
< (~(size_t) 0 - 1) / size
)
306 /* + 1 so that we can '\0' terminate invalid string table sections. */
307 mvar
= malloc (size
* nmemb
+ 1);
311 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
312 (unsigned long)(size
* nmemb
), reason
);
316 ((char *) mvar
)[size
* nmemb
] = '\0';
319 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
321 error (_("Unable to read in 0x%lx bytes of %s\n"),
322 (unsigned long)(size
* nmemb
), reason
);
332 byte_put_little_endian (unsigned char * field
, bfd_vma value
, int size
)
337 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
338 field
[6] = ((value
>> 24) >> 24) & 0xff;
339 field
[5] = ((value
>> 24) >> 16) & 0xff;
340 field
[4] = ((value
>> 24) >> 8) & 0xff;
343 field
[3] = (value
>> 24) & 0xff;
344 field
[2] = (value
>> 16) & 0xff;
347 field
[1] = (value
>> 8) & 0xff;
350 field
[0] = value
& 0xff;
354 error (_("Unhandled data length: %d\n"), size
);
359 /* Print a VMA value. */
362 print_vma (bfd_vma vma
, print_mode mode
)
375 return nc
+ printf ("%8.8" BFD_VMA_FMT
"x", vma
);
382 return printf ("%5" BFD_VMA_FMT
"d", vma
);
390 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
393 return printf ("%" BFD_VMA_FMT
"d", vma
);
396 return printf ("%" BFD_VMA_FMT
"u", vma
);
401 /* Display a symbol on stdout. Handles the display of non-printing characters.
403 If DO_WIDE is not true then format the symbol to be at most WIDTH characters,
404 truncating as necessary. If WIDTH is negative then format the string to be
405 exactly - WIDTH characters, truncating or padding as necessary.
407 Returns the number of emitted characters. */
410 print_symbol (int width
, const char * symbol
)
413 bfd_boolean extra_padding
= FALSE
;
414 unsigned int num_printed
= 0;
418 /* Set the width to a very large value. This simplifies the code below. */
423 /* Keep the width positive. This also helps. */
425 extra_padding
= TRUE
;
434 /* Look for non-printing symbols inside the symbol's name.
435 This test is triggered in particular by the names generated
436 by the assembler for local labels. */
437 while (ISPRINT (* c
))
447 printf ("%.*s", len
, symbol
);
453 if (* c
== 0 || width
== 0)
456 /* Now display the non-printing character, if
457 there is room left in which to dipslay it. */
463 printf ("^%c", *c
+ 0x40);
473 printf ("<0x%.2x>", *c
);
482 if (extra_padding
&& width
> 0)
484 /* Fill in the remaining spaces. */
485 printf ("%-*s", width
, " ");
493 byte_put_big_endian (unsigned char * field
, bfd_vma value
, int size
)
498 field
[7] = value
& 0xff;
499 field
[6] = (value
>> 8) & 0xff;
500 field
[5] = (value
>> 16) & 0xff;
501 field
[4] = (value
>> 24) & 0xff;
506 field
[3] = value
& 0xff;
507 field
[2] = (value
>> 8) & 0xff;
511 field
[1] = value
& 0xff;
515 field
[0] = value
& 0xff;
519 error (_("Unhandled data length: %d\n"), size
);
524 /* Return a pointer to section NAME, or NULL if no such section exists. */
526 static Elf_Internal_Shdr
*
527 find_section (const char * name
)
531 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
532 if (streq (SECTION_NAME (section_headers
+ i
), name
))
533 return section_headers
+ i
;
538 /* Guess the relocation size commonly used by the specific machines. */
541 guess_is_rela (unsigned int e_machine
)
545 /* Targets that use REL relocations. */
561 /* Targets that use RELA relocations. */
565 case EM_ALTERA_NIOS2
:
585 case EM_LATTICEMICO32
:
593 case EM_CYGNUS_MN10200
:
595 case EM_CYGNUS_MN10300
:
637 warn (_("Don't know about relocations on this machine architecture\n"));
643 slurp_rela_relocs (FILE * file
,
644 unsigned long rel_offset
,
645 unsigned long rel_size
,
646 Elf_Internal_Rela
** relasp
,
647 unsigned long * nrelasp
)
649 Elf_Internal_Rela
* relas
;
650 unsigned long nrelas
;
655 Elf32_External_Rela
* erelas
;
657 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
661 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
663 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
668 error (_("out of memory parsing relocs\n"));
672 for (i
= 0; i
< nrelas
; i
++)
674 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
675 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
676 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
683 Elf64_External_Rela
* erelas
;
685 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
689 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
691 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
696 error (_("out of memory parsing relocs\n"));
700 for (i
= 0; i
< nrelas
; i
++)
702 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
703 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
704 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
706 /* The #ifdef BFD64 below is to prevent a compile time
707 warning. We know that if we do not have a 64 bit data
708 type that we will never execute this code anyway. */
710 if (elf_header
.e_machine
== EM_MIPS
711 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
713 /* In little-endian objects, r_info isn't really a
714 64-bit little-endian value: it has a 32-bit
715 little-endian symbol index followed by four
716 individual byte fields. Reorder INFO
718 bfd_vma info
= relas
[i
].r_info
;
719 info
= (((info
& 0xffffffff) << 32)
720 | ((info
>> 56) & 0xff)
721 | ((info
>> 40) & 0xff00)
722 | ((info
>> 24) & 0xff0000)
723 | ((info
>> 8) & 0xff000000));
724 relas
[i
].r_info
= info
;
737 slurp_rel_relocs (FILE * file
,
738 unsigned long rel_offset
,
739 unsigned long rel_size
,
740 Elf_Internal_Rela
** relsp
,
741 unsigned long * nrelsp
)
743 Elf_Internal_Rela
* rels
;
749 Elf32_External_Rel
* erels
;
751 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
755 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
757 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
762 error (_("out of memory parsing relocs\n"));
766 for (i
= 0; i
< nrels
; i
++)
768 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
769 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
770 rels
[i
].r_addend
= 0;
777 Elf64_External_Rel
* erels
;
779 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
783 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
785 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
790 error (_("out of memory parsing relocs\n"));
794 for (i
= 0; i
< nrels
; i
++)
796 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
797 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
798 rels
[i
].r_addend
= 0;
800 /* The #ifdef BFD64 below is to prevent a compile time
801 warning. We know that if we do not have a 64 bit data
802 type that we will never execute this code anyway. */
804 if (elf_header
.e_machine
== EM_MIPS
805 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
807 /* In little-endian objects, r_info isn't really a
808 64-bit little-endian value: it has a 32-bit
809 little-endian symbol index followed by four
810 individual byte fields. Reorder INFO
812 bfd_vma info
= rels
[i
].r_info
;
813 info
= (((info
& 0xffffffff) << 32)
814 | ((info
>> 56) & 0xff)
815 | ((info
>> 40) & 0xff00)
816 | ((info
>> 24) & 0xff0000)
817 | ((info
>> 8) & 0xff000000));
818 rels
[i
].r_info
= info
;
830 /* Returns the reloc type extracted from the reloc info field. */
833 get_reloc_type (bfd_vma reloc_info
)
836 return ELF32_R_TYPE (reloc_info
);
838 switch (elf_header
.e_machine
)
841 /* Note: We assume that reloc_info has already been adjusted for us. */
842 return ELF64_MIPS_R_TYPE (reloc_info
);
845 return ELF64_R_TYPE_ID (reloc_info
);
848 return ELF64_R_TYPE (reloc_info
);
852 /* Return the symbol index extracted from the reloc info field. */
855 get_reloc_symindex (bfd_vma reloc_info
)
857 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
860 /* Display the contents of the relocation data found at the specified
864 dump_relocations (FILE * file
,
865 unsigned long rel_offset
,
866 unsigned long rel_size
,
867 Elf_Internal_Sym
* symtab
,
870 unsigned long strtablen
,
874 Elf_Internal_Rela
* rels
;
876 if (is_rela
== UNKNOWN
)
877 is_rela
= guess_is_rela (elf_header
.e_machine
);
881 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
886 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
895 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
897 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
902 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
904 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
912 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
914 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
919 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
921 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
925 for (i
= 0; i
< rel_size
; i
++)
930 bfd_vma symtab_index
;
933 offset
= rels
[i
].r_offset
;
934 info
= rels
[i
].r_info
;
936 type
= get_reloc_type (info
);
937 symtab_index
= get_reloc_symindex (info
);
941 printf ("%8.8lx %8.8lx ",
942 (unsigned long) offset
& 0xffffffff,
943 (unsigned long) info
& 0xffffffff);
947 #if BFD_HOST_64BIT_LONG
949 ? "%16.16lx %16.16lx "
950 : "%12.12lx %12.12lx ",
952 #elif BFD_HOST_64BIT_LONG_LONG
955 ? "%16.16llx %16.16llx "
956 : "%12.12llx %12.12llx ",
960 ? "%16.16I64x %16.16I64x "
961 : "%12.12I64x %12.12I64x ",
966 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
967 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
968 _bfd_int64_high (offset
),
969 _bfd_int64_low (offset
),
970 _bfd_int64_high (info
),
971 _bfd_int64_low (info
));
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
);
1089 rtype
= elf_alpha_reloc_type (type
);
1093 rtype
= elf_arm_reloc_type (type
);
1097 rtype
= elf_arc_reloc_type (type
);
1101 rtype
= elf_hppa_reloc_type (type
);
1107 rtype
= elf_h8_reloc_type (type
);
1112 rtype
= elf_or32_reloc_type (type
);
1117 rtype
= elf_pj_reloc_type (type
);
1120 rtype
= elf_ia64_reloc_type (type
);
1124 rtype
= elf_cris_reloc_type (type
);
1128 rtype
= elf_i860_reloc_type (type
);
1133 rtype
= elf_x86_64_reloc_type (type
);
1137 rtype
= i370_reloc_type (type
);
1142 rtype
= elf_s390_reloc_type (type
);
1146 rtype
= elf_score_reloc_type (type
);
1150 rtype
= elf_xstormy16_reloc_type (type
);
1154 rtype
= elf_crx_reloc_type (type
);
1158 rtype
= elf_vax_reloc_type (type
);
1163 rtype
= elf_ip2k_reloc_type (type
);
1167 rtype
= elf_iq2000_reloc_type (type
);
1172 rtype
= elf_xtensa_reloc_type (type
);
1175 case EM_LATTICEMICO32
:
1176 rtype
= elf_lm32_reloc_type (type
);
1181 rtype
= elf_m32c_reloc_type (type
);
1185 rtype
= elf_mt_reloc_type (type
);
1189 rtype
= elf_bfin_reloc_type (type
);
1193 rtype
= elf_mep_reloc_type (type
);
1198 rtype
= elf_cr16_reloc_type (type
);
1203 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1205 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1207 if (elf_header
.e_machine
== EM_ALPHA
1209 && streq (rtype
, "R_ALPHA_LITUSE")
1212 switch (rels
[i
].r_addend
)
1214 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1215 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1216 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1217 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1218 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1219 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1220 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1221 default: rtype
= NULL
;
1224 printf (" (%s)", rtype
);
1228 printf (_("<unknown addend: %lx>"),
1229 (unsigned long) rels
[i
].r_addend
);
1232 else if (symtab_index
)
1234 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1235 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1238 Elf_Internal_Sym
* psym
;
1240 psym
= symtab
+ symtab_index
;
1244 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1248 unsigned int width
= is_32bit_elf
? 8 : 14;
1250 /* Relocations against GNU_IFUNC symbols do not use the value
1251 of the symbol as the address to relocate against. Instead
1252 they invoke the function named by the symbol and use its
1253 result as the address for relocation.
1255 To indicate this to the user, do not display the value of
1256 the symbol in the "Symbols's Value" field. Instead show
1257 its name followed by () as a hint that the symbol is
1261 || psym
->st_name
== 0
1262 || psym
->st_name
>= strtablen
)
1265 name
= strtab
+ psym
->st_name
;
1267 len
= print_symbol (width
, name
);
1268 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
1272 print_vma (psym
->st_value
, LONG_HEX
);
1274 printf (is_32bit_elf
? " " : " ");
1277 if (psym
->st_name
== 0)
1279 const char * sec_name
= "<null>";
1282 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1284 if (psym
->st_shndx
< elf_header
.e_shnum
)
1286 = SECTION_NAME (section_headers
+ psym
->st_shndx
);
1287 else if (psym
->st_shndx
== SHN_ABS
)
1289 else if (psym
->st_shndx
== SHN_COMMON
)
1290 sec_name
= "COMMON";
1291 else if (elf_header
.e_machine
== EM_MIPS
1292 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1293 sec_name
= "SCOMMON";
1294 else if (elf_header
.e_machine
== EM_MIPS
1295 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1296 sec_name
= "SUNDEF";
1297 else if ((elf_header
.e_machine
== EM_X86_64
1298 || elf_header
.e_machine
== EM_L1OM
)
1299 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1300 sec_name
= "LARGE_COMMON";
1301 else if (elf_header
.e_machine
== EM_IA_64
1302 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1303 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1304 sec_name
= "ANSI_COM";
1305 else if (elf_header
.e_machine
== EM_IA_64
1306 && (elf_header
.e_ident
[EI_OSABI
]
1307 == ELFOSABI_OPENVMS
)
1308 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
1309 sec_name
= "VMS_SYMVEC";
1312 sprintf (name_buf
, "<section 0x%x>",
1313 (unsigned int) psym
->st_shndx
);
1314 sec_name
= name_buf
;
1317 print_symbol (22, sec_name
);
1319 else if (strtab
== NULL
)
1320 printf (_("<string table index: %3ld>"), psym
->st_name
);
1321 else if (psym
->st_name
>= strtablen
)
1322 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1324 print_symbol (22, strtab
+ psym
->st_name
);
1328 long offset
= (long) (bfd_signed_vma
) rels
[i
].r_addend
;
1331 printf (" - %lx", - offset
);
1333 printf (" + %lx", offset
);
1339 printf ("%*c", is_32bit_elf
?
1340 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1341 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1344 if (elf_header
.e_machine
== EM_SPARCV9
1346 && streq (rtype
, "R_SPARC_OLO10"))
1347 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1352 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1354 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (info
);
1355 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (info
);
1356 const char * rtype2
= elf_mips_reloc_type (type2
);
1357 const char * rtype3
= elf_mips_reloc_type (type3
);
1359 printf (" Type2: ");
1362 printf (_("unrecognized: %-7lx"),
1363 (unsigned long) type2
& 0xffffffff);
1365 printf ("%-17.17s", rtype2
);
1367 printf ("\n Type3: ");
1370 printf (_("unrecognized: %-7lx"),
1371 (unsigned long) type3
& 0xffffffff);
1373 printf ("%-17.17s", rtype3
);
1384 get_mips_dynamic_type (unsigned long type
)
1388 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1389 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1390 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1391 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1392 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1393 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1394 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1395 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1396 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1397 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1398 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1399 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1400 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1401 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1402 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1403 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1404 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1405 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1406 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1407 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1408 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1409 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1410 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1411 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1412 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1413 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1414 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1415 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1416 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1417 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1418 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1419 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1420 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1421 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1422 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1423 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1424 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1425 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1426 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1427 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1428 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1429 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1430 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1431 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
1432 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
1439 get_sparc64_dynamic_type (unsigned long type
)
1443 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1450 get_ppc_dynamic_type (unsigned long type
)
1454 case DT_PPC_GOT
: return "PPC_GOT";
1461 get_ppc64_dynamic_type (unsigned long type
)
1465 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1466 case DT_PPC64_OPD
: return "PPC64_OPD";
1467 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1474 get_parisc_dynamic_type (unsigned long type
)
1478 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1479 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1480 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1481 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1482 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1483 case DT_HP_PREINIT
: return "HP_PREINIT";
1484 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1485 case DT_HP_NEEDED
: return "HP_NEEDED";
1486 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1487 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1488 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1489 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1490 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1491 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1492 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1493 case DT_HP_FILTERED
: return "HP_FILTERED";
1494 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1495 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1496 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1497 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1498 case DT_PLT
: return "PLT";
1499 case DT_PLT_SIZE
: return "PLT_SIZE";
1500 case DT_DLT
: return "DLT";
1501 case DT_DLT_SIZE
: return "DLT_SIZE";
1508 get_ia64_dynamic_type (unsigned long type
)
1512 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1513 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
1514 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
1515 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
1516 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
1517 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
1518 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
1519 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
1520 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
1521 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
1522 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
1523 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
1524 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
1525 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
1526 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
1527 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
1528 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
1529 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
1530 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
1531 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
1532 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
1533 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
1534 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
1535 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
1536 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
1537 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
1538 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
1539 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
1540 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
1541 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
1542 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
1549 get_alpha_dynamic_type (unsigned long type
)
1553 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1560 get_score_dynamic_type (unsigned long type
)
1564 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1565 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1566 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1567 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1568 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1569 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1577 get_dynamic_type (unsigned long type
)
1579 static char buff
[64];
1583 case DT_NULL
: return "NULL";
1584 case DT_NEEDED
: return "NEEDED";
1585 case DT_PLTRELSZ
: return "PLTRELSZ";
1586 case DT_PLTGOT
: return "PLTGOT";
1587 case DT_HASH
: return "HASH";
1588 case DT_STRTAB
: return "STRTAB";
1589 case DT_SYMTAB
: return "SYMTAB";
1590 case DT_RELA
: return "RELA";
1591 case DT_RELASZ
: return "RELASZ";
1592 case DT_RELAENT
: return "RELAENT";
1593 case DT_STRSZ
: return "STRSZ";
1594 case DT_SYMENT
: return "SYMENT";
1595 case DT_INIT
: return "INIT";
1596 case DT_FINI
: return "FINI";
1597 case DT_SONAME
: return "SONAME";
1598 case DT_RPATH
: return "RPATH";
1599 case DT_SYMBOLIC
: return "SYMBOLIC";
1600 case DT_REL
: return "REL";
1601 case DT_RELSZ
: return "RELSZ";
1602 case DT_RELENT
: return "RELENT";
1603 case DT_PLTREL
: return "PLTREL";
1604 case DT_DEBUG
: return "DEBUG";
1605 case DT_TEXTREL
: return "TEXTREL";
1606 case DT_JMPREL
: return "JMPREL";
1607 case DT_BIND_NOW
: return "BIND_NOW";
1608 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1609 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1610 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1611 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1612 case DT_RUNPATH
: return "RUNPATH";
1613 case DT_FLAGS
: return "FLAGS";
1615 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1616 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1618 case DT_CHECKSUM
: return "CHECKSUM";
1619 case DT_PLTPADSZ
: return "PLTPADSZ";
1620 case DT_MOVEENT
: return "MOVEENT";
1621 case DT_MOVESZ
: return "MOVESZ";
1622 case DT_FEATURE
: return "FEATURE";
1623 case DT_POSFLAG_1
: return "POSFLAG_1";
1624 case DT_SYMINSZ
: return "SYMINSZ";
1625 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1627 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1628 case DT_CONFIG
: return "CONFIG";
1629 case DT_DEPAUDIT
: return "DEPAUDIT";
1630 case DT_AUDIT
: return "AUDIT";
1631 case DT_PLTPAD
: return "PLTPAD";
1632 case DT_MOVETAB
: return "MOVETAB";
1633 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1635 case DT_VERSYM
: return "VERSYM";
1637 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1638 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1639 case DT_RELACOUNT
: return "RELACOUNT";
1640 case DT_RELCOUNT
: return "RELCOUNT";
1641 case DT_FLAGS_1
: return "FLAGS_1";
1642 case DT_VERDEF
: return "VERDEF";
1643 case DT_VERDEFNUM
: return "VERDEFNUM";
1644 case DT_VERNEED
: return "VERNEED";
1645 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1647 case DT_AUXILIARY
: return "AUXILIARY";
1648 case DT_USED
: return "USED";
1649 case DT_FILTER
: return "FILTER";
1651 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1652 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1653 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1654 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1655 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1656 case DT_GNU_HASH
: return "GNU_HASH";
1659 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1661 const char * result
;
1663 switch (elf_header
.e_machine
)
1666 case EM_MIPS_RS3_LE
:
1667 result
= get_mips_dynamic_type (type
);
1670 result
= get_sparc64_dynamic_type (type
);
1673 result
= get_ppc_dynamic_type (type
);
1676 result
= get_ppc64_dynamic_type (type
);
1679 result
= get_ia64_dynamic_type (type
);
1682 result
= get_alpha_dynamic_type (type
);
1685 result
= get_score_dynamic_type (type
);
1695 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1697 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1698 || (elf_header
.e_machine
== EM_PARISC
1699 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1701 const char * result
;
1703 switch (elf_header
.e_machine
)
1706 result
= get_parisc_dynamic_type (type
);
1709 result
= get_ia64_dynamic_type (type
);
1719 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1723 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1730 get_file_type (unsigned e_type
)
1732 static char buff
[32];
1736 case ET_NONE
: return _("NONE (None)");
1737 case ET_REL
: return _("REL (Relocatable file)");
1738 case ET_EXEC
: return _("EXEC (Executable file)");
1739 case ET_DYN
: return _("DYN (Shared object file)");
1740 case ET_CORE
: return _("CORE (Core file)");
1743 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1744 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1745 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1746 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1748 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1754 get_machine_name (unsigned e_machine
)
1756 static char buff
[64]; /* XXX */
1760 case EM_NONE
: return _("None");
1761 case EM_M32
: return "WE32100";
1762 case EM_SPARC
: return "Sparc";
1763 case EM_SPU
: return "SPU";
1764 case EM_386
: return "Intel 80386";
1765 case EM_68K
: return "MC68000";
1766 case EM_88K
: return "MC88000";
1767 case EM_486
: return "Intel 80486";
1768 case EM_860
: return "Intel 80860";
1769 case EM_MIPS
: return "MIPS R3000";
1770 case EM_S370
: return "IBM System/370";
1771 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1772 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1773 case EM_PARISC
: return "HPPA";
1774 case EM_PPC_OLD
: return "Power PC (old)";
1775 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1776 case EM_960
: return "Intel 90860";
1777 case EM_PPC
: return "PowerPC";
1778 case EM_PPC64
: return "PowerPC64";
1779 case EM_V800
: return "NEC V800";
1780 case EM_FR20
: return "Fujitsu FR20";
1781 case EM_RH32
: return "TRW RH32";
1782 case EM_MCORE
: return "MCORE";
1783 case EM_ARM
: return "ARM";
1784 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1785 case EM_SH
: return "Renesas / SuperH SH";
1786 case EM_SPARCV9
: return "Sparc v9";
1787 case EM_TRICORE
: return "Siemens Tricore";
1788 case EM_ARC
: return "ARC";
1789 case EM_H8_300
: return "Renesas H8/300";
1790 case EM_H8_300H
: return "Renesas H8/300H";
1791 case EM_H8S
: return "Renesas H8S";
1792 case EM_H8_500
: return "Renesas H8/500";
1793 case EM_IA_64
: return "Intel IA-64";
1794 case EM_MIPS_X
: return "Stanford MIPS-X";
1795 case EM_COLDFIRE
: return "Motorola Coldfire";
1796 case EM_68HC12
: return "Motorola M68HC12";
1797 case EM_ALPHA
: return "Alpha";
1798 case EM_CYGNUS_D10V
:
1799 case EM_D10V
: return "d10v";
1800 case EM_CYGNUS_D30V
:
1801 case EM_D30V
: return "d30v";
1802 case EM_CYGNUS_M32R
:
1803 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1804 case EM_CYGNUS_V850
:
1805 case EM_V850
: return "NEC v850";
1806 case EM_CYGNUS_MN10300
:
1807 case EM_MN10300
: return "mn10300";
1808 case EM_CYGNUS_MN10200
:
1809 case EM_MN10200
: return "mn10200";
1810 case EM_CYGNUS_FR30
:
1811 case EM_FR30
: return "Fujitsu FR30";
1812 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1814 case EM_PJ
: return "picoJava";
1815 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1816 case EM_PCP
: return "Siemens PCP";
1817 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1818 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1819 case EM_STARCORE
: return "Motorola Star*Core processor";
1820 case EM_ME16
: return "Toyota ME16 processor";
1821 case EM_ST100
: return "STMicroelectronics ST100 processor";
1822 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1823 case EM_FX66
: return "Siemens FX66 microcontroller";
1824 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1825 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1826 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1827 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1828 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1829 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1830 case EM_SVX
: return "Silicon Graphics SVx";
1831 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1832 case EM_VAX
: return "Digital VAX";
1834 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1835 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1836 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1837 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1838 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1839 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1840 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1841 case EM_PRISM
: return "Vitesse Prism";
1842 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1843 case EM_L1OM
: return "Intel L1OM";
1845 case EM_S390
: return "IBM S/390";
1846 case EM_SCORE
: return "SUNPLUS S+Core";
1847 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1849 case EM_OR32
: return "OpenRISC";
1850 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1851 case EM_DLX
: return "OpenDLX";
1853 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1854 case EM_IQ2000
: return "Vitesse IQ2000";
1856 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1857 case EM_LATTICEMICO32
: return "Lattice Mico32";
1859 case EM_M32C
: return "Renesas M32c";
1860 case EM_MT
: return "Morpho Techologies MT processor";
1861 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1862 case EM_NIOS32
: return "Altera Nios";
1863 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1864 case EM_XC16X
: return "Infineon Technologies xc16x";
1865 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1867 case EM_CR16_OLD
: return "National Semiconductor's CR16";
1869 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
1875 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1880 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1881 e_flags
&= ~ EF_ARM_EABIMASK
;
1883 /* Handle "generic" ARM flags. */
1884 if (e_flags
& EF_ARM_RELEXEC
)
1886 strcat (buf
, ", relocatable executable");
1887 e_flags
&= ~ EF_ARM_RELEXEC
;
1890 if (e_flags
& EF_ARM_HASENTRY
)
1892 strcat (buf
, ", has entry point");
1893 e_flags
&= ~ EF_ARM_HASENTRY
;
1896 /* Now handle EABI specific flags. */
1900 strcat (buf
, ", <unrecognized EABI>");
1905 case EF_ARM_EABI_VER1
:
1906 strcat (buf
, ", Version1 EABI");
1911 /* Process flags one bit at a time. */
1912 flag
= e_flags
& - e_flags
;
1917 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1918 strcat (buf
, ", sorted symbol tables");
1928 case EF_ARM_EABI_VER2
:
1929 strcat (buf
, ", Version2 EABI");
1934 /* Process flags one bit at a time. */
1935 flag
= e_flags
& - e_flags
;
1940 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1941 strcat (buf
, ", sorted symbol tables");
1944 case EF_ARM_DYNSYMSUSESEGIDX
:
1945 strcat (buf
, ", dynamic symbols use segment index");
1948 case EF_ARM_MAPSYMSFIRST
:
1949 strcat (buf
, ", mapping symbols precede others");
1959 case EF_ARM_EABI_VER3
:
1960 strcat (buf
, ", Version3 EABI");
1963 case EF_ARM_EABI_VER4
:
1964 strcat (buf
, ", Version4 EABI");
1967 case EF_ARM_EABI_VER5
:
1968 strcat (buf
, ", Version5 EABI");
1974 /* Process flags one bit at a time. */
1975 flag
= e_flags
& - e_flags
;
1981 strcat (buf
, ", BE8");
1985 strcat (buf
, ", LE8");
1995 case EF_ARM_EABI_UNKNOWN
:
1996 strcat (buf
, ", GNU EABI");
2001 /* Process flags one bit at a time. */
2002 flag
= e_flags
& - e_flags
;
2007 case EF_ARM_INTERWORK
:
2008 strcat (buf
, ", interworking enabled");
2011 case EF_ARM_APCS_26
:
2012 strcat (buf
, ", uses APCS/26");
2015 case EF_ARM_APCS_FLOAT
:
2016 strcat (buf
, ", uses APCS/float");
2020 strcat (buf
, ", position independent");
2024 strcat (buf
, ", 8 bit structure alignment");
2027 case EF_ARM_NEW_ABI
:
2028 strcat (buf
, ", uses new ABI");
2031 case EF_ARM_OLD_ABI
:
2032 strcat (buf
, ", uses old ABI");
2035 case EF_ARM_SOFT_FLOAT
:
2036 strcat (buf
, ", software FP");
2039 case EF_ARM_VFP_FLOAT
:
2040 strcat (buf
, ", VFP");
2043 case EF_ARM_MAVERICK_FLOAT
:
2044 strcat (buf
, ", Maverick FP");
2055 strcat (buf
,", <unknown>");
2059 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
2061 static char buf
[1024];
2073 decode_ARM_machine_flags (e_flags
, buf
);
2077 switch (e_flags
& EF_FRV_CPU_MASK
)
2079 case EF_FRV_CPU_GENERIC
:
2083 strcat (buf
, ", fr???");
2086 case EF_FRV_CPU_FR300
:
2087 strcat (buf
, ", fr300");
2090 case EF_FRV_CPU_FR400
:
2091 strcat (buf
, ", fr400");
2093 case EF_FRV_CPU_FR405
:
2094 strcat (buf
, ", fr405");
2097 case EF_FRV_CPU_FR450
:
2098 strcat (buf
, ", fr450");
2101 case EF_FRV_CPU_FR500
:
2102 strcat (buf
, ", fr500");
2104 case EF_FRV_CPU_FR550
:
2105 strcat (buf
, ", fr550");
2108 case EF_FRV_CPU_SIMPLE
:
2109 strcat (buf
, ", simple");
2111 case EF_FRV_CPU_TOMCAT
:
2112 strcat (buf
, ", tomcat");
2118 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2119 strcat (buf
, ", m68000");
2120 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2121 strcat (buf
, ", cpu32");
2122 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2123 strcat (buf
, ", fido_a");
2126 char const * isa
= _("unknown");
2127 char const * mac
= _("unknown mac");
2128 char const * additional
= NULL
;
2130 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2132 case EF_M68K_CF_ISA_A_NODIV
:
2134 additional
= ", nodiv";
2136 case EF_M68K_CF_ISA_A
:
2139 case EF_M68K_CF_ISA_A_PLUS
:
2142 case EF_M68K_CF_ISA_B_NOUSP
:
2144 additional
= ", nousp";
2146 case EF_M68K_CF_ISA_B
:
2150 strcat (buf
, ", cf, isa ");
2153 strcat (buf
, additional
);
2154 if (e_flags
& EF_M68K_CF_FLOAT
)
2155 strcat (buf
, ", float");
2156 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2161 case EF_M68K_CF_MAC
:
2164 case EF_M68K_CF_EMAC
:
2177 if (e_flags
& EF_PPC_EMB
)
2178 strcat (buf
, ", emb");
2180 if (e_flags
& EF_PPC_RELOCATABLE
)
2181 strcat (buf
, ", relocatable");
2183 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2184 strcat (buf
, ", relocatable-lib");
2188 case EM_CYGNUS_V850
:
2189 switch (e_flags
& EF_V850_ARCH
)
2192 strcat (buf
, ", v850e1");
2195 strcat (buf
, ", v850e");
2198 strcat (buf
, ", v850");
2201 strcat (buf
, ", unknown v850 architecture variant");
2207 case EM_CYGNUS_M32R
:
2208 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2209 strcat (buf
, ", m32r");
2213 case EM_MIPS_RS3_LE
:
2214 if (e_flags
& EF_MIPS_NOREORDER
)
2215 strcat (buf
, ", noreorder");
2217 if (e_flags
& EF_MIPS_PIC
)
2218 strcat (buf
, ", pic");
2220 if (e_flags
& EF_MIPS_CPIC
)
2221 strcat (buf
, ", cpic");
2223 if (e_flags
& EF_MIPS_UCODE
)
2224 strcat (buf
, ", ugen_reserved");
2226 if (e_flags
& EF_MIPS_ABI2
)
2227 strcat (buf
, ", abi2");
2229 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2230 strcat (buf
, ", odk first");
2232 if (e_flags
& EF_MIPS_32BITMODE
)
2233 strcat (buf
, ", 32bitmode");
2235 switch ((e_flags
& EF_MIPS_MACH
))
2237 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2238 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2239 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2240 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2241 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2242 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2243 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2244 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2245 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2246 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2247 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
2248 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
2249 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
2250 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
2252 /* We simply ignore the field in this case to avoid confusion:
2253 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2256 default: strcat (buf
, ", unknown CPU"); break;
2259 switch ((e_flags
& EF_MIPS_ABI
))
2261 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2262 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2263 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2264 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2266 /* We simply ignore the field in this case to avoid confusion:
2267 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2268 This means it is likely to be an o32 file, but not for
2271 default: strcat (buf
, ", unknown ABI"); break;
2274 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2275 strcat (buf
, ", mdmx");
2277 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2278 strcat (buf
, ", mips16");
2280 switch ((e_flags
& EF_MIPS_ARCH
))
2282 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2283 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2284 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2285 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2286 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2287 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2288 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2289 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2290 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2291 default: strcat (buf
, ", unknown ISA"); break;
2297 switch ((e_flags
& EF_SH_MACH_MASK
))
2299 case EF_SH1
: strcat (buf
, ", sh1"); break;
2300 case EF_SH2
: strcat (buf
, ", sh2"); break;
2301 case EF_SH3
: strcat (buf
, ", sh3"); break;
2302 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2303 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2304 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2305 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2306 case EF_SH4
: strcat (buf
, ", sh4"); break;
2307 case EF_SH5
: strcat (buf
, ", sh5"); break;
2308 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2309 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2310 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2311 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2312 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2313 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2314 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2315 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2316 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2317 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2318 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2319 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2320 default: strcat (buf
, ", unknown ISA"); break;
2326 if (e_flags
& EF_SPARC_32PLUS
)
2327 strcat (buf
, ", v8+");
2329 if (e_flags
& EF_SPARC_SUN_US1
)
2330 strcat (buf
, ", ultrasparcI");
2332 if (e_flags
& EF_SPARC_SUN_US3
)
2333 strcat (buf
, ", ultrasparcIII");
2335 if (e_flags
& EF_SPARC_HAL_R1
)
2336 strcat (buf
, ", halr1");
2338 if (e_flags
& EF_SPARC_LEDATA
)
2339 strcat (buf
, ", ledata");
2341 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2342 strcat (buf
, ", tso");
2344 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2345 strcat (buf
, ", pso");
2347 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2348 strcat (buf
, ", rmo");
2352 switch (e_flags
& EF_PARISC_ARCH
)
2354 case EFA_PARISC_1_0
:
2355 strcpy (buf
, ", PA-RISC 1.0");
2357 case EFA_PARISC_1_1
:
2358 strcpy (buf
, ", PA-RISC 1.1");
2360 case EFA_PARISC_2_0
:
2361 strcpy (buf
, ", PA-RISC 2.0");
2366 if (e_flags
& EF_PARISC_TRAPNIL
)
2367 strcat (buf
, ", trapnil");
2368 if (e_flags
& EF_PARISC_EXT
)
2369 strcat (buf
, ", ext");
2370 if (e_flags
& EF_PARISC_LSB
)
2371 strcat (buf
, ", lsb");
2372 if (e_flags
& EF_PARISC_WIDE
)
2373 strcat (buf
, ", wide");
2374 if (e_flags
& EF_PARISC_NO_KABP
)
2375 strcat (buf
, ", no kabp");
2376 if (e_flags
& EF_PARISC_LAZYSWAP
)
2377 strcat (buf
, ", lazyswap");
2382 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2383 strcat (buf
, ", new calling convention");
2385 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2386 strcat (buf
, ", gnu calling convention");
2390 if ((e_flags
& EF_IA_64_ABI64
))
2391 strcat (buf
, ", 64-bit");
2393 strcat (buf
, ", 32-bit");
2394 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2395 strcat (buf
, ", reduced fp model");
2396 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2397 strcat (buf
, ", no function descriptors, constant gp");
2398 else if ((e_flags
& EF_IA_64_CONS_GP
))
2399 strcat (buf
, ", constant gp");
2400 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2401 strcat (buf
, ", absolute");
2405 if ((e_flags
& EF_VAX_NONPIC
))
2406 strcat (buf
, ", non-PIC");
2407 if ((e_flags
& EF_VAX_DFLOAT
))
2408 strcat (buf
, ", D-Float");
2409 if ((e_flags
& EF_VAX_GFLOAT
))
2410 strcat (buf
, ", G-Float");
2419 get_osabi_name (unsigned int osabi
)
2421 static char buff
[32];
2425 case ELFOSABI_NONE
: return "UNIX - System V";
2426 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2427 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2428 case ELFOSABI_LINUX
: return "UNIX - Linux";
2429 case ELFOSABI_HURD
: return "GNU/Hurd";
2430 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2431 case ELFOSABI_AIX
: return "UNIX - AIX";
2432 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2433 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2434 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2435 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2436 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2437 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2438 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2439 case ELFOSABI_AROS
: return "AROS";
2440 case ELFOSABI_STANDALONE
: return _("Standalone App");
2441 case ELFOSABI_ARM
: return "ARM";
2443 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2449 get_arm_segment_type (unsigned long type
)
2463 get_mips_segment_type (unsigned long type
)
2467 case PT_MIPS_REGINFO
:
2469 case PT_MIPS_RTPROC
:
2471 case PT_MIPS_OPTIONS
:
2481 get_parisc_segment_type (unsigned long type
)
2485 case PT_HP_TLS
: return "HP_TLS";
2486 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2487 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2488 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2489 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2490 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2491 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2492 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2493 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2494 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2495 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2496 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2497 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2498 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2499 case PT_HP_STACK
: return "HP_STACK";
2500 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2501 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2502 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2503 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2512 get_ia64_segment_type (unsigned long type
)
2516 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2517 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2518 case PT_HP_TLS
: return "HP_TLS";
2519 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2520 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2521 case PT_IA_64_HP_STACK
: return "HP_STACK";
2530 get_segment_type (unsigned long p_type
)
2532 static char buff
[32];
2536 case PT_NULL
: return "NULL";
2537 case PT_LOAD
: return "LOAD";
2538 case PT_DYNAMIC
: return "DYNAMIC";
2539 case PT_INTERP
: return "INTERP";
2540 case PT_NOTE
: return "NOTE";
2541 case PT_SHLIB
: return "SHLIB";
2542 case PT_PHDR
: return "PHDR";
2543 case PT_TLS
: return "TLS";
2545 case PT_GNU_EH_FRAME
:
2546 return "GNU_EH_FRAME";
2547 case PT_GNU_STACK
: return "GNU_STACK";
2548 case PT_GNU_RELRO
: return "GNU_RELRO";
2551 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2553 const char * result
;
2555 switch (elf_header
.e_machine
)
2558 result
= get_arm_segment_type (p_type
);
2561 case EM_MIPS_RS3_LE
:
2562 result
= get_mips_segment_type (p_type
);
2565 result
= get_parisc_segment_type (p_type
);
2568 result
= get_ia64_segment_type (p_type
);
2578 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2580 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2582 const char * result
;
2584 switch (elf_header
.e_machine
)
2587 result
= get_parisc_segment_type (p_type
);
2590 result
= get_ia64_segment_type (p_type
);
2600 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2603 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2610 get_mips_section_type_name (unsigned int sh_type
)
2614 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2615 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2616 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2617 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2618 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2619 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2620 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2621 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2622 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2623 case SHT_MIPS_RELD
: return "MIPS_RELD";
2624 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2625 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2626 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2627 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2628 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2629 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2630 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2631 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2632 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2633 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2634 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2635 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2636 case SHT_MIPS_LINE
: return "MIPS_LINE";
2637 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2638 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2639 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2640 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2641 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2642 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2643 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2644 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2645 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2646 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2647 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2648 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2649 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2650 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2651 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2652 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2660 get_parisc_section_type_name (unsigned int sh_type
)
2664 case SHT_PARISC_EXT
: return "PARISC_EXT";
2665 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2666 case SHT_PARISC_DOC
: return "PARISC_DOC";
2667 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2668 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2669 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2670 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2678 get_ia64_section_type_name (unsigned int sh_type
)
2680 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2681 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2682 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2686 case SHT_IA_64_EXT
: return "IA_64_EXT";
2687 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2688 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2689 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
2690 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
2691 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
2692 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
2693 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
2694 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
2695 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
2703 get_x86_64_section_type_name (unsigned int sh_type
)
2707 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2715 get_arm_section_type_name (unsigned int sh_type
)
2721 case SHT_ARM_PREEMPTMAP
:
2722 return "ARM_PREEMPTMAP";
2723 case SHT_ARM_ATTRIBUTES
:
2724 return "ARM_ATTRIBUTES";
2732 get_section_type_name (unsigned int sh_type
)
2734 static char buff
[32];
2738 case SHT_NULL
: return "NULL";
2739 case SHT_PROGBITS
: return "PROGBITS";
2740 case SHT_SYMTAB
: return "SYMTAB";
2741 case SHT_STRTAB
: return "STRTAB";
2742 case SHT_RELA
: return "RELA";
2743 case SHT_HASH
: return "HASH";
2744 case SHT_DYNAMIC
: return "DYNAMIC";
2745 case SHT_NOTE
: return "NOTE";
2746 case SHT_NOBITS
: return "NOBITS";
2747 case SHT_REL
: return "REL";
2748 case SHT_SHLIB
: return "SHLIB";
2749 case SHT_DYNSYM
: return "DYNSYM";
2750 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2751 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2752 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2753 case SHT_GNU_HASH
: return "GNU_HASH";
2754 case SHT_GROUP
: return "GROUP";
2755 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2756 case SHT_GNU_verdef
: return "VERDEF";
2757 case SHT_GNU_verneed
: return "VERNEED";
2758 case SHT_GNU_versym
: return "VERSYM";
2759 case 0x6ffffff0: return "VERSYM";
2760 case 0x6ffffffc: return "VERDEF";
2761 case 0x7ffffffd: return "AUXILIARY";
2762 case 0x7fffffff: return "FILTER";
2763 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2766 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2768 const char * result
;
2770 switch (elf_header
.e_machine
)
2773 case EM_MIPS_RS3_LE
:
2774 result
= get_mips_section_type_name (sh_type
);
2777 result
= get_parisc_section_type_name (sh_type
);
2780 result
= get_ia64_section_type_name (sh_type
);
2784 result
= get_x86_64_section_type_name (sh_type
);
2787 result
= get_arm_section_type_name (sh_type
);
2797 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2799 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2801 const char * result
;
2803 switch (elf_header
.e_machine
)
2806 result
= get_ia64_section_type_name (sh_type
);
2816 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2818 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2819 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2821 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2827 #define OPTION_DEBUG_DUMP 512
2829 static struct option options
[] =
2831 {"all", no_argument
, 0, 'a'},
2832 {"file-header", no_argument
, 0, 'h'},
2833 {"program-headers", no_argument
, 0, 'l'},
2834 {"headers", no_argument
, 0, 'e'},
2835 {"histogram", no_argument
, 0, 'I'},
2836 {"segments", no_argument
, 0, 'l'},
2837 {"sections", no_argument
, 0, 'S'},
2838 {"section-headers", no_argument
, 0, 'S'},
2839 {"section-groups", no_argument
, 0, 'g'},
2840 {"section-details", no_argument
, 0, 't'},
2841 {"full-section-name",no_argument
, 0, 'N'},
2842 {"symbols", no_argument
, 0, 's'},
2843 {"syms", no_argument
, 0, 's'},
2844 {"relocs", no_argument
, 0, 'r'},
2845 {"notes", no_argument
, 0, 'n'},
2846 {"dynamic", no_argument
, 0, 'd'},
2847 {"arch-specific", no_argument
, 0, 'A'},
2848 {"version-info", no_argument
, 0, 'V'},
2849 {"use-dynamic", no_argument
, 0, 'D'},
2850 {"unwind", no_argument
, 0, 'u'},
2851 {"archive-index", no_argument
, 0, 'c'},
2852 {"hex-dump", required_argument
, 0, 'x'},
2853 {"relocated-dump", required_argument
, 0, 'R'},
2854 {"string-dump", required_argument
, 0, 'p'},
2855 #ifdef SUPPORT_DISASSEMBLY
2856 {"instruction-dump", required_argument
, 0, 'i'},
2858 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2860 {"version", no_argument
, 0, 'v'},
2861 {"wide", no_argument
, 0, 'W'},
2862 {"help", no_argument
, 0, 'H'},
2863 {0, no_argument
, 0, 0}
2867 usage (FILE * stream
)
2869 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2870 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
2871 fprintf (stream
, _(" Options are:\n\
2872 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2873 -h --file-header Display the ELF file header\n\
2874 -l --program-headers Display the program headers\n\
2875 --segments An alias for --program-headers\n\
2876 -S --section-headers Display the sections' header\n\
2877 --sections An alias for --section-headers\n\
2878 -g --section-groups Display the section groups\n\
2879 -t --section-details Display the section details\n\
2880 -e --headers Equivalent to: -h -l -S\n\
2881 -s --syms Display the symbol table\n\
2882 --symbols An alias for --syms\n\
2883 -n --notes Display the core notes (if present)\n\
2884 -r --relocs Display the relocations (if present)\n\
2885 -u --unwind Display the unwind info (if present)\n\
2886 -d --dynamic Display the dynamic section (if present)\n\
2887 -V --version-info Display the version sections (if present)\n\
2888 -A --arch-specific Display architecture specific information (if any).\n\
2889 -c --archive-index Display the symbol/file index in an archive\n\
2890 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2891 -x --hex-dump=<number|name>\n\
2892 Dump the contents of section <number|name> as bytes\n\
2893 -p --string-dump=<number|name>\n\
2894 Dump the contents of section <number|name> as strings\n\
2895 -R --relocated-dump=<number|name>\n\
2896 Dump the contents of section <number|name> as relocated bytes\n\
2897 -w[lLiaprmfFsoR] or\n\
2898 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2899 Display the contents of DWARF2 debug sections\n"));
2900 #ifdef SUPPORT_DISASSEMBLY
2901 fprintf (stream
, _("\
2902 -i --instruction-dump=<number|name>\n\
2903 Disassemble the contents of section <number|name>\n"));
2905 fprintf (stream
, _("\
2906 -I --histogram Display histogram of bucket list lengths\n\
2907 -W --wide Allow output width to exceed 80 characters\n\
2908 @<file> Read options from <file>\n\
2909 -H --help Display this information\n\
2910 -v --version Display the version number of readelf\n"));
2912 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2913 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2915 exit (stream
== stdout
? 0 : 1);
2918 /* Record the fact that the user wants the contents of section number
2919 SECTION to be displayed using the method(s) encoded as flags bits
2920 in TYPE. Note, TYPE can be zero if we are creating the array for
2924 request_dump_bynumber (unsigned int section
, dump_type type
)
2926 if (section
>= num_dump_sects
)
2928 dump_type
* new_dump_sects
;
2930 new_dump_sects
= calloc (section
+ 1, sizeof (* dump_sects
));
2932 if (new_dump_sects
== NULL
)
2933 error (_("Out of memory allocating dump request table.\n"));
2936 /* Copy current flag settings. */
2937 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
* sizeof (* dump_sects
));
2941 dump_sects
= new_dump_sects
;
2942 num_dump_sects
= section
+ 1;
2947 dump_sects
[section
] |= type
;
2952 /* Request a dump by section name. */
2955 request_dump_byname (const char * section
, dump_type type
)
2957 struct dump_list_entry
* new_request
;
2959 new_request
= malloc (sizeof (struct dump_list_entry
));
2961 error (_("Out of memory allocating dump request table.\n"));
2963 new_request
->name
= strdup (section
);
2964 if (!new_request
->name
)
2965 error (_("Out of memory allocating dump request table.\n"));
2967 new_request
->type
= type
;
2969 new_request
->next
= dump_sects_byname
;
2970 dump_sects_byname
= new_request
;
2974 request_dump (dump_type type
)
2980 section
= strtoul (optarg
, & cp
, 0);
2982 if (! *cp
&& section
>= 0)
2983 request_dump_bynumber (section
, type
);
2985 request_dump_byname (optarg
, type
);
2990 parse_args (int argc
, char ** argv
)
2997 while ((c
= getopt_long
2998 (argc
, argv
, "ADHINR:SVWacdeghi:lnp:rstuvw::x:", options
, NULL
)) != EOF
)
3016 do_section_groups
++;
3024 do_section_groups
++;
3029 do_section_details
++;
3073 request_dump (HEX_DUMP
);
3076 request_dump (STRING_DUMP
);
3079 request_dump (RELOC_DUMP
);
3086 dwarf_select_sections_all ();
3091 dwarf_select_sections_by_letters (optarg
);
3094 case OPTION_DEBUG_DUMP
:
3101 dwarf_select_sections_by_names (optarg
);
3104 #ifdef SUPPORT_DISASSEMBLY
3106 request_dump (DISASS_DUMP
);
3110 print_version (program_name
);
3119 /* xgettext:c-format */
3120 error (_("Invalid option '-%c'\n"), c
);
3127 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3128 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3129 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3130 && !do_section_groups
&& !do_archive_index
)
3134 warn (_("Nothing to do.\n"));
3140 get_elf_class (unsigned int elf_class
)
3142 static char buff
[32];
3146 case ELFCLASSNONE
: return _("none");
3147 case ELFCLASS32
: return "ELF32";
3148 case ELFCLASS64
: return "ELF64";
3150 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3156 get_data_encoding (unsigned int encoding
)
3158 static char buff
[32];
3162 case ELFDATANONE
: return _("none");
3163 case ELFDATA2LSB
: return _("2's complement, little endian");
3164 case ELFDATA2MSB
: return _("2's complement, big endian");
3166 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3171 /* Decode the data held in 'elf_header'. */
3174 process_file_header (void)
3176 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3177 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3178 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3179 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3182 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3186 init_dwarf_regnames (elf_header
.e_machine
);
3192 printf (_("ELF Header:\n"));
3193 printf (_(" Magic: "));
3194 for (i
= 0; i
< EI_NIDENT
; i
++)
3195 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3197 printf (_(" Class: %s\n"),
3198 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3199 printf (_(" Data: %s\n"),
3200 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3201 printf (_(" Version: %d %s\n"),
3202 elf_header
.e_ident
[EI_VERSION
],
3203 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3205 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3208 printf (_(" OS/ABI: %s\n"),
3209 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3210 printf (_(" ABI Version: %d\n"),
3211 elf_header
.e_ident
[EI_ABIVERSION
]);
3212 printf (_(" Type: %s\n"),
3213 get_file_type (elf_header
.e_type
));
3214 printf (_(" Machine: %s\n"),
3215 get_machine_name (elf_header
.e_machine
));
3216 printf (_(" Version: 0x%lx\n"),
3217 (unsigned long) elf_header
.e_version
);
3219 printf (_(" Entry point address: "));
3220 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3221 printf (_("\n Start of program headers: "));
3222 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3223 printf (_(" (bytes into file)\n Start of section headers: "));
3224 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3225 printf (_(" (bytes into file)\n"));
3227 printf (_(" Flags: 0x%lx%s\n"),
3228 (unsigned long) elf_header
.e_flags
,
3229 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3230 printf (_(" Size of this header: %ld (bytes)\n"),
3231 (long) elf_header
.e_ehsize
);
3232 printf (_(" Size of program headers: %ld (bytes)\n"),
3233 (long) elf_header
.e_phentsize
);
3234 printf (_(" Number of program headers: %ld\n"),
3235 (long) elf_header
.e_phnum
);
3236 printf (_(" Size of section headers: %ld (bytes)\n"),
3237 (long) elf_header
.e_shentsize
);
3238 printf (_(" Number of section headers: %ld"),
3239 (long) elf_header
.e_shnum
);
3240 if (section_headers
!= NULL
&& elf_header
.e_shnum
== SHN_UNDEF
)
3241 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3242 putc ('\n', stdout
);
3243 printf (_(" Section header string table index: %ld"),
3244 (long) elf_header
.e_shstrndx
);
3245 if (section_headers
!= NULL
3246 && elf_header
.e_shstrndx
== (SHN_XINDEX
& 0xffff))
3247 printf (" (%u)", section_headers
[0].sh_link
);
3248 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3249 && elf_header
.e_shstrndx
>= elf_header
.e_shnum
)
3250 printf (" <corrupt: out of range>");
3251 putc ('\n', stdout
);
3254 if (section_headers
!= NULL
)
3256 if (elf_header
.e_shnum
== SHN_UNDEF
)
3257 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3258 if (elf_header
.e_shstrndx
== (SHN_XINDEX
& 0xffff))
3259 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3260 else if (elf_header
.e_shstrndx
>= elf_header
.e_shnum
)
3261 elf_header
.e_shstrndx
= SHN_UNDEF
;
3262 free (section_headers
);
3263 section_headers
= NULL
;
3271 get_32bit_program_headers (FILE * file
, Elf_Internal_Phdr
* program_headers
)
3273 Elf32_External_Phdr
* phdrs
;
3274 Elf32_External_Phdr
* external
;
3275 Elf_Internal_Phdr
* internal
;
3278 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3279 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3280 _("program headers"));
3284 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3285 i
< elf_header
.e_phnum
;
3286 i
++, internal
++, external
++)
3288 internal
->p_type
= BYTE_GET (external
->p_type
);
3289 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3290 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3291 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3292 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3293 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3294 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3295 internal
->p_align
= BYTE_GET (external
->p_align
);
3304 get_64bit_program_headers (FILE * file
, Elf_Internal_Phdr
* program_headers
)
3306 Elf64_External_Phdr
* phdrs
;
3307 Elf64_External_Phdr
* external
;
3308 Elf_Internal_Phdr
* internal
;
3311 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3312 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3313 _("program headers"));
3317 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3318 i
< elf_header
.e_phnum
;
3319 i
++, internal
++, external
++)
3321 internal
->p_type
= BYTE_GET (external
->p_type
);
3322 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3323 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3324 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3325 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3326 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3327 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3328 internal
->p_align
= BYTE_GET (external
->p_align
);
3336 /* Returns 1 if the program headers were read into `program_headers'. */
3339 get_program_headers (FILE * file
)
3341 Elf_Internal_Phdr
* phdrs
;
3343 /* Check cache of prior read. */
3344 if (program_headers
!= NULL
)
3347 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3351 error (_("Out of memory\n"));
3356 ? get_32bit_program_headers (file
, phdrs
)
3357 : get_64bit_program_headers (file
, phdrs
))
3359 program_headers
= phdrs
;
3367 /* Returns 1 if the program headers were loaded. */
3370 process_program_headers (FILE * file
)
3372 Elf_Internal_Phdr
* segment
;
3375 if (elf_header
.e_phnum
== 0)
3378 printf (_("\nThere are no program headers in this file.\n"));
3382 if (do_segments
&& !do_header
)
3384 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3385 printf (_("Entry point "));
3386 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3387 printf (_("\nThere are %d program headers, starting at offset "),
3388 elf_header
.e_phnum
);
3389 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3393 if (! get_program_headers (file
))
3398 if (elf_header
.e_phnum
> 1)
3399 printf (_("\nProgram Headers:\n"));
3401 printf (_("\nProgram Headers:\n"));
3405 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3408 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3412 (_(" Type Offset VirtAddr PhysAddr\n"));
3414 (_(" FileSiz MemSiz Flags Align\n"));
3421 for (i
= 0, segment
= program_headers
;
3422 i
< elf_header
.e_phnum
;
3427 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3431 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3432 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3433 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3434 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3435 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3437 (segment
->p_flags
& PF_R
? 'R' : ' '),
3438 (segment
->p_flags
& PF_W
? 'W' : ' '),
3439 (segment
->p_flags
& PF_X
? 'E' : ' '));
3440 printf ("%#lx", (unsigned long) segment
->p_align
);
3444 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3445 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3448 print_vma (segment
->p_offset
, FULL_HEX
);
3452 print_vma (segment
->p_vaddr
, FULL_HEX
);
3454 print_vma (segment
->p_paddr
, FULL_HEX
);
3457 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3458 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3461 print_vma (segment
->p_filesz
, FULL_HEX
);
3465 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3466 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3469 print_vma (segment
->p_offset
, FULL_HEX
);
3473 (segment
->p_flags
& PF_R
? 'R' : ' '),
3474 (segment
->p_flags
& PF_W
? 'W' : ' '),
3475 (segment
->p_flags
& PF_X
? 'E' : ' '));
3477 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3478 printf ("%#lx", (unsigned long) segment
->p_align
);
3481 print_vma (segment
->p_align
, PREFIX_HEX
);
3486 print_vma (segment
->p_offset
, FULL_HEX
);
3488 print_vma (segment
->p_vaddr
, FULL_HEX
);
3490 print_vma (segment
->p_paddr
, FULL_HEX
);
3492 print_vma (segment
->p_filesz
, FULL_HEX
);
3494 print_vma (segment
->p_memsz
, FULL_HEX
);
3496 (segment
->p_flags
& PF_R
? 'R' : ' '),
3497 (segment
->p_flags
& PF_W
? 'W' : ' '),
3498 (segment
->p_flags
& PF_X
? 'E' : ' '));
3499 print_vma (segment
->p_align
, HEX
);
3503 switch (segment
->p_type
)
3507 error (_("more than one dynamic segment\n"));
3509 /* By default, assume that the .dynamic section is the first
3510 section in the DYNAMIC segment. */
3511 dynamic_addr
= segment
->p_offset
;
3512 dynamic_size
= segment
->p_filesz
;
3514 /* Try to locate the .dynamic section. If there is
3515 a section header table, we can easily locate it. */
3516 if (section_headers
!= NULL
)
3518 Elf_Internal_Shdr
* sec
;
3520 sec
= find_section (".dynamic");
3521 if (sec
== NULL
|| sec
->sh_size
== 0)
3523 error (_("no .dynamic section in the dynamic segment\n"));
3527 if (sec
->sh_type
== SHT_NOBITS
)
3533 dynamic_addr
= sec
->sh_offset
;
3534 dynamic_size
= sec
->sh_size
;
3536 if (dynamic_addr
< segment
->p_offset
3537 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3538 warn (_("the .dynamic section is not contained"
3539 " within the dynamic segment\n"));
3540 else if (dynamic_addr
> segment
->p_offset
)
3541 warn (_("the .dynamic section is not the first section"
3542 " in the dynamic segment.\n"));
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
+ 1;
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"),
3628 (unsigned long) vma
);
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
- 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
& 0xffff) && shndx
!= NULL
)
3766 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3767 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
3768 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
3769 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3770 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3780 static Elf_Internal_Sym
*
3781 get_64bit_elf_symbols (FILE * file
, Elf_Internal_Shdr
* section
)
3783 unsigned long number
;
3784 Elf64_External_Sym
* esyms
;
3785 Elf_External_Sym_Shndx
* shndx
;
3786 Elf_Internal_Sym
* isyms
;
3787 Elf_Internal_Sym
* psym
;
3790 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3796 if (symtab_shndx_hdr
!= NULL
3797 && (symtab_shndx_hdr
->sh_link
3798 == (unsigned long) (section
- section_headers
)))
3800 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3801 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3809 number
= section
->sh_size
/ section
->sh_entsize
;
3810 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3814 error (_("Out of memory\n"));
3821 for (j
= 0, psym
= isyms
;
3825 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3826 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3827 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3828 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3829 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
3831 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3832 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
3833 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
3834 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3835 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3846 get_elf_section_flags (bfd_vma sh_flags
)
3848 static char buff
[1024];
3850 int field_size
= is_32bit_elf
? 8 : 16;
3851 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3852 bfd_vma os_flags
= 0;
3853 bfd_vma proc_flags
= 0;
3854 bfd_vma unknown_flags
= 0;
3868 { "LINK ORDER", 10 },
3869 { "OS NONCONF", 10 },
3872 /* IA-64 specific. */
3875 /* IA-64 OpenVMS specific. */
3876 { "VMS_GLOBAL", 10 },
3877 { "VMS_OVERLAID", 12 },
3878 { "VMS_SHARED", 10 },
3879 { "VMS_VECTOR", 10 },
3880 { "VMS_ALLOC_64BIT", 15 },
3881 { "VMS_PROTECTED", 13}
3884 if (do_section_details
)
3886 sprintf (buff
, "[%*.*lx]: ",
3887 field_size
, field_size
, (unsigned long) sh_flags
);
3888 p
+= field_size
+ 4;
3895 flag
= sh_flags
& - sh_flags
;
3898 if (do_section_details
)
3902 case SHF_WRITE
: index
= 0; break;
3903 case SHF_ALLOC
: index
= 1; break;
3904 case SHF_EXECINSTR
: index
= 2; break;
3905 case SHF_MERGE
: index
= 3; break;
3906 case SHF_STRINGS
: index
= 4; break;
3907 case SHF_INFO_LINK
: index
= 5; break;
3908 case SHF_LINK_ORDER
: index
= 6; break;
3909 case SHF_OS_NONCONFORMING
: index
= 7; break;
3910 case SHF_GROUP
: index
= 8; break;
3911 case SHF_TLS
: index
= 9; break;
3915 if (elf_header
.e_machine
== EM_IA_64
)
3917 if (flag
== SHF_IA_64_SHORT
)
3919 else if (flag
== SHF_IA_64_NORECOV
)
3922 else if (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3925 case SHF_IA_64_VMS_GLOBAL
: index
= 12; break;
3926 case SHF_IA_64_VMS_OVERLAID
: index
= 13; break;
3927 case SHF_IA_64_VMS_SHARED
: index
= 14; break;
3928 case SHF_IA_64_VMS_VECTOR
: index
= 15; break;
3929 case SHF_IA_64_VMS_ALLOC_64BIT
: index
= 16; break;
3930 case SHF_IA_64_VMS_PROTECTED
: index
= 17; break;
3940 if (p
!= buff
+ field_size
+ 4)
3942 if (size
< (10 + 2))
3949 size
-= flags
[index
].len
;
3950 p
= stpcpy (p
, flags
[index
].str
);
3952 else if (flag
& SHF_MASKOS
)
3954 else if (flag
& SHF_MASKPROC
)
3957 unknown_flags
|= flag
;
3963 case SHF_WRITE
: *p
= 'W'; break;
3964 case SHF_ALLOC
: *p
= 'A'; break;
3965 case SHF_EXECINSTR
: *p
= 'X'; break;
3966 case SHF_MERGE
: *p
= 'M'; break;
3967 case SHF_STRINGS
: *p
= 'S'; break;
3968 case SHF_INFO_LINK
: *p
= 'I'; break;
3969 case SHF_LINK_ORDER
: *p
= 'L'; break;
3970 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3971 case SHF_GROUP
: *p
= 'G'; break;
3972 case SHF_TLS
: *p
= 'T'; break;
3975 if ((elf_header
.e_machine
== EM_X86_64
3976 || elf_header
.e_machine
== EM_L1OM
)
3977 && flag
== SHF_X86_64_LARGE
)
3979 else if (flag
& SHF_MASKOS
)
3982 sh_flags
&= ~ SHF_MASKOS
;
3984 else if (flag
& SHF_MASKPROC
)
3987 sh_flags
&= ~ SHF_MASKPROC
;
3997 if (do_section_details
)
4001 size
-= 5 + field_size
;
4002 if (p
!= buff
+ field_size
+ 4)
4010 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
4011 (unsigned long) os_flags
);
4012 p
+= 5 + field_size
;
4016 size
-= 7 + field_size
;
4017 if (p
!= buff
+ field_size
+ 4)
4025 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
4026 (unsigned long) proc_flags
);
4027 p
+= 7 + field_size
;
4031 size
-= 10 + field_size
;
4032 if (p
!= buff
+ field_size
+ 4)
4040 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
4041 (unsigned long) unknown_flags
);
4042 p
+= 10 + field_size
;
4051 process_section_headers (FILE * file
)
4053 Elf_Internal_Shdr
* section
;
4056 section_headers
= NULL
;
4058 if (elf_header
.e_shnum
== 0)
4061 printf (_("\nThere are no sections in this file.\n"));
4066 if (do_sections
&& !do_header
)
4067 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4068 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4072 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4075 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4078 /* Read in the string table, so that we have names to display. */
4079 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4080 && elf_header
.e_shstrndx
< elf_header
.e_shnum
)
4082 section
= section_headers
+ elf_header
.e_shstrndx
;
4084 if (section
->sh_size
!= 0)
4086 string_table
= get_data (NULL
, file
, section
->sh_offset
,
4087 1, section
->sh_size
, _("string table"));
4089 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4093 /* Scan the sections for the dynamic symbol table
4094 and dynamic string table and debug sections. */
4095 dynamic_symbols
= NULL
;
4096 dynamic_strings
= NULL
;
4097 dynamic_syminfo
= NULL
;
4098 symtab_shndx_hdr
= NULL
;
4100 eh_addr_size
= is_32bit_elf
? 4 : 8;
4101 switch (elf_header
.e_machine
)
4104 case EM_MIPS_RS3_LE
:
4105 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4106 FDE addresses. However, the ABI also has a semi-official ILP32
4107 variant for which the normal FDE address size rules apply.
4109 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4110 section, where XX is the size of longs in bits. Unfortunately,
4111 earlier compilers provided no way of distinguishing ILP32 objects
4112 from LP64 objects, so if there's any doubt, we should assume that
4113 the official LP64 form is being used. */
4114 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4115 && find_section (".gcc_compiled_long32") == NULL
)
4121 switch (elf_header
.e_flags
& EF_H8_MACH
)
4123 case E_H8_MACH_H8300
:
4124 case E_H8_MACH_H8300HN
:
4125 case E_H8_MACH_H8300SN
:
4126 case E_H8_MACH_H8300SXN
:
4129 case E_H8_MACH_H8300H
:
4130 case E_H8_MACH_H8300S
:
4131 case E_H8_MACH_H8300SX
:
4139 switch (elf_header
.e_flags
& EF_M32C_CPU_MASK
)
4141 case EF_M32C_CPU_M16C
:
4148 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4151 size_t expected_entsize \
4152 = is_32bit_elf ? size32 : size64; \
4153 if (section->sh_entsize != expected_entsize) \
4154 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4155 i, (unsigned long int) section->sh_entsize, \
4156 (unsigned long int) expected_entsize); \
4157 section->sh_entsize = expected_entsize; \
4160 #define CHECK_ENTSIZE(section, i, type) \
4161 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4162 sizeof (Elf64_External_##type))
4164 for (i
= 0, section
= section_headers
;
4165 i
< elf_header
.e_shnum
;
4168 char * name
= SECTION_NAME (section
);
4170 if (section
->sh_type
== SHT_DYNSYM
)
4172 if (dynamic_symbols
!= NULL
)
4174 error (_("File contains multiple dynamic symbol tables\n"));
4178 CHECK_ENTSIZE (section
, i
, Sym
);
4179 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4180 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4182 else if (section
->sh_type
== SHT_STRTAB
4183 && streq (name
, ".dynstr"))
4185 if (dynamic_strings
!= NULL
)
4187 error (_("File contains multiple dynamic string tables\n"));
4191 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
4192 1, section
->sh_size
, _("dynamic strings"));
4193 dynamic_strings_length
= section
->sh_size
;
4195 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4197 if (symtab_shndx_hdr
!= NULL
)
4199 error (_("File contains multiple symtab shndx tables\n"));
4202 symtab_shndx_hdr
= section
;
4204 else if (section
->sh_type
== SHT_SYMTAB
)
4205 CHECK_ENTSIZE (section
, i
, Sym
);
4206 else if (section
->sh_type
== SHT_GROUP
)
4207 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4208 else if (section
->sh_type
== SHT_REL
)
4209 CHECK_ENTSIZE (section
, i
, Rel
);
4210 else if (section
->sh_type
== SHT_RELA
)
4211 CHECK_ENTSIZE (section
, i
, Rela
);
4212 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4213 || do_debug_lines
|| do_debug_pubnames
4214 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
4215 || do_debug_str
|| do_debug_loc
|| do_debug_ranges
)
4216 && (const_strneq (name
, ".debug_")
4217 || const_strneq (name
, ".zdebug_")))
4220 name
+= sizeof (".zdebug_") - 1;
4222 name
+= sizeof (".debug_") - 1;
4225 || (do_debug_info
&& streq (name
, "info"))
4226 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4227 || (do_debug_lines
&& streq (name
, "line"))
4228 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4229 || (do_debug_aranges
&& streq (name
, "aranges"))
4230 || (do_debug_ranges
&& streq (name
, "ranges"))
4231 || (do_debug_frames
&& streq (name
, "frame"))
4232 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4233 || (do_debug_str
&& streq (name
, "str"))
4234 || (do_debug_loc
&& streq (name
, "loc"))
4236 request_dump_bynumber (i
, DEBUG_DUMP
);
4238 /* Linkonce section to be combined with .debug_info at link time. */
4239 else if ((do_debugging
|| do_debug_info
)
4240 && const_strneq (name
, ".gnu.linkonce.wi."))
4241 request_dump_bynumber (i
, DEBUG_DUMP
);
4242 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4243 request_dump_bynumber (i
, DEBUG_DUMP
);
4249 if (elf_header
.e_shnum
> 1)
4250 printf (_("\nSection Headers:\n"));
4252 printf (_("\nSection Header:\n"));
4256 if (do_section_details
)
4258 printf (_(" [Nr] Name\n"));
4259 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4263 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4267 if (do_section_details
)
4269 printf (_(" [Nr] Name\n"));
4270 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4274 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4278 if (do_section_details
)
4280 printf (_(" [Nr] Name\n"));
4281 printf (_(" Type Address Offset Link\n"));
4282 printf (_(" Size EntSize Info Align\n"));
4286 printf (_(" [Nr] Name Type Address Offset\n"));
4287 printf (_(" Size EntSize Flags Link Info Align\n"));
4291 if (do_section_details
)
4292 printf (_(" Flags\n"));
4294 for (i
= 0, section
= section_headers
;
4295 i
< elf_header
.e_shnum
;
4298 if (do_section_details
)
4300 printf (" [%2u] %s\n",
4302 SECTION_NAME (section
));
4303 if (is_32bit_elf
|| do_wide
)
4304 printf (" %-15.15s ",
4305 get_section_type_name (section
->sh_type
));
4308 printf ((do_wide
? " [%2u] %-17s %-15s "
4309 : " [%2u] %-17.17s %-15.15s "),
4311 SECTION_NAME (section
),
4312 get_section_type_name (section
->sh_type
));
4316 print_vma (section
->sh_addr
, LONG_HEX
);
4318 printf ( " %6.6lx %6.6lx %2.2lx",
4319 (unsigned long) section
->sh_offset
,
4320 (unsigned long) section
->sh_size
,
4321 (unsigned long) section
->sh_entsize
);
4323 if (do_section_details
)
4324 fputs (" ", stdout
);
4326 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4328 printf ("%2u %3u %2lu\n",
4331 (unsigned long) section
->sh_addralign
);
4335 print_vma (section
->sh_addr
, LONG_HEX
);
4337 if ((long) section
->sh_offset
== section
->sh_offset
)
4338 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4342 print_vma (section
->sh_offset
, LONG_HEX
);
4345 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4346 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4350 print_vma (section
->sh_size
, LONG_HEX
);
4353 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4354 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4358 print_vma (section
->sh_entsize
, LONG_HEX
);
4361 if (do_section_details
)
4362 fputs (" ", stdout
);
4364 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4366 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
4368 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4369 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
4372 print_vma (section
->sh_addralign
, DEC
);
4376 else if (do_section_details
)
4378 printf (" %-15.15s ",
4379 get_section_type_name (section
->sh_type
));
4380 print_vma (section
->sh_addr
, LONG_HEX
);
4381 if ((long) section
->sh_offset
== section
->sh_offset
)
4382 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4386 print_vma (section
->sh_offset
, LONG_HEX
);
4388 printf (" %u\n ", section
->sh_link
);
4389 print_vma (section
->sh_size
, LONG_HEX
);
4391 print_vma (section
->sh_entsize
, LONG_HEX
);
4393 printf (" %-16u %lu\n",
4395 (unsigned long) section
->sh_addralign
);
4400 print_vma (section
->sh_addr
, LONG_HEX
);
4401 if ((long) section
->sh_offset
== section
->sh_offset
)
4402 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4406 print_vma (section
->sh_offset
, LONG_HEX
);
4409 print_vma (section
->sh_size
, LONG_HEX
);
4411 print_vma (section
->sh_entsize
, LONG_HEX
);
4413 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4415 printf (" %2u %3u %lu\n",
4418 (unsigned long) section
->sh_addralign
);
4421 if (do_section_details
)
4422 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4425 if (!do_section_details
)
4426 printf (_("Key to Flags:\n\
4427 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4428 I (info), L (link order), G (group), x (unknown)\n\
4429 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4435 get_group_flags (unsigned int flags
)
4437 static char buff
[32];
4444 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4451 process_section_groups (FILE * file
)
4453 Elf_Internal_Shdr
* section
;
4455 struct group
* group
;
4456 Elf_Internal_Shdr
* symtab_sec
;
4457 Elf_Internal_Shdr
* strtab_sec
;
4458 Elf_Internal_Sym
* symtab
;
4462 /* Don't process section groups unless needed. */
4463 if (!do_unwind
&& !do_section_groups
)
4466 if (elf_header
.e_shnum
== 0)
4468 if (do_section_groups
)
4469 printf (_("\nThere are no sections in this file.\n"));
4474 if (section_headers
== NULL
)
4476 error (_("Section headers are not available!\n"));
4480 section_headers_groups
= calloc (elf_header
.e_shnum
,
4481 sizeof (struct group
*));
4483 if (section_headers_groups
== NULL
)
4485 error (_("Out of memory\n"));
4489 /* Scan the sections for the group section. */
4491 for (i
= 0, section
= section_headers
;
4492 i
< elf_header
.e_shnum
;
4494 if (section
->sh_type
== SHT_GROUP
)
4497 if (group_count
== 0)
4499 if (do_section_groups
)
4500 printf (_("\nThere are no section groups in this file.\n"));
4505 section_groups
= calloc (group_count
, sizeof (struct group
));
4507 if (section_groups
== NULL
)
4509 error (_("Out of memory\n"));
4518 for (i
= 0, section
= section_headers
, group
= section_groups
;
4519 i
< elf_header
.e_shnum
;
4522 if (section
->sh_type
== SHT_GROUP
)
4524 char * name
= SECTION_NAME (section
);
4526 unsigned char * start
;
4527 unsigned char * indices
;
4528 unsigned int entry
, j
, size
;
4529 Elf_Internal_Shdr
* sec
;
4530 Elf_Internal_Sym
* sym
;
4532 /* Get the symbol table. */
4533 if (section
->sh_link
>= elf_header
.e_shnum
4534 || ((sec
= section_headers
+ section
->sh_link
)->sh_type
4537 error (_("Bad sh_link in group section `%s'\n"), name
);
4541 if (symtab_sec
!= sec
)
4546 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4549 sym
= symtab
+ section
->sh_info
;
4551 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4553 if (sym
->st_shndx
== 0
4554 || sym
->st_shndx
>= elf_header
.e_shnum
)
4556 error (_("Bad sh_info in group section `%s'\n"), name
);
4560 group_name
= SECTION_NAME (section_headers
+ sym
->st_shndx
);
4569 /* Get the string table. */
4570 if (symtab_sec
->sh_link
>= elf_header
.e_shnum
)
4579 != (sec
= section_headers
+ symtab_sec
->sh_link
))
4584 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4585 1, strtab_sec
->sh_size
,
4587 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4589 group_name
= sym
->st_name
< strtab_size
4590 ? strtab
+ sym
->st_name
: "<corrupt>";
4593 start
= get_data (NULL
, file
, section
->sh_offset
,
4594 1, section
->sh_size
, _("section data"));
4597 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4598 entry
= byte_get (indices
, 4);
4601 if (do_section_groups
)
4603 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4604 get_group_flags (entry
), i
, name
, group_name
, size
);
4606 printf (_(" [Index] Name\n"));
4609 group
->group_index
= i
;
4611 for (j
= 0; j
< size
; j
++)
4613 struct group_list
* g
;
4615 entry
= byte_get (indices
, 4);
4618 if (entry
>= elf_header
.e_shnum
)
4620 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4621 entry
, i
, elf_header
.e_shnum
- 1);
4625 if (section_headers_groups
[entry
] != NULL
)
4629 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4631 section_headers_groups
[entry
]->group_index
);
4636 /* Intel C/C++ compiler may put section 0 in a
4637 section group. We just warn it the first time
4638 and ignore it afterwards. */
4639 static int warned
= 0;
4642 error (_("section 0 in group section [%5u]\n"),
4643 section_headers_groups
[entry
]->group_index
);
4649 section_headers_groups
[entry
] = group
;
4651 if (do_section_groups
)
4653 sec
= section_headers
+ entry
;
4654 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4657 g
= xmalloc (sizeof (struct group_list
));
4658 g
->section_index
= entry
;
4659 g
->next
= group
->root
;
4683 } dynamic_relocations
[] =
4685 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4686 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4687 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4690 /* Process the reloc section. */
4693 process_relocs (FILE * file
)
4695 unsigned long rel_size
;
4696 unsigned long rel_offset
;
4702 if (do_using_dynamic
)
4706 int has_dynamic_reloc
;
4709 has_dynamic_reloc
= 0;
4711 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4713 is_rela
= dynamic_relocations
[i
].rela
;
4714 name
= dynamic_relocations
[i
].name
;
4715 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4716 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4718 has_dynamic_reloc
|= rel_size
;
4720 if (is_rela
== UNKNOWN
)
4722 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4723 switch (dynamic_info
[DT_PLTREL
])
4737 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4738 name
, rel_offset
, rel_size
);
4740 dump_relocations (file
,
4741 offset_from_vma (file
, rel_offset
, rel_size
),
4743 dynamic_symbols
, num_dynamic_syms
,
4744 dynamic_strings
, dynamic_strings_length
, is_rela
);
4748 if (! has_dynamic_reloc
)
4749 printf (_("\nThere are no dynamic relocations in this file.\n"));
4753 Elf_Internal_Shdr
* section
;
4757 for (i
= 0, section
= section_headers
;
4758 i
< elf_header
.e_shnum
;
4761 if ( section
->sh_type
!= SHT_RELA
4762 && section
->sh_type
!= SHT_REL
)
4765 rel_offset
= section
->sh_offset
;
4766 rel_size
= section
->sh_size
;
4770 Elf_Internal_Shdr
* strsec
;
4773 printf (_("\nRelocation section "));
4775 if (string_table
== NULL
)
4776 printf ("%d", section
->sh_name
);
4778 printf (_("'%s'"), SECTION_NAME (section
));
4780 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4781 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4783 is_rela
= section
->sh_type
== SHT_RELA
;
4785 if (section
->sh_link
!= 0
4786 && section
->sh_link
< elf_header
.e_shnum
)
4788 Elf_Internal_Shdr
* symsec
;
4789 Elf_Internal_Sym
* symtab
;
4790 unsigned long nsyms
;
4791 unsigned long strtablen
= 0;
4792 char * strtab
= NULL
;
4794 symsec
= section_headers
+ section
->sh_link
;
4795 if (symsec
->sh_type
!= SHT_SYMTAB
4796 && symsec
->sh_type
!= SHT_DYNSYM
)
4799 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4800 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4805 if (symsec
->sh_link
!= 0
4806 && symsec
->sh_link
< elf_header
.e_shnum
)
4808 strsec
= section_headers
+ symsec
->sh_link
;
4810 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4813 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4816 dump_relocations (file
, rel_offset
, rel_size
,
4817 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4823 dump_relocations (file
, rel_offset
, rel_size
,
4824 NULL
, 0, NULL
, 0, is_rela
);
4831 printf (_("\nThere are no relocations in this file.\n"));
4837 /* Process the unwind section. */
4839 #include "unwind-ia64.h"
4841 /* An absolute address consists of a section and an offset. If the
4842 section is NULL, the offset itself is the address, otherwise, the
4843 address equals to LOAD_ADDRESS(section) + offset. */
4847 unsigned short section
;
4851 #define ABSADDR(a) \
4853 ? section_headers [(a).section].sh_addr + (a).offset \
4856 struct ia64_unw_aux_info
4858 struct ia64_unw_table_entry
4860 struct absaddr start
;
4862 struct absaddr info
;
4864 *table
; /* Unwind table. */
4865 unsigned long table_len
; /* Length of unwind table. */
4866 unsigned char * info
; /* Unwind info. */
4867 unsigned long info_size
; /* Size of unwind info. */
4868 bfd_vma info_addr
; /* starting address of unwind info. */
4869 bfd_vma seg_base
; /* Starting address of segment. */
4870 Elf_Internal_Sym
* symtab
; /* The symbol table. */
4871 unsigned long nsyms
; /* Number of symbols. */
4872 char * strtab
; /* The string table. */
4873 unsigned long strtab_size
; /* Size of string table. */
4877 find_symbol_for_address (Elf_Internal_Sym
* symtab
,
4878 unsigned long nsyms
,
4879 const char * strtab
,
4880 unsigned long strtab_size
,
4881 struct absaddr addr
,
4882 const char ** symname
,
4885 bfd_vma dist
= 0x100000;
4886 Elf_Internal_Sym
* sym
;
4887 Elf_Internal_Sym
* best
= NULL
;
4890 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4892 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4893 && sym
->st_name
!= 0
4894 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4895 && addr
.offset
>= sym
->st_value
4896 && addr
.offset
- sym
->st_value
< dist
)
4899 dist
= addr
.offset
- sym
->st_value
;
4906 *symname
= (best
->st_name
>= strtab_size
4907 ? "<corrupt>" : strtab
+ best
->st_name
);
4912 *offset
= addr
.offset
;
4916 dump_ia64_unwind (struct ia64_unw_aux_info
* aux
)
4918 struct ia64_unw_table_entry
* tp
;
4921 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4925 const unsigned char * dp
;
4926 const unsigned char * head
;
4927 const char * procname
;
4929 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4930 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4932 fputs ("\n<", stdout
);
4936 fputs (procname
, stdout
);
4939 printf ("+%lx", (unsigned long) offset
);
4942 fputs (">: [", stdout
);
4943 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4944 fputc ('-', stdout
);
4945 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4946 printf ("], info at +0x%lx\n",
4947 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4949 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
4950 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4952 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4953 (unsigned) UNW_VER (stamp
),
4954 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4955 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4956 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4957 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4959 if (UNW_VER (stamp
) != 1)
4961 printf ("\tUnknown version.\n");
4966 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4967 dp
= unw_decode (dp
, in_body
, & in_body
);
4972 slurp_ia64_unwind_table (FILE * file
,
4973 struct ia64_unw_aux_info
* aux
,
4974 Elf_Internal_Shdr
* sec
)
4976 unsigned long size
, nrelas
, i
;
4977 Elf_Internal_Phdr
* seg
;
4978 struct ia64_unw_table_entry
* tep
;
4979 Elf_Internal_Shdr
* relsec
;
4980 Elf_Internal_Rela
* rela
;
4981 Elf_Internal_Rela
* rp
;
4982 unsigned char * table
;
4984 Elf_Internal_Sym
* sym
;
4985 const char * relname
;
4987 /* First, find the starting address of the segment that includes
4990 if (elf_header
.e_phnum
)
4992 if (! get_program_headers (file
))
4995 for (seg
= program_headers
;
4996 seg
< program_headers
+ elf_header
.e_phnum
;
4999 if (seg
->p_type
!= PT_LOAD
)
5002 if (sec
->sh_addr
>= seg
->p_vaddr
5003 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5005 aux
->seg_base
= seg
->p_vaddr
;
5011 /* Second, build the unwind table from the contents of the unwind section: */
5012 size
= sec
->sh_size
;
5013 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5017 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
5019 for (tp
= table
; tp
< table
+ size
; ++tep
)
5021 tep
->start
.section
= SHN_UNDEF
;
5022 tep
->end
.section
= SHN_UNDEF
;
5023 tep
->info
.section
= SHN_UNDEF
;
5024 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5025 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5026 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5027 tep
->start
.offset
+= aux
->seg_base
;
5028 tep
->end
.offset
+= aux
->seg_base
;
5029 tep
->info
.offset
+= aux
->seg_base
;
5033 /* Third, apply any relocations to the unwind table: */
5034 for (relsec
= section_headers
;
5035 relsec
< section_headers
+ elf_header
.e_shnum
;
5038 if (relsec
->sh_type
!= SHT_RELA
5039 || relsec
->sh_info
>= elf_header
.e_shnum
5040 || section_headers
+ relsec
->sh_info
!= sec
)
5043 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5047 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5049 relname
= elf_ia64_reloc_type (get_reloc_type (rp
->r_info
));
5050 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5052 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5054 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5058 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5060 switch (rp
->r_offset
/eh_addr_size
% 3)
5063 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5064 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5067 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5068 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5071 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5072 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5082 aux
->table_len
= size
/ (3 * eh_addr_size
);
5087 ia64_process_unwind (FILE * file
)
5089 Elf_Internal_Shdr
* sec
;
5090 Elf_Internal_Shdr
* unwsec
= NULL
;
5091 Elf_Internal_Shdr
* strsec
;
5092 unsigned long i
, unwcount
= 0, unwstart
= 0;
5093 struct ia64_unw_aux_info aux
;
5095 memset (& aux
, 0, sizeof (aux
));
5097 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5099 if (sec
->sh_type
== SHT_SYMTAB
5100 && sec
->sh_link
< elf_header
.e_shnum
)
5102 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5103 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5105 strsec
= section_headers
+ sec
->sh_link
;
5106 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5107 1, strsec
->sh_size
, _("string table"));
5108 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5110 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5115 printf (_("\nThere are no unwind sections in this file.\n"));
5117 while (unwcount
-- > 0)
5122 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5123 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5124 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5131 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5133 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5135 /* We need to find which section group it is in. */
5136 struct group_list
* g
= section_headers_groups
[i
]->root
;
5138 for (; g
!= NULL
; g
= g
->next
)
5140 sec
= section_headers
+ g
->section_index
;
5142 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5147 i
= elf_header
.e_shnum
;
5149 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5151 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5152 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5153 suffix
= SECTION_NAME (unwsec
) + len
;
5154 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5156 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5157 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5162 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5163 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5164 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5165 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5167 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5168 suffix
= SECTION_NAME (unwsec
) + len
;
5169 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5171 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5172 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5176 if (i
== elf_header
.e_shnum
)
5178 printf (_("\nCould not find unwind info section for "));
5180 if (string_table
== NULL
)
5181 printf ("%d", unwsec
->sh_name
);
5183 printf (_("'%s'"), SECTION_NAME (unwsec
));
5187 aux
.info_size
= sec
->sh_size
;
5188 aux
.info_addr
= sec
->sh_addr
;
5189 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
5192 printf (_("\nUnwind section "));
5194 if (string_table
== NULL
)
5195 printf ("%d", unwsec
->sh_name
);
5197 printf (_("'%s'"), SECTION_NAME (unwsec
));
5199 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5200 (unsigned long) unwsec
->sh_offset
,
5201 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5203 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5205 if (aux
.table_len
> 0)
5206 dump_ia64_unwind (& aux
);
5209 free ((char *) aux
.table
);
5211 free ((char *) aux
.info
);
5220 free ((char *) aux
.strtab
);
5225 struct hppa_unw_aux_info
5227 struct hppa_unw_table_entry
5229 struct absaddr start
;
5231 unsigned int Cannot_unwind
:1; /* 0 */
5232 unsigned int Millicode
:1; /* 1 */
5233 unsigned int Millicode_save_sr0
:1; /* 2 */
5234 unsigned int Region_description
:2; /* 3..4 */
5235 unsigned int reserved1
:1; /* 5 */
5236 unsigned int Entry_SR
:1; /* 6 */
5237 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5238 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5239 unsigned int Args_stored
:1; /* 16 */
5240 unsigned int Variable_Frame
:1; /* 17 */
5241 unsigned int Separate_Package_Body
:1; /* 18 */
5242 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5243 unsigned int Stack_Overflow_Check
:1; /* 20 */
5244 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5245 unsigned int Ada_Region
:1; /* 22 */
5246 unsigned int cxx_info
:1; /* 23 */
5247 unsigned int cxx_try_catch
:1; /* 24 */
5248 unsigned int sched_entry_seq
:1; /* 25 */
5249 unsigned int reserved2
:1; /* 26 */
5250 unsigned int Save_SP
:1; /* 27 */
5251 unsigned int Save_RP
:1; /* 28 */
5252 unsigned int Save_MRP_in_frame
:1; /* 29 */
5253 unsigned int extn_ptr_defined
:1; /* 30 */
5254 unsigned int Cleanup_defined
:1; /* 31 */
5256 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5257 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5258 unsigned int Large_frame
:1; /* 2 */
5259 unsigned int Pseudo_SP_Set
:1; /* 3 */
5260 unsigned int reserved4
:1; /* 4 */
5261 unsigned int Total_frame_size
:27; /* 5..31 */
5263 *table
; /* Unwind table. */
5264 unsigned long table_len
; /* Length of unwind table. */
5265 bfd_vma seg_base
; /* Starting address of segment. */
5266 Elf_Internal_Sym
* symtab
; /* The symbol table. */
5267 unsigned long nsyms
; /* Number of symbols. */
5268 char * strtab
; /* The string table. */
5269 unsigned long strtab_size
; /* Size of string table. */
5273 dump_hppa_unwind (struct hppa_unw_aux_info
* aux
)
5275 struct hppa_unw_table_entry
* tp
;
5277 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5280 const char * procname
;
5282 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5283 aux
->strtab_size
, tp
->start
, &procname
,
5286 fputs ("\n<", stdout
);
5290 fputs (procname
, stdout
);
5293 printf ("+%lx", (unsigned long) offset
);
5296 fputs (">: [", stdout
);
5297 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5298 fputc ('-', stdout
);
5299 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5302 #define PF(_m) if (tp->_m) printf (#_m " ");
5303 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5306 PF(Millicode_save_sr0
);
5307 /* PV(Region_description); */
5313 PF(Separate_Package_Body
);
5314 PF(Frame_Extension_Millicode
);
5315 PF(Stack_Overflow_Check
);
5316 PF(Two_Instruction_SP_Increment
);
5320 PF(sched_entry_seq
);
5323 PF(Save_MRP_in_frame
);
5324 PF(extn_ptr_defined
);
5325 PF(Cleanup_defined
);
5326 PF(MPE_XL_interrupt_marker
);
5327 PF(HP_UX_interrupt_marker
);
5330 PV(Total_frame_size
);
5339 slurp_hppa_unwind_table (FILE * file
,
5340 struct hppa_unw_aux_info
* aux
,
5341 Elf_Internal_Shdr
* sec
)
5343 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5344 Elf_Internal_Phdr
* seg
;
5345 struct hppa_unw_table_entry
* tep
;
5346 Elf_Internal_Shdr
* relsec
;
5347 Elf_Internal_Rela
* rela
;
5348 Elf_Internal_Rela
* rp
;
5349 unsigned char * table
;
5351 Elf_Internal_Sym
* sym
;
5352 const char * relname
;
5354 /* First, find the starting address of the segment that includes
5357 if (elf_header
.e_phnum
)
5359 if (! get_program_headers (file
))
5362 for (seg
= program_headers
;
5363 seg
< program_headers
+ elf_header
.e_phnum
;
5366 if (seg
->p_type
!= PT_LOAD
)
5369 if (sec
->sh_addr
>= seg
->p_vaddr
5370 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5372 aux
->seg_base
= seg
->p_vaddr
;
5378 /* Second, build the unwind table from the contents of the unwind
5380 size
= sec
->sh_size
;
5381 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5386 nentries
= size
/ unw_ent_size
;
5387 size
= unw_ent_size
* nentries
;
5389 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5391 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5393 unsigned int tmp1
, tmp2
;
5395 tep
->start
.section
= SHN_UNDEF
;
5396 tep
->end
.section
= SHN_UNDEF
;
5398 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5399 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5400 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5401 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5403 tep
->start
.offset
+= aux
->seg_base
;
5404 tep
->end
.offset
+= aux
->seg_base
;
5406 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5407 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5408 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5409 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5410 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5411 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5412 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5413 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5414 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5415 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5416 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5417 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5418 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5419 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5420 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5421 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5422 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5423 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5424 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5425 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5426 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5427 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5428 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5429 tep
->Cleanup_defined
= tmp1
& 0x1;
5431 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5432 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5433 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5434 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5435 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5436 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5440 /* Third, apply any relocations to the unwind table. */
5441 for (relsec
= section_headers
;
5442 relsec
< section_headers
+ elf_header
.e_shnum
;
5445 if (relsec
->sh_type
!= SHT_RELA
5446 || relsec
->sh_info
>= elf_header
.e_shnum
5447 || section_headers
+ relsec
->sh_info
!= sec
)
5450 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5454 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5456 relname
= elf_hppa_reloc_type (get_reloc_type (rp
->r_info
));
5457 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5459 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5460 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5462 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5466 i
= rp
->r_offset
/ unw_ent_size
;
5468 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5471 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5472 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5475 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5476 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5486 aux
->table_len
= nentries
;
5492 hppa_process_unwind (FILE * file
)
5494 struct hppa_unw_aux_info aux
;
5495 Elf_Internal_Shdr
* unwsec
= NULL
;
5496 Elf_Internal_Shdr
* strsec
;
5497 Elf_Internal_Shdr
* sec
;
5500 memset (& aux
, 0, sizeof (aux
));
5502 if (string_table
== NULL
)
5505 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5507 if (sec
->sh_type
== SHT_SYMTAB
5508 && sec
->sh_link
< elf_header
.e_shnum
)
5510 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5511 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5513 strsec
= section_headers
+ sec
->sh_link
;
5514 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5515 1, strsec
->sh_size
, _("string table"));
5516 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5518 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5523 printf (_("\nThere are no unwind sections in this file.\n"));
5525 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5527 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5529 printf (_("\nUnwind section "));
5530 printf (_("'%s'"), SECTION_NAME (sec
));
5532 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5533 (unsigned long) sec
->sh_offset
,
5534 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5536 slurp_hppa_unwind_table (file
, &aux
, sec
);
5537 if (aux
.table_len
> 0)
5538 dump_hppa_unwind (&aux
);
5541 free ((char *) aux
.table
);
5549 free ((char *) aux
.strtab
);
5555 process_unwind (FILE * file
)
5557 struct unwind_handler
5560 int (* handler
)(FILE *);
5563 { EM_IA_64
, ia64_process_unwind
},
5564 { EM_PARISC
, hppa_process_unwind
},
5572 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5573 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5574 return handlers
[i
].handler (file
);
5576 printf (_("\nThere are no unwind sections in this file.\n"));
5581 dynamic_section_mips_val (Elf_Internal_Dyn
* entry
)
5583 switch (entry
->d_tag
)
5586 if (entry
->d_un
.d_val
== 0)
5590 static const char * opts
[] =
5592 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5593 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5594 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5595 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5600 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
5601 if (entry
->d_un
.d_val
& (1 << cnt
))
5603 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5610 case DT_MIPS_IVERSION
:
5611 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5612 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5614 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5617 case DT_MIPS_TIME_STAMP
:
5622 time_t time
= entry
->d_un
.d_val
;
5623 tmp
= gmtime (&time
);
5624 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5625 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5626 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5627 printf ("Time Stamp: %s\n", timebuf
);
5631 case DT_MIPS_RLD_VERSION
:
5632 case DT_MIPS_LOCAL_GOTNO
:
5633 case DT_MIPS_CONFLICTNO
:
5634 case DT_MIPS_LIBLISTNO
:
5635 case DT_MIPS_SYMTABNO
:
5636 case DT_MIPS_UNREFEXTNO
:
5637 case DT_MIPS_HIPAGENO
:
5638 case DT_MIPS_DELTA_CLASS_NO
:
5639 case DT_MIPS_DELTA_INSTANCE_NO
:
5640 case DT_MIPS_DELTA_RELOC_NO
:
5641 case DT_MIPS_DELTA_SYM_NO
:
5642 case DT_MIPS_DELTA_CLASSSYM_NO
:
5643 case DT_MIPS_COMPACT_SIZE
:
5644 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5648 printf ("%#lx\n", (unsigned long) entry
->d_un
.d_ptr
);
5654 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
5656 switch (entry
->d_tag
)
5658 case DT_HP_DLD_FLAGS
:
5667 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5668 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5669 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5670 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5671 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5672 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5673 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5674 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5675 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5676 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5677 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5678 { DT_HP_GST
, "HP_GST" },
5679 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5680 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5681 { DT_HP_NODELETE
, "HP_NODELETE" },
5682 { DT_HP_GROUP
, "HP_GROUP" },
5683 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5687 bfd_vma val
= entry
->d_un
.d_val
;
5689 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
5690 if (val
& flags
[cnt
].bit
)
5694 fputs (flags
[cnt
].str
, stdout
);
5696 val
^= flags
[cnt
].bit
;
5699 if (val
!= 0 || first
)
5703 print_vma (val
, HEX
);
5709 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5716 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
5718 switch (entry
->d_tag
)
5720 case DT_IA_64_PLT_RESERVE
:
5721 /* First 3 slots reserved. */
5722 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5724 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5728 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5735 get_32bit_dynamic_section (FILE * file
)
5737 Elf32_External_Dyn
* edyn
;
5738 Elf32_External_Dyn
* ext
;
5739 Elf_Internal_Dyn
* entry
;
5741 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5742 _("dynamic section"));
5746 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5747 might not have the luxury of section headers. Look for the DT_NULL
5748 terminator to determine the number of entries. */
5749 for (ext
= edyn
, dynamic_nent
= 0;
5750 (char *) ext
< (char *) edyn
+ dynamic_size
;
5754 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5758 dynamic_section
= cmalloc (dynamic_nent
, sizeof (* entry
));
5759 if (dynamic_section
== NULL
)
5761 error (_("Out of memory\n"));
5766 for (ext
= edyn
, entry
= dynamic_section
;
5767 entry
< dynamic_section
+ dynamic_nent
;
5770 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5771 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5780 get_64bit_dynamic_section (FILE * file
)
5782 Elf64_External_Dyn
* edyn
;
5783 Elf64_External_Dyn
* ext
;
5784 Elf_Internal_Dyn
* entry
;
5786 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5787 _("dynamic section"));
5791 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5792 might not have the luxury of section headers. Look for the DT_NULL
5793 terminator to determine the number of entries. */
5794 for (ext
= edyn
, dynamic_nent
= 0;
5795 (char *) ext
< (char *) edyn
+ dynamic_size
;
5799 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5803 dynamic_section
= cmalloc (dynamic_nent
, sizeof (* entry
));
5804 if (dynamic_section
== NULL
)
5806 error (_("Out of memory\n"));
5811 for (ext
= edyn
, entry
= dynamic_section
;
5812 entry
< dynamic_section
+ dynamic_nent
;
5815 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5816 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5825 print_dynamic_flags (bfd_vma flags
)
5833 flag
= flags
& - flags
;
5843 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5844 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5845 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5846 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5847 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5848 default: fputs ("unknown", stdout
); break;
5854 /* Parse and display the contents of the dynamic section. */
5857 process_dynamic_section (FILE * file
)
5859 Elf_Internal_Dyn
* entry
;
5861 if (dynamic_size
== 0)
5864 printf (_("\nThere is no dynamic section in this file.\n"));
5871 if (! get_32bit_dynamic_section (file
))
5874 else if (! get_64bit_dynamic_section (file
))
5877 /* Find the appropriate symbol table. */
5878 if (dynamic_symbols
== NULL
)
5880 for (entry
= dynamic_section
;
5881 entry
< dynamic_section
+ dynamic_nent
;
5884 Elf_Internal_Shdr section
;
5886 if (entry
->d_tag
!= DT_SYMTAB
)
5889 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5891 /* Since we do not know how big the symbol table is,
5892 we default to reading in the entire file (!) and
5893 processing that. This is overkill, I know, but it
5895 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5897 if (archive_file_offset
!= 0)
5898 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5901 if (fseek (file
, 0, SEEK_END
))
5902 error (_("Unable to seek to end of file!\n"));
5904 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5908 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5910 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5912 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5913 if (num_dynamic_syms
< 1)
5915 error (_("Unable to determine the number of symbols to load\n"));
5919 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5923 /* Similarly find a string table. */
5924 if (dynamic_strings
== NULL
)
5926 for (entry
= dynamic_section
;
5927 entry
< dynamic_section
+ dynamic_nent
;
5930 unsigned long offset
;
5933 if (entry
->d_tag
!= DT_STRTAB
)
5936 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5938 /* Since we do not know how big the string table is,
5939 we default to reading in the entire file (!) and
5940 processing that. This is overkill, I know, but it
5943 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5945 if (archive_file_offset
!= 0)
5946 str_tab_len
= archive_file_size
- offset
;
5949 if (fseek (file
, 0, SEEK_END
))
5950 error (_("Unable to seek to end of file\n"));
5951 str_tab_len
= ftell (file
) - offset
;
5954 if (str_tab_len
< 1)
5957 (_("Unable to determine the length of the dynamic string table\n"));
5961 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5962 _("dynamic string table"));
5963 dynamic_strings_length
= str_tab_len
;
5968 /* And find the syminfo section if available. */
5969 if (dynamic_syminfo
== NULL
)
5971 unsigned long syminsz
= 0;
5973 for (entry
= dynamic_section
;
5974 entry
< dynamic_section
+ dynamic_nent
;
5977 if (entry
->d_tag
== DT_SYMINENT
)
5979 /* Note: these braces are necessary to avoid a syntax
5980 error from the SunOS4 C compiler. */
5981 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5983 else if (entry
->d_tag
== DT_SYMINSZ
)
5984 syminsz
= entry
->d_un
.d_val
;
5985 else if (entry
->d_tag
== DT_SYMINFO
)
5986 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5990 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5992 Elf_External_Syminfo
* extsyminfo
;
5993 Elf_External_Syminfo
* extsym
;
5994 Elf_Internal_Syminfo
* syminfo
;
5996 /* There is a syminfo section. Read the data. */
5997 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5998 syminsz
, _("symbol information"));
6002 dynamic_syminfo
= malloc (syminsz
);
6003 if (dynamic_syminfo
== NULL
)
6005 error (_("Out of memory\n"));
6009 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
6010 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
6011 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
6012 ++syminfo
, ++extsym
)
6014 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
6015 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
6022 if (do_dynamic
&& dynamic_addr
)
6023 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
6024 dynamic_addr
, dynamic_nent
);
6026 printf (_(" Tag Type Name/Value\n"));
6028 for (entry
= dynamic_section
;
6029 entry
< dynamic_section
+ dynamic_nent
;
6037 print_vma (entry
->d_tag
, FULL_HEX
);
6038 dtype
= get_dynamic_type (entry
->d_tag
);
6039 printf (" (%s)%*s", dtype
,
6040 ((is_32bit_elf
? 27 : 19)
6041 - (int) strlen (dtype
)),
6045 switch (entry
->d_tag
)
6049 print_dynamic_flags (entry
->d_un
.d_val
);
6059 switch (entry
->d_tag
)
6062 printf (_("Auxiliary library"));
6066 printf (_("Filter library"));
6070 printf (_("Configuration file"));
6074 printf (_("Dependency audit library"));
6078 printf (_("Audit library"));
6082 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6083 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6087 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6096 printf (_("Flags:"));
6098 if (entry
->d_un
.d_val
== 0)
6099 printf (_(" None\n"));
6102 unsigned long int val
= entry
->d_un
.d_val
;
6104 if (val
& DTF_1_PARINIT
)
6106 printf (" PARINIT");
6107 val
^= DTF_1_PARINIT
;
6109 if (val
& DTF_1_CONFEXP
)
6111 printf (" CONFEXP");
6112 val
^= DTF_1_CONFEXP
;
6115 printf (" %lx", val
);
6124 printf (_("Flags:"));
6126 if (entry
->d_un
.d_val
== 0)
6127 printf (_(" None\n"));
6130 unsigned long int val
= entry
->d_un
.d_val
;
6132 if (val
& DF_P1_LAZYLOAD
)
6134 printf (" LAZYLOAD");
6135 val
^= DF_P1_LAZYLOAD
;
6137 if (val
& DF_P1_GROUPPERM
)
6139 printf (" GROUPPERM");
6140 val
^= DF_P1_GROUPPERM
;
6143 printf (" %lx", val
);
6152 printf (_("Flags:"));
6153 if (entry
->d_un
.d_val
== 0)
6154 printf (_(" None\n"));
6157 unsigned long int val
= entry
->d_un
.d_val
;
6164 if (val
& DF_1_GLOBAL
)
6169 if (val
& DF_1_GROUP
)
6174 if (val
& DF_1_NODELETE
)
6176 printf (" NODELETE");
6177 val
^= DF_1_NODELETE
;
6179 if (val
& DF_1_LOADFLTR
)
6181 printf (" LOADFLTR");
6182 val
^= DF_1_LOADFLTR
;
6184 if (val
& DF_1_INITFIRST
)
6186 printf (" INITFIRST");
6187 val
^= DF_1_INITFIRST
;
6189 if (val
& DF_1_NOOPEN
)
6194 if (val
& DF_1_ORIGIN
)
6199 if (val
& DF_1_DIRECT
)
6204 if (val
& DF_1_TRANS
)
6209 if (val
& DF_1_INTERPOSE
)
6211 printf (" INTERPOSE");
6212 val
^= DF_1_INTERPOSE
;
6214 if (val
& DF_1_NODEFLIB
)
6216 printf (" NODEFLIB");
6217 val
^= DF_1_NODEFLIB
;
6219 if (val
& DF_1_NODUMP
)
6224 if (val
& DF_1_CONLFAT
)
6226 printf (" CONLFAT");
6227 val
^= DF_1_CONLFAT
;
6230 printf (" %lx", val
);
6237 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6239 puts (get_dynamic_type (entry
->d_un
.d_val
));
6259 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6265 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6266 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6272 switch (entry
->d_tag
)
6275 printf (_("Shared library: [%s]"), name
);
6277 if (streq (name
, program_interpreter
))
6278 printf (_(" program interpreter"));
6282 printf (_("Library soname: [%s]"), name
);
6286 printf (_("Library rpath: [%s]"), name
);
6290 printf (_("Library runpath: [%s]"), name
);
6294 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6299 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6312 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6316 case DT_INIT_ARRAYSZ
:
6317 case DT_FINI_ARRAYSZ
:
6318 case DT_GNU_CONFLICTSZ
:
6319 case DT_GNU_LIBLISTSZ
:
6322 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6323 printf (" (bytes)\n");
6333 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6346 if (entry
->d_tag
== DT_USED
6347 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6349 char * name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6353 printf (_("Not needed object: [%s]\n"), name
);
6358 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6364 /* The value of this entry is ignored. */
6369 case DT_GNU_PRELINKED
:
6373 time_t time
= entry
->d_un
.d_val
;
6375 tmp
= gmtime (&time
);
6376 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6377 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6378 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6384 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6387 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6393 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6394 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6399 switch (elf_header
.e_machine
)
6402 case EM_MIPS_RS3_LE
:
6403 dynamic_section_mips_val (entry
);
6406 dynamic_section_parisc_val (entry
);
6409 dynamic_section_ia64_val (entry
);
6412 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6424 get_ver_flags (unsigned int flags
)
6426 static char buff
[32];
6433 if (flags
& VER_FLG_BASE
)
6434 strcat (buff
, "BASE ");
6436 if (flags
& VER_FLG_WEAK
)
6438 if (flags
& VER_FLG_BASE
)
6439 strcat (buff
, "| ");
6441 strcat (buff
, "WEAK ");
6444 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6445 strcat (buff
, "| <unknown>");
6450 /* Display the contents of the version sections. */
6453 process_version_sections (FILE * file
)
6455 Elf_Internal_Shdr
* section
;
6462 for (i
= 0, section
= section_headers
;
6463 i
< elf_header
.e_shnum
;
6466 switch (section
->sh_type
)
6468 case SHT_GNU_verdef
:
6470 Elf_External_Verdef
* edefs
;
6478 (_("\nVersion definition section '%s' contains %u entries:\n"),
6479 SECTION_NAME (section
), section
->sh_info
);
6481 printf (_(" Addr: 0x"));
6482 printf_vma (section
->sh_addr
);
6483 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6484 (unsigned long) section
->sh_offset
, section
->sh_link
,
6485 section
->sh_link
< elf_header
.e_shnum
6486 ? SECTION_NAME (section_headers
+ section
->sh_link
)
6489 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6491 _("version definition section"));
6492 endbuf
= (char *) edefs
+ section
->sh_size
;
6496 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6499 Elf_External_Verdef
* edef
;
6500 Elf_Internal_Verdef ent
;
6501 Elf_External_Verdaux
* eaux
;
6502 Elf_Internal_Verdaux aux
;
6506 vstart
= ((char *) edefs
) + idx
;
6507 if (vstart
+ sizeof (*edef
) > endbuf
)
6510 edef
= (Elf_External_Verdef
*) vstart
;
6512 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6513 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6514 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6515 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6516 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6517 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6518 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6520 printf (_(" %#06x: Rev: %d Flags: %s"),
6521 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6523 printf (_(" Index: %d Cnt: %d "),
6524 ent
.vd_ndx
, ent
.vd_cnt
);
6526 vstart
+= ent
.vd_aux
;
6528 eaux
= (Elf_External_Verdaux
*) vstart
;
6530 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6531 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6533 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6534 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6536 printf (_("Name index: %ld\n"), aux
.vda_name
);
6538 isum
= idx
+ ent
.vd_aux
;
6540 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6542 isum
+= aux
.vda_next
;
6543 vstart
+= aux
.vda_next
;
6545 eaux
= (Elf_External_Verdaux
*) vstart
;
6546 if (vstart
+ sizeof (*eaux
) > endbuf
)
6549 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6550 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6552 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6553 printf (_(" %#06x: Parent %d: %s\n"),
6554 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6556 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6557 isum
, j
, aux
.vda_name
);
6560 printf (_(" Version def aux past end of section\n"));
6564 if (cnt
< section
->sh_info
)
6565 printf (_(" Version definition past end of section\n"));
6571 case SHT_GNU_verneed
:
6573 Elf_External_Verneed
* eneed
;
6580 printf (_("\nVersion needs section '%s' contains %u entries:\n"),
6581 SECTION_NAME (section
), section
->sh_info
);
6583 printf (_(" Addr: 0x"));
6584 printf_vma (section
->sh_addr
);
6585 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6586 (unsigned long) section
->sh_offset
, section
->sh_link
,
6587 section
->sh_link
< elf_header
.e_shnum
6588 ? SECTION_NAME (section_headers
+ section
->sh_link
)
6591 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6593 _("version need section"));
6594 endbuf
= (char *) eneed
+ section
->sh_size
;
6598 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6600 Elf_External_Verneed
* entry
;
6601 Elf_Internal_Verneed ent
;
6606 vstart
= ((char *) eneed
) + idx
;
6607 if (vstart
+ sizeof (*entry
) > endbuf
)
6610 entry
= (Elf_External_Verneed
*) vstart
;
6612 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6613 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6614 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6615 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6616 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6618 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6620 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6621 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6623 printf (_(" File: %lx"), ent
.vn_file
);
6625 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6627 vstart
+= ent
.vn_aux
;
6629 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6631 Elf_External_Vernaux
* eaux
;
6632 Elf_Internal_Vernaux aux
;
6634 if (vstart
+ sizeof (*eaux
) > endbuf
)
6636 eaux
= (Elf_External_Vernaux
*) vstart
;
6638 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6639 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6640 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6641 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6642 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6644 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6645 printf (_(" %#06x: Name: %s"),
6646 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6648 printf (_(" %#06x: Name index: %lx"),
6649 isum
, aux
.vna_name
);
6651 printf (_(" Flags: %s Version: %d\n"),
6652 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6654 isum
+= aux
.vna_next
;
6655 vstart
+= aux
.vna_next
;
6658 printf (_(" Version need aux past end of section\n"));
6662 if (cnt
< section
->sh_info
)
6663 printf (_(" Version need past end of section\n"));
6669 case SHT_GNU_versym
:
6671 Elf_Internal_Shdr
* link_section
;
6674 unsigned char * edata
;
6675 unsigned short * data
;
6677 Elf_Internal_Sym
* symbols
;
6678 Elf_Internal_Shdr
* string_sec
;
6681 if (section
->sh_link
>= elf_header
.e_shnum
)
6684 link_section
= section_headers
+ section
->sh_link
;
6685 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6687 if (link_section
->sh_link
>= elf_header
.e_shnum
)
6692 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6694 string_sec
= section_headers
+ link_section
->sh_link
;
6696 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6697 string_sec
->sh_size
, _("version string table"));
6701 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6702 SECTION_NAME (section
), total
);
6704 printf (_(" Addr: "));
6705 printf_vma (section
->sh_addr
);
6706 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6707 (unsigned long) section
->sh_offset
, section
->sh_link
,
6708 SECTION_NAME (link_section
));
6710 off
= offset_from_vma (file
,
6711 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6712 total
* sizeof (short));
6713 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6714 _("version symbol data"));
6721 data
= cmalloc (total
, sizeof (short));
6723 for (cnt
= total
; cnt
--;)
6724 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6729 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6732 int check_def
, check_need
;
6735 printf (" %03x:", cnt
);
6737 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6738 switch (data
[cnt
+ j
])
6741 fputs (_(" 0 (*local*) "), stdout
);
6745 fputs (_(" 1 (*global*) "), stdout
);
6749 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6750 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6754 if (symbols
[cnt
+ j
].st_shndx
>= elf_header
.e_shnum
6755 || section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
6758 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6765 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6767 Elf_Internal_Verneed ivn
;
6768 unsigned long offset
;
6770 offset
= offset_from_vma
6771 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6772 sizeof (Elf_External_Verneed
));
6776 Elf_Internal_Vernaux ivna
;
6777 Elf_External_Verneed evn
;
6778 Elf_External_Vernaux evna
;
6779 unsigned long a_off
;
6781 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6784 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6785 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6787 a_off
= offset
+ ivn
.vn_aux
;
6791 get_data (&evna
, file
, a_off
, sizeof (evna
),
6792 1, _("version need aux (2)"));
6794 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6795 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6797 a_off
+= ivna
.vna_next
;
6799 while (ivna
.vna_other
!= data
[cnt
+ j
]
6800 && ivna
.vna_next
!= 0);
6802 if (ivna
.vna_other
== data
[cnt
+ j
])
6804 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6806 if (ivna
.vna_name
>= string_sec
->sh_size
)
6807 name
= _("*invalid*");
6809 name
= strtab
+ ivna
.vna_name
;
6810 nn
+= printf ("(%s%-*s",
6812 12 - (int) strlen (name
),
6818 offset
+= ivn
.vn_next
;
6820 while (ivn
.vn_next
);
6823 if (check_def
&& data
[cnt
+ j
] != 0x8001
6824 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6826 Elf_Internal_Verdef ivd
;
6827 Elf_External_Verdef evd
;
6828 unsigned long offset
;
6830 offset
= offset_from_vma
6831 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6836 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6839 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6840 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6842 offset
+= ivd
.vd_next
;
6844 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6845 && ivd
.vd_next
!= 0);
6847 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6849 Elf_External_Verdaux evda
;
6850 Elf_Internal_Verdaux ivda
;
6852 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6854 get_data (&evda
, file
,
6855 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6857 _("version def aux"));
6859 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6861 if (ivda
.vda_name
>= string_sec
->sh_size
)
6862 name
= _("*invalid*");
6864 name
= strtab
+ ivda
.vda_name
;
6865 nn
+= printf ("(%s%-*s",
6867 12 - (int) strlen (name
),
6873 printf ("%*c", 18 - nn
, ' ');
6891 printf (_("\nNo version information found in this file.\n"));
6897 get_symbol_binding (unsigned int binding
)
6899 static char buff
[32];
6903 case STB_LOCAL
: return "LOCAL";
6904 case STB_GLOBAL
: return "GLOBAL";
6905 case STB_WEAK
: return "WEAK";
6907 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6908 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6910 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6912 if (binding
== STB_GNU_UNIQUE
6913 && (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_LINUX
6914 /* GNU/Linux is still using the default value 0. */
6915 || elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
))
6917 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6920 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6926 get_symbol_type (unsigned int type
)
6928 static char buff
[32];
6932 case STT_NOTYPE
: return "NOTYPE";
6933 case STT_OBJECT
: return "OBJECT";
6934 case STT_FUNC
: return "FUNC";
6935 case STT_SECTION
: return "SECTION";
6936 case STT_FILE
: return "FILE";
6937 case STT_COMMON
: return "COMMON";
6938 case STT_TLS
: return "TLS";
6939 case STT_RELC
: return "RELC";
6940 case STT_SRELC
: return "SRELC";
6942 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6944 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6945 return "THUMB_FUNC";
6947 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6950 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6951 return "PARISC_MILLI";
6953 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6955 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6957 if (elf_header
.e_machine
== EM_PARISC
)
6959 if (type
== STT_HP_OPAQUE
)
6961 if (type
== STT_HP_STUB
)
6965 if (type
== STT_GNU_IFUNC
6966 && (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_LINUX
6967 /* GNU/Linux is still using the default value 0. */
6968 || elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
))
6971 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6974 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6980 get_symbol_visibility (unsigned int visibility
)
6984 case STV_DEFAULT
: return "DEFAULT";
6985 case STV_INTERNAL
: return "INTERNAL";
6986 case STV_HIDDEN
: return "HIDDEN";
6987 case STV_PROTECTED
: return "PROTECTED";
6993 get_mips_symbol_other (unsigned int other
)
6997 case STO_OPTIONAL
: return "OPTIONAL";
6998 case STO_MIPS16
: return "MIPS16";
6999 case STO_MIPS_PLT
: return "MIPS PLT";
7000 case STO_MIPS_PIC
: return "MIPS PIC";
7001 default: return NULL
;
7006 get_symbol_other (unsigned int other
)
7008 const char * result
= NULL
;
7009 static char buff
[32];
7014 switch (elf_header
.e_machine
)
7017 result
= get_mips_symbol_other (other
);
7025 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
7030 get_symbol_index_type (unsigned int type
)
7032 static char buff
[32];
7036 case SHN_UNDEF
: return "UND";
7037 case SHN_ABS
: return "ABS";
7038 case SHN_COMMON
: return "COM";
7040 if (type
== SHN_IA_64_ANSI_COMMON
7041 && elf_header
.e_machine
== EM_IA_64
7042 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
7044 else if ((elf_header
.e_machine
== EM_X86_64
7045 || elf_header
.e_machine
== EM_L1OM
)
7046 && type
== SHN_X86_64_LCOMMON
)
7048 else if (type
== SHN_MIPS_SCOMMON
7049 && elf_header
.e_machine
== EM_MIPS
)
7051 else if (type
== SHN_MIPS_SUNDEFINED
7052 && elf_header
.e_machine
== EM_MIPS
)
7054 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
7055 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
7056 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
7057 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
7058 else if (type
>= SHN_LORESERVE
)
7059 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
7061 sprintf (buff
, "%3d", type
);
7069 get_dynamic_data (FILE * file
, unsigned int number
, unsigned int ent_size
)
7071 unsigned char * e_data
;
7074 e_data
= cmalloc (number
, ent_size
);
7078 error (_("Out of memory\n"));
7082 if (fread (e_data
, ent_size
, number
, file
) != number
)
7084 error (_("Unable to read in dynamic data\n"));
7088 i_data
= cmalloc (number
, sizeof (*i_data
));
7092 error (_("Out of memory\n"));
7098 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7106 print_dynamic_symbol (bfd_vma si
, unsigned long hn
)
7108 Elf_Internal_Sym
* psym
;
7111 psym
= dynamic_symbols
+ si
;
7113 n
= print_vma (si
, DEC_5
);
7115 fputs (" " + n
, stdout
);
7116 printf (" %3lu: ", hn
);
7117 print_vma (psym
->st_value
, LONG_HEX
);
7119 print_vma (psym
->st_size
, DEC_5
);
7121 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7122 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7123 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7124 /* Check to see if any other bits in the st_other field are set.
7125 Note - displaying this information disrupts the layout of the
7126 table being generated, but for the moment this case is very
7128 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7129 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7130 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7131 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7132 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7134 printf (" <corrupt: %14ld>", psym
->st_name
);
7138 /* Dump the symbol table. */
7140 process_symbol_table (FILE * file
)
7142 Elf_Internal_Shdr
* section
;
7143 bfd_vma nbuckets
= 0;
7144 bfd_vma nchains
= 0;
7145 bfd_vma
* buckets
= NULL
;
7146 bfd_vma
* chains
= NULL
;
7147 bfd_vma ngnubuckets
= 0;
7148 bfd_vma
* gnubuckets
= NULL
;
7149 bfd_vma
* gnuchains
= NULL
;
7150 bfd_vma gnusymidx
= 0;
7152 if (! do_syms
&& !do_histogram
)
7155 if (dynamic_info
[DT_HASH
]
7157 || (do_using_dynamic
&& dynamic_strings
!= NULL
)))
7159 unsigned char nb
[8];
7160 unsigned char nc
[8];
7161 int hash_ent_size
= 4;
7163 if ((elf_header
.e_machine
== EM_ALPHA
7164 || elf_header
.e_machine
== EM_S390
7165 || elf_header
.e_machine
== EM_S390_OLD
)
7166 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7170 (archive_file_offset
7171 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7172 sizeof nb
+ sizeof nc
)),
7175 error (_("Unable to seek to start of dynamic information\n"));
7179 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7181 error (_("Failed to read in number of buckets\n"));
7185 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7187 error (_("Failed to read in number of chains\n"));
7191 nbuckets
= byte_get (nb
, hash_ent_size
);
7192 nchains
= byte_get (nc
, hash_ent_size
);
7194 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7195 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7198 if (buckets
== NULL
|| chains
== NULL
)
7200 if (do_using_dynamic
)
7211 if (dynamic_info_DT_GNU_HASH
7213 || (do_using_dynamic
&& dynamic_strings
!= NULL
)))
7215 unsigned char nb
[16];
7216 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
7217 bfd_vma buckets_vma
;
7220 (archive_file_offset
7221 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7225 error (_("Unable to seek to start of dynamic information\n"));
7229 if (fread (nb
, 16, 1, file
) != 1)
7231 error (_("Failed to read in number of buckets\n"));
7235 ngnubuckets
= byte_get (nb
, 4);
7236 gnusymidx
= byte_get (nb
+ 4, 4);
7237 bitmaskwords
= byte_get (nb
+ 8, 4);
7238 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7240 buckets_vma
+= bitmaskwords
* 4;
7242 buckets_vma
+= bitmaskwords
* 8;
7245 (archive_file_offset
7246 + offset_from_vma (file
, buckets_vma
, 4)),
7249 error (_("Unable to seek to start of dynamic information\n"));
7253 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7255 if (gnubuckets
== NULL
)
7258 for (i
= 0; i
< ngnubuckets
; i
++)
7259 if (gnubuckets
[i
] != 0)
7261 if (gnubuckets
[i
] < gnusymidx
)
7264 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7265 maxchain
= gnubuckets
[i
];
7268 if (maxchain
== 0xffffffff)
7271 maxchain
-= gnusymidx
;
7274 (archive_file_offset
7275 + offset_from_vma (file
, buckets_vma
7276 + 4 * (ngnubuckets
+ maxchain
), 4)),
7279 error (_("Unable to seek to start of dynamic information\n"));
7285 if (fread (nb
, 4, 1, file
) != 1)
7287 error (_("Failed to determine last chain length\n"));
7291 if (maxchain
+ 1 == 0)
7296 while ((byte_get (nb
, 4) & 1) == 0);
7299 (archive_file_offset
7300 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7303 error (_("Unable to seek to start of dynamic information\n"));
7307 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7310 if (gnuchains
== NULL
)
7315 if (do_using_dynamic
)
7320 if ((dynamic_info
[DT_HASH
] || dynamic_info_DT_GNU_HASH
)
7323 && dynamic_strings
!= NULL
)
7327 if (dynamic_info
[DT_HASH
])
7331 printf (_("\nSymbol table for image:\n"));
7333 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7335 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7337 for (hn
= 0; hn
< nbuckets
; hn
++)
7342 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7343 print_dynamic_symbol (si
, hn
);
7347 if (dynamic_info_DT_GNU_HASH
)
7349 printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
7351 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7353 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7355 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7356 if (gnubuckets
[hn
] != 0)
7358 bfd_vma si
= gnubuckets
[hn
];
7359 bfd_vma off
= si
- gnusymidx
;
7363 print_dynamic_symbol (si
, hn
);
7366 while ((gnuchains
[off
++] & 1) == 0);
7370 else if (do_syms
&& !do_using_dynamic
)
7374 for (i
= 0, section
= section_headers
;
7375 i
< elf_header
.e_shnum
;
7379 char * strtab
= NULL
;
7380 unsigned long int strtab_size
= 0;
7381 Elf_Internal_Sym
* symtab
;
7382 Elf_Internal_Sym
* psym
;
7384 if ( section
->sh_type
!= SHT_SYMTAB
7385 && section
->sh_type
!= SHT_DYNSYM
)
7388 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7389 SECTION_NAME (section
),
7390 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7392 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7394 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7396 symtab
= GET_ELF_SYMBOLS (file
, section
);
7400 if (section
->sh_link
== elf_header
.e_shstrndx
)
7402 strtab
= string_table
;
7403 strtab_size
= string_table_length
;
7405 else if (section
->sh_link
< elf_header
.e_shnum
)
7407 Elf_Internal_Shdr
* string_sec
;
7409 string_sec
= section_headers
+ section
->sh_link
;
7411 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
7412 1, string_sec
->sh_size
, _("string table"));
7413 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7416 for (si
= 0, psym
= symtab
;
7417 si
< section
->sh_size
/ section
->sh_entsize
;
7420 printf ("%6d: ", si
);
7421 print_vma (psym
->st_value
, LONG_HEX
);
7423 print_vma (psym
->st_size
, DEC_5
);
7424 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7425 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7426 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7427 /* Check to see if any other bits in the st_other field are set.
7428 Note - displaying this information disrupts the layout of the
7429 table being generated, but for the moment this case is very rare. */
7430 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7431 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7432 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7433 print_symbol (25, psym
->st_name
< strtab_size
7434 ? strtab
+ psym
->st_name
: "<corrupt>");
7436 if (section
->sh_type
== SHT_DYNSYM
&&
7437 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7439 unsigned char data
[2];
7440 unsigned short vers_data
;
7441 unsigned long offset
;
7445 offset
= offset_from_vma
7446 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7447 sizeof data
+ si
* sizeof (vers_data
));
7449 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7450 sizeof (data
), 1, _("version data"));
7452 vers_data
= byte_get (data
, 2);
7454 is_nobits
= (psym
->st_shndx
< elf_header
.e_shnum
7455 && section_headers
[psym
->st_shndx
].sh_type
7458 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7460 if ((vers_data
& 0x8000) || vers_data
> 1)
7462 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7463 && (is_nobits
|| ! check_def
))
7465 Elf_External_Verneed evn
;
7466 Elf_Internal_Verneed ivn
;
7467 Elf_Internal_Vernaux ivna
;
7469 /* We must test both. */
7470 offset
= offset_from_vma
7471 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7476 unsigned long vna_off
;
7478 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7481 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7482 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7484 vna_off
= offset
+ ivn
.vn_aux
;
7488 Elf_External_Vernaux evna
;
7490 get_data (&evna
, file
, vna_off
,
7492 _("version need aux (3)"));
7494 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7495 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7496 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7498 vna_off
+= ivna
.vna_next
;
7500 while (ivna
.vna_other
!= vers_data
7501 && ivna
.vna_next
!= 0);
7503 if (ivna
.vna_other
== vers_data
)
7506 offset
+= ivn
.vn_next
;
7508 while (ivn
.vn_next
!= 0);
7510 if (ivna
.vna_other
== vers_data
)
7513 ivna
.vna_name
< strtab_size
7514 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7518 else if (! is_nobits
)
7519 error (_("bad dynamic symbol\n"));
7526 if (vers_data
!= 0x8001
7527 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7529 Elf_Internal_Verdef ivd
;
7530 Elf_Internal_Verdaux ivda
;
7531 Elf_External_Verdaux evda
;
7532 unsigned long offset
;
7534 offset
= offset_from_vma
7536 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7537 sizeof (Elf_External_Verdef
));
7541 Elf_External_Verdef evd
;
7543 get_data (&evd
, file
, offset
, sizeof (evd
),
7544 1, _("version def"));
7546 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7547 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7548 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7550 offset
+= ivd
.vd_next
;
7552 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7553 && ivd
.vd_next
!= 0);
7555 offset
-= ivd
.vd_next
;
7556 offset
+= ivd
.vd_aux
;
7558 get_data (&evda
, file
, offset
, sizeof (evda
),
7559 1, _("version def aux"));
7561 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7563 if (psym
->st_name
!= ivda
.vda_name
)
7564 printf ((vers_data
& 0x8000)
7566 ivda
.vda_name
< strtab_size
7567 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7577 if (strtab
!= string_table
)
7583 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7585 if (do_histogram
&& buckets
!= NULL
)
7587 unsigned long * lengths
;
7588 unsigned long * counts
;
7591 unsigned long maxlength
= 0;
7592 unsigned long nzero_counts
= 0;
7593 unsigned long nsyms
= 0;
7595 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7596 (unsigned long) nbuckets
);
7597 printf (_(" Length Number %% of total Coverage\n"));
7599 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7600 if (lengths
== NULL
)
7602 error (_("Out of memory\n"));
7605 for (hn
= 0; hn
< nbuckets
; ++hn
)
7607 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7610 if (maxlength
< ++lengths
[hn
])
7615 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7618 error (_("Out of memory\n"));
7622 for (hn
= 0; hn
< nbuckets
; ++hn
)
7623 ++counts
[lengths
[hn
]];
7628 printf (" 0 %-10lu (%5.1f%%)\n",
7629 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7630 for (i
= 1; i
<= maxlength
; ++i
)
7632 nzero_counts
+= counts
[i
] * i
;
7633 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7634 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7635 (nzero_counts
* 100.0) / nsyms
);
7643 if (buckets
!= NULL
)
7649 if (do_histogram
&& gnubuckets
!= NULL
)
7651 unsigned long * lengths
;
7652 unsigned long * counts
;
7654 unsigned long maxlength
= 0;
7655 unsigned long nzero_counts
= 0;
7656 unsigned long nsyms
= 0;
7658 lengths
= calloc (ngnubuckets
, sizeof (*lengths
));
7659 if (lengths
== NULL
)
7661 error (_("Out of memory\n"));
7665 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7666 (unsigned long) ngnubuckets
);
7667 printf (_(" Length Number %% of total Coverage\n"));
7669 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7670 if (gnubuckets
[hn
] != 0)
7672 bfd_vma off
, length
= 1;
7674 for (off
= gnubuckets
[hn
] - gnusymidx
;
7675 (gnuchains
[off
] & 1) == 0; ++off
)
7677 lengths
[hn
] = length
;
7678 if (length
> maxlength
)
7683 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7686 error (_("Out of memory\n"));
7690 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7691 ++counts
[lengths
[hn
]];
7693 if (ngnubuckets
> 0)
7696 printf (" 0 %-10lu (%5.1f%%)\n",
7697 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7698 for (j
= 1; j
<= maxlength
; ++j
)
7700 nzero_counts
+= counts
[j
] * j
;
7701 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7702 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7703 (nzero_counts
* 100.0) / nsyms
);
7717 process_syminfo (FILE * file ATTRIBUTE_UNUSED
)
7721 if (dynamic_syminfo
== NULL
7723 /* No syminfo, this is ok. */
7726 /* There better should be a dynamic symbol section. */
7727 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7731 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7732 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7734 printf (_(" Num: Name BoundTo Flags\n"));
7735 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7737 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7739 printf ("%4d: ", i
);
7740 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7741 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7743 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7746 switch (dynamic_syminfo
[i
].si_boundto
)
7748 case SYMINFO_BT_SELF
:
7749 fputs ("SELF ", stdout
);
7751 case SYMINFO_BT_PARENT
:
7752 fputs ("PARENT ", stdout
);
7755 if (dynamic_syminfo
[i
].si_boundto
> 0
7756 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7757 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7759 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7763 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7767 if (flags
& SYMINFO_FLG_DIRECT
)
7769 if (flags
& SYMINFO_FLG_PASSTHRU
)
7770 printf (" PASSTHRU");
7771 if (flags
& SYMINFO_FLG_COPY
)
7773 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7774 printf (" LAZYLOAD");
7782 /* Check to see if the given reloc needs to be handled in a target specific
7783 manner. If so then process the reloc and return TRUE otherwise return
7787 target_specific_reloc_handling (Elf_Internal_Rela
* reloc
,
7788 unsigned char * start
,
7789 Elf_Internal_Sym
* symtab
)
7791 unsigned int reloc_type
= get_reloc_type (reloc
->r_info
);
7793 switch (elf_header
.e_machine
)
7796 case EM_CYGNUS_MN10300
:
7798 static Elf_Internal_Sym
* saved_sym
= NULL
;
7802 case 34: /* R_MN10300_ALIGN */
7804 case 33: /* R_MN10300_SYM_DIFF */
7805 saved_sym
= symtab
+ get_reloc_symindex (reloc
->r_info
);
7807 case 1: /* R_MN10300_32 */
7808 case 2: /* R_MN10300_16 */
7809 if (saved_sym
!= NULL
)
7813 value
= reloc
->r_addend
7814 + (symtab
[get_reloc_symindex (reloc
->r_info
)].st_value
7815 - saved_sym
->st_value
);
7817 byte_put (start
+ reloc
->r_offset
, value
, reloc_type
== 1 ? 4 : 2);
7824 if (saved_sym
!= NULL
)
7825 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc"));
7835 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
7836 DWARF debug sections. This is a target specific test. Note - we do not
7837 go through the whole including-target-headers-multiple-times route, (as
7838 we have already done with <elf/h8.h>) because this would become very
7839 messy and even then this function would have to contain target specific
7840 information (the names of the relocs instead of their numeric values).
7841 FIXME: This is not the correct way to solve this problem. The proper way
7842 is to have target specific reloc sizing and typing functions created by
7843 the reloc-macros.h header, in the same way that it already creates the
7844 reloc naming functions. */
7847 is_32bit_abs_reloc (unsigned int reloc_type
)
7849 switch (elf_header
.e_machine
)
7853 return reloc_type
== 1; /* R_386_32. */
7855 return reloc_type
== 1; /* R_68K_32. */
7857 return reloc_type
== 1; /* R_860_32. */
7859 return reloc_type
== 1; /* XXX Is this right ? */
7861 return reloc_type
== 1; /* R_ARC_32. */
7863 return reloc_type
== 2; /* R_ARM_ABS32 */
7866 return reloc_type
== 1;
7868 return reloc_type
== 0x12; /* R_byte4_data. */
7870 return reloc_type
== 3; /* R_CRIS_32. */
7873 return reloc_type
== 3; /* R_CR16_NUM32. */
7875 return reloc_type
== 15; /* R_CRX_NUM32. */
7877 return reloc_type
== 1;
7878 case EM_CYGNUS_D10V
:
7880 return reloc_type
== 6; /* R_D10V_32. */
7881 case EM_CYGNUS_D30V
:
7883 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
7885 return reloc_type
== 3; /* R_DLX_RELOC_32. */
7886 case EM_CYGNUS_FR30
:
7888 return reloc_type
== 3; /* R_FR30_32. */
7892 return reloc_type
== 1; /* R_H8_DIR32. */
7894 return reloc_type
== 0x65; /* R_IA64_SECREL32LSB. */
7897 return reloc_type
== 2; /* R_IP2K_32. */
7899 return reloc_type
== 2; /* R_IQ2000_32. */
7900 case EM_LATTICEMICO32
:
7901 return reloc_type
== 3; /* R_LM32_32. */
7904 return reloc_type
== 3; /* R_M32C_32. */
7906 return reloc_type
== 34; /* R_M32R_32_RELA. */
7908 return reloc_type
== 1; /* R_MCORE_ADDR32. */
7910 return reloc_type
== 4; /* R_MEP_32. */
7912 return reloc_type
== 2; /* R_MIPS_32. */
7914 return reloc_type
== 4; /* R_MMIX_32. */
7915 case EM_CYGNUS_MN10200
:
7917 return reloc_type
== 1; /* R_MN10200_32. */
7918 case EM_CYGNUS_MN10300
:
7920 return reloc_type
== 1; /* R_MN10300_32. */
7923 return reloc_type
== 1; /* R_MSP43_32. */
7925 return reloc_type
== 2; /* R_MT_32. */
7926 case EM_ALTERA_NIOS2
:
7928 return reloc_type
== 1; /* R_NIOS_32. */
7931 return reloc_type
== 1; /* R_OR32_32. */
7933 return reloc_type
== 1; /* R_PARISC_DIR32. */
7936 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
7938 return reloc_type
== 1; /* R_PPC64_ADDR32. */
7940 return reloc_type
== 1; /* R_PPC_ADDR32. */
7942 return reloc_type
== 1; /* R_I370_ADDR31. */
7945 return reloc_type
== 4; /* R_S390_32. */
7947 return reloc_type
== 8; /* R_SCORE_ABS32. */
7949 return reloc_type
== 1; /* R_SH_DIR32. */
7950 case EM_SPARC32PLUS
:
7953 return reloc_type
== 3 /* R_SPARC_32. */
7954 || reloc_type
== 23; /* R_SPARC_UA32. */
7956 return reloc_type
== 6; /* R_SPU_ADDR32 */
7957 case EM_CYGNUS_V850
:
7959 return reloc_type
== 6; /* R_V850_ABS32. */
7961 return reloc_type
== 1; /* R_VAX_32. */
7964 return reloc_type
== 10; /* R_X86_64_32. */
7966 return reloc_type
== 1; /* R_XSTROMY16_32. */
7969 return reloc_type
== 1; /* R_XTENSA_32. */
7972 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
7973 elf_header
.e_machine
);
7978 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
7979 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
7982 is_32bit_pcrel_reloc (unsigned int reloc_type
)
7984 switch (elf_header
.e_machine
)
7988 return reloc_type
== 2; /* R_386_PC32. */
7990 return reloc_type
== 4; /* R_68K_PC32. */
7992 return reloc_type
== 10; /* R_ALPHA_SREL32. */
7994 return reloc_type
== 3; /* R_ARM_REL32 */
7996 return reloc_type
== 9; /* R_PARISC_PCREL32. */
7998 return reloc_type
== 26; /* R_PPC_REL32. */
8000 return reloc_type
== 26; /* R_PPC64_REL32. */
8003 return reloc_type
== 5; /* R_390_PC32. */
8005 return reloc_type
== 2; /* R_SH_REL32. */
8006 case EM_SPARC32PLUS
:
8009 return reloc_type
== 6; /* R_SPARC_DISP32. */
8011 return reloc_type
== 13; /* R_SPU_REL32. */
8014 return reloc_type
== 2; /* R_X86_64_PC32. */
8017 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
8019 /* Do not abort or issue an error message here. Not all targets use
8020 pc-relative 32-bit relocs in their DWARF debug information and we
8021 have already tested for target coverage in is_32bit_abs_reloc. A
8022 more helpful warning message will be generated by apply_relocations
8023 anyway, so just return. */
8028 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8029 a 64-bit absolute RELA relocation used in DWARF debug sections. */
8032 is_64bit_abs_reloc (unsigned int reloc_type
)
8034 switch (elf_header
.e_machine
)
8037 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
8039 return reloc_type
== 0x27; /* R_IA64_DIR64LSB. */
8041 return reloc_type
== 80; /* R_PARISC_DIR64. */
8043 return reloc_type
== 38; /* R_PPC64_ADDR64. */
8044 case EM_SPARC32PLUS
:
8047 return reloc_type
== 54; /* R_SPARC_UA64. */
8050 return reloc_type
== 1; /* R_X86_64_64. */
8053 return reloc_type
== 22; /* R_S390_64 */
8055 return reloc_type
== 18; /* R_MIPS_64 */
8061 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
8062 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
8065 is_64bit_pcrel_reloc (unsigned int reloc_type
)
8067 switch (elf_header
.e_machine
)
8070 return reloc_type
== 11; /* R_ALPHA_SREL64 */
8072 return reloc_type
== 0x4f; /* R_IA64_PCREL64LSB */
8074 return reloc_type
== 72; /* R_PARISC_PCREL64 */
8076 return reloc_type
== 44; /* R_PPC64_REL64 */
8077 case EM_SPARC32PLUS
:
8080 return reloc_type
== 46; /* R_SPARC_DISP64 */
8083 return reloc_type
== 24; /* R_X86_64_PC64 */
8086 return reloc_type
== 23; /* R_S390_PC64 */
8092 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8093 a 16-bit absolute RELA relocation used in DWARF debug sections. */
8096 is_16bit_abs_reloc (unsigned int reloc_type
)
8098 switch (elf_header
.e_machine
)
8102 return reloc_type
== 4; /* R_AVR_16. */
8103 case EM_CYGNUS_D10V
:
8105 return reloc_type
== 3; /* R_D10V_16. */
8109 return reloc_type
== R_H8_DIR16
;
8112 return reloc_type
== 1; /* R_IP2K_16. */
8115 return reloc_type
== 1; /* R_M32C_16 */
8118 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
8119 case EM_ALTERA_NIOS2
:
8121 return reloc_type
== 9; /* R_NIOS_16. */
8127 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
8128 relocation entries (possibly formerly used for SHT_GROUP sections). */
8131 is_none_reloc (unsigned int reloc_type
)
8133 switch (elf_header
.e_machine
)
8135 case EM_68K
: /* R_68K_NONE. */
8136 case EM_386
: /* R_386_NONE. */
8137 case EM_SPARC32PLUS
:
8139 case EM_SPARC
: /* R_SPARC_NONE. */
8140 case EM_MIPS
: /* R_MIPS_NONE. */
8141 case EM_PARISC
: /* R_PARISC_NONE. */
8142 case EM_ALPHA
: /* R_ALPHA_NONE. */
8143 case EM_PPC
: /* R_PPC_NONE. */
8144 case EM_PPC64
: /* R_PPC64_NONE. */
8145 case EM_ARM
: /* R_ARM_NONE. */
8146 case EM_IA_64
: /* R_IA64_NONE. */
8147 case EM_SH
: /* R_SH_NONE. */
8149 case EM_S390
: /* R_390_NONE. */
8150 case EM_CRIS
: /* R_CRIS_NONE. */
8151 case EM_X86_64
: /* R_X86_64_NONE. */
8152 case EM_L1OM
: /* R_X86_64_NONE. */
8153 case EM_MN10300
: /* R_MN10300_NONE. */
8154 case EM_M32R
: /* R_M32R_NONE. */
8155 return reloc_type
== 0;
8160 /* Apply relocations to a section.
8161 Note: So far support has been added only for those relocations
8162 which can be found in debug sections.
8163 FIXME: Add support for more relocations ? */
8166 apply_relocations (void * file
,
8167 Elf_Internal_Shdr
* section
,
8168 unsigned char * start
)
8170 Elf_Internal_Shdr
* relsec
;
8171 unsigned char * end
= start
+ section
->sh_size
;
8173 if (elf_header
.e_type
!= ET_REL
)
8176 /* Find the reloc section associated with the section. */
8177 for (relsec
= section_headers
;
8178 relsec
< section_headers
+ elf_header
.e_shnum
;
8181 bfd_boolean is_rela
;
8182 unsigned long num_relocs
;
8183 Elf_Internal_Rela
* relocs
;
8184 Elf_Internal_Rela
* rp
;
8185 Elf_Internal_Shdr
* symsec
;
8186 Elf_Internal_Sym
* symtab
;
8187 Elf_Internal_Sym
* sym
;
8189 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8190 || relsec
->sh_info
>= elf_header
.e_shnum
8191 || section_headers
+ relsec
->sh_info
!= section
8192 || relsec
->sh_size
== 0
8193 || relsec
->sh_link
>= elf_header
.e_shnum
)
8196 is_rela
= relsec
->sh_type
== SHT_RELA
;
8200 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8201 & relocs
, & num_relocs
))
8206 if (!slurp_rel_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8207 & relocs
, & num_relocs
))
8211 /* SH uses RELA but uses in place value instead of the addend field. */
8212 if (elf_header
.e_machine
== EM_SH
)
8215 symsec
= section_headers
+ relsec
->sh_link
;
8216 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
8218 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
8221 unsigned int reloc_type
;
8222 unsigned int reloc_size
;
8223 unsigned char * loc
;
8225 reloc_type
= get_reloc_type (rp
->r_info
);
8227 if (target_specific_reloc_handling (rp
, start
, symtab
))
8229 else if (is_none_reloc (reloc_type
))
8231 else if (is_32bit_abs_reloc (reloc_type
)
8232 || is_32bit_pcrel_reloc (reloc_type
))
8234 else if (is_64bit_abs_reloc (reloc_type
)
8235 || is_64bit_pcrel_reloc (reloc_type
))
8237 else if (is_16bit_abs_reloc (reloc_type
))
8241 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
8242 reloc_type
, SECTION_NAME (section
));
8246 loc
= start
+ rp
->r_offset
;
8247 if ((loc
+ reloc_size
) > end
)
8249 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
8250 (unsigned long) rp
->r_offset
,
8251 SECTION_NAME (section
));
8255 sym
= symtab
+ get_reloc_symindex (rp
->r_info
);
8257 /* If the reloc has a symbol associated with it,
8258 make sure that it is of an appropriate type.
8260 Relocations against symbols without type can happen.
8261 Gcc -feliminate-dwarf2-dups may generate symbols
8262 without type for debug info.
8264 Icc generates relocations against function symbols
8265 instead of local labels.
8267 Relocations against object symbols can happen, eg when
8268 referencing a global array. For an example of this see
8269 the _clz.o binary in libgcc.a. */
8271 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
8273 warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
8274 get_symbol_type (ELF_ST_TYPE (sym
->st_info
)),
8275 (long int)(rp
- relocs
),
8276 SECTION_NAME (relsec
));
8280 addend
= is_rela
? rp
->r_addend
: byte_get (loc
, reloc_size
);
8282 if (is_32bit_pcrel_reloc (reloc_type
)
8283 || is_64bit_pcrel_reloc (reloc_type
))
8285 /* On HPPA, all pc-relative relocations are biased by 8. */
8286 if (elf_header
.e_machine
== EM_PARISC
)
8288 byte_put (loc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
8292 byte_put (loc
, addend
+ sym
->st_value
, reloc_size
);
8301 #ifdef SUPPORT_DISASSEMBLY
8303 disassemble_section (Elf_Internal_Shdr
* section
, FILE * file
)
8305 printf (_("\nAssembly dump of section %s\n"),
8306 SECTION_NAME (section
));
8308 /* XXX -- to be done --- XXX */
8314 /* Reads in the contents of SECTION from FILE, returning a pointer
8315 to a malloc'ed buffer or NULL if something went wrong. */
8318 get_section_contents (Elf_Internal_Shdr
* section
, FILE * file
)
8320 bfd_size_type num_bytes
;
8322 num_bytes
= section
->sh_size
;
8324 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
8326 printf (_("\nSection '%s' has no data to dump.\n"),
8327 SECTION_NAME (section
));
8331 return get_data (NULL
, file
, section
->sh_offset
, 1, num_bytes
,
8332 _("section contents"));
8337 dump_section_as_strings (Elf_Internal_Shdr
* section
, FILE * file
)
8339 Elf_Internal_Shdr
* relsec
;
8340 bfd_size_type num_bytes
;
8345 char * name
= SECTION_NAME (section
);
8346 bfd_boolean some_strings_shown
;
8348 start
= get_section_contents (section
, file
);
8352 printf (_("\nString dump of section '%s':\n"), name
);
8354 /* If the section being dumped has relocations against it the user might
8355 be expecting these relocations to have been applied. Check for this
8356 case and issue a warning message in order to avoid confusion.
8357 FIXME: Maybe we ought to have an option that dumps a section with
8359 for (relsec
= section_headers
;
8360 relsec
< section_headers
+ elf_header
.e_shnum
;
8363 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8364 || relsec
->sh_info
>= elf_header
.e_shnum
8365 || section_headers
+ relsec
->sh_info
!= section
8366 || relsec
->sh_size
== 0
8367 || relsec
->sh_link
>= elf_header
.e_shnum
)
8370 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
8374 num_bytes
= section
->sh_size
;
8375 addr
= section
->sh_addr
;
8377 end
= start
+ num_bytes
;
8378 some_strings_shown
= FALSE
;
8382 while (!ISPRINT (* data
))
8389 printf (" [%6tx] %s\n", data
- start
, data
);
8391 printf (" [%6Ix] %s\n", (size_t) (data
- start
), data
);
8393 data
+= strlen (data
);
8394 some_strings_shown
= TRUE
;
8398 if (! some_strings_shown
)
8399 printf (_(" No strings found in this section."));
8407 dump_section_as_bytes (Elf_Internal_Shdr
* section
,
8409 bfd_boolean relocate
)
8411 Elf_Internal_Shdr
* relsec
;
8412 bfd_size_type bytes
;
8414 unsigned char * data
;
8415 unsigned char * start
;
8417 start
= (unsigned char *) get_section_contents (section
, file
);
8421 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
8425 apply_relocations (file
, section
, start
);
8429 /* If the section being dumped has relocations against it the user might
8430 be expecting these relocations to have been applied. Check for this
8431 case and issue a warning message in order to avoid confusion.
8432 FIXME: Maybe we ought to have an option that dumps a section with
8434 for (relsec
= section_headers
;
8435 relsec
< section_headers
+ elf_header
.e_shnum
;
8438 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8439 || relsec
->sh_info
>= elf_header
.e_shnum
8440 || section_headers
+ relsec
->sh_info
!= section
8441 || relsec
->sh_size
== 0
8442 || relsec
->sh_link
>= elf_header
.e_shnum
)
8445 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
8450 addr
= section
->sh_addr
;
8451 bytes
= section
->sh_size
;
8460 lbytes
= (bytes
> 16 ? 16 : bytes
);
8462 printf (" 0x%8.8lx ", (unsigned long) addr
);
8464 for (j
= 0; j
< 16; j
++)
8467 printf ("%2.2x", data
[j
]);
8475 for (j
= 0; j
< lbytes
; j
++)
8478 if (k
>= ' ' && k
< 0x7f)
8496 /* Uncompresses a section that was compressed using zlib, in place.
8497 This is a copy of bfd_uncompress_section_contents, in bfd/compress.c */
8500 uncompress_section_contents (unsigned char ** buffer
, dwarf_size_type
* size
)
8503 /* These are just to quiet gcc. */
8508 dwarf_size_type compressed_size
= *size
;
8509 unsigned char * compressed_buffer
= *buffer
;
8510 dwarf_size_type uncompressed_size
;
8511 unsigned char * uncompressed_buffer
;
8514 dwarf_size_type header_size
= 12;
8516 /* Read the zlib header. In this case, it should be "ZLIB" followed
8517 by the uncompressed section size, 8 bytes in big-endian order. */
8518 if (compressed_size
< header_size
8519 || ! streq ((char *) compressed_buffer
, "ZLIB"))
8522 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
8523 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
8524 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
8525 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
8526 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
8527 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
8528 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
8529 uncompressed_size
+= compressed_buffer
[11];
8531 /* It is possible the section consists of several compressed
8532 buffers concatenated together, so we uncompress in a loop. */
8536 strm
.avail_in
= compressed_size
- header_size
;
8537 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
8538 strm
.avail_out
= uncompressed_size
;
8539 uncompressed_buffer
= xmalloc (uncompressed_size
);
8541 rc
= inflateInit (& strm
);
8542 while (strm
.avail_in
> 0)
8546 strm
.next_out
= ((Bytef
*) uncompressed_buffer
8547 + (uncompressed_size
- strm
.avail_out
));
8548 rc
= inflate (&strm
, Z_FINISH
);
8549 if (rc
!= Z_STREAM_END
)
8551 rc
= inflateReset (& strm
);
8553 rc
= inflateEnd (& strm
);
8555 || strm
.avail_out
!= 0)
8558 free (compressed_buffer
);
8559 *buffer
= uncompressed_buffer
;
8560 *size
= uncompressed_size
;
8564 free (uncompressed_buffer
);
8566 #endif /* HAVE_ZLIB_H */
8570 load_specific_debug_section (enum dwarf_section_display_enum debug
,
8571 Elf_Internal_Shdr
* sec
, void * file
)
8573 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
8575 int section_is_compressed
;
8577 /* If it is already loaded, do nothing. */
8578 if (section
->start
!= NULL
)
8581 section_is_compressed
= section
->name
== section
->compressed_name
;
8583 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
8584 section
->address
= sec
->sh_addr
;
8585 section
->size
= sec
->sh_size
;
8586 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
8588 if (section
->start
== NULL
)
8591 if (section_is_compressed
)
8592 if (! uncompress_section_contents (§ion
->start
, §ion
->size
))
8595 if (debug_displays
[debug
].relocate
)
8596 apply_relocations (file
, sec
, section
->start
);
8602 load_debug_section (enum dwarf_section_display_enum debug
, void * file
)
8604 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
8605 Elf_Internal_Shdr
* sec
;
8607 /* Locate the debug section. */
8608 sec
= find_section (section
->uncompressed_name
);
8610 section
->name
= section
->uncompressed_name
;
8613 sec
= find_section (section
->compressed_name
);
8615 section
->name
= section
->compressed_name
;
8620 return load_specific_debug_section (debug
, sec
, file
);
8624 free_debug_section (enum dwarf_section_display_enum debug
)
8626 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
8628 if (section
->start
== NULL
)
8631 free ((char *) section
->start
);
8632 section
->start
= NULL
;
8633 section
->address
= 0;
8638 display_debug_section (Elf_Internal_Shdr
* section
, FILE * file
)
8640 char * name
= SECTION_NAME (section
);
8641 bfd_size_type length
;
8643 enum dwarf_section_display_enum i
;
8645 length
= section
->sh_size
;
8648 printf (_("\nSection '%s' has no debugging data.\n"), name
);
8651 if (section
->sh_type
== SHT_NOBITS
)
8653 /* There is no point in dumping the contents of a debugging section
8654 which has the NOBITS type - the bits in the file will be random.
8655 This can happen when a file containing a .eh_frame section is
8656 stripped with the --only-keep-debug command line option. */
8657 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), name
);
8661 if (const_strneq (name
, ".gnu.linkonce.wi."))
8662 name
= ".debug_info";
8664 /* See if we know how to display the contents of this section. */
8665 for (i
= 0; i
< max
; i
++)
8666 if (streq (debug_displays
[i
].section
.uncompressed_name
, name
)
8667 || streq (debug_displays
[i
].section
.compressed_name
, name
))
8669 struct dwarf_section
* sec
= &debug_displays
[i
].section
;
8670 int secondary
= (section
!= find_section (name
));
8673 free_debug_section (i
);
8675 if (streq (debug_displays
[i
].section
.uncompressed_name
, name
))
8676 sec
->name
= sec
->uncompressed_name
;
8678 sec
->name
= sec
->compressed_name
;
8679 if (load_specific_debug_section (i
, section
, file
))
8681 result
&= debug_displays
[i
].display (sec
, file
);
8683 if (secondary
|| (i
!= info
&& i
!= abbrev
))
8684 free_debug_section (i
);
8692 printf (_("Unrecognized debug section: %s\n"), name
);
8699 /* Set DUMP_SECTS for all sections where dumps were requested
8700 based on section name. */
8703 initialise_dumps_byname (void)
8705 struct dump_list_entry
* cur
;
8707 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
8712 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
8713 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
8715 request_dump_bynumber (i
, cur
->type
);
8720 warn (_("Section '%s' was not dumped because it does not exist!\n"),
8726 process_section_contents (FILE * file
)
8728 Elf_Internal_Shdr
* section
;
8734 initialise_dumps_byname ();
8736 for (i
= 0, section
= section_headers
;
8737 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8740 #ifdef SUPPORT_DISASSEMBLY
8741 if (dump_sects
[i
] & DISASS_DUMP
)
8742 disassemble_section (section
, file
);
8744 if (dump_sects
[i
] & HEX_DUMP
)
8745 dump_section_as_bytes (section
, file
, FALSE
);
8747 if (dump_sects
[i
] & RELOC_DUMP
)
8748 dump_section_as_bytes (section
, file
, TRUE
);
8750 if (dump_sects
[i
] & STRING_DUMP
)
8751 dump_section_as_strings (section
, file
);
8753 if (dump_sects
[i
] & DEBUG_DUMP
)
8754 display_debug_section (section
, file
);
8757 /* Check to see if the user requested a
8758 dump of a section that does not exist. */
8759 while (i
++ < num_dump_sects
)
8761 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
8765 process_mips_fpe_exception (int mask
)
8770 if (mask
& OEX_FPU_INEX
)
8771 fputs ("INEX", stdout
), first
= 0;
8772 if (mask
& OEX_FPU_UFLO
)
8773 printf ("%sUFLO", first
? "" : "|"), first
= 0;
8774 if (mask
& OEX_FPU_OFLO
)
8775 printf ("%sOFLO", first
? "" : "|"), first
= 0;
8776 if (mask
& OEX_FPU_DIV0
)
8777 printf ("%sDIV0", first
? "" : "|"), first
= 0;
8778 if (mask
& OEX_FPU_INVAL
)
8779 printf ("%sINVAL", first
? "" : "|");
8782 fputs ("0", stdout
);
8785 /* ARM EABI attributes section. */
8790 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8792 const char ** table
;
8793 } arm_attr_public_tag
;
8795 static const char * arm_attr_tag_CPU_arch
[] =
8796 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8797 "v6K", "v7", "v6-M", "v6S-M"};
8798 static const char * arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8799 static const char * arm_attr_tag_THUMB_ISA_use
[] =
8800 {"No", "Thumb-1", "Thumb-2"};
8801 static const char * arm_attr_tag_VFP_arch
[] =
8802 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16"};
8803 static const char * arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
8804 static const char * arm_attr_tag_Advanced_SIMD_arch
[] = {"No", "NEONv1"};
8805 static const char * arm_attr_tag_PCS_config
[] =
8806 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8807 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8808 static const char * arm_attr_tag_ABI_PCS_R9_use
[] =
8809 {"V6", "SB", "TLS", "Unused"};
8810 static const char * arm_attr_tag_ABI_PCS_RW_data
[] =
8811 {"Absolute", "PC-relative", "SB-relative", "None"};
8812 static const char * arm_attr_tag_ABI_PCS_RO_data
[] =
8813 {"Absolute", "PC-relative", "None"};
8814 static const char * arm_attr_tag_ABI_PCS_GOT_use
[] =
8815 {"None", "direct", "GOT-indirect"};
8816 static const char * arm_attr_tag_ABI_PCS_wchar_t
[] =
8817 {"None", "??? 1", "2", "??? 3", "4"};
8818 static const char * arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8819 static const char * arm_attr_tag_ABI_FP_denormal
[] =
8820 {"Unused", "Needed", "Sign only"};
8821 static const char * arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8822 static const char * arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8823 static const char * arm_attr_tag_ABI_FP_number_model
[] =
8824 {"Unused", "Finite", "RTABI", "IEEE 754"};
8825 static const char * arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8826 static const char * arm_attr_tag_ABI_align8_preserved
[] =
8827 {"No", "Yes, except leaf SP", "Yes"};
8828 static const char * arm_attr_tag_ABI_enum_size
[] =
8829 {"Unused", "small", "int", "forced to int"};
8830 static const char * arm_attr_tag_ABI_HardFP_use
[] =
8831 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8832 static const char * arm_attr_tag_ABI_VFP_args
[] =
8833 {"AAPCS", "VFP registers", "custom"};
8834 static const char * arm_attr_tag_ABI_WMMX_args
[] =
8835 {"AAPCS", "WMMX registers", "custom"};
8836 static const char * arm_attr_tag_ABI_optimization_goals
[] =
8837 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8838 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8839 static const char * arm_attr_tag_ABI_FP_optimization_goals
[] =
8840 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8841 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8842 static const char * arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
8843 static const char * arm_attr_tag_VFP_HP_extension
[] =
8844 {"Not Allowed", "Allowed"};
8845 static const char * arm_attr_tag_ABI_FP_16bit_format
[] =
8846 {"None", "IEEE 754", "Alternative Format"};
8847 static const char * arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
8848 static const char * arm_attr_tag_Virtualization_use
[] =
8849 {"Not Allowed", "Allowed"};
8850 static const char * arm_attr_tag_MPextension_use
[] = {"Not Allowed", "Allowed"};
8852 #define LOOKUP(id, name) \
8853 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8854 static arm_attr_public_tag arm_attr_public_tags
[] =
8856 {4, "CPU_raw_name", 1, NULL
},
8857 {5, "CPU_name", 1, NULL
},
8858 LOOKUP(6, CPU_arch
),
8859 {7, "CPU_arch_profile", 0, NULL
},
8860 LOOKUP(8, ARM_ISA_use
),
8861 LOOKUP(9, THUMB_ISA_use
),
8862 LOOKUP(10, VFP_arch
),
8863 LOOKUP(11, WMMX_arch
),
8864 LOOKUP(12, Advanced_SIMD_arch
),
8865 LOOKUP(13, PCS_config
),
8866 LOOKUP(14, ABI_PCS_R9_use
),
8867 LOOKUP(15, ABI_PCS_RW_data
),
8868 LOOKUP(16, ABI_PCS_RO_data
),
8869 LOOKUP(17, ABI_PCS_GOT_use
),
8870 LOOKUP(18, ABI_PCS_wchar_t
),
8871 LOOKUP(19, ABI_FP_rounding
),
8872 LOOKUP(20, ABI_FP_denormal
),
8873 LOOKUP(21, ABI_FP_exceptions
),
8874 LOOKUP(22, ABI_FP_user_exceptions
),
8875 LOOKUP(23, ABI_FP_number_model
),
8876 LOOKUP(24, ABI_align8_needed
),
8877 LOOKUP(25, ABI_align8_preserved
),
8878 LOOKUP(26, ABI_enum_size
),
8879 LOOKUP(27, ABI_HardFP_use
),
8880 LOOKUP(28, ABI_VFP_args
),
8881 LOOKUP(29, ABI_WMMX_args
),
8882 LOOKUP(30, ABI_optimization_goals
),
8883 LOOKUP(31, ABI_FP_optimization_goals
),
8884 {32, "compatibility", 0, NULL
},
8885 LOOKUP(34, CPU_unaligned_access
),
8886 LOOKUP(36, VFP_HP_extension
),
8887 LOOKUP(38, ABI_FP_16bit_format
),
8888 {64, "nodefaults", 0, NULL
},
8889 {65, "also_compatible_with", 0, NULL
},
8890 LOOKUP(66, T2EE_use
),
8891 {67, "conformance", 1, NULL
},
8892 LOOKUP(68, Virtualization_use
),
8893 LOOKUP(70, MPextension_use
)
8897 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8901 read_uleb128 (unsigned char * p
, unsigned int * plen
)
8915 val
|= ((unsigned int)c
& 0x7f) << shift
;
8924 static unsigned char *
8925 display_arm_attribute (unsigned char * p
)
8930 arm_attr_public_tag
* attr
;
8934 tag
= read_uleb128 (p
, &len
);
8937 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
8939 if (arm_attr_public_tags
[i
].tag
== tag
)
8941 attr
= &arm_attr_public_tags
[i
];
8948 printf (" Tag_%s: ", attr
->name
);
8954 case 7: /* Tag_CPU_arch_profile. */
8955 val
= read_uleb128 (p
, &len
);
8959 case 0: printf ("None\n"); break;
8960 case 'A': printf ("Application\n"); break;
8961 case 'R': printf ("Realtime\n"); break;
8962 case 'M': printf ("Microcontroller\n"); break;
8963 default: printf ("??? (%d)\n", val
); break;
8967 case 32: /* Tag_compatibility. */
8968 val
= read_uleb128 (p
, &len
);
8970 printf ("flag = %d, vendor = %s\n", val
, p
);
8971 p
+= strlen ((char *) p
) + 1;
8974 case 64: /* Tag_nodefaults. */
8979 case 65: /* Tag_also_compatible_with. */
8980 val
= read_uleb128 (p
, &len
);
8982 if (val
== 6 /* Tag_CPU_arch. */)
8984 val
= read_uleb128 (p
, &len
);
8986 if ((unsigned int)val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
8987 printf ("??? (%d)\n", val
);
8989 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
8993 while (*(p
++) != '\0' /* NUL terminator. */);
9007 assert (attr
->type
& 0x80);
9008 val
= read_uleb128 (p
, &len
);
9010 type
= attr
->type
& 0x7f;
9012 printf ("??? (%d)\n", val
);
9014 printf ("%s\n", attr
->table
[val
]);
9021 type
= 1; /* String. */
9023 type
= 2; /* uleb128. */
9024 printf (" Tag_unknown_%d: ", tag
);
9029 printf ("\"%s\"\n", p
);
9030 p
+= strlen ((char *) p
) + 1;
9034 val
= read_uleb128 (p
, &len
);
9036 printf ("%d (0x%x)\n", val
, val
);
9042 static unsigned char *
9043 display_gnu_attribute (unsigned char * p
,
9044 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
9051 tag
= read_uleb128 (p
, &len
);
9054 /* Tag_compatibility is the only generic GNU attribute defined at
9058 val
= read_uleb128 (p
, &len
);
9060 printf ("flag = %d, vendor = %s\n", val
, p
);
9061 p
+= strlen ((char *) p
) + 1;
9065 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
9066 return display_proc_gnu_attribute (p
, tag
);
9069 type
= 1; /* String. */
9071 type
= 2; /* uleb128. */
9072 printf (" Tag_unknown_%d: ", tag
);
9076 printf ("\"%s\"\n", p
);
9077 p
+= strlen ((char *) p
) + 1;
9081 val
= read_uleb128 (p
, &len
);
9083 printf ("%d (0x%x)\n", val
, val
);
9089 static unsigned char *
9090 display_power_gnu_attribute (unsigned char * p
, int tag
)
9096 if (tag
== Tag_GNU_Power_ABI_FP
)
9098 val
= read_uleb128 (p
, &len
);
9100 printf (" Tag_GNU_Power_ABI_FP: ");
9105 printf ("Hard or soft float\n");
9108 printf ("Hard float\n");
9111 printf ("Soft float\n");
9114 printf ("Single-precision hard float\n");
9117 printf ("??? (%d)\n", val
);
9123 if (tag
== Tag_GNU_Power_ABI_Vector
)
9125 val
= read_uleb128 (p
, &len
);
9127 printf (" Tag_GNU_Power_ABI_Vector: ");
9134 printf ("Generic\n");
9137 printf ("AltiVec\n");
9143 printf ("??? (%d)\n", val
);
9149 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
9151 val
= read_uleb128 (p
, &len
);
9153 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
9163 printf ("Memory\n");
9166 printf ("??? (%d)\n", val
);
9173 type
= 1; /* String. */
9175 type
= 2; /* uleb128. */
9176 printf (" Tag_unknown_%d: ", tag
);
9180 printf ("\"%s\"\n", p
);
9181 p
+= strlen ((char *) p
) + 1;
9185 val
= read_uleb128 (p
, &len
);
9187 printf ("%d (0x%x)\n", val
, val
);
9193 static unsigned char *
9194 display_mips_gnu_attribute (unsigned char * p
, int tag
)
9200 if (tag
== Tag_GNU_MIPS_ABI_FP
)
9202 val
= read_uleb128 (p
, &len
);
9204 printf (" Tag_GNU_MIPS_ABI_FP: ");
9209 printf ("Hard or soft float\n");
9212 printf ("Hard float (-mdouble-float)\n");
9215 printf ("Hard float (-msingle-float)\n");
9218 printf ("Soft float\n");
9221 printf ("64-bit float (-mips32r2 -mfp64)\n");
9224 printf ("??? (%d)\n", val
);
9231 type
= 1; /* String. */
9233 type
= 2; /* uleb128. */
9234 printf (" Tag_unknown_%d: ", tag
);
9238 printf ("\"%s\"\n", p
);
9239 p
+= strlen ((char *) p
) + 1;
9243 val
= read_uleb128 (p
, &len
);
9245 printf ("%d (0x%x)\n", val
, val
);
9252 process_attributes (FILE * file
,
9253 const char * public_name
,
9254 unsigned int proc_type
,
9255 unsigned char * (* display_pub_attribute
) (unsigned char *),
9256 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
9258 Elf_Internal_Shdr
* sect
;
9259 unsigned char * contents
;
9261 unsigned char * end
;
9262 bfd_vma section_len
;
9266 /* Find the section header so that we get the size. */
9267 for (i
= 0, sect
= section_headers
;
9268 i
< elf_header
.e_shnum
;
9271 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
9274 contents
= get_data (NULL
, file
, sect
->sh_offset
, 1, sect
->sh_size
,
9276 if (contents
== NULL
)
9282 len
= sect
->sh_size
- 1;
9288 bfd_boolean public_section
;
9289 bfd_boolean gnu_section
;
9291 section_len
= byte_get (p
, 4);
9294 if (section_len
> len
)
9296 printf (_("ERROR: Bad section length (%d > %d)\n"),
9297 (int) section_len
, (int) len
);
9302 printf ("Attribute Section: %s\n", p
);
9304 if (public_name
&& streq ((char *) p
, public_name
))
9305 public_section
= TRUE
;
9307 public_section
= FALSE
;
9309 if (streq ((char *) p
, "gnu"))
9312 gnu_section
= FALSE
;
9314 namelen
= strlen ((char *) p
) + 1;
9316 section_len
-= namelen
+ 4;
9318 while (section_len
> 0)
9324 size
= byte_get (p
, 4);
9325 if (size
> section_len
)
9327 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
9328 (int) size
, (int) section_len
);
9332 section_len
-= size
;
9339 printf ("File Attributes\n");
9342 printf ("Section Attributes:");
9345 printf ("Symbol Attributes:");
9351 val
= read_uleb128 (p
, &i
);
9355 printf (" %d", val
);
9360 printf ("Unknown tag: %d\n", tag
);
9361 public_section
= FALSE
;
9368 p
= display_pub_attribute (p
);
9370 else if (gnu_section
)
9373 p
= display_gnu_attribute (p
,
9374 display_proc_gnu_attribute
);
9378 /* ??? Do something sensible, like dump hex. */
9379 printf (" Unknown section contexts\n");
9386 printf (_("Unknown format '%c'\n"), *p
);
9394 process_arm_specific (FILE * file
)
9396 return process_attributes (file
, "aeabi", SHT_ARM_ATTRIBUTES
,
9397 display_arm_attribute
, NULL
);
9401 process_power_specific (FILE * file
)
9403 return process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
9404 display_power_gnu_attribute
);
9407 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
9408 Print the Address, Access and Initial fields of an entry at VMA ADDR
9409 and return the VMA of the next entry. */
9412 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
9415 print_vma (addr
, LONG_HEX
);
9417 if (addr
< pltgot
+ 0xfff0)
9418 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
9420 printf ("%10s", "");
9423 printf ("%*s", is_32bit_elf
? 8 : 16, "<unknown>");
9428 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
9429 print_vma (entry
, LONG_HEX
);
9431 return addr
+ (is_32bit_elf
? 4 : 8);
9434 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
9435 PLTGOT. Print the Address and Initial fields of an entry at VMA
9436 ADDR and return the VMA of the next entry. */
9439 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
9442 print_vma (addr
, LONG_HEX
);
9445 printf ("%*s", is_32bit_elf
? 8 : 16, "<unknown>");
9450 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
9451 print_vma (entry
, LONG_HEX
);
9453 return addr
+ (is_32bit_elf
? 4 : 8);
9457 process_mips_specific (FILE * file
)
9459 Elf_Internal_Dyn
* entry
;
9460 size_t liblist_offset
= 0;
9461 size_t liblistno
= 0;
9462 size_t conflictsno
= 0;
9463 size_t options_offset
= 0;
9464 size_t conflicts_offset
= 0;
9465 size_t pltrelsz
= 0;
9468 bfd_vma mips_pltgot
= 0;
9470 bfd_vma local_gotno
= 0;
9472 bfd_vma symtabno
= 0;
9474 process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
9475 display_mips_gnu_attribute
);
9477 /* We have a lot of special sections. Thanks SGI! */
9478 if (dynamic_section
== NULL
)
9479 /* No information available. */
9482 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
9483 switch (entry
->d_tag
)
9485 case DT_MIPS_LIBLIST
:
9487 = offset_from_vma (file
, entry
->d_un
.d_val
,
9488 liblistno
* sizeof (Elf32_External_Lib
));
9490 case DT_MIPS_LIBLISTNO
:
9491 liblistno
= entry
->d_un
.d_val
;
9493 case DT_MIPS_OPTIONS
:
9494 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
9496 case DT_MIPS_CONFLICT
:
9498 = offset_from_vma (file
, entry
->d_un
.d_val
,
9499 conflictsno
* sizeof (Elf32_External_Conflict
));
9501 case DT_MIPS_CONFLICTNO
:
9502 conflictsno
= entry
->d_un
.d_val
;
9505 pltgot
= entry
->d_un
.d_ptr
;
9507 case DT_MIPS_LOCAL_GOTNO
:
9508 local_gotno
= entry
->d_un
.d_val
;
9510 case DT_MIPS_GOTSYM
:
9511 gotsym
= entry
->d_un
.d_val
;
9513 case DT_MIPS_SYMTABNO
:
9514 symtabno
= entry
->d_un
.d_val
;
9516 case DT_MIPS_PLTGOT
:
9517 mips_pltgot
= entry
->d_un
.d_ptr
;
9520 pltrel
= entry
->d_un
.d_val
;
9523 pltrelsz
= entry
->d_un
.d_val
;
9526 jmprel
= entry
->d_un
.d_ptr
;
9532 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9534 Elf32_External_Lib
* elib
;
9537 elib
= get_data (NULL
, file
, liblist_offset
,
9538 liblistno
, sizeof (Elf32_External_Lib
),
9542 printf ("\nSection '.liblist' contains %lu entries:\n",
9543 (unsigned long) liblistno
);
9544 fputs (" Library Time Stamp Checksum Version Flags\n",
9547 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9554 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9555 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9556 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9557 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9558 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9560 tmp
= gmtime (&time
);
9561 snprintf (timebuf
, sizeof (timebuf
),
9562 "%04u-%02u-%02uT%02u:%02u:%02u",
9563 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9564 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9566 printf ("%3lu: ", (unsigned long) cnt
);
9567 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
9568 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
9570 printf ("<corrupt: %9ld>", liblist
.l_name
);
9571 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9574 if (liblist
.l_flags
== 0)
9585 { " EXACT_MATCH", LL_EXACT_MATCH
},
9586 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9587 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9588 { " EXPORTS", LL_EXPORTS
},
9589 { " DELAY_LOAD", LL_DELAY_LOAD
},
9590 { " DELTA", LL_DELTA
}
9592 int flags
= liblist
.l_flags
;
9595 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
9596 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9598 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9599 flags
^= l_flags_vals
[fcnt
].bit
;
9602 printf (" %#x", (unsigned int) flags
);
9612 if (options_offset
!= 0)
9614 Elf_External_Options
* eopt
;
9615 Elf_Internal_Shdr
* sect
= section_headers
;
9616 Elf_Internal_Options
* iopt
;
9617 Elf_Internal_Options
* option
;
9621 /* Find the section header so that we get the size. */
9622 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9625 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
9629 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (* iopt
));
9632 error (_("Out of memory\n"));
9639 while (offset
< sect
->sh_size
)
9641 Elf_External_Options
* eoption
;
9643 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9645 option
->kind
= BYTE_GET (eoption
->kind
);
9646 option
->size
= BYTE_GET (eoption
->size
);
9647 option
->section
= BYTE_GET (eoption
->section
);
9648 option
->info
= BYTE_GET (eoption
->info
);
9650 offset
+= option
->size
;
9656 printf (_("\nSection '%s' contains %d entries:\n"),
9657 SECTION_NAME (sect
), cnt
);
9665 switch (option
->kind
)
9668 /* This shouldn't happen. */
9669 printf (" NULL %d %lx", option
->section
, option
->info
);
9672 printf (" REGINFO ");
9673 if (elf_header
.e_machine
== EM_MIPS
)
9676 Elf32_External_RegInfo
* ereg
;
9677 Elf32_RegInfo reginfo
;
9679 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9680 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9681 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9682 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9683 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9684 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9685 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9687 printf ("GPR %08lx GP 0x%lx\n",
9689 (unsigned long) reginfo
.ri_gp_value
);
9690 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9691 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9692 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9697 Elf64_External_RegInfo
* ereg
;
9698 Elf64_Internal_RegInfo reginfo
;
9700 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9701 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9702 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9703 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9704 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9705 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9706 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9708 printf ("GPR %08lx GP 0x",
9709 reginfo
.ri_gprmask
);
9710 printf_vma (reginfo
.ri_gp_value
);
9713 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9714 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9715 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9719 case ODK_EXCEPTIONS
:
9720 fputs (" EXCEPTIONS fpe_min(", stdout
);
9721 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9722 fputs (") fpe_max(", stdout
);
9723 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9724 fputs (")", stdout
);
9726 if (option
->info
& OEX_PAGE0
)
9727 fputs (" PAGE0", stdout
);
9728 if (option
->info
& OEX_SMM
)
9729 fputs (" SMM", stdout
);
9730 if (option
->info
& OEX_FPDBUG
)
9731 fputs (" FPDBUG", stdout
);
9732 if (option
->info
& OEX_DISMISS
)
9733 fputs (" DISMISS", stdout
);
9736 fputs (" PAD ", stdout
);
9737 if (option
->info
& OPAD_PREFIX
)
9738 fputs (" PREFIX", stdout
);
9739 if (option
->info
& OPAD_POSTFIX
)
9740 fputs (" POSTFIX", stdout
);
9741 if (option
->info
& OPAD_SYMBOL
)
9742 fputs (" SYMBOL", stdout
);
9745 fputs (" HWPATCH ", stdout
);
9746 if (option
->info
& OHW_R4KEOP
)
9747 fputs (" R4KEOP", stdout
);
9748 if (option
->info
& OHW_R8KPFETCH
)
9749 fputs (" R8KPFETCH", stdout
);
9750 if (option
->info
& OHW_R5KEOP
)
9751 fputs (" R5KEOP", stdout
);
9752 if (option
->info
& OHW_R5KCVTL
)
9753 fputs (" R5KCVTL", stdout
);
9756 fputs (" FILL ", stdout
);
9757 /* XXX Print content of info word? */
9760 fputs (" TAGS ", stdout
);
9761 /* XXX Print content of info word? */
9764 fputs (" HWAND ", stdout
);
9765 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9766 fputs (" R4KEOP_CHECKED", stdout
);
9767 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9768 fputs (" R4KEOP_CLEAN", stdout
);
9771 fputs (" HWOR ", stdout
);
9772 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9773 fputs (" R4KEOP_CHECKED", stdout
);
9774 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9775 fputs (" R4KEOP_CLEAN", stdout
);
9778 printf (" GP_GROUP %#06lx self-contained %#06lx",
9779 option
->info
& OGP_GROUP
,
9780 (option
->info
& OGP_SELF
) >> 16);
9783 printf (" IDENT %#06lx self-contained %#06lx",
9784 option
->info
& OGP_GROUP
,
9785 (option
->info
& OGP_SELF
) >> 16);
9788 /* This shouldn't happen. */
9789 printf (" %3d ??? %d %lx",
9790 option
->kind
, option
->section
, option
->info
);
9794 len
= sizeof (* eopt
);
9795 while (len
< option
->size
)
9796 if (((char *) option
)[len
] >= ' '
9797 && ((char *) option
)[len
] < 0x7f)
9798 printf ("%c", ((char *) option
)[len
++]);
9800 printf ("\\%03o", ((char *) option
)[len
++]);
9802 fputs ("\n", stdout
);
9810 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9812 Elf32_Conflict
* iconf
;
9815 if (dynamic_symbols
== NULL
)
9817 error (_("conflict list found without a dynamic symbol table\n"));
9821 iconf
= cmalloc (conflictsno
, sizeof (* iconf
));
9824 error (_("Out of memory\n"));
9830 Elf32_External_Conflict
* econf32
;
9832 econf32
= get_data (NULL
, file
, conflicts_offset
,
9833 conflictsno
, sizeof (* econf32
), _("conflict"));
9837 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9838 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9844 Elf64_External_Conflict
* econf64
;
9846 econf64
= get_data (NULL
, file
, conflicts_offset
,
9847 conflictsno
, sizeof (* econf64
), _("conflict"));
9851 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9852 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
9857 printf (_("\nSection '.conflict' contains %lu entries:\n"),
9858 (unsigned long) conflictsno
);
9859 puts (_(" Num: Index Value Name"));
9861 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9863 Elf_Internal_Sym
* psym
= & dynamic_symbols
[iconf
[cnt
]];
9865 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
9866 print_vma (psym
->st_value
, FULL_HEX
);
9868 if (VALID_DYNAMIC_NAME (psym
->st_name
))
9869 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
9871 printf ("<corrupt: %14ld>", psym
->st_name
);
9878 if (pltgot
!= 0 && local_gotno
!= 0)
9880 bfd_vma entry
, local_end
, global_end
;
9882 unsigned char * data
;
9886 addr_size
= (is_32bit_elf
? 4 : 8);
9887 local_end
= pltgot
+ local_gotno
* addr_size
;
9888 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
9890 offset
= offset_from_vma (file
, pltgot
, global_end
- pltgot
);
9891 data
= get_data (NULL
, file
, offset
, global_end
- pltgot
, 1, _("GOT"));
9892 printf (_("\nPrimary GOT:\n"));
9893 printf (_(" Canonical gp value: "));
9894 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
9897 printf (_(" Reserved entries:\n"));
9898 printf (_(" %*s %10s %*s Purpose\n"),
9899 addr_size
* 2, "Address", "Access",
9900 addr_size
* 2, "Initial");
9901 entry
= print_mips_got_entry (data
, pltgot
, entry
);
9902 printf (" Lazy resolver\n");
9904 && (byte_get (data
+ entry
- pltgot
, addr_size
)
9905 >> (addr_size
* 8 - 1)) != 0)
9907 entry
= print_mips_got_entry (data
, pltgot
, entry
);
9908 printf (" Module pointer (GNU extension)\n");
9912 if (entry
< local_end
)
9914 printf (_(" Local entries:\n"));
9915 printf (_(" %*s %10s %*s\n"),
9916 addr_size
* 2, "Address", "Access",
9917 addr_size
* 2, "Initial");
9918 while (entry
< local_end
)
9920 entry
= print_mips_got_entry (data
, pltgot
, entry
);
9926 if (gotsym
< symtabno
)
9930 printf (_(" Global entries:\n"));
9931 printf (_(" %*s %10s %*s %*s %-7s %3s %s\n"),
9932 addr_size
* 2, "Address", "Access",
9933 addr_size
* 2, "Initial",
9934 addr_size
* 2, "Sym.Val.", "Type", "Ndx", "Name");
9935 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
9936 for (i
= gotsym
; i
< symtabno
; i
++)
9938 Elf_Internal_Sym
* psym
;
9940 psym
= dynamic_symbols
+ i
;
9941 entry
= print_mips_got_entry (data
, pltgot
, entry
);
9943 print_vma (psym
->st_value
, LONG_HEX
);
9944 printf (" %-7s %3s ",
9945 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
9946 get_symbol_index_type (psym
->st_shndx
));
9947 if (VALID_DYNAMIC_NAME (psym
->st_name
))
9948 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
9950 printf ("<corrupt: %14ld>", psym
->st_name
);
9960 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
9963 size_t offset
, rel_offset
;
9964 unsigned long count
, i
;
9965 unsigned char * data
;
9966 int addr_size
, sym_width
;
9967 Elf_Internal_Rela
* rels
;
9969 rel_offset
= offset_from_vma (file
, jmprel
, pltrelsz
);
9970 if (pltrel
== DT_RELA
)
9972 if (!slurp_rela_relocs (file
, rel_offset
, pltrelsz
, &rels
, &count
))
9977 if (!slurp_rel_relocs (file
, rel_offset
, pltrelsz
, &rels
, &count
))
9981 entry
= mips_pltgot
;
9982 addr_size
= (is_32bit_elf
? 4 : 8);
9983 end
= mips_pltgot
+ (2 + count
) * addr_size
;
9985 offset
= offset_from_vma (file
, mips_pltgot
, end
- mips_pltgot
);
9986 data
= get_data (NULL
, file
, offset
, end
- mips_pltgot
, 1, _("PLT GOT"));
9987 printf (_("\nPLT GOT:\n\n"));
9988 printf (_(" Reserved entries:\n"));
9989 printf (_(" %*s %*s Purpose\n"),
9990 addr_size
* 2, "Address", addr_size
* 2, "Initial");
9991 entry
= print_mips_pltgot_entry (data
, mips_pltgot
, entry
);
9992 printf (" PLT lazy resolver\n");
9993 entry
= print_mips_pltgot_entry (data
, mips_pltgot
, entry
);
9994 printf (" Module pointer\n");
9997 printf (_(" Entries:\n"));
9998 printf (_(" %*s %*s %*s %-7s %3s %s\n"),
9999 addr_size
* 2, "Address",
10000 addr_size
* 2, "Initial",
10001 addr_size
* 2, "Sym.Val.", "Type", "Ndx", "Name");
10002 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
10003 for (i
= 0; i
< count
; i
++)
10005 Elf_Internal_Sym
* psym
;
10007 psym
= dynamic_symbols
+ get_reloc_symindex (rels
[i
].r_info
);
10008 entry
= print_mips_pltgot_entry (data
, mips_pltgot
, entry
);
10010 print_vma (psym
->st_value
, LONG_HEX
);
10011 printf (" %-7s %3s ",
10012 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
10013 get_symbol_index_type (psym
->st_shndx
));
10014 if (VALID_DYNAMIC_NAME (psym
->st_name
))
10015 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
10017 printf ("<corrupt: %14ld>", psym
->st_name
);
10031 process_gnu_liblist (FILE * file
)
10033 Elf_Internal_Shdr
* section
;
10034 Elf_Internal_Shdr
* string_sec
;
10035 Elf32_External_Lib
* elib
;
10037 size_t strtab_size
;
10044 for (i
= 0, section
= section_headers
;
10045 i
< elf_header
.e_shnum
;
10048 switch (section
->sh_type
)
10050 case SHT_GNU_LIBLIST
:
10051 if (section
->sh_link
>= elf_header
.e_shnum
)
10054 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
10059 string_sec
= section_headers
+ section
->sh_link
;
10061 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
10062 string_sec
->sh_size
, _("liblist string table"));
10063 strtab_size
= string_sec
->sh_size
;
10066 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
10072 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
10073 SECTION_NAME (section
),
10074 (unsigned long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
10076 puts (" Library Time Stamp Checksum Version Flags");
10078 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
10086 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
10087 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
10088 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
10089 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
10090 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
10092 tmp
= gmtime (&time
);
10093 snprintf (timebuf
, sizeof (timebuf
),
10094 "%04u-%02u-%02uT%02u:%02u:%02u",
10095 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10096 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10098 printf ("%3lu: ", (unsigned long) cnt
);
10100 printf ("%-20s", liblist
.l_name
< strtab_size
10101 ? strtab
+ liblist
.l_name
: "<corrupt>");
10103 printf ("%-20.20s", liblist
.l_name
< strtab_size
10104 ? strtab
+ liblist
.l_name
: "<corrupt>");
10105 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
10106 liblist
.l_version
, liblist
.l_flags
);
10116 static const char *
10117 get_note_type (unsigned e_type
)
10119 static char buff
[64];
10121 if (elf_header
.e_type
== ET_CORE
)
10125 return _("NT_AUXV (auxiliary vector)");
10127 return _("NT_PRSTATUS (prstatus structure)");
10129 return _("NT_FPREGSET (floating point registers)");
10131 return _("NT_PRPSINFO (prpsinfo structure)");
10132 case NT_TASKSTRUCT
:
10133 return _("NT_TASKSTRUCT (task structure)");
10135 return _("NT_PRXFPREG (user_xfpregs structure)");
10137 return _("NT_PPC_VMX (ppc Altivec registers)");
10139 return _("NT_PPC_VSX (ppc VSX registers)");
10141 return _("NT_PSTATUS (pstatus structure)");
10143 return _("NT_FPREGS (floating point registers)");
10145 return _("NT_PSINFO (psinfo structure)");
10147 return _("NT_LWPSTATUS (lwpstatus_t structure)");
10149 return _("NT_LWPSINFO (lwpsinfo_t structure)");
10150 case NT_WIN32PSTATUS
:
10151 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
10159 return _("NT_VERSION (version)");
10161 return _("NT_ARCH (architecture)");
10166 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
10170 static const char *
10171 get_gnu_elf_note_type (unsigned e_type
)
10173 static char buff
[64];
10177 case NT_GNU_ABI_TAG
:
10178 return _("NT_GNU_ABI_TAG (ABI version tag)");
10180 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
10181 case NT_GNU_BUILD_ID
:
10182 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
10183 case NT_GNU_GOLD_VERSION
:
10184 return _("NT_GNU_GOLD_VERSION (gold version)");
10189 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
10193 static const char *
10194 get_netbsd_elfcore_note_type (unsigned e_type
)
10196 static char buff
[64];
10198 if (e_type
== NT_NETBSDCORE_PROCINFO
)
10200 /* NetBSD core "procinfo" structure. */
10201 return _("NetBSD procinfo structure");
10204 /* As of Jan 2002 there are no other machine-independent notes
10205 defined for NetBSD core files. If the note type is less
10206 than the start of the machine-dependent note types, we don't
10209 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
10211 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
10215 switch (elf_header
.e_machine
)
10217 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
10218 and PT_GETFPREGS == mach+2. */
10223 case EM_SPARC32PLUS
:
10227 case NT_NETBSDCORE_FIRSTMACH
+0:
10228 return _("PT_GETREGS (reg structure)");
10229 case NT_NETBSDCORE_FIRSTMACH
+2:
10230 return _("PT_GETFPREGS (fpreg structure)");
10236 /* On all other arch's, PT_GETREGS == mach+1 and
10237 PT_GETFPREGS == mach+3. */
10241 case NT_NETBSDCORE_FIRSTMACH
+1:
10242 return _("PT_GETREGS (reg structure)");
10243 case NT_NETBSDCORE_FIRSTMACH
+3:
10244 return _("PT_GETFPREGS (fpreg structure)");
10250 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
10251 e_type
- NT_NETBSDCORE_FIRSTMACH
);
10255 /* Note that by the ELF standard, the name field is already null byte
10256 terminated, and namesz includes the terminating null byte.
10257 I.E. the value of namesz for the name "FSF" is 4.
10259 If the value of namesz is zero, there is no name present. */
10261 process_note (Elf_Internal_Note
* pnote
)
10263 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
10266 if (pnote
->namesz
== 0)
10267 /* If there is no note name, then use the default set of
10268 note type strings. */
10269 nt
= get_note_type (pnote
->type
);
10271 else if (const_strneq (pnote
->namedata
, "GNU"))
10272 /* GNU-specific object file notes. */
10273 nt
= get_gnu_elf_note_type (pnote
->type
);
10275 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
10276 /* NetBSD-specific core file notes. */
10277 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
10279 else if (strneq (pnote
->namedata
, "SPU/", 4))
10281 /* SPU-specific core file notes. */
10282 nt
= pnote
->namedata
+ 4;
10287 /* Don't recognize this note name; just use the default set of
10288 note type strings. */
10289 nt
= get_note_type (pnote
->type
);
10291 printf (" %s\t\t0x%08lx\t%s\n", name
, pnote
->descsz
, nt
);
10297 process_corefile_note_segment (FILE * file
, bfd_vma offset
, bfd_vma length
)
10299 Elf_External_Note
* pnotes
;
10300 Elf_External_Note
* external
;
10306 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
10312 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
10313 (unsigned long) offset
, (unsigned long) length
);
10314 printf (_(" Owner\t\tData size\tDescription\n"));
10316 while (external
< (Elf_External_Note
*) ((char *) pnotes
+ length
))
10318 Elf_External_Note
* next
;
10319 Elf_Internal_Note inote
;
10320 char * temp
= NULL
;
10322 inote
.type
= BYTE_GET (external
->type
);
10323 inote
.namesz
= BYTE_GET (external
->namesz
);
10324 inote
.namedata
= external
->name
;
10325 inote
.descsz
= BYTE_GET (external
->descsz
);
10326 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
10327 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
10329 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
10331 if (((char *) next
) > (((char *) pnotes
) + length
))
10333 warn (_("corrupt note found at offset %lx into core notes\n"),
10334 (unsigned long) ((char *) external
- (char *) pnotes
));
10335 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
10336 inote
.type
, inote
.namesz
, inote
.descsz
);
10342 /* Verify that name is null terminated. It appears that at least
10343 one version of Linux (RedHat 6.0) generates corefiles that don't
10344 comply with the ELF spec by failing to include the null byte in
10346 if (inote
.namedata
[inote
.namesz
] != '\0')
10348 temp
= malloc (inote
.namesz
+ 1);
10352 error (_("Out of memory\n"));
10357 strncpy (temp
, inote
.namedata
, inote
.namesz
);
10358 temp
[inote
.namesz
] = 0;
10360 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
10361 inote
.namedata
= temp
;
10364 res
&= process_note (& inote
);
10379 process_corefile_note_segments (FILE * file
)
10381 Elf_Internal_Phdr
* segment
;
10385 if (! get_program_headers (file
))
10388 for (i
= 0, segment
= program_headers
;
10389 i
< elf_header
.e_phnum
;
10392 if (segment
->p_type
== PT_NOTE
)
10393 res
&= process_corefile_note_segment (file
,
10394 (bfd_vma
) segment
->p_offset
,
10395 (bfd_vma
) segment
->p_filesz
);
10402 process_note_sections (FILE * file
)
10404 Elf_Internal_Shdr
* section
;
10408 for (i
= 0, section
= section_headers
;
10409 i
< elf_header
.e_shnum
;
10411 if (section
->sh_type
== SHT_NOTE
)
10412 res
&= process_corefile_note_segment (file
,
10413 (bfd_vma
) section
->sh_offset
,
10414 (bfd_vma
) section
->sh_size
);
10420 process_notes (FILE * file
)
10422 /* If we have not been asked to display the notes then do nothing. */
10426 if (elf_header
.e_type
!= ET_CORE
)
10427 return process_note_sections (file
);
10429 /* No program headers means no NOTE segment. */
10430 if (elf_header
.e_phnum
> 0)
10431 return process_corefile_note_segments (file
);
10433 printf (_("No note segments present in the core file.\n"));
10438 process_arch_specific (FILE * file
)
10443 switch (elf_header
.e_machine
)
10446 return process_arm_specific (file
);
10448 case EM_MIPS_RS3_LE
:
10449 return process_mips_specific (file
);
10452 return process_power_specific (file
);
10461 get_file_header (FILE * file
)
10463 /* Read in the identity array. */
10464 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
10467 /* Determine how to read the rest of the header. */
10468 switch (elf_header
.e_ident
[EI_DATA
])
10470 default: /* fall through */
10471 case ELFDATANONE
: /* fall through */
10473 byte_get
= byte_get_little_endian
;
10474 byte_put
= byte_put_little_endian
;
10477 byte_get
= byte_get_big_endian
;
10478 byte_put
= byte_put_big_endian
;
10482 /* For now we only support 32 bit and 64 bit ELF files. */
10483 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
10485 /* Read in the rest of the header. */
10488 Elf32_External_Ehdr ehdr32
;
10490 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
10493 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
10494 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
10495 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
10496 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
10497 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
10498 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
10499 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
10500 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
10501 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
10502 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
10503 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
10504 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
10505 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
10509 Elf64_External_Ehdr ehdr64
;
10511 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10512 we will not be able to cope with the 64bit data found in
10513 64 ELF files. Detect this now and abort before we start
10514 overwriting things. */
10515 if (sizeof (bfd_vma
) < 8)
10517 error (_("This instance of readelf has been built without support for a\n\
10518 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10522 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
10525 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
10526 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
10527 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
10528 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
10529 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
10530 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
10531 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
10532 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
10533 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
10534 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
10535 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
10536 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
10537 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
10540 if (elf_header
.e_shoff
)
10542 /* There may be some extensions in the first section header. Don't
10543 bomb if we can't read it. */
10545 get_32bit_section_headers (file
, 1);
10547 get_64bit_section_headers (file
, 1);
10553 /* Process one ELF object file according to the command line options.
10554 This file may actually be stored in an archive. The file is
10555 positioned at the start of the ELF object. */
10558 process_object (char * file_name
, FILE * file
)
10562 if (! get_file_header (file
))
10564 error (_("%s: Failed to read file header\n"), file_name
);
10568 /* Initialise per file variables. */
10569 for (i
= ARRAY_SIZE (version_info
); i
--;)
10570 version_info
[i
] = 0;
10572 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
10573 dynamic_info
[i
] = 0;
10575 /* Process the file. */
10577 printf (_("\nFile: %s\n"), file_name
);
10579 /* Initialise the dump_sects array from the cmdline_dump_sects array.
10580 Note we do this even if cmdline_dump_sects is empty because we
10581 must make sure that the dump_sets array is zeroed out before each
10582 object file is processed. */
10583 if (num_dump_sects
> num_cmdline_dump_sects
)
10584 memset (dump_sects
, 0, num_dump_sects
* sizeof (* dump_sects
));
10586 if (num_cmdline_dump_sects
> 0)
10588 if (num_dump_sects
== 0)
10589 /* A sneaky way of allocating the dump_sects array. */
10590 request_dump_bynumber (num_cmdline_dump_sects
, 0);
10592 assert (num_dump_sects
>= num_cmdline_dump_sects
);
10593 memcpy (dump_sects
, cmdline_dump_sects
,
10594 num_cmdline_dump_sects
* sizeof (* dump_sects
));
10597 if (! process_file_header ())
10600 if (! process_section_headers (file
))
10602 /* Without loaded section headers we cannot process lots of
10604 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10606 if (! do_using_dynamic
)
10607 do_syms
= do_reloc
= 0;
10610 if (! process_section_groups (file
))
10612 /* Without loaded section groups we cannot process unwind. */
10616 if (process_program_headers (file
))
10617 process_dynamic_section (file
);
10619 process_relocs (file
);
10621 process_unwind (file
);
10623 process_symbol_table (file
);
10625 process_syminfo (file
);
10627 process_version_sections (file
);
10629 process_section_contents (file
);
10631 process_notes (file
);
10633 process_gnu_liblist (file
);
10635 process_arch_specific (file
);
10637 if (program_headers
)
10639 free (program_headers
);
10640 program_headers
= NULL
;
10643 if (section_headers
)
10645 free (section_headers
);
10646 section_headers
= NULL
;
10651 free (string_table
);
10652 string_table
= NULL
;
10653 string_table_length
= 0;
10656 if (dynamic_strings
)
10658 free (dynamic_strings
);
10659 dynamic_strings
= NULL
;
10660 dynamic_strings_length
= 0;
10663 if (dynamic_symbols
)
10665 free (dynamic_symbols
);
10666 dynamic_symbols
= NULL
;
10667 num_dynamic_syms
= 0;
10670 if (dynamic_syminfo
)
10672 free (dynamic_syminfo
);
10673 dynamic_syminfo
= NULL
;
10676 if (section_headers_groups
)
10678 free (section_headers_groups
);
10679 section_headers_groups
= NULL
;
10682 if (section_groups
)
10684 struct group_list
* g
;
10685 struct group_list
* next
;
10687 for (i
= 0; i
< group_count
; i
++)
10689 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
10696 free (section_groups
);
10697 section_groups
= NULL
;
10700 free_debug_memory ();
10705 /* Return the path name for a proxy entry in a thin archive, adjusted relative
10706 to the path name of the thin archive itself if necessary. Always returns
10707 a pointer to malloc'ed memory. */
10710 adjust_relative_path (char * file_name
, char * name
, int name_len
)
10712 char * member_file_name
;
10713 const char * base_name
= lbasename (file_name
);
10715 /* This is a proxy entry for a thin archive member.
10716 If the extended name table contains an absolute path
10717 name, or if the archive is in the current directory,
10718 use the path name as given. Otherwise, we need to
10719 find the member relative to the directory where the
10720 archive is located. */
10721 if (IS_ABSOLUTE_PATH (name
) || base_name
== file_name
)
10723 member_file_name
= malloc (name_len
+ 1);
10724 if (member_file_name
== NULL
)
10726 error (_("Out of memory\n"));
10729 memcpy (member_file_name
, name
, name_len
);
10730 member_file_name
[name_len
] = '\0';
10734 /* Concatenate the path components of the archive file name
10735 to the relative path name from the extended name table. */
10736 size_t prefix_len
= base_name
- file_name
;
10737 member_file_name
= malloc (prefix_len
+ name_len
+ 1);
10738 if (member_file_name
== NULL
)
10740 error (_("Out of memory\n"));
10743 memcpy (member_file_name
, file_name
, prefix_len
);
10744 memcpy (member_file_name
+ prefix_len
, name
, name_len
);
10745 member_file_name
[prefix_len
+ name_len
] = '\0';
10747 return member_file_name
;
10750 /* Structure to hold information about an archive file. */
10752 struct archive_info
10754 char * file_name
; /* Archive file name. */
10755 FILE * file
; /* Open file descriptor. */
10756 unsigned long index_num
; /* Number of symbols in table. */
10757 unsigned long * index_array
; /* The array of member offsets. */
10758 char * sym_table
; /* The symbol table. */
10759 unsigned long sym_size
; /* Size of the symbol table. */
10760 char * longnames
; /* The long file names table. */
10761 unsigned long longnames_size
; /* Size of the long file names table. */
10762 unsigned long nested_member_origin
; /* Origin in the nested archive of the current member. */
10763 unsigned long next_arhdr_offset
; /* Offset of the next archive header. */
10764 bfd_boolean is_thin_archive
; /* TRUE if this is a thin archive. */
10765 struct ar_hdr arhdr
; /* Current archive header. */
10768 /* Read the symbol table and long-name table from an archive. */
10771 setup_archive (struct archive_info
* arch
, char * file_name
, FILE * file
,
10772 bfd_boolean is_thin_archive
, bfd_boolean read_symbols
)
10775 unsigned long size
;
10777 arch
->file_name
= strdup (file_name
);
10779 arch
->index_num
= 0;
10780 arch
->index_array
= NULL
;
10781 arch
->sym_table
= NULL
;
10782 arch
->sym_size
= 0;
10783 arch
->longnames
= NULL
;
10784 arch
->longnames_size
= 0;
10785 arch
->nested_member_origin
= 0;
10786 arch
->is_thin_archive
= is_thin_archive
;
10787 arch
->next_arhdr_offset
= SARMAG
;
10789 /* Read the first archive member header. */
10790 if (fseek (file
, SARMAG
, SEEK_SET
) != 0)
10792 error (_("%s: failed to seek to first archive header\n"), file_name
);
10795 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, file
);
10796 if (got
!= sizeof arch
->arhdr
)
10801 error (_("%s: failed to read archive header\n"), file_name
);
10805 /* See if this is the archive symbol table. */
10806 if (const_strneq (arch
->arhdr
.ar_name
, "/ ")
10807 || const_strneq (arch
->arhdr
.ar_name
, "/SYM64/ "))
10809 size
= strtoul (arch
->arhdr
.ar_size
, NULL
, 10);
10810 size
= size
+ (size
& 1);
10812 arch
->next_arhdr_offset
+= sizeof arch
->arhdr
+ size
;
10817 /* A buffer used to hold numbers read in from an archive index.
10818 These are always 4 bytes long and stored in big-endian format. */
10819 #define SIZEOF_AR_INDEX_NUMBERS 4
10820 unsigned char integer_buffer
[SIZEOF_AR_INDEX_NUMBERS
];
10821 unsigned char * index_buffer
;
10823 /* Check the size of the archive index. */
10824 if (size
< SIZEOF_AR_INDEX_NUMBERS
)
10826 error (_("%s: the archive index is empty\n"), file_name
);
10830 /* Read the numer of entries in the archive index. */
10831 got
= fread (integer_buffer
, 1, sizeof integer_buffer
, file
);
10832 if (got
!= sizeof (integer_buffer
))
10834 error (_("%s: failed to read archive index\n"), file_name
);
10837 arch
->index_num
= byte_get_big_endian (integer_buffer
, sizeof integer_buffer
);
10838 size
-= SIZEOF_AR_INDEX_NUMBERS
;
10840 /* Read in the archive index. */
10841 if (size
< arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
)
10843 error (_("%s: the archive index is supposed to have %ld entries, but the size in the header is too small\n"),
10844 file_name
, arch
->index_num
);
10847 index_buffer
= malloc (arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
);
10848 if (index_buffer
== NULL
)
10850 error (_("Out of memory whilst trying to read archive symbol index\n"));
10853 got
= fread (index_buffer
, SIZEOF_AR_INDEX_NUMBERS
, arch
->index_num
, file
);
10854 if (got
!= arch
->index_num
)
10856 free (index_buffer
);
10857 error (_("%s: failed to read archive index\n"), file_name
);
10860 size
-= arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
;
10862 /* Convert the index numbers into the host's numeric format. */
10863 arch
->index_array
= malloc (arch
->index_num
* sizeof (* arch
->index_array
));
10864 if (arch
->index_array
== NULL
)
10866 free (index_buffer
);
10867 error (_("Out of memory whilst trying to convert the archive symbol index\n"));
10871 for (i
= 0; i
< arch
->index_num
; i
++)
10872 arch
->index_array
[i
] = byte_get_big_endian ((unsigned char *) (index_buffer
+ (i
* SIZEOF_AR_INDEX_NUMBERS
)),
10873 SIZEOF_AR_INDEX_NUMBERS
);
10874 free (index_buffer
);
10876 /* The remaining space in the header is taken up by the symbol table. */
10879 error (_("%s: the archive has an index but no symbols\n"), file_name
);
10882 arch
->sym_table
= malloc (size
);
10883 arch
->sym_size
= size
;
10884 if (arch
->sym_table
== NULL
)
10886 error (_("Out of memory whilst trying to read archive index symbol table\n"));
10889 got
= fread (arch
->sym_table
, 1, size
, file
);
10892 error (_("%s: failed to read archive index symbol table\n"), file_name
);
10898 if (fseek (file
, size
, SEEK_CUR
) != 0)
10900 error (_("%s: failed to skip archive symbol table\n"), file_name
);
10905 /* Read the next archive header. */
10906 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, file
);
10907 if (got
!= sizeof arch
->arhdr
)
10911 error (_("%s: failed to read archive header following archive index\n"), file_name
);
10915 else if (read_symbols
)
10916 printf (_("%s has no archive index\n"), file_name
);
10918 if (const_strneq (arch
->arhdr
.ar_name
, "// "))
10920 /* This is the archive string table holding long member names. */
10921 arch
->longnames_size
= strtoul (arch
->arhdr
.ar_size
, NULL
, 10);
10922 arch
->next_arhdr_offset
+= sizeof arch
->arhdr
+ arch
->longnames_size
;
10924 arch
->longnames
= malloc (arch
->longnames_size
);
10925 if (arch
->longnames
== NULL
)
10927 error (_("Out of memory reading long symbol names in archive\n"));
10931 if (fread (arch
->longnames
, arch
->longnames_size
, 1, file
) != 1)
10933 free (arch
->longnames
);
10934 arch
->longnames
= NULL
;
10935 error (_("%s: failed to read long symbol name string table\n"), file_name
);
10939 if ((arch
->longnames_size
& 1) != 0)
10946 /* Release the memory used for the archive information. */
10949 release_archive (struct archive_info
* arch
)
10951 if (arch
->file_name
!= NULL
)
10952 free (arch
->file_name
);
10953 if (arch
->index_array
!= NULL
)
10954 free (arch
->index_array
);
10955 if (arch
->sym_table
!= NULL
)
10956 free (arch
->sym_table
);
10957 if (arch
->longnames
!= NULL
)
10958 free (arch
->longnames
);
10961 /* Open and setup a nested archive, if not already open. */
10964 setup_nested_archive (struct archive_info
* nested_arch
, char * member_file_name
)
10966 FILE * member_file
;
10968 /* Have we already setup this archive? */
10969 if (nested_arch
->file_name
!= NULL
10970 && streq (nested_arch
->file_name
, member_file_name
))
10973 /* Close previous file and discard cached information. */
10974 if (nested_arch
->file
!= NULL
)
10975 fclose (nested_arch
->file
);
10976 release_archive (nested_arch
);
10978 member_file
= fopen (member_file_name
, "rb");
10979 if (member_file
== NULL
)
10981 return setup_archive (nested_arch
, member_file_name
, member_file
, FALSE
, FALSE
);
10985 get_archive_member_name_at (struct archive_info
* arch
,
10986 unsigned long offset
,
10987 struct archive_info
* nested_arch
);
10989 /* Get the name of an archive member from the current archive header.
10990 For simple names, this will modify the ar_name field of the current
10991 archive header. For long names, it will return a pointer to the
10992 longnames table. For nested archives, it will open the nested archive
10993 and get the name recursively. NESTED_ARCH is a single-entry cache so
10994 we don't keep rereading the same information from a nested archive. */
10997 get_archive_member_name (struct archive_info
* arch
,
10998 struct archive_info
* nested_arch
)
11000 unsigned long j
, k
;
11002 if (arch
->arhdr
.ar_name
[0] == '/')
11004 /* We have a long name. */
11006 char * member_file_name
;
11007 char * member_name
;
11009 arch
->nested_member_origin
= 0;
11010 k
= j
= strtoul (arch
->arhdr
.ar_name
+ 1, &endp
, 10);
11011 if (arch
->is_thin_archive
&& endp
!= NULL
&& * endp
== ':')
11012 arch
->nested_member_origin
= strtoul (endp
+ 1, NULL
, 10);
11014 while ((j
< arch
->longnames_size
)
11015 && (arch
->longnames
[j
] != '\n')
11016 && (arch
->longnames
[j
] != '\0'))
11018 if (arch
->longnames
[j
-1] == '/')
11020 arch
->longnames
[j
] = '\0';
11022 if (!arch
->is_thin_archive
|| arch
->nested_member_origin
== 0)
11023 return arch
->longnames
+ k
;
11025 /* This is a proxy for a member of a nested archive.
11026 Find the name of the member in that archive. */
11027 member_file_name
= adjust_relative_path (arch
->file_name
, arch
->longnames
+ k
, j
- k
);
11028 if (member_file_name
!= NULL
11029 && setup_nested_archive (nested_arch
, member_file_name
) == 0
11030 && (member_name
= get_archive_member_name_at (nested_arch
, arch
->nested_member_origin
, NULL
)) != NULL
)
11032 free (member_file_name
);
11033 return member_name
;
11035 free (member_file_name
);
11037 /* Last resort: just return the name of the nested archive. */
11038 return arch
->longnames
+ k
;
11041 /* We have a normal (short) name. */
11043 while ((arch
->arhdr
.ar_name
[j
] != '/') && (j
< 16))
11045 arch
->arhdr
.ar_name
[j
] = '\0';
11046 return arch
->arhdr
.ar_name
;
11049 /* Get the name of an archive member at a given OFFSET within an archive ARCH. */
11052 get_archive_member_name_at (struct archive_info
* arch
,
11053 unsigned long offset
,
11054 struct archive_info
* nested_arch
)
11058 if (fseek (arch
->file
, offset
, SEEK_SET
) != 0)
11060 error (_("%s: failed to seek to next file name\n"), arch
->file_name
);
11063 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, arch
->file
);
11064 if (got
!= sizeof arch
->arhdr
)
11066 error (_("%s: failed to read archive header\n"), arch
->file_name
);
11069 if (memcmp (arch
->arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
11071 error (_("%s: did not find a valid archive header\n"), arch
->file_name
);
11075 return get_archive_member_name (arch
, nested_arch
);
11078 /* Construct a string showing the name of the archive member, qualified
11079 with the name of the containing archive file. For thin archives, we
11080 use square brackets to denote the indirection. For nested archives,
11081 we show the qualified name of the external member inside the square
11082 brackets (e.g., "thin.a[normal.a(foo.o)]"). */
11085 make_qualified_name (struct archive_info
* arch
,
11086 struct archive_info
* nested_arch
,
11087 char * member_name
)
11092 len
= strlen (arch
->file_name
) + strlen (member_name
) + 3;
11093 if (arch
->is_thin_archive
&& arch
->nested_member_origin
!= 0)
11094 len
+= strlen (nested_arch
->file_name
) + 2;
11096 name
= malloc (len
);
11099 error (_("Out of memory\n"));
11103 if (arch
->is_thin_archive
&& arch
->nested_member_origin
!= 0)
11104 snprintf (name
, len
, "%s[%s(%s)]", arch
->file_name
, nested_arch
->file_name
, member_name
);
11105 else if (arch
->is_thin_archive
)
11106 snprintf (name
, len
, "%s[%s]", arch
->file_name
, member_name
);
11108 snprintf (name
, len
, "%s(%s)", arch
->file_name
, member_name
);
11113 /* Process an ELF archive.
11114 On entry the file is positioned just after the ARMAG string. */
11117 process_archive (char * file_name
, FILE * file
, bfd_boolean is_thin_archive
)
11119 struct archive_info arch
;
11120 struct archive_info nested_arch
;
11122 size_t file_name_size
;
11127 /* The ARCH structure is used to hold information about this archive. */
11128 arch
.file_name
= NULL
;
11130 arch
.index_array
= NULL
;
11131 arch
.sym_table
= NULL
;
11132 arch
.longnames
= NULL
;
11134 /* The NESTED_ARCH structure is used as a single-item cache of information
11135 about a nested archive (when members of a thin archive reside within
11136 another regular archive file). */
11137 nested_arch
.file_name
= NULL
;
11138 nested_arch
.file
= NULL
;
11139 nested_arch
.index_array
= NULL
;
11140 nested_arch
.sym_table
= NULL
;
11141 nested_arch
.longnames
= NULL
;
11143 if (setup_archive (&arch
, file_name
, file
, is_thin_archive
, do_archive_index
) != 0)
11149 if (do_archive_index
)
11151 if (arch
.sym_table
== NULL
)
11152 error (_("%s: unable to dump the index as none was found\n"), file_name
);
11156 unsigned long current_pos
;
11158 printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
11159 file_name
, arch
.index_num
, arch
.sym_size
);
11160 current_pos
= ftell (file
);
11162 for (i
= l
= 0; i
< arch
.index_num
; i
++)
11164 if ((i
== 0) || ((i
> 0) && (arch
.index_array
[i
] != arch
.index_array
[i
- 1])))
11166 char * member_name
;
11168 member_name
= get_archive_member_name_at (&arch
, arch
.index_array
[i
], &nested_arch
);
11170 if (member_name
!= NULL
)
11172 char * qualified_name
= make_qualified_name (&arch
, &nested_arch
, member_name
);
11174 if (qualified_name
!= NULL
)
11176 printf (_("Binary %s contains:\n"), qualified_name
);
11177 free (qualified_name
);
11182 if (l
>= arch
.sym_size
)
11184 error (_("%s: end of the symbol table reached before the end of the index\n"),
11188 printf ("\t%s\n", arch
.sym_table
+ l
);
11189 l
+= strlen (arch
.sym_table
+ l
) + 1;
11194 if (l
< arch
.sym_size
)
11195 error (_("%s: symbols remain in the index symbol table, but without corresponding entries in the index table\n"),
11198 if (fseek (file
, current_pos
, SEEK_SET
) != 0)
11200 error (_("%s: failed to seek back to start of object files in the archive\n"), file_name
);
11206 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
11207 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
11208 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
11209 && !do_section_groups
)
11211 ret
= 0; /* Archive index only. */
11216 file_name_size
= strlen (file_name
);
11223 char * qualified_name
;
11225 /* Read the next archive header. */
11226 if (fseek (file
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
11228 error (_("%s: failed to seek to next archive header\n"), file_name
);
11231 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, file
);
11232 if (got
!= sizeof arch
.arhdr
)
11236 error (_("%s: failed to read archive header\n"), file_name
);
11240 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
11242 error (_("%s: did not find a valid archive header\n"), arch
.file_name
);
11247 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
11249 archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
11250 if (archive_file_size
& 01)
11251 ++archive_file_size
;
11253 name
= get_archive_member_name (&arch
, &nested_arch
);
11256 error (_("%s: bad archive file name\n"), file_name
);
11260 namelen
= strlen (name
);
11262 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
11263 if (qualified_name
== NULL
)
11265 error (_("%s: bad archive file name\n"), file_name
);
11270 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
11272 /* This is a proxy for an external member of a thin archive. */
11273 FILE * member_file
;
11274 char * member_file_name
= adjust_relative_path (file_name
, name
, namelen
);
11275 if (member_file_name
== NULL
)
11281 member_file
= fopen (member_file_name
, "rb");
11282 if (member_file
== NULL
)
11284 error (_("Input file '%s' is not readable.\n"), member_file_name
);
11285 free (member_file_name
);
11290 archive_file_offset
= arch
.nested_member_origin
;
11292 ret
|= process_object (qualified_name
, member_file
);
11294 fclose (member_file
);
11295 free (member_file_name
);
11297 else if (is_thin_archive
)
11299 /* This is a proxy for a member of a nested archive. */
11300 archive_file_offset
= arch
.nested_member_origin
+ sizeof arch
.arhdr
;
11302 /* The nested archive file will have been opened and setup by
11303 get_archive_member_name. */
11304 if (fseek (nested_arch
.file
, archive_file_offset
, SEEK_SET
) != 0)
11306 error (_("%s: failed to seek to archive member.\n"), nested_arch
.file_name
);
11311 ret
|= process_object (qualified_name
, nested_arch
.file
);
11315 archive_file_offset
= arch
.next_arhdr_offset
;
11316 arch
.next_arhdr_offset
+= archive_file_size
;
11318 ret
|= process_object (qualified_name
, file
);
11321 free (qualified_name
);
11325 if (nested_arch
.file
!= NULL
)
11326 fclose (nested_arch
.file
);
11327 release_archive (&nested_arch
);
11328 release_archive (&arch
);
11334 process_file (char * file_name
)
11337 struct stat statbuf
;
11338 char armag
[SARMAG
];
11341 if (stat (file_name
, &statbuf
) < 0)
11343 if (errno
== ENOENT
)
11344 error (_("'%s': No such file\n"), file_name
);
11346 error (_("Could not locate '%s'. System error message: %s\n"),
11347 file_name
, strerror (errno
));
11351 if (! S_ISREG (statbuf
.st_mode
))
11353 error (_("'%s' is not an ordinary file\n"), file_name
);
11357 file
= fopen (file_name
, "rb");
11360 error (_("Input file '%s' is not readable.\n"), file_name
);
11364 if (fread (armag
, SARMAG
, 1, file
) != 1)
11366 error (_("%s: Failed to read file's magic number\n"), file_name
);
11371 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
11372 ret
= process_archive (file_name
, file
, FALSE
);
11373 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
11374 ret
= process_archive (file_name
, file
, TRUE
);
11377 if (do_archive_index
)
11378 error (_("File %s is not an archive so its index cannot be displayed.\n"),
11382 archive_file_size
= archive_file_offset
= 0;
11383 ret
= process_object (file_name
, file
);
11391 #ifdef SUPPORT_DISASSEMBLY
11392 /* Needed by the i386 disassembler. For extra credit, someone could
11393 fix this so that we insert symbolic addresses here, esp for GOT/PLT
11397 print_address (unsigned int addr
, FILE * outfile
)
11399 fprintf (outfile
,"0x%8.8x", addr
);
11402 /* Needed by the i386 disassembler. */
11404 db_task_printsym (unsigned int addr
)
11406 print_address (addr
, stderr
);
11411 main (int argc
, char ** argv
)
11415 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
11416 setlocale (LC_MESSAGES
, "");
11418 #if defined (HAVE_SETLOCALE)
11419 setlocale (LC_CTYPE
, "");
11421 bindtextdomain (PACKAGE
, LOCALEDIR
);
11422 textdomain (PACKAGE
);
11424 expandargv (&argc
, &argv
);
11426 parse_args (argc
, argv
);
11428 if (num_dump_sects
> 0)
11430 /* Make a copy of the dump_sects array. */
11431 cmdline_dump_sects
= malloc (num_dump_sects
* sizeof (* dump_sects
));
11432 if (cmdline_dump_sects
== NULL
)
11433 error (_("Out of memory allocating dump request table.\n"));
11436 memcpy (cmdline_dump_sects
, dump_sects
,
11437 num_dump_sects
* sizeof (* dump_sects
));
11438 num_cmdline_dump_sects
= num_dump_sects
;
11442 if (optind
< (argc
- 1))
11446 while (optind
< argc
)
11447 err
|= process_file (argv
[optind
++]);
11449 if (dump_sects
!= NULL
)
11451 if (cmdline_dump_sects
!= NULL
)
11452 free (cmdline_dump_sects
);