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/microblaze.h"
123 #include "elf/mips.h"
124 #include "elf/mmix.h"
125 #include "elf/mn10200.h"
126 #include "elf/mn10300.h"
128 #include "elf/msp430.h"
129 #include "elf/or32.h"
132 #include "elf/ppc64.h"
133 #include "elf/s390.h"
134 #include "elf/score.h"
136 #include "elf/sparc.h"
138 #include "elf/v850.h"
140 #include "elf/x86-64.h"
141 #include "elf/xstormy16.h"
142 #include "elf/xtensa.h"
147 #include "libiberty.h"
148 #include "safe-ctype.h"
149 #include "filenames.h"
151 char * program_name
= "readelf";
153 static long archive_file_offset
;
154 static unsigned long archive_file_size
;
155 static unsigned long dynamic_addr
;
156 static bfd_size_type dynamic_size
;
157 static unsigned int dynamic_nent
;
158 static char * dynamic_strings
;
159 static unsigned long dynamic_strings_length
;
160 static char * string_table
;
161 static unsigned long string_table_length
;
162 static unsigned long num_dynamic_syms
;
163 static Elf_Internal_Sym
* dynamic_symbols
;
164 static Elf_Internal_Syminfo
* dynamic_syminfo
;
165 static unsigned long dynamic_syminfo_offset
;
166 static unsigned int dynamic_syminfo_nent
;
167 static char program_interpreter
[PATH_MAX
];
168 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
169 static bfd_vma dynamic_info_DT_GNU_HASH
;
170 static bfd_vma version_info
[16];
171 static Elf_Internal_Ehdr elf_header
;
172 static Elf_Internal_Shdr
* section_headers
;
173 static Elf_Internal_Phdr
* program_headers
;
174 static Elf_Internal_Dyn
* dynamic_section
;
175 static Elf_Internal_Shdr
* symtab_shndx_hdr
;
176 static int show_name
;
177 static int do_dynamic
;
180 static int do_sections
;
181 static int do_section_groups
;
182 static int do_section_details
;
183 static int do_segments
;
184 static int do_unwind
;
185 static int do_using_dynamic
;
186 static int do_header
;
188 static int do_version
;
189 static int do_histogram
;
190 static int do_debugging
;
193 static int do_archive_index
;
194 static int is_32bit_elf
;
198 struct group_list
* next
;
199 unsigned int section_index
;
204 struct group_list
* root
;
205 unsigned int group_index
;
208 static size_t group_count
;
209 static struct group
* section_groups
;
210 static struct group
** section_headers_groups
;
213 /* Flag bits indicating particular types of dump. */
214 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
215 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
216 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
217 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
218 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
220 typedef unsigned char dump_type
;
222 /* A linked list of the section names for which dumps were requested. */
223 struct dump_list_entry
227 struct dump_list_entry
* next
;
229 static struct dump_list_entry
* dump_sects_byname
;
231 /* A dynamic array of flags indicating for which sections a dump
232 has been requested via command line switches. */
233 static dump_type
* cmdline_dump_sects
= NULL
;
234 static unsigned int num_cmdline_dump_sects
= 0;
236 /* A dynamic array of flags indicating for which sections a dump of
237 some kind has been requested. It is reset on a per-object file
238 basis and then initialised from the cmdline_dump_sects array,
239 the results of interpreting the -w switch, and the
240 dump_sects_byname list. */
241 static dump_type
* dump_sects
= NULL
;
242 static unsigned int num_dump_sects
= 0;
245 /* How to print a vma value. */
246 typedef enum print_mode
258 static void (* byte_put
) (unsigned char *, bfd_vma
, int);
262 #define SECTION_NAME(X) \
263 ((X) == NULL ? "<none>" \
264 : string_table == NULL ? "<no-name>" \
265 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
266 : string_table + (X)->sh_name))
268 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
270 #define BYTE_GET(field) byte_get (field, sizeof (field))
272 #define GET_ELF_SYMBOLS(file, section) \
273 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
274 : get_64bit_elf_symbols (file, section))
276 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
277 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
278 already been called and verified that the string exists. */
279 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
281 /* This is just a bit of syntatic sugar. */
282 #define streq(a,b) (strcmp ((a), (b)) == 0)
283 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
284 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
287 get_data (void * var
, FILE * file
, long offset
, size_t size
, size_t nmemb
,
292 if (size
== 0 || nmemb
== 0)
295 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
297 error (_("Unable to seek to 0x%lx for %s\n"),
298 (unsigned long) archive_file_offset
+ offset
, reason
);
305 /* Check for overflow. */
306 if (nmemb
< (~(size_t) 0 - 1) / size
)
307 /* + 1 so that we can '\0' terminate invalid string table sections. */
308 mvar
= malloc (size
* nmemb
+ 1);
312 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
313 (unsigned long)(size
* nmemb
), reason
);
317 ((char *) mvar
)[size
* nmemb
] = '\0';
320 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
322 error (_("Unable to read in 0x%lx bytes of %s\n"),
323 (unsigned long)(size
* nmemb
), reason
);
333 byte_put_little_endian (unsigned char * field
, bfd_vma value
, int size
)
338 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
339 field
[6] = ((value
>> 24) >> 24) & 0xff;
340 field
[5] = ((value
>> 24) >> 16) & 0xff;
341 field
[4] = ((value
>> 24) >> 8) & 0xff;
344 field
[3] = (value
>> 24) & 0xff;
347 field
[2] = (value
>> 16) & 0xff;
350 field
[1] = (value
>> 8) & 0xff;
353 field
[0] = value
& 0xff;
357 error (_("Unhandled data length: %d\n"), size
);
362 /* Print a VMA value. */
365 print_vma (bfd_vma vma
, print_mode mode
)
378 return nc
+ printf ("%8.8" BFD_VMA_FMT
"x", vma
);
385 return printf ("%5" BFD_VMA_FMT
"d", vma
);
393 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
396 return printf ("%" BFD_VMA_FMT
"d", vma
);
399 return printf ("%" BFD_VMA_FMT
"u", vma
);
404 /* Display a symbol on stdout. Handles the display of non-printing characters.
406 If DO_WIDE is not true then format the symbol to be at most WIDTH characters,
407 truncating as necessary. If WIDTH is negative then format the string to be
408 exactly - WIDTH characters, truncating or padding as necessary.
410 Returns the number of emitted characters. */
413 print_symbol (int width
, const char * symbol
)
416 bfd_boolean extra_padding
= FALSE
;
417 unsigned int num_printed
= 0;
421 /* Set the width to a very large value. This simplifies the code below. */
426 /* Keep the width positive. This also helps. */
428 extra_padding
= TRUE
;
437 /* Look for non-printing symbols inside the symbol's name.
438 This test is triggered in particular by the names generated
439 by the assembler for local labels. */
440 while (ISPRINT (* c
))
450 printf ("%.*s", len
, symbol
);
456 if (* c
== 0 || width
== 0)
459 /* Now display the non-printing character, if
460 there is room left in which to dipslay it. */
466 printf ("^%c", *c
+ 0x40);
476 printf ("<0x%.2x>", *c
);
485 if (extra_padding
&& width
> 0)
487 /* Fill in the remaining spaces. */
488 printf ("%-*s", width
, " ");
496 byte_put_big_endian (unsigned char * field
, bfd_vma value
, int size
)
501 field
[7] = value
& 0xff;
502 field
[6] = (value
>> 8) & 0xff;
503 field
[5] = (value
>> 16) & 0xff;
504 field
[4] = (value
>> 24) & 0xff;
509 field
[3] = value
& 0xff;
513 field
[2] = value
& 0xff;
517 field
[1] = value
& 0xff;
521 field
[0] = value
& 0xff;
525 error (_("Unhandled data length: %d\n"), size
);
530 /* Return a pointer to section NAME, or NULL if no such section exists. */
532 static Elf_Internal_Shdr
*
533 find_section (const char * name
)
537 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
538 if (streq (SECTION_NAME (section_headers
+ i
), name
))
539 return section_headers
+ i
;
544 /* Guess the relocation size commonly used by the specific machines. */
547 guess_is_rela (unsigned int e_machine
)
551 /* Targets that use REL relocations. */
567 /* Targets that use RELA relocations. */
571 case EM_ALTERA_NIOS2
:
591 case EM_LATTICEMICO32
:
599 case EM_CYGNUS_MN10200
:
601 case EM_CYGNUS_MN10300
:
624 case EM_MICROBLAZE_OLD
:
645 warn (_("Don't know about relocations on this machine architecture\n"));
651 slurp_rela_relocs (FILE * file
,
652 unsigned long rel_offset
,
653 unsigned long rel_size
,
654 Elf_Internal_Rela
** relasp
,
655 unsigned long * nrelasp
)
657 Elf_Internal_Rela
* relas
;
658 unsigned long nrelas
;
663 Elf32_External_Rela
* erelas
;
665 erelas
= (Elf32_External_Rela
*) get_data (NULL
, file
, rel_offset
, 1,
666 rel_size
, _("relocs"));
670 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
672 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
673 sizeof (Elf_Internal_Rela
));
678 error (_("out of memory parsing relocs\n"));
682 for (i
= 0; i
< nrelas
; i
++)
684 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
685 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
686 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
693 Elf64_External_Rela
* erelas
;
695 erelas
= (Elf64_External_Rela
*) get_data (NULL
, file
, rel_offset
, 1,
696 rel_size
, _("relocs"));
700 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
702 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
703 sizeof (Elf_Internal_Rela
));
708 error (_("out of memory parsing relocs\n"));
712 for (i
= 0; i
< nrelas
; i
++)
714 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
715 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
716 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
718 /* The #ifdef BFD64 below is to prevent a compile time
719 warning. We know that if we do not have a 64 bit data
720 type that we will never execute this code anyway. */
722 if (elf_header
.e_machine
== EM_MIPS
723 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
725 /* In little-endian objects, r_info isn't really a
726 64-bit little-endian value: it has a 32-bit
727 little-endian symbol index followed by four
728 individual byte fields. Reorder INFO
730 bfd_vma info
= relas
[i
].r_info
;
731 info
= (((info
& 0xffffffff) << 32)
732 | ((info
>> 56) & 0xff)
733 | ((info
>> 40) & 0xff00)
734 | ((info
>> 24) & 0xff0000)
735 | ((info
>> 8) & 0xff000000));
736 relas
[i
].r_info
= info
;
749 slurp_rel_relocs (FILE * file
,
750 unsigned long rel_offset
,
751 unsigned long rel_size
,
752 Elf_Internal_Rela
** relsp
,
753 unsigned long * nrelsp
)
755 Elf_Internal_Rela
* rels
;
761 Elf32_External_Rel
* erels
;
763 erels
= (Elf32_External_Rel
*) get_data (NULL
, file
, rel_offset
, 1,
764 rel_size
, _("relocs"));
768 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
770 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
775 error (_("out of memory parsing relocs\n"));
779 for (i
= 0; i
< nrels
; i
++)
781 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
782 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
783 rels
[i
].r_addend
= 0;
790 Elf64_External_Rel
* erels
;
792 erels
= (Elf64_External_Rel
*) get_data (NULL
, file
, rel_offset
, 1,
793 rel_size
, _("relocs"));
797 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
799 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
804 error (_("out of memory parsing relocs\n"));
808 for (i
= 0; i
< nrels
; i
++)
810 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
811 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
812 rels
[i
].r_addend
= 0;
814 /* The #ifdef BFD64 below is to prevent a compile time
815 warning. We know that if we do not have a 64 bit data
816 type that we will never execute this code anyway. */
818 if (elf_header
.e_machine
== EM_MIPS
819 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
821 /* In little-endian objects, r_info isn't really a
822 64-bit little-endian value: it has a 32-bit
823 little-endian symbol index followed by four
824 individual byte fields. Reorder INFO
826 bfd_vma info
= rels
[i
].r_info
;
827 info
= (((info
& 0xffffffff) << 32)
828 | ((info
>> 56) & 0xff)
829 | ((info
>> 40) & 0xff00)
830 | ((info
>> 24) & 0xff0000)
831 | ((info
>> 8) & 0xff000000));
832 rels
[i
].r_info
= info
;
844 /* Returns the reloc type extracted from the reloc info field. */
847 get_reloc_type (bfd_vma reloc_info
)
850 return ELF32_R_TYPE (reloc_info
);
852 switch (elf_header
.e_machine
)
855 /* Note: We assume that reloc_info has already been adjusted for us. */
856 return ELF64_MIPS_R_TYPE (reloc_info
);
859 return ELF64_R_TYPE_ID (reloc_info
);
862 return ELF64_R_TYPE (reloc_info
);
866 /* Return the symbol index extracted from the reloc info field. */
869 get_reloc_symindex (bfd_vma reloc_info
)
871 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
874 /* Display the contents of the relocation data found at the specified
878 dump_relocations (FILE * file
,
879 unsigned long rel_offset
,
880 unsigned long rel_size
,
881 Elf_Internal_Sym
* symtab
,
884 unsigned long strtablen
,
888 Elf_Internal_Rela
* rels
;
890 if (is_rela
== UNKNOWN
)
891 is_rela
= guess_is_rela (elf_header
.e_machine
);
895 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
900 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
909 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
911 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
916 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
918 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
926 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
928 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
933 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
935 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
939 for (i
= 0; i
< rel_size
; i
++)
944 bfd_vma symtab_index
;
947 offset
= rels
[i
].r_offset
;
948 info
= rels
[i
].r_info
;
950 type
= get_reloc_type (info
);
951 symtab_index
= get_reloc_symindex (info
);
955 printf ("%8.8lx %8.8lx ",
956 (unsigned long) offset
& 0xffffffff,
957 (unsigned long) info
& 0xffffffff);
961 #if BFD_HOST_64BIT_LONG
963 ? "%16.16lx %16.16lx "
964 : "%12.12lx %12.12lx ",
966 #elif BFD_HOST_64BIT_LONG_LONG
969 ? "%16.16llx %16.16llx "
970 : "%12.12llx %12.12llx ",
974 ? "%16.16I64x %16.16I64x "
975 : "%12.12I64x %12.12I64x ",
980 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
981 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
982 _bfd_int64_high (offset
),
983 _bfd_int64_low (offset
),
984 _bfd_int64_high (info
),
985 _bfd_int64_low (info
));
989 switch (elf_header
.e_machine
)
997 rtype
= elf_m32r_reloc_type (type
);
1002 rtype
= elf_i386_reloc_type (type
);
1007 rtype
= elf_m68hc11_reloc_type (type
);
1011 rtype
= elf_m68k_reloc_type (type
);
1015 rtype
= elf_i960_reloc_type (type
);
1020 rtype
= elf_avr_reloc_type (type
);
1023 case EM_OLD_SPARCV9
:
1024 case EM_SPARC32PLUS
:
1027 rtype
= elf_sparc_reloc_type (type
);
1031 rtype
= elf_spu_reloc_type (type
);
1035 case EM_CYGNUS_V850
:
1036 rtype
= v850_reloc_type (type
);
1040 case EM_CYGNUS_D10V
:
1041 rtype
= elf_d10v_reloc_type (type
);
1045 case EM_CYGNUS_D30V
:
1046 rtype
= elf_d30v_reloc_type (type
);
1050 rtype
= elf_dlx_reloc_type (type
);
1054 rtype
= elf_sh_reloc_type (type
);
1058 case EM_CYGNUS_MN10300
:
1059 rtype
= elf_mn10300_reloc_type (type
);
1063 case EM_CYGNUS_MN10200
:
1064 rtype
= elf_mn10200_reloc_type (type
);
1068 case EM_CYGNUS_FR30
:
1069 rtype
= elf_fr30_reloc_type (type
);
1073 rtype
= elf_frv_reloc_type (type
);
1077 rtype
= elf_mcore_reloc_type (type
);
1081 rtype
= elf_mmix_reloc_type (type
);
1086 rtype
= elf_msp430_reloc_type (type
);
1090 rtype
= elf_ppc_reloc_type (type
);
1094 rtype
= elf_ppc64_reloc_type (type
);
1098 case EM_MIPS_RS3_LE
:
1099 rtype
= elf_mips_reloc_type (type
);
1103 rtype
= elf_alpha_reloc_type (type
);
1107 rtype
= elf_arm_reloc_type (type
);
1111 rtype
= elf_arc_reloc_type (type
);
1115 rtype
= elf_hppa_reloc_type (type
);
1121 rtype
= elf_h8_reloc_type (type
);
1126 rtype
= elf_or32_reloc_type (type
);
1131 rtype
= elf_pj_reloc_type (type
);
1134 rtype
= elf_ia64_reloc_type (type
);
1138 rtype
= elf_cris_reloc_type (type
);
1142 rtype
= elf_i860_reloc_type (type
);
1147 rtype
= elf_x86_64_reloc_type (type
);
1151 rtype
= i370_reloc_type (type
);
1156 rtype
= elf_s390_reloc_type (type
);
1160 rtype
= elf_score_reloc_type (type
);
1164 rtype
= elf_xstormy16_reloc_type (type
);
1168 rtype
= elf_crx_reloc_type (type
);
1172 rtype
= elf_vax_reloc_type (type
);
1177 rtype
= elf_ip2k_reloc_type (type
);
1181 rtype
= elf_iq2000_reloc_type (type
);
1186 rtype
= elf_xtensa_reloc_type (type
);
1189 case EM_LATTICEMICO32
:
1190 rtype
= elf_lm32_reloc_type (type
);
1195 rtype
= elf_m32c_reloc_type (type
);
1199 rtype
= elf_mt_reloc_type (type
);
1203 rtype
= elf_bfin_reloc_type (type
);
1207 rtype
= elf_mep_reloc_type (type
);
1212 rtype
= elf_cr16_reloc_type (type
);
1216 case EM_MICROBLAZE_OLD
:
1217 rtype
= elf_microblaze_reloc_type (type
);
1222 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1224 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1226 if (elf_header
.e_machine
== EM_ALPHA
1228 && streq (rtype
, "R_ALPHA_LITUSE")
1231 switch (rels
[i
].r_addend
)
1233 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1234 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1235 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1236 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1237 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1238 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1239 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1240 default: rtype
= NULL
;
1243 printf (" (%s)", rtype
);
1247 printf (_("<unknown addend: %lx>"),
1248 (unsigned long) rels
[i
].r_addend
);
1251 else if (symtab_index
)
1253 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1254 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1257 Elf_Internal_Sym
* psym
;
1259 psym
= symtab
+ symtab_index
;
1263 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1267 unsigned int width
= is_32bit_elf
? 8 : 14;
1269 /* Relocations against GNU_IFUNC symbols do not use the value
1270 of the symbol as the address to relocate against. Instead
1271 they invoke the function named by the symbol and use its
1272 result as the address for relocation.
1274 To indicate this to the user, do not display the value of
1275 the symbol in the "Symbols's Value" field. Instead show
1276 its name followed by () as a hint that the symbol is
1280 || psym
->st_name
== 0
1281 || psym
->st_name
>= strtablen
)
1284 name
= strtab
+ psym
->st_name
;
1286 len
= print_symbol (width
, name
);
1287 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
1291 print_vma (psym
->st_value
, LONG_HEX
);
1293 printf (is_32bit_elf
? " " : " ");
1296 if (psym
->st_name
== 0)
1298 const char * sec_name
= "<null>";
1301 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1303 if (psym
->st_shndx
< elf_header
.e_shnum
)
1305 = SECTION_NAME (section_headers
+ psym
->st_shndx
);
1306 else if (psym
->st_shndx
== SHN_ABS
)
1308 else if (psym
->st_shndx
== SHN_COMMON
)
1309 sec_name
= "COMMON";
1310 else if (elf_header
.e_machine
== EM_MIPS
1311 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1312 sec_name
= "SCOMMON";
1313 else if (elf_header
.e_machine
== EM_MIPS
1314 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1315 sec_name
= "SUNDEF";
1316 else if ((elf_header
.e_machine
== EM_X86_64
1317 || elf_header
.e_machine
== EM_L1OM
)
1318 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1319 sec_name
= "LARGE_COMMON";
1320 else if (elf_header
.e_machine
== EM_IA_64
1321 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1322 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1323 sec_name
= "ANSI_COM";
1324 else if (elf_header
.e_machine
== EM_IA_64
1325 && (elf_header
.e_ident
[EI_OSABI
]
1326 == ELFOSABI_OPENVMS
)
1327 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
1328 sec_name
= "VMS_SYMVEC";
1331 sprintf (name_buf
, "<section 0x%x>",
1332 (unsigned int) psym
->st_shndx
);
1333 sec_name
= name_buf
;
1336 print_symbol (22, sec_name
);
1338 else if (strtab
== NULL
)
1339 printf (_("<string table index: %3ld>"), psym
->st_name
);
1340 else if (psym
->st_name
>= strtablen
)
1341 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1343 print_symbol (22, strtab
+ psym
->st_name
);
1347 long offset
= (long) (bfd_signed_vma
) rels
[i
].r_addend
;
1350 printf (" - %lx", - offset
);
1352 printf (" + %lx", offset
);
1358 printf ("%*c", is_32bit_elf
?
1359 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1360 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1363 if (elf_header
.e_machine
== EM_SPARCV9
1365 && streq (rtype
, "R_SPARC_OLO10"))
1366 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1371 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1373 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (info
);
1374 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (info
);
1375 const char * rtype2
= elf_mips_reloc_type (type2
);
1376 const char * rtype3
= elf_mips_reloc_type (type3
);
1378 printf (" Type2: ");
1381 printf (_("unrecognized: %-7lx"),
1382 (unsigned long) type2
& 0xffffffff);
1384 printf ("%-17.17s", rtype2
);
1386 printf ("\n Type3: ");
1389 printf (_("unrecognized: %-7lx"),
1390 (unsigned long) type3
& 0xffffffff);
1392 printf ("%-17.17s", rtype3
);
1403 get_mips_dynamic_type (unsigned long type
)
1407 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1408 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1409 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1410 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1411 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1412 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1413 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1414 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1415 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1416 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1417 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1418 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1419 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1420 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1421 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1422 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1423 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1424 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1425 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1426 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1427 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1428 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1429 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1430 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1431 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1432 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1433 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1434 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1435 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1436 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1437 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1438 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1439 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1440 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1441 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1442 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1443 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1444 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1445 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1446 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1447 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1448 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1449 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1450 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
1451 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
1458 get_sparc64_dynamic_type (unsigned long type
)
1462 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1469 get_ppc_dynamic_type (unsigned long type
)
1473 case DT_PPC_GOT
: return "PPC_GOT";
1480 get_ppc64_dynamic_type (unsigned long type
)
1484 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1485 case DT_PPC64_OPD
: return "PPC64_OPD";
1486 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1493 get_parisc_dynamic_type (unsigned long type
)
1497 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1498 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1499 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1500 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1501 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1502 case DT_HP_PREINIT
: return "HP_PREINIT";
1503 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1504 case DT_HP_NEEDED
: return "HP_NEEDED";
1505 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1506 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1507 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1508 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1509 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1510 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1511 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1512 case DT_HP_FILTERED
: return "HP_FILTERED";
1513 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1514 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1515 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1516 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1517 case DT_PLT
: return "PLT";
1518 case DT_PLT_SIZE
: return "PLT_SIZE";
1519 case DT_DLT
: return "DLT";
1520 case DT_DLT_SIZE
: return "DLT_SIZE";
1527 get_ia64_dynamic_type (unsigned long type
)
1531 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1532 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
1533 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
1534 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
1535 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
1536 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
1537 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
1538 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
1539 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
1540 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
1541 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
1542 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
1543 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
1544 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
1545 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
1546 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
1547 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
1548 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
1549 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
1550 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
1551 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
1552 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
1553 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
1554 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
1555 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
1556 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
1557 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
1558 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
1559 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
1560 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
1561 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
1568 get_alpha_dynamic_type (unsigned long type
)
1572 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1579 get_score_dynamic_type (unsigned long type
)
1583 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1584 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1585 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1586 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1587 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1588 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1596 get_dynamic_type (unsigned long type
)
1598 static char buff
[64];
1602 case DT_NULL
: return "NULL";
1603 case DT_NEEDED
: return "NEEDED";
1604 case DT_PLTRELSZ
: return "PLTRELSZ";
1605 case DT_PLTGOT
: return "PLTGOT";
1606 case DT_HASH
: return "HASH";
1607 case DT_STRTAB
: return "STRTAB";
1608 case DT_SYMTAB
: return "SYMTAB";
1609 case DT_RELA
: return "RELA";
1610 case DT_RELASZ
: return "RELASZ";
1611 case DT_RELAENT
: return "RELAENT";
1612 case DT_STRSZ
: return "STRSZ";
1613 case DT_SYMENT
: return "SYMENT";
1614 case DT_INIT
: return "INIT";
1615 case DT_FINI
: return "FINI";
1616 case DT_SONAME
: return "SONAME";
1617 case DT_RPATH
: return "RPATH";
1618 case DT_SYMBOLIC
: return "SYMBOLIC";
1619 case DT_REL
: return "REL";
1620 case DT_RELSZ
: return "RELSZ";
1621 case DT_RELENT
: return "RELENT";
1622 case DT_PLTREL
: return "PLTREL";
1623 case DT_DEBUG
: return "DEBUG";
1624 case DT_TEXTREL
: return "TEXTREL";
1625 case DT_JMPREL
: return "JMPREL";
1626 case DT_BIND_NOW
: return "BIND_NOW";
1627 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1628 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1629 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1630 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1631 case DT_RUNPATH
: return "RUNPATH";
1632 case DT_FLAGS
: return "FLAGS";
1634 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1635 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1637 case DT_CHECKSUM
: return "CHECKSUM";
1638 case DT_PLTPADSZ
: return "PLTPADSZ";
1639 case DT_MOVEENT
: return "MOVEENT";
1640 case DT_MOVESZ
: return "MOVESZ";
1641 case DT_FEATURE
: return "FEATURE";
1642 case DT_POSFLAG_1
: return "POSFLAG_1";
1643 case DT_SYMINSZ
: return "SYMINSZ";
1644 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1646 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1647 case DT_CONFIG
: return "CONFIG";
1648 case DT_DEPAUDIT
: return "DEPAUDIT";
1649 case DT_AUDIT
: return "AUDIT";
1650 case DT_PLTPAD
: return "PLTPAD";
1651 case DT_MOVETAB
: return "MOVETAB";
1652 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1654 case DT_VERSYM
: return "VERSYM";
1656 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1657 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1658 case DT_RELACOUNT
: return "RELACOUNT";
1659 case DT_RELCOUNT
: return "RELCOUNT";
1660 case DT_FLAGS_1
: return "FLAGS_1";
1661 case DT_VERDEF
: return "VERDEF";
1662 case DT_VERDEFNUM
: return "VERDEFNUM";
1663 case DT_VERNEED
: return "VERNEED";
1664 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1666 case DT_AUXILIARY
: return "AUXILIARY";
1667 case DT_USED
: return "USED";
1668 case DT_FILTER
: return "FILTER";
1670 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1671 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1672 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1673 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1674 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1675 case DT_GNU_HASH
: return "GNU_HASH";
1678 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1680 const char * result
;
1682 switch (elf_header
.e_machine
)
1685 case EM_MIPS_RS3_LE
:
1686 result
= get_mips_dynamic_type (type
);
1689 result
= get_sparc64_dynamic_type (type
);
1692 result
= get_ppc_dynamic_type (type
);
1695 result
= get_ppc64_dynamic_type (type
);
1698 result
= get_ia64_dynamic_type (type
);
1701 result
= get_alpha_dynamic_type (type
);
1704 result
= get_score_dynamic_type (type
);
1714 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1716 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1717 || (elf_header
.e_machine
== EM_PARISC
1718 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1720 const char * result
;
1722 switch (elf_header
.e_machine
)
1725 result
= get_parisc_dynamic_type (type
);
1728 result
= get_ia64_dynamic_type (type
);
1738 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1742 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1749 get_file_type (unsigned e_type
)
1751 static char buff
[32];
1755 case ET_NONE
: return _("NONE (None)");
1756 case ET_REL
: return _("REL (Relocatable file)");
1757 case ET_EXEC
: return _("EXEC (Executable file)");
1758 case ET_DYN
: return _("DYN (Shared object file)");
1759 case ET_CORE
: return _("CORE (Core file)");
1762 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1763 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1764 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1765 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1767 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1773 get_machine_name (unsigned e_machine
)
1775 static char buff
[64]; /* XXX */
1779 case EM_NONE
: return _("None");
1780 case EM_M32
: return "WE32100";
1781 case EM_SPARC
: return "Sparc";
1782 case EM_SPU
: return "SPU";
1783 case EM_386
: return "Intel 80386";
1784 case EM_68K
: return "MC68000";
1785 case EM_88K
: return "MC88000";
1786 case EM_486
: return "Intel 80486";
1787 case EM_860
: return "Intel 80860";
1788 case EM_MIPS
: return "MIPS R3000";
1789 case EM_S370
: return "IBM System/370";
1790 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1791 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1792 case EM_PARISC
: return "HPPA";
1793 case EM_PPC_OLD
: return "Power PC (old)";
1794 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1795 case EM_960
: return "Intel 90860";
1796 case EM_PPC
: return "PowerPC";
1797 case EM_PPC64
: return "PowerPC64";
1798 case EM_V800
: return "NEC V800";
1799 case EM_FR20
: return "Fujitsu FR20";
1800 case EM_RH32
: return "TRW RH32";
1801 case EM_MCORE
: return "MCORE";
1802 case EM_ARM
: return "ARM";
1803 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1804 case EM_SH
: return "Renesas / SuperH SH";
1805 case EM_SPARCV9
: return "Sparc v9";
1806 case EM_TRICORE
: return "Siemens Tricore";
1807 case EM_ARC
: return "ARC";
1808 case EM_H8_300
: return "Renesas H8/300";
1809 case EM_H8_300H
: return "Renesas H8/300H";
1810 case EM_H8S
: return "Renesas H8S";
1811 case EM_H8_500
: return "Renesas H8/500";
1812 case EM_IA_64
: return "Intel IA-64";
1813 case EM_MIPS_X
: return "Stanford MIPS-X";
1814 case EM_COLDFIRE
: return "Motorola Coldfire";
1815 case EM_68HC12
: return "Motorola M68HC12";
1816 case EM_ALPHA
: return "Alpha";
1817 case EM_CYGNUS_D10V
:
1818 case EM_D10V
: return "d10v";
1819 case EM_CYGNUS_D30V
:
1820 case EM_D30V
: return "d30v";
1821 case EM_CYGNUS_M32R
:
1822 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1823 case EM_CYGNUS_V850
:
1824 case EM_V850
: return "NEC v850";
1825 case EM_CYGNUS_MN10300
:
1826 case EM_MN10300
: return "mn10300";
1827 case EM_CYGNUS_MN10200
:
1828 case EM_MN10200
: return "mn10200";
1829 case EM_CYGNUS_FR30
:
1830 case EM_FR30
: return "Fujitsu FR30";
1831 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1833 case EM_PJ
: return "picoJava";
1834 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1835 case EM_PCP
: return "Siemens PCP";
1836 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1837 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1838 case EM_STARCORE
: return "Motorola Star*Core processor";
1839 case EM_ME16
: return "Toyota ME16 processor";
1840 case EM_ST100
: return "STMicroelectronics ST100 processor";
1841 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1842 case EM_FX66
: return "Siemens FX66 microcontroller";
1843 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1844 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1845 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1846 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1847 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1848 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1849 case EM_SVX
: return "Silicon Graphics SVx";
1850 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1851 case EM_VAX
: return "Digital VAX";
1853 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1854 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1855 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1856 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1857 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1858 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1859 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1860 case EM_PRISM
: return "Vitesse Prism";
1861 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1862 case EM_L1OM
: return "Intel L1OM";
1864 case EM_S390
: return "IBM S/390";
1865 case EM_SCORE
: return "SUNPLUS S+Core";
1866 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1868 case EM_OR32
: return "OpenRISC";
1869 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1870 case EM_DLX
: return "OpenDLX";
1872 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1873 case EM_IQ2000
: return "Vitesse IQ2000";
1875 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1876 case EM_LATTICEMICO32
: return "Lattice Mico32";
1878 case EM_M32C
: return "Renesas M32c";
1879 case EM_MT
: return "Morpho Techologies MT processor";
1880 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1881 case EM_NIOS32
: return "Altera Nios";
1882 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1883 case EM_XC16X
: return "Infineon Technologies xc16x";
1884 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1886 case EM_CR16_OLD
: return "National Semiconductor's CR16";
1887 case EM_MICROBLAZE
: return "Xilinx MicroBlaze";
1888 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
1890 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
1896 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1901 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1902 e_flags
&= ~ EF_ARM_EABIMASK
;
1904 /* Handle "generic" ARM flags. */
1905 if (e_flags
& EF_ARM_RELEXEC
)
1907 strcat (buf
, ", relocatable executable");
1908 e_flags
&= ~ EF_ARM_RELEXEC
;
1911 if (e_flags
& EF_ARM_HASENTRY
)
1913 strcat (buf
, ", has entry point");
1914 e_flags
&= ~ EF_ARM_HASENTRY
;
1917 /* Now handle EABI specific flags. */
1921 strcat (buf
, ", <unrecognized EABI>");
1926 case EF_ARM_EABI_VER1
:
1927 strcat (buf
, ", Version1 EABI");
1932 /* Process flags one bit at a time. */
1933 flag
= e_flags
& - e_flags
;
1938 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1939 strcat (buf
, ", sorted symbol tables");
1949 case EF_ARM_EABI_VER2
:
1950 strcat (buf
, ", Version2 EABI");
1955 /* Process flags one bit at a time. */
1956 flag
= e_flags
& - e_flags
;
1961 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1962 strcat (buf
, ", sorted symbol tables");
1965 case EF_ARM_DYNSYMSUSESEGIDX
:
1966 strcat (buf
, ", dynamic symbols use segment index");
1969 case EF_ARM_MAPSYMSFIRST
:
1970 strcat (buf
, ", mapping symbols precede others");
1980 case EF_ARM_EABI_VER3
:
1981 strcat (buf
, ", Version3 EABI");
1984 case EF_ARM_EABI_VER4
:
1985 strcat (buf
, ", Version4 EABI");
1988 case EF_ARM_EABI_VER5
:
1989 strcat (buf
, ", Version5 EABI");
1995 /* Process flags one bit at a time. */
1996 flag
= e_flags
& - e_flags
;
2002 strcat (buf
, ", BE8");
2006 strcat (buf
, ", LE8");
2016 case EF_ARM_EABI_UNKNOWN
:
2017 strcat (buf
, ", GNU EABI");
2022 /* Process flags one bit at a time. */
2023 flag
= e_flags
& - e_flags
;
2028 case EF_ARM_INTERWORK
:
2029 strcat (buf
, ", interworking enabled");
2032 case EF_ARM_APCS_26
:
2033 strcat (buf
, ", uses APCS/26");
2036 case EF_ARM_APCS_FLOAT
:
2037 strcat (buf
, ", uses APCS/float");
2041 strcat (buf
, ", position independent");
2045 strcat (buf
, ", 8 bit structure alignment");
2048 case EF_ARM_NEW_ABI
:
2049 strcat (buf
, ", uses new ABI");
2052 case EF_ARM_OLD_ABI
:
2053 strcat (buf
, ", uses old ABI");
2056 case EF_ARM_SOFT_FLOAT
:
2057 strcat (buf
, ", software FP");
2060 case EF_ARM_VFP_FLOAT
:
2061 strcat (buf
, ", VFP");
2064 case EF_ARM_MAVERICK_FLOAT
:
2065 strcat (buf
, ", Maverick FP");
2076 strcat (buf
,", <unknown>");
2080 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
2082 static char buf
[1024];
2094 decode_ARM_machine_flags (e_flags
, buf
);
2098 switch (e_flags
& EF_FRV_CPU_MASK
)
2100 case EF_FRV_CPU_GENERIC
:
2104 strcat (buf
, ", fr???");
2107 case EF_FRV_CPU_FR300
:
2108 strcat (buf
, ", fr300");
2111 case EF_FRV_CPU_FR400
:
2112 strcat (buf
, ", fr400");
2114 case EF_FRV_CPU_FR405
:
2115 strcat (buf
, ", fr405");
2118 case EF_FRV_CPU_FR450
:
2119 strcat (buf
, ", fr450");
2122 case EF_FRV_CPU_FR500
:
2123 strcat (buf
, ", fr500");
2125 case EF_FRV_CPU_FR550
:
2126 strcat (buf
, ", fr550");
2129 case EF_FRV_CPU_SIMPLE
:
2130 strcat (buf
, ", simple");
2132 case EF_FRV_CPU_TOMCAT
:
2133 strcat (buf
, ", tomcat");
2139 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2140 strcat (buf
, ", m68000");
2141 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2142 strcat (buf
, ", cpu32");
2143 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2144 strcat (buf
, ", fido_a");
2147 char const * isa
= _("unknown");
2148 char const * mac
= _("unknown mac");
2149 char const * additional
= NULL
;
2151 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2153 case EF_M68K_CF_ISA_A_NODIV
:
2155 additional
= ", nodiv";
2157 case EF_M68K_CF_ISA_A
:
2160 case EF_M68K_CF_ISA_A_PLUS
:
2163 case EF_M68K_CF_ISA_B_NOUSP
:
2165 additional
= ", nousp";
2167 case EF_M68K_CF_ISA_B
:
2171 strcat (buf
, ", cf, isa ");
2174 strcat (buf
, additional
);
2175 if (e_flags
& EF_M68K_CF_FLOAT
)
2176 strcat (buf
, ", float");
2177 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2182 case EF_M68K_CF_MAC
:
2185 case EF_M68K_CF_EMAC
:
2198 if (e_flags
& EF_PPC_EMB
)
2199 strcat (buf
, ", emb");
2201 if (e_flags
& EF_PPC_RELOCATABLE
)
2202 strcat (buf
, ", relocatable");
2204 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2205 strcat (buf
, ", relocatable-lib");
2209 case EM_CYGNUS_V850
:
2210 switch (e_flags
& EF_V850_ARCH
)
2213 strcat (buf
, ", v850e1");
2216 strcat (buf
, ", v850e");
2219 strcat (buf
, ", v850");
2222 strcat (buf
, ", unknown v850 architecture variant");
2228 case EM_CYGNUS_M32R
:
2229 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2230 strcat (buf
, ", m32r");
2234 case EM_MIPS_RS3_LE
:
2235 if (e_flags
& EF_MIPS_NOREORDER
)
2236 strcat (buf
, ", noreorder");
2238 if (e_flags
& EF_MIPS_PIC
)
2239 strcat (buf
, ", pic");
2241 if (e_flags
& EF_MIPS_CPIC
)
2242 strcat (buf
, ", cpic");
2244 if (e_flags
& EF_MIPS_UCODE
)
2245 strcat (buf
, ", ugen_reserved");
2247 if (e_flags
& EF_MIPS_ABI2
)
2248 strcat (buf
, ", abi2");
2250 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2251 strcat (buf
, ", odk first");
2253 if (e_flags
& EF_MIPS_32BITMODE
)
2254 strcat (buf
, ", 32bitmode");
2256 switch ((e_flags
& EF_MIPS_MACH
))
2258 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2259 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2260 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2261 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2262 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2263 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2264 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2265 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2266 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2267 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2268 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
2269 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
2270 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
2271 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
2273 /* We simply ignore the field in this case to avoid confusion:
2274 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2277 default: strcat (buf
, ", unknown CPU"); break;
2280 switch ((e_flags
& EF_MIPS_ABI
))
2282 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2283 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2284 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2285 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2287 /* We simply ignore the field in this case to avoid confusion:
2288 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2289 This means it is likely to be an o32 file, but not for
2292 default: strcat (buf
, ", unknown ABI"); break;
2295 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2296 strcat (buf
, ", mdmx");
2298 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2299 strcat (buf
, ", mips16");
2301 switch ((e_flags
& EF_MIPS_ARCH
))
2303 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2304 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2305 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2306 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2307 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2308 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2309 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2310 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2311 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2312 default: strcat (buf
, ", unknown ISA"); break;
2318 switch ((e_flags
& EF_SH_MACH_MASK
))
2320 case EF_SH1
: strcat (buf
, ", sh1"); break;
2321 case EF_SH2
: strcat (buf
, ", sh2"); break;
2322 case EF_SH3
: strcat (buf
, ", sh3"); break;
2323 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2324 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2325 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2326 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2327 case EF_SH4
: strcat (buf
, ", sh4"); break;
2328 case EF_SH5
: strcat (buf
, ", sh5"); break;
2329 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2330 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2331 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2332 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2333 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2334 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2335 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2336 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2337 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2338 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2339 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2340 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2341 default: strcat (buf
, ", unknown ISA"); break;
2347 if (e_flags
& EF_SPARC_32PLUS
)
2348 strcat (buf
, ", v8+");
2350 if (e_flags
& EF_SPARC_SUN_US1
)
2351 strcat (buf
, ", ultrasparcI");
2353 if (e_flags
& EF_SPARC_SUN_US3
)
2354 strcat (buf
, ", ultrasparcIII");
2356 if (e_flags
& EF_SPARC_HAL_R1
)
2357 strcat (buf
, ", halr1");
2359 if (e_flags
& EF_SPARC_LEDATA
)
2360 strcat (buf
, ", ledata");
2362 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2363 strcat (buf
, ", tso");
2365 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2366 strcat (buf
, ", pso");
2368 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2369 strcat (buf
, ", rmo");
2373 switch (e_flags
& EF_PARISC_ARCH
)
2375 case EFA_PARISC_1_0
:
2376 strcpy (buf
, ", PA-RISC 1.0");
2378 case EFA_PARISC_1_1
:
2379 strcpy (buf
, ", PA-RISC 1.1");
2381 case EFA_PARISC_2_0
:
2382 strcpy (buf
, ", PA-RISC 2.0");
2387 if (e_flags
& EF_PARISC_TRAPNIL
)
2388 strcat (buf
, ", trapnil");
2389 if (e_flags
& EF_PARISC_EXT
)
2390 strcat (buf
, ", ext");
2391 if (e_flags
& EF_PARISC_LSB
)
2392 strcat (buf
, ", lsb");
2393 if (e_flags
& EF_PARISC_WIDE
)
2394 strcat (buf
, ", wide");
2395 if (e_flags
& EF_PARISC_NO_KABP
)
2396 strcat (buf
, ", no kabp");
2397 if (e_flags
& EF_PARISC_LAZYSWAP
)
2398 strcat (buf
, ", lazyswap");
2403 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2404 strcat (buf
, ", new calling convention");
2406 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2407 strcat (buf
, ", gnu calling convention");
2411 if ((e_flags
& EF_IA_64_ABI64
))
2412 strcat (buf
, ", 64-bit");
2414 strcat (buf
, ", 32-bit");
2415 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2416 strcat (buf
, ", reduced fp model");
2417 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2418 strcat (buf
, ", no function descriptors, constant gp");
2419 else if ((e_flags
& EF_IA_64_CONS_GP
))
2420 strcat (buf
, ", constant gp");
2421 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2422 strcat (buf
, ", absolute");
2426 if ((e_flags
& EF_VAX_NONPIC
))
2427 strcat (buf
, ", non-PIC");
2428 if ((e_flags
& EF_VAX_DFLOAT
))
2429 strcat (buf
, ", D-Float");
2430 if ((e_flags
& EF_VAX_GFLOAT
))
2431 strcat (buf
, ", G-Float");
2440 get_osabi_name (unsigned int osabi
)
2442 static char buff
[32];
2446 case ELFOSABI_NONE
: return "UNIX - System V";
2447 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2448 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2449 case ELFOSABI_LINUX
: return "UNIX - Linux";
2450 case ELFOSABI_HURD
: return "GNU/Hurd";
2451 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2452 case ELFOSABI_AIX
: return "UNIX - AIX";
2453 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2454 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2455 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2456 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2457 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2458 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2459 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2460 case ELFOSABI_AROS
: return "AROS";
2461 case ELFOSABI_STANDALONE
: return _("Standalone App");
2462 case ELFOSABI_ARM
: return "ARM";
2464 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2470 get_arm_segment_type (unsigned long type
)
2484 get_mips_segment_type (unsigned long type
)
2488 case PT_MIPS_REGINFO
:
2490 case PT_MIPS_RTPROC
:
2492 case PT_MIPS_OPTIONS
:
2502 get_parisc_segment_type (unsigned long type
)
2506 case PT_HP_TLS
: return "HP_TLS";
2507 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2508 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2509 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2510 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2511 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2512 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2513 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2514 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2515 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2516 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2517 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2518 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2519 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2520 case PT_HP_STACK
: return "HP_STACK";
2521 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2522 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2523 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2524 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2533 get_ia64_segment_type (unsigned long type
)
2537 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2538 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2539 case PT_HP_TLS
: return "HP_TLS";
2540 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2541 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2542 case PT_IA_64_HP_STACK
: return "HP_STACK";
2551 get_segment_type (unsigned long p_type
)
2553 static char buff
[32];
2557 case PT_NULL
: return "NULL";
2558 case PT_LOAD
: return "LOAD";
2559 case PT_DYNAMIC
: return "DYNAMIC";
2560 case PT_INTERP
: return "INTERP";
2561 case PT_NOTE
: return "NOTE";
2562 case PT_SHLIB
: return "SHLIB";
2563 case PT_PHDR
: return "PHDR";
2564 case PT_TLS
: return "TLS";
2566 case PT_GNU_EH_FRAME
:
2567 return "GNU_EH_FRAME";
2568 case PT_GNU_STACK
: return "GNU_STACK";
2569 case PT_GNU_RELRO
: return "GNU_RELRO";
2572 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2574 const char * result
;
2576 switch (elf_header
.e_machine
)
2579 result
= get_arm_segment_type (p_type
);
2582 case EM_MIPS_RS3_LE
:
2583 result
= get_mips_segment_type (p_type
);
2586 result
= get_parisc_segment_type (p_type
);
2589 result
= get_ia64_segment_type (p_type
);
2599 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2601 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2603 const char * result
;
2605 switch (elf_header
.e_machine
)
2608 result
= get_parisc_segment_type (p_type
);
2611 result
= get_ia64_segment_type (p_type
);
2621 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2624 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2631 get_mips_section_type_name (unsigned int sh_type
)
2635 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2636 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2637 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2638 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2639 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2640 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2641 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2642 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2643 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2644 case SHT_MIPS_RELD
: return "MIPS_RELD";
2645 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2646 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2647 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2648 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2649 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2650 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2651 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2652 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2653 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2654 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2655 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2656 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2657 case SHT_MIPS_LINE
: return "MIPS_LINE";
2658 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2659 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2660 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2661 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2662 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2663 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2664 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2665 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2666 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2667 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2668 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2669 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2670 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2671 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2672 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2673 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2681 get_parisc_section_type_name (unsigned int sh_type
)
2685 case SHT_PARISC_EXT
: return "PARISC_EXT";
2686 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2687 case SHT_PARISC_DOC
: return "PARISC_DOC";
2688 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2689 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2690 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2691 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2699 get_ia64_section_type_name (unsigned int sh_type
)
2701 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2702 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2703 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2707 case SHT_IA_64_EXT
: return "IA_64_EXT";
2708 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2709 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2710 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
2711 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
2712 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
2713 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
2714 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
2715 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
2716 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
2724 get_x86_64_section_type_name (unsigned int sh_type
)
2728 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2736 get_arm_section_type_name (unsigned int sh_type
)
2740 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
2741 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
2742 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
2743 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
2744 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
2752 get_section_type_name (unsigned int sh_type
)
2754 static char buff
[32];
2758 case SHT_NULL
: return "NULL";
2759 case SHT_PROGBITS
: return "PROGBITS";
2760 case SHT_SYMTAB
: return "SYMTAB";
2761 case SHT_STRTAB
: return "STRTAB";
2762 case SHT_RELA
: return "RELA";
2763 case SHT_HASH
: return "HASH";
2764 case SHT_DYNAMIC
: return "DYNAMIC";
2765 case SHT_NOTE
: return "NOTE";
2766 case SHT_NOBITS
: return "NOBITS";
2767 case SHT_REL
: return "REL";
2768 case SHT_SHLIB
: return "SHLIB";
2769 case SHT_DYNSYM
: return "DYNSYM";
2770 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2771 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2772 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2773 case SHT_GNU_HASH
: return "GNU_HASH";
2774 case SHT_GROUP
: return "GROUP";
2775 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2776 case SHT_GNU_verdef
: return "VERDEF";
2777 case SHT_GNU_verneed
: return "VERNEED";
2778 case SHT_GNU_versym
: return "VERSYM";
2779 case 0x6ffffff0: return "VERSYM";
2780 case 0x6ffffffc: return "VERDEF";
2781 case 0x7ffffffd: return "AUXILIARY";
2782 case 0x7fffffff: return "FILTER";
2783 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2786 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2788 const char * result
;
2790 switch (elf_header
.e_machine
)
2793 case EM_MIPS_RS3_LE
:
2794 result
= get_mips_section_type_name (sh_type
);
2797 result
= get_parisc_section_type_name (sh_type
);
2800 result
= get_ia64_section_type_name (sh_type
);
2804 result
= get_x86_64_section_type_name (sh_type
);
2807 result
= get_arm_section_type_name (sh_type
);
2817 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2819 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2821 const char * result
;
2823 switch (elf_header
.e_machine
)
2826 result
= get_ia64_section_type_name (sh_type
);
2836 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2838 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2839 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2841 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2847 #define OPTION_DEBUG_DUMP 512
2849 static struct option options
[] =
2851 {"all", no_argument
, 0, 'a'},
2852 {"file-header", no_argument
, 0, 'h'},
2853 {"program-headers", no_argument
, 0, 'l'},
2854 {"headers", no_argument
, 0, 'e'},
2855 {"histogram", no_argument
, 0, 'I'},
2856 {"segments", no_argument
, 0, 'l'},
2857 {"sections", no_argument
, 0, 'S'},
2858 {"section-headers", no_argument
, 0, 'S'},
2859 {"section-groups", no_argument
, 0, 'g'},
2860 {"section-details", no_argument
, 0, 't'},
2861 {"full-section-name",no_argument
, 0, 'N'},
2862 {"symbols", no_argument
, 0, 's'},
2863 {"syms", no_argument
, 0, 's'},
2864 {"relocs", no_argument
, 0, 'r'},
2865 {"notes", no_argument
, 0, 'n'},
2866 {"dynamic", no_argument
, 0, 'd'},
2867 {"arch-specific", no_argument
, 0, 'A'},
2868 {"version-info", no_argument
, 0, 'V'},
2869 {"use-dynamic", no_argument
, 0, 'D'},
2870 {"unwind", no_argument
, 0, 'u'},
2871 {"archive-index", no_argument
, 0, 'c'},
2872 {"hex-dump", required_argument
, 0, 'x'},
2873 {"relocated-dump", required_argument
, 0, 'R'},
2874 {"string-dump", required_argument
, 0, 'p'},
2875 #ifdef SUPPORT_DISASSEMBLY
2876 {"instruction-dump", required_argument
, 0, 'i'},
2878 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2880 {"version", no_argument
, 0, 'v'},
2881 {"wide", no_argument
, 0, 'W'},
2882 {"help", no_argument
, 0, 'H'},
2883 {0, no_argument
, 0, 0}
2887 usage (FILE * stream
)
2889 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2890 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
2891 fprintf (stream
, _(" Options are:\n\
2892 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2893 -h --file-header Display the ELF file header\n\
2894 -l --program-headers Display the program headers\n\
2895 --segments An alias for --program-headers\n\
2896 -S --section-headers Display the sections' header\n\
2897 --sections An alias for --section-headers\n\
2898 -g --section-groups Display the section groups\n\
2899 -t --section-details Display the section details\n\
2900 -e --headers Equivalent to: -h -l -S\n\
2901 -s --syms Display the symbol table\n\
2902 --symbols An alias for --syms\n\
2903 -n --notes Display the core notes (if present)\n\
2904 -r --relocs Display the relocations (if present)\n\
2905 -u --unwind Display the unwind info (if present)\n\
2906 -d --dynamic Display the dynamic section (if present)\n\
2907 -V --version-info Display the version sections (if present)\n\
2908 -A --arch-specific Display architecture specific information (if any).\n\
2909 -c --archive-index Display the symbol/file index in an archive\n\
2910 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2911 -x --hex-dump=<number|name>\n\
2912 Dump the contents of section <number|name> as bytes\n\
2913 -p --string-dump=<number|name>\n\
2914 Dump the contents of section <number|name> as strings\n\
2915 -R --relocated-dump=<number|name>\n\
2916 Dump the contents of section <number|name> as relocated bytes\n\
2917 -w[lLiaprmfFsoR] or\n\
2918 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2919 Display the contents of DWARF2 debug sections\n"));
2920 #ifdef SUPPORT_DISASSEMBLY
2921 fprintf (stream
, _("\
2922 -i --instruction-dump=<number|name>\n\
2923 Disassemble the contents of section <number|name>\n"));
2925 fprintf (stream
, _("\
2926 -I --histogram Display histogram of bucket list lengths\n\
2927 -W --wide Allow output width to exceed 80 characters\n\
2928 @<file> Read options from <file>\n\
2929 -H --help Display this information\n\
2930 -v --version Display the version number of readelf\n"));
2932 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2933 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2935 exit (stream
== stdout
? 0 : 1);
2938 /* Record the fact that the user wants the contents of section number
2939 SECTION to be displayed using the method(s) encoded as flags bits
2940 in TYPE. Note, TYPE can be zero if we are creating the array for
2944 request_dump_bynumber (unsigned int section
, dump_type type
)
2946 if (section
>= num_dump_sects
)
2948 dump_type
* new_dump_sects
;
2950 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
2951 sizeof (* dump_sects
));
2953 if (new_dump_sects
== NULL
)
2954 error (_("Out of memory allocating dump request table.\n"));
2957 /* Copy current flag settings. */
2958 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
* sizeof (* dump_sects
));
2962 dump_sects
= new_dump_sects
;
2963 num_dump_sects
= section
+ 1;
2968 dump_sects
[section
] |= type
;
2973 /* Request a dump by section name. */
2976 request_dump_byname (const char * section
, dump_type type
)
2978 struct dump_list_entry
* new_request
;
2980 new_request
= (struct dump_list_entry
*)
2981 malloc (sizeof (struct dump_list_entry
));
2983 error (_("Out of memory allocating dump request table.\n"));
2985 new_request
->name
= strdup (section
);
2986 if (!new_request
->name
)
2987 error (_("Out of memory allocating dump request table.\n"));
2989 new_request
->type
= type
;
2991 new_request
->next
= dump_sects_byname
;
2992 dump_sects_byname
= new_request
;
2996 request_dump (dump_type type
)
3002 section
= strtoul (optarg
, & cp
, 0);
3004 if (! *cp
&& section
>= 0)
3005 request_dump_bynumber (section
, type
);
3007 request_dump_byname (optarg
, type
);
3012 parse_args (int argc
, char ** argv
)
3019 while ((c
= getopt_long
3020 (argc
, argv
, "ADHINR:SVWacdeghi:lnp:rstuvw::x:", options
, NULL
)) != EOF
)
3038 do_section_groups
++;
3046 do_section_groups
++;
3051 do_section_details
++;
3095 request_dump (HEX_DUMP
);
3098 request_dump (STRING_DUMP
);
3101 request_dump (RELOC_DUMP
);
3108 dwarf_select_sections_all ();
3113 dwarf_select_sections_by_letters (optarg
);
3116 case OPTION_DEBUG_DUMP
:
3123 dwarf_select_sections_by_names (optarg
);
3126 #ifdef SUPPORT_DISASSEMBLY
3128 request_dump (DISASS_DUMP
);
3132 print_version (program_name
);
3141 /* xgettext:c-format */
3142 error (_("Invalid option '-%c'\n"), c
);
3149 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3150 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3151 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3152 && !do_section_groups
&& !do_archive_index
)
3156 warn (_("Nothing to do.\n"));
3162 get_elf_class (unsigned int elf_class
)
3164 static char buff
[32];
3168 case ELFCLASSNONE
: return _("none");
3169 case ELFCLASS32
: return "ELF32";
3170 case ELFCLASS64
: return "ELF64";
3172 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3178 get_data_encoding (unsigned int encoding
)
3180 static char buff
[32];
3184 case ELFDATANONE
: return _("none");
3185 case ELFDATA2LSB
: return _("2's complement, little endian");
3186 case ELFDATA2MSB
: return _("2's complement, big endian");
3188 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3193 /* Decode the data held in 'elf_header'. */
3196 process_file_header (void)
3198 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3199 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3200 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3201 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3204 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3208 init_dwarf_regnames (elf_header
.e_machine
);
3214 printf (_("ELF Header:\n"));
3215 printf (_(" Magic: "));
3216 for (i
= 0; i
< EI_NIDENT
; i
++)
3217 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3219 printf (_(" Class: %s\n"),
3220 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3221 printf (_(" Data: %s\n"),
3222 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3223 printf (_(" Version: %d %s\n"),
3224 elf_header
.e_ident
[EI_VERSION
],
3225 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3227 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3230 printf (_(" OS/ABI: %s\n"),
3231 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3232 printf (_(" ABI Version: %d\n"),
3233 elf_header
.e_ident
[EI_ABIVERSION
]);
3234 printf (_(" Type: %s\n"),
3235 get_file_type (elf_header
.e_type
));
3236 printf (_(" Machine: %s\n"),
3237 get_machine_name (elf_header
.e_machine
));
3238 printf (_(" Version: 0x%lx\n"),
3239 (unsigned long) elf_header
.e_version
);
3241 printf (_(" Entry point address: "));
3242 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3243 printf (_("\n Start of program headers: "));
3244 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3245 printf (_(" (bytes into file)\n Start of section headers: "));
3246 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3247 printf (_(" (bytes into file)\n"));
3249 printf (_(" Flags: 0x%lx%s\n"),
3250 (unsigned long) elf_header
.e_flags
,
3251 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3252 printf (_(" Size of this header: %ld (bytes)\n"),
3253 (long) elf_header
.e_ehsize
);
3254 printf (_(" Size of program headers: %ld (bytes)\n"),
3255 (long) elf_header
.e_phentsize
);
3256 printf (_(" Number of program headers: %ld\n"),
3257 (long) elf_header
.e_phnum
);
3258 printf (_(" Size of section headers: %ld (bytes)\n"),
3259 (long) elf_header
.e_shentsize
);
3260 printf (_(" Number of section headers: %ld"),
3261 (long) elf_header
.e_shnum
);
3262 if (section_headers
!= NULL
&& elf_header
.e_shnum
== SHN_UNDEF
)
3263 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3264 putc ('\n', stdout
);
3265 printf (_(" Section header string table index: %ld"),
3266 (long) elf_header
.e_shstrndx
);
3267 if (section_headers
!= NULL
3268 && elf_header
.e_shstrndx
== (SHN_XINDEX
& 0xffff))
3269 printf (" (%u)", section_headers
[0].sh_link
);
3270 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3271 && elf_header
.e_shstrndx
>= elf_header
.e_shnum
)
3272 printf (" <corrupt: out of range>");
3273 putc ('\n', stdout
);
3276 if (section_headers
!= NULL
)
3278 if (elf_header
.e_shnum
== SHN_UNDEF
)
3279 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3280 if (elf_header
.e_shstrndx
== (SHN_XINDEX
& 0xffff))
3281 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3282 else if (elf_header
.e_shstrndx
>= elf_header
.e_shnum
)
3283 elf_header
.e_shstrndx
= SHN_UNDEF
;
3284 free (section_headers
);
3285 section_headers
= NULL
;
3293 get_32bit_program_headers (FILE * file
, Elf_Internal_Phdr
* program_headers
)
3295 Elf32_External_Phdr
* phdrs
;
3296 Elf32_External_Phdr
* external
;
3297 Elf_Internal_Phdr
* internal
;
3300 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, file
, elf_header
.e_phoff
,
3301 elf_header
.e_phentsize
,
3303 _("program headers"));
3307 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3308 i
< elf_header
.e_phnum
;
3309 i
++, internal
++, external
++)
3311 internal
->p_type
= BYTE_GET (external
->p_type
);
3312 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3313 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3314 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3315 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3316 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3317 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3318 internal
->p_align
= BYTE_GET (external
->p_align
);
3327 get_64bit_program_headers (FILE * file
, Elf_Internal_Phdr
* program_headers
)
3329 Elf64_External_Phdr
* phdrs
;
3330 Elf64_External_Phdr
* external
;
3331 Elf_Internal_Phdr
* internal
;
3334 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, file
, elf_header
.e_phoff
,
3335 elf_header
.e_phentsize
,
3337 _("program headers"));
3341 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3342 i
< elf_header
.e_phnum
;
3343 i
++, internal
++, external
++)
3345 internal
->p_type
= BYTE_GET (external
->p_type
);
3346 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3347 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3348 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3349 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3350 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3351 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3352 internal
->p_align
= BYTE_GET (external
->p_align
);
3360 /* Returns 1 if the program headers were read into `program_headers'. */
3363 get_program_headers (FILE * file
)
3365 Elf_Internal_Phdr
* phdrs
;
3367 /* Check cache of prior read. */
3368 if (program_headers
!= NULL
)
3371 phdrs
= (Elf_Internal_Phdr
*) cmalloc (elf_header
.e_phnum
,
3372 sizeof (Elf_Internal_Phdr
));
3376 error (_("Out of memory\n"));
3381 ? get_32bit_program_headers (file
, phdrs
)
3382 : get_64bit_program_headers (file
, phdrs
))
3384 program_headers
= phdrs
;
3392 /* Returns 1 if the program headers were loaded. */
3395 process_program_headers (FILE * file
)
3397 Elf_Internal_Phdr
* segment
;
3400 if (elf_header
.e_phnum
== 0)
3403 printf (_("\nThere are no program headers in this file.\n"));
3407 if (do_segments
&& !do_header
)
3409 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3410 printf (_("Entry point "));
3411 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3412 printf (_("\nThere are %d program headers, starting at offset "),
3413 elf_header
.e_phnum
);
3414 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3418 if (! get_program_headers (file
))
3423 if (elf_header
.e_phnum
> 1)
3424 printf (_("\nProgram Headers:\n"));
3426 printf (_("\nProgram Headers:\n"));
3430 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3433 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3437 (_(" Type Offset VirtAddr PhysAddr\n"));
3439 (_(" FileSiz MemSiz Flags Align\n"));
3446 for (i
= 0, segment
= program_headers
;
3447 i
< elf_header
.e_phnum
;
3452 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3456 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3457 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3458 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3459 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3460 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3462 (segment
->p_flags
& PF_R
? 'R' : ' '),
3463 (segment
->p_flags
& PF_W
? 'W' : ' '),
3464 (segment
->p_flags
& PF_X
? 'E' : ' '));
3465 printf ("%#lx", (unsigned long) segment
->p_align
);
3469 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3470 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3473 print_vma (segment
->p_offset
, FULL_HEX
);
3477 print_vma (segment
->p_vaddr
, FULL_HEX
);
3479 print_vma (segment
->p_paddr
, FULL_HEX
);
3482 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3483 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3486 print_vma (segment
->p_filesz
, FULL_HEX
);
3490 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3491 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3494 print_vma (segment
->p_offset
, FULL_HEX
);
3498 (segment
->p_flags
& PF_R
? 'R' : ' '),
3499 (segment
->p_flags
& PF_W
? 'W' : ' '),
3500 (segment
->p_flags
& PF_X
? 'E' : ' '));
3502 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3503 printf ("%#lx", (unsigned long) segment
->p_align
);
3506 print_vma (segment
->p_align
, PREFIX_HEX
);
3511 print_vma (segment
->p_offset
, FULL_HEX
);
3513 print_vma (segment
->p_vaddr
, FULL_HEX
);
3515 print_vma (segment
->p_paddr
, FULL_HEX
);
3517 print_vma (segment
->p_filesz
, FULL_HEX
);
3519 print_vma (segment
->p_memsz
, FULL_HEX
);
3521 (segment
->p_flags
& PF_R
? 'R' : ' '),
3522 (segment
->p_flags
& PF_W
? 'W' : ' '),
3523 (segment
->p_flags
& PF_X
? 'E' : ' '));
3524 print_vma (segment
->p_align
, HEX
);
3528 switch (segment
->p_type
)
3532 error (_("more than one dynamic segment\n"));
3534 /* By default, assume that the .dynamic section is the first
3535 section in the DYNAMIC segment. */
3536 dynamic_addr
= segment
->p_offset
;
3537 dynamic_size
= segment
->p_filesz
;
3539 /* Try to locate the .dynamic section. If there is
3540 a section header table, we can easily locate it. */
3541 if (section_headers
!= NULL
)
3543 Elf_Internal_Shdr
* sec
;
3545 sec
= find_section (".dynamic");
3546 if (sec
== NULL
|| sec
->sh_size
== 0)
3548 error (_("no .dynamic section in the dynamic segment\n"));
3552 if (sec
->sh_type
== SHT_NOBITS
)
3558 dynamic_addr
= sec
->sh_offset
;
3559 dynamic_size
= sec
->sh_size
;
3561 if (dynamic_addr
< segment
->p_offset
3562 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3563 warn (_("the .dynamic section is not contained"
3564 " within the dynamic segment\n"));
3565 else if (dynamic_addr
> segment
->p_offset
)
3566 warn (_("the .dynamic section is not the first section"
3567 " in the dynamic segment.\n"));
3572 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3574 error (_("Unable to find program interpreter name\n"));
3578 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3580 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3581 error (_("Internal error: failed to create format string to display program interpreter\n"));
3583 program_interpreter
[0] = 0;
3584 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3585 error (_("Unable to read program interpreter name\n"));
3588 printf (_("\n [Requesting program interpreter: %s]"),
3589 program_interpreter
);
3595 putc ('\n', stdout
);
3598 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3600 printf (_("\n Section to Segment mapping:\n"));
3601 printf (_(" Segment Sections...\n"));
3603 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3606 Elf_Internal_Shdr
* section
;
3608 segment
= program_headers
+ i
;
3609 section
= section_headers
+ 1;
3611 printf (" %2.2d ", i
);
3613 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3615 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY (section
, segment
))
3616 printf ("%s ", SECTION_NAME (section
));
3627 /* Find the file offset corresponding to VMA by using the program headers. */
3630 offset_from_vma (FILE * file
, bfd_vma vma
, bfd_size_type size
)
3632 Elf_Internal_Phdr
* seg
;
3634 if (! get_program_headers (file
))
3636 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3640 for (seg
= program_headers
;
3641 seg
< program_headers
+ elf_header
.e_phnum
;
3644 if (seg
->p_type
!= PT_LOAD
)
3647 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3648 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3649 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3652 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3653 (unsigned long) vma
);
3659 get_32bit_section_headers (FILE * file
, unsigned int num
)
3661 Elf32_External_Shdr
* shdrs
;
3662 Elf_Internal_Shdr
* internal
;
3665 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, file
, elf_header
.e_shoff
,
3666 elf_header
.e_shentsize
, num
,
3667 _("section headers"));
3671 section_headers
= (Elf_Internal_Shdr
*) cmalloc (num
,
3672 sizeof (Elf_Internal_Shdr
));
3674 if (section_headers
== NULL
)
3676 error (_("Out of memory\n"));
3680 for (i
= 0, internal
= section_headers
;
3684 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3685 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3686 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3687 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3688 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3689 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3690 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3691 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3692 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3693 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3702 get_64bit_section_headers (FILE * file
, unsigned int num
)
3704 Elf64_External_Shdr
* shdrs
;
3705 Elf_Internal_Shdr
* internal
;
3708 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, file
, elf_header
.e_shoff
,
3709 elf_header
.e_shentsize
, num
,
3710 _("section headers"));
3714 section_headers
= (Elf_Internal_Shdr
*) cmalloc (num
,
3715 sizeof (Elf_Internal_Shdr
));
3717 if (section_headers
== NULL
)
3719 error (_("Out of memory\n"));
3723 for (i
= 0, internal
= section_headers
;
3727 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3728 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3729 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3730 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3731 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3732 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3733 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3734 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3735 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3736 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3744 static Elf_Internal_Sym
*
3745 get_32bit_elf_symbols (FILE * file
, Elf_Internal_Shdr
* section
)
3747 unsigned long number
;
3748 Elf32_External_Sym
* esyms
;
3749 Elf_External_Sym_Shndx
* shndx
;
3750 Elf_Internal_Sym
* isyms
;
3751 Elf_Internal_Sym
* psym
;
3754 esyms
= (Elf32_External_Sym
*) get_data (NULL
, file
, section
->sh_offset
, 1,
3755 section
->sh_size
, _("symbols"));
3760 if (symtab_shndx_hdr
!= NULL
3761 && (symtab_shndx_hdr
->sh_link
3762 == (unsigned long) (section
- section_headers
)))
3764 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, file
,
3765 symtab_shndx_hdr
->sh_offset
,
3766 1, symtab_shndx_hdr
->sh_size
,
3775 number
= section
->sh_size
/ section
->sh_entsize
;
3776 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
3780 error (_("Out of memory\n"));
3787 for (j
= 0, psym
= isyms
;
3791 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3792 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3793 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3794 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3795 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
3797 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3798 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
3799 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
3800 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3801 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3811 static Elf_Internal_Sym
*
3812 get_64bit_elf_symbols (FILE * file
, Elf_Internal_Shdr
* section
)
3814 unsigned long number
;
3815 Elf64_External_Sym
* esyms
;
3816 Elf_External_Sym_Shndx
* shndx
;
3817 Elf_Internal_Sym
* isyms
;
3818 Elf_Internal_Sym
* psym
;
3821 esyms
= (Elf64_External_Sym
*) get_data (NULL
, file
, section
->sh_offset
, 1,
3822 section
->sh_size
, _("symbols"));
3827 if (symtab_shndx_hdr
!= NULL
3828 && (symtab_shndx_hdr
->sh_link
3829 == (unsigned long) (section
- section_headers
)))
3831 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, file
,
3832 symtab_shndx_hdr
->sh_offset
,
3833 1, symtab_shndx_hdr
->sh_size
,
3842 number
= section
->sh_size
/ section
->sh_entsize
;
3843 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
3847 error (_("Out of memory\n"));
3854 for (j
= 0, psym
= isyms
;
3858 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3859 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3860 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3861 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3862 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
3864 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3865 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
3866 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
3867 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3868 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3879 get_elf_section_flags (bfd_vma sh_flags
)
3881 static char buff
[1024];
3883 int field_size
= is_32bit_elf
? 8 : 16;
3884 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3885 bfd_vma os_flags
= 0;
3886 bfd_vma proc_flags
= 0;
3887 bfd_vma unknown_flags
= 0;
3895 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
3896 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
3897 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
3898 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
3899 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
3900 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
3901 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
3902 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
3903 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
3904 /* 9 */ { STRING_COMMA_LEN ("TLS") },
3905 /* IA-64 specific. */
3906 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
3907 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
3908 /* IA-64 OpenVMS specific. */
3909 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
3910 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
3911 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
3912 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
3913 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
3914 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
3915 /* SPARC specific. */
3916 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
3917 /* 19 */ { STRING_COMMA_LEN ("ORDERED") }
3920 if (do_section_details
)
3922 sprintf (buff
, "[%*.*lx]: ",
3923 field_size
, field_size
, (unsigned long) sh_flags
);
3924 p
+= field_size
+ 4;
3931 flag
= sh_flags
& - sh_flags
;
3934 if (do_section_details
)
3938 case SHF_WRITE
: index
= 0; break;
3939 case SHF_ALLOC
: index
= 1; break;
3940 case SHF_EXECINSTR
: index
= 2; break;
3941 case SHF_MERGE
: index
= 3; break;
3942 case SHF_STRINGS
: index
= 4; break;
3943 case SHF_INFO_LINK
: index
= 5; break;
3944 case SHF_LINK_ORDER
: index
= 6; break;
3945 case SHF_OS_NONCONFORMING
: index
= 7; break;
3946 case SHF_GROUP
: index
= 8; break;
3947 case SHF_TLS
: index
= 9; break;
3951 switch (elf_header
.e_machine
)
3954 if (flag
== SHF_IA_64_SHORT
)
3956 else if (flag
== SHF_IA_64_NORECOV
)
3959 else if (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
3962 case SHF_IA_64_VMS_GLOBAL
: index
= 12; break;
3963 case SHF_IA_64_VMS_OVERLAID
: index
= 13; break;
3964 case SHF_IA_64_VMS_SHARED
: index
= 14; break;
3965 case SHF_IA_64_VMS_VECTOR
: index
= 15; break;
3966 case SHF_IA_64_VMS_ALLOC_64BIT
: index
= 16; break;
3967 case SHF_IA_64_VMS_PROTECTED
: index
= 17; break;
3973 case EM_OLD_SPARCV9
:
3974 case EM_SPARC32PLUS
:
3977 if (flag
== SHF_EXCLUDE
)
3979 else if (flag
== SHF_ORDERED
)
3989 if (p
!= buff
+ field_size
+ 4)
3991 if (size
< (10 + 2))
3998 size
-= flags
[index
].len
;
3999 p
= stpcpy (p
, flags
[index
].str
);
4001 else if (flag
& SHF_MASKOS
)
4003 else if (flag
& SHF_MASKPROC
)
4006 unknown_flags
|= flag
;
4012 case SHF_WRITE
: *p
= 'W'; break;
4013 case SHF_ALLOC
: *p
= 'A'; break;
4014 case SHF_EXECINSTR
: *p
= 'X'; break;
4015 case SHF_MERGE
: *p
= 'M'; break;
4016 case SHF_STRINGS
: *p
= 'S'; break;
4017 case SHF_INFO_LINK
: *p
= 'I'; break;
4018 case SHF_LINK_ORDER
: *p
= 'L'; break;
4019 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
4020 case SHF_GROUP
: *p
= 'G'; break;
4021 case SHF_TLS
: *p
= 'T'; break;
4024 if ((elf_header
.e_machine
== EM_X86_64
4025 || elf_header
.e_machine
== EM_L1OM
)
4026 && flag
== SHF_X86_64_LARGE
)
4028 else if (flag
& SHF_MASKOS
)
4031 sh_flags
&= ~ SHF_MASKOS
;
4033 else if (flag
& SHF_MASKPROC
)
4036 sh_flags
&= ~ SHF_MASKPROC
;
4046 if (do_section_details
)
4050 size
-= 5 + field_size
;
4051 if (p
!= buff
+ field_size
+ 4)
4059 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
4060 (unsigned long) os_flags
);
4061 p
+= 5 + field_size
;
4065 size
-= 7 + field_size
;
4066 if (p
!= buff
+ field_size
+ 4)
4074 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
4075 (unsigned long) proc_flags
);
4076 p
+= 7 + field_size
;
4080 size
-= 10 + field_size
;
4081 if (p
!= buff
+ field_size
+ 4)
4089 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
4090 (unsigned long) unknown_flags
);
4091 p
+= 10 + field_size
;
4100 process_section_headers (FILE * file
)
4102 Elf_Internal_Shdr
* section
;
4105 section_headers
= NULL
;
4107 if (elf_header
.e_shnum
== 0)
4110 printf (_("\nThere are no sections in this file.\n"));
4115 if (do_sections
&& !do_header
)
4116 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4117 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4121 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4124 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4127 /* Read in the string table, so that we have names to display. */
4128 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4129 && elf_header
.e_shstrndx
< elf_header
.e_shnum
)
4131 section
= section_headers
+ elf_header
.e_shstrndx
;
4133 if (section
->sh_size
!= 0)
4135 string_table
= (char *) get_data (NULL
, file
, section
->sh_offset
,
4136 1, section
->sh_size
,
4139 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4143 /* Scan the sections for the dynamic symbol table
4144 and dynamic string table and debug sections. */
4145 dynamic_symbols
= NULL
;
4146 dynamic_strings
= NULL
;
4147 dynamic_syminfo
= NULL
;
4148 symtab_shndx_hdr
= NULL
;
4150 eh_addr_size
= is_32bit_elf
? 4 : 8;
4151 switch (elf_header
.e_machine
)
4154 case EM_MIPS_RS3_LE
:
4155 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4156 FDE addresses. However, the ABI also has a semi-official ILP32
4157 variant for which the normal FDE address size rules apply.
4159 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4160 section, where XX is the size of longs in bits. Unfortunately,
4161 earlier compilers provided no way of distinguishing ILP32 objects
4162 from LP64 objects, so if there's any doubt, we should assume that
4163 the official LP64 form is being used. */
4164 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4165 && find_section (".gcc_compiled_long32") == NULL
)
4171 switch (elf_header
.e_flags
& EF_H8_MACH
)
4173 case E_H8_MACH_H8300
:
4174 case E_H8_MACH_H8300HN
:
4175 case E_H8_MACH_H8300SN
:
4176 case E_H8_MACH_H8300SXN
:
4179 case E_H8_MACH_H8300H
:
4180 case E_H8_MACH_H8300S
:
4181 case E_H8_MACH_H8300SX
:
4189 switch (elf_header
.e_flags
& EF_M32C_CPU_MASK
)
4191 case EF_M32C_CPU_M16C
:
4198 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4201 size_t expected_entsize \
4202 = is_32bit_elf ? size32 : size64; \
4203 if (section->sh_entsize != expected_entsize) \
4204 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4205 i, (unsigned long int) section->sh_entsize, \
4206 (unsigned long int) expected_entsize); \
4207 section->sh_entsize = expected_entsize; \
4210 #define CHECK_ENTSIZE(section, i, type) \
4211 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4212 sizeof (Elf64_External_##type))
4214 for (i
= 0, section
= section_headers
;
4215 i
< elf_header
.e_shnum
;
4218 char * name
= SECTION_NAME (section
);
4220 if (section
->sh_type
== SHT_DYNSYM
)
4222 if (dynamic_symbols
!= NULL
)
4224 error (_("File contains multiple dynamic symbol tables\n"));
4228 CHECK_ENTSIZE (section
, i
, Sym
);
4229 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4230 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4232 else if (section
->sh_type
== SHT_STRTAB
4233 && streq (name
, ".dynstr"))
4235 if (dynamic_strings
!= NULL
)
4237 error (_("File contains multiple dynamic string tables\n"));
4241 dynamic_strings
= (char *) get_data (NULL
, file
, section
->sh_offset
,
4242 1, section
->sh_size
,
4243 _("dynamic strings"));
4244 dynamic_strings_length
= section
->sh_size
;
4246 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4248 if (symtab_shndx_hdr
!= NULL
)
4250 error (_("File contains multiple symtab shndx tables\n"));
4253 symtab_shndx_hdr
= section
;
4255 else if (section
->sh_type
== SHT_SYMTAB
)
4256 CHECK_ENTSIZE (section
, i
, Sym
);
4257 else if (section
->sh_type
== SHT_GROUP
)
4258 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4259 else if (section
->sh_type
== SHT_REL
)
4260 CHECK_ENTSIZE (section
, i
, Rel
);
4261 else if (section
->sh_type
== SHT_RELA
)
4262 CHECK_ENTSIZE (section
, i
, Rela
);
4263 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4264 || do_debug_lines
|| do_debug_pubnames
4265 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
4266 || do_debug_str
|| do_debug_loc
|| do_debug_ranges
)
4267 && (const_strneq (name
, ".debug_")
4268 || const_strneq (name
, ".zdebug_")))
4271 name
+= sizeof (".zdebug_") - 1;
4273 name
+= sizeof (".debug_") - 1;
4276 || (do_debug_info
&& streq (name
, "info"))
4277 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4278 || (do_debug_lines
&& streq (name
, "line"))
4279 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4280 || (do_debug_aranges
&& streq (name
, "aranges"))
4281 || (do_debug_ranges
&& streq (name
, "ranges"))
4282 || (do_debug_frames
&& streq (name
, "frame"))
4283 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4284 || (do_debug_str
&& streq (name
, "str"))
4285 || (do_debug_loc
&& streq (name
, "loc"))
4287 request_dump_bynumber (i
, DEBUG_DUMP
);
4289 /* Linkonce section to be combined with .debug_info at link time. */
4290 else if ((do_debugging
|| do_debug_info
)
4291 && const_strneq (name
, ".gnu.linkonce.wi."))
4292 request_dump_bynumber (i
, DEBUG_DUMP
);
4293 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4294 request_dump_bynumber (i
, DEBUG_DUMP
);
4300 if (elf_header
.e_shnum
> 1)
4301 printf (_("\nSection Headers:\n"));
4303 printf (_("\nSection Header:\n"));
4307 if (do_section_details
)
4309 printf (_(" [Nr] Name\n"));
4310 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4314 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4318 if (do_section_details
)
4320 printf (_(" [Nr] Name\n"));
4321 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4325 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4329 if (do_section_details
)
4331 printf (_(" [Nr] Name\n"));
4332 printf (_(" Type Address Offset Link\n"));
4333 printf (_(" Size EntSize Info Align\n"));
4337 printf (_(" [Nr] Name Type Address Offset\n"));
4338 printf (_(" Size EntSize Flags Link Info Align\n"));
4342 if (do_section_details
)
4343 printf (_(" Flags\n"));
4345 for (i
= 0, section
= section_headers
;
4346 i
< elf_header
.e_shnum
;
4349 if (do_section_details
)
4351 printf (" [%2u] %s\n",
4353 SECTION_NAME (section
));
4354 if (is_32bit_elf
|| do_wide
)
4355 printf (" %-15.15s ",
4356 get_section_type_name (section
->sh_type
));
4359 printf ((do_wide
? " [%2u] %-17s %-15s "
4360 : " [%2u] %-17.17s %-15.15s "),
4362 SECTION_NAME (section
),
4363 get_section_type_name (section
->sh_type
));
4367 const char * link_too_big
= NULL
;
4369 print_vma (section
->sh_addr
, LONG_HEX
);
4371 printf ( " %6.6lx %6.6lx %2.2lx",
4372 (unsigned long) section
->sh_offset
,
4373 (unsigned long) section
->sh_size
,
4374 (unsigned long) section
->sh_entsize
);
4376 if (do_section_details
)
4377 fputs (" ", stdout
);
4379 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4381 if (section
->sh_link
>= elf_header
.e_shnum
)
4384 /* The sh_link value is out of range. Normally this indicates
4385 an error but it can have special values in SPARC binaries. */
4386 switch (elf_header
.e_machine
)
4388 case EM_OLD_SPARCV9
:
4389 case EM_SPARC32PLUS
:
4392 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
4393 link_too_big
= "BEFORE";
4394 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
4395 link_too_big
= "AFTER";
4402 if (do_section_details
)
4404 if (link_too_big
!= NULL
&& * link_too_big
)
4405 printf ("<%s> ", link_too_big
);
4407 printf ("%2u ", section
->sh_link
);
4408 printf ("%3u %2lu\n", section
->sh_info
,
4409 (unsigned long) section
->sh_addralign
);
4412 printf ("%2u %3u %2lu\n",
4415 (unsigned long) section
->sh_addralign
);
4417 if (link_too_big
&& ! * link_too_big
)
4418 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
4419 i
, section
->sh_link
);
4423 print_vma (section
->sh_addr
, LONG_HEX
);
4425 if ((long) section
->sh_offset
== section
->sh_offset
)
4426 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4430 print_vma (section
->sh_offset
, LONG_HEX
);
4433 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4434 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4438 print_vma (section
->sh_size
, LONG_HEX
);
4441 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4442 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4446 print_vma (section
->sh_entsize
, LONG_HEX
);
4449 if (do_section_details
)
4450 fputs (" ", stdout
);
4452 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4454 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
4456 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4457 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
4460 print_vma (section
->sh_addralign
, DEC
);
4464 else if (do_section_details
)
4466 printf (" %-15.15s ",
4467 get_section_type_name (section
->sh_type
));
4468 print_vma (section
->sh_addr
, LONG_HEX
);
4469 if ((long) section
->sh_offset
== section
->sh_offset
)
4470 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4474 print_vma (section
->sh_offset
, LONG_HEX
);
4476 printf (" %u\n ", section
->sh_link
);
4477 print_vma (section
->sh_size
, LONG_HEX
);
4479 print_vma (section
->sh_entsize
, LONG_HEX
);
4481 printf (" %-16u %lu\n",
4483 (unsigned long) section
->sh_addralign
);
4488 print_vma (section
->sh_addr
, LONG_HEX
);
4489 if ((long) section
->sh_offset
== section
->sh_offset
)
4490 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4494 print_vma (section
->sh_offset
, LONG_HEX
);
4497 print_vma (section
->sh_size
, LONG_HEX
);
4499 print_vma (section
->sh_entsize
, LONG_HEX
);
4501 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4503 printf (" %2u %3u %lu\n",
4506 (unsigned long) section
->sh_addralign
);
4509 if (do_section_details
)
4510 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4513 if (!do_section_details
)
4514 printf (_("Key to Flags:\n\
4515 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4516 I (info), L (link order), G (group), x (unknown)\n\
4517 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4523 get_group_flags (unsigned int flags
)
4525 static char buff
[32];
4532 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4539 process_section_groups (FILE * file
)
4541 Elf_Internal_Shdr
* section
;
4543 struct group
* group
;
4544 Elf_Internal_Shdr
* symtab_sec
;
4545 Elf_Internal_Shdr
* strtab_sec
;
4546 Elf_Internal_Sym
* symtab
;
4550 /* Don't process section groups unless needed. */
4551 if (!do_unwind
&& !do_section_groups
)
4554 if (elf_header
.e_shnum
== 0)
4556 if (do_section_groups
)
4557 printf (_("\nThere are no sections in this file.\n"));
4562 if (section_headers
== NULL
)
4564 error (_("Section headers are not available!\n"));
4568 section_headers_groups
= (struct group
**) calloc (elf_header
.e_shnum
,
4569 sizeof (struct group
*));
4571 if (section_headers_groups
== NULL
)
4573 error (_("Out of memory\n"));
4577 /* Scan the sections for the group section. */
4579 for (i
= 0, section
= section_headers
;
4580 i
< elf_header
.e_shnum
;
4582 if (section
->sh_type
== SHT_GROUP
)
4585 if (group_count
== 0)
4587 if (do_section_groups
)
4588 printf (_("\nThere are no section groups in this file.\n"));
4593 section_groups
= (struct group
*) calloc (group_count
, sizeof (struct group
));
4595 if (section_groups
== NULL
)
4597 error (_("Out of memory\n"));
4606 for (i
= 0, section
= section_headers
, group
= section_groups
;
4607 i
< elf_header
.e_shnum
;
4610 if (section
->sh_type
== SHT_GROUP
)
4612 char * name
= SECTION_NAME (section
);
4614 unsigned char * start
;
4615 unsigned char * indices
;
4616 unsigned int entry
, j
, size
;
4617 Elf_Internal_Shdr
* sec
;
4618 Elf_Internal_Sym
* sym
;
4620 /* Get the symbol table. */
4621 if (section
->sh_link
>= elf_header
.e_shnum
4622 || ((sec
= section_headers
+ section
->sh_link
)->sh_type
4625 error (_("Bad sh_link in group section `%s'\n"), name
);
4629 if (symtab_sec
!= sec
)
4634 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4637 sym
= symtab
+ section
->sh_info
;
4639 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4641 if (sym
->st_shndx
== 0
4642 || sym
->st_shndx
>= elf_header
.e_shnum
)
4644 error (_("Bad sh_info in group section `%s'\n"), name
);
4648 group_name
= SECTION_NAME (section_headers
+ sym
->st_shndx
);
4657 /* Get the string table. */
4658 if (symtab_sec
->sh_link
>= elf_header
.e_shnum
)
4667 != (sec
= section_headers
+ symtab_sec
->sh_link
))
4672 strtab
= (char *) get_data (NULL
, file
, strtab_sec
->sh_offset
,
4673 1, strtab_sec
->sh_size
,
4675 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4677 group_name
= sym
->st_name
< strtab_size
4678 ? strtab
+ sym
->st_name
: "<corrupt>";
4681 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
,
4682 1, section
->sh_size
,
4686 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4687 entry
= byte_get (indices
, 4);
4690 if (do_section_groups
)
4692 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4693 get_group_flags (entry
), i
, name
, group_name
, size
);
4695 printf (_(" [Index] Name\n"));
4698 group
->group_index
= i
;
4700 for (j
= 0; j
< size
; j
++)
4702 struct group_list
* g
;
4704 entry
= byte_get (indices
, 4);
4707 if (entry
>= elf_header
.e_shnum
)
4709 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4710 entry
, i
, elf_header
.e_shnum
- 1);
4714 if (section_headers_groups
[entry
] != NULL
)
4718 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4720 section_headers_groups
[entry
]->group_index
);
4725 /* Intel C/C++ compiler may put section 0 in a
4726 section group. We just warn it the first time
4727 and ignore it afterwards. */
4728 static int warned
= 0;
4731 error (_("section 0 in group section [%5u]\n"),
4732 section_headers_groups
[entry
]->group_index
);
4738 section_headers_groups
[entry
] = group
;
4740 if (do_section_groups
)
4742 sec
= section_headers
+ entry
;
4743 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4746 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
4747 g
->section_index
= entry
;
4748 g
->next
= group
->root
;
4772 } dynamic_relocations
[] =
4774 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4775 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4776 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4779 /* Process the reloc section. */
4782 process_relocs (FILE * file
)
4784 unsigned long rel_size
;
4785 unsigned long rel_offset
;
4791 if (do_using_dynamic
)
4795 int has_dynamic_reloc
;
4798 has_dynamic_reloc
= 0;
4800 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4802 is_rela
= dynamic_relocations
[i
].rela
;
4803 name
= dynamic_relocations
[i
].name
;
4804 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4805 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4807 has_dynamic_reloc
|= rel_size
;
4809 if (is_rela
== UNKNOWN
)
4811 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4812 switch (dynamic_info
[DT_PLTREL
])
4826 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4827 name
, rel_offset
, rel_size
);
4829 dump_relocations (file
,
4830 offset_from_vma (file
, rel_offset
, rel_size
),
4832 dynamic_symbols
, num_dynamic_syms
,
4833 dynamic_strings
, dynamic_strings_length
, is_rela
);
4837 if (! has_dynamic_reloc
)
4838 printf (_("\nThere are no dynamic relocations in this file.\n"));
4842 Elf_Internal_Shdr
* section
;
4846 for (i
= 0, section
= section_headers
;
4847 i
< elf_header
.e_shnum
;
4850 if ( section
->sh_type
!= SHT_RELA
4851 && section
->sh_type
!= SHT_REL
)
4854 rel_offset
= section
->sh_offset
;
4855 rel_size
= section
->sh_size
;
4859 Elf_Internal_Shdr
* strsec
;
4862 printf (_("\nRelocation section "));
4864 if (string_table
== NULL
)
4865 printf ("%d", section
->sh_name
);
4867 printf (_("'%s'"), SECTION_NAME (section
));
4869 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4870 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4872 is_rela
= section
->sh_type
== SHT_RELA
;
4874 if (section
->sh_link
!= 0
4875 && section
->sh_link
< elf_header
.e_shnum
)
4877 Elf_Internal_Shdr
* symsec
;
4878 Elf_Internal_Sym
* symtab
;
4879 unsigned long nsyms
;
4880 unsigned long strtablen
= 0;
4881 char * strtab
= NULL
;
4883 symsec
= section_headers
+ section
->sh_link
;
4884 if (symsec
->sh_type
!= SHT_SYMTAB
4885 && symsec
->sh_type
!= SHT_DYNSYM
)
4888 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4889 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4894 if (symsec
->sh_link
!= 0
4895 && symsec
->sh_link
< elf_header
.e_shnum
)
4897 strsec
= section_headers
+ symsec
->sh_link
;
4899 strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
4902 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4905 dump_relocations (file
, rel_offset
, rel_size
,
4906 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4912 dump_relocations (file
, rel_offset
, rel_size
,
4913 NULL
, 0, NULL
, 0, is_rela
);
4920 printf (_("\nThere are no relocations in this file.\n"));
4926 /* Process the unwind section. */
4928 #include "unwind-ia64.h"
4930 /* An absolute address consists of a section and an offset. If the
4931 section is NULL, the offset itself is the address, otherwise, the
4932 address equals to LOAD_ADDRESS(section) + offset. */
4936 unsigned short section
;
4940 #define ABSADDR(a) \
4942 ? section_headers [(a).section].sh_addr + (a).offset \
4945 struct ia64_unw_table_entry
4947 struct absaddr start
;
4949 struct absaddr info
;
4952 struct ia64_unw_aux_info
4955 struct ia64_unw_table_entry
*table
; /* Unwind table. */
4956 unsigned long table_len
; /* Length of unwind table. */
4957 unsigned char * info
; /* Unwind info. */
4958 unsigned long info_size
; /* Size of unwind info. */
4959 bfd_vma info_addr
; /* starting address of unwind info. */
4960 bfd_vma seg_base
; /* Starting address of segment. */
4961 Elf_Internal_Sym
* symtab
; /* The symbol table. */
4962 unsigned long nsyms
; /* Number of symbols. */
4963 char * strtab
; /* The string table. */
4964 unsigned long strtab_size
; /* Size of string table. */
4968 find_symbol_for_address (Elf_Internal_Sym
* symtab
,
4969 unsigned long nsyms
,
4970 const char * strtab
,
4971 unsigned long strtab_size
,
4972 struct absaddr addr
,
4973 const char ** symname
,
4976 bfd_vma dist
= 0x100000;
4977 Elf_Internal_Sym
* sym
;
4978 Elf_Internal_Sym
* best
= NULL
;
4981 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4983 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4984 && sym
->st_name
!= 0
4985 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4986 && addr
.offset
>= sym
->st_value
4987 && addr
.offset
- sym
->st_value
< dist
)
4990 dist
= addr
.offset
- sym
->st_value
;
4997 *symname
= (best
->st_name
>= strtab_size
4998 ? "<corrupt>" : strtab
+ best
->st_name
);
5003 *offset
= addr
.offset
;
5007 dump_ia64_unwind (struct ia64_unw_aux_info
* aux
)
5009 struct ia64_unw_table_entry
* tp
;
5012 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5016 const unsigned char * dp
;
5017 const unsigned char * head
;
5018 const char * procname
;
5020 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5021 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
5023 fputs ("\n<", stdout
);
5027 fputs (procname
, stdout
);
5030 printf ("+%lx", (unsigned long) offset
);
5033 fputs (">: [", stdout
);
5034 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5035 fputc ('-', stdout
);
5036 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5037 printf ("], info at +0x%lx\n",
5038 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
5040 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
5041 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
5043 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
5044 (unsigned) UNW_VER (stamp
),
5045 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
5046 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
5047 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
5048 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
5050 if (UNW_VER (stamp
) != 1)
5052 printf ("\tUnknown version.\n");
5057 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
5058 dp
= unw_decode (dp
, in_body
, & in_body
);
5063 slurp_ia64_unwind_table (FILE * file
,
5064 struct ia64_unw_aux_info
* aux
,
5065 Elf_Internal_Shdr
* sec
)
5067 unsigned long size
, nrelas
, i
;
5068 Elf_Internal_Phdr
* seg
;
5069 struct ia64_unw_table_entry
* tep
;
5070 Elf_Internal_Shdr
* relsec
;
5071 Elf_Internal_Rela
* rela
;
5072 Elf_Internal_Rela
* rp
;
5073 unsigned char * table
;
5075 Elf_Internal_Sym
* sym
;
5076 const char * relname
;
5078 /* First, find the starting address of the segment that includes
5081 if (elf_header
.e_phnum
)
5083 if (! get_program_headers (file
))
5086 for (seg
= program_headers
;
5087 seg
< program_headers
+ elf_header
.e_phnum
;
5090 if (seg
->p_type
!= PT_LOAD
)
5093 if (sec
->sh_addr
>= seg
->p_vaddr
5094 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5096 aux
->seg_base
= seg
->p_vaddr
;
5102 /* Second, build the unwind table from the contents of the unwind section: */
5103 size
= sec
->sh_size
;
5104 table
= (unsigned char *) get_data (NULL
, file
, sec
->sh_offset
, 1, size
,
5109 aux
->table
= (struct ia64_unw_table_entry
*)
5110 xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
5112 for (tp
= table
; tp
< table
+ size
; ++tep
)
5114 tep
->start
.section
= SHN_UNDEF
;
5115 tep
->end
.section
= SHN_UNDEF
;
5116 tep
->info
.section
= SHN_UNDEF
;
5117 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5118 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5119 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5120 tep
->start
.offset
+= aux
->seg_base
;
5121 tep
->end
.offset
+= aux
->seg_base
;
5122 tep
->info
.offset
+= aux
->seg_base
;
5126 /* Third, apply any relocations to the unwind table: */
5127 for (relsec
= section_headers
;
5128 relsec
< section_headers
+ elf_header
.e_shnum
;
5131 if (relsec
->sh_type
!= SHT_RELA
5132 || relsec
->sh_info
>= elf_header
.e_shnum
5133 || section_headers
+ relsec
->sh_info
!= sec
)
5136 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5140 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5142 relname
= elf_ia64_reloc_type (get_reloc_type (rp
->r_info
));
5143 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5145 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5147 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5151 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5153 switch (rp
->r_offset
/eh_addr_size
% 3)
5156 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5157 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5160 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5161 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5164 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5165 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5175 aux
->table_len
= size
/ (3 * eh_addr_size
);
5180 ia64_process_unwind (FILE * file
)
5182 Elf_Internal_Shdr
* sec
;
5183 Elf_Internal_Shdr
* unwsec
= NULL
;
5184 Elf_Internal_Shdr
* strsec
;
5185 unsigned long i
, unwcount
= 0, unwstart
= 0;
5186 struct ia64_unw_aux_info aux
;
5188 memset (& aux
, 0, sizeof (aux
));
5190 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5192 if (sec
->sh_type
== SHT_SYMTAB
5193 && sec
->sh_link
< elf_header
.e_shnum
)
5195 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5196 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5198 strsec
= section_headers
+ sec
->sh_link
;
5199 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
5202 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5204 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5209 printf (_("\nThere are no unwind sections in this file.\n"));
5211 while (unwcount
-- > 0)
5216 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5217 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5218 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5225 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5227 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5229 /* We need to find which section group it is in. */
5230 struct group_list
* g
= section_headers_groups
[i
]->root
;
5232 for (; g
!= NULL
; g
= g
->next
)
5234 sec
= section_headers
+ g
->section_index
;
5236 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5241 i
= elf_header
.e_shnum
;
5243 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5245 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5246 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5247 suffix
= SECTION_NAME (unwsec
) + len
;
5248 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5250 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5251 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5256 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5257 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5258 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5259 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5261 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5262 suffix
= SECTION_NAME (unwsec
) + len
;
5263 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5265 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5266 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5270 if (i
== elf_header
.e_shnum
)
5272 printf (_("\nCould not find unwind info section for "));
5274 if (string_table
== NULL
)
5275 printf ("%d", unwsec
->sh_name
);
5277 printf (_("'%s'"), SECTION_NAME (unwsec
));
5281 aux
.info_size
= sec
->sh_size
;
5282 aux
.info_addr
= sec
->sh_addr
;
5283 aux
.info
= (unsigned char *) get_data (NULL
, file
, sec
->sh_offset
, 1,
5287 printf (_("\nUnwind section "));
5289 if (string_table
== NULL
)
5290 printf ("%d", unwsec
->sh_name
);
5292 printf (_("'%s'"), SECTION_NAME (unwsec
));
5294 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5295 (unsigned long) unwsec
->sh_offset
,
5296 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5298 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5300 if (aux
.table_len
> 0)
5301 dump_ia64_unwind (& aux
);
5304 free ((char *) aux
.table
);
5306 free ((char *) aux
.info
);
5315 free ((char *) aux
.strtab
);
5320 struct hppa_unw_table_entry
5322 struct absaddr start
;
5324 unsigned int Cannot_unwind
:1; /* 0 */
5325 unsigned int Millicode
:1; /* 1 */
5326 unsigned int Millicode_save_sr0
:1; /* 2 */
5327 unsigned int Region_description
:2; /* 3..4 */
5328 unsigned int reserved1
:1; /* 5 */
5329 unsigned int Entry_SR
:1; /* 6 */
5330 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5331 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5332 unsigned int Args_stored
:1; /* 16 */
5333 unsigned int Variable_Frame
:1; /* 17 */
5334 unsigned int Separate_Package_Body
:1; /* 18 */
5335 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5336 unsigned int Stack_Overflow_Check
:1; /* 20 */
5337 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5338 unsigned int Ada_Region
:1; /* 22 */
5339 unsigned int cxx_info
:1; /* 23 */
5340 unsigned int cxx_try_catch
:1; /* 24 */
5341 unsigned int sched_entry_seq
:1; /* 25 */
5342 unsigned int reserved2
:1; /* 26 */
5343 unsigned int Save_SP
:1; /* 27 */
5344 unsigned int Save_RP
:1; /* 28 */
5345 unsigned int Save_MRP_in_frame
:1; /* 29 */
5346 unsigned int extn_ptr_defined
:1; /* 30 */
5347 unsigned int Cleanup_defined
:1; /* 31 */
5349 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5350 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5351 unsigned int Large_frame
:1; /* 2 */
5352 unsigned int Pseudo_SP_Set
:1; /* 3 */
5353 unsigned int reserved4
:1; /* 4 */
5354 unsigned int Total_frame_size
:27; /* 5..31 */
5357 struct hppa_unw_aux_info
5359 struct hppa_unw_table_entry
*table
; /* Unwind table. */
5360 unsigned long table_len
; /* Length of unwind table. */
5361 bfd_vma seg_base
; /* Starting address of segment. */
5362 Elf_Internal_Sym
* symtab
; /* The symbol table. */
5363 unsigned long nsyms
; /* Number of symbols. */
5364 char * strtab
; /* The string table. */
5365 unsigned long strtab_size
; /* Size of string table. */
5369 dump_hppa_unwind (struct hppa_unw_aux_info
* aux
)
5371 struct hppa_unw_table_entry
* tp
;
5373 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5376 const char * procname
;
5378 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5379 aux
->strtab_size
, tp
->start
, &procname
,
5382 fputs ("\n<", stdout
);
5386 fputs (procname
, stdout
);
5389 printf ("+%lx", (unsigned long) offset
);
5392 fputs (">: [", stdout
);
5393 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5394 fputc ('-', stdout
);
5395 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5398 #define PF(_m) if (tp->_m) printf (#_m " ");
5399 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5402 PF(Millicode_save_sr0
);
5403 /* PV(Region_description); */
5409 PF(Separate_Package_Body
);
5410 PF(Frame_Extension_Millicode
);
5411 PF(Stack_Overflow_Check
);
5412 PF(Two_Instruction_SP_Increment
);
5416 PF(sched_entry_seq
);
5419 PF(Save_MRP_in_frame
);
5420 PF(extn_ptr_defined
);
5421 PF(Cleanup_defined
);
5422 PF(MPE_XL_interrupt_marker
);
5423 PF(HP_UX_interrupt_marker
);
5426 PV(Total_frame_size
);
5435 slurp_hppa_unwind_table (FILE * file
,
5436 struct hppa_unw_aux_info
* aux
,
5437 Elf_Internal_Shdr
* sec
)
5439 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5440 Elf_Internal_Phdr
* seg
;
5441 struct hppa_unw_table_entry
* tep
;
5442 Elf_Internal_Shdr
* relsec
;
5443 Elf_Internal_Rela
* rela
;
5444 Elf_Internal_Rela
* rp
;
5445 unsigned char * table
;
5447 Elf_Internal_Sym
* sym
;
5448 const char * relname
;
5450 /* First, find the starting address of the segment that includes
5453 if (elf_header
.e_phnum
)
5455 if (! get_program_headers (file
))
5458 for (seg
= program_headers
;
5459 seg
< program_headers
+ elf_header
.e_phnum
;
5462 if (seg
->p_type
!= PT_LOAD
)
5465 if (sec
->sh_addr
>= seg
->p_vaddr
5466 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5468 aux
->seg_base
= seg
->p_vaddr
;
5474 /* Second, build the unwind table from the contents of the unwind
5476 size
= sec
->sh_size
;
5477 table
= (unsigned char *) get_data (NULL
, file
, sec
->sh_offset
, 1, size
,
5483 nentries
= size
/ unw_ent_size
;
5484 size
= unw_ent_size
* nentries
;
5486 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
5487 xcmalloc (nentries
, sizeof (aux
->table
[0]));
5489 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5491 unsigned int tmp1
, tmp2
;
5493 tep
->start
.section
= SHN_UNDEF
;
5494 tep
->end
.section
= SHN_UNDEF
;
5496 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5497 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5498 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5499 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5501 tep
->start
.offset
+= aux
->seg_base
;
5502 tep
->end
.offset
+= aux
->seg_base
;
5504 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5505 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5506 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5507 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5508 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5509 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5510 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5511 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5512 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5513 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5514 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5515 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5516 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5517 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5518 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5519 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5520 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5521 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5522 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5523 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5524 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5525 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5526 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5527 tep
->Cleanup_defined
= tmp1
& 0x1;
5529 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5530 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5531 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5532 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5533 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5534 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5538 /* Third, apply any relocations to the unwind table. */
5539 for (relsec
= section_headers
;
5540 relsec
< section_headers
+ elf_header
.e_shnum
;
5543 if (relsec
->sh_type
!= SHT_RELA
5544 || relsec
->sh_info
>= elf_header
.e_shnum
5545 || section_headers
+ relsec
->sh_info
!= sec
)
5548 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5552 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5554 relname
= elf_hppa_reloc_type (get_reloc_type (rp
->r_info
));
5555 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5557 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5558 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5560 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5564 i
= rp
->r_offset
/ unw_ent_size
;
5566 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5569 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5570 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5573 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5574 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5584 aux
->table_len
= nentries
;
5590 hppa_process_unwind (FILE * file
)
5592 struct hppa_unw_aux_info aux
;
5593 Elf_Internal_Shdr
* unwsec
= NULL
;
5594 Elf_Internal_Shdr
* strsec
;
5595 Elf_Internal_Shdr
* sec
;
5598 memset (& aux
, 0, sizeof (aux
));
5600 if (string_table
== NULL
)
5603 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5605 if (sec
->sh_type
== SHT_SYMTAB
5606 && sec
->sh_link
< elf_header
.e_shnum
)
5608 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5609 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5611 strsec
= section_headers
+ sec
->sh_link
;
5612 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
5615 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5617 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5622 printf (_("\nThere are no unwind sections in this file.\n"));
5624 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5626 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5628 printf (_("\nUnwind section "));
5629 printf (_("'%s'"), SECTION_NAME (sec
));
5631 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5632 (unsigned long) sec
->sh_offset
,
5633 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5635 slurp_hppa_unwind_table (file
, &aux
, sec
);
5636 if (aux
.table_len
> 0)
5637 dump_hppa_unwind (&aux
);
5640 free ((char *) aux
.table
);
5648 free ((char *) aux
.strtab
);
5654 process_unwind (FILE * file
)
5656 struct unwind_handler
5659 int (* handler
)(FILE *);
5662 { EM_IA_64
, ia64_process_unwind
},
5663 { EM_PARISC
, hppa_process_unwind
},
5671 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5672 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5673 return handlers
[i
].handler (file
);
5675 printf (_("\nThere are no unwind sections in this file.\n"));
5680 dynamic_section_mips_val (Elf_Internal_Dyn
* entry
)
5682 switch (entry
->d_tag
)
5685 if (entry
->d_un
.d_val
== 0)
5689 static const char * opts
[] =
5691 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5692 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5693 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5694 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5699 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
5700 if (entry
->d_un
.d_val
& (1 << cnt
))
5702 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5709 case DT_MIPS_IVERSION
:
5710 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5711 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5713 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5716 case DT_MIPS_TIME_STAMP
:
5721 time_t time
= entry
->d_un
.d_val
;
5722 tmp
= gmtime (&time
);
5723 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5724 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5725 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5726 printf ("Time Stamp: %s\n", timebuf
);
5730 case DT_MIPS_RLD_VERSION
:
5731 case DT_MIPS_LOCAL_GOTNO
:
5732 case DT_MIPS_CONFLICTNO
:
5733 case DT_MIPS_LIBLISTNO
:
5734 case DT_MIPS_SYMTABNO
:
5735 case DT_MIPS_UNREFEXTNO
:
5736 case DT_MIPS_HIPAGENO
:
5737 case DT_MIPS_DELTA_CLASS_NO
:
5738 case DT_MIPS_DELTA_INSTANCE_NO
:
5739 case DT_MIPS_DELTA_RELOC_NO
:
5740 case DT_MIPS_DELTA_SYM_NO
:
5741 case DT_MIPS_DELTA_CLASSSYM_NO
:
5742 case DT_MIPS_COMPACT_SIZE
:
5743 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5747 printf ("%#lx\n", (unsigned long) entry
->d_un
.d_ptr
);
5753 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
5755 switch (entry
->d_tag
)
5757 case DT_HP_DLD_FLAGS
:
5766 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5767 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5768 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5769 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5770 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5771 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5772 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5773 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5774 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5775 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5776 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5777 { DT_HP_GST
, "HP_GST" },
5778 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5779 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5780 { DT_HP_NODELETE
, "HP_NODELETE" },
5781 { DT_HP_GROUP
, "HP_GROUP" },
5782 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5786 bfd_vma val
= entry
->d_un
.d_val
;
5788 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
5789 if (val
& flags
[cnt
].bit
)
5793 fputs (flags
[cnt
].str
, stdout
);
5795 val
^= flags
[cnt
].bit
;
5798 if (val
!= 0 || first
)
5802 print_vma (val
, HEX
);
5808 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5815 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
5817 switch (entry
->d_tag
)
5819 case DT_IA_64_PLT_RESERVE
:
5820 /* First 3 slots reserved. */
5821 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5823 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5827 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5834 get_32bit_dynamic_section (FILE * file
)
5836 Elf32_External_Dyn
* edyn
;
5837 Elf32_External_Dyn
* ext
;
5838 Elf_Internal_Dyn
* entry
;
5840 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
, 1,
5841 dynamic_size
, _("dynamic section"));
5845 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5846 might not have the luxury of section headers. Look for the DT_NULL
5847 terminator to determine the number of entries. */
5848 for (ext
= edyn
, dynamic_nent
= 0;
5849 (char *) ext
< (char *) edyn
+ dynamic_size
;
5853 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5857 dynamic_section
= (Elf_Internal_Dyn
*) cmalloc (dynamic_nent
,
5859 if (dynamic_section
== NULL
)
5861 error (_("Out of memory\n"));
5866 for (ext
= edyn
, entry
= dynamic_section
;
5867 entry
< dynamic_section
+ dynamic_nent
;
5870 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5871 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5880 get_64bit_dynamic_section (FILE * file
)
5882 Elf64_External_Dyn
* edyn
;
5883 Elf64_External_Dyn
* ext
;
5884 Elf_Internal_Dyn
* entry
;
5886 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
, 1,
5887 dynamic_size
, _("dynamic section"));
5891 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5892 might not have the luxury of section headers. Look for the DT_NULL
5893 terminator to determine the number of entries. */
5894 for (ext
= edyn
, dynamic_nent
= 0;
5895 (char *) ext
< (char *) edyn
+ dynamic_size
;
5899 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5903 dynamic_section
= (Elf_Internal_Dyn
*) cmalloc (dynamic_nent
,
5905 if (dynamic_section
== NULL
)
5907 error (_("Out of memory\n"));
5912 for (ext
= edyn
, entry
= dynamic_section
;
5913 entry
< dynamic_section
+ dynamic_nent
;
5916 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5917 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5926 print_dynamic_flags (bfd_vma flags
)
5934 flag
= flags
& - flags
;
5944 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5945 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5946 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5947 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5948 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5949 default: fputs ("unknown", stdout
); break;
5955 /* Parse and display the contents of the dynamic section. */
5958 process_dynamic_section (FILE * file
)
5960 Elf_Internal_Dyn
* entry
;
5962 if (dynamic_size
== 0)
5965 printf (_("\nThere is no dynamic section in this file.\n"));
5972 if (! get_32bit_dynamic_section (file
))
5975 else if (! get_64bit_dynamic_section (file
))
5978 /* Find the appropriate symbol table. */
5979 if (dynamic_symbols
== NULL
)
5981 for (entry
= dynamic_section
;
5982 entry
< dynamic_section
+ dynamic_nent
;
5985 Elf_Internal_Shdr section
;
5987 if (entry
->d_tag
!= DT_SYMTAB
)
5990 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5992 /* Since we do not know how big the symbol table is,
5993 we default to reading in the entire file (!) and
5994 processing that. This is overkill, I know, but it
5996 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5998 if (archive_file_offset
!= 0)
5999 section
.sh_size
= archive_file_size
- section
.sh_offset
;
6002 if (fseek (file
, 0, SEEK_END
))
6003 error (_("Unable to seek to end of file!\n"));
6005 section
.sh_size
= ftell (file
) - section
.sh_offset
;
6009 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
6011 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
6013 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
6014 if (num_dynamic_syms
< 1)
6016 error (_("Unable to determine the number of symbols to load\n"));
6020 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
6024 /* Similarly find a string table. */
6025 if (dynamic_strings
== NULL
)
6027 for (entry
= dynamic_section
;
6028 entry
< dynamic_section
+ dynamic_nent
;
6031 unsigned long offset
;
6034 if (entry
->d_tag
!= DT_STRTAB
)
6037 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
6039 /* Since we do not know how big the string table is,
6040 we default to reading in the entire file (!) and
6041 processing that. This is overkill, I know, but it
6044 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
6046 if (archive_file_offset
!= 0)
6047 str_tab_len
= archive_file_size
- offset
;
6050 if (fseek (file
, 0, SEEK_END
))
6051 error (_("Unable to seek to end of file\n"));
6052 str_tab_len
= ftell (file
) - offset
;
6055 if (str_tab_len
< 1)
6058 (_("Unable to determine the length of the dynamic string table\n"));
6062 dynamic_strings
= (char *) get_data (NULL
, file
, offset
, 1,
6064 _("dynamic string table"));
6065 dynamic_strings_length
= str_tab_len
;
6070 /* And find the syminfo section if available. */
6071 if (dynamic_syminfo
== NULL
)
6073 unsigned long syminsz
= 0;
6075 for (entry
= dynamic_section
;
6076 entry
< dynamic_section
+ dynamic_nent
;
6079 if (entry
->d_tag
== DT_SYMINENT
)
6081 /* Note: these braces are necessary to avoid a syntax
6082 error from the SunOS4 C compiler. */
6083 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
6085 else if (entry
->d_tag
== DT_SYMINSZ
)
6086 syminsz
= entry
->d_un
.d_val
;
6087 else if (entry
->d_tag
== DT_SYMINFO
)
6088 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
6092 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
6094 Elf_External_Syminfo
* extsyminfo
;
6095 Elf_External_Syminfo
* extsym
;
6096 Elf_Internal_Syminfo
* syminfo
;
6098 /* There is a syminfo section. Read the data. */
6099 extsyminfo
= (Elf_External_Syminfo
*)
6100 get_data (NULL
, file
, dynamic_syminfo_offset
, 1, syminsz
,
6101 _("symbol information"));
6105 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
6106 if (dynamic_syminfo
== NULL
)
6108 error (_("Out of memory\n"));
6112 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
6113 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
6114 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
6115 ++syminfo
, ++extsym
)
6117 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
6118 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
6125 if (do_dynamic
&& dynamic_addr
)
6126 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
6127 dynamic_addr
, dynamic_nent
);
6129 printf (_(" Tag Type Name/Value\n"));
6131 for (entry
= dynamic_section
;
6132 entry
< dynamic_section
+ dynamic_nent
;
6140 print_vma (entry
->d_tag
, FULL_HEX
);
6141 dtype
= get_dynamic_type (entry
->d_tag
);
6142 printf (" (%s)%*s", dtype
,
6143 ((is_32bit_elf
? 27 : 19)
6144 - (int) strlen (dtype
)),
6148 switch (entry
->d_tag
)
6152 print_dynamic_flags (entry
->d_un
.d_val
);
6162 switch (entry
->d_tag
)
6165 printf (_("Auxiliary library"));
6169 printf (_("Filter library"));
6173 printf (_("Configuration file"));
6177 printf (_("Dependency audit library"));
6181 printf (_("Audit library"));
6185 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6186 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6190 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6199 printf (_("Flags:"));
6201 if (entry
->d_un
.d_val
== 0)
6202 printf (_(" None\n"));
6205 unsigned long int val
= entry
->d_un
.d_val
;
6207 if (val
& DTF_1_PARINIT
)
6209 printf (" PARINIT");
6210 val
^= DTF_1_PARINIT
;
6212 if (val
& DTF_1_CONFEXP
)
6214 printf (" CONFEXP");
6215 val
^= DTF_1_CONFEXP
;
6218 printf (" %lx", val
);
6227 printf (_("Flags:"));
6229 if (entry
->d_un
.d_val
== 0)
6230 printf (_(" None\n"));
6233 unsigned long int val
= entry
->d_un
.d_val
;
6235 if (val
& DF_P1_LAZYLOAD
)
6237 printf (" LAZYLOAD");
6238 val
^= DF_P1_LAZYLOAD
;
6240 if (val
& DF_P1_GROUPPERM
)
6242 printf (" GROUPPERM");
6243 val
^= DF_P1_GROUPPERM
;
6246 printf (" %lx", val
);
6255 printf (_("Flags:"));
6256 if (entry
->d_un
.d_val
== 0)
6257 printf (_(" None\n"));
6260 unsigned long int val
= entry
->d_un
.d_val
;
6267 if (val
& DF_1_GLOBAL
)
6272 if (val
& DF_1_GROUP
)
6277 if (val
& DF_1_NODELETE
)
6279 printf (" NODELETE");
6280 val
^= DF_1_NODELETE
;
6282 if (val
& DF_1_LOADFLTR
)
6284 printf (" LOADFLTR");
6285 val
^= DF_1_LOADFLTR
;
6287 if (val
& DF_1_INITFIRST
)
6289 printf (" INITFIRST");
6290 val
^= DF_1_INITFIRST
;
6292 if (val
& DF_1_NOOPEN
)
6297 if (val
& DF_1_ORIGIN
)
6302 if (val
& DF_1_DIRECT
)
6307 if (val
& DF_1_TRANS
)
6312 if (val
& DF_1_INTERPOSE
)
6314 printf (" INTERPOSE");
6315 val
^= DF_1_INTERPOSE
;
6317 if (val
& DF_1_NODEFLIB
)
6319 printf (" NODEFLIB");
6320 val
^= DF_1_NODEFLIB
;
6322 if (val
& DF_1_NODUMP
)
6327 if (val
& DF_1_CONLFAT
)
6329 printf (" CONLFAT");
6330 val
^= DF_1_CONLFAT
;
6333 printf (" %lx", val
);
6340 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6342 puts (get_dynamic_type (entry
->d_un
.d_val
));
6362 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6368 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6369 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6375 switch (entry
->d_tag
)
6378 printf (_("Shared library: [%s]"), name
);
6380 if (streq (name
, program_interpreter
))
6381 printf (_(" program interpreter"));
6385 printf (_("Library soname: [%s]"), name
);
6389 printf (_("Library rpath: [%s]"), name
);
6393 printf (_("Library runpath: [%s]"), name
);
6397 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6402 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6415 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6419 case DT_INIT_ARRAYSZ
:
6420 case DT_FINI_ARRAYSZ
:
6421 case DT_GNU_CONFLICTSZ
:
6422 case DT_GNU_LIBLISTSZ
:
6425 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6426 printf (" (bytes)\n");
6436 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6449 if (entry
->d_tag
== DT_USED
6450 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6452 char * name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6456 printf (_("Not needed object: [%s]\n"), name
);
6461 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6467 /* The value of this entry is ignored. */
6472 case DT_GNU_PRELINKED
:
6476 time_t time
= entry
->d_un
.d_val
;
6478 tmp
= gmtime (&time
);
6479 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6480 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6481 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6487 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
6490 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6496 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6497 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6502 switch (elf_header
.e_machine
)
6505 case EM_MIPS_RS3_LE
:
6506 dynamic_section_mips_val (entry
);
6509 dynamic_section_parisc_val (entry
);
6512 dynamic_section_ia64_val (entry
);
6515 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6527 get_ver_flags (unsigned int flags
)
6529 static char buff
[32];
6536 if (flags
& VER_FLG_BASE
)
6537 strcat (buff
, "BASE ");
6539 if (flags
& VER_FLG_WEAK
)
6541 if (flags
& VER_FLG_BASE
)
6542 strcat (buff
, "| ");
6544 strcat (buff
, "WEAK ");
6547 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6548 strcat (buff
, "| <unknown>");
6553 /* Display the contents of the version sections. */
6556 process_version_sections (FILE * file
)
6558 Elf_Internal_Shdr
* section
;
6565 for (i
= 0, section
= section_headers
;
6566 i
< elf_header
.e_shnum
;
6569 switch (section
->sh_type
)
6571 case SHT_GNU_verdef
:
6573 Elf_External_Verdef
* edefs
;
6581 (_("\nVersion definition section '%s' contains %u entries:\n"),
6582 SECTION_NAME (section
), section
->sh_info
);
6584 printf (_(" Addr: 0x"));
6585 printf_vma (section
->sh_addr
);
6586 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6587 (unsigned long) section
->sh_offset
, section
->sh_link
,
6588 section
->sh_link
< elf_header
.e_shnum
6589 ? SECTION_NAME (section_headers
+ section
->sh_link
)
6592 edefs
= (Elf_External_Verdef
*)
6593 get_data (NULL
, file
, section
->sh_offset
, 1,section
->sh_size
,
6594 _("version definition section"));
6595 endbuf
= (char *) edefs
+ section
->sh_size
;
6599 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6602 Elf_External_Verdef
* edef
;
6603 Elf_Internal_Verdef ent
;
6604 Elf_External_Verdaux
* eaux
;
6605 Elf_Internal_Verdaux aux
;
6609 vstart
= ((char *) edefs
) + idx
;
6610 if (vstart
+ sizeof (*edef
) > endbuf
)
6613 edef
= (Elf_External_Verdef
*) vstart
;
6615 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6616 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6617 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6618 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6619 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6620 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6621 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6623 printf (_(" %#06x: Rev: %d Flags: %s"),
6624 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6626 printf (_(" Index: %d Cnt: %d "),
6627 ent
.vd_ndx
, ent
.vd_cnt
);
6629 vstart
+= ent
.vd_aux
;
6631 eaux
= (Elf_External_Verdaux
*) vstart
;
6633 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6634 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6636 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6637 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6639 printf (_("Name index: %ld\n"), aux
.vda_name
);
6641 isum
= idx
+ ent
.vd_aux
;
6643 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6645 isum
+= aux
.vda_next
;
6646 vstart
+= aux
.vda_next
;
6648 eaux
= (Elf_External_Verdaux
*) vstart
;
6649 if (vstart
+ sizeof (*eaux
) > endbuf
)
6652 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6653 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6655 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6656 printf (_(" %#06x: Parent %d: %s\n"),
6657 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6659 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6660 isum
, j
, aux
.vda_name
);
6663 printf (_(" Version def aux past end of section\n"));
6667 if (cnt
< section
->sh_info
)
6668 printf (_(" Version definition past end of section\n"));
6674 case SHT_GNU_verneed
:
6676 Elf_External_Verneed
* eneed
;
6683 printf (_("\nVersion needs section '%s' contains %u entries:\n"),
6684 SECTION_NAME (section
), section
->sh_info
);
6686 printf (_(" Addr: 0x"));
6687 printf_vma (section
->sh_addr
);
6688 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6689 (unsigned long) section
->sh_offset
, section
->sh_link
,
6690 section
->sh_link
< elf_header
.e_shnum
6691 ? SECTION_NAME (section_headers
+ section
->sh_link
)
6694 eneed
= (Elf_External_Verneed
*) get_data (NULL
, file
,
6695 section
->sh_offset
, 1,
6697 _("version need section"));
6698 endbuf
= (char *) eneed
+ section
->sh_size
;
6702 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6704 Elf_External_Verneed
* entry
;
6705 Elf_Internal_Verneed ent
;
6710 vstart
= ((char *) eneed
) + idx
;
6711 if (vstart
+ sizeof (*entry
) > endbuf
)
6714 entry
= (Elf_External_Verneed
*) vstart
;
6716 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6717 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6718 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6719 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6720 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6722 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6724 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6725 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6727 printf (_(" File: %lx"), ent
.vn_file
);
6729 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6731 vstart
+= ent
.vn_aux
;
6733 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6735 Elf_External_Vernaux
* eaux
;
6736 Elf_Internal_Vernaux aux
;
6738 if (vstart
+ sizeof (*eaux
) > endbuf
)
6740 eaux
= (Elf_External_Vernaux
*) vstart
;
6742 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6743 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6744 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6745 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6746 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6748 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6749 printf (_(" %#06x: Name: %s"),
6750 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6752 printf (_(" %#06x: Name index: %lx"),
6753 isum
, aux
.vna_name
);
6755 printf (_(" Flags: %s Version: %d\n"),
6756 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6758 isum
+= aux
.vna_next
;
6759 vstart
+= aux
.vna_next
;
6762 printf (_(" Version need aux past end of section\n"));
6766 if (cnt
< section
->sh_info
)
6767 printf (_(" Version need past end of section\n"));
6773 case SHT_GNU_versym
:
6775 Elf_Internal_Shdr
* link_section
;
6778 unsigned char * edata
;
6779 unsigned short * data
;
6781 Elf_Internal_Sym
* symbols
;
6782 Elf_Internal_Shdr
* string_sec
;
6785 if (section
->sh_link
>= elf_header
.e_shnum
)
6788 link_section
= section_headers
+ section
->sh_link
;
6789 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6791 if (link_section
->sh_link
>= elf_header
.e_shnum
)
6796 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6798 string_sec
= section_headers
+ link_section
->sh_link
;
6800 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6801 string_sec
->sh_size
,
6802 _("version string table"));
6806 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6807 SECTION_NAME (section
), total
);
6809 printf (_(" Addr: "));
6810 printf_vma (section
->sh_addr
);
6811 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
6812 (unsigned long) section
->sh_offset
, section
->sh_link
,
6813 SECTION_NAME (link_section
));
6815 off
= offset_from_vma (file
,
6816 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6817 total
* sizeof (short));
6818 edata
= (unsigned char *) get_data (NULL
, file
, off
, total
,
6820 _("version symbol data"));
6827 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
6829 for (cnt
= total
; cnt
--;)
6830 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6835 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6838 int check_def
, check_need
;
6841 printf (" %03x:", cnt
);
6843 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6844 switch (data
[cnt
+ j
])
6847 fputs (_(" 0 (*local*) "), stdout
);
6851 fputs (_(" 1 (*global*) "), stdout
);
6855 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
6856 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
6860 if (symbols
[cnt
+ j
].st_shndx
>= elf_header
.e_shnum
6861 || section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
6864 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6871 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6873 Elf_Internal_Verneed ivn
;
6874 unsigned long offset
;
6876 offset
= offset_from_vma
6877 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6878 sizeof (Elf_External_Verneed
));
6882 Elf_Internal_Vernaux ivna
;
6883 Elf_External_Verneed evn
;
6884 Elf_External_Vernaux evna
;
6885 unsigned long a_off
;
6887 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6890 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6891 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6893 a_off
= offset
+ ivn
.vn_aux
;
6897 get_data (&evna
, file
, a_off
, sizeof (evna
),
6898 1, _("version need aux (2)"));
6900 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6901 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6903 a_off
+= ivna
.vna_next
;
6905 while (ivna
.vna_other
!= data
[cnt
+ j
]
6906 && ivna
.vna_next
!= 0);
6908 if (ivna
.vna_other
== data
[cnt
+ j
])
6910 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6912 if (ivna
.vna_name
>= string_sec
->sh_size
)
6913 name
= _("*invalid*");
6915 name
= strtab
+ ivna
.vna_name
;
6916 nn
+= printf ("(%s%-*s",
6918 12 - (int) strlen (name
),
6924 offset
+= ivn
.vn_next
;
6926 while (ivn
.vn_next
);
6929 if (check_def
&& data
[cnt
+ j
] != 0x8001
6930 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6932 Elf_Internal_Verdef ivd
;
6933 Elf_External_Verdef evd
;
6934 unsigned long offset
;
6936 offset
= offset_from_vma
6937 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6942 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6945 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6946 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6948 offset
+= ivd
.vd_next
;
6950 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
6951 && ivd
.vd_next
!= 0);
6953 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
6955 Elf_External_Verdaux evda
;
6956 Elf_Internal_Verdaux ivda
;
6958 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6960 get_data (&evda
, file
,
6961 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6963 _("version def aux"));
6965 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6967 if (ivda
.vda_name
>= string_sec
->sh_size
)
6968 name
= _("*invalid*");
6970 name
= strtab
+ ivda
.vda_name
;
6971 nn
+= printf ("(%s%-*s",
6973 12 - (int) strlen (name
),
6979 printf ("%*c", 18 - nn
, ' ');
6997 printf (_("\nNo version information found in this file.\n"));
7003 get_symbol_binding (unsigned int binding
)
7005 static char buff
[32];
7009 case STB_LOCAL
: return "LOCAL";
7010 case STB_GLOBAL
: return "GLOBAL";
7011 case STB_WEAK
: return "WEAK";
7013 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
7014 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
7016 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
7018 if (binding
== STB_GNU_UNIQUE
7019 && (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_LINUX
7020 /* GNU/Linux is still using the default value 0. */
7021 || elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
))
7023 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
7026 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
7032 get_symbol_type (unsigned int type
)
7034 static char buff
[32];
7038 case STT_NOTYPE
: return "NOTYPE";
7039 case STT_OBJECT
: return "OBJECT";
7040 case STT_FUNC
: return "FUNC";
7041 case STT_SECTION
: return "SECTION";
7042 case STT_FILE
: return "FILE";
7043 case STT_COMMON
: return "COMMON";
7044 case STT_TLS
: return "TLS";
7045 case STT_RELC
: return "RELC";
7046 case STT_SRELC
: return "SRELC";
7048 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
7050 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
7051 return "THUMB_FUNC";
7053 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
7056 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
7057 return "PARISC_MILLI";
7059 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
7061 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
7063 if (elf_header
.e_machine
== EM_PARISC
)
7065 if (type
== STT_HP_OPAQUE
)
7067 if (type
== STT_HP_STUB
)
7071 if (type
== STT_GNU_IFUNC
7072 && (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_LINUX
7073 /* GNU/Linux is still using the default value 0. */
7074 || elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
))
7077 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
7080 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
7086 get_symbol_visibility (unsigned int visibility
)
7090 case STV_DEFAULT
: return "DEFAULT";
7091 case STV_INTERNAL
: return "INTERNAL";
7092 case STV_HIDDEN
: return "HIDDEN";
7093 case STV_PROTECTED
: return "PROTECTED";
7099 get_mips_symbol_other (unsigned int other
)
7103 case STO_OPTIONAL
: return "OPTIONAL";
7104 case STO_MIPS16
: return "MIPS16";
7105 case STO_MIPS_PLT
: return "MIPS PLT";
7106 case STO_MIPS_PIC
: return "MIPS PIC";
7107 default: return NULL
;
7112 get_symbol_other (unsigned int other
)
7114 const char * result
= NULL
;
7115 static char buff
[32];
7120 switch (elf_header
.e_machine
)
7123 result
= get_mips_symbol_other (other
);
7131 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
7136 get_symbol_index_type (unsigned int type
)
7138 static char buff
[32];
7142 case SHN_UNDEF
: return "UND";
7143 case SHN_ABS
: return "ABS";
7144 case SHN_COMMON
: return "COM";
7146 if (type
== SHN_IA_64_ANSI_COMMON
7147 && elf_header
.e_machine
== EM_IA_64
7148 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
7150 else if ((elf_header
.e_machine
== EM_X86_64
7151 || elf_header
.e_machine
== EM_L1OM
)
7152 && type
== SHN_X86_64_LCOMMON
)
7154 else if (type
== SHN_MIPS_SCOMMON
7155 && elf_header
.e_machine
== EM_MIPS
)
7157 else if (type
== SHN_MIPS_SUNDEFINED
7158 && elf_header
.e_machine
== EM_MIPS
)
7160 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
7161 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
7162 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
7163 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
7164 else if (type
>= SHN_LORESERVE
)
7165 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
7167 sprintf (buff
, "%3d", type
);
7175 get_dynamic_data (FILE * file
, unsigned int number
, unsigned int ent_size
)
7177 unsigned char * e_data
;
7180 e_data
= (unsigned char *) cmalloc (number
, ent_size
);
7184 error (_("Out of memory\n"));
7188 if (fread (e_data
, ent_size
, number
, file
) != number
)
7190 error (_("Unable to read in dynamic data\n"));
7194 i_data
= (bfd_vma
*) cmalloc (number
, sizeof (*i_data
));
7198 error (_("Out of memory\n"));
7204 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7212 print_dynamic_symbol (bfd_vma si
, unsigned long hn
)
7214 Elf_Internal_Sym
* psym
;
7217 psym
= dynamic_symbols
+ si
;
7219 n
= print_vma (si
, DEC_5
);
7221 fputs (" " + n
, stdout
);
7222 printf (" %3lu: ", hn
);
7223 print_vma (psym
->st_value
, LONG_HEX
);
7225 print_vma (psym
->st_size
, DEC_5
);
7227 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7228 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7229 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7230 /* Check to see if any other bits in the st_other field are set.
7231 Note - displaying this information disrupts the layout of the
7232 table being generated, but for the moment this case is very
7234 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7235 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7236 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7237 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7238 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7240 printf (" <corrupt: %14ld>", psym
->st_name
);
7244 /* Dump the symbol table. */
7246 process_symbol_table (FILE * file
)
7248 Elf_Internal_Shdr
* section
;
7249 bfd_vma nbuckets
= 0;
7250 bfd_vma nchains
= 0;
7251 bfd_vma
* buckets
= NULL
;
7252 bfd_vma
* chains
= NULL
;
7253 bfd_vma ngnubuckets
= 0;
7254 bfd_vma
* gnubuckets
= NULL
;
7255 bfd_vma
* gnuchains
= NULL
;
7256 bfd_vma gnusymidx
= 0;
7258 if (! do_syms
&& !do_histogram
)
7261 if (dynamic_info
[DT_HASH
]
7263 || (do_using_dynamic
&& dynamic_strings
!= NULL
)))
7265 unsigned char nb
[8];
7266 unsigned char nc
[8];
7267 int hash_ent_size
= 4;
7269 if ((elf_header
.e_machine
== EM_ALPHA
7270 || elf_header
.e_machine
== EM_S390
7271 || elf_header
.e_machine
== EM_S390_OLD
)
7272 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
7276 (archive_file_offset
7277 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
7278 sizeof nb
+ sizeof nc
)),
7281 error (_("Unable to seek to start of dynamic information\n"));
7285 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
7287 error (_("Failed to read in number of buckets\n"));
7291 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
7293 error (_("Failed to read in number of chains\n"));
7297 nbuckets
= byte_get (nb
, hash_ent_size
);
7298 nchains
= byte_get (nc
, hash_ent_size
);
7300 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
7301 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
7304 if (buckets
== NULL
|| chains
== NULL
)
7306 if (do_using_dynamic
)
7317 if (dynamic_info_DT_GNU_HASH
7319 || (do_using_dynamic
&& dynamic_strings
!= NULL
)))
7321 unsigned char nb
[16];
7322 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
7323 bfd_vma buckets_vma
;
7326 (archive_file_offset
7327 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
7331 error (_("Unable to seek to start of dynamic information\n"));
7335 if (fread (nb
, 16, 1, file
) != 1)
7337 error (_("Failed to read in number of buckets\n"));
7341 ngnubuckets
= byte_get (nb
, 4);
7342 gnusymidx
= byte_get (nb
+ 4, 4);
7343 bitmaskwords
= byte_get (nb
+ 8, 4);
7344 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
7346 buckets_vma
+= bitmaskwords
* 4;
7348 buckets_vma
+= bitmaskwords
* 8;
7351 (archive_file_offset
7352 + offset_from_vma (file
, buckets_vma
, 4)),
7355 error (_("Unable to seek to start of dynamic information\n"));
7359 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
7361 if (gnubuckets
== NULL
)
7364 for (i
= 0; i
< ngnubuckets
; i
++)
7365 if (gnubuckets
[i
] != 0)
7367 if (gnubuckets
[i
] < gnusymidx
)
7370 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
7371 maxchain
= gnubuckets
[i
];
7374 if (maxchain
== 0xffffffff)
7377 maxchain
-= gnusymidx
;
7380 (archive_file_offset
7381 + offset_from_vma (file
, buckets_vma
7382 + 4 * (ngnubuckets
+ maxchain
), 4)),
7385 error (_("Unable to seek to start of dynamic information\n"));
7391 if (fread (nb
, 4, 1, file
) != 1)
7393 error (_("Failed to determine last chain length\n"));
7397 if (maxchain
+ 1 == 0)
7402 while ((byte_get (nb
, 4) & 1) == 0);
7405 (archive_file_offset
7406 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
7409 error (_("Unable to seek to start of dynamic information\n"));
7413 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
7416 if (gnuchains
== NULL
)
7421 if (do_using_dynamic
)
7426 if ((dynamic_info
[DT_HASH
] || dynamic_info_DT_GNU_HASH
)
7429 && dynamic_strings
!= NULL
)
7433 if (dynamic_info
[DT_HASH
])
7437 printf (_("\nSymbol table for image:\n"));
7439 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7441 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7443 for (hn
= 0; hn
< nbuckets
; hn
++)
7448 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
7449 print_dynamic_symbol (si
, hn
);
7453 if (dynamic_info_DT_GNU_HASH
)
7455 printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
7457 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7459 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7461 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7462 if (gnubuckets
[hn
] != 0)
7464 bfd_vma si
= gnubuckets
[hn
];
7465 bfd_vma off
= si
- gnusymidx
;
7469 print_dynamic_symbol (si
, hn
);
7472 while ((gnuchains
[off
++] & 1) == 0);
7476 else if (do_syms
&& !do_using_dynamic
)
7480 for (i
= 0, section
= section_headers
;
7481 i
< elf_header
.e_shnum
;
7485 char * strtab
= NULL
;
7486 unsigned long int strtab_size
= 0;
7487 Elf_Internal_Sym
* symtab
;
7488 Elf_Internal_Sym
* psym
;
7490 if ( section
->sh_type
!= SHT_SYMTAB
7491 && section
->sh_type
!= SHT_DYNSYM
)
7494 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7495 SECTION_NAME (section
),
7496 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
7498 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7500 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7502 symtab
= GET_ELF_SYMBOLS (file
, section
);
7506 if (section
->sh_link
== elf_header
.e_shstrndx
)
7508 strtab
= string_table
;
7509 strtab_size
= string_table_length
;
7511 else if (section
->sh_link
< elf_header
.e_shnum
)
7513 Elf_Internal_Shdr
* string_sec
;
7515 string_sec
= section_headers
+ section
->sh_link
;
7517 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
7518 1, string_sec
->sh_size
,
7520 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
7523 for (si
= 0, psym
= symtab
;
7524 si
< section
->sh_size
/ section
->sh_entsize
;
7527 printf ("%6d: ", si
);
7528 print_vma (psym
->st_value
, LONG_HEX
);
7530 print_vma (psym
->st_size
, DEC_5
);
7531 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7532 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7533 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7534 /* Check to see if any other bits in the st_other field are set.
7535 Note - displaying this information disrupts the layout of the
7536 table being generated, but for the moment this case is very rare. */
7537 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7538 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7539 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
7540 print_symbol (25, psym
->st_name
< strtab_size
7541 ? strtab
+ psym
->st_name
: "<corrupt>");
7543 if (section
->sh_type
== SHT_DYNSYM
&&
7544 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
7546 unsigned char data
[2];
7547 unsigned short vers_data
;
7548 unsigned long offset
;
7552 offset
= offset_from_vma
7553 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7554 sizeof data
+ si
* sizeof (vers_data
));
7556 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
7557 sizeof (data
), 1, _("version data"));
7559 vers_data
= byte_get (data
, 2);
7561 is_nobits
= (psym
->st_shndx
< elf_header
.e_shnum
7562 && section_headers
[psym
->st_shndx
].sh_type
7565 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
7567 if ((vers_data
& VERSYM_HIDDEN
) || vers_data
> 1)
7569 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
7570 && (is_nobits
|| ! check_def
))
7572 Elf_External_Verneed evn
;
7573 Elf_Internal_Verneed ivn
;
7574 Elf_Internal_Vernaux ivna
;
7576 /* We must test both. */
7577 offset
= offset_from_vma
7578 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7583 unsigned long vna_off
;
7585 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7588 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7589 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7591 vna_off
= offset
+ ivn
.vn_aux
;
7595 Elf_External_Vernaux evna
;
7597 get_data (&evna
, file
, vna_off
,
7599 _("version need aux (3)"));
7601 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7602 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7603 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7605 vna_off
+= ivna
.vna_next
;
7607 while (ivna
.vna_other
!= vers_data
7608 && ivna
.vna_next
!= 0);
7610 if (ivna
.vna_other
== vers_data
)
7613 offset
+= ivn
.vn_next
;
7615 while (ivn
.vn_next
!= 0);
7617 if (ivna
.vna_other
== vers_data
)
7620 ivna
.vna_name
< strtab_size
7621 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7625 else if (! is_nobits
)
7626 error (_("bad dynamic symbol\n"));
7633 if (vers_data
!= 0x8001
7634 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7636 Elf_Internal_Verdef ivd
;
7637 Elf_Internal_Verdaux ivda
;
7638 Elf_External_Verdaux evda
;
7639 unsigned long offset
;
7641 offset
= offset_from_vma
7643 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7644 sizeof (Elf_External_Verdef
));
7648 Elf_External_Verdef evd
;
7650 get_data (&evd
, file
, offset
, sizeof (evd
),
7651 1, _("version def"));
7653 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7654 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7655 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7657 offset
+= ivd
.vd_next
;
7659 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
)
7660 && ivd
.vd_next
!= 0);
7662 offset
-= ivd
.vd_next
;
7663 offset
+= ivd
.vd_aux
;
7665 get_data (&evda
, file
, offset
, sizeof (evda
),
7666 1, _("version def aux"));
7668 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7670 if (psym
->st_name
!= ivda
.vda_name
)
7671 printf ((vers_data
& VERSYM_HIDDEN
)
7673 ivda
.vda_name
< strtab_size
7674 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7684 if (strtab
!= string_table
)
7690 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7692 if (do_histogram
&& buckets
!= NULL
)
7694 unsigned long * lengths
;
7695 unsigned long * counts
;
7698 unsigned long maxlength
= 0;
7699 unsigned long nzero_counts
= 0;
7700 unsigned long nsyms
= 0;
7702 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7703 (unsigned long) nbuckets
);
7704 printf (_(" Length Number %% of total Coverage\n"));
7706 lengths
= (unsigned long *) calloc (nbuckets
, sizeof (*lengths
));
7707 if (lengths
== NULL
)
7709 error (_("Out of memory\n"));
7712 for (hn
= 0; hn
< nbuckets
; ++hn
)
7714 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7717 if (maxlength
< ++lengths
[hn
])
7722 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
7725 error (_("Out of memory\n"));
7729 for (hn
= 0; hn
< nbuckets
; ++hn
)
7730 ++counts
[lengths
[hn
]];
7735 printf (" 0 %-10lu (%5.1f%%)\n",
7736 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7737 for (i
= 1; i
<= maxlength
; ++i
)
7739 nzero_counts
+= counts
[i
] * i
;
7740 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7741 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7742 (nzero_counts
* 100.0) / nsyms
);
7750 if (buckets
!= NULL
)
7756 if (do_histogram
&& gnubuckets
!= NULL
)
7758 unsigned long * lengths
;
7759 unsigned long * counts
;
7761 unsigned long maxlength
= 0;
7762 unsigned long nzero_counts
= 0;
7763 unsigned long nsyms
= 0;
7765 lengths
= (unsigned long *) calloc (ngnubuckets
, sizeof (*lengths
));
7766 if (lengths
== NULL
)
7768 error (_("Out of memory\n"));
7772 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7773 (unsigned long) ngnubuckets
);
7774 printf (_(" Length Number %% of total Coverage\n"));
7776 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7777 if (gnubuckets
[hn
] != 0)
7779 bfd_vma off
, length
= 1;
7781 for (off
= gnubuckets
[hn
] - gnusymidx
;
7782 (gnuchains
[off
] & 1) == 0; ++off
)
7784 lengths
[hn
] = length
;
7785 if (length
> maxlength
)
7790 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
7793 error (_("Out of memory\n"));
7797 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
7798 ++counts
[lengths
[hn
]];
7800 if (ngnubuckets
> 0)
7803 printf (" 0 %-10lu (%5.1f%%)\n",
7804 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
7805 for (j
= 1; j
<= maxlength
; ++j
)
7807 nzero_counts
+= counts
[j
] * j
;
7808 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7809 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
7810 (nzero_counts
* 100.0) / nsyms
);
7824 process_syminfo (FILE * file ATTRIBUTE_UNUSED
)
7828 if (dynamic_syminfo
== NULL
7830 /* No syminfo, this is ok. */
7833 /* There better should be a dynamic symbol section. */
7834 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7838 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7839 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7841 printf (_(" Num: Name BoundTo Flags\n"));
7842 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7844 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7846 printf ("%4d: ", i
);
7847 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7848 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7850 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7853 switch (dynamic_syminfo
[i
].si_boundto
)
7855 case SYMINFO_BT_SELF
:
7856 fputs ("SELF ", stdout
);
7858 case SYMINFO_BT_PARENT
:
7859 fputs ("PARENT ", stdout
);
7862 if (dynamic_syminfo
[i
].si_boundto
> 0
7863 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7864 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7866 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7870 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7874 if (flags
& SYMINFO_FLG_DIRECT
)
7876 if (flags
& SYMINFO_FLG_PASSTHRU
)
7877 printf (" PASSTHRU");
7878 if (flags
& SYMINFO_FLG_COPY
)
7880 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7881 printf (" LAZYLOAD");
7889 /* Check to see if the given reloc needs to be handled in a target specific
7890 manner. If so then process the reloc and return TRUE otherwise return
7894 target_specific_reloc_handling (Elf_Internal_Rela
* reloc
,
7895 unsigned char * start
,
7896 Elf_Internal_Sym
* symtab
)
7898 unsigned int reloc_type
= get_reloc_type (reloc
->r_info
);
7900 switch (elf_header
.e_machine
)
7903 case EM_CYGNUS_MN10300
:
7905 static Elf_Internal_Sym
* saved_sym
= NULL
;
7909 case 34: /* R_MN10300_ALIGN */
7911 case 33: /* R_MN10300_SYM_DIFF */
7912 saved_sym
= symtab
+ get_reloc_symindex (reloc
->r_info
);
7914 case 1: /* R_MN10300_32 */
7915 case 2: /* R_MN10300_16 */
7916 if (saved_sym
!= NULL
)
7920 value
= reloc
->r_addend
7921 + (symtab
[get_reloc_symindex (reloc
->r_info
)].st_value
7922 - saved_sym
->st_value
);
7924 byte_put (start
+ reloc
->r_offset
, value
, reloc_type
== 1 ? 4 : 2);
7931 if (saved_sym
!= NULL
)
7932 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc"));
7942 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
7943 DWARF debug sections. This is a target specific test. Note - we do not
7944 go through the whole including-target-headers-multiple-times route, (as
7945 we have already done with <elf/h8.h>) because this would become very
7946 messy and even then this function would have to contain target specific
7947 information (the names of the relocs instead of their numeric values).
7948 FIXME: This is not the correct way to solve this problem. The proper way
7949 is to have target specific reloc sizing and typing functions created by
7950 the reloc-macros.h header, in the same way that it already creates the
7951 reloc naming functions. */
7954 is_32bit_abs_reloc (unsigned int reloc_type
)
7956 switch (elf_header
.e_machine
)
7960 return reloc_type
== 1; /* R_386_32. */
7962 return reloc_type
== 1; /* R_68K_32. */
7964 return reloc_type
== 1; /* R_860_32. */
7966 return reloc_type
== 1; /* XXX Is this right ? */
7968 return reloc_type
== 1; /* R_ARC_32. */
7970 return reloc_type
== 2; /* R_ARM_ABS32 */
7973 return reloc_type
== 1;
7975 return reloc_type
== 0x12; /* R_byte4_data. */
7977 return reloc_type
== 3; /* R_CRIS_32. */
7980 return reloc_type
== 3; /* R_CR16_NUM32. */
7982 return reloc_type
== 15; /* R_CRX_NUM32. */
7984 return reloc_type
== 1;
7985 case EM_CYGNUS_D10V
:
7987 return reloc_type
== 6; /* R_D10V_32. */
7988 case EM_CYGNUS_D30V
:
7990 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
7992 return reloc_type
== 3; /* R_DLX_RELOC_32. */
7993 case EM_CYGNUS_FR30
:
7995 return reloc_type
== 3; /* R_FR30_32. */
7999 return reloc_type
== 1; /* R_H8_DIR32. */
8001 return reloc_type
== 0x65; /* R_IA64_SECREL32LSB. */
8004 return reloc_type
== 2; /* R_IP2K_32. */
8006 return reloc_type
== 2; /* R_IQ2000_32. */
8007 case EM_LATTICEMICO32
:
8008 return reloc_type
== 3; /* R_LM32_32. */
8011 return reloc_type
== 3; /* R_M32C_32. */
8013 return reloc_type
== 34; /* R_M32R_32_RELA. */
8015 return reloc_type
== 1; /* R_MCORE_ADDR32. */
8017 return reloc_type
== 4; /* R_MEP_32. */
8019 return reloc_type
== 2; /* R_MIPS_32. */
8021 return reloc_type
== 4; /* R_MMIX_32. */
8022 case EM_CYGNUS_MN10200
:
8024 return reloc_type
== 1; /* R_MN10200_32. */
8025 case EM_CYGNUS_MN10300
:
8027 return reloc_type
== 1; /* R_MN10300_32. */
8030 return reloc_type
== 1; /* R_MSP43_32. */
8032 return reloc_type
== 2; /* R_MT_32. */
8033 case EM_ALTERA_NIOS2
:
8035 return reloc_type
== 1; /* R_NIOS_32. */
8038 return reloc_type
== 1; /* R_OR32_32. */
8040 return (reloc_type
== 1 /* R_PARISC_DIR32. */
8041 || reloc_type
== 41); /* R_PARISC_SECREL32. */
8044 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
8046 return reloc_type
== 1; /* R_PPC64_ADDR32. */
8048 return reloc_type
== 1; /* R_PPC_ADDR32. */
8050 return reloc_type
== 1; /* R_I370_ADDR31. */
8053 return reloc_type
== 4; /* R_S390_32. */
8055 return reloc_type
== 8; /* R_SCORE_ABS32. */
8057 return reloc_type
== 1; /* R_SH_DIR32. */
8058 case EM_SPARC32PLUS
:
8061 return reloc_type
== 3 /* R_SPARC_32. */
8062 || reloc_type
== 23; /* R_SPARC_UA32. */
8064 return reloc_type
== 6; /* R_SPU_ADDR32 */
8065 case EM_CYGNUS_V850
:
8067 return reloc_type
== 6; /* R_V850_ABS32. */
8069 return reloc_type
== 1; /* R_VAX_32. */
8072 return reloc_type
== 10; /* R_X86_64_32. */
8074 return reloc_type
== 1; /* R_XSTROMY16_32. */
8077 return reloc_type
== 1; /* R_XTENSA_32. */
8080 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
8081 elf_header
.e_machine
);
8086 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8087 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
8090 is_32bit_pcrel_reloc (unsigned int reloc_type
)
8092 switch (elf_header
.e_machine
)
8096 return reloc_type
== 2; /* R_386_PC32. */
8098 return reloc_type
== 4; /* R_68K_PC32. */
8100 return reloc_type
== 10; /* R_ALPHA_SREL32. */
8102 return reloc_type
== 3; /* R_ARM_REL32 */
8104 return reloc_type
== 9; /* R_PARISC_PCREL32. */
8106 return reloc_type
== 26; /* R_PPC_REL32. */
8108 return reloc_type
== 26; /* R_PPC64_REL32. */
8111 return reloc_type
== 5; /* R_390_PC32. */
8113 return reloc_type
== 2; /* R_SH_REL32. */
8114 case EM_SPARC32PLUS
:
8117 return reloc_type
== 6; /* R_SPARC_DISP32. */
8119 return reloc_type
== 13; /* R_SPU_REL32. */
8122 return reloc_type
== 2; /* R_X86_64_PC32. */
8125 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
8127 /* Do not abort or issue an error message here. Not all targets use
8128 pc-relative 32-bit relocs in their DWARF debug information and we
8129 have already tested for target coverage in is_32bit_abs_reloc. A
8130 more helpful warning message will be generated by apply_relocations
8131 anyway, so just return. */
8136 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8137 a 64-bit absolute RELA relocation used in DWARF debug sections. */
8140 is_64bit_abs_reloc (unsigned int reloc_type
)
8142 switch (elf_header
.e_machine
)
8145 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
8147 return reloc_type
== 0x27; /* R_IA64_DIR64LSB. */
8149 return reloc_type
== 80; /* R_PARISC_DIR64. */
8151 return reloc_type
== 38; /* R_PPC64_ADDR64. */
8152 case EM_SPARC32PLUS
:
8155 return reloc_type
== 54; /* R_SPARC_UA64. */
8158 return reloc_type
== 1; /* R_X86_64_64. */
8161 return reloc_type
== 22; /* R_S390_64 */
8163 return reloc_type
== 18; /* R_MIPS_64 */
8169 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
8170 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
8173 is_64bit_pcrel_reloc (unsigned int reloc_type
)
8175 switch (elf_header
.e_machine
)
8178 return reloc_type
== 11; /* R_ALPHA_SREL64 */
8180 return reloc_type
== 0x4f; /* R_IA64_PCREL64LSB */
8182 return reloc_type
== 72; /* R_PARISC_PCREL64 */
8184 return reloc_type
== 44; /* R_PPC64_REL64 */
8185 case EM_SPARC32PLUS
:
8188 return reloc_type
== 46; /* R_SPARC_DISP64 */
8191 return reloc_type
== 24; /* R_X86_64_PC64 */
8194 return reloc_type
== 23; /* R_S390_PC64 */
8200 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8201 a 24-bit absolute RELA relocation used in DWARF debug sections. */
8204 is_24bit_abs_reloc (unsigned int reloc_type
)
8206 switch (elf_header
.e_machine
)
8208 case EM_CYGNUS_MN10200
:
8210 return reloc_type
== 4; /* R_MN10200_24. */
8216 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8217 a 16-bit absolute RELA relocation used in DWARF debug sections. */
8220 is_16bit_abs_reloc (unsigned int reloc_type
)
8222 switch (elf_header
.e_machine
)
8226 return reloc_type
== 4; /* R_AVR_16. */
8227 case EM_CYGNUS_D10V
:
8229 return reloc_type
== 3; /* R_D10V_16. */
8233 return reloc_type
== R_H8_DIR16
;
8236 return reloc_type
== 1; /* R_IP2K_16. */
8239 return reloc_type
== 1; /* R_M32C_16 */
8242 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
8243 case EM_ALTERA_NIOS2
:
8245 return reloc_type
== 9; /* R_NIOS_16. */
8251 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
8252 relocation entries (possibly formerly used for SHT_GROUP sections). */
8255 is_none_reloc (unsigned int reloc_type
)
8257 switch (elf_header
.e_machine
)
8259 case EM_68K
: /* R_68K_NONE. */
8260 case EM_386
: /* R_386_NONE. */
8261 case EM_SPARC32PLUS
:
8263 case EM_SPARC
: /* R_SPARC_NONE. */
8264 case EM_MIPS
: /* R_MIPS_NONE. */
8265 case EM_PARISC
: /* R_PARISC_NONE. */
8266 case EM_ALPHA
: /* R_ALPHA_NONE. */
8267 case EM_PPC
: /* R_PPC_NONE. */
8268 case EM_PPC64
: /* R_PPC64_NONE. */
8269 case EM_ARM
: /* R_ARM_NONE. */
8270 case EM_IA_64
: /* R_IA64_NONE. */
8271 case EM_SH
: /* R_SH_NONE. */
8273 case EM_S390
: /* R_390_NONE. */
8274 case EM_CRIS
: /* R_CRIS_NONE. */
8275 case EM_X86_64
: /* R_X86_64_NONE. */
8276 case EM_L1OM
: /* R_X86_64_NONE. */
8277 case EM_MN10300
: /* R_MN10300_NONE. */
8278 case EM_M32R
: /* R_M32R_NONE. */
8279 return reloc_type
== 0;
8282 return (reloc_type
== 0 /* R_XTENSA_NONE. */
8283 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
8284 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
8285 || reloc_type
== 19 /* R_XTENSA_DIFF32. */);
8290 /* Apply relocations to a section.
8291 Note: So far support has been added only for those relocations
8292 which can be found in debug sections.
8293 FIXME: Add support for more relocations ? */
8296 apply_relocations (void * file
,
8297 Elf_Internal_Shdr
* section
,
8298 unsigned char * start
)
8300 Elf_Internal_Shdr
* relsec
;
8301 unsigned char * end
= start
+ section
->sh_size
;
8303 if (elf_header
.e_type
!= ET_REL
)
8306 /* Find the reloc section associated with the section. */
8307 for (relsec
= section_headers
;
8308 relsec
< section_headers
+ elf_header
.e_shnum
;
8311 bfd_boolean is_rela
;
8312 unsigned long num_relocs
;
8313 Elf_Internal_Rela
* relocs
;
8314 Elf_Internal_Rela
* rp
;
8315 Elf_Internal_Shdr
* symsec
;
8316 Elf_Internal_Sym
* symtab
;
8317 Elf_Internal_Sym
* sym
;
8319 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8320 || relsec
->sh_info
>= elf_header
.e_shnum
8321 || section_headers
+ relsec
->sh_info
!= section
8322 || relsec
->sh_size
== 0
8323 || relsec
->sh_link
>= elf_header
.e_shnum
)
8326 is_rela
= relsec
->sh_type
== SHT_RELA
;
8330 if (!slurp_rela_relocs ((FILE *) file
, relsec
->sh_offset
,
8331 relsec
->sh_size
, & relocs
, & num_relocs
))
8336 if (!slurp_rel_relocs ((FILE *) file
, relsec
->sh_offset
,
8337 relsec
->sh_size
, & relocs
, & num_relocs
))
8341 /* SH uses RELA but uses in place value instead of the addend field. */
8342 if (elf_header
.e_machine
== EM_SH
)
8345 symsec
= section_headers
+ relsec
->sh_link
;
8346 symtab
= GET_ELF_SYMBOLS ((FILE *) file
, symsec
);
8348 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
8351 unsigned int reloc_type
;
8352 unsigned int reloc_size
;
8353 unsigned char * loc
;
8355 reloc_type
= get_reloc_type (rp
->r_info
);
8357 if (target_specific_reloc_handling (rp
, start
, symtab
))
8359 else if (is_none_reloc (reloc_type
))
8361 else if (is_32bit_abs_reloc (reloc_type
)
8362 || is_32bit_pcrel_reloc (reloc_type
))
8364 else if (is_64bit_abs_reloc (reloc_type
)
8365 || is_64bit_pcrel_reloc (reloc_type
))
8367 else if (is_24bit_abs_reloc (reloc_type
))
8369 else if (is_16bit_abs_reloc (reloc_type
))
8373 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
8374 reloc_type
, SECTION_NAME (section
));
8378 loc
= start
+ rp
->r_offset
;
8379 if ((loc
+ reloc_size
) > end
)
8381 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
8382 (unsigned long) rp
->r_offset
,
8383 SECTION_NAME (section
));
8387 sym
= symtab
+ get_reloc_symindex (rp
->r_info
);
8389 /* If the reloc has a symbol associated with it,
8390 make sure that it is of an appropriate type.
8392 Relocations against symbols without type can happen.
8393 Gcc -feliminate-dwarf2-dups may generate symbols
8394 without type for debug info.
8396 Icc generates relocations against function symbols
8397 instead of local labels.
8399 Relocations against object symbols can happen, eg when
8400 referencing a global array. For an example of this see
8401 the _clz.o binary in libgcc.a. */
8403 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
8405 warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
8406 get_symbol_type (ELF_ST_TYPE (sym
->st_info
)),
8407 (long int)(rp
- relocs
),
8408 SECTION_NAME (relsec
));
8414 addend
+= rp
->r_addend
;
8415 /* R_XTENSA_32 and R_PJ_DATA_DIR32 are partial_inplace. */
8417 || (elf_header
.e_machine
== EM_XTENSA
8419 || ((elf_header
.e_machine
== EM_PJ
8420 || elf_header
.e_machine
== EM_PJ_OLD
)
8421 && reloc_type
== 1))
8422 addend
+= byte_get (loc
, reloc_size
);
8424 if (is_32bit_pcrel_reloc (reloc_type
)
8425 || is_64bit_pcrel_reloc (reloc_type
))
8427 /* On HPPA, all pc-relative relocations are biased by 8. */
8428 if (elf_header
.e_machine
== EM_PARISC
)
8430 byte_put (loc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
8434 byte_put (loc
, addend
+ sym
->st_value
, reloc_size
);
8443 #ifdef SUPPORT_DISASSEMBLY
8445 disassemble_section (Elf_Internal_Shdr
* section
, FILE * file
)
8447 printf (_("\nAssembly dump of section %s\n"),
8448 SECTION_NAME (section
));
8450 /* XXX -- to be done --- XXX */
8456 /* Reads in the contents of SECTION from FILE, returning a pointer
8457 to a malloc'ed buffer or NULL if something went wrong. */
8460 get_section_contents (Elf_Internal_Shdr
* section
, FILE * file
)
8462 bfd_size_type num_bytes
;
8464 num_bytes
= section
->sh_size
;
8466 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
8468 printf (_("\nSection '%s' has no data to dump.\n"),
8469 SECTION_NAME (section
));
8473 return (char *) get_data (NULL
, file
, section
->sh_offset
, 1, num_bytes
,
8474 _("section contents"));
8479 dump_section_as_strings (Elf_Internal_Shdr
* section
, FILE * file
)
8481 Elf_Internal_Shdr
* relsec
;
8482 bfd_size_type num_bytes
;
8487 char * name
= SECTION_NAME (section
);
8488 bfd_boolean some_strings_shown
;
8490 start
= get_section_contents (section
, file
);
8494 printf (_("\nString dump of section '%s':\n"), name
);
8496 /* If the section being dumped has relocations against it the user might
8497 be expecting these relocations to have been applied. Check for this
8498 case and issue a warning message in order to avoid confusion.
8499 FIXME: Maybe we ought to have an option that dumps a section with
8501 for (relsec
= section_headers
;
8502 relsec
< section_headers
+ elf_header
.e_shnum
;
8505 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8506 || relsec
->sh_info
>= elf_header
.e_shnum
8507 || section_headers
+ relsec
->sh_info
!= section
8508 || relsec
->sh_size
== 0
8509 || relsec
->sh_link
>= elf_header
.e_shnum
)
8512 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
8516 num_bytes
= section
->sh_size
;
8517 addr
= section
->sh_addr
;
8519 end
= start
+ num_bytes
;
8520 some_strings_shown
= FALSE
;
8524 while (!ISPRINT (* data
))
8531 printf (" [%6tx] %s\n", data
- start
, data
);
8533 printf (" [%6Ix] %s\n", (size_t) (data
- start
), data
);
8535 data
+= strlen (data
);
8536 some_strings_shown
= TRUE
;
8540 if (! some_strings_shown
)
8541 printf (_(" No strings found in this section."));
8549 dump_section_as_bytes (Elf_Internal_Shdr
* section
,
8551 bfd_boolean relocate
)
8553 Elf_Internal_Shdr
* relsec
;
8554 bfd_size_type bytes
;
8556 unsigned char * data
;
8557 unsigned char * start
;
8559 start
= (unsigned char *) get_section_contents (section
, file
);
8563 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
8567 apply_relocations (file
, section
, start
);
8571 /* If the section being dumped has relocations against it the user might
8572 be expecting these relocations to have been applied. Check for this
8573 case and issue a warning message in order to avoid confusion.
8574 FIXME: Maybe we ought to have an option that dumps a section with
8576 for (relsec
= section_headers
;
8577 relsec
< section_headers
+ elf_header
.e_shnum
;
8580 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
8581 || relsec
->sh_info
>= elf_header
.e_shnum
8582 || section_headers
+ relsec
->sh_info
!= section
8583 || relsec
->sh_size
== 0
8584 || relsec
->sh_link
>= elf_header
.e_shnum
)
8587 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
8592 addr
= section
->sh_addr
;
8593 bytes
= section
->sh_size
;
8602 lbytes
= (bytes
> 16 ? 16 : bytes
);
8604 printf (" 0x%8.8lx ", (unsigned long) addr
);
8606 for (j
= 0; j
< 16; j
++)
8609 printf ("%2.2x", data
[j
]);
8617 for (j
= 0; j
< lbytes
; j
++)
8620 if (k
>= ' ' && k
< 0x7f)
8638 /* Uncompresses a section that was compressed using zlib, in place.
8639 This is a copy of bfd_uncompress_section_contents, in bfd/compress.c */
8642 uncompress_section_contents (unsigned char ** buffer
, dwarf_size_type
* size
)
8645 /* These are just to quiet gcc. */
8650 dwarf_size_type compressed_size
= *size
;
8651 unsigned char * compressed_buffer
= *buffer
;
8652 dwarf_size_type uncompressed_size
;
8653 unsigned char * uncompressed_buffer
;
8656 dwarf_size_type header_size
= 12;
8658 /* Read the zlib header. In this case, it should be "ZLIB" followed
8659 by the uncompressed section size, 8 bytes in big-endian order. */
8660 if (compressed_size
< header_size
8661 || ! streq ((char *) compressed_buffer
, "ZLIB"))
8664 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
8665 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
8666 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
8667 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
8668 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
8669 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
8670 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
8671 uncompressed_size
+= compressed_buffer
[11];
8673 /* It is possible the section consists of several compressed
8674 buffers concatenated together, so we uncompress in a loop. */
8678 strm
.avail_in
= compressed_size
- header_size
;
8679 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
8680 strm
.avail_out
= uncompressed_size
;
8681 uncompressed_buffer
= (unsigned char *) xmalloc (uncompressed_size
);
8683 rc
= inflateInit (& strm
);
8684 while (strm
.avail_in
> 0)
8688 strm
.next_out
= ((Bytef
*) uncompressed_buffer
8689 + (uncompressed_size
- strm
.avail_out
));
8690 rc
= inflate (&strm
, Z_FINISH
);
8691 if (rc
!= Z_STREAM_END
)
8693 rc
= inflateReset (& strm
);
8695 rc
= inflateEnd (& strm
);
8697 || strm
.avail_out
!= 0)
8700 free (compressed_buffer
);
8701 *buffer
= uncompressed_buffer
;
8702 *size
= uncompressed_size
;
8706 free (uncompressed_buffer
);
8708 #endif /* HAVE_ZLIB_H */
8712 load_specific_debug_section (enum dwarf_section_display_enum debug
,
8713 Elf_Internal_Shdr
* sec
, void * file
)
8715 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
8717 int section_is_compressed
;
8719 /* If it is already loaded, do nothing. */
8720 if (section
->start
!= NULL
)
8723 section_is_compressed
= section
->name
== section
->compressed_name
;
8725 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
8726 section
->address
= sec
->sh_addr
;
8727 section
->size
= sec
->sh_size
;
8728 section
->start
= (unsigned char *) get_data (NULL
, (FILE *) file
,
8731 if (section
->start
== NULL
)
8734 if (section_is_compressed
)
8735 if (! uncompress_section_contents (§ion
->start
, §ion
->size
))
8738 if (debug_displays
[debug
].relocate
)
8739 apply_relocations ((FILE *) file
, sec
, section
->start
);
8745 load_debug_section (enum dwarf_section_display_enum debug
, void * file
)
8747 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
8748 Elf_Internal_Shdr
* sec
;
8750 /* Locate the debug section. */
8751 sec
= find_section (section
->uncompressed_name
);
8753 section
->name
= section
->uncompressed_name
;
8756 sec
= find_section (section
->compressed_name
);
8758 section
->name
= section
->compressed_name
;
8763 return load_specific_debug_section (debug
, sec
, (FILE *) file
);
8767 free_debug_section (enum dwarf_section_display_enum debug
)
8769 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
8771 if (section
->start
== NULL
)
8774 free ((char *) section
->start
);
8775 section
->start
= NULL
;
8776 section
->address
= 0;
8781 display_debug_section (Elf_Internal_Shdr
* section
, FILE * file
)
8783 char * name
= SECTION_NAME (section
);
8784 bfd_size_type length
;
8788 length
= section
->sh_size
;
8791 printf (_("\nSection '%s' has no debugging data.\n"), name
);
8794 if (section
->sh_type
== SHT_NOBITS
)
8796 /* There is no point in dumping the contents of a debugging section
8797 which has the NOBITS type - the bits in the file will be random.
8798 This can happen when a file containing a .eh_frame section is
8799 stripped with the --only-keep-debug command line option. */
8800 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), name
);
8804 if (const_strneq (name
, ".gnu.linkonce.wi."))
8805 name
= ".debug_info";
8807 /* See if we know how to display the contents of this section. */
8808 for (i
= 0; i
< max
; i
++)
8809 if (streq (debug_displays
[i
].section
.uncompressed_name
, name
)
8810 || streq (debug_displays
[i
].section
.compressed_name
, name
))
8812 struct dwarf_section
* sec
= &debug_displays
[i
].section
;
8813 int secondary
= (section
!= find_section (name
));
8816 free_debug_section ((enum dwarf_section_display_enum
) i
);
8818 if (streq (debug_displays
[i
].section
.uncompressed_name
, name
))
8819 sec
->name
= sec
->uncompressed_name
;
8821 sec
->name
= sec
->compressed_name
;
8822 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
8825 result
&= debug_displays
[i
].display (sec
, file
);
8827 if (secondary
|| (i
!= info
&& i
!= abbrev
))
8828 free_debug_section ((enum dwarf_section_display_enum
) i
);
8836 printf (_("Unrecognized debug section: %s\n"), name
);
8843 /* Set DUMP_SECTS for all sections where dumps were requested
8844 based on section name. */
8847 initialise_dumps_byname (void)
8849 struct dump_list_entry
* cur
;
8851 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
8856 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
8857 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
8859 request_dump_bynumber (i
, cur
->type
);
8864 warn (_("Section '%s' was not dumped because it does not exist!\n"),
8870 process_section_contents (FILE * file
)
8872 Elf_Internal_Shdr
* section
;
8878 initialise_dumps_byname ();
8880 for (i
= 0, section
= section_headers
;
8881 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
8884 #ifdef SUPPORT_DISASSEMBLY
8885 if (dump_sects
[i
] & DISASS_DUMP
)
8886 disassemble_section (section
, file
);
8888 if (dump_sects
[i
] & HEX_DUMP
)
8889 dump_section_as_bytes (section
, file
, FALSE
);
8891 if (dump_sects
[i
] & RELOC_DUMP
)
8892 dump_section_as_bytes (section
, file
, TRUE
);
8894 if (dump_sects
[i
] & STRING_DUMP
)
8895 dump_section_as_strings (section
, file
);
8897 if (dump_sects
[i
] & DEBUG_DUMP
)
8898 display_debug_section (section
, file
);
8901 /* Check to see if the user requested a
8902 dump of a section that does not exist. */
8903 while (i
++ < num_dump_sects
)
8905 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
8909 process_mips_fpe_exception (int mask
)
8914 if (mask
& OEX_FPU_INEX
)
8915 fputs ("INEX", stdout
), first
= 0;
8916 if (mask
& OEX_FPU_UFLO
)
8917 printf ("%sUFLO", first
? "" : "|"), first
= 0;
8918 if (mask
& OEX_FPU_OFLO
)
8919 printf ("%sOFLO", first
? "" : "|"), first
= 0;
8920 if (mask
& OEX_FPU_DIV0
)
8921 printf ("%sDIV0", first
? "" : "|"), first
= 0;
8922 if (mask
& OEX_FPU_INVAL
)
8923 printf ("%sINVAL", first
? "" : "|");
8926 fputs ("0", stdout
);
8929 /* ARM EABI attributes section. */
8934 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
8936 const char ** table
;
8937 } arm_attr_public_tag
;
8939 static const char * arm_attr_tag_CPU_arch
[] =
8940 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
8941 "v6K", "v7", "v6-M", "v6S-M"};
8942 static const char * arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
8943 static const char * arm_attr_tag_THUMB_ISA_use
[] =
8944 {"No", "Thumb-1", "Thumb-2"};
8945 static const char * arm_attr_tag_VFP_arch
[] =
8946 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16"};
8947 static const char * arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
8948 static const char * arm_attr_tag_Advanced_SIMD_arch
[] = {"No", "NEONv1"};
8949 static const char * arm_attr_tag_PCS_config
[] =
8950 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
8951 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
8952 static const char * arm_attr_tag_ABI_PCS_R9_use
[] =
8953 {"V6", "SB", "TLS", "Unused"};
8954 static const char * arm_attr_tag_ABI_PCS_RW_data
[] =
8955 {"Absolute", "PC-relative", "SB-relative", "None"};
8956 static const char * arm_attr_tag_ABI_PCS_RO_data
[] =
8957 {"Absolute", "PC-relative", "None"};
8958 static const char * arm_attr_tag_ABI_PCS_GOT_use
[] =
8959 {"None", "direct", "GOT-indirect"};
8960 static const char * arm_attr_tag_ABI_PCS_wchar_t
[] =
8961 {"None", "??? 1", "2", "??? 3", "4"};
8962 static const char * arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
8963 static const char * arm_attr_tag_ABI_FP_denormal
[] =
8964 {"Unused", "Needed", "Sign only"};
8965 static const char * arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
8966 static const char * arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
8967 static const char * arm_attr_tag_ABI_FP_number_model
[] =
8968 {"Unused", "Finite", "RTABI", "IEEE 754"};
8969 static const char * arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
8970 static const char * arm_attr_tag_ABI_align8_preserved
[] =
8971 {"No", "Yes, except leaf SP", "Yes"};
8972 static const char * arm_attr_tag_ABI_enum_size
[] =
8973 {"Unused", "small", "int", "forced to int"};
8974 static const char * arm_attr_tag_ABI_HardFP_use
[] =
8975 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
8976 static const char * arm_attr_tag_ABI_VFP_args
[] =
8977 {"AAPCS", "VFP registers", "custom"};
8978 static const char * arm_attr_tag_ABI_WMMX_args
[] =
8979 {"AAPCS", "WMMX registers", "custom"};
8980 static const char * arm_attr_tag_ABI_optimization_goals
[] =
8981 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8982 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
8983 static const char * arm_attr_tag_ABI_FP_optimization_goals
[] =
8984 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
8985 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
8986 static const char * arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
8987 static const char * arm_attr_tag_VFP_HP_extension
[] =
8988 {"Not Allowed", "Allowed"};
8989 static const char * arm_attr_tag_ABI_FP_16bit_format
[] =
8990 {"None", "IEEE 754", "Alternative Format"};
8991 static const char * arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
8992 static const char * arm_attr_tag_Virtualization_use
[] =
8993 {"Not Allowed", "Allowed"};
8994 static const char * arm_attr_tag_MPextension_use
[] = {"Not Allowed", "Allowed"};
8996 #define LOOKUP(id, name) \
8997 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
8998 static arm_attr_public_tag arm_attr_public_tags
[] =
9000 {4, "CPU_raw_name", 1, NULL
},
9001 {5, "CPU_name", 1, NULL
},
9002 LOOKUP(6, CPU_arch
),
9003 {7, "CPU_arch_profile", 0, NULL
},
9004 LOOKUP(8, ARM_ISA_use
),
9005 LOOKUP(9, THUMB_ISA_use
),
9006 LOOKUP(10, VFP_arch
),
9007 LOOKUP(11, WMMX_arch
),
9008 LOOKUP(12, Advanced_SIMD_arch
),
9009 LOOKUP(13, PCS_config
),
9010 LOOKUP(14, ABI_PCS_R9_use
),
9011 LOOKUP(15, ABI_PCS_RW_data
),
9012 LOOKUP(16, ABI_PCS_RO_data
),
9013 LOOKUP(17, ABI_PCS_GOT_use
),
9014 LOOKUP(18, ABI_PCS_wchar_t
),
9015 LOOKUP(19, ABI_FP_rounding
),
9016 LOOKUP(20, ABI_FP_denormal
),
9017 LOOKUP(21, ABI_FP_exceptions
),
9018 LOOKUP(22, ABI_FP_user_exceptions
),
9019 LOOKUP(23, ABI_FP_number_model
),
9020 LOOKUP(24, ABI_align8_needed
),
9021 LOOKUP(25, ABI_align8_preserved
),
9022 LOOKUP(26, ABI_enum_size
),
9023 LOOKUP(27, ABI_HardFP_use
),
9024 LOOKUP(28, ABI_VFP_args
),
9025 LOOKUP(29, ABI_WMMX_args
),
9026 LOOKUP(30, ABI_optimization_goals
),
9027 LOOKUP(31, ABI_FP_optimization_goals
),
9028 {32, "compatibility", 0, NULL
},
9029 LOOKUP(34, CPU_unaligned_access
),
9030 LOOKUP(36, VFP_HP_extension
),
9031 LOOKUP(38, ABI_FP_16bit_format
),
9032 {64, "nodefaults", 0, NULL
},
9033 {65, "also_compatible_with", 0, NULL
},
9034 LOOKUP(66, T2EE_use
),
9035 {67, "conformance", 1, NULL
},
9036 LOOKUP(68, Virtualization_use
),
9037 LOOKUP(70, MPextension_use
)
9041 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
9045 read_uleb128 (unsigned char * p
, unsigned int * plen
)
9059 val
|= ((unsigned int)c
& 0x7f) << shift
;
9068 static unsigned char *
9069 display_arm_attribute (unsigned char * p
)
9074 arm_attr_public_tag
* attr
;
9078 tag
= read_uleb128 (p
, &len
);
9081 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
9083 if (arm_attr_public_tags
[i
].tag
== tag
)
9085 attr
= &arm_attr_public_tags
[i
];
9092 printf (" Tag_%s: ", attr
->name
);
9098 case 7: /* Tag_CPU_arch_profile. */
9099 val
= read_uleb128 (p
, &len
);
9103 case 0: printf ("None\n"); break;
9104 case 'A': printf ("Application\n"); break;
9105 case 'R': printf ("Realtime\n"); break;
9106 case 'M': printf ("Microcontroller\n"); break;
9107 default: printf ("??? (%d)\n", val
); break;
9111 case 32: /* Tag_compatibility. */
9112 val
= read_uleb128 (p
, &len
);
9114 printf ("flag = %d, vendor = %s\n", val
, p
);
9115 p
+= strlen ((char *) p
) + 1;
9118 case 64: /* Tag_nodefaults. */
9123 case 65: /* Tag_also_compatible_with. */
9124 val
= read_uleb128 (p
, &len
);
9126 if (val
== 6 /* Tag_CPU_arch. */)
9128 val
= read_uleb128 (p
, &len
);
9130 if ((unsigned int)val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
9131 printf ("??? (%d)\n", val
);
9133 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
9137 while (*(p
++) != '\0' /* NUL terminator. */);
9151 assert (attr
->type
& 0x80);
9152 val
= read_uleb128 (p
, &len
);
9154 type
= attr
->type
& 0x7f;
9156 printf ("??? (%d)\n", val
);
9158 printf ("%s\n", attr
->table
[val
]);
9165 type
= 1; /* String. */
9167 type
= 2; /* uleb128. */
9168 printf (" Tag_unknown_%d: ", tag
);
9173 printf ("\"%s\"\n", p
);
9174 p
+= strlen ((char *) p
) + 1;
9178 val
= read_uleb128 (p
, &len
);
9180 printf ("%d (0x%x)\n", val
, val
);
9186 static unsigned char *
9187 display_gnu_attribute (unsigned char * p
,
9188 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
9195 tag
= read_uleb128 (p
, &len
);
9198 /* Tag_compatibility is the only generic GNU attribute defined at
9202 val
= read_uleb128 (p
, &len
);
9204 printf ("flag = %d, vendor = %s\n", val
, p
);
9205 p
+= strlen ((char *) p
) + 1;
9209 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
9210 return display_proc_gnu_attribute (p
, tag
);
9213 type
= 1; /* String. */
9215 type
= 2; /* uleb128. */
9216 printf (" Tag_unknown_%d: ", tag
);
9220 printf ("\"%s\"\n", p
);
9221 p
+= strlen ((char *) p
) + 1;
9225 val
= read_uleb128 (p
, &len
);
9227 printf ("%d (0x%x)\n", val
, val
);
9233 static unsigned char *
9234 display_power_gnu_attribute (unsigned char * p
, int tag
)
9240 if (tag
== Tag_GNU_Power_ABI_FP
)
9242 val
= read_uleb128 (p
, &len
);
9244 printf (" Tag_GNU_Power_ABI_FP: ");
9249 printf ("Hard or soft float\n");
9252 printf ("Hard float\n");
9255 printf ("Soft float\n");
9258 printf ("Single-precision hard float\n");
9261 printf ("??? (%d)\n", val
);
9267 if (tag
== Tag_GNU_Power_ABI_Vector
)
9269 val
= read_uleb128 (p
, &len
);
9271 printf (" Tag_GNU_Power_ABI_Vector: ");
9278 printf ("Generic\n");
9281 printf ("AltiVec\n");
9287 printf ("??? (%d)\n", val
);
9293 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
9295 val
= read_uleb128 (p
, &len
);
9297 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
9307 printf ("Memory\n");
9310 printf ("??? (%d)\n", val
);
9317 type
= 1; /* String. */
9319 type
= 2; /* uleb128. */
9320 printf (" Tag_unknown_%d: ", tag
);
9324 printf ("\"%s\"\n", p
);
9325 p
+= strlen ((char *) p
) + 1;
9329 val
= read_uleb128 (p
, &len
);
9331 printf ("%d (0x%x)\n", val
, val
);
9337 static unsigned char *
9338 display_mips_gnu_attribute (unsigned char * p
, int tag
)
9344 if (tag
== Tag_GNU_MIPS_ABI_FP
)
9346 val
= read_uleb128 (p
, &len
);
9348 printf (" Tag_GNU_MIPS_ABI_FP: ");
9353 printf ("Hard or soft float\n");
9356 printf ("Hard float (-mdouble-float)\n");
9359 printf ("Hard float (-msingle-float)\n");
9362 printf ("Soft float\n");
9365 printf ("64-bit float (-mips32r2 -mfp64)\n");
9368 printf ("??? (%d)\n", val
);
9375 type
= 1; /* String. */
9377 type
= 2; /* uleb128. */
9378 printf (" Tag_unknown_%d: ", tag
);
9382 printf ("\"%s\"\n", p
);
9383 p
+= strlen ((char *) p
) + 1;
9387 val
= read_uleb128 (p
, &len
);
9389 printf ("%d (0x%x)\n", val
, val
);
9396 process_attributes (FILE * file
,
9397 const char * public_name
,
9398 unsigned int proc_type
,
9399 unsigned char * (* display_pub_attribute
) (unsigned char *),
9400 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
9402 Elf_Internal_Shdr
* sect
;
9403 unsigned char * contents
;
9405 unsigned char * end
;
9406 bfd_vma section_len
;
9410 /* Find the section header so that we get the size. */
9411 for (i
= 0, sect
= section_headers
;
9412 i
< elf_header
.e_shnum
;
9415 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
9418 contents
= (unsigned char *) get_data (NULL
, file
, sect
->sh_offset
, 1,
9419 sect
->sh_size
, _("attributes"));
9420 if (contents
== NULL
)
9426 len
= sect
->sh_size
- 1;
9432 bfd_boolean public_section
;
9433 bfd_boolean gnu_section
;
9435 section_len
= byte_get (p
, 4);
9438 if (section_len
> len
)
9440 printf (_("ERROR: Bad section length (%d > %d)\n"),
9441 (int) section_len
, (int) len
);
9446 printf ("Attribute Section: %s\n", p
);
9448 if (public_name
&& streq ((char *) p
, public_name
))
9449 public_section
= TRUE
;
9451 public_section
= FALSE
;
9453 if (streq ((char *) p
, "gnu"))
9456 gnu_section
= FALSE
;
9458 namelen
= strlen ((char *) p
) + 1;
9460 section_len
-= namelen
+ 4;
9462 while (section_len
> 0)
9468 size
= byte_get (p
, 4);
9469 if (size
> section_len
)
9471 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
9472 (int) size
, (int) section_len
);
9476 section_len
-= size
;
9483 printf ("File Attributes\n");
9486 printf ("Section Attributes:");
9489 printf ("Symbol Attributes:");
9495 val
= read_uleb128 (p
, &i
);
9499 printf (" %d", val
);
9504 printf ("Unknown tag: %d\n", tag
);
9505 public_section
= FALSE
;
9512 p
= display_pub_attribute (p
);
9514 else if (gnu_section
)
9517 p
= display_gnu_attribute (p
,
9518 display_proc_gnu_attribute
);
9522 /* ??? Do something sensible, like dump hex. */
9523 printf (" Unknown section contexts\n");
9530 printf (_("Unknown format '%c'\n"), *p
);
9538 process_arm_specific (FILE * file
)
9540 return process_attributes (file
, "aeabi", SHT_ARM_ATTRIBUTES
,
9541 display_arm_attribute
, NULL
);
9545 process_power_specific (FILE * file
)
9547 return process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
9548 display_power_gnu_attribute
);
9551 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
9552 Print the Address, Access and Initial fields of an entry at VMA ADDR
9553 and return the VMA of the next entry. */
9556 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
9559 print_vma (addr
, LONG_HEX
);
9561 if (addr
< pltgot
+ 0xfff0)
9562 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
9564 printf ("%10s", "");
9567 printf ("%*s", is_32bit_elf
? 8 : 16, "<unknown>");
9572 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
9573 print_vma (entry
, LONG_HEX
);
9575 return addr
+ (is_32bit_elf
? 4 : 8);
9578 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
9579 PLTGOT. Print the Address and Initial fields of an entry at VMA
9580 ADDR and return the VMA of the next entry. */
9583 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
9586 print_vma (addr
, LONG_HEX
);
9589 printf ("%*s", is_32bit_elf
? 8 : 16, "<unknown>");
9594 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
9595 print_vma (entry
, LONG_HEX
);
9597 return addr
+ (is_32bit_elf
? 4 : 8);
9601 process_mips_specific (FILE * file
)
9603 Elf_Internal_Dyn
* entry
;
9604 size_t liblist_offset
= 0;
9605 size_t liblistno
= 0;
9606 size_t conflictsno
= 0;
9607 size_t options_offset
= 0;
9608 size_t conflicts_offset
= 0;
9609 size_t pltrelsz
= 0;
9612 bfd_vma mips_pltgot
= 0;
9614 bfd_vma local_gotno
= 0;
9616 bfd_vma symtabno
= 0;
9618 process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
9619 display_mips_gnu_attribute
);
9621 /* We have a lot of special sections. Thanks SGI! */
9622 if (dynamic_section
== NULL
)
9623 /* No information available. */
9626 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
9627 switch (entry
->d_tag
)
9629 case DT_MIPS_LIBLIST
:
9631 = offset_from_vma (file
, entry
->d_un
.d_val
,
9632 liblistno
* sizeof (Elf32_External_Lib
));
9634 case DT_MIPS_LIBLISTNO
:
9635 liblistno
= entry
->d_un
.d_val
;
9637 case DT_MIPS_OPTIONS
:
9638 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
9640 case DT_MIPS_CONFLICT
:
9642 = offset_from_vma (file
, entry
->d_un
.d_val
,
9643 conflictsno
* sizeof (Elf32_External_Conflict
));
9645 case DT_MIPS_CONFLICTNO
:
9646 conflictsno
= entry
->d_un
.d_val
;
9649 pltgot
= entry
->d_un
.d_ptr
;
9651 case DT_MIPS_LOCAL_GOTNO
:
9652 local_gotno
= entry
->d_un
.d_val
;
9654 case DT_MIPS_GOTSYM
:
9655 gotsym
= entry
->d_un
.d_val
;
9657 case DT_MIPS_SYMTABNO
:
9658 symtabno
= entry
->d_un
.d_val
;
9660 case DT_MIPS_PLTGOT
:
9661 mips_pltgot
= entry
->d_un
.d_ptr
;
9664 pltrel
= entry
->d_un
.d_val
;
9667 pltrelsz
= entry
->d_un
.d_val
;
9670 jmprel
= entry
->d_un
.d_ptr
;
9676 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9678 Elf32_External_Lib
* elib
;
9681 elib
= (Elf32_External_Lib
*) get_data (NULL
, file
, liblist_offset
,
9683 sizeof (Elf32_External_Lib
),
9687 printf ("\nSection '.liblist' contains %lu entries:\n",
9688 (unsigned long) liblistno
);
9689 fputs (" Library Time Stamp Checksum Version Flags\n",
9692 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9699 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9700 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9701 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9702 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9703 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9705 tmp
= gmtime (&time
);
9706 snprintf (timebuf
, sizeof (timebuf
),
9707 "%04u-%02u-%02uT%02u:%02u:%02u",
9708 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9709 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9711 printf ("%3lu: ", (unsigned long) cnt
);
9712 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
9713 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
9715 printf ("<corrupt: %9ld>", liblist
.l_name
);
9716 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9719 if (liblist
.l_flags
== 0)
9730 { " EXACT_MATCH", LL_EXACT_MATCH
},
9731 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9732 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9733 { " EXPORTS", LL_EXPORTS
},
9734 { " DELAY_LOAD", LL_DELAY_LOAD
},
9735 { " DELTA", LL_DELTA
}
9737 int flags
= liblist
.l_flags
;
9740 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
9741 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9743 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9744 flags
^= l_flags_vals
[fcnt
].bit
;
9747 printf (" %#x", (unsigned int) flags
);
9757 if (options_offset
!= 0)
9759 Elf_External_Options
* eopt
;
9760 Elf_Internal_Shdr
* sect
= section_headers
;
9761 Elf_Internal_Options
* iopt
;
9762 Elf_Internal_Options
* option
;
9766 /* Find the section header so that we get the size. */
9767 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9770 eopt
= (Elf_External_Options
*) get_data (NULL
, file
, options_offset
, 1,
9771 sect
->sh_size
, _("options"));
9774 iopt
= (Elf_Internal_Options
*)
9775 cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (* iopt
));
9778 error (_("Out of memory\n"));
9785 while (offset
< sect
->sh_size
)
9787 Elf_External_Options
* eoption
;
9789 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9791 option
->kind
= BYTE_GET (eoption
->kind
);
9792 option
->size
= BYTE_GET (eoption
->size
);
9793 option
->section
= BYTE_GET (eoption
->section
);
9794 option
->info
= BYTE_GET (eoption
->info
);
9796 offset
+= option
->size
;
9802 printf (_("\nSection '%s' contains %d entries:\n"),
9803 SECTION_NAME (sect
), cnt
);
9811 switch (option
->kind
)
9814 /* This shouldn't happen. */
9815 printf (" NULL %d %lx", option
->section
, option
->info
);
9818 printf (" REGINFO ");
9819 if (elf_header
.e_machine
== EM_MIPS
)
9822 Elf32_External_RegInfo
* ereg
;
9823 Elf32_RegInfo reginfo
;
9825 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9826 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9827 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9828 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9829 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9830 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9831 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9833 printf ("GPR %08lx GP 0x%lx\n",
9835 (unsigned long) reginfo
.ri_gp_value
);
9836 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9837 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9838 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9843 Elf64_External_RegInfo
* ereg
;
9844 Elf64_Internal_RegInfo reginfo
;
9846 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9847 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9848 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9849 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9850 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9851 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9852 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9854 printf ("GPR %08lx GP 0x",
9855 reginfo
.ri_gprmask
);
9856 printf_vma (reginfo
.ri_gp_value
);
9859 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9860 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9861 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9865 case ODK_EXCEPTIONS
:
9866 fputs (" EXCEPTIONS fpe_min(", stdout
);
9867 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9868 fputs (") fpe_max(", stdout
);
9869 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9870 fputs (")", stdout
);
9872 if (option
->info
& OEX_PAGE0
)
9873 fputs (" PAGE0", stdout
);
9874 if (option
->info
& OEX_SMM
)
9875 fputs (" SMM", stdout
);
9876 if (option
->info
& OEX_FPDBUG
)
9877 fputs (" FPDBUG", stdout
);
9878 if (option
->info
& OEX_DISMISS
)
9879 fputs (" DISMISS", stdout
);
9882 fputs (" PAD ", stdout
);
9883 if (option
->info
& OPAD_PREFIX
)
9884 fputs (" PREFIX", stdout
);
9885 if (option
->info
& OPAD_POSTFIX
)
9886 fputs (" POSTFIX", stdout
);
9887 if (option
->info
& OPAD_SYMBOL
)
9888 fputs (" SYMBOL", stdout
);
9891 fputs (" HWPATCH ", stdout
);
9892 if (option
->info
& OHW_R4KEOP
)
9893 fputs (" R4KEOP", stdout
);
9894 if (option
->info
& OHW_R8KPFETCH
)
9895 fputs (" R8KPFETCH", stdout
);
9896 if (option
->info
& OHW_R5KEOP
)
9897 fputs (" R5KEOP", stdout
);
9898 if (option
->info
& OHW_R5KCVTL
)
9899 fputs (" R5KCVTL", stdout
);
9902 fputs (" FILL ", stdout
);
9903 /* XXX Print content of info word? */
9906 fputs (" TAGS ", stdout
);
9907 /* XXX Print content of info word? */
9910 fputs (" HWAND ", stdout
);
9911 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9912 fputs (" R4KEOP_CHECKED", stdout
);
9913 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9914 fputs (" R4KEOP_CLEAN", stdout
);
9917 fputs (" HWOR ", stdout
);
9918 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9919 fputs (" R4KEOP_CHECKED", stdout
);
9920 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9921 fputs (" R4KEOP_CLEAN", stdout
);
9924 printf (" GP_GROUP %#06lx self-contained %#06lx",
9925 option
->info
& OGP_GROUP
,
9926 (option
->info
& OGP_SELF
) >> 16);
9929 printf (" IDENT %#06lx self-contained %#06lx",
9930 option
->info
& OGP_GROUP
,
9931 (option
->info
& OGP_SELF
) >> 16);
9934 /* This shouldn't happen. */
9935 printf (" %3d ??? %d %lx",
9936 option
->kind
, option
->section
, option
->info
);
9940 len
= sizeof (* eopt
);
9941 while (len
< option
->size
)
9942 if (((char *) option
)[len
] >= ' '
9943 && ((char *) option
)[len
] < 0x7f)
9944 printf ("%c", ((char *) option
)[len
++]);
9946 printf ("\\%03o", ((char *) option
)[len
++]);
9948 fputs ("\n", stdout
);
9956 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9958 Elf32_Conflict
* iconf
;
9961 if (dynamic_symbols
== NULL
)
9963 error (_("conflict list found without a dynamic symbol table\n"));
9967 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
9970 error (_("Out of memory\n"));
9976 Elf32_External_Conflict
* econf32
;
9978 econf32
= (Elf32_External_Conflict
*)
9979 get_data (NULL
, file
, conflicts_offset
, conflictsno
,
9980 sizeof (* econf32
), _("conflict"));
9984 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9985 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9991 Elf64_External_Conflict
* econf64
;
9993 econf64
= (Elf64_External_Conflict
*)
9994 get_data (NULL
, file
, conflicts_offset
, conflictsno
,
9995 sizeof (* econf64
), _("conflict"));
9999 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
10000 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
10005 printf (_("\nSection '.conflict' contains %lu entries:\n"),
10006 (unsigned long) conflictsno
);
10007 puts (_(" Num: Index Value Name"));
10009 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
10011 Elf_Internal_Sym
* psym
= & dynamic_symbols
[iconf
[cnt
]];
10013 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
10014 print_vma (psym
->st_value
, FULL_HEX
);
10016 if (VALID_DYNAMIC_NAME (psym
->st_name
))
10017 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
10019 printf ("<corrupt: %14ld>", psym
->st_name
);
10026 if (pltgot
!= 0 && local_gotno
!= 0)
10028 bfd_vma entry
, local_end
, global_end
;
10030 unsigned char * data
;
10034 addr_size
= (is_32bit_elf
? 4 : 8);
10035 local_end
= pltgot
+ local_gotno
* addr_size
;
10036 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
10038 offset
= offset_from_vma (file
, pltgot
, global_end
- pltgot
);
10039 data
= (unsigned char *) get_data (NULL
, file
, offset
,
10040 global_end
- pltgot
, 1, _("GOT"));
10041 printf (_("\nPrimary GOT:\n"));
10042 printf (_(" Canonical gp value: "));
10043 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
10046 printf (_(" Reserved entries:\n"));
10047 printf (_(" %*s %10s %*s Purpose\n"),
10048 addr_size
* 2, "Address", "Access",
10049 addr_size
* 2, "Initial");
10050 entry
= print_mips_got_entry (data
, pltgot
, entry
);
10051 printf (" Lazy resolver\n");
10053 && (byte_get (data
+ entry
- pltgot
, addr_size
)
10054 >> (addr_size
* 8 - 1)) != 0)
10056 entry
= print_mips_got_entry (data
, pltgot
, entry
);
10057 printf (" Module pointer (GNU extension)\n");
10061 if (entry
< local_end
)
10063 printf (_(" Local entries:\n"));
10064 printf (_(" %*s %10s %*s\n"),
10065 addr_size
* 2, "Address", "Access",
10066 addr_size
* 2, "Initial");
10067 while (entry
< local_end
)
10069 entry
= print_mips_got_entry (data
, pltgot
, entry
);
10075 if (gotsym
< symtabno
)
10079 printf (_(" Global entries:\n"));
10080 printf (_(" %*s %10s %*s %*s %-7s %3s %s\n"),
10081 addr_size
* 2, "Address", "Access",
10082 addr_size
* 2, "Initial",
10083 addr_size
* 2, "Sym.Val.", "Type", "Ndx", "Name");
10084 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
10085 for (i
= gotsym
; i
< symtabno
; i
++)
10087 Elf_Internal_Sym
* psym
;
10089 psym
= dynamic_symbols
+ i
;
10090 entry
= print_mips_got_entry (data
, pltgot
, entry
);
10092 print_vma (psym
->st_value
, LONG_HEX
);
10093 printf (" %-7s %3s ",
10094 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
10095 get_symbol_index_type (psym
->st_shndx
));
10096 if (VALID_DYNAMIC_NAME (psym
->st_name
))
10097 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
10099 printf ("<corrupt: %14ld>", psym
->st_name
);
10109 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
10111 bfd_vma entry
, end
;
10112 size_t offset
, rel_offset
;
10113 unsigned long count
, i
;
10114 unsigned char * data
;
10115 int addr_size
, sym_width
;
10116 Elf_Internal_Rela
* rels
;
10118 rel_offset
= offset_from_vma (file
, jmprel
, pltrelsz
);
10119 if (pltrel
== DT_RELA
)
10121 if (!slurp_rela_relocs (file
, rel_offset
, pltrelsz
, &rels
, &count
))
10126 if (!slurp_rel_relocs (file
, rel_offset
, pltrelsz
, &rels
, &count
))
10130 entry
= mips_pltgot
;
10131 addr_size
= (is_32bit_elf
? 4 : 8);
10132 end
= mips_pltgot
+ (2 + count
) * addr_size
;
10134 offset
= offset_from_vma (file
, mips_pltgot
, end
- mips_pltgot
);
10135 data
= (unsigned char *) get_data (NULL
, file
, offset
, end
- mips_pltgot
,
10137 printf (_("\nPLT GOT:\n\n"));
10138 printf (_(" Reserved entries:\n"));
10139 printf (_(" %*s %*s Purpose\n"),
10140 addr_size
* 2, "Address", addr_size
* 2, "Initial");
10141 entry
= print_mips_pltgot_entry (data
, mips_pltgot
, entry
);
10142 printf (" PLT lazy resolver\n");
10143 entry
= print_mips_pltgot_entry (data
, mips_pltgot
, entry
);
10144 printf (" Module pointer\n");
10147 printf (_(" Entries:\n"));
10148 printf (_(" %*s %*s %*s %-7s %3s %s\n"),
10149 addr_size
* 2, "Address",
10150 addr_size
* 2, "Initial",
10151 addr_size
* 2, "Sym.Val.", "Type", "Ndx", "Name");
10152 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
10153 for (i
= 0; i
< count
; i
++)
10155 Elf_Internal_Sym
* psym
;
10157 psym
= dynamic_symbols
+ get_reloc_symindex (rels
[i
].r_info
);
10158 entry
= print_mips_pltgot_entry (data
, mips_pltgot
, entry
);
10160 print_vma (psym
->st_value
, LONG_HEX
);
10161 printf (" %-7s %3s ",
10162 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
10163 get_symbol_index_type (psym
->st_shndx
));
10164 if (VALID_DYNAMIC_NAME (psym
->st_name
))
10165 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
10167 printf ("<corrupt: %14ld>", psym
->st_name
);
10181 process_gnu_liblist (FILE * file
)
10183 Elf_Internal_Shdr
* section
;
10184 Elf_Internal_Shdr
* string_sec
;
10185 Elf32_External_Lib
* elib
;
10187 size_t strtab_size
;
10194 for (i
= 0, section
= section_headers
;
10195 i
< elf_header
.e_shnum
;
10198 switch (section
->sh_type
)
10200 case SHT_GNU_LIBLIST
:
10201 if (section
->sh_link
>= elf_header
.e_shnum
)
10204 elib
= (Elf32_External_Lib
*)
10205 get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
10210 string_sec
= section_headers
+ section
->sh_link
;
10212 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
, 1,
10213 string_sec
->sh_size
,
10214 _("liblist string table"));
10215 strtab_size
= string_sec
->sh_size
;
10218 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
10224 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
10225 SECTION_NAME (section
),
10226 (unsigned long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
10228 puts (" Library Time Stamp Checksum Version Flags");
10230 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
10238 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
10239 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
10240 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
10241 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
10242 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
10244 tmp
= gmtime (&time
);
10245 snprintf (timebuf
, sizeof (timebuf
),
10246 "%04u-%02u-%02uT%02u:%02u:%02u",
10247 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10248 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10250 printf ("%3lu: ", (unsigned long) cnt
);
10252 printf ("%-20s", liblist
.l_name
< strtab_size
10253 ? strtab
+ liblist
.l_name
: "<corrupt>");
10255 printf ("%-20.20s", liblist
.l_name
< strtab_size
10256 ? strtab
+ liblist
.l_name
: "<corrupt>");
10257 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
10258 liblist
.l_version
, liblist
.l_flags
);
10268 static const char *
10269 get_note_type (unsigned e_type
)
10271 static char buff
[64];
10273 if (elf_header
.e_type
== ET_CORE
)
10277 return _("NT_AUXV (auxiliary vector)");
10279 return _("NT_PRSTATUS (prstatus structure)");
10281 return _("NT_FPREGSET (floating point registers)");
10283 return _("NT_PRPSINFO (prpsinfo structure)");
10284 case NT_TASKSTRUCT
:
10285 return _("NT_TASKSTRUCT (task structure)");
10287 return _("NT_PRXFPREG (user_xfpregs structure)");
10289 return _("NT_PPC_VMX (ppc Altivec registers)");
10291 return _("NT_PPC_VSX (ppc VSX registers)");
10293 return _("NT_PSTATUS (pstatus structure)");
10295 return _("NT_FPREGS (floating point registers)");
10297 return _("NT_PSINFO (psinfo structure)");
10299 return _("NT_LWPSTATUS (lwpstatus_t structure)");
10301 return _("NT_LWPSINFO (lwpsinfo_t structure)");
10302 case NT_WIN32PSTATUS
:
10303 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
10311 return _("NT_VERSION (version)");
10313 return _("NT_ARCH (architecture)");
10318 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
10322 static const char *
10323 get_gnu_elf_note_type (unsigned e_type
)
10325 static char buff
[64];
10329 case NT_GNU_ABI_TAG
:
10330 return _("NT_GNU_ABI_TAG (ABI version tag)");
10332 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
10333 case NT_GNU_BUILD_ID
:
10334 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
10335 case NT_GNU_GOLD_VERSION
:
10336 return _("NT_GNU_GOLD_VERSION (gold version)");
10341 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
10345 static const char *
10346 get_netbsd_elfcore_note_type (unsigned e_type
)
10348 static char buff
[64];
10350 if (e_type
== NT_NETBSDCORE_PROCINFO
)
10352 /* NetBSD core "procinfo" structure. */
10353 return _("NetBSD procinfo structure");
10356 /* As of Jan 2002 there are no other machine-independent notes
10357 defined for NetBSD core files. If the note type is less
10358 than the start of the machine-dependent note types, we don't
10361 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
10363 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
10367 switch (elf_header
.e_machine
)
10369 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
10370 and PT_GETFPREGS == mach+2. */
10375 case EM_SPARC32PLUS
:
10379 case NT_NETBSDCORE_FIRSTMACH
+0:
10380 return _("PT_GETREGS (reg structure)");
10381 case NT_NETBSDCORE_FIRSTMACH
+2:
10382 return _("PT_GETFPREGS (fpreg structure)");
10388 /* On all other arch's, PT_GETREGS == mach+1 and
10389 PT_GETFPREGS == mach+3. */
10393 case NT_NETBSDCORE_FIRSTMACH
+1:
10394 return _("PT_GETREGS (reg structure)");
10395 case NT_NETBSDCORE_FIRSTMACH
+3:
10396 return _("PT_GETFPREGS (fpreg structure)");
10402 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
10403 e_type
- NT_NETBSDCORE_FIRSTMACH
);
10407 /* Note that by the ELF standard, the name field is already null byte
10408 terminated, and namesz includes the terminating null byte.
10409 I.E. the value of namesz for the name "FSF" is 4.
10411 If the value of namesz is zero, there is no name present. */
10413 process_note (Elf_Internal_Note
* pnote
)
10415 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
10418 if (pnote
->namesz
== 0)
10419 /* If there is no note name, then use the default set of
10420 note type strings. */
10421 nt
= get_note_type (pnote
->type
);
10423 else if (const_strneq (pnote
->namedata
, "GNU"))
10424 /* GNU-specific object file notes. */
10425 nt
= get_gnu_elf_note_type (pnote
->type
);
10427 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
10428 /* NetBSD-specific core file notes. */
10429 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
10431 else if (strneq (pnote
->namedata
, "SPU/", 4))
10433 /* SPU-specific core file notes. */
10434 nt
= pnote
->namedata
+ 4;
10439 /* Don't recognize this note name; just use the default set of
10440 note type strings. */
10441 nt
= get_note_type (pnote
->type
);
10443 printf (" %s\t\t0x%08lx\t%s\n", name
, pnote
->descsz
, nt
);
10449 process_corefile_note_segment (FILE * file
, bfd_vma offset
, bfd_vma length
)
10451 Elf_External_Note
* pnotes
;
10452 Elf_External_Note
* external
;
10458 pnotes
= (Elf_External_Note
*) get_data (NULL
, file
, offset
, 1, length
,
10465 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
10466 (unsigned long) offset
, (unsigned long) length
);
10467 printf (_(" Owner\t\tData size\tDescription\n"));
10469 while (external
< (Elf_External_Note
*) ((char *) pnotes
+ length
))
10471 Elf_External_Note
* next
;
10472 Elf_Internal_Note inote
;
10473 char * temp
= NULL
;
10475 inote
.type
= BYTE_GET (external
->type
);
10476 inote
.namesz
= BYTE_GET (external
->namesz
);
10477 inote
.namedata
= external
->name
;
10478 inote
.descsz
= BYTE_GET (external
->descsz
);
10479 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
10480 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
10482 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
10484 if (((char *) next
) > (((char *) pnotes
) + length
))
10486 warn (_("corrupt note found at offset %lx into core notes\n"),
10487 (unsigned long) ((char *) external
- (char *) pnotes
));
10488 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
10489 inote
.type
, inote
.namesz
, inote
.descsz
);
10495 /* Verify that name is null terminated. It appears that at least
10496 one version of Linux (RedHat 6.0) generates corefiles that don't
10497 comply with the ELF spec by failing to include the null byte in
10499 if (inote
.namedata
[inote
.namesz
] != '\0')
10501 temp
= (char *) malloc (inote
.namesz
+ 1);
10505 error (_("Out of memory\n"));
10510 strncpy (temp
, inote
.namedata
, inote
.namesz
);
10511 temp
[inote
.namesz
] = 0;
10513 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
10514 inote
.namedata
= temp
;
10517 res
&= process_note (& inote
);
10532 process_corefile_note_segments (FILE * file
)
10534 Elf_Internal_Phdr
* segment
;
10538 if (! get_program_headers (file
))
10541 for (i
= 0, segment
= program_headers
;
10542 i
< elf_header
.e_phnum
;
10545 if (segment
->p_type
== PT_NOTE
)
10546 res
&= process_corefile_note_segment (file
,
10547 (bfd_vma
) segment
->p_offset
,
10548 (bfd_vma
) segment
->p_filesz
);
10555 process_note_sections (FILE * file
)
10557 Elf_Internal_Shdr
* section
;
10561 for (i
= 0, section
= section_headers
;
10562 i
< elf_header
.e_shnum
;
10564 if (section
->sh_type
== SHT_NOTE
)
10565 res
&= process_corefile_note_segment (file
,
10566 (bfd_vma
) section
->sh_offset
,
10567 (bfd_vma
) section
->sh_size
);
10573 process_notes (FILE * file
)
10575 /* If we have not been asked to display the notes then do nothing. */
10579 if (elf_header
.e_type
!= ET_CORE
)
10580 return process_note_sections (file
);
10582 /* No program headers means no NOTE segment. */
10583 if (elf_header
.e_phnum
> 0)
10584 return process_corefile_note_segments (file
);
10586 printf (_("No note segments present in the core file.\n"));
10591 process_arch_specific (FILE * file
)
10596 switch (elf_header
.e_machine
)
10599 return process_arm_specific (file
);
10601 case EM_MIPS_RS3_LE
:
10602 return process_mips_specific (file
);
10605 return process_power_specific (file
);
10614 get_file_header (FILE * file
)
10616 /* Read in the identity array. */
10617 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
10620 /* Determine how to read the rest of the header. */
10621 switch (elf_header
.e_ident
[EI_DATA
])
10623 default: /* fall through */
10624 case ELFDATANONE
: /* fall through */
10626 byte_get
= byte_get_little_endian
;
10627 byte_put
= byte_put_little_endian
;
10630 byte_get
= byte_get_big_endian
;
10631 byte_put
= byte_put_big_endian
;
10635 /* For now we only support 32 bit and 64 bit ELF files. */
10636 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
10638 /* Read in the rest of the header. */
10641 Elf32_External_Ehdr ehdr32
;
10643 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
10646 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
10647 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
10648 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
10649 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
10650 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
10651 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
10652 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
10653 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
10654 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
10655 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
10656 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
10657 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
10658 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
10662 Elf64_External_Ehdr ehdr64
;
10664 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10665 we will not be able to cope with the 64bit data found in
10666 64 ELF files. Detect this now and abort before we start
10667 overwriting things. */
10668 if (sizeof (bfd_vma
) < 8)
10670 error (_("This instance of readelf has been built without support for a\n\
10671 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10675 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
10678 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
10679 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
10680 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
10681 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
10682 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
10683 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
10684 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
10685 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
10686 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
10687 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
10688 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
10689 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
10690 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
10693 if (elf_header
.e_shoff
)
10695 /* There may be some extensions in the first section header. Don't
10696 bomb if we can't read it. */
10698 get_32bit_section_headers (file
, 1);
10700 get_64bit_section_headers (file
, 1);
10706 /* Process one ELF object file according to the command line options.
10707 This file may actually be stored in an archive. The file is
10708 positioned at the start of the ELF object. */
10711 process_object (char * file_name
, FILE * file
)
10715 if (! get_file_header (file
))
10717 error (_("%s: Failed to read file header\n"), file_name
);
10721 /* Initialise per file variables. */
10722 for (i
= ARRAY_SIZE (version_info
); i
--;)
10723 version_info
[i
] = 0;
10725 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
10726 dynamic_info
[i
] = 0;
10728 /* Process the file. */
10730 printf (_("\nFile: %s\n"), file_name
);
10732 /* Initialise the dump_sects array from the cmdline_dump_sects array.
10733 Note we do this even if cmdline_dump_sects is empty because we
10734 must make sure that the dump_sets array is zeroed out before each
10735 object file is processed. */
10736 if (num_dump_sects
> num_cmdline_dump_sects
)
10737 memset (dump_sects
, 0, num_dump_sects
* sizeof (* dump_sects
));
10739 if (num_cmdline_dump_sects
> 0)
10741 if (num_dump_sects
== 0)
10742 /* A sneaky way of allocating the dump_sects array. */
10743 request_dump_bynumber (num_cmdline_dump_sects
, 0);
10745 assert (num_dump_sects
>= num_cmdline_dump_sects
);
10746 memcpy (dump_sects
, cmdline_dump_sects
,
10747 num_cmdline_dump_sects
* sizeof (* dump_sects
));
10750 if (! process_file_header ())
10753 if (! process_section_headers (file
))
10755 /* Without loaded section headers we cannot process lots of
10757 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10759 if (! do_using_dynamic
)
10760 do_syms
= do_reloc
= 0;
10763 if (! process_section_groups (file
))
10765 /* Without loaded section groups we cannot process unwind. */
10769 if (process_program_headers (file
))
10770 process_dynamic_section (file
);
10772 process_relocs (file
);
10774 process_unwind (file
);
10776 process_symbol_table (file
);
10778 process_syminfo (file
);
10780 process_version_sections (file
);
10782 process_section_contents (file
);
10784 process_notes (file
);
10786 process_gnu_liblist (file
);
10788 process_arch_specific (file
);
10790 if (program_headers
)
10792 free (program_headers
);
10793 program_headers
= NULL
;
10796 if (section_headers
)
10798 free (section_headers
);
10799 section_headers
= NULL
;
10804 free (string_table
);
10805 string_table
= NULL
;
10806 string_table_length
= 0;
10809 if (dynamic_strings
)
10811 free (dynamic_strings
);
10812 dynamic_strings
= NULL
;
10813 dynamic_strings_length
= 0;
10816 if (dynamic_symbols
)
10818 free (dynamic_symbols
);
10819 dynamic_symbols
= NULL
;
10820 num_dynamic_syms
= 0;
10823 if (dynamic_syminfo
)
10825 free (dynamic_syminfo
);
10826 dynamic_syminfo
= NULL
;
10829 if (section_headers_groups
)
10831 free (section_headers_groups
);
10832 section_headers_groups
= NULL
;
10835 if (section_groups
)
10837 struct group_list
* g
;
10838 struct group_list
* next
;
10840 for (i
= 0; i
< group_count
; i
++)
10842 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
10849 free (section_groups
);
10850 section_groups
= NULL
;
10853 free_debug_memory ();
10858 /* Return the path name for a proxy entry in a thin archive, adjusted relative
10859 to the path name of the thin archive itself if necessary. Always returns
10860 a pointer to malloc'ed memory. */
10863 adjust_relative_path (char * file_name
, char * name
, int name_len
)
10865 char * member_file_name
;
10866 const char * base_name
= lbasename (file_name
);
10868 /* This is a proxy entry for a thin archive member.
10869 If the extended name table contains an absolute path
10870 name, or if the archive is in the current directory,
10871 use the path name as given. Otherwise, we need to
10872 find the member relative to the directory where the
10873 archive is located. */
10874 if (IS_ABSOLUTE_PATH (name
) || base_name
== file_name
)
10876 member_file_name
= (char *) malloc (name_len
+ 1);
10877 if (member_file_name
== NULL
)
10879 error (_("Out of memory\n"));
10882 memcpy (member_file_name
, name
, name_len
);
10883 member_file_name
[name_len
] = '\0';
10887 /* Concatenate the path components of the archive file name
10888 to the relative path name from the extended name table. */
10889 size_t prefix_len
= base_name
- file_name
;
10890 member_file_name
= (char *) malloc (prefix_len
+ name_len
+ 1);
10891 if (member_file_name
== NULL
)
10893 error (_("Out of memory\n"));
10896 memcpy (member_file_name
, file_name
, prefix_len
);
10897 memcpy (member_file_name
+ prefix_len
, name
, name_len
);
10898 member_file_name
[prefix_len
+ name_len
] = '\0';
10900 return member_file_name
;
10903 /* Structure to hold information about an archive file. */
10905 struct archive_info
10907 char * file_name
; /* Archive file name. */
10908 FILE * file
; /* Open file descriptor. */
10909 unsigned long index_num
; /* Number of symbols in table. */
10910 unsigned long * index_array
; /* The array of member offsets. */
10911 char * sym_table
; /* The symbol table. */
10912 unsigned long sym_size
; /* Size of the symbol table. */
10913 char * longnames
; /* The long file names table. */
10914 unsigned long longnames_size
; /* Size of the long file names table. */
10915 unsigned long nested_member_origin
; /* Origin in the nested archive of the current member. */
10916 unsigned long next_arhdr_offset
; /* Offset of the next archive header. */
10917 bfd_boolean is_thin_archive
; /* TRUE if this is a thin archive. */
10918 struct ar_hdr arhdr
; /* Current archive header. */
10921 /* Read the symbol table and long-name table from an archive. */
10924 setup_archive (struct archive_info
* arch
, char * file_name
, FILE * file
,
10925 bfd_boolean is_thin_archive
, bfd_boolean read_symbols
)
10928 unsigned long size
;
10930 arch
->file_name
= strdup (file_name
);
10932 arch
->index_num
= 0;
10933 arch
->index_array
= NULL
;
10934 arch
->sym_table
= NULL
;
10935 arch
->sym_size
= 0;
10936 arch
->longnames
= NULL
;
10937 arch
->longnames_size
= 0;
10938 arch
->nested_member_origin
= 0;
10939 arch
->is_thin_archive
= is_thin_archive
;
10940 arch
->next_arhdr_offset
= SARMAG
;
10942 /* Read the first archive member header. */
10943 if (fseek (file
, SARMAG
, SEEK_SET
) != 0)
10945 error (_("%s: failed to seek to first archive header\n"), file_name
);
10948 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, file
);
10949 if (got
!= sizeof arch
->arhdr
)
10954 error (_("%s: failed to read archive header\n"), file_name
);
10958 /* See if this is the archive symbol table. */
10959 if (const_strneq (arch
->arhdr
.ar_name
, "/ ")
10960 || const_strneq (arch
->arhdr
.ar_name
, "/SYM64/ "))
10962 size
= strtoul (arch
->arhdr
.ar_size
, NULL
, 10);
10963 size
= size
+ (size
& 1);
10965 arch
->next_arhdr_offset
+= sizeof arch
->arhdr
+ size
;
10970 /* A buffer used to hold numbers read in from an archive index.
10971 These are always 4 bytes long and stored in big-endian format. */
10972 #define SIZEOF_AR_INDEX_NUMBERS 4
10973 unsigned char integer_buffer
[SIZEOF_AR_INDEX_NUMBERS
];
10974 unsigned char * index_buffer
;
10976 /* Check the size of the archive index. */
10977 if (size
< SIZEOF_AR_INDEX_NUMBERS
)
10979 error (_("%s: the archive index is empty\n"), file_name
);
10983 /* Read the numer of entries in the archive index. */
10984 got
= fread (integer_buffer
, 1, sizeof integer_buffer
, file
);
10985 if (got
!= sizeof (integer_buffer
))
10987 error (_("%s: failed to read archive index\n"), file_name
);
10990 arch
->index_num
= byte_get_big_endian (integer_buffer
, sizeof integer_buffer
);
10991 size
-= SIZEOF_AR_INDEX_NUMBERS
;
10993 /* Read in the archive index. */
10994 if (size
< arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
)
10996 error (_("%s: the archive index is supposed to have %ld entries, but the size in the header is too small\n"),
10997 file_name
, arch
->index_num
);
11000 index_buffer
= (unsigned char *)
11001 malloc (arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
);
11002 if (index_buffer
== NULL
)
11004 error (_("Out of memory whilst trying to read archive symbol index\n"));
11007 got
= fread (index_buffer
, SIZEOF_AR_INDEX_NUMBERS
, arch
->index_num
, file
);
11008 if (got
!= arch
->index_num
)
11010 free (index_buffer
);
11011 error (_("%s: failed to read archive index\n"), file_name
);
11014 size
-= arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
;
11016 /* Convert the index numbers into the host's numeric format. */
11017 arch
->index_array
= (long unsigned int *)
11018 malloc (arch
->index_num
* sizeof (* arch
->index_array
));
11019 if (arch
->index_array
== NULL
)
11021 free (index_buffer
);
11022 error (_("Out of memory whilst trying to convert the archive symbol index\n"));
11026 for (i
= 0; i
< arch
->index_num
; i
++)
11027 arch
->index_array
[i
] = byte_get_big_endian ((unsigned char *) (index_buffer
+ (i
* SIZEOF_AR_INDEX_NUMBERS
)),
11028 SIZEOF_AR_INDEX_NUMBERS
);
11029 free (index_buffer
);
11031 /* The remaining space in the header is taken up by the symbol table. */
11034 error (_("%s: the archive has an index but no symbols\n"), file_name
);
11037 arch
->sym_table
= (char *) malloc (size
);
11038 arch
->sym_size
= size
;
11039 if (arch
->sym_table
== NULL
)
11041 error (_("Out of memory whilst trying to read archive index symbol table\n"));
11044 got
= fread (arch
->sym_table
, 1, size
, file
);
11047 error (_("%s: failed to read archive index symbol table\n"), file_name
);
11053 if (fseek (file
, size
, SEEK_CUR
) != 0)
11055 error (_("%s: failed to skip archive symbol table\n"), file_name
);
11060 /* Read the next archive header. */
11061 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, file
);
11062 if (got
!= sizeof arch
->arhdr
)
11066 error (_("%s: failed to read archive header following archive index\n"), file_name
);
11070 else if (read_symbols
)
11071 printf (_("%s has no archive index\n"), file_name
);
11073 if (const_strneq (arch
->arhdr
.ar_name
, "// "))
11075 /* This is the archive string table holding long member names. */
11076 arch
->longnames_size
= strtoul (arch
->arhdr
.ar_size
, NULL
, 10);
11077 arch
->next_arhdr_offset
+= sizeof arch
->arhdr
+ arch
->longnames_size
;
11079 arch
->longnames
= (char *) malloc (arch
->longnames_size
);
11080 if (arch
->longnames
== NULL
)
11082 error (_("Out of memory reading long symbol names in archive\n"));
11086 if (fread (arch
->longnames
, arch
->longnames_size
, 1, file
) != 1)
11088 free (arch
->longnames
);
11089 arch
->longnames
= NULL
;
11090 error (_("%s: failed to read long symbol name string table\n"), file_name
);
11094 if ((arch
->longnames_size
& 1) != 0)
11101 /* Release the memory used for the archive information. */
11104 release_archive (struct archive_info
* arch
)
11106 if (arch
->file_name
!= NULL
)
11107 free (arch
->file_name
);
11108 if (arch
->index_array
!= NULL
)
11109 free (arch
->index_array
);
11110 if (arch
->sym_table
!= NULL
)
11111 free (arch
->sym_table
);
11112 if (arch
->longnames
!= NULL
)
11113 free (arch
->longnames
);
11116 /* Open and setup a nested archive, if not already open. */
11119 setup_nested_archive (struct archive_info
* nested_arch
, char * member_file_name
)
11121 FILE * member_file
;
11123 /* Have we already setup this archive? */
11124 if (nested_arch
->file_name
!= NULL
11125 && streq (nested_arch
->file_name
, member_file_name
))
11128 /* Close previous file and discard cached information. */
11129 if (nested_arch
->file
!= NULL
)
11130 fclose (nested_arch
->file
);
11131 release_archive (nested_arch
);
11133 member_file
= fopen (member_file_name
, "rb");
11134 if (member_file
== NULL
)
11136 return setup_archive (nested_arch
, member_file_name
, member_file
, FALSE
, FALSE
);
11140 get_archive_member_name_at (struct archive_info
* arch
,
11141 unsigned long offset
,
11142 struct archive_info
* nested_arch
);
11144 /* Get the name of an archive member from the current archive header.
11145 For simple names, this will modify the ar_name field of the current
11146 archive header. For long names, it will return a pointer to the
11147 longnames table. For nested archives, it will open the nested archive
11148 and get the name recursively. NESTED_ARCH is a single-entry cache so
11149 we don't keep rereading the same information from a nested archive. */
11152 get_archive_member_name (struct archive_info
* arch
,
11153 struct archive_info
* nested_arch
)
11155 unsigned long j
, k
;
11157 if (arch
->arhdr
.ar_name
[0] == '/')
11159 /* We have a long name. */
11161 char * member_file_name
;
11162 char * member_name
;
11164 arch
->nested_member_origin
= 0;
11165 k
= j
= strtoul (arch
->arhdr
.ar_name
+ 1, &endp
, 10);
11166 if (arch
->is_thin_archive
&& endp
!= NULL
&& * endp
== ':')
11167 arch
->nested_member_origin
= strtoul (endp
+ 1, NULL
, 10);
11169 while ((j
< arch
->longnames_size
)
11170 && (arch
->longnames
[j
] != '\n')
11171 && (arch
->longnames
[j
] != '\0'))
11173 if (arch
->longnames
[j
-1] == '/')
11175 arch
->longnames
[j
] = '\0';
11177 if (!arch
->is_thin_archive
|| arch
->nested_member_origin
== 0)
11178 return arch
->longnames
+ k
;
11180 /* This is a proxy for a member of a nested archive.
11181 Find the name of the member in that archive. */
11182 member_file_name
= adjust_relative_path (arch
->file_name
, arch
->longnames
+ k
, j
- k
);
11183 if (member_file_name
!= NULL
11184 && setup_nested_archive (nested_arch
, member_file_name
) == 0
11185 && (member_name
= get_archive_member_name_at (nested_arch
, arch
->nested_member_origin
, NULL
)) != NULL
)
11187 free (member_file_name
);
11188 return member_name
;
11190 free (member_file_name
);
11192 /* Last resort: just return the name of the nested archive. */
11193 return arch
->longnames
+ k
;
11196 /* We have a normal (short) name. */
11198 while ((arch
->arhdr
.ar_name
[j
] != '/') && (j
< 16))
11200 arch
->arhdr
.ar_name
[j
] = '\0';
11201 return arch
->arhdr
.ar_name
;
11204 /* Get the name of an archive member at a given OFFSET within an archive ARCH. */
11207 get_archive_member_name_at (struct archive_info
* arch
,
11208 unsigned long offset
,
11209 struct archive_info
* nested_arch
)
11213 if (fseek (arch
->file
, offset
, SEEK_SET
) != 0)
11215 error (_("%s: failed to seek to next file name\n"), arch
->file_name
);
11218 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, arch
->file
);
11219 if (got
!= sizeof arch
->arhdr
)
11221 error (_("%s: failed to read archive header\n"), arch
->file_name
);
11224 if (memcmp (arch
->arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
11226 error (_("%s: did not find a valid archive header\n"), arch
->file_name
);
11230 return get_archive_member_name (arch
, nested_arch
);
11233 /* Construct a string showing the name of the archive member, qualified
11234 with the name of the containing archive file. For thin archives, we
11235 use square brackets to denote the indirection. For nested archives,
11236 we show the qualified name of the external member inside the square
11237 brackets (e.g., "thin.a[normal.a(foo.o)]"). */
11240 make_qualified_name (struct archive_info
* arch
,
11241 struct archive_info
* nested_arch
,
11242 char * member_name
)
11247 len
= strlen (arch
->file_name
) + strlen (member_name
) + 3;
11248 if (arch
->is_thin_archive
&& arch
->nested_member_origin
!= 0)
11249 len
+= strlen (nested_arch
->file_name
) + 2;
11251 name
= (char *) malloc (len
);
11254 error (_("Out of memory\n"));
11258 if (arch
->is_thin_archive
&& arch
->nested_member_origin
!= 0)
11259 snprintf (name
, len
, "%s[%s(%s)]", arch
->file_name
, nested_arch
->file_name
, member_name
);
11260 else if (arch
->is_thin_archive
)
11261 snprintf (name
, len
, "%s[%s]", arch
->file_name
, member_name
);
11263 snprintf (name
, len
, "%s(%s)", arch
->file_name
, member_name
);
11268 /* Process an ELF archive.
11269 On entry the file is positioned just after the ARMAG string. */
11272 process_archive (char * file_name
, FILE * file
, bfd_boolean is_thin_archive
)
11274 struct archive_info arch
;
11275 struct archive_info nested_arch
;
11277 size_t file_name_size
;
11282 /* The ARCH structure is used to hold information about this archive. */
11283 arch
.file_name
= NULL
;
11285 arch
.index_array
= NULL
;
11286 arch
.sym_table
= NULL
;
11287 arch
.longnames
= NULL
;
11289 /* The NESTED_ARCH structure is used as a single-item cache of information
11290 about a nested archive (when members of a thin archive reside within
11291 another regular archive file). */
11292 nested_arch
.file_name
= NULL
;
11293 nested_arch
.file
= NULL
;
11294 nested_arch
.index_array
= NULL
;
11295 nested_arch
.sym_table
= NULL
;
11296 nested_arch
.longnames
= NULL
;
11298 if (setup_archive (&arch
, file_name
, file
, is_thin_archive
, do_archive_index
) != 0)
11304 if (do_archive_index
)
11306 if (arch
.sym_table
== NULL
)
11307 error (_("%s: unable to dump the index as none was found\n"), file_name
);
11311 unsigned long current_pos
;
11313 printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
11314 file_name
, arch
.index_num
, arch
.sym_size
);
11315 current_pos
= ftell (file
);
11317 for (i
= l
= 0; i
< arch
.index_num
; i
++)
11319 if ((i
== 0) || ((i
> 0) && (arch
.index_array
[i
] != arch
.index_array
[i
- 1])))
11321 char * member_name
;
11323 member_name
= get_archive_member_name_at (&arch
, arch
.index_array
[i
], &nested_arch
);
11325 if (member_name
!= NULL
)
11327 char * qualified_name
= make_qualified_name (&arch
, &nested_arch
, member_name
);
11329 if (qualified_name
!= NULL
)
11331 printf (_("Binary %s contains:\n"), qualified_name
);
11332 free (qualified_name
);
11337 if (l
>= arch
.sym_size
)
11339 error (_("%s: end of the symbol table reached before the end of the index\n"),
11343 printf ("\t%s\n", arch
.sym_table
+ l
);
11344 l
+= strlen (arch
.sym_table
+ l
) + 1;
11349 if (l
< arch
.sym_size
)
11350 error (_("%s: symbols remain in the index symbol table, but without corresponding entries in the index table\n"),
11353 if (fseek (file
, current_pos
, SEEK_SET
) != 0)
11355 error (_("%s: failed to seek back to start of object files in the archive\n"), file_name
);
11361 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
11362 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
11363 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
11364 && !do_section_groups
)
11366 ret
= 0; /* Archive index only. */
11371 file_name_size
= strlen (file_name
);
11378 char * qualified_name
;
11380 /* Read the next archive header. */
11381 if (fseek (file
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
11383 error (_("%s: failed to seek to next archive header\n"), file_name
);
11386 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, file
);
11387 if (got
!= sizeof arch
.arhdr
)
11391 error (_("%s: failed to read archive header\n"), file_name
);
11395 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
11397 error (_("%s: did not find a valid archive header\n"), arch
.file_name
);
11402 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
11404 archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
11405 if (archive_file_size
& 01)
11406 ++archive_file_size
;
11408 name
= get_archive_member_name (&arch
, &nested_arch
);
11411 error (_("%s: bad archive file name\n"), file_name
);
11415 namelen
= strlen (name
);
11417 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
11418 if (qualified_name
== NULL
)
11420 error (_("%s: bad archive file name\n"), file_name
);
11425 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
11427 /* This is a proxy for an external member of a thin archive. */
11428 FILE * member_file
;
11429 char * member_file_name
= adjust_relative_path (file_name
, name
, namelen
);
11430 if (member_file_name
== NULL
)
11436 member_file
= fopen (member_file_name
, "rb");
11437 if (member_file
== NULL
)
11439 error (_("Input file '%s' is not readable.\n"), member_file_name
);
11440 free (member_file_name
);
11445 archive_file_offset
= arch
.nested_member_origin
;
11447 ret
|= process_object (qualified_name
, member_file
);
11449 fclose (member_file
);
11450 free (member_file_name
);
11452 else if (is_thin_archive
)
11454 /* This is a proxy for a member of a nested archive. */
11455 archive_file_offset
= arch
.nested_member_origin
+ sizeof arch
.arhdr
;
11457 /* The nested archive file will have been opened and setup by
11458 get_archive_member_name. */
11459 if (fseek (nested_arch
.file
, archive_file_offset
, SEEK_SET
) != 0)
11461 error (_("%s: failed to seek to archive member.\n"), nested_arch
.file_name
);
11466 ret
|= process_object (qualified_name
, nested_arch
.file
);
11470 archive_file_offset
= arch
.next_arhdr_offset
;
11471 arch
.next_arhdr_offset
+= archive_file_size
;
11473 ret
|= process_object (qualified_name
, file
);
11476 free (qualified_name
);
11480 if (nested_arch
.file
!= NULL
)
11481 fclose (nested_arch
.file
);
11482 release_archive (&nested_arch
);
11483 release_archive (&arch
);
11489 process_file (char * file_name
)
11492 struct stat statbuf
;
11493 char armag
[SARMAG
];
11496 if (stat (file_name
, &statbuf
) < 0)
11498 if (errno
== ENOENT
)
11499 error (_("'%s': No such file\n"), file_name
);
11501 error (_("Could not locate '%s'. System error message: %s\n"),
11502 file_name
, strerror (errno
));
11506 if (! S_ISREG (statbuf
.st_mode
))
11508 error (_("'%s' is not an ordinary file\n"), file_name
);
11512 file
= fopen (file_name
, "rb");
11515 error (_("Input file '%s' is not readable.\n"), file_name
);
11519 if (fread (armag
, SARMAG
, 1, file
) != 1)
11521 error (_("%s: Failed to read file's magic number\n"), file_name
);
11526 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
11527 ret
= process_archive (file_name
, file
, FALSE
);
11528 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
11529 ret
= process_archive (file_name
, file
, TRUE
);
11532 if (do_archive_index
)
11533 error (_("File %s is not an archive so its index cannot be displayed.\n"),
11537 archive_file_size
= archive_file_offset
= 0;
11538 ret
= process_object (file_name
, file
);
11546 #ifdef SUPPORT_DISASSEMBLY
11547 /* Needed by the i386 disassembler. For extra credit, someone could
11548 fix this so that we insert symbolic addresses here, esp for GOT/PLT
11552 print_address (unsigned int addr
, FILE * outfile
)
11554 fprintf (outfile
,"0x%8.8x", addr
);
11557 /* Needed by the i386 disassembler. */
11559 db_task_printsym (unsigned int addr
)
11561 print_address (addr
, stderr
);
11566 main (int argc
, char ** argv
)
11570 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
11571 setlocale (LC_MESSAGES
, "");
11573 #if defined (HAVE_SETLOCALE)
11574 setlocale (LC_CTYPE
, "");
11576 bindtextdomain (PACKAGE
, LOCALEDIR
);
11577 textdomain (PACKAGE
);
11579 expandargv (&argc
, &argv
);
11581 parse_args (argc
, argv
);
11583 if (num_dump_sects
> 0)
11585 /* Make a copy of the dump_sects array. */
11586 cmdline_dump_sects
= (dump_type
*)
11587 malloc (num_dump_sects
* sizeof (* dump_sects
));
11588 if (cmdline_dump_sects
== NULL
)
11589 error (_("Out of memory allocating dump request table.\n"));
11592 memcpy (cmdline_dump_sects
, dump_sects
,
11593 num_dump_sects
* sizeof (* dump_sects
));
11594 num_cmdline_dump_sects
= num_dump_sects
;
11598 if (optind
< (argc
- 1))
11602 while (optind
< argc
)
11603 err
|= process_file (argv
[optind
++]);
11605 if (dump_sects
!= NULL
)
11607 if (cmdline_dump_sects
!= NULL
)
11608 free (cmdline_dump_sects
);