1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 Free Software Foundation, Inc.
6 Originally developed by Eric Youngdale <eric@andante.jic.com>
7 Modifications by Nick Clifton <nickc@redhat.com>
9 This file is part of GNU Binutils.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
26 /* The difference between readelf and objdump:
28 Both programs are capable of displaying the contents of ELF format files,
29 so why does the binutils project have two file dumpers ?
31 The reason is that objdump sees an ELF file through a BFD filter of the
32 world; if BFD has a bug where, say, it disagrees about a machine constant
33 in e_flags, then the odds are good that it will remain internally
34 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
35 GAS sees it the BFD way. There was need for a tool to go find out what
36 the file actually says.
38 This is why the readelf program does not link against the BFD library - it
39 exists as an independent program to help verify the correct working of BFD.
41 There is also the case that readelf can provide more information about an
42 ELF file than is provided by objdump. In particular it can display DWARF
43 debugging information which (at the moment) objdump cannot. */
55 /* Define BFD64 here, even if our default architecture is 32 bit ELF
56 as this will allow us to read in and parse 64bit and 32bit ELF files.
57 Only do this if we believe that the compiler can support a 64 bit
58 data type. For now we only rely on GCC being able to do this. */
66 #include "elf/common.h"
67 #include "elf/external.h"
68 #include "elf/internal.h"
71 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
72 we can obtain the H8 reloc numbers. We need these for the
73 get_reloc_size() function. We include h8.h again after defining
74 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
79 /* Undo the effects of #including reloc-macros.h. */
81 #undef START_RELOC_NUMBERS
85 #undef END_RELOC_NUMBERS
86 #undef _RELOC_MACROS_H
88 /* The following headers use the elf/reloc-macros.h file to
89 automatically generate relocation recognition functions
90 such as elf_mips_reloc_type() */
92 #define RELOC_MACROS_GEN_FUNC
94 #include "elf/alpha.h"
100 #include "elf/cris.h"
102 #include "elf/d10v.h"
103 #include "elf/d30v.h"
105 #include "elf/fr30.h"
108 #include "elf/hppa.h"
109 #include "elf/i386.h"
110 #include "elf/i370.h"
111 #include "elf/i860.h"
112 #include "elf/i960.h"
113 #include "elf/ia64.h"
114 #include "elf/ip2k.h"
115 #include "elf/lm32.h"
116 #include "elf/iq2000.h"
117 #include "elf/m32c.h"
118 #include "elf/m32r.h"
119 #include "elf/m68k.h"
120 #include "elf/m68hc11.h"
121 #include "elf/mcore.h"
123 #include "elf/microblaze.h"
124 #include "elf/mips.h"
125 #include "elf/mmix.h"
126 #include "elf/mn10200.h"
127 #include "elf/mn10300.h"
129 #include "elf/msp430.h"
130 #include "elf/or32.h"
133 #include "elf/ppc64.h"
135 #include "elf/s390.h"
136 #include "elf/score.h"
138 #include "elf/sparc.h"
140 #include "elf/v850.h"
142 #include "elf/x86-64.h"
143 #include "elf/xc16x.h"
144 #include "elf/xstormy16.h"
145 #include "elf/xtensa.h"
150 #include "libiberty.h"
151 #include "safe-ctype.h"
152 #include "filenames.h"
154 char * program_name
= "readelf";
155 static long archive_file_offset
;
156 static unsigned long archive_file_size
;
157 static unsigned long dynamic_addr
;
158 static bfd_size_type dynamic_size
;
159 static unsigned int dynamic_nent
;
160 static char * dynamic_strings
;
161 static unsigned long dynamic_strings_length
;
162 static char * string_table
;
163 static unsigned long string_table_length
;
164 static unsigned long num_dynamic_syms
;
165 static Elf_Internal_Sym
* dynamic_symbols
;
166 static Elf_Internal_Syminfo
* dynamic_syminfo
;
167 static unsigned long dynamic_syminfo_offset
;
168 static unsigned int dynamic_syminfo_nent
;
169 static char program_interpreter
[PATH_MAX
];
170 static bfd_vma dynamic_info
[DT_ENCODING
];
171 static bfd_vma dynamic_info_DT_GNU_HASH
;
172 static bfd_vma version_info
[16];
173 static Elf_Internal_Ehdr elf_header
;
174 static Elf_Internal_Shdr
* section_headers
;
175 static Elf_Internal_Phdr
* program_headers
;
176 static Elf_Internal_Dyn
* dynamic_section
;
177 static Elf_Internal_Shdr
* symtab_shndx_hdr
;
178 static int show_name
;
179 static int do_dynamic
;
181 static int do_dyn_syms
;
183 static int do_sections
;
184 static int do_section_groups
;
185 static int do_section_details
;
186 static int do_segments
;
187 static int do_unwind
;
188 static int do_using_dynamic
;
189 static int do_header
;
191 static int do_version
;
192 static int do_histogram
;
193 static int do_debugging
;
196 static int do_archive_index
;
197 static int is_32bit_elf
;
201 struct group_list
* next
;
202 unsigned int section_index
;
207 struct group_list
* root
;
208 unsigned int group_index
;
211 static size_t group_count
;
212 static struct group
* section_groups
;
213 static struct group
** section_headers_groups
;
216 /* Flag bits indicating particular types of dump. */
217 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
218 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
219 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
220 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
221 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
223 typedef unsigned char dump_type
;
225 /* A linked list of the section names for which dumps were requested. */
226 struct dump_list_entry
230 struct dump_list_entry
* next
;
232 static struct dump_list_entry
* dump_sects_byname
;
234 /* A dynamic array of flags indicating for which sections a dump
235 has been requested via command line switches. */
236 static dump_type
* cmdline_dump_sects
= NULL
;
237 static unsigned int num_cmdline_dump_sects
= 0;
239 /* A dynamic array of flags indicating for which sections a dump of
240 some kind has been requested. It is reset on a per-object file
241 basis and then initialised from the cmdline_dump_sects array,
242 the results of interpreting the -w switch, and the
243 dump_sects_byname list. */
244 static dump_type
* dump_sects
= NULL
;
245 static unsigned int num_dump_sects
= 0;
248 /* How to print a vma value. */
249 typedef enum print_mode
261 static void (* byte_put
) (unsigned char *, bfd_vma
, int);
265 #define SECTION_NAME(X) \
266 ((X) == NULL ? "<none>" \
267 : string_table == NULL ? "<no-name>" \
268 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
269 : string_table + (X)->sh_name))
271 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
273 #define BYTE_GET(field) byte_get (field, sizeof (field))
275 #define GET_ELF_SYMBOLS(file, section) \
276 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
277 : get_64bit_elf_symbols (file, section))
279 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
280 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
281 already been called and verified that the string exists. */
282 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
284 /* This is just a bit of syntatic sugar. */
285 #define streq(a,b) (strcmp ((a), (b)) == 0)
286 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
287 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
289 #define REMOVE_ARCH_BITS(ADDR) do { \
290 if (elf_header.e_machine == EM_ARM) \
295 get_data (void * var
, FILE * file
, long offset
, size_t size
, size_t nmemb
,
300 if (size
== 0 || nmemb
== 0)
303 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
305 error (_("Unable to seek to 0x%lx for %s\n"),
306 (unsigned long) archive_file_offset
+ offset
, reason
);
313 /* Check for overflow. */
314 if (nmemb
< (~(size_t) 0 - 1) / size
)
315 /* + 1 so that we can '\0' terminate invalid string table sections. */
316 mvar
= malloc (size
* nmemb
+ 1);
320 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
321 (unsigned long)(size
* nmemb
), reason
);
325 ((char *) mvar
)[size
* nmemb
] = '\0';
328 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
330 error (_("Unable to read in 0x%lx bytes of %s\n"),
331 (unsigned long)(size
* nmemb
), reason
);
341 byte_put_little_endian (unsigned char * field
, bfd_vma value
, int size
)
346 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
347 field
[6] = ((value
>> 24) >> 24) & 0xff;
348 field
[5] = ((value
>> 24) >> 16) & 0xff;
349 field
[4] = ((value
>> 24) >> 8) & 0xff;
352 field
[3] = (value
>> 24) & 0xff;
355 field
[2] = (value
>> 16) & 0xff;
358 field
[1] = (value
>> 8) & 0xff;
361 field
[0] = value
& 0xff;
365 error (_("Unhandled data length: %d\n"), size
);
370 /* Print a VMA value. */
373 print_vma (bfd_vma vma
, print_mode mode
)
386 return nc
+ printf ("%8.8" BFD_VMA_FMT
"x", vma
);
393 return printf ("%5" BFD_VMA_FMT
"d", vma
);
401 return nc
+ printf ("%" BFD_VMA_FMT
"x", vma
);
404 return printf ("%" BFD_VMA_FMT
"d", vma
);
407 return printf ("%" BFD_VMA_FMT
"u", vma
);
412 /* Display a symbol on stdout. Handles the display of non-printing characters.
414 If DO_WIDE is not true then format the symbol to be at most WIDTH characters,
415 truncating as necessary. If WIDTH is negative then format the string to be
416 exactly - WIDTH characters, truncating or padding as necessary.
418 Returns the number of emitted characters. */
421 print_symbol (int width
, const char * symbol
)
424 bfd_boolean extra_padding
= FALSE
;
425 unsigned int num_printed
= 0;
429 /* Set the width to a very large value. This simplifies the code below. */
434 /* Keep the width positive. This also helps. */
436 extra_padding
= TRUE
;
445 /* Look for non-printing symbols inside the symbol's name.
446 This test is triggered in particular by the names generated
447 by the assembler for local labels. */
448 while (ISPRINT (* c
))
458 printf ("%.*s", len
, symbol
);
464 if (* c
== 0 || width
== 0)
467 /* Now display the non-printing character, if
468 there is room left in which to dipslay it. */
474 printf ("^%c", *c
+ 0x40);
484 printf ("<0x%.2x>", *c
);
493 if (extra_padding
&& width
> 0)
495 /* Fill in the remaining spaces. */
496 printf ("%-*s", width
, " ");
504 byte_put_big_endian (unsigned char * field
, bfd_vma value
, int size
)
509 field
[7] = value
& 0xff;
510 field
[6] = (value
>> 8) & 0xff;
511 field
[5] = (value
>> 16) & 0xff;
512 field
[4] = (value
>> 24) & 0xff;
517 field
[3] = value
& 0xff;
521 field
[2] = value
& 0xff;
525 field
[1] = value
& 0xff;
529 field
[0] = value
& 0xff;
533 error (_("Unhandled data length: %d\n"), size
);
538 /* Return a pointer to section NAME, or NULL if no such section exists. */
540 static Elf_Internal_Shdr
*
541 find_section (const char * name
)
545 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
546 if (streq (SECTION_NAME (section_headers
+ i
), name
))
547 return section_headers
+ i
;
552 /* Return a pointer to a section containing ADDR, or NULL if no such
555 static Elf_Internal_Shdr
*
556 find_section_by_address (bfd_vma addr
)
560 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
562 Elf_Internal_Shdr
*sec
= section_headers
+ i
;
563 if (addr
>= sec
->sh_addr
&& addr
< sec
->sh_addr
+ sec
->sh_size
)
570 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
574 read_uleb128 (unsigned char *data
, unsigned int *length_return
)
576 return read_leb128 (data
, length_return
, 0);
579 /* Guess the relocation size commonly used by the specific machines. */
582 guess_is_rela (unsigned int e_machine
)
586 /* Targets that use REL relocations. */
602 /* Targets that use RELA relocations. */
606 case EM_ALTERA_NIOS2
:
626 case EM_LATTICEMICO32
:
634 case EM_CYGNUS_MN10200
:
636 case EM_CYGNUS_MN10300
:
660 case EM_MICROBLAZE_OLD
:
681 warn (_("Don't know about relocations on this machine architecture\n"));
687 slurp_rela_relocs (FILE * file
,
688 unsigned long rel_offset
,
689 unsigned long rel_size
,
690 Elf_Internal_Rela
** relasp
,
691 unsigned long * nrelasp
)
693 Elf_Internal_Rela
* relas
;
694 unsigned long nrelas
;
699 Elf32_External_Rela
* erelas
;
701 erelas
= (Elf32_External_Rela
*) get_data (NULL
, file
, rel_offset
, 1,
702 rel_size
, _("relocs"));
706 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
708 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
709 sizeof (Elf_Internal_Rela
));
714 error (_("out of memory parsing relocs\n"));
718 for (i
= 0; i
< nrelas
; i
++)
720 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
721 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
722 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
729 Elf64_External_Rela
* erelas
;
731 erelas
= (Elf64_External_Rela
*) get_data (NULL
, file
, rel_offset
, 1,
732 rel_size
, _("relocs"));
736 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
738 relas
= (Elf_Internal_Rela
*) cmalloc (nrelas
,
739 sizeof (Elf_Internal_Rela
));
744 error (_("out of memory parsing relocs\n"));
748 for (i
= 0; i
< nrelas
; i
++)
750 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
751 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
752 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
754 /* The #ifdef BFD64 below is to prevent a compile time
755 warning. We know that if we do not have a 64 bit data
756 type that we will never execute this code anyway. */
758 if (elf_header
.e_machine
== EM_MIPS
759 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
761 /* In little-endian objects, r_info isn't really a
762 64-bit little-endian value: it has a 32-bit
763 little-endian symbol index followed by four
764 individual byte fields. Reorder INFO
766 bfd_vma inf
= relas
[i
].r_info
;
767 inf
= (((inf
& 0xffffffff) << 32)
768 | ((inf
>> 56) & 0xff)
769 | ((inf
>> 40) & 0xff00)
770 | ((inf
>> 24) & 0xff0000)
771 | ((inf
>> 8) & 0xff000000));
772 relas
[i
].r_info
= inf
;
785 slurp_rel_relocs (FILE * file
,
786 unsigned long rel_offset
,
787 unsigned long rel_size
,
788 Elf_Internal_Rela
** relsp
,
789 unsigned long * nrelsp
)
791 Elf_Internal_Rela
* rels
;
797 Elf32_External_Rel
* erels
;
799 erels
= (Elf32_External_Rel
*) get_data (NULL
, file
, rel_offset
, 1,
800 rel_size
, _("relocs"));
804 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
806 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
811 error (_("out of memory parsing relocs\n"));
815 for (i
= 0; i
< nrels
; i
++)
817 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
818 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
819 rels
[i
].r_addend
= 0;
826 Elf64_External_Rel
* erels
;
828 erels
= (Elf64_External_Rel
*) get_data (NULL
, file
, rel_offset
, 1,
829 rel_size
, _("relocs"));
833 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
835 rels
= (Elf_Internal_Rela
*) cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
840 error (_("out of memory parsing relocs\n"));
844 for (i
= 0; i
< nrels
; i
++)
846 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
847 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
848 rels
[i
].r_addend
= 0;
850 /* The #ifdef BFD64 below is to prevent a compile time
851 warning. We know that if we do not have a 64 bit data
852 type that we will never execute this code anyway. */
854 if (elf_header
.e_machine
== EM_MIPS
855 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
857 /* In little-endian objects, r_info isn't really a
858 64-bit little-endian value: it has a 32-bit
859 little-endian symbol index followed by four
860 individual byte fields. Reorder INFO
862 bfd_vma inf
= rels
[i
].r_info
;
863 inf
= (((inf
& 0xffffffff) << 32)
864 | ((inf
>> 56) & 0xff)
865 | ((inf
>> 40) & 0xff00)
866 | ((inf
>> 24) & 0xff0000)
867 | ((inf
>> 8) & 0xff000000));
868 rels
[i
].r_info
= inf
;
880 /* Returns the reloc type extracted from the reloc info field. */
883 get_reloc_type (bfd_vma reloc_info
)
886 return ELF32_R_TYPE (reloc_info
);
888 switch (elf_header
.e_machine
)
891 /* Note: We assume that reloc_info has already been adjusted for us. */
892 return ELF64_MIPS_R_TYPE (reloc_info
);
895 return ELF64_R_TYPE_ID (reloc_info
);
898 return ELF64_R_TYPE (reloc_info
);
902 /* Return the symbol index extracted from the reloc info field. */
905 get_reloc_symindex (bfd_vma reloc_info
)
907 return is_32bit_elf
? ELF32_R_SYM (reloc_info
) : ELF64_R_SYM (reloc_info
);
910 /* Display the contents of the relocation data found at the specified
914 dump_relocations (FILE * file
,
915 unsigned long rel_offset
,
916 unsigned long rel_size
,
917 Elf_Internal_Sym
* symtab
,
920 unsigned long strtablen
,
924 Elf_Internal_Rela
* rels
;
926 if (is_rela
== UNKNOWN
)
927 is_rela
= guess_is_rela (elf_header
.e_machine
);
931 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
936 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
945 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
947 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
952 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
954 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
962 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
964 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
969 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
971 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
975 for (i
= 0; i
< rel_size
; i
++)
980 bfd_vma symtab_index
;
983 offset
= rels
[i
].r_offset
;
984 inf
= rels
[i
].r_info
;
986 type
= get_reloc_type (inf
);
987 symtab_index
= get_reloc_symindex (inf
);
991 printf ("%8.8lx %8.8lx ",
992 (unsigned long) offset
& 0xffffffff,
993 (unsigned long) inf
& 0xffffffff);
997 #if BFD_HOST_64BIT_LONG
999 ? "%16.16lx %16.16lx "
1000 : "%12.12lx %12.12lx ",
1002 #elif BFD_HOST_64BIT_LONG_LONG
1005 ? "%16.16llx %16.16llx "
1006 : "%12.12llx %12.12llx ",
1010 ? "%16.16I64x %16.16I64x "
1011 : "%12.12I64x %12.12I64x ",
1016 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1017 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1018 _bfd_int64_high (offset
),
1019 _bfd_int64_low (offset
),
1020 _bfd_int64_high (inf
),
1021 _bfd_int64_low (inf
));
1025 switch (elf_header
.e_machine
)
1032 case EM_CYGNUS_M32R
:
1033 rtype
= elf_m32r_reloc_type (type
);
1038 rtype
= elf_i386_reloc_type (type
);
1043 rtype
= elf_m68hc11_reloc_type (type
);
1047 rtype
= elf_m68k_reloc_type (type
);
1051 rtype
= elf_i960_reloc_type (type
);
1056 rtype
= elf_avr_reloc_type (type
);
1059 case EM_OLD_SPARCV9
:
1060 case EM_SPARC32PLUS
:
1063 rtype
= elf_sparc_reloc_type (type
);
1067 rtype
= elf_spu_reloc_type (type
);
1071 case EM_CYGNUS_V850
:
1072 rtype
= v850_reloc_type (type
);
1076 case EM_CYGNUS_D10V
:
1077 rtype
= elf_d10v_reloc_type (type
);
1081 case EM_CYGNUS_D30V
:
1082 rtype
= elf_d30v_reloc_type (type
);
1086 rtype
= elf_dlx_reloc_type (type
);
1090 rtype
= elf_sh_reloc_type (type
);
1094 case EM_CYGNUS_MN10300
:
1095 rtype
= elf_mn10300_reloc_type (type
);
1099 case EM_CYGNUS_MN10200
:
1100 rtype
= elf_mn10200_reloc_type (type
);
1104 case EM_CYGNUS_FR30
:
1105 rtype
= elf_fr30_reloc_type (type
);
1109 rtype
= elf_frv_reloc_type (type
);
1113 rtype
= elf_mcore_reloc_type (type
);
1117 rtype
= elf_mmix_reloc_type (type
);
1122 rtype
= elf_msp430_reloc_type (type
);
1126 rtype
= elf_ppc_reloc_type (type
);
1130 rtype
= elf_ppc64_reloc_type (type
);
1134 case EM_MIPS_RS3_LE
:
1135 rtype
= elf_mips_reloc_type (type
);
1139 rtype
= elf_alpha_reloc_type (type
);
1143 rtype
= elf_arm_reloc_type (type
);
1147 rtype
= elf_arc_reloc_type (type
);
1151 rtype
= elf_hppa_reloc_type (type
);
1157 rtype
= elf_h8_reloc_type (type
);
1162 rtype
= elf_or32_reloc_type (type
);
1167 rtype
= elf_pj_reloc_type (type
);
1170 rtype
= elf_ia64_reloc_type (type
);
1174 rtype
= elf_cris_reloc_type (type
);
1178 rtype
= elf_i860_reloc_type (type
);
1183 rtype
= elf_x86_64_reloc_type (type
);
1187 rtype
= i370_reloc_type (type
);
1192 rtype
= elf_s390_reloc_type (type
);
1196 rtype
= elf_score_reloc_type (type
);
1200 rtype
= elf_xstormy16_reloc_type (type
);
1204 rtype
= elf_crx_reloc_type (type
);
1208 rtype
= elf_vax_reloc_type (type
);
1213 rtype
= elf_ip2k_reloc_type (type
);
1217 rtype
= elf_iq2000_reloc_type (type
);
1222 rtype
= elf_xtensa_reloc_type (type
);
1225 case EM_LATTICEMICO32
:
1226 rtype
= elf_lm32_reloc_type (type
);
1231 rtype
= elf_m32c_reloc_type (type
);
1235 rtype
= elf_mt_reloc_type (type
);
1239 rtype
= elf_bfin_reloc_type (type
);
1243 rtype
= elf_mep_reloc_type (type
);
1248 rtype
= elf_cr16_reloc_type (type
);
1252 case EM_MICROBLAZE_OLD
:
1253 rtype
= elf_microblaze_reloc_type (type
);
1257 rtype
= elf_rx_reloc_type (type
);
1262 rtype
= elf_xc16x_reloc_type (type
);
1267 printf (_("unrecognized: %-7lx"), (unsigned long) type
& 0xffffffff);
1269 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1271 if (elf_header
.e_machine
== EM_ALPHA
1273 && streq (rtype
, "R_ALPHA_LITUSE")
1276 switch (rels
[i
].r_addend
)
1278 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1279 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1280 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1281 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1282 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1283 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1284 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1285 default: rtype
= NULL
;
1288 printf (" (%s)", rtype
);
1292 printf (_("<unknown addend: %lx>"),
1293 (unsigned long) rels
[i
].r_addend
);
1296 else if (symtab_index
)
1298 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1299 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1302 Elf_Internal_Sym
* psym
;
1304 psym
= symtab
+ symtab_index
;
1308 if (ELF_ST_TYPE (psym
->st_info
) == STT_GNU_IFUNC
)
1312 unsigned int width
= is_32bit_elf
? 8 : 14;
1314 /* Relocations against GNU_IFUNC symbols do not use the value
1315 of the symbol as the address to relocate against. Instead
1316 they invoke the function named by the symbol and use its
1317 result as the address for relocation.
1319 To indicate this to the user, do not display the value of
1320 the symbol in the "Symbols's Value" field. Instead show
1321 its name followed by () as a hint that the symbol is
1325 || psym
->st_name
== 0
1326 || psym
->st_name
>= strtablen
)
1329 name
= strtab
+ psym
->st_name
;
1331 len
= print_symbol (width
, name
);
1332 printf ("()%-*s", len
<= width
? (width
+ 1) - len
: 1, " ");
1336 print_vma (psym
->st_value
, LONG_HEX
);
1338 printf (is_32bit_elf
? " " : " ");
1341 if (psym
->st_name
== 0)
1343 const char * sec_name
= "<null>";
1346 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1348 if (psym
->st_shndx
< elf_header
.e_shnum
)
1350 = SECTION_NAME (section_headers
+ psym
->st_shndx
);
1351 else if (psym
->st_shndx
== SHN_ABS
)
1353 else if (psym
->st_shndx
== SHN_COMMON
)
1354 sec_name
= "COMMON";
1355 else if (elf_header
.e_machine
== EM_MIPS
1356 && psym
->st_shndx
== SHN_MIPS_SCOMMON
)
1357 sec_name
= "SCOMMON";
1358 else if (elf_header
.e_machine
== EM_MIPS
1359 && psym
->st_shndx
== SHN_MIPS_SUNDEFINED
)
1360 sec_name
= "SUNDEF";
1361 else if ((elf_header
.e_machine
== EM_X86_64
1362 || elf_header
.e_machine
== EM_L1OM
)
1363 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1364 sec_name
= "LARGE_COMMON";
1365 else if (elf_header
.e_machine
== EM_IA_64
1366 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1367 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1368 sec_name
= "ANSI_COM";
1369 else if (elf_header
.e_machine
== EM_IA_64
1370 && (elf_header
.e_ident
[EI_OSABI
]
1371 == ELFOSABI_OPENVMS
)
1372 && psym
->st_shndx
== SHN_IA_64_VMS_SYMVEC
)
1373 sec_name
= "VMS_SYMVEC";
1376 sprintf (name_buf
, "<section 0x%x>",
1377 (unsigned int) psym
->st_shndx
);
1378 sec_name
= name_buf
;
1381 print_symbol (22, sec_name
);
1383 else if (strtab
== NULL
)
1384 printf (_("<string table index: %3ld>"), psym
->st_name
);
1385 else if (psym
->st_name
>= strtablen
)
1386 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1388 print_symbol (22, strtab
+ psym
->st_name
);
1392 long off
= (long) (bfd_signed_vma
) rels
[i
].r_addend
;
1395 printf (" - %lx", - off
);
1397 printf (" + %lx", off
);
1403 printf ("%*c", is_32bit_elf
?
1404 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1405 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1408 if (elf_header
.e_machine
== EM_SPARCV9
1410 && streq (rtype
, "R_SPARC_OLO10"))
1411 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf
));
1416 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1418 bfd_vma type2
= ELF64_MIPS_R_TYPE2 (inf
);
1419 bfd_vma type3
= ELF64_MIPS_R_TYPE3 (inf
);
1420 const char * rtype2
= elf_mips_reloc_type (type2
);
1421 const char * rtype3
= elf_mips_reloc_type (type3
);
1423 printf (" Type2: ");
1426 printf (_("unrecognized: %-7lx"),
1427 (unsigned long) type2
& 0xffffffff);
1429 printf ("%-17.17s", rtype2
);
1431 printf ("\n Type3: ");
1434 printf (_("unrecognized: %-7lx"),
1435 (unsigned long) type3
& 0xffffffff);
1437 printf ("%-17.17s", rtype3
);
1448 get_mips_dynamic_type (unsigned long type
)
1452 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1453 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1454 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1455 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1456 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1457 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1458 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1459 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1460 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1461 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1462 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1463 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1464 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1465 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1466 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1467 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1468 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1469 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1470 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1471 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1472 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1473 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1474 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1475 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1476 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1477 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1478 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1479 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1480 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1481 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1482 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1483 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1484 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1485 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1486 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1487 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1488 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1489 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1490 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1491 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1492 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1493 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1494 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1495 case DT_MIPS_PLTGOT
: return "MIPS_PLTGOT";
1496 case DT_MIPS_RWPLT
: return "MIPS_RWPLT";
1503 get_sparc64_dynamic_type (unsigned long type
)
1507 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1514 get_ppc_dynamic_type (unsigned long type
)
1518 case DT_PPC_GOT
: return "PPC_GOT";
1519 case DT_PPC_TLSOPT
: return "PPC_TLSOPT";
1526 get_ppc64_dynamic_type (unsigned long type
)
1530 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1531 case DT_PPC64_OPD
: return "PPC64_OPD";
1532 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1533 case DT_PPC64_TLSOPT
: return "PPC64_TLSOPT";
1540 get_parisc_dynamic_type (unsigned long type
)
1544 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1545 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1546 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1547 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1548 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1549 case DT_HP_PREINIT
: return "HP_PREINIT";
1550 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1551 case DT_HP_NEEDED
: return "HP_NEEDED";
1552 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1553 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1554 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1555 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1556 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1557 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1558 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1559 case DT_HP_FILTERED
: return "HP_FILTERED";
1560 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1561 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1562 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1563 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1564 case DT_PLT
: return "PLT";
1565 case DT_PLT_SIZE
: return "PLT_SIZE";
1566 case DT_DLT
: return "DLT";
1567 case DT_DLT_SIZE
: return "DLT_SIZE";
1574 get_ia64_dynamic_type (unsigned long type
)
1578 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1579 case DT_IA_64_VMS_SUBTYPE
: return "VMS_SUBTYPE";
1580 case DT_IA_64_VMS_IMGIOCNT
: return "VMS_IMGIOCNT";
1581 case DT_IA_64_VMS_LNKFLAGS
: return "VMS_LNKFLAGS";
1582 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ
: return "VMS_VIR_MEM_BLK_SIZ";
1583 case DT_IA_64_VMS_IDENT
: return "VMS_IDENT";
1584 case DT_IA_64_VMS_NEEDED_IDENT
: return "VMS_NEEDED_IDENT";
1585 case DT_IA_64_VMS_IMG_RELA_CNT
: return "VMS_IMG_RELA_CNT";
1586 case DT_IA_64_VMS_SEG_RELA_CNT
: return "VMS_SEG_RELA_CNT";
1587 case DT_IA_64_VMS_FIXUP_RELA_CNT
: return "VMS_FIXUP_RELA_CNT";
1588 case DT_IA_64_VMS_FIXUP_NEEDED
: return "VMS_FIXUP_NEEDED";
1589 case DT_IA_64_VMS_SYMVEC_CNT
: return "VMS_SYMVEC_CNT";
1590 case DT_IA_64_VMS_XLATED
: return "VMS_XLATED";
1591 case DT_IA_64_VMS_STACKSIZE
: return "VMS_STACKSIZE";
1592 case DT_IA_64_VMS_UNWINDSZ
: return "VMS_UNWINDSZ";
1593 case DT_IA_64_VMS_UNWIND_CODSEG
: return "VMS_UNWIND_CODSEG";
1594 case DT_IA_64_VMS_UNWIND_INFOSEG
: return "VMS_UNWIND_INFOSEG";
1595 case DT_IA_64_VMS_LINKTIME
: return "VMS_LINKTIME";
1596 case DT_IA_64_VMS_SEG_NO
: return "VMS_SEG_NO";
1597 case DT_IA_64_VMS_SYMVEC_OFFSET
: return "VMS_SYMVEC_OFFSET";
1598 case DT_IA_64_VMS_SYMVEC_SEG
: return "VMS_SYMVEC_SEG";
1599 case DT_IA_64_VMS_UNWIND_OFFSET
: return "VMS_UNWIND_OFFSET";
1600 case DT_IA_64_VMS_UNWIND_SEG
: return "VMS_UNWIND_SEG";
1601 case DT_IA_64_VMS_STRTAB_OFFSET
: return "VMS_STRTAB_OFFSET";
1602 case DT_IA_64_VMS_SYSVER_OFFSET
: return "VMS_SYSVER_OFFSET";
1603 case DT_IA_64_VMS_IMG_RELA_OFF
: return "VMS_IMG_RELA_OFF";
1604 case DT_IA_64_VMS_SEG_RELA_OFF
: return "VMS_SEG_RELA_OFF";
1605 case DT_IA_64_VMS_FIXUP_RELA_OFF
: return "VMS_FIXUP_RELA_OFF";
1606 case DT_IA_64_VMS_PLTGOT_OFFSET
: return "VMS_PLTGOT_OFFSET";
1607 case DT_IA_64_VMS_PLTGOT_SEG
: return "VMS_PLTGOT_SEG";
1608 case DT_IA_64_VMS_FPMODE
: return "VMS_FPMODE";
1615 get_alpha_dynamic_type (unsigned long type
)
1619 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1626 get_score_dynamic_type (unsigned long type
)
1630 case DT_SCORE_BASE_ADDRESS
: return "SCORE_BASE_ADDRESS";
1631 case DT_SCORE_LOCAL_GOTNO
: return "SCORE_LOCAL_GOTNO";
1632 case DT_SCORE_SYMTABNO
: return "SCORE_SYMTABNO";
1633 case DT_SCORE_GOTSYM
: return "SCORE_GOTSYM";
1634 case DT_SCORE_UNREFEXTNO
: return "SCORE_UNREFEXTNO";
1635 case DT_SCORE_HIPAGENO
: return "SCORE_HIPAGENO";
1643 get_dynamic_type (unsigned long type
)
1645 static char buff
[64];
1649 case DT_NULL
: return "NULL";
1650 case DT_NEEDED
: return "NEEDED";
1651 case DT_PLTRELSZ
: return "PLTRELSZ";
1652 case DT_PLTGOT
: return "PLTGOT";
1653 case DT_HASH
: return "HASH";
1654 case DT_STRTAB
: return "STRTAB";
1655 case DT_SYMTAB
: return "SYMTAB";
1656 case DT_RELA
: return "RELA";
1657 case DT_RELASZ
: return "RELASZ";
1658 case DT_RELAENT
: return "RELAENT";
1659 case DT_STRSZ
: return "STRSZ";
1660 case DT_SYMENT
: return "SYMENT";
1661 case DT_INIT
: return "INIT";
1662 case DT_FINI
: return "FINI";
1663 case DT_SONAME
: return "SONAME";
1664 case DT_RPATH
: return "RPATH";
1665 case DT_SYMBOLIC
: return "SYMBOLIC";
1666 case DT_REL
: return "REL";
1667 case DT_RELSZ
: return "RELSZ";
1668 case DT_RELENT
: return "RELENT";
1669 case DT_PLTREL
: return "PLTREL";
1670 case DT_DEBUG
: return "DEBUG";
1671 case DT_TEXTREL
: return "TEXTREL";
1672 case DT_JMPREL
: return "JMPREL";
1673 case DT_BIND_NOW
: return "BIND_NOW";
1674 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1675 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1676 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1677 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1678 case DT_RUNPATH
: return "RUNPATH";
1679 case DT_FLAGS
: return "FLAGS";
1681 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1682 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1684 case DT_CHECKSUM
: return "CHECKSUM";
1685 case DT_PLTPADSZ
: return "PLTPADSZ";
1686 case DT_MOVEENT
: return "MOVEENT";
1687 case DT_MOVESZ
: return "MOVESZ";
1688 case DT_FEATURE
: return "FEATURE";
1689 case DT_POSFLAG_1
: return "POSFLAG_1";
1690 case DT_SYMINSZ
: return "SYMINSZ";
1691 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1693 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1694 case DT_CONFIG
: return "CONFIG";
1695 case DT_DEPAUDIT
: return "DEPAUDIT";
1696 case DT_AUDIT
: return "AUDIT";
1697 case DT_PLTPAD
: return "PLTPAD";
1698 case DT_MOVETAB
: return "MOVETAB";
1699 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1701 case DT_VERSYM
: return "VERSYM";
1703 case DT_TLSDESC_GOT
: return "TLSDESC_GOT";
1704 case DT_TLSDESC_PLT
: return "TLSDESC_PLT";
1705 case DT_RELACOUNT
: return "RELACOUNT";
1706 case DT_RELCOUNT
: return "RELCOUNT";
1707 case DT_FLAGS_1
: return "FLAGS_1";
1708 case DT_VERDEF
: return "VERDEF";
1709 case DT_VERDEFNUM
: return "VERDEFNUM";
1710 case DT_VERNEED
: return "VERNEED";
1711 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1713 case DT_AUXILIARY
: return "AUXILIARY";
1714 case DT_USED
: return "USED";
1715 case DT_FILTER
: return "FILTER";
1717 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1718 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1719 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1720 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1721 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1722 case DT_GNU_HASH
: return "GNU_HASH";
1725 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1727 const char * result
;
1729 switch (elf_header
.e_machine
)
1732 case EM_MIPS_RS3_LE
:
1733 result
= get_mips_dynamic_type (type
);
1736 result
= get_sparc64_dynamic_type (type
);
1739 result
= get_ppc_dynamic_type (type
);
1742 result
= get_ppc64_dynamic_type (type
);
1745 result
= get_ia64_dynamic_type (type
);
1748 result
= get_alpha_dynamic_type (type
);
1751 result
= get_score_dynamic_type (type
);
1761 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1763 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1764 || (elf_header
.e_machine
== EM_PARISC
1765 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1767 const char * result
;
1769 switch (elf_header
.e_machine
)
1772 result
= get_parisc_dynamic_type (type
);
1775 result
= get_ia64_dynamic_type (type
);
1785 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1789 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1796 get_file_type (unsigned e_type
)
1798 static char buff
[32];
1802 case ET_NONE
: return _("NONE (None)");
1803 case ET_REL
: return _("REL (Relocatable file)");
1804 case ET_EXEC
: return _("EXEC (Executable file)");
1805 case ET_DYN
: return _("DYN (Shared object file)");
1806 case ET_CORE
: return _("CORE (Core file)");
1809 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1810 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1811 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1812 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1814 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1820 get_machine_name (unsigned e_machine
)
1822 static char buff
[64]; /* XXX */
1826 case EM_NONE
: return _("None");
1827 case EM_M32
: return "WE32100";
1828 case EM_SPARC
: return "Sparc";
1829 case EM_SPU
: return "SPU";
1830 case EM_386
: return "Intel 80386";
1831 case EM_68K
: return "MC68000";
1832 case EM_88K
: return "MC88000";
1833 case EM_486
: return "Intel 80486";
1834 case EM_860
: return "Intel 80860";
1835 case EM_MIPS
: return "MIPS R3000";
1836 case EM_S370
: return "IBM System/370";
1837 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1838 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1839 case EM_PARISC
: return "HPPA";
1840 case EM_PPC_OLD
: return "Power PC (old)";
1841 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1842 case EM_960
: return "Intel 90860";
1843 case EM_PPC
: return "PowerPC";
1844 case EM_PPC64
: return "PowerPC64";
1845 case EM_V800
: return "NEC V800";
1846 case EM_FR20
: return "Fujitsu FR20";
1847 case EM_RH32
: return "TRW RH32";
1848 case EM_MCORE
: return "MCORE";
1849 case EM_ARM
: return "ARM";
1850 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1851 case EM_SH
: return "Renesas / SuperH SH";
1852 case EM_SPARCV9
: return "Sparc v9";
1853 case EM_TRICORE
: return "Siemens Tricore";
1854 case EM_ARC
: return "ARC";
1855 case EM_H8_300
: return "Renesas H8/300";
1856 case EM_H8_300H
: return "Renesas H8/300H";
1857 case EM_H8S
: return "Renesas H8S";
1858 case EM_H8_500
: return "Renesas H8/500";
1859 case EM_IA_64
: return "Intel IA-64";
1860 case EM_MIPS_X
: return "Stanford MIPS-X";
1861 case EM_COLDFIRE
: return "Motorola Coldfire";
1862 case EM_68HC12
: return "Motorola M68HC12";
1863 case EM_ALPHA
: return "Alpha";
1864 case EM_CYGNUS_D10V
:
1865 case EM_D10V
: return "d10v";
1866 case EM_CYGNUS_D30V
:
1867 case EM_D30V
: return "d30v";
1868 case EM_CYGNUS_M32R
:
1869 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1870 case EM_CYGNUS_V850
:
1871 case EM_V850
: return "NEC v850";
1872 case EM_CYGNUS_MN10300
:
1873 case EM_MN10300
: return "mn10300";
1874 case EM_CYGNUS_MN10200
:
1875 case EM_MN10200
: return "mn10200";
1876 case EM_CYGNUS_FR30
:
1877 case EM_FR30
: return "Fujitsu FR30";
1878 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1880 case EM_PJ
: return "picoJava";
1881 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1882 case EM_PCP
: return "Siemens PCP";
1883 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1884 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1885 case EM_STARCORE
: return "Motorola Star*Core processor";
1886 case EM_ME16
: return "Toyota ME16 processor";
1887 case EM_ST100
: return "STMicroelectronics ST100 processor";
1888 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1889 case EM_PDSP
: return "Sony DSP processor";
1890 case EM_PDP10
: return "Digital Equipment Corp. PDP-10";
1891 case EM_PDP11
: return "Digital Equipment Corp. PDP-11";
1892 case EM_FX66
: return "Siemens FX66 microcontroller";
1893 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1894 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1895 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1896 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1897 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1898 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1899 case EM_SVX
: return "Silicon Graphics SVx";
1900 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1901 case EM_VAX
: return "Digital VAX";
1903 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1904 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1905 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1906 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1907 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1908 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1909 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1910 case EM_PRISM
: return "Vitesse Prism";
1911 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1912 case EM_L1OM
: return "Intel L1OM";
1914 case EM_S390
: return "IBM S/390";
1915 case EM_SCORE
: return "SUNPLUS S+Core";
1916 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1918 case EM_OR32
: return "OpenRISC";
1919 case EM_ARC_A5
: return "ARC International ARCompact processor";
1920 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1921 case EM_DLX
: return "OpenDLX";
1923 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1924 case EM_IQ2000
: return "Vitesse IQ2000";
1926 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1927 case EM_VIDEOCORE
: return "Alphamosaic VideoCore processor";
1928 case EM_TMM_GPP
: return "Thompson Multimedia General Purpose Processor";
1929 case EM_NS32K
: return "National Semiconductor 32000 series";
1930 case EM_TPC
: return "Tenor Network TPC processor";
1931 case EM_ST200
: return "STMicroelectronics ST200 microcontroller";
1932 case EM_MAX
: return "MAX Processor";
1933 case EM_CR
: return "National Semiconductor CompactRISC";
1934 case EM_F2MC16
: return "Fujitsu F2MC16";
1935 case EM_MSP430
: return "Texas Instruments msp430 microcontroller";
1936 case EM_LATTICEMICO32
: return "Lattice Mico32";
1938 case EM_M32C
: return "Renesas M32c";
1939 case EM_MT
: return "Morpho Techologies MT processor";
1940 case EM_BLACKFIN
: return "Analog Devices Blackfin";
1941 case EM_SE_C33
: return "S1C33 Family of Seiko Epson processors";
1942 case EM_SEP
: return "Sharp embedded microprocessor";
1943 case EM_ARCA
: return "Arca RISC microprocessor";
1944 case EM_UNICORE
: return "Unicore";
1945 case EM_EXCESS
: return "eXcess 16/32/64-bit configurable embedded CPU";
1946 case EM_DXP
: return "Icera Semiconductor Inc. Deep Execution Processor";
1947 case EM_NIOS32
: return "Altera Nios";
1948 case EM_ALTERA_NIOS2
: return "Altera Nios II";
1950 case EM_XC16X
: return "Infineon Technologies xc16x";
1951 case EM_M16C
: return "Renesas M16C series microprocessors";
1952 case EM_DSPIC30F
: return "Microchip Technology dsPIC30F Digital Signal Controller";
1953 case EM_CE
: return "Freescale Communication Engine RISC core";
1954 case EM_TSK3000
: return "Altium TSK3000 core";
1955 case EM_RS08
: return "Freescale RS08 embedded processor";
1956 case EM_ECOG2
: return "Cyan Technology eCOG2 microprocessor";
1957 case EM_DSP24
: return "New Japan Radio (NJR) 24-bit DSP Processor";
1958 case EM_VIDEOCORE3
: return "Broadcom VideoCore III processor";
1959 case EM_SE_C17
: return "Seiko Epson C17 family";
1960 case EM_TI_C6000
: return "Texas Instruments TMS320C6000 DSP family";
1961 case EM_TI_C2000
: return "Texas Instruments TMS320C2000 DSP family";
1962 case EM_TI_C5500
: return "Texas Instruments TMS320C55x DSP family";
1963 case EM_MMDSP_PLUS
: return "STMicroelectronics 64bit VLIW Data Signal Processor";
1964 case EM_CYPRESS_M8C
: return "Cypress M8C microprocessor";
1965 case EM_R32C
: return "Renesas R32C series microprocessors";
1966 case EM_TRIMEDIA
: return "NXP Semiconductors TriMedia architecture family";
1967 case EM_QDSP6
: return "QUALCOMM DSP6 Processor";
1968 case EM_8051
: return "Intel 8051 and variants";
1969 case EM_STXP7X
: return "STMicroelectronics STxP7x family";
1970 case EM_NDS32
: return "Andes Technology compact code size embedded RISC processor family";
1971 case EM_ECOG1X
: return "Cyan Technology eCOG1X family";
1972 case EM_MAXQ30
: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
1973 case EM_XIMO16
: return "New Japan Radio (NJR) 16-bit DSP Processor";
1974 case EM_MANIK
: return "M2000 Reconfigurable RISC Microprocessor";
1975 case EM_CRAYNV2
: return "Cray Inc. NV2 vector architecture";
1976 case EM_CYGNUS_MEP
: return "Toshiba MeP Media Engine";
1978 case EM_CR16_OLD
: return "National Semiconductor's CR16";
1979 case EM_MICROBLAZE
: return "Xilinx MicroBlaze";
1980 case EM_MICROBLAZE_OLD
: return "Xilinx MicroBlaze";
1981 case EM_RX
: return "Renesas RX";
1982 case EM_METAG
: return "Imagination Technologies META processor architecture";
1983 case EM_MCST_ELBRUS
: return "MCST Elbrus general purpose hardware architecture";
1984 case EM_ECOG16
: return "Cyan Technology eCOG16 family";
1985 case EM_ETPU
: return "Freescale Extended Time Processing Unit";
1986 case EM_SLE9X
: return "Infineon Technologies SLE9X core";
1987 case EM_AVR32
: return "Atmel Corporation 32-bit microprocessor family";
1988 case EM_STM8
: return "STMicroeletronics STM8 8-bit microcontroller";
1989 case EM_TILE64
: return "Tilera TILE64 multicore architecture family";
1990 case EM_TILEPRO
: return "Tilera TILEPro multicore architecture family";
1991 case EM_CUDA
: return "NVIDIA CUDA architecture";
1993 snprintf (buff
, sizeof (buff
), _("<unknown>: 0x%x"), e_machine
);
1999 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
2004 eabi
= EF_ARM_EABI_VERSION (e_flags
);
2005 e_flags
&= ~ EF_ARM_EABIMASK
;
2007 /* Handle "generic" ARM flags. */
2008 if (e_flags
& EF_ARM_RELEXEC
)
2010 strcat (buf
, ", relocatable executable");
2011 e_flags
&= ~ EF_ARM_RELEXEC
;
2014 if (e_flags
& EF_ARM_HASENTRY
)
2016 strcat (buf
, ", has entry point");
2017 e_flags
&= ~ EF_ARM_HASENTRY
;
2020 /* Now handle EABI specific flags. */
2024 strcat (buf
, ", <unrecognized EABI>");
2029 case EF_ARM_EABI_VER1
:
2030 strcat (buf
, ", Version1 EABI");
2035 /* Process flags one bit at a time. */
2036 flag
= e_flags
& - e_flags
;
2041 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2042 strcat (buf
, ", sorted symbol tables");
2052 case EF_ARM_EABI_VER2
:
2053 strcat (buf
, ", Version2 EABI");
2058 /* Process flags one bit at a time. */
2059 flag
= e_flags
& - e_flags
;
2064 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
2065 strcat (buf
, ", sorted symbol tables");
2068 case EF_ARM_DYNSYMSUSESEGIDX
:
2069 strcat (buf
, ", dynamic symbols use segment index");
2072 case EF_ARM_MAPSYMSFIRST
:
2073 strcat (buf
, ", mapping symbols precede others");
2083 case EF_ARM_EABI_VER3
:
2084 strcat (buf
, ", Version3 EABI");
2087 case EF_ARM_EABI_VER4
:
2088 strcat (buf
, ", Version4 EABI");
2091 case EF_ARM_EABI_VER5
:
2092 strcat (buf
, ", Version5 EABI");
2098 /* Process flags one bit at a time. */
2099 flag
= e_flags
& - e_flags
;
2105 strcat (buf
, ", BE8");
2109 strcat (buf
, ", LE8");
2119 case EF_ARM_EABI_UNKNOWN
:
2120 strcat (buf
, ", GNU EABI");
2125 /* Process flags one bit at a time. */
2126 flag
= e_flags
& - e_flags
;
2131 case EF_ARM_INTERWORK
:
2132 strcat (buf
, ", interworking enabled");
2135 case EF_ARM_APCS_26
:
2136 strcat (buf
, ", uses APCS/26");
2139 case EF_ARM_APCS_FLOAT
:
2140 strcat (buf
, ", uses APCS/float");
2144 strcat (buf
, ", position independent");
2148 strcat (buf
, ", 8 bit structure alignment");
2151 case EF_ARM_NEW_ABI
:
2152 strcat (buf
, ", uses new ABI");
2155 case EF_ARM_OLD_ABI
:
2156 strcat (buf
, ", uses old ABI");
2159 case EF_ARM_SOFT_FLOAT
:
2160 strcat (buf
, ", software FP");
2163 case EF_ARM_VFP_FLOAT
:
2164 strcat (buf
, ", VFP");
2167 case EF_ARM_MAVERICK_FLOAT
:
2168 strcat (buf
, ", Maverick FP");
2179 strcat (buf
,", <unknown>");
2183 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
2185 static char buf
[1024];
2197 decode_ARM_machine_flags (e_flags
, buf
);
2201 switch (e_flags
& EF_FRV_CPU_MASK
)
2203 case EF_FRV_CPU_GENERIC
:
2207 strcat (buf
, ", fr???");
2210 case EF_FRV_CPU_FR300
:
2211 strcat (buf
, ", fr300");
2214 case EF_FRV_CPU_FR400
:
2215 strcat (buf
, ", fr400");
2217 case EF_FRV_CPU_FR405
:
2218 strcat (buf
, ", fr405");
2221 case EF_FRV_CPU_FR450
:
2222 strcat (buf
, ", fr450");
2225 case EF_FRV_CPU_FR500
:
2226 strcat (buf
, ", fr500");
2228 case EF_FRV_CPU_FR550
:
2229 strcat (buf
, ", fr550");
2232 case EF_FRV_CPU_SIMPLE
:
2233 strcat (buf
, ", simple");
2235 case EF_FRV_CPU_TOMCAT
:
2236 strcat (buf
, ", tomcat");
2242 if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_M68000
)
2243 strcat (buf
, ", m68000");
2244 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_CPU32
)
2245 strcat (buf
, ", cpu32");
2246 else if ((e_flags
& EF_M68K_ARCH_MASK
) == EF_M68K_FIDO
)
2247 strcat (buf
, ", fido_a");
2250 char const * isa
= _("unknown");
2251 char const * mac
= _("unknown mac");
2252 char const * additional
= NULL
;
2254 switch (e_flags
& EF_M68K_CF_ISA_MASK
)
2256 case EF_M68K_CF_ISA_A_NODIV
:
2258 additional
= ", nodiv";
2260 case EF_M68K_CF_ISA_A
:
2263 case EF_M68K_CF_ISA_A_PLUS
:
2266 case EF_M68K_CF_ISA_B_NOUSP
:
2268 additional
= ", nousp";
2270 case EF_M68K_CF_ISA_B
:
2274 strcat (buf
, ", cf, isa ");
2277 strcat (buf
, additional
);
2278 if (e_flags
& EF_M68K_CF_FLOAT
)
2279 strcat (buf
, ", float");
2280 switch (e_flags
& EF_M68K_CF_MAC_MASK
)
2285 case EF_M68K_CF_MAC
:
2288 case EF_M68K_CF_EMAC
:
2301 if (e_flags
& EF_PPC_EMB
)
2302 strcat (buf
, ", emb");
2304 if (e_flags
& EF_PPC_RELOCATABLE
)
2305 strcat (buf
, ", relocatable");
2307 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2308 strcat (buf
, ", relocatable-lib");
2312 case EM_CYGNUS_V850
:
2313 switch (e_flags
& EF_V850_ARCH
)
2316 strcat (buf
, ", v850e1");
2319 strcat (buf
, ", v850e");
2322 strcat (buf
, ", v850");
2325 strcat (buf
, ", unknown v850 architecture variant");
2331 case EM_CYGNUS_M32R
:
2332 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2333 strcat (buf
, ", m32r");
2337 case EM_MIPS_RS3_LE
:
2338 if (e_flags
& EF_MIPS_NOREORDER
)
2339 strcat (buf
, ", noreorder");
2341 if (e_flags
& EF_MIPS_PIC
)
2342 strcat (buf
, ", pic");
2344 if (e_flags
& EF_MIPS_CPIC
)
2345 strcat (buf
, ", cpic");
2347 if (e_flags
& EF_MIPS_UCODE
)
2348 strcat (buf
, ", ugen_reserved");
2350 if (e_flags
& EF_MIPS_ABI2
)
2351 strcat (buf
, ", abi2");
2353 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2354 strcat (buf
, ", odk first");
2356 if (e_flags
& EF_MIPS_32BITMODE
)
2357 strcat (buf
, ", 32bitmode");
2359 switch ((e_flags
& EF_MIPS_MACH
))
2361 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2362 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2363 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2364 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2365 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2366 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2367 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2368 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2369 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2370 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2371 case E_MIPS_MACH_LS2E
: strcat (buf
, ", loongson-2e"); break;
2372 case E_MIPS_MACH_LS2F
: strcat (buf
, ", loongson-2f"); break;
2373 case E_MIPS_MACH_OCTEON
: strcat (buf
, ", octeon"); break;
2374 case E_MIPS_MACH_OCTEON2
: strcat (buf
, ", octeon2"); break;
2375 case E_MIPS_MACH_XLR
: strcat (buf
, ", xlr"); break;
2377 /* We simply ignore the field in this case to avoid confusion:
2378 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2381 default: strcat (buf
, ", unknown CPU"); break;
2384 switch ((e_flags
& EF_MIPS_ABI
))
2386 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2387 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2388 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2389 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2391 /* We simply ignore the field in this case to avoid confusion:
2392 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2393 This means it is likely to be an o32 file, but not for
2396 default: strcat (buf
, ", unknown ABI"); break;
2399 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2400 strcat (buf
, ", mdmx");
2402 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2403 strcat (buf
, ", mips16");
2405 switch ((e_flags
& EF_MIPS_ARCH
))
2407 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2408 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2409 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2410 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2411 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2412 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2413 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2414 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2415 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2416 default: strcat (buf
, ", unknown ISA"); break;
2422 switch ((e_flags
& EF_SH_MACH_MASK
))
2424 case EF_SH1
: strcat (buf
, ", sh1"); break;
2425 case EF_SH2
: strcat (buf
, ", sh2"); break;
2426 case EF_SH3
: strcat (buf
, ", sh3"); break;
2427 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2428 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2429 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2430 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2431 case EF_SH4
: strcat (buf
, ", sh4"); break;
2432 case EF_SH5
: strcat (buf
, ", sh5"); break;
2433 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2434 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2435 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2436 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2437 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2438 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2439 case EF_SH3_NOMMU
: strcat (buf
, ", sh3-nommu"); break;
2440 case EF_SH4_NOMMU_NOFPU
: strcat (buf
, ", sh4-nommu-nofpu"); break;
2441 case EF_SH2A_SH4_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2442 case EF_SH2A_SH3_NOFPU
: strcat (buf
, ", sh2a-nofpu-or-sh3-nommu"); break;
2443 case EF_SH2A_SH4
: strcat (buf
, ", sh2a-or-sh4"); break;
2444 case EF_SH2A_SH3E
: strcat (buf
, ", sh2a-or-sh3e"); break;
2445 default: strcat (buf
, ", unknown ISA"); break;
2451 if (e_flags
& EF_SPARC_32PLUS
)
2452 strcat (buf
, ", v8+");
2454 if (e_flags
& EF_SPARC_SUN_US1
)
2455 strcat (buf
, ", ultrasparcI");
2457 if (e_flags
& EF_SPARC_SUN_US3
)
2458 strcat (buf
, ", ultrasparcIII");
2460 if (e_flags
& EF_SPARC_HAL_R1
)
2461 strcat (buf
, ", halr1");
2463 if (e_flags
& EF_SPARC_LEDATA
)
2464 strcat (buf
, ", ledata");
2466 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2467 strcat (buf
, ", tso");
2469 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2470 strcat (buf
, ", pso");
2472 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2473 strcat (buf
, ", rmo");
2477 switch (e_flags
& EF_PARISC_ARCH
)
2479 case EFA_PARISC_1_0
:
2480 strcpy (buf
, ", PA-RISC 1.0");
2482 case EFA_PARISC_1_1
:
2483 strcpy (buf
, ", PA-RISC 1.1");
2485 case EFA_PARISC_2_0
:
2486 strcpy (buf
, ", PA-RISC 2.0");
2491 if (e_flags
& EF_PARISC_TRAPNIL
)
2492 strcat (buf
, ", trapnil");
2493 if (e_flags
& EF_PARISC_EXT
)
2494 strcat (buf
, ", ext");
2495 if (e_flags
& EF_PARISC_LSB
)
2496 strcat (buf
, ", lsb");
2497 if (e_flags
& EF_PARISC_WIDE
)
2498 strcat (buf
, ", wide");
2499 if (e_flags
& EF_PARISC_NO_KABP
)
2500 strcat (buf
, ", no kabp");
2501 if (e_flags
& EF_PARISC_LAZYSWAP
)
2502 strcat (buf
, ", lazyswap");
2507 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2508 strcat (buf
, ", new calling convention");
2510 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2511 strcat (buf
, ", gnu calling convention");
2515 if ((e_flags
& EF_IA_64_ABI64
))
2516 strcat (buf
, ", 64-bit");
2518 strcat (buf
, ", 32-bit");
2519 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2520 strcat (buf
, ", reduced fp model");
2521 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2522 strcat (buf
, ", no function descriptors, constant gp");
2523 else if ((e_flags
& EF_IA_64_CONS_GP
))
2524 strcat (buf
, ", constant gp");
2525 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2526 strcat (buf
, ", absolute");
2530 if ((e_flags
& EF_VAX_NONPIC
))
2531 strcat (buf
, ", non-PIC");
2532 if ((e_flags
& EF_VAX_DFLOAT
))
2533 strcat (buf
, ", D-Float");
2534 if ((e_flags
& EF_VAX_GFLOAT
))
2535 strcat (buf
, ", G-Float");
2539 if (e_flags
& E_FLAG_RX_64BIT_DOUBLES
)
2540 strcat (buf
, ", 64-bit doubles");
2541 if (e_flags
& E_FLAG_RX_DSP
)
2542 strcat (buf
, ", dsp");
2545 if (e_flags
& EF_S390_HIGH_GPRS
)
2546 strcat (buf
, ", highgprs");
2554 get_osabi_name (unsigned int osabi
)
2556 static char buff
[32];
2560 case ELFOSABI_NONE
: return "UNIX - System V";
2561 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2562 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2563 case ELFOSABI_LINUX
: return "UNIX - Linux";
2564 case ELFOSABI_HURD
: return "GNU/Hurd";
2565 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2566 case ELFOSABI_AIX
: return "UNIX - AIX";
2567 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2568 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2569 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2570 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2571 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2572 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2573 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2574 case ELFOSABI_AROS
: return "AROS";
2575 case ELFOSABI_FENIXOS
: return "FenixOS";
2576 case ELFOSABI_STANDALONE
: return _("Standalone App");
2577 case ELFOSABI_ARM
: return "ARM";
2579 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2585 get_arm_segment_type (unsigned long type
)
2599 get_mips_segment_type (unsigned long type
)
2603 case PT_MIPS_REGINFO
:
2605 case PT_MIPS_RTPROC
:
2607 case PT_MIPS_OPTIONS
:
2617 get_parisc_segment_type (unsigned long type
)
2621 case PT_HP_TLS
: return "HP_TLS";
2622 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2623 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2624 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2625 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2626 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2627 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2628 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2629 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2630 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2631 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2632 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2633 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2634 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2635 case PT_HP_STACK
: return "HP_STACK";
2636 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2637 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2638 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2639 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2648 get_ia64_segment_type (unsigned long type
)
2652 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2653 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2654 case PT_HP_TLS
: return "HP_TLS";
2655 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2656 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2657 case PT_IA_64_HP_STACK
: return "HP_STACK";
2666 get_segment_type (unsigned long p_type
)
2668 static char buff
[32];
2672 case PT_NULL
: return "NULL";
2673 case PT_LOAD
: return "LOAD";
2674 case PT_DYNAMIC
: return "DYNAMIC";
2675 case PT_INTERP
: return "INTERP";
2676 case PT_NOTE
: return "NOTE";
2677 case PT_SHLIB
: return "SHLIB";
2678 case PT_PHDR
: return "PHDR";
2679 case PT_TLS
: return "TLS";
2681 case PT_GNU_EH_FRAME
:
2682 return "GNU_EH_FRAME";
2683 case PT_GNU_STACK
: return "GNU_STACK";
2684 case PT_GNU_RELRO
: return "GNU_RELRO";
2687 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2689 const char * result
;
2691 switch (elf_header
.e_machine
)
2694 result
= get_arm_segment_type (p_type
);
2697 case EM_MIPS_RS3_LE
:
2698 result
= get_mips_segment_type (p_type
);
2701 result
= get_parisc_segment_type (p_type
);
2704 result
= get_ia64_segment_type (p_type
);
2714 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2716 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2718 const char * result
;
2720 switch (elf_header
.e_machine
)
2723 result
= get_parisc_segment_type (p_type
);
2726 result
= get_ia64_segment_type (p_type
);
2736 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2739 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2746 get_mips_section_type_name (unsigned int sh_type
)
2750 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2751 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2752 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2753 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2754 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2755 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2756 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2757 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2758 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2759 case SHT_MIPS_RELD
: return "MIPS_RELD";
2760 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2761 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2762 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2763 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2764 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2765 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2766 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2767 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2768 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2769 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2770 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2771 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2772 case SHT_MIPS_LINE
: return "MIPS_LINE";
2773 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2774 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2775 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2776 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2777 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2778 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2779 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2780 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2781 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2782 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2783 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2784 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2785 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2786 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2787 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2788 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2796 get_parisc_section_type_name (unsigned int sh_type
)
2800 case SHT_PARISC_EXT
: return "PARISC_EXT";
2801 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2802 case SHT_PARISC_DOC
: return "PARISC_DOC";
2803 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2804 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2805 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2806 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2814 get_ia64_section_type_name (unsigned int sh_type
)
2816 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2817 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2818 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2822 case SHT_IA_64_EXT
: return "IA_64_EXT";
2823 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2824 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2825 case SHT_IA_64_VMS_TRACE
: return "VMS_TRACE";
2826 case SHT_IA_64_VMS_TIE_SIGNATURES
: return "VMS_TIE_SIGNATURES";
2827 case SHT_IA_64_VMS_DEBUG
: return "VMS_DEBUG";
2828 case SHT_IA_64_VMS_DEBUG_STR
: return "VMS_DEBUG_STR";
2829 case SHT_IA_64_VMS_LINKAGES
: return "VMS_LINKAGES";
2830 case SHT_IA_64_VMS_SYMBOL_VECTOR
: return "VMS_SYMBOL_VECTOR";
2831 case SHT_IA_64_VMS_FIXUP
: return "VMS_FIXUP";
2839 get_x86_64_section_type_name (unsigned int sh_type
)
2843 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2851 get_arm_section_type_name (unsigned int sh_type
)
2855 case SHT_ARM_EXIDX
: return "ARM_EXIDX";
2856 case SHT_ARM_PREEMPTMAP
: return "ARM_PREEMPTMAP";
2857 case SHT_ARM_ATTRIBUTES
: return "ARM_ATTRIBUTES";
2858 case SHT_ARM_DEBUGOVERLAY
: return "ARM_DEBUGOVERLAY";
2859 case SHT_ARM_OVERLAYSECTION
: return "ARM_OVERLAYSECTION";
2867 get_section_type_name (unsigned int sh_type
)
2869 static char buff
[32];
2873 case SHT_NULL
: return "NULL";
2874 case SHT_PROGBITS
: return "PROGBITS";
2875 case SHT_SYMTAB
: return "SYMTAB";
2876 case SHT_STRTAB
: return "STRTAB";
2877 case SHT_RELA
: return "RELA";
2878 case SHT_HASH
: return "HASH";
2879 case SHT_DYNAMIC
: return "DYNAMIC";
2880 case SHT_NOTE
: return "NOTE";
2881 case SHT_NOBITS
: return "NOBITS";
2882 case SHT_REL
: return "REL";
2883 case SHT_SHLIB
: return "SHLIB";
2884 case SHT_DYNSYM
: return "DYNSYM";
2885 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2886 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2887 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2888 case SHT_GNU_HASH
: return "GNU_HASH";
2889 case SHT_GROUP
: return "GROUP";
2890 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2891 case SHT_GNU_verdef
: return "VERDEF";
2892 case SHT_GNU_verneed
: return "VERNEED";
2893 case SHT_GNU_versym
: return "VERSYM";
2894 case 0x6ffffff0: return "VERSYM";
2895 case 0x6ffffffc: return "VERDEF";
2896 case 0x7ffffffd: return "AUXILIARY";
2897 case 0x7fffffff: return "FILTER";
2898 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2901 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2903 const char * result
;
2905 switch (elf_header
.e_machine
)
2908 case EM_MIPS_RS3_LE
:
2909 result
= get_mips_section_type_name (sh_type
);
2912 result
= get_parisc_section_type_name (sh_type
);
2915 result
= get_ia64_section_type_name (sh_type
);
2919 result
= get_x86_64_section_type_name (sh_type
);
2922 result
= get_arm_section_type_name (sh_type
);
2932 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2934 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2936 const char * result
;
2938 switch (elf_header
.e_machine
)
2941 result
= get_ia64_section_type_name (sh_type
);
2951 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2953 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2954 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2956 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2962 #define OPTION_DEBUG_DUMP 512
2963 #define OPTION_DYN_SYMS 513
2965 static struct option options
[] =
2967 {"all", no_argument
, 0, 'a'},
2968 {"file-header", no_argument
, 0, 'h'},
2969 {"program-headers", no_argument
, 0, 'l'},
2970 {"headers", no_argument
, 0, 'e'},
2971 {"histogram", no_argument
, 0, 'I'},
2972 {"segments", no_argument
, 0, 'l'},
2973 {"sections", no_argument
, 0, 'S'},
2974 {"section-headers", no_argument
, 0, 'S'},
2975 {"section-groups", no_argument
, 0, 'g'},
2976 {"section-details", no_argument
, 0, 't'},
2977 {"full-section-name",no_argument
, 0, 'N'},
2978 {"symbols", no_argument
, 0, 's'},
2979 {"syms", no_argument
, 0, 's'},
2980 {"dyn-syms", no_argument
, 0, OPTION_DYN_SYMS
},
2981 {"relocs", no_argument
, 0, 'r'},
2982 {"notes", no_argument
, 0, 'n'},
2983 {"dynamic", no_argument
, 0, 'd'},
2984 {"arch-specific", no_argument
, 0, 'A'},
2985 {"version-info", no_argument
, 0, 'V'},
2986 {"use-dynamic", no_argument
, 0, 'D'},
2987 {"unwind", no_argument
, 0, 'u'},
2988 {"archive-index", no_argument
, 0, 'c'},
2989 {"hex-dump", required_argument
, 0, 'x'},
2990 {"relocated-dump", required_argument
, 0, 'R'},
2991 {"string-dump", required_argument
, 0, 'p'},
2992 #ifdef SUPPORT_DISASSEMBLY
2993 {"instruction-dump", required_argument
, 0, 'i'},
2995 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2997 {"version", no_argument
, 0, 'v'},
2998 {"wide", no_argument
, 0, 'W'},
2999 {"help", no_argument
, 0, 'H'},
3000 {0, no_argument
, 0, 0}
3004 usage (FILE * stream
)
3006 fprintf (stream
, _("Usage: readelf <option(s)> elf-file(s)\n"));
3007 fprintf (stream
, _(" Display information about the contents of ELF format files\n"));
3008 fprintf (stream
, _(" Options are:\n\
3009 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
3010 -h --file-header Display the ELF file header\n\
3011 -l --program-headers Display the program headers\n\
3012 --segments An alias for --program-headers\n\
3013 -S --section-headers Display the sections' header\n\
3014 --sections An alias for --section-headers\n\
3015 -g --section-groups Display the section groups\n\
3016 -t --section-details Display the section details\n\
3017 -e --headers Equivalent to: -h -l -S\n\
3018 -s --syms Display the symbol table\n\
3019 --symbols An alias for --syms\n\
3020 --dyn-syms Display the dynamic symbol table\n\
3021 -n --notes Display the core notes (if present)\n\
3022 -r --relocs Display the relocations (if present)\n\
3023 -u --unwind Display the unwind info (if present)\n\
3024 -d --dynamic Display the dynamic section (if present)\n\
3025 -V --version-info Display the version sections (if present)\n\
3026 -A --arch-specific Display architecture specific information (if any).\n\
3027 -c --archive-index Display the symbol/file index in an archive\n\
3028 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
3029 -x --hex-dump=<number|name>\n\
3030 Dump the contents of section <number|name> as bytes\n\
3031 -p --string-dump=<number|name>\n\
3032 Dump the contents of section <number|name> as strings\n\
3033 -R --relocated-dump=<number|name>\n\
3034 Dump the contents of section <number|name> as relocated bytes\n\
3035 -w[lLiaprmfFsoRt] or\n\
3036 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
3037 =frames-interp,=str,=loc,=Ranges,=pubtypes]\n\
3038 Display the contents of DWARF2 debug sections\n"));
3039 #ifdef SUPPORT_DISASSEMBLY
3040 fprintf (stream
, _("\
3041 -i --instruction-dump=<number|name>\n\
3042 Disassemble the contents of section <number|name>\n"));
3044 fprintf (stream
, _("\
3045 -I --histogram Display histogram of bucket list lengths\n\
3046 -W --wide Allow output width to exceed 80 characters\n\
3047 @<file> Read options from <file>\n\
3048 -H --help Display this information\n\
3049 -v --version Display the version number of readelf\n"));
3051 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
3052 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
3054 exit (stream
== stdout
? 0 : 1);
3057 /* Record the fact that the user wants the contents of section number
3058 SECTION to be displayed using the method(s) encoded as flags bits
3059 in TYPE. Note, TYPE can be zero if we are creating the array for
3063 request_dump_bynumber (unsigned int section
, dump_type type
)
3065 if (section
>= num_dump_sects
)
3067 dump_type
* new_dump_sects
;
3069 new_dump_sects
= (dump_type
*) calloc (section
+ 1,
3070 sizeof (* dump_sects
));
3072 if (new_dump_sects
== NULL
)
3073 error (_("Out of memory allocating dump request table.\n"));
3076 /* Copy current flag settings. */
3077 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
* sizeof (* dump_sects
));
3081 dump_sects
= new_dump_sects
;
3082 num_dump_sects
= section
+ 1;
3087 dump_sects
[section
] |= type
;
3092 /* Request a dump by section name. */
3095 request_dump_byname (const char * section
, dump_type type
)
3097 struct dump_list_entry
* new_request
;
3099 new_request
= (struct dump_list_entry
*)
3100 malloc (sizeof (struct dump_list_entry
));
3102 error (_("Out of memory allocating dump request table.\n"));
3104 new_request
->name
= strdup (section
);
3105 if (!new_request
->name
)
3106 error (_("Out of memory allocating dump request table.\n"));
3108 new_request
->type
= type
;
3110 new_request
->next
= dump_sects_byname
;
3111 dump_sects_byname
= new_request
;
3115 request_dump (dump_type type
)
3121 section
= strtoul (optarg
, & cp
, 0);
3123 if (! *cp
&& section
>= 0)
3124 request_dump_bynumber (section
, type
);
3126 request_dump_byname (optarg
, type
);
3131 parse_args (int argc
, char ** argv
)
3138 while ((c
= getopt_long
3139 (argc
, argv
, "ADHINR:SVWacdeghi:lnp:rstuvw::x:", options
, NULL
)) != EOF
)
3157 do_section_groups
++;
3165 do_section_groups
++;
3170 do_section_details
++;
3214 request_dump (HEX_DUMP
);
3217 request_dump (STRING_DUMP
);
3220 request_dump (RELOC_DUMP
);
3227 dwarf_select_sections_all ();
3232 dwarf_select_sections_by_letters (optarg
);
3235 case OPTION_DEBUG_DUMP
:
3242 dwarf_select_sections_by_names (optarg
);
3245 case OPTION_DYN_SYMS
:
3248 #ifdef SUPPORT_DISASSEMBLY
3250 request_dump (DISASS_DUMP
);
3254 print_version (program_name
);
3263 /* xgettext:c-format */
3264 error (_("Invalid option '-%c'\n"), c
);
3271 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
3272 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
3273 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
3274 && !do_section_groups
&& !do_archive_index
3279 warn (_("Nothing to do.\n"));
3285 get_elf_class (unsigned int elf_class
)
3287 static char buff
[32];
3291 case ELFCLASSNONE
: return _("none");
3292 case ELFCLASS32
: return "ELF32";
3293 case ELFCLASS64
: return "ELF64";
3295 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
3301 get_data_encoding (unsigned int encoding
)
3303 static char buff
[32];
3307 case ELFDATANONE
: return _("none");
3308 case ELFDATA2LSB
: return _("2's complement, little endian");
3309 case ELFDATA2MSB
: return _("2's complement, big endian");
3311 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
3316 /* Decode the data held in 'elf_header'. */
3319 process_file_header (void)
3321 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
3322 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
3323 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
3324 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
3327 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3331 init_dwarf_regnames (elf_header
.e_machine
);
3337 printf (_("ELF Header:\n"));
3338 printf (_(" Magic: "));
3339 for (i
= 0; i
< EI_NIDENT
; i
++)
3340 printf ("%2.2x ", elf_header
.e_ident
[i
]);
3342 printf (_(" Class: %s\n"),
3343 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
3344 printf (_(" Data: %s\n"),
3345 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
3346 printf (_(" Version: %d %s\n"),
3347 elf_header
.e_ident
[EI_VERSION
],
3348 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3350 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3353 printf (_(" OS/ABI: %s\n"),
3354 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3355 printf (_(" ABI Version: %d\n"),
3356 elf_header
.e_ident
[EI_ABIVERSION
]);
3357 printf (_(" Type: %s\n"),
3358 get_file_type (elf_header
.e_type
));
3359 printf (_(" Machine: %s\n"),
3360 get_machine_name (elf_header
.e_machine
));
3361 printf (_(" Version: 0x%lx\n"),
3362 (unsigned long) elf_header
.e_version
);
3364 printf (_(" Entry point address: "));
3365 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3366 printf (_("\n Start of program headers: "));
3367 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3368 printf (_(" (bytes into file)\n Start of section headers: "));
3369 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3370 printf (_(" (bytes into file)\n"));
3372 printf (_(" Flags: 0x%lx%s\n"),
3373 (unsigned long) elf_header
.e_flags
,
3374 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3375 printf (_(" Size of this header: %ld (bytes)\n"),
3376 (long) elf_header
.e_ehsize
);
3377 printf (_(" Size of program headers: %ld (bytes)\n"),
3378 (long) elf_header
.e_phentsize
);
3379 printf (_(" Number of program headers: %ld"),
3380 (long) elf_header
.e_phnum
);
3381 if (section_headers
!= NULL
3382 && elf_header
.e_phnum
== PN_XNUM
3383 && section_headers
[0].sh_info
!= 0)
3384 printf (_(" (%ld)"), (long) section_headers
[0].sh_info
);
3385 putc ('\n', stdout
);
3386 printf (_(" Size of section headers: %ld (bytes)\n"),
3387 (long) elf_header
.e_shentsize
);
3388 printf (_(" Number of section headers: %ld"),
3389 (long) elf_header
.e_shnum
);
3390 if (section_headers
!= NULL
&& elf_header
.e_shnum
== SHN_UNDEF
)
3391 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3392 putc ('\n', stdout
);
3393 printf (_(" Section header string table index: %ld"),
3394 (long) elf_header
.e_shstrndx
);
3395 if (section_headers
!= NULL
3396 && elf_header
.e_shstrndx
== (SHN_XINDEX
& 0xffff))
3397 printf (" (%u)", section_headers
[0].sh_link
);
3398 else if (elf_header
.e_shstrndx
!= SHN_UNDEF
3399 && elf_header
.e_shstrndx
>= elf_header
.e_shnum
)
3400 printf (" <corrupt: out of range>");
3401 putc ('\n', stdout
);
3404 if (section_headers
!= NULL
)
3406 if (elf_header
.e_phnum
== PN_XNUM
3407 && section_headers
[0].sh_info
!= 0)
3408 elf_header
.e_phnum
= section_headers
[0].sh_info
;
3409 if (elf_header
.e_shnum
== SHN_UNDEF
)
3410 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3411 if (elf_header
.e_shstrndx
== (SHN_XINDEX
& 0xffff))
3412 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3413 else if (elf_header
.e_shstrndx
>= elf_header
.e_shnum
)
3414 elf_header
.e_shstrndx
= SHN_UNDEF
;
3415 free (section_headers
);
3416 section_headers
= NULL
;
3424 get_32bit_program_headers (FILE * file
, Elf_Internal_Phdr
* pheaders
)
3426 Elf32_External_Phdr
* phdrs
;
3427 Elf32_External_Phdr
* external
;
3428 Elf_Internal_Phdr
* internal
;
3431 phdrs
= (Elf32_External_Phdr
*) get_data (NULL
, file
, elf_header
.e_phoff
,
3432 elf_header
.e_phentsize
,
3434 _("program headers"));
3438 for (i
= 0, internal
= pheaders
, external
= phdrs
;
3439 i
< elf_header
.e_phnum
;
3440 i
++, internal
++, external
++)
3442 internal
->p_type
= BYTE_GET (external
->p_type
);
3443 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3444 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3445 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3446 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3447 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3448 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3449 internal
->p_align
= BYTE_GET (external
->p_align
);
3458 get_64bit_program_headers (FILE * file
, Elf_Internal_Phdr
* pheaders
)
3460 Elf64_External_Phdr
* phdrs
;
3461 Elf64_External_Phdr
* external
;
3462 Elf_Internal_Phdr
* internal
;
3465 phdrs
= (Elf64_External_Phdr
*) get_data (NULL
, file
, elf_header
.e_phoff
,
3466 elf_header
.e_phentsize
,
3468 _("program headers"));
3472 for (i
= 0, internal
= pheaders
, external
= phdrs
;
3473 i
< elf_header
.e_phnum
;
3474 i
++, internal
++, external
++)
3476 internal
->p_type
= BYTE_GET (external
->p_type
);
3477 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3478 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3479 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3480 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3481 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3482 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3483 internal
->p_align
= BYTE_GET (external
->p_align
);
3491 /* Returns 1 if the program headers were read into `program_headers'. */
3494 get_program_headers (FILE * file
)
3496 Elf_Internal_Phdr
* phdrs
;
3498 /* Check cache of prior read. */
3499 if (program_headers
!= NULL
)
3502 phdrs
= (Elf_Internal_Phdr
*) cmalloc (elf_header
.e_phnum
,
3503 sizeof (Elf_Internal_Phdr
));
3507 error (_("Out of memory\n"));
3512 ? get_32bit_program_headers (file
, phdrs
)
3513 : get_64bit_program_headers (file
, phdrs
))
3515 program_headers
= phdrs
;
3523 /* Returns 1 if the program headers were loaded. */
3526 process_program_headers (FILE * file
)
3528 Elf_Internal_Phdr
* segment
;
3531 if (elf_header
.e_phnum
== 0)
3534 printf (_("\nThere are no program headers in this file.\n"));
3538 if (do_segments
&& !do_header
)
3540 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3541 printf (_("Entry point "));
3542 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3543 printf (_("\nThere are %d program headers, starting at offset "),
3544 elf_header
.e_phnum
);
3545 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3549 if (! get_program_headers (file
))
3554 if (elf_header
.e_phnum
> 1)
3555 printf (_("\nProgram Headers:\n"));
3557 printf (_("\nProgram Headers:\n"));
3561 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3564 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3568 (_(" Type Offset VirtAddr PhysAddr\n"));
3570 (_(" FileSiz MemSiz Flags Align\n"));
3577 for (i
= 0, segment
= program_headers
;
3578 i
< elf_header
.e_phnum
;
3583 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3587 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3588 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3589 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3590 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3591 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3593 (segment
->p_flags
& PF_R
? 'R' : ' '),
3594 (segment
->p_flags
& PF_W
? 'W' : ' '),
3595 (segment
->p_flags
& PF_X
? 'E' : ' '));
3596 printf ("%#lx", (unsigned long) segment
->p_align
);
3600 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3601 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3604 print_vma (segment
->p_offset
, FULL_HEX
);
3608 print_vma (segment
->p_vaddr
, FULL_HEX
);
3610 print_vma (segment
->p_paddr
, FULL_HEX
);
3613 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3614 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3617 print_vma (segment
->p_filesz
, FULL_HEX
);
3621 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3622 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3625 print_vma (segment
->p_offset
, FULL_HEX
);
3629 (segment
->p_flags
& PF_R
? 'R' : ' '),
3630 (segment
->p_flags
& PF_W
? 'W' : ' '),
3631 (segment
->p_flags
& PF_X
? 'E' : ' '));
3633 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3634 printf ("%#lx", (unsigned long) segment
->p_align
);
3637 print_vma (segment
->p_align
, PREFIX_HEX
);
3642 print_vma (segment
->p_offset
, FULL_HEX
);
3644 print_vma (segment
->p_vaddr
, FULL_HEX
);
3646 print_vma (segment
->p_paddr
, FULL_HEX
);
3648 print_vma (segment
->p_filesz
, FULL_HEX
);
3650 print_vma (segment
->p_memsz
, FULL_HEX
);
3652 (segment
->p_flags
& PF_R
? 'R' : ' '),
3653 (segment
->p_flags
& PF_W
? 'W' : ' '),
3654 (segment
->p_flags
& PF_X
? 'E' : ' '));
3655 print_vma (segment
->p_align
, HEX
);
3659 switch (segment
->p_type
)
3663 error (_("more than one dynamic segment\n"));
3665 /* By default, assume that the .dynamic section is the first
3666 section in the DYNAMIC segment. */
3667 dynamic_addr
= segment
->p_offset
;
3668 dynamic_size
= segment
->p_filesz
;
3670 /* Try to locate the .dynamic section. If there is
3671 a section header table, we can easily locate it. */
3672 if (section_headers
!= NULL
)
3674 Elf_Internal_Shdr
* sec
;
3676 sec
= find_section (".dynamic");
3677 if (sec
== NULL
|| sec
->sh_size
== 0)
3679 error (_("no .dynamic section in the dynamic segment\n"));
3683 if (sec
->sh_type
== SHT_NOBITS
)
3689 dynamic_addr
= sec
->sh_offset
;
3690 dynamic_size
= sec
->sh_size
;
3692 if (dynamic_addr
< segment
->p_offset
3693 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3694 warn (_("the .dynamic section is not contained"
3695 " within the dynamic segment\n"));
3696 else if (dynamic_addr
> segment
->p_offset
)
3697 warn (_("the .dynamic section is not the first section"
3698 " in the dynamic segment.\n"));
3703 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3705 error (_("Unable to find program interpreter name\n"));
3709 int ret
= snprintf (fmt
, sizeof (fmt
), "%%%ds", PATH_MAX
);
3711 if (ret
>= (int) sizeof (fmt
) || ret
< 0)
3712 error (_("Internal error: failed to create format string to display program interpreter\n"));
3714 program_interpreter
[0] = 0;
3715 if (fscanf (file
, fmt
, program_interpreter
) <= 0)
3716 error (_("Unable to read program interpreter name\n"));
3719 printf (_("\n [Requesting program interpreter: %s]"),
3720 program_interpreter
);
3726 putc ('\n', stdout
);
3729 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3731 printf (_("\n Section to Segment mapping:\n"));
3732 printf (_(" Segment Sections...\n"));
3734 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3737 Elf_Internal_Shdr
* section
;
3739 segment
= program_headers
+ i
;
3740 section
= section_headers
+ 1;
3742 printf (" %2.2d ", i
);
3744 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3746 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY (section
, segment
))
3747 printf ("%s ", SECTION_NAME (section
));
3758 /* Find the file offset corresponding to VMA by using the program headers. */
3761 offset_from_vma (FILE * file
, bfd_vma vma
, bfd_size_type size
)
3763 Elf_Internal_Phdr
* seg
;
3765 if (! get_program_headers (file
))
3767 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3771 for (seg
= program_headers
;
3772 seg
< program_headers
+ elf_header
.e_phnum
;
3775 if (seg
->p_type
!= PT_LOAD
)
3778 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3779 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3780 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3783 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3784 (unsigned long) vma
);
3790 get_32bit_section_headers (FILE * file
, unsigned int num
)
3792 Elf32_External_Shdr
* shdrs
;
3793 Elf_Internal_Shdr
* internal
;
3796 shdrs
= (Elf32_External_Shdr
*) get_data (NULL
, file
, elf_header
.e_shoff
,
3797 elf_header
.e_shentsize
, num
,
3798 _("section headers"));
3802 section_headers
= (Elf_Internal_Shdr
*) cmalloc (num
,
3803 sizeof (Elf_Internal_Shdr
));
3805 if (section_headers
== NULL
)
3807 error (_("Out of memory\n"));
3811 for (i
= 0, internal
= section_headers
;
3815 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3816 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3817 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3818 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3819 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3820 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3821 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3822 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3823 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3824 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3833 get_64bit_section_headers (FILE * file
, unsigned int num
)
3835 Elf64_External_Shdr
* shdrs
;
3836 Elf_Internal_Shdr
* internal
;
3839 shdrs
= (Elf64_External_Shdr
*) get_data (NULL
, file
, elf_header
.e_shoff
,
3840 elf_header
.e_shentsize
, num
,
3841 _("section headers"));
3845 section_headers
= (Elf_Internal_Shdr
*) cmalloc (num
,
3846 sizeof (Elf_Internal_Shdr
));
3848 if (section_headers
== NULL
)
3850 error (_("Out of memory\n"));
3854 for (i
= 0, internal
= section_headers
;
3858 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3859 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3860 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3861 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3862 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3863 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3864 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3865 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3866 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3867 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3875 static Elf_Internal_Sym
*
3876 get_32bit_elf_symbols (FILE * file
, Elf_Internal_Shdr
* section
)
3878 unsigned long number
;
3879 Elf32_External_Sym
* esyms
;
3880 Elf_External_Sym_Shndx
* shndx
;
3881 Elf_Internal_Sym
* isyms
;
3882 Elf_Internal_Sym
* psym
;
3885 esyms
= (Elf32_External_Sym
*) get_data (NULL
, file
, section
->sh_offset
, 1,
3886 section
->sh_size
, _("symbols"));
3891 if (symtab_shndx_hdr
!= NULL
3892 && (symtab_shndx_hdr
->sh_link
3893 == (unsigned long) (section
- section_headers
)))
3895 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, file
,
3896 symtab_shndx_hdr
->sh_offset
,
3897 1, symtab_shndx_hdr
->sh_size
,
3906 number
= section
->sh_size
/ section
->sh_entsize
;
3907 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
3911 error (_("Out of memory\n"));
3918 for (j
= 0, psym
= isyms
;
3922 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3923 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3924 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3925 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3926 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
3928 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3929 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
3930 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
3931 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3932 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3942 static Elf_Internal_Sym
*
3943 get_64bit_elf_symbols (FILE * file
, Elf_Internal_Shdr
* section
)
3945 unsigned long number
;
3946 Elf64_External_Sym
* esyms
;
3947 Elf_External_Sym_Shndx
* shndx
;
3948 Elf_Internal_Sym
* isyms
;
3949 Elf_Internal_Sym
* psym
;
3952 esyms
= (Elf64_External_Sym
*) get_data (NULL
, file
, section
->sh_offset
, 1,
3953 section
->sh_size
, _("symbols"));
3958 if (symtab_shndx_hdr
!= NULL
3959 && (symtab_shndx_hdr
->sh_link
3960 == (unsigned long) (section
- section_headers
)))
3962 shndx
= (Elf_External_Sym_Shndx
*) get_data (NULL
, file
,
3963 symtab_shndx_hdr
->sh_offset
,
3964 1, symtab_shndx_hdr
->sh_size
,
3973 number
= section
->sh_size
/ section
->sh_entsize
;
3974 isyms
= (Elf_Internal_Sym
*) cmalloc (number
, sizeof (Elf_Internal_Sym
));
3978 error (_("Out of memory\n"));
3985 for (j
= 0, psym
= isyms
;
3989 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3990 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3991 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3992 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3993 if (psym
->st_shndx
== (SHN_XINDEX
& 0xffff) && shndx
!= NULL
)
3995 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3996 else if (psym
->st_shndx
>= (SHN_LORESERVE
& 0xffff))
3997 psym
->st_shndx
+= SHN_LORESERVE
- (SHN_LORESERVE
& 0xffff);
3998 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3999 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
4010 get_elf_section_flags (bfd_vma sh_flags
)
4012 static char buff
[1024];
4014 int field_size
= is_32bit_elf
? 8 : 16;
4016 int size
= sizeof (buff
) - (field_size
+ 4 + 1);
4017 bfd_vma os_flags
= 0;
4018 bfd_vma proc_flags
= 0;
4019 bfd_vma unknown_flags
= 0;
4027 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
4028 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
4029 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
4030 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
4031 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
4032 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
4033 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
4034 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
4035 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
4036 /* 9 */ { STRING_COMMA_LEN ("TLS") },
4037 /* IA-64 specific. */
4038 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
4039 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
4040 /* IA-64 OpenVMS specific. */
4041 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
4042 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
4043 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
4044 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
4045 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
4046 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
4047 /* SPARC specific. */
4048 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
4049 /* 19 */ { STRING_COMMA_LEN ("ORDERED") }
4052 if (do_section_details
)
4054 sprintf (buff
, "[%*.*lx]: ",
4055 field_size
, field_size
, (unsigned long) sh_flags
);
4056 p
+= field_size
+ 4;
4063 flag
= sh_flags
& - sh_flags
;
4066 if (do_section_details
)
4070 case SHF_WRITE
: sindex
= 0; break;
4071 case SHF_ALLOC
: sindex
= 1; break;
4072 case SHF_EXECINSTR
: sindex
= 2; break;
4073 case SHF_MERGE
: sindex
= 3; break;
4074 case SHF_STRINGS
: sindex
= 4; break;
4075 case SHF_INFO_LINK
: sindex
= 5; break;
4076 case SHF_LINK_ORDER
: sindex
= 6; break;
4077 case SHF_OS_NONCONFORMING
: sindex
= 7; break;
4078 case SHF_GROUP
: sindex
= 8; break;
4079 case SHF_TLS
: sindex
= 9; break;
4083 switch (elf_header
.e_machine
)
4086 if (flag
== SHF_IA_64_SHORT
)
4088 else if (flag
== SHF_IA_64_NORECOV
)
4091 else if (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_OPENVMS
)
4094 case SHF_IA_64_VMS_GLOBAL
: sindex
= 12; break;
4095 case SHF_IA_64_VMS_OVERLAID
: sindex
= 13; break;
4096 case SHF_IA_64_VMS_SHARED
: sindex
= 14; break;
4097 case SHF_IA_64_VMS_VECTOR
: sindex
= 15; break;
4098 case SHF_IA_64_VMS_ALLOC_64BIT
: sindex
= 16; break;
4099 case SHF_IA_64_VMS_PROTECTED
: sindex
= 17; break;
4108 case EM_OLD_SPARCV9
:
4109 case EM_SPARC32PLUS
:
4112 if (flag
== SHF_EXCLUDE
)
4114 else if (flag
== SHF_ORDERED
)
4124 if (p
!= buff
+ field_size
+ 4)
4126 if (size
< (10 + 2))
4133 size
-= flags
[sindex
].len
;
4134 p
= stpcpy (p
, flags
[sindex
].str
);
4136 else if (flag
& SHF_MASKOS
)
4138 else if (flag
& SHF_MASKPROC
)
4141 unknown_flags
|= flag
;
4147 case SHF_WRITE
: *p
= 'W'; break;
4148 case SHF_ALLOC
: *p
= 'A'; break;
4149 case SHF_EXECINSTR
: *p
= 'X'; break;
4150 case SHF_MERGE
: *p
= 'M'; break;
4151 case SHF_STRINGS
: *p
= 'S'; break;
4152 case SHF_INFO_LINK
: *p
= 'I'; break;
4153 case SHF_LINK_ORDER
: *p
= 'L'; break;
4154 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
4155 case SHF_GROUP
: *p
= 'G'; break;
4156 case SHF_TLS
: *p
= 'T'; break;
4159 if ((elf_header
.e_machine
== EM_X86_64
4160 || elf_header
.e_machine
== EM_L1OM
)
4161 && flag
== SHF_X86_64_LARGE
)
4163 else if (flag
& SHF_MASKOS
)
4166 sh_flags
&= ~ SHF_MASKOS
;
4168 else if (flag
& SHF_MASKPROC
)
4171 sh_flags
&= ~ SHF_MASKPROC
;
4181 if (do_section_details
)
4185 size
-= 5 + field_size
;
4186 if (p
!= buff
+ field_size
+ 4)
4194 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
4195 (unsigned long) os_flags
);
4196 p
+= 5 + field_size
;
4200 size
-= 7 + field_size
;
4201 if (p
!= buff
+ field_size
+ 4)
4209 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
4210 (unsigned long) proc_flags
);
4211 p
+= 7 + field_size
;
4215 size
-= 10 + field_size
;
4216 if (p
!= buff
+ field_size
+ 4)
4224 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
4225 (unsigned long) unknown_flags
);
4226 p
+= 10 + field_size
;
4235 process_section_headers (FILE * file
)
4237 Elf_Internal_Shdr
* section
;
4240 section_headers
= NULL
;
4242 if (elf_header
.e_shnum
== 0)
4245 printf (_("\nThere are no sections in this file.\n"));
4250 if (do_sections
&& !do_header
)
4251 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
4252 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
4256 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
4259 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
4262 /* Read in the string table, so that we have names to display. */
4263 if (elf_header
.e_shstrndx
!= SHN_UNDEF
4264 && elf_header
.e_shstrndx
< elf_header
.e_shnum
)
4266 section
= section_headers
+ elf_header
.e_shstrndx
;
4268 if (section
->sh_size
!= 0)
4270 string_table
= (char *) get_data (NULL
, file
, section
->sh_offset
,
4271 1, section
->sh_size
,
4274 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
4278 /* Scan the sections for the dynamic symbol table
4279 and dynamic string table and debug sections. */
4280 dynamic_symbols
= NULL
;
4281 dynamic_strings
= NULL
;
4282 dynamic_syminfo
= NULL
;
4283 symtab_shndx_hdr
= NULL
;
4285 eh_addr_size
= is_32bit_elf
? 4 : 8;
4286 switch (elf_header
.e_machine
)
4289 case EM_MIPS_RS3_LE
:
4290 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
4291 FDE addresses. However, the ABI also has a semi-official ILP32
4292 variant for which the normal FDE address size rules apply.
4294 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
4295 section, where XX is the size of longs in bits. Unfortunately,
4296 earlier compilers provided no way of distinguishing ILP32 objects
4297 from LP64 objects, so if there's any doubt, we should assume that
4298 the official LP64 form is being used. */
4299 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
4300 && find_section (".gcc_compiled_long32") == NULL
)
4306 switch (elf_header
.e_flags
& EF_H8_MACH
)
4308 case E_H8_MACH_H8300
:
4309 case E_H8_MACH_H8300HN
:
4310 case E_H8_MACH_H8300SN
:
4311 case E_H8_MACH_H8300SXN
:
4314 case E_H8_MACH_H8300H
:
4315 case E_H8_MACH_H8300S
:
4316 case E_H8_MACH_H8300SX
:
4324 switch (elf_header
.e_flags
& EF_M32C_CPU_MASK
)
4326 case EF_M32C_CPU_M16C
:
4333 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4336 size_t expected_entsize \
4337 = is_32bit_elf ? size32 : size64; \
4338 if (section->sh_entsize != expected_entsize) \
4339 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4340 i, (unsigned long int) section->sh_entsize, \
4341 (unsigned long int) expected_entsize); \
4342 section->sh_entsize = expected_entsize; \
4345 #define CHECK_ENTSIZE(section, i, type) \
4346 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4347 sizeof (Elf64_External_##type))
4349 for (i
= 0, section
= section_headers
;
4350 i
< elf_header
.e_shnum
;
4353 char * name
= SECTION_NAME (section
);
4355 if (section
->sh_type
== SHT_DYNSYM
)
4357 if (dynamic_symbols
!= NULL
)
4359 error (_("File contains multiple dynamic symbol tables\n"));
4363 CHECK_ENTSIZE (section
, i
, Sym
);
4364 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
4365 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
4367 else if (section
->sh_type
== SHT_STRTAB
4368 && streq (name
, ".dynstr"))
4370 if (dynamic_strings
!= NULL
)
4372 error (_("File contains multiple dynamic string tables\n"));
4376 dynamic_strings
= (char *) get_data (NULL
, file
, section
->sh_offset
,
4377 1, section
->sh_size
,
4378 _("dynamic strings"));
4379 dynamic_strings_length
= section
->sh_size
;
4381 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
4383 if (symtab_shndx_hdr
!= NULL
)
4385 error (_("File contains multiple symtab shndx tables\n"));
4388 symtab_shndx_hdr
= section
;
4390 else if (section
->sh_type
== SHT_SYMTAB
)
4391 CHECK_ENTSIZE (section
, i
, Sym
);
4392 else if (section
->sh_type
== SHT_GROUP
)
4393 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
4394 else if (section
->sh_type
== SHT_REL
)
4395 CHECK_ENTSIZE (section
, i
, Rel
);
4396 else if (section
->sh_type
== SHT_RELA
)
4397 CHECK_ENTSIZE (section
, i
, Rela
);
4398 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
4399 || do_debug_lines
|| do_debug_pubnames
|| do_debug_pubtypes
4400 || do_debug_aranges
|| do_debug_frames
|| do_debug_macinfo
4401 || do_debug_str
|| do_debug_loc
|| do_debug_ranges
)
4402 && (const_strneq (name
, ".debug_")
4403 || const_strneq (name
, ".zdebug_")))
4406 name
+= sizeof (".zdebug_") - 1;
4408 name
+= sizeof (".debug_") - 1;
4411 || (do_debug_info
&& streq (name
, "info"))
4412 || (do_debug_info
&& streq (name
, "types"))
4413 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
4414 || (do_debug_lines
&& streq (name
, "line"))
4415 || (do_debug_pubnames
&& streq (name
, "pubnames"))
4416 || (do_debug_pubtypes
&& streq (name
, "pubtypes"))
4417 || (do_debug_aranges
&& streq (name
, "aranges"))
4418 || (do_debug_ranges
&& streq (name
, "ranges"))
4419 || (do_debug_frames
&& streq (name
, "frame"))
4420 || (do_debug_macinfo
&& streq (name
, "macinfo"))
4421 || (do_debug_str
&& streq (name
, "str"))
4422 || (do_debug_loc
&& streq (name
, "loc"))
4424 request_dump_bynumber (i
, DEBUG_DUMP
);
4426 /* Linkonce section to be combined with .debug_info at link time. */
4427 else if ((do_debugging
|| do_debug_info
)
4428 && const_strneq (name
, ".gnu.linkonce.wi."))
4429 request_dump_bynumber (i
, DEBUG_DUMP
);
4430 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
4431 request_dump_bynumber (i
, DEBUG_DUMP
);
4437 if (elf_header
.e_shnum
> 1)
4438 printf (_("\nSection Headers:\n"));
4440 printf (_("\nSection Header:\n"));
4444 if (do_section_details
)
4446 printf (_(" [Nr] Name\n"));
4447 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4451 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4455 if (do_section_details
)
4457 printf (_(" [Nr] Name\n"));
4458 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4462 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4466 if (do_section_details
)
4468 printf (_(" [Nr] Name\n"));
4469 printf (_(" Type Address Offset Link\n"));
4470 printf (_(" Size EntSize Info Align\n"));
4474 printf (_(" [Nr] Name Type Address Offset\n"));
4475 printf (_(" Size EntSize Flags Link Info Align\n"));
4479 if (do_section_details
)
4480 printf (_(" Flags\n"));
4482 for (i
= 0, section
= section_headers
;
4483 i
< elf_header
.e_shnum
;
4486 if (do_section_details
)
4488 printf (" [%2u] %s\n",
4490 SECTION_NAME (section
));
4491 if (is_32bit_elf
|| do_wide
)
4492 printf (" %-15.15s ",
4493 get_section_type_name (section
->sh_type
));
4496 printf ((do_wide
? " [%2u] %-17s %-15s "
4497 : " [%2u] %-17.17s %-15.15s "),
4499 SECTION_NAME (section
),
4500 get_section_type_name (section
->sh_type
));
4504 const char * link_too_big
= NULL
;
4506 print_vma (section
->sh_addr
, LONG_HEX
);
4508 printf ( " %6.6lx %6.6lx %2.2lx",
4509 (unsigned long) section
->sh_offset
,
4510 (unsigned long) section
->sh_size
,
4511 (unsigned long) section
->sh_entsize
);
4513 if (do_section_details
)
4514 fputs (" ", stdout
);
4516 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4518 if (section
->sh_link
>= elf_header
.e_shnum
)
4521 /* The sh_link value is out of range. Normally this indicates
4522 an error but it can have special values in Solaris binaries. */
4523 switch (elf_header
.e_machine
)
4528 case EM_OLD_SPARCV9
:
4529 case EM_SPARC32PLUS
:
4532 if (section
->sh_link
== (SHN_BEFORE
& 0xffff))
4533 link_too_big
= "BEFORE";
4534 else if (section
->sh_link
== (SHN_AFTER
& 0xffff))
4535 link_too_big
= "AFTER";
4542 if (do_section_details
)
4544 if (link_too_big
!= NULL
&& * link_too_big
)
4545 printf ("<%s> ", link_too_big
);
4547 printf ("%2u ", section
->sh_link
);
4548 printf ("%3u %2lu\n", section
->sh_info
,
4549 (unsigned long) section
->sh_addralign
);
4552 printf ("%2u %3u %2lu\n",
4555 (unsigned long) section
->sh_addralign
);
4557 if (link_too_big
&& ! * link_too_big
)
4558 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
4559 i
, section
->sh_link
);
4563 print_vma (section
->sh_addr
, LONG_HEX
);
4565 if ((long) section
->sh_offset
== section
->sh_offset
)
4566 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4570 print_vma (section
->sh_offset
, LONG_HEX
);
4573 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4574 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4578 print_vma (section
->sh_size
, LONG_HEX
);
4581 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4582 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4586 print_vma (section
->sh_entsize
, LONG_HEX
);
4589 if (do_section_details
)
4590 fputs (" ", stdout
);
4592 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4594 printf ("%2u %3u ", section
->sh_link
, section
->sh_info
);
4596 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4597 printf ("%2lu\n", (unsigned long) section
->sh_addralign
);
4600 print_vma (section
->sh_addralign
, DEC
);
4604 else if (do_section_details
)
4606 printf (" %-15.15s ",
4607 get_section_type_name (section
->sh_type
));
4608 print_vma (section
->sh_addr
, LONG_HEX
);
4609 if ((long) section
->sh_offset
== section
->sh_offset
)
4610 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4614 print_vma (section
->sh_offset
, LONG_HEX
);
4616 printf (" %u\n ", section
->sh_link
);
4617 print_vma (section
->sh_size
, LONG_HEX
);
4619 print_vma (section
->sh_entsize
, LONG_HEX
);
4621 printf (" %-16u %lu\n",
4623 (unsigned long) section
->sh_addralign
);
4628 print_vma (section
->sh_addr
, LONG_HEX
);
4629 if ((long) section
->sh_offset
== section
->sh_offset
)
4630 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4634 print_vma (section
->sh_offset
, LONG_HEX
);
4637 print_vma (section
->sh_size
, LONG_HEX
);
4639 print_vma (section
->sh_entsize
, LONG_HEX
);
4641 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4643 printf (" %2u %3u %lu\n",
4646 (unsigned long) section
->sh_addralign
);
4649 if (do_section_details
)
4650 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4653 if (!do_section_details
)
4654 printf (_("Key to Flags:\n\
4655 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4656 I (info), L (link order), G (group), x (unknown)\n\
4657 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4663 get_group_flags (unsigned int flags
)
4665 static char buff
[32];
4675 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x] "), flags
);
4682 process_section_groups (FILE * file
)
4684 Elf_Internal_Shdr
* section
;
4686 struct group
* group
;
4687 Elf_Internal_Shdr
* symtab_sec
;
4688 Elf_Internal_Shdr
* strtab_sec
;
4689 Elf_Internal_Sym
* symtab
;
4693 /* Don't process section groups unless needed. */
4694 if (!do_unwind
&& !do_section_groups
)
4697 if (elf_header
.e_shnum
== 0)
4699 if (do_section_groups
)
4700 printf (_("\nThere are no sections in this file.\n"));
4705 if (section_headers
== NULL
)
4707 error (_("Section headers are not available!\n"));
4711 section_headers_groups
= (struct group
**) calloc (elf_header
.e_shnum
,
4712 sizeof (struct group
*));
4714 if (section_headers_groups
== NULL
)
4716 error (_("Out of memory\n"));
4720 /* Scan the sections for the group section. */
4722 for (i
= 0, section
= section_headers
;
4723 i
< elf_header
.e_shnum
;
4725 if (section
->sh_type
== SHT_GROUP
)
4728 if (group_count
== 0)
4730 if (do_section_groups
)
4731 printf (_("\nThere are no section groups in this file.\n"));
4736 section_groups
= (struct group
*) calloc (group_count
, sizeof (struct group
));
4738 if (section_groups
== NULL
)
4740 error (_("Out of memory\n"));
4749 for (i
= 0, section
= section_headers
, group
= section_groups
;
4750 i
< elf_header
.e_shnum
;
4753 if (section
->sh_type
== SHT_GROUP
)
4755 char * name
= SECTION_NAME (section
);
4757 unsigned char * start
;
4758 unsigned char * indices
;
4759 unsigned int entry
, j
, size
;
4760 Elf_Internal_Shdr
* sec
;
4761 Elf_Internal_Sym
* sym
;
4763 /* Get the symbol table. */
4764 if (section
->sh_link
>= elf_header
.e_shnum
4765 || ((sec
= section_headers
+ section
->sh_link
)->sh_type
4768 error (_("Bad sh_link in group section `%s'\n"), name
);
4772 if (symtab_sec
!= sec
)
4777 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4780 sym
= symtab
+ section
->sh_info
;
4782 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4784 if (sym
->st_shndx
== 0
4785 || sym
->st_shndx
>= elf_header
.e_shnum
)
4787 error (_("Bad sh_info in group section `%s'\n"), name
);
4791 group_name
= SECTION_NAME (section_headers
+ sym
->st_shndx
);
4800 /* Get the string table. */
4801 if (symtab_sec
->sh_link
>= elf_header
.e_shnum
)
4810 != (sec
= section_headers
+ symtab_sec
->sh_link
))
4815 strtab
= (char *) get_data (NULL
, file
, strtab_sec
->sh_offset
,
4816 1, strtab_sec
->sh_size
,
4818 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4820 group_name
= sym
->st_name
< strtab_size
4821 ? strtab
+ sym
->st_name
: "<corrupt>";
4824 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
,
4825 1, section
->sh_size
,
4829 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4830 entry
= byte_get (indices
, 4);
4833 if (do_section_groups
)
4835 printf ("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n",
4836 get_group_flags (entry
), i
, name
, group_name
, size
);
4838 printf (_(" [Index] Name\n"));
4841 group
->group_index
= i
;
4843 for (j
= 0; j
< size
; j
++)
4845 struct group_list
* g
;
4847 entry
= byte_get (indices
, 4);
4850 if (entry
>= elf_header
.e_shnum
)
4852 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4853 entry
, i
, elf_header
.e_shnum
- 1);
4857 if (section_headers_groups
[entry
] != NULL
)
4861 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4863 section_headers_groups
[entry
]->group_index
);
4868 /* Intel C/C++ compiler may put section 0 in a
4869 section group. We just warn it the first time
4870 and ignore it afterwards. */
4871 static int warned
= 0;
4874 error (_("section 0 in group section [%5u]\n"),
4875 section_headers_groups
[entry
]->group_index
);
4881 section_headers_groups
[entry
] = group
;
4883 if (do_section_groups
)
4885 sec
= section_headers
+ entry
;
4886 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4889 g
= (struct group_list
*) xmalloc (sizeof (struct group_list
));
4890 g
->section_index
= entry
;
4891 g
->next
= group
->root
;
4915 } dynamic_relocations
[] =
4917 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4918 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4919 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4922 /* Process the reloc section. */
4925 process_relocs (FILE * file
)
4927 unsigned long rel_size
;
4928 unsigned long rel_offset
;
4934 if (do_using_dynamic
)
4938 int has_dynamic_reloc
;
4941 has_dynamic_reloc
= 0;
4943 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4945 is_rela
= dynamic_relocations
[i
].rela
;
4946 name
= dynamic_relocations
[i
].name
;
4947 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4948 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4950 has_dynamic_reloc
|= rel_size
;
4952 if (is_rela
== UNKNOWN
)
4954 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4955 switch (dynamic_info
[DT_PLTREL
])
4969 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4970 name
, rel_offset
, rel_size
);
4972 dump_relocations (file
,
4973 offset_from_vma (file
, rel_offset
, rel_size
),
4975 dynamic_symbols
, num_dynamic_syms
,
4976 dynamic_strings
, dynamic_strings_length
, is_rela
);
4980 if (! has_dynamic_reloc
)
4981 printf (_("\nThere are no dynamic relocations in this file.\n"));
4985 Elf_Internal_Shdr
* section
;
4989 for (i
= 0, section
= section_headers
;
4990 i
< elf_header
.e_shnum
;
4993 if ( section
->sh_type
!= SHT_RELA
4994 && section
->sh_type
!= SHT_REL
)
4997 rel_offset
= section
->sh_offset
;
4998 rel_size
= section
->sh_size
;
5002 Elf_Internal_Shdr
* strsec
;
5005 printf (_("\nRelocation section "));
5007 if (string_table
== NULL
)
5008 printf ("%d", section
->sh_name
);
5010 printf (_("'%s'"), SECTION_NAME (section
));
5012 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5013 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
5015 is_rela
= section
->sh_type
== SHT_RELA
;
5017 if (section
->sh_link
!= 0
5018 && section
->sh_link
< elf_header
.e_shnum
)
5020 Elf_Internal_Shdr
* symsec
;
5021 Elf_Internal_Sym
* symtab
;
5022 unsigned long nsyms
;
5023 unsigned long strtablen
= 0;
5024 char * strtab
= NULL
;
5026 symsec
= section_headers
+ section
->sh_link
;
5027 if (symsec
->sh_type
!= SHT_SYMTAB
5028 && symsec
->sh_type
!= SHT_DYNSYM
)
5031 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
5032 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
5037 if (symsec
->sh_link
!= 0
5038 && symsec
->sh_link
< elf_header
.e_shnum
)
5040 strsec
= section_headers
+ symsec
->sh_link
;
5042 strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
5045 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
5048 dump_relocations (file
, rel_offset
, rel_size
,
5049 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
5055 dump_relocations (file
, rel_offset
, rel_size
,
5056 NULL
, 0, NULL
, 0, is_rela
);
5063 printf (_("\nThere are no relocations in this file.\n"));
5069 /* Process the unwind section. */
5071 #include "unwind-ia64.h"
5073 /* An absolute address consists of a section and an offset. If the
5074 section is NULL, the offset itself is the address, otherwise, the
5075 address equals to LOAD_ADDRESS(section) + offset. */
5079 unsigned short section
;
5083 #define ABSADDR(a) \
5085 ? section_headers [(a).section].sh_addr + (a).offset \
5088 struct ia64_unw_table_entry
5090 struct absaddr start
;
5092 struct absaddr info
;
5095 struct ia64_unw_aux_info
5098 struct ia64_unw_table_entry
*table
; /* Unwind table. */
5099 unsigned long table_len
; /* Length of unwind table. */
5100 unsigned char * info
; /* Unwind info. */
5101 unsigned long info_size
; /* Size of unwind info. */
5102 bfd_vma info_addr
; /* starting address of unwind info. */
5103 bfd_vma seg_base
; /* Starting address of segment. */
5104 Elf_Internal_Sym
* symtab
; /* The symbol table. */
5105 unsigned long nsyms
; /* Number of symbols. */
5106 char * strtab
; /* The string table. */
5107 unsigned long strtab_size
; /* Size of string table. */
5111 find_symbol_for_address (Elf_Internal_Sym
* symtab
,
5112 unsigned long nsyms
,
5113 const char * strtab
,
5114 unsigned long strtab_size
,
5115 struct absaddr addr
,
5116 const char ** symname
,
5119 bfd_vma dist
= 0x100000;
5120 Elf_Internal_Sym
* sym
;
5121 Elf_Internal_Sym
* best
= NULL
;
5124 REMOVE_ARCH_BITS (addr
.offset
);
5126 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
5128 bfd_vma value
= sym
->st_value
;
5130 REMOVE_ARCH_BITS (value
);
5132 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
5133 && sym
->st_name
!= 0
5134 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
5135 && addr
.offset
>= value
5136 && addr
.offset
- value
< dist
)
5139 dist
= addr
.offset
- value
;
5146 *symname
= (best
->st_name
>= strtab_size
5147 ? "<corrupt>" : strtab
+ best
->st_name
);
5152 *offset
= addr
.offset
;
5156 dump_ia64_unwind (struct ia64_unw_aux_info
* aux
)
5158 struct ia64_unw_table_entry
* tp
;
5161 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5165 const unsigned char * dp
;
5166 const unsigned char * head
;
5167 const char * procname
;
5169 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5170 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
5172 fputs ("\n<", stdout
);
5176 fputs (procname
, stdout
);
5179 printf ("+%lx", (unsigned long) offset
);
5182 fputs (">: [", stdout
);
5183 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5184 fputc ('-', stdout
);
5185 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5186 printf ("], info at +0x%lx\n",
5187 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
5189 head
= aux
->info
+ (ABSADDR (tp
->info
) - aux
->info_addr
);
5190 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
5192 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
5193 (unsigned) UNW_VER (stamp
),
5194 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
5195 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
5196 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
5197 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
5199 if (UNW_VER (stamp
) != 1)
5201 printf ("\tUnknown version.\n");
5206 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
5207 dp
= unw_decode (dp
, in_body
, & in_body
);
5212 slurp_ia64_unwind_table (FILE * file
,
5213 struct ia64_unw_aux_info
* aux
,
5214 Elf_Internal_Shdr
* sec
)
5216 unsigned long size
, nrelas
, i
;
5217 Elf_Internal_Phdr
* seg
;
5218 struct ia64_unw_table_entry
* tep
;
5219 Elf_Internal_Shdr
* relsec
;
5220 Elf_Internal_Rela
* rela
;
5221 Elf_Internal_Rela
* rp
;
5222 unsigned char * table
;
5224 Elf_Internal_Sym
* sym
;
5225 const char * relname
;
5227 /* First, find the starting address of the segment that includes
5230 if (elf_header
.e_phnum
)
5232 if (! get_program_headers (file
))
5235 for (seg
= program_headers
;
5236 seg
< program_headers
+ elf_header
.e_phnum
;
5239 if (seg
->p_type
!= PT_LOAD
)
5242 if (sec
->sh_addr
>= seg
->p_vaddr
5243 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5245 aux
->seg_base
= seg
->p_vaddr
;
5251 /* Second, build the unwind table from the contents of the unwind section: */
5252 size
= sec
->sh_size
;
5253 table
= (unsigned char *) get_data (NULL
, file
, sec
->sh_offset
, 1, size
,
5258 aux
->table
= (struct ia64_unw_table_entry
*)
5259 xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
5261 for (tp
= table
; tp
< table
+ size
; ++tep
)
5263 tep
->start
.section
= SHN_UNDEF
;
5264 tep
->end
.section
= SHN_UNDEF
;
5265 tep
->info
.section
= SHN_UNDEF
;
5266 tep
->start
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5267 tep
->end
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5268 tep
->info
.offset
= byte_get (tp
, eh_addr_size
); tp
+= eh_addr_size
;
5269 tep
->start
.offset
+= aux
->seg_base
;
5270 tep
->end
.offset
+= aux
->seg_base
;
5271 tep
->info
.offset
+= aux
->seg_base
;
5275 /* Third, apply any relocations to the unwind table: */
5276 for (relsec
= section_headers
;
5277 relsec
< section_headers
+ elf_header
.e_shnum
;
5280 if (relsec
->sh_type
!= SHT_RELA
5281 || relsec
->sh_info
>= elf_header
.e_shnum
5282 || section_headers
+ relsec
->sh_info
!= sec
)
5285 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5289 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5291 relname
= elf_ia64_reloc_type (get_reloc_type (rp
->r_info
));
5292 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5294 if (! const_strneq (relname
, "R_IA64_SEGREL"))
5296 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5300 i
= rp
->r_offset
/ (3 * eh_addr_size
);
5302 switch (rp
->r_offset
/eh_addr_size
% 3)
5305 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5306 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
5309 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5310 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
5313 aux
->table
[i
].info
.section
= sym
->st_shndx
;
5314 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
5324 aux
->table_len
= size
/ (3 * eh_addr_size
);
5329 ia64_process_unwind (FILE * file
)
5331 Elf_Internal_Shdr
* sec
;
5332 Elf_Internal_Shdr
* unwsec
= NULL
;
5333 Elf_Internal_Shdr
* strsec
;
5334 unsigned long i
, unwcount
= 0, unwstart
= 0;
5335 struct ia64_unw_aux_info aux
;
5337 memset (& aux
, 0, sizeof (aux
));
5339 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5341 if (sec
->sh_type
== SHT_SYMTAB
5342 && sec
->sh_link
< elf_header
.e_shnum
)
5344 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5345 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5347 strsec
= section_headers
+ sec
->sh_link
;
5348 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
5351 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5353 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5358 printf (_("\nThere are no unwind sections in this file.\n"));
5360 while (unwcount
-- > 0)
5365 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
5366 i
< elf_header
.e_shnum
; ++i
, ++sec
)
5367 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
5374 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
5376 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
5378 /* We need to find which section group it is in. */
5379 struct group_list
* g
= section_headers_groups
[i
]->root
;
5381 for (; g
!= NULL
; g
= g
->next
)
5383 sec
= section_headers
+ g
->section_index
;
5385 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
5390 i
= elf_header
.e_shnum
;
5392 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
5394 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5395 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
5396 suffix
= SECTION_NAME (unwsec
) + len
;
5397 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5399 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
5400 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5405 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5406 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5407 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
5408 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
5410 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
5411 suffix
= SECTION_NAME (unwsec
) + len
;
5412 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
5414 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
5415 && streq (SECTION_NAME (sec
) + len2
, suffix
))
5419 if (i
== elf_header
.e_shnum
)
5421 printf (_("\nCould not find unwind info section for "));
5423 if (string_table
== NULL
)
5424 printf ("%d", unwsec
->sh_name
);
5426 printf (_("'%s'"), SECTION_NAME (unwsec
));
5430 aux
.info_size
= sec
->sh_size
;
5431 aux
.info_addr
= sec
->sh_addr
;
5432 aux
.info
= (unsigned char *) get_data (NULL
, file
, sec
->sh_offset
, 1,
5436 printf (_("\nUnwind section "));
5438 if (string_table
== NULL
)
5439 printf ("%d", unwsec
->sh_name
);
5441 printf (_("'%s'"), SECTION_NAME (unwsec
));
5443 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5444 (unsigned long) unwsec
->sh_offset
,
5445 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
5447 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
5449 if (aux
.table_len
> 0)
5450 dump_ia64_unwind (& aux
);
5453 free ((char *) aux
.table
);
5455 free ((char *) aux
.info
);
5464 free ((char *) aux
.strtab
);
5469 struct hppa_unw_table_entry
5471 struct absaddr start
;
5473 unsigned int Cannot_unwind
:1; /* 0 */
5474 unsigned int Millicode
:1; /* 1 */
5475 unsigned int Millicode_save_sr0
:1; /* 2 */
5476 unsigned int Region_description
:2; /* 3..4 */
5477 unsigned int reserved1
:1; /* 5 */
5478 unsigned int Entry_SR
:1; /* 6 */
5479 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
5480 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
5481 unsigned int Args_stored
:1; /* 16 */
5482 unsigned int Variable_Frame
:1; /* 17 */
5483 unsigned int Separate_Package_Body
:1; /* 18 */
5484 unsigned int Frame_Extension_Millicode
:1; /* 19 */
5485 unsigned int Stack_Overflow_Check
:1; /* 20 */
5486 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
5487 unsigned int Ada_Region
:1; /* 22 */
5488 unsigned int cxx_info
:1; /* 23 */
5489 unsigned int cxx_try_catch
:1; /* 24 */
5490 unsigned int sched_entry_seq
:1; /* 25 */
5491 unsigned int reserved2
:1; /* 26 */
5492 unsigned int Save_SP
:1; /* 27 */
5493 unsigned int Save_RP
:1; /* 28 */
5494 unsigned int Save_MRP_in_frame
:1; /* 29 */
5495 unsigned int extn_ptr_defined
:1; /* 30 */
5496 unsigned int Cleanup_defined
:1; /* 31 */
5498 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
5499 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
5500 unsigned int Large_frame
:1; /* 2 */
5501 unsigned int Pseudo_SP_Set
:1; /* 3 */
5502 unsigned int reserved4
:1; /* 4 */
5503 unsigned int Total_frame_size
:27; /* 5..31 */
5506 struct hppa_unw_aux_info
5508 struct hppa_unw_table_entry
*table
; /* Unwind table. */
5509 unsigned long table_len
; /* Length of unwind table. */
5510 bfd_vma seg_base
; /* Starting address of segment. */
5511 Elf_Internal_Sym
* symtab
; /* The symbol table. */
5512 unsigned long nsyms
; /* Number of symbols. */
5513 char * strtab
; /* The string table. */
5514 unsigned long strtab_size
; /* Size of string table. */
5518 dump_hppa_unwind (struct hppa_unw_aux_info
* aux
)
5520 struct hppa_unw_table_entry
* tp
;
5522 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5525 const char * procname
;
5527 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5528 aux
->strtab_size
, tp
->start
, &procname
,
5531 fputs ("\n<", stdout
);
5535 fputs (procname
, stdout
);
5538 printf ("+%lx", (unsigned long) offset
);
5541 fputs (">: [", stdout
);
5542 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5543 fputc ('-', stdout
);
5544 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5547 #define PF(_m) if (tp->_m) printf (#_m " ");
5548 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5551 PF(Millicode_save_sr0
);
5552 /* PV(Region_description); */
5558 PF(Separate_Package_Body
);
5559 PF(Frame_Extension_Millicode
);
5560 PF(Stack_Overflow_Check
);
5561 PF(Two_Instruction_SP_Increment
);
5565 PF(sched_entry_seq
);
5568 PF(Save_MRP_in_frame
);
5569 PF(extn_ptr_defined
);
5570 PF(Cleanup_defined
);
5571 PF(MPE_XL_interrupt_marker
);
5572 PF(HP_UX_interrupt_marker
);
5575 PV(Total_frame_size
);
5584 slurp_hppa_unwind_table (FILE * file
,
5585 struct hppa_unw_aux_info
* aux
,
5586 Elf_Internal_Shdr
* sec
)
5588 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5589 Elf_Internal_Phdr
* seg
;
5590 struct hppa_unw_table_entry
* tep
;
5591 Elf_Internal_Shdr
* relsec
;
5592 Elf_Internal_Rela
* rela
;
5593 Elf_Internal_Rela
* rp
;
5594 unsigned char * table
;
5596 Elf_Internal_Sym
* sym
;
5597 const char * relname
;
5599 /* First, find the starting address of the segment that includes
5602 if (elf_header
.e_phnum
)
5604 if (! get_program_headers (file
))
5607 for (seg
= program_headers
;
5608 seg
< program_headers
+ elf_header
.e_phnum
;
5611 if (seg
->p_type
!= PT_LOAD
)
5614 if (sec
->sh_addr
>= seg
->p_vaddr
5615 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5617 aux
->seg_base
= seg
->p_vaddr
;
5623 /* Second, build the unwind table from the contents of the unwind
5625 size
= sec
->sh_size
;
5626 table
= (unsigned char *) get_data (NULL
, file
, sec
->sh_offset
, 1, size
,
5632 nentries
= size
/ unw_ent_size
;
5633 size
= unw_ent_size
* nentries
;
5635 tep
= aux
->table
= (struct hppa_unw_table_entry
*)
5636 xcmalloc (nentries
, sizeof (aux
->table
[0]));
5638 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5640 unsigned int tmp1
, tmp2
;
5642 tep
->start
.section
= SHN_UNDEF
;
5643 tep
->end
.section
= SHN_UNDEF
;
5645 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5646 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5647 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5648 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5650 tep
->start
.offset
+= aux
->seg_base
;
5651 tep
->end
.offset
+= aux
->seg_base
;
5653 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5654 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5655 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5656 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5657 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5658 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5659 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5660 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5661 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5662 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5663 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5664 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5665 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5666 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5667 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5668 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5669 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5670 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5671 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5672 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5673 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5674 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5675 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5676 tep
->Cleanup_defined
= tmp1
& 0x1;
5678 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5679 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5680 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5681 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5682 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5683 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5687 /* Third, apply any relocations to the unwind table. */
5688 for (relsec
= section_headers
;
5689 relsec
< section_headers
+ elf_header
.e_shnum
;
5692 if (relsec
->sh_type
!= SHT_RELA
5693 || relsec
->sh_info
>= elf_header
.e_shnum
5694 || section_headers
+ relsec
->sh_info
!= sec
)
5697 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5701 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5703 relname
= elf_hppa_reloc_type (get_reloc_type (rp
->r_info
));
5704 sym
= aux
->symtab
+ get_reloc_symindex (rp
->r_info
);
5706 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5707 if (! const_strneq (relname
, "R_PARISC_SEGREL"))
5709 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5713 i
= rp
->r_offset
/ unw_ent_size
;
5715 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5718 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5719 aux
->table
[i
].start
.offset
= sym
->st_value
+ rp
->r_addend
;
5722 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5723 aux
->table
[i
].end
.offset
= sym
->st_value
+ rp
->r_addend
;
5733 aux
->table_len
= nentries
;
5739 hppa_process_unwind (FILE * file
)
5741 struct hppa_unw_aux_info aux
;
5742 Elf_Internal_Shdr
* unwsec
= NULL
;
5743 Elf_Internal_Shdr
* strsec
;
5744 Elf_Internal_Shdr
* sec
;
5747 memset (& aux
, 0, sizeof (aux
));
5749 if (string_table
== NULL
)
5752 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5754 if (sec
->sh_type
== SHT_SYMTAB
5755 && sec
->sh_link
< elf_header
.e_shnum
)
5757 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5758 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5760 strsec
= section_headers
+ sec
->sh_link
;
5761 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
5764 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5766 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5771 printf (_("\nThere are no unwind sections in this file.\n"));
5773 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5775 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5777 printf (_("\nUnwind section "));
5778 printf (_("'%s'"), SECTION_NAME (sec
));
5780 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5781 (unsigned long) sec
->sh_offset
,
5782 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5784 slurp_hppa_unwind_table (file
, &aux
, sec
);
5785 if (aux
.table_len
> 0)
5786 dump_hppa_unwind (&aux
);
5789 free ((char *) aux
.table
);
5797 free ((char *) aux
.strtab
);
5804 unsigned char *data
;
5806 Elf_Internal_Shdr
*sec
;
5807 Elf_Internal_Rela
*rela
;
5808 unsigned long nrelas
;
5809 unsigned int rel_type
;
5811 Elf_Internal_Rela
*next_rela
;
5814 struct arm_unw_aux_info
5818 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5819 unsigned long nsyms
; /* Number of symbols. */
5820 char *strtab
; /* The string table. */
5821 unsigned long strtab_size
; /* Size of string table. */
5825 arm_print_vma_and_name (struct arm_unw_aux_info
*aux
,
5826 bfd_vma fn
, struct absaddr addr
)
5828 const char *procname
;
5831 if (addr
.section
== SHN_UNDEF
)
5834 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5835 aux
->strtab_size
, addr
, &procname
,
5838 print_vma (fn
, PREFIX_HEX
);
5842 fputs (" <", stdout
);
5843 fputs (procname
, stdout
);
5846 printf ("+0x%lx", (unsigned long) sym_offset
);
5847 fputc ('>', stdout
);
5854 arm_free_section (struct arm_section
*arm_sec
)
5856 if (arm_sec
->data
!= NULL
)
5857 free (arm_sec
->data
);
5859 if (arm_sec
->rela
!= NULL
)
5860 free (arm_sec
->rela
);
5864 arm_section_get_word (struct arm_unw_aux_info
*aux
,
5865 struct arm_section
*arm_sec
,
5866 Elf_Internal_Shdr
*sec
, bfd_vma word_offset
,
5867 unsigned int *wordp
, struct absaddr
*addr
)
5869 Elf_Internal_Rela
*rp
;
5870 Elf_Internal_Sym
*sym
;
5871 const char * relname
;
5873 bfd_boolean wrapped
;
5875 addr
->section
= SHN_UNDEF
;
5878 if (sec
!= arm_sec
->sec
)
5880 Elf_Internal_Shdr
*relsec
;
5882 arm_free_section (arm_sec
);
5885 arm_sec
->data
= get_data (NULL
, aux
->file
, sec
->sh_offset
, 1,
5886 sec
->sh_size
, _("unwind data"));
5888 arm_sec
->rela
= NULL
;
5889 arm_sec
->nrelas
= 0;
5891 for (relsec
= section_headers
;
5892 relsec
< section_headers
+ elf_header
.e_shnum
;
5895 if (relsec
->sh_info
>= elf_header
.e_shnum
5896 || section_headers
+ relsec
->sh_info
!= sec
)
5899 if (relsec
->sh_type
== SHT_REL
)
5901 if (!slurp_rel_relocs (aux
->file
, relsec
->sh_offset
,
5903 & arm_sec
->rela
, & arm_sec
->nrelas
))
5907 else if (relsec
->sh_type
== SHT_RELA
)
5909 if (!slurp_rela_relocs (aux
->file
, relsec
->sh_offset
,
5911 & arm_sec
->rela
, & arm_sec
->nrelas
))
5917 arm_sec
->next_rela
= arm_sec
->rela
;
5920 if (arm_sec
->data
== NULL
)
5923 word
= byte_get (arm_sec
->data
+ word_offset
, 4);
5926 for (rp
= arm_sec
->next_rela
; rp
!= arm_sec
->rela
+ arm_sec
->nrelas
; rp
++)
5928 bfd_vma prelval
, offset
;
5930 if (rp
->r_offset
> word_offset
&& !wrapped
)
5935 if (rp
->r_offset
> word_offset
)
5938 if (rp
->r_offset
& 3)
5940 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
5941 (unsigned long) rp
->r_offset
);
5945 if (rp
->r_offset
< word_offset
)
5948 relname
= elf_arm_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5950 if (streq (relname
, "R_ARM_NONE"))
5953 if (! streq (relname
, "R_ARM_PREL31"))
5955 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5959 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5961 if (arm_sec
->rel_type
== SHT_REL
)
5963 offset
= word
& 0x7fffffff;
5964 if (offset
& 0x40000000)
5965 offset
|= ~ (bfd_vma
) 0x7fffffff;
5968 offset
= rp
->r_addend
;
5970 offset
+= sym
->st_value
;
5971 prelval
= offset
- (arm_sec
->sec
->sh_addr
+ rp
->r_offset
);
5973 word
= (word
& ~ (bfd_vma
) 0x7fffffff) | (prelval
& 0x7fffffff);
5974 addr
->section
= sym
->st_shndx
;
5975 addr
->offset
= offset
;
5980 arm_sec
->next_rela
= rp
;
5986 decode_arm_unwind (struct arm_unw_aux_info
*aux
,
5987 unsigned int word
, unsigned int remaining
,
5988 bfd_vma data_offset
, Elf_Internal_Shdr
*data_sec
,
5989 struct arm_section
*data_arm_sec
)
5992 unsigned int more_words
;
5993 struct absaddr addr
;
5996 if (remaining == 0 && more_words) \
5999 if (!arm_section_get_word (aux, data_arm_sec, data_sec, \
6000 data_offset, &word, &addr)) \
6006 #define GET_OP(OP) \
6011 (OP) = word >> 24; \
6016 printf ("[Truncated opcode]\n"); \
6019 printf (_("0x%02x "), OP)
6023 /* Fetch the first word. */
6024 if (!arm_section_get_word (aux
, data_arm_sec
, data_sec
, data_offset
,
6030 if ((word
& 0x80000000) == 0)
6032 /* Expand prel31 for personality routine. */
6034 const char *procname
;
6037 if (fn
& 0x40000000)
6038 fn
|= ~ (bfd_vma
) 0x7fffffff;
6039 fn
= fn
+ data_sec
->sh_addr
+ data_offset
;
6041 printf (_(" Personality routine: "));
6042 procname
= arm_print_vma_and_name (aux
, fn
, addr
);
6043 fputc ('\n', stdout
);
6045 /* The GCC personality routines use the standard compact
6046 encoding, starting with one byte giving the number of
6048 if (procname
!= NULL
6049 && (const_strneq (procname
, "__gcc_personality_v0")
6050 || const_strneq (procname
, "__gxx_personality_v0")
6051 || const_strneq (procname
, "__gcj_personality_v0")
6052 || const_strneq (procname
, "__gnu_objc_personality_v0")))
6059 printf (_(" [Truncated data]\n"));
6062 more_words
= word
>> 24;
6072 per_index
= (word
>> 24) & 0x7f;
6073 if (per_index
!= 0 && per_index
!= 1 && per_index
!= 2)
6075 printf (_(" [reserved compact index %d]\n"), per_index
);
6079 printf (_(" Compact model %d\n"), per_index
);
6088 more_words
= (word
>> 16) & 0xff;
6094 /* Decode the unwinding instructions. */
6097 unsigned int op
, op2
;
6106 printf (_(" 0x%02x "), op
);
6108 if ((op
& 0xc0) == 0x00)
6110 int offset
= ((op
& 0x3f) << 2) + 4;
6111 printf (_(" vsp = vsp + %d"), offset
);
6113 else if ((op
& 0xc0) == 0x40)
6115 int offset
= ((op
& 0x3f) << 2) + 4;
6116 printf (_(" vsp = vsp - %d"), offset
);
6118 else if ((op
& 0xf0) == 0x80)
6121 if (op
== 0x80 && op2
== 0)
6122 printf (_("Refuse to unwind"));
6125 unsigned int mask
= ((op
& 0x0f) << 8) | op2
;
6129 for (i
= 0; i
< 12; i
++)
6130 if (mask
& (1 << i
))
6136 printf ("r%d", 4 + i
);
6141 else if ((op
& 0xf0) == 0x90)
6143 if (op
== 0x9d || op
== 0x9f)
6144 printf (_(" [Reserved]"));
6146 printf (_(" vsp = r%d"), op
& 0x0f);
6148 else if ((op
& 0xf0) == 0xa0)
6150 int end
= 4 + (op
& 0x07);
6154 for (i
= 4; i
<= end
; i
++)
6170 else if (op
== 0xb0)
6171 printf (_(" finish"));
6172 else if (op
== 0xb1)
6175 if (op2
== 0 || (op2
& 0xf0) != 0)
6176 printf (_("[Spare]"));
6179 unsigned int mask
= op2
& 0x0f;
6183 for (i
= 0; i
< 12; i
++)
6184 if (mask
& (1 << i
))
6195 else if (op
== 0xb2)
6197 unsigned char buf
[5];
6198 unsigned int i
, len
;
6199 unsigned long offset
;
6200 for (i
= 0; i
< 9; i
++)
6203 if ((buf
[i
] & 0x80) == 0)
6206 assert (i
< sizeof (buf
));
6207 offset
= read_uleb128 (buf
, &len
);
6208 assert (len
== i
+ 1);
6209 offset
= offset
* 4 + 0x204;
6210 printf (_("vsp = vsp + %ld"), offset
);
6214 if (op
== 0xb3 || op
== 0xc6 || op
== 0xc7 || op
== 0xc8 || op
== 0xc9)
6217 printf (_("[unsupported two-byte opcode]"));
6221 printf (_(" [unsupported opcode]"));
6227 /* Decode the descriptors. Not implemented. */
6231 dump_arm_unwind (struct arm_unw_aux_info
*aux
, Elf_Internal_Shdr
*exidx_sec
)
6233 struct arm_section exidx_arm_sec
, extab_arm_sec
;
6234 unsigned int i
, exidx_len
;
6236 memset (&exidx_arm_sec
, 0, sizeof (exidx_arm_sec
));
6237 memset (&extab_arm_sec
, 0, sizeof (extab_arm_sec
));
6238 exidx_len
= exidx_sec
->sh_size
/ 8;
6240 for (i
= 0; i
< exidx_len
; i
++)
6242 unsigned int exidx_fn
, exidx_entry
;
6243 struct absaddr fn_addr
, entry_addr
;
6246 fputc ('\n', stdout
);
6248 if (!arm_section_get_word (aux
, &exidx_arm_sec
, exidx_sec
,
6249 8 * i
, &exidx_fn
, &fn_addr
)
6250 || !arm_section_get_word (aux
, &exidx_arm_sec
, exidx_sec
,
6251 8 * i
+ 4, &exidx_entry
, &entry_addr
))
6253 arm_free_section (&exidx_arm_sec
);
6254 arm_free_section (&extab_arm_sec
);
6258 fn
= exidx_fn
& 0x7fffffff;
6259 if (fn
& 0x40000000)
6260 fn
|= ~ (bfd_vma
) 0x7fffffff;
6261 fn
= fn
+ exidx_sec
->sh_addr
+ 8 * i
;
6263 arm_print_vma_and_name (aux
, fn
, entry_addr
);
6264 fputs (": ", stdout
);
6266 if (exidx_entry
== 1)
6268 print_vma (exidx_entry
, PREFIX_HEX
);
6269 fputs (" [cantunwind]\n", stdout
);
6271 else if (exidx_entry
& 0x80000000)
6273 print_vma (exidx_entry
, PREFIX_HEX
);
6274 fputc ('\n', stdout
);
6275 decode_arm_unwind (aux
, exidx_entry
, 4, 0, NULL
, NULL
);
6279 bfd_vma table
, table_offset
;
6280 Elf_Internal_Shdr
*table_sec
;
6282 fputs ("@", stdout
);
6283 table
= exidx_entry
;
6284 if (table
& 0x40000000)
6285 table
|= ~ (bfd_vma
) 0x7fffffff;
6286 table
= table
+ exidx_sec
->sh_addr
+ 8 * i
+ 4;
6287 print_vma (table
, PREFIX_HEX
);
6290 /* Locate the matching .ARM.extab. */
6291 if (entry_addr
.section
!= SHN_UNDEF
6292 && entry_addr
.section
< elf_header
.e_shnum
)
6294 table_sec
= section_headers
+ entry_addr
.section
;
6295 table_offset
= entry_addr
.offset
;
6299 table_sec
= find_section_by_address (table
);
6300 if (table_sec
!= NULL
)
6301 table_offset
= table
- table_sec
->sh_addr
;
6303 if (table_sec
== NULL
)
6305 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
6306 (unsigned long) table
);
6309 decode_arm_unwind (aux
, 0, 0, table_offset
, table_sec
,
6316 arm_free_section (&exidx_arm_sec
);
6317 arm_free_section (&extab_arm_sec
);
6321 arm_process_unwind (FILE *file
)
6323 struct arm_unw_aux_info aux
;
6324 Elf_Internal_Shdr
*unwsec
= NULL
;
6325 Elf_Internal_Shdr
*strsec
;
6326 Elf_Internal_Shdr
*sec
;
6329 memset (& aux
, 0, sizeof (aux
));
6332 if (string_table
== NULL
)
6335 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
6337 if (sec
->sh_type
== SHT_SYMTAB
&& sec
->sh_link
< elf_header
.e_shnum
)
6339 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
6340 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
6342 strsec
= section_headers
+ sec
->sh_link
;
6343 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
6344 1, strsec
->sh_size
, _("string table"));
6345 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
6347 else if (sec
->sh_type
== SHT_ARM_EXIDX
)
6352 printf (_("\nThere are no unwind sections in this file.\n"));
6354 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
6356 if (sec
->sh_type
== SHT_ARM_EXIDX
)
6358 printf (_("\nUnwind table index '%s' at offset 0x%lx contains %lu entries:\n"),
6360 (unsigned long) sec
->sh_offset
,
6361 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
)));
6363 dump_arm_unwind (&aux
, sec
);
6370 free ((char *) aux
.strtab
);
6376 process_unwind (FILE * file
)
6378 struct unwind_handler
6381 int (* handler
)(FILE *);
6384 { EM_ARM
, arm_process_unwind
},
6385 { EM_IA_64
, ia64_process_unwind
},
6386 { EM_PARISC
, hppa_process_unwind
},
6394 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
6395 if (elf_header
.e_machine
== handlers
[i
].machtype
)
6396 return handlers
[i
].handler (file
);
6398 printf (_("\nThere are no unwind sections in this file.\n"));
6403 dynamic_section_mips_val (Elf_Internal_Dyn
* entry
)
6405 switch (entry
->d_tag
)
6408 if (entry
->d_un
.d_val
== 0)
6412 static const char * opts
[] =
6414 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
6415 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
6416 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
6417 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
6422 for (cnt
= 0; cnt
< ARRAY_SIZE (opts
); ++cnt
)
6423 if (entry
->d_un
.d_val
& (1 << cnt
))
6425 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
6432 case DT_MIPS_IVERSION
:
6433 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6434 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6436 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
6439 case DT_MIPS_TIME_STAMP
:
6444 time_t atime
= entry
->d_un
.d_val
;
6445 tmp
= gmtime (&atime
);
6446 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
6447 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6448 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6449 printf ("Time Stamp: %s\n", timebuf
);
6453 case DT_MIPS_RLD_VERSION
:
6454 case DT_MIPS_LOCAL_GOTNO
:
6455 case DT_MIPS_CONFLICTNO
:
6456 case DT_MIPS_LIBLISTNO
:
6457 case DT_MIPS_SYMTABNO
:
6458 case DT_MIPS_UNREFEXTNO
:
6459 case DT_MIPS_HIPAGENO
:
6460 case DT_MIPS_DELTA_CLASS_NO
:
6461 case DT_MIPS_DELTA_INSTANCE_NO
:
6462 case DT_MIPS_DELTA_RELOC_NO
:
6463 case DT_MIPS_DELTA_SYM_NO
:
6464 case DT_MIPS_DELTA_CLASSSYM_NO
:
6465 case DT_MIPS_COMPACT_SIZE
:
6466 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
6470 printf ("%#lx\n", (unsigned long) entry
->d_un
.d_ptr
);
6476 dynamic_section_parisc_val (Elf_Internal_Dyn
* entry
)
6478 switch (entry
->d_tag
)
6480 case DT_HP_DLD_FLAGS
:
6489 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
6490 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
6491 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
6492 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
6493 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
6494 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
6495 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
6496 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
6497 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
6498 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
6499 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
6500 { DT_HP_GST
, "HP_GST" },
6501 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
6502 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
6503 { DT_HP_NODELETE
, "HP_NODELETE" },
6504 { DT_HP_GROUP
, "HP_GROUP" },
6505 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
6509 bfd_vma val
= entry
->d_un
.d_val
;
6511 for (cnt
= 0; cnt
< ARRAY_SIZE (flags
); ++cnt
)
6512 if (val
& flags
[cnt
].bit
)
6516 fputs (flags
[cnt
].str
, stdout
);
6518 val
^= flags
[cnt
].bit
;
6521 if (val
!= 0 || first
)
6525 print_vma (val
, HEX
);
6531 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
6538 dynamic_section_ia64_val (Elf_Internal_Dyn
* entry
)
6540 switch (entry
->d_tag
)
6542 case DT_IA_64_PLT_RESERVE
:
6543 /* First 3 slots reserved. */
6544 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
6546 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
6550 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
6557 get_32bit_dynamic_section (FILE * file
)
6559 Elf32_External_Dyn
* edyn
;
6560 Elf32_External_Dyn
* ext
;
6561 Elf_Internal_Dyn
* entry
;
6563 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
, 1,
6564 dynamic_size
, _("dynamic section"));
6568 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
6569 might not have the luxury of section headers. Look for the DT_NULL
6570 terminator to determine the number of entries. */
6571 for (ext
= edyn
, dynamic_nent
= 0;
6572 (char *) ext
< (char *) edyn
+ dynamic_size
;
6576 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
6580 dynamic_section
= (Elf_Internal_Dyn
*) cmalloc (dynamic_nent
,
6582 if (dynamic_section
== NULL
)
6584 error (_("Out of memory\n"));
6589 for (ext
= edyn
, entry
= dynamic_section
;
6590 entry
< dynamic_section
+ dynamic_nent
;
6593 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
6594 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
6603 get_64bit_dynamic_section (FILE * file
)
6605 Elf64_External_Dyn
* edyn
;
6606 Elf64_External_Dyn
* ext
;
6607 Elf_Internal_Dyn
* entry
;
6609 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
, 1,
6610 dynamic_size
, _("dynamic section"));
6614 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
6615 might not have the luxury of section headers. Look for the DT_NULL
6616 terminator to determine the number of entries. */
6617 for (ext
= edyn
, dynamic_nent
= 0;
6618 (char *) ext
< (char *) edyn
+ dynamic_size
;
6622 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
6626 dynamic_section
= (Elf_Internal_Dyn
*) cmalloc (dynamic_nent
,
6628 if (dynamic_section
== NULL
)
6630 error (_("Out of memory\n"));
6635 for (ext
= edyn
, entry
= dynamic_section
;
6636 entry
< dynamic_section
+ dynamic_nent
;
6639 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
6640 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
6649 print_dynamic_flags (bfd_vma flags
)
6657 flag
= flags
& - flags
;
6667 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
6668 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
6669 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
6670 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
6671 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
6672 default: fputs ("unknown", stdout
); break;
6678 /* Parse and display the contents of the dynamic section. */
6681 process_dynamic_section (FILE * file
)
6683 Elf_Internal_Dyn
* entry
;
6685 if (dynamic_size
== 0)
6688 printf (_("\nThere is no dynamic section in this file.\n"));
6695 if (! get_32bit_dynamic_section (file
))
6698 else if (! get_64bit_dynamic_section (file
))
6701 /* Find the appropriate symbol table. */
6702 if (dynamic_symbols
== NULL
)
6704 for (entry
= dynamic_section
;
6705 entry
< dynamic_section
+ dynamic_nent
;
6708 Elf_Internal_Shdr section
;
6710 if (entry
->d_tag
!= DT_SYMTAB
)
6713 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
6715 /* Since we do not know how big the symbol table is,
6716 we default to reading in the entire file (!) and
6717 processing that. This is overkill, I know, but it
6719 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
6721 if (archive_file_offset
!= 0)
6722 section
.sh_size
= archive_file_size
- section
.sh_offset
;
6725 if (fseek (file
, 0, SEEK_END
))
6726 error (_("Unable to seek to end of file!\n"));
6728 section
.sh_size
= ftell (file
) - section
.sh_offset
;
6732 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
6734 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
6736 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
6737 if (num_dynamic_syms
< 1)
6739 error (_("Unable to determine the number of symbols to load\n"));
6743 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
6747 /* Similarly find a string table. */
6748 if (dynamic_strings
== NULL
)
6750 for (entry
= dynamic_section
;
6751 entry
< dynamic_section
+ dynamic_nent
;
6754 unsigned long offset
;
6757 if (entry
->d_tag
!= DT_STRTAB
)
6760 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
6762 /* Since we do not know how big the string table is,
6763 we default to reading in the entire file (!) and
6764 processing that. This is overkill, I know, but it
6767 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
6769 if (archive_file_offset
!= 0)
6770 str_tab_len
= archive_file_size
- offset
;
6773 if (fseek (file
, 0, SEEK_END
))
6774 error (_("Unable to seek to end of file\n"));
6775 str_tab_len
= ftell (file
) - offset
;
6778 if (str_tab_len
< 1)
6781 (_("Unable to determine the length of the dynamic string table\n"));
6785 dynamic_strings
= (char *) get_data (NULL
, file
, offset
, 1,
6787 _("dynamic string table"));
6788 dynamic_strings_length
= str_tab_len
;
6793 /* And find the syminfo section if available. */
6794 if (dynamic_syminfo
== NULL
)
6796 unsigned long syminsz
= 0;
6798 for (entry
= dynamic_section
;
6799 entry
< dynamic_section
+ dynamic_nent
;
6802 if (entry
->d_tag
== DT_SYMINENT
)
6804 /* Note: these braces are necessary to avoid a syntax
6805 error from the SunOS4 C compiler. */
6806 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
6808 else if (entry
->d_tag
== DT_SYMINSZ
)
6809 syminsz
= entry
->d_un
.d_val
;
6810 else if (entry
->d_tag
== DT_SYMINFO
)
6811 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
6815 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
6817 Elf_External_Syminfo
* extsyminfo
;
6818 Elf_External_Syminfo
* extsym
;
6819 Elf_Internal_Syminfo
* syminfo
;
6821 /* There is a syminfo section. Read the data. */
6822 extsyminfo
= (Elf_External_Syminfo
*)
6823 get_data (NULL
, file
, dynamic_syminfo_offset
, 1, syminsz
,
6824 _("symbol information"));
6828 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
6829 if (dynamic_syminfo
== NULL
)
6831 error (_("Out of memory\n"));
6835 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
6836 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
6837 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
6838 ++syminfo
, ++extsym
)
6840 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
6841 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
6848 if (do_dynamic
&& dynamic_addr
)
6849 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
6850 dynamic_addr
, dynamic_nent
);
6852 printf (_(" Tag Type Name/Value\n"));
6854 for (entry
= dynamic_section
;
6855 entry
< dynamic_section
+ dynamic_nent
;
6863 print_vma (entry
->d_tag
, FULL_HEX
);
6864 dtype
= get_dynamic_type (entry
->d_tag
);
6865 printf (" (%s)%*s", dtype
,
6866 ((is_32bit_elf
? 27 : 19)
6867 - (int) strlen (dtype
)),
6871 switch (entry
->d_tag
)
6875 print_dynamic_flags (entry
->d_un
.d_val
);
6885 switch (entry
->d_tag
)
6888 printf (_("Auxiliary library"));
6892 printf (_("Filter library"));
6896 printf (_("Configuration file"));
6900 printf (_("Dependency audit library"));
6904 printf (_("Audit library"));
6908 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6909 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
6913 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6922 printf (_("Flags:"));
6924 if (entry
->d_un
.d_val
== 0)
6925 printf (_(" None\n"));
6928 unsigned long int val
= entry
->d_un
.d_val
;
6930 if (val
& DTF_1_PARINIT
)
6932 printf (" PARINIT");
6933 val
^= DTF_1_PARINIT
;
6935 if (val
& DTF_1_CONFEXP
)
6937 printf (" CONFEXP");
6938 val
^= DTF_1_CONFEXP
;
6941 printf (" %lx", val
);
6950 printf (_("Flags:"));
6952 if (entry
->d_un
.d_val
== 0)
6953 printf (_(" None\n"));
6956 unsigned long int val
= entry
->d_un
.d_val
;
6958 if (val
& DF_P1_LAZYLOAD
)
6960 printf (" LAZYLOAD");
6961 val
^= DF_P1_LAZYLOAD
;
6963 if (val
& DF_P1_GROUPPERM
)
6965 printf (" GROUPPERM");
6966 val
^= DF_P1_GROUPPERM
;
6969 printf (" %lx", val
);
6978 printf (_("Flags:"));
6979 if (entry
->d_un
.d_val
== 0)
6980 printf (_(" None\n"));
6983 unsigned long int val
= entry
->d_un
.d_val
;
6990 if (val
& DF_1_GLOBAL
)
6995 if (val
& DF_1_GROUP
)
7000 if (val
& DF_1_NODELETE
)
7002 printf (" NODELETE");
7003 val
^= DF_1_NODELETE
;
7005 if (val
& DF_1_LOADFLTR
)
7007 printf (" LOADFLTR");
7008 val
^= DF_1_LOADFLTR
;
7010 if (val
& DF_1_INITFIRST
)
7012 printf (" INITFIRST");
7013 val
^= DF_1_INITFIRST
;
7015 if (val
& DF_1_NOOPEN
)
7020 if (val
& DF_1_ORIGIN
)
7025 if (val
& DF_1_DIRECT
)
7030 if (val
& DF_1_TRANS
)
7035 if (val
& DF_1_INTERPOSE
)
7037 printf (" INTERPOSE");
7038 val
^= DF_1_INTERPOSE
;
7040 if (val
& DF_1_NODEFLIB
)
7042 printf (" NODEFLIB");
7043 val
^= DF_1_NODEFLIB
;
7045 if (val
& DF_1_NODUMP
)
7050 if (val
& DF_1_CONLFAT
)
7052 printf (" CONLFAT");
7053 val
^= DF_1_CONLFAT
;
7056 printf (" %lx", val
);
7063 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
7065 puts (get_dynamic_type (entry
->d_un
.d_val
));
7085 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
7091 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
7092 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
7098 switch (entry
->d_tag
)
7101 printf (_("Shared library: [%s]"), name
);
7103 if (streq (name
, program_interpreter
))
7104 printf (_(" program interpreter"));
7108 printf (_("Library soname: [%s]"), name
);
7112 printf (_("Library rpath: [%s]"), name
);
7116 printf (_("Library runpath: [%s]"), name
);
7120 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
7125 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
7138 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
7142 case DT_INIT_ARRAYSZ
:
7143 case DT_FINI_ARRAYSZ
:
7144 case DT_GNU_CONFLICTSZ
:
7145 case DT_GNU_LIBLISTSZ
:
7148 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
7149 printf (" (bytes)\n");
7159 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
7172 if (entry
->d_tag
== DT_USED
7173 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
7175 char * name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
7179 printf (_("Not needed object: [%s]\n"), name
);
7184 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
7190 /* The value of this entry is ignored. */
7195 case DT_GNU_PRELINKED
:
7199 time_t atime
= entry
->d_un
.d_val
;
7201 tmp
= gmtime (&atime
);
7202 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
7203 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
7204 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
7210 dynamic_info_DT_GNU_HASH
= entry
->d_un
.d_val
;
7213 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
7219 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
7220 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
7225 switch (elf_header
.e_machine
)
7228 case EM_MIPS_RS3_LE
:
7229 dynamic_section_mips_val (entry
);
7232 dynamic_section_parisc_val (entry
);
7235 dynamic_section_ia64_val (entry
);
7238 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
7250 get_ver_flags (unsigned int flags
)
7252 static char buff
[32];
7259 if (flags
& VER_FLG_BASE
)
7260 strcat (buff
, "BASE ");
7262 if (flags
& VER_FLG_WEAK
)
7264 if (flags
& VER_FLG_BASE
)
7265 strcat (buff
, "| ");
7267 strcat (buff
, "WEAK ");
7270 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
7271 strcat (buff
, "| <unknown>");
7276 /* Display the contents of the version sections. */
7279 process_version_sections (FILE * file
)
7281 Elf_Internal_Shdr
* section
;
7288 for (i
= 0, section
= section_headers
;
7289 i
< elf_header
.e_shnum
;
7292 switch (section
->sh_type
)
7294 case SHT_GNU_verdef
:
7296 Elf_External_Verdef
* edefs
;
7304 (_("\nVersion definition section '%s' contains %u entries:\n"),
7305 SECTION_NAME (section
), section
->sh_info
);
7307 printf (_(" Addr: 0x"));
7308 printf_vma (section
->sh_addr
);
7309 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
7310 (unsigned long) section
->sh_offset
, section
->sh_link
,
7311 section
->sh_link
< elf_header
.e_shnum
7312 ? SECTION_NAME (section_headers
+ section
->sh_link
)
7315 edefs
= (Elf_External_Verdef
*)
7316 get_data (NULL
, file
, section
->sh_offset
, 1,section
->sh_size
,
7317 _("version definition section"));
7318 endbuf
= (char *) edefs
+ section
->sh_size
;
7322 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
7325 Elf_External_Verdef
* edef
;
7326 Elf_Internal_Verdef ent
;
7327 Elf_External_Verdaux
* eaux
;
7328 Elf_Internal_Verdaux aux
;
7332 vstart
= ((char *) edefs
) + idx
;
7333 if (vstart
+ sizeof (*edef
) > endbuf
)
7336 edef
= (Elf_External_Verdef
*) vstart
;
7338 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
7339 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
7340 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
7341 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
7342 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
7343 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
7344 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
7346 printf (_(" %#06x: Rev: %d Flags: %s"),
7347 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
7349 printf (_(" Index: %d Cnt: %d "),
7350 ent
.vd_ndx
, ent
.vd_cnt
);
7352 vstart
+= ent
.vd_aux
;
7354 eaux
= (Elf_External_Verdaux
*) vstart
;
7356 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
7357 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
7359 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
7360 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
7362 printf (_("Name index: %ld\n"), aux
.vda_name
);
7364 isum
= idx
+ ent
.vd_aux
;
7366 for (j
= 1; j
< ent
.vd_cnt
; j
++)
7368 isum
+= aux
.vda_next
;
7369 vstart
+= aux
.vda_next
;
7371 eaux
= (Elf_External_Verdaux
*) vstart
;
7372 if (vstart
+ sizeof (*eaux
) > endbuf
)
7375 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
7376 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
7378 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
7379 printf (_(" %#06x: Parent %d: %s\n"),
7380 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
7382 printf (_(" %#06x: Parent %d, name index: %ld\n"),
7383 isum
, j
, aux
.vda_name
);
7386 printf (_(" Version def aux past end of section\n"));
7390 if (cnt
< section
->sh_info
)
7391 printf (_(" Version definition past end of section\n"));
7397 case SHT_GNU_verneed
:
7399 Elf_External_Verneed
* eneed
;
7406 printf (_("\nVersion needs section '%s' contains %u entries:\n"),
7407 SECTION_NAME (section
), section
->sh_info
);
7409 printf (_(" Addr: 0x"));
7410 printf_vma (section
->sh_addr
);
7411 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
7412 (unsigned long) section
->sh_offset
, section
->sh_link
,
7413 section
->sh_link
< elf_header
.e_shnum
7414 ? SECTION_NAME (section_headers
+ section
->sh_link
)
7417 eneed
= (Elf_External_Verneed
*) get_data (NULL
, file
,
7418 section
->sh_offset
, 1,
7420 _("version need section"));
7421 endbuf
= (char *) eneed
+ section
->sh_size
;
7425 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
7427 Elf_External_Verneed
* entry
;
7428 Elf_Internal_Verneed ent
;
7433 vstart
= ((char *) eneed
) + idx
;
7434 if (vstart
+ sizeof (*entry
) > endbuf
)
7437 entry
= (Elf_External_Verneed
*) vstart
;
7439 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
7440 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
7441 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
7442 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
7443 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
7445 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
7447 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
7448 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
7450 printf (_(" File: %lx"), ent
.vn_file
);
7452 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
7454 vstart
+= ent
.vn_aux
;
7456 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
7458 Elf_External_Vernaux
* eaux
;
7459 Elf_Internal_Vernaux aux
;
7461 if (vstart
+ sizeof (*eaux
) > endbuf
)
7463 eaux
= (Elf_External_Vernaux
*) vstart
;
7465 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
7466 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
7467 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
7468 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
7469 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
7471 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
7472 printf (_(" %#06x: Name: %s"),
7473 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
7475 printf (_(" %#06x: Name index: %lx"),
7476 isum
, aux
.vna_name
);
7478 printf (_(" Flags: %s Version: %d\n"),
7479 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
7481 isum
+= aux
.vna_next
;
7482 vstart
+= aux
.vna_next
;
7485 printf (_(" Version need aux past end of section\n"));
7489 if (cnt
< section
->sh_info
)
7490 printf (_(" Version need past end of section\n"));
7496 case SHT_GNU_versym
:
7498 Elf_Internal_Shdr
* link_section
;
7501 unsigned char * edata
;
7502 unsigned short * data
;
7504 Elf_Internal_Sym
* symbols
;
7505 Elf_Internal_Shdr
* string_sec
;
7508 if (section
->sh_link
>= elf_header
.e_shnum
)
7511 link_section
= section_headers
+ section
->sh_link
;
7512 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
7514 if (link_section
->sh_link
>= elf_header
.e_shnum
)
7519 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
7521 string_sec
= section_headers
+ link_section
->sh_link
;
7523 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
, 1,
7524 string_sec
->sh_size
,
7525 _("version string table"));
7529 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
7530 SECTION_NAME (section
), total
);
7532 printf (_(" Addr: "));
7533 printf_vma (section
->sh_addr
);
7534 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
7535 (unsigned long) section
->sh_offset
, section
->sh_link
,
7536 SECTION_NAME (link_section
));
7538 off
= offset_from_vma (file
,
7539 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
7540 total
* sizeof (short));
7541 edata
= (unsigned char *) get_data (NULL
, file
, off
, total
,
7543 _("version symbol data"));
7550 data
= (short unsigned int *) cmalloc (total
, sizeof (short));
7552 for (cnt
= total
; cnt
--;)
7553 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
7558 for (cnt
= 0; cnt
< total
; cnt
+= 4)
7561 int check_def
, check_need
;
7564 printf (" %03x:", cnt
);
7566 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
7567 switch (data
[cnt
+ j
])
7570 fputs (_(" 0 (*local*) "), stdout
);
7574 fputs (_(" 1 (*global*) "), stdout
);
7578 nn
= printf ("%4x%c", data
[cnt
+ j
] & VERSYM_VERSION
,
7579 data
[cnt
+ j
] & VERSYM_HIDDEN
? 'h' : ' ');
7583 if (symbols
[cnt
+ j
].st_shndx
>= elf_header
.e_shnum
7584 || section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
7587 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
7594 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
7596 Elf_Internal_Verneed ivn
;
7597 unsigned long offset
;
7599 offset
= offset_from_vma
7600 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
7601 sizeof (Elf_External_Verneed
));
7605 Elf_Internal_Vernaux ivna
;
7606 Elf_External_Verneed evn
;
7607 Elf_External_Vernaux evna
;
7608 unsigned long a_off
;
7610 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
7613 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
7614 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
7616 a_off
= offset
+ ivn
.vn_aux
;
7620 get_data (&evna
, file
, a_off
, sizeof (evna
),
7621 1, _("version need aux (2)"));
7623 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
7624 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
7626 a_off
+= ivna
.vna_next
;
7628 while (ivna
.vna_other
!= data
[cnt
+ j
]
7629 && ivna
.vna_next
!= 0);
7631 if (ivna
.vna_other
== data
[cnt
+ j
])
7633 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
7635 if (ivna
.vna_name
>= string_sec
->sh_size
)
7636 name
= _("*invalid*");
7638 name
= strtab
+ ivna
.vna_name
;
7639 nn
+= printf ("(%s%-*s",
7641 12 - (int) strlen (name
),
7647 offset
+= ivn
.vn_next
;
7649 while (ivn
.vn_next
);
7652 if (check_def
&& data
[cnt
+ j
] != 0x8001
7653 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7655 Elf_Internal_Verdef ivd
;
7656 Elf_External_Verdef evd
;
7657 unsigned long offset
;
7659 offset
= offset_from_vma
7660 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7665 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
7668 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7669 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7671 offset
+= ivd
.vd_next
;
7673 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & VERSYM_VERSION
)
7674 && ivd
.vd_next
!= 0);
7676 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & VERSYM_VERSION
))
7678 Elf_External_Verdaux evda
;
7679 Elf_Internal_Verdaux ivda
;
7681 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7683 get_data (&evda
, file
,
7684 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
7686 _("version def aux"));
7688 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7690 if (ivda
.vda_name
>= string_sec
->sh_size
)
7691 name
= _("*invalid*");
7693 name
= strtab
+ ivda
.vda_name
;
7694 nn
+= printf ("(%s%-*s",
7696 12 - (int) strlen (name
),
7702 printf ("%*c", 18 - nn
, ' ');
7720 printf (_("\nNo version information found in this file.\n"));
7726 get_symbol_binding (unsigned int binding
)
7728 static char buff
[32];
7732 case STB_LOCAL
: return "LOCAL";
7733 case STB_GLOBAL
: return "GLOBAL";
7734 case STB_WEAK
: return "WEAK";
7736 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
7737 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
7739 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
7741 if (binding
== STB_GNU_UNIQUE
7742 && (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_LINUX
7743 /* GNU/Linux is still using the default value 0. */
7744 || elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
))
7746 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
7749 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
7755 get_symbol_type (unsigned int type
)
7757 static char buff
[32];
7761 case STT_NOTYPE
: return "NOTYPE";
7762 case STT_OBJECT
: return "OBJECT";
7763 case STT_FUNC
: return "FUNC";
7764 case STT_SECTION
: return "SECTION";
7765 case STT_FILE
: return "FILE";
7766 case STT_COMMON
: return "COMMON";
7767 case STT_TLS
: return "TLS";
7768 case STT_RELC
: return "RELC";
7769 case STT_SRELC
: return "SRELC";
7771 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
7773 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
7774 return "THUMB_FUNC";
7776 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
7779 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
7780 return "PARISC_MILLI";
7782 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
7784 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
7786 if (elf_header
.e_machine
== EM_PARISC
)
7788 if (type
== STT_HP_OPAQUE
)
7790 if (type
== STT_HP_STUB
)
7794 if (type
== STT_GNU_IFUNC
7795 && (elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_LINUX
7796 /* GNU/Linux is still using the default value 0. */
7797 || elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_NONE
))
7800 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
7803 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
7809 get_symbol_visibility (unsigned int visibility
)
7813 case STV_DEFAULT
: return "DEFAULT";
7814 case STV_INTERNAL
: return "INTERNAL";
7815 case STV_HIDDEN
: return "HIDDEN";
7816 case STV_PROTECTED
: return "PROTECTED";
7822 get_mips_symbol_other (unsigned int other
)
7826 case STO_OPTIONAL
: return "OPTIONAL";
7827 case STO_MIPS16
: return "MIPS16";
7828 case STO_MIPS_PLT
: return "MIPS PLT";
7829 case STO_MIPS_PIC
: return "MIPS PIC";
7830 default: return NULL
;
7835 get_symbol_other (unsigned int other
)
7837 const char * result
= NULL
;
7838 static char buff
[32];
7843 switch (elf_header
.e_machine
)
7846 result
= get_mips_symbol_other (other
);
7854 snprintf (buff
, sizeof buff
, _("<other>: %x"), other
);
7859 get_symbol_index_type (unsigned int type
)
7861 static char buff
[32];
7865 case SHN_UNDEF
: return "UND";
7866 case SHN_ABS
: return "ABS";
7867 case SHN_COMMON
: return "COM";
7869 if (type
== SHN_IA_64_ANSI_COMMON
7870 && elf_header
.e_machine
== EM_IA_64
7871 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
7873 else if ((elf_header
.e_machine
== EM_X86_64
7874 || elf_header
.e_machine
== EM_L1OM
)
7875 && type
== SHN_X86_64_LCOMMON
)
7877 else if (type
== SHN_MIPS_SCOMMON
7878 && elf_header
.e_machine
== EM_MIPS
)
7880 else if (type
== SHN_MIPS_SUNDEFINED
7881 && elf_header
.e_machine
== EM_MIPS
)
7883 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
7884 sprintf (buff
, "PRC[0x%04x]", type
& 0xffff);
7885 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
7886 sprintf (buff
, "OS [0x%04x]", type
& 0xffff);
7887 else if (type
>= SHN_LORESERVE
)
7888 sprintf (buff
, "RSV[0x%04x]", type
& 0xffff);
7890 sprintf (buff
, "%3d", type
);
7898 get_dynamic_data (FILE * file
, unsigned int number
, unsigned int ent_size
)
7900 unsigned char * e_data
;
7903 e_data
= (unsigned char *) cmalloc (number
, ent_size
);
7907 error (_("Out of memory\n"));
7911 if (fread (e_data
, ent_size
, number
, file
) != number
)
7913 error (_("Unable to read in dynamic data\n"));
7917 i_data
= (bfd_vma
*) cmalloc (number
, sizeof (*i_data
));
7921 error (_("Out of memory\n"));
7927 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
7935 print_dynamic_symbol (bfd_vma si
, unsigned long hn
)
7937 Elf_Internal_Sym
* psym
;
7940 psym
= dynamic_symbols
+ si
;
7942 n
= print_vma (si
, DEC_5
);
7944 fputs (" " + n
, stdout
);
7945 printf (" %3lu: ", hn
);
7946 print_vma (psym
->st_value
, LONG_HEX
);
7948 print_vma (psym
->st_size
, DEC_5
);
7950 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
7951 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
7952 printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
7953 /* Check to see if any other bits in the st_other field are set.
7954 Note - displaying this information disrupts the layout of the
7955 table being generated, but for the moment this case is very
7957 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
7958 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
7959 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
7960 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7961 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7963 printf (" <corrupt: %14ld>", psym
->st_name
);
7967 /* Dump the symbol table. */
7969 process_symbol_table (FILE * file
)
7971 Elf_Internal_Shdr
* section
;
7972 bfd_vma nbuckets
= 0;
7973 bfd_vma nchains
= 0;
7974 bfd_vma
* buckets
= NULL
;
7975 bfd_vma
* chains
= NULL
;
7976 bfd_vma ngnubuckets
= 0;
7977 bfd_vma
* gnubuckets
= NULL
;
7978 bfd_vma
* gnuchains
= NULL
;
7979 bfd_vma gnusymidx
= 0;
7981 if (!do_syms
&& !do_dyn_syms
&& !do_histogram
)
7984 if (dynamic_info
[DT_HASH
]
7986 || (do_using_dynamic
7988 && dynamic_strings
!= NULL
)))
7990 unsigned char nb
[8];
7991 unsigned char nc
[8];
7992 int hash_ent_size
= 4;
7994 if ((elf_header
.e_machine
== EM_ALPHA
7995 || elf_header
.e_machine
== EM_S390
7996 || elf_header
.e_machine
== EM_S390_OLD
)
7997 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
8001 (archive_file_offset
8002 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
8003 sizeof nb
+ sizeof nc
)),
8006 error (_("Unable to seek to start of dynamic information\n"));
8010 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
8012 error (_("Failed to read in number of buckets\n"));
8016 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
8018 error (_("Failed to read in number of chains\n"));
8022 nbuckets
= byte_get (nb
, hash_ent_size
);
8023 nchains
= byte_get (nc
, hash_ent_size
);
8025 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
8026 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
8029 if (buckets
== NULL
|| chains
== NULL
)
8031 if (do_using_dynamic
)
8042 if (dynamic_info_DT_GNU_HASH
8044 || (do_using_dynamic
8046 && dynamic_strings
!= NULL
)))
8048 unsigned char nb
[16];
8049 bfd_vma i
, maxchain
= 0xffffffff, bitmaskwords
;
8050 bfd_vma buckets_vma
;
8053 (archive_file_offset
8054 + offset_from_vma (file
, dynamic_info_DT_GNU_HASH
,
8058 error (_("Unable to seek to start of dynamic information\n"));
8062 if (fread (nb
, 16, 1, file
) != 1)
8064 error (_("Failed to read in number of buckets\n"));
8068 ngnubuckets
= byte_get (nb
, 4);
8069 gnusymidx
= byte_get (nb
+ 4, 4);
8070 bitmaskwords
= byte_get (nb
+ 8, 4);
8071 buckets_vma
= dynamic_info_DT_GNU_HASH
+ 16;
8073 buckets_vma
+= bitmaskwords
* 4;
8075 buckets_vma
+= bitmaskwords
* 8;
8078 (archive_file_offset
8079 + offset_from_vma (file
, buckets_vma
, 4)),
8082 error (_("Unable to seek to start of dynamic information\n"));
8086 gnubuckets
= get_dynamic_data (file
, ngnubuckets
, 4);
8088 if (gnubuckets
== NULL
)
8091 for (i
= 0; i
< ngnubuckets
; i
++)
8092 if (gnubuckets
[i
] != 0)
8094 if (gnubuckets
[i
] < gnusymidx
)
8097 if (maxchain
== 0xffffffff || gnubuckets
[i
] > maxchain
)
8098 maxchain
= gnubuckets
[i
];
8101 if (maxchain
== 0xffffffff)
8104 maxchain
-= gnusymidx
;
8107 (archive_file_offset
8108 + offset_from_vma (file
, buckets_vma
8109 + 4 * (ngnubuckets
+ maxchain
), 4)),
8112 error (_("Unable to seek to start of dynamic information\n"));
8118 if (fread (nb
, 4, 1, file
) != 1)
8120 error (_("Failed to determine last chain length\n"));
8124 if (maxchain
+ 1 == 0)
8129 while ((byte_get (nb
, 4) & 1) == 0);
8132 (archive_file_offset
8133 + offset_from_vma (file
, buckets_vma
+ 4 * ngnubuckets
, 4)),
8136 error (_("Unable to seek to start of dynamic information\n"));
8140 gnuchains
= get_dynamic_data (file
, maxchain
, 4);
8143 if (gnuchains
== NULL
)
8148 if (do_using_dynamic
)
8153 if ((dynamic_info
[DT_HASH
] || dynamic_info_DT_GNU_HASH
)
8156 && dynamic_strings
!= NULL
)
8160 if (dynamic_info
[DT_HASH
])
8164 printf (_("\nSymbol table for image:\n"));
8166 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
8168 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
8170 for (hn
= 0; hn
< nbuckets
; hn
++)
8175 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
8176 print_dynamic_symbol (si
, hn
);
8180 if (dynamic_info_DT_GNU_HASH
)
8182 printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
8184 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
8186 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
8188 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
8189 if (gnubuckets
[hn
] != 0)
8191 bfd_vma si
= gnubuckets
[hn
];
8192 bfd_vma off
= si
- gnusymidx
;
8196 print_dynamic_symbol (si
, hn
);
8199 while ((gnuchains
[off
++] & 1) == 0);
8203 else if (do_dyn_syms
|| (do_syms
&& !do_using_dynamic
))
8207 for (i
= 0, section
= section_headers
;
8208 i
< elf_header
.e_shnum
;
8212 char * strtab
= NULL
;
8213 unsigned long int strtab_size
= 0;
8214 Elf_Internal_Sym
* symtab
;
8215 Elf_Internal_Sym
* psym
;
8217 if ((section
->sh_type
!= SHT_SYMTAB
8218 && section
->sh_type
!= SHT_DYNSYM
)
8220 && section
->sh_type
== SHT_SYMTAB
))
8223 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
8224 SECTION_NAME (section
),
8225 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
8227 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
8229 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
8231 symtab
= GET_ELF_SYMBOLS (file
, section
);
8235 if (section
->sh_link
== elf_header
.e_shstrndx
)
8237 strtab
= string_table
;
8238 strtab_size
= string_table_length
;
8240 else if (section
->sh_link
< elf_header
.e_shnum
)
8242 Elf_Internal_Shdr
* string_sec
;
8244 string_sec
= section_headers
+ section
->sh_link
;
8246 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
8247 1, string_sec
->sh_size
,
8249 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
8252 for (si
= 0, psym
= symtab
;
8253 si
< section
->sh_size
/ section
->sh_entsize
;
8256 printf ("%6d: ", si
);
8257 print_vma (psym
->st_value
, LONG_HEX
);
8259 print_vma (psym
->st_size
, DEC_5
);
8260 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
8261 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
8262 printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
8263 /* Check to see if any other bits in the st_other field are set.
8264 Note - displaying this information disrupts the layout of the
8265 table being generated, but for the moment this case is very rare. */
8266 if (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
))
8267 printf (" [%s] ", get_symbol_other (psym
->st_other
^ ELF_ST_VISIBILITY (psym
->st_other
)));
8268 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
8269 print_symbol (25, psym
->st_name
< strtab_size
8270 ? strtab
+ psym
->st_name
: "<corrupt>");
8272 if (section
->sh_type
== SHT_DYNSYM
&&
8273 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
8275 unsigned char data
[2];
8276 unsigned short vers_data
;
8277 unsigned long offset
;
8281 offset
= offset_from_vma
8282 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
8283 sizeof data
+ si
* sizeof (vers_data
));
8285 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
8286 sizeof (data
), 1, _("version data"));
8288 vers_data
= byte_get (data
, 2);
8290 is_nobits
= (psym
->st_shndx
< elf_header
.e_shnum
8291 && section_headers
[psym
->st_shndx
].sh_type
8294 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
8296 if ((vers_data
& VERSYM_HIDDEN
) || vers_data
> 1)
8298 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
8299 && (is_nobits
|| ! check_def
))
8301 Elf_External_Verneed evn
;
8302 Elf_Internal_Verneed ivn
;
8303 Elf_Internal_Vernaux ivna
;
8305 /* We must test both. */
8306 offset
= offset_from_vma
8307 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
8312 unsigned long vna_off
;
8314 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
8317 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
8318 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
8320 vna_off
= offset
+ ivn
.vn_aux
;
8324 Elf_External_Vernaux evna
;
8326 get_data (&evna
, file
, vna_off
,
8328 _("version need aux (3)"));
8330 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
8331 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
8332 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
8334 vna_off
+= ivna
.vna_next
;
8336 while (ivna
.vna_other
!= vers_data
8337 && ivna
.vna_next
!= 0);
8339 if (ivna
.vna_other
== vers_data
)
8342 offset
+= ivn
.vn_next
;
8344 while (ivn
.vn_next
!= 0);
8346 if (ivna
.vna_other
== vers_data
)
8349 ivna
.vna_name
< strtab_size
8350 ? strtab
+ ivna
.vna_name
: "<corrupt>",
8354 else if (! is_nobits
)
8355 error (_("bad dynamic symbol\n"));
8362 if (vers_data
!= 0x8001
8363 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
8365 Elf_Internal_Verdef ivd
;
8366 Elf_Internal_Verdaux ivda
;
8367 Elf_External_Verdaux evda
;
8370 off
= offset_from_vma
8372 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
8373 sizeof (Elf_External_Verdef
));
8377 Elf_External_Verdef evd
;
8379 get_data (&evd
, file
, off
, sizeof (evd
),
8380 1, _("version def"));
8382 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
8383 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
8384 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
8388 while (ivd
.vd_ndx
!= (vers_data
& VERSYM_VERSION
)
8389 && ivd
.vd_next
!= 0);
8394 get_data (&evda
, file
, off
, sizeof (evda
),
8395 1, _("version def aux"));
8397 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
8399 if (psym
->st_name
!= ivda
.vda_name
)
8400 printf ((vers_data
& VERSYM_HIDDEN
)
8402 ivda
.vda_name
< strtab_size
8403 ? strtab
+ ivda
.vda_name
: "<corrupt>");
8413 if (strtab
!= string_table
)
8419 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
8421 if (do_histogram
&& buckets
!= NULL
)
8423 unsigned long * lengths
;
8424 unsigned long * counts
;
8427 unsigned long maxlength
= 0;
8428 unsigned long nzero_counts
= 0;
8429 unsigned long nsyms
= 0;
8431 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
8432 (unsigned long) nbuckets
);
8433 printf (_(" Length Number %% of total Coverage\n"));
8435 lengths
= (unsigned long *) calloc (nbuckets
, sizeof (*lengths
));
8436 if (lengths
== NULL
)
8438 error (_("Out of memory\n"));
8441 for (hn
= 0; hn
< nbuckets
; ++hn
)
8443 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
8446 if (maxlength
< ++lengths
[hn
])
8451 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
8454 error (_("Out of memory\n"));
8458 for (hn
= 0; hn
< nbuckets
; ++hn
)
8459 ++counts
[lengths
[hn
]];
8464 printf (" 0 %-10lu (%5.1f%%)\n",
8465 counts
[0], (counts
[0] * 100.0) / nbuckets
);
8466 for (i
= 1; i
<= maxlength
; ++i
)
8468 nzero_counts
+= counts
[i
] * i
;
8469 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
8470 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
8471 (nzero_counts
* 100.0) / nsyms
);
8479 if (buckets
!= NULL
)
8485 if (do_histogram
&& gnubuckets
!= NULL
)
8487 unsigned long * lengths
;
8488 unsigned long * counts
;
8490 unsigned long maxlength
= 0;
8491 unsigned long nzero_counts
= 0;
8492 unsigned long nsyms
= 0;
8494 lengths
= (unsigned long *) calloc (ngnubuckets
, sizeof (*lengths
));
8495 if (lengths
== NULL
)
8497 error (_("Out of memory\n"));
8501 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
8502 (unsigned long) ngnubuckets
);
8503 printf (_(" Length Number %% of total Coverage\n"));
8505 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
8506 if (gnubuckets
[hn
] != 0)
8508 bfd_vma off
, length
= 1;
8510 for (off
= gnubuckets
[hn
] - gnusymidx
;
8511 (gnuchains
[off
] & 1) == 0; ++off
)
8513 lengths
[hn
] = length
;
8514 if (length
> maxlength
)
8519 counts
= (unsigned long *) calloc (maxlength
+ 1, sizeof (*counts
));
8522 error (_("Out of memory\n"));
8526 for (hn
= 0; hn
< ngnubuckets
; ++hn
)
8527 ++counts
[lengths
[hn
]];
8529 if (ngnubuckets
> 0)
8532 printf (" 0 %-10lu (%5.1f%%)\n",
8533 counts
[0], (counts
[0] * 100.0) / ngnubuckets
);
8534 for (j
= 1; j
<= maxlength
; ++j
)
8536 nzero_counts
+= counts
[j
] * j
;
8537 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
8538 j
, counts
[j
], (counts
[j
] * 100.0) / ngnubuckets
,
8539 (nzero_counts
* 100.0) / nsyms
);
8553 process_syminfo (FILE * file ATTRIBUTE_UNUSED
)
8557 if (dynamic_syminfo
== NULL
8559 /* No syminfo, this is ok. */
8562 /* There better should be a dynamic symbol section. */
8563 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
8567 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
8568 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
8570 printf (_(" Num: Name BoundTo Flags\n"));
8571 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
8573 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
8575 printf ("%4d: ", i
);
8576 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
8577 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
8579 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
8582 switch (dynamic_syminfo
[i
].si_boundto
)
8584 case SYMINFO_BT_SELF
:
8585 fputs ("SELF ", stdout
);
8587 case SYMINFO_BT_PARENT
:
8588 fputs ("PARENT ", stdout
);
8591 if (dynamic_syminfo
[i
].si_boundto
> 0
8592 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
8593 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
8595 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
8599 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
8603 if (flags
& SYMINFO_FLG_DIRECT
)
8605 if (flags
& SYMINFO_FLG_PASSTHRU
)
8606 printf (" PASSTHRU");
8607 if (flags
& SYMINFO_FLG_COPY
)
8609 if (flags
& SYMINFO_FLG_LAZYLOAD
)
8610 printf (" LAZYLOAD");
8618 /* Check to see if the given reloc needs to be handled in a target specific
8619 manner. If so then process the reloc and return TRUE otherwise return
8623 target_specific_reloc_handling (Elf_Internal_Rela
* reloc
,
8624 unsigned char * start
,
8625 Elf_Internal_Sym
* symtab
)
8627 unsigned int reloc_type
= get_reloc_type (reloc
->r_info
);
8629 switch (elf_header
.e_machine
)
8632 case EM_CYGNUS_MN10300
:
8634 static Elf_Internal_Sym
* saved_sym
= NULL
;
8638 case 34: /* R_MN10300_ALIGN */
8640 case 33: /* R_MN10300_SYM_DIFF */
8641 saved_sym
= symtab
+ get_reloc_symindex (reloc
->r_info
);
8643 case 1: /* R_MN10300_32 */
8644 case 2: /* R_MN10300_16 */
8645 if (saved_sym
!= NULL
)
8649 value
= reloc
->r_addend
8650 + (symtab
[get_reloc_symindex (reloc
->r_info
)].st_value
8651 - saved_sym
->st_value
);
8653 byte_put (start
+ reloc
->r_offset
, value
, reloc_type
== 1 ? 4 : 2);
8660 if (saved_sym
!= NULL
)
8661 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc"));
8671 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
8672 DWARF debug sections. This is a target specific test. Note - we do not
8673 go through the whole including-target-headers-multiple-times route, (as
8674 we have already done with <elf/h8.h>) because this would become very
8675 messy and even then this function would have to contain target specific
8676 information (the names of the relocs instead of their numeric values).
8677 FIXME: This is not the correct way to solve this problem. The proper way
8678 is to have target specific reloc sizing and typing functions created by
8679 the reloc-macros.h header, in the same way that it already creates the
8680 reloc naming functions. */
8683 is_32bit_abs_reloc (unsigned int reloc_type
)
8685 switch (elf_header
.e_machine
)
8689 return reloc_type
== 1; /* R_386_32. */
8691 return reloc_type
== 1; /* R_68K_32. */
8693 return reloc_type
== 1; /* R_860_32. */
8695 return reloc_type
== 1; /* XXX Is this right ? */
8697 return reloc_type
== 1; /* R_ARC_32. */
8699 return reloc_type
== 2; /* R_ARM_ABS32 */
8702 return reloc_type
== 1;
8704 return reloc_type
== 0x12; /* R_byte4_data. */
8706 return reloc_type
== 3; /* R_CRIS_32. */
8709 return reloc_type
== 3; /* R_CR16_NUM32. */
8711 return reloc_type
== 15; /* R_CRX_NUM32. */
8713 return reloc_type
== 1;
8714 case EM_CYGNUS_D10V
:
8716 return reloc_type
== 6; /* R_D10V_32. */
8717 case EM_CYGNUS_D30V
:
8719 return reloc_type
== 12; /* R_D30V_32_NORMAL. */
8721 return reloc_type
== 3; /* R_DLX_RELOC_32. */
8722 case EM_CYGNUS_FR30
:
8724 return reloc_type
== 3; /* R_FR30_32. */
8728 return reloc_type
== 1; /* R_H8_DIR32. */
8730 return reloc_type
== 0x65; /* R_IA64_SECREL32LSB. */
8733 return reloc_type
== 2; /* R_IP2K_32. */
8735 return reloc_type
== 2; /* R_IQ2000_32. */
8736 case EM_LATTICEMICO32
:
8737 return reloc_type
== 3; /* R_LM32_32. */
8740 return reloc_type
== 3; /* R_M32C_32. */
8742 return reloc_type
== 34; /* R_M32R_32_RELA. */
8744 return reloc_type
== 1; /* R_MCORE_ADDR32. */
8746 return reloc_type
== 4; /* R_MEP_32. */
8748 return reloc_type
== 2; /* R_MIPS_32. */
8750 return reloc_type
== 4; /* R_MMIX_32. */
8751 case EM_CYGNUS_MN10200
:
8753 return reloc_type
== 1; /* R_MN10200_32. */
8754 case EM_CYGNUS_MN10300
:
8756 return reloc_type
== 1; /* R_MN10300_32. */
8759 return reloc_type
== 1; /* R_MSP43_32. */
8761 return reloc_type
== 2; /* R_MT_32. */
8762 case EM_ALTERA_NIOS2
:
8764 return reloc_type
== 1; /* R_NIOS_32. */
8767 return reloc_type
== 1; /* R_OR32_32. */
8769 return (reloc_type
== 1 /* R_PARISC_DIR32. */
8770 || reloc_type
== 41); /* R_PARISC_SECREL32. */
8773 return reloc_type
== 1; /* R_PJ_DATA_DIR32. */
8775 return reloc_type
== 1; /* R_PPC64_ADDR32. */
8777 return reloc_type
== 1; /* R_PPC_ADDR32. */
8779 return reloc_type
== 1; /* R_RX_DIR32. */
8781 return reloc_type
== 1; /* R_I370_ADDR31. */
8784 return reloc_type
== 4; /* R_S390_32. */
8786 return reloc_type
== 8; /* R_SCORE_ABS32. */
8788 return reloc_type
== 1; /* R_SH_DIR32. */
8789 case EM_SPARC32PLUS
:
8792 return reloc_type
== 3 /* R_SPARC_32. */
8793 || reloc_type
== 23; /* R_SPARC_UA32. */
8795 return reloc_type
== 6; /* R_SPU_ADDR32 */
8796 case EM_CYGNUS_V850
:
8798 return reloc_type
== 6; /* R_V850_ABS32. */
8800 return reloc_type
== 1; /* R_VAX_32. */
8803 return reloc_type
== 10; /* R_X86_64_32. */
8806 return reloc_type
== 3; /* R_XC16C_ABS_32. */
8808 return reloc_type
== 1; /* R_XSTROMY16_32. */
8811 return reloc_type
== 1; /* R_XTENSA_32. */
8813 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
8814 elf_header
.e_machine
);
8819 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8820 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
8823 is_32bit_pcrel_reloc (unsigned int reloc_type
)
8825 switch (elf_header
.e_machine
)
8829 return reloc_type
== 2; /* R_386_PC32. */
8831 return reloc_type
== 4; /* R_68K_PC32. */
8833 return reloc_type
== 10; /* R_ALPHA_SREL32. */
8835 return reloc_type
== 3; /* R_ARM_REL32 */
8837 return reloc_type
== 9; /* R_PARISC_PCREL32. */
8839 return reloc_type
== 26; /* R_PPC_REL32. */
8841 return reloc_type
== 26; /* R_PPC64_REL32. */
8844 return reloc_type
== 5; /* R_390_PC32. */
8846 return reloc_type
== 2; /* R_SH_REL32. */
8847 case EM_SPARC32PLUS
:
8850 return reloc_type
== 6; /* R_SPARC_DISP32. */
8852 return reloc_type
== 13; /* R_SPU_REL32. */
8855 return reloc_type
== 2; /* R_X86_64_PC32. */
8858 return reloc_type
== 14; /* R_XTENSA_32_PCREL. */
8860 /* Do not abort or issue an error message here. Not all targets use
8861 pc-relative 32-bit relocs in their DWARF debug information and we
8862 have already tested for target coverage in is_32bit_abs_reloc. A
8863 more helpful warning message will be generated by apply_relocations
8864 anyway, so just return. */
8869 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8870 a 64-bit absolute RELA relocation used in DWARF debug sections. */
8873 is_64bit_abs_reloc (unsigned int reloc_type
)
8875 switch (elf_header
.e_machine
)
8878 return reloc_type
== 2; /* R_ALPHA_REFQUAD. */
8880 return reloc_type
== 0x27; /* R_IA64_DIR64LSB. */
8882 return reloc_type
== 80; /* R_PARISC_DIR64. */
8884 return reloc_type
== 38; /* R_PPC64_ADDR64. */
8885 case EM_SPARC32PLUS
:
8888 return reloc_type
== 54; /* R_SPARC_UA64. */
8891 return reloc_type
== 1; /* R_X86_64_64. */
8894 return reloc_type
== 22; /* R_S390_64 */
8896 return reloc_type
== 18; /* R_MIPS_64 */
8902 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
8903 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
8906 is_64bit_pcrel_reloc (unsigned int reloc_type
)
8908 switch (elf_header
.e_machine
)
8911 return reloc_type
== 11; /* R_ALPHA_SREL64 */
8913 return reloc_type
== 0x4f; /* R_IA64_PCREL64LSB */
8915 return reloc_type
== 72; /* R_PARISC_PCREL64 */
8917 return reloc_type
== 44; /* R_PPC64_REL64 */
8918 case EM_SPARC32PLUS
:
8921 return reloc_type
== 46; /* R_SPARC_DISP64 */
8924 return reloc_type
== 24; /* R_X86_64_PC64 */
8927 return reloc_type
== 23; /* R_S390_PC64 */
8933 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8934 a 24-bit absolute RELA relocation used in DWARF debug sections. */
8937 is_24bit_abs_reloc (unsigned int reloc_type
)
8939 switch (elf_header
.e_machine
)
8941 case EM_CYGNUS_MN10200
:
8943 return reloc_type
== 4; /* R_MN10200_24. */
8949 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
8950 a 16-bit absolute RELA relocation used in DWARF debug sections. */
8953 is_16bit_abs_reloc (unsigned int reloc_type
)
8955 switch (elf_header
.e_machine
)
8959 return reloc_type
== 4; /* R_AVR_16. */
8960 case EM_CYGNUS_D10V
:
8962 return reloc_type
== 3; /* R_D10V_16. */
8966 return reloc_type
== R_H8_DIR16
;
8969 return reloc_type
== 1; /* R_IP2K_16. */
8972 return reloc_type
== 1; /* R_M32C_16 */
8975 return reloc_type
== 5; /* R_MSP430_16_BYTE. */
8976 case EM_ALTERA_NIOS2
:
8978 return reloc_type
== 9; /* R_NIOS_16. */
8981 return reloc_type
== 2; /* R_XC16C_ABS_16. */
8987 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
8988 relocation entries (possibly formerly used for SHT_GROUP sections). */
8991 is_none_reloc (unsigned int reloc_type
)
8993 switch (elf_header
.e_machine
)
8995 case EM_68K
: /* R_68K_NONE. */
8996 case EM_386
: /* R_386_NONE. */
8997 case EM_SPARC32PLUS
:
8999 case EM_SPARC
: /* R_SPARC_NONE. */
9000 case EM_MIPS
: /* R_MIPS_NONE. */
9001 case EM_PARISC
: /* R_PARISC_NONE. */
9002 case EM_ALPHA
: /* R_ALPHA_NONE. */
9003 case EM_PPC
: /* R_PPC_NONE. */
9004 case EM_PPC64
: /* R_PPC64_NONE. */
9005 case EM_ARM
: /* R_ARM_NONE. */
9006 case EM_IA_64
: /* R_IA64_NONE. */
9007 case EM_SH
: /* R_SH_NONE. */
9009 case EM_S390
: /* R_390_NONE. */
9010 case EM_CRIS
: /* R_CRIS_NONE. */
9011 case EM_X86_64
: /* R_X86_64_NONE. */
9012 case EM_L1OM
: /* R_X86_64_NONE. */
9013 case EM_MN10300
: /* R_MN10300_NONE. */
9014 case EM_M32R
: /* R_M32R_NONE. */
9016 case EM_C166
: /* R_XC16X_NONE. */
9017 return reloc_type
== 0;
9020 return (reloc_type
== 0 /* R_XTENSA_NONE. */
9021 || reloc_type
== 17 /* R_XTENSA_DIFF8. */
9022 || reloc_type
== 18 /* R_XTENSA_DIFF16. */
9023 || reloc_type
== 19 /* R_XTENSA_DIFF32. */);
9028 /* Apply relocations to a section.
9029 Note: So far support has been added only for those relocations
9030 which can be found in debug sections.
9031 FIXME: Add support for more relocations ? */
9034 apply_relocations (void * file
,
9035 Elf_Internal_Shdr
* section
,
9036 unsigned char * start
)
9038 Elf_Internal_Shdr
* relsec
;
9039 unsigned char * end
= start
+ section
->sh_size
;
9041 if (elf_header
.e_type
!= ET_REL
)
9044 /* Find the reloc section associated with the section. */
9045 for (relsec
= section_headers
;
9046 relsec
< section_headers
+ elf_header
.e_shnum
;
9049 bfd_boolean is_rela
;
9050 unsigned long num_relocs
;
9051 Elf_Internal_Rela
* relocs
;
9052 Elf_Internal_Rela
* rp
;
9053 Elf_Internal_Shdr
* symsec
;
9054 Elf_Internal_Sym
* symtab
;
9055 Elf_Internal_Sym
* sym
;
9057 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
9058 || relsec
->sh_info
>= elf_header
.e_shnum
9059 || section_headers
+ relsec
->sh_info
!= section
9060 || relsec
->sh_size
== 0
9061 || relsec
->sh_link
>= elf_header
.e_shnum
)
9064 is_rela
= relsec
->sh_type
== SHT_RELA
;
9068 if (!slurp_rela_relocs ((FILE *) file
, relsec
->sh_offset
,
9069 relsec
->sh_size
, & relocs
, & num_relocs
))
9074 if (!slurp_rel_relocs ((FILE *) file
, relsec
->sh_offset
,
9075 relsec
->sh_size
, & relocs
, & num_relocs
))
9079 /* SH uses RELA but uses in place value instead of the addend field. */
9080 if (elf_header
.e_machine
== EM_SH
)
9083 symsec
= section_headers
+ relsec
->sh_link
;
9084 symtab
= GET_ELF_SYMBOLS ((FILE *) file
, symsec
);
9086 for (rp
= relocs
; rp
< relocs
+ num_relocs
; ++rp
)
9089 unsigned int reloc_type
;
9090 unsigned int reloc_size
;
9091 unsigned char * rloc
;
9093 reloc_type
= get_reloc_type (rp
->r_info
);
9095 if (target_specific_reloc_handling (rp
, start
, symtab
))
9097 else if (is_none_reloc (reloc_type
))
9099 else if (is_32bit_abs_reloc (reloc_type
)
9100 || is_32bit_pcrel_reloc (reloc_type
))
9102 else if (is_64bit_abs_reloc (reloc_type
)
9103 || is_64bit_pcrel_reloc (reloc_type
))
9105 else if (is_24bit_abs_reloc (reloc_type
))
9107 else if (is_16bit_abs_reloc (reloc_type
))
9111 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
9112 reloc_type
, SECTION_NAME (section
));
9116 rloc
= start
+ rp
->r_offset
;
9117 if ((rloc
+ reloc_size
) > end
)
9119 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
9120 (unsigned long) rp
->r_offset
,
9121 SECTION_NAME (section
));
9125 sym
= symtab
+ get_reloc_symindex (rp
->r_info
);
9127 /* If the reloc has a symbol associated with it,
9128 make sure that it is of an appropriate type.
9130 Relocations against symbols without type can happen.
9131 Gcc -feliminate-dwarf2-dups may generate symbols
9132 without type for debug info.
9134 Icc generates relocations against function symbols
9135 instead of local labels.
9137 Relocations against object symbols can happen, eg when
9138 referencing a global array. For an example of this see
9139 the _clz.o binary in libgcc.a. */
9141 && ELF_ST_TYPE (sym
->st_info
) > STT_SECTION
)
9143 warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
9144 get_symbol_type (ELF_ST_TYPE (sym
->st_info
)),
9145 (long int)(rp
- relocs
),
9146 SECTION_NAME (relsec
));
9152 addend
+= rp
->r_addend
;
9153 /* R_XTENSA_32 and R_PJ_DATA_DIR32 are partial_inplace. */
9155 || (elf_header
.e_machine
== EM_XTENSA
9157 || ((elf_header
.e_machine
== EM_PJ
9158 || elf_header
.e_machine
== EM_PJ_OLD
)
9159 && reloc_type
== 1))
9160 addend
+= byte_get (rloc
, reloc_size
);
9162 if (is_32bit_pcrel_reloc (reloc_type
)
9163 || is_64bit_pcrel_reloc (reloc_type
))
9165 /* On HPPA, all pc-relative relocations are biased by 8. */
9166 if (elf_header
.e_machine
== EM_PARISC
)
9168 byte_put (rloc
, (addend
+ sym
->st_value
) - rp
->r_offset
,
9172 byte_put (rloc
, addend
+ sym
->st_value
, reloc_size
);
9181 #ifdef SUPPORT_DISASSEMBLY
9183 disassemble_section (Elf_Internal_Shdr
* section
, FILE * file
)
9185 printf (_("\nAssembly dump of section %s\n"),
9186 SECTION_NAME (section
));
9188 /* XXX -- to be done --- XXX */
9194 /* Reads in the contents of SECTION from FILE, returning a pointer
9195 to a malloc'ed buffer or NULL if something went wrong. */
9198 get_section_contents (Elf_Internal_Shdr
* section
, FILE * file
)
9200 bfd_size_type num_bytes
;
9202 num_bytes
= section
->sh_size
;
9204 if (num_bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
9206 printf (_("\nSection '%s' has no data to dump.\n"),
9207 SECTION_NAME (section
));
9211 return (char *) get_data (NULL
, file
, section
->sh_offset
, 1, num_bytes
,
9212 _("section contents"));
9217 dump_section_as_strings (Elf_Internal_Shdr
* section
, FILE * file
)
9219 Elf_Internal_Shdr
* relsec
;
9220 bfd_size_type num_bytes
;
9225 char * name
= SECTION_NAME (section
);
9226 bfd_boolean some_strings_shown
;
9228 start
= get_section_contents (section
, file
);
9232 printf (_("\nString dump of section '%s':\n"), name
);
9234 /* If the section being dumped has relocations against it the user might
9235 be expecting these relocations to have been applied. Check for this
9236 case and issue a warning message in order to avoid confusion.
9237 FIXME: Maybe we ought to have an option that dumps a section with
9239 for (relsec
= section_headers
;
9240 relsec
< section_headers
+ elf_header
.e_shnum
;
9243 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
9244 || relsec
->sh_info
>= elf_header
.e_shnum
9245 || section_headers
+ relsec
->sh_info
!= section
9246 || relsec
->sh_size
== 0
9247 || relsec
->sh_link
>= elf_header
.e_shnum
)
9250 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
9254 num_bytes
= section
->sh_size
;
9255 addr
= section
->sh_addr
;
9257 end
= start
+ num_bytes
;
9258 some_strings_shown
= FALSE
;
9262 while (!ISPRINT (* data
))
9269 /* PR 11128: Use two separate invocations in order to work
9270 around bugs in the Solaris 8 implementation of printf. */
9271 printf (" [%6tx] ", data
- start
);
9272 printf ("%s\n", data
);
9274 printf (" [%6Ix] %s\n", (size_t) (data
- start
), data
);
9276 data
+= strlen (data
);
9277 some_strings_shown
= TRUE
;
9281 if (! some_strings_shown
)
9282 printf (_(" No strings found in this section."));
9290 dump_section_as_bytes (Elf_Internal_Shdr
* section
,
9292 bfd_boolean relocate
)
9294 Elf_Internal_Shdr
* relsec
;
9295 bfd_size_type bytes
;
9297 unsigned char * data
;
9298 unsigned char * start
;
9300 start
= (unsigned char *) get_section_contents (section
, file
);
9304 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
9308 apply_relocations (file
, section
, start
);
9312 /* If the section being dumped has relocations against it the user might
9313 be expecting these relocations to have been applied. Check for this
9314 case and issue a warning message in order to avoid confusion.
9315 FIXME: Maybe we ought to have an option that dumps a section with
9317 for (relsec
= section_headers
;
9318 relsec
< section_headers
+ elf_header
.e_shnum
;
9321 if ((relsec
->sh_type
!= SHT_RELA
&& relsec
->sh_type
!= SHT_REL
)
9322 || relsec
->sh_info
>= elf_header
.e_shnum
9323 || section_headers
+ relsec
->sh_info
!= section
9324 || relsec
->sh_size
== 0
9325 || relsec
->sh_link
>= elf_header
.e_shnum
)
9328 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
9333 addr
= section
->sh_addr
;
9334 bytes
= section
->sh_size
;
9343 lbytes
= (bytes
> 16 ? 16 : bytes
);
9345 printf (" 0x%8.8lx ", (unsigned long) addr
);
9347 for (j
= 0; j
< 16; j
++)
9350 printf ("%2.2x", data
[j
]);
9358 for (j
= 0; j
< lbytes
; j
++)
9361 if (k
>= ' ' && k
< 0x7f)
9379 /* Uncompresses a section that was compressed using zlib, in place.
9380 This is a copy of bfd_uncompress_section_contents, in bfd/compress.c */
9383 uncompress_section_contents (unsigned char ** buffer
, dwarf_size_type
* size
)
9386 /* These are just to quiet gcc. */
9391 dwarf_size_type compressed_size
= *size
;
9392 unsigned char * compressed_buffer
= *buffer
;
9393 dwarf_size_type uncompressed_size
;
9394 unsigned char * uncompressed_buffer
;
9397 dwarf_size_type header_size
= 12;
9399 /* Read the zlib header. In this case, it should be "ZLIB" followed
9400 by the uncompressed section size, 8 bytes in big-endian order. */
9401 if (compressed_size
< header_size
9402 || ! streq ((char *) compressed_buffer
, "ZLIB"))
9405 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
9406 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
9407 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
9408 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
9409 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
9410 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
9411 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
9412 uncompressed_size
+= compressed_buffer
[11];
9414 /* It is possible the section consists of several compressed
9415 buffers concatenated together, so we uncompress in a loop. */
9419 strm
.avail_in
= compressed_size
- header_size
;
9420 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
9421 strm
.avail_out
= uncompressed_size
;
9422 uncompressed_buffer
= (unsigned char *) xmalloc (uncompressed_size
);
9424 rc
= inflateInit (& strm
);
9425 while (strm
.avail_in
> 0)
9429 strm
.next_out
= ((Bytef
*) uncompressed_buffer
9430 + (uncompressed_size
- strm
.avail_out
));
9431 rc
= inflate (&strm
, Z_FINISH
);
9432 if (rc
!= Z_STREAM_END
)
9434 rc
= inflateReset (& strm
);
9436 rc
= inflateEnd (& strm
);
9438 || strm
.avail_out
!= 0)
9441 free (compressed_buffer
);
9442 *buffer
= uncompressed_buffer
;
9443 *size
= uncompressed_size
;
9447 free (uncompressed_buffer
);
9449 #endif /* HAVE_ZLIB_H */
9453 load_specific_debug_section (enum dwarf_section_display_enum debug
,
9454 Elf_Internal_Shdr
* sec
, void * file
)
9456 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
9458 int section_is_compressed
;
9460 /* If it is already loaded, do nothing. */
9461 if (section
->start
!= NULL
)
9464 section_is_compressed
= section
->name
== section
->compressed_name
;
9466 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
9467 section
->address
= sec
->sh_addr
;
9468 section
->size
= sec
->sh_size
;
9469 section
->start
= (unsigned char *) get_data (NULL
, (FILE *) file
,
9472 if (section
->start
== NULL
)
9475 if (section_is_compressed
)
9476 if (! uncompress_section_contents (§ion
->start
, §ion
->size
))
9479 if (debug_displays
[debug
].relocate
)
9480 apply_relocations ((FILE *) file
, sec
, section
->start
);
9486 load_debug_section (enum dwarf_section_display_enum debug
, void * file
)
9488 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
9489 Elf_Internal_Shdr
* sec
;
9491 /* Locate the debug section. */
9492 sec
= find_section (section
->uncompressed_name
);
9494 section
->name
= section
->uncompressed_name
;
9497 sec
= find_section (section
->compressed_name
);
9499 section
->name
= section
->compressed_name
;
9504 return load_specific_debug_section (debug
, sec
, (FILE *) file
);
9508 free_debug_section (enum dwarf_section_display_enum debug
)
9510 struct dwarf_section
* section
= &debug_displays
[debug
].section
;
9512 if (section
->start
== NULL
)
9515 free ((char *) section
->start
);
9516 section
->start
= NULL
;
9517 section
->address
= 0;
9522 display_debug_section (Elf_Internal_Shdr
* section
, FILE * file
)
9524 char * name
= SECTION_NAME (section
);
9525 bfd_size_type length
;
9529 length
= section
->sh_size
;
9532 printf (_("\nSection '%s' has no debugging data.\n"), name
);
9535 if (section
->sh_type
== SHT_NOBITS
)
9537 /* There is no point in dumping the contents of a debugging section
9538 which has the NOBITS type - the bits in the file will be random.
9539 This can happen when a file containing a .eh_frame section is
9540 stripped with the --only-keep-debug command line option. */
9541 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), name
);
9545 if (const_strneq (name
, ".gnu.linkonce.wi."))
9546 name
= ".debug_info";
9548 /* See if we know how to display the contents of this section. */
9549 for (i
= 0; i
< max
; i
++)
9550 if (streq (debug_displays
[i
].section
.uncompressed_name
, name
)
9551 || streq (debug_displays
[i
].section
.compressed_name
, name
))
9553 struct dwarf_section
* sec
= &debug_displays
[i
].section
;
9554 int secondary
= (section
!= find_section (name
));
9557 free_debug_section ((enum dwarf_section_display_enum
) i
);
9559 if (streq (sec
->uncompressed_name
, name
))
9560 sec
->name
= sec
->uncompressed_name
;
9562 sec
->name
= sec
->compressed_name
;
9563 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
9566 result
&= debug_displays
[i
].display (sec
, file
);
9568 if (secondary
|| (i
!= info
&& i
!= abbrev
))
9569 free_debug_section ((enum dwarf_section_display_enum
) i
);
9577 printf (_("Unrecognized debug section: %s\n"), name
);
9584 /* Set DUMP_SECTS for all sections where dumps were requested
9585 based on section name. */
9588 initialise_dumps_byname (void)
9590 struct dump_list_entry
* cur
;
9592 for (cur
= dump_sects_byname
; cur
; cur
= cur
->next
)
9597 for (i
= 0, any
= 0; i
< elf_header
.e_shnum
; i
++)
9598 if (streq (SECTION_NAME (section_headers
+ i
), cur
->name
))
9600 request_dump_bynumber (i
, cur
->type
);
9605 warn (_("Section '%s' was not dumped because it does not exist!\n"),
9611 process_section_contents (FILE * file
)
9613 Elf_Internal_Shdr
* section
;
9619 initialise_dumps_byname ();
9621 for (i
= 0, section
= section_headers
;
9622 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9625 #ifdef SUPPORT_DISASSEMBLY
9626 if (dump_sects
[i
] & DISASS_DUMP
)
9627 disassemble_section (section
, file
);
9629 if (dump_sects
[i
] & HEX_DUMP
)
9630 dump_section_as_bytes (section
, file
, FALSE
);
9632 if (dump_sects
[i
] & RELOC_DUMP
)
9633 dump_section_as_bytes (section
, file
, TRUE
);
9635 if (dump_sects
[i
] & STRING_DUMP
)
9636 dump_section_as_strings (section
, file
);
9638 if (dump_sects
[i
] & DEBUG_DUMP
)
9639 display_debug_section (section
, file
);
9642 /* Check to see if the user requested a
9643 dump of a section that does not exist. */
9644 while (i
++ < num_dump_sects
)
9646 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
9650 process_mips_fpe_exception (int mask
)
9655 if (mask
& OEX_FPU_INEX
)
9656 fputs ("INEX", stdout
), first
= 0;
9657 if (mask
& OEX_FPU_UFLO
)
9658 printf ("%sUFLO", first
? "" : "|"), first
= 0;
9659 if (mask
& OEX_FPU_OFLO
)
9660 printf ("%sOFLO", first
? "" : "|"), first
= 0;
9661 if (mask
& OEX_FPU_DIV0
)
9662 printf ("%sDIV0", first
? "" : "|"), first
= 0;
9663 if (mask
& OEX_FPU_INVAL
)
9664 printf ("%sINVAL", first
? "" : "|");
9667 fputs ("0", stdout
);
9670 /* ARM EABI attributes section. */
9675 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
9677 const char ** table
;
9678 } arm_attr_public_tag
;
9680 static const char * arm_attr_tag_CPU_arch
[] =
9681 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
9682 "v6K", "v7", "v6-M", "v6S-M", "v7E-M"};
9683 static const char * arm_attr_tag_ARM_ISA_use
[] = {"No", "Yes"};
9684 static const char * arm_attr_tag_THUMB_ISA_use
[] =
9685 {"No", "Thumb-1", "Thumb-2"};
9686 static const char * arm_attr_tag_VFP_arch
[] =
9687 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16"};
9688 static const char * arm_attr_tag_WMMX_arch
[] = {"No", "WMMXv1", "WMMXv2"};
9689 static const char * arm_attr_tag_Advanced_SIMD_arch
[] =
9690 {"No", "NEONv1", "NEONv1 with Fused-MAC"};
9691 static const char * arm_attr_tag_PCS_config
[] =
9692 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
9693 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
9694 static const char * arm_attr_tag_ABI_PCS_R9_use
[] =
9695 {"V6", "SB", "TLS", "Unused"};
9696 static const char * arm_attr_tag_ABI_PCS_RW_data
[] =
9697 {"Absolute", "PC-relative", "SB-relative", "None"};
9698 static const char * arm_attr_tag_ABI_PCS_RO_data
[] =
9699 {"Absolute", "PC-relative", "None"};
9700 static const char * arm_attr_tag_ABI_PCS_GOT_use
[] =
9701 {"None", "direct", "GOT-indirect"};
9702 static const char * arm_attr_tag_ABI_PCS_wchar_t
[] =
9703 {"None", "??? 1", "2", "??? 3", "4"};
9704 static const char * arm_attr_tag_ABI_FP_rounding
[] = {"Unused", "Needed"};
9705 static const char * arm_attr_tag_ABI_FP_denormal
[] =
9706 {"Unused", "Needed", "Sign only"};
9707 static const char * arm_attr_tag_ABI_FP_exceptions
[] = {"Unused", "Needed"};
9708 static const char * arm_attr_tag_ABI_FP_user_exceptions
[] = {"Unused", "Needed"};
9709 static const char * arm_attr_tag_ABI_FP_number_model
[] =
9710 {"Unused", "Finite", "RTABI", "IEEE 754"};
9711 static const char * arm_attr_tag_ABI_align8_needed
[] = {"No", "Yes", "4-byte"};
9712 static const char * arm_attr_tag_ABI_align8_preserved
[] =
9713 {"No", "Yes, except leaf SP", "Yes"};
9714 static const char * arm_attr_tag_ABI_enum_size
[] =
9715 {"Unused", "small", "int", "forced to int"};
9716 static const char * arm_attr_tag_ABI_HardFP_use
[] =
9717 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
9718 static const char * arm_attr_tag_ABI_VFP_args
[] =
9719 {"AAPCS", "VFP registers", "custom"};
9720 static const char * arm_attr_tag_ABI_WMMX_args
[] =
9721 {"AAPCS", "WMMX registers", "custom"};
9722 static const char * arm_attr_tag_ABI_optimization_goals
[] =
9723 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
9724 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
9725 static const char * arm_attr_tag_ABI_FP_optimization_goals
[] =
9726 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
9727 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
9728 static const char * arm_attr_tag_CPU_unaligned_access
[] = {"None", "v6"};
9729 static const char * arm_attr_tag_VFP_HP_extension
[] =
9730 {"Not Allowed", "Allowed"};
9731 static const char * arm_attr_tag_ABI_FP_16bit_format
[] =
9732 {"None", "IEEE 754", "Alternative Format"};
9733 static const char * arm_attr_tag_MPextension_use
[] =
9734 {"Not Allowed", "Allowed"};
9735 static const char * arm_attr_tag_DIV_use
[] =
9736 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
9737 "Allowed in v7-A with integer division extension"};
9738 static const char * arm_attr_tag_T2EE_use
[] = {"Not Allowed", "Allowed"};
9739 static const char * arm_attr_tag_Virtualization_use
[] =
9740 {"Not Allowed", "TrustZone", "Virtualization Extensions",
9741 "TrustZone and Virtualization Extensions"};
9742 static const char * arm_attr_tag_MPextension_use_legacy
[] =
9743 {"Not Allowed", "Allowed"};
9745 #define LOOKUP(id, name) \
9746 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
9747 static arm_attr_public_tag arm_attr_public_tags
[] =
9749 {4, "CPU_raw_name", 1, NULL
},
9750 {5, "CPU_name", 1, NULL
},
9751 LOOKUP(6, CPU_arch
),
9752 {7, "CPU_arch_profile", 0, NULL
},
9753 LOOKUP(8, ARM_ISA_use
),
9754 LOOKUP(9, THUMB_ISA_use
),
9755 LOOKUP(10, VFP_arch
),
9756 LOOKUP(11, WMMX_arch
),
9757 LOOKUP(12, Advanced_SIMD_arch
),
9758 LOOKUP(13, PCS_config
),
9759 LOOKUP(14, ABI_PCS_R9_use
),
9760 LOOKUP(15, ABI_PCS_RW_data
),
9761 LOOKUP(16, ABI_PCS_RO_data
),
9762 LOOKUP(17, ABI_PCS_GOT_use
),
9763 LOOKUP(18, ABI_PCS_wchar_t
),
9764 LOOKUP(19, ABI_FP_rounding
),
9765 LOOKUP(20, ABI_FP_denormal
),
9766 LOOKUP(21, ABI_FP_exceptions
),
9767 LOOKUP(22, ABI_FP_user_exceptions
),
9768 LOOKUP(23, ABI_FP_number_model
),
9769 LOOKUP(24, ABI_align8_needed
),
9770 LOOKUP(25, ABI_align8_preserved
),
9771 LOOKUP(26, ABI_enum_size
),
9772 LOOKUP(27, ABI_HardFP_use
),
9773 LOOKUP(28, ABI_VFP_args
),
9774 LOOKUP(29, ABI_WMMX_args
),
9775 LOOKUP(30, ABI_optimization_goals
),
9776 LOOKUP(31, ABI_FP_optimization_goals
),
9777 {32, "compatibility", 0, NULL
},
9778 LOOKUP(34, CPU_unaligned_access
),
9779 LOOKUP(36, VFP_HP_extension
),
9780 LOOKUP(38, ABI_FP_16bit_format
),
9781 LOOKUP(42, MPextension_use
),
9782 LOOKUP(44, DIV_use
),
9783 {64, "nodefaults", 0, NULL
},
9784 {65, "also_compatible_with", 0, NULL
},
9785 LOOKUP(66, T2EE_use
),
9786 {67, "conformance", 1, NULL
},
9787 LOOKUP(68, Virtualization_use
),
9788 LOOKUP(70, MPextension_use_legacy
)
9792 static unsigned char *
9793 display_arm_attribute (unsigned char * p
)
9798 arm_attr_public_tag
* attr
;
9802 tag
= read_uleb128 (p
, &len
);
9805 for (i
= 0; i
< ARRAY_SIZE (arm_attr_public_tags
); i
++)
9807 if (arm_attr_public_tags
[i
].tag
== tag
)
9809 attr
= &arm_attr_public_tags
[i
];
9816 printf (" Tag_%s: ", attr
->name
);
9822 case 7: /* Tag_CPU_arch_profile. */
9823 val
= read_uleb128 (p
, &len
);
9827 case 0: printf ("None\n"); break;
9828 case 'A': printf ("Application\n"); break;
9829 case 'R': printf ("Realtime\n"); break;
9830 case 'M': printf ("Microcontroller\n"); break;
9831 default: printf ("??? (%d)\n", val
); break;
9835 case 32: /* Tag_compatibility. */
9836 val
= read_uleb128 (p
, &len
);
9838 printf ("flag = %d, vendor = %s\n", val
, p
);
9839 p
+= strlen ((char *) p
) + 1;
9842 case 64: /* Tag_nodefaults. */
9847 case 65: /* Tag_also_compatible_with. */
9848 val
= read_uleb128 (p
, &len
);
9850 if (val
== 6 /* Tag_CPU_arch. */)
9852 val
= read_uleb128 (p
, &len
);
9854 if ((unsigned int)val
>= ARRAY_SIZE (arm_attr_tag_CPU_arch
))
9855 printf ("??? (%d)\n", val
);
9857 printf ("%s\n", arm_attr_tag_CPU_arch
[val
]);
9861 while (*(p
++) != '\0' /* NUL terminator. */);
9875 assert (attr
->type
& 0x80);
9876 val
= read_uleb128 (p
, &len
);
9878 type
= attr
->type
& 0x7f;
9880 printf ("??? (%d)\n", val
);
9882 printf ("%s\n", attr
->table
[val
]);
9889 type
= 1; /* String. */
9891 type
= 2; /* uleb128. */
9892 printf (" Tag_unknown_%d: ", tag
);
9897 printf ("\"%s\"\n", p
);
9898 p
+= strlen ((char *) p
) + 1;
9902 val
= read_uleb128 (p
, &len
);
9904 printf ("%d (0x%x)\n", val
, val
);
9910 static unsigned char *
9911 display_gnu_attribute (unsigned char * p
,
9912 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
9919 tag
= read_uleb128 (p
, &len
);
9922 /* Tag_compatibility is the only generic GNU attribute defined at
9926 val
= read_uleb128 (p
, &len
);
9928 printf ("flag = %d, vendor = %s\n", val
, p
);
9929 p
+= strlen ((char *) p
) + 1;
9933 if ((tag
& 2) == 0 && display_proc_gnu_attribute
)
9934 return display_proc_gnu_attribute (p
, tag
);
9937 type
= 1; /* String. */
9939 type
= 2; /* uleb128. */
9940 printf (" Tag_unknown_%d: ", tag
);
9944 printf ("\"%s\"\n", p
);
9945 p
+= strlen ((char *) p
) + 1;
9949 val
= read_uleb128 (p
, &len
);
9951 printf ("%d (0x%x)\n", val
, val
);
9957 static unsigned char *
9958 display_power_gnu_attribute (unsigned char * p
, int tag
)
9964 if (tag
== Tag_GNU_Power_ABI_FP
)
9966 val
= read_uleb128 (p
, &len
);
9968 printf (" Tag_GNU_Power_ABI_FP: ");
9973 printf ("Hard or soft float\n");
9976 printf ("Hard float\n");
9979 printf ("Soft float\n");
9982 printf ("Single-precision hard float\n");
9985 printf ("??? (%d)\n", val
);
9991 if (tag
== Tag_GNU_Power_ABI_Vector
)
9993 val
= read_uleb128 (p
, &len
);
9995 printf (" Tag_GNU_Power_ABI_Vector: ");
10002 printf ("Generic\n");
10005 printf ("AltiVec\n");
10011 printf ("??? (%d)\n", val
);
10017 if (tag
== Tag_GNU_Power_ABI_Struct_Return
)
10019 val
= read_uleb128 (p
, &len
);
10021 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
10028 printf ("r3/r4\n");
10031 printf ("Memory\n");
10034 printf ("??? (%d)\n", val
);
10041 type
= 1; /* String. */
10043 type
= 2; /* uleb128. */
10044 printf (" Tag_unknown_%d: ", tag
);
10048 printf ("\"%s\"\n", p
);
10049 p
+= strlen ((char *) p
) + 1;
10053 val
= read_uleb128 (p
, &len
);
10055 printf ("%d (0x%x)\n", val
, val
);
10061 static unsigned char *
10062 display_mips_gnu_attribute (unsigned char * p
, int tag
)
10068 if (tag
== Tag_GNU_MIPS_ABI_FP
)
10070 val
= read_uleb128 (p
, &len
);
10072 printf (" Tag_GNU_MIPS_ABI_FP: ");
10077 printf ("Hard or soft float\n");
10080 printf ("Hard float (-mdouble-float)\n");
10083 printf ("Hard float (-msingle-float)\n");
10086 printf ("Soft float\n");
10089 printf ("64-bit float (-mips32r2 -mfp64)\n");
10092 printf ("??? (%d)\n", val
);
10099 type
= 1; /* String. */
10101 type
= 2; /* uleb128. */
10102 printf (" Tag_unknown_%d: ", tag
);
10106 printf ("\"%s\"\n", p
);
10107 p
+= strlen ((char *) p
) + 1;
10111 val
= read_uleb128 (p
, &len
);
10113 printf ("%d (0x%x)\n", val
, val
);
10120 process_attributes (FILE * file
,
10121 const char * public_name
,
10122 unsigned int proc_type
,
10123 unsigned char * (* display_pub_attribute
) (unsigned char *),
10124 unsigned char * (* display_proc_gnu_attribute
) (unsigned char *, int))
10126 Elf_Internal_Shdr
* sect
;
10127 unsigned char * contents
;
10129 unsigned char * end
;
10130 bfd_vma section_len
;
10134 /* Find the section header so that we get the size. */
10135 for (i
= 0, sect
= section_headers
;
10136 i
< elf_header
.e_shnum
;
10139 if (sect
->sh_type
!= proc_type
&& sect
->sh_type
!= SHT_GNU_ATTRIBUTES
)
10142 contents
= (unsigned char *) get_data (NULL
, file
, sect
->sh_offset
, 1,
10143 sect
->sh_size
, _("attributes"));
10144 if (contents
== NULL
)
10150 len
= sect
->sh_size
- 1;
10156 bfd_boolean public_section
;
10157 bfd_boolean gnu_section
;
10159 section_len
= byte_get (p
, 4);
10162 if (section_len
> len
)
10164 printf (_("ERROR: Bad section length (%d > %d)\n"),
10165 (int) section_len
, (int) len
);
10169 len
-= section_len
;
10170 printf ("Attribute Section: %s\n", p
);
10172 if (public_name
&& streq ((char *) p
, public_name
))
10173 public_section
= TRUE
;
10175 public_section
= FALSE
;
10177 if (streq ((char *) p
, "gnu"))
10178 gnu_section
= TRUE
;
10180 gnu_section
= FALSE
;
10182 namelen
= strlen ((char *) p
) + 1;
10184 section_len
-= namelen
+ 4;
10186 while (section_len
> 0)
10192 size
= byte_get (p
, 4);
10193 if (size
> section_len
)
10195 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
10196 (int) size
, (int) section_len
);
10197 size
= section_len
;
10200 section_len
-= size
;
10201 end
= p
+ size
- 1;
10207 printf ("File Attributes\n");
10210 printf ("Section Attributes:");
10213 printf ("Symbol Attributes:");
10219 val
= read_uleb128 (p
, &j
);
10223 printf (" %d", val
);
10228 printf ("Unknown tag: %d\n", tag
);
10229 public_section
= FALSE
;
10233 if (public_section
)
10236 p
= display_pub_attribute (p
);
10238 else if (gnu_section
)
10241 p
= display_gnu_attribute (p
,
10242 display_proc_gnu_attribute
);
10246 /* ??? Do something sensible, like dump hex. */
10247 printf (" Unknown section contexts\n");
10254 printf (_("Unknown format '%c'\n"), *p
);
10262 process_arm_specific (FILE * file
)
10264 return process_attributes (file
, "aeabi", SHT_ARM_ATTRIBUTES
,
10265 display_arm_attribute
, NULL
);
10269 process_power_specific (FILE * file
)
10271 return process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
10272 display_power_gnu_attribute
);
10275 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
10276 Print the Address, Access and Initial fields of an entry at VMA ADDR
10277 and return the VMA of the next entry. */
10280 print_mips_got_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
10283 print_vma (addr
, LONG_HEX
);
10285 if (addr
< pltgot
+ 0xfff0)
10286 printf ("%6d(gp)", (int) (addr
- pltgot
- 0x7ff0));
10288 printf ("%10s", "");
10291 printf ("%*s", is_32bit_elf
? 8 : 16, "<unknown>");
10296 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
10297 print_vma (entry
, LONG_HEX
);
10299 return addr
+ (is_32bit_elf
? 4 : 8);
10302 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
10303 PLTGOT. Print the Address and Initial fields of an entry at VMA
10304 ADDR and return the VMA of the next entry. */
10307 print_mips_pltgot_entry (unsigned char * data
, bfd_vma pltgot
, bfd_vma addr
)
10310 print_vma (addr
, LONG_HEX
);
10313 printf ("%*s", is_32bit_elf
? 8 : 16, "<unknown>");
10318 entry
= byte_get (data
+ addr
- pltgot
, is_32bit_elf
? 4 : 8);
10319 print_vma (entry
, LONG_HEX
);
10321 return addr
+ (is_32bit_elf
? 4 : 8);
10325 process_mips_specific (FILE * file
)
10327 Elf_Internal_Dyn
* entry
;
10328 size_t liblist_offset
= 0;
10329 size_t liblistno
= 0;
10330 size_t conflictsno
= 0;
10331 size_t options_offset
= 0;
10332 size_t conflicts_offset
= 0;
10333 size_t pltrelsz
= 0;
10335 bfd_vma pltgot
= 0;
10336 bfd_vma mips_pltgot
= 0;
10337 bfd_vma jmprel
= 0;
10338 bfd_vma local_gotno
= 0;
10339 bfd_vma gotsym
= 0;
10340 bfd_vma symtabno
= 0;
10342 process_attributes (file
, NULL
, SHT_GNU_ATTRIBUTES
, NULL
,
10343 display_mips_gnu_attribute
);
10345 /* We have a lot of special sections. Thanks SGI! */
10346 if (dynamic_section
== NULL
)
10347 /* No information available. */
10350 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
10351 switch (entry
->d_tag
)
10353 case DT_MIPS_LIBLIST
:
10355 = offset_from_vma (file
, entry
->d_un
.d_val
,
10356 liblistno
* sizeof (Elf32_External_Lib
));
10358 case DT_MIPS_LIBLISTNO
:
10359 liblistno
= entry
->d_un
.d_val
;
10361 case DT_MIPS_OPTIONS
:
10362 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
10364 case DT_MIPS_CONFLICT
:
10366 = offset_from_vma (file
, entry
->d_un
.d_val
,
10367 conflictsno
* sizeof (Elf32_External_Conflict
));
10369 case DT_MIPS_CONFLICTNO
:
10370 conflictsno
= entry
->d_un
.d_val
;
10373 pltgot
= entry
->d_un
.d_ptr
;
10375 case DT_MIPS_LOCAL_GOTNO
:
10376 local_gotno
= entry
->d_un
.d_val
;
10378 case DT_MIPS_GOTSYM
:
10379 gotsym
= entry
->d_un
.d_val
;
10381 case DT_MIPS_SYMTABNO
:
10382 symtabno
= entry
->d_un
.d_val
;
10384 case DT_MIPS_PLTGOT
:
10385 mips_pltgot
= entry
->d_un
.d_ptr
;
10388 pltrel
= entry
->d_un
.d_val
;
10391 pltrelsz
= entry
->d_un
.d_val
;
10394 jmprel
= entry
->d_un
.d_ptr
;
10400 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
10402 Elf32_External_Lib
* elib
;
10405 elib
= (Elf32_External_Lib
*) get_data (NULL
, file
, liblist_offset
,
10407 sizeof (Elf32_External_Lib
),
10411 printf ("\nSection '.liblist' contains %lu entries:\n",
10412 (unsigned long) liblistno
);
10413 fputs (" Library Time Stamp Checksum Version Flags\n",
10416 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
10423 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
10424 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
10425 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
10426 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
10427 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
10429 tmp
= gmtime (&atime
);
10430 snprintf (timebuf
, sizeof (timebuf
),
10431 "%04u-%02u-%02uT%02u:%02u:%02u",
10432 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10433 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10435 printf ("%3lu: ", (unsigned long) cnt
);
10436 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
10437 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
10439 printf ("<corrupt: %9ld>", liblist
.l_name
);
10440 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
10441 liblist
.l_version
);
10443 if (liblist
.l_flags
== 0)
10447 static const struct
10454 { " EXACT_MATCH", LL_EXACT_MATCH
},
10455 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
10456 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
10457 { " EXPORTS", LL_EXPORTS
},
10458 { " DELAY_LOAD", LL_DELAY_LOAD
},
10459 { " DELTA", LL_DELTA
}
10461 int flags
= liblist
.l_flags
;
10464 for (fcnt
= 0; fcnt
< ARRAY_SIZE (l_flags_vals
); ++fcnt
)
10465 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
10467 fputs (l_flags_vals
[fcnt
].name
, stdout
);
10468 flags
^= l_flags_vals
[fcnt
].bit
;
10471 printf (" %#x", (unsigned int) flags
);
10481 if (options_offset
!= 0)
10483 Elf_External_Options
* eopt
;
10484 Elf_Internal_Shdr
* sect
= section_headers
;
10485 Elf_Internal_Options
* iopt
;
10486 Elf_Internal_Options
* option
;
10490 /* Find the section header so that we get the size. */
10491 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
10494 eopt
= (Elf_External_Options
*) get_data (NULL
, file
, options_offset
, 1,
10495 sect
->sh_size
, _("options"));
10498 iopt
= (Elf_Internal_Options
*)
10499 cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (* iopt
));
10502 error (_("Out of memory\n"));
10509 while (offset
< sect
->sh_size
)
10511 Elf_External_Options
* eoption
;
10513 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
10515 option
->kind
= BYTE_GET (eoption
->kind
);
10516 option
->size
= BYTE_GET (eoption
->size
);
10517 option
->section
= BYTE_GET (eoption
->section
);
10518 option
->info
= BYTE_GET (eoption
->info
);
10520 offset
+= option
->size
;
10526 printf (_("\nSection '%s' contains %d entries:\n"),
10527 SECTION_NAME (sect
), cnt
);
10535 switch (option
->kind
)
10538 /* This shouldn't happen. */
10539 printf (" NULL %d %lx", option
->section
, option
->info
);
10542 printf (" REGINFO ");
10543 if (elf_header
.e_machine
== EM_MIPS
)
10546 Elf32_External_RegInfo
* ereg
;
10547 Elf32_RegInfo reginfo
;
10549 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
10550 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
10551 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
10552 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
10553 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
10554 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
10555 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
10557 printf ("GPR %08lx GP 0x%lx\n",
10558 reginfo
.ri_gprmask
,
10559 (unsigned long) reginfo
.ri_gp_value
);
10560 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
10561 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
10562 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
10567 Elf64_External_RegInfo
* ereg
;
10568 Elf64_Internal_RegInfo reginfo
;
10570 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
10571 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
10572 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
10573 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
10574 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
10575 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
10576 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
10578 printf ("GPR %08lx GP 0x",
10579 reginfo
.ri_gprmask
);
10580 printf_vma (reginfo
.ri_gp_value
);
10583 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
10584 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
10585 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
10589 case ODK_EXCEPTIONS
:
10590 fputs (" EXCEPTIONS fpe_min(", stdout
);
10591 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
10592 fputs (") fpe_max(", stdout
);
10593 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
10594 fputs (")", stdout
);
10596 if (option
->info
& OEX_PAGE0
)
10597 fputs (" PAGE0", stdout
);
10598 if (option
->info
& OEX_SMM
)
10599 fputs (" SMM", stdout
);
10600 if (option
->info
& OEX_FPDBUG
)
10601 fputs (" FPDBUG", stdout
);
10602 if (option
->info
& OEX_DISMISS
)
10603 fputs (" DISMISS", stdout
);
10606 fputs (" PAD ", stdout
);
10607 if (option
->info
& OPAD_PREFIX
)
10608 fputs (" PREFIX", stdout
);
10609 if (option
->info
& OPAD_POSTFIX
)
10610 fputs (" POSTFIX", stdout
);
10611 if (option
->info
& OPAD_SYMBOL
)
10612 fputs (" SYMBOL", stdout
);
10615 fputs (" HWPATCH ", stdout
);
10616 if (option
->info
& OHW_R4KEOP
)
10617 fputs (" R4KEOP", stdout
);
10618 if (option
->info
& OHW_R8KPFETCH
)
10619 fputs (" R8KPFETCH", stdout
);
10620 if (option
->info
& OHW_R5KEOP
)
10621 fputs (" R5KEOP", stdout
);
10622 if (option
->info
& OHW_R5KCVTL
)
10623 fputs (" R5KCVTL", stdout
);
10626 fputs (" FILL ", stdout
);
10627 /* XXX Print content of info word? */
10630 fputs (" TAGS ", stdout
);
10631 /* XXX Print content of info word? */
10634 fputs (" HWAND ", stdout
);
10635 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
10636 fputs (" R4KEOP_CHECKED", stdout
);
10637 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
10638 fputs (" R4KEOP_CLEAN", stdout
);
10641 fputs (" HWOR ", stdout
);
10642 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
10643 fputs (" R4KEOP_CHECKED", stdout
);
10644 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
10645 fputs (" R4KEOP_CLEAN", stdout
);
10648 printf (" GP_GROUP %#06lx self-contained %#06lx",
10649 option
->info
& OGP_GROUP
,
10650 (option
->info
& OGP_SELF
) >> 16);
10653 printf (" IDENT %#06lx self-contained %#06lx",
10654 option
->info
& OGP_GROUP
,
10655 (option
->info
& OGP_SELF
) >> 16);
10658 /* This shouldn't happen. */
10659 printf (" %3d ??? %d %lx",
10660 option
->kind
, option
->section
, option
->info
);
10664 len
= sizeof (* eopt
);
10665 while (len
< option
->size
)
10666 if (((char *) option
)[len
] >= ' '
10667 && ((char *) option
)[len
] < 0x7f)
10668 printf ("%c", ((char *) option
)[len
++]);
10670 printf ("\\%03o", ((char *) option
)[len
++]);
10672 fputs ("\n", stdout
);
10680 if (conflicts_offset
!= 0 && conflictsno
!= 0)
10682 Elf32_Conflict
* iconf
;
10685 if (dynamic_symbols
== NULL
)
10687 error (_("conflict list found without a dynamic symbol table\n"));
10691 iconf
= (Elf32_Conflict
*) cmalloc (conflictsno
, sizeof (* iconf
));
10694 error (_("Out of memory\n"));
10700 Elf32_External_Conflict
* econf32
;
10702 econf32
= (Elf32_External_Conflict
*)
10703 get_data (NULL
, file
, conflicts_offset
, conflictsno
,
10704 sizeof (* econf32
), _("conflict"));
10708 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
10709 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
10715 Elf64_External_Conflict
* econf64
;
10717 econf64
= (Elf64_External_Conflict
*)
10718 get_data (NULL
, file
, conflicts_offset
, conflictsno
,
10719 sizeof (* econf64
), _("conflict"));
10723 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
10724 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
10729 printf (_("\nSection '.conflict' contains %lu entries:\n"),
10730 (unsigned long) conflictsno
);
10731 puts (_(" Num: Index Value Name"));
10733 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
10735 Elf_Internal_Sym
* psym
= & dynamic_symbols
[iconf
[cnt
]];
10737 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
10738 print_vma (psym
->st_value
, FULL_HEX
);
10740 if (VALID_DYNAMIC_NAME (psym
->st_name
))
10741 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
10743 printf ("<corrupt: %14ld>", psym
->st_name
);
10750 if (pltgot
!= 0 && local_gotno
!= 0)
10752 bfd_vma ent
, local_end
, global_end
;
10754 unsigned char * data
;
10758 addr_size
= (is_32bit_elf
? 4 : 8);
10759 local_end
= pltgot
+ local_gotno
* addr_size
;
10760 global_end
= local_end
+ (symtabno
- gotsym
) * addr_size
;
10762 offset
= offset_from_vma (file
, pltgot
, global_end
- pltgot
);
10763 data
= (unsigned char *) get_data (NULL
, file
, offset
,
10764 global_end
- pltgot
, 1, _("GOT"));
10765 printf (_("\nPrimary GOT:\n"));
10766 printf (_(" Canonical gp value: "));
10767 print_vma (pltgot
+ 0x7ff0, LONG_HEX
);
10770 printf (_(" Reserved entries:\n"));
10771 printf (_(" %*s %10s %*s Purpose\n"),
10772 addr_size
* 2, "Address", "Access",
10773 addr_size
* 2, "Initial");
10774 ent
= print_mips_got_entry (data
, pltgot
, ent
);
10775 printf (" Lazy resolver\n");
10777 && (byte_get (data
+ ent
- pltgot
, addr_size
)
10778 >> (addr_size
* 8 - 1)) != 0)
10780 ent
= print_mips_got_entry (data
, pltgot
, ent
);
10781 printf (" Module pointer (GNU extension)\n");
10785 if (ent
< local_end
)
10787 printf (_(" Local entries:\n"));
10788 printf (_(" %*s %10s %*s\n"),
10789 addr_size
* 2, "Address", "Access",
10790 addr_size
* 2, "Initial");
10791 while (ent
< local_end
)
10793 ent
= print_mips_got_entry (data
, pltgot
, ent
);
10799 if (gotsym
< symtabno
)
10803 printf (_(" Global entries:\n"));
10804 printf (_(" %*s %10s %*s %*s %-7s %3s %s\n"),
10805 addr_size
* 2, "Address", "Access",
10806 addr_size
* 2, "Initial",
10807 addr_size
* 2, "Sym.Val.", "Type", "Ndx", "Name");
10808 sym_width
= (is_32bit_elf
? 80 : 160) - 28 - addr_size
* 6 - 1;
10809 for (i
= gotsym
; i
< symtabno
; i
++)
10811 Elf_Internal_Sym
* psym
;
10813 psym
= dynamic_symbols
+ i
;
10814 ent
= print_mips_got_entry (data
, pltgot
, ent
);
10816 print_vma (psym
->st_value
, LONG_HEX
);
10817 printf (" %-7s %3s ",
10818 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
10819 get_symbol_index_type (psym
->st_shndx
));
10820 if (VALID_DYNAMIC_NAME (psym
->st_name
))
10821 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
10823 printf ("<corrupt: %14ld>", psym
->st_name
);
10833 if (mips_pltgot
!= 0 && jmprel
!= 0 && pltrel
!= 0 && pltrelsz
!= 0)
10836 size_t offset
, rel_offset
;
10837 unsigned long count
, i
;
10838 unsigned char * data
;
10839 int addr_size
, sym_width
;
10840 Elf_Internal_Rela
* rels
;
10842 rel_offset
= offset_from_vma (file
, jmprel
, pltrelsz
);
10843 if (pltrel
== DT_RELA
)
10845 if (!slurp_rela_relocs (file
, rel_offset
, pltrelsz
, &rels
, &count
))
10850 if (!slurp_rel_relocs (file
, rel_offset
, pltrelsz
, &rels
, &count
))
10855 addr_size
= (is_32bit_elf
? 4 : 8);
10856 end
= mips_pltgot
+ (2 + count
) * addr_size
;
10858 offset
= offset_from_vma (file
, mips_pltgot
, end
- mips_pltgot
);
10859 data
= (unsigned char *) get_data (NULL
, file
, offset
, end
- mips_pltgot
,
10861 printf (_("\nPLT GOT:\n\n"));
10862 printf (_(" Reserved entries:\n"));
10863 printf (_(" %*s %*s Purpose\n"),
10864 addr_size
* 2, "Address", addr_size
* 2, "Initial");
10865 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
10866 printf (" PLT lazy resolver\n");
10867 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
10868 printf (" Module pointer\n");
10871 printf (_(" Entries:\n"));
10872 printf (_(" %*s %*s %*s %-7s %3s %s\n"),
10873 addr_size
* 2, "Address",
10874 addr_size
* 2, "Initial",
10875 addr_size
* 2, "Sym.Val.", "Type", "Ndx", "Name");
10876 sym_width
= (is_32bit_elf
? 80 : 160) - 17 - addr_size
* 6 - 1;
10877 for (i
= 0; i
< count
; i
++)
10879 Elf_Internal_Sym
* psym
;
10881 psym
= dynamic_symbols
+ get_reloc_symindex (rels
[i
].r_info
);
10882 ent
= print_mips_pltgot_entry (data
, mips_pltgot
, ent
);
10884 print_vma (psym
->st_value
, LONG_HEX
);
10885 printf (" %-7s %3s ",
10886 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
10887 get_symbol_index_type (psym
->st_shndx
));
10888 if (VALID_DYNAMIC_NAME (psym
->st_name
))
10889 print_symbol (sym_width
, GET_DYNAMIC_NAME (psym
->st_name
));
10891 printf ("<corrupt: %14ld>", psym
->st_name
);
10905 process_gnu_liblist (FILE * file
)
10907 Elf_Internal_Shdr
* section
;
10908 Elf_Internal_Shdr
* string_sec
;
10909 Elf32_External_Lib
* elib
;
10911 size_t strtab_size
;
10918 for (i
= 0, section
= section_headers
;
10919 i
< elf_header
.e_shnum
;
10922 switch (section
->sh_type
)
10924 case SHT_GNU_LIBLIST
:
10925 if (section
->sh_link
>= elf_header
.e_shnum
)
10928 elib
= (Elf32_External_Lib
*)
10929 get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
10934 string_sec
= section_headers
+ section
->sh_link
;
10936 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
, 1,
10937 string_sec
->sh_size
,
10938 _("liblist string table"));
10939 strtab_size
= string_sec
->sh_size
;
10942 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
10948 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
10949 SECTION_NAME (section
),
10950 (unsigned long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
10952 puts (" Library Time Stamp Checksum Version Flags");
10954 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
10962 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
10963 atime
= BYTE_GET (elib
[cnt
].l_time_stamp
);
10964 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
10965 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
10966 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
10968 tmp
= gmtime (&atime
);
10969 snprintf (timebuf
, sizeof (timebuf
),
10970 "%04u-%02u-%02uT%02u:%02u:%02u",
10971 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10972 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10974 printf ("%3lu: ", (unsigned long) cnt
);
10976 printf ("%-20s", liblist
.l_name
< strtab_size
10977 ? strtab
+ liblist
.l_name
: "<corrupt>");
10979 printf ("%-20.20s", liblist
.l_name
< strtab_size
10980 ? strtab
+ liblist
.l_name
: "<corrupt>");
10981 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
10982 liblist
.l_version
, liblist
.l_flags
);
10992 static const char *
10993 get_note_type (unsigned e_type
)
10995 static char buff
[64];
10997 if (elf_header
.e_type
== ET_CORE
)
11001 return _("NT_AUXV (auxiliary vector)");
11003 return _("NT_PRSTATUS (prstatus structure)");
11005 return _("NT_FPREGSET (floating point registers)");
11007 return _("NT_PRPSINFO (prpsinfo structure)");
11008 case NT_TASKSTRUCT
:
11009 return _("NT_TASKSTRUCT (task structure)");
11011 return _("NT_PRXFPREG (user_xfpregs structure)");
11013 return _("NT_PPC_VMX (ppc Altivec registers)");
11015 return _("NT_PPC_VSX (ppc VSX registers)");
11016 case NT_X86_XSTATE
:
11017 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
11018 case NT_S390_HIGH_GPRS
:
11019 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
11020 case NT_S390_TIMER
:
11021 return _("NT_S390_TIMER (s390 timer register)");
11022 case NT_S390_TODCMP
:
11023 return _("NT_S390_TODCMP (s390 TOD comparator register)");
11024 case NT_S390_TODPREG
:
11025 return _("NT_S390_TODPREG (s390 TOD programmable register)");
11027 return _("NT_S390_CTRS (s390 control registers)");
11028 case NT_S390_PREFIX
:
11029 return _("NT_S390_PREFIX (s390 prefix register)");
11031 return _("NT_PSTATUS (pstatus structure)");
11033 return _("NT_FPREGS (floating point registers)");
11035 return _("NT_PSINFO (psinfo structure)");
11037 return _("NT_LWPSTATUS (lwpstatus_t structure)");
11039 return _("NT_LWPSINFO (lwpsinfo_t structure)");
11040 case NT_WIN32PSTATUS
:
11041 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
11049 return _("NT_VERSION (version)");
11051 return _("NT_ARCH (architecture)");
11056 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
11060 static const char *
11061 get_gnu_elf_note_type (unsigned e_type
)
11063 static char buff
[64];
11067 case NT_GNU_ABI_TAG
:
11068 return _("NT_GNU_ABI_TAG (ABI version tag)");
11070 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
11071 case NT_GNU_BUILD_ID
:
11072 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
11073 case NT_GNU_GOLD_VERSION
:
11074 return _("NT_GNU_GOLD_VERSION (gold version)");
11079 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
11083 static const char *
11084 get_netbsd_elfcore_note_type (unsigned e_type
)
11086 static char buff
[64];
11088 if (e_type
== NT_NETBSDCORE_PROCINFO
)
11090 /* NetBSD core "procinfo" structure. */
11091 return _("NetBSD procinfo structure");
11094 /* As of Jan 2002 there are no other machine-independent notes
11095 defined for NetBSD core files. If the note type is less
11096 than the start of the machine-dependent note types, we don't
11099 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
11101 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
11105 switch (elf_header
.e_machine
)
11107 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
11108 and PT_GETFPREGS == mach+2. */
11113 case EM_SPARC32PLUS
:
11117 case NT_NETBSDCORE_FIRSTMACH
+0:
11118 return _("PT_GETREGS (reg structure)");
11119 case NT_NETBSDCORE_FIRSTMACH
+2:
11120 return _("PT_GETFPREGS (fpreg structure)");
11126 /* On all other arch's, PT_GETREGS == mach+1 and
11127 PT_GETFPREGS == mach+3. */
11131 case NT_NETBSDCORE_FIRSTMACH
+1:
11132 return _("PT_GETREGS (reg structure)");
11133 case NT_NETBSDCORE_FIRSTMACH
+3:
11134 return _("PT_GETFPREGS (fpreg structure)");
11140 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
11141 e_type
- NT_NETBSDCORE_FIRSTMACH
);
11145 /* Note that by the ELF standard, the name field is already null byte
11146 terminated, and namesz includes the terminating null byte.
11147 I.E. the value of namesz for the name "FSF" is 4.
11149 If the value of namesz is zero, there is no name present. */
11151 process_note (Elf_Internal_Note
* pnote
)
11153 const char * name
= pnote
->namesz
? pnote
->namedata
: "(NONE)";
11156 if (pnote
->namesz
== 0)
11157 /* If there is no note name, then use the default set of
11158 note type strings. */
11159 nt
= get_note_type (pnote
->type
);
11161 else if (const_strneq (pnote
->namedata
, "GNU"))
11162 /* GNU-specific object file notes. */
11163 nt
= get_gnu_elf_note_type (pnote
->type
);
11165 else if (const_strneq (pnote
->namedata
, "NetBSD-CORE"))
11166 /* NetBSD-specific core file notes. */
11167 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
11169 else if (strneq (pnote
->namedata
, "SPU/", 4))
11171 /* SPU-specific core file notes. */
11172 nt
= pnote
->namedata
+ 4;
11177 /* Don't recognize this note name; just use the default set of
11178 note type strings. */
11179 nt
= get_note_type (pnote
->type
);
11181 printf (" %s\t\t0x%08lx\t%s\n", name
, pnote
->descsz
, nt
);
11187 process_corefile_note_segment (FILE * file
, bfd_vma offset
, bfd_vma length
)
11189 Elf_External_Note
* pnotes
;
11190 Elf_External_Note
* external
;
11196 pnotes
= (Elf_External_Note
*) get_data (NULL
, file
, offset
, 1, length
,
11203 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
11204 (unsigned long) offset
, (unsigned long) length
);
11205 printf (_(" Owner\t\tData size\tDescription\n"));
11207 while (external
< (Elf_External_Note
*) ((char *) pnotes
+ length
))
11209 Elf_External_Note
* next
;
11210 Elf_Internal_Note inote
;
11211 char * temp
= NULL
;
11213 inote
.type
= BYTE_GET (external
->type
);
11214 inote
.namesz
= BYTE_GET (external
->namesz
);
11215 inote
.namedata
= external
->name
;
11216 inote
.descsz
= BYTE_GET (external
->descsz
);
11217 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
11218 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
11220 next
= (Elf_External_Note
*) (inote
.descdata
+ align_power (inote
.descsz
, 2));
11222 if (((char *) next
) > (((char *) pnotes
) + length
))
11224 warn (_("corrupt note found at offset %lx into core notes\n"),
11225 (unsigned long) ((char *) external
- (char *) pnotes
));
11226 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
11227 inote
.type
, inote
.namesz
, inote
.descsz
);
11233 /* Verify that name is null terminated. It appears that at least
11234 one version of Linux (RedHat 6.0) generates corefiles that don't
11235 comply with the ELF spec by failing to include the null byte in
11237 if (inote
.namedata
[inote
.namesz
] != '\0')
11239 temp
= (char *) malloc (inote
.namesz
+ 1);
11243 error (_("Out of memory\n"));
11248 strncpy (temp
, inote
.namedata
, inote
.namesz
);
11249 temp
[inote
.namesz
] = 0;
11251 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
11252 inote
.namedata
= temp
;
11255 res
&= process_note (& inote
);
11270 process_corefile_note_segments (FILE * file
)
11272 Elf_Internal_Phdr
* segment
;
11276 if (! get_program_headers (file
))
11279 for (i
= 0, segment
= program_headers
;
11280 i
< elf_header
.e_phnum
;
11283 if (segment
->p_type
== PT_NOTE
)
11284 res
&= process_corefile_note_segment (file
,
11285 (bfd_vma
) segment
->p_offset
,
11286 (bfd_vma
) segment
->p_filesz
);
11293 process_note_sections (FILE * file
)
11295 Elf_Internal_Shdr
* section
;
11299 for (i
= 0, section
= section_headers
;
11300 i
< elf_header
.e_shnum
;
11302 if (section
->sh_type
== SHT_NOTE
)
11303 res
&= process_corefile_note_segment (file
,
11304 (bfd_vma
) section
->sh_offset
,
11305 (bfd_vma
) section
->sh_size
);
11311 process_notes (FILE * file
)
11313 /* If we have not been asked to display the notes then do nothing. */
11317 if (elf_header
.e_type
!= ET_CORE
)
11318 return process_note_sections (file
);
11320 /* No program headers means no NOTE segment. */
11321 if (elf_header
.e_phnum
> 0)
11322 return process_corefile_note_segments (file
);
11324 printf (_("No note segments present in the core file.\n"));
11329 process_arch_specific (FILE * file
)
11334 switch (elf_header
.e_machine
)
11337 return process_arm_specific (file
);
11339 case EM_MIPS_RS3_LE
:
11340 return process_mips_specific (file
);
11343 return process_power_specific (file
);
11352 get_file_header (FILE * file
)
11354 /* Read in the identity array. */
11355 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
11358 /* Determine how to read the rest of the header. */
11359 switch (elf_header
.e_ident
[EI_DATA
])
11361 default: /* fall through */
11362 case ELFDATANONE
: /* fall through */
11364 byte_get
= byte_get_little_endian
;
11365 byte_put
= byte_put_little_endian
;
11368 byte_get
= byte_get_big_endian
;
11369 byte_put
= byte_put_big_endian
;
11373 /* For now we only support 32 bit and 64 bit ELF files. */
11374 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
11376 /* Read in the rest of the header. */
11379 Elf32_External_Ehdr ehdr32
;
11381 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
11384 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
11385 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
11386 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
11387 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
11388 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
11389 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
11390 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
11391 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
11392 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
11393 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
11394 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
11395 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
11396 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
11400 Elf64_External_Ehdr ehdr64
;
11402 /* If we have been compiled with sizeof (bfd_vma) == 4, then
11403 we will not be able to cope with the 64bit data found in
11404 64 ELF files. Detect this now and abort before we start
11405 overwriting things. */
11406 if (sizeof (bfd_vma
) < 8)
11408 error (_("This instance of readelf has been built without support for a\n\
11409 64 bit data type and so it cannot read 64 bit ELF files.\n"));
11413 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
11416 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
11417 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
11418 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
11419 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
11420 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
11421 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
11422 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
11423 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
11424 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
11425 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
11426 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
11427 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
11428 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
11431 if (elf_header
.e_shoff
)
11433 /* There may be some extensions in the first section header. Don't
11434 bomb if we can't read it. */
11436 get_32bit_section_headers (file
, 1);
11438 get_64bit_section_headers (file
, 1);
11444 /* Process one ELF object file according to the command line options.
11445 This file may actually be stored in an archive. The file is
11446 positioned at the start of the ELF object. */
11449 process_object (char * file_name
, FILE * file
)
11453 if (! get_file_header (file
))
11455 error (_("%s: Failed to read file header\n"), file_name
);
11459 /* Initialise per file variables. */
11460 for (i
= ARRAY_SIZE (version_info
); i
--;)
11461 version_info
[i
] = 0;
11463 for (i
= ARRAY_SIZE (dynamic_info
); i
--;)
11464 dynamic_info
[i
] = 0;
11466 /* Process the file. */
11468 printf (_("\nFile: %s\n"), file_name
);
11470 /* Initialise the dump_sects array from the cmdline_dump_sects array.
11471 Note we do this even if cmdline_dump_sects is empty because we
11472 must make sure that the dump_sets array is zeroed out before each
11473 object file is processed. */
11474 if (num_dump_sects
> num_cmdline_dump_sects
)
11475 memset (dump_sects
, 0, num_dump_sects
* sizeof (* dump_sects
));
11477 if (num_cmdline_dump_sects
> 0)
11479 if (num_dump_sects
== 0)
11480 /* A sneaky way of allocating the dump_sects array. */
11481 request_dump_bynumber (num_cmdline_dump_sects
, 0);
11483 assert (num_dump_sects
>= num_cmdline_dump_sects
);
11484 memcpy (dump_sects
, cmdline_dump_sects
,
11485 num_cmdline_dump_sects
* sizeof (* dump_sects
));
11488 if (! process_file_header ())
11491 if (! process_section_headers (file
))
11493 /* Without loaded section headers we cannot process lots of
11495 do_unwind
= do_version
= do_dump
= do_arch
= 0;
11497 if (! do_using_dynamic
)
11498 do_syms
= do_dyn_syms
= do_reloc
= 0;
11501 if (! process_section_groups (file
))
11503 /* Without loaded section groups we cannot process unwind. */
11507 if (process_program_headers (file
))
11508 process_dynamic_section (file
);
11510 process_relocs (file
);
11512 process_unwind (file
);
11514 process_symbol_table (file
);
11516 process_syminfo (file
);
11518 process_version_sections (file
);
11520 process_section_contents (file
);
11522 process_notes (file
);
11524 process_gnu_liblist (file
);
11526 process_arch_specific (file
);
11528 if (program_headers
)
11530 free (program_headers
);
11531 program_headers
= NULL
;
11534 if (section_headers
)
11536 free (section_headers
);
11537 section_headers
= NULL
;
11542 free (string_table
);
11543 string_table
= NULL
;
11544 string_table_length
= 0;
11547 if (dynamic_strings
)
11549 free (dynamic_strings
);
11550 dynamic_strings
= NULL
;
11551 dynamic_strings_length
= 0;
11554 if (dynamic_symbols
)
11556 free (dynamic_symbols
);
11557 dynamic_symbols
= NULL
;
11558 num_dynamic_syms
= 0;
11561 if (dynamic_syminfo
)
11563 free (dynamic_syminfo
);
11564 dynamic_syminfo
= NULL
;
11567 if (section_headers_groups
)
11569 free (section_headers_groups
);
11570 section_headers_groups
= NULL
;
11573 if (section_groups
)
11575 struct group_list
* g
;
11576 struct group_list
* next
;
11578 for (i
= 0; i
< group_count
; i
++)
11580 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
11587 free (section_groups
);
11588 section_groups
= NULL
;
11591 free_debug_memory ();
11596 /* Return the path name for a proxy entry in a thin archive, adjusted relative
11597 to the path name of the thin archive itself if necessary. Always returns
11598 a pointer to malloc'ed memory. */
11601 adjust_relative_path (char * file_name
, char * name
, int name_len
)
11603 char * member_file_name
;
11604 const char * base_name
= lbasename (file_name
);
11606 /* This is a proxy entry for a thin archive member.
11607 If the extended name table contains an absolute path
11608 name, or if the archive is in the current directory,
11609 use the path name as given. Otherwise, we need to
11610 find the member relative to the directory where the
11611 archive is located. */
11612 if (IS_ABSOLUTE_PATH (name
) || base_name
== file_name
)
11614 member_file_name
= (char *) malloc (name_len
+ 1);
11615 if (member_file_name
== NULL
)
11617 error (_("Out of memory\n"));
11620 memcpy (member_file_name
, name
, name_len
);
11621 member_file_name
[name_len
] = '\0';
11625 /* Concatenate the path components of the archive file name
11626 to the relative path name from the extended name table. */
11627 size_t prefix_len
= base_name
- file_name
;
11628 member_file_name
= (char *) malloc (prefix_len
+ name_len
+ 1);
11629 if (member_file_name
== NULL
)
11631 error (_("Out of memory\n"));
11634 memcpy (member_file_name
, file_name
, prefix_len
);
11635 memcpy (member_file_name
+ prefix_len
, name
, name_len
);
11636 member_file_name
[prefix_len
+ name_len
] = '\0';
11638 return member_file_name
;
11641 /* Structure to hold information about an archive file. */
11643 struct archive_info
11645 char * file_name
; /* Archive file name. */
11646 FILE * file
; /* Open file descriptor. */
11647 unsigned long index_num
; /* Number of symbols in table. */
11648 unsigned long * index_array
; /* The array of member offsets. */
11649 char * sym_table
; /* The symbol table. */
11650 unsigned long sym_size
; /* Size of the symbol table. */
11651 char * longnames
; /* The long file names table. */
11652 unsigned long longnames_size
; /* Size of the long file names table. */
11653 unsigned long nested_member_origin
; /* Origin in the nested archive of the current member. */
11654 unsigned long next_arhdr_offset
; /* Offset of the next archive header. */
11655 bfd_boolean is_thin_archive
; /* TRUE if this is a thin archive. */
11656 struct ar_hdr arhdr
; /* Current archive header. */
11659 /* Read the symbol table and long-name table from an archive. */
11662 setup_archive (struct archive_info
* arch
, char * file_name
, FILE * file
,
11663 bfd_boolean is_thin_archive
, bfd_boolean read_symbols
)
11666 unsigned long size
;
11668 arch
->file_name
= strdup (file_name
);
11670 arch
->index_num
= 0;
11671 arch
->index_array
= NULL
;
11672 arch
->sym_table
= NULL
;
11673 arch
->sym_size
= 0;
11674 arch
->longnames
= NULL
;
11675 arch
->longnames_size
= 0;
11676 arch
->nested_member_origin
= 0;
11677 arch
->is_thin_archive
= is_thin_archive
;
11678 arch
->next_arhdr_offset
= SARMAG
;
11680 /* Read the first archive member header. */
11681 if (fseek (file
, SARMAG
, SEEK_SET
) != 0)
11683 error (_("%s: failed to seek to first archive header\n"), file_name
);
11686 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, file
);
11687 if (got
!= sizeof arch
->arhdr
)
11692 error (_("%s: failed to read archive header\n"), file_name
);
11696 /* See if this is the archive symbol table. */
11697 if (const_strneq (arch
->arhdr
.ar_name
, "/ ")
11698 || const_strneq (arch
->arhdr
.ar_name
, "/SYM64/ "))
11700 size
= strtoul (arch
->arhdr
.ar_size
, NULL
, 10);
11701 size
= size
+ (size
& 1);
11703 arch
->next_arhdr_offset
+= sizeof arch
->arhdr
+ size
;
11708 /* A buffer used to hold numbers read in from an archive index.
11709 These are always 4 bytes long and stored in big-endian format. */
11710 #define SIZEOF_AR_INDEX_NUMBERS 4
11711 unsigned char integer_buffer
[SIZEOF_AR_INDEX_NUMBERS
];
11712 unsigned char * index_buffer
;
11714 /* Check the size of the archive index. */
11715 if (size
< SIZEOF_AR_INDEX_NUMBERS
)
11717 error (_("%s: the archive index is empty\n"), file_name
);
11721 /* Read the numer of entries in the archive index. */
11722 got
= fread (integer_buffer
, 1, sizeof integer_buffer
, file
);
11723 if (got
!= sizeof (integer_buffer
))
11725 error (_("%s: failed to read archive index\n"), file_name
);
11728 arch
->index_num
= byte_get_big_endian (integer_buffer
, sizeof integer_buffer
);
11729 size
-= SIZEOF_AR_INDEX_NUMBERS
;
11731 /* Read in the archive index. */
11732 if (size
< arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
)
11734 error (_("%s: the archive index is supposed to have %ld entries, but the size in the header is too small\n"),
11735 file_name
, arch
->index_num
);
11738 index_buffer
= (unsigned char *)
11739 malloc (arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
);
11740 if (index_buffer
== NULL
)
11742 error (_("Out of memory whilst trying to read archive symbol index\n"));
11745 got
= fread (index_buffer
, SIZEOF_AR_INDEX_NUMBERS
, arch
->index_num
, file
);
11746 if (got
!= arch
->index_num
)
11748 free (index_buffer
);
11749 error (_("%s: failed to read archive index\n"), file_name
);
11752 size
-= arch
->index_num
* SIZEOF_AR_INDEX_NUMBERS
;
11754 /* Convert the index numbers into the host's numeric format. */
11755 arch
->index_array
= (long unsigned int *)
11756 malloc (arch
->index_num
* sizeof (* arch
->index_array
));
11757 if (arch
->index_array
== NULL
)
11759 free (index_buffer
);
11760 error (_("Out of memory whilst trying to convert the archive symbol index\n"));
11764 for (i
= 0; i
< arch
->index_num
; i
++)
11765 arch
->index_array
[i
] = byte_get_big_endian ((unsigned char *) (index_buffer
+ (i
* SIZEOF_AR_INDEX_NUMBERS
)),
11766 SIZEOF_AR_INDEX_NUMBERS
);
11767 free (index_buffer
);
11769 /* The remaining space in the header is taken up by the symbol table. */
11772 error (_("%s: the archive has an index but no symbols\n"), file_name
);
11775 arch
->sym_table
= (char *) malloc (size
);
11776 arch
->sym_size
= size
;
11777 if (arch
->sym_table
== NULL
)
11779 error (_("Out of memory whilst trying to read archive index symbol table\n"));
11782 got
= fread (arch
->sym_table
, 1, size
, file
);
11785 error (_("%s: failed to read archive index symbol table\n"), file_name
);
11791 if (fseek (file
, size
, SEEK_CUR
) != 0)
11793 error (_("%s: failed to skip archive symbol table\n"), file_name
);
11798 /* Read the next archive header. */
11799 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, file
);
11800 if (got
!= sizeof arch
->arhdr
)
11804 error (_("%s: failed to read archive header following archive index\n"), file_name
);
11808 else if (read_symbols
)
11809 printf (_("%s has no archive index\n"), file_name
);
11811 if (const_strneq (arch
->arhdr
.ar_name
, "// "))
11813 /* This is the archive string table holding long member names. */
11814 arch
->longnames_size
= strtoul (arch
->arhdr
.ar_size
, NULL
, 10);
11815 arch
->next_arhdr_offset
+= sizeof arch
->arhdr
+ arch
->longnames_size
;
11817 arch
->longnames
= (char *) malloc (arch
->longnames_size
);
11818 if (arch
->longnames
== NULL
)
11820 error (_("Out of memory reading long symbol names in archive\n"));
11824 if (fread (arch
->longnames
, arch
->longnames_size
, 1, file
) != 1)
11826 free (arch
->longnames
);
11827 arch
->longnames
= NULL
;
11828 error (_("%s: failed to read long symbol name string table\n"), file_name
);
11832 if ((arch
->longnames_size
& 1) != 0)
11839 /* Release the memory used for the archive information. */
11842 release_archive (struct archive_info
* arch
)
11844 if (arch
->file_name
!= NULL
)
11845 free (arch
->file_name
);
11846 if (arch
->index_array
!= NULL
)
11847 free (arch
->index_array
);
11848 if (arch
->sym_table
!= NULL
)
11849 free (arch
->sym_table
);
11850 if (arch
->longnames
!= NULL
)
11851 free (arch
->longnames
);
11854 /* Open and setup a nested archive, if not already open. */
11857 setup_nested_archive (struct archive_info
* nested_arch
, char * member_file_name
)
11859 FILE * member_file
;
11861 /* Have we already setup this archive? */
11862 if (nested_arch
->file_name
!= NULL
11863 && streq (nested_arch
->file_name
, member_file_name
))
11866 /* Close previous file and discard cached information. */
11867 if (nested_arch
->file
!= NULL
)
11868 fclose (nested_arch
->file
);
11869 release_archive (nested_arch
);
11871 member_file
= fopen (member_file_name
, "rb");
11872 if (member_file
== NULL
)
11874 return setup_archive (nested_arch
, member_file_name
, member_file
, FALSE
, FALSE
);
11878 get_archive_member_name_at (struct archive_info
* arch
,
11879 unsigned long offset
,
11880 struct archive_info
* nested_arch
);
11882 /* Get the name of an archive member from the current archive header.
11883 For simple names, this will modify the ar_name field of the current
11884 archive header. For long names, it will return a pointer to the
11885 longnames table. For nested archives, it will open the nested archive
11886 and get the name recursively. NESTED_ARCH is a single-entry cache so
11887 we don't keep rereading the same information from a nested archive. */
11890 get_archive_member_name (struct archive_info
* arch
,
11891 struct archive_info
* nested_arch
)
11893 unsigned long j
, k
;
11895 if (arch
->arhdr
.ar_name
[0] == '/')
11897 /* We have a long name. */
11899 char * member_file_name
;
11900 char * member_name
;
11902 arch
->nested_member_origin
= 0;
11903 k
= j
= strtoul (arch
->arhdr
.ar_name
+ 1, &endp
, 10);
11904 if (arch
->is_thin_archive
&& endp
!= NULL
&& * endp
== ':')
11905 arch
->nested_member_origin
= strtoul (endp
+ 1, NULL
, 10);
11907 while ((j
< arch
->longnames_size
)
11908 && (arch
->longnames
[j
] != '\n')
11909 && (arch
->longnames
[j
] != '\0'))
11911 if (arch
->longnames
[j
-1] == '/')
11913 arch
->longnames
[j
] = '\0';
11915 if (!arch
->is_thin_archive
|| arch
->nested_member_origin
== 0)
11916 return arch
->longnames
+ k
;
11918 /* This is a proxy for a member of a nested archive.
11919 Find the name of the member in that archive. */
11920 member_file_name
= adjust_relative_path (arch
->file_name
, arch
->longnames
+ k
, j
- k
);
11921 if (member_file_name
!= NULL
11922 && setup_nested_archive (nested_arch
, member_file_name
) == 0
11923 && (member_name
= get_archive_member_name_at (nested_arch
, arch
->nested_member_origin
, NULL
)) != NULL
)
11925 free (member_file_name
);
11926 return member_name
;
11928 free (member_file_name
);
11930 /* Last resort: just return the name of the nested archive. */
11931 return arch
->longnames
+ k
;
11934 /* We have a normal (short) name. */
11936 while ((arch
->arhdr
.ar_name
[j
] != '/') && (j
< 16))
11938 arch
->arhdr
.ar_name
[j
] = '\0';
11939 return arch
->arhdr
.ar_name
;
11942 /* Get the name of an archive member at a given OFFSET within an archive ARCH. */
11945 get_archive_member_name_at (struct archive_info
* arch
,
11946 unsigned long offset
,
11947 struct archive_info
* nested_arch
)
11951 if (fseek (arch
->file
, offset
, SEEK_SET
) != 0)
11953 error (_("%s: failed to seek to next file name\n"), arch
->file_name
);
11956 got
= fread (&arch
->arhdr
, 1, sizeof arch
->arhdr
, arch
->file
);
11957 if (got
!= sizeof arch
->arhdr
)
11959 error (_("%s: failed to read archive header\n"), arch
->file_name
);
11962 if (memcmp (arch
->arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
11964 error (_("%s: did not find a valid archive header\n"), arch
->file_name
);
11968 return get_archive_member_name (arch
, nested_arch
);
11971 /* Construct a string showing the name of the archive member, qualified
11972 with the name of the containing archive file. For thin archives, we
11973 use square brackets to denote the indirection. For nested archives,
11974 we show the qualified name of the external member inside the square
11975 brackets (e.g., "thin.a[normal.a(foo.o)]"). */
11978 make_qualified_name (struct archive_info
* arch
,
11979 struct archive_info
* nested_arch
,
11980 char * member_name
)
11985 len
= strlen (arch
->file_name
) + strlen (member_name
) + 3;
11986 if (arch
->is_thin_archive
&& arch
->nested_member_origin
!= 0)
11987 len
+= strlen (nested_arch
->file_name
) + 2;
11989 name
= (char *) malloc (len
);
11992 error (_("Out of memory\n"));
11996 if (arch
->is_thin_archive
&& arch
->nested_member_origin
!= 0)
11997 snprintf (name
, len
, "%s[%s(%s)]", arch
->file_name
, nested_arch
->file_name
, member_name
);
11998 else if (arch
->is_thin_archive
)
11999 snprintf (name
, len
, "%s[%s]", arch
->file_name
, member_name
);
12001 snprintf (name
, len
, "%s(%s)", arch
->file_name
, member_name
);
12006 /* Process an ELF archive.
12007 On entry the file is positioned just after the ARMAG string. */
12010 process_archive (char * file_name
, FILE * file
, bfd_boolean is_thin_archive
)
12012 struct archive_info arch
;
12013 struct archive_info nested_arch
;
12015 size_t file_name_size
;
12020 /* The ARCH structure is used to hold information about this archive. */
12021 arch
.file_name
= NULL
;
12023 arch
.index_array
= NULL
;
12024 arch
.sym_table
= NULL
;
12025 arch
.longnames
= NULL
;
12027 /* The NESTED_ARCH structure is used as a single-item cache of information
12028 about a nested archive (when members of a thin archive reside within
12029 another regular archive file). */
12030 nested_arch
.file_name
= NULL
;
12031 nested_arch
.file
= NULL
;
12032 nested_arch
.index_array
= NULL
;
12033 nested_arch
.sym_table
= NULL
;
12034 nested_arch
.longnames
= NULL
;
12036 if (setup_archive (&arch
, file_name
, file
, is_thin_archive
, do_archive_index
) != 0)
12042 if (do_archive_index
)
12044 if (arch
.sym_table
== NULL
)
12045 error (_("%s: unable to dump the index as none was found\n"), file_name
);
12049 unsigned long current_pos
;
12051 printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
12052 file_name
, arch
.index_num
, arch
.sym_size
);
12053 current_pos
= ftell (file
);
12055 for (i
= l
= 0; i
< arch
.index_num
; i
++)
12057 if ((i
== 0) || ((i
> 0) && (arch
.index_array
[i
] != arch
.index_array
[i
- 1])))
12059 char * member_name
;
12061 member_name
= get_archive_member_name_at (&arch
, arch
.index_array
[i
], &nested_arch
);
12063 if (member_name
!= NULL
)
12065 char * qualified_name
= make_qualified_name (&arch
, &nested_arch
, member_name
);
12067 if (qualified_name
!= NULL
)
12069 printf (_("Binary %s contains:\n"), qualified_name
);
12070 free (qualified_name
);
12075 if (l
>= arch
.sym_size
)
12077 error (_("%s: end of the symbol table reached before the end of the index\n"),
12081 printf ("\t%s\n", arch
.sym_table
+ l
);
12082 l
+= strlen (arch
.sym_table
+ l
) + 1;
12087 if (l
< arch
.sym_size
)
12088 error (_("%s: symbols remain in the index symbol table, but without corresponding entries in the index table\n"),
12091 if (fseek (file
, current_pos
, SEEK_SET
) != 0)
12093 error (_("%s: failed to seek back to start of object files in the archive\n"), file_name
);
12099 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
12100 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
12101 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
12102 && !do_section_groups
&& !do_dyn_syms
)
12104 ret
= 0; /* Archive index only. */
12109 file_name_size
= strlen (file_name
);
12116 char * qualified_name
;
12118 /* Read the next archive header. */
12119 if (fseek (file
, arch
.next_arhdr_offset
, SEEK_SET
) != 0)
12121 error (_("%s: failed to seek to next archive header\n"), file_name
);
12124 got
= fread (&arch
.arhdr
, 1, sizeof arch
.arhdr
, file
);
12125 if (got
!= sizeof arch
.arhdr
)
12129 error (_("%s: failed to read archive header\n"), file_name
);
12133 if (memcmp (arch
.arhdr
.ar_fmag
, ARFMAG
, 2) != 0)
12135 error (_("%s: did not find a valid archive header\n"), arch
.file_name
);
12140 arch
.next_arhdr_offset
+= sizeof arch
.arhdr
;
12142 archive_file_size
= strtoul (arch
.arhdr
.ar_size
, NULL
, 10);
12143 if (archive_file_size
& 01)
12144 ++archive_file_size
;
12146 name
= get_archive_member_name (&arch
, &nested_arch
);
12149 error (_("%s: bad archive file name\n"), file_name
);
12153 namelen
= strlen (name
);
12155 qualified_name
= make_qualified_name (&arch
, &nested_arch
, name
);
12156 if (qualified_name
== NULL
)
12158 error (_("%s: bad archive file name\n"), file_name
);
12163 if (is_thin_archive
&& arch
.nested_member_origin
== 0)
12165 /* This is a proxy for an external member of a thin archive. */
12166 FILE * member_file
;
12167 char * member_file_name
= adjust_relative_path (file_name
, name
, namelen
);
12168 if (member_file_name
== NULL
)
12174 member_file
= fopen (member_file_name
, "rb");
12175 if (member_file
== NULL
)
12177 error (_("Input file '%s' is not readable.\n"), member_file_name
);
12178 free (member_file_name
);
12183 archive_file_offset
= arch
.nested_member_origin
;
12185 ret
|= process_object (qualified_name
, member_file
);
12187 fclose (member_file
);
12188 free (member_file_name
);
12190 else if (is_thin_archive
)
12192 /* This is a proxy for a member of a nested archive. */
12193 archive_file_offset
= arch
.nested_member_origin
+ sizeof arch
.arhdr
;
12195 /* The nested archive file will have been opened and setup by
12196 get_archive_member_name. */
12197 if (fseek (nested_arch
.file
, archive_file_offset
, SEEK_SET
) != 0)
12199 error (_("%s: failed to seek to archive member.\n"), nested_arch
.file_name
);
12204 ret
|= process_object (qualified_name
, nested_arch
.file
);
12208 archive_file_offset
= arch
.next_arhdr_offset
;
12209 arch
.next_arhdr_offset
+= archive_file_size
;
12211 ret
|= process_object (qualified_name
, file
);
12214 free (qualified_name
);
12218 if (nested_arch
.file
!= NULL
)
12219 fclose (nested_arch
.file
);
12220 release_archive (&nested_arch
);
12221 release_archive (&arch
);
12227 process_file (char * file_name
)
12230 struct stat statbuf
;
12231 char armag
[SARMAG
];
12234 if (stat (file_name
, &statbuf
) < 0)
12236 if (errno
== ENOENT
)
12237 error (_("'%s': No such file\n"), file_name
);
12239 error (_("Could not locate '%s'. System error message: %s\n"),
12240 file_name
, strerror (errno
));
12244 if (! S_ISREG (statbuf
.st_mode
))
12246 error (_("'%s' is not an ordinary file\n"), file_name
);
12250 file
= fopen (file_name
, "rb");
12253 error (_("Input file '%s' is not readable.\n"), file_name
);
12257 if (fread (armag
, SARMAG
, 1, file
) != 1)
12259 error (_("%s: Failed to read file's magic number\n"), file_name
);
12264 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
12265 ret
= process_archive (file_name
, file
, FALSE
);
12266 else if (memcmp (armag
, ARMAGT
, SARMAG
) == 0)
12267 ret
= process_archive (file_name
, file
, TRUE
);
12270 if (do_archive_index
)
12271 error (_("File %s is not an archive so its index cannot be displayed.\n"),
12275 archive_file_size
= archive_file_offset
= 0;
12276 ret
= process_object (file_name
, file
);
12284 #ifdef SUPPORT_DISASSEMBLY
12285 /* Needed by the i386 disassembler. For extra credit, someone could
12286 fix this so that we insert symbolic addresses here, esp for GOT/PLT
12290 print_address (unsigned int addr
, FILE * outfile
)
12292 fprintf (outfile
,"0x%8.8x", addr
);
12295 /* Needed by the i386 disassembler. */
12297 db_task_printsym (unsigned int addr
)
12299 print_address (addr
, stderr
);
12304 main (int argc
, char ** argv
)
12308 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
12309 setlocale (LC_MESSAGES
, "");
12311 #if defined (HAVE_SETLOCALE)
12312 setlocale (LC_CTYPE
, "");
12314 bindtextdomain (PACKAGE
, LOCALEDIR
);
12315 textdomain (PACKAGE
);
12317 expandargv (&argc
, &argv
);
12319 parse_args (argc
, argv
);
12321 if (num_dump_sects
> 0)
12323 /* Make a copy of the dump_sects array. */
12324 cmdline_dump_sects
= (dump_type
*)
12325 malloc (num_dump_sects
* sizeof (* dump_sects
));
12326 if (cmdline_dump_sects
== NULL
)
12327 error (_("Out of memory allocating dump request table.\n"));
12330 memcpy (cmdline_dump_sects
, dump_sects
,
12331 num_dump_sects
* sizeof (* dump_sects
));
12332 num_cmdline_dump_sects
= num_dump_sects
;
12336 if (optind
< (argc
- 1))
12340 while (optind
< argc
)
12341 err
|= process_file (argv
[optind
++]);
12343 if (dump_sects
!= NULL
)
12345 if (cmdline_dump_sects
!= NULL
)
12346 free (cmdline_dump_sects
);