1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 /* The difference between readelf and objdump:
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
45 #include <sys/types.h>
51 /* Define BFD64 here, even if our default architecture is 32 bit ELF
52 as this will allow us to read in and parse 64bit and 32bit ELF files.
53 Only do this if we believe that the compiler can support a 64 bit
54 data type. For now we only rely on GCC being able to do this. */
60 #include "elf/common.h"
61 #include "elf/external.h"
62 #include "elf/internal.h"
64 /* The following headers use the elf/reloc-macros.h file to
65 automatically generate relocation recognition functions
66 such as elf_mips_reloc_type() */
68 #define RELOC_MACROS_GEN_FUNC
70 #include "elf/alpha.h"
92 #include "elf/m68hc11.h"
93 #include "elf/mcore.h"
96 #include "elf/mn10200.h"
97 #include "elf/mn10300.h"
99 #include "elf/msp430.h"
100 #include "elf/or32.h"
103 #include "elf/ppc64.h"
104 #include "elf/s390.h"
106 #include "elf/sparc.h"
107 #include "elf/v850.h"
109 #include "elf/x86-64.h"
110 #include "elf/xstormy16.h"
112 #include "elf/iq2000.h"
113 #include "elf/xtensa.h"
119 #include "libiberty.h"
121 char *program_name
= "readelf";
122 static long archive_file_offset
;
123 static unsigned long archive_file_size
;
124 static unsigned long dynamic_addr
;
125 static bfd_size_type dynamic_size
;
126 static unsigned int dynamic_nent
;
127 static char *dynamic_strings
;
128 static unsigned long dynamic_strings_length
;
129 static char *string_table
;
130 static unsigned long string_table_length
;
131 static unsigned long num_dynamic_syms
;
132 static Elf_Internal_Sym
*dynamic_symbols
;
133 static Elf_Internal_Syminfo
*dynamic_syminfo
;
134 static unsigned long dynamic_syminfo_offset
;
135 static unsigned int dynamic_syminfo_nent
;
136 static char program_interpreter
[64];
137 static bfd_vma dynamic_info
[DT_JMPREL
+ 1];
138 static bfd_vma version_info
[16];
139 static Elf_Internal_Ehdr elf_header
;
140 static Elf_Internal_Shdr
*section_headers
;
141 static Elf_Internal_Phdr
*program_headers
;
142 static Elf_Internal_Dyn
*dynamic_section
;
143 static Elf_Internal_Shdr
*symtab_shndx_hdr
;
144 static int show_name
;
145 static int do_dynamic
;
148 static int do_sections
;
149 static int do_section_groups
;
150 static int do_section_details
;
151 static int do_segments
;
152 static int do_unwind
;
153 static int do_using_dynamic
;
154 static int do_header
;
156 static int do_version
;
158 static int do_histogram
;
159 static int do_debugging
;
162 static int is_32bit_elf
;
166 struct group_list
*next
;
167 unsigned int section_index
;
172 struct group_list
*root
;
173 unsigned int group_index
;
176 static size_t group_count
;
177 static struct group
*section_groups
;
178 static struct group
**section_headers_groups
;
180 /* A dynamic array of flags indicating for which sections a hex dump
181 has been requested (via the -x switch) and/or a disassembly dump
182 (via the -i switch). */
183 char *cmdline_dump_sects
= NULL
;
184 unsigned num_cmdline_dump_sects
= 0;
186 /* A dynamic array of flags indicating for which sections a dump of
187 some kind has been requested. It is reset on a per-object file
188 basis and then initialised from the cmdline_dump_sects array and
189 the results of interpreting the -w switch. */
190 char *dump_sects
= NULL
;
191 unsigned int num_dump_sects
= 0;
193 #define HEX_DUMP (1 << 0)
194 #define DISASS_DUMP (1 << 1)
195 #define DEBUG_DUMP (1 << 2)
197 /* How to print a vma value. */
198 typedef enum print_mode
210 static void (*byte_put
) (unsigned char *, bfd_vma
, int);
214 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
215 ((X)->sh_name >= string_table_length \
216 ? "<corrupt>" : string_table + (X)->sh_name))
218 /* Given st_shndx I, map to section_headers index. */
219 #define SECTION_HEADER_INDEX(I) \
220 ((I) < SHN_LORESERVE \
222 : ((I) <= SHN_HIRESERVE \
224 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
226 /* Reverse of the above. */
227 #define SECTION_HEADER_NUM(N) \
228 ((N) < SHN_LORESERVE \
230 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
232 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
234 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
236 #define BYTE_GET(field) byte_get (field, sizeof (field))
238 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
240 #define GET_ELF_SYMBOLS(file, section) \
241 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
242 : get_64bit_elf_symbols (file, section))
244 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
245 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
246 already been called and verified that the string exists. */
247 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
249 /* This is just a bit of syntatic sugar. */
250 #define streq(a,b) (strcmp ((a), (b)) == 0)
251 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
254 get_data (void *var
, FILE *file
, long offset
, size_t size
, size_t nmemb
,
259 if (size
== 0 || nmemb
== 0)
262 if (fseek (file
, archive_file_offset
+ offset
, SEEK_SET
))
264 error (_("Unable to seek to 0x%lx for %s\n"),
265 archive_file_offset
+ offset
, reason
);
272 /* Check for overflow. */
273 if (nmemb
< (~(size_t) 0 - 1) / size
)
274 /* + 1 so that we can '\0' terminate invalid string table sections. */
275 mvar
= malloc (size
* nmemb
+ 1);
279 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
280 (unsigned long)(size
* nmemb
), reason
);
284 ((char *) mvar
)[size
* nmemb
] = '\0';
287 if (fread (mvar
, size
, nmemb
, file
) != nmemb
)
289 error (_("Unable to read in 0x%lx bytes of %s\n"),
290 (unsigned long)(size
* nmemb
), reason
);
300 byte_put_little_endian (unsigned char *field
, bfd_vma value
, int size
)
305 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
306 field
[6] = ((value
>> 24) >> 24) & 0xff;
307 field
[5] = ((value
>> 24) >> 16) & 0xff;
308 field
[4] = ((value
>> 24) >> 8) & 0xff;
311 field
[3] = (value
>> 24) & 0xff;
312 field
[2] = (value
>> 16) & 0xff;
315 field
[1] = (value
>> 8) & 0xff;
318 field
[0] = value
& 0xff;
322 error (_("Unhandled data length: %d\n"), size
);
327 #if defined BFD64 && !BFD_HOST_64BIT_LONG
329 print_dec_vma (bfd_vma vma
, int is_signed
)
335 if (is_signed
&& (bfd_signed_vma
) vma
< 0)
344 *bufp
++ = '0' + vma
% 10;
356 print_hex_vma (bfd_vma vma
)
364 char digit
= '0' + (vma
& 0x0f);
366 digit
+= 'a' - '0' - 10;
379 /* Print a VMA value. */
381 print_vma (bfd_vma vma
, print_mode mode
)
390 return printf ("0x%8.8lx", (unsigned long) vma
);
393 return printf ("%8.8lx", (unsigned long) vma
);
397 return printf ("%5ld", (long) vma
);
401 return printf ("0x%lx", (unsigned long) vma
);
404 return printf ("%lx", (unsigned long) vma
);
407 return printf ("%ld", (unsigned long) vma
);
410 return printf ("%lu", (unsigned long) vma
);
433 #if BFD_HOST_64BIT_LONG
434 return nc
+ printf ("%lx", vma
);
436 return nc
+ print_hex_vma (vma
);
440 #if BFD_HOST_64BIT_LONG
441 return printf ("%ld", vma
);
443 return print_dec_vma (vma
, 1);
447 #if BFD_HOST_64BIT_LONG
449 return printf ("%5ld", vma
);
451 return printf ("%#lx", vma
);
454 return printf ("%5ld", _bfd_int64_low (vma
));
456 return print_hex_vma (vma
);
460 #if BFD_HOST_64BIT_LONG
461 return printf ("%lu", vma
);
463 return print_dec_vma (vma
, 0);
471 /* Display a symbol on stdout. If do_wide is not true then
472 format the symbol to be at most WIDTH characters,
473 truncating as necessary. If WIDTH is negative then
474 format the string to be exactly - WIDTH characters,
475 truncating or padding as necessary. */
478 print_symbol (int width
, const char *symbol
)
481 printf ("%s", symbol
);
483 printf ("%-*.*s", width
, width
, symbol
);
485 printf ("%-.*s", width
, symbol
);
489 byte_put_big_endian (unsigned char *field
, bfd_vma value
, int size
)
494 field
[7] = value
& 0xff;
495 field
[6] = (value
>> 8) & 0xff;
496 field
[5] = (value
>> 16) & 0xff;
497 field
[4] = (value
>> 24) & 0xff;
502 field
[3] = value
& 0xff;
503 field
[2] = (value
>> 8) & 0xff;
507 field
[1] = value
& 0xff;
511 field
[0] = value
& 0xff;
515 error (_("Unhandled data length: %d\n"), size
);
520 /* Return a pointer to section NAME, or NULL if no such section exists. */
522 static Elf_Internal_Shdr
*
523 find_section (const char *name
)
527 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
528 if (streq (SECTION_NAME (section_headers
+ i
), name
))
529 return section_headers
+ i
;
534 /* Guess the relocation size commonly used by the specific machines. */
537 guess_is_rela (unsigned long e_machine
)
541 /* Targets that use REL relocations. */
556 /* Targets that use RELA relocations. */
571 case EM_CYGNUS_MN10200
:
573 case EM_CYGNUS_MN10300
:
623 warn (_("Don't know about relocations on this machine architecture\n"));
629 slurp_rela_relocs (FILE *file
,
630 unsigned long rel_offset
,
631 unsigned long rel_size
,
632 Elf_Internal_Rela
**relasp
,
633 unsigned long *nrelasp
)
635 Elf_Internal_Rela
*relas
;
636 unsigned long nrelas
;
641 Elf32_External_Rela
*erelas
;
643 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
647 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
649 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
654 error (_("out of memory parsing relocs"));
658 for (i
= 0; i
< nrelas
; i
++)
660 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
661 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
662 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
669 Elf64_External_Rela
*erelas
;
671 erelas
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
675 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
677 relas
= cmalloc (nrelas
, sizeof (Elf_Internal_Rela
));
682 error (_("out of memory parsing relocs"));
686 for (i
= 0; i
< nrelas
; i
++)
688 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
689 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
690 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
701 slurp_rel_relocs (FILE *file
,
702 unsigned long rel_offset
,
703 unsigned long rel_size
,
704 Elf_Internal_Rela
**relsp
,
705 unsigned long *nrelsp
)
707 Elf_Internal_Rela
*rels
;
713 Elf32_External_Rel
*erels
;
715 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
719 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
721 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
726 error (_("out of memory parsing relocs"));
730 for (i
= 0; i
< nrels
; i
++)
732 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
733 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
734 rels
[i
].r_addend
= 0;
741 Elf64_External_Rel
*erels
;
743 erels
= get_data (NULL
, file
, rel_offset
, 1, rel_size
, _("relocs"));
747 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
749 rels
= cmalloc (nrels
, sizeof (Elf_Internal_Rela
));
754 error (_("out of memory parsing relocs"));
758 for (i
= 0; i
< nrels
; i
++)
760 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
761 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
762 rels
[i
].r_addend
= 0;
772 /* Display the contents of the relocation data found at the specified
776 dump_relocations (FILE *file
,
777 unsigned long rel_offset
,
778 unsigned long rel_size
,
779 Elf_Internal_Sym
*symtab
,
782 unsigned long strtablen
,
786 Elf_Internal_Rela
*rels
;
789 if (is_rela
== UNKNOWN
)
790 is_rela
= guess_is_rela (elf_header
.e_machine
);
794 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
799 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
808 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
810 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
815 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
817 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
825 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
827 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
832 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
834 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
838 for (i
= 0; i
< rel_size
; i
++)
841 const char *rtype2
= NULL
;
842 const char *rtype3
= NULL
;
845 bfd_vma symtab_index
;
850 offset
= rels
[i
].r_offset
;
851 info
= rels
[i
].r_info
;
855 type
= ELF32_R_TYPE (info
);
856 symtab_index
= ELF32_R_SYM (info
);
860 /* The #ifdef BFD64 below is to prevent a compile time warning.
861 We know that if we do not have a 64 bit data type that we
862 will never execute this code anyway. */
864 if (elf_header
.e_machine
== EM_MIPS
)
866 /* In little-endian objects, r_info isn't really a 64-bit
867 little-endian value: it has a 32-bit little-endian
868 symbol index followed by four individual byte fields.
869 Reorder INFO accordingly. */
870 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
871 info
= (((info
& 0xffffffff) << 32)
872 | ((info
>> 56) & 0xff)
873 | ((info
>> 40) & 0xff00)
874 | ((info
>> 24) & 0xff0000)
875 | ((info
>> 8) & 0xff000000));
876 type
= ELF64_MIPS_R_TYPE (info
);
877 type2
= ELF64_MIPS_R_TYPE2 (info
);
878 type3
= ELF64_MIPS_R_TYPE3 (info
);
880 else if (elf_header
.e_machine
== EM_SPARCV9
)
881 type
= ELF64_R_TYPE_ID (info
);
883 type
= ELF64_R_TYPE (info
);
885 symtab_index
= ELF64_R_SYM (info
);
891 #ifdef _bfd_int64_low
892 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
894 printf ("%8.8lx %8.8lx ", offset
, info
);
899 #ifdef _bfd_int64_low
901 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
902 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
903 _bfd_int64_high (offset
),
904 _bfd_int64_low (offset
),
905 _bfd_int64_high (info
),
906 _bfd_int64_low (info
));
909 ? "%16.16lx %16.16lx "
910 : "%12.12lx %12.12lx ",
915 switch (elf_header
.e_machine
)
923 rtype
= elf_m32r_reloc_type (type
);
928 rtype
= elf_i386_reloc_type (type
);
933 rtype
= elf_m68hc11_reloc_type (type
);
937 rtype
= elf_m68k_reloc_type (type
);
941 rtype
= elf_i960_reloc_type (type
);
946 rtype
= elf_avr_reloc_type (type
);
953 rtype
= elf_sparc_reloc_type (type
);
958 rtype
= v850_reloc_type (type
);
963 rtype
= elf_d10v_reloc_type (type
);
968 rtype
= elf_d30v_reloc_type (type
);
972 rtype
= elf_dlx_reloc_type (type
);
976 rtype
= elf_sh_reloc_type (type
);
980 case EM_CYGNUS_MN10300
:
981 rtype
= elf_mn10300_reloc_type (type
);
985 case EM_CYGNUS_MN10200
:
986 rtype
= elf_mn10200_reloc_type (type
);
991 rtype
= elf_fr30_reloc_type (type
);
995 rtype
= elf_frv_reloc_type (type
);
999 rtype
= elf_mcore_reloc_type (type
);
1003 rtype
= elf_mmix_reloc_type (type
);
1008 rtype
= elf_msp430_reloc_type (type
);
1012 rtype
= elf_ppc_reloc_type (type
);
1016 rtype
= elf_ppc64_reloc_type (type
);
1020 case EM_MIPS_RS3_LE
:
1021 rtype
= elf_mips_reloc_type (type
);
1024 rtype2
= elf_mips_reloc_type (type2
);
1025 rtype3
= elf_mips_reloc_type (type3
);
1030 rtype
= elf_alpha_reloc_type (type
);
1034 rtype
= elf_arm_reloc_type (type
);
1038 rtype
= elf_arc_reloc_type (type
);
1042 rtype
= elf_hppa_reloc_type (type
);
1048 rtype
= elf_h8_reloc_type (type
);
1053 rtype
= elf_or32_reloc_type (type
);
1058 rtype
= elf_pj_reloc_type (type
);
1061 rtype
= elf_ia64_reloc_type (type
);
1065 rtype
= elf_cris_reloc_type (type
);
1069 rtype
= elf_i860_reloc_type (type
);
1073 rtype
= elf_x86_64_reloc_type (type
);
1077 rtype
= i370_reloc_type (type
);
1082 rtype
= elf_s390_reloc_type (type
);
1086 rtype
= elf_xstormy16_reloc_type (type
);
1090 rtype
= elf_crx_reloc_type (type
);
1094 rtype
= elf_vax_reloc_type (type
);
1099 rtype
= elf_ip2k_reloc_type (type
);
1103 rtype
= elf_iq2000_reloc_type (type
);
1108 rtype
= elf_xtensa_reloc_type (type
);
1112 rtype
= elf_m32c_reloc_type (type
);
1116 rtype
= elf_ms1_reloc_type (type
);
1120 rtype
= elf_bfin_reloc_type (type
);
1126 #ifdef _bfd_int64_low
1127 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1129 printf (_("unrecognized: %-7lx"), type
);
1132 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1134 if (elf_header
.e_machine
== EM_ALPHA
1135 && streq (rtype
, "R_ALPHA_LITUSE")
1138 switch (rels
[i
].r_addend
)
1140 case LITUSE_ALPHA_ADDR
: rtype
= "ADDR"; break;
1141 case LITUSE_ALPHA_BASE
: rtype
= "BASE"; break;
1142 case LITUSE_ALPHA_BYTOFF
: rtype
= "BYTOFF"; break;
1143 case LITUSE_ALPHA_JSR
: rtype
= "JSR"; break;
1144 case LITUSE_ALPHA_TLSGD
: rtype
= "TLSGD"; break;
1145 case LITUSE_ALPHA_TLSLDM
: rtype
= "TLSLDM"; break;
1146 case LITUSE_ALPHA_JSRDIRECT
: rtype
= "JSRDIRECT"; break;
1147 default: rtype
= NULL
;
1150 printf (" (%s)", rtype
);
1154 printf (_("<unknown addend: %lx>"),
1155 (unsigned long) rels
[i
].r_addend
);
1158 else if (symtab_index
)
1160 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1161 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1164 Elf_Internal_Sym
*psym
;
1166 psym
= symtab
+ symtab_index
;
1169 print_vma (psym
->st_value
, LONG_HEX
);
1170 printf (is_32bit_elf
? " " : " ");
1172 if (psym
->st_name
== 0)
1174 const char *sec_name
= "<null>";
1177 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1179 bfd_vma sec_index
= (bfd_vma
) -1;
1181 if (psym
->st_shndx
< SHN_LORESERVE
)
1182 sec_index
= psym
->st_shndx
;
1183 else if (psym
->st_shndx
> SHN_HIRESERVE
)
1184 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1187 if (sec_index
!= (bfd_vma
) -1)
1188 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1189 else if (psym
->st_shndx
== SHN_ABS
)
1191 else if (psym
->st_shndx
== SHN_COMMON
)
1192 sec_name
= "COMMON";
1193 else if (elf_header
.e_machine
== EM_X86_64
1194 && psym
->st_shndx
== SHN_X86_64_LCOMMON
)
1195 sec_name
= "LARGE_COMMON";
1196 else if (elf_header
.e_machine
== EM_IA_64
1197 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
1198 && psym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
1199 sec_name
= "ANSI_COM";
1202 sprintf (name_buf
, "<section 0x%x>",
1203 (unsigned int) psym
->st_shndx
);
1204 sec_name
= name_buf
;
1207 print_symbol (22, sec_name
);
1209 else if (strtab
== NULL
)
1210 printf (_("<string table index: %3ld>"), psym
->st_name
);
1211 else if (psym
->st_name
>= strtablen
)
1212 printf (_("<corrupt string table index: %3ld>"), psym
->st_name
);
1214 print_symbol (22, strtab
+ psym
->st_name
);
1217 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1222 printf ("%*c", is_32bit_elf
?
1223 (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1224 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1227 if (elf_header
.e_machine
== EM_SPARCV9
&& streq (rtype
, "R_SPARC_OLO10"))
1228 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1232 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1234 printf (" Type2: ");
1237 #ifdef _bfd_int64_low
1238 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1240 printf (_("unrecognized: %-7lx"), type2
);
1243 printf ("%-17.17s", rtype2
);
1245 printf ("\n Type3: ");
1248 #ifdef _bfd_int64_low
1249 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1251 printf (_("unrecognized: %-7lx"), type3
);
1254 printf ("%-17.17s", rtype3
);
1266 get_mips_dynamic_type (unsigned long type
)
1270 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1271 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1272 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1273 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1274 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1275 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1276 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1277 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1278 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1279 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1280 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1281 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1282 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1283 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1284 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1285 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1286 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1287 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1288 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1289 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1290 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1291 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1292 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1293 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1294 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1295 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1296 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1297 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1298 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1299 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1300 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1301 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1302 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1303 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1304 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1305 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1306 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1307 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1308 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1309 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1310 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1311 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1312 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1319 get_sparc64_dynamic_type (unsigned long type
)
1323 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1330 get_ppc_dynamic_type (unsigned long type
)
1334 case DT_PPC_GOT
: return "PPC_GOT";
1341 get_ppc64_dynamic_type (unsigned long type
)
1345 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1346 case DT_PPC64_OPD
: return "PPC64_OPD";
1347 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1354 get_parisc_dynamic_type (unsigned long type
)
1358 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1359 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1360 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1361 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1362 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1363 case DT_HP_PREINIT
: return "HP_PREINIT";
1364 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1365 case DT_HP_NEEDED
: return "HP_NEEDED";
1366 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1367 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1368 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1369 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1370 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1371 case DT_HP_EPLTREL
: return "HP_GST_EPLTREL";
1372 case DT_HP_EPLTRELSZ
: return "HP_GST_EPLTRELSZ";
1373 case DT_HP_FILTERED
: return "HP_FILTERED";
1374 case DT_HP_FILTER_TLS
: return "HP_FILTER_TLS";
1375 case DT_HP_COMPAT_FILTERED
: return "HP_COMPAT_FILTERED";
1376 case DT_HP_LAZYLOAD
: return "HP_LAZYLOAD";
1377 case DT_HP_BIND_NOW_COUNT
: return "HP_BIND_NOW_COUNT";
1378 case DT_PLT
: return "PLT";
1379 case DT_PLT_SIZE
: return "PLT_SIZE";
1380 case DT_DLT
: return "DLT";
1381 case DT_DLT_SIZE
: return "DLT_SIZE";
1388 get_ia64_dynamic_type (unsigned long type
)
1392 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1399 get_alpha_dynamic_type (unsigned long type
)
1403 case DT_ALPHA_PLTRO
: return "ALPHA_PLTRO";
1410 get_dynamic_type (unsigned long type
)
1412 static char buff
[64];
1416 case DT_NULL
: return "NULL";
1417 case DT_NEEDED
: return "NEEDED";
1418 case DT_PLTRELSZ
: return "PLTRELSZ";
1419 case DT_PLTGOT
: return "PLTGOT";
1420 case DT_HASH
: return "HASH";
1421 case DT_STRTAB
: return "STRTAB";
1422 case DT_SYMTAB
: return "SYMTAB";
1423 case DT_RELA
: return "RELA";
1424 case DT_RELASZ
: return "RELASZ";
1425 case DT_RELAENT
: return "RELAENT";
1426 case DT_STRSZ
: return "STRSZ";
1427 case DT_SYMENT
: return "SYMENT";
1428 case DT_INIT
: return "INIT";
1429 case DT_FINI
: return "FINI";
1430 case DT_SONAME
: return "SONAME";
1431 case DT_RPATH
: return "RPATH";
1432 case DT_SYMBOLIC
: return "SYMBOLIC";
1433 case DT_REL
: return "REL";
1434 case DT_RELSZ
: return "RELSZ";
1435 case DT_RELENT
: return "RELENT";
1436 case DT_PLTREL
: return "PLTREL";
1437 case DT_DEBUG
: return "DEBUG";
1438 case DT_TEXTREL
: return "TEXTREL";
1439 case DT_JMPREL
: return "JMPREL";
1440 case DT_BIND_NOW
: return "BIND_NOW";
1441 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1442 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1443 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1444 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1445 case DT_RUNPATH
: return "RUNPATH";
1446 case DT_FLAGS
: return "FLAGS";
1448 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1449 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1451 case DT_CHECKSUM
: return "CHECKSUM";
1452 case DT_PLTPADSZ
: return "PLTPADSZ";
1453 case DT_MOVEENT
: return "MOVEENT";
1454 case DT_MOVESZ
: return "MOVESZ";
1455 case DT_FEATURE
: return "FEATURE";
1456 case DT_POSFLAG_1
: return "POSFLAG_1";
1457 case DT_SYMINSZ
: return "SYMINSZ";
1458 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1460 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1461 case DT_CONFIG
: return "CONFIG";
1462 case DT_DEPAUDIT
: return "DEPAUDIT";
1463 case DT_AUDIT
: return "AUDIT";
1464 case DT_PLTPAD
: return "PLTPAD";
1465 case DT_MOVETAB
: return "MOVETAB";
1466 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1468 case DT_VERSYM
: return "VERSYM";
1470 case DT_RELACOUNT
: return "RELACOUNT";
1471 case DT_RELCOUNT
: return "RELCOUNT";
1472 case DT_FLAGS_1
: return "FLAGS_1";
1473 case DT_VERDEF
: return "VERDEF";
1474 case DT_VERDEFNUM
: return "VERDEFNUM";
1475 case DT_VERNEED
: return "VERNEED";
1476 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1478 case DT_AUXILIARY
: return "AUXILIARY";
1479 case DT_USED
: return "USED";
1480 case DT_FILTER
: return "FILTER";
1482 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1483 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1484 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1485 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1486 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1489 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1493 switch (elf_header
.e_machine
)
1496 case EM_MIPS_RS3_LE
:
1497 result
= get_mips_dynamic_type (type
);
1500 result
= get_sparc64_dynamic_type (type
);
1503 result
= get_ppc_dynamic_type (type
);
1506 result
= get_ppc64_dynamic_type (type
);
1509 result
= get_ia64_dynamic_type (type
);
1512 result
= get_alpha_dynamic_type (type
);
1522 snprintf (buff
, sizeof (buff
), _("Processor Specific: %lx"), type
);
1524 else if (((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1525 || (elf_header
.e_machine
== EM_PARISC
1526 && (type
>= OLD_DT_LOOS
) && (type
<= OLD_DT_HIOS
)))
1530 switch (elf_header
.e_machine
)
1533 result
= get_parisc_dynamic_type (type
);
1543 snprintf (buff
, sizeof (buff
), _("Operating System specific: %lx"),
1547 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), type
);
1554 get_file_type (unsigned e_type
)
1556 static char buff
[32];
1560 case ET_NONE
: return _("NONE (None)");
1561 case ET_REL
: return _("REL (Relocatable file)");
1562 case ET_EXEC
: return _("EXEC (Executable file)");
1563 case ET_DYN
: return _("DYN (Shared object file)");
1564 case ET_CORE
: return _("CORE (Core file)");
1567 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1568 snprintf (buff
, sizeof (buff
), _("Processor Specific: (%x)"), e_type
);
1569 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1570 snprintf (buff
, sizeof (buff
), _("OS Specific: (%x)"), e_type
);
1572 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_type
);
1578 get_machine_name (unsigned e_machine
)
1580 static char buff
[64]; /* XXX */
1584 case EM_NONE
: return _("None");
1585 case EM_M32
: return "WE32100";
1586 case EM_SPARC
: return "Sparc";
1587 case EM_386
: return "Intel 80386";
1588 case EM_68K
: return "MC68000";
1589 case EM_88K
: return "MC88000";
1590 case EM_486
: return "Intel 80486";
1591 case EM_860
: return "Intel 80860";
1592 case EM_MIPS
: return "MIPS R3000";
1593 case EM_S370
: return "IBM System/370";
1594 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1595 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1596 case EM_PARISC
: return "HPPA";
1597 case EM_PPC_OLD
: return "Power PC (old)";
1598 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1599 case EM_960
: return "Intel 90860";
1600 case EM_PPC
: return "PowerPC";
1601 case EM_PPC64
: return "PowerPC64";
1602 case EM_V800
: return "NEC V800";
1603 case EM_FR20
: return "Fujitsu FR20";
1604 case EM_RH32
: return "TRW RH32";
1605 case EM_MCORE
: return "MCORE";
1606 case EM_ARM
: return "ARM";
1607 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1608 case EM_SH
: return "Renesas / SuperH SH";
1609 case EM_SPARCV9
: return "Sparc v9";
1610 case EM_TRICORE
: return "Siemens Tricore";
1611 case EM_ARC
: return "ARC";
1612 case EM_H8_300
: return "Renesas H8/300";
1613 case EM_H8_300H
: return "Renesas H8/300H";
1614 case EM_H8S
: return "Renesas H8S";
1615 case EM_H8_500
: return "Renesas H8/500";
1616 case EM_IA_64
: return "Intel IA-64";
1617 case EM_MIPS_X
: return "Stanford MIPS-X";
1618 case EM_COLDFIRE
: return "Motorola Coldfire";
1619 case EM_68HC12
: return "Motorola M68HC12";
1620 case EM_ALPHA
: return "Alpha";
1621 case EM_CYGNUS_D10V
:
1622 case EM_D10V
: return "d10v";
1623 case EM_CYGNUS_D30V
:
1624 case EM_D30V
: return "d30v";
1625 case EM_CYGNUS_M32R
:
1626 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1627 case EM_CYGNUS_V850
:
1628 case EM_V850
: return "NEC v850";
1629 case EM_CYGNUS_MN10300
:
1630 case EM_MN10300
: return "mn10300";
1631 case EM_CYGNUS_MN10200
:
1632 case EM_MN10200
: return "mn10200";
1633 case EM_CYGNUS_FR30
:
1634 case EM_FR30
: return "Fujitsu FR30";
1635 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1637 case EM_PJ
: return "picoJava";
1638 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1639 case EM_PCP
: return "Siemens PCP";
1640 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1641 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1642 case EM_STARCORE
: return "Motorola Star*Core processor";
1643 case EM_ME16
: return "Toyota ME16 processor";
1644 case EM_ST100
: return "STMicroelectronics ST100 processor";
1645 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1646 case EM_FX66
: return "Siemens FX66 microcontroller";
1647 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1648 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1649 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1650 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1651 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1652 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1653 case EM_SVX
: return "Silicon Graphics SVx";
1654 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1655 case EM_VAX
: return "Digital VAX";
1657 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1658 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1659 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1660 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1661 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1662 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1663 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1664 case EM_PRISM
: return "Vitesse Prism";
1665 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1667 case EM_S390
: return "IBM S/390";
1668 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1670 case EM_OR32
: return "OpenRISC";
1671 case EM_CRX
: return "National Semiconductor CRX microprocessor";
1672 case EM_DLX
: return "OpenDLX";
1674 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1675 case EM_IQ2000
: return "Vitesse IQ2000";
1677 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1678 case EM_M32C
: return "Renesas M32c";
1679 case EM_MS1
: return "Morpho Techologies MS1 processor";
1681 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), e_machine
);
1687 decode_ARM_machine_flags (unsigned e_flags
, char buf
[])
1692 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1693 e_flags
&= ~ EF_ARM_EABIMASK
;
1695 /* Handle "generic" ARM flags. */
1696 if (e_flags
& EF_ARM_RELEXEC
)
1698 strcat (buf
, ", relocatable executable");
1699 e_flags
&= ~ EF_ARM_RELEXEC
;
1702 if (e_flags
& EF_ARM_HASENTRY
)
1704 strcat (buf
, ", has entry point");
1705 e_flags
&= ~ EF_ARM_HASENTRY
;
1708 /* Now handle EABI specific flags. */
1712 strcat (buf
, ", <unrecognized EABI>");
1717 case EF_ARM_EABI_VER1
:
1718 strcat (buf
, ", Version1 EABI");
1723 /* Process flags one bit at a time. */
1724 flag
= e_flags
& - e_flags
;
1729 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1730 strcat (buf
, ", sorted symbol tables");
1740 case EF_ARM_EABI_VER2
:
1741 strcat (buf
, ", Version2 EABI");
1746 /* Process flags one bit at a time. */
1747 flag
= e_flags
& - e_flags
;
1752 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1753 strcat (buf
, ", sorted symbol tables");
1756 case EF_ARM_DYNSYMSUSESEGIDX
:
1757 strcat (buf
, ", dynamic symbols use segment index");
1760 case EF_ARM_MAPSYMSFIRST
:
1761 strcat (buf
, ", mapping symbols precede others");
1771 case EF_ARM_EABI_VER3
:
1772 strcat (buf
, ", Version3 EABI");
1775 case EF_ARM_EABI_VER4
:
1776 strcat (buf
, ", Version4 EABI");
1781 /* Process flags one bit at a time. */
1782 flag
= e_flags
& - e_flags
;
1788 strcat (buf
, ", BE8");
1792 strcat (buf
, ", LE8");
1802 case EF_ARM_EABI_UNKNOWN
:
1803 strcat (buf
, ", GNU EABI");
1808 /* Process flags one bit at a time. */
1809 flag
= e_flags
& - e_flags
;
1814 case EF_ARM_INTERWORK
:
1815 strcat (buf
, ", interworking enabled");
1818 case EF_ARM_APCS_26
:
1819 strcat (buf
, ", uses APCS/26");
1822 case EF_ARM_APCS_FLOAT
:
1823 strcat (buf
, ", uses APCS/float");
1827 strcat (buf
, ", position independent");
1831 strcat (buf
, ", 8 bit structure alignment");
1834 case EF_ARM_NEW_ABI
:
1835 strcat (buf
, ", uses new ABI");
1838 case EF_ARM_OLD_ABI
:
1839 strcat (buf
, ", uses old ABI");
1842 case EF_ARM_SOFT_FLOAT
:
1843 strcat (buf
, ", software FP");
1846 case EF_ARM_VFP_FLOAT
:
1847 strcat (buf
, ", VFP");
1850 case EF_ARM_MAVERICK_FLOAT
:
1851 strcat (buf
, ", Maverick FP");
1862 strcat (buf
,", <unknown>");
1866 get_machine_flags (unsigned e_flags
, unsigned e_machine
)
1868 static char buf
[1024];
1880 decode_ARM_machine_flags (e_flags
, buf
);
1884 switch (e_flags
& EF_FRV_CPU_MASK
)
1886 case EF_FRV_CPU_GENERIC
:
1890 strcat (buf
, ", fr???");
1893 case EF_FRV_CPU_FR300
:
1894 strcat (buf
, ", fr300");
1897 case EF_FRV_CPU_FR400
:
1898 strcat (buf
, ", fr400");
1900 case EF_FRV_CPU_FR405
:
1901 strcat (buf
, ", fr405");
1904 case EF_FRV_CPU_FR450
:
1905 strcat (buf
, ", fr450");
1908 case EF_FRV_CPU_FR500
:
1909 strcat (buf
, ", fr500");
1911 case EF_FRV_CPU_FR550
:
1912 strcat (buf
, ", fr550");
1915 case EF_FRV_CPU_SIMPLE
:
1916 strcat (buf
, ", simple");
1918 case EF_FRV_CPU_TOMCAT
:
1919 strcat (buf
, ", tomcat");
1925 if (e_flags
& EF_CPU32
)
1926 strcat (buf
, ", cpu32");
1927 if (e_flags
& EF_M68000
)
1928 strcat (buf
, ", m68000");
1932 if (e_flags
& EF_PPC_EMB
)
1933 strcat (buf
, ", emb");
1935 if (e_flags
& EF_PPC_RELOCATABLE
)
1936 strcat (buf
, ", relocatable");
1938 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1939 strcat (buf
, ", relocatable-lib");
1943 case EM_CYGNUS_V850
:
1944 switch (e_flags
& EF_V850_ARCH
)
1947 strcat (buf
, ", v850e1");
1950 strcat (buf
, ", v850e");
1953 strcat (buf
, ", v850");
1956 strcat (buf
, ", unknown v850 architecture variant");
1962 case EM_CYGNUS_M32R
:
1963 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1964 strcat (buf
, ", m32r");
1969 case EM_MIPS_RS3_LE
:
1970 if (e_flags
& EF_MIPS_NOREORDER
)
1971 strcat (buf
, ", noreorder");
1973 if (e_flags
& EF_MIPS_PIC
)
1974 strcat (buf
, ", pic");
1976 if (e_flags
& EF_MIPS_CPIC
)
1977 strcat (buf
, ", cpic");
1979 if (e_flags
& EF_MIPS_UCODE
)
1980 strcat (buf
, ", ugen_reserved");
1982 if (e_flags
& EF_MIPS_ABI2
)
1983 strcat (buf
, ", abi2");
1985 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
1986 strcat (buf
, ", odk first");
1988 if (e_flags
& EF_MIPS_32BITMODE
)
1989 strcat (buf
, ", 32bitmode");
1991 switch ((e_flags
& EF_MIPS_MACH
))
1993 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
1994 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
1995 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
1996 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
1997 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
1998 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
1999 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2000 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2001 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2002 case E_MIPS_MACH_9000
: strcat (buf
, ", 9000"); break;
2004 /* We simply ignore the field in this case to avoid confusion:
2005 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2008 default: strcat (buf
, ", unknown CPU"); break;
2011 switch ((e_flags
& EF_MIPS_ABI
))
2013 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2014 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2015 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2016 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2018 /* We simply ignore the field in this case to avoid confusion:
2019 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2020 This means it is likely to be an o32 file, but not for
2023 default: strcat (buf
, ", unknown ABI"); break;
2026 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2027 strcat (buf
, ", mdmx");
2029 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2030 strcat (buf
, ", mips16");
2032 switch ((e_flags
& EF_MIPS_ARCH
))
2034 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2035 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2036 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2037 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2038 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2039 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2040 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2041 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2042 case E_MIPS_ARCH_64R2
: strcat (buf
, ", mips64r2"); break;
2043 default: strcat (buf
, ", unknown ISA"); break;
2049 switch ((e_flags
& EF_SH_MACH_MASK
))
2051 case EF_SH1
: strcat (buf
, ", sh1"); break;
2052 case EF_SH2
: strcat (buf
, ", sh2"); break;
2053 case EF_SH3
: strcat (buf
, ", sh3"); break;
2054 case EF_SH_DSP
: strcat (buf
, ", sh-dsp"); break;
2055 case EF_SH3_DSP
: strcat (buf
, ", sh3-dsp"); break;
2056 case EF_SH4AL_DSP
: strcat (buf
, ", sh4al-dsp"); break;
2057 case EF_SH3E
: strcat (buf
, ", sh3e"); break;
2058 case EF_SH4
: strcat (buf
, ", sh4"); break;
2059 case EF_SH5
: strcat (buf
, ", sh5"); break;
2060 case EF_SH2E
: strcat (buf
, ", sh2e"); break;
2061 case EF_SH4A
: strcat (buf
, ", sh4a"); break;
2062 case EF_SH2A
: strcat (buf
, ", sh2a"); break;
2063 case EF_SH4_NOFPU
: strcat (buf
, ", sh4-nofpu"); break;
2064 case EF_SH4A_NOFPU
: strcat (buf
, ", sh4a-nofpu"); break;
2065 case EF_SH2A_NOFPU
: strcat (buf
, ", sh2a-nofpu"); break;
2066 default: strcat (buf
, ", unknown ISA"); break;
2072 if (e_flags
& EF_SPARC_32PLUS
)
2073 strcat (buf
, ", v8+");
2075 if (e_flags
& EF_SPARC_SUN_US1
)
2076 strcat (buf
, ", ultrasparcI");
2078 if (e_flags
& EF_SPARC_SUN_US3
)
2079 strcat (buf
, ", ultrasparcIII");
2081 if (e_flags
& EF_SPARC_HAL_R1
)
2082 strcat (buf
, ", halr1");
2084 if (e_flags
& EF_SPARC_LEDATA
)
2085 strcat (buf
, ", ledata");
2087 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2088 strcat (buf
, ", tso");
2090 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2091 strcat (buf
, ", pso");
2093 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2094 strcat (buf
, ", rmo");
2098 switch (e_flags
& EF_PARISC_ARCH
)
2100 case EFA_PARISC_1_0
:
2101 strcpy (buf
, ", PA-RISC 1.0");
2103 case EFA_PARISC_1_1
:
2104 strcpy (buf
, ", PA-RISC 1.1");
2106 case EFA_PARISC_2_0
:
2107 strcpy (buf
, ", PA-RISC 2.0");
2112 if (e_flags
& EF_PARISC_TRAPNIL
)
2113 strcat (buf
, ", trapnil");
2114 if (e_flags
& EF_PARISC_EXT
)
2115 strcat (buf
, ", ext");
2116 if (e_flags
& EF_PARISC_LSB
)
2117 strcat (buf
, ", lsb");
2118 if (e_flags
& EF_PARISC_WIDE
)
2119 strcat (buf
, ", wide");
2120 if (e_flags
& EF_PARISC_NO_KABP
)
2121 strcat (buf
, ", no kabp");
2122 if (e_flags
& EF_PARISC_LAZYSWAP
)
2123 strcat (buf
, ", lazyswap");
2128 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2129 strcat (buf
, ", new calling convention");
2131 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2132 strcat (buf
, ", gnu calling convention");
2136 if ((e_flags
& EF_IA_64_ABI64
))
2137 strcat (buf
, ", 64-bit");
2139 strcat (buf
, ", 32-bit");
2140 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2141 strcat (buf
, ", reduced fp model");
2142 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2143 strcat (buf
, ", no function descriptors, constant gp");
2144 else if ((e_flags
& EF_IA_64_CONS_GP
))
2145 strcat (buf
, ", constant gp");
2146 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2147 strcat (buf
, ", absolute");
2151 if ((e_flags
& EF_VAX_NONPIC
))
2152 strcat (buf
, ", non-PIC");
2153 if ((e_flags
& EF_VAX_DFLOAT
))
2154 strcat (buf
, ", D-Float");
2155 if ((e_flags
& EF_VAX_GFLOAT
))
2156 strcat (buf
, ", G-Float");
2165 get_osabi_name (unsigned int osabi
)
2167 static char buff
[32];
2171 case ELFOSABI_NONE
: return "UNIX - System V";
2172 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2173 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2174 case ELFOSABI_LINUX
: return "UNIX - Linux";
2175 case ELFOSABI_HURD
: return "GNU/Hurd";
2176 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2177 case ELFOSABI_AIX
: return "UNIX - AIX";
2178 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2179 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2180 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2181 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2182 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2183 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2184 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2185 case ELFOSABI_AROS
: return "Amiga Research OS";
2186 case ELFOSABI_STANDALONE
: return _("Standalone App");
2187 case ELFOSABI_ARM
: return "ARM";
2189 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), osabi
);
2195 get_arm_segment_type (unsigned long type
)
2209 get_mips_segment_type (unsigned long type
)
2213 case PT_MIPS_REGINFO
:
2215 case PT_MIPS_RTPROC
:
2217 case PT_MIPS_OPTIONS
:
2227 get_parisc_segment_type (unsigned long type
)
2231 case PT_HP_TLS
: return "HP_TLS";
2232 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2233 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2234 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2235 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2236 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2237 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2238 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2239 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2240 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2241 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2242 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2243 case PT_HP_OPT_ANNOT
: return "HP_OPT_ANNOT";
2244 case PT_HP_HSL_ANNOT
: return "HP_HSL_ANNOT";
2245 case PT_HP_STACK
: return "HP_STACK";
2246 case PT_HP_CORE_UTSNAME
: return "HP_CORE_UTSNAME";
2247 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2248 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2249 case PT_PARISC_WEAKORDER
: return "PARISC_WEAKORDER";
2258 get_ia64_segment_type (unsigned long type
)
2262 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2263 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2264 case PT_HP_TLS
: return "HP_TLS";
2265 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2266 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2267 case PT_IA_64_HP_STACK
: return "HP_STACK";
2276 get_segment_type (unsigned long p_type
)
2278 static char buff
[32];
2282 case PT_NULL
: return "NULL";
2283 case PT_LOAD
: return "LOAD";
2284 case PT_DYNAMIC
: return "DYNAMIC";
2285 case PT_INTERP
: return "INTERP";
2286 case PT_NOTE
: return "NOTE";
2287 case PT_SHLIB
: return "SHLIB";
2288 case PT_PHDR
: return "PHDR";
2289 case PT_TLS
: return "TLS";
2291 case PT_GNU_EH_FRAME
:
2292 return "GNU_EH_FRAME";
2293 case PT_GNU_STACK
: return "GNU_STACK";
2294 case PT_GNU_RELRO
: return "GNU_RELRO";
2297 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2301 switch (elf_header
.e_machine
)
2304 result
= get_arm_segment_type (p_type
);
2307 case EM_MIPS_RS3_LE
:
2308 result
= get_mips_segment_type (p_type
);
2311 result
= get_parisc_segment_type (p_type
);
2314 result
= get_ia64_segment_type (p_type
);
2324 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2326 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2330 switch (elf_header
.e_machine
)
2333 result
= get_parisc_segment_type (p_type
);
2336 result
= get_ia64_segment_type (p_type
);
2346 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2349 snprintf (buff
, sizeof (buff
), _("<unknown>: %lx"), p_type
);
2356 get_mips_section_type_name (unsigned int sh_type
)
2360 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2361 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2362 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2363 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2364 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2365 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2366 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2367 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2368 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2369 case SHT_MIPS_RELD
: return "MIPS_RELD";
2370 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2371 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2372 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2373 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2374 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2375 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2376 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2377 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2378 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2379 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2380 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2381 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2382 case SHT_MIPS_LINE
: return "MIPS_LINE";
2383 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2384 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2385 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2386 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2387 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2388 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2389 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2390 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2391 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2392 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2393 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2394 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2395 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2396 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2397 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2398 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2406 get_parisc_section_type_name (unsigned int sh_type
)
2410 case SHT_PARISC_EXT
: return "PARISC_EXT";
2411 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2412 case SHT_PARISC_DOC
: return "PARISC_DOC";
2413 case SHT_PARISC_ANNOT
: return "PARISC_ANNOT";
2414 case SHT_PARISC_SYMEXTN
: return "PARISC_SYMEXTN";
2415 case SHT_PARISC_STUBS
: return "PARISC_STUBS";
2416 case SHT_PARISC_DLKM
: return "PARISC_DLKM";
2424 get_ia64_section_type_name (unsigned int sh_type
)
2426 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2427 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2428 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2432 case SHT_IA_64_EXT
: return "IA_64_EXT";
2433 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2434 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2442 get_x86_64_section_type_name (unsigned int sh_type
)
2446 case SHT_X86_64_UNWIND
: return "X86_64_UNWIND";
2454 get_arm_section_type_name (unsigned int sh_type
)
2460 case SHT_ARM_PREEMPTMAP
:
2461 return "ARM_PREEMPTMAP";
2462 case SHT_ARM_ATTRIBUTES
:
2463 return "ARM_ATTRIBUTES";
2471 get_section_type_name (unsigned int sh_type
)
2473 static char buff
[32];
2477 case SHT_NULL
: return "NULL";
2478 case SHT_PROGBITS
: return "PROGBITS";
2479 case SHT_SYMTAB
: return "SYMTAB";
2480 case SHT_STRTAB
: return "STRTAB";
2481 case SHT_RELA
: return "RELA";
2482 case SHT_HASH
: return "HASH";
2483 case SHT_DYNAMIC
: return "DYNAMIC";
2484 case SHT_NOTE
: return "NOTE";
2485 case SHT_NOBITS
: return "NOBITS";
2486 case SHT_REL
: return "REL";
2487 case SHT_SHLIB
: return "SHLIB";
2488 case SHT_DYNSYM
: return "DYNSYM";
2489 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2490 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2491 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2492 case SHT_GROUP
: return "GROUP";
2493 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2494 case SHT_GNU_verdef
: return "VERDEF";
2495 case SHT_GNU_verneed
: return "VERNEED";
2496 case SHT_GNU_versym
: return "VERSYM";
2497 case 0x6ffffff0: return "VERSYM";
2498 case 0x6ffffffc: return "VERDEF";
2499 case 0x7ffffffd: return "AUXILIARY";
2500 case 0x7fffffff: return "FILTER";
2501 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2504 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2508 switch (elf_header
.e_machine
)
2511 case EM_MIPS_RS3_LE
:
2512 result
= get_mips_section_type_name (sh_type
);
2515 result
= get_parisc_section_type_name (sh_type
);
2518 result
= get_ia64_section_type_name (sh_type
);
2521 result
= get_x86_64_section_type_name (sh_type
);
2524 result
= get_arm_section_type_name (sh_type
);
2534 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2536 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2537 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2538 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2539 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2541 snprintf (buff
, sizeof (buff
), _("<unknown>: %x"), sh_type
);
2547 #define OPTION_DEBUG_DUMP 512
2549 static struct option options
[] =
2551 {"all", no_argument
, 0, 'a'},
2552 {"file-header", no_argument
, 0, 'h'},
2553 {"program-headers", no_argument
, 0, 'l'},
2554 {"headers", no_argument
, 0, 'e'},
2555 {"histogram", no_argument
, 0, 'I'},
2556 {"segments", no_argument
, 0, 'l'},
2557 {"sections", no_argument
, 0, 'S'},
2558 {"section-headers", no_argument
, 0, 'S'},
2559 {"section-groups", no_argument
, 0, 'g'},
2560 {"section-details", no_argument
, 0, 't'},
2561 {"full-section-name",no_argument
, 0, 'N'},
2562 {"symbols", no_argument
, 0, 's'},
2563 {"syms", no_argument
, 0, 's'},
2564 {"relocs", no_argument
, 0, 'r'},
2565 {"notes", no_argument
, 0, 'n'},
2566 {"dynamic", no_argument
, 0, 'd'},
2567 {"arch-specific", no_argument
, 0, 'A'},
2568 {"version-info", no_argument
, 0, 'V'},
2569 {"use-dynamic", no_argument
, 0, 'D'},
2570 {"hex-dump", required_argument
, 0, 'x'},
2571 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2572 {"unwind", no_argument
, 0, 'u'},
2573 #ifdef SUPPORT_DISASSEMBLY
2574 {"instruction-dump", required_argument
, 0, 'i'},
2577 {"version", no_argument
, 0, 'v'},
2578 {"wide", no_argument
, 0, 'W'},
2579 {"help", no_argument
, 0, 'H'},
2580 {0, no_argument
, 0, 0}
2586 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2587 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2588 fprintf (stdout
, _(" Options are:\n\
2589 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2590 -h --file-header Display the ELF file header\n\
2591 -l --program-headers Display the program headers\n\
2592 --segments An alias for --program-headers\n\
2593 -S --section-headers Display the sections' header\n\
2594 --sections An alias for --section-headers\n\
2595 -g --section-groups Display the section groups\n\
2596 -t --section-details Display the section details\n\
2597 -e --headers Equivalent to: -h -l -S\n\
2598 -s --syms Display the symbol table\n\
2599 --symbols An alias for --syms\n\
2600 -n --notes Display the core notes (if present)\n\
2601 -r --relocs Display the relocations (if present)\n\
2602 -u --unwind Display the unwind info (if present)\n\
2603 -d --dynamic Display the dynamic section (if present)\n\
2604 -V --version-info Display the version sections (if present)\n\
2605 -A --arch-specific Display architecture specific information (if any).\n\
2606 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2607 -x --hex-dump=<number> Dump the contents of section <number>\n\
2608 -w[liaprmfFsoR] or\n\
2609 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2610 Display the contents of DWARF2 debug sections\n"));
2611 #ifdef SUPPORT_DISASSEMBLY
2612 fprintf (stdout
, _("\
2613 -i --instruction-dump=<number>\n\
2614 Disassemble the contents of section <number>\n"));
2616 fprintf (stdout
, _("\
2617 -I --histogram Display histogram of bucket list lengths\n\
2618 -W --wide Allow output width to exceed 80 characters\n\
2619 -H --help Display this information\n\
2620 -v --version Display the version number of readelf\n"));
2621 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2626 /* Record the fact that the user wants the contents of section number
2627 SECTION to be displayed using the method(s) encoded as flags bits
2628 in TYPE. Note, TYPE can be zero if we are creating the array for
2632 request_dump (unsigned int section
, int type
)
2634 if (section
>= num_dump_sects
)
2636 char *new_dump_sects
;
2638 new_dump_sects
= calloc (section
+ 1, 1);
2640 if (new_dump_sects
== NULL
)
2641 error (_("Out of memory allocating dump request table."));
2644 /* Copy current flag settings. */
2645 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2649 dump_sects
= new_dump_sects
;
2650 num_dump_sects
= section
+ 1;
2655 dump_sects
[section
] |= type
;
2661 parse_args (int argc
, char **argv
)
2668 while ((c
= getopt_long
2669 (argc
, argv
, "ersuahnldSDAINtgw::x:i:vVWH", options
, NULL
)) != EOF
)
2690 do_section_groups
++;
2698 do_section_groups
++;
2703 do_section_details
++;
2745 section
= strtoul (optarg
, & cp
, 0);
2746 if (! *cp
&& section
>= 0)
2748 request_dump (section
, HEX_DUMP
);
2758 unsigned int index
= 0;
2762 while (optarg
[index
])
2763 switch (optarg
[index
++])
2772 do_debug_abbrevs
= 1;
2782 do_debug_pubnames
= 1;
2786 do_debug_aranges
= 1;
2790 do_debug_ranges
= 1;
2794 do_debug_frames_interp
= 1;
2796 do_debug_frames
= 1;
2801 do_debug_macinfo
= 1;
2815 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2820 case OPTION_DEBUG_DUMP
:
2828 const char * option
;
2831 debug_dump_long_opts
;
2833 debug_dump_long_opts opts_table
[] =
2835 /* Please keep this table alpha- sorted. */
2836 { "Ranges", & do_debug_ranges
},
2837 { "abbrev", & do_debug_abbrevs
},
2838 { "aranges", & do_debug_aranges
},
2839 { "frames", & do_debug_frames
},
2840 { "frames-interp", & do_debug_frames_interp
},
2841 { "info", & do_debug_info
},
2842 { "line", & do_debug_lines
},
2843 { "loc", & do_debug_loc
},
2844 { "macro", & do_debug_macinfo
},
2845 { "pubnames", & do_debug_pubnames
},
2846 /* This entry is for compatability
2847 with earlier versions of readelf. */
2848 { "ranges", & do_debug_aranges
},
2849 { "str", & do_debug_str
},
2860 debug_dump_long_opts
* entry
;
2862 for (entry
= opts_table
; entry
->option
; entry
++)
2864 size_t len
= strlen (entry
->option
);
2866 if (strneq (p
, entry
->option
, len
)
2867 && (p
[len
] == ',' || p
[len
] == '\0'))
2869 * entry
->variable
= 1;
2871 /* The --debug-dump=frames-interp option also
2872 enables the --debug-dump=frames option. */
2873 if (do_debug_frames_interp
)
2874 do_debug_frames
= 1;
2881 if (entry
->option
== NULL
)
2883 warn (_("Unrecognized debug option '%s'\n"), p
);
2884 p
= strchr (p
, ',');
2894 #ifdef SUPPORT_DISASSEMBLY
2897 section
= strtoul (optarg
, & cp
, 0);
2898 if (! *cp
&& section
>= 0)
2900 request_dump (section
, DISASS_DUMP
);
2906 print_version (program_name
);
2916 /* xgettext:c-format */
2917 error (_("Invalid option '-%c'\n"), c
);
2924 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2925 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2926 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
2927 && !do_section_groups
)
2931 warn (_("Nothing to do.\n"));
2937 get_elf_class (unsigned int elf_class
)
2939 static char buff
[32];
2943 case ELFCLASSNONE
: return _("none");
2944 case ELFCLASS32
: return "ELF32";
2945 case ELFCLASS64
: return "ELF64";
2947 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), elf_class
);
2953 get_data_encoding (unsigned int encoding
)
2955 static char buff
[32];
2959 case ELFDATANONE
: return _("none");
2960 case ELFDATA2LSB
: return _("2's complement, little endian");
2961 case ELFDATA2MSB
: return _("2's complement, big endian");
2963 snprintf (buff
, sizeof (buff
), _("<unknown: %x>"), encoding
);
2968 /* Decode the data held in 'elf_header'. */
2971 process_file_header (void)
2973 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2974 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2975 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2976 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2979 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2987 printf (_("ELF Header:\n"));
2988 printf (_(" Magic: "));
2989 for (i
= 0; i
< EI_NIDENT
; i
++)
2990 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2992 printf (_(" Class: %s\n"),
2993 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2994 printf (_(" Data: %s\n"),
2995 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2996 printf (_(" Version: %d %s\n"),
2997 elf_header
.e_ident
[EI_VERSION
],
2998 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
3000 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3003 printf (_(" OS/ABI: %s\n"),
3004 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3005 printf (_(" ABI Version: %d\n"),
3006 elf_header
.e_ident
[EI_ABIVERSION
]);
3007 printf (_(" Type: %s\n"),
3008 get_file_type (elf_header
.e_type
));
3009 printf (_(" Machine: %s\n"),
3010 get_machine_name (elf_header
.e_machine
));
3011 printf (_(" Version: 0x%lx\n"),
3012 (unsigned long) elf_header
.e_version
);
3014 printf (_(" Entry point address: "));
3015 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3016 printf (_("\n Start of program headers: "));
3017 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3018 printf (_(" (bytes into file)\n Start of section headers: "));
3019 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3020 printf (_(" (bytes into file)\n"));
3022 printf (_(" Flags: 0x%lx%s\n"),
3023 (unsigned long) elf_header
.e_flags
,
3024 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3025 printf (_(" Size of this header: %ld (bytes)\n"),
3026 (long) elf_header
.e_ehsize
);
3027 printf (_(" Size of program headers: %ld (bytes)\n"),
3028 (long) elf_header
.e_phentsize
);
3029 printf (_(" Number of program headers: %ld\n"),
3030 (long) elf_header
.e_phnum
);
3031 printf (_(" Size of section headers: %ld (bytes)\n"),
3032 (long) elf_header
.e_shentsize
);
3033 printf (_(" Number of section headers: %ld"),
3034 (long) elf_header
.e_shnum
);
3035 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3036 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3037 putc ('\n', stdout
);
3038 printf (_(" Section header string table index: %ld"),
3039 (long) elf_header
.e_shstrndx
);
3040 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3041 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3042 putc ('\n', stdout
);
3045 if (section_headers
!= NULL
)
3047 if (elf_header
.e_shnum
== 0)
3048 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3049 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3050 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3051 free (section_headers
);
3052 section_headers
= NULL
;
3060 get_32bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3062 Elf32_External_Phdr
*phdrs
;
3063 Elf32_External_Phdr
*external
;
3064 Elf_Internal_Phdr
*internal
;
3067 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3068 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3069 _("program headers"));
3073 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3074 i
< elf_header
.e_phnum
;
3075 i
++, internal
++, external
++)
3077 internal
->p_type
= BYTE_GET (external
->p_type
);
3078 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3079 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3080 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3081 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3082 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3083 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3084 internal
->p_align
= BYTE_GET (external
->p_align
);
3093 get_64bit_program_headers (FILE *file
, Elf_Internal_Phdr
*program_headers
)
3095 Elf64_External_Phdr
*phdrs
;
3096 Elf64_External_Phdr
*external
;
3097 Elf_Internal_Phdr
*internal
;
3100 phdrs
= get_data (NULL
, file
, elf_header
.e_phoff
,
3101 elf_header
.e_phentsize
, elf_header
.e_phnum
,
3102 _("program headers"));
3106 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3107 i
< elf_header
.e_phnum
;
3108 i
++, internal
++, external
++)
3110 internal
->p_type
= BYTE_GET (external
->p_type
);
3111 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3112 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3113 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3114 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3115 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3116 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3117 internal
->p_align
= BYTE_GET (external
->p_align
);
3125 /* Returns 1 if the program headers were read into `program_headers'. */
3128 get_program_headers (FILE *file
)
3130 Elf_Internal_Phdr
*phdrs
;
3132 /* Check cache of prior read. */
3133 if (program_headers
!= NULL
)
3136 phdrs
= cmalloc (elf_header
.e_phnum
, sizeof (Elf_Internal_Phdr
));
3140 error (_("Out of memory\n"));
3145 ? get_32bit_program_headers (file
, phdrs
)
3146 : get_64bit_program_headers (file
, phdrs
))
3148 program_headers
= phdrs
;
3156 /* Returns 1 if the program headers were loaded. */
3159 process_program_headers (FILE *file
)
3161 Elf_Internal_Phdr
*segment
;
3164 if (elf_header
.e_phnum
== 0)
3167 printf (_("\nThere are no program headers in this file.\n"));
3171 if (do_segments
&& !do_header
)
3173 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3174 printf (_("Entry point "));
3175 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3176 printf (_("\nThere are %d program headers, starting at offset "),
3177 elf_header
.e_phnum
);
3178 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3182 if (! get_program_headers (file
))
3187 if (elf_header
.e_phnum
> 1)
3188 printf (_("\nProgram Headers:\n"));
3190 printf (_("\nProgram Headers:\n"));
3194 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3197 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3201 (_(" Type Offset VirtAddr PhysAddr\n"));
3203 (_(" FileSiz MemSiz Flags Align\n"));
3210 for (i
= 0, segment
= program_headers
;
3211 i
< elf_header
.e_phnum
;
3216 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3220 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3221 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3222 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3223 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3224 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3226 (segment
->p_flags
& PF_R
? 'R' : ' '),
3227 (segment
->p_flags
& PF_W
? 'W' : ' '),
3228 (segment
->p_flags
& PF_X
? 'E' : ' '));
3229 printf ("%#lx", (unsigned long) segment
->p_align
);
3233 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3234 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3237 print_vma (segment
->p_offset
, FULL_HEX
);
3241 print_vma (segment
->p_vaddr
, FULL_HEX
);
3243 print_vma (segment
->p_paddr
, FULL_HEX
);
3246 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3247 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3250 print_vma (segment
->p_filesz
, FULL_HEX
);
3254 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3255 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3258 print_vma (segment
->p_offset
, FULL_HEX
);
3262 (segment
->p_flags
& PF_R
? 'R' : ' '),
3263 (segment
->p_flags
& PF_W
? 'W' : ' '),
3264 (segment
->p_flags
& PF_X
? 'E' : ' '));
3266 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3267 printf ("%#lx", (unsigned long) segment
->p_align
);
3270 print_vma (segment
->p_align
, PREFIX_HEX
);
3275 print_vma (segment
->p_offset
, FULL_HEX
);
3277 print_vma (segment
->p_vaddr
, FULL_HEX
);
3279 print_vma (segment
->p_paddr
, FULL_HEX
);
3281 print_vma (segment
->p_filesz
, FULL_HEX
);
3283 print_vma (segment
->p_memsz
, FULL_HEX
);
3285 (segment
->p_flags
& PF_R
? 'R' : ' '),
3286 (segment
->p_flags
& PF_W
? 'W' : ' '),
3287 (segment
->p_flags
& PF_X
? 'E' : ' '));
3288 print_vma (segment
->p_align
, HEX
);
3292 switch (segment
->p_type
)
3296 error (_("more than one dynamic segment\n"));
3298 /* Try to locate the .dynamic section. If there is
3299 a section header table, we can easily locate it. */
3300 if (section_headers
!= NULL
)
3302 Elf_Internal_Shdr
*sec
;
3304 sec
= find_section (".dynamic");
3305 if (sec
== NULL
|| sec
->sh_size
== 0)
3307 error (_("no .dynamic section in the dynamic segment"));
3311 dynamic_addr
= sec
->sh_offset
;
3312 dynamic_size
= sec
->sh_size
;
3314 if (dynamic_addr
< segment
->p_offset
3315 || dynamic_addr
> segment
->p_offset
+ segment
->p_filesz
)
3316 warn (_("the .dynamic section is not contained within the dynamic segment"));
3317 else if (dynamic_addr
> segment
->p_offset
)
3318 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3322 /* Otherwise, we can only assume that the .dynamic
3323 section is the first section in the DYNAMIC segment. */
3324 dynamic_addr
= segment
->p_offset
;
3325 dynamic_size
= segment
->p_filesz
;
3330 if (fseek (file
, archive_file_offset
+ (long) segment
->p_offset
,
3332 error (_("Unable to find program interpreter name\n"));
3335 program_interpreter
[0] = 0;
3336 fscanf (file
, "%63s", program_interpreter
);
3339 printf (_("\n [Requesting program interpreter: %s]"),
3340 program_interpreter
);
3346 putc ('\n', stdout
);
3349 if (do_segments
&& section_headers
!= NULL
&& string_table
!= NULL
)
3351 printf (_("\n Section to Segment mapping:\n"));
3352 printf (_(" Segment Sections...\n"));
3354 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3357 Elf_Internal_Shdr
*section
;
3359 segment
= program_headers
+ i
;
3360 section
= section_headers
;
3362 printf (" %2.2d ", i
);
3364 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3366 if (section
->sh_size
> 0
3367 /* Compare allocated sections by VMA, unallocated
3368 sections by file offset. */
3369 && (section
->sh_flags
& SHF_ALLOC
3370 ? (section
->sh_addr
>= segment
->p_vaddr
3371 && section
->sh_addr
+ section
->sh_size
3372 <= segment
->p_vaddr
+ segment
->p_memsz
)
3373 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3374 && (section
->sh_offset
+ section
->sh_size
3375 <= segment
->p_offset
+ segment
->p_filesz
)))
3376 /* .tbss is special. It doesn't contribute memory space
3377 to normal segments. */
3378 && (!((section
->sh_flags
& SHF_TLS
) != 0
3379 && section
->sh_type
== SHT_NOBITS
)
3380 || segment
->p_type
== PT_TLS
))
3381 printf ("%s ", SECTION_NAME (section
));
3392 /* Find the file offset corresponding to VMA by using the program headers. */
3395 offset_from_vma (FILE *file
, bfd_vma vma
, bfd_size_type size
)
3397 Elf_Internal_Phdr
*seg
;
3399 if (! get_program_headers (file
))
3401 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3405 for (seg
= program_headers
;
3406 seg
< program_headers
+ elf_header
.e_phnum
;
3409 if (seg
->p_type
!= PT_LOAD
)
3412 if (vma
>= (seg
->p_vaddr
& -seg
->p_align
)
3413 && vma
+ size
<= seg
->p_vaddr
+ seg
->p_filesz
)
3414 return vma
- seg
->p_vaddr
+ seg
->p_offset
;
3417 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3424 get_32bit_section_headers (FILE *file
, unsigned int num
)
3426 Elf32_External_Shdr
*shdrs
;
3427 Elf_Internal_Shdr
*internal
;
3430 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3431 elf_header
.e_shentsize
, num
, _("section headers"));
3435 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3437 if (section_headers
== NULL
)
3439 error (_("Out of memory\n"));
3443 for (i
= 0, internal
= section_headers
;
3447 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3448 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3449 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3450 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3451 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3452 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3453 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3454 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3455 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3456 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3465 get_64bit_section_headers (FILE *file
, unsigned int num
)
3467 Elf64_External_Shdr
*shdrs
;
3468 Elf_Internal_Shdr
*internal
;
3471 shdrs
= get_data (NULL
, file
, elf_header
.e_shoff
,
3472 elf_header
.e_shentsize
, num
, _("section headers"));
3476 section_headers
= cmalloc (num
, sizeof (Elf_Internal_Shdr
));
3478 if (section_headers
== NULL
)
3480 error (_("Out of memory\n"));
3484 for (i
= 0, internal
= section_headers
;
3488 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3489 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3490 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3491 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3492 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3493 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3494 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3495 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3496 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3497 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3505 static Elf_Internal_Sym
*
3506 get_32bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3508 unsigned long number
;
3509 Elf32_External_Sym
*esyms
;
3510 Elf_External_Sym_Shndx
*shndx
;
3511 Elf_Internal_Sym
*isyms
;
3512 Elf_Internal_Sym
*psym
;
3515 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3521 if (symtab_shndx_hdr
!= NULL
3522 && (symtab_shndx_hdr
->sh_link
3523 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3525 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3526 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3534 number
= section
->sh_size
/ section
->sh_entsize
;
3535 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3539 error (_("Out of memory\n"));
3546 for (j
= 0, psym
= isyms
;
3550 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3551 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3552 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3553 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3554 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3556 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3557 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3558 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3568 static Elf_Internal_Sym
*
3569 get_64bit_elf_symbols (FILE *file
, Elf_Internal_Shdr
*section
)
3571 unsigned long number
;
3572 Elf64_External_Sym
*esyms
;
3573 Elf_External_Sym_Shndx
*shndx
;
3574 Elf_Internal_Sym
*isyms
;
3575 Elf_Internal_Sym
*psym
;
3578 esyms
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
3584 if (symtab_shndx_hdr
!= NULL
3585 && (symtab_shndx_hdr
->sh_link
3586 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3588 shndx
= get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3589 1, symtab_shndx_hdr
->sh_size
, _("symtab shndx"));
3597 number
= section
->sh_size
/ section
->sh_entsize
;
3598 isyms
= cmalloc (number
, sizeof (Elf_Internal_Sym
));
3602 error (_("Out of memory\n"));
3609 for (j
= 0, psym
= isyms
;
3613 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3614 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3615 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3616 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3617 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3619 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3620 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3621 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3632 get_elf_section_flags (bfd_vma sh_flags
)
3634 static char buff
[1024];
3636 int field_size
= is_32bit_elf
? 8 : 16;
3637 int index
, size
= sizeof (buff
) - (field_size
+ 4 + 1);
3638 bfd_vma os_flags
= 0;
3639 bfd_vma proc_flags
= 0;
3640 bfd_vma unknown_flags
= 0;
3654 { "LINK ORDER", 10 },
3655 { "OS NONCONF", 10 },
3660 if (do_section_details
)
3662 sprintf (buff
, "[%*.*lx]: ",
3663 field_size
, field_size
, (unsigned long) sh_flags
);
3664 p
+= field_size
+ 4;
3671 flag
= sh_flags
& - sh_flags
;
3674 if (do_section_details
)
3678 case SHF_WRITE
: index
= 0; break;
3679 case SHF_ALLOC
: index
= 1; break;
3680 case SHF_EXECINSTR
: index
= 2; break;
3681 case SHF_MERGE
: index
= 3; break;
3682 case SHF_STRINGS
: index
= 4; break;
3683 case SHF_INFO_LINK
: index
= 5; break;
3684 case SHF_LINK_ORDER
: index
= 6; break;
3685 case SHF_OS_NONCONFORMING
: index
= 7; break;
3686 case SHF_GROUP
: index
= 8; break;
3687 case SHF_TLS
: index
= 9; break;
3696 if (p
!= buff
+ field_size
+ 4)
3698 if (size
< (10 + 2))
3705 size
-= flags
[index
].len
;
3706 p
= stpcpy (p
, flags
[index
].str
);
3708 else if (flag
& SHF_MASKOS
)
3710 else if (flag
& SHF_MASKPROC
)
3713 unknown_flags
|= flag
;
3719 case SHF_WRITE
: *p
= 'W'; break;
3720 case SHF_ALLOC
: *p
= 'A'; break;
3721 case SHF_EXECINSTR
: *p
= 'X'; break;
3722 case SHF_MERGE
: *p
= 'M'; break;
3723 case SHF_STRINGS
: *p
= 'S'; break;
3724 case SHF_INFO_LINK
: *p
= 'I'; break;
3725 case SHF_LINK_ORDER
: *p
= 'L'; break;
3726 case SHF_OS_NONCONFORMING
: *p
= 'O'; break;
3727 case SHF_GROUP
: *p
= 'G'; break;
3728 case SHF_TLS
: *p
= 'T'; break;
3731 if (elf_header
.e_machine
== EM_X86_64
3732 && flag
== SHF_X86_64_LARGE
)
3734 else if (flag
& SHF_MASKOS
)
3737 sh_flags
&= ~ SHF_MASKOS
;
3739 else if (flag
& SHF_MASKPROC
)
3742 sh_flags
&= ~ SHF_MASKPROC
;
3752 if (do_section_details
)
3756 size
-= 5 + field_size
;
3757 if (p
!= buff
+ field_size
+ 4)
3765 sprintf (p
, "OS (%*.*lx)", field_size
, field_size
,
3766 (unsigned long) os_flags
);
3767 p
+= 5 + field_size
;
3771 size
-= 7 + field_size
;
3772 if (p
!= buff
+ field_size
+ 4)
3780 sprintf (p
, "PROC (%*.*lx)", field_size
, field_size
,
3781 (unsigned long) proc_flags
);
3782 p
+= 7 + field_size
;
3786 size
-= 10 + field_size
;
3787 if (p
!= buff
+ field_size
+ 4)
3795 sprintf (p
, "UNKNOWN (%*.*lx)", field_size
, field_size
,
3796 (unsigned long) unknown_flags
);
3797 p
+= 10 + field_size
;
3806 process_section_headers (FILE *file
)
3808 Elf_Internal_Shdr
*section
;
3811 section_headers
= NULL
;
3813 if (elf_header
.e_shnum
== 0)
3816 printf (_("\nThere are no sections in this file.\n"));
3821 if (do_sections
&& !do_header
)
3822 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3823 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3827 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3830 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3833 /* Read in the string table, so that we have names to display. */
3834 if (SECTION_HEADER_INDEX (elf_header
.e_shstrndx
) < elf_header
.e_shnum
)
3836 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3838 if (section
->sh_size
!= 0)
3840 string_table
= get_data (NULL
, file
, section
->sh_offset
,
3841 1, section
->sh_size
, _("string table"));
3843 string_table_length
= string_table
!= NULL
? section
->sh_size
: 0;
3847 /* Scan the sections for the dynamic symbol table
3848 and dynamic string table and debug sections. */
3849 dynamic_symbols
= NULL
;
3850 dynamic_strings
= NULL
;
3851 dynamic_syminfo
= NULL
;
3852 symtab_shndx_hdr
= NULL
;
3854 eh_addr_size
= is_32bit_elf
? 4 : 8;
3855 switch (elf_header
.e_machine
)
3858 case EM_MIPS_RS3_LE
:
3859 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
3860 FDE addresses. However, the ABI also has a semi-official ILP32
3861 variant for which the normal FDE address size rules apply.
3863 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
3864 section, where XX is the size of longs in bits. Unfortunately,
3865 earlier compilers provided no way of distinguishing ILP32 objects
3866 from LP64 objects, so if there's any doubt, we should assume that
3867 the official LP64 form is being used. */
3868 if ((elf_header
.e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
3869 && find_section (".gcc_compiled_long32") == NULL
)
3874 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
3877 size_t expected_entsize \
3878 = is_32bit_elf ? size32 : size64; \
3879 if (section->sh_entsize != expected_entsize) \
3880 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
3881 i, (unsigned long int) section->sh_entsize, \
3882 (unsigned long int) expected_entsize); \
3883 section->sh_entsize = expected_entsize; \
3886 #define CHECK_ENTSIZE(section, i, type) \
3887 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
3888 sizeof (Elf64_External_##type))
3890 for (i
= 0, section
= section_headers
;
3891 i
< elf_header
.e_shnum
;
3894 char *name
= SECTION_NAME (section
);
3896 if (section
->sh_type
== SHT_DYNSYM
)
3898 if (dynamic_symbols
!= NULL
)
3900 error (_("File contains multiple dynamic symbol tables\n"));
3904 CHECK_ENTSIZE (section
, i
, Sym
);
3905 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3906 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3908 else if (section
->sh_type
== SHT_STRTAB
3909 && streq (name
, ".dynstr"))
3911 if (dynamic_strings
!= NULL
)
3913 error (_("File contains multiple dynamic string tables\n"));
3917 dynamic_strings
= get_data (NULL
, file
, section
->sh_offset
,
3918 1, section
->sh_size
, _("dynamic strings"));
3919 dynamic_strings_length
= section
->sh_size
;
3921 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3923 if (symtab_shndx_hdr
!= NULL
)
3925 error (_("File contains multiple symtab shndx tables\n"));
3928 symtab_shndx_hdr
= section
;
3930 else if (section
->sh_type
== SHT_SYMTAB
)
3931 CHECK_ENTSIZE (section
, i
, Sym
);
3932 else if (section
->sh_type
== SHT_GROUP
)
3933 CHECK_ENTSIZE_VALUES (section
, i
, GRP_ENTRY_SIZE
, GRP_ENTRY_SIZE
);
3934 else if (section
->sh_type
== SHT_REL
)
3935 CHECK_ENTSIZE (section
, i
, Rel
);
3936 else if (section
->sh_type
== SHT_RELA
)
3937 CHECK_ENTSIZE (section
, i
, Rela
);
3938 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3939 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3940 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3941 || do_debug_loc
|| do_debug_ranges
)
3942 && strneq (name
, ".debug_", 7))
3947 || (do_debug_info
&& streq (name
, "info"))
3948 || (do_debug_abbrevs
&& streq (name
, "abbrev"))
3949 || (do_debug_lines
&& streq (name
, "line"))
3950 || (do_debug_pubnames
&& streq (name
, "pubnames"))
3951 || (do_debug_aranges
&& streq (name
, "aranges"))
3952 || (do_debug_ranges
&& streq (name
, "ranges"))
3953 || (do_debug_frames
&& streq (name
, "frame"))
3954 || (do_debug_macinfo
&& streq (name
, "macinfo"))
3955 || (do_debug_str
&& streq (name
, "str"))
3956 || (do_debug_loc
&& streq (name
, "loc"))
3958 request_dump (i
, DEBUG_DUMP
);
3960 /* linkonce section to be combined with .debug_info at link time. */
3961 else if ((do_debugging
|| do_debug_info
)
3962 && strneq (name
, ".gnu.linkonce.wi.", 17))
3963 request_dump (i
, DEBUG_DUMP
);
3964 else if (do_debug_frames
&& streq (name
, ".eh_frame"))
3965 request_dump (i
, DEBUG_DUMP
);
3971 if (elf_header
.e_shnum
> 1)
3972 printf (_("\nSection Headers:\n"));
3974 printf (_("\nSection Header:\n"));
3978 if (do_section_details
)
3980 printf (_(" [Nr] Name\n"));
3981 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
3985 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3989 if (do_section_details
)
3991 printf (_(" [Nr] Name\n"));
3992 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
3996 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4000 if (do_section_details
)
4002 printf (_(" [Nr] Name\n"));
4003 printf (_(" Type Address Offset Link\n"));
4004 printf (_(" Size EntSize Info Align\n"));
4008 printf (_(" [Nr] Name Type Address Offset\n"));
4009 printf (_(" Size EntSize Flags Link Info Align\n"));
4013 if (do_section_details
)
4014 printf (_(" Flags\n"));
4016 for (i
= 0, section
= section_headers
;
4017 i
< elf_header
.e_shnum
;
4020 if (do_section_details
)
4022 printf (" [%2u] %s\n",
4023 SECTION_HEADER_NUM (i
),
4024 SECTION_NAME (section
));
4025 if (is_32bit_elf
|| do_wide
)
4026 printf (" %-15.15s ",
4027 get_section_type_name (section
->sh_type
));
4030 printf (" [%2u] %-17.17s %-15.15s ",
4031 SECTION_HEADER_NUM (i
),
4032 SECTION_NAME (section
),
4033 get_section_type_name (section
->sh_type
));
4037 print_vma (section
->sh_addr
, LONG_HEX
);
4039 printf ( " %6.6lx %6.6lx %2.2lx",
4040 (unsigned long) section
->sh_offset
,
4041 (unsigned long) section
->sh_size
,
4042 (unsigned long) section
->sh_entsize
);
4044 if (do_section_details
)
4045 fputs (" ", stdout
);
4047 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4049 printf ("%2ld %3lu %2ld\n",
4050 (unsigned long) section
->sh_link
,
4051 (unsigned long) section
->sh_info
,
4052 (unsigned long) section
->sh_addralign
);
4056 print_vma (section
->sh_addr
, LONG_HEX
);
4058 if ((long) section
->sh_offset
== section
->sh_offset
)
4059 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
4063 print_vma (section
->sh_offset
, LONG_HEX
);
4066 if ((unsigned long) section
->sh_size
== section
->sh_size
)
4067 printf (" %6.6lx", (unsigned long) section
->sh_size
);
4071 print_vma (section
->sh_size
, LONG_HEX
);
4074 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
4075 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
4079 print_vma (section
->sh_entsize
, LONG_HEX
);
4082 if (do_section_details
)
4083 fputs (" ", stdout
);
4085 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4087 printf ("%2ld %3lu ",
4088 (unsigned long) section
->sh_link
,
4089 (unsigned long) section
->sh_info
);
4091 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
4092 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
4095 print_vma (section
->sh_addralign
, DEC
);
4099 else if (do_section_details
)
4101 printf (" %-15.15s ",
4102 get_section_type_name (section
->sh_type
));
4103 print_vma (section
->sh_addr
, LONG_HEX
);
4104 if ((long) section
->sh_offset
== section
->sh_offset
)
4105 printf (" %16.16lx", (unsigned long) section
->sh_offset
);
4109 print_vma (section
->sh_offset
, LONG_HEX
);
4111 printf (" %ld\n ", (unsigned long) section
->sh_link
);
4112 print_vma (section
->sh_size
, LONG_HEX
);
4114 print_vma (section
->sh_entsize
, LONG_HEX
);
4116 printf (" %-16lu %ld\n",
4117 (unsigned long) section
->sh_info
,
4118 (unsigned long) section
->sh_addralign
);
4123 print_vma (section
->sh_addr
, LONG_HEX
);
4124 if ((long) section
->sh_offset
== section
->sh_offset
)
4125 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
4129 print_vma (section
->sh_offset
, LONG_HEX
);
4132 print_vma (section
->sh_size
, LONG_HEX
);
4134 print_vma (section
->sh_entsize
, LONG_HEX
);
4136 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
4138 printf (" %2ld %3lu %ld\n",
4139 (unsigned long) section
->sh_link
,
4140 (unsigned long) section
->sh_info
,
4141 (unsigned long) section
->sh_addralign
);
4144 if (do_section_details
)
4145 printf (" %s\n", get_elf_section_flags (section
->sh_flags
));
4148 if (!do_section_details
)
4149 printf (_("Key to Flags:\n\
4150 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4151 I (info), L (link order), G (group), x (unknown)\n\
4152 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4158 get_group_flags (unsigned int flags
)
4160 static char buff
[32];
4167 snprintf (buff
, sizeof (buff
), _("[<unknown>: 0x%x]"), flags
);
4174 process_section_groups (FILE *file
)
4176 Elf_Internal_Shdr
*section
;
4178 struct group
*group
;
4179 Elf_Internal_Shdr
*symtab_sec
, *strtab_sec
;
4180 Elf_Internal_Sym
*symtab
;
4184 /* Don't process section groups unless needed. */
4185 if (!do_unwind
&& !do_section_groups
)
4188 if (elf_header
.e_shnum
== 0)
4190 if (do_section_groups
)
4191 printf (_("\nThere are no sections in this file.\n"));
4196 if (section_headers
== NULL
)
4198 error (_("Section headers are not available!\n"));
4202 section_headers_groups
= calloc (elf_header
.e_shnum
,
4203 sizeof (struct group
*));
4205 if (section_headers_groups
== NULL
)
4207 error (_("Out of memory\n"));
4211 /* Scan the sections for the group section. */
4213 for (i
= 0, section
= section_headers
;
4214 i
< elf_header
.e_shnum
;
4216 if (section
->sh_type
== SHT_GROUP
)
4219 if (group_count
== 0)
4221 if (do_section_groups
)
4222 printf (_("\nThere are no section groups in this file.\n"));
4227 section_groups
= calloc (group_count
, sizeof (struct group
));
4229 if (section_groups
== NULL
)
4231 error (_("Out of memory\n"));
4240 for (i
= 0, section
= section_headers
, group
= section_groups
;
4241 i
< elf_header
.e_shnum
;
4244 if (section
->sh_type
== SHT_GROUP
)
4246 char *name
= SECTION_NAME (section
);
4248 unsigned char *start
, *indices
;
4249 unsigned int entry
, j
, size
;
4250 Elf_Internal_Shdr
*sec
;
4251 Elf_Internal_Sym
*sym
;
4253 /* Get the symbol table. */
4254 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
4255 || ((sec
= SECTION_HEADER (section
->sh_link
))->sh_type
4258 error (_("Bad sh_link in group section `%s'\n"), name
);
4262 if (symtab_sec
!= sec
)
4267 symtab
= GET_ELF_SYMBOLS (file
, symtab_sec
);
4270 sym
= symtab
+ section
->sh_info
;
4272 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4274 bfd_vma sec_index
= SECTION_HEADER_INDEX (sym
->st_shndx
);
4277 error (_("Bad sh_info in group section `%s'\n"), name
);
4281 group_name
= SECTION_NAME (section_headers
+ sec_index
);
4290 /* Get the string table. */
4291 if (SECTION_HEADER_INDEX (symtab_sec
->sh_link
)
4292 >= elf_header
.e_shnum
)
4301 != (sec
= SECTION_HEADER (symtab_sec
->sh_link
)))
4306 strtab
= get_data (NULL
, file
, strtab_sec
->sh_offset
,
4307 1, strtab_sec
->sh_size
,
4309 strtab_size
= strtab
!= NULL
? strtab_sec
->sh_size
: 0;
4311 group_name
= sym
->st_name
< strtab_size
4312 ? strtab
+ sym
->st_name
: "<corrupt>";
4315 start
= get_data (NULL
, file
, section
->sh_offset
,
4316 1, section
->sh_size
, _("section data"));
4319 size
= (section
->sh_size
/ section
->sh_entsize
) - 1;
4320 entry
= byte_get (indices
, 4);
4323 if (do_section_groups
)
4325 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4326 get_group_flags (entry
), i
, name
, group_name
, size
);
4328 printf (_(" [Index] Name\n"));
4331 group
->group_index
= i
;
4333 for (j
= 0; j
< size
; j
++)
4335 struct group_list
*g
;
4337 entry
= byte_get (indices
, 4);
4340 if (SECTION_HEADER_INDEX (entry
) >= elf_header
.e_shnum
)
4342 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4343 entry
, i
, elf_header
.e_shnum
- 1);
4346 else if (entry
>= SHN_LORESERVE
&& entry
<= SHN_HIRESERVE
)
4348 error (_("invalid section [%5u] in group section [%5u]\n"),
4353 if (section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4358 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4360 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4365 /* Intel C/C++ compiler may put section 0 in a
4366 section group. We just warn it the first time
4367 and ignore it afterwards. */
4368 static int warned
= 0;
4371 error (_("section 0 in group section [%5u]\n"),
4372 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]->group_index
);
4378 section_headers_groups
[SECTION_HEADER_INDEX (entry
)]
4381 if (do_section_groups
)
4383 sec
= SECTION_HEADER (entry
);
4384 printf (" [%5u] %s\n", entry
, SECTION_NAME (sec
));
4387 g
= xmalloc (sizeof (struct group_list
));
4388 g
->section_index
= entry
;
4389 g
->next
= group
->root
;
4413 } dynamic_relocations
[] =
4415 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
4416 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
4417 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
4420 /* Process the reloc section. */
4423 process_relocs (FILE *file
)
4425 unsigned long rel_size
;
4426 unsigned long rel_offset
;
4432 if (do_using_dynamic
)
4436 int has_dynamic_reloc
;
4439 has_dynamic_reloc
= 0;
4441 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
4443 is_rela
= dynamic_relocations
[i
].rela
;
4444 name
= dynamic_relocations
[i
].name
;
4445 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
4446 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
4448 has_dynamic_reloc
|= rel_size
;
4450 if (is_rela
== UNKNOWN
)
4452 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
4453 switch (dynamic_info
[DT_PLTREL
])
4467 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4468 name
, rel_offset
, rel_size
);
4470 dump_relocations (file
,
4471 offset_from_vma (file
, rel_offset
, rel_size
),
4473 dynamic_symbols
, num_dynamic_syms
,
4474 dynamic_strings
, dynamic_strings_length
, is_rela
);
4478 if (! has_dynamic_reloc
)
4479 printf (_("\nThere are no dynamic relocations in this file.\n"));
4483 Elf_Internal_Shdr
*section
;
4487 for (i
= 0, section
= section_headers
;
4488 i
< elf_header
.e_shnum
;
4491 if ( section
->sh_type
!= SHT_RELA
4492 && section
->sh_type
!= SHT_REL
)
4495 rel_offset
= section
->sh_offset
;
4496 rel_size
= section
->sh_size
;
4500 Elf_Internal_Shdr
*strsec
;
4503 printf (_("\nRelocation section "));
4505 if (string_table
== NULL
)
4506 printf ("%d", section
->sh_name
);
4508 printf (_("'%s'"), SECTION_NAME (section
));
4510 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4511 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
4513 is_rela
= section
->sh_type
== SHT_RELA
;
4515 if (section
->sh_link
4516 && SECTION_HEADER_INDEX (section
->sh_link
)
4517 < elf_header
.e_shnum
)
4519 Elf_Internal_Shdr
*symsec
;
4520 Elf_Internal_Sym
*symtab
;
4521 unsigned long nsyms
;
4522 unsigned long strtablen
= 0;
4523 char *strtab
= NULL
;
4525 symsec
= SECTION_HEADER (section
->sh_link
);
4526 if (symsec
->sh_type
!= SHT_SYMTAB
4527 && symsec
->sh_type
!= SHT_DYNSYM
)
4530 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4531 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4536 if (SECTION_HEADER_INDEX (symsec
->sh_link
)
4537 < elf_header
.e_shnum
)
4539 strsec
= SECTION_HEADER (symsec
->sh_link
);
4541 strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4544 strtablen
= strtab
== NULL
? 0 : strsec
->sh_size
;
4547 dump_relocations (file
, rel_offset
, rel_size
,
4548 symtab
, nsyms
, strtab
, strtablen
, is_rela
);
4554 dump_relocations (file
, rel_offset
, rel_size
,
4555 NULL
, 0, NULL
, 0, is_rela
);
4562 printf (_("\nThere are no relocations in this file.\n"));
4568 /* Process the unwind section. */
4570 #include "unwind-ia64.h"
4572 /* An absolute address consists of a section and an offset. If the
4573 section is NULL, the offset itself is the address, otherwise, the
4574 address equals to LOAD_ADDRESS(section) + offset. */
4578 unsigned short section
;
4582 struct ia64_unw_aux_info
4584 struct ia64_unw_table_entry
4586 struct absaddr start
;
4588 struct absaddr info
;
4590 *table
; /* Unwind table. */
4591 unsigned long table_len
; /* Length of unwind table. */
4592 unsigned char *info
; /* Unwind info. */
4593 unsigned long info_size
; /* Size of unwind info. */
4594 bfd_vma info_addr
; /* starting address of unwind info. */
4595 bfd_vma seg_base
; /* Starting address of segment. */
4596 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4597 unsigned long nsyms
; /* Number of symbols. */
4598 char *strtab
; /* The string table. */
4599 unsigned long strtab_size
; /* Size of string table. */
4603 find_symbol_for_address (Elf_Internal_Sym
*symtab
,
4604 unsigned long nsyms
,
4606 unsigned long strtab_size
,
4607 struct absaddr addr
,
4608 const char **symname
,
4611 bfd_vma dist
= 0x100000;
4612 Elf_Internal_Sym
*sym
, *best
= NULL
;
4615 for (i
= 0, sym
= symtab
; i
< nsyms
; ++i
, ++sym
)
4617 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4618 && sym
->st_name
!= 0
4619 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4620 && addr
.offset
>= sym
->st_value
4621 && addr
.offset
- sym
->st_value
< dist
)
4624 dist
= addr
.offset
- sym
->st_value
;
4631 *symname
= (best
->st_name
>= strtab_size
4632 ? "<corrupt>" : strtab
+ best
->st_name
);
4637 *offset
= addr
.offset
;
4641 dump_ia64_unwind (struct ia64_unw_aux_info
*aux
)
4643 struct ia64_unw_table_entry
*tp
;
4646 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4650 const unsigned char *dp
;
4651 const unsigned char *head
;
4652 const char *procname
;
4654 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
4655 aux
->strtab_size
, tp
->start
, &procname
, &offset
);
4657 fputs ("\n<", stdout
);
4661 fputs (procname
, stdout
);
4664 printf ("+%lx", (unsigned long) offset
);
4667 fputs (">: [", stdout
);
4668 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4669 fputc ('-', stdout
);
4670 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4671 printf ("], info at +0x%lx\n",
4672 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4674 head
= aux
->info
+ (tp
->info
.offset
- aux
->info_addr
);
4675 stamp
= byte_get ((unsigned char *) head
, sizeof (stamp
));
4677 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4678 (unsigned) UNW_VER (stamp
),
4679 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4680 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4681 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4682 (unsigned long) (eh_addr_size
* UNW_LENGTH (stamp
)));
4684 if (UNW_VER (stamp
) != 1)
4686 printf ("\tUnknown version.\n");
4691 for (dp
= head
+ 8; dp
< head
+ 8 + eh_addr_size
* UNW_LENGTH (stamp
);)
4692 dp
= unw_decode (dp
, in_body
, & in_body
);
4697 slurp_ia64_unwind_table (FILE *file
,
4698 struct ia64_unw_aux_info
*aux
,
4699 Elf_Internal_Shdr
*sec
)
4701 unsigned long size
, nrelas
, i
;
4702 Elf_Internal_Phdr
*seg
;
4703 struct ia64_unw_table_entry
*tep
;
4704 Elf_Internal_Shdr
*relsec
;
4705 Elf_Internal_Rela
*rela
, *rp
;
4706 unsigned char *table
, *tp
;
4707 Elf_Internal_Sym
*sym
;
4708 const char *relname
;
4710 /* First, find the starting address of the segment that includes
4713 if (elf_header
.e_phnum
)
4715 if (! get_program_headers (file
))
4718 for (seg
= program_headers
;
4719 seg
< program_headers
+ elf_header
.e_phnum
;
4722 if (seg
->p_type
!= PT_LOAD
)
4725 if (sec
->sh_addr
>= seg
->p_vaddr
4726 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4728 aux
->seg_base
= seg
->p_vaddr
;
4734 /* Second, build the unwind table from the contents of the unwind section: */
4735 size
= sec
->sh_size
;
4736 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
4740 aux
->table
= xcmalloc (size
/ (3 * eh_addr_size
), sizeof (aux
->table
[0]));
4742 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * eh_addr_size
, ++tep
)
4744 tep
->start
.section
= SHN_UNDEF
;
4745 tep
->end
.section
= SHN_UNDEF
;
4746 tep
->info
.section
= SHN_UNDEF
;
4749 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4750 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4751 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4755 tep
->start
.offset
= BYTE_GET ((unsigned char *) tp
+ 0);
4756 tep
->end
.offset
= BYTE_GET ((unsigned char *) tp
+ 8);
4757 tep
->info
.offset
= BYTE_GET ((unsigned char *) tp
+ 16);
4759 tep
->start
.offset
+= aux
->seg_base
;
4760 tep
->end
.offset
+= aux
->seg_base
;
4761 tep
->info
.offset
+= aux
->seg_base
;
4765 /* Third, apply any relocations to the unwind table: */
4767 for (relsec
= section_headers
;
4768 relsec
< section_headers
+ elf_header
.e_shnum
;
4771 if (relsec
->sh_type
!= SHT_RELA
4772 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
4773 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4776 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4780 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4784 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4785 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4789 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4790 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4793 if (! strneq (relname
, "R_IA64_SEGREL", 13))
4795 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4799 i
= rp
->r_offset
/ (3 * eh_addr_size
);
4801 switch (rp
->r_offset
/eh_addr_size
% 3)
4804 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4805 aux
->table
[i
].start
.offset
+= rp
->r_addend
+ sym
->st_value
;
4808 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4809 aux
->table
[i
].end
.offset
+= rp
->r_addend
+ sym
->st_value
;
4812 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4813 aux
->table
[i
].info
.offset
+= rp
->r_addend
+ sym
->st_value
;
4823 aux
->table_len
= size
/ (3 * eh_addr_size
);
4828 ia64_process_unwind (FILE *file
)
4830 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4831 unsigned long i
, unwcount
= 0, unwstart
= 0;
4832 struct ia64_unw_aux_info aux
;
4834 memset (& aux
, 0, sizeof (aux
));
4836 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4838 if (sec
->sh_type
== SHT_SYMTAB
4839 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
4841 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4842 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4844 strsec
= SECTION_HEADER (sec
->sh_link
);
4845 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
4846 1, strsec
->sh_size
, _("string table"));
4847 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
4849 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4854 printf (_("\nThere are no unwind sections in this file.\n"));
4856 while (unwcount
-- > 0)
4861 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4862 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4863 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4870 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4872 if ((unwsec
->sh_flags
& SHF_GROUP
) != 0)
4874 /* We need to find which section group it is in. */
4875 struct group_list
*g
= section_headers_groups
[i
]->root
;
4877 for (; g
!= NULL
; g
= g
->next
)
4879 sec
= SECTION_HEADER (g
->section_index
);
4881 if (streq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
))
4886 i
= elf_header
.e_shnum
;
4888 else if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
, len
))
4890 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
4891 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4892 suffix
= SECTION_NAME (unwsec
) + len
;
4893 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4895 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info_once
, len2
)
4896 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4901 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4902 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
4903 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4904 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4906 if (strneq (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
, len
))
4907 suffix
= SECTION_NAME (unwsec
) + len
;
4908 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4910 if (strneq (SECTION_NAME (sec
), ELF_STRING_ia64_unwind_info
, len2
)
4911 && streq (SECTION_NAME (sec
) + len2
, suffix
))
4915 if (i
== elf_header
.e_shnum
)
4917 printf (_("\nCould not find unwind info section for "));
4919 if (string_table
== NULL
)
4920 printf ("%d", unwsec
->sh_name
);
4922 printf (_("'%s'"), SECTION_NAME (unwsec
));
4926 aux
.info_size
= sec
->sh_size
;
4927 aux
.info_addr
= sec
->sh_addr
;
4928 aux
.info
= get_data (NULL
, file
, sec
->sh_offset
, 1, aux
.info_size
,
4931 printf (_("\nUnwind section "));
4933 if (string_table
== NULL
)
4934 printf ("%d", unwsec
->sh_name
);
4936 printf (_("'%s'"), SECTION_NAME (unwsec
));
4938 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4939 (unsigned long) unwsec
->sh_offset
,
4940 (unsigned long) (unwsec
->sh_size
/ (3 * eh_addr_size
)));
4942 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4944 if (aux
.table_len
> 0)
4945 dump_ia64_unwind (& aux
);
4948 free ((char *) aux
.table
);
4950 free ((char *) aux
.info
);
4959 free ((char *) aux
.strtab
);
4964 struct hppa_unw_aux_info
4966 struct hppa_unw_table_entry
4968 struct absaddr start
;
4970 unsigned int Cannot_unwind
:1; /* 0 */
4971 unsigned int Millicode
:1; /* 1 */
4972 unsigned int Millicode_save_sr0
:1; /* 2 */
4973 unsigned int Region_description
:2; /* 3..4 */
4974 unsigned int reserved1
:1; /* 5 */
4975 unsigned int Entry_SR
:1; /* 6 */
4976 unsigned int Entry_FR
:4; /* number saved */ /* 7..10 */
4977 unsigned int Entry_GR
:5; /* number saved */ /* 11..15 */
4978 unsigned int Args_stored
:1; /* 16 */
4979 unsigned int Variable_Frame
:1; /* 17 */
4980 unsigned int Separate_Package_Body
:1; /* 18 */
4981 unsigned int Frame_Extension_Millicode
:1; /* 19 */
4982 unsigned int Stack_Overflow_Check
:1; /* 20 */
4983 unsigned int Two_Instruction_SP_Increment
:1; /* 21 */
4984 unsigned int Ada_Region
:1; /* 22 */
4985 unsigned int cxx_info
:1; /* 23 */
4986 unsigned int cxx_try_catch
:1; /* 24 */
4987 unsigned int sched_entry_seq
:1; /* 25 */
4988 unsigned int reserved2
:1; /* 26 */
4989 unsigned int Save_SP
:1; /* 27 */
4990 unsigned int Save_RP
:1; /* 28 */
4991 unsigned int Save_MRP_in_frame
:1; /* 29 */
4992 unsigned int extn_ptr_defined
:1; /* 30 */
4993 unsigned int Cleanup_defined
:1; /* 31 */
4995 unsigned int MPE_XL_interrupt_marker
:1; /* 0 */
4996 unsigned int HP_UX_interrupt_marker
:1; /* 1 */
4997 unsigned int Large_frame
:1; /* 2 */
4998 unsigned int Pseudo_SP_Set
:1; /* 3 */
4999 unsigned int reserved4
:1; /* 4 */
5000 unsigned int Total_frame_size
:27; /* 5..31 */
5002 *table
; /* Unwind table. */
5003 unsigned long table_len
; /* Length of unwind table. */
5004 bfd_vma seg_base
; /* Starting address of segment. */
5005 Elf_Internal_Sym
*symtab
; /* The symbol table. */
5006 unsigned long nsyms
; /* Number of symbols. */
5007 char *strtab
; /* The string table. */
5008 unsigned long strtab_size
; /* Size of string table. */
5012 dump_hppa_unwind (struct hppa_unw_aux_info
*aux
)
5014 struct hppa_unw_table_entry
*tp
;
5016 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
5019 const char *procname
;
5021 find_symbol_for_address (aux
->symtab
, aux
->nsyms
, aux
->strtab
,
5022 aux
->strtab_size
, tp
->start
, &procname
,
5025 fputs ("\n<", stdout
);
5029 fputs (procname
, stdout
);
5032 printf ("+%lx", (unsigned long) offset
);
5035 fputs (">: [", stdout
);
5036 print_vma (tp
->start
.offset
, PREFIX_HEX
);
5037 fputc ('-', stdout
);
5038 print_vma (tp
->end
.offset
, PREFIX_HEX
);
5041 #define PF(_m) if (tp->_m) printf (#_m " ");
5042 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5045 PF(Millicode_save_sr0
);
5046 /* PV(Region_description); */
5052 PF(Separate_Package_Body
);
5053 PF(Frame_Extension_Millicode
);
5054 PF(Stack_Overflow_Check
);
5055 PF(Two_Instruction_SP_Increment
);
5059 PF(sched_entry_seq
);
5062 PF(Save_MRP_in_frame
);
5063 PF(extn_ptr_defined
);
5064 PF(Cleanup_defined
);
5065 PF(MPE_XL_interrupt_marker
);
5066 PF(HP_UX_interrupt_marker
);
5069 PV(Total_frame_size
);
5078 slurp_hppa_unwind_table (FILE *file
,
5079 struct hppa_unw_aux_info
*aux
,
5080 Elf_Internal_Shdr
*sec
)
5082 unsigned long size
, unw_ent_size
, nentries
, nrelas
, i
;
5083 Elf_Internal_Phdr
*seg
;
5084 struct hppa_unw_table_entry
*tep
;
5085 Elf_Internal_Shdr
*relsec
;
5086 Elf_Internal_Rela
*rela
, *rp
;
5087 unsigned char *table
, *tp
;
5088 Elf_Internal_Sym
*sym
;
5089 const char *relname
;
5091 /* First, find the starting address of the segment that includes
5094 if (elf_header
.e_phnum
)
5096 if (! get_program_headers (file
))
5099 for (seg
= program_headers
;
5100 seg
< program_headers
+ elf_header
.e_phnum
;
5103 if (seg
->p_type
!= PT_LOAD
)
5106 if (sec
->sh_addr
>= seg
->p_vaddr
5107 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
5109 aux
->seg_base
= seg
->p_vaddr
;
5115 /* Second, build the unwind table from the contents of the unwind
5117 size
= sec
->sh_size
;
5118 table
= get_data (NULL
, file
, sec
->sh_offset
, 1, size
, _("unwind table"));
5123 nentries
= size
/ unw_ent_size
;
5124 size
= unw_ent_size
* nentries
;
5126 tep
= aux
->table
= xcmalloc (nentries
, sizeof (aux
->table
[0]));
5128 for (tp
= table
; tp
< table
+ size
; tp
+= unw_ent_size
, ++tep
)
5130 unsigned int tmp1
, tmp2
;
5132 tep
->start
.section
= SHN_UNDEF
;
5133 tep
->end
.section
= SHN_UNDEF
;
5135 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
5136 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
5137 tmp1
= byte_get ((unsigned char *) tp
+ 8, 4);
5138 tmp2
= byte_get ((unsigned char *) tp
+ 12, 4);
5140 tep
->start
.offset
+= aux
->seg_base
;
5141 tep
->end
.offset
+= aux
->seg_base
;
5143 tep
->Cannot_unwind
= (tmp1
>> 31) & 0x1;
5144 tep
->Millicode
= (tmp1
>> 30) & 0x1;
5145 tep
->Millicode_save_sr0
= (tmp1
>> 29) & 0x1;
5146 tep
->Region_description
= (tmp1
>> 27) & 0x3;
5147 tep
->reserved1
= (tmp1
>> 26) & 0x1;
5148 tep
->Entry_SR
= (tmp1
>> 25) & 0x1;
5149 tep
->Entry_FR
= (tmp1
>> 21) & 0xf;
5150 tep
->Entry_GR
= (tmp1
>> 16) & 0x1f;
5151 tep
->Args_stored
= (tmp1
>> 15) & 0x1;
5152 tep
->Variable_Frame
= (tmp1
>> 14) & 0x1;
5153 tep
->Separate_Package_Body
= (tmp1
>> 13) & 0x1;
5154 tep
->Frame_Extension_Millicode
= (tmp1
>> 12) & 0x1;
5155 tep
->Stack_Overflow_Check
= (tmp1
>> 11) & 0x1;
5156 tep
->Two_Instruction_SP_Increment
= (tmp1
>> 10) & 0x1;
5157 tep
->Ada_Region
= (tmp1
>> 9) & 0x1;
5158 tep
->cxx_info
= (tmp1
>> 8) & 0x1;
5159 tep
->cxx_try_catch
= (tmp1
>> 7) & 0x1;
5160 tep
->sched_entry_seq
= (tmp1
>> 6) & 0x1;
5161 tep
->reserved2
= (tmp1
>> 5) & 0x1;
5162 tep
->Save_SP
= (tmp1
>> 4) & 0x1;
5163 tep
->Save_RP
= (tmp1
>> 3) & 0x1;
5164 tep
->Save_MRP_in_frame
= (tmp1
>> 2) & 0x1;
5165 tep
->extn_ptr_defined
= (tmp1
>> 1) & 0x1;
5166 tep
->Cleanup_defined
= tmp1
& 0x1;
5168 tep
->MPE_XL_interrupt_marker
= (tmp2
>> 31) & 0x1;
5169 tep
->HP_UX_interrupt_marker
= (tmp2
>> 30) & 0x1;
5170 tep
->Large_frame
= (tmp2
>> 29) & 0x1;
5171 tep
->Pseudo_SP_Set
= (tmp2
>> 28) & 0x1;
5172 tep
->reserved4
= (tmp2
>> 27) & 0x1;
5173 tep
->Total_frame_size
= tmp2
& 0x7ffffff;
5177 /* Third, apply any relocations to the unwind table. */
5179 for (relsec
= section_headers
;
5180 relsec
< section_headers
+ elf_header
.e_shnum
;
5183 if (relsec
->sh_type
!= SHT_RELA
5184 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
5185 || SECTION_HEADER (relsec
->sh_info
) != sec
)
5188 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
5192 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
5196 relname
= elf_hppa_reloc_type (ELF32_R_TYPE (rp
->r_info
));
5197 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
5201 relname
= elf_hppa_reloc_type (ELF64_R_TYPE (rp
->r_info
));
5202 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
5205 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5206 if (strncmp (relname
, "R_PARISC_SEGREL", 15) != 0)
5208 warn (_("Skipping unexpected relocation type %s\n"), relname
);
5212 i
= rp
->r_offset
/ unw_ent_size
;
5214 switch ((rp
->r_offset
% unw_ent_size
) / eh_addr_size
)
5217 aux
->table
[i
].start
.section
= sym
->st_shndx
;
5218 aux
->table
[i
].start
.offset
+= sym
->st_value
+ rp
->r_addend
;
5221 aux
->table
[i
].end
.section
= sym
->st_shndx
;
5222 aux
->table
[i
].end
.offset
+= sym
->st_value
+ rp
->r_addend
;
5232 aux
->table_len
= nentries
;
5238 hppa_process_unwind (FILE *file
)
5240 struct hppa_unw_aux_info aux
;
5241 Elf_Internal_Shdr
*unwsec
= NULL
;
5242 Elf_Internal_Shdr
*strsec
;
5243 Elf_Internal_Shdr
*sec
;
5246 memset (& aux
, 0, sizeof (aux
));
5248 if (string_table
== NULL
)
5251 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5253 if (sec
->sh_type
== SHT_SYMTAB
5254 && SECTION_HEADER_INDEX (sec
->sh_link
) < elf_header
.e_shnum
)
5256 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
5257 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
5259 strsec
= SECTION_HEADER (sec
->sh_link
);
5260 aux
.strtab
= get_data (NULL
, file
, strsec
->sh_offset
,
5261 1, strsec
->sh_size
, _("string table"));
5262 aux
.strtab_size
= aux
.strtab
!= NULL
? strsec
->sh_size
: 0;
5264 else if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5269 printf (_("\nThere are no unwind sections in this file.\n"));
5271 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
5273 if (streq (SECTION_NAME (sec
), ".PARISC.unwind"))
5275 printf (_("\nUnwind section "));
5276 printf (_("'%s'"), SECTION_NAME (sec
));
5278 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5279 (unsigned long) sec
->sh_offset
,
5280 (unsigned long) (sec
->sh_size
/ (2 * eh_addr_size
+ 8)));
5282 slurp_hppa_unwind_table (file
, &aux
, sec
);
5283 if (aux
.table_len
> 0)
5284 dump_hppa_unwind (&aux
);
5287 free ((char *) aux
.table
);
5295 free ((char *) aux
.strtab
);
5301 process_unwind (FILE *file
)
5303 struct unwind_handler
{
5305 int (*handler
)(FILE *file
);
5307 { EM_IA_64
, ia64_process_unwind
},
5308 { EM_PARISC
, hppa_process_unwind
},
5316 for (i
= 0; handlers
[i
].handler
!= NULL
; i
++)
5317 if (elf_header
.e_machine
== handlers
[i
].machtype
)
5318 return handlers
[i
].handler (file
);
5320 printf (_("\nThere are no unwind sections in this file.\n"));
5325 dynamic_section_mips_val (Elf_Internal_Dyn
*entry
)
5327 switch (entry
->d_tag
)
5330 if (entry
->d_un
.d_val
== 0)
5334 static const char * opts
[] =
5336 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5337 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5338 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5339 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5344 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
5345 if (entry
->d_un
.d_val
& (1 << cnt
))
5347 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
5354 case DT_MIPS_IVERSION
:
5355 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5356 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5358 printf ("<corrupt: %ld>\n", (long) entry
->d_un
.d_ptr
);
5361 case DT_MIPS_TIME_STAMP
:
5366 time_t time
= entry
->d_un
.d_val
;
5367 tmp
= gmtime (&time
);
5368 snprintf (timebuf
, sizeof (timebuf
), "%04u-%02u-%02uT%02u:%02u:%02u",
5369 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5370 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5371 printf ("Time Stamp: %s\n", timebuf
);
5375 case DT_MIPS_RLD_VERSION
:
5376 case DT_MIPS_LOCAL_GOTNO
:
5377 case DT_MIPS_CONFLICTNO
:
5378 case DT_MIPS_LIBLISTNO
:
5379 case DT_MIPS_SYMTABNO
:
5380 case DT_MIPS_UNREFEXTNO
:
5381 case DT_MIPS_HIPAGENO
:
5382 case DT_MIPS_DELTA_CLASS_NO
:
5383 case DT_MIPS_DELTA_INSTANCE_NO
:
5384 case DT_MIPS_DELTA_RELOC_NO
:
5385 case DT_MIPS_DELTA_SYM_NO
:
5386 case DT_MIPS_DELTA_CLASSSYM_NO
:
5387 case DT_MIPS_COMPACT_SIZE
:
5388 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
5392 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
5398 dynamic_section_parisc_val (Elf_Internal_Dyn
*entry
)
5400 switch (entry
->d_tag
)
5402 case DT_HP_DLD_FLAGS
:
5411 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
5412 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
5413 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
5414 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
5415 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
5416 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
5417 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
5418 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
5419 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
5420 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
5421 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" },
5422 { DT_HP_GST
, "HP_GST" },
5423 { DT_HP_SHLIB_FIXED
, "HP_SHLIB_FIXED" },
5424 { DT_HP_MERGE_SHLIB_SEG
, "HP_MERGE_SHLIB_SEG" },
5425 { DT_HP_NODELETE
, "HP_NODELETE" },
5426 { DT_HP_GROUP
, "HP_GROUP" },
5427 { DT_HP_PROTECT_LINKAGE_TABLE
, "HP_PROTECT_LINKAGE_TABLE" }
5431 bfd_vma val
= entry
->d_un
.d_val
;
5433 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
5434 if (val
& flags
[cnt
].bit
)
5438 fputs (flags
[cnt
].str
, stdout
);
5440 val
^= flags
[cnt
].bit
;
5443 if (val
!= 0 || first
)
5447 print_vma (val
, HEX
);
5453 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5460 dynamic_section_ia64_val (Elf_Internal_Dyn
*entry
)
5462 switch (entry
->d_tag
)
5464 case DT_IA_64_PLT_RESERVE
:
5465 /* First 3 slots reserved. */
5466 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5468 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
5472 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
5479 get_32bit_dynamic_section (FILE *file
)
5481 Elf32_External_Dyn
*edyn
, *ext
;
5482 Elf_Internal_Dyn
*entry
;
5484 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5485 _("dynamic section"));
5489 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5490 might not have the luxury of section headers. Look for the DT_NULL
5491 terminator to determine the number of entries. */
5492 for (ext
= edyn
, dynamic_nent
= 0;
5493 (char *) ext
< (char *) edyn
+ dynamic_size
;
5497 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5501 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5502 if (dynamic_section
== NULL
)
5504 error (_("Out of memory\n"));
5509 for (ext
= edyn
, entry
= dynamic_section
;
5510 entry
< dynamic_section
+ dynamic_nent
;
5513 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5514 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5523 get_64bit_dynamic_section (FILE *file
)
5525 Elf64_External_Dyn
*edyn
, *ext
;
5526 Elf_Internal_Dyn
*entry
;
5528 edyn
= get_data (NULL
, file
, dynamic_addr
, 1, dynamic_size
,
5529 _("dynamic section"));
5533 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5534 might not have the luxury of section headers. Look for the DT_NULL
5535 terminator to determine the number of entries. */
5536 for (ext
= edyn
, dynamic_nent
= 0;
5537 (char *) ext
< (char *) edyn
+ dynamic_size
;
5541 if (BYTE_GET (ext
->d_tag
) == DT_NULL
)
5545 dynamic_section
= cmalloc (dynamic_nent
, sizeof (*entry
));
5546 if (dynamic_section
== NULL
)
5548 error (_("Out of memory\n"));
5553 for (ext
= edyn
, entry
= dynamic_section
;
5554 entry
< dynamic_section
+ dynamic_nent
;
5557 entry
->d_tag
= BYTE_GET (ext
->d_tag
);
5558 entry
->d_un
.d_val
= BYTE_GET (ext
->d_un
.d_val
);
5567 print_dynamic_flags (bfd_vma flags
)
5575 flag
= flags
& - flags
;
5585 case DF_ORIGIN
: fputs ("ORIGIN", stdout
); break;
5586 case DF_SYMBOLIC
: fputs ("SYMBOLIC", stdout
); break;
5587 case DF_TEXTREL
: fputs ("TEXTREL", stdout
); break;
5588 case DF_BIND_NOW
: fputs ("BIND_NOW", stdout
); break;
5589 case DF_STATIC_TLS
: fputs ("STATIC_TLS", stdout
); break;
5590 default: fputs ("unknown", stdout
); break;
5596 /* Parse and display the contents of the dynamic section. */
5599 process_dynamic_section (FILE *file
)
5601 Elf_Internal_Dyn
*entry
;
5603 if (dynamic_size
== 0)
5606 printf (_("\nThere is no dynamic section in this file.\n"));
5613 if (! get_32bit_dynamic_section (file
))
5616 else if (! get_64bit_dynamic_section (file
))
5619 /* Find the appropriate symbol table. */
5620 if (dynamic_symbols
== NULL
)
5622 for (entry
= dynamic_section
;
5623 entry
< dynamic_section
+ dynamic_nent
;
5626 Elf_Internal_Shdr section
;
5628 if (entry
->d_tag
!= DT_SYMTAB
)
5631 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
5633 /* Since we do not know how big the symbol table is,
5634 we default to reading in the entire file (!) and
5635 processing that. This is overkill, I know, but it
5637 section
.sh_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5639 if (archive_file_offset
!= 0)
5640 section
.sh_size
= archive_file_size
- section
.sh_offset
;
5643 if (fseek (file
, 0, SEEK_END
))
5644 error (_("Unable to seek to end of file!"));
5646 section
.sh_size
= ftell (file
) - section
.sh_offset
;
5650 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
5652 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
5654 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
5655 if (num_dynamic_syms
< 1)
5657 error (_("Unable to determine the number of symbols to load\n"));
5661 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
5665 /* Similarly find a string table. */
5666 if (dynamic_strings
== NULL
)
5668 for (entry
= dynamic_section
;
5669 entry
< dynamic_section
+ dynamic_nent
;
5672 unsigned long offset
;
5675 if (entry
->d_tag
!= DT_STRTAB
)
5678 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
5680 /* Since we do not know how big the string table is,
5681 we default to reading in the entire file (!) and
5682 processing that. This is overkill, I know, but it
5685 offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
5687 if (archive_file_offset
!= 0)
5688 str_tab_len
= archive_file_size
- offset
;
5691 if (fseek (file
, 0, SEEK_END
))
5692 error (_("Unable to seek to end of file\n"));
5693 str_tab_len
= ftell (file
) - offset
;
5696 if (str_tab_len
< 1)
5699 (_("Unable to determine the length of the dynamic string table\n"));
5703 dynamic_strings
= get_data (NULL
, file
, offset
, 1, str_tab_len
,
5704 _("dynamic string table"));
5705 dynamic_strings_length
= str_tab_len
;
5710 /* And find the syminfo section if available. */
5711 if (dynamic_syminfo
== NULL
)
5713 unsigned long syminsz
= 0;
5715 for (entry
= dynamic_section
;
5716 entry
< dynamic_section
+ dynamic_nent
;
5719 if (entry
->d_tag
== DT_SYMINENT
)
5721 /* Note: these braces are necessary to avoid a syntax
5722 error from the SunOS4 C compiler. */
5723 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
5725 else if (entry
->d_tag
== DT_SYMINSZ
)
5726 syminsz
= entry
->d_un
.d_val
;
5727 else if (entry
->d_tag
== DT_SYMINFO
)
5728 dynamic_syminfo_offset
= offset_from_vma (file
, entry
->d_un
.d_val
,
5732 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
5734 Elf_External_Syminfo
*extsyminfo
, *extsym
;
5735 Elf_Internal_Syminfo
*syminfo
;
5737 /* There is a syminfo section. Read the data. */
5738 extsyminfo
= get_data (NULL
, file
, dynamic_syminfo_offset
, 1,
5739 syminsz
, _("symbol information"));
5743 dynamic_syminfo
= malloc (syminsz
);
5744 if (dynamic_syminfo
== NULL
)
5746 error (_("Out of memory\n"));
5750 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
5751 for (syminfo
= dynamic_syminfo
, extsym
= extsyminfo
;
5752 syminfo
< dynamic_syminfo
+ dynamic_syminfo_nent
;
5753 ++syminfo
, ++extsym
)
5755 syminfo
->si_boundto
= BYTE_GET (extsym
->si_boundto
);
5756 syminfo
->si_flags
= BYTE_GET (extsym
->si_flags
);
5763 if (do_dynamic
&& dynamic_addr
)
5764 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5765 dynamic_addr
, dynamic_nent
);
5767 printf (_(" Tag Type Name/Value\n"));
5769 for (entry
= dynamic_section
;
5770 entry
< dynamic_section
+ dynamic_nent
;
5778 print_vma (entry
->d_tag
, FULL_HEX
);
5779 dtype
= get_dynamic_type (entry
->d_tag
);
5780 printf (" (%s)%*s", dtype
,
5781 ((is_32bit_elf
? 27 : 19)
5782 - (int) strlen (dtype
)),
5786 switch (entry
->d_tag
)
5790 print_dynamic_flags (entry
->d_un
.d_val
);
5800 switch (entry
->d_tag
)
5803 printf (_("Auxiliary library"));
5807 printf (_("Filter library"));
5811 printf (_("Configuration file"));
5815 printf (_("Dependency audit library"));
5819 printf (_("Audit library"));
5823 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
5824 printf (": [%s]\n", GET_DYNAMIC_NAME (entry
->d_un
.d_val
));
5828 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5837 printf (_("Flags:"));
5839 if (entry
->d_un
.d_val
== 0)
5840 printf (_(" None\n"));
5843 unsigned long int val
= entry
->d_un
.d_val
;
5845 if (val
& DTF_1_PARINIT
)
5847 printf (" PARINIT");
5848 val
^= DTF_1_PARINIT
;
5850 if (val
& DTF_1_CONFEXP
)
5852 printf (" CONFEXP");
5853 val
^= DTF_1_CONFEXP
;
5856 printf (" %lx", val
);
5865 printf (_("Flags:"));
5867 if (entry
->d_un
.d_val
== 0)
5868 printf (_(" None\n"));
5871 unsigned long int val
= entry
->d_un
.d_val
;
5873 if (val
& DF_P1_LAZYLOAD
)
5875 printf (" LAZYLOAD");
5876 val
^= DF_P1_LAZYLOAD
;
5878 if (val
& DF_P1_GROUPPERM
)
5880 printf (" GROUPPERM");
5881 val
^= DF_P1_GROUPPERM
;
5884 printf (" %lx", val
);
5893 printf (_("Flags:"));
5894 if (entry
->d_un
.d_val
== 0)
5895 printf (_(" None\n"));
5898 unsigned long int val
= entry
->d_un
.d_val
;
5905 if (val
& DF_1_GLOBAL
)
5910 if (val
& DF_1_GROUP
)
5915 if (val
& DF_1_NODELETE
)
5917 printf (" NODELETE");
5918 val
^= DF_1_NODELETE
;
5920 if (val
& DF_1_LOADFLTR
)
5922 printf (" LOADFLTR");
5923 val
^= DF_1_LOADFLTR
;
5925 if (val
& DF_1_INITFIRST
)
5927 printf (" INITFIRST");
5928 val
^= DF_1_INITFIRST
;
5930 if (val
& DF_1_NOOPEN
)
5935 if (val
& DF_1_ORIGIN
)
5940 if (val
& DF_1_DIRECT
)
5945 if (val
& DF_1_TRANS
)
5950 if (val
& DF_1_INTERPOSE
)
5952 printf (" INTERPOSE");
5953 val
^= DF_1_INTERPOSE
;
5955 if (val
& DF_1_NODEFLIB
)
5957 printf (" NODEFLIB");
5958 val
^= DF_1_NODEFLIB
;
5960 if (val
& DF_1_NODUMP
)
5965 if (val
& DF_1_CONLFAT
)
5967 printf (" CONLFAT");
5968 val
^= DF_1_CONLFAT
;
5971 printf (" %lx", val
);
5978 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5980 puts (get_dynamic_type (entry
->d_un
.d_val
));
6000 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6006 if (VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6007 name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6013 switch (entry
->d_tag
)
6016 printf (_("Shared library: [%s]"), name
);
6018 if (streq (name
, program_interpreter
))
6019 printf (_(" program interpreter"));
6023 printf (_("Library soname: [%s]"), name
);
6027 printf (_("Library rpath: [%s]"), name
);
6031 printf (_("Library runpath: [%s]"), name
);
6035 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6040 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6053 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
6057 case DT_INIT_ARRAYSZ
:
6058 case DT_FINI_ARRAYSZ
:
6059 case DT_GNU_CONFLICTSZ
:
6060 case DT_GNU_LIBLISTSZ
:
6063 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6064 printf (" (bytes)\n");
6074 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
6087 if (entry
->d_tag
== DT_USED
6088 && VALID_DYNAMIC_NAME (entry
->d_un
.d_val
))
6090 char *name
= GET_DYNAMIC_NAME (entry
->d_un
.d_val
);
6094 printf (_("Not needed object: [%s]\n"), name
);
6099 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6105 /* The value of this entry is ignored. */
6110 case DT_GNU_PRELINKED
:
6114 time_t time
= entry
->d_un
.d_val
;
6116 tmp
= gmtime (&time
);
6117 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6118 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
6119 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
6125 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
6126 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
6131 switch (elf_header
.e_machine
)
6134 case EM_MIPS_RS3_LE
:
6135 dynamic_section_mips_val (entry
);
6138 dynamic_section_parisc_val (entry
);
6141 dynamic_section_ia64_val (entry
);
6144 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
6156 get_ver_flags (unsigned int flags
)
6158 static char buff
[32];
6165 if (flags
& VER_FLG_BASE
)
6166 strcat (buff
, "BASE ");
6168 if (flags
& VER_FLG_WEAK
)
6170 if (flags
& VER_FLG_BASE
)
6171 strcat (buff
, "| ");
6173 strcat (buff
, "WEAK ");
6176 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
6177 strcat (buff
, "| <unknown>");
6182 /* Display the contents of the version sections. */
6184 process_version_sections (FILE *file
)
6186 Elf_Internal_Shdr
*section
;
6193 for (i
= 0, section
= section_headers
;
6194 i
< elf_header
.e_shnum
;
6197 switch (section
->sh_type
)
6199 case SHT_GNU_verdef
:
6201 Elf_External_Verdef
*edefs
;
6208 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6209 SECTION_NAME (section
), section
->sh_info
);
6211 printf (_(" Addr: 0x"));
6212 printf_vma (section
->sh_addr
);
6213 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6214 (unsigned long) section
->sh_offset
, section
->sh_link
,
6215 SECTION_HEADER_INDEX (section
->sh_link
)
6216 < elf_header
.e_shnum
6217 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6220 edefs
= get_data (NULL
, file
, section
->sh_offset
, 1,
6222 _("version definition section"));
6226 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6229 Elf_External_Verdef
*edef
;
6230 Elf_Internal_Verdef ent
;
6231 Elf_External_Verdaux
*eaux
;
6232 Elf_Internal_Verdaux aux
;
6236 vstart
= ((char *) edefs
) + idx
;
6238 edef
= (Elf_External_Verdef
*) vstart
;
6240 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
6241 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
6242 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
6243 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
6244 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
6245 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
6246 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
6248 printf (_(" %#06x: Rev: %d Flags: %s"),
6249 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
6251 printf (_(" Index: %d Cnt: %d "),
6252 ent
.vd_ndx
, ent
.vd_cnt
);
6254 vstart
+= ent
.vd_aux
;
6256 eaux
= (Elf_External_Verdaux
*) vstart
;
6258 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6259 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6261 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6262 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux
.vda_name
));
6264 printf (_("Name index: %ld\n"), aux
.vda_name
);
6266 isum
= idx
+ ent
.vd_aux
;
6268 for (j
= 1; j
< ent
.vd_cnt
; j
++)
6270 isum
+= aux
.vda_next
;
6271 vstart
+= aux
.vda_next
;
6273 eaux
= (Elf_External_Verdaux
*) vstart
;
6275 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
6276 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
6278 if (VALID_DYNAMIC_NAME (aux
.vda_name
))
6279 printf (_(" %#06x: Parent %d: %s\n"),
6280 isum
, j
, GET_DYNAMIC_NAME (aux
.vda_name
));
6282 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6283 isum
, j
, aux
.vda_name
);
6293 case SHT_GNU_verneed
:
6295 Elf_External_Verneed
*eneed
;
6301 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6302 SECTION_NAME (section
), section
->sh_info
);
6304 printf (_(" Addr: 0x"));
6305 printf_vma (section
->sh_addr
);
6306 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6307 (unsigned long) section
->sh_offset
, section
->sh_link
,
6308 SECTION_HEADER_INDEX (section
->sh_link
)
6309 < elf_header
.e_shnum
6310 ? SECTION_NAME (SECTION_HEADER (section
->sh_link
))
6313 eneed
= get_data (NULL
, file
, section
->sh_offset
, 1,
6315 _("version need section"));
6319 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
6321 Elf_External_Verneed
*entry
;
6322 Elf_Internal_Verneed ent
;
6327 vstart
= ((char *) eneed
) + idx
;
6329 entry
= (Elf_External_Verneed
*) vstart
;
6331 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
6332 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
6333 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
6334 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
6335 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
6337 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
6339 if (VALID_DYNAMIC_NAME (ent
.vn_file
))
6340 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent
.vn_file
));
6342 printf (_(" File: %lx"), ent
.vn_file
);
6344 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
6346 vstart
+= ent
.vn_aux
;
6348 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
6350 Elf_External_Vernaux
*eaux
;
6351 Elf_Internal_Vernaux aux
;
6353 eaux
= (Elf_External_Vernaux
*) vstart
;
6355 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
6356 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
6357 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
6358 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
6359 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
6361 if (VALID_DYNAMIC_NAME (aux
.vna_name
))
6362 printf (_(" %#06x: Name: %s"),
6363 isum
, GET_DYNAMIC_NAME (aux
.vna_name
));
6365 printf (_(" %#06x: Name index: %lx"),
6366 isum
, aux
.vna_name
);
6368 printf (_(" Flags: %s Version: %d\n"),
6369 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
6371 isum
+= aux
.vna_next
;
6372 vstart
+= aux
.vna_next
;
6382 case SHT_GNU_versym
:
6384 Elf_Internal_Shdr
*link_section
;
6387 unsigned char *edata
;
6388 unsigned short *data
;
6390 Elf_Internal_Sym
*symbols
;
6391 Elf_Internal_Shdr
*string_sec
;
6394 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
6397 link_section
= SECTION_HEADER (section
->sh_link
);
6398 total
= section
->sh_size
/ sizeof (Elf_External_Versym
);
6400 if (SECTION_HEADER_INDEX (link_section
->sh_link
)
6401 >= elf_header
.e_shnum
)
6406 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
6408 string_sec
= SECTION_HEADER (link_section
->sh_link
);
6410 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
6411 string_sec
->sh_size
, _("version string table"));
6415 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6416 SECTION_NAME (section
), total
);
6418 printf (_(" Addr: "));
6419 printf_vma (section
->sh_addr
);
6420 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6421 (unsigned long) section
->sh_offset
, section
->sh_link
,
6422 SECTION_NAME (link_section
));
6424 off
= offset_from_vma (file
,
6425 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6426 total
* sizeof (short));
6427 edata
= get_data (NULL
, file
, off
, total
, sizeof (short),
6428 _("version symbol data"));
6435 data
= cmalloc (total
, sizeof (short));
6437 for (cnt
= total
; cnt
--;)
6438 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
6443 for (cnt
= 0; cnt
< total
; cnt
+= 4)
6446 int check_def
, check_need
;
6449 printf (" %03x:", cnt
);
6451 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
6452 switch (data
[cnt
+ j
])
6455 fputs (_(" 0 (*local*) "), stdout
);
6459 fputs (_(" 1 (*global*) "), stdout
);
6463 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
6464 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
6468 if (SECTION_HEADER_INDEX (symbols
[cnt
+ j
].st_shndx
)
6469 >= elf_header
.e_shnum
6470 || SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
6473 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
6480 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
6482 Elf_Internal_Verneed ivn
;
6483 unsigned long offset
;
6485 offset
= offset_from_vma
6486 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6487 sizeof (Elf_External_Verneed
));
6491 Elf_Internal_Vernaux ivna
;
6492 Elf_External_Verneed evn
;
6493 Elf_External_Vernaux evna
;
6494 unsigned long a_off
;
6496 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6499 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6500 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6502 a_off
= offset
+ ivn
.vn_aux
;
6506 get_data (&evna
, file
, a_off
, sizeof (evna
),
6507 1, _("version need aux (2)"));
6509 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6510 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6512 a_off
+= ivna
.vna_next
;
6514 while (ivna
.vna_other
!= data
[cnt
+ j
]
6515 && ivna
.vna_next
!= 0);
6517 if (ivna
.vna_other
== data
[cnt
+ j
])
6519 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6521 name
= strtab
+ ivna
.vna_name
;
6522 nn
+= printf ("(%s%-*s",
6524 12 - (int) strlen (name
),
6530 offset
+= ivn
.vn_next
;
6532 while (ivn
.vn_next
);
6535 if (check_def
&& data
[cnt
+ j
] != 0x8001
6536 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6538 Elf_Internal_Verdef ivd
;
6539 Elf_External_Verdef evd
;
6540 unsigned long offset
;
6542 offset
= offset_from_vma
6543 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
6548 get_data (&evd
, file
, offset
, sizeof (evd
), 1,
6551 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6552 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6554 offset
+= ivd
.vd_next
;
6556 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
6557 && ivd
.vd_next
!= 0);
6559 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
6561 Elf_External_Verdaux evda
;
6562 Elf_Internal_Verdaux ivda
;
6564 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6566 get_data (&evda
, file
,
6567 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
6569 _("version def aux"));
6571 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6573 name
= strtab
+ ivda
.vda_name
;
6574 nn
+= printf ("(%s%-*s",
6576 12 - (int) strlen (name
),
6582 printf ("%*c", 18 - nn
, ' ');
6600 printf (_("\nNo version information found in this file.\n"));
6606 get_symbol_binding (unsigned int binding
)
6608 static char buff
[32];
6612 case STB_LOCAL
: return "LOCAL";
6613 case STB_GLOBAL
: return "GLOBAL";
6614 case STB_WEAK
: return "WEAK";
6616 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
6617 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"),
6619 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
6620 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), binding
);
6622 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), binding
);
6628 get_symbol_type (unsigned int type
)
6630 static char buff
[32];
6634 case STT_NOTYPE
: return "NOTYPE";
6635 case STT_OBJECT
: return "OBJECT";
6636 case STT_FUNC
: return "FUNC";
6637 case STT_SECTION
: return "SECTION";
6638 case STT_FILE
: return "FILE";
6639 case STT_COMMON
: return "COMMON";
6640 case STT_TLS
: return "TLS";
6642 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
6644 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
6645 return "THUMB_FUNC";
6647 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
6650 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
6651 return "PARISC_MILLI";
6653 snprintf (buff
, sizeof (buff
), _("<processor specific>: %d"), type
);
6655 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
6657 if (elf_header
.e_machine
== EM_PARISC
)
6659 if (type
== STT_HP_OPAQUE
)
6661 if (type
== STT_HP_STUB
)
6665 snprintf (buff
, sizeof (buff
), _("<OS specific>: %d"), type
);
6668 snprintf (buff
, sizeof (buff
), _("<unknown>: %d"), type
);
6674 get_symbol_visibility (unsigned int visibility
)
6678 case STV_DEFAULT
: return "DEFAULT";
6679 case STV_INTERNAL
: return "INTERNAL";
6680 case STV_HIDDEN
: return "HIDDEN";
6681 case STV_PROTECTED
: return "PROTECTED";
6687 get_symbol_index_type (unsigned int type
)
6689 static char buff
[32];
6693 case SHN_UNDEF
: return "UND";
6694 case SHN_ABS
: return "ABS";
6695 case SHN_COMMON
: return "COM";
6697 if (type
== SHN_IA_64_ANSI_COMMON
6698 && elf_header
.e_machine
== EM_IA_64
6699 && elf_header
.e_ident
[EI_OSABI
] == ELFOSABI_HPUX
)
6701 else if (elf_header
.e_machine
== EM_X86_64
6702 && type
== SHN_X86_64_LCOMMON
)
6704 else if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
6705 sprintf (buff
, "PRC[0x%04x]", type
);
6706 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
6707 sprintf (buff
, "OS [0x%04x]", type
);
6708 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
6709 sprintf (buff
, "RSV[0x%04x]", type
);
6711 sprintf (buff
, "%3d", type
);
6719 get_dynamic_data (FILE *file
, unsigned int number
, unsigned int ent_size
)
6721 unsigned char *e_data
;
6724 e_data
= cmalloc (number
, ent_size
);
6728 error (_("Out of memory\n"));
6732 if (fread (e_data
, ent_size
, number
, file
) != number
)
6734 error (_("Unable to read in dynamic data\n"));
6738 i_data
= cmalloc (number
, sizeof (*i_data
));
6742 error (_("Out of memory\n"));
6748 i_data
[number
] = byte_get (e_data
+ number
* ent_size
, ent_size
);
6755 /* Dump the symbol table. */
6757 process_symbol_table (FILE *file
)
6759 Elf_Internal_Shdr
*section
;
6760 bfd_vma nbuckets
= 0;
6761 bfd_vma nchains
= 0;
6762 bfd_vma
*buckets
= NULL
;
6763 bfd_vma
*chains
= NULL
;
6765 if (! do_syms
&& !do_histogram
)
6768 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
6771 unsigned char nb
[8];
6772 unsigned char nc
[8];
6773 int hash_ent_size
= 4;
6775 if ((elf_header
.e_machine
== EM_ALPHA
6776 || elf_header
.e_machine
== EM_S390
6777 || elf_header
.e_machine
== EM_S390_OLD
)
6778 && elf_header
.e_ident
[EI_CLASS
] == ELFCLASS64
)
6782 (archive_file_offset
6783 + offset_from_vma (file
, dynamic_info
[DT_HASH
],
6784 sizeof nb
+ sizeof nc
)),
6787 error (_("Unable to seek to start of dynamic information"));
6791 if (fread (nb
, hash_ent_size
, 1, file
) != 1)
6793 error (_("Failed to read in number of buckets\n"));
6797 if (fread (nc
, hash_ent_size
, 1, file
) != 1)
6799 error (_("Failed to read in number of chains\n"));
6803 nbuckets
= byte_get (nb
, hash_ent_size
);
6804 nchains
= byte_get (nc
, hash_ent_size
);
6806 buckets
= get_dynamic_data (file
, nbuckets
, hash_ent_size
);
6807 chains
= get_dynamic_data (file
, nchains
, hash_ent_size
);
6809 if (buckets
== NULL
|| chains
== NULL
)
6814 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
6819 printf (_("\nSymbol table for image:\n"));
6821 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6823 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6825 for (hn
= 0; hn
< nbuckets
; hn
++)
6830 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
6832 Elf_Internal_Sym
*psym
;
6835 psym
= dynamic_symbols
+ si
;
6837 n
= print_vma (si
, DEC_5
);
6839 fputs (" " + n
, stdout
);
6840 printf (" %3lu: ", hn
);
6841 print_vma (psym
->st_value
, LONG_HEX
);
6843 print_vma (psym
->st_size
, DEC_5
);
6845 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6846 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6847 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6848 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
6849 if (VALID_DYNAMIC_NAME (psym
->st_name
))
6850 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
6852 printf (" <corrupt: %14ld>", psym
->st_name
);
6857 else if (do_syms
&& !do_using_dynamic
)
6861 for (i
= 0, section
= section_headers
;
6862 i
< elf_header
.e_shnum
;
6866 char *strtab
= NULL
;
6867 unsigned long int strtab_size
= 0;
6868 Elf_Internal_Sym
*symtab
;
6869 Elf_Internal_Sym
*psym
;
6872 if ( section
->sh_type
!= SHT_SYMTAB
6873 && section
->sh_type
!= SHT_DYNSYM
)
6876 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
6877 SECTION_NAME (section
),
6878 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
6880 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6882 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6884 symtab
= GET_ELF_SYMBOLS (file
, section
);
6888 if (section
->sh_link
== elf_header
.e_shstrndx
)
6890 strtab
= string_table
;
6891 strtab_size
= string_table_length
;
6893 else if (SECTION_HEADER_INDEX (section
->sh_link
) < elf_header
.e_shnum
)
6895 Elf_Internal_Shdr
*string_sec
;
6897 string_sec
= SECTION_HEADER (section
->sh_link
);
6899 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
,
6900 1, string_sec
->sh_size
, _("string table"));
6901 strtab_size
= strtab
!= NULL
? string_sec
->sh_size
: 0;
6904 for (si
= 0, psym
= symtab
;
6905 si
< section
->sh_size
/ section
->sh_entsize
;
6908 printf ("%6d: ", si
);
6909 print_vma (psym
->st_value
, LONG_HEX
);
6911 print_vma (psym
->st_size
, DEC_5
);
6912 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
6913 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
6914 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
6915 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
6916 print_symbol (25, psym
->st_name
< strtab_size
6917 ? strtab
+ psym
->st_name
: "<corrupt>");
6919 if (section
->sh_type
== SHT_DYNSYM
&&
6920 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
6922 unsigned char data
[2];
6923 unsigned short vers_data
;
6924 unsigned long offset
;
6928 offset
= offset_from_vma
6929 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)],
6930 sizeof data
+ si
* sizeof (vers_data
));
6932 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
6933 sizeof (data
), 1, _("version data"));
6935 vers_data
= byte_get (data
, 2);
6937 is_nobits
= (SECTION_HEADER_INDEX (psym
->st_shndx
)
6938 < elf_header
.e_shnum
6939 && SECTION_HEADER (psym
->st_shndx
)->sh_type
6942 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
6944 if ((vers_data
& 0x8000) || vers_data
> 1)
6946 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
6947 && (is_nobits
|| ! check_def
))
6949 Elf_External_Verneed evn
;
6950 Elf_Internal_Verneed ivn
;
6951 Elf_Internal_Vernaux ivna
;
6953 /* We must test both. */
6954 offset
= offset_from_vma
6955 (file
, version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)],
6960 unsigned long vna_off
;
6962 get_data (&evn
, file
, offset
, sizeof (evn
), 1,
6965 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6966 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6968 vna_off
= offset
+ ivn
.vn_aux
;
6972 Elf_External_Vernaux evna
;
6974 get_data (&evna
, file
, vna_off
,
6976 _("version need aux (3)"));
6978 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6979 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6980 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6982 vna_off
+= ivna
.vna_next
;
6984 while (ivna
.vna_other
!= vers_data
6985 && ivna
.vna_next
!= 0);
6987 if (ivna
.vna_other
== vers_data
)
6990 offset
+= ivn
.vn_next
;
6992 while (ivn
.vn_next
!= 0);
6994 if (ivna
.vna_other
== vers_data
)
6997 ivna
.vna_name
< strtab_size
6998 ? strtab
+ ivna
.vna_name
: "<corrupt>",
7002 else if (! is_nobits
)
7003 error (_("bad dynamic symbol"));
7010 if (vers_data
!= 0x8001
7011 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
7013 Elf_Internal_Verdef ivd
;
7014 Elf_Internal_Verdaux ivda
;
7015 Elf_External_Verdaux evda
;
7016 unsigned long offset
;
7018 offset
= offset_from_vma
7020 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)],
7021 sizeof (Elf_External_Verdef
));
7025 Elf_External_Verdef evd
;
7027 get_data (&evd
, file
, offset
, sizeof (evd
),
7028 1, _("version def"));
7030 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
7031 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
7032 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
7034 offset
+= ivd
.vd_next
;
7036 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
7037 && ivd
.vd_next
!= 0);
7039 offset
-= ivd
.vd_next
;
7040 offset
+= ivd
.vd_aux
;
7042 get_data (&evda
, file
, offset
, sizeof (evda
),
7043 1, _("version def aux"));
7045 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
7047 if (psym
->st_name
!= ivda
.vda_name
)
7048 printf ((vers_data
& 0x8000)
7050 ivda
.vda_name
< strtab_size
7051 ? strtab
+ ivda
.vda_name
: "<corrupt>");
7061 if (strtab
!= string_table
)
7067 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7069 if (do_histogram
&& buckets
!= NULL
)
7071 unsigned long *lengths
;
7072 unsigned long *counts
;
7075 unsigned long maxlength
= 0;
7076 unsigned long nzero_counts
= 0;
7077 unsigned long nsyms
= 0;
7079 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7080 (unsigned long) nbuckets
);
7081 printf (_(" Length Number %% of total Coverage\n"));
7083 lengths
= calloc (nbuckets
, sizeof (*lengths
));
7084 if (lengths
== NULL
)
7086 error (_("Out of memory"));
7089 for (hn
= 0; hn
< nbuckets
; ++hn
)
7091 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
7094 if (maxlength
< ++lengths
[hn
])
7099 counts
= calloc (maxlength
+ 1, sizeof (*counts
));
7102 error (_("Out of memory"));
7106 for (hn
= 0; hn
< nbuckets
; ++hn
)
7107 ++counts
[lengths
[hn
]];
7112 printf (" 0 %-10lu (%5.1f%%)\n",
7113 counts
[0], (counts
[0] * 100.0) / nbuckets
);
7114 for (i
= 1; i
<= maxlength
; ++i
)
7116 nzero_counts
+= counts
[i
] * i
;
7117 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7118 i
, counts
[i
], (counts
[i
] * 100.0) / nbuckets
,
7119 (nzero_counts
* 100.0) / nsyms
);
7127 if (buckets
!= NULL
)
7137 process_syminfo (FILE *file ATTRIBUTE_UNUSED
)
7141 if (dynamic_syminfo
== NULL
7143 /* No syminfo, this is ok. */
7146 /* There better should be a dynamic symbol section. */
7147 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
7151 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7152 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
7154 printf (_(" Num: Name BoundTo Flags\n"));
7155 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
7157 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
7159 printf ("%4d: ", i
);
7160 if (VALID_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
))
7161 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols
[i
].st_name
));
7163 printf ("<corrupt: %19ld>", dynamic_symbols
[i
].st_name
);
7166 switch (dynamic_syminfo
[i
].si_boundto
)
7168 case SYMINFO_BT_SELF
:
7169 fputs ("SELF ", stdout
);
7171 case SYMINFO_BT_PARENT
:
7172 fputs ("PARENT ", stdout
);
7175 if (dynamic_syminfo
[i
].si_boundto
> 0
7176 && dynamic_syminfo
[i
].si_boundto
< dynamic_nent
7177 && VALID_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
))
7179 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
7183 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
7187 if (flags
& SYMINFO_FLG_DIRECT
)
7189 if (flags
& SYMINFO_FLG_PASSTHRU
)
7190 printf (" PASSTHRU");
7191 if (flags
& SYMINFO_FLG_COPY
)
7193 if (flags
& SYMINFO_FLG_LAZYLOAD
)
7194 printf (" LAZYLOAD");
7202 #ifdef SUPPORT_DISASSEMBLY
7204 disassemble_section (Elf_Internal_Shdr
*section
, FILE *file
)
7206 printf (_("\nAssembly dump of section %s\n"),
7207 SECTION_NAME (section
));
7209 /* XXX -- to be done --- XXX */
7216 dump_section (Elf_Internal_Shdr
*section
, FILE *file
)
7218 bfd_size_type bytes
;
7220 unsigned char *data
;
7221 unsigned char *start
;
7223 bytes
= section
->sh_size
;
7225 if (bytes
== 0 || section
->sh_type
== SHT_NOBITS
)
7227 printf (_("\nSection '%s' has no data to dump.\n"),
7228 SECTION_NAME (section
));
7232 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
7234 addr
= section
->sh_addr
;
7236 start
= get_data (NULL
, file
, section
->sh_offset
, 1, bytes
,
7249 lbytes
= (bytes
> 16 ? 16 : bytes
);
7251 printf (" 0x%8.8lx ", (unsigned long) addr
);
7253 switch (elf_header
.e_ident
[EI_DATA
])
7257 for (j
= 15; j
>= 0; j
--)
7260 printf ("%2.2x", data
[j
]);
7270 for (j
= 0; j
< 16; j
++)
7273 printf ("%2.2x", data
[j
]);
7283 for (j
= 0; j
< lbytes
; j
++)
7286 if (k
>= ' ' && k
< 0x7f)
7304 /* Apply addends of RELA relocations. */
7307 debug_apply_rela_addends (void *file
,
7308 Elf_Internal_Shdr
*section
,
7309 unsigned char *start
)
7311 Elf_Internal_Shdr
*relsec
;
7312 unsigned char *end
= start
+ section
->sh_size
;
7313 /* FIXME: The relocation field size is relocation type dependent. */
7314 unsigned int reloc_size
= 4;
7316 if (!is_relocatable
)
7319 if (section
->sh_size
< reloc_size
)
7322 for (relsec
= section_headers
;
7323 relsec
< section_headers
+ elf_header
.e_shnum
;
7326 unsigned long nrelas
;
7327 Elf_Internal_Rela
*rela
, *rp
;
7328 Elf_Internal_Shdr
*symsec
;
7329 Elf_Internal_Sym
*symtab
;
7330 Elf_Internal_Sym
*sym
;
7332 if (relsec
->sh_type
!= SHT_RELA
7333 || SECTION_HEADER_INDEX (relsec
->sh_info
) >= elf_header
.e_shnum
7334 || SECTION_HEADER (relsec
->sh_info
) != section
7335 || relsec
->sh_size
== 0
7336 || SECTION_HEADER_INDEX (relsec
->sh_link
) >= elf_header
.e_shnum
)
7339 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
7343 symsec
= SECTION_HEADER (relsec
->sh_link
);
7344 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
7346 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
7350 loc
= start
+ rp
->r_offset
;
7351 if ((loc
+ reloc_size
) > end
)
7353 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7354 (unsigned long) rp
->r_offset
,
7355 SECTION_NAME (section
));
7361 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
7363 if (ELF32_R_SYM (rp
->r_info
) != 0
7364 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
7365 /* Relocations against object symbols can happen,
7366 eg when referencing a global array. For an
7367 example of this see the _clz.o binary in libgcc.a. */
7368 && ELF32_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7370 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7371 get_symbol_type (ELF32_ST_TYPE (sym
->st_info
)),
7372 SECTION_NAME (section
));
7378 /* In MIPS little-endian objects, r_info isn't really a
7379 64-bit little-endian value: it has a 32-bit little-endian
7380 symbol index followed by four individual byte fields.
7381 Reorder INFO accordingly. */
7382 if (elf_header
.e_machine
== EM_MIPS
7383 && elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
7384 rp
->r_info
= (((rp
->r_info
& 0xffffffff) << 32)
7385 | ((rp
->r_info
>> 56) & 0xff)
7386 | ((rp
->r_info
>> 40) & 0xff00)
7387 | ((rp
->r_info
>> 24) & 0xff0000)
7388 | ((rp
->r_info
>> 8) & 0xff000000));
7390 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
7392 if (ELF64_R_SYM (rp
->r_info
) != 0
7393 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
7394 && ELF64_ST_TYPE (sym
->st_info
) != STT_OBJECT
)
7396 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7397 get_symbol_type (ELF64_ST_TYPE (sym
->st_info
)),
7398 SECTION_NAME (section
));
7403 byte_put (loc
, rp
->r_addend
, reloc_size
);
7414 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
7416 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7417 Elf_Internal_Shdr
*sec
;
7420 /* If it is already loaded, do nothing. */
7421 if (section
->start
!= NULL
)
7424 /* Locate the debug section. */
7425 sec
= find_section (section
->name
);
7429 snprintf (buf
, sizeof (buf
), _("%s section data"), section
->name
);
7430 section
->address
= sec
->sh_addr
;
7431 section
->size
= sec
->sh_size
;
7432 section
->start
= get_data (NULL
, file
, sec
->sh_offset
, 1,
7435 if (debug_displays
[debug
].relocate
)
7436 debug_apply_rela_addends (file
, sec
, section
->start
);
7438 return section
->start
!= NULL
;
7442 free_debug_section (enum dwarf_section_display_enum debug
)
7444 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
7446 if (section
->start
== NULL
)
7449 free ((char *) section
->start
);
7450 section
->start
= NULL
;
7451 section
->address
= 0;
7456 display_debug_section (Elf_Internal_Shdr
*section
, FILE *file
)
7458 char *name
= SECTION_NAME (section
);
7459 bfd_size_type length
;
7461 enum dwarf_section_display_enum i
;
7463 length
= section
->sh_size
;
7466 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7470 if (strneq (name
, ".gnu.linkonce.wi.", 17))
7471 name
= ".debug_info";
7473 /* See if we know how to display the contents of this section. */
7474 for (i
= 0; i
< max
; i
++)
7475 if (streq (debug_displays
[i
].section
.name
, name
))
7477 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
7479 if (load_debug_section (i
, file
))
7481 result
&= debug_displays
[i
].display (sec
, file
);
7483 if (i
!= info
&& i
!= abbrev
)
7484 free_debug_section (i
);
7492 printf (_("Unrecognized debug section: %s\n"), name
);
7500 process_section_contents (FILE *file
)
7502 Elf_Internal_Shdr
*section
;
7508 for (i
= 0, section
= section_headers
;
7509 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
7512 #ifdef SUPPORT_DISASSEMBLY
7513 if (dump_sects
[i
] & DISASS_DUMP
)
7514 disassemble_section (section
, file
);
7516 if (dump_sects
[i
] & HEX_DUMP
)
7517 dump_section (section
, file
);
7519 if (dump_sects
[i
] & DEBUG_DUMP
)
7520 display_debug_section (section
, file
);
7523 /* Check to see if the user requested a
7524 dump of a section that does not exist. */
7525 while (i
++ < num_dump_sects
)
7527 warn (_("Section %d was not dumped because it does not exist!\n"), i
);
7531 process_mips_fpe_exception (int mask
)
7536 if (mask
& OEX_FPU_INEX
)
7537 fputs ("INEX", stdout
), first
= 0;
7538 if (mask
& OEX_FPU_UFLO
)
7539 printf ("%sUFLO", first
? "" : "|"), first
= 0;
7540 if (mask
& OEX_FPU_OFLO
)
7541 printf ("%sOFLO", first
? "" : "|"), first
= 0;
7542 if (mask
& OEX_FPU_DIV0
)
7543 printf ("%sDIV0", first
? "" : "|"), first
= 0;
7544 if (mask
& OEX_FPU_INVAL
)
7545 printf ("%sINVAL", first
? "" : "|");
7548 fputs ("0", stdout
);
7552 process_mips_specific (FILE *file
)
7554 Elf_Internal_Dyn
*entry
;
7555 size_t liblist_offset
= 0;
7556 size_t liblistno
= 0;
7557 size_t conflictsno
= 0;
7558 size_t options_offset
= 0;
7559 size_t conflicts_offset
= 0;
7561 /* We have a lot of special sections. Thanks SGI! */
7562 if (dynamic_section
== NULL
)
7563 /* No information available. */
7566 for (entry
= dynamic_section
; entry
->d_tag
!= DT_NULL
; ++entry
)
7567 switch (entry
->d_tag
)
7569 case DT_MIPS_LIBLIST
:
7571 = offset_from_vma (file
, entry
->d_un
.d_val
,
7572 liblistno
* sizeof (Elf32_External_Lib
));
7574 case DT_MIPS_LIBLISTNO
:
7575 liblistno
= entry
->d_un
.d_val
;
7577 case DT_MIPS_OPTIONS
:
7578 options_offset
= offset_from_vma (file
, entry
->d_un
.d_val
, 0);
7580 case DT_MIPS_CONFLICT
:
7582 = offset_from_vma (file
, entry
->d_un
.d_val
,
7583 conflictsno
* sizeof (Elf32_External_Conflict
));
7585 case DT_MIPS_CONFLICTNO
:
7586 conflictsno
= entry
->d_un
.d_val
;
7592 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
7594 Elf32_External_Lib
*elib
;
7597 elib
= get_data (NULL
, file
, liblist_offset
,
7598 liblistno
, sizeof (Elf32_External_Lib
),
7602 printf ("\nSection '.liblist' contains %lu entries:\n",
7603 (unsigned long) liblistno
);
7604 fputs (" Library Time Stamp Checksum Version Flags\n",
7607 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
7614 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
7615 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
7616 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
7617 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
7618 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
7620 tmp
= gmtime (&time
);
7621 snprintf (timebuf
, sizeof (timebuf
),
7622 "%04u-%02u-%02uT%02u:%02u:%02u",
7623 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
7624 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
7626 printf ("%3lu: ", (unsigned long) cnt
);
7627 if (VALID_DYNAMIC_NAME (liblist
.l_name
))
7628 print_symbol (20, GET_DYNAMIC_NAME (liblist
.l_name
));
7630 printf ("<corrupt: %9ld>", liblist
.l_name
);
7631 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
7634 if (liblist
.l_flags
== 0)
7645 { " EXACT_MATCH", LL_EXACT_MATCH
},
7646 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
7647 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
7648 { " EXPORTS", LL_EXPORTS
},
7649 { " DELAY_LOAD", LL_DELAY_LOAD
},
7650 { " DELTA", LL_DELTA
}
7652 int flags
= liblist
.l_flags
;
7656 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
7658 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
7660 fputs (l_flags_vals
[fcnt
].name
, stdout
);
7661 flags
^= l_flags_vals
[fcnt
].bit
;
7664 printf (" %#x", (unsigned int) flags
);
7674 if (options_offset
!= 0)
7676 Elf_External_Options
*eopt
;
7677 Elf_Internal_Shdr
*sect
= section_headers
;
7678 Elf_Internal_Options
*iopt
;
7679 Elf_Internal_Options
*option
;
7683 /* Find the section header so that we get the size. */
7684 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
7687 eopt
= get_data (NULL
, file
, options_offset
, 1, sect
->sh_size
,
7691 iopt
= cmalloc ((sect
->sh_size
/ sizeof (eopt
)), sizeof (*iopt
));
7694 error (_("Out of memory"));
7701 while (offset
< sect
->sh_size
)
7703 Elf_External_Options
*eoption
;
7705 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
7707 option
->kind
= BYTE_GET (eoption
->kind
);
7708 option
->size
= BYTE_GET (eoption
->size
);
7709 option
->section
= BYTE_GET (eoption
->section
);
7710 option
->info
= BYTE_GET (eoption
->info
);
7712 offset
+= option
->size
;
7718 printf (_("\nSection '%s' contains %d entries:\n"),
7719 SECTION_NAME (sect
), cnt
);
7727 switch (option
->kind
)
7730 /* This shouldn't happen. */
7731 printf (" NULL %d %lx", option
->section
, option
->info
);
7734 printf (" REGINFO ");
7735 if (elf_header
.e_machine
== EM_MIPS
)
7738 Elf32_External_RegInfo
*ereg
;
7739 Elf32_RegInfo reginfo
;
7741 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
7742 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
7743 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
7744 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
7745 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
7746 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
7747 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
7749 printf ("GPR %08lx GP 0x%lx\n",
7751 (unsigned long) reginfo
.ri_gp_value
);
7752 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7753 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
7754 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
7759 Elf64_External_RegInfo
*ereg
;
7760 Elf64_Internal_RegInfo reginfo
;
7762 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
7763 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
7764 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
7765 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
7766 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
7767 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
7768 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
7770 printf ("GPR %08lx GP 0x",
7771 reginfo
.ri_gprmask
);
7772 printf_vma (reginfo
.ri_gp_value
);
7775 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7776 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
7777 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
7781 case ODK_EXCEPTIONS
:
7782 fputs (" EXCEPTIONS fpe_min(", stdout
);
7783 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
7784 fputs (") fpe_max(", stdout
);
7785 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
7786 fputs (")", stdout
);
7788 if (option
->info
& OEX_PAGE0
)
7789 fputs (" PAGE0", stdout
);
7790 if (option
->info
& OEX_SMM
)
7791 fputs (" SMM", stdout
);
7792 if (option
->info
& OEX_FPDBUG
)
7793 fputs (" FPDBUG", stdout
);
7794 if (option
->info
& OEX_DISMISS
)
7795 fputs (" DISMISS", stdout
);
7798 fputs (" PAD ", stdout
);
7799 if (option
->info
& OPAD_PREFIX
)
7800 fputs (" PREFIX", stdout
);
7801 if (option
->info
& OPAD_POSTFIX
)
7802 fputs (" POSTFIX", stdout
);
7803 if (option
->info
& OPAD_SYMBOL
)
7804 fputs (" SYMBOL", stdout
);
7807 fputs (" HWPATCH ", stdout
);
7808 if (option
->info
& OHW_R4KEOP
)
7809 fputs (" R4KEOP", stdout
);
7810 if (option
->info
& OHW_R8KPFETCH
)
7811 fputs (" R8KPFETCH", stdout
);
7812 if (option
->info
& OHW_R5KEOP
)
7813 fputs (" R5KEOP", stdout
);
7814 if (option
->info
& OHW_R5KCVTL
)
7815 fputs (" R5KCVTL", stdout
);
7818 fputs (" FILL ", stdout
);
7819 /* XXX Print content of info word? */
7822 fputs (" TAGS ", stdout
);
7823 /* XXX Print content of info word? */
7826 fputs (" HWAND ", stdout
);
7827 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
7828 fputs (" R4KEOP_CHECKED", stdout
);
7829 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
7830 fputs (" R4KEOP_CLEAN", stdout
);
7833 fputs (" HWOR ", stdout
);
7834 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
7835 fputs (" R4KEOP_CHECKED", stdout
);
7836 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
7837 fputs (" R4KEOP_CLEAN", stdout
);
7840 printf (" GP_GROUP %#06lx self-contained %#06lx",
7841 option
->info
& OGP_GROUP
,
7842 (option
->info
& OGP_SELF
) >> 16);
7845 printf (" IDENT %#06lx self-contained %#06lx",
7846 option
->info
& OGP_GROUP
,
7847 (option
->info
& OGP_SELF
) >> 16);
7850 /* This shouldn't happen. */
7851 printf (" %3d ??? %d %lx",
7852 option
->kind
, option
->section
, option
->info
);
7856 len
= sizeof (*eopt
);
7857 while (len
< option
->size
)
7858 if (((char *) option
)[len
] >= ' '
7859 && ((char *) option
)[len
] < 0x7f)
7860 printf ("%c", ((char *) option
)[len
++]);
7862 printf ("\\%03o", ((char *) option
)[len
++]);
7864 fputs ("\n", stdout
);
7872 if (conflicts_offset
!= 0 && conflictsno
!= 0)
7874 Elf32_Conflict
*iconf
;
7877 if (dynamic_symbols
== NULL
)
7879 error (_("conflict list found without a dynamic symbol table"));
7883 iconf
= cmalloc (conflictsno
, sizeof (*iconf
));
7886 error (_("Out of memory"));
7892 Elf32_External_Conflict
*econf32
;
7894 econf32
= get_data (NULL
, file
, conflicts_offset
,
7895 conflictsno
, sizeof (*econf32
), _("conflict"));
7899 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
7900 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
7906 Elf64_External_Conflict
*econf64
;
7908 econf64
= get_data (NULL
, file
, conflicts_offset
,
7909 conflictsno
, sizeof (*econf64
), _("conflict"));
7913 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
7914 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
7919 printf (_("\nSection '.conflict' contains %lu entries:\n"),
7920 (unsigned long) conflictsno
);
7921 puts (_(" Num: Index Value Name"));
7923 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
7925 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
7927 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
7928 print_vma (psym
->st_value
, FULL_HEX
);
7930 if (VALID_DYNAMIC_NAME (psym
->st_name
))
7931 print_symbol (25, GET_DYNAMIC_NAME (psym
->st_name
));
7933 printf ("<corrupt: %14ld>", psym
->st_name
);
7944 process_gnu_liblist (FILE *file
)
7946 Elf_Internal_Shdr
*section
, *string_sec
;
7947 Elf32_External_Lib
*elib
;
7956 for (i
= 0, section
= section_headers
;
7957 i
< elf_header
.e_shnum
;
7960 switch (section
->sh_type
)
7962 case SHT_GNU_LIBLIST
:
7963 if (SECTION_HEADER_INDEX (section
->sh_link
) >= elf_header
.e_shnum
)
7966 elib
= get_data (NULL
, file
, section
->sh_offset
, 1, section
->sh_size
,
7971 string_sec
= SECTION_HEADER (section
->sh_link
);
7973 strtab
= get_data (NULL
, file
, string_sec
->sh_offset
, 1,
7974 string_sec
->sh_size
, _("liblist string table"));
7975 strtab_size
= string_sec
->sh_size
;
7978 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
7984 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
7985 SECTION_NAME (section
),
7986 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
7988 puts (" Library Time Stamp Checksum Version Flags");
7990 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
7998 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
7999 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
8000 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
8001 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
8002 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
8004 tmp
= gmtime (&time
);
8005 snprintf (timebuf
, sizeof (timebuf
),
8006 "%04u-%02u-%02uT%02u:%02u:%02u",
8007 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
8008 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
8010 printf ("%3lu: ", (unsigned long) cnt
);
8012 printf ("%-20s", liblist
.l_name
< strtab_size
8013 ? strtab
+ liblist
.l_name
: "<corrupt>");
8015 printf ("%-20.20s", liblist
.l_name
< strtab_size
8016 ? strtab
+ liblist
.l_name
: "<corrupt>");
8017 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
8018 liblist
.l_version
, liblist
.l_flags
);
8029 get_note_type (unsigned e_type
)
8031 static char buff
[64];
8033 if (elf_header
.e_type
== ET_CORE
)
8037 return _("NT_AUXV (auxiliary vector)");
8039 return _("NT_PRSTATUS (prstatus structure)");
8041 return _("NT_FPREGSET (floating point registers)");
8043 return _("NT_PRPSINFO (prpsinfo structure)");
8045 return _("NT_TASKSTRUCT (task structure)");
8047 return _("NT_PRXFPREG (user_xfpregs structure)");
8049 return _("NT_PSTATUS (pstatus structure)");
8051 return _("NT_FPREGS (floating point registers)");
8053 return _("NT_PSINFO (psinfo structure)");
8055 return _("NT_LWPSTATUS (lwpstatus_t structure)");
8057 return _("NT_LWPSINFO (lwpsinfo_t structure)");
8058 case NT_WIN32PSTATUS
:
8059 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8067 return _("NT_VERSION (version)");
8069 return _("NT_ARCH (architecture)");
8074 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8079 get_netbsd_elfcore_note_type (unsigned e_type
)
8081 static char buff
[64];
8083 if (e_type
== NT_NETBSDCORE_PROCINFO
)
8085 /* NetBSD core "procinfo" structure. */
8086 return _("NetBSD procinfo structure");
8089 /* As of Jan 2002 there are no other machine-independent notes
8090 defined for NetBSD core files. If the note type is less
8091 than the start of the machine-dependent note types, we don't
8094 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
8096 snprintf (buff
, sizeof (buff
), _("Unknown note type: (0x%08x)"), e_type
);
8100 switch (elf_header
.e_machine
)
8102 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8103 and PT_GETFPREGS == mach+2. */
8108 case EM_SPARC32PLUS
:
8112 case NT_NETBSDCORE_FIRSTMACH
+0:
8113 return _("PT_GETREGS (reg structure)");
8114 case NT_NETBSDCORE_FIRSTMACH
+2:
8115 return _("PT_GETFPREGS (fpreg structure)");
8121 /* On all other arch's, PT_GETREGS == mach+1 and
8122 PT_GETFPREGS == mach+3. */
8126 case NT_NETBSDCORE_FIRSTMACH
+1:
8127 return _("PT_GETREGS (reg structure)");
8128 case NT_NETBSDCORE_FIRSTMACH
+3:
8129 return _("PT_GETFPREGS (fpreg structure)");
8135 snprintf (buff
, sizeof (buff
), _("PT_FIRSTMACH+%d"),
8136 e_type
- NT_NETBSDCORE_FIRSTMACH
);
8140 /* Note that by the ELF standard, the name field is already null byte
8141 terminated, and namesz includes the terminating null byte.
8142 I.E. the value of namesz for the name "FSF" is 4.
8144 If the value of namesz is zero, there is no name present. */
8146 process_note (Elf_Internal_Note
*pnote
)
8150 if (pnote
->namesz
== 0)
8151 /* If there is no note name, then use the default set of
8152 note type strings. */
8153 nt
= get_note_type (pnote
->type
);
8155 else if (strneq (pnote
->namedata
, "NetBSD-CORE", 11))
8156 /* NetBSD-specific core file notes. */
8157 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
8160 /* Don't recognize this note name; just use the default set of
8161 note type strings. */
8162 nt
= get_note_type (pnote
->type
);
8164 printf (" %s\t\t0x%08lx\t%s\n",
8165 pnote
->namesz
? pnote
->namedata
: "(NONE)",
8172 process_corefile_note_segment (FILE *file
, bfd_vma offset
, bfd_vma length
)
8174 Elf_External_Note
*pnotes
;
8175 Elf_External_Note
*external
;
8181 pnotes
= get_data (NULL
, file
, offset
, 1, length
, _("notes"));
8187 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8188 (unsigned long) offset
, (unsigned long) length
);
8189 printf (_(" Owner\t\tData size\tDescription\n"));
8191 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
8193 Elf_External_Note
*next
;
8194 Elf_Internal_Note inote
;
8197 inote
.type
= BYTE_GET (external
->type
);
8198 inote
.namesz
= BYTE_GET (external
->namesz
);
8199 inote
.namedata
= external
->name
;
8200 inote
.descsz
= BYTE_GET (external
->descsz
);
8201 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
8202 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
8204 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
8206 if (((char *) next
) > (((char *) pnotes
) + length
))
8208 warn (_("corrupt note found at offset %lx into core notes\n"),
8209 (long)((char *)external
- (char *)pnotes
));
8210 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
8211 inote
.type
, inote
.namesz
, inote
.descsz
);
8217 /* Verify that name is null terminated. It appears that at least
8218 one version of Linux (RedHat 6.0) generates corefiles that don't
8219 comply with the ELF spec by failing to include the null byte in
8221 if (inote
.namedata
[inote
.namesz
] != '\0')
8223 temp
= malloc (inote
.namesz
+ 1);
8227 error (_("Out of memory\n"));
8232 strncpy (temp
, inote
.namedata
, inote
.namesz
);
8233 temp
[inote
.namesz
] = 0;
8235 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8236 inote
.namedata
= temp
;
8239 res
&= process_note (& inote
);
8254 process_corefile_note_segments (FILE *file
)
8256 Elf_Internal_Phdr
*segment
;
8260 if (! get_program_headers (file
))
8263 for (i
= 0, segment
= program_headers
;
8264 i
< elf_header
.e_phnum
;
8267 if (segment
->p_type
== PT_NOTE
)
8268 res
&= process_corefile_note_segment (file
,
8269 (bfd_vma
) segment
->p_offset
,
8270 (bfd_vma
) segment
->p_filesz
);
8277 process_note_sections (FILE *file
)
8279 Elf_Internal_Shdr
*section
;
8283 for (i
= 0, section
= section_headers
;
8284 i
< elf_header
.e_shnum
;
8286 if (section
->sh_type
== SHT_NOTE
)
8287 res
&= process_corefile_note_segment (file
,
8288 (bfd_vma
) section
->sh_offset
,
8289 (bfd_vma
) section
->sh_size
);
8295 process_notes (FILE *file
)
8297 /* If we have not been asked to display the notes then do nothing. */
8301 if (elf_header
.e_type
!= ET_CORE
)
8302 return process_note_sections (file
);
8304 /* No program headers means no NOTE segment. */
8305 if (elf_header
.e_phnum
> 0)
8306 return process_corefile_note_segments (file
);
8308 printf (_("No note segments present in the core file.\n"));
8313 process_arch_specific (FILE *file
)
8318 switch (elf_header
.e_machine
)
8321 case EM_MIPS_RS3_LE
:
8322 return process_mips_specific (file
);
8331 get_file_header (FILE *file
)
8333 /* Read in the identity array. */
8334 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
8337 /* Determine how to read the rest of the header. */
8338 switch (elf_header
.e_ident
[EI_DATA
])
8340 default: /* fall through */
8341 case ELFDATANONE
: /* fall through */
8343 byte_get
= byte_get_little_endian
;
8344 byte_put
= byte_put_little_endian
;
8347 byte_get
= byte_get_big_endian
;
8348 byte_put
= byte_put_big_endian
;
8352 /* For now we only support 32 bit and 64 bit ELF files. */
8353 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
8355 /* Read in the rest of the header. */
8358 Elf32_External_Ehdr ehdr32
;
8360 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
8363 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
8364 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
8365 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
8366 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
8367 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
8368 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
8369 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
8370 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
8371 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
8372 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
8373 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
8374 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
8375 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
8379 Elf64_External_Ehdr ehdr64
;
8381 /* If we have been compiled with sizeof (bfd_vma) == 4, then
8382 we will not be able to cope with the 64bit data found in
8383 64 ELF files. Detect this now and abort before we start
8384 overwriting things. */
8385 if (sizeof (bfd_vma
) < 8)
8387 error (_("This instance of readelf has been built without support for a\n\
8388 64 bit data type and so it cannot read 64 bit ELF files.\n"));
8392 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
8395 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
8396 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
8397 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
8398 elf_header
.e_entry
= BYTE_GET (ehdr64
.e_entry
);
8399 elf_header
.e_phoff
= BYTE_GET (ehdr64
.e_phoff
);
8400 elf_header
.e_shoff
= BYTE_GET (ehdr64
.e_shoff
);
8401 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
8402 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
8403 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
8404 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
8405 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
8406 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
8407 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
8410 if (elf_header
.e_shoff
)
8412 /* There may be some extensions in the first section header. Don't
8413 bomb if we can't read it. */
8415 get_32bit_section_headers (file
, 1);
8417 get_64bit_section_headers (file
, 1);
8420 is_relocatable
= elf_header
.e_type
== ET_REL
;
8425 /* Process one ELF object file according to the command line options.
8426 This file may actually be stored in an archive. The file is
8427 positioned at the start of the ELF object. */
8430 process_object (char *file_name
, FILE *file
)
8434 if (! get_file_header (file
))
8436 error (_("%s: Failed to read file header\n"), file_name
);
8440 /* Initialise per file variables. */
8441 for (i
= NUM_ELEM (version_info
); i
--;)
8442 version_info
[i
] = 0;
8444 for (i
= NUM_ELEM (dynamic_info
); i
--;)
8445 dynamic_info
[i
] = 0;
8447 /* Process the file. */
8449 printf (_("\nFile: %s\n"), file_name
);
8451 /* Initialise the dump_sects array from the cmdline_dump_sects array.
8452 Note we do this even if cmdline_dump_sects is empty because we
8453 must make sure that the dump_sets array is zeroed out before each
8454 object file is processed. */
8455 if (num_dump_sects
> num_cmdline_dump_sects
)
8456 memset (dump_sects
, 0, num_dump_sects
);
8458 if (num_cmdline_dump_sects
> 0)
8460 if (num_dump_sects
== 0)
8461 /* A sneaky way of allocating the dump_sects array. */
8462 request_dump (num_cmdline_dump_sects
, 0);
8464 assert (num_dump_sects
>= num_cmdline_dump_sects
);
8465 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
8468 if (! process_file_header ())
8471 if (! process_section_headers (file
))
8473 /* Without loaded section headers we cannot process lots of
8475 do_unwind
= do_version
= do_dump
= do_arch
= 0;
8477 if (! do_using_dynamic
)
8478 do_syms
= do_reloc
= 0;
8481 if (! process_section_groups (file
))
8483 /* Without loaded section groups we cannot process unwind. */
8487 if (process_program_headers (file
))
8488 process_dynamic_section (file
);
8490 process_relocs (file
);
8492 process_unwind (file
);
8494 process_symbol_table (file
);
8496 process_syminfo (file
);
8498 process_version_sections (file
);
8500 process_section_contents (file
);
8502 process_notes (file
);
8504 process_gnu_liblist (file
);
8506 process_arch_specific (file
);
8508 if (program_headers
)
8510 free (program_headers
);
8511 program_headers
= NULL
;
8514 if (section_headers
)
8516 free (section_headers
);
8517 section_headers
= NULL
;
8522 free (string_table
);
8523 string_table
= NULL
;
8524 string_table_length
= 0;
8527 if (dynamic_strings
)
8529 free (dynamic_strings
);
8530 dynamic_strings
= NULL
;
8531 dynamic_strings_length
= 0;
8534 if (dynamic_symbols
)
8536 free (dynamic_symbols
);
8537 dynamic_symbols
= NULL
;
8538 num_dynamic_syms
= 0;
8541 if (dynamic_syminfo
)
8543 free (dynamic_syminfo
);
8544 dynamic_syminfo
= NULL
;
8547 if (section_headers_groups
)
8549 free (section_headers_groups
);
8550 section_headers_groups
= NULL
;
8555 struct group_list
*g
, *next
;
8557 for (i
= 0; i
< group_count
; i
++)
8559 for (g
= section_groups
[i
].root
; g
!= NULL
; g
= next
)
8566 free (section_groups
);
8567 section_groups
= NULL
;
8570 free_debug_memory ();
8575 /* Process an ELF archive. The file is positioned just after the
8579 process_archive (char *file_name
, FILE *file
)
8581 struct ar_hdr arhdr
;
8584 char *longnames
= NULL
;
8585 unsigned long longnames_size
= 0;
8586 size_t file_name_size
;
8591 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
8592 if (got
!= sizeof arhdr
)
8597 error (_("%s: failed to read archive header\n"), file_name
);
8601 if (memcmp (arhdr
.ar_name
, "/ ", 16) == 0)
8603 /* This is the archive symbol table. Skip it.
8604 FIXME: We should have an option to dump it. */
8605 size
= strtoul (arhdr
.ar_size
, NULL
, 10);
8606 if (fseek (file
, size
+ (size
& 1), SEEK_CUR
) != 0)
8608 error (_("%s: failed to skip archive symbol table\n"), file_name
);
8612 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
8613 if (got
!= sizeof arhdr
)
8618 error (_("%s: failed to read archive header\n"), file_name
);
8623 if (memcmp (arhdr
.ar_name
, "// ", 16) == 0)
8625 /* This is the archive string table holding long member
8628 longnames_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
8630 longnames
= malloc (longnames_size
);
8631 if (longnames
== NULL
)
8633 error (_("Out of memory\n"));
8637 if (fread (longnames
, longnames_size
, 1, file
) != 1)
8640 error (_("%s: failed to read string table\n"), file_name
);
8644 if ((longnames_size
& 1) != 0)
8647 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
8648 if (got
!= sizeof arhdr
)
8655 error (_("%s: failed to read archive header\n"), file_name
);
8660 file_name_size
= strlen (file_name
);
8669 if (arhdr
.ar_name
[0] == '/')
8673 off
= strtoul (arhdr
.ar_name
+ 1, NULL
, 10);
8674 if (off
>= longnames_size
)
8676 error (_("%s: invalid archive string table offset %lu\n"), file_name
, off
);
8681 name
= longnames
+ off
;
8682 nameend
= memchr (name
, '/', longnames_size
- off
);
8686 name
= arhdr
.ar_name
;
8687 nameend
= memchr (name
, '/', 16);
8690 if (nameend
== NULL
)
8692 error (_("%s: bad archive file name\n"), file_name
);
8697 namealc
= malloc (file_name_size
+ (nameend
- name
) + 3);
8698 if (namealc
== NULL
)
8700 error (_("Out of memory\n"));
8705 memcpy (namealc
, file_name
, file_name_size
);
8706 namealc
[file_name_size
] = '(';
8707 memcpy (namealc
+ file_name_size
+ 1, name
, nameend
- name
);
8708 namealc
[file_name_size
+ 1 + (nameend
- name
)] = ')';
8709 namealc
[file_name_size
+ 2 + (nameend
- name
)] = '\0';
8711 archive_file_offset
= ftell (file
);
8712 archive_file_size
= strtoul (arhdr
.ar_size
, NULL
, 10);
8714 ret
|= process_object (namealc
, file
);
8719 (archive_file_offset
8721 + (archive_file_size
& 1)),
8724 error (_("%s: failed to seek to next archive header\n"), file_name
);
8729 got
= fread (&arhdr
, 1, sizeof arhdr
, file
);
8730 if (got
!= sizeof arhdr
)
8735 error (_("%s: failed to read archive header\n"), file_name
);
8748 process_file (char *file_name
)
8751 struct stat statbuf
;
8755 if (stat (file_name
, &statbuf
) < 0)
8757 if (errno
== ENOENT
)
8758 error (_("'%s': No such file\n"), file_name
);
8760 error (_("Could not locate '%s'. System error message: %s\n"),
8761 file_name
, strerror (errno
));
8765 if (! S_ISREG (statbuf
.st_mode
))
8767 error (_("'%s' is not an ordinary file\n"), file_name
);
8771 file
= fopen (file_name
, "rb");
8774 error (_("Input file '%s' is not readable.\n"), file_name
);
8778 if (fread (armag
, SARMAG
, 1, file
) != 1)
8780 error (_("%s: Failed to read file header\n"), file_name
);
8785 if (memcmp (armag
, ARMAG
, SARMAG
) == 0)
8786 ret
= process_archive (file_name
, file
);
8790 archive_file_size
= archive_file_offset
= 0;
8791 ret
= process_object (file_name
, file
);
8799 #ifdef SUPPORT_DISASSEMBLY
8800 /* Needed by the i386 disassembler. For extra credit, someone could
8801 fix this so that we insert symbolic addresses here, esp for GOT/PLT
8805 print_address (unsigned int addr
, FILE *outfile
)
8807 fprintf (outfile
,"0x%8.8x", addr
);
8810 /* Needed by the i386 disassembler. */
8812 db_task_printsym (unsigned int addr
)
8814 print_address (addr
, stderr
);
8819 main (int argc
, char **argv
)
8823 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
8824 setlocale (LC_MESSAGES
, "");
8826 #if defined (HAVE_SETLOCALE)
8827 setlocale (LC_CTYPE
, "");
8829 bindtextdomain (PACKAGE
, LOCALEDIR
);
8830 textdomain (PACKAGE
);
8832 expandargv (&argc
, &argv
);
8834 parse_args (argc
, argv
);
8836 if (num_dump_sects
> 0)
8838 /* Make a copy of the dump_sects array. */
8839 cmdline_dump_sects
= malloc (num_dump_sects
);
8840 if (cmdline_dump_sects
== NULL
)
8841 error (_("Out of memory allocating dump request table."));
8844 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
8845 num_cmdline_dump_sects
= num_dump_sects
;
8849 if (optind
< (argc
- 1))
8853 while (optind
< argc
)
8854 err
|= process_file (argv
[optind
++]);
8856 if (dump_sects
!= NULL
)
8858 if (cmdline_dump_sects
!= NULL
)
8859 free (cmdline_dump_sects
);