1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2014 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* The difference between readelf and objdump:
26 Both programs are capable of displaying the contents of ELF format files,
27 so why does the binutils project have two file dumpers ?
29 The reason is that objdump sees an ELF file through a BFD filter of the
30 world; if BFD has a bug where, say, it disagrees about a machine constant
31 in e_flags, then the odds are good that it will remain internally
32 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
33 GAS sees it the BFD way. There was need for a tool to go find out what
34 the file actually says.
36 This is why the readelf program does not link against the BFD library - it
37 exists as an independent program to help verify the correct working of BFD.
39 There is also the case that readelf can provide more information about an
40 ELF file than is provided by objdump. In particular it can display DWARF
41 debugging information which (at the moment) objdump cannot. */
54 /* Define BFD64 here, even if our default architecture is 32 bit ELF
55 as this will allow us to read in and parse 64bit and 32bit ELF files.
56 Only do this if we believe that the compiler can support a 64 bit
57 data type. For now we only rely on GCC being able to do this. */
66 #include "elf/common.h"
67 #include "elf/external.h"
68 #include "elf/internal.h"
71 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
72 we can obtain the H8 reloc numbers. We need these for the
73 get_reloc_size() function. We include h8.h again after defining
74 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
79 /* Undo the effects of #including reloc-macros.h. */
81 #undef START_RELOC_NUMBERS
85 #undef END_RELOC_NUMBERS
86 #undef _RELOC_MACROS_H
88 /* The following headers use the elf/reloc-macros.h file to
89 automatically generate relocation recognition functions
90 such as elf_mips_reloc_type() */
92 #define RELOC_MACROS_GEN_FUNC
94 #include "elf/aarch64.h"
95 #include "elf/alpha.h"
100 #include "elf/cr16.h"
101 #include "elf/cris.h"
103 #include "elf/d10v.h"
104 #include "elf/d30v.h"
106 #include "elf/epiphany.h"
107 #include "elf/fr30.h"
110 #include "elf/hppa.h"
111 #include "elf/i386.h"
112 #include "elf/i370.h"
113 #include "elf/i860.h"
114 #include "elf/i960.h"
115 #include "elf/ia64.h"
116 #include "elf/ip2k.h"
117 #include "elf/lm32.h"
118 #include "elf/iq2000.h"
119 #include "elf/m32c.h"
120 #include "elf/m32r.h"
121 #include "elf/m68k.h"
122 #include "elf/m68hc11.h"
123 #include "elf/mcore.h"
125 #include "elf/metag.h"
126 #include "elf/microblaze.h"
127 #include "elf/mips.h"
128 #include "elf/mmix.h"
129 #include "elf/mn10200.h"
130 #include "elf/mn10300.h"
131 #include "elf/moxie.h"
133 #include "elf/msp430.h"
134 #include "elf/nds32.h"
135 #include "elf/nios2.h"
136 #include "elf/or1k.h"
139 #include "elf/ppc64.h"
140 #include "elf/rl78.h"
142 #include "elf/s390.h"
143 #include "elf/score.h"
145 #include "elf/sparc.h"
147 #include "elf/tic6x.h"
148 #include "elf/tilegx.h"
149 #include "elf/tilepro.h"
150 #include "elf/v850.h"
152 #include "elf/x86-64.h"
153 #include "elf/xc16x.h"
154 #include "elf/xgate.h"
155 #include "elf/xstormy16.h"
156 #include "elf/xtensa.h"
159 #include "libiberty.h"
160 #include "safe-ctype.h"
161 #include "filenames.h"
164 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
167 char * program_name = "readelf";
168 static unsigned long archive_file_offset;
169 static unsigned long archive_file_size;
170 static bfd_size_type current_file_size;
171 static unsigned long dynamic_addr;
172 static bfd_size_type dynamic_size;
173 static size_t dynamic_nent;
174 static char * dynamic_strings;
175 static unsigned long dynamic_strings_length;
176 static char * string_table;
177 static unsigned long string_table_length;
178 static unsigned long num_dynamic_syms;
179 static Elf_Internal_Sym * dynamic_symbols;
180 static Elf_Internal_Syminfo * dynamic_syminfo;
181 static unsigned long dynamic_syminfo_offset;
182 static unsigned int dynamic_syminfo_nent;
183 static char program_interpreter[PATH_MAX];
184 static bfd_vma dynamic_info[DT_ENCODING];
185 static bfd_vma dynamic_info_DT_GNU_HASH;
186 static bfd_vma version_info[16];
187 static Elf_Internal_Ehdr elf_header;
188 static Elf_Internal_Shdr * section_headers;
189 static Elf_Internal_Phdr * program_headers;
190 static Elf_Internal_Dyn * dynamic_section;
191 static Elf_Internal_Shdr * symtab_shndx_hdr;
192 static int show_name;
193 static int do_dynamic;
195 static int do_dyn_syms;
197 static int do_sections;
198 static int do_section_groups;
199 static int do_section_details;
200 static int do_segments;
201 static int do_unwind;
202 static int do_using_dynamic;
203 static int do_header;
205 static int do_version;
206 static int do_histogram;
207 static int do_debugging;
210 static int do_archive_index;
211 static int is_32bit_elf;
215 struct group_list * next;
216 unsigned int section_index;
221 struct group_list * root;
222 unsigned int group_index;
225 static size_t group_count;
226 static struct group * section_groups;
227 static struct group ** section_headers_groups;
230 /* Flag bits indicating particular types of dump. */
231 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
232 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
233 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
234 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
235 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
237 typedef unsigned char dump_type;
239 /* A linked list of the section names for which dumps were requested. */
240 struct dump_list_entry
244 struct dump_list_entry * next;
246 static struct dump_list_entry * dump_sects_byname;
248 /* A dynamic array of flags indicating for which sections a dump
249 has been requested via command line switches. */
250 static dump_type * cmdline_dump_sects = NULL;
251 static unsigned int num_cmdline_dump_sects = 0;
253 /* A dynamic array of flags indicating for which sections a dump of
254 some kind has been requested. It is reset on a per-object file
255 basis and then initialised from the cmdline_dump_sects array,
256 the results of interpreting the -w switch, and the
257 dump_sects_byname list. */
258 static dump_type * dump_sects = NULL;
259 static unsigned int num_dump_sects = 0;
262 /* How to print a vma value. */
263 typedef enum print_mode
277 #define SECTION_NAME(X) \
278 ((X) == NULL ? _("<none>") \
279 : string_table == NULL ? _("<no-name>") \
280 : ((X)->sh_name >= string_table_length ? _("<corrupt>") \
281 : string_table + (X)->sh_name))
283 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
285 #define GET_ELF_SYMBOLS(file, section, sym_count) \
286 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
287 : get_64bit_elf_symbols (file, section, sym_count))
289 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
290 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
291 already been called and verified that the string exists. */
292 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
294 #define REMOVE_ARCH_BITS(ADDR) \
297 if (elf_header.e_machine == EM_ARM) \
302 /* Retrieve NMEMB structures, each SIZE bytes long from FILE starting at OFFSET +
303 the offset of the current archive member, if we are examining an archive.
304 Put the retrieved data into VAR, if it is not NULL. Otherwise allocate a buffer
305 using malloc and fill that. In either case return the pointer to the start of
306 the retrieved data or NULL if something went wrong. If something does go wrong
307 and REASON is not NULL then emit an error message using REASON as part of the
311 get_data (void * var, FILE * file, unsigned long offset, bfd_size_type size,
312 bfd_size_type nmemb, const char * reason)
315 bfd_size_type amt = size * nmemb;
317 if (size == 0 || nmemb == 0)
320 /* If the size_t type is smaller than the bfd_size_type, eg because
321 you are building a 32-bit tool on a 64-bit host, then make sure
322 that when the sizes are cast to (size_t) no information is lost. */
323 if (sizeof (size_t) < sizeof (bfd_size_type)
324 && ( (bfd_size_type) ((size_t) size) != size
325 || (bfd_size_type) ((size_t) nmemb) != nmemb))
328 error (_("Size truncation prevents reading 0x%llx elements of size 0x%llx for %s\n"),
329 (unsigned long long) nmemb, (unsigned long long) size, reason);
333 /* Check for size overflow. */
337 error (_("Size overflow prevents reading 0x%llx elements of size 0x%llx for %s\n"),
338 (unsigned long long) nmemb, (unsigned long long) size, reason);
342 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
343 attempting to allocate memory when the read is bound to fail. */
344 if (amt > current_file_size
345 || offset + archive_file_offset + amt > current_file_size)
348 error (_("Reading 0x%llx bytes extends past end of file for %s\n"),
349 (unsigned long long) amt, reason);
353 if (fseek (file, archive_file_offset + offset, SEEK_SET))
356 error (_("Unable to seek to 0x%lx for %s\n"),
357 (unsigned long) archive_file_offset + offset, reason);
364 /* Check for overflow. */
365 if (nmemb < (~(bfd_size_type) 0 - 1) / size)
366 /* + 1 so that we can '\0' terminate invalid string table sections. */
367 mvar = malloc ((size_t) amt + 1);
372 error (_("Out of memory allocating 0x%llx bytes for %s\n"),
373 (unsigned long long) amt, reason);
377 ((char *) mvar)[amt] = '\0';
380 if (fread (mvar, (size_t) size, (size_t) nmemb, file) != nmemb)
383 error (_("Unable to read in 0x%llx bytes of %s\n"),
384 (unsigned long long) amt, reason);
393 /* Print a VMA value. */
396 print_vma (bfd_vma vma, print_mode mode)
409 return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
416 return printf ("%5" BFD_VMA_FMT "d", vma);
424 return nc + printf ("%" BFD_VMA_FMT "x", vma);
427 return printf ("%" BFD_VMA_FMT "d", vma);
430 return printf ("%" BFD_VMA_FMT "u", vma);
435 /* Display a symbol on stdout. Handles the display of control characters and
436 multibye characters (assuming the host environment supports them).
438 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
440 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
441 padding as necessary.
443 Returns the number of emitted characters. */
446 print_symbol (int width, const char *symbol)
448 bfd_boolean extra_padding = FALSE;
450 #ifdef HAVE_MBSTATE_T
457 /* Keep the width positive. This also helps. */
459 extra_padding = TRUE;
464 /* Set the remaining width to a very large value.
465 This simplifies the code below. */
466 width_remaining = INT_MAX;
468 width_remaining = width;
470 #ifdef HAVE_MBSTATE_T
471 /* Initialise the multibyte conversion state. */
472 memset (& state, 0, sizeof (state));
475 while (width_remaining)
478 const char c = *symbol++;
483 /* Do not print control characters directly as they can affect terminal
484 settings. Such characters usually appear in the names generated
485 by the assembler for local labels. */
488 if (width_remaining < 2)
491 printf ("^%c", c + 0x40);
492 width_remaining -= 2;
495 else if (ISPRINT (c))
503 #ifdef HAVE_MBSTATE_T
506 /* Let printf do the hard work of displaying multibyte characters. */
507 printf ("%.1s", symbol - 1);
511 #ifdef HAVE_MBSTATE_T
512 /* Try to find out how many bytes made up the character that was
513 just printed. Advance the symbol pointer past the bytes that
515 n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
519 if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
524 if (extra_padding && num_printed < width)
526 /* Fill in the remaining spaces. */
527 printf ("%-*s", width - num_printed, " ");
534 /* Returns a pointer to a static buffer containing a printable version of
535 the given section's name. Like print_symbol, except that it does not try
536 to print multibyte characters, it just interprets them as hex values. */
539 printable_section_name (Elf_Internal_Shdr * sec)
541 #define MAX_PRINT_SEC_NAME_LEN 128
542 static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
543 const char * name = SECTION_NAME (sec);
544 char * buf = sec_name_buf;
546 unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
548 while ((c = * name ++) != 0)
559 else if (ISPRINT (c))
566 static char hex[17] = "0123456789ABCDEF";
571 * buf ++ = hex[(c & 0xf0) >> 4];
572 * buf ++ = hex[c & 0x0f];
586 printable_section_name_from_index (unsigned long ndx)
588 if (ndx >= elf_header.e_shnum)
589 return _("<corrupt>");
591 return printable_section_name (section_headers + ndx);
594 /* Return a pointer to section NAME, or NULL if no such section exists. */
596 static Elf_Internal_Shdr *
597 find_section (const char * name)
601 for (i = 0; i < elf_header.e_shnum; i++)
602 if (streq (SECTION_NAME (section_headers + i), name))
603 return section_headers + i;
608 /* Return a pointer to a section containing ADDR, or NULL if no such
611 static Elf_Internal_Shdr *
612 find_section_by_address (bfd_vma addr)
616 for (i = 0; i < elf_header.e_shnum; i++)
618 Elf_Internal_Shdr *sec = section_headers + i;
619 if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
626 static Elf_Internal_Shdr *
627 find_section_by_type (unsigned int type)
631 for (i = 0; i < elf_header.e_shnum; i++)
633 Elf_Internal_Shdr *sec = section_headers + i;
634 if (sec->sh_type == type)
641 /* Return a pointer to section NAME, or NULL if no such section exists,
642 restricted to the list of sections given in SET. */
644 static Elf_Internal_Shdr *
645 find_section_in_set (const char * name, unsigned int * set)
651 while ((i = *set++) > 0)
652 if (streq (SECTION_NAME (section_headers + i), name))
653 return section_headers + i;
656 return find_section (name);
659 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
662 static inline unsigned long
663 read_uleb128 (unsigned char *data,
664 unsigned int *length_return,
665 const unsigned char * const end)
667 return read_leb128 (data, length_return, FALSE, end);
670 /* Return true if the current file is for IA-64 machine and OpenVMS ABI.
671 This OS has so many departures from the ELF standard that we test it at
677 return elf_header.e_machine == EM_IA_64
678 && elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
681 /* Guess the relocation size commonly used by the specific machines. */
684 guess_is_rela (unsigned int e_machine)
688 /* Targets that use REL relocations. */
703 /* Targets that use RELA relocations. */
707 case EM_ADAPTEVA_EPIPHANY:
709 case EM_ALTERA_NIOS2:
728 case EM_LATTICEMICO32:
737 case EM_CYGNUS_MN10200:
739 case EM_CYGNUS_MN10300:
772 case EM_MICROBLAZE_OLD:
793 warn (_("Don't know about relocations on this machine architecture\n"));
799 slurp_rela_relocs (FILE * file,
800 unsigned long rel_offset,
801 unsigned long rel_size,
802 Elf_Internal_Rela ** relasp,
803 unsigned long * nrelasp)
805 Elf_Internal_Rela * relas;
811 Elf32_External_Rela * erelas;
813 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset, 1,
814 rel_size, _("32-bit relocation data"));
818 nrelas = rel_size / sizeof (Elf32_External_Rela);
820 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
821 sizeof (Elf_Internal_Rela));
826 error (_("out of memory parsing relocs\n"));
830 for (i = 0; i < nrelas; i++)
832 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
833 relas[i].r_info = BYTE_GET (erelas[i].r_info);
834 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
841 Elf64_External_Rela * erelas;
843 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset, 1,
844 rel_size, _("64-bit relocation data"));
848 nrelas = rel_size / sizeof (Elf64_External_Rela);
850 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
851 sizeof (Elf_Internal_Rela));
856 error (_("out of memory parsing relocs\n"));
860 for (i = 0; i < nrelas; i++)
862 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
863 relas[i].r_info = BYTE_GET (erelas[i].r_info);
864 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
866 /* The #ifdef BFD64 below is to prevent a compile time
867 warning. We know that if we do not have a 64 bit data
868 type that we will never execute this code anyway. */
870 if (elf_header.e_machine == EM_MIPS
871 && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
873 /* In little-endian objects, r_info isn't really a
874 64-bit little-endian value: it has a 32-bit
875 little-endian symbol index followed by four
876 individual byte fields. Reorder INFO
878 bfd_vma inf = relas[i].r_info;
879 inf = (((inf & 0xffffffff) << 32)
880 | ((inf >> 56) & 0xff)
881 | ((inf >> 40) & 0xff00)
882 | ((inf >> 24) & 0xff0000)
883 | ((inf >> 8) & 0xff000000));
884 relas[i].r_info = inf;
897 slurp_rel_relocs (FILE * file,
898 unsigned long rel_offset,
899 unsigned long rel_size,
900 Elf_Internal_Rela ** relsp,
901 unsigned long * nrelsp)
903 Elf_Internal_Rela * rels;
909 Elf32_External_Rel * erels;
911 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset, 1,
912 rel_size, _("32-bit relocation data"));
916 nrels = rel_size / sizeof (Elf32_External_Rel);
918 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
923 error (_("out of memory parsing relocs\n"));
927 for (i = 0; i < nrels; i++)
929 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
930 rels[i].r_info = BYTE_GET (erels[i].r_info);
931 rels[i].r_addend = 0;
938 Elf64_External_Rel * erels;
940 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset, 1,
941 rel_size, _("64-bit relocation data"));
945 nrels = rel_size / sizeof (Elf64_External_Rel);
947 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
952 error (_("out of memory parsing relocs\n"));
956 for (i = 0; i < nrels; i++)
958 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
959 rels[i].r_info = BYTE_GET (erels[i].r_info);
960 rels[i].r_addend = 0;
962 /* The #ifdef BFD64 below is to prevent a compile time
963 warning. We know that if we do not have a 64 bit data
964 type that we will never execute this code anyway. */
966 if (elf_header.e_machine == EM_MIPS
967 && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
969 /* In little-endian objects, r_info isn't really a
970 64-bit little-endian value: it has a 32-bit
971 little-endian symbol index followed by four
972 individual byte fields. Reorder INFO
974 bfd_vma inf = rels[i].r_info;
975 inf = (((inf & 0xffffffff) << 32)
976 | ((inf >> 56) & 0xff)
977 | ((inf >> 40) & 0xff00)
978 | ((inf >> 24) & 0xff0000)
979 | ((inf >> 8) & 0xff000000));
980 rels[i].r_info = inf;
992 /* Returns the reloc type extracted from the reloc info field. */
995 get_reloc_type (bfd_vma reloc_info)
998 return ELF32_R_TYPE (reloc_info);
1000 switch (elf_header.e_machine)
1003 /* Note: We assume that reloc_info has already been adjusted for us. */
1004 return ELF64_MIPS_R_TYPE (reloc_info);
1007 return ELF64_R_TYPE_ID (reloc_info);
1010 return ELF64_R_TYPE (reloc_info);
1014 /* Return the symbol index extracted from the reloc info field. */
1017 get_reloc_symindex (bfd_vma reloc_info)
1019 return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
1022 static inline bfd_boolean
1023 uses_msp430x_relocs (void)
1026 elf_header.e_machine == EM_MSP430 /* Paranoia. */
1027 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1028 && (((elf_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
1029 /* TI compiler uses ELFOSABI_NONE. */
1030 || (elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
1033 /* Display the contents of the relocation data found at the specified
1037 dump_relocations (FILE * file,
1038 unsigned long rel_offset,
1039 unsigned long rel_size,
1040 Elf_Internal_Sym * symtab,
1041 unsigned long nsyms,
1043 unsigned long strtablen,
1047 Elf_Internal_Rela * rels;
1049 if (is_rela == UNKNOWN)
1050 is_rela = guess_is_rela (elf_header.e_machine);
1054 if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
1059 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
1068 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1070 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1075 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1077 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1085 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1087 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1092 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1094 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1098 for (i = 0; i < rel_size; i++)
1103 bfd_vma symtab_index;
1106 offset = rels[i].r_offset;
1107 inf = rels[i].r_info;
1109 type = get_reloc_type (inf);
1110 symtab_index = get_reloc_symindex (inf);
1114 printf ("%8.8lx %8.8lx ",
1115 (unsigned long) offset & 0xffffffff,
1116 (unsigned long) inf & 0xffffffff);
1120 #if BFD_HOST_64BIT_LONG
1122 ? "%16.16lx %16.16lx "
1123 : "%12.12lx %12.12lx ",
1125 #elif BFD_HOST_64BIT_LONG_LONG
1128 ? "%16.16llx %16.16llx "
1129 : "%12.12llx %12.12llx ",
1133 ? "%16.16I64x %16.16I64x "
1134 : "%12.12I64x %12.12I64x ",
1139 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1140 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1141 _bfd_int64_high (offset),
1142 _bfd_int64_low (offset),
1143 _bfd_int64_high (inf),
1144 _bfd_int64_low (inf));
1148 switch (elf_header.e_machine)
1155 rtype = elf_aarch64_reloc_type (type);
1159 case EM_CYGNUS_M32R:
1160 rtype = elf_m32r_reloc_type (type);
1165 rtype = elf_i386_reloc_type (type);
1170 rtype = elf_m68hc11_reloc_type (type);
1174 rtype = elf_m68k_reloc_type (type);
1178 rtype = elf_i960_reloc_type (type);
1183 rtype = elf_avr_reloc_type (type);
1186 case EM_OLD_SPARCV9:
1187 case EM_SPARC32PLUS:
1190 rtype = elf_sparc_reloc_type (type);
1194 rtype = elf_spu_reloc_type (type);
1198 rtype = v800_reloc_type (type);
1201 case EM_CYGNUS_V850:
1202 rtype = v850_reloc_type (type);
1206 case EM_CYGNUS_D10V:
1207 rtype = elf_d10v_reloc_type (type);
1211 case EM_CYGNUS_D30V:
1212 rtype = elf_d30v_reloc_type (type);
1216 rtype = elf_dlx_reloc_type (type);
1220 rtype = elf_sh_reloc_type (type);
1224 case EM_CYGNUS_MN10300:
1225 rtype = elf_mn10300_reloc_type (type);
1229 case EM_CYGNUS_MN10200:
1230 rtype = elf_mn10200_reloc_type (type);
1234 case EM_CYGNUS_FR30:
1235 rtype = elf_fr30_reloc_type (type);
1239 rtype = elf_frv_reloc_type (type);
1243 rtype = elf_mcore_reloc_type (type);
1247 rtype = elf_mmix_reloc_type (type);
1251 rtype = elf_moxie_reloc_type (type);
1255 if (uses_msp430x_relocs ())
1257 rtype = elf_msp430x_reloc_type (type);
1261 rtype = elf_msp430_reloc_type (type);
1265 rtype = elf_nds32_reloc_type (type);
1269 rtype = elf_ppc_reloc_type (type);
1273 rtype = elf_ppc64_reloc_type (type);
1277 case EM_MIPS_RS3_LE:
1278 rtype = elf_mips_reloc_type (type);
1282 rtype = elf_alpha_reloc_type (type);
1286 rtype = elf_arm_reloc_type (type);
1290 rtype = elf_arc_reloc_type (type);
1294 rtype = elf_hppa_reloc_type (type);
1300 rtype = elf_h8_reloc_type (type);
1304 rtype = elf_or1k_reloc_type (type);
1309 rtype = elf_pj_reloc_type (type);
1312 rtype = elf_ia64_reloc_type (type);
1316 rtype = elf_cris_reloc_type (type);
1320 rtype = elf_i860_reloc_type (type);
1326 rtype = elf_x86_64_reloc_type (type);
1330 rtype = i370_reloc_type (type);
1335 rtype = elf_s390_reloc_type (type);
1339 rtype = elf_score_reloc_type (type);
1343 rtype = elf_xstormy16_reloc_type (type);
1347 rtype = elf_crx_reloc_type (type);
1351 rtype = elf_vax_reloc_type (type);
1354 case EM_ADAPTEVA_EPIPHANY:
1355 rtype = elf_epiphany_reloc_type (type);
1360 rtype = elf_ip2k_reloc_type (type);
1364 rtype = elf_iq2000_reloc_type (type);
1369 rtype = elf_xtensa_reloc_type (type);
1372 case EM_LATTICEMICO32:
1373 rtype = elf_lm32_reloc_type (type);
1378 rtype = elf_m32c_reloc_type (type);
1382 rtype = elf_mt_reloc_type (type);
1386 rtype = elf_bfin_reloc_type (type);
1390 rtype = elf_mep_reloc_type (type);
1394 rtype = elf_cr16_reloc_type (type);
1398 case EM_MICROBLAZE_OLD:
1399 rtype = elf_microblaze_reloc_type (type);
1403 rtype = elf_rl78_reloc_type (type);
1407 rtype = elf_rx_reloc_type (type);
1411 rtype = elf_metag_reloc_type (type);
1416 rtype = elf_xc16x_reloc_type (type);
1420 rtype = elf_tic6x_reloc_type (type);
1424 rtype = elf_tilegx_reloc_type (type);
1428 rtype = elf_tilepro_reloc_type (type);
1432 rtype = elf_xgate_reloc_type (type);
1435 case EM_ALTERA_NIOS2:
1436 rtype = elf_nios2_reloc_type (type);
1441 printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
1443 printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1445 if (elf_header.e_machine == EM_ALPHA
1447 && streq (rtype, "R_ALPHA_LITUSE")
1450 switch (rels[i].r_addend)
1452 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1453 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1454 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1455 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1456 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1457 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1458 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1459 default: rtype = NULL;
1462 printf (" (%s)", rtype);
1466 printf (_("<unknown addend: %lx>"),
1467 (unsigned long) rels[i].r_addend);
1470 else if (symtab_index)
1472 if (symtab == NULL || symtab_index >= nsyms)
1473 printf (_(" bad symbol index: %08lx"), (unsigned long) symtab_index);
1476 Elf_Internal_Sym * psym;
1478 psym = symtab + symtab_index;
1482 if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
1486 unsigned int width = is_32bit_elf ? 8 : 14;
1488 /* Relocations against GNU_IFUNC symbols do not use the value
1489 of the symbol as the address to relocate against. Instead
1490 they invoke the function named by the symbol and use its
1491 result as the address for relocation.
1493 To indicate this to the user, do not display the value of
1494 the symbol in the "Symbols's Value" field. Instead show
1495 its name followed by () as a hint that the symbol is
1499 || psym->st_name == 0
1500 || psym->st_name >= strtablen)
1503 name = strtab + psym->st_name;
1505 len = print_symbol (width, name);
1506 printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
1510 print_vma (psym->st_value, LONG_HEX);
1512 printf (is_32bit_elf ? " " : " ");
1515 if (psym->st_name == 0)
1517 const char * sec_name = "<null>";
1520 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1522 if (psym->st_shndx < elf_header.e_shnum)
1523 sec_name = SECTION_NAME (section_headers + psym->st_shndx);
1524 else if (psym->st_shndx == SHN_ABS)
1526 else if (psym->st_shndx == SHN_COMMON)
1527 sec_name = "COMMON";
1528 else if ((elf_header.e_machine == EM_MIPS
1529 && psym->st_shndx == SHN_MIPS_SCOMMON)
1530 || (elf_header.e_machine == EM_TI_C6000
1531 && psym->st_shndx == SHN_TIC6X_SCOMMON))
1532 sec_name = "SCOMMON";
1533 else if (elf_header.e_machine == EM_MIPS
1534 && psym->st_shndx == SHN_MIPS_SUNDEFINED)
1535 sec_name = "SUNDEF";
1536 else if ((elf_header.e_machine == EM_X86_64
1537 || elf_header.e_machine == EM_L1OM
1538 || elf_header.e_machine == EM_K1OM)
1539 && psym->st_shndx == SHN_X86_64_LCOMMON)
1540 sec_name = "LARGE_COMMON";
1541 else if (elf_header.e_machine == EM_IA_64
1542 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1543 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1544 sec_name = "ANSI_COM";
1545 else if (is_ia64_vms ()
1546 && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
1547 sec_name = "VMS_SYMVEC";
1550 sprintf (name_buf, "<section 0x%x>",
1551 (unsigned int) psym->st_shndx);
1552 sec_name = name_buf;
1555 print_symbol (22, sec_name);
1557 else if (strtab == NULL)
1558 printf (_("<string table index: %3ld>"), psym->st_name);
1559 else if (psym->st_name >= strtablen)
1560 printf (_("<corrupt string table index: %3ld>"), psym->st_name);
1562 print_symbol (22, strtab + psym->st_name);
1566 bfd_signed_vma off = rels[i].r_addend;
1568 /* PR 17531: file: 2e63226f. */
1569 if (off == ((bfd_signed_vma) 1) << ((sizeof (bfd_signed_vma) * 8) - 1))
1570 printf (" + %" BFD_VMA_FMT "x", off);
1572 printf (" - %" BFD_VMA_FMT "x", - off);
1574 printf (" + %" BFD_VMA_FMT "x", off);
1580 bfd_signed_vma off = rels[i].r_addend;
1582 printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
1583 /* PR 17531: file: 2e63226f. */
1584 if (off == ((bfd_signed_vma) 1) << ((sizeof (bfd_signed_vma) * 8) - 1))
1585 printf ("%" BFD_VMA_FMT "x", off);
1587 printf ("-%" BFD_VMA_FMT "x", - off);
1589 printf ("%" BFD_VMA_FMT "x", off);
1592 if (elf_header.e_machine == EM_SPARCV9
1594 && streq (rtype, "R_SPARC_OLO10"))
1595 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
1600 if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
1602 bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
1603 bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
1604 const char * rtype2 = elf_mips_reloc_type (type2);
1605 const char * rtype3 = elf_mips_reloc_type (type3);
1607 printf (" Type2: ");
1610 printf (_("unrecognized: %-7lx"),
1611 (unsigned long) type2 & 0xffffffff);
1613 printf ("%-17.17s", rtype2);
1615 printf ("\n Type3: ");
1618 printf (_("unrecognized: %-7lx"),
1619 (unsigned long) type3 & 0xffffffff);
1621 printf ("%-17.17s", rtype3);
1632 get_mips_dynamic_type (unsigned long type)
1636 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1637 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1638 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1639 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1640 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1641 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1642 case DT_MIPS_MSYM: return "MIPS_MSYM";
1643 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1644 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1645 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1646 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1647 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1648 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1649 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1650 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1651 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1652 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1653 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1654 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1655 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1656 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1657 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1658 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1659 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1660 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1661 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1662 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1663 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1664 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1665 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1666 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1667 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1668 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1669 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1670 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1671 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1672 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1673 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1674 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1675 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1676 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1677 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1678 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1679 case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
1680 case DT_MIPS_RWPLT: return "MIPS_RWPLT";
1687 get_sparc64_dynamic_type (unsigned long type)
1691 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1698 get_ppc_dynamic_type (unsigned long type)
1702 case DT_PPC_GOT: return "PPC_GOT";
1703 case DT_PPC_OPT: return "PPC_OPT";
1710 get_ppc64_dynamic_type (unsigned long type)
1714 case DT_PPC64_GLINK: return "PPC64_GLINK";
1715 case DT_PPC64_OPD: return "PPC64_OPD";
1716 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1717 case DT_PPC64_OPT: return "PPC64_OPT";
1724 get_parisc_dynamic_type (unsigned long type)
1728 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1729 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1730 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1731 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1732 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1733 case DT_HP_PREINIT: return "HP_PREINIT";
1734 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1735 case DT_HP_NEEDED: return "HP_NEEDED";
1736 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1737 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1738 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1739 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1740 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1741 case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
1742 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
1743 case DT_HP_FILTERED: return "HP_FILTERED";
1744 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
1745 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1746 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
1747 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
1748 case DT_PLT: return "PLT";
1749 case DT_PLT_SIZE: return "PLT_SIZE";
1750 case DT_DLT: return "DLT";
1751 case DT_DLT_SIZE: return "DLT_SIZE";
1758 get_ia64_dynamic_type (unsigned long type)
1762 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1763 case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
1764 case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
1765 case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
1766 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
1767 case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
1768 case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
1769 case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
1770 case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
1771 case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
1772 case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
1773 case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
1774 case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
1775 case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
1776 case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
1777 case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
1778 case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
1779 case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
1780 case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
1781 case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
1782 case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
1783 case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
1784 case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
1785 case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
1786 case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
1787 case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
1788 case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
1789 case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
1790 case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
1791 case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
1792 case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
1799 get_alpha_dynamic_type (unsigned long type)
1803 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
1810 get_score_dynamic_type (unsigned long type)
1814 case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
1815 case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
1816 case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
1817 case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
1818 case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
1819 case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
1826 get_tic6x_dynamic_type (unsigned long type)
1830 case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
1831 case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
1832 case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE";
1833 case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE";
1834 case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
1835 case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX";
1842 get_nios2_dynamic_type (unsigned long type)
1846 case DT_NIOS2_GP: return "NIOS2_GP";
1853 get_dynamic_type (unsigned long type)
1855 static char buff[64];
1859 case DT_NULL: return "NULL";
1860 case DT_NEEDED: return "NEEDED";
1861 case DT_PLTRELSZ: return "PLTRELSZ";
1862 case DT_PLTGOT: return "PLTGOT";
1863 case DT_HASH: return "HASH";
1864 case DT_STRTAB: return "STRTAB";
1865 case DT_SYMTAB: return "SYMTAB";
1866 case DT_RELA: return "RELA";
1867 case DT_RELASZ: return "RELASZ";
1868 case DT_RELAENT: return "RELAENT";
1869 case DT_STRSZ: return "STRSZ";
1870 case DT_SYMENT: return "SYMENT";
1871 case DT_INIT: return "INIT";
1872 case DT_FINI: return "FINI";
1873 case DT_SONAME: return "SONAME";
1874 case DT_RPATH: return "RPATH";
1875 case DT_SYMBOLIC: return "SYMBOLIC";
1876 case DT_REL: return "REL";
1877 case DT_RELSZ: return "RELSZ";
1878 case DT_RELENT: return "RELENT";
1879 case DT_PLTREL: return "PLTREL";
1880 case DT_DEBUG: return "DEBUG";
1881 case DT_TEXTREL: return "TEXTREL";
1882 case DT_JMPREL: return "JMPREL";
1883 case DT_BIND_NOW: return "BIND_NOW";
1884 case DT_INIT_ARRAY: return "INIT_ARRAY";
1885 case DT_FINI_ARRAY: return "FINI_ARRAY";
1886 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1887 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1888 case DT_RUNPATH: return "RUNPATH";
1889 case DT_FLAGS: return "FLAGS";
1891 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1892 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1894 case DT_CHECKSUM: return "CHECKSUM";
1895 case DT_PLTPADSZ: return "PLTPADSZ";
1896 case DT_MOVEENT: return "MOVEENT";
1897 case DT_MOVESZ: return "MOVESZ";
1898 case DT_FEATURE: return "FEATURE";
1899 case DT_POSFLAG_1: return "POSFLAG_1";
1900 case DT_SYMINSZ: return "SYMINSZ";
1901 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1903 case DT_ADDRRNGLO: return "ADDRRNGLO";
1904 case DT_CONFIG: return "CONFIG";
1905 case DT_DEPAUDIT: return "DEPAUDIT";
1906 case DT_AUDIT: return "AUDIT";
1907 case DT_PLTPAD: return "PLTPAD";
1908 case DT_MOVETAB: return "MOVETAB";
1909 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1911 case DT_VERSYM: return "VERSYM";
1913 case DT_TLSDESC_GOT: return "TLSDESC_GOT";
1914 case DT_TLSDESC_PLT: return "TLSDESC_PLT";
1915 case DT_RELACOUNT: return "RELACOUNT";
1916 case DT_RELCOUNT: return "RELCOUNT";
1917 case DT_FLAGS_1: return "FLAGS_1";
1918 case DT_VERDEF: return "VERDEF";
1919 case DT_VERDEFNUM: return "VERDEFNUM";
1920 case DT_VERNEED: return "VERNEED";
1921 case DT_VERNEEDNUM: return "VERNEEDNUM";
1923 case DT_AUXILIARY: return "AUXILIARY";
1924 case DT_USED: return "USED";
1925 case DT_FILTER: return "FILTER";
1927 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
1928 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
1929 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
1930 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
1931 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
1932 case DT_GNU_HASH: return "GNU_HASH";
1935 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1937 const char * result;
1939 switch (elf_header.e_machine)
1942 case EM_MIPS_RS3_LE:
1943 result = get_mips_dynamic_type (type);
1946 result = get_sparc64_dynamic_type (type);
1949 result = get_ppc_dynamic_type (type);
1952 result = get_ppc64_dynamic_type (type);
1955 result = get_ia64_dynamic_type (type);
1958 result = get_alpha_dynamic_type (type);
1961 result = get_score_dynamic_type (type);
1964 result = get_tic6x_dynamic_type (type);
1966 case EM_ALTERA_NIOS2:
1967 result = get_nios2_dynamic_type (type);
1977 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
1979 else if (((type >= DT_LOOS) && (type <= DT_HIOS))
1980 || (elf_header.e_machine == EM_PARISC
1981 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
1983 const char * result;
1985 switch (elf_header.e_machine)
1988 result = get_parisc_dynamic_type (type);
1991 result = get_ia64_dynamic_type (type);
2001 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
2005 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
2012 get_file_type (unsigned e_type)
2014 static char buff[32];
2018 case ET_NONE: return _("NONE (None)");
2019 case ET_REL: return _("REL (Relocatable file)");
2020 case ET_EXEC: return _("EXEC (Executable file)");
2021 case ET_DYN: return _("DYN (Shared object file)");
2022 case ET_CORE: return _("CORE (Core file)");
2025 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
2026 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
2027 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
2028 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
2030 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
2036 get_machine_name (unsigned e_machine)
2038 static char buff[64]; /* XXX */
2042 case EM_NONE: return _("None");
2043 case EM_AARCH64: return "AArch64";
2044 case EM_M32: return "WE32100";
2045 case EM_SPARC: return "Sparc";
2046 case EM_SPU: return "SPU";
2047 case EM_386: return "Intel 80386";
2048 case EM_68K: return "MC68000";
2049 case EM_88K: return "MC88000";
2050 case EM_486: return "Intel 80486";
2051 case EM_860: return "Intel 80860";
2052 case EM_MIPS: return "MIPS R3000";
2053 case EM_S370: return "IBM System/370";
2054 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
2055 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
2056 case EM_PARISC: return "HPPA";
2057 case EM_PPC_OLD: return "Power PC (old)";
2058 case EM_SPARC32PLUS: return "Sparc v8+" ;
2059 case EM_960: return "Intel 90860";
2060 case EM_PPC: return "PowerPC";
2061 case EM_PPC64: return "PowerPC64";
2062 case EM_FR20: return "Fujitsu FR20";
2063 case EM_RH32: return "TRW RH32";
2064 case EM_MCORE: return "MCORE";
2065 case EM_ARM: return "ARM";
2066 case EM_OLD_ALPHA: return "Digital Alpha (old)";
2067 case EM_SH: return "Renesas / SuperH SH";
2068 case EM_SPARCV9: return "Sparc v9";
2069 case EM_TRICORE: return "Siemens Tricore";
2070 case EM_ARC: return "ARC";
2071 case EM_H8_300: return "Renesas H8/300";
2072 case EM_H8_300H: return "Renesas H8/300H";
2073 case EM_H8S: return "Renesas H8S";
2074 case EM_H8_500: return "Renesas H8/500";
2075 case EM_IA_64: return "Intel IA-64";
2076 case EM_MIPS_X: return "Stanford MIPS-X";
2077 case EM_COLDFIRE: return "Motorola Coldfire";
2078 case EM_ALPHA: return "Alpha";
2079 case EM_CYGNUS_D10V:
2080 case EM_D10V: return "d10v";
2081 case EM_CYGNUS_D30V:
2082 case EM_D30V: return "d30v";
2083 case EM_CYGNUS_M32R:
2084 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
2085 case EM_CYGNUS_V850:
2086 case EM_V800: return "Renesas V850 (using RH850 ABI)";
2087 case EM_V850: return "Renesas V850";
2088 case EM_CYGNUS_MN10300:
2089 case EM_MN10300: return "mn10300";
2090 case EM_CYGNUS_MN10200:
2091 case EM_MN10200: return "mn10200";
2092 case EM_MOXIE: return "Moxie";
2093 case EM_CYGNUS_FR30:
2094 case EM_FR30: return "Fujitsu FR30";
2095 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
2097 case EM_PJ: return "picoJava";
2098 case EM_MMA: return "Fujitsu Multimedia Accelerator";
2099 case EM_PCP: return "Siemens PCP";
2100 case EM_NCPU: return "Sony nCPU embedded RISC processor";
2101 case EM_NDR1: return "Denso NDR1 microprocesspr";
2102 case EM_STARCORE: return "Motorola Star*Core processor";
2103 case EM_ME16: return "Toyota ME16 processor";
2104 case EM_ST100: return "STMicroelectronics ST100 processor";
2105 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
2106 case EM_PDSP: return "Sony DSP processor";
2107 case EM_PDP10: return "Digital Equipment Corp. PDP-10";
2108 case EM_PDP11: return "Digital Equipment Corp. PDP-11";
2109 case EM_FX66: return "Siemens FX66 microcontroller";
2110 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2111 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
2112 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
2113 case EM_68HC12: return "Motorola MC68HC12 Microcontroller";
2114 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
2115 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
2116 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
2117 case EM_SVX: return "Silicon Graphics SVx";
2118 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
2119 case EM_VAX: return "Digital VAX";
2121 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
2122 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
2123 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
2124 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
2125 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
2126 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
2127 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
2128 case EM_PRISM: return "Vitesse Prism";
2129 case EM_X86_64: return "Advanced Micro Devices X86-64";
2130 case EM_L1OM: return "Intel L1OM";
2131 case EM_K1OM: return "Intel K1OM";
2133 case EM_S390: return "IBM S/390";
2134 case EM_SCORE: return "SUNPLUS S+Core";
2135 case EM_XSTORMY16: return "Sanyo XStormy16 CPU core";
2136 case EM_OR1K: return "OpenRISC 1000";
2137 case EM_ARC_A5: return "ARC International ARCompact processor";
2138 case EM_CRX: return "National Semiconductor CRX microprocessor";
2139 case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
2140 case EM_DLX: return "OpenDLX";
2142 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
2143 case EM_IQ2000: return "Vitesse IQ2000";
2145 case EM_XTENSA: return "Tensilica Xtensa Processor";
2146 case EM_VIDEOCORE: return "Alphamosaic VideoCore processor";
2147 case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor";
2148 case EM_NS32K: return "National Semiconductor 32000 series";
2149 case EM_TPC: return "Tenor Network TPC processor";
2150 case EM_ST200: return "STMicroelectronics ST200 microcontroller";
2151 case EM_MAX: return "MAX Processor";
2152 case EM_CR: return "National Semiconductor CompactRISC";
2153 case EM_F2MC16: return "Fujitsu F2MC16";
2154 case EM_MSP430: return "Texas Instruments msp430 microcontroller";
2155 case EM_LATTICEMICO32: return "Lattice Mico32";
2157 case EM_M32C: return "Renesas M32c";
2158 case EM_MT: return "Morpho Techologies MT processor";
2159 case EM_BLACKFIN: return "Analog Devices Blackfin";
2160 case EM_SE_C33: return "S1C33 Family of Seiko Epson processors";
2161 case EM_SEP: return "Sharp embedded microprocessor";
2162 case EM_ARCA: return "Arca RISC microprocessor";
2163 case EM_UNICORE: return "Unicore";
2164 case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU";
2165 case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor";
2166 case EM_NIOS32: return "Altera Nios";
2167 case EM_ALTERA_NIOS2: return "Altera Nios II";
2169 case EM_XC16X: return "Infineon Technologies xc16x";
2170 case EM_M16C: return "Renesas M16C series microprocessors";
2171 case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller";
2172 case EM_CE: return "Freescale Communication Engine RISC core";
2173 case EM_TSK3000: return "Altium TSK3000 core";
2174 case EM_RS08: return "Freescale RS08 embedded processor";
2175 case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor";
2176 case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor";
2177 case EM_VIDEOCORE3: return "Broadcom VideoCore III processor";
2178 case EM_SE_C17: return "Seiko Epson C17 family";
2179 case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family";
2180 case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family";
2181 case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family";
2182 case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2183 case EM_CYPRESS_M8C: return "Cypress M8C microprocessor";
2184 case EM_R32C: return "Renesas R32C series microprocessors";
2185 case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family";
2186 case EM_QDSP6: return "QUALCOMM DSP6 Processor";
2187 case EM_8051: return "Intel 8051 and variants";
2188 case EM_STXP7X: return "STMicroelectronics STxP7x family";
2189 case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family";
2190 case EM_ECOG1X: return "Cyan Technology eCOG1X family";
2191 case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2192 case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor";
2193 case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor";
2194 case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture";
2195 case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
2198 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
2199 case EM_RL78: return "Renesas RL78";
2200 case EM_RX: return "Renesas RX";
2201 case EM_METAG: return "Imagination Technologies Meta processor architecture";
2202 case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
2203 case EM_ECOG16: return "Cyan Technology eCOG16 family";
2204 case EM_ETPU: return "Freescale Extended Time Processing Unit";
2205 case EM_SLE9X: return "Infineon Technologies SLE9X core";
2206 case EM_AVR32: return "Atmel Corporation 32-bit microprocessor family";
2207 case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller";
2208 case EM_TILE64: return "Tilera TILE64 multicore architecture family";
2209 case EM_TILEPRO: return "Tilera TILEPro multicore architecture family";
2210 case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family";
2211 case EM_CUDA: return "NVIDIA CUDA architecture";
2212 case EM_XGATE: return "Motorola XGATE embedded processor";
2214 snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
2220 decode_ARM_machine_flags (unsigned e_flags, char buf[])
2225 eabi = EF_ARM_EABI_VERSION (e_flags);
2226 e_flags &= ~ EF_ARM_EABIMASK;
2228 /* Handle "generic" ARM flags. */
2229 if (e_flags & EF_ARM_RELEXEC)
2231 strcat (buf, ", relocatable executable");
2232 e_flags &= ~ EF_ARM_RELEXEC;
2235 if (e_flags & EF_ARM_HASENTRY)
2237 strcat (buf, ", has entry point");
2238 e_flags &= ~ EF_ARM_HASENTRY;
2241 /* Now handle EABI specific flags. */
2245 strcat (buf, ", <unrecognized EABI>");
2250 case EF_ARM_EABI_VER1:
2251 strcat (buf, ", Version1 EABI");
2256 /* Process flags one bit at a time. */
2257 flag = e_flags & - e_flags;
2262 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2263 strcat (buf, ", sorted symbol tables");
2273 case EF_ARM_EABI_VER2:
2274 strcat (buf, ", Version2 EABI");
2279 /* Process flags one bit at a time. */
2280 flag = e_flags & - e_flags;
2285 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2286 strcat (buf, ", sorted symbol tables");
2289 case EF_ARM_DYNSYMSUSESEGIDX:
2290 strcat (buf, ", dynamic symbols use segment index");
2293 case EF_ARM_MAPSYMSFIRST:
2294 strcat (buf, ", mapping symbols precede others");
2304 case EF_ARM_EABI_VER3:
2305 strcat (buf, ", Version3 EABI");
2308 case EF_ARM_EABI_VER4:
2309 strcat (buf, ", Version4 EABI");
2314 /* Process flags one bit at a time. */
2315 flag = e_flags & - e_flags;
2321 strcat (buf, ", BE8");
2325 strcat (buf, ", LE8");
2336 case EF_ARM_EABI_VER5:
2337 strcat (buf, ", Version5 EABI");
2342 /* Process flags one bit at a time. */
2343 flag = e_flags & - e_flags;
2349 strcat (buf, ", BE8");
2353 strcat (buf, ", LE8");
2356 case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2357 strcat (buf, ", soft-float ABI");
2360 case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */
2361 strcat (buf, ", hard-float ABI");
2371 case EF_ARM_EABI_UNKNOWN:
2372 strcat (buf, ", GNU EABI");
2377 /* Process flags one bit at a time. */
2378 flag = e_flags & - e_flags;
2383 case EF_ARM_INTERWORK:
2384 strcat (buf, ", interworking enabled");
2387 case EF_ARM_APCS_26:
2388 strcat (buf, ", uses APCS/26");
2391 case EF_ARM_APCS_FLOAT:
2392 strcat (buf, ", uses APCS/float");
2396 strcat (buf, ", position independent");
2400 strcat (buf, ", 8 bit structure alignment");
2403 case EF_ARM_NEW_ABI:
2404 strcat (buf, ", uses new ABI");
2407 case EF_ARM_OLD_ABI:
2408 strcat (buf, ", uses old ABI");
2411 case EF_ARM_SOFT_FLOAT:
2412 strcat (buf, ", software FP");
2415 case EF_ARM_VFP_FLOAT:
2416 strcat (buf, ", VFP");
2419 case EF_ARM_MAVERICK_FLOAT:
2420 strcat (buf, ", Maverick FP");
2431 strcat (buf,_(", <unknown>"));
2435 decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
2444 static const char *ABI_STRINGS[] =
2446 "ABI v0", /* use r5 as return register; only used in N1213HC */
2447 "ABI v1", /* use r0 as return register */
2448 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2449 "ABI v2fp", /* for FPU */
2453 static const char *VER_STRINGS[] =
2455 "Andes ELF V1.3 or older",
2459 static const char *ARCH_STRINGS[] =
2468 abi = EF_NDS_ABI & e_flags;
2469 arch = EF_NDS_ARCH & e_flags;
2470 config = EF_NDS_INST & e_flags;
2471 version = EF_NDS32_ELF_VERSION & e_flags;
2473 memset (buf, 0, size);
2480 case E_NDS_ABI_V2FP:
2481 case E_NDS_ABI_AABI:
2482 case E_NDS_ABI_V2FP_PLUS:
2483 /* In case there are holes in the array. */
2484 r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
2488 r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
2494 case E_NDS32_ELF_VER_1_2:
2495 case E_NDS32_ELF_VER_1_3:
2496 case E_NDS32_ELF_VER_1_4:
2497 r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
2501 r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
2505 if (E_NDS_ABI_V0 == abi)
2507 /* OLD ABI; only used in N1213HC, has performance extension 1. */
2508 r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
2509 if (arch == E_NDS_ARCH_STAR_V1_0)
2510 r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
2516 case E_NDS_ARCH_STAR_V1_0:
2517 case E_NDS_ARCH_STAR_V2_0:
2518 case E_NDS_ARCH_STAR_V3_0:
2519 case E_NDS_ARCH_STAR_V3_M:
2520 r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
2524 r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
2525 /* ARCH version determines how the e_flags are interpreted.
2526 If it is unknown, we cannot proceed. */
2530 /* Newer ABI; Now handle architecture specific flags. */
2531 if (arch == E_NDS_ARCH_STAR_V1_0)
2533 if (config & E_NDS32_HAS_MFUSR_PC_INST)
2534 r += snprintf (buf + r, size -r, ", MFUSR_PC");
2536 if (!(config & E_NDS32_HAS_NO_MAC_INST))
2537 r += snprintf (buf + r, size -r, ", MAC");
2539 if (config & E_NDS32_HAS_DIV_INST)
2540 r += snprintf (buf + r, size -r, ", DIV");
2542 if (config & E_NDS32_HAS_16BIT_INST)
2543 r += snprintf (buf + r, size -r, ", 16b");
2547 if (config & E_NDS32_HAS_MFUSR_PC_INST)
2549 if (version <= E_NDS32_ELF_VER_1_3)
2550 r += snprintf (buf + r, size -r, ", [B8]");
2552 r += snprintf (buf + r, size -r, ", EX9");
2555 if (config & E_NDS32_HAS_MAC_DX_INST)
2556 r += snprintf (buf + r, size -r, ", MAC_DX");
2558 if (config & E_NDS32_HAS_DIV_DX_INST)
2559 r += snprintf (buf + r, size -r, ", DIV_DX");
2561 if (config & E_NDS32_HAS_16BIT_INST)
2563 if (version <= E_NDS32_ELF_VER_1_3)
2564 r += snprintf (buf + r, size -r, ", 16b");
2566 r += snprintf (buf + r, size -r, ", IFC");
2570 if (config & E_NDS32_HAS_EXT_INST)
2571 r += snprintf (buf + r, size -r, ", PERF1");
2573 if (config & E_NDS32_HAS_EXT2_INST)
2574 r += snprintf (buf + r, size -r, ", PERF2");
2576 if (config & E_NDS32_HAS_FPU_INST)
2579 r += snprintf (buf + r, size -r, ", FPU_SP");
2582 if (config & E_NDS32_HAS_FPU_DP_INST)
2585 r += snprintf (buf + r, size -r, ", FPU_DP");
2588 if (config & E_NDS32_HAS_FPU_MAC_INST)
2591 r += snprintf (buf + r, size -r, ", FPU_MAC");
2596 switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
2598 case E_NDS32_FPU_REG_8SP_4DP:
2599 r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
2601 case E_NDS32_FPU_REG_16SP_8DP:
2602 r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
2604 case E_NDS32_FPU_REG_32SP_16DP:
2605 r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
2607 case E_NDS32_FPU_REG_32SP_32DP:
2608 r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
2613 if (config & E_NDS32_HAS_AUDIO_INST)
2614 r += snprintf (buf + r, size -r, ", AUDIO");
2616 if (config & E_NDS32_HAS_STRING_INST)
2617 r += snprintf (buf + r, size -r, ", STR");
2619 if (config & E_NDS32_HAS_REDUCED_REGS)
2620 r += snprintf (buf + r, size -r, ", 16REG");
2622 if (config & E_NDS32_HAS_VIDEO_INST)
2624 if (version <= E_NDS32_ELF_VER_1_3)
2625 r += snprintf (buf + r, size -r, ", VIDEO");
2627 r += snprintf (buf + r, size -r, ", SATURATION");
2630 if (config & E_NDS32_HAS_ENCRIPT_INST)
2631 r += snprintf (buf + r, size -r, ", ENCRP");
2633 if (config & E_NDS32_HAS_L2C_INST)
2634 r += snprintf (buf + r, size -r, ", L2C");
2638 get_machine_flags (unsigned e_flags, unsigned e_machine)
2640 static char buf[1024];
2652 decode_ARM_machine_flags (e_flags, buf);
2656 if (e_flags & EF_BFIN_PIC)
2657 strcat (buf, ", PIC");
2659 if (e_flags & EF_BFIN_FDPIC)
2660 strcat (buf, ", FDPIC");
2662 if (e_flags & EF_BFIN_CODE_IN_L1)
2663 strcat (buf, ", code in L1");
2665 if (e_flags & EF_BFIN_DATA_IN_L1)
2666 strcat (buf, ", data in L1");
2671 switch (e_flags & EF_FRV_CPU_MASK)
2673 case EF_FRV_CPU_GENERIC:
2677 strcat (buf, ", fr???");
2680 case EF_FRV_CPU_FR300:
2681 strcat (buf, ", fr300");
2684 case EF_FRV_CPU_FR400:
2685 strcat (buf, ", fr400");
2687 case EF_FRV_CPU_FR405:
2688 strcat (buf, ", fr405");
2691 case EF_FRV_CPU_FR450:
2692 strcat (buf, ", fr450");
2695 case EF_FRV_CPU_FR500:
2696 strcat (buf, ", fr500");
2698 case EF_FRV_CPU_FR550:
2699 strcat (buf, ", fr550");
2702 case EF_FRV_CPU_SIMPLE:
2703 strcat (buf, ", simple");
2705 case EF_FRV_CPU_TOMCAT:
2706 strcat (buf, ", tomcat");
2712 if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
2713 strcat (buf, ", m68000");
2714 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
2715 strcat (buf, ", cpu32");
2716 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
2717 strcat (buf, ", fido_a");
2720 char const * isa = _("unknown");
2721 char const * mac = _("unknown mac");
2722 char const * additional = NULL;
2724 switch (e_flags & EF_M68K_CF_ISA_MASK)
2726 case EF_M68K_CF_ISA_A_NODIV:
2728 additional = ", nodiv";
2730 case EF_M68K_CF_ISA_A:
2733 case EF_M68K_CF_ISA_A_PLUS:
2736 case EF_M68K_CF_ISA_B_NOUSP:
2738 additional = ", nousp";
2740 case EF_M68K_CF_ISA_B:
2743 case EF_M68K_CF_ISA_C:
2746 case EF_M68K_CF_ISA_C_NODIV:
2748 additional = ", nodiv";
2751 strcat (buf, ", cf, isa ");
2754 strcat (buf, additional);
2755 if (e_flags & EF_M68K_CF_FLOAT)
2756 strcat (buf, ", float");
2757 switch (e_flags & EF_M68K_CF_MAC_MASK)
2762 case EF_M68K_CF_MAC:
2765 case EF_M68K_CF_EMAC:
2768 case EF_M68K_CF_EMAC_B:
2781 if (e_flags & EF_PPC_EMB)
2782 strcat (buf, ", emb");
2784 if (e_flags & EF_PPC_RELOCATABLE)
2785 strcat (buf, _(", relocatable"));
2787 if (e_flags & EF_PPC_RELOCATABLE_LIB)
2788 strcat (buf, _(", relocatable-lib"));
2792 if (e_flags & EF_PPC64_ABI)
2794 char abi[] = ", abiv0";
2796 abi[6] += e_flags & EF_PPC64_ABI;
2802 if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
2803 strcat (buf, ", RH850 ABI");
2805 if (e_flags & EF_V800_850E3)
2806 strcat (buf, ", V3 architecture");
2808 if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
2809 strcat (buf, ", FPU not used");
2811 if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
2812 strcat (buf, ", regmode: COMMON");
2814 if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
2815 strcat (buf, ", r4 not used");
2817 if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
2818 strcat (buf, ", r30 not used");
2820 if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
2821 strcat (buf, ", r5 not used");
2823 if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
2824 strcat (buf, ", r2 not used");
2826 for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
2828 switch (e_flags & - e_flags)
2830 case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
2831 case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
2832 case EF_RH850_SIMD: strcat (buf, ", SIMD"); break;
2833 case EF_RH850_CACHE: strcat (buf, ", CACHE"); break;
2834 case EF_RH850_MMU: strcat (buf, ", MMU"); break;
2835 case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
2836 case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
2837 case EF_RH850_DATA_ALIGN8: strcat (buf, ", 8-byte alignment"); break;
2838 case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
2839 case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
2840 case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
2841 case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
2842 case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
2843 case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
2844 case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
2845 case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
2852 case EM_CYGNUS_V850:
2853 switch (e_flags & EF_V850_ARCH)
2855 case E_V850E3V5_ARCH:
2856 strcat (buf, ", v850e3v5");
2858 case E_V850E2V3_ARCH:
2859 strcat (buf, ", v850e2v3");
2862 strcat (buf, ", v850e2");
2865 strcat (buf, ", v850e1");
2868 strcat (buf, ", v850e");
2871 strcat (buf, ", v850");
2874 strcat (buf, _(", unknown v850 architecture variant"));
2880 case EM_CYGNUS_M32R:
2881 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
2882 strcat (buf, ", m32r");
2886 case EM_MIPS_RS3_LE:
2887 if (e_flags & EF_MIPS_NOREORDER)
2888 strcat (buf, ", noreorder");
2890 if (e_flags & EF_MIPS_PIC)
2891 strcat (buf, ", pic");
2893 if (e_flags & EF_MIPS_CPIC)
2894 strcat (buf, ", cpic");
2896 if (e_flags & EF_MIPS_UCODE)
2897 strcat (buf, ", ugen_reserved");
2899 if (e_flags & EF_MIPS_ABI2)
2900 strcat (buf, ", abi2");
2902 if (e_flags & EF_MIPS_OPTIONS_FIRST)
2903 strcat (buf, ", odk first");
2905 if (e_flags & EF_MIPS_32BITMODE)
2906 strcat (buf, ", 32bitmode");
2908 if (e_flags & EF_MIPS_NAN2008)
2909 strcat (buf, ", nan2008");
2911 if (e_flags & EF_MIPS_FP64)
2912 strcat (buf, ", fp64");
2914 switch ((e_flags & EF_MIPS_MACH))
2916 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
2917 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
2918 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
2919 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
2920 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
2921 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
2922 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
2923 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
2924 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
2925 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
2926 case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
2927 case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
2928 case E_MIPS_MACH_LS3A: strcat (buf, ", loongson-3a"); break;
2929 case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
2930 case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
2931 case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
2932 case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break;
2934 /* We simply ignore the field in this case to avoid confusion:
2935 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2938 default: strcat (buf, _(", unknown CPU")); break;
2941 switch ((e_flags & EF_MIPS_ABI))
2943 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
2944 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
2945 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
2946 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
2948 /* We simply ignore the field in this case to avoid confusion:
2949 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2950 This means it is likely to be an o32 file, but not for
2953 default: strcat (buf, _(", unknown ABI")); break;
2956 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
2957 strcat (buf, ", mdmx");
2959 if (e_flags & EF_MIPS_ARCH_ASE_M16)
2960 strcat (buf, ", mips16");
2962 if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
2963 strcat (buf, ", micromips");
2965 switch ((e_flags & EF_MIPS_ARCH))
2967 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
2968 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
2969 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
2970 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
2971 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
2972 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
2973 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
2974 case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
2975 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
2976 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
2977 case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
2978 default: strcat (buf, _(", unknown ISA")); break;
2983 decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
2987 switch ((e_flags & EF_SH_MACH_MASK))
2989 case EF_SH1: strcat (buf, ", sh1"); break;
2990 case EF_SH2: strcat (buf, ", sh2"); break;
2991 case EF_SH3: strcat (buf, ", sh3"); break;
2992 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
2993 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
2994 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
2995 case EF_SH3E: strcat (buf, ", sh3e"); break;
2996 case EF_SH4: strcat (buf, ", sh4"); break;
2997 case EF_SH5: strcat (buf, ", sh5"); break;
2998 case EF_SH2E: strcat (buf, ", sh2e"); break;
2999 case EF_SH4A: strcat (buf, ", sh4a"); break;
3000 case EF_SH2A: strcat (buf, ", sh2a"); break;
3001 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
3002 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
3003 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
3004 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
3005 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
3006 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3007 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
3008 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
3009 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
3010 default: strcat (buf, _(", unknown ISA")); break;
3013 if (e_flags & EF_SH_PIC)
3014 strcat (buf, ", pic");
3016 if (e_flags & EF_SH_FDPIC)
3017 strcat (buf, ", fdpic");
3021 if (e_flags & EF_OR1K_NODELAY)
3022 strcat (buf, ", no delay");
3026 if (e_flags & EF_SPARC_32PLUS)
3027 strcat (buf, ", v8+");
3029 if (e_flags & EF_SPARC_SUN_US1)
3030 strcat (buf, ", ultrasparcI");
3032 if (e_flags & EF_SPARC_SUN_US3)
3033 strcat (buf, ", ultrasparcIII");
3035 if (e_flags & EF_SPARC_HAL_R1)
3036 strcat (buf, ", halr1");
3038 if (e_flags & EF_SPARC_LEDATA)
3039 strcat (buf, ", ledata");
3041 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
3042 strcat (buf, ", tso");
3044 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
3045 strcat (buf, ", pso");
3047 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
3048 strcat (buf, ", rmo");
3052 switch (e_flags & EF_PARISC_ARCH)
3054 case EFA_PARISC_1_0:
3055 strcpy (buf, ", PA-RISC 1.0");
3057 case EFA_PARISC_1_1:
3058 strcpy (buf, ", PA-RISC 1.1");
3060 case EFA_PARISC_2_0:
3061 strcpy (buf, ", PA-RISC 2.0");
3066 if (e_flags & EF_PARISC_TRAPNIL)
3067 strcat (buf, ", trapnil");
3068 if (e_flags & EF_PARISC_EXT)
3069 strcat (buf, ", ext");
3070 if (e_flags & EF_PARISC_LSB)
3071 strcat (buf, ", lsb");
3072 if (e_flags & EF_PARISC_WIDE)
3073 strcat (buf, ", wide");
3074 if (e_flags & EF_PARISC_NO_KABP)
3075 strcat (buf, ", no kabp");
3076 if (e_flags & EF_PARISC_LAZYSWAP)
3077 strcat (buf, ", lazyswap");
3082 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
3083 strcat (buf, ", new calling convention");
3085 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
3086 strcat (buf, ", gnu calling convention");
3090 if ((e_flags & EF_IA_64_ABI64))
3091 strcat (buf, ", 64-bit");
3093 strcat (buf, ", 32-bit");
3094 if ((e_flags & EF_IA_64_REDUCEDFP))
3095 strcat (buf, ", reduced fp model");
3096 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
3097 strcat (buf, ", no function descriptors, constant gp");
3098 else if ((e_flags & EF_IA_64_CONS_GP))
3099 strcat (buf, ", constant gp");
3100 if ((e_flags & EF_IA_64_ABSOLUTE))
3101 strcat (buf, ", absolute");
3102 if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
3104 if ((e_flags & EF_IA_64_VMS_LINKAGES))
3105 strcat (buf, ", vms_linkages");
3106 switch ((e_flags & EF_IA_64_VMS_COMCOD))
3108 case EF_IA_64_VMS_COMCOD_SUCCESS:
3110 case EF_IA_64_VMS_COMCOD_WARNING:
3111 strcat (buf, ", warning");
3113 case EF_IA_64_VMS_COMCOD_ERROR:
3114 strcat (buf, ", error");
3116 case EF_IA_64_VMS_COMCOD_ABORT:
3117 strcat (buf, ", abort");
3120 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3121 e_flags & EF_IA_64_VMS_COMCOD);
3122 strcat (buf, ", <unknown>");
3128 if ((e_flags & EF_VAX_NONPIC))
3129 strcat (buf, ", non-PIC");
3130 if ((e_flags & EF_VAX_DFLOAT))
3131 strcat (buf, ", D-Float");
3132 if ((e_flags & EF_VAX_GFLOAT))
3133 strcat (buf, ", G-Float");
3137 if (e_flags & E_FLAG_RL78_G10)
3138 strcat (buf, ", G10");
3139 if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
3140 strcat (buf, ", 64-bit doubles");
3144 if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
3145 strcat (buf, ", 64-bit doubles");
3146 if (e_flags & E_FLAG_RX_DSP)
3147 strcat (buf, ", dsp");
3148 if (e_flags & E_FLAG_RX_PID)
3149 strcat (buf, ", pid");
3150 if (e_flags & E_FLAG_RX_ABI)
3151 strcat (buf, ", RX ABI");
3155 if (e_flags & EF_S390_HIGH_GPRS)
3156 strcat (buf, ", highgprs");
3160 if ((e_flags & EF_C6000_REL))
3161 strcat (buf, ", relocatable module");
3165 strcat (buf, _(": architecture variant: "));
3166 switch (e_flags & EF_MSP430_MACH)
3168 case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
3169 case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
3170 case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
3171 case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
3172 case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
3173 case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
3174 case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
3175 case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
3176 case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
3177 case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
3178 case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
3179 case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
3180 case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
3181 case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
3182 case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break;
3184 strcat (buf, _(": unknown")); break;
3187 if (e_flags & ~ EF_MSP430_MACH)
3188 strcat (buf, _(": unknown extra flag bits also present"));
3196 get_osabi_name (unsigned int osabi)
3198 static char buff[32];
3202 case ELFOSABI_NONE: return "UNIX - System V";
3203 case ELFOSABI_HPUX: return "UNIX - HP-UX";
3204 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
3205 case ELFOSABI_GNU: return "UNIX - GNU";
3206 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
3207 case ELFOSABI_AIX: return "UNIX - AIX";
3208 case ELFOSABI_IRIX: return "UNIX - IRIX";
3209 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
3210 case ELFOSABI_TRU64: return "UNIX - TRU64";
3211 case ELFOSABI_MODESTO: return "Novell - Modesto";
3212 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
3213 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
3214 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
3215 case ELFOSABI_AROS: return "AROS";
3216 case ELFOSABI_FENIXOS: return "FenixOS";
3219 switch (elf_header.e_machine)
3224 case ELFOSABI_ARM: return "ARM";
3234 case ELFOSABI_STANDALONE: return _("Standalone App");
3243 case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000");
3244 case ELFOSABI_C6000_LINUX: return "Linux C6000";
3253 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
3259 get_aarch64_segment_type (unsigned long type)
3263 case PT_AARCH64_ARCHEXT:
3264 return "AARCH64_ARCHEXT";
3273 get_arm_segment_type (unsigned long type)
3287 get_mips_segment_type (unsigned long type)
3291 case PT_MIPS_REGINFO:
3293 case PT_MIPS_RTPROC:
3295 case PT_MIPS_OPTIONS:
3297 case PT_MIPS_ABIFLAGS:
3307 get_parisc_segment_type (unsigned long type)
3311 case PT_HP_TLS: return "HP_TLS";
3312 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
3313 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
3314 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
3315 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
3316 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
3317 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
3318 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
3319 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
3320 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
3321 case PT_HP_PARALLEL: return "HP_PARALLEL";
3322 case PT_HP_FASTBIND: return "HP_FASTBIND";
3323 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
3324 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
3325 case PT_HP_STACK: return "HP_STACK";
3326 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
3327 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
3328 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
3329 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
3338 get_ia64_segment_type (unsigned long type)
3342 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
3343 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
3344 case PT_HP_TLS: return "HP_TLS";
3345 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
3346 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
3347 case PT_IA_64_HP_STACK: return "HP_STACK";
3356 get_tic6x_segment_type (unsigned long type)
3360 case PT_C6000_PHATTR: return "C6000_PHATTR";
3369 get_segment_type (unsigned long p_type)
3371 static char buff[32];
3375 case PT_NULL: return "NULL";
3376 case PT_LOAD: return "LOAD";
3377 case PT_DYNAMIC: return "DYNAMIC";
3378 case PT_INTERP: return "INTERP";
3379 case PT_NOTE: return "NOTE";
3380 case PT_SHLIB: return "SHLIB";
3381 case PT_PHDR: return "PHDR";
3382 case PT_TLS: return "TLS";
3384 case PT_GNU_EH_FRAME:
3385 return "GNU_EH_FRAME";
3386 case PT_GNU_STACK: return "GNU_STACK";
3387 case PT_GNU_RELRO: return "GNU_RELRO";
3390 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
3392 const char * result;
3394 switch (elf_header.e_machine)
3397 result = get_aarch64_segment_type (p_type);
3400 result = get_arm_segment_type (p_type);
3403 case EM_MIPS_RS3_LE:
3404 result = get_mips_segment_type (p_type);
3407 result = get_parisc_segment_type (p_type);
3410 result = get_ia64_segment_type (p_type);
3413 result = get_tic6x_segment_type (p_type);
3423 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
3425 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
3427 const char * result;
3429 switch (elf_header.e_machine)
3432 result = get_parisc_segment_type (p_type);
3435 result = get_ia64_segment_type (p_type);
3445 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
3448 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
3455 get_mips_section_type_name (unsigned int sh_type)
3459 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
3460 case SHT_MIPS_MSYM: return "MIPS_MSYM";
3461 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
3462 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
3463 case SHT_MIPS_UCODE: return "MIPS_UCODE";
3464 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
3465 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
3466 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
3467 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
3468 case SHT_MIPS_RELD: return "MIPS_RELD";
3469 case SHT_MIPS_IFACE: return "MIPS_IFACE";
3470 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
3471 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
3472 case SHT_MIPS_SHDR: return "MIPS_SHDR";
3473 case SHT_MIPS_FDESC: return "MIPS_FDESC";
3474 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
3475 case SHT_MIPS_DENSE: return "MIPS_DENSE";
3476 case SHT_MIPS_PDESC: return "MIPS_PDESC";
3477 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
3478 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
3479 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
3480 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
3481 case SHT_MIPS_LINE: return "MIPS_LINE";
3482 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
3483 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
3484 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
3485 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
3486 case SHT_MIPS_DWARF: return "MIPS_DWARF";
3487 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
3488 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
3489 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
3490 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
3491 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
3492 case SHT_MIPS_XLATE: return "MIPS_XLATE";
3493 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
3494 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
3495 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
3496 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
3497 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
3498 case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS";
3506 get_parisc_section_type_name (unsigned int sh_type)
3510 case SHT_PARISC_EXT: return "PARISC_EXT";
3511 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
3512 case SHT_PARISC_DOC: return "PARISC_DOC";
3513 case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
3514 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
3515 case SHT_PARISC_STUBS: return "PARISC_STUBS";
3516 case SHT_PARISC_DLKM: return "PARISC_DLKM";
3524 get_ia64_section_type_name (unsigned int sh_type)
3526 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
3527 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
3528 return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
3532 case SHT_IA_64_EXT: return "IA_64_EXT";
3533 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
3534 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
3535 case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
3536 case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
3537 case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
3538 case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
3539 case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
3540 case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
3541 case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
3549 get_x86_64_section_type_name (unsigned int sh_type)
3553 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
3561 get_aarch64_section_type_name (unsigned int sh_type)
3565 case SHT_AARCH64_ATTRIBUTES:
3566 return "AARCH64_ATTRIBUTES";
3574 get_arm_section_type_name (unsigned int sh_type)
3578 case SHT_ARM_EXIDX: return "ARM_EXIDX";
3579 case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
3580 case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
3581 case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
3582 case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
3590 get_tic6x_section_type_name (unsigned int sh_type)
3594 case SHT_C6000_UNWIND:
3595 return "C6000_UNWIND";
3596 case SHT_C6000_PREEMPTMAP:
3597 return "C6000_PREEMPTMAP";
3598 case SHT_C6000_ATTRIBUTES:
3599 return "C6000_ATTRIBUTES";
3604 case SHT_TI_HANDLER:
3605 return "TI_HANDLER";
3606 case SHT_TI_INITINFO:
3607 return "TI_INITINFO";
3608 case SHT_TI_PHATTRS:
3609 return "TI_PHATTRS";
3617 get_msp430x_section_type_name (unsigned int sh_type)
3621 case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS";
3622 case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
3623 case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES";
3624 default: return NULL;
3629 get_section_type_name (unsigned int sh_type)
3631 static char buff[32];
3635 case SHT_NULL: return "NULL";
3636 case SHT_PROGBITS: return "PROGBITS";
3637 case SHT_SYMTAB: return "SYMTAB";
3638 case SHT_STRTAB: return "STRTAB";
3639 case SHT_RELA: return "RELA";
3640 case SHT_HASH: return "HASH";
3641 case SHT_DYNAMIC: return "DYNAMIC";
3642 case SHT_NOTE: return "NOTE";
3643 case SHT_NOBITS: return "NOBITS";
3644 case SHT_REL: return "REL";
3645 case SHT_SHLIB: return "SHLIB";
3646 case SHT_DYNSYM: return "DYNSYM";
3647 case SHT_INIT_ARRAY: return "INIT_ARRAY";
3648 case SHT_FINI_ARRAY: return "FINI_ARRAY";
3649 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
3650 case SHT_GNU_HASH: return "GNU_HASH";
3651 case SHT_GROUP: return "GROUP";
3652 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
3653 case SHT_GNU_verdef: return "VERDEF";
3654 case SHT_GNU_verneed: return "VERNEED";
3655 case SHT_GNU_versym: return "VERSYM";
3656 case 0x6ffffff0: return "VERSYM";
3657 case 0x6ffffffc: return "VERDEF";
3658 case 0x7ffffffd: return "AUXILIARY";
3659 case 0x7fffffff: return "FILTER";
3660 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
3663 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
3665 const char * result;
3667 switch (elf_header.e_machine)
3670 case EM_MIPS_RS3_LE:
3671 result = get_mips_section_type_name (sh_type);
3674 result = get_parisc_section_type_name (sh_type);
3677 result = get_ia64_section_type_name (sh_type);
3682 result = get_x86_64_section_type_name (sh_type);
3685 result = get_aarch64_section_type_name (sh_type);
3688 result = get_arm_section_type_name (sh_type);
3691 result = get_tic6x_section_type_name (sh_type);
3694 result = get_msp430x_section_type_name (sh_type);
3704 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
3706 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
3708 const char * result;
3710 switch (elf_header.e_machine)
3713 result = get_ia64_section_type_name (sh_type);
3723 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
3725 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
3726 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
3728 /* This message is probably going to be displayed in a 15
3729 character wide field, so put the hex value first. */
3730 snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
3736 #define OPTION_DEBUG_DUMP 512
3737 #define OPTION_DYN_SYMS 513
3738 #define OPTION_DWARF_DEPTH 514
3739 #define OPTION_DWARF_START 515
3740 #define OPTION_DWARF_CHECK 516
3742 static struct option options[] =
3744 {"all", no_argument, 0, 'a'},
3745 {"file-header", no_argument, 0, 'h'},
3746 {"program-headers", no_argument, 0, 'l'},
3747 {"headers", no_argument, 0, 'e'},
3748 {"histogram", no_argument, 0, 'I'},
3749 {"segments", no_argument, 0, 'l'},
3750 {"sections", no_argument, 0, 'S'},
3751 {"section-headers", no_argument, 0, 'S'},
3752 {"section-groups", no_argument, 0, 'g'},
3753 {"section-details", no_argument, 0, 't'},
3754 {"full-section-name",no_argument, 0, 'N'},
3755 {"symbols", no_argument, 0, 's'},
3756 {"syms", no_argument, 0, 's'},
3757 {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS},
3758 {"relocs", no_argument, 0, 'r'},
3759 {"notes", no_argument, 0, 'n'},
3760 {"dynamic", no_argument, 0, 'd'},
3761 {"arch-specific", no_argument, 0, 'A'},
3762 {"version-info", no_argument, 0, 'V'},
3763 {"use-dynamic", no_argument, 0, 'D'},
3764 {"unwind", no_argument, 0, 'u'},
3765 {"archive-index", no_argument, 0, 'c'},
3766 {"hex-dump", required_argument, 0, 'x'},
3767 {"relocated-dump", required_argument, 0, 'R'},
3768 {"string-dump", required_argument, 0, 'p'},
3769 #ifdef SUPPORT_DISASSEMBLY
3770 {"instruction-dump", required_argument, 0, 'i'},
3772 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
3774 {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
3775 {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
3776 {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
3778 {"version", no_argument, 0, 'v'},
3779 {"wide", no_argument, 0, 'W'},
3780 {"help", no_argument, 0, 'H'},
3781 {0, no_argument, 0, 0}
3785 usage (FILE * stream)
3787 fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
3788 fprintf (stream, _(" Display information about the contents of ELF format files\n"));
3789 fprintf (stream, _(" Options are:\n\
3790 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
3791 -h --file-header Display the ELF file header\n\
3792 -l --program-headers Display the program headers\n\
3793 --segments An alias for --program-headers\n\
3794 -S --section-headers Display the sections' header\n\
3795 --sections An alias for --section-headers\n\
3796 -g --section-groups Display the section groups\n\
3797 -t --section-details Display the section details\n\
3798 -e --headers Equivalent to: -h -l -S\n\
3799 -s --syms Display the symbol table\n\
3800 --symbols An alias for --syms\n\
3801 --dyn-syms Display the dynamic symbol table\n\
3802 -n --notes Display the core notes (if present)\n\
3803 -r --relocs Display the relocations (if present)\n\
3804 -u --unwind Display the unwind info (if present)\n\
3805 -d --dynamic Display the dynamic section (if present)\n\
3806 -V --version-info Display the version sections (if present)\n\
3807 -A --arch-specific Display architecture specific information (if any)\n\
3808 -c --archive-index Display the symbol/file index in an archive\n\
3809 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
3810 -x --hex-dump=<number|name>\n\
3811 Dump the contents of section <number|name> as bytes\n\
3812 -p --string-dump=<number|name>\n\
3813 Dump the contents of section <number|name> as strings\n\
3814 -R --relocated-dump=<number|name>\n\
3815 Dump the contents of section <number|name> as relocated bytes\n\
3816 -w[lLiaprmfFsoRt] or\n\
3817 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
3818 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
3819 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
3821 Display the contents of DWARF2 debug sections\n"));
3822 fprintf (stream, _("\
3823 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
3824 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
3826 #ifdef SUPPORT_DISASSEMBLY
3827 fprintf (stream, _("\
3828 -i --instruction-dump=<number|name>\n\
3829 Disassemble the contents of section <number|name>\n"));
3831 fprintf (stream, _("\
3832 -I --histogram Display histogram of bucket list lengths\n\
3833 -W --wide Allow output width to exceed 80 characters\n\
3834 @<file> Read options from <file>\n\
3835 -H --help Display this information\n\
3836 -v --version Display the version number of readelf\n"));
3838 if (REPORT_BUGS_TO[0] && stream == stdout)
3839 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
3841 exit (stream == stdout ? 0 : 1);
3844 /* Record the fact that the user wants the contents of section number
3845 SECTION to be displayed using the method(s) encoded as flags bits
3846 in TYPE. Note, TYPE can be zero if we are creating the array for
3850 request_dump_bynumber (unsigned int section, dump_type type)
3852 if (section >= num_dump_sects)
3854 dump_type * new_dump_sects;
3856 new_dump_sects = (dump_type *) calloc (section + 1,
3857 sizeof (* dump_sects));
3859 if (new_dump_sects == NULL)
3860 error (_("Out of memory allocating dump request table.\n"));
3863 /* Copy current flag settings. */
3864 memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects));
3868 dump_sects = new_dump_sects;
3869 num_dump_sects = section + 1;
3874 dump_sects[section] |= type;
3879 /* Request a dump by section name. */
3882 request_dump_byname (const char * section, dump_type type)
3884 struct dump_list_entry * new_request;
3886 new_request = (struct dump_list_entry *)
3887 malloc (sizeof (struct dump_list_entry));
3889 error (_("Out of memory allocating dump request table.\n"));
3891 new_request->name = strdup (section);
3892 if (!new_request->name)
3893 error (_("Out of memory allocating dump request table.\n"));
3895 new_request->type = type;
3897 new_request->next = dump_sects_byname;
3898 dump_sects_byname = new_request;
3902 request_dump (dump_type type)
3908 section = strtoul (optarg, & cp, 0);
3910 if (! *cp && section >= 0)
3911 request_dump_bynumber (section, type);
3913 request_dump_byname (optarg, type);
3918 parse_args (int argc, char ** argv)
3925 while ((c = getopt_long
3926 (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:", options, NULL)) != EOF)
3944 do_section_groups++;
3952 do_section_groups++;
3957 do_section_details++;
4001 request_dump (HEX_DUMP);
4004 request_dump (STRING_DUMP);
4007 request_dump (RELOC_DUMP);
4014 dwarf_select_sections_all ();
4019 dwarf_select_sections_by_letters (optarg);
4022 case OPTION_DEBUG_DUMP:
4029 dwarf_select_sections_by_names (optarg);
4032 case OPTION_DWARF_DEPTH:
4036 dwarf_cutoff_level = strtoul (optarg, & cp, 0);
4039 case OPTION_DWARF_START:
4043 dwarf_start_die = strtoul (optarg, & cp, 0);
4046 case OPTION_DWARF_CHECK:
4049 case OPTION_DYN_SYMS:
4052 #ifdef SUPPORT_DISASSEMBLY
4054 request_dump (DISASS_DUMP);
4058 print_version (program_name);
4067 /* xgettext:c-format */
4068 error (_("Invalid option '-%c'\n"), c);
4075 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
4076 && !do_segments && !do_header && !do_dump && !do_version
4077 && !do_histogram && !do_debugging && !do_arch && !do_notes
4078 && !do_section_groups && !do_archive_index
4083 warn (_("Nothing to do.\n"));
4089 get_elf_class (unsigned int elf_class)
4091 static char buff[32];
4095 case ELFCLASSNONE: return _("none");
4096 case ELFCLASS32: return "ELF32";
4097 case ELFCLASS64: return "ELF64";
4099 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
4105 get_data_encoding (unsigned int encoding)
4107 static char buff[32];
4111 case ELFDATANONE: return _("none");
4112 case ELFDATA2LSB: return _("2's complement, little endian");
4113 case ELFDATA2MSB: return _("2's complement, big endian");
4115 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
4120 /* Decode the data held in 'elf_header'. */
4123 process_file_header (void)
4125 if ( elf_header.e_ident[EI_MAG0] != ELFMAG0
4126 || elf_header.e_ident[EI_MAG1] != ELFMAG1
4127 || elf_header.e_ident[EI_MAG2] != ELFMAG2
4128 || elf_header.e_ident[EI_MAG3] != ELFMAG3)
4131 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
4135 init_dwarf_regnames (elf_header.e_machine);
4141 printf (_("ELF Header:\n"));
4142 printf (_(" Magic: "));
4143 for (i = 0; i < EI_NIDENT; i++)
4144 printf ("%2.2x ", elf_header.e_ident[i]);
4146 printf (_(" Class: %s\n"),
4147 get_elf_class (elf_header.e_ident[EI_CLASS]));
4148 printf (_(" Data: %s\n"),
4149 get_data_encoding (elf_header.e_ident[EI_DATA]));
4150 printf (_(" Version: %d %s\n"),
4151 elf_header.e_ident[EI_VERSION],
4152 (elf_header.e_ident[EI_VERSION] == EV_CURRENT
4154 : (elf_header.e_ident[EI_VERSION] != EV_NONE
4155 ? _("<unknown: %lx>")
4157 printf (_(" OS/ABI: %s\n"),
4158 get_osabi_name (elf_header.e_ident[EI_OSABI]));
4159 printf (_(" ABI Version: %d\n"),
4160 elf_header.e_ident[EI_ABIVERSION]);
4161 printf (_(" Type: %s\n"),
4162 get_file_type (elf_header.e_type));
4163 printf (_(" Machine: %s\n"),
4164 get_machine_name (elf_header.e_machine));
4165 printf (_(" Version: 0x%lx\n"),
4166 (unsigned long) elf_header.e_version);
4168 printf (_(" Entry point address: "));
4169 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
4170 printf (_("\n Start of program headers: "));
4171 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
4172 printf (_(" (bytes into file)\n Start of section headers: "));
4173 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
4174 printf (_(" (bytes into file)\n"));
4176 printf (_(" Flags: 0x%lx%s\n"),
4177 (unsigned long) elf_header.e_flags,
4178 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
4179 printf (_(" Size of this header: %ld (bytes)\n"),
4180 (long) elf_header.e_ehsize);
4181 printf (_(" Size of program headers: %ld (bytes)\n"),
4182 (long) elf_header.e_phentsize);
4183 printf (_(" Number of program headers: %ld"),
4184 (long) elf_header.e_phnum);
4185 if (section_headers != NULL
4186 && elf_header.e_phnum == PN_XNUM
4187 && section_headers[0].sh_info != 0)
4188 printf (" (%ld)", (long) section_headers[0].sh_info);
4189 putc ('\n', stdout);
4190 printf (_(" Size of section headers: %ld (bytes)\n"),
4191 (long) elf_header.e_shentsize);
4192 printf (_(" Number of section headers: %ld"),
4193 (long) elf_header.e_shnum);
4194 if (section_headers != NULL && elf_header.e_shnum == SHN_UNDEF)
4195 printf (" (%ld)", (long) section_headers[0].sh_size);
4196 putc ('\n', stdout);
4197 printf (_(" Section header string table index: %ld"),
4198 (long) elf_header.e_shstrndx);
4199 if (section_headers != NULL
4200 && elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
4201 printf (" (%u)", section_headers[0].sh_link);
4202 else if (elf_header.e_shstrndx != SHN_UNDEF
4203 && elf_header.e_shstrndx >= elf_header.e_shnum)
4204 printf (_(" <corrupt: out of range>"));
4205 putc ('\n', stdout);
4208 if (section_headers != NULL)
4210 if (elf_header.e_phnum == PN_XNUM
4211 && section_headers[0].sh_info != 0)
4212 elf_header.e_phnum = section_headers[0].sh_info;
4213 if (elf_header.e_shnum == SHN_UNDEF)
4214 elf_header.e_shnum = section_headers[0].sh_size;
4215 if (elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
4216 elf_header.e_shstrndx = section_headers[0].sh_link;
4217 else if (elf_header.e_shstrndx >= elf_header.e_shnum)
4218 elf_header.e_shstrndx = SHN_UNDEF;
4219 free (section_headers);
4220 section_headers = NULL;
4227 get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
4229 Elf32_External_Phdr * phdrs;
4230 Elf32_External_Phdr * external;
4231 Elf_Internal_Phdr * internal;
4233 unsigned int size = elf_header.e_phentsize;
4234 unsigned int num = elf_header.e_phnum;
4236 /* PR binutils/17531: Cope with unexpected section header sizes. */
4237 if (size == 0 || num == 0)
4239 if (size < sizeof * phdrs)
4241 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
4244 if (size > sizeof * phdrs)
4245 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
4247 phdrs = (Elf32_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
4248 size, num, _("program headers"));
4252 for (i = 0, internal = pheaders, external = phdrs;
4253 i < elf_header.e_phnum;
4254 i++, internal++, external++)
4256 internal->p_type = BYTE_GET (external->p_type);
4257 internal->p_offset = BYTE_GET (external->p_offset);
4258 internal->p_vaddr = BYTE_GET (external->p_vaddr);
4259 internal->p_paddr = BYTE_GET (external->p_paddr);
4260 internal->p_filesz = BYTE_GET (external->p_filesz);
4261 internal->p_memsz = BYTE_GET (external->p_memsz);
4262 internal->p_flags = BYTE_GET (external->p_flags);
4263 internal->p_align = BYTE_GET (external->p_align);
4271 get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
4273 Elf64_External_Phdr * phdrs;
4274 Elf64_External_Phdr * external;
4275 Elf_Internal_Phdr * internal;
4277 unsigned int size = elf_header.e_phentsize;
4278 unsigned int num = elf_header.e_phnum;
4280 /* PR binutils/17531: Cope with unexpected section header sizes. */
4281 if (size == 0 || num == 0)
4283 if (size < sizeof * phdrs)
4285 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
4288 if (size > sizeof * phdrs)
4289 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
4291 phdrs = (Elf64_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
4292 size, num, _("program headers"));
4296 for (i = 0, internal = pheaders, external = phdrs;
4297 i < elf_header.e_phnum;
4298 i++, internal++, external++)
4300 internal->p_type = BYTE_GET (external->p_type);
4301 internal->p_flags = BYTE_GET (external->p_flags);
4302 internal->p_offset = BYTE_GET (external->p_offset);
4303 internal->p_vaddr = BYTE_GET (external->p_vaddr);
4304 internal->p_paddr = BYTE_GET (external->p_paddr);
4305 internal->p_filesz = BYTE_GET (external->p_filesz);
4306 internal->p_memsz = BYTE_GET (external->p_memsz);
4307 internal->p_align = BYTE_GET (external->p_align);
4314 /* Returns 1 if the program headers were read into `program_headers'. */
4317 get_program_headers (FILE * file)
4319 Elf_Internal_Phdr * phdrs;
4321 /* Check cache of prior read. */
4322 if (program_headers != NULL)
4325 phdrs = (Elf_Internal_Phdr *) cmalloc (elf_header.e_phnum,
4326 sizeof (Elf_Internal_Phdr));
4330 error (_("Out of memory reading %u program headers\n"),
4331 elf_header.e_phnum);
4336 ? get_32bit_program_headers (file, phdrs)
4337 : get_64bit_program_headers (file, phdrs))
4339 program_headers = phdrs;
4347 /* Returns 1 if the program headers were loaded. */
4350 process_program_headers (FILE * file)
4352 Elf_Internal_Phdr * segment;
4355 if (elf_header.e_phnum == 0)
4357 /* PR binutils/12467. */
4358 if (elf_header.e_phoff != 0)
4359 warn (_("possibly corrupt ELF header - it has a non-zero program"
4360 " header offset, but no program headers\n"));
4361 else if (do_segments)
4362 printf (_("\nThere are no program headers in this file.\n"));
4366 if (do_segments && !do_header)
4368 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
4369 printf (_("Entry point "));
4370 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
4371 printf (_("\nThere are %d program headers, starting at offset "),
4372 elf_header.e_phnum);
4373 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
4377 if (! get_program_headers (file))
4382 if (elf_header.e_phnum > 1)
4383 printf (_("\nProgram Headers:\n"));
4385 printf (_("\nProgram Headers:\n"));
4389 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
4392 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
4396 (_(" Type Offset VirtAddr PhysAddr\n"));
4398 (_(" FileSiz MemSiz Flags Align\n"));
4405 for (i = 0, segment = program_headers;
4406 i < elf_header.e_phnum;
4411 printf (" %-14.14s ", get_segment_type (segment->p_type));
4415 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
4416 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
4417 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
4418 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
4419 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
4421 (segment->p_flags & PF_R ? 'R' : ' '),
4422 (segment->p_flags & PF_W ? 'W' : ' '),
4423 (segment->p_flags & PF_X ? 'E' : ' '));
4424 printf ("%#lx", (unsigned long) segment->p_align);
4428 if ((unsigned long) segment->p_offset == segment->p_offset)
4429 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
4432 print_vma (segment->p_offset, FULL_HEX);
4436 print_vma (segment->p_vaddr, FULL_HEX);
4438 print_vma (segment->p_paddr, FULL_HEX);
4441 if ((unsigned long) segment->p_filesz == segment->p_filesz)
4442 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
4445 print_vma (segment->p_filesz, FULL_HEX);
4449 if ((unsigned long) segment->p_memsz == segment->p_memsz)
4450 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
4453 print_vma (segment->p_memsz, FULL_HEX);
4457 (segment->p_flags & PF_R ? 'R' : ' '),
4458 (segment->p_flags & PF_W ? 'W' : ' '),
4459 (segment->p_flags & PF_X ? 'E' : ' '));
4461 if ((unsigned long) segment->p_align == segment->p_align)
4462 printf ("%#lx", (unsigned long) segment->p_align);
4465 print_vma (segment->p_align, PREFIX_HEX);
4470 print_vma (segment->p_offset, FULL_HEX);
4472 print_vma (segment->p_vaddr, FULL_HEX);
4474 print_vma (segment->p_paddr, FULL_HEX);
4476 print_vma (segment->p_filesz, FULL_HEX);
4478 print_vma (segment->p_memsz, FULL_HEX);
4480 (segment->p_flags & PF_R ? 'R' : ' '),
4481 (segment->p_flags & PF_W ? 'W' : ' '),
4482 (segment->p_flags & PF_X ? 'E' : ' '));
4483 print_vma (segment->p_align, HEX);
4488 putc ('\n', stdout);
4490 switch (segment->p_type)
4494 error (_("more than one dynamic segment\n"));
4496 /* By default, assume that the .dynamic section is the first
4497 section in the DYNAMIC segment. */
4498 dynamic_addr = segment->p_offset;
4499 dynamic_size = segment->p_filesz;
4500 /* PR binutils/17512: Avoid corrupt dynamic section info in the segment. */
4501 if (dynamic_addr + dynamic_size >= current_file_size)
4503 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
4504 dynamic_addr = dynamic_size = 0;
4507 /* Try to locate the .dynamic section. If there is
4508 a section header table, we can easily locate it. */
4509 if (section_headers != NULL)
4511 Elf_Internal_Shdr * sec;
4513 sec = find_section (".dynamic");
4514 if (sec == NULL || sec->sh_size == 0)
4516 /* A corresponding .dynamic section is expected, but on
4517 IA-64/OpenVMS it is OK for it to be missing. */
4518 if (!is_ia64_vms ())
4519 error (_("no .dynamic section in the dynamic segment\n"));
4523 if (sec->sh_type == SHT_NOBITS)
4529 dynamic_addr = sec->sh_offset;
4530 dynamic_size = sec->sh_size;
4532 if (dynamic_addr < segment->p_offset
4533 || dynamic_addr > segment->p_offset + segment->p_filesz)
4534 warn (_("the .dynamic section is not contained"
4535 " within the dynamic segment\n"));
4536 else if (dynamic_addr > segment->p_offset)
4537 warn (_("the .dynamic section is not the first section"
4538 " in the dynamic segment.\n"));
4543 if (fseek (file, archive_file_offset + (long) segment->p_offset,
4545 error (_("Unable to find program interpreter name\n"));
4549 int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
4551 if (ret >= (int) sizeof (fmt) || ret < 0)
4552 error (_("Internal error: failed to create format string to display program interpreter\n"));
4554 program_interpreter[0] = 0;
4555 if (fscanf (file, fmt, program_interpreter) <= 0)
4556 error (_("Unable to read program interpreter name\n"));
4559 printf (_(" [Requesting program interpreter: %s]\n"),
4560 program_interpreter);
4566 if (do_segments && section_headers != NULL && string_table != NULL)
4568 printf (_("\n Section to Segment mapping:\n"));
4569 printf (_(" Segment Sections...\n"));
4571 for (i = 0; i < elf_header.e_phnum; i++)
4574 Elf_Internal_Shdr * section;
4576 segment = program_headers + i;
4577 section = section_headers + 1;
4579 printf (" %2.2d ", i);
4581 for (j = 1; j < elf_header.e_shnum; j++, section++)
4583 if (!ELF_TBSS_SPECIAL (section, segment)
4584 && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
4585 printf ("%s ", printable_section_name (section));
4596 /* Find the file offset corresponding to VMA by using the program headers. */
4599 offset_from_vma (FILE * file, bfd_vma vma, bfd_size_type size)
4601 Elf_Internal_Phdr * seg;
4603 if (! get_program_headers (file))
4605 warn (_("Cannot interpret virtual addresses without program headers.\n"));
4609 for (seg = program_headers;
4610 seg < program_headers + elf_header.e_phnum;
4613 if (seg->p_type != PT_LOAD)
4616 if (vma >= (seg->p_vaddr & -seg->p_align)
4617 && vma + size <= seg->p_vaddr + seg->p_filesz)
4618 return vma - seg->p_vaddr + seg->p_offset;
4621 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
4622 (unsigned long) vma);
4627 /* Allocate memory and load the sections headers into the global pointer
4628 SECTION_HEADERS. If PROBE is true, this is just a probe and we do not
4629 generate any error messages if the load fails. */
4632 get_32bit_section_headers (FILE * file, bfd_boolean probe)
4634 Elf32_External_Shdr * shdrs;
4635 Elf_Internal_Shdr * internal;
4637 unsigned int size = elf_header.e_shentsize;
4638 unsigned int num = probe ? 1 : elf_header.e_shnum;
4640 /* PR binutils/17531: Cope with unexpected section header sizes. */
4641 if (size == 0 || num == 0)
4643 if (size < sizeof * shdrs)
4646 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
4649 if (!probe && size > sizeof * shdrs)
4650 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
4652 shdrs = (Elf32_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
4654 probe ? NULL : _("section headers"));
4658 if (section_headers != NULL)
4659 free (section_headers);
4660 section_headers = (Elf_Internal_Shdr *) cmalloc (num,
4661 sizeof (Elf_Internal_Shdr));
4662 if (section_headers == NULL)
4665 error (_("Out of memory reading %u section headers\n"), num);
4669 for (i = 0, internal = section_headers;
4673 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
4674 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
4675 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
4676 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
4677 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
4678 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
4679 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
4680 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
4681 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
4682 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
4690 get_64bit_section_headers (FILE * file, bfd_boolean probe)
4692 Elf64_External_Shdr * shdrs;
4693 Elf_Internal_Shdr * internal;
4695 unsigned int size = elf_header.e_shentsize;
4696 unsigned int num = probe ? 1 : elf_header.e_shnum;
4698 /* PR binutils/17531: Cope with unexpected section header sizes. */
4699 if (size == 0 || num == 0)
4701 if (size < sizeof * shdrs)
4704 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
4707 if (! probe && size > sizeof * shdrs)
4708 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
4710 shdrs = (Elf64_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
4712 probe ? NULL : _("section headers"));
4716 if (section_headers != NULL)
4717 free (section_headers);
4718 section_headers = (Elf_Internal_Shdr *) cmalloc (num,
4719 sizeof (Elf_Internal_Shdr));
4720 if (section_headers == NULL)
4723 error (_("Out of memory reading %u section headers\n"), num);
4727 for (i = 0, internal = section_headers;
4731 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
4732 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
4733 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
4734 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
4735 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
4736 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
4737 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
4738 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
4739 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
4740 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
4747 static Elf_Internal_Sym *
4748 get_32bit_elf_symbols (FILE * file,
4749 Elf_Internal_Shdr * section,
4750 unsigned long * num_syms_return)
4752 unsigned long number = 0;
4753 Elf32_External_Sym * esyms = NULL;
4754 Elf_External_Sym_Shndx * shndx = NULL;
4755 Elf_Internal_Sym * isyms = NULL;
4756 Elf_Internal_Sym * psym;
4759 if (section->sh_size == 0)
4761 if (num_syms_return != NULL)
4762 * num_syms_return = 0;
4766 /* Run some sanity checks first. */
4767 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
4769 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
4770 printable_section_name (section), (unsigned long) section->sh_entsize);
4774 if (section->sh_size > current_file_size)
4776 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
4777 printable_section_name (section), (unsigned long) section->sh_size);
4781 number = section->sh_size / section->sh_entsize;
4783 if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
4785 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
4786 (unsigned long) section->sh_size,
4787 printable_section_name (section),
4788 (unsigned long) section->sh_entsize);
4792 esyms = (Elf32_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
4793 section->sh_size, _("symbols"));
4798 if (symtab_shndx_hdr != NULL
4799 && (symtab_shndx_hdr->sh_link
4800 == (unsigned long) (section - section_headers)))
4802 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
4803 symtab_shndx_hdr->sh_offset,
4804 1, symtab_shndx_hdr->sh_size,
4805 _("symbol table section indicies"));
4808 /* PR17531: file: heap-buffer-overflow */
4809 else if (symtab_shndx_hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
4811 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
4812 printable_section_name (symtab_shndx_hdr),
4813 (unsigned long) symtab_shndx_hdr->sh_size,
4814 (unsigned long) section->sh_size);
4819 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
4823 error (_("Out of memory reading %lu symbols\n"),
4824 (unsigned long) number);
4828 for (j = 0, psym = isyms; j < number; j++, psym++)
4830 psym->st_name = BYTE_GET (esyms[j].st_name);
4831 psym->st_value = BYTE_GET (esyms[j].st_value);
4832 psym->st_size = BYTE_GET (esyms[j].st_size);
4833 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
4834 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
4836 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4837 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
4838 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
4839 psym->st_info = BYTE_GET (esyms[j].st_info);
4840 psym->st_other = BYTE_GET (esyms[j].st_other);
4849 if (num_syms_return != NULL)
4850 * num_syms_return = isyms == NULL ? 0 : number;
4855 static Elf_Internal_Sym *
4856 get_64bit_elf_symbols (FILE * file,
4857 Elf_Internal_Shdr * section,
4858 unsigned long * num_syms_return)
4860 unsigned long number = 0;
4861 Elf64_External_Sym * esyms = NULL;
4862 Elf_External_Sym_Shndx * shndx = NULL;
4863 Elf_Internal_Sym * isyms = NULL;
4864 Elf_Internal_Sym * psym;
4867 if (section->sh_size == 0)
4869 if (num_syms_return != NULL)
4870 * num_syms_return = 0;
4874 /* Run some sanity checks first. */
4875 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
4877 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
4878 printable_section_name (section),
4879 (unsigned long) section->sh_entsize);
4883 if (section->sh_size > current_file_size)
4885 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
4886 printable_section_name (section),
4887 (unsigned long) section->sh_size);
4891 number = section->sh_size / section->sh_entsize;
4893 if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
4895 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
4896 (unsigned long) section->sh_size,
4897 printable_section_name (section),
4898 (unsigned long) section->sh_entsize);
4902 esyms = (Elf64_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
4903 section->sh_size, _("symbols"));
4907 if (symtab_shndx_hdr != NULL
4908 && (symtab_shndx_hdr->sh_link
4909 == (unsigned long) (section - section_headers)))
4911 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
4912 symtab_shndx_hdr->sh_offset,
4913 1, symtab_shndx_hdr->sh_size,
4914 _("symbol table section indicies"));
4917 else if (symtab_shndx_hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
4919 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
4920 printable_section_name (symtab_shndx_hdr),
4921 (unsigned long) symtab_shndx_hdr->sh_size,
4922 (unsigned long) section->sh_size);
4927 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
4931 error (_("Out of memory reading %lu symbols\n"),
4932 (unsigned long) number);
4936 for (j = 0, psym = isyms; j < number; j++, psym++)
4938 psym->st_name = BYTE_GET (esyms[j].st_name);
4939 psym->st_info = BYTE_GET (esyms[j].st_info);
4940 psym->st_other = BYTE_GET (esyms[j].st_other);
4941 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
4943 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
4945 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
4946 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
4947 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
4949 psym->st_value = BYTE_GET (esyms[j].st_value);
4950 psym->st_size = BYTE_GET (esyms[j].st_size);
4959 if (num_syms_return != NULL)
4960 * num_syms_return = isyms == NULL ? 0 : number;
4966 get_elf_section_flags (bfd_vma sh_flags)
4968 static char buff[1024];
4970 int field_size = is_32bit_elf ? 8 : 16;
4972 int size = sizeof (buff) - (field_size + 4 + 1);
4973 bfd_vma os_flags = 0;
4974 bfd_vma proc_flags = 0;
4975 bfd_vma unknown_flags = 0;
4983 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
4984 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
4985 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
4986 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
4987 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
4988 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
4989 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
4990 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
4991 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
4992 /* 9 */ { STRING_COMMA_LEN ("TLS") },
4993 /* IA-64 specific. */
4994 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
4995 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
4996 /* IA-64 OpenVMS specific. */
4997 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
4998 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
4999 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
5000 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
5001 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
5002 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
5004 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
5005 /* SPARC specific. */
5006 /* 19 */ { STRING_COMMA_LEN ("ORDERED") }
5009 if (do_section_details)
5011 sprintf (buff, "[%*.*lx]: ",
5012 field_size, field_size, (unsigned long) sh_flags);
5013 p += field_size + 4;
5020 flag = sh_flags & - sh_flags;
5023 if (do_section_details)
5027 case SHF_WRITE: sindex = 0; break;
5028 case SHF_ALLOC: sindex = 1; break;
5029 case SHF_EXECINSTR: sindex = 2; break;
5030 case SHF_MERGE: sindex = 3; break;
5031 case SHF_STRINGS: sindex = 4; break;
5032 case SHF_INFO_LINK: sindex = 5; break;
5033 case SHF_LINK_ORDER: sindex = 6; break;
5034 case SHF_OS_NONCONFORMING: sindex = 7; break;
5035 case SHF_GROUP: sindex = 8; break;
5036 case SHF_TLS: sindex = 9; break;
5037 case SHF_EXCLUDE: sindex = 18; break;
5041 switch (elf_header.e_machine)
5044 if (flag == SHF_IA_64_SHORT)
5046 else if (flag == SHF_IA_64_NORECOV)
5049 else if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
5052 case SHF_IA_64_VMS_GLOBAL: sindex = 12; break;
5053 case SHF_IA_64_VMS_OVERLAID: sindex = 13; break;
5054 case SHF_IA_64_VMS_SHARED: sindex = 14; break;
5055 case SHF_IA_64_VMS_VECTOR: sindex = 15; break;
5056 case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
5057 case SHF_IA_64_VMS_PROTECTED: sindex = 17; break;
5068 case EM_OLD_SPARCV9:
5069 case EM_SPARC32PLUS:
5072 if (flag == SHF_ORDERED)
5082 if (p != buff + field_size + 4)
5084 if (size < (10 + 2))
5086 warn (_("Internal error: not enough buffer room for section flag info"));
5087 return _("<unknown>");
5094 size -= flags [sindex].len;
5095 p = stpcpy (p, flags [sindex].str);
5097 else if (flag & SHF_MASKOS)
5099 else if (flag & SHF_MASKPROC)
5102 unknown_flags |= flag;
5108 case SHF_WRITE: *p = 'W'; break;
5109 case SHF_ALLOC: *p = 'A'; break;
5110 case SHF_EXECINSTR: *p = 'X'; break;
5111 case SHF_MERGE: *p = 'M'; break;
5112 case SHF_STRINGS: *p = 'S'; break;
5113 case SHF_INFO_LINK: *p = 'I'; break;
5114 case SHF_LINK_ORDER: *p = 'L'; break;
5115 case SHF_OS_NONCONFORMING: *p = 'O'; break;
5116 case SHF_GROUP: *p = 'G'; break;
5117 case SHF_TLS: *p = 'T'; break;
5118 case SHF_EXCLUDE: *p = 'E'; break;
5121 if ((elf_header.e_machine == EM_X86_64
5122 || elf_header.e_machine == EM_L1OM
5123 || elf_header.e_machine == EM_K1OM)
5124 && flag == SHF_X86_64_LARGE)
5126 else if (flag & SHF_MASKOS)
5129 sh_flags &= ~ SHF_MASKOS;
5131 else if (flag & SHF_MASKPROC)
5134 sh_flags &= ~ SHF_MASKPROC;
5144 if (do_section_details)
5148 size -= 5 + field_size;
5149 if (p != buff + field_size + 4)
5153 warn (_("Internal error: not enough buffer room for section flag info"));
5154 return _("<unknown>");
5160 sprintf (p, "OS (%*.*lx)", field_size, field_size,
5161 (unsigned long) os_flags);
5162 p += 5 + field_size;
5166 size -= 7 + field_size;
5167 if (p != buff + field_size + 4)
5171 warn (_("Internal error: not enough buffer room for section flag info"));
5172 return _("<unknown>");
5178 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
5179 (unsigned long) proc_flags);
5180 p += 7 + field_size;
5184 size -= 10 + field_size;
5185 if (p != buff + field_size + 4)
5189 warn (_("Internal error: not enough buffer room for section flag info"));
5190 return _("<unknown>");
5196 sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
5197 (unsigned long) unknown_flags);
5198 p += 10 + field_size;
5207 process_section_headers (FILE * file)
5209 Elf_Internal_Shdr * section;
5212 section_headers = NULL;
5214 if (elf_header.e_shnum == 0)
5216 /* PR binutils/12467. */
5217 if (elf_header.e_shoff != 0)
5218 warn (_("possibly corrupt ELF file header - it has a non-zero"
5219 " section header offset, but no section headers\n"));
5220 else if (do_sections)
5221 printf (_("\nThere are no sections in this file.\n"));
5226 if (do_sections && !do_header)
5227 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
5228 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
5232 if (! get_32bit_section_headers (file, FALSE))
5235 else if (! get_64bit_section_headers (file, FALSE))
5238 /* Read in the string table, so that we have names to display. */
5239 if (elf_header.e_shstrndx != SHN_UNDEF
5240 && elf_header.e_shstrndx < elf_header.e_shnum)
5242 section = section_headers + elf_header.e_shstrndx;
5244 if (section->sh_size != 0)
5246 string_table = (char *) get_data (NULL, file, section->sh_offset,
5247 1, section->sh_size,
5250 string_table_length = string_table != NULL ? section->sh_size : 0;
5254 /* Scan the sections for the dynamic symbol table
5255 and dynamic string table and debug sections. */
5256 dynamic_symbols = NULL;
5257 dynamic_strings = NULL;
5258 dynamic_syminfo = NULL;
5259 symtab_shndx_hdr = NULL;
5261 eh_addr_size = is_32bit_elf ? 4 : 8;
5262 switch (elf_header.e_machine)
5265 case EM_MIPS_RS3_LE:
5266 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
5267 FDE addresses. However, the ABI also has a semi-official ILP32
5268 variant for which the normal FDE address size rules apply.
5270 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
5271 section, where XX is the size of longs in bits. Unfortunately,
5272 earlier compilers provided no way of distinguishing ILP32 objects
5273 from LP64 objects, so if there's any doubt, we should assume that
5274 the official LP64 form is being used. */
5275 if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
5276 && find_section (".gcc_compiled_long32") == NULL)
5282 switch (elf_header.e_flags & EF_H8_MACH)
5284 case E_H8_MACH_H8300:
5285 case E_H8_MACH_H8300HN:
5286 case E_H8_MACH_H8300SN:
5287 case E_H8_MACH_H8300SXN:
5290 case E_H8_MACH_H8300H:
5291 case E_H8_MACH_H8300S:
5292 case E_H8_MACH_H8300SX:
5300 switch (elf_header.e_flags & EF_M32C_CPU_MASK)
5302 case EF_M32C_CPU_M16C:
5309 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
5312 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
5313 if (section->sh_entsize != expected_entsize) \
5316 sprintf_vma (buf, section->sh_entsize); \
5317 /* Note: coded this way so that there is a single string for \
5319 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
5320 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
5321 (unsigned) expected_entsize); \
5322 section->sh_entsize = expected_entsize; \
5327 #define CHECK_ENTSIZE(section, i, type) \
5328 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
5329 sizeof (Elf64_External_##type))
5331 for (i = 0, section = section_headers;
5332 i < elf_header.e_shnum;
5335 char * name = SECTION_NAME (section);
5337 if (section->sh_type == SHT_DYNSYM)
5339 if (dynamic_symbols != NULL)
5341 error (_("File contains multiple dynamic symbol tables\n"));
5345 CHECK_ENTSIZE (section, i, Sym);
5346 dynamic_symbols = GET_ELF_SYMBOLS (file, section, & num_dynamic_syms);
5348 else if (section->sh_type == SHT_STRTAB
5349 && streq (name, ".dynstr"))
5351 if (dynamic_strings != NULL)
5353 error (_("File contains multiple dynamic string tables\n"));
5357 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
5358 1, section->sh_size,
5359 _("dynamic strings"));
5360 dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
5362 else if (section->sh_type == SHT_SYMTAB_SHNDX)
5364 if (symtab_shndx_hdr != NULL)
5366 error (_("File contains multiple symtab shndx tables\n"));
5369 symtab_shndx_hdr = section;
5371 else if (section->sh_type == SHT_SYMTAB)
5372 CHECK_ENTSIZE (section, i, Sym);
5373 else if (section->sh_type == SHT_GROUP)
5374 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
5375 else if (section->sh_type == SHT_REL)
5376 CHECK_ENTSIZE (section, i, Rel);
5377 else if (section->sh_type == SHT_RELA)
5378 CHECK_ENTSIZE (section, i, Rela);
5379 else if ((do_debugging || do_debug_info || do_debug_abbrevs
5380 || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
5381 || do_debug_aranges || do_debug_frames || do_debug_macinfo
5382 || do_debug_str || do_debug_loc || do_debug_ranges
5383 || do_debug_addr || do_debug_cu_index)
5384 && (const_strneq (name, ".debug_")
5385 || const_strneq (name, ".zdebug_")))
5388 name += sizeof (".zdebug_") - 1;
5390 name += sizeof (".debug_") - 1;
5393 || (do_debug_info && const_strneq (name, "info"))
5394 || (do_debug_info && const_strneq (name, "types"))
5395 || (do_debug_abbrevs && const_strneq (name, "abbrev"))
5396 || (do_debug_lines && strcmp (name, "line") == 0)
5397 || (do_debug_lines && const_strneq (name, "line."))
5398 || (do_debug_pubnames && const_strneq (name, "pubnames"))
5399 || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
5400 || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
5401 || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
5402 || (do_debug_aranges && const_strneq (name, "aranges"))
5403 || (do_debug_ranges && const_strneq (name, "ranges"))
5404 || (do_debug_frames && const_strneq (name, "frame"))
5405 || (do_debug_macinfo && const_strneq (name, "macinfo"))
5406 || (do_debug_macinfo && const_strneq (name, "macro"))
5407 || (do_debug_str && const_strneq (name, "str"))
5408 || (do_debug_loc && const_strneq (name, "loc"))
5409 || (do_debug_addr && const_strneq (name, "addr"))
5410 || (do_debug_cu_index && const_strneq (name, "cu_index"))
5411 || (do_debug_cu_index && const_strneq (name, "tu_index"))
5413 request_dump_bynumber (i, DEBUG_DUMP);
5415 /* Linkonce section to be combined with .debug_info at link time. */
5416 else if ((do_debugging || do_debug_info)
5417 && const_strneq (name, ".gnu.linkonce.wi."))
5418 request_dump_bynumber (i, DEBUG_DUMP);
5419 else if (do_debug_frames && streq (name, ".eh_frame"))
5420 request_dump_bynumber (i, DEBUG_DUMP);
5421 else if (do_gdb_index && streq (name, ".gdb_index"))
5422 request_dump_bynumber (i, DEBUG_DUMP);
5423 /* Trace sections for Itanium VMS. */
5424 else if ((do_debugging || do_trace_info || do_trace_abbrevs
5425 || do_trace_aranges)
5426 && const_strneq (name, ".trace_"))
5428 name += sizeof (".trace_") - 1;
5431 || (do_trace_info && streq (name, "info"))
5432 || (do_trace_abbrevs && streq (name, "abbrev"))
5433 || (do_trace_aranges && streq (name, "aranges"))
5435 request_dump_bynumber (i, DEBUG_DUMP);
5442 if (elf_header.e_shnum > 1)
5443 printf (_("\nSection Headers:\n"));
5445 printf (_("\nSection Header:\n"));
5449 if (do_section_details)
5451 printf (_(" [Nr] Name\n"));
5452 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
5456 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
5460 if (do_section_details)
5462 printf (_(" [Nr] Name\n"));
5463 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
5467 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
5471 if (do_section_details)
5473 printf (_(" [Nr] Name\n"));
5474 printf (_(" Type Address Offset Link\n"));
5475 printf (_(" Size EntSize Info Align\n"));
5479 printf (_(" [Nr] Name Type Address Offset\n"));
5480 printf (_(" Size EntSize Flags Link Info Align\n"));
5484 if (do_section_details)
5485 printf (_(" Flags\n"));
5487 for (i = 0, section = section_headers;
5488 i < elf_header.e_shnum;
5491 printf (" [%2u] ", i);
5492 if (do_section_details)
5493 printf ("%s\n ", printable_section_name (section));
5495 print_symbol (-17, SECTION_NAME (section));
5497 printf (do_wide ? " %-15s " : " %-15.15s ",
5498 get_section_type_name (section->sh_type));
5502 const char * link_too_big = NULL;
5504 print_vma (section->sh_addr, LONG_HEX);
5506 printf ( " %6.6lx %6.6lx %2.2lx",
5507 (unsigned long) section->sh_offset,
5508 (unsigned long) section->sh_size,
5509 (unsigned long) section->sh_entsize);
5511 if (do_section_details)
5512 fputs (" ", stdout);
5514 printf (" %3s ", get_elf_section_flags (section->sh_flags));
5516 if (section->sh_link >= elf_header.e_shnum)
5519 /* The sh_link value is out of range. Normally this indicates
5520 an error but it can have special values in Solaris binaries. */
5521 switch (elf_header.e_machine)
5528 case EM_OLD_SPARCV9:
5529 case EM_SPARC32PLUS:
5532 if (section->sh_link == (SHN_BEFORE & 0xffff))
5533 link_too_big = "BEFORE";
5534 else if (section->sh_link == (SHN_AFTER & 0xffff))
5535 link_too_big = "AFTER";
5542 if (do_section_details)
5544 if (link_too_big != NULL && * link_too_big)
5545 printf ("<%s> ", link_too_big);
5547 printf ("%2u ", section->sh_link);
5548 printf ("%3u %2lu\n", section->sh_info,
5549 (unsigned long) section->sh_addralign);
5552 printf ("%2u %3u %2lu\n",
5555 (unsigned long) section->sh_addralign);
5557 if (link_too_big && ! * link_too_big)
5558 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
5559 i, section->sh_link);
5563 print_vma (section->sh_addr, LONG_HEX);
5565 if ((long) section->sh_offset == section->sh_offset)
5566 printf (" %6.6lx", (unsigned long) section->sh_offset);
5570 print_vma (section->sh_offset, LONG_HEX);
5573 if ((unsigned long) section->sh_size == section->sh_size)
5574 printf (" %6.6lx", (unsigned long) section->sh_size);
5578 print_vma (section->sh_size, LONG_HEX);
5581 if ((unsigned long) section->sh_entsize == section->sh_entsize)
5582 printf (" %2.2lx", (unsigned long) section->sh_entsize);
5586 print_vma (section->sh_entsize, LONG_HEX);
5589 if (do_section_details)
5590 fputs (" ", stdout);
5592 printf (" %3s ", get_elf_section_flags (section->sh_flags));
5594 printf ("%2u %3u ", section->sh_link, section->sh_info);
5596 if ((unsigned long) section->sh_addralign == section->sh_addralign)
5597 printf ("%2lu\n", (unsigned long) section->sh_addralign);
5600 print_vma (section->sh_addralign, DEC);
5604 else if (do_section_details)
5606 printf (" %-15.15s ",
5607 get_section_type_name (section->sh_type));
5608 print_vma (section->sh_addr, LONG_HEX);
5609 if ((long) section->sh_offset == section->sh_offset)
5610 printf (" %16.16lx", (unsigned long) section->sh_offset);
5614 print_vma (section->sh_offset, LONG_HEX);
5616 printf (" %u\n ", section->sh_link);
5617 print_vma (section->sh_size, LONG_HEX);
5619 print_vma (section->sh_entsize, LONG_HEX);
5621 printf (" %-16u %lu\n",
5623 (unsigned long) section->sh_addralign);
5628 print_vma (section->sh_addr, LONG_HEX);
5629 if ((long) section->sh_offset == section->sh_offset)
5630 printf (" %8.8lx", (unsigned long) section->sh_offset);
5634 print_vma (section->sh_offset, LONG_HEX);
5637 print_vma (section->sh_size, LONG_HEX);
5639 print_vma (section->sh_entsize, LONG_HEX);
5641 printf (" %3s ", get_elf_section_flags (section->sh_flags));
5643 printf (" %2u %3u %lu\n",
5646 (unsigned long) section->sh_addralign);
5649 if (do_section_details)
5650 printf (" %s\n", get_elf_section_flags (section->sh_flags));
5653 if (!do_section_details)
5655 if (elf_header.e_machine == EM_X86_64
5656 || elf_header.e_machine == EM_L1OM
5657 || elf_header.e_machine == EM_K1OM)
5658 printf (_("Key to Flags:\n\
5659 W (write), A (alloc), X (execute), M (merge), S (strings), l (large)\n\
5660 I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n\
5661 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
5663 printf (_("Key to Flags:\n\
5664 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
5665 I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n\
5666 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
5673 get_group_flags (unsigned int flags)
5675 static char buff[32];
5685 snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x] "), flags);
5692 process_section_groups (FILE * file)
5694 Elf_Internal_Shdr * section;
5696 struct group * group;
5697 Elf_Internal_Shdr * symtab_sec;
5698 Elf_Internal_Shdr * strtab_sec;
5699 Elf_Internal_Sym * symtab;
5700 unsigned long num_syms;
5704 /* Don't process section groups unless needed. */
5705 if (!do_unwind && !do_section_groups)
5708 if (elf_header.e_shnum == 0)
5710 if (do_section_groups)
5711 printf (_("\nThere are no sections to group in this file.\n"));
5716 if (section_headers == NULL)
5718 error (_("Section headers are not available!\n"));
5719 /* PR 13622: This can happen with a corrupt ELF header. */
5723 section_headers_groups = (struct group **) calloc (elf_header.e_shnum,
5724 sizeof (struct group *));
5726 if (section_headers_groups == NULL)
5728 error (_("Out of memory reading %u section group headers\n"),
5729 elf_header.e_shnum);
5733 /* Scan the sections for the group section. */
5735 for (i = 0, section = section_headers;
5736 i < elf_header.e_shnum;
5738 if (section->sh_type == SHT_GROUP)
5741 if (group_count == 0)
5743 if (do_section_groups)
5744 printf (_("\nThere are no section groups in this file.\n"));
5749 section_groups = (struct group *) calloc (group_count, sizeof (struct group));
5751 if (section_groups == NULL)
5753 error (_("Out of memory reading %lu groups\n"),
5754 (unsigned long) group_count);
5764 for (i = 0, section = section_headers, group = section_groups;
5765 i < elf_header.e_shnum;
5768 if (section->sh_type == SHT_GROUP)
5770 const char * name = printable_section_name (section);
5771 const char * group_name;
5772 unsigned char * start;
5773 unsigned char * indices;
5774 unsigned int entry, j, size;
5775 Elf_Internal_Shdr * sec;
5776 Elf_Internal_Sym * sym;
5778 /* Get the symbol table. */
5779 if (section->sh_link >= elf_header.e_shnum
5780 || ((sec = section_headers + section->sh_link)->sh_type
5783 error (_("Bad sh_link in group section `%s'\n"), name);
5787 if (symtab_sec != sec)
5792 symtab = GET_ELF_SYMBOLS (file, symtab_sec, & num_syms);
5797 error (_("Corrupt header in group section `%s'\n"), name);
5801 if (section->sh_info >= num_syms)
5803 error (_("Bad sh_info in group section `%s'\n"), name);
5807 sym = symtab + section->sh_info;
5809 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
5811 if (sym->st_shndx == 0
5812 || sym->st_shndx >= elf_header.e_shnum)
5814 error (_("Bad sh_info in group section `%s'\n"), name);
5818 group_name = SECTION_NAME (section_headers + sym->st_shndx);
5827 /* Get the string table. */
5828 if (symtab_sec->sh_link >= elf_header.e_shnum)
5837 != (sec = section_headers + symtab_sec->sh_link))
5843 strtab = (char *) get_data (NULL, file, strtab_sec->sh_offset,
5844 1, strtab_sec->sh_size,
5846 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
5848 group_name = sym->st_name < strtab_size
5849 ? strtab + sym->st_name : _("<corrupt>");
5852 /* PR 17531: file: loop. */
5853 if (section->sh_entsize > section->sh_size)
5855 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
5856 printable_section_name (section),
5857 (unsigned long) section->sh_entsize,
5858 (unsigned long) section->sh_size);
5862 start = (unsigned char *) get_data (NULL, file, section->sh_offset,
5863 1, section->sh_size,
5869 size = (section->sh_size / section->sh_entsize) - 1;
5870 entry = byte_get (indices, 4);
5873 if (do_section_groups)
5875 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
5876 get_group_flags (entry), i, name, group_name, size);
5878 printf (_(" [Index] Name\n"));
5881 group->group_index = i;
5883 for (j = 0; j < size; j++)
5885 struct group_list * g;
5887 entry = byte_get (indices, 4);
5890 if (entry >= elf_header.e_shnum)
5892 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
5893 entry, i, elf_header.e_shnum - 1);
5897 if (section_headers_groups [entry] != NULL)
5901 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
5903 section_headers_groups [entry]->group_index);
5908 /* Intel C/C++ compiler may put section 0 in a
5909 section group. We just warn it the first time
5910 and ignore it afterwards. */
5911 static int warned = 0;
5914 error (_("section 0 in group section [%5u]\n"),
5915 section_headers_groups [entry]->group_index);
5921 section_headers_groups [entry] = group;
5923 if (do_section_groups)
5925 sec = section_headers + entry;
5926 printf (" [%5u] %s\n", entry, printable_section_name (sec));
5929 g = (struct group_list *) xmalloc (sizeof (struct group_list));
5930 g->section_index = entry;
5931 g->next = group->root;
5949 /* Data used to display dynamic fixups. */
5951 struct ia64_vms_dynfixup
5953 bfd_vma needed_ident; /* Library ident number. */
5954 bfd_vma needed; /* Index in the dstrtab of the library name. */
5955 bfd_vma fixup_needed; /* Index of the library. */
5956 bfd_vma fixup_rela_cnt; /* Number of fixups. */
5957 bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */
5960 /* Data used to display dynamic relocations. */
5962 struct ia64_vms_dynimgrela
5964 bfd_vma img_rela_cnt; /* Number of relocations. */
5965 bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */
5968 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
5972 dump_ia64_vms_dynamic_fixups (FILE *file, struct ia64_vms_dynfixup *fixup,
5973 const char *strtab, unsigned int strtab_sz)
5975 Elf64_External_VMS_IMAGE_FIXUP *imfs;
5977 const char *lib_name;
5979 imfs = get_data (NULL, file, dynamic_addr + fixup->fixup_rela_off,
5980 1, fixup->fixup_rela_cnt * sizeof (*imfs),
5981 _("dynamic section image fixups"));
5985 if (fixup->needed < strtab_sz)
5986 lib_name = strtab + fixup->needed;
5989 warn ("corrupt library name index of 0x%lx found in dynamic entry",
5990 (unsigned long) fixup->needed);
5993 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
5994 (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
5996 (_("Seg Offset Type SymVec DataType\n"));
5998 for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
6003 printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
6004 printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
6005 type = BYTE_GET (imfs [i].type);
6006 rtype = elf_ia64_reloc_type (type);
6008 printf (" 0x%08x ", type);
6010 printf (" %-32s ", rtype);
6011 printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
6012 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
6018 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
6021 dump_ia64_vms_dynamic_relocs (FILE *file, struct ia64_vms_dynimgrela *imgrela)
6023 Elf64_External_VMS_IMAGE_RELA *imrs;
6026 imrs = get_data (NULL, file, dynamic_addr + imgrela->img_rela_off,
6027 1, imgrela->img_rela_cnt * sizeof (*imrs),
6028 _("dynamic section image relocations"));
6032 printf (_("\nImage relocs\n"));
6034 (_("Seg Offset Type Addend Seg Sym Off\n"));
6036 for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
6041 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
6042 printf ("%08" BFD_VMA_FMT "x ",
6043 (bfd_vma) BYTE_GET (imrs [i].rela_offset));
6044 type = BYTE_GET (imrs [i].type);
6045 rtype = elf_ia64_reloc_type (type);
6047 printf ("0x%08x ", type);
6049 printf ("%-31s ", rtype);
6050 print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
6051 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
6052 printf ("%08" BFD_VMA_FMT "x\n",
6053 (bfd_vma) BYTE_GET (imrs [i].sym_offset));
6059 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
6062 process_ia64_vms_dynamic_relocs (FILE *file)
6064 struct ia64_vms_dynfixup fixup;
6065 struct ia64_vms_dynimgrela imgrela;
6066 Elf_Internal_Dyn *entry;
6068 bfd_vma strtab_off = 0;
6069 bfd_vma strtab_sz = 0;
6070 char *strtab = NULL;
6072 memset (&fixup, 0, sizeof (fixup));
6073 memset (&imgrela, 0, sizeof (imgrela));
6075 /* Note: the order of the entries is specified by the OpenVMS specs. */
6076 for (entry = dynamic_section;
6077 entry < dynamic_section + dynamic_nent;
6080 switch (entry->d_tag)
6082 case DT_IA_64_VMS_STRTAB_OFFSET:
6083 strtab_off = entry->d_un.d_val;
6086 strtab_sz = entry->d_un.d_val;
6088 strtab = get_data (NULL, file, dynamic_addr + strtab_off,
6089 1, strtab_sz, _("dynamic string section"));
6092 case DT_IA_64_VMS_NEEDED_IDENT:
6093 fixup.needed_ident = entry->d_un.d_val;
6096 fixup.needed = entry->d_un.d_val;
6098 case DT_IA_64_VMS_FIXUP_NEEDED:
6099 fixup.fixup_needed = entry->d_un.d_val;
6101 case DT_IA_64_VMS_FIXUP_RELA_CNT:
6102 fixup.fixup_rela_cnt = entry->d_un.d_val;
6104 case DT_IA_64_VMS_FIXUP_RELA_OFF:
6105 fixup.fixup_rela_off = entry->d_un.d_val;
6107 dump_ia64_vms_dynamic_fixups (file, &fixup, strtab, strtab_sz);
6110 case DT_IA_64_VMS_IMG_RELA_CNT:
6111 imgrela.img_rela_cnt = entry->d_un.d_val;
6113 case DT_IA_64_VMS_IMG_RELA_OFF:
6114 imgrela.img_rela_off = entry->d_un.d_val;
6116 dump_ia64_vms_dynamic_relocs (file, &imgrela);
6136 } dynamic_relocations [] =
6138 { "REL", DT_REL, DT_RELSZ, FALSE },
6139 { "RELA", DT_RELA, DT_RELASZ, TRUE },
6140 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
6143 /* Process the reloc section. */
6146 process_relocs (FILE * file)
6148 unsigned long rel_size;
6149 unsigned long rel_offset;
6155 if (do_using_dynamic)
6159 int has_dynamic_reloc;
6162 has_dynamic_reloc = 0;
6164 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
6166 is_rela = dynamic_relocations [i].rela;
6167 name = dynamic_relocations [i].name;
6168 rel_size = dynamic_info [dynamic_relocations [i].size];
6169 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
6171 has_dynamic_reloc |= rel_size;
6173 if (is_rela == UNKNOWN)
6175 if (dynamic_relocations [i].reloc == DT_JMPREL)
6176 switch (dynamic_info[DT_PLTREL])
6190 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
6191 name, rel_offset, rel_size);
6193 dump_relocations (file,
6194 offset_from_vma (file, rel_offset, rel_size),
6196 dynamic_symbols, num_dynamic_syms,
6197 dynamic_strings, dynamic_strings_length,
6203 has_dynamic_reloc |= process_ia64_vms_dynamic_relocs (file);
6205 if (! has_dynamic_reloc)
6206 printf (_("\nThere are no dynamic relocations in this file.\n"));
6210 Elf_Internal_Shdr * section;
6214 for (i = 0, section = section_headers;
6215 i < elf_header.e_shnum;
6218 if ( section->sh_type != SHT_RELA
6219 && section->sh_type != SHT_REL)
6222 rel_offset = section->sh_offset;
6223 rel_size = section->sh_size;
6227 Elf_Internal_Shdr * strsec;
6230 printf (_("\nRelocation section "));
6232 if (string_table == NULL)
6233 printf ("%d", section->sh_name);
6235 printf ("'%s'", printable_section_name (section));
6237 printf (_(" at offset 0x%lx contains %lu entries:\n"),
6238 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
6240 is_rela = section->sh_type == SHT_RELA;
6242 if (section->sh_link != 0
6243 && section->sh_link < elf_header.e_shnum)
6245 Elf_Internal_Shdr * symsec;
6246 Elf_Internal_Sym * symtab;
6247 unsigned long nsyms;
6248 unsigned long strtablen = 0;
6249 char * strtab = NULL;
6251 symsec = section_headers + section->sh_link;
6252 if (symsec->sh_type != SHT_SYMTAB
6253 && symsec->sh_type != SHT_DYNSYM)
6256 symtab = GET_ELF_SYMBOLS (file, symsec, & nsyms);
6261 if (symsec->sh_link != 0
6262 && symsec->sh_link < elf_header.e_shnum)
6264 strsec = section_headers + symsec->sh_link;
6266 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
6269 strtablen = strtab == NULL ? 0 : strsec->sh_size;
6272 dump_relocations (file, rel_offset, rel_size,
6273 symtab, nsyms, strtab, strtablen,
6280 dump_relocations (file, rel_offset, rel_size,
6281 NULL, 0, NULL, 0, is_rela);
6288 printf (_("\nThere are no relocations in this file.\n"));
6294 /* Process the unwind section. */
6296 #include "unwind-ia64.h"
6298 /* An absolute address consists of a section and an offset. If the
6299 section is NULL, the offset itself is the address, otherwise, the
6300 address equals to LOAD_ADDRESS(section) + offset. */
6304 unsigned short section;
6308 #define ABSADDR(a) \
6310 ? section_headers [(a).section].sh_addr + (a).offset \
6313 struct ia64_unw_table_entry
6315 struct absaddr start;
6317 struct absaddr info;
6320 struct ia64_unw_aux_info
6323 struct ia64_unw_table_entry *table; /* Unwind table. */
6324 unsigned long table_len; /* Length of unwind table. */
6325 unsigned char * info; /* Unwind info. */
6326 unsigned long info_size; /* Size of unwind info. */
6327 bfd_vma info_addr; /* starting address of unwind info. */
6328 bfd_vma seg_base; /* Starting address of segment. */
6329 Elf_Internal_Sym * symtab; /* The symbol table. */
6330 unsigned long nsyms; /* Number of symbols. */
6331 char * strtab; /* The string table. */
6332 unsigned long strtab_size; /* Size of string table. */
6336 find_symbol_for_address (Elf_Internal_Sym * symtab,
6337 unsigned long nsyms,
6338 const char * strtab,
6339 unsigned long strtab_size,
6340 struct absaddr addr,
6341 const char ** symname,
6344 bfd_vma dist = 0x100000;
6345 Elf_Internal_Sym * sym;
6346 Elf_Internal_Sym * best = NULL;
6349 REMOVE_ARCH_BITS (addr.offset);
6351 for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
6353 bfd_vma value = sym->st_value;
6355 REMOVE_ARCH_BITS (value);
6357 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
6358 && sym->st_name != 0
6359 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
6360 && addr.offset >= value
6361 && addr.offset - value < dist)
6364 dist = addr.offset - value;
6372 *symname = (best->st_name >= strtab_size
6373 ? _("<corrupt>") : strtab + best->st_name);
6379 *offset = addr.offset;
6383 dump_ia64_unwind (struct ia64_unw_aux_info * aux)
6385 struct ia64_unw_table_entry * tp;
6388 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
6392 const unsigned char * dp;
6393 const unsigned char * head;
6394 const unsigned char * end;
6395 const char * procname;
6397 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
6398 aux->strtab_size, tp->start, &procname, &offset);
6400 fputs ("\n<", stdout);
6404 fputs (procname, stdout);
6407 printf ("+%lx", (unsigned long) offset);
6410 fputs (">: [", stdout);
6411 print_vma (tp->start.offset, PREFIX_HEX);
6412 fputc ('-', stdout);
6413 print_vma (tp->end.offset, PREFIX_HEX);
6414 printf ("], info at +0x%lx\n",
6415 (unsigned long) (tp->info.offset - aux->seg_base));
6417 /* PR 17531: file: 86232b32. */
6418 if (aux->info == NULL)
6421 /* PR 17531: file: 0997b4d1. */
6422 if ((ABSADDR (tp->info) - aux->info_addr) >= aux->info_size)
6424 warn (_("Invalid offset %lx in table entry %ld\n"),
6425 (long) tp->info.offset, (long) (tp - aux->table));
6429 head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
6430 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
6432 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
6433 (unsigned) UNW_VER (stamp),
6434 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
6435 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
6436 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
6437 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
6439 if (UNW_VER (stamp) != 1)
6441 printf (_("\tUnknown version.\n"));
6446 end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
6447 /* PR 17531: file: 16ceda89. */
6448 if (end > aux->info + aux->info_size)
6449 end = aux->info + aux->info_size;
6450 for (dp = head + 8; dp < end;)
6451 dp = unw_decode (dp, in_body, & in_body);
6456 slurp_ia64_unwind_table (FILE * file,
6457 struct ia64_unw_aux_info * aux,
6458 Elf_Internal_Shdr * sec)
6460 unsigned long size, nrelas, i;
6461 Elf_Internal_Phdr * seg;
6462 struct ia64_unw_table_entry * tep;
6463 Elf_Internal_Shdr * relsec;
6464 Elf_Internal_Rela * rela;
6465 Elf_Internal_Rela * rp;
6466 unsigned char * table;
6468 Elf_Internal_Sym * sym;
6469 const char * relname;
6473 /* First, find the starting address of the segment that includes
6476 if (elf_header.e_phnum)
6478 if (! get_program_headers (file))
6481 for (seg = program_headers;
6482 seg < program_headers + elf_header.e_phnum;
6485 if (seg->p_type != PT_LOAD)
6488 if (sec->sh_addr >= seg->p_vaddr
6489 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
6491 aux->seg_base = seg->p_vaddr;
6497 /* Second, build the unwind table from the contents of the unwind section: */
6498 size = sec->sh_size;
6499 table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
6504 aux->table_len = size / (3 * eh_addr_size);
6505 aux->table = (struct ia64_unw_table_entry *)
6506 xcmalloc (aux->table_len, sizeof (aux->table[0]));
6509 for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
6511 tep->start.section = SHN_UNDEF;
6512 tep->end.section = SHN_UNDEF;
6513 tep->info.section = SHN_UNDEF;
6514 tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
6515 tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
6516 tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
6517 tep->start.offset += aux->seg_base;
6518 tep->end.offset += aux->seg_base;
6519 tep->info.offset += aux->seg_base;
6523 /* Third, apply any relocations to the unwind table: */
6524 for (relsec = section_headers;
6525 relsec < section_headers + elf_header.e_shnum;
6528 if (relsec->sh_type != SHT_RELA
6529 || relsec->sh_info >= elf_header.e_shnum
6530 || section_headers + relsec->sh_info != sec)
6533 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
6542 for (rp = rela; rp < rela + nrelas; ++rp)
6544 relname = elf_ia64_reloc_type (get_reloc_type (rp->r_info));
6545 sym = aux->symtab + get_reloc_symindex (rp->r_info);
6547 /* PR 17531: file: 9fa67536. */
6548 if (relname == NULL)
6550 warn (_("Skipping unknown relocation type: %u\n"), get_reloc_type (rp->r_info));
6554 if (! const_strneq (relname, "R_IA64_SEGREL"))
6556 warn (_("Skipping unexpected relocation type: %s\n"), relname);
6560 i = rp->r_offset / (3 * eh_addr_size);
6562 /* PR 17531: file: 5bc8d9bf. */
6563 if (i >= aux->table_len)
6565 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
6569 switch (rp->r_offset / eh_addr_size % 3)
6572 aux->table[i].start.section = sym->st_shndx;
6573 aux->table[i].start.offset = rp->r_addend + sym->st_value;
6576 aux->table[i].end.section = sym->st_shndx;
6577 aux->table[i].end.offset = rp->r_addend + sym->st_value;
6580 aux->table[i].info.section = sym->st_shndx;
6581 aux->table[i].info.offset = rp->r_addend + sym->st_value;
6595 ia64_process_unwind (FILE * file)
6597 Elf_Internal_Shdr * sec;
6598 Elf_Internal_Shdr * unwsec = NULL;
6599 Elf_Internal_Shdr * strsec;
6600 unsigned long i, unwcount = 0, unwstart = 0;
6601 struct ia64_unw_aux_info aux;
6603 memset (& aux, 0, sizeof (aux));
6605 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
6607 if (sec->sh_type == SHT_SYMTAB
6608 && sec->sh_link < elf_header.e_shnum)
6610 aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
6612 strsec = section_headers + sec->sh_link;
6613 if (aux.strtab != NULL)
6615 error (_("Multiple auxillary string tables encountered\n"));
6618 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
6621 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
6623 else if (sec->sh_type == SHT_IA_64_UNWIND)
6628 printf (_("\nThere are no unwind sections in this file.\n"));
6630 while (unwcount-- > 0)
6635 for (i = unwstart, sec = section_headers + unwstart, unwsec = NULL;
6636 i < elf_header.e_shnum; ++i, ++sec)
6637 if (sec->sh_type == SHT_IA_64_UNWIND)
6642 /* We have already counted the number of SHT_IA64_UNWIND
6643 sections so the loop above should never fail. */
6644 assert (unwsec != NULL);
6647 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
6649 if ((unwsec->sh_flags & SHF_GROUP) != 0)
6651 /* We need to find which section group it is in. */
6652 struct group_list * g;
6654 if (section_headers_groups == NULL
6655 || section_headers_groups [i] == NULL)
6656 i = elf_header.e_shnum;
6659 g = section_headers_groups [i]->root;
6661 for (; g != NULL; g = g->next)
6663 sec = section_headers + g->section_index;
6665 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
6670 i = elf_header.e_shnum;
6673 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
6675 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
6676 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
6677 suffix = SECTION_NAME (unwsec) + len;
6678 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
6680 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
6681 && streq (SECTION_NAME (sec) + len2, suffix))
6686 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
6687 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
6688 len = sizeof (ELF_STRING_ia64_unwind) - 1;
6689 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
6691 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
6692 suffix = SECTION_NAME (unwsec) + len;
6693 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
6695 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
6696 && streq (SECTION_NAME (sec) + len2, suffix))
6700 if (i == elf_header.e_shnum)
6702 printf (_("\nCould not find unwind info section for "));
6704 if (string_table == NULL)
6705 printf ("%d", unwsec->sh_name);
6707 printf ("'%s'", printable_section_name (unwsec));
6711 aux.info_addr = sec->sh_addr;
6712 aux.info = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1,
6715 aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
6717 printf (_("\nUnwind section "));
6719 if (string_table == NULL)
6720 printf ("%d", unwsec->sh_name);
6722 printf ("'%s'", printable_section_name (unwsec));
6724 printf (_(" at offset 0x%lx contains %lu entries:\n"),
6725 (unsigned long) unwsec->sh_offset,
6726 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
6728 if (slurp_ia64_unwind_table (file, & aux, unwsec)
6729 && aux.table_len > 0)
6730 dump_ia64_unwind (& aux);
6733 free ((char *) aux.table);
6735 free ((char *) aux.info);
6744 free ((char *) aux.strtab);
6747 struct hppa_unw_table_entry
6749 struct absaddr start;
6751 unsigned int Cannot_unwind:1; /* 0 */
6752 unsigned int Millicode:1; /* 1 */
6753 unsigned int Millicode_save_sr0:1; /* 2 */
6754 unsigned int Region_description:2; /* 3..4 */
6755 unsigned int reserved1:1; /* 5 */
6756 unsigned int Entry_SR:1; /* 6 */
6757 unsigned int Entry_FR:4; /* number saved */ /* 7..10 */
6758 unsigned int Entry_GR:5; /* number saved */ /* 11..15 */
6759 unsigned int Args_stored:1; /* 16 */
6760 unsigned int Variable_Frame:1; /* 17 */
6761 unsigned int Separate_Package_Body:1; /* 18 */
6762 unsigned int Frame_Extension_Millicode:1; /* 19 */
6763 unsigned int Stack_Overflow_Check:1; /* 20 */
6764 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
6765 unsigned int Ada_Region:1; /* 22 */
6766 unsigned int cxx_info:1; /* 23 */
6767 unsigned int cxx_try_catch:1; /* 24 */
6768 unsigned int sched_entry_seq:1; /* 25 */
6769 unsigned int reserved2:1; /* 26 */
6770 unsigned int Save_SP:1; /* 27 */
6771 unsigned int Save_RP:1; /* 28 */
6772 unsigned int Save_MRP_in_frame:1; /* 29 */
6773 unsigned int extn_ptr_defined:1; /* 30 */
6774 unsigned int Cleanup_defined:1; /* 31 */
6776 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
6777 unsigned int HP_UX_interrupt_marker:1; /* 1 */
6778 unsigned int Large_frame:1; /* 2 */
6779 unsigned int Pseudo_SP_Set:1; /* 3 */
6780 unsigned int reserved4:1; /* 4 */
6781 unsigned int Total_frame_size:27; /* 5..31 */
6784 struct hppa_unw_aux_info
6786 struct hppa_unw_table_entry *table; /* Unwind table. */
6787 unsigned long table_len; /* Length of unwind table. */
6788 bfd_vma seg_base; /* Starting address of segment. */
6789 Elf_Internal_Sym * symtab; /* The symbol table. */
6790 unsigned long nsyms; /* Number of symbols. */
6791 char * strtab; /* The string table. */
6792 unsigned long strtab_size; /* Size of string table. */
6796 dump_hppa_unwind (struct hppa_unw_aux_info * aux)
6798 struct hppa_unw_table_entry * tp;
6800 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
6803 const char * procname;
6805 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
6806 aux->strtab_size, tp->start, &procname,
6809 fputs ("\n<", stdout);
6813 fputs (procname, stdout);
6816 printf ("+%lx", (unsigned long) offset);
6819 fputs (">: [", stdout);
6820 print_vma (tp->start.offset, PREFIX_HEX);
6821 fputc ('-', stdout);
6822 print_vma (tp->end.offset, PREFIX_HEX);
6825 #define PF(_m) if (tp->_m) printf (#_m " ");
6826 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
6829 PF(Millicode_save_sr0);
6830 /* PV(Region_description); */
6836 PF(Separate_Package_Body);
6837 PF(Frame_Extension_Millicode);
6838 PF(Stack_Overflow_Check);
6839 PF(Two_Instruction_SP_Increment);
6843 PF(sched_entry_seq);
6846 PF(Save_MRP_in_frame);
6847 PF(extn_ptr_defined);
6848 PF(Cleanup_defined);
6849 PF(MPE_XL_interrupt_marker);
6850 PF(HP_UX_interrupt_marker);
6853 PV(Total_frame_size);
6862 slurp_hppa_unwind_table (FILE * file,
6863 struct hppa_unw_aux_info * aux,
6864 Elf_Internal_Shdr * sec)
6866 unsigned long size, unw_ent_size, nentries, nrelas, i;
6867 Elf_Internal_Phdr * seg;
6868 struct hppa_unw_table_entry * tep;
6869 Elf_Internal_Shdr * relsec;
6870 Elf_Internal_Rela * rela;
6871 Elf_Internal_Rela * rp;
6872 unsigned char * table;
6874 Elf_Internal_Sym * sym;
6875 const char * relname;
6877 /* First, find the starting address of the segment that includes
6880 if (elf_header.e_phnum)
6882 if (! get_program_headers (file))
6885 for (seg = program_headers;
6886 seg < program_headers + elf_header.e_phnum;
6889 if (seg->p_type != PT_LOAD)
6892 if (sec->sh_addr >= seg->p_vaddr
6893 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
6895 aux->seg_base = seg->p_vaddr;
6901 /* Second, build the unwind table from the contents of the unwind
6903 size = sec->sh_size;
6904 table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
6910 nentries = size / unw_ent_size;
6911 size = unw_ent_size * nentries;
6913 tep = aux->table = (struct hppa_unw_table_entry *)
6914 xcmalloc (nentries, sizeof (aux->table[0]));
6916 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
6918 unsigned int tmp1, tmp2;
6920 tep->start.section = SHN_UNDEF;
6921 tep->end.section = SHN_UNDEF;
6923 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
6924 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
6925 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
6926 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
6928 tep->start.offset += aux->seg_base;
6929 tep->end.offset += aux->seg_base;
6931 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
6932 tep->Millicode = (tmp1 >> 30) & 0x1;
6933 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
6934 tep->Region_description = (tmp1 >> 27) & 0x3;
6935 tep->reserved1 = (tmp1 >> 26) & 0x1;
6936 tep->Entry_SR = (tmp1 >> 25) & 0x1;
6937 tep->Entry_FR = (tmp1 >> 21) & 0xf;
6938 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
6939 tep->Args_stored = (tmp1 >> 15) & 0x1;
6940 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
6941 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
6942 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
6943 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
6944 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
6945 tep->Ada_Region = (tmp1 >> 9) & 0x1;
6946 tep->cxx_info = (tmp1 >> 8) & 0x1;
6947 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
6948 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
6949 tep->reserved2 = (tmp1 >> 5) & 0x1;
6950 tep->Save_SP = (tmp1 >> 4) & 0x1;
6951 tep->Save_RP = (tmp1 >> 3) & 0x1;
6952 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
6953 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
6954 tep->Cleanup_defined = tmp1 & 0x1;
6956 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
6957 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
6958 tep->Large_frame = (tmp2 >> 29) & 0x1;
6959 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
6960 tep->reserved4 = (tmp2 >> 27) & 0x1;
6961 tep->Total_frame_size = tmp2 & 0x7ffffff;
6965 /* Third, apply any relocations to the unwind table. */
6966 for (relsec = section_headers;
6967 relsec < section_headers + elf_header.e_shnum;
6970 if (relsec->sh_type != SHT_RELA
6971 || relsec->sh_info >= elf_header.e_shnum
6972 || section_headers + relsec->sh_info != sec)
6975 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
6979 for (rp = rela; rp < rela + nrelas; ++rp)
6981 relname = elf_hppa_reloc_type (get_reloc_type (rp->r_info));
6982 sym = aux->symtab + get_reloc_symindex (rp->r_info);
6984 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
6985 if (! const_strneq (relname, "R_PARISC_SEGREL"))
6987 warn (_("Skipping unexpected relocation type %s\n"), relname);
6991 i = rp->r_offset / unw_ent_size;
6993 switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
6996 aux->table[i].start.section = sym->st_shndx;
6997 aux->table[i].start.offset = sym->st_value + rp->r_addend;
7000 aux->table[i].end.section = sym->st_shndx;
7001 aux->table[i].end.offset = sym->st_value + rp->r_addend;
7011 aux->table_len = nentries;
7017 hppa_process_unwind (FILE * file)
7019 struct hppa_unw_aux_info aux;
7020 Elf_Internal_Shdr * unwsec = NULL;
7021 Elf_Internal_Shdr * strsec;
7022 Elf_Internal_Shdr * sec;
7025 if (string_table == NULL)
7028 memset (& aux, 0, sizeof (aux));
7030 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
7032 if (sec->sh_type == SHT_SYMTAB
7033 && sec->sh_link < elf_header.e_shnum)
7035 aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
7037 strsec = section_headers + sec->sh_link;
7038 if (aux.strtab != NULL)
7040 error (_("Multiple auxillary string tables encountered\n"));
7043 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
7046 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
7048 else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
7053 printf (_("\nThere are no unwind sections in this file.\n"));
7055 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
7057 if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
7059 printf (_("\nUnwind section '%s' at offset 0x%lx contains %lu entries:\n"),
7060 printable_section_name (sec),
7061 (unsigned long) sec->sh_offset,
7062 (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
7064 slurp_hppa_unwind_table (file, &aux, sec);
7065 if (aux.table_len > 0)
7066 dump_hppa_unwind (&aux);
7069 free ((char *) aux.table);
7077 free ((char *) aux.strtab);
7082 unsigned char * data; /* The unwind data. */
7083 Elf_Internal_Shdr * sec; /* The cached unwind section header. */
7084 Elf_Internal_Rela * rela; /* The cached relocations for this section. */
7085 unsigned long nrelas; /* The number of relocations. */
7086 unsigned int rel_type; /* REL or RELA ? */
7087 Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */
7090 struct arm_unw_aux_info
7092 FILE * file; /* The file containing the unwind sections. */
7093 Elf_Internal_Sym * symtab; /* The file's symbol table. */
7094 unsigned long nsyms; /* Number of symbols. */
7095 char * strtab; /* The file's string table. */
7096 unsigned long strtab_size; /* Size of string table. */
7100 arm_print_vma_and_name (struct arm_unw_aux_info *aux,
7101 bfd_vma fn, struct absaddr addr)
7103 const char *procname;
7106 if (addr.section == SHN_UNDEF)
7109 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
7110 aux->strtab_size, addr, &procname,
7113 print_vma (fn, PREFIX_HEX);
7117 fputs (" <", stdout);
7118 fputs (procname, stdout);
7121 printf ("+0x%lx", (unsigned long) sym_offset);
7122 fputc ('>', stdout);
7129 arm_free_section (struct arm_section *arm_sec)
7131 if (arm_sec->data != NULL)
7132 free (arm_sec->data);
7134 if (arm_sec->rela != NULL)
7135 free (arm_sec->rela);
7138 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
7139 cached section and install SEC instead.
7140 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
7141 and return its valued in * WORDP, relocating if necessary.
7142 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
7143 relocation's offset in ADDR.
7144 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
7145 into the string table of the symbol associated with the reloc. If no
7146 reloc was applied store -1 there.
7147 5) Return TRUE upon success, FALSE otherwise. */
7150 get_unwind_section_word (struct arm_unw_aux_info * aux,
7151 struct arm_section * arm_sec,
7152 Elf_Internal_Shdr * sec,
7153 bfd_vma word_offset,
7154 unsigned int * wordp,
7155 struct absaddr * addr,
7158 Elf_Internal_Rela *rp;
7159 Elf_Internal_Sym *sym;
7160 const char * relname;
7162 bfd_boolean wrapped;
7164 if (sec == NULL || arm_sec == NULL)
7167 addr->section = SHN_UNDEF;
7170 if (sym_name != NULL)
7171 *sym_name = (bfd_vma) -1;
7173 /* If necessary, update the section cache. */
7174 if (sec != arm_sec->sec)
7176 Elf_Internal_Shdr *relsec;
7178 arm_free_section (arm_sec);
7181 arm_sec->data = get_data (NULL, aux->file, sec->sh_offset, 1,
7182 sec->sh_size, _("unwind data"));
7183 arm_sec->rela = NULL;
7184 arm_sec->nrelas = 0;
7186 for (relsec = section_headers;
7187 relsec < section_headers + elf_header.e_shnum;
7190 if (relsec->sh_info >= elf_header.e_shnum
7191 || section_headers + relsec->sh_info != sec
7192 /* PR 15745: Check the section type as well. */
7193 || (relsec->sh_type != SHT_REL
7194 && relsec->sh_type != SHT_RELA))
7197 arm_sec->rel_type = relsec->sh_type;
7198 if (relsec->sh_type == SHT_REL)
7200 if (!slurp_rel_relocs (aux->file, relsec->sh_offset,
7202 & arm_sec->rela, & arm_sec->nrelas))
7205 else /* relsec->sh_type == SHT_RELA */
7207 if (!slurp_rela_relocs (aux->file, relsec->sh_offset,
7209 & arm_sec->rela, & arm_sec->nrelas))
7215 arm_sec->next_rela = arm_sec->rela;
7218 /* If there is no unwind data we can do nothing. */
7219 if (arm_sec->data == NULL)
7222 /* If the offset is invalid then fail. */
7223 if (word_offset > sec->sh_size - 4)
7226 /* Get the word at the required offset. */
7227 word = byte_get (arm_sec->data + word_offset, 4);
7229 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
7230 if (arm_sec->rela == NULL)
7236 /* Look through the relocs to find the one that applies to the provided offset. */
7238 for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
7240 bfd_vma prelval, offset;
7242 if (rp->r_offset > word_offset && !wrapped)
7247 if (rp->r_offset > word_offset)
7250 if (rp->r_offset & 3)
7252 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
7253 (unsigned long) rp->r_offset);
7257 if (rp->r_offset < word_offset)
7260 /* PR 17531: file: 027-161405-0.004 */
7261 if (aux->symtab == NULL)
7264 if (arm_sec->rel_type == SHT_REL)
7266 offset = word & 0x7fffffff;
7267 if (offset & 0x40000000)
7268 offset |= ~ (bfd_vma) 0x7fffffff;
7270 else if (arm_sec->rel_type == SHT_RELA)
7271 offset = rp->r_addend;
7274 error (_("Unknown section relocation type %d encountered\n"),
7279 /* PR 17531 file: 027-1241568-0.004. */
7280 if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
7282 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
7283 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
7287 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
7288 offset += sym->st_value;
7289 prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
7291 /* Check that we are processing the expected reloc type. */
7292 if (elf_header.e_machine == EM_ARM)
7294 relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
7295 if (relname == NULL)
7297 warn (_("Skipping unknown ARM relocation type: %d\n"),
7298 (int) ELF32_R_TYPE (rp->r_info));
7302 if (streq (relname, "R_ARM_NONE"))
7305 if (! streq (relname, "R_ARM_PREL31"))
7307 warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
7311 else if (elf_header.e_machine == EM_TI_C6000)
7313 relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
7314 if (relname == NULL)
7316 warn (_("Skipping unknown C6000 relocation type: %d\n"),
7317 (int) ELF32_R_TYPE (rp->r_info));
7321 if (streq (relname, "R_C6000_NONE"))
7324 if (! streq (relname, "R_C6000_PREL31"))
7326 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
7334 /* This function currently only supports ARM and TI unwinders. */
7335 warn (_("Only TI and ARM unwinders are currently supported\n"));
7339 word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
7340 addr->section = sym->st_shndx;
7341 addr->offset = offset;
7344 * sym_name = sym->st_name;
7349 arm_sec->next_rela = rp;
7354 static const char *tic6x_unwind_regnames[16] =
7356 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
7357 "A14", "A13", "A12", "A11", "A10",
7358 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
7362 decode_tic6x_unwind_regmask (unsigned int mask)
7366 for (i = 12; mask; mask >>= 1, i--)
7370 fputs (tic6x_unwind_regnames[i], stdout);
7372 fputs (", ", stdout);
7378 if (remaining == 0 && more_words) \
7381 if (! get_unwind_section_word (aux, data_arm_sec, data_sec, \
7382 data_offset, & word, & addr, NULL)) \
7388 #define GET_OP(OP) \
7393 (OP) = word >> 24; \
7398 printf (_("[Truncated opcode]\n")); \
7401 printf ("0x%02x ", OP)
7404 decode_arm_unwind_bytecode (struct arm_unw_aux_info *aux,
7405 unsigned int word, unsigned int remaining,
7406 unsigned int more_words,
7407 bfd_vma data_offset, Elf_Internal_Shdr *data_sec,
7408 struct arm_section *data_arm_sec)
7410 struct absaddr addr;
7412 /* Decode the unwinding instructions. */
7415 unsigned int op, op2;
7424 printf (" 0x%02x ", op);
7426 if ((op & 0xc0) == 0x00)
7428 int offset = ((op & 0x3f) << 2) + 4;
7430 printf (" vsp = vsp + %d", offset);
7432 else if ((op & 0xc0) == 0x40)
7434 int offset = ((op & 0x3f) << 2) + 4;
7436 printf (" vsp = vsp - %d", offset);
7438 else if ((op & 0xf0) == 0x80)
7441 if (op == 0x80 && op2 == 0)
7442 printf (_("Refuse to unwind"));
7445 unsigned int mask = ((op & 0x0f) << 8) | op2;
7450 for (i = 0; i < 12; i++)
7451 if (mask & (1 << i))
7457 printf ("r%d", 4 + i);
7462 else if ((op & 0xf0) == 0x90)
7464 if (op == 0x9d || op == 0x9f)
7465 printf (_(" [Reserved]"));
7467 printf (" vsp = r%d", op & 0x0f);
7469 else if ((op & 0xf0) == 0xa0)
7471 int end = 4 + (op & 0x07);
7476 for (i = 4; i <= end; i++)
7492 else if (op == 0xb0)
7493 printf (_(" finish"));
7494 else if (op == 0xb1)
7497 if (op2 == 0 || (op2 & 0xf0) != 0)
7498 printf (_("[Spare]"));
7501 unsigned int mask = op2 & 0x0f;
7506 for (i = 0; i < 12; i++)
7507 if (mask & (1 << i))
7518 else if (op == 0xb2)
7520 unsigned char buf[9];
7521 unsigned int i, len;
7522 unsigned long offset;
7524 for (i = 0; i < sizeof (buf); i++)
7527 if ((buf[i] & 0x80) == 0)
7530 if (i == sizeof (buf))
7531 printf (_("corrupt change to vsp"));
7534 offset = read_uleb128 (buf, &len, buf + i + 1);
7535 assert (len == i + 1);
7536 offset = offset * 4 + 0x204;
7537 printf ("vsp = vsp + %ld", offset);
7540 else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
7542 unsigned int first, last;
7549 printf ("pop {D%d", first);
7551 printf ("-D%d", first + last);
7554 else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
7556 unsigned int count = op & 0x07;
7560 printf ("-D%d", 8 + count);
7563 else if (op >= 0xc0 && op <= 0xc5)
7565 unsigned int count = op & 0x07;
7567 printf (" pop {wR10");
7569 printf ("-wR%d", 10 + count);
7572 else if (op == 0xc6)
7574 unsigned int first, last;
7579 printf ("pop {wR%d", first);
7581 printf ("-wR%d", first + last);
7584 else if (op == 0xc7)
7587 if (op2 == 0 || (op2 & 0xf0) != 0)
7588 printf (_("[Spare]"));
7591 unsigned int mask = op2 & 0x0f;
7596 for (i = 0; i < 4; i++)
7597 if (mask & (1 << i))
7603 printf ("wCGR%d", i);
7609 printf (_(" [unsupported opcode]"));
7615 decode_tic6x_unwind_bytecode (struct arm_unw_aux_info *aux,
7616 unsigned int word, unsigned int remaining,
7617 unsigned int more_words,
7618 bfd_vma data_offset, Elf_Internal_Shdr *data_sec,
7619 struct arm_section *data_arm_sec)
7621 struct absaddr addr;
7623 /* Decode the unwinding instructions. */
7626 unsigned int op, op2;
7635 printf (" 0x%02x ", op);
7637 if ((op & 0xc0) == 0x00)
7639 int offset = ((op & 0x3f) << 3) + 8;
7640 printf (" sp = sp + %d", offset);
7642 else if ((op & 0xc0) == 0x80)
7645 if (op == 0x80 && op2 == 0)
7646 printf (_("Refuse to unwind"));
7649 unsigned int mask = ((op & 0x1f) << 8) | op2;
7651 printf ("pop compact {");
7655 decode_tic6x_unwind_regmask (mask);
7659 else if ((op & 0xf0) == 0xc0)
7667 unsigned int offset;
7671 /* Scan entire instruction first so that GET_OP output is not
7672 interleaved with disassembly. */
7674 for (i = 0; nregs < (op & 0xf); i++)
7680 regpos[nregs].offset = i * 2;
7681 regpos[nregs].reg = reg;
7688 regpos[nregs].offset = i * 2 + 1;
7689 regpos[nregs].reg = reg;
7694 printf (_("pop frame {"));
7696 for (i = i * 2; i > 0; i--)
7698 if (regpos[reg].offset == i - 1)
7700 name = tic6x_unwind_regnames[regpos[reg].reg];
7707 fputs (name, stdout);
7714 else if (op == 0xd0)
7715 printf (" MOV FP, SP");
7716 else if (op == 0xd1)
7717 printf (" __c6xabi_pop_rts");
7718 else if (op == 0xd2)
7720 unsigned char buf[9];
7721 unsigned int i, len;
7722 unsigned long offset;
7724 for (i = 0; i < sizeof (buf); i++)
7727 if ((buf[i] & 0x80) == 0)
7730 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
7731 if (i == sizeof (buf))
7733 printf ("<corrupt sp adjust>\n");
7734 warn (_("Corrupt stack pointer adjustment detected\n"));
7738 offset = read_uleb128 (buf, &len, buf + i + 1);
7739 assert (len == i + 1);
7740 offset = offset * 8 + 0x408;
7741 printf (_("sp = sp + %ld"), offset);
7743 else if ((op & 0xf0) == 0xe0)
7745 if ((op & 0x0f) == 7)
7748 printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
7752 printf (_(" [unsupported opcode]"));
7759 arm_expand_prel31 (bfd_vma word, bfd_vma where)
7763 offset = word & 0x7fffffff;
7764 if (offset & 0x40000000)
7765 offset |= ~ (bfd_vma) 0x7fffffff;
7767 if (elf_header.e_machine == EM_TI_C6000)
7770 return offset + where;
7774 decode_arm_unwind (struct arm_unw_aux_info * aux,
7776 unsigned int remaining,
7777 bfd_vma data_offset,
7778 Elf_Internal_Shdr * data_sec,
7779 struct arm_section * data_arm_sec)
7782 unsigned int more_words = 0;
7783 struct absaddr addr;
7784 bfd_vma sym_name = (bfd_vma) -1;
7788 /* Fetch the first word.
7789 Note - when decoding an object file the address extracted
7790 here will always be 0. So we also pass in the sym_name
7791 parameter so that we can find the symbol associated with
7792 the personality routine. */
7793 if (! get_unwind_section_word (aux, data_arm_sec, data_sec, data_offset,
7794 & word, & addr, & sym_name))
7800 if ((word & 0x80000000) == 0)
7802 /* Expand prel31 for personality routine. */
7804 const char *procname;
7806 fn = arm_expand_prel31 (word, data_sec->sh_addr + data_offset);
7807 printf (_(" Personality routine: "));
7809 && addr.section == SHN_UNDEF && addr.offset == 0
7810 && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
7812 procname = aux->strtab + sym_name;
7813 print_vma (fn, PREFIX_HEX);
7816 fputs (" <", stdout);
7817 fputs (procname, stdout);
7818 fputc ('>', stdout);
7822 procname = arm_print_vma_and_name (aux, fn, addr);
7823 fputc ('\n', stdout);
7825 /* The GCC personality routines use the standard compact
7826 encoding, starting with one byte giving the number of
7828 if (procname != NULL
7829 && (const_strneq (procname, "__gcc_personality_v0")
7830 || const_strneq (procname, "__gxx_personality_v0")
7831 || const_strneq (procname, "__gcj_personality_v0")
7832 || const_strneq (procname, "__gnu_objc_personality_v0")))
7839 printf (_(" [Truncated data]\n"));
7842 more_words = word >> 24;
7852 /* ARM EHABI Section 6.3:
7854 An exception-handling table entry for the compact model looks like:
7858 1 0 index Data for personalityRoutine[index] */
7860 if (elf_header.e_machine == EM_ARM
7861 && (word & 0x70000000))
7862 warn (_("Corrupt ARM compact model table entry: %x \n"), word);
7864 per_index = (word >> 24) & 0x7f;
7865 printf (_(" Compact model index: %d\n"), per_index);
7872 else if (per_index < 3)
7874 more_words = (word >> 16) & 0xff;
7880 switch (elf_header.e_machine)
7885 decode_arm_unwind_bytecode (aux, word, remaining, more_words,
7886 data_offset, data_sec, data_arm_sec);
7890 warn (_("Unknown ARM compact model index encountered\n"));
7891 printf (_(" [reserved]\n"));
7898 decode_tic6x_unwind_bytecode (aux, word, remaining, more_words,
7899 data_offset, data_sec, data_arm_sec);
7901 else if (per_index < 5)
7903 if (((word >> 17) & 0x7f) == 0x7f)
7904 printf (_(" Restore stack from frame pointer\n"));
7906 printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc);
7907 printf (_(" Registers restored: "));
7909 printf (" (compact) ");
7910 decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
7912 printf (_(" Return register: %s\n"),
7913 tic6x_unwind_regnames[word & 0xf]);
7916 printf (_(" [reserved (%d)]\n"), per_index);
7920 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
7921 elf_header.e_machine);
7924 /* Decode the descriptors. Not implemented. */
7928 dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec)
7930 struct arm_section exidx_arm_sec, extab_arm_sec;
7931 unsigned int i, exidx_len;
7933 memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
7934 memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
7935 exidx_len = exidx_sec->sh_size / 8;
7937 for (i = 0; i < exidx_len; i++)
7939 unsigned int exidx_fn, exidx_entry;
7940 struct absaddr fn_addr, entry_addr;
7943 fputc ('\n', stdout);
7945 if (! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
7946 8 * i, & exidx_fn, & fn_addr, NULL)
7947 || ! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
7948 8 * i + 4, & exidx_entry, & entry_addr, NULL))
7950 arm_free_section (& exidx_arm_sec);
7951 arm_free_section (& extab_arm_sec);
7955 /* ARM EHABI, Section 5:
7956 An index table entry consists of 2 words.
7957 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
7958 if (exidx_fn & 0x80000000)
7959 warn (_("corrupt index table entry: %x\n"), exidx_fn);
7961 fn = arm_expand_prel31 (exidx_fn, exidx_sec->sh_addr + 8 * i);
7963 arm_print_vma_and_name (aux, fn, fn_addr);
7964 fputs (": ", stdout);
7966 if (exidx_entry == 1)
7968 print_vma (exidx_entry, PREFIX_HEX);
7969 fputs (" [cantunwind]\n", stdout);
7971 else if (exidx_entry & 0x80000000)
7973 print_vma (exidx_entry, PREFIX_HEX);
7974 fputc ('\n', stdout);
7975 decode_arm_unwind (aux, exidx_entry, 4, 0, NULL, NULL);
7979 bfd_vma table, table_offset = 0;
7980 Elf_Internal_Shdr *table_sec;
7982 fputs ("@", stdout);
7983 table = arm_expand_prel31 (exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
7984 print_vma (table, PREFIX_HEX);
7987 /* Locate the matching .ARM.extab. */
7988 if (entry_addr.section != SHN_UNDEF
7989 && entry_addr.section < elf_header.e_shnum)
7991 table_sec = section_headers + entry_addr.section;
7992 table_offset = entry_addr.offset;
7996 table_sec = find_section_by_address (table);
7997 if (table_sec != NULL)
7998 table_offset = table - table_sec->sh_addr;
8000 if (table_sec == NULL)
8002 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
8003 (unsigned long) table);
8006 decode_arm_unwind (aux, 0, 0, table_offset, table_sec,
8013 arm_free_section (&exidx_arm_sec);
8014 arm_free_section (&extab_arm_sec);
8017 /* Used for both ARM and C6X unwinding tables. */
8020 arm_process_unwind (FILE *file)
8022 struct arm_unw_aux_info aux;
8023 Elf_Internal_Shdr *unwsec = NULL;
8024 Elf_Internal_Shdr *strsec;
8025 Elf_Internal_Shdr *sec;
8027 unsigned int sec_type;
8029 switch (elf_header.e_machine)
8032 sec_type = SHT_ARM_EXIDX;
8036 sec_type = SHT_C6000_UNWIND;
8040 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
8041 elf_header.e_machine);
8045 if (string_table == NULL)
8048 memset (& aux, 0, sizeof (aux));
8051 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
8053 if (sec->sh_type == SHT_SYMTAB && sec->sh_link < elf_header.e_shnum)
8055 aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
8057 strsec = section_headers + sec->sh_link;
8059 /* PR binutils/17531 file: 011-12666-0.004. */
8060 if (aux.strtab != NULL)
8062 error (_("Multiple string tables found in file.\n"));
8065 aux.strtab = get_data (NULL, file, strsec->sh_offset,
8066 1, strsec->sh_size, _("string table"));
8067 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
8069 else if (sec->sh_type == sec_type)
8074 printf (_("\nThere are no unwind sections in this file.\n"));
8076 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
8078 if (sec->sh_type == sec_type)
8080 printf (_("\nUnwind table index '%s' at offset 0x%lx contains %lu entries:\n"),
8081 printable_section_name (sec),
8082 (unsigned long) sec->sh_offset,
8083 (unsigned long) (sec->sh_size / (2 * eh_addr_size)));
8085 dump_arm_unwind (&aux, sec);
8092 free ((char *) aux.strtab);
8096 process_unwind (FILE * file)
8098 struct unwind_handler
8101 void (* handler)(FILE *);
8104 { EM_ARM, arm_process_unwind },
8105 { EM_IA_64, ia64_process_unwind },
8106 { EM_PARISC, hppa_process_unwind },
8107 { EM_TI_C6000, arm_process_unwind },
8115 for (i = 0; handlers[i].handler != NULL; i++)
8116 if (elf_header.e_machine == handlers[i].machtype)
8118 handlers[i].handler (file);
8122 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
8123 get_machine_name (elf_header.e_machine));
8127 dynamic_section_mips_val (Elf_Internal_Dyn * entry)
8129 switch (entry->d_tag)
8132 if (entry->d_un.d_val == 0)
8136 static const char * opts[] =
8138 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
8139 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
8140 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
8141 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
8147 for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
8148 if (entry->d_un.d_val & (1 << cnt))
8150 printf ("%s%s", first ? "" : " ", opts[cnt]);
8156 case DT_MIPS_IVERSION:
8157 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
8158 printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
8162 sprintf_vma (buf, entry->d_un.d_ptr);
8163 /* Note: coded this way so that there is a single string for translation. */
8164 printf (_("<corrupt: %s>"), buf);
8168 case DT_MIPS_TIME_STAMP:
8173 time_t atime = entry->d_un.d_val;
8174 tmp = gmtime (&atime);
8175 /* PR 17531: file: 6accc532. */
8177 snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
8179 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
8180 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8181 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8182 printf (_("Time Stamp: %s"), timebuf);
8186 case DT_MIPS_RLD_VERSION:
8187 case DT_MIPS_LOCAL_GOTNO:
8188 case DT_MIPS_CONFLICTNO:
8189 case DT_MIPS_LIBLISTNO:
8190 case DT_MIPS_SYMTABNO:
8191 case DT_MIPS_UNREFEXTNO:
8192 case DT_MIPS_HIPAGENO:
8193 case DT_MIPS_DELTA_CLASS_NO:
8194 case DT_MIPS_DELTA_INSTANCE_NO:
8195 case DT_MIPS_DELTA_RELOC_NO:
8196 case DT_MIPS_DELTA_SYM_NO:
8197 case DT_MIPS_DELTA_CLASSSYM_NO:
8198 case DT_MIPS_COMPACT_SIZE:
8199 print_vma (entry->d_un.d_ptr, DEC);
8203 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
8209 dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
8211 switch (entry->d_tag)
8213 case DT_HP_DLD_FLAGS:
8222 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
8223 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
8224 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
8225 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
8226 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
8227 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
8228 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
8229 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
8230 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
8231 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
8232 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
8233 { DT_HP_GST, "HP_GST" },
8234 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
8235 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
8236 { DT_HP_NODELETE, "HP_NODELETE" },
8237 { DT_HP_GROUP, "HP_GROUP" },
8238 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
8242 bfd_vma val = entry->d_un.d_val;
8244 for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
8245 if (val & flags[cnt].bit)
8249 fputs (flags[cnt].str, stdout);
8251 val ^= flags[cnt].bit;
8254 if (val != 0 || first)
8258 print_vma (val, HEX);
8264 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
8272 /* VMS vs Unix time offset and factor. */
8274 #define VMS_EPOCH_OFFSET 35067168000000000LL
8275 #define VMS_GRANULARITY_FACTOR 10000000
8277 /* Display a VMS time in a human readable format. */
8280 print_vms_time (bfd_int64_t vmstime)
8285 unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
8286 tm = gmtime (&unxtime);
8287 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
8288 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
8289 tm->tm_hour, tm->tm_min, tm->tm_sec);
8294 dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
8296 switch (entry->d_tag)
8298 case DT_IA_64_PLT_RESERVE:
8299 /* First 3 slots reserved. */
8300 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
8302 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
8305 case DT_IA_64_VMS_LINKTIME:
8307 print_vms_time (entry->d_un.d_val);
8311 case DT_IA_64_VMS_LNKFLAGS:
8312 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
8313 if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
8314 printf (" CALL_DEBUG");
8315 if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
8316 printf (" NOP0BUFS");
8317 if (entry->d_un.d_val & VMS_LF_P0IMAGE)
8318 printf (" P0IMAGE");
8319 if (entry->d_un.d_val & VMS_LF_MKTHREADS)
8320 printf (" MKTHREADS");
8321 if (entry->d_un.d_val & VMS_LF_UPCALLS)
8322 printf (" UPCALLS");
8323 if (entry->d_un.d_val & VMS_LF_IMGSTA)
8325 if (entry->d_un.d_val & VMS_LF_INITIALIZE)
8326 printf (" INITIALIZE");
8327 if (entry->d_un.d_val & VMS_LF_MAIN)
8329 if (entry->d_un.d_val & VMS_LF_EXE_INIT)
8330 printf (" EXE_INIT");
8331 if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
8332 printf (" TBK_IN_IMG");
8333 if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
8334 printf (" DBG_IN_IMG");
8335 if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
8336 printf (" TBK_IN_DSF");
8337 if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
8338 printf (" DBG_IN_DSF");
8339 if (entry->d_un.d_val & VMS_LF_SIGNATURES)
8340 printf (" SIGNATURES");
8341 if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
8342 printf (" REL_SEG_OFF");
8346 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
8353 get_32bit_dynamic_section (FILE * file)
8355 Elf32_External_Dyn * edyn;
8356 Elf32_External_Dyn * ext;
8357 Elf_Internal_Dyn * entry;
8359 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
8360 dynamic_size, _("dynamic section"));
8364 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
8365 might not have the luxury of section headers. Look for the DT_NULL
8366 terminator to determine the number of entries. */
8367 for (ext = edyn, dynamic_nent = 0;
8368 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
8372 if (BYTE_GET (ext->d_tag) == DT_NULL)
8376 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
8378 if (dynamic_section == NULL)
8380 error (_("Out of memory allocating space for %lu dynamic entries\n"),
8381 (unsigned long) dynamic_nent);
8386 for (ext = edyn, entry = dynamic_section;
8387 entry < dynamic_section + dynamic_nent;
8390 entry->d_tag = BYTE_GET (ext->d_tag);
8391 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
8400 get_64bit_dynamic_section (FILE * file)
8402 Elf64_External_Dyn * edyn;
8403 Elf64_External_Dyn * ext;
8404 Elf_Internal_Dyn * entry;
8406 /* Read in the data. */
8407 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
8408 dynamic_size, _("dynamic section"));
8412 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
8413 might not have the luxury of section headers. Look for the DT_NULL
8414 terminator to determine the number of entries. */
8415 for (ext = edyn, dynamic_nent = 0;
8416 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
8417 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
8421 if (BYTE_GET (ext->d_tag) == DT_NULL)
8425 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
8427 if (dynamic_section == NULL)
8429 error (_("Out of memory allocating space for %lu dynamic entries\n"),
8430 (unsigned long) dynamic_nent);
8435 /* Convert from external to internal formats. */
8436 for (ext = edyn, entry = dynamic_section;
8437 entry < dynamic_section + dynamic_nent;
8440 entry->d_tag = BYTE_GET (ext->d_tag);
8441 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
8450 print_dynamic_flags (bfd_vma flags)
8458 flag = flags & - flags;
8468 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
8469 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
8470 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
8471 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
8472 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
8473 default: fputs (_("unknown"), stdout); break;
8479 /* Parse and display the contents of the dynamic section. */
8482 process_dynamic_section (FILE * file)
8484 Elf_Internal_Dyn * entry;
8486 if (dynamic_size == 0)
8489 printf (_("\nThere is no dynamic section in this file.\n"));
8496 if (! get_32bit_dynamic_section (file))
8499 else if (! get_64bit_dynamic_section (file))
8502 /* Find the appropriate symbol table. */
8503 if (dynamic_symbols == NULL)
8505 for (entry = dynamic_section;
8506 entry < dynamic_section + dynamic_nent;
8509 Elf_Internal_Shdr section;
8511 if (entry->d_tag != DT_SYMTAB)
8514 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
8516 /* Since we do not know how big the symbol table is,
8517 we default to reading in the entire file (!) and
8518 processing that. This is overkill, I know, but it
8520 section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
8522 if (archive_file_offset != 0)
8523 section.sh_size = archive_file_size - section.sh_offset;
8526 if (fseek (file, 0, SEEK_END))
8527 error (_("Unable to seek to end of file!\n"));
8529 section.sh_size = ftell (file) - section.sh_offset;
8533 section.sh_entsize = sizeof (Elf32_External_Sym);
8535 section.sh_entsize = sizeof (Elf64_External_Sym);
8536 section.sh_name = string_table_length;
8538 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion, & num_dynamic_syms);
8539 if (num_dynamic_syms < 1)
8541 error (_("Unable to determine the number of symbols to load\n"));
8547 /* Similarly find a string table. */
8548 if (dynamic_strings == NULL)
8550 for (entry = dynamic_section;
8551 entry < dynamic_section + dynamic_nent;
8554 unsigned long offset;
8557 if (entry->d_tag != DT_STRTAB)
8560 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
8562 /* Since we do not know how big the string table is,
8563 we default to reading in the entire file (!) and
8564 processing that. This is overkill, I know, but it
8567 offset = offset_from_vma (file, entry->d_un.d_val, 0);
8569 if (archive_file_offset != 0)
8570 str_tab_len = archive_file_size - offset;
8573 if (fseek (file, 0, SEEK_END))
8574 error (_("Unable to seek to end of file\n"));
8575 str_tab_len = ftell (file) - offset;
8578 if (str_tab_len < 1)
8581 (_("Unable to determine the length of the dynamic string table\n"));
8585 dynamic_strings = (char *) get_data (NULL, file, offset, 1,
8587 _("dynamic string table"));
8588 dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
8593 /* And find the syminfo section if available. */
8594 if (dynamic_syminfo == NULL)
8596 unsigned long syminsz = 0;
8598 for (entry = dynamic_section;
8599 entry < dynamic_section + dynamic_nent;
8602 if (entry->d_tag == DT_SYMINENT)
8604 /* Note: these braces are necessary to avoid a syntax
8605 error from the SunOS4 C compiler. */
8606 /* PR binutils/17531: A corrupt file can trigger this test.
8607 So do not use an assert, instead generate an error message. */
8608 if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
8609 error (_("Bad value (%d) for SYMINENT entry\n"),
8610 (int) entry->d_un.d_val);
8612 else if (entry->d_tag == DT_SYMINSZ)
8613 syminsz = entry->d_un.d_val;
8614 else if (entry->d_tag == DT_SYMINFO)
8615 dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
8619 if (dynamic_syminfo_offset != 0 && syminsz != 0)
8621 Elf_External_Syminfo * extsyminfo;
8622 Elf_External_Syminfo * extsym;
8623 Elf_Internal_Syminfo * syminfo;
8625 /* There is a syminfo section. Read the data. */
8626 extsyminfo = (Elf_External_Syminfo *)
8627 get_data (NULL, file, dynamic_syminfo_offset, 1, syminsz,
8628 _("symbol information"));
8632 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
8633 if (dynamic_syminfo == NULL)
8635 error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
8636 (unsigned long) syminsz);
8640 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
8641 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
8642 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
8643 ++syminfo, ++extsym)
8645 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
8646 syminfo->si_flags = BYTE_GET (extsym->si_flags);
8653 if (do_dynamic && dynamic_addr)
8654 printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"),
8655 dynamic_addr, (unsigned long) dynamic_nent);
8657 printf (_(" Tag Type Name/Value\n"));
8659 for (entry = dynamic_section;
8660 entry < dynamic_section + dynamic_nent;
8668 print_vma (entry->d_tag, FULL_HEX);
8669 dtype = get_dynamic_type (entry->d_tag);
8670 printf (" (%s)%*s", dtype,
8671 ((is_32bit_elf ? 27 : 19)
8672 - (int) strlen (dtype)),
8676 switch (entry->d_tag)
8680 print_dynamic_flags (entry->d_un.d_val);
8690 switch (entry->d_tag)
8693 printf (_("Auxiliary library"));
8697 printf (_("Filter library"));
8701 printf (_("Configuration file"));
8705 printf (_("Dependency audit library"));
8709 printf (_("Audit library"));
8713 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
8714 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
8718 print_vma (entry->d_un.d_val, PREFIX_HEX);
8727 printf (_("Flags:"));
8729 if (entry->d_un.d_val == 0)
8730 printf (_(" None\n"));
8733 unsigned long int val = entry->d_un.d_val;
8735 if (val & DTF_1_PARINIT)
8737 printf (" PARINIT");
8738 val ^= DTF_1_PARINIT;
8740 if (val & DTF_1_CONFEXP)
8742 printf (" CONFEXP");
8743 val ^= DTF_1_CONFEXP;
8746 printf (" %lx", val);
8755 printf (_("Flags:"));
8757 if (entry->d_un.d_val == 0)
8758 printf (_(" None\n"));
8761 unsigned long int val = entry->d_un.d_val;
8763 if (val & DF_P1_LAZYLOAD)
8765 printf (" LAZYLOAD");
8766 val ^= DF_P1_LAZYLOAD;
8768 if (val & DF_P1_GROUPPERM)
8770 printf (" GROUPPERM");
8771 val ^= DF_P1_GROUPPERM;
8774 printf (" %lx", val);
8783 printf (_("Flags:"));
8784 if (entry->d_un.d_val == 0)
8785 printf (_(" None\n"));
8788 unsigned long int val = entry->d_un.d_val;
8795 if (val & DF_1_GLOBAL)
8800 if (val & DF_1_GROUP)
8805 if (val & DF_1_NODELETE)
8807 printf (" NODELETE");
8808 val ^= DF_1_NODELETE;
8810 if (val & DF_1_LOADFLTR)
8812 printf (" LOADFLTR");
8813 val ^= DF_1_LOADFLTR;
8815 if (val & DF_1_INITFIRST)
8817 printf (" INITFIRST");
8818 val ^= DF_1_INITFIRST;
8820 if (val & DF_1_NOOPEN)
8825 if (val & DF_1_ORIGIN)
8830 if (val & DF_1_DIRECT)
8835 if (val & DF_1_TRANS)
8840 if (val & DF_1_INTERPOSE)
8842 printf (" INTERPOSE");
8843 val ^= DF_1_INTERPOSE;
8845 if (val & DF_1_NODEFLIB)
8847 printf (" NODEFLIB");
8848 val ^= DF_1_NODEFLIB;
8850 if (val & DF_1_NODUMP)
8855 if (val & DF_1_CONFALT)
8857 printf (" CONFALT");
8858 val ^= DF_1_CONFALT;
8860 if (val & DF_1_ENDFILTEE)
8862 printf (" ENDFILTEE");
8863 val ^= DF_1_ENDFILTEE;
8865 if (val & DF_1_DISPRELDNE)
8867 printf (" DISPRELDNE");
8868 val ^= DF_1_DISPRELDNE;
8870 if (val & DF_1_DISPRELPND)
8872 printf (" DISPRELPND");
8873 val ^= DF_1_DISPRELPND;
8875 if (val & DF_1_NODIRECT)
8877 printf (" NODIRECT");
8878 val ^= DF_1_NODIRECT;
8880 if (val & DF_1_IGNMULDEF)
8882 printf (" IGNMULDEF");
8883 val ^= DF_1_IGNMULDEF;
8885 if (val & DF_1_NOKSYMS)
8887 printf (" NOKSYMS");
8888 val ^= DF_1_NOKSYMS;
8890 if (val & DF_1_NOHDR)
8895 if (val & DF_1_EDITED)
8900 if (val & DF_1_NORELOC)
8902 printf (" NORELOC");
8903 val ^= DF_1_NORELOC;
8905 if (val & DF_1_SYMINTPOSE)
8907 printf (" SYMINTPOSE");
8908 val ^= DF_1_SYMINTPOSE;
8910 if (val & DF_1_GLOBAUDIT)
8912 printf (" GLOBAUDIT");
8913 val ^= DF_1_GLOBAUDIT;
8915 if (val & DF_1_SINGLETON)
8917 printf (" SINGLETON");
8918 val ^= DF_1_SINGLETON;
8921 printf (" %lx", val);
8928 dynamic_info[entry->d_tag] = entry->d_un.d_val;
8930 puts (get_dynamic_type (entry->d_un.d_val));
8950 dynamic_info[entry->d_tag] = entry->d_un.d_val;
8956 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
8957 name = GET_DYNAMIC_NAME (entry->d_un.d_val);
8963 switch (entry->d_tag)
8966 printf (_("Shared library: [%s]"), name);
8968 if (streq (name, program_interpreter))
8969 printf (_(" program interpreter"));
8973 printf (_("Library soname: [%s]"), name);
8977 printf (_("Library rpath: [%s]"), name);
8981 printf (_("Library runpath: [%s]"), name);
8985 print_vma (entry->d_un.d_val, PREFIX_HEX);
8990 print_vma (entry->d_un.d_val, PREFIX_HEX);
9003 dynamic_info[entry->d_tag] = entry->d_un.d_val;
9007 case DT_INIT_ARRAYSZ:
9008 case DT_FINI_ARRAYSZ:
9009 case DT_GNU_CONFLICTSZ:
9010 case DT_GNU_LIBLISTSZ:
9013 print_vma (entry->d_un.d_val, UNSIGNED);
9014 printf (_(" (bytes)\n"));
9024 print_vma (entry->d_un.d_val, UNSIGNED);
9037 if (entry->d_tag == DT_USED
9038 && VALID_DYNAMIC_NAME (entry->d_un.d_val))
9040 char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
9044 printf (_("Not needed object: [%s]\n"), name);
9049 print_vma (entry->d_un.d_val, PREFIX_HEX);
9055 /* The value of this entry is ignored. */
9060 case DT_GNU_PRELINKED:
9064 time_t atime = entry->d_un.d_val;
9066 tmp = gmtime (&atime);
9067 /* PR 17533 file: 041-1244816-0.004. */
9069 printf (_("<corrupt time val: %lx"),
9070 (unsigned long) atime);
9072 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
9073 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9074 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
9080 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
9083 print_vma (entry->d_un.d_val, PREFIX_HEX);
9089 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
9090 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
9095 switch (elf_header.e_machine)
9098 case EM_MIPS_RS3_LE:
9099 dynamic_section_mips_val (entry);
9102 dynamic_section_parisc_val (entry);
9105 dynamic_section_ia64_val (entry);
9108 print_vma (entry->d_un.d_val, PREFIX_HEX);
9120 get_ver_flags (unsigned int flags)
9122 static char buff[32];
9129 if (flags & VER_FLG_BASE)
9130 strcat (buff, "BASE ");
9132 if (flags & VER_FLG_WEAK)
9134 if (flags & VER_FLG_BASE)
9135 strcat (buff, "| ");
9137 strcat (buff, "WEAK ");
9140 if (flags & VER_FLG_INFO)
9142 if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
9143 strcat (buff, "| ");
9145 strcat (buff, "INFO ");
9148 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
9149 strcat (buff, _("| <unknown>"));
9154 /* Display the contents of the version sections. */
9157 process_version_sections (FILE * file)
9159 Elf_Internal_Shdr * section;
9166 for (i = 0, section = section_headers;
9167 i < elf_header.e_shnum;
9170 switch (section->sh_type)
9172 case SHT_GNU_verdef:
9174 Elf_External_Verdef * edefs;
9181 printf (_("\nVersion definition section '%s' contains %u entries:\n"),
9182 printable_section_name (section),
9185 printf (_(" Addr: 0x"));
9186 printf_vma (section->sh_addr);
9187 printf (_(" Offset: %#08lx Link: %u (%s)"),
9188 (unsigned long) section->sh_offset, section->sh_link,
9189 printable_section_name_from_index (section->sh_link));
9191 edefs = (Elf_External_Verdef *)
9192 get_data (NULL, file, section->sh_offset, 1,section->sh_size,
9193 _("version definition section"));
9196 endbuf = (char *) edefs + section->sh_size;
9198 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
9201 Elf_External_Verdef * edef;
9202 Elf_Internal_Verdef ent;
9203 Elf_External_Verdaux * eaux;
9204 Elf_Internal_Verdaux aux;
9208 /* Check for very large indicies. */
9209 if (idx > (size_t) (endbuf - (char *) edefs))
9212 vstart = ((char *) edefs) + idx;
9213 if (vstart + sizeof (*edef) > endbuf)
9216 edef = (Elf_External_Verdef *) vstart;
9218 ent.vd_version = BYTE_GET (edef->vd_version);
9219 ent.vd_flags = BYTE_GET (edef->vd_flags);
9220 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
9221 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
9222 ent.vd_hash = BYTE_GET (edef->vd_hash);
9223 ent.vd_aux = BYTE_GET (edef->vd_aux);
9224 ent.vd_next = BYTE_GET (edef->vd_next);
9226 printf (_(" %#06x: Rev: %d Flags: %s"),
9227 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
9229 printf (_(" Index: %d Cnt: %d "),
9230 ent.vd_ndx, ent.vd_cnt);
9232 /* Check for overflow. */
9233 if (ent.vd_aux > (size_t) (endbuf - vstart))
9236 vstart += ent.vd_aux;
9238 eaux = (Elf_External_Verdaux *) vstart;
9240 aux.vda_name = BYTE_GET (eaux->vda_name);
9241 aux.vda_next = BYTE_GET (eaux->vda_next);
9243 if (VALID_DYNAMIC_NAME (aux.vda_name))
9244 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
9246 printf (_("Name index: %ld\n"), aux.vda_name);
9248 isum = idx + ent.vd_aux;
9250 for (j = 1; j < ent.vd_cnt; j++)
9252 /* Check for overflow. */
9253 if (aux.vda_next > (size_t) (endbuf - vstart))
9256 isum += aux.vda_next;
9257 vstart += aux.vda_next;
9259 eaux = (Elf_External_Verdaux *) vstart;
9260 if (vstart + sizeof (*eaux) > endbuf)
9263 aux.vda_name = BYTE_GET (eaux->vda_name);
9264 aux.vda_next = BYTE_GET (eaux->vda_next);
9266 if (VALID_DYNAMIC_NAME (aux.vda_name))
9267 printf (_(" %#06x: Parent %d: %s\n"),
9268 isum, j, GET_DYNAMIC_NAME (aux.vda_name));
9270 printf (_(" %#06x: Parent %d, name index: %ld\n"),
9271 isum, j, aux.vda_name);
9275 printf (_(" Version def aux past end of section\n"));
9277 /* PR 17531: file: id:000001,src:000172+005151,op:splice,rep:2. */
9278 if (idx + ent.vd_next <= idx)
9284 if (cnt < section->sh_info)
9285 printf (_(" Version definition past end of section\n"));
9291 case SHT_GNU_verneed:
9293 Elf_External_Verneed * eneed;
9300 printf (_("\nVersion needs section '%s' contains %u entries:\n"),
9301 printable_section_name (section), section->sh_info);
9303 printf (_(" Addr: 0x"));
9304 printf_vma (section->sh_addr);
9305 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
9306 (unsigned long) section->sh_offset, section->sh_link,
9307 printable_section_name_from_index (section->sh_link));
9309 eneed = (Elf_External_Verneed *) get_data (NULL, file,
9310 section->sh_offset, 1,
9312 _("Version Needs section"));
9315 endbuf = (char *) eneed + section->sh_size;
9317 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
9319 Elf_External_Verneed * entry;
9320 Elf_Internal_Verneed ent;
9325 if (idx > (size_t) (endbuf - (char *) eneed))
9328 vstart = ((char *) eneed) + idx;
9329 if (vstart + sizeof (*entry) > endbuf)
9332 entry = (Elf_External_Verneed *) vstart;
9334 ent.vn_version = BYTE_GET (entry->vn_version);
9335 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
9336 ent.vn_file = BYTE_GET (entry->vn_file);
9337 ent.vn_aux = BYTE_GET (entry->vn_aux);
9338 ent.vn_next = BYTE_GET (entry->vn_next);
9340 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
9342 if (VALID_DYNAMIC_NAME (ent.vn_file))
9343 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
9345 printf (_(" File: %lx"), ent.vn_file);
9347 printf (_(" Cnt: %d\n"), ent.vn_cnt);
9349 /* Check for overflow. */
9350 if (ent.vn_aux > (size_t) (endbuf - vstart))
9353 vstart += ent.vn_aux;
9355 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
9357 Elf_External_Vernaux * eaux;
9358 Elf_Internal_Vernaux aux;
9360 if (vstart + sizeof (*eaux) > endbuf)
9362 eaux = (Elf_External_Vernaux *) vstart;
9364 aux.vna_hash = BYTE_GET (eaux->vna_hash);
9365 aux.vna_flags = BYTE_GET (eaux->vna_flags);
9366 aux.vna_other = BYTE_GET (eaux->vna_other);
9367 aux.vna_name = BYTE_GET (eaux->vna_name);
9368 aux.vna_next = BYTE_GET (eaux->vna_next);
9370 if (VALID_DYNAMIC_NAME (aux.vna_name))
9371 printf (_(" %#06x: Name: %s"),
9372 isum, GET_DYNAMIC_NAME (aux.vna_name));
9374 printf (_(" %#06x: Name index: %lx"),
9375 isum, aux.vna_name);
9377 printf (_(" Flags: %s Version: %d\n"),
9378 get_ver_flags (aux.vna_flags), aux.vna_other);
9380 /* Check for overflow. */
9381 if (aux.vna_next > (size_t) (endbuf - vstart)
9382 || (aux.vna_next == 0 && j < ent.vn_cnt - 1))
9384 warn (_("Invalid vna_next field of %lx\n"),
9390 isum += aux.vna_next;
9391 vstart += aux.vna_next;
9395 warn (_("Missing Version Needs auxillary information\n"));
9397 if (ent.vn_next == 0 && cnt < section->sh_info - 1)
9399 warn (_("Corrupt Version Needs structure - offset to next structure is zero with entries still left to be processed\n"));
9400 cnt = section->sh_info;
9406 if (cnt < section->sh_info)
9407 warn (_("Missing Version Needs information\n"));
9413 case SHT_GNU_versym:
9415 Elf_Internal_Shdr * link_section;
9418 unsigned char * edata;
9419 unsigned short * data;
9421 Elf_Internal_Sym * symbols;
9422 Elf_Internal_Shdr * string_sec;
9423 unsigned long num_syms;
9426 if (section->sh_link >= elf_header.e_shnum)
9429 link_section = section_headers + section->sh_link;
9430 total = section->sh_size / sizeof (Elf_External_Versym);
9432 if (link_section->sh_link >= elf_header.e_shnum)
9437 symbols = GET_ELF_SYMBOLS (file, link_section, & num_syms);
9438 if (symbols == NULL)
9441 string_sec = section_headers + link_section->sh_link;
9443 strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
9444 string_sec->sh_size,
9445 _("version string table"));
9452 printf (_("\nVersion symbols section '%s' contains %lu entries:\n"),
9453 printable_section_name (section), (unsigned long) total);
9455 printf (_(" Addr: "));
9456 printf_vma (section->sh_addr);
9457 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
9458 (unsigned long) section->sh_offset, section->sh_link,
9459 printable_section_name (link_section));
9461 off = offset_from_vma (file,
9462 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
9463 total * sizeof (short));
9464 edata = (unsigned char *) get_data (NULL, file, off, total,
9466 _("version symbol data"));
9474 data = (short unsigned int *) cmalloc (total, sizeof (short));
9476 for (cnt = total; cnt --;)
9477 data[cnt] = byte_get (edata + cnt * sizeof (short),
9482 for (cnt = 0; cnt < total; cnt += 4)
9485 int check_def, check_need;
9488 printf (" %03x:", cnt);
9490 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
9491 switch (data[cnt + j])
9494 fputs (_(" 0 (*local*) "), stdout);
9498 fputs (_(" 1 (*global*) "), stdout);
9502 nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
9503 data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
9505 /* If this index value is greater than the size of the symbols
9506 array, break to avoid an out-of-bounds read. */
9507 if ((unsigned long)(cnt + j) >= num_syms)
9509 warn (_("invalid index into symbol array\n"));
9515 if (symbols[cnt + j].st_shndx >= elf_header.e_shnum
9516 || section_headers[symbols[cnt + j].st_shndx].sh_type
9519 if (symbols[cnt + j].st_shndx == SHN_UNDEF)
9526 && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
9528 Elf_Internal_Verneed ivn;
9529 unsigned long offset;
9531 offset = offset_from_vma
9532 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
9533 sizeof (Elf_External_Verneed));
9537 Elf_Internal_Vernaux ivna;
9538 Elf_External_Verneed evn;
9539 Elf_External_Vernaux evna;
9540 unsigned long a_off;
9542 if (get_data (&evn, file, offset, sizeof (evn), 1,
9543 _("version need")) == NULL)
9546 ivn.vn_aux = BYTE_GET (evn.vn_aux);
9547 ivn.vn_next = BYTE_GET (evn.vn_next);
9549 a_off = offset + ivn.vn_aux;
9553 if (get_data (&evna, file, a_off, sizeof (evna),
9554 1, _("version need aux (2)")) == NULL)
9561 ivna.vna_next = BYTE_GET (evna.vna_next);
9562 ivna.vna_other = BYTE_GET (evna.vna_other);
9565 a_off += ivna.vna_next;
9567 while (ivna.vna_other != data[cnt + j]
9568 && ivna.vna_next != 0);
9570 if (ivna.vna_other == data[cnt + j])
9572 ivna.vna_name = BYTE_GET (evna.vna_name);
9574 if (ivna.vna_name >= string_sec->sh_size)
9575 name = _("*invalid*");
9577 name = strtab + ivna.vna_name;
9578 nn += printf ("(%s%-*s",
9580 12 - (int) strlen (name),
9586 offset += ivn.vn_next;
9588 while (ivn.vn_next);
9591 if (check_def && data[cnt + j] != 0x8001
9592 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
9594 Elf_Internal_Verdef ivd;
9595 Elf_External_Verdef evd;
9596 unsigned long offset;
9598 offset = offset_from_vma
9599 (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
9604 if (get_data (&evd, file, offset, sizeof (evd), 1,
9605 _("version def")) == NULL)
9608 /* PR 17531: file: 046-1082287-0.004. */
9609 ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1;
9614 ivd.vd_next = BYTE_GET (evd.vd_next);
9615 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
9618 offset += ivd.vd_next;
9620 while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
9621 && ivd.vd_next != 0);
9623 if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
9625 Elf_External_Verdaux evda;
9626 Elf_Internal_Verdaux ivda;
9628 ivd.vd_aux = BYTE_GET (evd.vd_aux);
9630 if (get_data (&evda, file,
9631 offset - ivd.vd_next + ivd.vd_aux,
9633 _("version def aux")) == NULL)
9636 ivda.vda_name = BYTE_GET (evda.vda_name);
9638 if (ivda.vda_name >= string_sec->sh_size)
9639 name = _("*invalid*");
9641 name = strtab + ivda.vda_name;
9642 nn += printf ("(%s%-*s",
9644 12 - (int) strlen (name),
9650 printf ("%*c", 18 - nn, ' ');
9668 printf (_("\nNo version information found in this file.\n"));
9674 get_symbol_binding (unsigned int binding)
9676 static char buff[32];
9680 case STB_LOCAL: return "LOCAL";
9681 case STB_GLOBAL: return "GLOBAL";
9682 case STB_WEAK: return "WEAK";
9684 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
9685 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
9687 else if (binding >= STB_LOOS && binding <= STB_HIOS)
9689 if (binding == STB_GNU_UNIQUE
9690 && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
9691 /* GNU is still using the default value 0. */
9692 || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
9694 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
9697 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
9703 get_symbol_type (unsigned int type)
9705 static char buff[32];
9709 case STT_NOTYPE: return "NOTYPE";
9710 case STT_OBJECT: return "OBJECT";
9711 case STT_FUNC: return "FUNC";
9712 case STT_SECTION: return "SECTION";
9713 case STT_FILE: return "FILE";
9714 case STT_COMMON: return "COMMON";
9715 case STT_TLS: return "TLS";
9716 case STT_RELC: return "RELC";
9717 case STT_SRELC: return "SRELC";
9719 if (type >= STT_LOPROC && type <= STT_HIPROC)
9721 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
9722 return "THUMB_FUNC";
9724 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
9727 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
9728 return "PARISC_MILLI";
9730 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
9732 else if (type >= STT_LOOS && type <= STT_HIOS)
9734 if (elf_header.e_machine == EM_PARISC)
9736 if (type == STT_HP_OPAQUE)
9738 if (type == STT_HP_STUB)
9742 if (type == STT_GNU_IFUNC
9743 && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
9744 || elf_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD
9745 /* GNU is still using the default value 0. */
9746 || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
9749 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
9752 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
9758 get_symbol_visibility (unsigned int visibility)
9762 case STV_DEFAULT: return "DEFAULT";
9763 case STV_INTERNAL: return "INTERNAL";
9764 case STV_HIDDEN: return "HIDDEN";
9765 case STV_PROTECTED: return "PROTECTED";
9767 error (_("Unrecognized visibility value: %u"), visibility);
9768 return _("<unknown>");
9773 get_mips_symbol_other (unsigned int other)
9785 case STO_MICROMIPS | STO_MIPS_PIC:
9786 return "MICROMIPS, MIPS PIC";
9795 get_ia64_symbol_other (unsigned int other)
9799 static char res[32];
9803 /* Function types is for images and .STB files only. */
9804 switch (elf_header.e_type)
9808 switch (VMS_ST_FUNC_TYPE (other))
9810 case VMS_SFT_CODE_ADDR:
9811 strcat (res, " CA");
9813 case VMS_SFT_SYMV_IDX:
9814 strcat (res, " VEC");
9817 strcat (res, " FD");
9819 case VMS_SFT_RESERVE:
9820 strcat (res, " RSV");
9823 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
9824 VMS_ST_FUNC_TYPE (other));
9825 strcat (res, " <unknown>");
9832 switch (VMS_ST_LINKAGE (other))
9834 case VMS_STL_IGNORE:
9835 strcat (res, " IGN");
9837 case VMS_STL_RESERVE:
9838 strcat (res, " RSV");
9841 strcat (res, " STD");
9844 strcat (res, " LNK");
9847 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
9848 VMS_ST_LINKAGE (other));
9849 strcat (res, " <unknown>");
9862 get_ppc64_symbol_other (unsigned int other)
9864 if (PPC64_LOCAL_ENTRY_OFFSET (other) != 0)
9866 static char buf[32];
9867 snprintf (buf, sizeof buf, _("<localentry>: %d"),
9868 PPC64_LOCAL_ENTRY_OFFSET (other));
9875 get_symbol_other (unsigned int other)
9877 const char * result = NULL;
9878 static char buff [32];
9883 switch (elf_header.e_machine)
9886 result = get_mips_symbol_other (other);
9889 result = get_ia64_symbol_other (other);
9892 result = get_ppc64_symbol_other (other);
9901 snprintf (buff, sizeof buff, _("<other>: %x"), other);
9906 get_symbol_index_type (unsigned int type)
9908 static char buff[32];
9912 case SHN_UNDEF: return "UND";
9913 case SHN_ABS: return "ABS";
9914 case SHN_COMMON: return "COM";
9916 if (type == SHN_IA_64_ANSI_COMMON
9917 && elf_header.e_machine == EM_IA_64
9918 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
9920 else if ((elf_header.e_machine == EM_X86_64
9921 || elf_header.e_machine == EM_L1OM
9922 || elf_header.e_machine == EM_K1OM)
9923 && type == SHN_X86_64_LCOMMON)
9925 else if ((type == SHN_MIPS_SCOMMON
9926 && elf_header.e_machine == EM_MIPS)
9927 || (type == SHN_TIC6X_SCOMMON
9928 && elf_header.e_machine == EM_TI_C6000))
9930 else if (type == SHN_MIPS_SUNDEFINED
9931 && elf_header.e_machine == EM_MIPS)
9933 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
9934 sprintf (buff, "PRC[0x%04x]", type & 0xffff);
9935 else if (type >= SHN_LOOS && type <= SHN_HIOS)
9936 sprintf (buff, "OS [0x%04x]", type & 0xffff);
9937 else if (type >= SHN_LORESERVE)
9938 sprintf (buff, "RSV[0x%04x]", type & 0xffff);
9939 else if (type >= elf_header.e_shnum)
9940 sprintf (buff, _("bad section index[%3d]"), type);
9942 sprintf (buff, "%3d", type);
9950 get_dynamic_data (FILE * file, bfd_size_type number, unsigned int ent_size)
9952 unsigned char * e_data;
9955 /* If the size_t type is smaller than the bfd_size_type, eg because
9956 you are building a 32-bit tool on a 64-bit host, then make sure
9957 that when (number) is cast to (size_t) no information is lost. */
9958 if (sizeof (size_t) < sizeof (bfd_size_type)
9959 && (bfd_size_type) ((size_t) number) != number)
9961 error (_("Size truncation prevents reading %llu elements of size %u\n"),
9962 (unsigned long long) number, ent_size);
9966 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
9967 attempting to allocate memory when the read is bound to fail. */
9968 if (ent_size * number > current_file_size)
9970 error (_("Invalid number of dynamic entries: %llu\n"),
9971 (unsigned long long) number);
9975 e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
9978 error (_("Out of memory reading %llu dynamic entries\n"),
9979 (unsigned long long) number);
9983 if (fread (e_data, ent_size, (size_t) number, file) != number)
9985 error (_("Unable to read in %llu bytes of dynamic data\n"),
9986 (unsigned long long) (number * ent_size));
9991 i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
9994 error (_("Out of memory allocating space for %llu dynamic entries\n"),
9995 (unsigned long long) number);
10001 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
10009 print_dynamic_symbol (bfd_vma si, unsigned long hn)
10011 Elf_Internal_Sym * psym;
10014 n = print_vma (si, DEC_5);
10016 fputs (&" "[n], stdout);
10017 printf (" %3lu: ", hn);
10019 if (dynamic_symbols == NULL || si >= num_dynamic_syms)
10021 printf (_("<No info available for dynamic symbol number %lu>\n"),
10022 (unsigned long) si);
10026 psym = dynamic_symbols + si;
10027 print_vma (psym->st_value, LONG_HEX);
10029 print_vma (psym->st_size, DEC_5);
10031 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
10032 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
10033 printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
10034 /* Check to see if any other bits in the st_other field are set.
10035 Note - displaying this information disrupts the layout of the
10036 table being generated, but for the moment this case is very
10038 if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
10039 printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
10040 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
10041 if (VALID_DYNAMIC_NAME (psym->st_name))
10042 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
10044 printf (_(" <corrupt: %14ld>"), psym->st_name);
10048 /* Dump the symbol table. */
10050 process_symbol_table (FILE * file)
10052 Elf_Internal_Shdr * section;
10053 bfd_size_type nbuckets = 0;
10054 bfd_size_type nchains = 0;
10055 bfd_vma * buckets = NULL;
10056 bfd_vma * chains = NULL;
10057 bfd_vma ngnubuckets = 0;
10058 bfd_vma * gnubuckets = NULL;
10059 bfd_vma * gnuchains = NULL;
10060 bfd_vma gnusymidx = 0;
10061 bfd_size_type ngnuchains = 0;
10063 if (!do_syms && !do_dyn_syms && !do_histogram)
10066 if (dynamic_info[DT_HASH]
10068 || (do_using_dynamic
10070 && dynamic_strings != NULL)))
10072 unsigned char nb[8];
10073 unsigned char nc[8];
10074 unsigned int hash_ent_size = 4;
10076 if ((elf_header.e_machine == EM_ALPHA
10077 || elf_header.e_machine == EM_S390
10078 || elf_header.e_machine == EM_S390_OLD)
10079 && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
10083 (archive_file_offset
10084 + offset_from_vma (file, dynamic_info[DT_HASH],
10085 sizeof nb + sizeof nc)),
10088 error (_("Unable to seek to start of dynamic information\n"));
10092 if (fread (nb, hash_ent_size, 1, file) != 1)
10094 error (_("Failed to read in number of buckets\n"));
10098 if (fread (nc, hash_ent_size, 1, file) != 1)
10100 error (_("Failed to read in number of chains\n"));
10104 nbuckets = byte_get (nb, hash_ent_size);
10105 nchains = byte_get (nc, hash_ent_size);
10107 buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
10108 chains = get_dynamic_data (file, nchains, hash_ent_size);
10111 if (buckets == NULL || chains == NULL)
10113 if (do_using_dynamic)
10124 if (dynamic_info_DT_GNU_HASH
10126 || (do_using_dynamic
10128 && dynamic_strings != NULL)))
10130 unsigned char nb[16];
10131 bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
10132 bfd_vma buckets_vma;
10135 (archive_file_offset
10136 + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
10140 error (_("Unable to seek to start of dynamic information\n"));
10144 if (fread (nb, 16, 1, file) != 1)
10146 error (_("Failed to read in number of buckets\n"));
10150 ngnubuckets = byte_get (nb, 4);
10151 gnusymidx = byte_get (nb + 4, 4);
10152 bitmaskwords = byte_get (nb + 8, 4);
10153 buckets_vma = dynamic_info_DT_GNU_HASH + 16;
10155 buckets_vma += bitmaskwords * 4;
10157 buckets_vma += bitmaskwords * 8;
10160 (archive_file_offset
10161 + offset_from_vma (file, buckets_vma, 4)),
10164 error (_("Unable to seek to start of dynamic information\n"));
10168 gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
10170 if (gnubuckets == NULL)
10173 for (i = 0; i < ngnubuckets; i++)
10174 if (gnubuckets[i] != 0)
10176 if (gnubuckets[i] < gnusymidx)
10179 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
10180 maxchain = gnubuckets[i];
10183 if (maxchain == 0xffffffff)
10186 maxchain -= gnusymidx;
10189 (archive_file_offset
10190 + offset_from_vma (file, buckets_vma
10191 + 4 * (ngnubuckets + maxchain), 4)),
10194 error (_("Unable to seek to start of dynamic information\n"));
10200 if (fread (nb, 4, 1, file) != 1)
10202 error (_("Failed to determine last chain length\n"));
10206 if (maxchain + 1 == 0)
10211 while ((byte_get (nb, 4) & 1) == 0);
10214 (archive_file_offset
10215 + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
10218 error (_("Unable to seek to start of dynamic information\n"));
10222 gnuchains = get_dynamic_data (file, maxchain, 4);
10223 ngnuchains = maxchain;
10226 if (gnuchains == NULL)
10231 if (do_using_dynamic)
10236 if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
10238 && do_using_dynamic
10239 && dynamic_strings != NULL
10240 && dynamic_symbols != NULL)
10244 if (dynamic_info[DT_HASH])
10248 printf (_("\nSymbol table for image:\n"));
10250 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
10252 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
10254 for (hn = 0; hn < nbuckets; hn++)
10259 for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
10260 print_dynamic_symbol (si, hn);
10264 if (dynamic_info_DT_GNU_HASH)
10266 printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
10268 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
10270 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
10272 for (hn = 0; hn < ngnubuckets; ++hn)
10273 if (gnubuckets[hn] != 0)
10275 bfd_vma si = gnubuckets[hn];
10276 bfd_vma off = si - gnusymidx;
10280 print_dynamic_symbol (si, hn);
10283 while (off < ngnuchains && (gnuchains[off++] & 1) == 0);
10287 else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
10288 && section_headers != NULL)
10292 for (i = 0, section = section_headers;
10293 i < elf_header.e_shnum;
10297 char * strtab = NULL;
10298 unsigned long int strtab_size = 0;
10299 Elf_Internal_Sym * symtab;
10300 Elf_Internal_Sym * psym;
10301 unsigned long num_syms;
10303 if ((section->sh_type != SHT_SYMTAB
10304 && section->sh_type != SHT_DYNSYM)
10306 && section->sh_type == SHT_SYMTAB))
10309 if (section->sh_entsize == 0)
10311 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
10312 printable_section_name (section));
10316 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
10317 printable_section_name (section),
10318 (unsigned long) (section->sh_size / section->sh_entsize));
10321 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
10323 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
10325 symtab = GET_ELF_SYMBOLS (file, section, & num_syms);
10326 if (symtab == NULL)
10329 if (section->sh_link == elf_header.e_shstrndx)
10331 strtab = string_table;
10332 strtab_size = string_table_length;
10334 else if (section->sh_link < elf_header.e_shnum)
10336 Elf_Internal_Shdr * string_sec;
10338 string_sec = section_headers + section->sh_link;
10340 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
10341 1, string_sec->sh_size,
10342 _("string table"));
10343 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
10346 for (si = 0, psym = symtab; si < num_syms; si++, psym++)
10348 printf ("%6d: ", si);
10349 print_vma (psym->st_value, LONG_HEX);
10351 print_vma (psym->st_size, DEC_5);
10352 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
10353 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
10354 printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
10355 /* Check to see if any other bits in the st_other field are set.
10356 Note - displaying this information disrupts the layout of the
10357 table being generated, but for the moment this case is very rare. */
10358 if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
10359 printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
10360 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
10361 print_symbol (25, psym->st_name < strtab_size
10362 ? strtab + psym->st_name : _("<corrupt>"));
10364 if (section->sh_type == SHT_DYNSYM
10365 && version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
10367 unsigned char data[2];
10368 unsigned short vers_data;
10369 unsigned long offset;
10373 offset = offset_from_vma
10374 (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
10375 sizeof data + si * sizeof (vers_data));
10377 if (get_data (&data, file, offset + si * sizeof (vers_data),
10378 sizeof (data), 1, _("version data")) == NULL)
10381 vers_data = byte_get (data, 2);
10383 is_nobits = (section_headers != NULL
10384 && psym->st_shndx < elf_header.e_shnum
10385 && section_headers[psym->st_shndx].sh_type
10388 check_def = (psym->st_shndx != SHN_UNDEF);
10390 if ((vers_data & VERSYM_HIDDEN) || vers_data > 1)
10392 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
10393 && (is_nobits || ! check_def))
10395 Elf_External_Verneed evn;
10396 Elf_Internal_Verneed ivn;
10397 Elf_Internal_Vernaux ivna;
10399 /* We must test both. */
10400 offset = offset_from_vma
10401 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
10406 unsigned long vna_off;
10408 if (get_data (&evn, file, offset, sizeof (evn), 1,
10409 _("version need")) == NULL)
10412 ivna.vna_other = 0;
10417 ivn.vn_aux = BYTE_GET (evn.vn_aux);
10418 ivn.vn_next = BYTE_GET (evn.vn_next);
10420 vna_off = offset + ivn.vn_aux;
10424 Elf_External_Vernaux evna;
10426 if (get_data (&evna, file, vna_off,
10428 _("version need aux (3)")) == NULL)
10431 ivna.vna_other = 0;
10436 ivna.vna_other = BYTE_GET (evna.vna_other);
10437 ivna.vna_next = BYTE_GET (evna.vna_next);
10438 ivna.vna_name = BYTE_GET (evna.vna_name);
10441 vna_off += ivna.vna_next;
10443 while (ivna.vna_other != vers_data
10444 && ivna.vna_next != 0);
10446 if (ivna.vna_other == vers_data)
10449 offset += ivn.vn_next;
10451 while (ivn.vn_next != 0);
10453 if (ivna.vna_other == vers_data)
10455 printf ("@%s (%d)",
10456 ivna.vna_name < strtab_size
10457 ? strtab + ivna.vna_name : _("<corrupt>"),
10461 else if (! is_nobits)
10462 error (_("bad dynamic symbol\n"));
10469 if (vers_data != 0x8001
10470 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
10472 Elf_Internal_Verdef ivd;
10473 Elf_Internal_Verdaux ivda;
10474 Elf_External_Verdaux evda;
10477 off = offset_from_vma
10479 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
10480 sizeof (Elf_External_Verdef));
10484 Elf_External_Verdef evd;
10486 if (get_data (&evd, file, off, sizeof (evd),
10487 1, _("version def")) == NULL)
10495 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
10496 ivd.vd_aux = BYTE_GET (evd.vd_aux);
10497 ivd.vd_next = BYTE_GET (evd.vd_next);
10500 off += ivd.vd_next;
10502 while (ivd.vd_ndx != (vers_data & VERSYM_VERSION)
10503 && ivd.vd_next != 0);
10505 off -= ivd.vd_next;
10508 if (get_data (&evda, file, off, sizeof (evda),
10509 1, _("version def aux")) == NULL)
10512 ivda.vda_name = BYTE_GET (evda.vda_name);
10514 if (psym->st_name != ivda.vda_name)
10515 printf ((vers_data & VERSYM_HIDDEN)
10517 ivda.vda_name < strtab_size
10518 ? strtab + ivda.vda_name : _("<corrupt>"));
10528 if (strtab != string_table)
10534 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
10536 if (do_histogram && buckets != NULL)
10538 unsigned long * lengths;
10539 unsigned long * counts;
10542 unsigned long maxlength = 0;
10543 unsigned long nzero_counts = 0;
10544 unsigned long nsyms = 0;
10545 unsigned long chained;
10547 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
10548 (unsigned long) nbuckets);
10550 lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
10551 if (lengths == NULL)
10553 error (_("Out of memory allocating space for histogram buckets\n"));
10557 printf (_(" Length Number %% of total Coverage\n"));
10558 for (hn = 0; hn < nbuckets; ++hn)
10560 for (si = buckets[hn], chained = 0;
10561 si > 0 && si < nchains && si < nbuckets && chained <= nchains;
10562 si = chains[si], ++chained)
10565 if (maxlength < ++lengths[hn])
10569 /* PR binutils/17531: A corrupt binary could contain broken
10570 histogram data. Do not go into an infinite loop trying
10572 if (chained > nchains)
10574 error (_("histogram chain is corrupt\n"));
10579 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
10580 if (counts == NULL)
10583 error (_("Out of memory allocating space for histogram counts\n"));
10587 for (hn = 0; hn < nbuckets; ++hn)
10588 ++counts[lengths[hn]];
10593 printf (" 0 %-10lu (%5.1f%%)\n",
10594 counts[0], (counts[0] * 100.0) / nbuckets);
10595 for (i = 1; i <= maxlength; ++i)
10597 nzero_counts += counts[i] * i;
10598 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
10599 i, counts[i], (counts[i] * 100.0) / nbuckets,
10600 (nzero_counts * 100.0) / nsyms);
10608 if (buckets != NULL)
10614 if (do_histogram && gnubuckets != NULL)
10616 unsigned long * lengths;
10617 unsigned long * counts;
10619 unsigned long maxlength = 0;
10620 unsigned long nzero_counts = 0;
10621 unsigned long nsyms = 0;
10623 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
10624 (unsigned long) ngnubuckets);
10626 lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
10627 if (lengths == NULL)
10629 error (_("Out of memory allocating space for gnu histogram buckets\n"));
10633 printf (_(" Length Number %% of total Coverage\n"));
10635 for (hn = 0; hn < ngnubuckets; ++hn)
10636 if (gnubuckets[hn] != 0)
10638 bfd_vma off, length = 1;
10640 for (off = gnubuckets[hn] - gnusymidx;
10641 /* PR 17531 file: 010-77222-0.004. */
10642 off < ngnuchains && (gnuchains[off] & 1) == 0;
10645 lengths[hn] = length;
10646 if (length > maxlength)
10647 maxlength = length;
10651 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
10652 if (counts == NULL)
10655 error (_("Out of memory allocating space for gnu histogram counts\n"));
10659 for (hn = 0; hn < ngnubuckets; ++hn)
10660 ++counts[lengths[hn]];
10662 if (ngnubuckets > 0)
10665 printf (" 0 %-10lu (%5.1f%%)\n",
10666 counts[0], (counts[0] * 100.0) / ngnubuckets);
10667 for (j = 1; j <= maxlength; ++j)
10669 nzero_counts += counts[j] * j;
10670 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
10671 j, counts[j], (counts[j] * 100.0) / ngnubuckets,
10672 (nzero_counts * 100.0) / nsyms);
10686 process_syminfo (FILE * file ATTRIBUTE_UNUSED)
10690 if (dynamic_syminfo == NULL
10692 /* No syminfo, this is ok. */
10695 /* There better should be a dynamic symbol section. */
10696 if (dynamic_symbols == NULL || dynamic_strings == NULL)
10700 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
10701 dynamic_syminfo_offset, dynamic_syminfo_nent);
10703 printf (_(" Num: Name BoundTo Flags\n"));
10704 for (i = 0; i < dynamic_syminfo_nent; ++i)
10706 unsigned short int flags = dynamic_syminfo[i].si_flags;
10708 printf ("%4d: ", i);
10709 if (i >= num_dynamic_syms)
10710 printf (_("<corrupt index>"));
10711 else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
10712 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
10714 printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
10717 switch (dynamic_syminfo[i].si_boundto)
10719 case SYMINFO_BT_SELF:
10720 fputs ("SELF ", stdout);
10722 case SYMINFO_BT_PARENT:
10723 fputs ("PARENT ", stdout);
10726 if (dynamic_syminfo[i].si_boundto > 0
10727 && dynamic_syminfo[i].si_boundto < dynamic_nent
10728 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
10730 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
10734 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
10738 if (flags & SYMINFO_FLG_DIRECT)
10739 printf (" DIRECT");
10740 if (flags & SYMINFO_FLG_PASSTHRU)
10741 printf (" PASSTHRU");
10742 if (flags & SYMINFO_FLG_COPY)
10744 if (flags & SYMINFO_FLG_LAZYLOAD)
10745 printf (" LAZYLOAD");
10753 /* Check to see if the given reloc needs to be handled in a target specific
10754 manner. If so then process the reloc and return TRUE otherwise return
10758 target_specific_reloc_handling (Elf_Internal_Rela * reloc,
10759 unsigned char * start,
10760 Elf_Internal_Sym * symtab)
10762 unsigned int reloc_type = get_reloc_type (reloc->r_info);
10764 switch (elf_header.e_machine)
10767 case EM_MSP430_OLD:
10769 static Elf_Internal_Sym * saved_sym = NULL;
10771 switch (reloc_type)
10773 case 10: /* R_MSP430_SYM_DIFF */
10774 if (uses_msp430x_relocs ())
10776 case 21: /* R_MSP430X_SYM_DIFF */
10777 saved_sym = symtab + get_reloc_symindex (reloc->r_info);
10780 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
10781 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
10782 goto handle_sym_diff;
10784 case 5: /* R_MSP430_16_BYTE */
10785 case 9: /* R_MSP430_8 */
10786 if (uses_msp430x_relocs ())
10788 goto handle_sym_diff;
10790 case 2: /* R_MSP430_ABS16 */
10791 case 15: /* R_MSP430X_ABS16 */
10792 if (! uses_msp430x_relocs ())
10794 goto handle_sym_diff;
10797 if (saved_sym != NULL)
10801 value = reloc->r_addend
10802 + (symtab[get_reloc_symindex (reloc->r_info)].st_value
10803 - saved_sym->st_value);
10805 byte_put (start + reloc->r_offset, value, reloc_type == 1 ? 4 : 2);
10813 if (saved_sym != NULL)
10814 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
10821 case EM_CYGNUS_MN10300:
10823 static Elf_Internal_Sym * saved_sym = NULL;
10825 switch (reloc_type)
10827 case 34: /* R_MN10300_ALIGN */
10829 case 33: /* R_MN10300_SYM_DIFF */
10830 saved_sym = symtab + get_reloc_symindex (reloc->r_info);
10832 case 1: /* R_MN10300_32 */
10833 case 2: /* R_MN10300_16 */
10834 if (saved_sym != NULL)
10838 value = reloc->r_addend
10839 + (symtab[get_reloc_symindex (reloc->r_info)].st_value
10840 - saved_sym->st_value);
10842 byte_put (start + reloc->r_offset, value, reloc_type == 1 ? 4 : 2);
10849 if (saved_sym != NULL)
10850 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
10860 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
10861 DWARF debug sections. This is a target specific test. Note - we do not
10862 go through the whole including-target-headers-multiple-times route, (as
10863 we have already done with <elf/h8.h>) because this would become very
10864 messy and even then this function would have to contain target specific
10865 information (the names of the relocs instead of their numeric values).
10866 FIXME: This is not the correct way to solve this problem. The proper way
10867 is to have target specific reloc sizing and typing functions created by
10868 the reloc-macros.h header, in the same way that it already creates the
10869 reloc naming functions. */
10872 is_32bit_abs_reloc (unsigned int reloc_type)
10874 switch (elf_header.e_machine)
10878 return reloc_type == 1; /* R_386_32. */
10880 return reloc_type == 1; /* R_68K_32. */
10882 return reloc_type == 1; /* R_860_32. */
10884 return reloc_type == 2; /* R_960_32. */
10886 return reloc_type == 258; /* R_AARCH64_ABS32 */
10888 return reloc_type == 1; /* R_ALPHA_REFLONG. */
10890 return reloc_type == 1; /* R_ARC_32. */
10892 return reloc_type == 2; /* R_ARM_ABS32 */
10895 return reloc_type == 1;
10896 case EM_ADAPTEVA_EPIPHANY:
10897 return reloc_type == 3;
10899 return reloc_type == 0x12; /* R_byte4_data. */
10901 return reloc_type == 3; /* R_CRIS_32. */
10903 return reloc_type == 3; /* R_CR16_NUM32. */
10905 return reloc_type == 15; /* R_CRX_NUM32. */
10906 case EM_CYGNUS_FRV:
10907 return reloc_type == 1;
10908 case EM_CYGNUS_D10V:
10910 return reloc_type == 6; /* R_D10V_32. */
10911 case EM_CYGNUS_D30V:
10913 return reloc_type == 12; /* R_D30V_32_NORMAL. */
10915 return reloc_type == 3; /* R_DLX_RELOC_32. */
10916 case EM_CYGNUS_FR30:
10918 return reloc_type == 3; /* R_FR30_32. */
10922 return reloc_type == 1; /* R_H8_DIR32. */
10924 return reloc_type == 0x65; /* R_IA64_SECREL32LSB. */
10927 return reloc_type == 2; /* R_IP2K_32. */
10929 return reloc_type == 2; /* R_IQ2000_32. */
10930 case EM_LATTICEMICO32:
10931 return reloc_type == 3; /* R_LM32_32. */
10934 return reloc_type == 3; /* R_M32C_32. */
10936 return reloc_type == 34; /* R_M32R_32_RELA. */
10938 return reloc_type == 1; /* R_MCORE_ADDR32. */
10939 case EM_CYGNUS_MEP:
10940 return reloc_type == 4; /* R_MEP_32. */
10942 return reloc_type == 2; /* R_METAG_ADDR32. */
10943 case EM_MICROBLAZE:
10944 return reloc_type == 1; /* R_MICROBLAZE_32. */
10946 return reloc_type == 2; /* R_MIPS_32. */
10948 return reloc_type == 4; /* R_MMIX_32. */
10949 case EM_CYGNUS_MN10200:
10951 return reloc_type == 1; /* R_MN10200_32. */
10952 case EM_CYGNUS_MN10300:
10954 return reloc_type == 1; /* R_MN10300_32. */
10956 return reloc_type == 1; /* R_MOXIE_32. */
10957 case EM_MSP430_OLD:
10959 return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */
10961 return reloc_type == 2; /* R_MT_32. */
10963 return reloc_type == 20; /* R_NDS32_RELA. */
10964 case EM_ALTERA_NIOS2:
10965 return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
10967 return reloc_type == 1; /* R_NIOS_32. */
10969 return reloc_type == 1; /* R_OR1K_32. */
10971 return (reloc_type == 1 /* R_PARISC_DIR32. */
10972 || reloc_type == 41); /* R_PARISC_SECREL32. */
10975 return reloc_type == 1; /* R_PJ_DATA_DIR32. */
10977 return reloc_type == 1; /* R_PPC64_ADDR32. */
10979 return reloc_type == 1; /* R_PPC_ADDR32. */
10981 return reloc_type == 1; /* R_RL78_DIR32. */
10983 return reloc_type == 1; /* R_RX_DIR32. */
10985 return reloc_type == 1; /* R_I370_ADDR31. */
10988 return reloc_type == 4; /* R_S390_32. */
10990 return reloc_type == 8; /* R_SCORE_ABS32. */
10992 return reloc_type == 1; /* R_SH_DIR32. */
10993 case EM_SPARC32PLUS:
10996 return reloc_type == 3 /* R_SPARC_32. */
10997 || reloc_type == 23; /* R_SPARC_UA32. */
10999 return reloc_type == 6; /* R_SPU_ADDR32 */
11001 return reloc_type == 1; /* R_C6000_ABS32. */
11003 return reloc_type == 2; /* R_TILEGX_32. */
11005 return reloc_type == 1; /* R_TILEPRO_32. */
11006 case EM_CYGNUS_V850:
11008 return reloc_type == 6; /* R_V850_ABS32. */
11010 return reloc_type == 0x33; /* R_V810_WORD. */
11012 return reloc_type == 1; /* R_VAX_32. */
11016 return reloc_type == 10; /* R_X86_64_32. */
11019 return reloc_type == 3; /* R_XC16C_ABS_32. */
11021 return reloc_type == 4; /* R_XGATE_32. */
11023 return reloc_type == 1; /* R_XSTROMY16_32. */
11024 case EM_XTENSA_OLD:
11026 return reloc_type == 1; /* R_XTENSA_32. */
11028 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
11029 elf_header.e_machine);
11034 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
11035 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
11038 is_32bit_pcrel_reloc (unsigned int reloc_type)
11040 switch (elf_header.e_machine)
11044 return reloc_type == 2; /* R_386_PC32. */
11046 return reloc_type == 4; /* R_68K_PC32. */
11048 return reloc_type == 261; /* R_AARCH64_PREL32 */
11049 case EM_ADAPTEVA_EPIPHANY:
11050 return reloc_type == 6;
11052 return reloc_type == 10; /* R_ALPHA_SREL32. */
11054 return reloc_type == 3; /* R_ARM_REL32 */
11055 case EM_MICROBLAZE:
11056 return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */
11058 return reloc_type == 9; /* R_OR1K_32_PCREL. */
11060 return reloc_type == 9; /* R_PARISC_PCREL32. */
11062 return reloc_type == 26; /* R_PPC_REL32. */
11064 return reloc_type == 26; /* R_PPC64_REL32. */
11067 return reloc_type == 5; /* R_390_PC32. */
11069 return reloc_type == 2; /* R_SH_REL32. */
11070 case EM_SPARC32PLUS:
11073 return reloc_type == 6; /* R_SPARC_DISP32. */
11075 return reloc_type == 13; /* R_SPU_REL32. */
11077 return reloc_type == 6; /* R_TILEGX_32_PCREL. */
11079 return reloc_type == 4; /* R_TILEPRO_32_PCREL. */
11083 return reloc_type == 2; /* R_X86_64_PC32. */
11084 case EM_XTENSA_OLD:
11086 return reloc_type == 14; /* R_XTENSA_32_PCREL. */
11088 /* Do not abort or issue an error message here. Not all targets use
11089 pc-relative 32-bit relocs in their DWARF debug information and we
11090 have already tested for target coverage in is_32bit_abs_reloc. A
11091 more helpful warning message will be generated by apply_relocations
11092 anyway, so just return. */
11097 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
11098 a 64-bit absolute RELA relocation used in DWARF debug sections. */
11101 is_64bit_abs_reloc (unsigned int reloc_type)
11103 switch (elf_header.e_machine)
11106 return reloc_type == 257; /* R_AARCH64_ABS64. */
11108 return reloc_type == 2; /* R_ALPHA_REFQUAD. */
11110 return reloc_type == 0x27; /* R_IA64_DIR64LSB. */
11112 return reloc_type == 80; /* R_PARISC_DIR64. */
11114 return reloc_type == 38; /* R_PPC64_ADDR64. */
11115 case EM_SPARC32PLUS:
11118 return reloc_type == 54; /* R_SPARC_UA64. */
11122 return reloc_type == 1; /* R_X86_64_64. */
11125 return reloc_type == 22; /* R_S390_64. */
11127 return reloc_type == 1; /* R_TILEGX_64. */
11129 return reloc_type == 18; /* R_MIPS_64. */
11135 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
11136 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
11139 is_64bit_pcrel_reloc (unsigned int reloc_type)
11141 switch (elf_header.e_machine)
11144 return reloc_type == 260; /* R_AARCH64_PREL64. */
11146 return reloc_type == 11; /* R_ALPHA_SREL64. */
11148 return reloc_type == 0x4f; /* R_IA64_PCREL64LSB. */
11150 return reloc_type == 72; /* R_PARISC_PCREL64. */
11152 return reloc_type == 44; /* R_PPC64_REL64. */
11153 case EM_SPARC32PLUS:
11156 return reloc_type == 46; /* R_SPARC_DISP64. */
11160 return reloc_type == 24; /* R_X86_64_PC64. */
11163 return reloc_type == 23; /* R_S390_PC64. */
11165 return reloc_type == 5; /* R_TILEGX_64_PCREL. */
11171 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
11172 a 24-bit absolute RELA relocation used in DWARF debug sections. */
11175 is_24bit_abs_reloc (unsigned int reloc_type)
11177 switch (elf_header.e_machine)
11179 case EM_CYGNUS_MN10200:
11181 return reloc_type == 4; /* R_MN10200_24. */
11187 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
11188 a 16-bit absolute RELA relocation used in DWARF debug sections. */
11191 is_16bit_abs_reloc (unsigned int reloc_type)
11193 switch (elf_header.e_machine)
11197 return reloc_type == 4; /* R_AVR_16. */
11198 case EM_ADAPTEVA_EPIPHANY:
11199 return reloc_type == 5;
11200 case EM_CYGNUS_D10V:
11202 return reloc_type == 3; /* R_D10V_16. */
11206 return reloc_type == R_H8_DIR16;
11209 return reloc_type == 1; /* R_IP2K_16. */
11212 return reloc_type == 1; /* R_M32C_16 */
11214 if (uses_msp430x_relocs ())
11215 return reloc_type == 2; /* R_MSP430_ABS16. */
11216 case EM_MSP430_OLD:
11217 return reloc_type == 5; /* R_MSP430_16_BYTE. */
11219 return reloc_type == 19; /* R_NDS32_RELA. */
11220 case EM_ALTERA_NIOS2:
11221 return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
11223 return reloc_type == 9; /* R_NIOS_16. */
11225 return reloc_type == 2; /* R_OR1K_16. */
11227 return reloc_type == 2; /* R_C6000_ABS16. */
11230 return reloc_type == 2; /* R_XC16C_ABS_16. */
11231 case EM_CYGNUS_MN10200:
11233 return reloc_type == 2; /* R_MN10200_16. */
11234 case EM_CYGNUS_MN10300:
11236 return reloc_type == 2; /* R_MN10300_16. */
11238 return reloc_type == 3; /* R_XGATE_16. */
11244 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
11245 relocation entries (possibly formerly used for SHT_GROUP sections). */
11248 is_none_reloc (unsigned int reloc_type)
11250 switch (elf_header.e_machine)
11252 case EM_68K: /* R_68K_NONE. */
11253 case EM_386: /* R_386_NONE. */
11254 case EM_SPARC32PLUS:
11256 case EM_SPARC: /* R_SPARC_NONE. */
11257 case EM_MIPS: /* R_MIPS_NONE. */
11258 case EM_PARISC: /* R_PARISC_NONE. */
11259 case EM_ALPHA: /* R_ALPHA_NONE. */
11260 case EM_ADAPTEVA_EPIPHANY:
11261 case EM_PPC: /* R_PPC_NONE. */
11262 case EM_PPC64: /* R_PPC64_NONE. */
11263 case EM_ARM: /* R_ARM_NONE. */
11264 case EM_IA_64: /* R_IA64_NONE. */
11265 case EM_SH: /* R_SH_NONE. */
11267 case EM_S390: /* R_390_NONE. */
11268 case EM_CRIS: /* R_CRIS_NONE. */
11269 case EM_X86_64: /* R_X86_64_NONE. */
11270 case EM_L1OM: /* R_X86_64_NONE. */
11271 case EM_K1OM: /* R_X86_64_NONE. */
11272 case EM_MN10300: /* R_MN10300_NONE. */
11273 case EM_MOXIE: /* R_MOXIE_NONE. */
11274 case EM_M32R: /* R_M32R_NONE. */
11275 case EM_TI_C6000:/* R_C6000_NONE. */
11276 case EM_TILEGX: /* R_TILEGX_NONE. */
11277 case EM_TILEPRO: /* R_TILEPRO_NONE. */
11279 case EM_C166: /* R_XC16X_NONE. */
11280 case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
11281 case EM_NIOS32: /* R_NIOS_NONE. */
11282 case EM_OR1K: /* R_OR1K_NONE. */
11283 return reloc_type == 0;
11285 return reloc_type == 0 || reloc_type == 256;
11287 return (reloc_type == 0 /* R_XTENSA_NONE. */
11288 || reloc_type == 204 /* R_NDS32_DIFF8. */
11289 || reloc_type == 205 /* R_NDS32_DIFF16. */
11290 || reloc_type == 206 /* R_NDS32_DIFF32. */
11291 || reloc_type == 207 /* R_NDS32_ULEB128. */);
11292 case EM_XTENSA_OLD:
11294 return (reloc_type == 0 /* R_XTENSA_NONE. */
11295 || reloc_type == 17 /* R_XTENSA_DIFF8. */
11296 || reloc_type == 18 /* R_XTENSA_DIFF16. */
11297 || reloc_type == 19 /* R_XTENSA_DIFF32. */);
11299 return reloc_type == 3; /* R_METAG_NONE. */
11304 /* Apply relocations to a section.
11305 Note: So far support has been added only for those relocations
11306 which can be found in debug sections.
11307 FIXME: Add support for more relocations ? */
11310 apply_relocations (void * file,
11311 Elf_Internal_Shdr * section,
11312 unsigned char * start)
11314 Elf_Internal_Shdr * relsec;
11315 unsigned char * end = start + section->sh_size;
11317 if (elf_header.e_type != ET_REL)
11320 /* Find the reloc section associated with the section. */
11321 for (relsec = section_headers;
11322 relsec < section_headers + elf_header.e_shnum;
11325 bfd_boolean is_rela;
11326 unsigned long num_relocs;
11327 Elf_Internal_Rela * relocs;
11328 Elf_Internal_Rela * rp;
11329 Elf_Internal_Shdr * symsec;
11330 Elf_Internal_Sym * symtab;
11331 unsigned long num_syms;
11332 Elf_Internal_Sym * sym;
11334 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
11335 || relsec->sh_info >= elf_header.e_shnum
11336 || section_headers + relsec->sh_info != section
11337 || relsec->sh_size == 0
11338 || relsec->sh_link >= elf_header.e_shnum)
11341 is_rela = relsec->sh_type == SHT_RELA;
11345 if (!slurp_rela_relocs ((FILE *) file, relsec->sh_offset,
11346 relsec->sh_size, & relocs, & num_relocs))
11351 if (!slurp_rel_relocs ((FILE *) file, relsec->sh_offset,
11352 relsec->sh_size, & relocs, & num_relocs))
11356 /* SH uses RELA but uses in place value instead of the addend field. */
11357 if (elf_header.e_machine == EM_SH)
11360 symsec = section_headers + relsec->sh_link;
11361 symtab = GET_ELF_SYMBOLS ((FILE *) file, symsec, & num_syms);
11363 for (rp = relocs; rp < relocs + num_relocs; ++rp)
11366 unsigned int reloc_type;
11367 unsigned int reloc_size;
11368 unsigned char * rloc;
11369 unsigned long sym_index;
11371 reloc_type = get_reloc_type (rp->r_info);
11373 if (target_specific_reloc_handling (rp, start, symtab))
11375 else if (is_none_reloc (reloc_type))
11377 else if (is_32bit_abs_reloc (reloc_type)
11378 || is_32bit_pcrel_reloc (reloc_type))
11380 else if (is_64bit_abs_reloc (reloc_type)
11381 || is_64bit_pcrel_reloc (reloc_type))
11383 else if (is_24bit_abs_reloc (reloc_type))
11385 else if (is_16bit_abs_reloc (reloc_type))
11389 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
11390 reloc_type, printable_section_name (section));
11394 rloc = start + rp->r_offset;
11395 if ((rloc + reloc_size) > end || (rloc < start))
11397 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
11398 (unsigned long) rp->r_offset,
11399 printable_section_name (section));
11403 sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
11404 if (sym_index >= num_syms)
11406 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
11407 sym_index, printable_section_name (section));
11410 sym = symtab + sym_index;
11412 /* If the reloc has a symbol associated with it,
11413 make sure that it is of an appropriate type.
11415 Relocations against symbols without type can happen.
11416 Gcc -feliminate-dwarf2-dups may generate symbols
11417 without type for debug info.
11419 Icc generates relocations against function symbols
11420 instead of local labels.
11422 Relocations against object symbols can happen, eg when
11423 referencing a global array. For an example of this see
11424 the _clz.o binary in libgcc.a. */
11426 && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
11428 warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
11429 get_symbol_type (ELF_ST_TYPE (sym->st_info)),
11430 (long int)(rp - relocs),
11431 printable_section_name (relsec));
11437 addend += rp->r_addend;
11438 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
11439 partial_inplace. */
11441 || (elf_header.e_machine == EM_XTENSA
11442 && reloc_type == 1)
11443 || ((elf_header.e_machine == EM_PJ
11444 || elf_header.e_machine == EM_PJ_OLD)
11445 && reloc_type == 1)
11446 || ((elf_header.e_machine == EM_D30V
11447 || elf_header.e_machine == EM_CYGNUS_D30V)
11448 && reloc_type == 12))
11449 addend += byte_get (rloc, reloc_size);
11451 if (is_32bit_pcrel_reloc (reloc_type)
11452 || is_64bit_pcrel_reloc (reloc_type))
11454 /* On HPPA, all pc-relative relocations are biased by 8. */
11455 if (elf_header.e_machine == EM_PARISC)
11457 byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
11461 byte_put (rloc, addend + sym->st_value, reloc_size);
11470 #ifdef SUPPORT_DISASSEMBLY
11472 disassemble_section (Elf_Internal_Shdr * section, FILE * file)
11474 printf (_("\nAssembly dump of section %s\n"), printable_section_name (section));
11476 /* FIXME: XXX -- to be done --- XXX */
11482 /* Reads in the contents of SECTION from FILE, returning a pointer
11483 to a malloc'ed buffer or NULL if something went wrong. */
11486 get_section_contents (Elf_Internal_Shdr * section, FILE * file)
11488 bfd_size_type num_bytes;
11490 num_bytes = section->sh_size;
11492 if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
11494 printf (_("\nSection '%s' has no data to dump.\n"),
11495 printable_section_name (section));
11499 return (char *) get_data (NULL, file, section->sh_offset, 1, num_bytes,
11500 _("section contents"));
11505 dump_section_as_strings (Elf_Internal_Shdr * section, FILE * file)
11507 Elf_Internal_Shdr * relsec;
11508 bfd_size_type num_bytes;
11512 bfd_boolean some_strings_shown;
11514 start = get_section_contents (section, file);
11518 printf (_("\nString dump of section '%s':\n"), printable_section_name (section));
11520 /* If the section being dumped has relocations against it the user might
11521 be expecting these relocations to have been applied. Check for this
11522 case and issue a warning message in order to avoid confusion.
11523 FIXME: Maybe we ought to have an option that dumps a section with
11524 relocs applied ? */
11525 for (relsec = section_headers;
11526 relsec < section_headers + elf_header.e_shnum;
11529 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
11530 || relsec->sh_info >= elf_header.e_shnum
11531 || section_headers + relsec->sh_info != section
11532 || relsec->sh_size == 0
11533 || relsec->sh_link >= elf_header.e_shnum)
11536 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
11540 num_bytes = section->sh_size;
11542 end = start + num_bytes;
11543 some_strings_shown = FALSE;
11547 while (!ISPRINT (* data))
11548 if (++ data >= end)
11553 size_t maxlen = end - data;
11556 /* PR 11128: Use two separate invocations in order to work
11557 around bugs in the Solaris 8 implementation of printf. */
11558 printf (" [%6tx] ", data - start);
11560 printf (" [%6Ix] ", (size_t) (data - start));
11564 print_symbol ((int) maxlen, data);
11566 data += strnlen (data, maxlen);
11570 printf (_("<corrupt>\n"));
11573 some_strings_shown = TRUE;
11577 if (! some_strings_shown)
11578 printf (_(" No strings found in this section."));
11586 dump_section_as_bytes (Elf_Internal_Shdr * section,
11588 bfd_boolean relocate)
11590 Elf_Internal_Shdr * relsec;
11591 bfd_size_type bytes;
11593 unsigned char * data;
11594 unsigned char * start;
11596 start = (unsigned char *) get_section_contents (section, file);
11600 printf (_("\nHex dump of section '%s':\n"), printable_section_name (section));
11604 apply_relocations (file, section, start);
11608 /* If the section being dumped has relocations against it the user might
11609 be expecting these relocations to have been applied. Check for this
11610 case and issue a warning message in order to avoid confusion.
11611 FIXME: Maybe we ought to have an option that dumps a section with
11612 relocs applied ? */
11613 for (relsec = section_headers;
11614 relsec < section_headers + elf_header.e_shnum;
11617 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
11618 || relsec->sh_info >= elf_header.e_shnum
11619 || section_headers + relsec->sh_info != section
11620 || relsec->sh_size == 0
11621 || relsec->sh_link >= elf_header.e_shnum)
11624 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
11629 addr = section->sh_addr;
11630 bytes = section->sh_size;
11639 lbytes = (bytes > 16 ? 16 : bytes);
11641 printf (" 0x%8.8lx ", (unsigned long) addr);
11643 for (j = 0; j < 16; j++)
11646 printf ("%2.2x", data[j]);
11654 for (j = 0; j < lbytes; j++)
11657 if (k >= ' ' && k < 0x7f)
11675 /* Uncompresses a section that was compressed using zlib, in place. */
11678 uncompress_section_contents (unsigned char **buffer ATTRIBUTE_UNUSED,
11679 dwarf_size_type *size ATTRIBUTE_UNUSED)
11681 #ifndef HAVE_ZLIB_H
11684 dwarf_size_type compressed_size = *size;
11685 unsigned char * compressed_buffer = *buffer;
11686 dwarf_size_type uncompressed_size;
11687 unsigned char * uncompressed_buffer;
11690 dwarf_size_type header_size = 12;
11692 /* Read the zlib header. In this case, it should be "ZLIB" followed
11693 by the uncompressed section size, 8 bytes in big-endian order. */
11694 if (compressed_size < header_size
11695 || ! streq ((char *) compressed_buffer, "ZLIB"))
11698 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
11699 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
11700 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
11701 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
11702 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
11703 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
11704 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
11705 uncompressed_size += compressed_buffer[11];
11707 /* It is possible the section consists of several compressed
11708 buffers concatenated together, so we uncompress in a loop. */
11709 strm.zalloc = NULL;
11711 strm.opaque = NULL;
11712 strm.avail_in = compressed_size - header_size;
11713 strm.next_in = (Bytef *) compressed_buffer + header_size;
11714 strm.avail_out = uncompressed_size;
11715 uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
11717 rc = inflateInit (& strm);
11718 while (strm.avail_in > 0)
11722 strm.next_out = ((Bytef *) uncompressed_buffer
11723 + (uncompressed_size - strm.avail_out));
11724 rc = inflate (&strm, Z_FINISH);
11725 if (rc != Z_STREAM_END)
11727 rc = inflateReset (& strm);
11729 rc = inflateEnd (& strm);
11731 || strm.avail_out != 0)
11734 free (compressed_buffer);
11735 *buffer = uncompressed_buffer;
11736 *size = uncompressed_size;
11740 free (uncompressed_buffer);
11741 /* Indicate decompression failure. */
11744 #endif /* HAVE_ZLIB_H */
11748 load_specific_debug_section (enum dwarf_section_display_enum debug,
11749 Elf_Internal_Shdr * sec, void * file)
11751 struct dwarf_section * section = &debug_displays [debug].section;
11754 /* If it is already loaded, do nothing. */
11755 if (section->start != NULL)
11758 snprintf (buf, sizeof (buf), _("%s section data"), section->name);
11759 section->address = sec->sh_addr;
11760 section->start = (unsigned char *) get_data (NULL, (FILE *) file,
11762 sec->sh_size, buf);
11763 if (section->start == NULL)
11767 section->size = sec->sh_size;
11768 if (uncompress_section_contents (§ion->start, §ion->size))
11769 sec->sh_size = section->size;
11772 if (section->start == NULL)
11775 if (debug_displays [debug].relocate)
11776 apply_relocations ((FILE *) file, sec, section->start);
11781 /* If this is not NULL, load_debug_section will only look for sections
11782 within the list of sections given here. */
11783 unsigned int *section_subset = NULL;
11786 load_debug_section (enum dwarf_section_display_enum debug, void * file)
11788 struct dwarf_section * section = &debug_displays [debug].section;
11789 Elf_Internal_Shdr * sec;
11791 /* Locate the debug section. */
11792 sec = find_section_in_set (section->uncompressed_name, section_subset);
11794 section->name = section->uncompressed_name;
11797 sec = find_section_in_set (section->compressed_name, section_subset);
11799 section->name = section->compressed_name;
11804 /* If we're loading from a subset of sections, and we've loaded
11805 a section matching this name before, it's likely that it's a
11807 if (section_subset != NULL)
11808 free_debug_section (debug);
11810 return load_specific_debug_section (debug, sec, (FILE *) file);
11814 free_debug_section (enum dwarf_section_display_enum debug)
11816 struct dwarf_section * section = &debug_displays [debug].section;
11818 if (section->start == NULL)
11821 free ((char *) section->start);
11822 section->start = NULL;
11823 section->address = 0;
11828 display_debug_section (int shndx, Elf_Internal_Shdr * section, FILE * file)
11830 char * name = SECTION_NAME (section);
11831 const char * print_name = printable_section_name (section);
11832 bfd_size_type length;
11836 length = section->sh_size;
11839 printf (_("\nSection '%s' has no debugging data.\n"), print_name);
11842 if (section->sh_type == SHT_NOBITS)
11844 /* There is no point in dumping the contents of a debugging section
11845 which has the NOBITS type - the bits in the file will be random.
11846 This can happen when a file containing a .eh_frame section is
11847 stripped with the --only-keep-debug command line option. */
11848 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
11853 if (const_strneq (name, ".gnu.linkonce.wi."))
11854 name = ".debug_info";
11856 /* See if we know how to display the contents of this section. */
11857 for (i = 0; i < max; i++)
11858 if (streq (debug_displays[i].section.uncompressed_name, name)
11859 || (i == line && const_strneq (name, ".debug_line."))
11860 || streq (debug_displays[i].section.compressed_name, name))
11862 struct dwarf_section * sec = &debug_displays [i].section;
11863 int secondary = (section != find_section (name));
11866 free_debug_section ((enum dwarf_section_display_enum) i);
11868 if (i == line && const_strneq (name, ".debug_line."))
11870 else if (streq (sec->uncompressed_name, name))
11871 sec->name = sec->uncompressed_name;
11873 sec->name = sec->compressed_name;
11874 if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
11877 /* If this debug section is part of a CU/TU set in a .dwp file,
11878 restrict load_debug_section to the sections in that set. */
11879 section_subset = find_cu_tu_set (file, shndx);
11881 result &= debug_displays[i].display (sec, file);
11883 section_subset = NULL;
11885 if (secondary || (i != info && i != abbrev))
11886 free_debug_section ((enum dwarf_section_display_enum) i);
11894 printf (_("Unrecognized debug section: %s\n"), print_name);
11901 /* Set DUMP_SECTS for all sections where dumps were requested
11902 based on section name. */
11905 initialise_dumps_byname (void)
11907 struct dump_list_entry * cur;
11909 for (cur = dump_sects_byname; cur; cur = cur->next)
11914 for (i = 0, any = 0; i < elf_header.e_shnum; i++)
11915 if (streq (SECTION_NAME (section_headers + i), cur->name))
11917 request_dump_bynumber (i, cur->type);
11922 warn (_("Section '%s' was not dumped because it does not exist!\n"),
11928 process_section_contents (FILE * file)
11930 Elf_Internal_Shdr * section;
11936 initialise_dumps_byname ();
11938 for (i = 0, section = section_headers;
11939 i < elf_header.e_shnum && i < num_dump_sects;
11942 #ifdef SUPPORT_DISASSEMBLY
11943 if (dump_sects[i] & DISASS_DUMP)
11944 disassemble_section (section, file);
11946 if (dump_sects[i] & HEX_DUMP)
11947 dump_section_as_bytes (section, file, FALSE);
11949 if (dump_sects[i] & RELOC_DUMP)
11950 dump_section_as_bytes (section, file, TRUE);
11952 if (dump_sects[i] & STRING_DUMP)
11953 dump_section_as_strings (section, file);
11955 if (dump_sects[i] & DEBUG_DUMP)
11956 display_debug_section (i, section, file);
11959 /* Check to see if the user requested a
11960 dump of a section that does not exist. */
11961 while (i++ < num_dump_sects)
11963 warn (_("Section %d was not dumped because it does not exist!\n"), i);
11967 process_mips_fpe_exception (int mask)
11972 if (mask & OEX_FPU_INEX)
11973 fputs ("INEX", stdout), first = 0;
11974 if (mask & OEX_FPU_UFLO)
11975 printf ("%sUFLO", first ? "" : "|"), first = 0;
11976 if (mask & OEX_FPU_OFLO)
11977 printf ("%sOFLO", first ? "" : "|"), first = 0;
11978 if (mask & OEX_FPU_DIV0)
11979 printf ("%sDIV0", first ? "" : "|"), first = 0;
11980 if (mask & OEX_FPU_INVAL)
11981 printf ("%sINVAL", first ? "" : "|");
11984 fputs ("0", stdout);
11987 /* Display's the value of TAG at location P. If TAG is
11988 greater than 0 it is assumed to be an unknown tag, and
11989 a message is printed to this effect. Otherwise it is
11990 assumed that a message has already been printed.
11992 If the bottom bit of TAG is set it assumed to have a
11993 string value, otherwise it is assumed to have an integer
11996 Returns an updated P pointing to the first unread byte
11997 beyond the end of TAG's value.
11999 Reads at or beyond END will not be made. */
12001 static unsigned char *
12002 display_tag_value (int tag,
12004 const unsigned char * const end)
12009 printf (" Tag_unknown_%d: ", tag);
12013 warn (_("<corrupt tag>\n"));
12017 /* PR 17531 file: 027-19978-0.004. */
12018 size_t maxlen = (end - p) - 1;
12023 print_symbol ((int) maxlen, (const char *) p);
12024 p += strnlen ((char *) p, maxlen) + 1;
12028 printf (_("<corrupt string tag>"));
12029 p = (unsigned char *) end;
12037 val = read_uleb128 (p, &len, end);
12039 printf ("%ld (0x%lx)\n", val, val);
12046 /* ARM EABI attributes section. */
12051 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
12053 const char ** table;
12054 } arm_attr_public_tag;
12056 static const char * arm_attr_tag_CPU_arch[] =
12057 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
12058 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8"};
12059 static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
12060 static const char * arm_attr_tag_THUMB_ISA_use[] =
12061 {"No", "Thumb-1", "Thumb-2"};
12062 static const char * arm_attr_tag_FP_arch[] =
12063 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
12065 static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
12066 static const char * arm_attr_tag_Advanced_SIMD_arch[] =
12067 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8"};
12068 static const char * arm_attr_tag_PCS_config[] =
12069 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
12070 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
12071 static const char * arm_attr_tag_ABI_PCS_R9_use[] =
12072 {"V6", "SB", "TLS", "Unused"};
12073 static const char * arm_attr_tag_ABI_PCS_RW_data[] =
12074 {"Absolute", "PC-relative", "SB-relative", "None"};
12075 static const char * arm_attr_tag_ABI_PCS_RO_data[] =
12076 {"Absolute", "PC-relative", "None"};
12077 static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
12078 {"None", "direct", "GOT-indirect"};
12079 static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
12080 {"None", "??? 1", "2", "??? 3", "4"};
12081 static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
12082 static const char * arm_attr_tag_ABI_FP_denormal[] =
12083 {"Unused", "Needed", "Sign only"};
12084 static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
12085 static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
12086 static const char * arm_attr_tag_ABI_FP_number_model[] =
12087 {"Unused", "Finite", "RTABI", "IEEE 754"};
12088 static const char * arm_attr_tag_ABI_enum_size[] =
12089 {"Unused", "small", "int", "forced to int"};
12090 static const char * arm_attr_tag_ABI_HardFP_use[] =
12091 {"As Tag_FP_arch", "SP only", "DP only", "SP and DP"};
12092 static const char * arm_attr_tag_ABI_VFP_args[] =
12093 {"AAPCS", "VFP registers", "custom"};
12094 static const char * arm_attr_tag_ABI_WMMX_args[] =
12095 {"AAPCS", "WMMX registers", "custom"};
12096 static const char * arm_attr_tag_ABI_optimization_goals[] =
12097 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
12098 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
12099 static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
12100 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
12101 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
12102 static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
12103 static const char * arm_attr_tag_FP_HP_extension[] =
12104 {"Not Allowed", "Allowed"};
12105 static const char * arm_attr_tag_ABI_FP_16bit_format[] =
12106 {"None", "IEEE 754", "Alternative Format"};
12107 static const char * arm_attr_tag_MPextension_use[] =
12108 {"Not Allowed", "Allowed"};
12109 static const char * arm_attr_tag_DIV_use[] =
12110 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
12111 "Allowed in v7-A with integer division extension"};
12112 static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
12113 static const char * arm_attr_tag_Virtualization_use[] =
12114 {"Not Allowed", "TrustZone", "Virtualization Extensions",
12115 "TrustZone and Virtualization Extensions"};
12116 static const char * arm_attr_tag_MPextension_use_legacy[] =
12117 {"Not Allowed", "Allowed"};
12119 #define LOOKUP(id, name) \
12120 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
12121 static arm_attr_public_tag arm_attr_public_tags[] =
12123 {4, "CPU_raw_name", 1, NULL},
12124 {5, "CPU_name", 1, NULL},
12125 LOOKUP(6, CPU_arch),
12126 {7, "CPU_arch_profile", 0, NULL},
12127 LOOKUP(8, ARM_ISA_use),
12128 LOOKUP(9, THUMB_ISA_use),
12129 LOOKUP(10, FP_arch),
12130 LOOKUP(11, WMMX_arch),
12131 LOOKUP(12, Advanced_SIMD_arch),
12132 LOOKUP(13, PCS_config),
12133 LOOKUP(14, ABI_PCS_R9_use),
12134 LOOKUP(15, ABI_PCS_RW_data),
12135 LOOKUP(16, ABI_PCS_RO_data),
12136 LOOKUP(17, ABI_PCS_GOT_use),
12137 LOOKUP(18, ABI_PCS_wchar_t),
12138 LOOKUP(19, ABI_FP_rounding),
12139 LOOKUP(20, ABI_FP_denormal),
12140 LOOKUP(21, ABI_FP_exceptions),
12141 LOOKUP(22, ABI_FP_user_exceptions),
12142 LOOKUP(23, ABI_FP_number_model),
12143 {24, "ABI_align_needed", 0, NULL},
12144 {25, "ABI_align_preserved", 0, NULL},
12145 LOOKUP(26, ABI_enum_size),
12146 LOOKUP(27, ABI_HardFP_use),
12147 LOOKUP(28, ABI_VFP_args),
12148 LOOKUP(29, ABI_WMMX_args),
12149 LOOKUP(30, ABI_optimization_goals),
12150 LOOKUP(31, ABI_FP_optimization_goals),
12151 {32, "compatibility", 0, NULL},
12152 LOOKUP(34, CPU_unaligned_access),
12153 LOOKUP(36, FP_HP_extension),
12154 LOOKUP(38, ABI_FP_16bit_format),
12155 LOOKUP(42, MPextension_use),
12156 LOOKUP(44, DIV_use),
12157 {64, "nodefaults", 0, NULL},
12158 {65, "also_compatible_with", 0, NULL},
12159 LOOKUP(66, T2EE_use),
12160 {67, "conformance", 1, NULL},
12161 LOOKUP(68, Virtualization_use),
12162 LOOKUP(70, MPextension_use_legacy)
12166 static unsigned char *
12167 display_arm_attribute (unsigned char * p,
12168 const unsigned char * const end)
12173 arm_attr_public_tag * attr;
12177 tag = read_uleb128 (p, &len, end);
12180 for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
12182 if (arm_attr_public_tags[i].tag == tag)
12184 attr = &arm_attr_public_tags[i];
12191 printf (" Tag_%s: ", attr->name);
12192 switch (attr->type)
12197 case 7: /* Tag_CPU_arch_profile. */
12198 val = read_uleb128 (p, &len, end);
12202 case 0: printf (_("None\n")); break;
12203 case 'A': printf (_("Application\n")); break;
12204 case 'R': printf (_("Realtime\n")); break;
12205 case 'M': printf (_("Microcontroller\n")); break;
12206 case 'S': printf (_("Application or Realtime\n")); break;
12207 default: printf ("??? (%d)\n", val); break;
12211 case 24: /* Tag_align_needed. */
12212 val = read_uleb128 (p, &len, end);
12216 case 0: printf (_("None\n")); break;
12217 case 1: printf (_("8-byte\n")); break;
12218 case 2: printf (_("4-byte\n")); break;
12219 case 3: printf ("??? 3\n"); break;
12222 printf (_("8-byte and up to %d-byte extended\n"),
12225 printf ("??? (%d)\n", val);
12230 case 25: /* Tag_align_preserved. */
12231 val = read_uleb128 (p, &len, end);
12235 case 0: printf (_("None\n")); break;
12236 case 1: printf (_("8-byte, except leaf SP\n")); break;
12237 case 2: printf (_("8-byte\n")); break;
12238 case 3: printf ("??? 3\n"); break;
12241 printf (_("8-byte and up to %d-byte extended\n"),
12244 printf ("??? (%d)\n", val);
12249 case 32: /* Tag_compatibility. */
12251 val = read_uleb128 (p, &len, end);
12253 printf (_("flag = %d, vendor = "), val);
12256 size_t maxlen = (end - p) - 1;
12258 print_symbol ((int) maxlen, (const char *) p);
12259 p += strnlen ((char *) p, maxlen) + 1;
12263 printf (_("<corrupt>"));
12264 p = (unsigned char *) end;
12270 case 64: /* Tag_nodefaults. */
12271 /* PR 17531: file: 001-505008-0.01. */
12274 printf (_("True\n"));
12277 case 65: /* Tag_also_compatible_with. */
12278 val = read_uleb128 (p, &len, end);
12280 if (val == 6 /* Tag_CPU_arch. */)
12282 val = read_uleb128 (p, &len, end);
12284 if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
12285 printf ("??? (%d)\n", val);
12287 printf ("%s\n", arm_attr_tag_CPU_arch[val]);
12291 while (p < end && *(p++) != '\0' /* NUL terminator. */)
12296 printf (_("<unknown: %d>\n"), tag);
12302 return display_tag_value (-1, p, end);
12304 return display_tag_value (0, p, end);
12307 assert (attr->type & 0x80);
12308 val = read_uleb128 (p, &len, end);
12310 type = attr->type & 0x7f;
12312 printf ("??? (%d)\n", val);
12314 printf ("%s\n", attr->table[val]);
12319 return display_tag_value (tag, p, end);
12322 static unsigned char *
12323 display_gnu_attribute (unsigned char * p,
12324 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int, const unsigned char * const),
12325 const unsigned char * const end)
12331 tag = read_uleb128 (p, &len, end);
12334 /* Tag_compatibility is the only generic GNU attribute defined at
12338 val = read_uleb128 (p, &len, end);
12341 printf (_("flag = %d, vendor = "), val);
12344 printf (_("<corrupt>\n"));
12345 warn (_("corrupt vendor attribute\n"));
12351 size_t maxlen = (end - p) - 1;
12353 print_symbol ((int) maxlen, (const char *) p);
12354 p += strnlen ((char *) p, maxlen) + 1;
12358 printf (_("<corrupt>"));
12359 p = (unsigned char *) end;
12366 if ((tag & 2) == 0 && display_proc_gnu_attribute)
12367 return display_proc_gnu_attribute (p, tag, end);
12369 return display_tag_value (tag, p, end);
12372 static unsigned char *
12373 display_power_gnu_attribute (unsigned char * p,
12375 const unsigned char * const end)
12380 if (tag == Tag_GNU_Power_ABI_FP)
12382 val = read_uleb128 (p, &len, end);
12384 printf (" Tag_GNU_Power_ABI_FP: ");
12389 printf (_("Hard or soft float\n"));
12392 printf (_("Hard float\n"));
12395 printf (_("Soft float\n"));
12398 printf (_("Single-precision hard float\n"));
12401 printf ("??? (%d)\n", val);
12407 if (tag == Tag_GNU_Power_ABI_Vector)
12409 val = read_uleb128 (p, &len, end);
12411 printf (" Tag_GNU_Power_ABI_Vector: ");
12415 printf (_("Any\n"));
12418 printf (_("Generic\n"));
12421 printf ("AltiVec\n");
12427 printf ("??? (%d)\n", val);
12433 if (tag == Tag_GNU_Power_ABI_Struct_Return)
12437 warn (_("corrupt Tag_GNU_Power_ABI_Struct_Return\n"));
12441 val = read_uleb128 (p, &len, end);
12443 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
12447 printf (_("Any\n"));
12450 printf ("r3/r4\n");
12453 printf (_("Memory\n"));
12456 printf ("??? (%d)\n", val);
12462 return display_tag_value (tag & 1, p, end);
12466 display_sparc_hwcaps (int mask)
12472 if (mask & ELF_SPARC_HWCAP_MUL32)
12473 fputs ("mul32", stdout), first = 0;
12474 if (mask & ELF_SPARC_HWCAP_DIV32)
12475 printf ("%sdiv32", first ? "" : "|"), first = 0;
12476 if (mask & ELF_SPARC_HWCAP_FSMULD)
12477 printf ("%sfsmuld", first ? "" : "|"), first = 0;
12478 if (mask & ELF_SPARC_HWCAP_V8PLUS)
12479 printf ("%sv8plus", first ? "" : "|"), first = 0;
12480 if (mask & ELF_SPARC_HWCAP_POPC)
12481 printf ("%spopc", first ? "" : "|"), first = 0;
12482 if (mask & ELF_SPARC_HWCAP_VIS)
12483 printf ("%svis", first ? "" : "|"), first = 0;
12484 if (mask & ELF_SPARC_HWCAP_VIS2)
12485 printf ("%svis2", first ? "" : "|"), first = 0;
12486 if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
12487 printf ("%sASIBlkInit", first ? "" : "|"), first = 0;
12488 if (mask & ELF_SPARC_HWCAP_FMAF)
12489 printf ("%sfmaf", first ? "" : "|"), first = 0;
12490 if (mask & ELF_SPARC_HWCAP_VIS3)
12491 printf ("%svis3", first ? "" : "|"), first = 0;
12492 if (mask & ELF_SPARC_HWCAP_HPC)
12493 printf ("%shpc", first ? "" : "|"), first = 0;
12494 if (mask & ELF_SPARC_HWCAP_RANDOM)
12495 printf ("%srandom", first ? "" : "|"), first = 0;
12496 if (mask & ELF_SPARC_HWCAP_TRANS)
12497 printf ("%strans", first ? "" : "|"), first = 0;
12498 if (mask & ELF_SPARC_HWCAP_FJFMAU)
12499 printf ("%sfjfmau", first ? "" : "|"), first = 0;
12500 if (mask & ELF_SPARC_HWCAP_IMA)
12501 printf ("%sima", first ? "" : "|"), first = 0;
12502 if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
12503 printf ("%scspare", first ? "" : "|"), first = 0;
12506 fputc ('0', stdout);
12507 fputc ('\n', stdout);
12511 display_sparc_hwcaps2 (int mask)
12517 if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
12518 fputs ("fjathplus", stdout), first = 0;
12519 if (mask & ELF_SPARC_HWCAP2_VIS3B)
12520 printf ("%svis3b", first ? "" : "|"), first = 0;
12521 if (mask & ELF_SPARC_HWCAP2_ADP)
12522 printf ("%sadp", first ? "" : "|"), first = 0;
12523 if (mask & ELF_SPARC_HWCAP2_SPARC5)
12524 printf ("%ssparc5", first ? "" : "|"), first = 0;
12525 if (mask & ELF_SPARC_HWCAP2_MWAIT)
12526 printf ("%smwait", first ? "" : "|"), first = 0;
12527 if (mask & ELF_SPARC_HWCAP2_XMPMUL)
12528 printf ("%sxmpmul", first ? "" : "|"), first = 0;
12529 if (mask & ELF_SPARC_HWCAP2_XMONT)
12530 printf ("%sxmont2", first ? "" : "|"), first = 0;
12531 if (mask & ELF_SPARC_HWCAP2_NSEC)
12532 printf ("%snsec", first ? "" : "|"), first = 0;
12533 if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
12534 printf ("%sfjathhpc", first ? "" : "|"), first = 0;
12535 if (mask & ELF_SPARC_HWCAP2_FJDES)
12536 printf ("%sfjdes", first ? "" : "|"), first = 0;
12537 if (mask & ELF_SPARC_HWCAP2_FJAES)
12538 printf ("%sfjaes", first ? "" : "|"), first = 0;
12541 fputc ('0', stdout);
12542 fputc ('\n', stdout);
12545 static unsigned char *
12546 display_sparc_gnu_attribute (unsigned char * p,
12548 const unsigned char * const end)
12553 if (tag == Tag_GNU_Sparc_HWCAPS)
12555 val = read_uleb128 (p, &len, end);
12557 printf (" Tag_GNU_Sparc_HWCAPS: ");
12558 display_sparc_hwcaps (val);
12561 if (tag == Tag_GNU_Sparc_HWCAPS2)
12563 val = read_uleb128 (p, &len, end);
12565 printf (" Tag_GNU_Sparc_HWCAPS2: ");
12566 display_sparc_hwcaps2 (val);
12570 return display_tag_value (tag, p, end);
12574 print_mips_fp_abi_value (int val)
12578 case Val_GNU_MIPS_ABI_FP_ANY:
12579 printf (_("Hard or soft float\n"));
12581 case Val_GNU_MIPS_ABI_FP_DOUBLE:
12582 printf (_("Hard float (double precision)\n"));
12584 case Val_GNU_MIPS_ABI_FP_SINGLE:
12585 printf (_("Hard float (single precision)\n"));
12587 case Val_GNU_MIPS_ABI_FP_SOFT:
12588 printf (_("Soft float\n"));
12590 case Val_GNU_MIPS_ABI_FP_OLD_64:
12591 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
12593 case Val_GNU_MIPS_ABI_FP_XX:
12594 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
12596 case Val_GNU_MIPS_ABI_FP_64:
12597 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
12599 case Val_GNU_MIPS_ABI_FP_64A:
12600 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
12603 printf ("??? (%d)\n", val);
12608 static unsigned char *
12609 display_mips_gnu_attribute (unsigned char * p,
12611 const unsigned char * const end)
12613 if (tag == Tag_GNU_MIPS_ABI_FP)
12618 val = read_uleb128 (p, &len, end);
12620 printf (" Tag_GNU_MIPS_ABI_FP: ");
12622 print_mips_fp_abi_value (val);
12627 if (tag == Tag_GNU_MIPS_ABI_MSA)
12632 val = read_uleb128 (p, &len, end);
12634 printf (" Tag_GNU_MIPS_ABI_MSA: ");
12638 case Val_GNU_MIPS_ABI_MSA_ANY:
12639 printf (_("Any MSA or not\n"));
12641 case Val_GNU_MIPS_ABI_MSA_128:
12642 printf (_("128-bit MSA\n"));
12645 printf ("??? (%d)\n", val);
12651 return display_tag_value (tag & 1, p, end);
12654 static unsigned char *
12655 display_tic6x_attribute (unsigned char * p,
12656 const unsigned char * const end)
12662 tag = read_uleb128 (p, &len, end);
12668 val = read_uleb128 (p, &len, end);
12670 printf (" Tag_ISA: ");
12674 case C6XABI_Tag_ISA_none:
12675 printf (_("None\n"));
12677 case C6XABI_Tag_ISA_C62X:
12680 case C6XABI_Tag_ISA_C67X:
12683 case C6XABI_Tag_ISA_C67XP:
12684 printf ("C67x+\n");
12686 case C6XABI_Tag_ISA_C64X:
12689 case C6XABI_Tag_ISA_C64XP:
12690 printf ("C64x+\n");
12692 case C6XABI_Tag_ISA_C674X:
12693 printf ("C674x\n");
12696 printf ("??? (%d)\n", val);
12701 case Tag_ABI_wchar_t:
12702 val = read_uleb128 (p, &len, end);
12704 printf (" Tag_ABI_wchar_t: ");
12708 printf (_("Not used\n"));
12711 printf (_("2 bytes\n"));
12714 printf (_("4 bytes\n"));
12717 printf ("??? (%d)\n", val);
12722 case Tag_ABI_stack_align_needed:
12723 val = read_uleb128 (p, &len, end);
12725 printf (" Tag_ABI_stack_align_needed: ");
12729 printf (_("8-byte\n"));
12732 printf (_("16-byte\n"));
12735 printf ("??? (%d)\n", val);
12740 case Tag_ABI_stack_align_preserved:
12741 val = read_uleb128 (p, &len, end);
12743 printf (" Tag_ABI_stack_align_preserved: ");
12747 printf (_("8-byte\n"));
12750 printf (_("16-byte\n"));
12753 printf ("??? (%d)\n", val);
12759 val = read_uleb128 (p, &len, end);
12761 printf (" Tag_ABI_DSBT: ");
12765 printf (_("DSBT addressing not used\n"));
12768 printf (_("DSBT addressing used\n"));
12771 printf ("??? (%d)\n", val);
12777 val = read_uleb128 (p, &len, end);
12779 printf (" Tag_ABI_PID: ");
12783 printf (_("Data addressing position-dependent\n"));
12786 printf (_("Data addressing position-independent, GOT near DP\n"));
12789 printf (_("Data addressing position-independent, GOT far from DP\n"));
12792 printf ("??? (%d)\n", val);
12798 val = read_uleb128 (p, &len, end);
12800 printf (" Tag_ABI_PIC: ");
12804 printf (_("Code addressing position-dependent\n"));
12807 printf (_("Code addressing position-independent\n"));
12810 printf ("??? (%d)\n", val);
12815 case Tag_ABI_array_object_alignment:
12816 val = read_uleb128 (p, &len, end);
12818 printf (" Tag_ABI_array_object_alignment: ");
12822 printf (_("8-byte\n"));
12825 printf (_("4-byte\n"));
12828 printf (_("16-byte\n"));
12831 printf ("??? (%d)\n", val);
12836 case Tag_ABI_array_object_align_expected:
12837 val = read_uleb128 (p, &len, end);
12839 printf (" Tag_ABI_array_object_align_expected: ");
12843 printf (_("8-byte\n"));
12846 printf (_("4-byte\n"));
12849 printf (_("16-byte\n"));
12852 printf ("??? (%d)\n", val);
12857 case Tag_ABI_compatibility:
12859 val = read_uleb128 (p, &len, end);
12861 printf (" Tag_ABI_compatibility: ");
12862 printf (_("flag = %d, vendor = "), val);
12865 size_t maxlen = (end - p) - 1;
12867 print_symbol ((int) maxlen, (const char *) p);
12868 p += strnlen ((char *) p, maxlen) + 1;
12872 printf (_("<corrupt>"));
12873 p = (unsigned char *) end;
12879 case Tag_ABI_conformance:
12881 printf (" Tag_ABI_conformance: \"");
12884 size_t maxlen = (end - p) - 1;
12886 print_symbol ((int) maxlen, (const char *) p);
12887 p += strnlen ((char *) p, maxlen) + 1;
12891 printf (_("<corrupt>"));
12892 p = (unsigned char *) end;
12899 return display_tag_value (tag, p, end);
12903 display_raw_attribute (unsigned char * p, unsigned char * end)
12905 unsigned long addr = 0;
12906 size_t bytes = end - p;
12913 int lbytes = (bytes > 16 ? 16 : bytes);
12915 printf (" 0x%8.8lx ", addr);
12917 for (j = 0; j < 16; j++)
12920 printf ("%2.2x", p[j]);
12928 for (j = 0; j < lbytes; j++)
12931 if (k >= ' ' && k < 0x7f)
12947 static unsigned char *
12948 display_msp430x_attribute (unsigned char * p,
12949 const unsigned char * const end)
12955 tag = read_uleb128 (p, & len, end);
12960 case OFBA_MSPABI_Tag_ISA:
12961 val = read_uleb128 (p, &len, end);
12963 printf (" Tag_ISA: ");
12966 case 0: printf (_("None\n")); break;
12967 case 1: printf (_("MSP430\n")); break;
12968 case 2: printf (_("MSP430X\n")); break;
12969 default: printf ("??? (%d)\n", val); break;
12973 case OFBA_MSPABI_Tag_Code_Model:
12974 val = read_uleb128 (p, &len, end);
12976 printf (" Tag_Code_Model: ");
12979 case 0: printf (_("None\n")); break;
12980 case 1: printf (_("Small\n")); break;
12981 case 2: printf (_("Large\n")); break;
12982 default: printf ("??? (%d)\n", val); break;
12986 case OFBA_MSPABI_Tag_Data_Model:
12987 val = read_uleb128 (p, &len, end);
12989 printf (" Tag_Data_Model: ");
12992 case 0: printf (_("None\n")); break;
12993 case 1: printf (_("Small\n")); break;
12994 case 2: printf (_("Large\n")); break;
12995 case 3: printf (_("Restricted Large\n")); break;
12996 default: printf ("??? (%d)\n", val); break;
13001 printf (_(" <unknown tag %d>: "), tag);
13008 size_t maxlen = (end - p) - 1;
13010 print_symbol ((int) maxlen, (const char *) p);
13011 p += strnlen ((char *) p, maxlen) + 1;
13015 printf (_("<corrupt>"));
13016 p = (unsigned char *) end;
13022 val = read_uleb128 (p, &len, end);
13024 printf ("%d (0x%x)\n", val, val);
13034 process_attributes (FILE * file,
13035 const char * public_name,
13036 unsigned int proc_type,
13037 unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
13038 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int, const unsigned char * const))
13040 Elf_Internal_Shdr * sect;
13043 /* Find the section header so that we get the size. */
13044 for (i = 0, sect = section_headers;
13045 i < elf_header.e_shnum;
13048 unsigned char * contents;
13051 if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
13054 contents = (unsigned char *) get_data (NULL, file, sect->sh_offset, 1,
13055 sect->sh_size, _("attributes"));
13056 if (contents == NULL)
13062 bfd_vma section_len;
13064 section_len = sect->sh_size - 1;
13067 while (section_len > 0)
13070 unsigned int namelen;
13071 bfd_boolean public_section;
13072 bfd_boolean gnu_section;
13074 if (section_len <= 4)
13076 error (_("Tag section ends prematurely\n"));
13079 attr_len = byte_get (p, 4);
13082 if (attr_len > section_len)
13084 error (_("Bad attribute length (%u > %u)\n"),
13085 (unsigned) attr_len, (unsigned) section_len);
13086 attr_len = section_len;
13088 /* PR 17531: file: 001-101425-0.004 */
13089 else if (attr_len < 5)
13091 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
13095 section_len -= attr_len;
13098 namelen = strnlen ((char *) p, attr_len) + 1;
13099 if (namelen == 0 || namelen >= attr_len)
13101 error (_("Corrupt attribute section name\n"));
13105 printf (_("Attribute Section: "));
13106 print_symbol (INT_MAX, (const char *) p);
13109 if (public_name && streq ((char *) p, public_name))
13110 public_section = TRUE;
13112 public_section = FALSE;
13114 if (streq ((char *) p, "gnu"))
13115 gnu_section = TRUE;
13117 gnu_section = FALSE;
13120 attr_len -= namelen;
13122 while (attr_len > 0 && p < contents + sect->sh_size)
13127 unsigned char * end;
13129 /* PR binutils/17531: Safe handling of corrupt files. */
13132 error (_("Unused bytes at end of section\n"));
13138 size = byte_get (p, 4);
13139 if (size > attr_len)
13141 error (_("Bad subsection length (%u > %u)\n"),
13142 (unsigned) size, (unsigned) attr_len);
13145 /* PR binutils/17531: Safe handling of corrupt files. */
13148 error (_("Bad subsection length (%u < 6)\n"),
13155 end = p + size - 1;
13156 assert (end <= contents + sect->sh_size);
13162 printf (_("File Attributes\n"));
13165 printf (_("Section Attributes:"));
13168 printf (_("Symbol Attributes:"));
13174 val = read_uleb128 (p, &j, end);
13178 printf (" %d", val);
13183 printf (_("Unknown tag: %d\n"), tag);
13184 public_section = FALSE;
13188 if (public_section && display_pub_attribute != NULL)
13191 p = display_pub_attribute (p, end);
13194 else if (gnu_section && display_proc_gnu_attribute != NULL)
13197 p = display_gnu_attribute (p,
13198 display_proc_gnu_attribute,
13204 printf (_(" Unknown attribute:\n"));
13205 display_raw_attribute (p, end);
13214 printf (_("Unknown format '%c' (%d)\n"), *p, *p);
13222 process_arm_specific (FILE * file)
13224 return process_attributes (file, "aeabi", SHT_ARM_ATTRIBUTES,
13225 display_arm_attribute, NULL);
13229 process_power_specific (FILE * file)
13231 return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
13232 display_power_gnu_attribute);
13236 process_sparc_specific (FILE * file)
13238 return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
13239 display_sparc_gnu_attribute);
13243 process_tic6x_specific (FILE * file)
13245 return process_attributes (file, "c6xabi", SHT_C6000_ATTRIBUTES,
13246 display_tic6x_attribute, NULL);
13250 process_msp430x_specific (FILE * file)
13252 return process_attributes (file, "mspabi", SHT_MSP430_ATTRIBUTES,
13253 display_msp430x_attribute, NULL);
13256 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
13257 Print the Address, Access and Initial fields of an entry at VMA ADDR
13258 and return the VMA of the next entry, or -1 if there was a problem.
13259 Does not read from DATA_END or beyond. */
13262 print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
13263 unsigned char * data_end)
13266 print_vma (addr, LONG_HEX);
13268 if (addr < pltgot + 0xfff0)
13269 printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
13271 printf ("%10s", "");
13274 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
13278 unsigned char * from = data + addr - pltgot;
13280 if (from + (is_32bit_elf ? 4 : 8) > data_end)
13282 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
13283 printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
13284 return (bfd_vma) -1;
13288 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
13289 print_vma (entry, LONG_HEX);
13292 return addr + (is_32bit_elf ? 4 : 8);
13295 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
13296 PLTGOT. Print the Address and Initial fields of an entry at VMA
13297 ADDR and return the VMA of the next entry. */
13300 print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
13303 print_vma (addr, LONG_HEX);
13306 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
13311 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
13312 print_vma (entry, LONG_HEX);
13314 return addr + (is_32bit_elf ? 4 : 8);
13318 print_mips_ases (unsigned int mask)
13320 if (mask & AFL_ASE_DSP)
13321 fputs ("\n\tDSP ASE", stdout);
13322 if (mask & AFL_ASE_DSPR2)
13323 fputs ("\n\tDSP R2 ASE", stdout);
13324 if (mask & AFL_ASE_EVA)
13325 fputs ("\n\tEnhanced VA Scheme", stdout);
13326 if (mask & AFL_ASE_MCU)
13327 fputs ("\n\tMCU (MicroController) ASE", stdout);
13328 if (mask & AFL_ASE_MDMX)
13329 fputs ("\n\tMDMX ASE", stdout);
13330 if (mask & AFL_ASE_MIPS3D)
13331 fputs ("\n\tMIPS-3D ASE", stdout);
13332 if (mask & AFL_ASE_MT)
13333 fputs ("\n\tMT ASE", stdout);
13334 if (mask & AFL_ASE_SMARTMIPS)
13335 fputs ("\n\tSmartMIPS ASE", stdout);
13336 if (mask & AFL_ASE_VIRT)
13337 fputs ("\n\tVZ ASE", stdout);
13338 if (mask & AFL_ASE_MSA)
13339 fputs ("\n\tMSA ASE", stdout);
13340 if (mask & AFL_ASE_MIPS16)
13341 fputs ("\n\tMIPS16 ASE", stdout);
13342 if (mask & AFL_ASE_MICROMIPS)
13343 fputs ("\n\tMICROMIPS ASE", stdout);
13344 if (mask & AFL_ASE_XPA)
13345 fputs ("\n\tXPA ASE", stdout);
13347 fprintf (stdout, "\n\t%s", _("None"));
13348 else if ((mask & ~AFL_ASE_MASK) != 0)
13349 fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
13353 print_mips_isa_ext (unsigned int isa_ext)
13358 fputs (_("None"), stdout);
13361 fputs ("RMI XLR", stdout);
13363 case AFL_EXT_OCTEON2:
13364 fputs ("Cavium Networks Octeon2", stdout);
13366 case AFL_EXT_OCTEONP:
13367 fputs ("Cavium Networks OcteonP", stdout);
13369 case AFL_EXT_LOONGSON_3A:
13370 fputs ("Loongson 3A", stdout);
13372 case AFL_EXT_OCTEON:
13373 fputs ("Cavium Networks Octeon", stdout);
13376 fputs ("Toshiba R5900", stdout);
13379 fputs ("MIPS R4650", stdout);
13382 fputs ("LSI R4010", stdout);
13385 fputs ("NEC VR4100", stdout);
13388 fputs ("Toshiba R3900", stdout);
13390 case AFL_EXT_10000:
13391 fputs ("MIPS R10000", stdout);
13394 fputs ("Broadcom SB-1", stdout);
13397 fputs ("NEC VR4111/VR4181", stdout);
13400 fputs ("NEC VR4120", stdout);
13403 fputs ("NEC VR5400", stdout);
13406 fputs ("NEC VR5500", stdout);
13408 case AFL_EXT_LOONGSON_2E:
13409 fputs ("ST Microelectronics Loongson 2E", stdout);
13411 case AFL_EXT_LOONGSON_2F:
13412 fputs ("ST Microelectronics Loongson 2F", stdout);
13415 fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
13420 get_mips_reg_size (int reg_size)
13422 return (reg_size == AFL_REG_NONE) ? 0
13423 : (reg_size == AFL_REG_32) ? 32
13424 : (reg_size == AFL_REG_64) ? 64
13425 : (reg_size == AFL_REG_128) ? 128
13430 process_mips_specific (FILE * file)
13432 Elf_Internal_Dyn * entry;
13433 Elf_Internal_Shdr *sect = NULL;
13434 size_t liblist_offset = 0;
13435 size_t liblistno = 0;
13436 size_t conflictsno = 0;
13437 size_t options_offset = 0;
13438 size_t conflicts_offset = 0;
13439 size_t pltrelsz = 0;
13441 bfd_vma pltgot = 0;
13442 bfd_vma mips_pltgot = 0;
13443 bfd_vma jmprel = 0;
13444 bfd_vma local_gotno = 0;
13445 bfd_vma gotsym = 0;
13446 bfd_vma symtabno = 0;
13448 process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
13449 display_mips_gnu_attribute);
13451 sect = find_section (".MIPS.abiflags");
13455 Elf_External_ABIFlags_v0 *abiflags_ext;
13456 Elf_Internal_ABIFlags_v0 abiflags_in;
13458 if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
13459 fputs ("\nCorrupt ABI Flags section.\n", stdout);
13462 abiflags_ext = get_data (NULL, file, sect->sh_offset, 1,
13463 sect->sh_size, _("MIPS ABI Flags section"));
13466 abiflags_in.version = BYTE_GET (abiflags_ext->version);
13467 abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
13468 abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
13469 abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
13470 abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
13471 abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
13472 abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
13473 abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
13474 abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
13475 abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
13476 abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
13478 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
13479 printf ("\nISA: MIPS%d", abiflags_in.isa_level);
13480 if (abiflags_in.isa_rev > 1)
13481 printf ("r%d", abiflags_in.isa_rev);
13482 printf ("\nGPR size: %d",
13483 get_mips_reg_size (abiflags_in.gpr_size));
13484 printf ("\nCPR1 size: %d",
13485 get_mips_reg_size (abiflags_in.cpr1_size));
13486 printf ("\nCPR2 size: %d",
13487 get_mips_reg_size (abiflags_in.cpr2_size));
13488 fputs ("\nFP ABI: ", stdout);
13489 print_mips_fp_abi_value (abiflags_in.fp_abi);
13490 fputs ("ISA Extension: ", stdout);
13491 print_mips_isa_ext (abiflags_in.isa_ext);
13492 fputs ("\nASEs:", stdout);
13493 print_mips_ases (abiflags_in.ases);
13494 printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
13495 printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
13496 fputc ('\n', stdout);
13497 free (abiflags_ext);
13502 /* We have a lot of special sections. Thanks SGI! */
13503 if (dynamic_section == NULL)
13504 /* No information available. */
13507 for (entry = dynamic_section;
13508 /* PR 17531 file: 012-50589-0.004. */
13509 entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL;
13511 switch (entry->d_tag)
13513 case DT_MIPS_LIBLIST:
13515 = offset_from_vma (file, entry->d_un.d_val,
13516 liblistno * sizeof (Elf32_External_Lib));
13518 case DT_MIPS_LIBLISTNO:
13519 liblistno = entry->d_un.d_val;
13521 case DT_MIPS_OPTIONS:
13522 options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
13524 case DT_MIPS_CONFLICT:
13526 = offset_from_vma (file, entry->d_un.d_val,
13527 conflictsno * sizeof (Elf32_External_Conflict));
13529 case DT_MIPS_CONFLICTNO:
13530 conflictsno = entry->d_un.d_val;
13533 pltgot = entry->d_un.d_ptr;
13535 case DT_MIPS_LOCAL_GOTNO:
13536 local_gotno = entry->d_un.d_val;
13538 case DT_MIPS_GOTSYM:
13539 gotsym = entry->d_un.d_val;
13541 case DT_MIPS_SYMTABNO:
13542 symtabno = entry->d_un.d_val;
13544 case DT_MIPS_PLTGOT:
13545 mips_pltgot = entry->d_un.d_ptr;
13548 pltrel = entry->d_un.d_val;
13551 pltrelsz = entry->d_un.d_val;
13554 jmprel = entry->d_un.d_ptr;
13560 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
13562 Elf32_External_Lib * elib;
13565 elib = (Elf32_External_Lib *) get_data (NULL, file, liblist_offset,
13567 sizeof (Elf32_External_Lib),
13568 _("liblist section data"));
13571 printf (_("\nSection '.liblist' contains %lu entries:\n"),
13572 (unsigned long) liblistno);
13573 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
13576 for (cnt = 0; cnt < liblistno; ++cnt)
13583 liblist.l_name = BYTE_GET (elib[cnt].l_name);
13584 atime = BYTE_GET (elib[cnt].l_time_stamp);
13585 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
13586 liblist.l_version = BYTE_GET (elib[cnt].l_version);
13587 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
13589 tmp = gmtime (&atime);
13590 snprintf (timebuf, sizeof (timebuf),
13591 "%04u-%02u-%02uT%02u:%02u:%02u",
13592 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
13593 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
13595 printf ("%3lu: ", (unsigned long) cnt);
13596 if (VALID_DYNAMIC_NAME (liblist.l_name))
13597 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
13599 printf (_("<corrupt: %9ld>"), liblist.l_name);
13600 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
13601 liblist.l_version);
13603 if (liblist.l_flags == 0)
13607 static const struct
13614 { " EXACT_MATCH", LL_EXACT_MATCH },
13615 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
13616 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
13617 { " EXPORTS", LL_EXPORTS },
13618 { " DELAY_LOAD", LL_DELAY_LOAD },
13619 { " DELTA", LL_DELTA }
13621 int flags = liblist.l_flags;
13624 for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
13625 if ((flags & l_flags_vals[fcnt].bit) != 0)
13627 fputs (l_flags_vals[fcnt].name, stdout);
13628 flags ^= l_flags_vals[fcnt].bit;
13631 printf (" %#x", (unsigned int) flags);
13641 if (options_offset != 0)
13643 Elf_External_Options * eopt;
13644 Elf_Internal_Options * iopt;
13645 Elf_Internal_Options * option;
13648 sect = section_headers;
13650 /* Find the section header so that we get the size. */
13651 sect = find_section_by_type (SHT_MIPS_OPTIONS);
13652 /* PR 17533 file: 012-277276-0.004. */
13655 error (_("No MIPS_OPTIONS header found\n"));
13659 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset, 1,
13660 sect->sh_size, _("options"));
13663 iopt = (Elf_Internal_Options *)
13664 cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
13667 error (_("Out of memory allocatinf space for MIPS options\n"));
13674 while (offset <= sect->sh_size - sizeof (* eopt))
13676 Elf_External_Options * eoption;
13678 eoption = (Elf_External_Options *) ((char *) eopt + offset);
13680 option->kind = BYTE_GET (eoption->kind);
13681 option->size = BYTE_GET (eoption->size);
13682 option->section = BYTE_GET (eoption->section);
13683 option->info = BYTE_GET (eoption->info);
13685 /* PR 17531: file: ffa0fa3b. */
13686 if (option->size < sizeof (* eopt)
13687 || offset + option->size > sect->sh_size)
13689 error (_("Invalid size (%u) for MIPS option\n"), option->size);
13692 offset += option->size;
13698 printf (_("\nSection '%s' contains %d entries:\n"),
13699 printable_section_name (sect), cnt);
13708 switch (option->kind)
13711 /* This shouldn't happen. */
13712 printf (" NULL %d %lx", option->section, option->info);
13715 printf (" REGINFO ");
13716 if (elf_header.e_machine == EM_MIPS)
13719 Elf32_External_RegInfo * ereg;
13720 Elf32_RegInfo reginfo;
13722 ereg = (Elf32_External_RegInfo *) (option + 1);
13723 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
13724 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
13725 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
13726 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
13727 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
13728 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
13730 printf ("GPR %08lx GP 0x%lx\n",
13731 reginfo.ri_gprmask,
13732 (unsigned long) reginfo.ri_gp_value);
13733 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
13734 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
13735 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
13740 Elf64_External_RegInfo * ereg;
13741 Elf64_Internal_RegInfo reginfo;
13743 ereg = (Elf64_External_RegInfo *) (option + 1);
13744 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
13745 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
13746 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
13747 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
13748 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
13749 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
13751 printf ("GPR %08lx GP 0x",
13752 reginfo.ri_gprmask);
13753 printf_vma (reginfo.ri_gp_value);
13756 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
13757 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
13758 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
13762 case ODK_EXCEPTIONS:
13763 fputs (" EXCEPTIONS fpe_min(", stdout);
13764 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
13765 fputs (") fpe_max(", stdout);
13766 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
13767 fputs (")", stdout);
13769 if (option->info & OEX_PAGE0)
13770 fputs (" PAGE0", stdout);
13771 if (option->info & OEX_SMM)
13772 fputs (" SMM", stdout);
13773 if (option->info & OEX_FPDBUG)
13774 fputs (" FPDBUG", stdout);
13775 if (option->info & OEX_DISMISS)
13776 fputs (" DISMISS", stdout);
13779 fputs (" PAD ", stdout);
13780 if (option->info & OPAD_PREFIX)
13781 fputs (" PREFIX", stdout);
13782 if (option->info & OPAD_POSTFIX)
13783 fputs (" POSTFIX", stdout);
13784 if (option->info & OPAD_SYMBOL)
13785 fputs (" SYMBOL", stdout);
13788 fputs (" HWPATCH ", stdout);
13789 if (option->info & OHW_R4KEOP)
13790 fputs (" R4KEOP", stdout);
13791 if (option->info & OHW_R8KPFETCH)
13792 fputs (" R8KPFETCH", stdout);
13793 if (option->info & OHW_R5KEOP)
13794 fputs (" R5KEOP", stdout);
13795 if (option->info & OHW_R5KCVTL)
13796 fputs (" R5KCVTL", stdout);
13799 fputs (" FILL ", stdout);
13800 /* XXX Print content of info word? */
13803 fputs (" TAGS ", stdout);
13804 /* XXX Print content of info word? */
13807 fputs (" HWAND ", stdout);
13808 if (option->info & OHWA0_R4KEOP_CHECKED)
13809 fputs (" R4KEOP_CHECKED", stdout);
13810 if (option->info & OHWA0_R4KEOP_CLEAN)
13811 fputs (" R4KEOP_CLEAN", stdout);
13814 fputs (" HWOR ", stdout);
13815 if (option->info & OHWA0_R4KEOP_CHECKED)
13816 fputs (" R4KEOP_CHECKED", stdout);
13817 if (option->info & OHWA0_R4KEOP_CLEAN)
13818 fputs (" R4KEOP_CLEAN", stdout);
13821 printf (" GP_GROUP %#06lx self-contained %#06lx",
13822 option->info & OGP_GROUP,
13823 (option->info & OGP_SELF) >> 16);
13826 printf (" IDENT %#06lx self-contained %#06lx",
13827 option->info & OGP_GROUP,
13828 (option->info & OGP_SELF) >> 16);
13831 /* This shouldn't happen. */
13832 printf (" %3d ??? %d %lx",
13833 option->kind, option->section, option->info);
13837 len = sizeof (* eopt);
13838 while (len < option->size)
13840 char datum = * ((char *) eopt + offset + len);
13842 if (ISPRINT (datum))
13843 printf ("%c", datum);
13845 printf ("\\%03o", datum);
13849 fputs ("\n", stdout);
13850 offset += option->size;
13858 if (conflicts_offset != 0 && conflictsno != 0)
13860 Elf32_Conflict * iconf;
13863 if (dynamic_symbols == NULL)
13865 error (_("conflict list found without a dynamic symbol table\n"));
13869 iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
13872 error (_("Out of memory allocating space for dynamic conflicts\n"));
13878 Elf32_External_Conflict * econf32;
13880 econf32 = (Elf32_External_Conflict *)
13881 get_data (NULL, file, conflicts_offset, conflictsno,
13882 sizeof (* econf32), _("conflict"));
13886 for (cnt = 0; cnt < conflictsno; ++cnt)
13887 iconf[cnt] = BYTE_GET (econf32[cnt]);
13893 Elf64_External_Conflict * econf64;
13895 econf64 = (Elf64_External_Conflict *)
13896 get_data (NULL, file, conflicts_offset, conflictsno,
13897 sizeof (* econf64), _("conflict"));
13901 for (cnt = 0; cnt < conflictsno; ++cnt)
13902 iconf[cnt] = BYTE_GET (econf64[cnt]);
13907 printf (_("\nSection '.conflict' contains %lu entries:\n"),
13908 (unsigned long) conflictsno);
13909 puts (_(" Num: Index Value Name"));
13911 for (cnt = 0; cnt < conflictsno; ++cnt)
13913 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
13915 if (iconf[cnt] >= num_dynamic_syms)
13916 printf (_("<corrupt symbol index>"));
13919 Elf_Internal_Sym * psym;
13921 psym = & dynamic_symbols[iconf[cnt]];
13922 print_vma (psym->st_value, FULL_HEX);
13924 if (VALID_DYNAMIC_NAME (psym->st_name))
13925 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
13927 printf (_("<corrupt: %14ld>"), psym->st_name);
13935 if (pltgot != 0 && local_gotno != 0)
13937 bfd_vma ent, local_end, global_end;
13939 unsigned char * data;
13940 unsigned char * data_end;
13944 addr_size = (is_32bit_elf ? 4 : 8);
13945 local_end = pltgot + local_gotno * addr_size;
13947 /* PR binutils/17533 file: 012-111227-0.004 */
13948 if (symtabno < gotsym)
13950 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
13951 (unsigned long) gotsym, (unsigned long) symtabno);
13955 global_end = local_end + (symtabno - gotsym) * addr_size;
13956 /* PR 17531: file: 54c91a34. */
13957 if (global_end < local_end)
13959 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
13963 offset = offset_from_vma (file, pltgot, global_end - pltgot);
13964 data = (unsigned char *) get_data (NULL, file, offset,
13965 global_end - pltgot, 1,
13966 _("Global Offset Table data"));
13969 data_end = data + (global_end - pltgot);
13971 printf (_("\nPrimary GOT:\n"));
13972 printf (_(" Canonical gp value: "));
13973 print_vma (pltgot + 0x7ff0, LONG_HEX);
13976 printf (_(" Reserved entries:\n"));
13977 printf (_(" %*s %10s %*s Purpose\n"),
13978 addr_size * 2, _("Address"), _("Access"),
13979 addr_size * 2, _("Initial"));
13980 ent = print_mips_got_entry (data, pltgot, ent, data_end);
13981 printf (_(" Lazy resolver\n"));
13982 if (ent == (bfd_vma) -1)
13983 goto got_print_fail;
13985 && (byte_get (data + ent - pltgot, addr_size)
13986 >> (addr_size * 8 - 1)) != 0)
13988 ent = print_mips_got_entry (data, pltgot, ent, data_end);
13989 printf (_(" Module pointer (GNU extension)\n"));
13990 if (ent == (bfd_vma) -1)
13991 goto got_print_fail;
13995 if (ent < local_end)
13997 printf (_(" Local entries:\n"));
13998 printf (" %*s %10s %*s\n",
13999 addr_size * 2, _("Address"), _("Access"),
14000 addr_size * 2, _("Initial"));
14001 while (ent < local_end)
14003 ent = print_mips_got_entry (data, pltgot, ent, data_end);
14005 if (ent == (bfd_vma) -1)
14006 goto got_print_fail;
14011 if (gotsym < symtabno)
14015 printf (_(" Global entries:\n"));
14016 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
14017 addr_size * 2, _("Address"),
14019 addr_size * 2, _("Initial"),
14020 addr_size * 2, _("Sym.Val."),
14022 /* Note for translators: "Ndx" = abbreviated form of "Index". */
14023 _("Ndx"), _("Name"));
14025 sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
14027 for (i = gotsym; i < symtabno; i++)
14029 ent = print_mips_got_entry (data, pltgot, ent, data_end);
14032 if (dynamic_symbols == NULL)
14033 printf (_("<no dynamic symbols>"));
14034 else if (i < num_dynamic_syms)
14036 Elf_Internal_Sym * psym = dynamic_symbols + i;
14038 print_vma (psym->st_value, LONG_HEX);
14039 printf (" %-7s %3s ",
14040 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
14041 get_symbol_index_type (psym->st_shndx));
14043 if (VALID_DYNAMIC_NAME (psym->st_name))
14044 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
14046 printf (_("<corrupt: %14ld>"), psym->st_name);
14049 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
14050 (unsigned long) i);
14053 if (ent == (bfd_vma) -1)
14064 if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
14067 size_t offset, rel_offset;
14068 unsigned long count, i;
14069 unsigned char * data;
14070 int addr_size, sym_width;
14071 Elf_Internal_Rela * rels;
14073 rel_offset = offset_from_vma (file, jmprel, pltrelsz);
14074 if (pltrel == DT_RELA)
14076 if (!slurp_rela_relocs (file, rel_offset, pltrelsz, &rels, &count))
14081 if (!slurp_rel_relocs (file, rel_offset, pltrelsz, &rels, &count))
14086 addr_size = (is_32bit_elf ? 4 : 8);
14087 end = mips_pltgot + (2 + count) * addr_size;
14089 offset = offset_from_vma (file, mips_pltgot, end - mips_pltgot);
14090 data = (unsigned char *) get_data (NULL, file, offset, end - mips_pltgot,
14091 1, _("Procedure Linkage Table data"));
14095 printf ("\nPLT GOT:\n\n");
14096 printf (_(" Reserved entries:\n"));
14097 printf (_(" %*s %*s Purpose\n"),
14098 addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
14099 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
14100 printf (_(" PLT lazy resolver\n"));
14101 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
14102 printf (_(" Module pointer\n"));
14105 printf (_(" Entries:\n"));
14106 printf (" %*s %*s %*s %-7s %3s %s\n",
14107 addr_size * 2, _("Address"),
14108 addr_size * 2, _("Initial"),
14109 addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
14110 sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
14111 for (i = 0; i < count; i++)
14113 unsigned long idx = get_reloc_symindex (rels[i].r_info);
14115 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
14118 if (idx >= num_dynamic_syms)
14119 printf (_("<corrupt symbol index: %lu>"), idx);
14122 Elf_Internal_Sym * psym = dynamic_symbols + idx;
14124 print_vma (psym->st_value, LONG_HEX);
14125 printf (" %-7s %3s ",
14126 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
14127 get_symbol_index_type (psym->st_shndx));
14128 if (VALID_DYNAMIC_NAME (psym->st_name))
14129 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
14131 printf (_("<corrupt: %14ld>"), psym->st_name);
14146 process_nds32_specific (FILE * file)
14148 Elf_Internal_Shdr *sect = NULL;
14150 sect = find_section (".nds32_e_flags");
14153 unsigned int *flag;
14155 printf ("\nNDS32 elf flags section:\n");
14156 flag = get_data (NULL, file, sect->sh_offset, 1,
14157 sect->sh_size, _("NDS32 elf flags section"));
14159 switch ((*flag) & 0x3)
14162 printf ("(VEC_SIZE):\tNo entry.\n");
14165 printf ("(VEC_SIZE):\t4 bytes\n");
14168 printf ("(VEC_SIZE):\t16 bytes\n");
14171 printf ("(VEC_SIZE):\treserved\n");
14180 process_gnu_liblist (FILE * file)
14182 Elf_Internal_Shdr * section;
14183 Elf_Internal_Shdr * string_sec;
14184 Elf32_External_Lib * elib;
14186 size_t strtab_size;
14193 for (i = 0, section = section_headers;
14194 i < elf_header.e_shnum;
14197 switch (section->sh_type)
14199 case SHT_GNU_LIBLIST:
14200 if (section->sh_link >= elf_header.e_shnum)
14203 elib = (Elf32_External_Lib *)
14204 get_data (NULL, file, section->sh_offset, 1, section->sh_size,
14205 _("liblist section data"));
14209 string_sec = section_headers + section->sh_link;
14211 strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
14212 string_sec->sh_size,
14213 _("liblist string table"));
14215 || section->sh_entsize != sizeof (Elf32_External_Lib))
14221 strtab_size = string_sec->sh_size;
14223 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
14224 printable_section_name (section),
14225 (unsigned long) (section->sh_size / sizeof (Elf32_External_Lib)));
14227 puts (_(" Library Time Stamp Checksum Version Flags"));
14229 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
14237 liblist.l_name = BYTE_GET (elib[cnt].l_name);
14238 atime = BYTE_GET (elib[cnt].l_time_stamp);
14239 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
14240 liblist.l_version = BYTE_GET (elib[cnt].l_version);
14241 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
14243 tmp = gmtime (&atime);
14244 snprintf (timebuf, sizeof (timebuf),
14245 "%04u-%02u-%02uT%02u:%02u:%02u",
14246 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
14247 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
14249 printf ("%3lu: ", (unsigned long) cnt);
14251 printf ("%-20s", liblist.l_name < strtab_size
14252 ? strtab + liblist.l_name : _("<corrupt>"));
14254 printf ("%-20.20s", liblist.l_name < strtab_size
14255 ? strtab + liblist.l_name : _("<corrupt>"));
14256 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
14257 liblist.l_version, liblist.l_flags);
14268 static const char *
14269 get_note_type (unsigned e_type)
14271 static char buff[64];
14273 if (elf_header.e_type == ET_CORE)
14277 return _("NT_AUXV (auxiliary vector)");
14279 return _("NT_PRSTATUS (prstatus structure)");
14281 return _("NT_FPREGSET (floating point registers)");
14283 return _("NT_PRPSINFO (prpsinfo structure)");
14284 case NT_TASKSTRUCT:
14285 return _("NT_TASKSTRUCT (task structure)");
14287 return _("NT_PRXFPREG (user_xfpregs structure)");
14289 return _("NT_PPC_VMX (ppc Altivec registers)");
14291 return _("NT_PPC_VSX (ppc VSX registers)");
14293 return _("NT_386_TLS (x86 TLS information)");
14294 case NT_386_IOPERM:
14295 return _("NT_386_IOPERM (x86 I/O permissions)");
14296 case NT_X86_XSTATE:
14297 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
14298 case NT_S390_HIGH_GPRS:
14299 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
14300 case NT_S390_TIMER:
14301 return _("NT_S390_TIMER (s390 timer register)");
14302 case NT_S390_TODCMP:
14303 return _("NT_S390_TODCMP (s390 TOD comparator register)");
14304 case NT_S390_TODPREG:
14305 return _("NT_S390_TODPREG (s390 TOD programmable register)");
14307 return _("NT_S390_CTRS (s390 control registers)");
14308 case NT_S390_PREFIX:
14309 return _("NT_S390_PREFIX (s390 prefix register)");
14310 case NT_S390_LAST_BREAK:
14311 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
14312 case NT_S390_SYSTEM_CALL:
14313 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
14315 return _("NT_S390_TDB (s390 transaction diagnostic block)");
14317 return _("NT_ARM_VFP (arm VFP registers)");
14319 return _("NT_ARM_TLS (AArch TLS registers)");
14320 case NT_ARM_HW_BREAK:
14321 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
14322 case NT_ARM_HW_WATCH:
14323 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
14325 return _("NT_PSTATUS (pstatus structure)");
14327 return _("NT_FPREGS (floating point registers)");
14329 return _("NT_PSINFO (psinfo structure)");
14331 return _("NT_LWPSTATUS (lwpstatus_t structure)");
14333 return _("NT_LWPSINFO (lwpsinfo_t structure)");
14334 case NT_WIN32PSTATUS:
14335 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
14337 return _("NT_SIGINFO (siginfo_t data)");
14339 return _("NT_FILE (mapped files)");
14347 return _("NT_VERSION (version)");
14349 return _("NT_ARCH (architecture)");
14354 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
14359 print_core_note (Elf_Internal_Note *pnote)
14361 unsigned int addr_size = is_32bit_elf ? 4 : 8;
14362 bfd_vma count, page_size;
14363 unsigned char *descdata, *filenames, *descend;
14365 if (pnote->type != NT_FILE)
14371 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
14372 /* Still "successful". */
14377 if (pnote->descsz < 2 * addr_size)
14379 printf (_(" Malformed note - too short for header\n"));
14383 descdata = (unsigned char *) pnote->descdata;
14384 descend = descdata + pnote->descsz;
14386 if (descdata[pnote->descsz - 1] != '\0')
14388 printf (_(" Malformed note - does not end with \\0\n"));
14392 count = byte_get (descdata, addr_size);
14393 descdata += addr_size;
14395 page_size = byte_get (descdata, addr_size);
14396 descdata += addr_size;
14398 if (pnote->descsz < 2 * addr_size + count * 3 * addr_size)
14400 printf (_(" Malformed note - too short for supplied file count\n"));
14404 printf (_(" Page size: "));
14405 print_vma (page_size, DEC);
14408 printf (_(" %*s%*s%*s\n"),
14409 (int) (2 + 2 * addr_size), _("Start"),
14410 (int) (4 + 2 * addr_size), _("End"),
14411 (int) (4 + 2 * addr_size), _("Page Offset"));
14412 filenames = descdata + count * 3 * addr_size;
14413 while (--count > 0)
14415 bfd_vma start, end, file_ofs;
14417 if (filenames == descend)
14419 printf (_(" Malformed note - filenames end too early\n"));
14423 start = byte_get (descdata, addr_size);
14424 descdata += addr_size;
14425 end = byte_get (descdata, addr_size);
14426 descdata += addr_size;
14427 file_ofs = byte_get (descdata, addr_size);
14428 descdata += addr_size;
14431 print_vma (start, FULL_HEX);
14433 print_vma (end, FULL_HEX);
14435 print_vma (file_ofs, FULL_HEX);
14436 printf ("\n %s\n", filenames);
14438 filenames += 1 + strlen ((char *) filenames);
14444 static const char *
14445 get_gnu_elf_note_type (unsigned e_type)
14447 static char buff[64];
14451 case NT_GNU_ABI_TAG:
14452 return _("NT_GNU_ABI_TAG (ABI version tag)");
14454 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
14455 case NT_GNU_BUILD_ID:
14456 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
14457 case NT_GNU_GOLD_VERSION:
14458 return _("NT_GNU_GOLD_VERSION (gold version)");
14463 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
14468 print_gnu_note (Elf_Internal_Note *pnote)
14470 switch (pnote->type)
14472 case NT_GNU_BUILD_ID:
14476 printf (_(" Build ID: "));
14477 for (i = 0; i < pnote->descsz; ++i)
14478 printf ("%02x", pnote->descdata[i] & 0xff);
14483 case NT_GNU_ABI_TAG:
14485 unsigned long os, major, minor, subminor;
14486 const char *osname;
14488 /* PR 17531: file: 030-599401-0.004. */
14489 if (pnote->descsz < 16)
14491 printf (_(" <corrupt GNU_ABI_TAG>\n"));
14495 os = byte_get ((unsigned char *) pnote->descdata, 4);
14496 major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
14497 minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
14498 subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
14502 case GNU_ABI_TAG_LINUX:
14505 case GNU_ABI_TAG_HURD:
14508 case GNU_ABI_TAG_SOLARIS:
14509 osname = "Solaris";
14511 case GNU_ABI_TAG_FREEBSD:
14512 osname = "FreeBSD";
14514 case GNU_ABI_TAG_NETBSD:
14518 osname = "Unknown";
14522 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname,
14523 major, minor, subminor);
14527 case NT_GNU_GOLD_VERSION:
14531 printf (_(" Version: "));
14532 for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
14533 printf ("%c", pnote->descdata[i]);
14542 static const char *
14543 get_netbsd_elfcore_note_type (unsigned e_type)
14545 static char buff[64];
14547 if (e_type == NT_NETBSDCORE_PROCINFO)
14549 /* NetBSD core "procinfo" structure. */
14550 return _("NetBSD procinfo structure");
14553 /* As of Jan 2002 there are no other machine-independent notes
14554 defined for NetBSD core files. If the note type is less
14555 than the start of the machine-dependent note types, we don't
14558 if (e_type < NT_NETBSDCORE_FIRSTMACH)
14560 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
14564 switch (elf_header.e_machine)
14566 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
14567 and PT_GETFPREGS == mach+2. */
14572 case EM_SPARC32PLUS:
14576 case NT_NETBSDCORE_FIRSTMACH + 0:
14577 return _("PT_GETREGS (reg structure)");
14578 case NT_NETBSDCORE_FIRSTMACH + 2:
14579 return _("PT_GETFPREGS (fpreg structure)");
14585 /* On all other arch's, PT_GETREGS == mach+1 and
14586 PT_GETFPREGS == mach+3. */
14590 case NT_NETBSDCORE_FIRSTMACH + 1:
14591 return _("PT_GETREGS (reg structure)");
14592 case NT_NETBSDCORE_FIRSTMACH + 3:
14593 return _("PT_GETFPREGS (fpreg structure)");
14599 snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
14600 e_type - NT_NETBSDCORE_FIRSTMACH);
14604 static const char *
14605 get_stapsdt_note_type (unsigned e_type)
14607 static char buff[64];
14612 return _("NT_STAPSDT (SystemTap probe descriptors)");
14618 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
14623 print_stapsdt_note (Elf_Internal_Note *pnote)
14625 int addr_size = is_32bit_elf ? 4 : 8;
14626 char *data = pnote->descdata;
14627 char *data_end = pnote->descdata + pnote->descsz;
14628 bfd_vma pc, base_addr, semaphore;
14629 char *provider, *probe, *arg_fmt;
14631 pc = byte_get ((unsigned char *) data, addr_size);
14633 base_addr = byte_get ((unsigned char *) data, addr_size);
14635 semaphore = byte_get ((unsigned char *) data, addr_size);
14639 data += strlen (data) + 1;
14641 data += strlen (data) + 1;
14643 data += strlen (data) + 1;
14645 printf (_(" Provider: %s\n"), provider);
14646 printf (_(" Name: %s\n"), probe);
14647 printf (_(" Location: "));
14648 print_vma (pc, FULL_HEX);
14649 printf (_(", Base: "));
14650 print_vma (base_addr, FULL_HEX);
14651 printf (_(", Semaphore: "));
14652 print_vma (semaphore, FULL_HEX);
14654 printf (_(" Arguments: %s\n"), arg_fmt);
14656 return data == data_end;
14659 static const char *
14660 get_ia64_vms_note_type (unsigned e_type)
14662 static char buff[64];
14667 return _("NT_VMS_MHD (module header)");
14669 return _("NT_VMS_LNM (language name)");
14671 return _("NT_VMS_SRC (source files)");
14673 return "NT_VMS_TITLE";
14675 return _("NT_VMS_EIDC (consistency check)");
14676 case NT_VMS_FPMODE:
14677 return _("NT_VMS_FPMODE (FP mode)");
14678 case NT_VMS_LINKTIME:
14679 return "NT_VMS_LINKTIME";
14680 case NT_VMS_IMGNAM:
14681 return _("NT_VMS_IMGNAM (image name)");
14683 return _("NT_VMS_IMGID (image id)");
14684 case NT_VMS_LINKID:
14685 return _("NT_VMS_LINKID (link id)");
14686 case NT_VMS_IMGBID:
14687 return _("NT_VMS_IMGBID (build id)");
14688 case NT_VMS_GSTNAM:
14689 return _("NT_VMS_GSTNAM (sym table name)");
14690 case NT_VMS_ORIG_DYN:
14691 return "NT_VMS_ORIG_DYN";
14692 case NT_VMS_PATCHTIME:
14693 return "NT_VMS_PATCHTIME";
14695 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
14701 print_ia64_vms_note (Elf_Internal_Note * pnote)
14703 switch (pnote->type)
14706 if (pnote->descsz > 36)
14708 size_t l = strlen (pnote->descdata + 34);
14709 printf (_(" Creation date : %.17s\n"), pnote->descdata);
14710 printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17);
14711 printf (_(" Module name : %s\n"), pnote->descdata + 34);
14712 printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1);
14715 printf (_(" Invalid size\n"));
14718 printf (_(" Language: %s\n"), pnote->descdata);
14721 case NT_VMS_FPMODE:
14722 printf (_(" Floating Point mode: "));
14723 printf ("0x%016" BFD_VMA_FMT "x\n",
14724 (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
14726 case NT_VMS_LINKTIME:
14727 printf (_(" Link time: "));
14729 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
14732 case NT_VMS_PATCHTIME:
14733 printf (_(" Patch time: "));
14735 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
14738 case NT_VMS_ORIG_DYN:
14739 printf (_(" Major id: %u, minor id: %u\n"),
14740 (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
14741 (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
14742 printf (_(" Last modified : "));
14744 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
14745 printf (_("\n Link flags : "));
14746 printf ("0x%016" BFD_VMA_FMT "x\n",
14747 (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
14748 printf (_(" Header flags: 0x%08x\n"),
14749 (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
14750 printf (_(" Image id : %s\n"), pnote->descdata + 32);
14753 case NT_VMS_IMGNAM:
14754 printf (_(" Image name: %s\n"), pnote->descdata);
14756 case NT_VMS_GSTNAM:
14757 printf (_(" Global symbol table name: %s\n"), pnote->descdata);
14760 printf (_(" Image id: %s\n"), pnote->descdata);
14762 case NT_VMS_LINKID:
14763 printf (_(" Linker id: %s\n"), pnote->descdata);
14771 /* Note that by the ELF standard, the name field is already null byte
14772 terminated, and namesz includes the terminating null byte.
14773 I.E. the value of namesz for the name "FSF" is 4.
14775 If the value of namesz is zero, there is no name present. */
14777 process_note (Elf_Internal_Note * pnote)
14779 const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
14782 if (pnote->namesz == 0)
14783 /* If there is no note name, then use the default set of
14784 note type strings. */
14785 nt = get_note_type (pnote->type);
14787 else if (const_strneq (pnote->namedata, "GNU"))
14788 /* GNU-specific object file notes. */
14789 nt = get_gnu_elf_note_type (pnote->type);
14791 else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
14792 /* NetBSD-specific core file notes. */
14793 nt = get_netbsd_elfcore_note_type (pnote->type);
14795 else if (strneq (pnote->namedata, "SPU/", 4))
14797 /* SPU-specific core file notes. */
14798 nt = pnote->namedata + 4;
14802 else if (const_strneq (pnote->namedata, "IPF/VMS"))
14803 /* VMS/ia64-specific file notes. */
14804 nt = get_ia64_vms_note_type (pnote->type);
14806 else if (const_strneq (pnote->namedata, "stapsdt"))
14807 nt = get_stapsdt_note_type (pnote->type);
14810 /* Don't recognize this note name; just use the default set of
14811 note type strings. */
14812 nt = get_note_type (pnote->type);
14814 printf (" %-20s 0x%08lx\t%s\n", name, pnote->descsz, nt);
14816 if (const_strneq (pnote->namedata, "IPF/VMS"))
14817 return print_ia64_vms_note (pnote);
14818 else if (const_strneq (pnote->namedata, "GNU"))
14819 return print_gnu_note (pnote);
14820 else if (const_strneq (pnote->namedata, "stapsdt"))
14821 return print_stapsdt_note (pnote);
14822 else if (const_strneq (pnote->namedata, "CORE"))
14823 return print_core_note (pnote);
14830 process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length)
14832 Elf_External_Note * pnotes;
14833 Elf_External_Note * external;
14840 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length,
14842 if (pnotes == NULL)
14847 printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
14848 (unsigned long) offset, (unsigned long) length);
14849 printf (_(" %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
14851 end = (char *) pnotes + length;
14852 while ((char *) external < end)
14854 Elf_Internal_Note inote;
14857 char * temp = NULL;
14858 size_t data_remaining = end - (char *) external;
14860 if (!is_ia64_vms ())
14862 /* PR binutils/15191
14863 Make sure that there is enough data to read. */
14864 min_notesz = offsetof (Elf_External_Note, name);
14865 if (data_remaining < min_notesz)
14867 warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
14868 (int) data_remaining);
14871 inote.type = BYTE_GET (external->type);
14872 inote.namesz = BYTE_GET (external->namesz);
14873 inote.namedata = external->name;
14874 inote.descsz = BYTE_GET (external->descsz);
14875 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
14876 /* PR 17531: file: 3443835e. */
14877 if (inote.descdata < (char *) pnotes || inote.descdata > end)
14879 warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
14880 inote.descdata = inote.namedata;
14884 inote.descpos = offset + (inote.descdata - (char *) pnotes);
14885 next = inote.descdata + align_power (inote.descsz, 2);
14889 Elf64_External_VMS_Note *vms_external;
14891 /* PR binutils/15191
14892 Make sure that there is enough data to read. */
14893 min_notesz = offsetof (Elf64_External_VMS_Note, name);
14894 if (data_remaining < min_notesz)
14896 warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
14897 (int) data_remaining);
14901 vms_external = (Elf64_External_VMS_Note *) external;
14902 inote.type = BYTE_GET (vms_external->type);
14903 inote.namesz = BYTE_GET (vms_external->namesz);
14904 inote.namedata = vms_external->name;
14905 inote.descsz = BYTE_GET (vms_external->descsz);
14906 inote.descdata = inote.namedata + align_power (inote.namesz, 3);
14907 inote.descpos = offset + (inote.descdata - (char *) pnotes);
14908 next = inote.descdata + align_power (inote.descsz, 3);
14911 if (inote.descdata < (char *) external + min_notesz
14912 || next < (char *) external + min_notesz
14913 /* PR binutils/17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
14914 || inote.namedata + inote.namesz < inote.namedata
14915 || inote.descdata + inote.descsz < inote.descdata
14916 || data_remaining < (size_t)(next - (char *) external))
14918 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
14919 (unsigned long) ((char *) external - (char *) pnotes));
14920 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx\n"),
14921 inote.type, inote.namesz, inote.descsz);
14925 external = (Elf_External_Note *) next;
14927 /* Verify that name is null terminated. It appears that at least
14928 one version of Linux (RedHat 6.0) generates corefiles that don't
14929 comply with the ELF spec by failing to include the null byte in
14931 if (inote.namedata[inote.namesz - 1] != '\0')
14933 temp = (char *) malloc (inote.namesz + 1);
14936 error (_("Out of memory allocating space for inote name\n"));
14941 strncpy (temp, inote.namedata, inote.namesz);
14942 temp[inote.namesz] = 0;
14944 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
14945 inote.namedata = temp;
14948 res &= process_note (& inote);
14963 process_corefile_note_segments (FILE * file)
14965 Elf_Internal_Phdr * segment;
14969 if (! get_program_headers (file))
14972 for (i = 0, segment = program_headers;
14973 i < elf_header.e_phnum;
14976 if (segment->p_type == PT_NOTE)
14977 res &= process_corefile_note_segment (file,
14978 (bfd_vma) segment->p_offset,
14979 (bfd_vma) segment->p_filesz);
14986 process_note_sections (FILE * file)
14988 Elf_Internal_Shdr * section;
14993 for (i = 0, section = section_headers;
14994 i < elf_header.e_shnum && section != NULL;
14996 if (section->sh_type == SHT_NOTE)
14998 res &= process_corefile_note_segment (file,
14999 (bfd_vma) section->sh_offset,
15000 (bfd_vma) section->sh_size);
15005 /* Try processing NOTE segments instead. */
15006 return process_corefile_note_segments (file);
15012 process_notes (FILE * file)
15014 /* If we have not been asked to display the notes then do nothing. */
15018 if (elf_header.e_type != ET_CORE)
15019 return process_note_sections (file);
15021 /* No program headers means no NOTE segment. */
15022 if (elf_header.e_phnum > 0)
15023 return process_corefile_note_segments (file);
15025 printf (_("No note segments present in the core file.\n"));
15030 process_arch_specific (FILE * file)
15035 switch (elf_header.e_machine)
15038 return process_arm_specific (file);
15040 case EM_MIPS_RS3_LE:
15041 return process_mips_specific (file);
15044 return process_nds32_specific (file);
15047 return process_power_specific (file);
15050 case EM_SPARC32PLUS:
15052 return process_sparc_specific (file);
15055 return process_tic6x_specific (file);
15058 return process_msp430x_specific (file);
15066 get_file_header (FILE * file)
15068 /* Read in the identity array. */
15069 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
15072 /* Determine how to read the rest of the header. */
15073 switch (elf_header.e_ident[EI_DATA])
15075 default: /* fall through */
15076 case ELFDATANONE: /* fall through */
15078 byte_get = byte_get_little_endian;
15079 byte_put = byte_put_little_endian;
15082 byte_get = byte_get_big_endian;
15083 byte_put = byte_put_big_endian;
15087 /* For now we only support 32 bit and 64 bit ELF files. */
15088 is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
15090 /* Read in the rest of the header. */
15093 Elf32_External_Ehdr ehdr32;
15095 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
15098 elf_header.e_type = BYTE_GET (ehdr32.e_type);
15099 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
15100 elf_header.e_version = BYTE_GET (ehdr32.e_version);
15101 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
15102 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
15103 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
15104 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
15105 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
15106 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
15107 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
15108 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
15109 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
15110 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
15114 Elf64_External_Ehdr ehdr64;
15116 /* If we have been compiled with sizeof (bfd_vma) == 4, then
15117 we will not be able to cope with the 64bit data found in
15118 64 ELF files. Detect this now and abort before we start
15119 overwriting things. */
15120 if (sizeof (bfd_vma) < 8)
15122 error (_("This instance of readelf has been built without support for a\n\
15123 64 bit data type and so it cannot read 64 bit ELF files.\n"));
15127 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
15130 elf_header.e_type = BYTE_GET (ehdr64.e_type);
15131 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
15132 elf_header.e_version = BYTE_GET (ehdr64.e_version);
15133 elf_header.e_entry = BYTE_GET (ehdr64.e_entry);
15134 elf_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
15135 elf_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
15136 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
15137 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
15138 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
15139 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
15140 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
15141 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
15142 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
15145 if (elf_header.e_shoff)
15147 /* There may be some extensions in the first section header. Don't
15148 bomb if we can't read it. */
15150 get_32bit_section_headers (file, TRUE);
15152 get_64bit_section_headers (file, TRUE);
15158 /* Process one ELF object file according to the command line options.
15159 This file may actually be stored in an archive. The file is
15160 positioned at the start of the ELF object. */
15163 process_object (char * file_name, FILE * file)
15167 if (! get_file_header (file))
15169 error (_("%s: Failed to read file header\n"), file_name);
15173 /* Initialise per file variables. */
15174 for (i = ARRAY_SIZE (version_info); i--;)
15175 version_info[i] = 0;
15177 for (i = ARRAY_SIZE (dynamic_info); i--;)
15178 dynamic_info[i] = 0;
15179 dynamic_info_DT_GNU_HASH = 0;
15181 /* Process the file. */
15183 printf (_("\nFile: %s\n"), file_name);
15185 /* Initialise the dump_sects array from the cmdline_dump_sects array.
15186 Note we do this even if cmdline_dump_sects is empty because we
15187 must make sure that the dump_sets array is zeroed out before each
15188 object file is processed. */
15189 if (num_dump_sects > num_cmdline_dump_sects)
15190 memset (dump_sects, 0, num_dump_sects * sizeof (* dump_sects));
15192 if (num_cmdline_dump_sects > 0)
15194 if (num_dump_sects == 0)
15195 /* A sneaky way of allocating the dump_sects array. */
15196 request_dump_bynumber (num_cmdline_dump_sects, 0);
15198 assert (num_dump_sects >= num_cmdline_dump_sects);
15199 memcpy (dump_sects, cmdline_dump_sects,
15200 num_cmdline_dump_sects * sizeof (* dump_sects));
15203 if (! process_file_header ())
15206 if (! process_section_headers (file))
15208 /* Without loaded section headers we cannot process lots of
15210 do_unwind = do_version = do_dump = do_arch = 0;
15212 if (! do_using_dynamic)
15213 do_syms = do_dyn_syms = do_reloc = 0;
15216 if (! process_section_groups (file))
15218 /* Without loaded section groups we cannot process unwind. */
15222 if (process_program_headers (file))
15223 process_dynamic_section (file);
15225 process_relocs (file);
15227 process_unwind (file);
15229 process_symbol_table (file);
15231 process_syminfo (file);
15233 process_version_sections (file);
15235 process_section_contents (file);
15237 process_notes (file);
15239 process_gnu_liblist (file);
15241 process_arch_specific (file);
15243 if (program_headers)
15245 free (program_headers);
15246 program_headers = NULL;
15249 if (section_headers)
15251 free (section_headers);
15252 section_headers = NULL;
15257 free (string_table);
15258 string_table = NULL;
15259 string_table_length = 0;
15262 if (dynamic_strings)
15264 free (dynamic_strings);
15265 dynamic_strings = NULL;
15266 dynamic_strings_length = 0;
15269 if (dynamic_symbols)
15271 free (dynamic_symbols);
15272 dynamic_symbols = NULL;
15273 num_dynamic_syms = 0;
15276 if (dynamic_syminfo)
15278 free (dynamic_syminfo);
15279 dynamic_syminfo = NULL;
15282 if (dynamic_section)
15284 free (dynamic_section);
15285 dynamic_section = NULL;
15288 if (section_headers_groups)
15290 free (section_headers_groups);
15291 section_headers_groups = NULL;
15294 if (section_groups)
15296 struct group_list * g;
15297 struct group_list * next;
15299 for (i = 0; i < group_count; i++)
15301 for (g = section_groups [i].root; g != NULL; g = next)
15308 free (section_groups);
15309 section_groups = NULL;
15312 free_debug_memory ();
15317 /* Process an ELF archive.
15318 On entry the file is positioned just after the ARMAG string. */
15321 process_archive (char * file_name, FILE * file, bfd_boolean is_thin_archive)
15323 struct archive_info arch;
15324 struct archive_info nested_arch;
15330 /* The ARCH structure is used to hold information about this archive. */
15331 arch.file_name = NULL;
15333 arch.index_array = NULL;
15334 arch.sym_table = NULL;
15335 arch.longnames = NULL;
15337 /* The NESTED_ARCH structure is used as a single-item cache of information
15338 about a nested archive (when members of a thin archive reside within
15339 another regular archive file). */
15340 nested_arch.file_name = NULL;
15341 nested_arch.file = NULL;
15342 nested_arch.index_array = NULL;
15343 nested_arch.sym_table = NULL;
15344 nested_arch.longnames = NULL;
15346 if (setup_archive (&arch, file_name, file, is_thin_archive, do_archive_index) != 0)
15352 if (do_archive_index)
15354 if (arch.sym_table == NULL)
15355 error (_("%s: unable to dump the index as none was found\n"), file_name);
15358 unsigned long i, l;
15359 unsigned long current_pos;
15361 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"),
15362 file_name, (unsigned long) arch.index_num, arch.sym_size);
15363 current_pos = ftell (file);
15365 for (i = l = 0; i < arch.index_num; i++)
15367 if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
15369 char * member_name;
15371 member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
15373 if (member_name != NULL)
15375 char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
15377 if (qualified_name != NULL)
15379 printf (_("Contents of binary %s at offset "), qualified_name);
15380 (void) print_vma (arch.index_array[i], PREFIX_HEX);
15382 free (qualified_name);
15387 if (l >= arch.sym_size)
15389 error (_("%s: end of the symbol table reached before the end of the index\n"),
15393 /* PR 17531: file: 0b6630b2. */
15394 printf ("\t%.*s\n", (int) (arch.sym_size - l), arch.sym_table + l);
15395 l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
15398 if (arch.uses_64bit_indicies)
15403 if (l < arch.sym_size)
15404 error (_("%s: %ld bytes remain in the symbol table, but without corresponding entries in the index table\n"),
15405 file_name, arch.sym_size - l);
15407 if (fseek (file, current_pos, SEEK_SET) != 0)
15409 error (_("%s: failed to seek back to start of object files in the archive\n"), file_name);
15415 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
15416 && !do_segments && !do_header && !do_dump && !do_version
15417 && !do_histogram && !do_debugging && !do_arch && !do_notes
15418 && !do_section_groups && !do_dyn_syms)
15420 ret = 0; /* Archive index only. */
15431 char * qualified_name;
15433 /* Read the next archive header. */
15434 if (fseek (file, arch.next_arhdr_offset, SEEK_SET) != 0)
15436 error (_("%s: failed to seek to next archive header\n"), file_name);
15439 got = fread (&arch.arhdr, 1, sizeof arch.arhdr, file);
15440 if (got != sizeof arch.arhdr)
15444 error (_("%s: failed to read archive header\n"), file_name);
15448 if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
15450 error (_("%s: did not find a valid archive header\n"), arch.file_name);
15455 arch.next_arhdr_offset += sizeof arch.arhdr;
15457 archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
15458 if (archive_file_size & 01)
15459 ++archive_file_size;
15461 name = get_archive_member_name (&arch, &nested_arch);
15464 error (_("%s: bad archive file name\n"), file_name);
15468 namelen = strlen (name);
15470 qualified_name = make_qualified_name (&arch, &nested_arch, name);
15471 if (qualified_name == NULL)
15473 error (_("%s: bad archive file name\n"), file_name);
15478 if (is_thin_archive && arch.nested_member_origin == 0)
15480 /* This is a proxy for an external member of a thin archive. */
15481 FILE * member_file;
15482 char * member_file_name = adjust_relative_path (file_name, name, namelen);
15483 if (member_file_name == NULL)
15489 member_file = fopen (member_file_name, "rb");
15490 if (member_file == NULL)
15492 error (_("Input file '%s' is not readable.\n"), member_file_name);
15493 free (member_file_name);
15498 archive_file_offset = arch.nested_member_origin;
15500 ret |= process_object (qualified_name, member_file);
15502 fclose (member_file);
15503 free (member_file_name);
15505 else if (is_thin_archive)
15507 /* PR 15140: Allow for corrupt thin archives. */
15508 if (nested_arch.file == NULL)
15510 error (_("%s: contains corrupt thin archive: %s\n"),
15516 /* This is a proxy for a member of a nested archive. */
15517 archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
15519 /* The nested archive file will have been opened and setup by
15520 get_archive_member_name. */
15521 if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
15523 error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
15528 ret |= process_object (qualified_name, nested_arch.file);
15532 archive_file_offset = arch.next_arhdr_offset;
15533 arch.next_arhdr_offset += archive_file_size;
15535 ret |= process_object (qualified_name, file);
15538 if (dump_sects != NULL)
15542 num_dump_sects = 0;
15545 free (qualified_name);
15549 if (nested_arch.file != NULL)
15550 fclose (nested_arch.file);
15551 release_archive (&nested_arch);
15552 release_archive (&arch);
15558 process_file (char * file_name)
15561 struct stat statbuf;
15562 char armag[SARMAG];
15565 if (stat (file_name, &statbuf) < 0)
15567 if (errno == ENOENT)
15568 error (_("'%s': No such file\n"), file_name);
15570 error (_("Could not locate '%s'. System error message: %s\n"),
15571 file_name, strerror (errno));
15575 if (! S_ISREG (statbuf.st_mode))
15577 error (_("'%s' is not an ordinary file\n"), file_name);
15581 file = fopen (file_name, "rb");
15584 error (_("Input file '%s' is not readable.\n"), file_name);
15588 if (fread (armag, SARMAG, 1, file) != 1)
15590 error (_("%s: Failed to read file's magic number\n"), file_name);
15595 current_file_size = (bfd_size_type) statbuf.st_size;
15597 if (memcmp (armag, ARMAG, SARMAG) == 0)
15598 ret = process_archive (file_name, file, FALSE);
15599 else if (memcmp (armag, ARMAGT, SARMAG) == 0)
15600 ret = process_archive (file_name, file, TRUE);
15603 if (do_archive_index)
15604 error (_("File %s is not an archive so its index cannot be displayed.\n"),
15608 archive_file_size = archive_file_offset = 0;
15609 ret = process_object (file_name, file);
15614 current_file_size = 0;
15618 #ifdef SUPPORT_DISASSEMBLY
15619 /* Needed by the i386 disassembler. For extra credit, someone could
15620 fix this so that we insert symbolic addresses here, esp for GOT/PLT
15624 print_address (unsigned int addr, FILE * outfile)
15626 fprintf (outfile,"0x%8.8x", addr);
15629 /* Needed by the i386 disassembler. */
15631 db_task_printsym (unsigned int addr)
15633 print_address (addr, stderr);
15638 main (int argc, char ** argv)
15642 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
15643 setlocale (LC_MESSAGES, "");
15645 #if defined (HAVE_SETLOCALE)
15646 setlocale (LC_CTYPE, "");
15648 bindtextdomain (PACKAGE, LOCALEDIR);
15649 textdomain (PACKAGE);
15651 expandargv (&argc, &argv);
15653 parse_args (argc, argv);
15655 if (num_dump_sects > 0)
15657 /* Make a copy of the dump_sects array. */
15658 cmdline_dump_sects = (dump_type *)
15659 malloc (num_dump_sects * sizeof (* dump_sects));
15660 if (cmdline_dump_sects == NULL)
15661 error (_("Out of memory allocating dump request table.\n"));
15664 memcpy (cmdline_dump_sects, dump_sects,
15665 num_dump_sects * sizeof (* dump_sects));
15666 num_cmdline_dump_sects = num_dump_sects;
15670 if (optind < (argc - 1))
15674 while (optind < argc)
15675 err |= process_file (argv[optind++]);
15677 if (dump_sects != NULL)
15679 if (cmdline_dump_sects != NULL)
15680 free (cmdline_dump_sects);