1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998-2018 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. */
52 /* Define BFD64 here, even if our default architecture is 32 bit ELF
53 as this will allow us to read in and parse 64bit and 32bit ELF files.
54 Only do this if we believe that the compiler can support a 64 bit
55 data type. For now we only rely on GCC being able to do this. */
64 #include "elf/common.h"
65 #include "elf/external.h"
66 #include "elf/internal.h"
69 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
70 we can obtain the H8 reloc numbers. We need these for the
71 get_reloc_size() function. We include h8.h again after defining
72 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
77 /* Undo the effects of #including reloc-macros.h. */
79 #undef START_RELOC_NUMBERS
83 #undef END_RELOC_NUMBERS
84 #undef _RELOC_MACROS_H
86 /* The following headers use the elf/reloc-macros.h file to
87 automatically generate relocation recognition functions
88 such as elf_mips_reloc_type() */
90 #define RELOC_MACROS_GEN_FUNC
92 #include "elf/aarch64.h"
93 #include "elf/alpha.h"
101 #include "elf/d10v.h"
102 #include "elf/d30v.h"
104 #include "elf/epiphany.h"
105 #include "elf/fr30.h"
107 #include "elf/ft32.h"
109 #include "elf/hppa.h"
110 #include "elf/i386.h"
111 #include "elf/ia64.h"
112 #include "elf/ip2k.h"
113 #include "elf/lm32.h"
114 #include "elf/iq2000.h"
115 #include "elf/m32c.h"
116 #include "elf/m32r.h"
117 #include "elf/m68k.h"
118 #include "elf/m68hc11.h"
119 #include "elf/mcore.h"
121 #include "elf/metag.h"
122 #include "elf/microblaze.h"
123 #include "elf/mips.h"
124 #include "elf/mmix.h"
125 #include "elf/mn10200.h"
126 #include "elf/mn10300.h"
127 #include "elf/moxie.h"
129 #include "elf/msp430.h"
130 #include "elf/nds32.h"
131 #include "elf/nios2.h"
132 #include "elf/or1k.h"
135 #include "elf/ppc64.h"
137 #include "elf/riscv.h"
138 #include "elf/rl78.h"
140 #include "elf/s390.h"
141 #include "elf/score.h"
143 #include "elf/sparc.h"
145 #include "elf/tic6x.h"
146 #include "elf/tilegx.h"
147 #include "elf/tilepro.h"
148 #include "elf/v850.h"
150 #include "elf/visium.h"
151 #include "elf/wasm32.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 typedef struct elf_section_list
169 Elf_Internal_Shdr * hdr;
170 struct elf_section_list * next;
173 /* Flag bits indicating particular types of dump. */
174 #define HEX_DUMP (1 << 0) /* The -x command line switch. */
175 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
176 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
177 #define STRING_DUMP (1 << 3) /* The -p command line switch. */
178 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
180 typedef unsigned char dump_type;
182 /* A linked list of the section names for which dumps were requested. */
183 struct dump_list_entry
187 struct dump_list_entry * next;
190 typedef struct filedata
192 const char * file_name;
194 bfd_size_type file_size;
195 Elf_Internal_Ehdr file_header;
196 Elf_Internal_Shdr * section_headers;
197 Elf_Internal_Phdr * program_headers;
199 unsigned long string_table_length;
200 /* A dynamic array of flags indicating for which sections a dump of
201 some kind has been requested. It is reset on a per-object file
202 basis and then initialised from the cmdline_dump_sects array,
203 the results of interpreting the -w switch, and the
204 dump_sects_byname list. */
205 dump_type * dump_sects;
206 unsigned int num_dump_sects;
209 char * program_name = "readelf";
211 static unsigned long archive_file_offset;
212 static unsigned long archive_file_size;
213 static unsigned long dynamic_addr;
214 static bfd_size_type dynamic_size;
215 static size_t dynamic_nent;
216 static char * dynamic_strings;
217 static unsigned long dynamic_strings_length;
218 static unsigned long num_dynamic_syms;
219 static Elf_Internal_Sym * dynamic_symbols;
220 static Elf_Internal_Syminfo * dynamic_syminfo;
221 static unsigned long dynamic_syminfo_offset;
222 static unsigned int dynamic_syminfo_nent;
223 static char program_interpreter[PATH_MAX];
224 static bfd_vma dynamic_info[DT_ENCODING];
225 static bfd_vma dynamic_info_DT_GNU_HASH;
226 static bfd_vma version_info[16];
227 static Elf_Internal_Dyn * dynamic_section;
228 static elf_section_list * symtab_shndx_list;
229 static bfd_boolean show_name = FALSE;
230 static bfd_boolean do_dynamic = FALSE;
231 static bfd_boolean do_syms = FALSE;
232 static bfd_boolean do_dyn_syms = FALSE;
233 static bfd_boolean do_reloc = FALSE;
234 static bfd_boolean do_sections = FALSE;
235 static bfd_boolean do_section_groups = FALSE;
236 static bfd_boolean do_section_details = FALSE;
237 static bfd_boolean do_segments = FALSE;
238 static bfd_boolean do_unwind = FALSE;
239 static bfd_boolean do_using_dynamic = FALSE;
240 static bfd_boolean do_header = FALSE;
241 static bfd_boolean do_dump = FALSE;
242 static bfd_boolean do_version = FALSE;
243 static bfd_boolean do_histogram = FALSE;
244 static bfd_boolean do_debugging = FALSE;
245 static bfd_boolean do_arch = FALSE;
246 static bfd_boolean do_notes = FALSE;
247 static bfd_boolean do_archive_index = FALSE;
248 static bfd_boolean is_32bit_elf = FALSE;
249 static bfd_boolean decompress_dumps = FALSE;
253 struct group_list * next;
254 unsigned int section_index;
259 struct group_list * root;
260 unsigned int group_index;
263 static size_t group_count;
264 static struct group * section_groups;
265 static struct group ** section_headers_groups;
267 /* A dynamic array of flags indicating for which sections a dump
268 has been requested via command line switches. */
269 static Filedata cmdline;
271 static struct dump_list_entry * dump_sects_byname;
273 /* How to print a vma value. */
274 typedef enum print_mode
286 /* Versioned symbol info. */
287 enum versioned_symbol_info
294 static const char * get_symbol_version_string
295 (Filedata *, bfd_boolean, const char *, unsigned long, unsigned,
296 Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *);
300 #define SECTION_NAME(X) \
301 ((X) == NULL ? _("<none>") \
302 : filedata->string_table == NULL ? _("<no-strings>") \
303 : ((X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \
304 : filedata->string_table + (X)->sh_name))
306 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
308 #define GET_ELF_SYMBOLS(file, section, sym_count) \
309 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
310 : get_64bit_elf_symbols (file, section, sym_count))
312 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
313 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
314 already been called and verified that the string exists. */
315 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
317 #define REMOVE_ARCH_BITS(ADDR) \
320 if (filedata->file_header.e_machine == EM_ARM) \
325 /* Print a BFD_VMA to an internal buffer, for use in error messages.
326 BFD_FMA_FMT can't be used in translated strings. */
329 bfd_vmatoa (char *fmtch, bfd_vma value)
331 /* bfd_vmatoa is used more then once in a printf call for output.
332 Cycle through an array of buffers. */
333 static int buf_pos = 0;
334 static struct bfd_vmatoa_buf
341 ret = buf[buf_pos++].place;
342 buf_pos %= ARRAY_SIZE (buf);
344 sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
345 snprintf (ret, sizeof (buf[0].place), fmt, value);
349 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
350 OFFSET + the offset of the current archive member, if we are examining an
351 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
352 allocate a buffer using malloc and fill that. In either case return the
353 pointer to the start of the retrieved data or NULL if something went wrong.
354 If something does go wrong and REASON is not NULL then emit an error
355 message using REASON as part of the context. */
358 get_data (void * var,
360 unsigned long offset,
366 bfd_size_type amt = size * nmemb;
368 if (size == 0 || nmemb == 0)
371 /* If the size_t type is smaller than the bfd_size_type, eg because
372 you are building a 32-bit tool on a 64-bit host, then make sure
373 that when the sizes are cast to (size_t) no information is lost. */
374 if (sizeof (size_t) < sizeof (bfd_size_type)
375 && ( (bfd_size_type) ((size_t) size) != size
376 || (bfd_size_type) ((size_t) nmemb) != nmemb))
379 error (_("Size truncation prevents reading %s"
380 " elements of size %s for %s\n"),
381 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
385 /* Check for size overflow. */
389 error (_("Size overflow prevents reading %s"
390 " elements of size %s for %s\n"),
391 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
395 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
396 attempting to allocate memory when the read is bound to fail. */
397 if (amt > filedata->file_size
398 || offset + archive_file_offset + amt > filedata->file_size)
401 error (_("Reading %s bytes extends past end of file for %s\n"),
402 bfd_vmatoa ("u", amt), reason);
406 if (fseek (filedata->handle, archive_file_offset + offset, SEEK_SET))
409 error (_("Unable to seek to 0x%lx for %s\n"),
410 archive_file_offset + offset, reason);
417 /* Check for overflow. */
418 if (nmemb < (~(bfd_size_type) 0 - 1) / size)
419 /* + 1 so that we can '\0' terminate invalid string table sections. */
420 mvar = malloc ((size_t) amt + 1);
425 error (_("Out of memory allocating %s bytes for %s\n"),
426 bfd_vmatoa ("u", amt), reason);
430 ((char *) mvar)[amt] = '\0';
433 if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb)
436 error (_("Unable to read in %s bytes of %s\n"),
437 bfd_vmatoa ("u", amt), reason);
446 /* Print a VMA value in the MODE specified.
447 Returns the number of characters displayed. */
450 print_vma (bfd_vma vma, print_mode mode)
462 return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
469 return printf ("%5" BFD_VMA_FMT "d", vma);
475 return nc + printf ("%" BFD_VMA_FMT "x", vma);
478 return printf ("%" BFD_VMA_FMT "d", vma);
481 return printf ("%" BFD_VMA_FMT "u", vma);
484 /* FIXME: Report unrecognised mode ? */
489 /* Display a symbol on stdout. Handles the display of control characters and
490 multibye characters (assuming the host environment supports them).
492 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
494 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
495 padding as necessary.
497 Returns the number of emitted characters. */
500 print_symbol (signed int width, const char *symbol)
502 bfd_boolean extra_padding = FALSE;
503 signed int num_printed = 0;
504 #ifdef HAVE_MBSTATE_T
507 unsigned int width_remaining;
511 /* Keep the width positive. This helps the code below. */
513 extra_padding = TRUE;
518 /* Set the remaining width to a very large value.
519 This simplifies the code below. */
520 width_remaining = INT_MAX;
522 width_remaining = width;
524 #ifdef HAVE_MBSTATE_T
525 /* Initialise the multibyte conversion state. */
526 memset (& state, 0, sizeof (state));
529 while (width_remaining)
532 const char c = *symbol++;
537 /* Do not print control characters directly as they can affect terminal
538 settings. Such characters usually appear in the names generated
539 by the assembler for local labels. */
542 if (width_remaining < 2)
545 printf ("^%c", c + 0x40);
546 width_remaining -= 2;
549 else if (ISPRINT (c))
557 #ifdef HAVE_MBSTATE_T
560 /* Let printf do the hard work of displaying multibyte characters. */
561 printf ("%.1s", symbol - 1);
565 #ifdef HAVE_MBSTATE_T
566 /* Try to find out how many bytes made up the character that was
567 just printed. Advance the symbol pointer past the bytes that
569 n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
573 if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
578 if (extra_padding && num_printed < width)
580 /* Fill in the remaining spaces. */
581 printf ("%-*s", width - num_printed, " ");
588 /* Returns a pointer to a static buffer containing a printable version of
589 the given section's name. Like print_symbol, except that it does not try
590 to print multibyte characters, it just interprets them as hex values. */
593 printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec)
595 #define MAX_PRINT_SEC_NAME_LEN 128
596 static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
597 const char * name = SECTION_NAME (sec);
598 char * buf = sec_name_buf;
600 unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
602 while ((c = * name ++) != 0)
613 else if (ISPRINT (c))
620 static char hex[17] = "0123456789ABCDEF";
625 * buf ++ = hex[(c & 0xf0) >> 4];
626 * buf ++ = hex[c & 0x0f];
640 printable_section_name_from_index (Filedata * filedata, unsigned long ndx)
642 if (ndx >= filedata->file_header.e_shnum)
643 return _("<corrupt>");
645 return printable_section_name (filedata, filedata->section_headers + ndx);
648 /* Return a pointer to section NAME, or NULL if no such section exists. */
650 static Elf_Internal_Shdr *
651 find_section (Filedata * filedata, const char * name)
655 if (filedata->section_headers == NULL)
658 for (i = 0; i < filedata->file_header.e_shnum; i++)
659 if (streq (SECTION_NAME (filedata->section_headers + i), name))
660 return filedata->section_headers + i;
665 /* Return a pointer to a section containing ADDR, or NULL if no such
668 static Elf_Internal_Shdr *
669 find_section_by_address (Filedata * filedata, bfd_vma addr)
673 if (filedata->section_headers == NULL)
676 for (i = 0; i < filedata->file_header.e_shnum; i++)
678 Elf_Internal_Shdr *sec = filedata->section_headers + i;
680 if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
687 static Elf_Internal_Shdr *
688 find_section_by_type (Filedata * filedata, unsigned int type)
692 if (filedata->section_headers == NULL)
695 for (i = 0; i < filedata->file_header.e_shnum; i++)
697 Elf_Internal_Shdr *sec = filedata->section_headers + i;
699 if (sec->sh_type == type)
706 /* Return a pointer to section NAME, or NULL if no such section exists,
707 restricted to the list of sections given in SET. */
709 static Elf_Internal_Shdr *
710 find_section_in_set (Filedata * filedata, const char * name, unsigned int * set)
714 if (filedata->section_headers == NULL)
719 while ((i = *set++) > 0)
721 /* See PR 21156 for a reproducer. */
722 if (i >= filedata->file_header.e_shnum)
723 continue; /* FIXME: Should we issue an error message ? */
725 if (streq (SECTION_NAME (filedata->section_headers + i), name))
726 return filedata->section_headers + i;
730 return find_section (filedata, name);
733 /* Read an unsigned LEB128 encoded value from DATA.
734 Set *LENGTH_RETURN to the number of bytes read. */
736 static inline unsigned long
737 read_uleb128 (unsigned char * data,
738 unsigned int * length_return,
739 const unsigned char * const end)
741 return read_leb128 (data, length_return, FALSE, end);
744 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
745 This OS has so many departures from the ELF standard that we test it at
748 static inline bfd_boolean
749 is_ia64_vms (Filedata * filedata)
751 return filedata->file_header.e_machine == EM_IA_64
752 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
755 /* Guess the relocation size commonly used by the specific machines. */
758 guess_is_rela (unsigned int e_machine)
762 /* Targets that use REL relocations. */
776 /* Targets that use RELA relocations. */
779 case EM_ADAPTEVA_EPIPHANY:
781 case EM_ALTERA_NIOS2:
784 case EM_ARC_COMPACT2:
804 case EM_LATTICEMICO32:
813 case EM_CYGNUS_MN10200:
815 case EM_CYGNUS_MN10300:
851 case EM_MICROBLAZE_OLD:
873 warn (_("Don't know about relocations on this machine architecture\n"));
878 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
879 Returns TRUE upon success, FALSE otherwise. If successful then a
880 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
881 and the number of relocs loaded is placed in *NRELASP. It is the caller's
882 responsibility to free the allocated buffer. */
885 slurp_rela_relocs (Filedata * filedata,
886 unsigned long rel_offset,
887 unsigned long rel_size,
888 Elf_Internal_Rela ** relasp,
889 unsigned long * nrelasp)
891 Elf_Internal_Rela * relas;
897 Elf32_External_Rela * erelas;
899 erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
900 rel_size, _("32-bit relocation data"));
904 nrelas = rel_size / sizeof (Elf32_External_Rela);
906 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
907 sizeof (Elf_Internal_Rela));
912 error (_("out of memory parsing relocs\n"));
916 for (i = 0; i < nrelas; i++)
918 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
919 relas[i].r_info = BYTE_GET (erelas[i].r_info);
920 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
927 Elf64_External_Rela * erelas;
929 erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
930 rel_size, _("64-bit relocation data"));
934 nrelas = rel_size / sizeof (Elf64_External_Rela);
936 relas = (Elf_Internal_Rela *) cmalloc (nrelas,
937 sizeof (Elf_Internal_Rela));
942 error (_("out of memory parsing relocs\n"));
946 for (i = 0; i < nrelas; i++)
948 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
949 relas[i].r_info = BYTE_GET (erelas[i].r_info);
950 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
952 /* The #ifdef BFD64 below is to prevent a compile time
953 warning. We know that if we do not have a 64 bit data
954 type that we will never execute this code anyway. */
956 if (filedata->file_header.e_machine == EM_MIPS
957 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
959 /* In little-endian objects, r_info isn't really a
960 64-bit little-endian value: it has a 32-bit
961 little-endian symbol index followed by four
962 individual byte fields. Reorder INFO
964 bfd_vma inf = relas[i].r_info;
965 inf = (((inf & 0xffffffff) << 32)
966 | ((inf >> 56) & 0xff)
967 | ((inf >> 40) & 0xff00)
968 | ((inf >> 24) & 0xff0000)
969 | ((inf >> 8) & 0xff000000));
970 relas[i].r_info = inf;
983 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
984 Returns TRUE upon success, FALSE otherwise. If successful then a
985 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
986 and the number of relocs loaded is placed in *NRELSP. It is the caller's
987 responsibility to free the allocated buffer. */
990 slurp_rel_relocs (Filedata * filedata,
991 unsigned long rel_offset,
992 unsigned long rel_size,
993 Elf_Internal_Rela ** relsp,
994 unsigned long * nrelsp)
996 Elf_Internal_Rela * rels;
1002 Elf32_External_Rel * erels;
1004 erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
1005 rel_size, _("32-bit relocation data"));
1009 nrels = rel_size / sizeof (Elf32_External_Rel);
1011 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
1016 error (_("out of memory parsing relocs\n"));
1020 for (i = 0; i < nrels; i++)
1022 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1023 rels[i].r_info = BYTE_GET (erels[i].r_info);
1024 rels[i].r_addend = 0;
1031 Elf64_External_Rel * erels;
1033 erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
1034 rel_size, _("64-bit relocation data"));
1038 nrels = rel_size / sizeof (Elf64_External_Rel);
1040 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
1045 error (_("out of memory parsing relocs\n"));
1049 for (i = 0; i < nrels; i++)
1051 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
1052 rels[i].r_info = BYTE_GET (erels[i].r_info);
1053 rels[i].r_addend = 0;
1055 /* The #ifdef BFD64 below is to prevent a compile time
1056 warning. We know that if we do not have a 64 bit data
1057 type that we will never execute this code anyway. */
1059 if (filedata->file_header.e_machine == EM_MIPS
1060 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
1062 /* In little-endian objects, r_info isn't really a
1063 64-bit little-endian value: it has a 32-bit
1064 little-endian symbol index followed by four
1065 individual byte fields. Reorder INFO
1067 bfd_vma inf = rels[i].r_info;
1068 inf = (((inf & 0xffffffff) << 32)
1069 | ((inf >> 56) & 0xff)
1070 | ((inf >> 40) & 0xff00)
1071 | ((inf >> 24) & 0xff0000)
1072 | ((inf >> 8) & 0xff000000));
1073 rels[i].r_info = inf;
1086 /* Returns the reloc type extracted from the reloc info field. */
1089 get_reloc_type (Filedata * filedata, bfd_vma reloc_info)
1092 return ELF32_R_TYPE (reloc_info);
1094 switch (filedata->file_header.e_machine)
1097 /* Note: We assume that reloc_info has already been adjusted for us. */
1098 return ELF64_MIPS_R_TYPE (reloc_info);
1101 return ELF64_R_TYPE_ID (reloc_info);
1104 return ELF64_R_TYPE (reloc_info);
1108 /* Return the symbol index extracted from the reloc info field. */
1111 get_reloc_symindex (bfd_vma reloc_info)
1113 return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
1116 static inline bfd_boolean
1117 uses_msp430x_relocs (Filedata * filedata)
1120 filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */
1121 /* GCC uses osabi == ELFOSBI_STANDALONE. */
1122 && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
1123 /* TI compiler uses ELFOSABI_NONE. */
1124 || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
1127 /* Display the contents of the relocation data found at the specified
1131 dump_relocations (Filedata * filedata,
1132 unsigned long rel_offset,
1133 unsigned long rel_size,
1134 Elf_Internal_Sym * symtab,
1135 unsigned long nsyms,
1137 unsigned long strtablen,
1139 bfd_boolean is_dynsym)
1142 Elf_Internal_Rela * rels;
1143 bfd_boolean res = TRUE;
1145 if (is_rela == UNKNOWN)
1146 is_rela = guess_is_rela (filedata->file_header.e_machine);
1150 if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
1155 if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
1164 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1166 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1171 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1173 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1181 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1183 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1188 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1190 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1194 for (i = 0; i < rel_size; i++)
1199 bfd_vma symtab_index;
1202 offset = rels[i].r_offset;
1203 inf = rels[i].r_info;
1205 type = get_reloc_type (filedata, inf);
1206 symtab_index = get_reloc_symindex (inf);
1210 printf ("%8.8lx %8.8lx ",
1211 (unsigned long) offset & 0xffffffff,
1212 (unsigned long) inf & 0xffffffff);
1216 #if BFD_HOST_64BIT_LONG
1218 ? "%16.16lx %16.16lx "
1219 : "%12.12lx %12.12lx ",
1221 #elif BFD_HOST_64BIT_LONG_LONG
1224 ? "%16.16llx %16.16llx "
1225 : "%12.12llx %12.12llx ",
1229 ? "%16.16I64x %16.16I64x "
1230 : "%12.12I64x %12.12I64x ",
1235 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1236 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1237 _bfd_int64_high (offset),
1238 _bfd_int64_low (offset),
1239 _bfd_int64_high (inf),
1240 _bfd_int64_low (inf));
1244 switch (filedata->file_header.e_machine)
1251 rtype = elf_aarch64_reloc_type (type);
1255 case EM_CYGNUS_M32R:
1256 rtype = elf_m32r_reloc_type (type);
1261 rtype = elf_i386_reloc_type (type);
1266 rtype = elf_m68hc11_reloc_type (type);
1270 rtype = elf_m68k_reloc_type (type);
1275 rtype = elf_avr_reloc_type (type);
1278 case EM_OLD_SPARCV9:
1279 case EM_SPARC32PLUS:
1282 rtype = elf_sparc_reloc_type (type);
1286 rtype = elf_spu_reloc_type (type);
1290 rtype = v800_reloc_type (type);
1293 case EM_CYGNUS_V850:
1294 rtype = v850_reloc_type (type);
1298 case EM_CYGNUS_D10V:
1299 rtype = elf_d10v_reloc_type (type);
1303 case EM_CYGNUS_D30V:
1304 rtype = elf_d30v_reloc_type (type);
1308 rtype = elf_dlx_reloc_type (type);
1312 rtype = elf_sh_reloc_type (type);
1316 case EM_CYGNUS_MN10300:
1317 rtype = elf_mn10300_reloc_type (type);
1321 case EM_CYGNUS_MN10200:
1322 rtype = elf_mn10200_reloc_type (type);
1326 case EM_CYGNUS_FR30:
1327 rtype = elf_fr30_reloc_type (type);
1331 rtype = elf_frv_reloc_type (type);
1335 rtype = elf_ft32_reloc_type (type);
1339 rtype = elf_mcore_reloc_type (type);
1343 rtype = elf_mmix_reloc_type (type);
1347 rtype = elf_moxie_reloc_type (type);
1351 if (uses_msp430x_relocs (filedata))
1353 rtype = elf_msp430x_reloc_type (type);
1358 rtype = elf_msp430_reloc_type (type);
1362 rtype = elf_nds32_reloc_type (type);
1366 rtype = elf_ppc_reloc_type (type);
1370 rtype = elf_ppc64_reloc_type (type);
1374 case EM_MIPS_RS3_LE:
1375 rtype = elf_mips_reloc_type (type);
1379 rtype = elf_riscv_reloc_type (type);
1383 rtype = elf_alpha_reloc_type (type);
1387 rtype = elf_arm_reloc_type (type);
1391 case EM_ARC_COMPACT:
1392 case EM_ARC_COMPACT2:
1393 rtype = elf_arc_reloc_type (type);
1397 rtype = elf_hppa_reloc_type (type);
1403 rtype = elf_h8_reloc_type (type);
1407 rtype = elf_or1k_reloc_type (type);
1412 rtype = elf_pj_reloc_type (type);
1415 rtype = elf_ia64_reloc_type (type);
1419 rtype = elf_cris_reloc_type (type);
1425 rtype = elf_x86_64_reloc_type (type);
1430 rtype = elf_s390_reloc_type (type);
1434 rtype = elf_score_reloc_type (type);
1438 rtype = elf_xstormy16_reloc_type (type);
1442 rtype = elf_crx_reloc_type (type);
1446 rtype = elf_vax_reloc_type (type);
1450 rtype = elf_visium_reloc_type (type);
1453 case EM_ADAPTEVA_EPIPHANY:
1454 rtype = elf_epiphany_reloc_type (type);
1459 rtype = elf_ip2k_reloc_type (type);
1463 rtype = elf_iq2000_reloc_type (type);
1468 rtype = elf_xtensa_reloc_type (type);
1471 case EM_LATTICEMICO32:
1472 rtype = elf_lm32_reloc_type (type);
1477 rtype = elf_m32c_reloc_type (type);
1481 rtype = elf_mt_reloc_type (type);
1485 rtype = elf_bfin_reloc_type (type);
1489 rtype = elf_mep_reloc_type (type);
1493 rtype = elf_cr16_reloc_type (type);
1497 case EM_MICROBLAZE_OLD:
1498 rtype = elf_microblaze_reloc_type (type);
1502 rtype = elf_rl78_reloc_type (type);
1506 rtype = elf_rx_reloc_type (type);
1510 rtype = elf_metag_reloc_type (type);
1515 rtype = elf_xc16x_reloc_type (type);
1519 rtype = elf_tic6x_reloc_type (type);
1523 rtype = elf_tilegx_reloc_type (type);
1527 rtype = elf_tilepro_reloc_type (type);
1530 case EM_WEBASSEMBLY:
1531 rtype = elf_wasm32_reloc_type (type);
1535 rtype = elf_xgate_reloc_type (type);
1538 case EM_ALTERA_NIOS2:
1539 rtype = elf_nios2_reloc_type (type);
1543 rtype = elf_pru_reloc_type (type);
1548 printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
1550 printf (do_wide ? "%-22s" : "%-17.17s", rtype);
1552 if (filedata->file_header.e_machine == EM_ALPHA
1554 && streq (rtype, "R_ALPHA_LITUSE")
1557 switch (rels[i].r_addend)
1559 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1560 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1561 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1562 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1563 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1564 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1565 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1566 default: rtype = NULL;
1570 printf (" (%s)", rtype);
1574 printf (_("<unknown addend: %lx>"),
1575 (unsigned long) rels[i].r_addend);
1579 else if (symtab_index)
1581 if (symtab == NULL || symtab_index >= nsyms)
1583 error (_(" bad symbol index: %08lx in reloc"), (unsigned long) symtab_index);
1588 Elf_Internal_Sym * psym;
1589 const char * version_string;
1590 enum versioned_symbol_info sym_info;
1591 unsigned short vna_other;
1593 psym = symtab + symtab_index;
1596 = get_symbol_version_string (filedata, is_dynsym,
1605 if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
1609 unsigned int width = is_32bit_elf ? 8 : 14;
1611 /* Relocations against GNU_IFUNC symbols do not use the value
1612 of the symbol as the address to relocate against. Instead
1613 they invoke the function named by the symbol and use its
1614 result as the address for relocation.
1616 To indicate this to the user, do not display the value of
1617 the symbol in the "Symbols's Value" field. Instead show
1618 its name followed by () as a hint that the symbol is
1622 || psym->st_name == 0
1623 || psym->st_name >= strtablen)
1626 name = strtab + psym->st_name;
1628 len = print_symbol (width, name);
1630 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1632 printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
1636 print_vma (psym->st_value, LONG_HEX);
1638 printf (is_32bit_elf ? " " : " ");
1641 if (psym->st_name == 0)
1643 const char * sec_name = "<null>";
1646 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1648 if (psym->st_shndx < filedata->file_header.e_shnum)
1649 sec_name = SECTION_NAME (filedata->section_headers + psym->st_shndx);
1650 else if (psym->st_shndx == SHN_ABS)
1652 else if (psym->st_shndx == SHN_COMMON)
1653 sec_name = "COMMON";
1654 else if ((filedata->file_header.e_machine == EM_MIPS
1655 && psym->st_shndx == SHN_MIPS_SCOMMON)
1656 || (filedata->file_header.e_machine == EM_TI_C6000
1657 && psym->st_shndx == SHN_TIC6X_SCOMMON))
1658 sec_name = "SCOMMON";
1659 else if (filedata->file_header.e_machine == EM_MIPS
1660 && psym->st_shndx == SHN_MIPS_SUNDEFINED)
1661 sec_name = "SUNDEF";
1662 else if ((filedata->file_header.e_machine == EM_X86_64
1663 || filedata->file_header.e_machine == EM_L1OM
1664 || filedata->file_header.e_machine == EM_K1OM)
1665 && psym->st_shndx == SHN_X86_64_LCOMMON)
1666 sec_name = "LARGE_COMMON";
1667 else if (filedata->file_header.e_machine == EM_IA_64
1668 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1669 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1670 sec_name = "ANSI_COM";
1671 else if (is_ia64_vms (filedata)
1672 && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
1673 sec_name = "VMS_SYMVEC";
1676 sprintf (name_buf, "<section 0x%x>",
1677 (unsigned int) psym->st_shndx);
1678 sec_name = name_buf;
1681 print_symbol (22, sec_name);
1683 else if (strtab == NULL)
1684 printf (_("<string table index: %3ld>"), psym->st_name);
1685 else if (psym->st_name >= strtablen)
1687 error (_("<corrupt string table index: %3ld>"), psym->st_name);
1692 print_symbol (22, strtab + psym->st_name);
1694 printf (sym_info == symbol_public ? "@@%s" : "@%s",
1700 bfd_vma off = rels[i].r_addend;
1702 if ((bfd_signed_vma) off < 0)
1703 printf (" - %" BFD_VMA_FMT "x", - off);
1705 printf (" + %" BFD_VMA_FMT "x", off);
1711 bfd_vma off = rels[i].r_addend;
1713 printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
1714 if ((bfd_signed_vma) off < 0)
1715 printf ("-%" BFD_VMA_FMT "x", - off);
1717 printf ("%" BFD_VMA_FMT "x", off);
1720 if (filedata->file_header.e_machine == EM_SPARCV9
1722 && streq (rtype, "R_SPARC_OLO10"))
1723 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
1728 if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS)
1730 bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
1731 bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
1732 const char * rtype2 = elf_mips_reloc_type (type2);
1733 const char * rtype3 = elf_mips_reloc_type (type3);
1735 printf (" Type2: ");
1738 printf (_("unrecognized: %-7lx"),
1739 (unsigned long) type2 & 0xffffffff);
1741 printf ("%-17.17s", rtype2);
1743 printf ("\n Type3: ");
1746 printf (_("unrecognized: %-7lx"),
1747 (unsigned long) type3 & 0xffffffff);
1749 printf ("%-17.17s", rtype3);
1762 get_mips_dynamic_type (unsigned long type)
1766 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1767 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1768 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1769 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1770 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1771 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1772 case DT_MIPS_MSYM: return "MIPS_MSYM";
1773 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1774 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1775 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1776 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1777 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1778 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1779 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1780 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1781 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1782 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1783 case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
1784 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1785 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1786 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1787 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1788 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1789 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1790 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1791 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1792 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1793 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1794 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1795 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1796 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1797 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1798 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1799 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1800 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1801 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1802 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1803 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1804 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1805 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1806 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1807 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1808 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1809 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1810 case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
1811 case DT_MIPS_RWPLT: return "MIPS_RWPLT";
1818 get_sparc64_dynamic_type (unsigned long type)
1822 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1829 get_ppc_dynamic_type (unsigned long type)
1833 case DT_PPC_GOT: return "PPC_GOT";
1834 case DT_PPC_OPT: return "PPC_OPT";
1841 get_ppc64_dynamic_type (unsigned long type)
1845 case DT_PPC64_GLINK: return "PPC64_GLINK";
1846 case DT_PPC64_OPD: return "PPC64_OPD";
1847 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1848 case DT_PPC64_OPT: return "PPC64_OPT";
1855 get_parisc_dynamic_type (unsigned long type)
1859 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1860 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1861 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1862 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1863 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1864 case DT_HP_PREINIT: return "HP_PREINIT";
1865 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1866 case DT_HP_NEEDED: return "HP_NEEDED";
1867 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1868 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1869 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1870 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1871 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1872 case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
1873 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
1874 case DT_HP_FILTERED: return "HP_FILTERED";
1875 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
1876 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1877 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
1878 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
1879 case DT_PLT: return "PLT";
1880 case DT_PLT_SIZE: return "PLT_SIZE";
1881 case DT_DLT: return "DLT";
1882 case DT_DLT_SIZE: return "DLT_SIZE";
1889 get_ia64_dynamic_type (unsigned long type)
1893 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1894 case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
1895 case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
1896 case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
1897 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
1898 case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
1899 case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
1900 case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
1901 case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
1902 case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
1903 case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
1904 case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
1905 case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
1906 case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
1907 case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
1908 case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
1909 case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
1910 case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
1911 case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
1912 case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
1913 case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
1914 case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
1915 case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
1916 case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
1917 case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
1918 case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
1919 case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
1920 case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
1921 case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
1922 case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
1923 case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
1930 get_solaris_section_type (unsigned long type)
1934 case 0x6fffffee: return "SUNW_ancillary";
1935 case 0x6fffffef: return "SUNW_capchain";
1936 case 0x6ffffff0: return "SUNW_capinfo";
1937 case 0x6ffffff1: return "SUNW_symsort";
1938 case 0x6ffffff2: return "SUNW_tlssort";
1939 case 0x6ffffff3: return "SUNW_LDYNSYM";
1940 case 0x6ffffff4: return "SUNW_dof";
1941 case 0x6ffffff5: return "SUNW_cap";
1942 case 0x6ffffff6: return "SUNW_SIGNATURE";
1943 case 0x6ffffff7: return "SUNW_ANNOTATE";
1944 case 0x6ffffff8: return "SUNW_DEBUGSTR";
1945 case 0x6ffffff9: return "SUNW_DEBUG";
1946 case 0x6ffffffa: return "SUNW_move";
1947 case 0x6ffffffb: return "SUNW_COMDAT";
1948 case 0x6ffffffc: return "SUNW_syminfo";
1949 case 0x6ffffffd: return "SUNW_verdef";
1950 case 0x6ffffffe: return "SUNW_verneed";
1951 case 0x6fffffff: return "SUNW_versym";
1952 case 0x70000000: return "SPARC_GOTDATA";
1953 default: return NULL;
1958 get_alpha_dynamic_type (unsigned long type)
1962 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
1963 default: return NULL;
1968 get_score_dynamic_type (unsigned long type)
1972 case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
1973 case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
1974 case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
1975 case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
1976 case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
1977 case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
1978 default: return NULL;
1983 get_tic6x_dynamic_type (unsigned long type)
1987 case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
1988 case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
1989 case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE";
1990 case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE";
1991 case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
1992 case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX";
1993 default: return NULL;
1998 get_nios2_dynamic_type (unsigned long type)
2002 case DT_NIOS2_GP: return "NIOS2_GP";
2003 default: return NULL;
2008 get_solaris_dynamic_type (unsigned long type)
2012 case 0x6000000d: return "SUNW_AUXILIARY";
2013 case 0x6000000e: return "SUNW_RTLDINF";
2014 case 0x6000000f: return "SUNW_FILTER";
2015 case 0x60000010: return "SUNW_CAP";
2016 case 0x60000011: return "SUNW_SYMTAB";
2017 case 0x60000012: return "SUNW_SYMSZ";
2018 case 0x60000013: return "SUNW_SORTENT";
2019 case 0x60000014: return "SUNW_SYMSORT";
2020 case 0x60000015: return "SUNW_SYMSORTSZ";
2021 case 0x60000016: return "SUNW_TLSSORT";
2022 case 0x60000017: return "SUNW_TLSSORTSZ";
2023 case 0x60000018: return "SUNW_CAPINFO";
2024 case 0x60000019: return "SUNW_STRPAD";
2025 case 0x6000001a: return "SUNW_CAPCHAIN";
2026 case 0x6000001b: return "SUNW_LDMACH";
2027 case 0x6000001d: return "SUNW_CAPCHAINENT";
2028 case 0x6000001f: return "SUNW_CAPCHAINSZ";
2029 case 0x60000021: return "SUNW_PARENT";
2030 case 0x60000023: return "SUNW_ASLR";
2031 case 0x60000025: return "SUNW_RELAX";
2032 case 0x60000029: return "SUNW_NXHEAP";
2033 case 0x6000002b: return "SUNW_NXSTACK";
2035 case 0x70000001: return "SPARC_REGISTER";
2036 case 0x7ffffffd: return "AUXILIARY";
2037 case 0x7ffffffe: return "USED";
2038 case 0x7fffffff: return "FILTER";
2040 default: return NULL;
2045 get_dynamic_type (Filedata * filedata, unsigned long type)
2047 static char buff[64];
2051 case DT_NULL: return "NULL";
2052 case DT_NEEDED: return "NEEDED";
2053 case DT_PLTRELSZ: return "PLTRELSZ";
2054 case DT_PLTGOT: return "PLTGOT";
2055 case DT_HASH: return "HASH";
2056 case DT_STRTAB: return "STRTAB";
2057 case DT_SYMTAB: return "SYMTAB";
2058 case DT_RELA: return "RELA";
2059 case DT_RELASZ: return "RELASZ";
2060 case DT_RELAENT: return "RELAENT";
2061 case DT_STRSZ: return "STRSZ";
2062 case DT_SYMENT: return "SYMENT";
2063 case DT_INIT: return "INIT";
2064 case DT_FINI: return "FINI";
2065 case DT_SONAME: return "SONAME";
2066 case DT_RPATH: return "RPATH";
2067 case DT_SYMBOLIC: return "SYMBOLIC";
2068 case DT_REL: return "REL";
2069 case DT_RELSZ: return "RELSZ";
2070 case DT_RELENT: return "RELENT";
2071 case DT_PLTREL: return "PLTREL";
2072 case DT_DEBUG: return "DEBUG";
2073 case DT_TEXTREL: return "TEXTREL";
2074 case DT_JMPREL: return "JMPREL";
2075 case DT_BIND_NOW: return "BIND_NOW";
2076 case DT_INIT_ARRAY: return "INIT_ARRAY";
2077 case DT_FINI_ARRAY: return "FINI_ARRAY";
2078 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
2079 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
2080 case DT_RUNPATH: return "RUNPATH";
2081 case DT_FLAGS: return "FLAGS";
2083 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2084 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
2085 case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX";
2087 case DT_CHECKSUM: return "CHECKSUM";
2088 case DT_PLTPADSZ: return "PLTPADSZ";
2089 case DT_MOVEENT: return "MOVEENT";
2090 case DT_MOVESZ: return "MOVESZ";
2091 case DT_FEATURE: return "FEATURE";
2092 case DT_POSFLAG_1: return "POSFLAG_1";
2093 case DT_SYMINSZ: return "SYMINSZ";
2094 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
2096 case DT_ADDRRNGLO: return "ADDRRNGLO";
2097 case DT_CONFIG: return "CONFIG";
2098 case DT_DEPAUDIT: return "DEPAUDIT";
2099 case DT_AUDIT: return "AUDIT";
2100 case DT_PLTPAD: return "PLTPAD";
2101 case DT_MOVETAB: return "MOVETAB";
2102 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
2104 case DT_VERSYM: return "VERSYM";
2106 case DT_TLSDESC_GOT: return "TLSDESC_GOT";
2107 case DT_TLSDESC_PLT: return "TLSDESC_PLT";
2108 case DT_RELACOUNT: return "RELACOUNT";
2109 case DT_RELCOUNT: return "RELCOUNT";
2110 case DT_FLAGS_1: return "FLAGS_1";
2111 case DT_VERDEF: return "VERDEF";
2112 case DT_VERDEFNUM: return "VERDEFNUM";
2113 case DT_VERNEED: return "VERNEED";
2114 case DT_VERNEEDNUM: return "VERNEEDNUM";
2116 case DT_AUXILIARY: return "AUXILIARY";
2117 case DT_USED: return "USED";
2118 case DT_FILTER: return "FILTER";
2120 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
2121 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
2122 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
2123 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
2124 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
2125 case DT_GNU_HASH: return "GNU_HASH";
2128 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
2130 const char * result;
2132 switch (filedata->file_header.e_machine)
2135 case EM_MIPS_RS3_LE:
2136 result = get_mips_dynamic_type (type);
2139 result = get_sparc64_dynamic_type (type);
2142 result = get_ppc_dynamic_type (type);
2145 result = get_ppc64_dynamic_type (type);
2148 result = get_ia64_dynamic_type (type);
2151 result = get_alpha_dynamic_type (type);
2154 result = get_score_dynamic_type (type);
2157 result = get_tic6x_dynamic_type (type);
2159 case EM_ALTERA_NIOS2:
2160 result = get_nios2_dynamic_type (type);
2163 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
2164 result = get_solaris_dynamic_type (type);
2173 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
2175 else if (((type >= DT_LOOS) && (type <= DT_HIOS))
2176 || (filedata->file_header.e_machine == EM_PARISC
2177 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
2179 const char * result;
2181 switch (filedata->file_header.e_machine)
2184 result = get_parisc_dynamic_type (type);
2187 result = get_ia64_dynamic_type (type);
2190 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
2191 result = get_solaris_dynamic_type (type);
2200 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
2204 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
2211 get_file_type (unsigned e_type)
2213 static char buff[32];
2217 case ET_NONE: return _("NONE (None)");
2218 case ET_REL: return _("REL (Relocatable file)");
2219 case ET_EXEC: return _("EXEC (Executable file)");
2220 case ET_DYN: return _("DYN (Shared object file)");
2221 case ET_CORE: return _("CORE (Core file)");
2224 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
2225 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
2226 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
2227 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
2229 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
2235 get_machine_name (unsigned e_machine)
2237 static char buff[64]; /* XXX */
2241 /* Please keep this switch table sorted by increasing EM_ value. */
2243 case EM_NONE: return _("None");
2244 case EM_M32: return "WE32100";
2245 case EM_SPARC: return "Sparc";
2246 case EM_386: return "Intel 80386";
2247 case EM_68K: return "MC68000";
2248 case EM_88K: return "MC88000";
2249 case EM_IAMCU: return "Intel MCU";
2250 case EM_860: return "Intel 80860";
2251 case EM_MIPS: return "MIPS R3000";
2252 case EM_S370: return "IBM System/370";
2254 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
2255 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
2256 case EM_PARISC: return "HPPA";
2257 case EM_VPP550: return "Fujitsu VPP500";
2258 case EM_SPARC32PLUS: return "Sparc v8+" ;
2259 case EM_960: return "Intel 80960";
2260 case EM_PPC: return "PowerPC";
2262 case EM_PPC64: return "PowerPC64";
2264 case EM_S390: return "IBM S/390";
2265 case EM_SPU: return "SPU";
2267 case EM_V800: return "Renesas V850 (using RH850 ABI)";
2268 case EM_FR20: return "Fujitsu FR20";
2269 case EM_RH32: return "TRW RH32";
2270 case EM_MCORE: return "MCORE";
2272 case EM_ARM: return "ARM";
2273 case EM_OLD_ALPHA: return "Digital Alpha (old)";
2274 case EM_SH: return "Renesas / SuperH SH";
2275 case EM_SPARCV9: return "Sparc v9";
2276 case EM_TRICORE: return "Siemens Tricore";
2277 case EM_ARC: return "ARC";
2278 case EM_H8_300: return "Renesas H8/300";
2279 case EM_H8_300H: return "Renesas H8/300H";
2280 case EM_H8S: return "Renesas H8S";
2281 case EM_H8_500: return "Renesas H8/500";
2283 case EM_IA_64: return "Intel IA-64";
2284 case EM_MIPS_X: return "Stanford MIPS-X";
2285 case EM_COLDFIRE: return "Motorola Coldfire";
2286 case EM_68HC12: return "Motorola MC68HC12 Microcontroller";
2287 case EM_MMA: return "Fujitsu Multimedia Accelerator";
2288 case EM_PCP: return "Siemens PCP";
2289 case EM_NCPU: return "Sony nCPU embedded RISC processor";
2290 case EM_NDR1: return "Denso NDR1 microprocesspr";
2291 case EM_STARCORE: return "Motorola Star*Core processor";
2292 case EM_ME16: return "Toyota ME16 processor";
2294 case EM_ST100: return "STMicroelectronics ST100 processor";
2295 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
2296 case EM_X86_64: return "Advanced Micro Devices X86-64";
2297 case EM_PDSP: return "Sony DSP processor";
2298 case EM_PDP10: return "Digital Equipment Corp. PDP-10";
2299 case EM_PDP11: return "Digital Equipment Corp. PDP-11";
2300 case EM_FX66: return "Siemens FX66 microcontroller";
2301 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
2302 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
2303 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
2305 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
2306 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
2307 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
2308 case EM_SVX: return "Silicon Graphics SVx";
2309 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
2310 case EM_VAX: return "Digital VAX";
2311 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
2312 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
2313 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
2314 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
2316 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
2317 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
2318 case EM_PRISM: return "Vitesse Prism";
2320 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
2321 case EM_CYGNUS_FR30:
2322 case EM_FR30: return "Fujitsu FR30";
2323 case EM_CYGNUS_D10V:
2324 case EM_D10V: return "d10v";
2325 case EM_CYGNUS_D30V:
2326 case EM_D30V: return "d30v";
2327 case EM_CYGNUS_V850:
2328 case EM_V850: return "Renesas V850";
2329 case EM_CYGNUS_M32R:
2330 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
2331 case EM_CYGNUS_MN10300:
2332 case EM_MN10300: return "mn10300";
2334 case EM_CYGNUS_MN10200:
2335 case EM_MN10200: return "mn10200";
2336 case EM_PJ: return "picoJava";
2337 case EM_OR1K: return "OpenRISC 1000";
2338 case EM_ARC_COMPACT: return "ARCompact";
2340 case EM_XTENSA: return "Tensilica Xtensa Processor";
2341 case EM_VIDEOCORE: return "Alphamosaic VideoCore processor";
2342 case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor";
2343 case EM_NS32K: return "National Semiconductor 32000 series";
2344 case EM_TPC: return "Tenor Network TPC processor";
2345 case EM_SNP1K: return "Trebia SNP 1000 processor";
2347 case EM_ST200: return "STMicroelectronics ST200 microcontroller";
2349 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
2350 case EM_MAX: return "MAX Processor";
2351 case EM_CR: return "National Semiconductor CompactRISC";
2352 case EM_F2MC16: return "Fujitsu F2MC16";
2353 case EM_MSP430: return "Texas Instruments msp430 microcontroller";
2354 case EM_BLACKFIN: return "Analog Devices Blackfin";
2355 case EM_SE_C33: return "S1C33 Family of Seiko Epson processors";
2356 case EM_SEP: return "Sharp embedded microprocessor";
2357 case EM_ARCA: return "Arca RISC microprocessor";
2359 case EM_UNICORE: return "Unicore";
2360 case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU";
2361 case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor";
2362 case EM_ALTERA_NIOS2: return "Altera Nios II";
2363 case EM_CRX: return "National Semiconductor CRX microprocessor";
2364 case EM_XGATE: return "Motorola XGATE embedded processor";
2366 case EM_XC16X: return "Infineon Technologies xc16x";
2367 case EM_M16C: return "Renesas M16C series microprocessors";
2368 case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller";
2369 case EM_CE: return "Freescale Communication Engine RISC core";
2371 case EM_M32C: return "Renesas M32c";
2373 case EM_TSK3000: return "Altium TSK3000 core";
2374 case EM_RS08: return "Freescale RS08 embedded processor";
2375 case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor";
2376 case EM_SCORE: return "SUNPLUS S+Core";
2377 case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor";
2378 case EM_VIDEOCORE3: return "Broadcom VideoCore III processor";
2379 case EM_LATTICEMICO32: return "Lattice Mico32";
2380 case EM_SE_C17: return "Seiko Epson C17 family";
2382 case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family";
2383 case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family";
2384 case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family";
2385 case EM_TI_PRU: return "TI PRU I/O processor";
2387 case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor";
2388 case EM_CYPRESS_M8C: return "Cypress M8C microprocessor";
2389 case EM_R32C: return "Renesas R32C series microprocessors";
2390 case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family";
2391 case EM_QDSP6: return "QUALCOMM DSP6 Processor";
2392 case EM_8051: return "Intel 8051 and variants";
2393 case EM_STXP7X: return "STMicroelectronics STxP7x family";
2394 case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family";
2395 case EM_ECOG1X: return "Cyan Technology eCOG1X family";
2396 case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
2398 case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor";
2399 case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor";
2400 case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture";
2401 case EM_RX: return "Renesas RX";
2402 case EM_METAG: return "Imagination Technologies Meta processor architecture";
2403 case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
2404 case EM_ECOG16: return "Cyan Technology eCOG16 family";
2407 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
2408 case EM_ETPU: return "Freescale Extended Time Processing Unit";
2409 case EM_SLE9X: return "Infineon Technologies SLE9X core";
2411 case EM_L1OM: return "Intel L1OM";
2412 case EM_K1OM: return "Intel K1OM";
2413 case EM_INTEL182: return "Intel (reserved)";
2414 case EM_AARCH64: return "AArch64";
2415 case EM_ARM184: return "ARM (reserved)";
2416 case EM_AVR32: return "Atmel Corporation 32-bit microprocessor";
2417 case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller";
2418 case EM_TILE64: return "Tilera TILE64 multicore architecture family";
2419 case EM_TILEPRO: return "Tilera TILEPro multicore architecture family";
2421 case EM_CUDA: return "NVIDIA CUDA architecture";
2422 case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family";
2423 case EM_CLOUDSHIELD: return "CloudShield architecture family";
2424 case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family";
2425 case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family";
2426 case EM_ARC_COMPACT2: return "ARCv2";
2427 case EM_OPEN8: return "Open8 8-bit RISC soft processor core";
2428 case EM_RL78: return "Renesas RL78";
2429 case EM_VIDEOCORE5: return "Broadcom VideoCore V processor";
2430 case EM_78K0R: return "Renesas 78K0R";
2432 case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)";
2433 case EM_BA1: return "Beyond BA1 CPU architecture";
2434 case EM_BA2: return "Beyond BA2 CPU architecture";
2435 case EM_XCORE: return "XMOS xCORE processor family";
2436 case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family";
2438 case EM_KM32: return "KM211 KM32 32-bit processor";
2439 case EM_KMX32: return "KM211 KMX32 32-bit processor";
2440 case EM_KMX16: return "KM211 KMX16 16-bit processor";
2441 case EM_KMX8: return "KM211 KMX8 8-bit processor";
2442 case EM_KVARC: return "KM211 KVARC processor";
2443 case EM_CDP: return "Paneve CDP architecture family";
2444 case EM_COGE: return "Cognitive Smart Memory Processor";
2445 case EM_COOL: return "Bluechip Systems CoolEngine";
2446 case EM_NORC: return "Nanoradio Optimized RISC";
2447 case EM_CSR_KALIMBA: return "CSR Kalimba architecture family";
2449 case EM_Z80: return "Zilog Z80";
2450 case EM_VISIUM: return "CDS VISIUMcore processor";
2451 case EM_FT32: return "FTDI Chip FT32";
2452 case EM_MOXIE: return "Moxie";
2453 case EM_AMDGPU: return "AMD GPU";
2454 case EM_RISCV: return "RISC-V";
2455 case EM_LANAI: return "Lanai 32-bit processor";
2456 case EM_BPF: return "Linux BPF";
2458 /* Large numbers... */
2459 case EM_MT: return "Morpho Techologies MT processor";
2460 case EM_ALPHA: return "Alpha";
2461 case EM_WEBASSEMBLY: return "Web Assembly";
2462 case EM_DLX: return "OpenDLX";
2463 case EM_XSTORMY16: return "Sanyo XStormy16 CPU core";
2464 case EM_IQ2000: return "Vitesse IQ2000";
2466 case EM_NIOS32: return "Altera Nios";
2467 case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
2468 case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
2469 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
2472 snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
2478 decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[])
2480 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
2481 other compilers don't a specific architecture type in the e_flags, and
2482 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
2483 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
2486 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
2487 but also sets a specific architecture type in the e_flags field.
2489 However, when decoding the flags we don't worry if we see an
2490 unexpected pairing, for example EM_ARC_COMPACT machine type, with
2491 ARCEM architecture type. */
2493 switch (e_flags & EF_ARC_MACH_MSK)
2495 /* We only expect these to occur for EM_ARC_COMPACT2. */
2496 case EF_ARC_CPU_ARCV2EM:
2497 strcat (buf, ", ARC EM");
2499 case EF_ARC_CPU_ARCV2HS:
2500 strcat (buf, ", ARC HS");
2503 /* We only expect these to occur for EM_ARC_COMPACT. */
2504 case E_ARC_MACH_ARC600:
2505 strcat (buf, ", ARC600");
2507 case E_ARC_MACH_ARC601:
2508 strcat (buf, ", ARC601");
2510 case E_ARC_MACH_ARC700:
2511 strcat (buf, ", ARC700");
2514 /* The only times we should end up here are (a) A corrupt ELF, (b) A
2515 new ELF with new architecture being read by an old version of
2516 readelf, or (c) An ELF built with non-GNU compiler that does not
2517 set the architecture in the e_flags. */
2519 if (e_machine == EM_ARC_COMPACT)
2520 strcat (buf, ", Unknown ARCompact");
2522 strcat (buf, ", Unknown ARC");
2526 switch (e_flags & EF_ARC_OSABI_MSK)
2528 case E_ARC_OSABI_ORIG:
2529 strcat (buf, ", (ABI:legacy)");
2531 case E_ARC_OSABI_V2:
2532 strcat (buf, ", (ABI:v2)");
2534 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
2535 case E_ARC_OSABI_V3:
2536 strcat (buf, ", v3 no-legacy-syscalls ABI");
2538 case E_ARC_OSABI_V4:
2539 strcat (buf, ", v4 ABI");
2542 strcat (buf, ", unrecognised ARC OSABI flag");
2548 decode_ARM_machine_flags (unsigned e_flags, char buf[])
2551 bfd_boolean unknown = FALSE;
2553 eabi = EF_ARM_EABI_VERSION (e_flags);
2554 e_flags &= ~ EF_ARM_EABIMASK;
2556 /* Handle "generic" ARM flags. */
2557 if (e_flags & EF_ARM_RELEXEC)
2559 strcat (buf, ", relocatable executable");
2560 e_flags &= ~ EF_ARM_RELEXEC;
2563 /* Now handle EABI specific flags. */
2567 strcat (buf, ", <unrecognized EABI>");
2572 case EF_ARM_EABI_VER1:
2573 strcat (buf, ", Version1 EABI");
2578 /* Process flags one bit at a time. */
2579 flag = e_flags & - e_flags;
2584 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2585 strcat (buf, ", sorted symbol tables");
2595 case EF_ARM_EABI_VER2:
2596 strcat (buf, ", Version2 EABI");
2601 /* Process flags one bit at a time. */
2602 flag = e_flags & - e_flags;
2607 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
2608 strcat (buf, ", sorted symbol tables");
2611 case EF_ARM_DYNSYMSUSESEGIDX:
2612 strcat (buf, ", dynamic symbols use segment index");
2615 case EF_ARM_MAPSYMSFIRST:
2616 strcat (buf, ", mapping symbols precede others");
2626 case EF_ARM_EABI_VER3:
2627 strcat (buf, ", Version3 EABI");
2630 case EF_ARM_EABI_VER4:
2631 strcat (buf, ", Version4 EABI");
2636 /* Process flags one bit at a time. */
2637 flag = e_flags & - e_flags;
2643 strcat (buf, ", BE8");
2647 strcat (buf, ", LE8");
2657 case EF_ARM_EABI_VER5:
2658 strcat (buf, ", Version5 EABI");
2663 /* Process flags one bit at a time. */
2664 flag = e_flags & - e_flags;
2670 strcat (buf, ", BE8");
2674 strcat (buf, ", LE8");
2677 case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */
2678 strcat (buf, ", soft-float ABI");
2681 case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */
2682 strcat (buf, ", hard-float ABI");
2692 case EF_ARM_EABI_UNKNOWN:
2693 strcat (buf, ", GNU EABI");
2698 /* Process flags one bit at a time. */
2699 flag = e_flags & - e_flags;
2704 case EF_ARM_INTERWORK:
2705 strcat (buf, ", interworking enabled");
2708 case EF_ARM_APCS_26:
2709 strcat (buf, ", uses APCS/26");
2712 case EF_ARM_APCS_FLOAT:
2713 strcat (buf, ", uses APCS/float");
2717 strcat (buf, ", position independent");
2721 strcat (buf, ", 8 bit structure alignment");
2724 case EF_ARM_NEW_ABI:
2725 strcat (buf, ", uses new ABI");
2728 case EF_ARM_OLD_ABI:
2729 strcat (buf, ", uses old ABI");
2732 case EF_ARM_SOFT_FLOAT:
2733 strcat (buf, ", software FP");
2736 case EF_ARM_VFP_FLOAT:
2737 strcat (buf, ", VFP");
2740 case EF_ARM_MAVERICK_FLOAT:
2741 strcat (buf, ", Maverick FP");
2752 strcat (buf,_(", <unknown>"));
2756 decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size)
2758 --size; /* Leave space for null terminator. */
2760 switch (e_flags & EF_AVR_MACH)
2762 case E_AVR_MACH_AVR1:
2763 strncat (buf, ", avr:1", size);
2765 case E_AVR_MACH_AVR2:
2766 strncat (buf, ", avr:2", size);
2768 case E_AVR_MACH_AVR25:
2769 strncat (buf, ", avr:25", size);
2771 case E_AVR_MACH_AVR3:
2772 strncat (buf, ", avr:3", size);
2774 case E_AVR_MACH_AVR31:
2775 strncat (buf, ", avr:31", size);
2777 case E_AVR_MACH_AVR35:
2778 strncat (buf, ", avr:35", size);
2780 case E_AVR_MACH_AVR4:
2781 strncat (buf, ", avr:4", size);
2783 case E_AVR_MACH_AVR5:
2784 strncat (buf, ", avr:5", size);
2786 case E_AVR_MACH_AVR51:
2787 strncat (buf, ", avr:51", size);
2789 case E_AVR_MACH_AVR6:
2790 strncat (buf, ", avr:6", size);
2792 case E_AVR_MACH_AVRTINY:
2793 strncat (buf, ", avr:100", size);
2795 case E_AVR_MACH_XMEGA1:
2796 strncat (buf, ", avr:101", size);
2798 case E_AVR_MACH_XMEGA2:
2799 strncat (buf, ", avr:102", size);
2801 case E_AVR_MACH_XMEGA3:
2802 strncat (buf, ", avr:103", size);
2804 case E_AVR_MACH_XMEGA4:
2805 strncat (buf, ", avr:104", size);
2807 case E_AVR_MACH_XMEGA5:
2808 strncat (buf, ", avr:105", size);
2810 case E_AVR_MACH_XMEGA6:
2811 strncat (buf, ", avr:106", size);
2813 case E_AVR_MACH_XMEGA7:
2814 strncat (buf, ", avr:107", size);
2817 strncat (buf, ", avr:<unknown>", size);
2821 size -= strlen (buf);
2822 if (e_flags & EF_AVR_LINKRELAX_PREPARED)
2823 strncat (buf, ", link-relax", size);
2827 decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
2833 bfd_boolean has_fpu = FALSE;
2836 static const char *ABI_STRINGS[] =
2838 "ABI v0", /* use r5 as return register; only used in N1213HC */
2839 "ABI v1", /* use r0 as return register */
2840 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
2841 "ABI v2fp", /* for FPU */
2845 static const char *VER_STRINGS[] =
2847 "Andes ELF V1.3 or older",
2851 static const char *ARCH_STRINGS[] =
2860 abi = EF_NDS_ABI & e_flags;
2861 arch = EF_NDS_ARCH & e_flags;
2862 config = EF_NDS_INST & e_flags;
2863 version = EF_NDS32_ELF_VERSION & e_flags;
2865 memset (buf, 0, size);
2872 case E_NDS_ABI_V2FP:
2873 case E_NDS_ABI_AABI:
2874 case E_NDS_ABI_V2FP_PLUS:
2875 /* In case there are holes in the array. */
2876 r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
2880 r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
2886 case E_NDS32_ELF_VER_1_2:
2887 case E_NDS32_ELF_VER_1_3:
2888 case E_NDS32_ELF_VER_1_4:
2889 r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
2893 r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
2897 if (E_NDS_ABI_V0 == abi)
2899 /* OLD ABI; only used in N1213HC, has performance extension 1. */
2900 r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
2901 if (arch == E_NDS_ARCH_STAR_V1_0)
2902 r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
2908 case E_NDS_ARCH_STAR_V1_0:
2909 case E_NDS_ARCH_STAR_V2_0:
2910 case E_NDS_ARCH_STAR_V3_0:
2911 case E_NDS_ARCH_STAR_V3_M:
2912 r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
2916 r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
2917 /* ARCH version determines how the e_flags are interpreted.
2918 If it is unknown, we cannot proceed. */
2922 /* Newer ABI; Now handle architecture specific flags. */
2923 if (arch == E_NDS_ARCH_STAR_V1_0)
2925 if (config & E_NDS32_HAS_MFUSR_PC_INST)
2926 r += snprintf (buf + r, size -r, ", MFUSR_PC");
2928 if (!(config & E_NDS32_HAS_NO_MAC_INST))
2929 r += snprintf (buf + r, size -r, ", MAC");
2931 if (config & E_NDS32_HAS_DIV_INST)
2932 r += snprintf (buf + r, size -r, ", DIV");
2934 if (config & E_NDS32_HAS_16BIT_INST)
2935 r += snprintf (buf + r, size -r, ", 16b");
2939 if (config & E_NDS32_HAS_MFUSR_PC_INST)
2941 if (version <= E_NDS32_ELF_VER_1_3)
2942 r += snprintf (buf + r, size -r, ", [B8]");
2944 r += snprintf (buf + r, size -r, ", EX9");
2947 if (config & E_NDS32_HAS_MAC_DX_INST)
2948 r += snprintf (buf + r, size -r, ", MAC_DX");
2950 if (config & E_NDS32_HAS_DIV_DX_INST)
2951 r += snprintf (buf + r, size -r, ", DIV_DX");
2953 if (config & E_NDS32_HAS_16BIT_INST)
2955 if (version <= E_NDS32_ELF_VER_1_3)
2956 r += snprintf (buf + r, size -r, ", 16b");
2958 r += snprintf (buf + r, size -r, ", IFC");
2962 if (config & E_NDS32_HAS_EXT_INST)
2963 r += snprintf (buf + r, size -r, ", PERF1");
2965 if (config & E_NDS32_HAS_EXT2_INST)
2966 r += snprintf (buf + r, size -r, ", PERF2");
2968 if (config & E_NDS32_HAS_FPU_INST)
2971 r += snprintf (buf + r, size -r, ", FPU_SP");
2974 if (config & E_NDS32_HAS_FPU_DP_INST)
2977 r += snprintf (buf + r, size -r, ", FPU_DP");
2980 if (config & E_NDS32_HAS_FPU_MAC_INST)
2983 r += snprintf (buf + r, size -r, ", FPU_MAC");
2988 switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
2990 case E_NDS32_FPU_REG_8SP_4DP:
2991 r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
2993 case E_NDS32_FPU_REG_16SP_8DP:
2994 r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
2996 case E_NDS32_FPU_REG_32SP_16DP:
2997 r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
2999 case E_NDS32_FPU_REG_32SP_32DP:
3000 r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
3005 if (config & E_NDS32_HAS_AUDIO_INST)
3006 r += snprintf (buf + r, size -r, ", AUDIO");
3008 if (config & E_NDS32_HAS_STRING_INST)
3009 r += snprintf (buf + r, size -r, ", STR");
3011 if (config & E_NDS32_HAS_REDUCED_REGS)
3012 r += snprintf (buf + r, size -r, ", 16REG");
3014 if (config & E_NDS32_HAS_VIDEO_INST)
3016 if (version <= E_NDS32_ELF_VER_1_3)
3017 r += snprintf (buf + r, size -r, ", VIDEO");
3019 r += snprintf (buf + r, size -r, ", SATURATION");
3022 if (config & E_NDS32_HAS_ENCRIPT_INST)
3023 r += snprintf (buf + r, size -r, ", ENCRP");
3025 if (config & E_NDS32_HAS_L2C_INST)
3026 r += snprintf (buf + r, size -r, ", L2C");
3030 get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine)
3032 static char buf[1024];
3043 case EM_ARC_COMPACT2:
3044 case EM_ARC_COMPACT:
3045 decode_ARC_machine_flags (e_flags, e_machine, buf);
3049 decode_ARM_machine_flags (e_flags, buf);
3053 decode_AVR_machine_flags (e_flags, buf, sizeof buf);
3057 if (e_flags & EF_BFIN_PIC)
3058 strcat (buf, ", PIC");
3060 if (e_flags & EF_BFIN_FDPIC)
3061 strcat (buf, ", FDPIC");
3063 if (e_flags & EF_BFIN_CODE_IN_L1)
3064 strcat (buf, ", code in L1");
3066 if (e_flags & EF_BFIN_DATA_IN_L1)
3067 strcat (buf, ", data in L1");
3072 switch (e_flags & EF_FRV_CPU_MASK)
3074 case EF_FRV_CPU_GENERIC:
3078 strcat (buf, ", fr???");
3081 case EF_FRV_CPU_FR300:
3082 strcat (buf, ", fr300");
3085 case EF_FRV_CPU_FR400:
3086 strcat (buf, ", fr400");
3088 case EF_FRV_CPU_FR405:
3089 strcat (buf, ", fr405");
3092 case EF_FRV_CPU_FR450:
3093 strcat (buf, ", fr450");
3096 case EF_FRV_CPU_FR500:
3097 strcat (buf, ", fr500");
3099 case EF_FRV_CPU_FR550:
3100 strcat (buf, ", fr550");
3103 case EF_FRV_CPU_SIMPLE:
3104 strcat (buf, ", simple");
3106 case EF_FRV_CPU_TOMCAT:
3107 strcat (buf, ", tomcat");
3113 if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
3114 strcat (buf, ", m68000");
3115 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
3116 strcat (buf, ", cpu32");
3117 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
3118 strcat (buf, ", fido_a");
3121 char const * isa = _("unknown");
3122 char const * mac = _("unknown mac");
3123 char const * additional = NULL;
3125 switch (e_flags & EF_M68K_CF_ISA_MASK)
3127 case EF_M68K_CF_ISA_A_NODIV:
3129 additional = ", nodiv";
3131 case EF_M68K_CF_ISA_A:
3134 case EF_M68K_CF_ISA_A_PLUS:
3137 case EF_M68K_CF_ISA_B_NOUSP:
3139 additional = ", nousp";
3141 case EF_M68K_CF_ISA_B:
3144 case EF_M68K_CF_ISA_C:
3147 case EF_M68K_CF_ISA_C_NODIV:
3149 additional = ", nodiv";
3152 strcat (buf, ", cf, isa ");
3155 strcat (buf, additional);
3156 if (e_flags & EF_M68K_CF_FLOAT)
3157 strcat (buf, ", float");
3158 switch (e_flags & EF_M68K_CF_MAC_MASK)
3163 case EF_M68K_CF_MAC:
3166 case EF_M68K_CF_EMAC:
3169 case EF_M68K_CF_EMAC_B:
3182 switch (e_flags & EF_MEP_CPU_MASK)
3184 case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break;
3185 case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break;
3186 case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break;
3187 case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break;
3188 case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break;
3189 case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break;
3190 default: strcat (buf, _(", <unknown MeP cpu type>")); break;
3193 switch (e_flags & EF_MEP_COP_MASK)
3195 case EF_MEP_COP_NONE: break;
3196 case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break;
3197 case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break;
3198 case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break;
3199 case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break;
3200 default: strcat (buf, _("<unknown MeP copro type>")); break;
3203 if (e_flags & EF_MEP_LIBRARY)
3204 strcat (buf, ", Built for Library");
3206 if (e_flags & EF_MEP_INDEX_MASK)
3207 sprintf (buf + strlen (buf), ", Configuration Index: %#x",
3208 e_flags & EF_MEP_INDEX_MASK);
3210 if (e_flags & ~ EF_MEP_ALL_FLAGS)
3211 sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
3212 e_flags & ~ EF_MEP_ALL_FLAGS);
3216 if (e_flags & EF_PPC_EMB)
3217 strcat (buf, ", emb");
3219 if (e_flags & EF_PPC_RELOCATABLE)
3220 strcat (buf, _(", relocatable"));
3222 if (e_flags & EF_PPC_RELOCATABLE_LIB)
3223 strcat (buf, _(", relocatable-lib"));
3227 if (e_flags & EF_PPC64_ABI)
3229 char abi[] = ", abiv0";
3231 abi[6] += e_flags & EF_PPC64_ABI;
3237 if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
3238 strcat (buf, ", RH850 ABI");
3240 if (e_flags & EF_V800_850E3)
3241 strcat (buf, ", V3 architecture");
3243 if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
3244 strcat (buf, ", FPU not used");
3246 if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
3247 strcat (buf, ", regmode: COMMON");
3249 if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
3250 strcat (buf, ", r4 not used");
3252 if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
3253 strcat (buf, ", r30 not used");
3255 if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
3256 strcat (buf, ", r5 not used");
3258 if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
3259 strcat (buf, ", r2 not used");
3261 for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
3263 switch (e_flags & - e_flags)
3265 case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
3266 case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
3267 case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
3268 case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
3269 case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
3270 case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
3271 case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
3272 case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
3273 case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
3274 case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
3275 case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
3276 case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
3283 case EM_CYGNUS_V850:
3284 switch (e_flags & EF_V850_ARCH)
3286 case E_V850E3V5_ARCH:
3287 strcat (buf, ", v850e3v5");
3289 case E_V850E2V3_ARCH:
3290 strcat (buf, ", v850e2v3");
3293 strcat (buf, ", v850e2");
3296 strcat (buf, ", v850e1");
3299 strcat (buf, ", v850e");
3302 strcat (buf, ", v850");
3305 strcat (buf, _(", unknown v850 architecture variant"));
3311 case EM_CYGNUS_M32R:
3312 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
3313 strcat (buf, ", m32r");
3317 case EM_MIPS_RS3_LE:
3318 if (e_flags & EF_MIPS_NOREORDER)
3319 strcat (buf, ", noreorder");
3321 if (e_flags & EF_MIPS_PIC)
3322 strcat (buf, ", pic");
3324 if (e_flags & EF_MIPS_CPIC)
3325 strcat (buf, ", cpic");
3327 if (e_flags & EF_MIPS_UCODE)
3328 strcat (buf, ", ugen_reserved");
3330 if (e_flags & EF_MIPS_ABI2)
3331 strcat (buf, ", abi2");
3333 if (e_flags & EF_MIPS_OPTIONS_FIRST)
3334 strcat (buf, ", odk first");
3336 if (e_flags & EF_MIPS_32BITMODE)
3337 strcat (buf, ", 32bitmode");
3339 if (e_flags & EF_MIPS_NAN2008)
3340 strcat (buf, ", nan2008");
3342 if (e_flags & EF_MIPS_FP64)
3343 strcat (buf, ", fp64");
3345 switch ((e_flags & EF_MIPS_MACH))
3347 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
3348 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
3349 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
3350 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
3351 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
3352 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
3353 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
3354 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
3355 case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break;
3356 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
3357 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
3358 case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
3359 case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
3360 case E_MIPS_MACH_LS3A: strcat (buf, ", loongson-3a"); break;
3361 case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
3362 case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
3363 case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
3364 case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break;
3365 case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break;
3367 /* We simply ignore the field in this case to avoid confusion:
3368 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
3371 default: strcat (buf, _(", unknown CPU")); break;
3374 switch ((e_flags & EF_MIPS_ABI))
3376 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
3377 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
3378 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
3379 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
3381 /* We simply ignore the field in this case to avoid confusion:
3382 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
3383 This means it is likely to be an o32 file, but not for
3386 default: strcat (buf, _(", unknown ABI")); break;
3389 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
3390 strcat (buf, ", mdmx");
3392 if (e_flags & EF_MIPS_ARCH_ASE_M16)
3393 strcat (buf, ", mips16");
3395 if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
3396 strcat (buf, ", micromips");
3398 switch ((e_flags & EF_MIPS_ARCH))
3400 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
3401 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
3402 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
3403 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
3404 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
3405 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
3406 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
3407 case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
3408 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
3409 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
3410 case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
3411 default: strcat (buf, _(", unknown ISA")); break;
3416 decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
3420 if (e_flags & EF_RISCV_RVC)
3421 strcat (buf, ", RVC");
3423 switch (e_flags & EF_RISCV_FLOAT_ABI)
3425 case EF_RISCV_FLOAT_ABI_SOFT:
3426 strcat (buf, ", soft-float ABI");
3429 case EF_RISCV_FLOAT_ABI_SINGLE:
3430 strcat (buf, ", single-float ABI");
3433 case EF_RISCV_FLOAT_ABI_DOUBLE:
3434 strcat (buf, ", double-float ABI");
3437 case EF_RISCV_FLOAT_ABI_QUAD:
3438 strcat (buf, ", quad-float ABI");
3444 switch ((e_flags & EF_SH_MACH_MASK))
3446 case EF_SH1: strcat (buf, ", sh1"); break;
3447 case EF_SH2: strcat (buf, ", sh2"); break;
3448 case EF_SH3: strcat (buf, ", sh3"); break;
3449 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
3450 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
3451 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
3452 case EF_SH3E: strcat (buf, ", sh3e"); break;
3453 case EF_SH4: strcat (buf, ", sh4"); break;
3454 case EF_SH5: strcat (buf, ", sh5"); break;
3455 case EF_SH2E: strcat (buf, ", sh2e"); break;
3456 case EF_SH4A: strcat (buf, ", sh4a"); break;
3457 case EF_SH2A: strcat (buf, ", sh2a"); break;
3458 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
3459 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
3460 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
3461 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
3462 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
3463 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
3464 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
3465 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
3466 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
3467 default: strcat (buf, _(", unknown ISA")); break;
3470 if (e_flags & EF_SH_PIC)
3471 strcat (buf, ", pic");
3473 if (e_flags & EF_SH_FDPIC)
3474 strcat (buf, ", fdpic");
3478 if (e_flags & EF_OR1K_NODELAY)
3479 strcat (buf, ", no delay");
3483 if (e_flags & EF_SPARC_32PLUS)
3484 strcat (buf, ", v8+");
3486 if (e_flags & EF_SPARC_SUN_US1)
3487 strcat (buf, ", ultrasparcI");
3489 if (e_flags & EF_SPARC_SUN_US3)
3490 strcat (buf, ", ultrasparcIII");
3492 if (e_flags & EF_SPARC_HAL_R1)
3493 strcat (buf, ", halr1");
3495 if (e_flags & EF_SPARC_LEDATA)
3496 strcat (buf, ", ledata");
3498 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
3499 strcat (buf, ", tso");
3501 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
3502 strcat (buf, ", pso");
3504 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
3505 strcat (buf, ", rmo");
3509 switch (e_flags & EF_PARISC_ARCH)
3511 case EFA_PARISC_1_0:
3512 strcpy (buf, ", PA-RISC 1.0");
3514 case EFA_PARISC_1_1:
3515 strcpy (buf, ", PA-RISC 1.1");
3517 case EFA_PARISC_2_0:
3518 strcpy (buf, ", PA-RISC 2.0");
3523 if (e_flags & EF_PARISC_TRAPNIL)
3524 strcat (buf, ", trapnil");
3525 if (e_flags & EF_PARISC_EXT)
3526 strcat (buf, ", ext");
3527 if (e_flags & EF_PARISC_LSB)
3528 strcat (buf, ", lsb");
3529 if (e_flags & EF_PARISC_WIDE)
3530 strcat (buf, ", wide");
3531 if (e_flags & EF_PARISC_NO_KABP)
3532 strcat (buf, ", no kabp");
3533 if (e_flags & EF_PARISC_LAZYSWAP)
3534 strcat (buf, ", lazyswap");
3539 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
3540 strcat (buf, ", new calling convention");
3542 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
3543 strcat (buf, ", gnu calling convention");
3547 if ((e_flags & EF_IA_64_ABI64))
3548 strcat (buf, ", 64-bit");
3550 strcat (buf, ", 32-bit");
3551 if ((e_flags & EF_IA_64_REDUCEDFP))
3552 strcat (buf, ", reduced fp model");
3553 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
3554 strcat (buf, ", no function descriptors, constant gp");
3555 else if ((e_flags & EF_IA_64_CONS_GP))
3556 strcat (buf, ", constant gp");
3557 if ((e_flags & EF_IA_64_ABSOLUTE))
3558 strcat (buf, ", absolute");
3559 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
3561 if ((e_flags & EF_IA_64_VMS_LINKAGES))
3562 strcat (buf, ", vms_linkages");
3563 switch ((e_flags & EF_IA_64_VMS_COMCOD))
3565 case EF_IA_64_VMS_COMCOD_SUCCESS:
3567 case EF_IA_64_VMS_COMCOD_WARNING:
3568 strcat (buf, ", warning");
3570 case EF_IA_64_VMS_COMCOD_ERROR:
3571 strcat (buf, ", error");
3573 case EF_IA_64_VMS_COMCOD_ABORT:
3574 strcat (buf, ", abort");
3577 warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
3578 e_flags & EF_IA_64_VMS_COMCOD);
3579 strcat (buf, ", <unknown>");
3585 if ((e_flags & EF_VAX_NONPIC))
3586 strcat (buf, ", non-PIC");
3587 if ((e_flags & EF_VAX_DFLOAT))
3588 strcat (buf, ", D-Float");
3589 if ((e_flags & EF_VAX_GFLOAT))
3590 strcat (buf, ", G-Float");
3594 if (e_flags & EF_VISIUM_ARCH_MCM)
3595 strcat (buf, ", mcm");
3596 else if (e_flags & EF_VISIUM_ARCH_MCM24)
3597 strcat (buf, ", mcm24");
3598 if (e_flags & EF_VISIUM_ARCH_GR6)
3599 strcat (buf, ", gr6");
3603 switch (e_flags & E_FLAG_RL78_CPU_MASK)
3605 case E_FLAG_RL78_ANY_CPU: break;
3606 case E_FLAG_RL78_G10: strcat (buf, ", G10"); break;
3607 case E_FLAG_RL78_G13: strcat (buf, ", G13"); break;
3608 case E_FLAG_RL78_G14: strcat (buf, ", G14"); break;
3610 if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
3611 strcat (buf, ", 64-bit doubles");
3615 if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
3616 strcat (buf, ", 64-bit doubles");
3617 if (e_flags & E_FLAG_RX_DSP)
3618 strcat (buf, ", dsp");
3619 if (e_flags & E_FLAG_RX_PID)
3620 strcat (buf, ", pid");
3621 if (e_flags & E_FLAG_RX_ABI)
3622 strcat (buf, ", RX ABI");
3623 if (e_flags & E_FLAG_RX_SINSNS_SET)
3624 strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES
3625 ? ", uses String instructions" : ", bans String instructions");
3626 if (e_flags & E_FLAG_RX_V2)
3627 strcat (buf, ", V2");
3631 if (e_flags & EF_S390_HIGH_GPRS)
3632 strcat (buf, ", highgprs");
3636 if ((e_flags & EF_C6000_REL))
3637 strcat (buf, ", relocatable module");
3641 strcat (buf, _(": architecture variant: "));
3642 switch (e_flags & EF_MSP430_MACH)
3644 case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
3645 case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
3646 case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
3647 case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
3648 case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
3649 case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
3650 case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
3651 case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
3652 case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
3653 case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
3654 case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
3655 case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
3656 case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
3657 case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
3658 case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break;
3660 strcat (buf, _(": unknown")); break;
3663 if (e_flags & ~ EF_MSP430_MACH)
3664 strcat (buf, _(": unknown extra flag bits also present"));
3672 get_osabi_name (Filedata * filedata, unsigned int osabi)
3674 static char buff[32];
3678 case ELFOSABI_NONE: return "UNIX - System V";
3679 case ELFOSABI_HPUX: return "UNIX - HP-UX";
3680 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
3681 case ELFOSABI_GNU: return "UNIX - GNU";
3682 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
3683 case ELFOSABI_AIX: return "UNIX - AIX";
3684 case ELFOSABI_IRIX: return "UNIX - IRIX";
3685 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
3686 case ELFOSABI_TRU64: return "UNIX - TRU64";
3687 case ELFOSABI_MODESTO: return "Novell - Modesto";
3688 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
3689 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
3690 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
3691 case ELFOSABI_AROS: return "AROS";
3692 case ELFOSABI_FENIXOS: return "FenixOS";
3693 case ELFOSABI_CLOUDABI: return "Nuxi CloudABI";
3694 case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS";
3697 switch (filedata->file_header.e_machine)
3702 case ELFOSABI_ARM: return "ARM";
3713 case ELFOSABI_STANDALONE: return _("Standalone App");
3722 case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000");
3723 case ELFOSABI_C6000_LINUX: return "Linux C6000";
3732 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
3738 get_aarch64_segment_type (unsigned long type)
3742 case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT";
3743 default: return NULL;
3748 get_arm_segment_type (unsigned long type)
3752 case PT_ARM_EXIDX: return "EXIDX";
3753 default: return NULL;
3758 get_s390_segment_type (unsigned long type)
3762 case PT_S390_PGSTE: return "S390_PGSTE";
3763 default: return NULL;
3768 get_mips_segment_type (unsigned long type)
3772 case PT_MIPS_REGINFO: return "REGINFO";
3773 case PT_MIPS_RTPROC: return "RTPROC";
3774 case PT_MIPS_OPTIONS: return "OPTIONS";
3775 case PT_MIPS_ABIFLAGS: return "ABIFLAGS";
3776 default: return NULL;
3781 get_parisc_segment_type (unsigned long type)
3785 case PT_HP_TLS: return "HP_TLS";
3786 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
3787 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
3788 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
3789 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
3790 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
3791 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
3792 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
3793 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
3794 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
3795 case PT_HP_PARALLEL: return "HP_PARALLEL";
3796 case PT_HP_FASTBIND: return "HP_FASTBIND";
3797 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
3798 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
3799 case PT_HP_STACK: return "HP_STACK";
3800 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
3801 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
3802 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
3803 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
3804 default: return NULL;
3809 get_ia64_segment_type (unsigned long type)
3813 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
3814 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
3815 case PT_HP_TLS: return "HP_TLS";
3816 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
3817 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
3818 case PT_IA_64_HP_STACK: return "HP_STACK";
3819 default: return NULL;
3824 get_tic6x_segment_type (unsigned long type)
3828 case PT_C6000_PHATTR: return "C6000_PHATTR";
3829 default: return NULL;
3834 get_solaris_segment_type (unsigned long type)
3838 case 0x6464e550: return "PT_SUNW_UNWIND";
3839 case 0x6474e550: return "PT_SUNW_EH_FRAME";
3840 case 0x6ffffff7: return "PT_LOSUNW";
3841 case 0x6ffffffa: return "PT_SUNWBSS";
3842 case 0x6ffffffb: return "PT_SUNWSTACK";
3843 case 0x6ffffffc: return "PT_SUNWDTRACE";
3844 case 0x6ffffffd: return "PT_SUNWCAP";
3845 case 0x6fffffff: return "PT_HISUNW";
3846 default: return NULL;
3851 get_segment_type (Filedata * filedata, unsigned long p_type)
3853 static char buff[32];
3857 case PT_NULL: return "NULL";
3858 case PT_LOAD: return "LOAD";
3859 case PT_DYNAMIC: return "DYNAMIC";
3860 case PT_INTERP: return "INTERP";
3861 case PT_NOTE: return "NOTE";
3862 case PT_SHLIB: return "SHLIB";
3863 case PT_PHDR: return "PHDR";
3864 case PT_TLS: return "TLS";
3865 case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
3866 case PT_GNU_STACK: return "GNU_STACK";
3867 case PT_GNU_RELRO: return "GNU_RELRO";
3870 if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI)
3872 sprintf (buff, "GNU_MBIND+%#lx",
3873 p_type - PT_GNU_MBIND_LO);
3875 else if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
3877 const char * result;
3879 switch (filedata->file_header.e_machine)
3882 result = get_aarch64_segment_type (p_type);
3885 result = get_arm_segment_type (p_type);
3888 case EM_MIPS_RS3_LE:
3889 result = get_mips_segment_type (p_type);
3892 result = get_parisc_segment_type (p_type);
3895 result = get_ia64_segment_type (p_type);
3898 result = get_tic6x_segment_type (p_type);
3902 result = get_s390_segment_type (p_type);
3912 sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC);
3914 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
3916 const char * result;
3918 switch (filedata->file_header.e_machine)
3921 result = get_parisc_segment_type (p_type);
3924 result = get_ia64_segment_type (p_type);
3927 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
3928 result = get_solaris_segment_type (p_type);
3937 sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS);
3940 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
3947 get_arc_section_type_name (unsigned int sh_type)
3951 case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES";
3959 get_mips_section_type_name (unsigned int sh_type)
3963 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
3964 case SHT_MIPS_MSYM: return "MIPS_MSYM";
3965 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
3966 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
3967 case SHT_MIPS_UCODE: return "MIPS_UCODE";
3968 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
3969 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
3970 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
3971 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
3972 case SHT_MIPS_RELD: return "MIPS_RELD";
3973 case SHT_MIPS_IFACE: return "MIPS_IFACE";
3974 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
3975 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
3976 case SHT_MIPS_SHDR: return "MIPS_SHDR";
3977 case SHT_MIPS_FDESC: return "MIPS_FDESC";
3978 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
3979 case SHT_MIPS_DENSE: return "MIPS_DENSE";
3980 case SHT_MIPS_PDESC: return "MIPS_PDESC";
3981 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
3982 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
3983 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
3984 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
3985 case SHT_MIPS_LINE: return "MIPS_LINE";
3986 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
3987 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
3988 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
3989 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
3990 case SHT_MIPS_DWARF: return "MIPS_DWARF";
3991 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
3992 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
3993 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
3994 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
3995 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
3996 case SHT_MIPS_XLATE: return "MIPS_XLATE";
3997 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
3998 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
3999 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
4000 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
4001 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
4002 case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS";
4010 get_parisc_section_type_name (unsigned int sh_type)
4014 case SHT_PARISC_EXT: return "PARISC_EXT";
4015 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
4016 case SHT_PARISC_DOC: return "PARISC_DOC";
4017 case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
4018 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
4019 case SHT_PARISC_STUBS: return "PARISC_STUBS";
4020 case SHT_PARISC_DLKM: return "PARISC_DLKM";
4021 default: return NULL;
4026 get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type)
4028 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
4029 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
4030 return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16);
4034 case SHT_IA_64_EXT: return "IA_64_EXT";
4035 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
4036 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
4037 case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
4038 case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
4039 case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
4040 case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
4041 case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
4042 case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
4043 case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
4051 get_x86_64_section_type_name (unsigned int sh_type)
4055 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
4056 default: return NULL;
4061 get_aarch64_section_type_name (unsigned int sh_type)
4065 case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES";
4066 default: return NULL;
4071 get_arm_section_type_name (unsigned int sh_type)
4075 case SHT_ARM_EXIDX: return "ARM_EXIDX";
4076 case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
4077 case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
4078 case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
4079 case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
4080 default: return NULL;
4085 get_tic6x_section_type_name (unsigned int sh_type)
4089 case SHT_C6000_UNWIND: return "C6000_UNWIND";
4090 case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
4091 case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES";
4092 case SHT_TI_ICODE: return "TI_ICODE";
4093 case SHT_TI_XREF: return "TI_XREF";
4094 case SHT_TI_HANDLER: return "TI_HANDLER";
4095 case SHT_TI_INITINFO: return "TI_INITINFO";
4096 case SHT_TI_PHATTRS: return "TI_PHATTRS";
4097 default: return NULL;
4102 get_msp430x_section_type_name (unsigned int sh_type)
4106 case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS";
4107 case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
4108 case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES";
4109 default: return NULL;
4114 get_v850_section_type_name (unsigned int sh_type)
4118 case SHT_V850_SCOMMON: return "V850 Small Common";
4119 case SHT_V850_TCOMMON: return "V850 Tiny Common";
4120 case SHT_V850_ZCOMMON: return "V850 Zero Common";
4121 case SHT_RENESAS_IOP: return "RENESAS IOP";
4122 case SHT_RENESAS_INFO: return "RENESAS INFO";
4123 default: return NULL;
4128 get_section_type_name (Filedata * filedata, unsigned int sh_type)
4130 static char buff[32];
4131 const char * result;
4135 case SHT_NULL: return "NULL";
4136 case SHT_PROGBITS: return "PROGBITS";
4137 case SHT_SYMTAB: return "SYMTAB";
4138 case SHT_STRTAB: return "STRTAB";
4139 case SHT_RELA: return "RELA";
4140 case SHT_HASH: return "HASH";
4141 case SHT_DYNAMIC: return "DYNAMIC";
4142 case SHT_NOTE: return "NOTE";
4143 case SHT_NOBITS: return "NOBITS";
4144 case SHT_REL: return "REL";
4145 case SHT_SHLIB: return "SHLIB";
4146 case SHT_DYNSYM: return "DYNSYM";
4147 case SHT_INIT_ARRAY: return "INIT_ARRAY";
4148 case SHT_FINI_ARRAY: return "FINI_ARRAY";
4149 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
4150 case SHT_GNU_HASH: return "GNU_HASH";
4151 case SHT_GROUP: return "GROUP";
4152 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
4153 case SHT_GNU_verdef: return "VERDEF";
4154 case SHT_GNU_verneed: return "VERNEED";
4155 case SHT_GNU_versym: return "VERSYM";
4156 case 0x6ffffff0: return "VERSYM";
4157 case 0x6ffffffc: return "VERDEF";
4158 case 0x7ffffffd: return "AUXILIARY";
4159 case 0x7fffffff: return "FILTER";
4160 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
4163 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
4165 switch (filedata->file_header.e_machine)
4168 case EM_ARC_COMPACT:
4169 case EM_ARC_COMPACT2:
4170 result = get_arc_section_type_name (sh_type);
4173 case EM_MIPS_RS3_LE:
4174 result = get_mips_section_type_name (sh_type);
4177 result = get_parisc_section_type_name (sh_type);
4180 result = get_ia64_section_type_name (filedata, sh_type);
4185 result = get_x86_64_section_type_name (sh_type);
4188 result = get_aarch64_section_type_name (sh_type);
4191 result = get_arm_section_type_name (sh_type);
4194 result = get_tic6x_section_type_name (sh_type);
4197 result = get_msp430x_section_type_name (sh_type);
4201 case EM_CYGNUS_V850:
4202 result = get_v850_section_type_name (sh_type);
4212 sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC);
4214 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
4216 switch (filedata->file_header.e_machine)
4219 result = get_ia64_section_type_name (filedata, sh_type);
4222 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
4223 result = get_solaris_section_type (sh_type);
4228 case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break;
4229 case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break;
4230 case SHT_GNU_HASH: result = "GNU_HASH"; break;
4231 case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break;
4243 sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS);
4245 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
4247 switch (filedata->file_header.e_machine)
4251 case EM_CYGNUS_V850:
4252 result = get_v850_section_type_name (sh_type);
4262 sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER);
4265 /* This message is probably going to be displayed in a 15
4266 character wide field, so put the hex value first. */
4267 snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
4273 #define OPTION_DEBUG_DUMP 512
4274 #define OPTION_DYN_SYMS 513
4275 #define OPTION_DWARF_DEPTH 514
4276 #define OPTION_DWARF_START 515
4277 #define OPTION_DWARF_CHECK 516
4279 static struct option options[] =
4281 {"all", no_argument, 0, 'a'},
4282 {"file-header", no_argument, 0, 'h'},
4283 {"program-headers", no_argument, 0, 'l'},
4284 {"headers", no_argument, 0, 'e'},
4285 {"histogram", no_argument, 0, 'I'},
4286 {"segments", no_argument, 0, 'l'},
4287 {"sections", no_argument, 0, 'S'},
4288 {"section-headers", no_argument, 0, 'S'},
4289 {"section-groups", no_argument, 0, 'g'},
4290 {"section-details", no_argument, 0, 't'},
4291 {"full-section-name",no_argument, 0, 'N'},
4292 {"symbols", no_argument, 0, 's'},
4293 {"syms", no_argument, 0, 's'},
4294 {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS},
4295 {"relocs", no_argument, 0, 'r'},
4296 {"notes", no_argument, 0, 'n'},
4297 {"dynamic", no_argument, 0, 'd'},
4298 {"arch-specific", no_argument, 0, 'A'},
4299 {"version-info", no_argument, 0, 'V'},
4300 {"use-dynamic", no_argument, 0, 'D'},
4301 {"unwind", no_argument, 0, 'u'},
4302 {"archive-index", no_argument, 0, 'c'},
4303 {"hex-dump", required_argument, 0, 'x'},
4304 {"relocated-dump", required_argument, 0, 'R'},
4305 {"string-dump", required_argument, 0, 'p'},
4306 {"decompress", no_argument, 0, 'z'},
4307 #ifdef SUPPORT_DISASSEMBLY
4308 {"instruction-dump", required_argument, 0, 'i'},
4310 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
4312 {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
4313 {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
4314 {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
4316 {"version", no_argument, 0, 'v'},
4317 {"wide", no_argument, 0, 'W'},
4318 {"help", no_argument, 0, 'H'},
4319 {0, no_argument, 0, 0}
4323 usage (FILE * stream)
4325 fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
4326 fprintf (stream, _(" Display information about the contents of ELF format files\n"));
4327 fprintf (stream, _(" Options are:\n\
4328 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
4329 -h --file-header Display the ELF file header\n\
4330 -l --program-headers Display the program headers\n\
4331 --segments An alias for --program-headers\n\
4332 -S --section-headers Display the sections' header\n\
4333 --sections An alias for --section-headers\n\
4334 -g --section-groups Display the section groups\n\
4335 -t --section-details Display the section details\n\
4336 -e --headers Equivalent to: -h -l -S\n\
4337 -s --syms Display the symbol table\n\
4338 --symbols An alias for --syms\n\
4339 --dyn-syms Display the dynamic symbol table\n\
4340 -n --notes Display the core notes (if present)\n\
4341 -r --relocs Display the relocations (if present)\n\
4342 -u --unwind Display the unwind info (if present)\n\
4343 -d --dynamic Display the dynamic section (if present)\n\
4344 -V --version-info Display the version sections (if present)\n\
4345 -A --arch-specific Display architecture specific information (if any)\n\
4346 -c --archive-index Display the symbol/file index in an archive\n\
4347 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
4348 -x --hex-dump=<number|name>\n\
4349 Dump the contents of section <number|name> as bytes\n\
4350 -p --string-dump=<number|name>\n\
4351 Dump the contents of section <number|name> as strings\n\
4352 -R --relocated-dump=<number|name>\n\
4353 Dump the contents of section <number|name> as relocated bytes\n\
4354 -z --decompress Decompress section before dumping it\n\
4355 -w[lLiaprmfFsoRtUuTgAckK] or\n\
4356 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
4357 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
4358 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
4359 =addr,=cu_index,=links,=follow-links]\n\
4360 Display the contents of DWARF debug sections\n"));
4361 fprintf (stream, _("\
4362 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
4363 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
4365 #ifdef SUPPORT_DISASSEMBLY
4366 fprintf (stream, _("\
4367 -i --instruction-dump=<number|name>\n\
4368 Disassemble the contents of section <number|name>\n"));
4370 fprintf (stream, _("\
4371 -I --histogram Display histogram of bucket list lengths\n\
4372 -W --wide Allow output width to exceed 80 characters\n\
4373 @<file> Read options from <file>\n\
4374 -H --help Display this information\n\
4375 -v --version Display the version number of readelf\n"));
4377 if (REPORT_BUGS_TO[0] && stream == stdout)
4378 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
4380 exit (stream == stdout ? 0 : 1);
4383 /* Record the fact that the user wants the contents of section number
4384 SECTION to be displayed using the method(s) encoded as flags bits
4385 in TYPE. Note, TYPE can be zero if we are creating the array for
4389 request_dump_bynumber (Filedata * filedata, unsigned int section, dump_type type)
4391 if (section >= filedata->num_dump_sects)
4393 dump_type * new_dump_sects;
4395 new_dump_sects = (dump_type *) calloc (section + 1,
4396 sizeof (* new_dump_sects));
4398 if (new_dump_sects == NULL)
4399 error (_("Out of memory allocating dump request table.\n"));
4402 if (filedata->dump_sects)
4404 /* Copy current flag settings. */
4405 memcpy (new_dump_sects, filedata->dump_sects,
4406 filedata->num_dump_sects * sizeof (* new_dump_sects));
4408 free (filedata->dump_sects);
4411 filedata->dump_sects = new_dump_sects;
4412 filedata->num_dump_sects = section + 1;
4416 if (filedata->dump_sects)
4417 filedata->dump_sects[section] |= type;
4420 /* Request a dump by section name. */
4423 request_dump_byname (const char * section, dump_type type)
4425 struct dump_list_entry * new_request;
4427 new_request = (struct dump_list_entry *)
4428 malloc (sizeof (struct dump_list_entry));
4430 error (_("Out of memory allocating dump request table.\n"));
4432 new_request->name = strdup (section);
4433 if (!new_request->name)
4434 error (_("Out of memory allocating dump request table.\n"));
4436 new_request->type = type;
4438 new_request->next = dump_sects_byname;
4439 dump_sects_byname = new_request;
4443 request_dump (Filedata * filedata, dump_type type)
4449 section = strtoul (optarg, & cp, 0);
4451 if (! *cp && section >= 0)
4452 request_dump_bynumber (filedata, section, type);
4454 request_dump_byname (optarg, type);
4458 parse_args (Filedata * filedata, int argc, char ** argv)
4465 while ((c = getopt_long
4466 (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
4484 do_section_groups = TRUE;
4487 do_histogram = TRUE;
4492 do_section_groups = TRUE;
4497 do_section_details = TRUE;
4508 do_using_dynamic = TRUE;
4532 do_histogram = TRUE;
4538 do_archive_index = TRUE;
4541 request_dump (filedata, HEX_DUMP);
4544 request_dump (filedata, STRING_DUMP);
4547 request_dump (filedata, RELOC_DUMP);
4550 decompress_dumps = TRUE;
4556 do_debugging = TRUE;
4557 dwarf_select_sections_all ();
4561 do_debugging = FALSE;
4562 dwarf_select_sections_by_letters (optarg);
4565 case OPTION_DEBUG_DUMP:
4568 do_debugging = TRUE;
4571 do_debugging = FALSE;
4572 dwarf_select_sections_by_names (optarg);
4575 case OPTION_DWARF_DEPTH:
4579 dwarf_cutoff_level = strtoul (optarg, & cp, 0);
4582 case OPTION_DWARF_START:
4586 dwarf_start_die = strtoul (optarg, & cp, 0);
4589 case OPTION_DWARF_CHECK:
4592 case OPTION_DYN_SYMS:
4595 #ifdef SUPPORT_DISASSEMBLY
4597 request_dump (filedata, DISASS_DUMP);
4601 print_version (program_name);
4610 /* xgettext:c-format */
4611 error (_("Invalid option '-%c'\n"), c);
4618 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
4619 && !do_segments && !do_header && !do_dump && !do_version
4620 && !do_histogram && !do_debugging && !do_arch && !do_notes
4621 && !do_section_groups && !do_archive_index
4627 get_elf_class (unsigned int elf_class)
4629 static char buff[32];
4633 case ELFCLASSNONE: return _("none");
4634 case ELFCLASS32: return "ELF32";
4635 case ELFCLASS64: return "ELF64";
4637 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
4643 get_data_encoding (unsigned int encoding)
4645 static char buff[32];
4649 case ELFDATANONE: return _("none");
4650 case ELFDATA2LSB: return _("2's complement, little endian");
4651 case ELFDATA2MSB: return _("2's complement, big endian");
4653 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
4658 /* Decode the data held in 'filedata->file_header'. */
4661 process_file_header (Filedata * filedata)
4663 Elf_Internal_Ehdr * header = & filedata->file_header;
4665 if ( header->e_ident[EI_MAG0] != ELFMAG0
4666 || header->e_ident[EI_MAG1] != ELFMAG1
4667 || header->e_ident[EI_MAG2] != ELFMAG2
4668 || header->e_ident[EI_MAG3] != ELFMAG3)
4671 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
4675 init_dwarf_regnames (header->e_machine);
4681 printf (_("ELF Header:\n"));
4682 printf (_(" Magic: "));
4683 for (i = 0; i < EI_NIDENT; i++)
4684 printf ("%2.2x ", header->e_ident[i]);
4686 printf (_(" Class: %s\n"),
4687 get_elf_class (header->e_ident[EI_CLASS]));
4688 printf (_(" Data: %s\n"),
4689 get_data_encoding (header->e_ident[EI_DATA]));
4690 printf (_(" Version: %d %s\n"),
4691 header->e_ident[EI_VERSION],
4692 (header->e_ident[EI_VERSION] == EV_CURRENT
4694 : (header->e_ident[EI_VERSION] != EV_NONE
4695 ? _("<unknown: %lx>")
4697 printf (_(" OS/ABI: %s\n"),
4698 get_osabi_name (filedata, header->e_ident[EI_OSABI]));
4699 printf (_(" ABI Version: %d\n"),
4700 header->e_ident[EI_ABIVERSION]);
4701 printf (_(" Type: %s\n"),
4702 get_file_type (header->e_type));
4703 printf (_(" Machine: %s\n"),
4704 get_machine_name (header->e_machine));
4705 printf (_(" Version: 0x%lx\n"),
4706 (unsigned long) header->e_version);
4708 printf (_(" Entry point address: "));
4709 print_vma ((bfd_vma) header->e_entry, PREFIX_HEX);
4710 printf (_("\n Start of program headers: "));
4711 print_vma ((bfd_vma) header->e_phoff, DEC);
4712 printf (_(" (bytes into file)\n Start of section headers: "));
4713 print_vma ((bfd_vma) header->e_shoff, DEC);
4714 printf (_(" (bytes into file)\n"));
4716 printf (_(" Flags: 0x%lx%s\n"),
4717 (unsigned long) header->e_flags,
4718 get_machine_flags (filedata, header->e_flags, header->e_machine));
4719 printf (_(" Size of this header: %ld (bytes)\n"),
4720 (long) header->e_ehsize);
4721 printf (_(" Size of program headers: %ld (bytes)\n"),
4722 (long) header->e_phentsize);
4723 printf (_(" Number of program headers: %ld"),
4724 (long) header->e_phnum);
4725 if (filedata->section_headers != NULL
4726 && header->e_phnum == PN_XNUM
4727 && filedata->section_headers[0].sh_info != 0)
4728 printf (" (%ld)", (long) filedata->section_headers[0].sh_info);
4729 putc ('\n', stdout);
4730 printf (_(" Size of section headers: %ld (bytes)\n"),
4731 (long) header->e_shentsize);
4732 printf (_(" Number of section headers: %ld"),
4733 (long) header->e_shnum);
4734 if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF)
4735 printf (" (%ld)", (long) filedata->section_headers[0].sh_size);
4736 putc ('\n', stdout);
4737 printf (_(" Section header string table index: %ld"),
4738 (long) header->e_shstrndx);
4739 if (filedata->section_headers != NULL
4740 && header->e_shstrndx == (SHN_XINDEX & 0xffff))
4741 printf (" (%u)", filedata->section_headers[0].sh_link);
4742 else if (header->e_shstrndx != SHN_UNDEF
4743 && header->e_shstrndx >= header->e_shnum)
4744 printf (_(" <corrupt: out of range>"));
4745 putc ('\n', stdout);
4748 if (filedata->section_headers != NULL)
4750 if (header->e_phnum == PN_XNUM
4751 && filedata->section_headers[0].sh_info != 0)
4752 header->e_phnum = filedata->section_headers[0].sh_info;
4753 if (header->e_shnum == SHN_UNDEF)
4754 header->e_shnum = filedata->section_headers[0].sh_size;
4755 if (header->e_shstrndx == (SHN_XINDEX & 0xffff))
4756 header->e_shstrndx = filedata->section_headers[0].sh_link;
4757 if (header->e_shstrndx >= header->e_shnum)
4758 header->e_shstrndx = SHN_UNDEF;
4759 free (filedata->section_headers);
4760 filedata->section_headers = NULL;
4766 /* Read in the program headers from FILEDATA and store them in PHEADERS.
4767 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
4770 get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
4772 Elf32_External_Phdr * phdrs;
4773 Elf32_External_Phdr * external;
4774 Elf_Internal_Phdr * internal;
4776 unsigned int size = filedata->file_header.e_phentsize;
4777 unsigned int num = filedata->file_header.e_phnum;
4779 /* PR binutils/17531: Cope with unexpected section header sizes. */
4780 if (size == 0 || num == 0)
4782 if (size < sizeof * phdrs)
4784 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
4787 if (size > sizeof * phdrs)
4788 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
4790 phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
4791 size, num, _("program headers"));
4795 for (i = 0, internal = pheaders, external = phdrs;
4796 i < filedata->file_header.e_phnum;
4797 i++, internal++, external++)
4799 internal->p_type = BYTE_GET (external->p_type);
4800 internal->p_offset = BYTE_GET (external->p_offset);
4801 internal->p_vaddr = BYTE_GET (external->p_vaddr);
4802 internal->p_paddr = BYTE_GET (external->p_paddr);
4803 internal->p_filesz = BYTE_GET (external->p_filesz);
4804 internal->p_memsz = BYTE_GET (external->p_memsz);
4805 internal->p_flags = BYTE_GET (external->p_flags);
4806 internal->p_align = BYTE_GET (external->p_align);
4813 /* Read in the program headers from FILEDATA and store them in PHEADERS.
4814 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
4817 get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
4819 Elf64_External_Phdr * phdrs;
4820 Elf64_External_Phdr * external;
4821 Elf_Internal_Phdr * internal;
4823 unsigned int size = filedata->file_header.e_phentsize;
4824 unsigned int num = filedata->file_header.e_phnum;
4826 /* PR binutils/17531: Cope with unexpected section header sizes. */
4827 if (size == 0 || num == 0)
4829 if (size < sizeof * phdrs)
4831 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
4834 if (size > sizeof * phdrs)
4835 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
4837 phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
4838 size, num, _("program headers"));
4842 for (i = 0, internal = pheaders, external = phdrs;
4843 i < filedata->file_header.e_phnum;
4844 i++, internal++, external++)
4846 internal->p_type = BYTE_GET (external->p_type);
4847 internal->p_flags = BYTE_GET (external->p_flags);
4848 internal->p_offset = BYTE_GET (external->p_offset);
4849 internal->p_vaddr = BYTE_GET (external->p_vaddr);
4850 internal->p_paddr = BYTE_GET (external->p_paddr);
4851 internal->p_filesz = BYTE_GET (external->p_filesz);
4852 internal->p_memsz = BYTE_GET (external->p_memsz);
4853 internal->p_align = BYTE_GET (external->p_align);
4860 /* Returns TRUE if the program headers were read into `program_headers'. */
4863 get_program_headers (Filedata * filedata)
4865 Elf_Internal_Phdr * phdrs;
4867 /* Check cache of prior read. */
4868 if (filedata->program_headers != NULL)
4871 /* Be kind to memory checkers by looking for
4872 e_phnum values which we know must be invalid. */
4873 if (filedata->file_header.e_phnum
4874 * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr))
4875 >= filedata->file_size)
4877 error (_("Too many program headers - %#x - the file is not that big\n"),
4878 filedata->file_header.e_phnum);
4882 phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum,
4883 sizeof (Elf_Internal_Phdr));
4886 error (_("Out of memory reading %u program headers\n"),
4887 filedata->file_header.e_phnum);
4892 ? get_32bit_program_headers (filedata, phdrs)
4893 : get_64bit_program_headers (filedata, phdrs))
4895 filedata->program_headers = phdrs;
4903 /* Returns TRUE if the program headers were loaded. */
4906 process_program_headers (Filedata * filedata)
4908 Elf_Internal_Phdr * segment;
4910 Elf_Internal_Phdr * previous_load = NULL;
4912 if (filedata->file_header.e_phnum == 0)
4914 /* PR binutils/12467. */
4915 if (filedata->file_header.e_phoff != 0)
4917 warn (_("possibly corrupt ELF header - it has a non-zero program"
4918 " header offset, but no program headers\n"));
4921 else if (do_segments)
4922 printf (_("\nThere are no program headers in this file.\n"));
4926 if (do_segments && !do_header)
4928 printf (_("\nElf file type is %s\n"), get_file_type (filedata->file_header.e_type));
4929 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry));
4930 printf (ngettext ("There is %d program header, starting at offset %s\n",
4931 "There are %d program headers, starting at offset %s\n",
4932 filedata->file_header.e_phnum),
4933 filedata->file_header.e_phnum,
4934 bfd_vmatoa ("u", filedata->file_header.e_phoff));
4937 if (! get_program_headers (filedata))
4942 if (filedata->file_header.e_phnum > 1)
4943 printf (_("\nProgram Headers:\n"));
4945 printf (_("\nProgram Headers:\n"));
4949 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
4952 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
4956 (_(" Type Offset VirtAddr PhysAddr\n"));
4958 (_(" FileSiz MemSiz Flags Align\n"));
4965 for (i = 0, segment = filedata->program_headers;
4966 i < filedata->file_header.e_phnum;
4971 printf (" %-14.14s ", get_segment_type (filedata, segment->p_type));
4975 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
4976 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
4977 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
4978 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
4979 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
4981 (segment->p_flags & PF_R ? 'R' : ' '),
4982 (segment->p_flags & PF_W ? 'W' : ' '),
4983 (segment->p_flags & PF_X ? 'E' : ' '));
4984 printf ("%#lx", (unsigned long) segment->p_align);
4988 if ((unsigned long) segment->p_offset == segment->p_offset)
4989 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
4992 print_vma (segment->p_offset, FULL_HEX);
4996 print_vma (segment->p_vaddr, FULL_HEX);
4998 print_vma (segment->p_paddr, FULL_HEX);
5001 if ((unsigned long) segment->p_filesz == segment->p_filesz)
5002 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
5005 print_vma (segment->p_filesz, FULL_HEX);
5009 if ((unsigned long) segment->p_memsz == segment->p_memsz)
5010 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
5013 print_vma (segment->p_memsz, FULL_HEX);
5017 (segment->p_flags & PF_R ? 'R' : ' '),
5018 (segment->p_flags & PF_W ? 'W' : ' '),
5019 (segment->p_flags & PF_X ? 'E' : ' '));
5021 if ((unsigned long) segment->p_align == segment->p_align)
5022 printf ("%#lx", (unsigned long) segment->p_align);
5025 print_vma (segment->p_align, PREFIX_HEX);
5030 print_vma (segment->p_offset, FULL_HEX);
5032 print_vma (segment->p_vaddr, FULL_HEX);
5034 print_vma (segment->p_paddr, FULL_HEX);
5036 print_vma (segment->p_filesz, FULL_HEX);
5038 print_vma (segment->p_memsz, FULL_HEX);
5040 (segment->p_flags & PF_R ? 'R' : ' '),
5041 (segment->p_flags & PF_W ? 'W' : ' '),
5042 (segment->p_flags & PF_X ? 'E' : ' '));
5043 print_vma (segment->p_align, PREFIX_HEX);
5046 putc ('\n', stdout);
5049 switch (segment->p_type)
5052 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
5053 required by the ELF standard, several programs, including the Linux
5054 kernel, make use of non-ordered segments. */
5056 && previous_load->p_vaddr > segment->p_vaddr)
5057 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
5059 if (segment->p_memsz < segment->p_filesz)
5060 error (_("the segment's file size is larger than its memory size\n"));
5061 previous_load = segment;
5065 /* PR 20815 - Verify that the program header is loaded into memory. */
5066 if (i > 0 && previous_load != NULL)
5067 error (_("the PHDR segment must occur before any LOAD segment\n"));
5068 if (filedata->file_header.e_machine != EM_PARISC)
5072 for (j = 1; j < filedata->file_header.e_phnum; j++)
5073 if (filedata->program_headers[j].p_vaddr <= segment->p_vaddr
5074 && (filedata->program_headers[j].p_vaddr
5075 + filedata->program_headers[j].p_memsz)
5076 >= (segment->p_vaddr + segment->p_filesz))
5078 if (j == filedata->file_header.e_phnum)
5079 error (_("the PHDR segment is not covered by a LOAD segment\n"));
5085 error (_("more than one dynamic segment\n"));
5087 /* By default, assume that the .dynamic section is the first
5088 section in the DYNAMIC segment. */
5089 dynamic_addr = segment->p_offset;
5090 dynamic_size = segment->p_filesz;
5092 /* Try to locate the .dynamic section. If there is
5093 a section header table, we can easily locate it. */
5094 if (filedata->section_headers != NULL)
5096 Elf_Internal_Shdr * sec;
5098 sec = find_section (filedata, ".dynamic");
5099 if (sec == NULL || sec->sh_size == 0)
5101 /* A corresponding .dynamic section is expected, but on
5102 IA-64/OpenVMS it is OK for it to be missing. */
5103 if (!is_ia64_vms (filedata))
5104 error (_("no .dynamic section in the dynamic segment\n"));
5108 if (sec->sh_type == SHT_NOBITS)
5114 dynamic_addr = sec->sh_offset;
5115 dynamic_size = sec->sh_size;
5117 if (dynamic_addr < segment->p_offset
5118 || dynamic_addr > segment->p_offset + segment->p_filesz)
5119 warn (_("the .dynamic section is not contained"
5120 " within the dynamic segment\n"));
5121 else if (dynamic_addr > segment->p_offset)
5122 warn (_("the .dynamic section is not the first section"
5123 " in the dynamic segment.\n"));
5126 /* PR binutils/17512: Avoid corrupt dynamic section info in the
5127 segment. Check this after matching against the section headers
5128 so we don't warn on debuginfo file (which have NOBITS .dynamic
5130 if (dynamic_addr + dynamic_size >= filedata->file_size)
5132 error (_("the dynamic segment offset + size exceeds the size of the file\n"));
5133 dynamic_addr = dynamic_size = 0;
5138 if (fseek (filedata->handle, archive_file_offset + (long) segment->p_offset,
5140 error (_("Unable to find program interpreter name\n"));
5144 int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
5146 if (ret >= (int) sizeof (fmt) || ret < 0)
5147 error (_("Internal error: failed to create format string to display program interpreter\n"));
5149 program_interpreter[0] = 0;
5150 if (fscanf (filedata->handle, fmt, program_interpreter) <= 0)
5151 error (_("Unable to read program interpreter name\n"));
5154 printf (_(" [Requesting program interpreter: %s]\n"),
5155 program_interpreter);
5162 && filedata->section_headers != NULL
5163 && filedata->string_table != NULL)
5165 printf (_("\n Section to Segment mapping:\n"));
5166 printf (_(" Segment Sections...\n"));
5168 for (i = 0; i < filedata->file_header.e_phnum; i++)
5171 Elf_Internal_Shdr * section;
5173 segment = filedata->program_headers + i;
5174 section = filedata->section_headers + 1;
5176 printf (" %2.2d ", i);
5178 for (j = 1; j < filedata->file_header.e_shnum; j++, section++)
5180 if (!ELF_TBSS_SPECIAL (section, segment)
5181 && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
5182 printf ("%s ", printable_section_name (filedata, section));
5193 /* Find the file offset corresponding to VMA by using the program headers. */
5196 offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size)
5198 Elf_Internal_Phdr * seg;
5200 if (! get_program_headers (filedata))
5202 warn (_("Cannot interpret virtual addresses without program headers.\n"));
5206 for (seg = filedata->program_headers;
5207 seg < filedata->program_headers + filedata->file_header.e_phnum;
5210 if (seg->p_type != PT_LOAD)
5213 if (vma >= (seg->p_vaddr & -seg->p_align)
5214 && vma + size <= seg->p_vaddr + seg->p_filesz)
5215 return vma - seg->p_vaddr + seg->p_offset;
5218 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
5219 (unsigned long) vma);
5224 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
5225 If PROBE is true, this is just a probe and we do not generate any error
5226 messages if the load fails. */
5229 get_32bit_section_headers (Filedata * filedata, bfd_boolean probe)
5231 Elf32_External_Shdr * shdrs;
5232 Elf_Internal_Shdr * internal;
5234 unsigned int size = filedata->file_header.e_shentsize;
5235 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
5237 /* PR binutils/17531: Cope with unexpected section header sizes. */
5238 if (size == 0 || num == 0)
5240 if (size < sizeof * shdrs)
5243 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5246 if (!probe && size > sizeof * shdrs)
5247 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5249 shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff,
5251 probe ? NULL : _("section headers"));
5255 free (filedata->section_headers);
5256 filedata->section_headers = (Elf_Internal_Shdr *)
5257 cmalloc (num, sizeof (Elf_Internal_Shdr));
5258 if (filedata->section_headers == NULL)
5261 error (_("Out of memory reading %u section headers\n"), num);
5265 for (i = 0, internal = filedata->section_headers;
5269 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5270 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
5271 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5272 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5273 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5274 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5275 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5276 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5277 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
5278 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
5279 if (!probe && internal->sh_link > num)
5280 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5281 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5282 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
5289 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
5292 get_64bit_section_headers (Filedata * filedata, bfd_boolean probe)
5294 Elf64_External_Shdr * shdrs;
5295 Elf_Internal_Shdr * internal;
5297 unsigned int size = filedata->file_header.e_shentsize;
5298 unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
5300 /* PR binutils/17531: Cope with unexpected section header sizes. */
5301 if (size == 0 || num == 0)
5304 if (size < sizeof * shdrs)
5307 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
5311 if (! probe && size > sizeof * shdrs)
5312 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
5314 shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata,
5315 filedata->file_header.e_shoff,
5317 probe ? NULL : _("section headers"));
5321 free (filedata->section_headers);
5322 filedata->section_headers = (Elf_Internal_Shdr *)
5323 cmalloc (num, sizeof (Elf_Internal_Shdr));
5324 if (filedata->section_headers == NULL)
5327 error (_("Out of memory reading %u section headers\n"), num);
5331 for (i = 0, internal = filedata->section_headers;
5335 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
5336 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
5337 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
5338 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
5339 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
5340 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
5341 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
5342 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
5343 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
5344 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
5345 if (!probe && internal->sh_link > num)
5346 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
5347 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
5348 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
5355 static Elf_Internal_Sym *
5356 get_32bit_elf_symbols (Filedata * filedata,
5357 Elf_Internal_Shdr * section,
5358 unsigned long * num_syms_return)
5360 unsigned long number = 0;
5361 Elf32_External_Sym * esyms = NULL;
5362 Elf_External_Sym_Shndx * shndx = NULL;
5363 Elf_Internal_Sym * isyms = NULL;
5364 Elf_Internal_Sym * psym;
5367 if (section->sh_size == 0)
5369 if (num_syms_return != NULL)
5370 * num_syms_return = 0;
5374 /* Run some sanity checks first. */
5375 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
5377 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5378 printable_section_name (filedata, section),
5379 (unsigned long) section->sh_entsize);
5383 if (section->sh_size > filedata->file_size)
5385 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5386 printable_section_name (filedata, section),
5387 (unsigned long) section->sh_size);
5391 number = section->sh_size / section->sh_entsize;
5393 if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
5395 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5396 (unsigned long) section->sh_size,
5397 printable_section_name (filedata, section),
5398 (unsigned long) section->sh_entsize);
5402 esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
5403 section->sh_size, _("symbols"));
5408 elf_section_list * entry;
5411 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
5412 if (entry->hdr->sh_link == (unsigned long) (section - filedata->section_headers))
5414 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5415 entry->hdr->sh_offset,
5416 1, entry->hdr->sh_size,
5417 _("symbol table section indicies"));
5420 /* PR17531: file: heap-buffer-overflow */
5421 else if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5423 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5424 printable_section_name (filedata, entry->hdr),
5425 (unsigned long) entry->hdr->sh_size,
5426 (unsigned long) section->sh_size);
5432 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
5436 error (_("Out of memory reading %lu symbols\n"),
5437 (unsigned long) number);
5441 for (j = 0, psym = isyms; j < number; j++, psym++)
5443 psym->st_name = BYTE_GET (esyms[j].st_name);
5444 psym->st_value = BYTE_GET (esyms[j].st_value);
5445 psym->st_size = BYTE_GET (esyms[j].st_size);
5446 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
5447 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
5449 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
5450 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5451 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
5452 psym->st_info = BYTE_GET (esyms[j].st_info);
5453 psym->st_other = BYTE_GET (esyms[j].st_other);
5462 if (num_syms_return != NULL)
5463 * num_syms_return = isyms == NULL ? 0 : number;
5468 static Elf_Internal_Sym *
5469 get_64bit_elf_symbols (Filedata * filedata,
5470 Elf_Internal_Shdr * section,
5471 unsigned long * num_syms_return)
5473 unsigned long number = 0;
5474 Elf64_External_Sym * esyms = NULL;
5475 Elf_External_Sym_Shndx * shndx = NULL;
5476 Elf_Internal_Sym * isyms = NULL;
5477 Elf_Internal_Sym * psym;
5480 if (section->sh_size == 0)
5482 if (num_syms_return != NULL)
5483 * num_syms_return = 0;
5487 /* Run some sanity checks first. */
5488 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
5490 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
5491 printable_section_name (filedata, section),
5492 (unsigned long) section->sh_entsize);
5496 if (section->sh_size > filedata->file_size)
5498 error (_("Section %s has an invalid sh_size of 0x%lx\n"),
5499 printable_section_name (filedata, section),
5500 (unsigned long) section->sh_size);
5504 number = section->sh_size / section->sh_entsize;
5506 if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
5508 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
5509 (unsigned long) section->sh_size,
5510 printable_section_name (filedata, section),
5511 (unsigned long) section->sh_entsize);
5515 esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
5516 section->sh_size, _("symbols"));
5521 elf_section_list * entry;
5524 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
5525 if (entry->hdr->sh_link == (unsigned long) (section - filedata->section_headers))
5527 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
5528 entry->hdr->sh_offset,
5529 1, entry->hdr->sh_size,
5530 _("symbol table section indicies"));
5533 /* PR17531: file: heap-buffer-overflow */
5534 else if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
5536 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
5537 printable_section_name (filedata, entry->hdr),
5538 (unsigned long) entry->hdr->sh_size,
5539 (unsigned long) section->sh_size);
5545 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
5549 error (_("Out of memory reading %lu symbols\n"),
5550 (unsigned long) number);
5554 for (j = 0, psym = isyms; j < number; j++, psym++)
5556 psym->st_name = BYTE_GET (esyms[j].st_name);
5557 psym->st_info = BYTE_GET (esyms[j].st_info);
5558 psym->st_other = BYTE_GET (esyms[j].st_other);
5559 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
5561 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
5563 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
5564 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
5565 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
5567 psym->st_value = BYTE_GET (esyms[j].st_value);
5568 psym->st_size = BYTE_GET (esyms[j].st_size);
5577 if (num_syms_return != NULL)
5578 * num_syms_return = isyms == NULL ? 0 : number;
5584 get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
5586 static char buff[1024];
5588 unsigned int field_size = is_32bit_elf ? 8 : 16;
5590 unsigned int size = sizeof (buff) - (field_size + 4 + 1);
5591 bfd_vma os_flags = 0;
5592 bfd_vma proc_flags = 0;
5593 bfd_vma unknown_flags = 0;
5601 /* 0 */ { STRING_COMMA_LEN ("WRITE") },
5602 /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
5603 /* 2 */ { STRING_COMMA_LEN ("EXEC") },
5604 /* 3 */ { STRING_COMMA_LEN ("MERGE") },
5605 /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
5606 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
5607 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
5608 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
5609 /* 8 */ { STRING_COMMA_LEN ("GROUP") },
5610 /* 9 */ { STRING_COMMA_LEN ("TLS") },
5611 /* IA-64 specific. */
5612 /* 10 */ { STRING_COMMA_LEN ("SHORT") },
5613 /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
5614 /* IA-64 OpenVMS specific. */
5615 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
5616 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
5617 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
5618 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
5619 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
5620 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
5622 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
5623 /* SPARC specific. */
5624 /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
5625 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
5627 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
5628 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
5629 /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
5631 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
5633 /* 25 */ { STRING_COMMA_LEN ("VLE") },
5636 if (do_section_details)
5638 sprintf (buff, "[%*.*lx]: ",
5639 field_size, field_size, (unsigned long) sh_flags);
5640 p += field_size + 4;
5647 flag = sh_flags & - sh_flags;
5650 if (do_section_details)
5654 case SHF_WRITE: sindex = 0; break;
5655 case SHF_ALLOC: sindex = 1; break;
5656 case SHF_EXECINSTR: sindex = 2; break;
5657 case SHF_MERGE: sindex = 3; break;
5658 case SHF_STRINGS: sindex = 4; break;
5659 case SHF_INFO_LINK: sindex = 5; break;
5660 case SHF_LINK_ORDER: sindex = 6; break;
5661 case SHF_OS_NONCONFORMING: sindex = 7; break;
5662 case SHF_GROUP: sindex = 8; break;
5663 case SHF_TLS: sindex = 9; break;
5664 case SHF_EXCLUDE: sindex = 18; break;
5665 case SHF_COMPRESSED: sindex = 20; break;
5666 case SHF_GNU_MBIND: sindex = 24; break;
5670 switch (filedata->file_header.e_machine)
5673 if (flag == SHF_IA_64_SHORT)
5675 else if (flag == SHF_IA_64_NORECOV)
5678 else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
5681 case SHF_IA_64_VMS_GLOBAL: sindex = 12; break;
5682 case SHF_IA_64_VMS_OVERLAID: sindex = 13; break;
5683 case SHF_IA_64_VMS_SHARED: sindex = 14; break;
5684 case SHF_IA_64_VMS_VECTOR: sindex = 15; break;
5685 case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
5686 case SHF_IA_64_VMS_PROTECTED: sindex = 17; break;
5697 case EM_OLD_SPARCV9:
5698 case EM_SPARC32PLUS:
5701 if (flag == SHF_ORDERED)
5708 case SHF_ENTRYSECT: sindex = 21; break;
5709 case SHF_ARM_PURECODE: sindex = 22; break;
5710 case SHF_COMDEF: sindex = 23; break;
5715 if (flag == SHF_PPC_VLE)
5726 if (p != buff + field_size + 4)
5728 if (size < (10 + 2))
5730 warn (_("Internal error: not enough buffer room for section flag info"));
5731 return _("<unknown>");
5738 size -= flags [sindex].len;
5739 p = stpcpy (p, flags [sindex].str);
5741 else if (flag & SHF_MASKOS)
5743 else if (flag & SHF_MASKPROC)
5746 unknown_flags |= flag;
5752 case SHF_WRITE: *p = 'W'; break;
5753 case SHF_ALLOC: *p = 'A'; break;
5754 case SHF_EXECINSTR: *p = 'X'; break;
5755 case SHF_MERGE: *p = 'M'; break;
5756 case SHF_STRINGS: *p = 'S'; break;
5757 case SHF_INFO_LINK: *p = 'I'; break;
5758 case SHF_LINK_ORDER: *p = 'L'; break;
5759 case SHF_OS_NONCONFORMING: *p = 'O'; break;
5760 case SHF_GROUP: *p = 'G'; break;
5761 case SHF_TLS: *p = 'T'; break;
5762 case SHF_EXCLUDE: *p = 'E'; break;
5763 case SHF_COMPRESSED: *p = 'C'; break;
5764 case SHF_GNU_MBIND: *p = 'D'; break;
5767 if ((filedata->file_header.e_machine == EM_X86_64
5768 || filedata->file_header.e_machine == EM_L1OM
5769 || filedata->file_header.e_machine == EM_K1OM)
5770 && flag == SHF_X86_64_LARGE)
5772 else if (filedata->file_header.e_machine == EM_ARM
5773 && flag == SHF_ARM_PURECODE)
5775 else if (filedata->file_header.e_machine == EM_PPC
5776 && flag == SHF_PPC_VLE)
5778 else if (flag & SHF_MASKOS)
5781 sh_flags &= ~ SHF_MASKOS;
5783 else if (flag & SHF_MASKPROC)
5786 sh_flags &= ~ SHF_MASKPROC;
5796 if (do_section_details)
5800 size -= 5 + field_size;
5801 if (p != buff + field_size + 4)
5805 warn (_("Internal error: not enough buffer room for section flag info"));
5806 return _("<unknown>");
5812 sprintf (p, "OS (%*.*lx)", field_size, field_size,
5813 (unsigned long) os_flags);
5814 p += 5 + field_size;
5818 size -= 7 + field_size;
5819 if (p != buff + field_size + 4)
5823 warn (_("Internal error: not enough buffer room for section flag info"));
5824 return _("<unknown>");
5830 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
5831 (unsigned long) proc_flags);
5832 p += 7 + field_size;
5836 size -= 10 + field_size;
5837 if (p != buff + field_size + 4)
5841 warn (_("Internal error: not enough buffer room for section flag info"));
5842 return _("<unknown>");
5848 sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
5849 (unsigned long) unknown_flags);
5850 p += 10 + field_size;
5859 get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size)
5863 Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf;
5865 if (size < sizeof (* echdr))
5867 error (_("Compressed section is too small even for a compression header\n"));
5871 chdr->ch_type = BYTE_GET (echdr->ch_type);
5872 chdr->ch_size = BYTE_GET (echdr->ch_size);
5873 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
5874 return sizeof (*echdr);
5878 Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf;
5880 if (size < sizeof (* echdr))
5882 error (_("Compressed section is too small even for a compression header\n"));
5886 chdr->ch_type = BYTE_GET (echdr->ch_type);
5887 chdr->ch_size = BYTE_GET (echdr->ch_size);
5888 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
5889 return sizeof (*echdr);
5894 process_section_headers (Filedata * filedata)
5896 Elf_Internal_Shdr * section;
5899 filedata->section_headers = NULL;
5901 if (filedata->file_header.e_shnum == 0)
5903 /* PR binutils/12467. */
5904 if (filedata->file_header.e_shoff != 0)
5906 warn (_("possibly corrupt ELF file header - it has a non-zero"
5907 " section header offset, but no section headers\n"));
5910 else if (do_sections)
5911 printf (_("\nThere are no sections in this file.\n"));
5916 if (do_sections && !do_header)
5917 printf (ngettext ("There is %d section header, "
5918 "starting at offset 0x%lx:\n",
5919 "There are %d section headers, "
5920 "starting at offset 0x%lx:\n",
5921 filedata->file_header.e_shnum),
5922 filedata->file_header.e_shnum,
5923 (unsigned long) filedata->file_header.e_shoff);
5927 if (! get_32bit_section_headers (filedata, FALSE))
5932 if (! get_64bit_section_headers (filedata, FALSE))
5936 /* Read in the string table, so that we have names to display. */
5937 if (filedata->file_header.e_shstrndx != SHN_UNDEF
5938 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
5940 section = filedata->section_headers + filedata->file_header.e_shstrndx;
5942 if (section->sh_size != 0)
5944 filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset,
5945 1, section->sh_size,
5948 filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0;
5952 /* Scan the sections for the dynamic symbol table
5953 and dynamic string table and debug sections. */
5954 dynamic_symbols = NULL;
5955 dynamic_strings = NULL;
5956 dynamic_syminfo = NULL;
5957 symtab_shndx_list = NULL;
5959 eh_addr_size = is_32bit_elf ? 4 : 8;
5960 switch (filedata->file_header.e_machine)
5963 case EM_MIPS_RS3_LE:
5964 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
5965 FDE addresses. However, the ABI also has a semi-official ILP32
5966 variant for which the normal FDE address size rules apply.
5968 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
5969 section, where XX is the size of longs in bits. Unfortunately,
5970 earlier compilers provided no way of distinguishing ILP32 objects
5971 from LP64 objects, so if there's any doubt, we should assume that
5972 the official LP64 form is being used. */
5973 if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
5974 && find_section (filedata, ".gcc_compiled_long32") == NULL)
5980 switch (filedata->file_header.e_flags & EF_H8_MACH)
5982 case E_H8_MACH_H8300:
5983 case E_H8_MACH_H8300HN:
5984 case E_H8_MACH_H8300SN:
5985 case E_H8_MACH_H8300SXN:
5988 case E_H8_MACH_H8300H:
5989 case E_H8_MACH_H8300S:
5990 case E_H8_MACH_H8300SX:
5998 switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK)
6000 case EF_M32C_CPU_M16C:
6007 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
6010 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
6011 if (section->sh_entsize != expected_entsize) \
6014 sprintf_vma (buf, section->sh_entsize); \
6015 /* Note: coded this way so that there is a single string for \
6017 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
6018 error (_("(Using the expected size of %u for the rest of this dump)\n"), \
6019 (unsigned) expected_entsize); \
6020 section->sh_entsize = expected_entsize; \
6025 #define CHECK_ENTSIZE(section, i, type) \
6026 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
6027 sizeof (Elf64_External_##type))
6029 for (i = 0, section = filedata->section_headers;
6030 i < filedata->file_header.e_shnum;
6033 char * name = SECTION_NAME (section);
6035 if (section->sh_type == SHT_DYNSYM)
6037 if (dynamic_symbols != NULL)
6039 error (_("File contains multiple dynamic symbol tables\n"));
6043 CHECK_ENTSIZE (section, i, Sym);
6044 dynamic_symbols = GET_ELF_SYMBOLS (filedata, section, & num_dynamic_syms);
6046 else if (section->sh_type == SHT_STRTAB
6047 && streq (name, ".dynstr"))
6049 if (dynamic_strings != NULL)
6051 error (_("File contains multiple dynamic string tables\n"));
6055 dynamic_strings = (char *) get_data (NULL, filedata, section->sh_offset,
6056 1, section->sh_size,
6057 _("dynamic strings"));
6058 dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
6060 else if (section->sh_type == SHT_SYMTAB_SHNDX)
6062 elf_section_list * entry = xmalloc (sizeof * entry);
6064 entry->hdr = section;
6065 entry->next = symtab_shndx_list;
6066 symtab_shndx_list = entry;
6068 else if (section->sh_type == SHT_SYMTAB)
6069 CHECK_ENTSIZE (section, i, Sym);
6070 else if (section->sh_type == SHT_GROUP)
6071 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
6072 else if (section->sh_type == SHT_REL)
6073 CHECK_ENTSIZE (section, i, Rel);
6074 else if (section->sh_type == SHT_RELA)
6075 CHECK_ENTSIZE (section, i, Rela);
6076 else if ((do_debugging || do_debug_info || do_debug_abbrevs
6077 || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
6078 || do_debug_aranges || do_debug_frames || do_debug_macinfo
6079 || do_debug_str || do_debug_loc || do_debug_ranges
6080 || do_debug_addr || do_debug_cu_index || do_debug_links)
6081 && (const_strneq (name, ".debug_")
6082 || const_strneq (name, ".zdebug_")))
6085 name += sizeof (".zdebug_") - 1;
6087 name += sizeof (".debug_") - 1;
6090 || (do_debug_info && const_strneq (name, "info"))
6091 || (do_debug_info && const_strneq (name, "types"))
6092 || (do_debug_abbrevs && const_strneq (name, "abbrev"))
6093 || (do_debug_lines && strcmp (name, "line") == 0)
6094 || (do_debug_lines && const_strneq (name, "line."))
6095 || (do_debug_pubnames && const_strneq (name, "pubnames"))
6096 || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
6097 || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
6098 || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
6099 || (do_debug_aranges && const_strneq (name, "aranges"))
6100 || (do_debug_ranges && const_strneq (name, "ranges"))
6101 || (do_debug_ranges && const_strneq (name, "rnglists"))
6102 || (do_debug_frames && const_strneq (name, "frame"))
6103 || (do_debug_macinfo && const_strneq (name, "macinfo"))
6104 || (do_debug_macinfo && const_strneq (name, "macro"))
6105 || (do_debug_str && const_strneq (name, "str"))
6106 || (do_debug_loc && const_strneq (name, "loc"))
6107 || (do_debug_loc && const_strneq (name, "loclists"))
6108 || (do_debug_addr && const_strneq (name, "addr"))
6109 || (do_debug_cu_index && const_strneq (name, "cu_index"))
6110 || (do_debug_cu_index && const_strneq (name, "tu_index"))
6112 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6114 /* Linkonce section to be combined with .debug_info at link time. */
6115 else if ((do_debugging || do_debug_info)
6116 && const_strneq (name, ".gnu.linkonce.wi."))
6117 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6118 else if (do_debug_frames && streq (name, ".eh_frame"))
6119 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6120 else if (do_gdb_index && (streq (name, ".gdb_index")
6121 || streq (name, ".debug_names")))
6122 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6123 /* Trace sections for Itanium VMS. */
6124 else if ((do_debugging || do_trace_info || do_trace_abbrevs
6125 || do_trace_aranges)
6126 && const_strneq (name, ".trace_"))
6128 name += sizeof (".trace_") - 1;
6131 || (do_trace_info && streq (name, "info"))
6132 || (do_trace_abbrevs && streq (name, "abbrev"))
6133 || (do_trace_aranges && streq (name, "aranges"))
6135 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6137 else if ((do_debugging || do_debug_links)
6138 && (const_strneq (name, ".gnu_debuglink")
6139 || const_strneq (name, ".gnu_debugaltlink")))
6140 request_dump_bynumber (filedata, i, DEBUG_DUMP);
6146 if (filedata->file_header.e_shnum > 1)
6147 printf (_("\nSection Headers:\n"));
6149 printf (_("\nSection Header:\n"));
6153 if (do_section_details)
6155 printf (_(" [Nr] Name\n"));
6156 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
6160 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
6164 if (do_section_details)
6166 printf (_(" [Nr] Name\n"));
6167 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
6171 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
6175 if (do_section_details)
6177 printf (_(" [Nr] Name\n"));
6178 printf (_(" Type Address Offset Link\n"));
6179 printf (_(" Size EntSize Info Align\n"));
6183 printf (_(" [Nr] Name Type Address Offset\n"));
6184 printf (_(" Size EntSize Flags Link Info Align\n"));
6188 if (do_section_details)
6189 printf (_(" Flags\n"));
6191 for (i = 0, section = filedata->section_headers;
6192 i < filedata->file_header.e_shnum;
6195 /* Run some sanity checks on the section header. */
6197 /* Check the sh_link field. */
6198 switch (section->sh_type)
6200 case SHT_SYMTAB_SHNDX:
6204 case SHT_GNU_versym:
6207 if (section->sh_link < 1
6208 || section->sh_link >= filedata->file_header.e_shnum
6209 || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB
6210 && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM))
6211 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
6212 i, section->sh_link);
6218 case SHT_GNU_verneed:
6219 case SHT_GNU_verdef:
6220 case SHT_GNU_LIBLIST:
6221 if (section->sh_link < 1
6222 || section->sh_link >= filedata->file_header.e_shnum
6223 || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB)
6224 warn (_("[%2u]: Link field (%u) should index a string section.\n"),
6225 i, section->sh_link);
6228 case SHT_INIT_ARRAY:
6229 case SHT_FINI_ARRAY:
6230 case SHT_PREINIT_ARRAY:
6231 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6232 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6233 i, section->sh_link);
6237 /* FIXME: Add support for target specific section types. */
6238 #if 0 /* Currently we do not check other section types as there are too
6239 many special cases. Stab sections for example have a type
6240 of SHT_PROGBITS but an sh_link field that links to the .stabstr
6242 if (section->sh_type < SHT_LOOS && section->sh_link != 0)
6243 warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
6244 i, section->sh_link);
6249 /* Check the sh_info field. */
6250 switch (section->sh_type)
6254 if (section->sh_info < 1
6255 || section->sh_info >= filedata->file_header.e_shnum
6256 || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS
6257 && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS
6258 && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE
6259 && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
6260 /* FIXME: Are other section types valid ? */
6261 && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS))
6263 if (section->sh_info == 0
6264 && (filedata->file_header.e_type == ET_EXEC
6265 || filedata->file_header.e_type == ET_DYN
6266 /* These next two tests may be redundant, but
6267 they have been left in for paranoia's sake. */
6268 || streq (SECTION_NAME (section), ".rel.dyn")
6269 || streq (SECTION_NAME (section), ".rela.dyn")))
6270 /* Dynamic relocations apply to segments, not sections, so
6271 they do not need an sh_info value. */
6274 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
6275 i, section->sh_info);
6281 case SHT_SYMTAB_SHNDX:
6282 case SHT_INIT_ARRAY:
6283 case SHT_FINI_ARRAY:
6284 case SHT_PREINIT_ARRAY:
6285 if (section->sh_info != 0)
6286 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6287 i, section->sh_info);
6293 /* A symbol index - we assume that it is valid. */
6297 /* FIXME: Add support for target specific section types. */
6298 if (section->sh_type == SHT_NOBITS)
6299 /* NOBITS section headers with non-zero sh_info fields can be
6300 created when a binary is stripped of everything but its debug
6301 information. The stripped sections have their headers
6302 preserved but their types set to SHT_NOBITS. So do not check
6303 this type of section. */
6305 else if (section->sh_flags & SHF_INFO_LINK)
6307 if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum)
6308 warn (_("[%2u]: Expected link to another section in info field"), i);
6310 else if (section->sh_type < SHT_LOOS
6311 && (section->sh_flags & SHF_GNU_MBIND) == 0
6312 && section->sh_info != 0)
6313 warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
6314 i, section->sh_info);
6318 /* Check the sh_size field. */
6319 if (section->sh_size > filedata->file_size
6320 && section->sh_type != SHT_NOBITS
6321 && section->sh_type != SHT_NULL
6322 && section->sh_type < SHT_LOOS)
6323 warn (_("Size of section %u is larger than the entire file!\n"), i);
6325 printf (" [%2u] ", i);
6326 if (do_section_details)
6327 printf ("%s\n ", printable_section_name (filedata, section));
6329 print_symbol (-17, SECTION_NAME (section));
6331 printf (do_wide ? " %-15s " : " %-15.15s ",
6332 get_section_type_name (filedata, section->sh_type));
6336 const char * link_too_big = NULL;
6338 print_vma (section->sh_addr, LONG_HEX);
6340 printf ( " %6.6lx %6.6lx %2.2lx",
6341 (unsigned long) section->sh_offset,
6342 (unsigned long) section->sh_size,
6343 (unsigned long) section->sh_entsize);
6345 if (do_section_details)
6346 fputs (" ", stdout);
6348 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
6350 if (section->sh_link >= filedata->file_header.e_shnum)
6353 /* The sh_link value is out of range. Normally this indicates
6354 an error but it can have special values in Solaris binaries. */
6355 switch (filedata->file_header.e_machine)
6362 case EM_OLD_SPARCV9:
6363 case EM_SPARC32PLUS:
6366 if (section->sh_link == (SHN_BEFORE & 0xffff))
6367 link_too_big = "BEFORE";
6368 else if (section->sh_link == (SHN_AFTER & 0xffff))
6369 link_too_big = "AFTER";
6376 if (do_section_details)
6378 if (link_too_big != NULL && * link_too_big)
6379 printf ("<%s> ", link_too_big);
6381 printf ("%2u ", section->sh_link);
6382 printf ("%3u %2lu\n", section->sh_info,
6383 (unsigned long) section->sh_addralign);
6386 printf ("%2u %3u %2lu\n",
6389 (unsigned long) section->sh_addralign);
6391 if (link_too_big && ! * link_too_big)
6392 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
6393 i, section->sh_link);
6397 print_vma (section->sh_addr, LONG_HEX);
6399 if ((long) section->sh_offset == section->sh_offset)
6400 printf (" %6.6lx", (unsigned long) section->sh_offset);
6404 print_vma (section->sh_offset, LONG_HEX);
6407 if ((unsigned long) section->sh_size == section->sh_size)
6408 printf (" %6.6lx", (unsigned long) section->sh_size);
6412 print_vma (section->sh_size, LONG_HEX);
6415 if ((unsigned long) section->sh_entsize == section->sh_entsize)
6416 printf (" %2.2lx", (unsigned long) section->sh_entsize);
6420 print_vma (section->sh_entsize, LONG_HEX);
6423 if (do_section_details)
6424 fputs (" ", stdout);
6426 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
6428 printf ("%2u %3u ", section->sh_link, section->sh_info);
6430 if ((unsigned long) section->sh_addralign == section->sh_addralign)
6431 printf ("%2lu\n", (unsigned long) section->sh_addralign);
6434 print_vma (section->sh_addralign, DEC);
6438 else if (do_section_details)
6440 printf (" %-15.15s ",
6441 get_section_type_name (filedata, section->sh_type));
6442 print_vma (section->sh_addr, LONG_HEX);
6443 if ((long) section->sh_offset == section->sh_offset)
6444 printf (" %16.16lx", (unsigned long) section->sh_offset);
6448 print_vma (section->sh_offset, LONG_HEX);
6450 printf (" %u\n ", section->sh_link);
6451 print_vma (section->sh_size, LONG_HEX);
6453 print_vma (section->sh_entsize, LONG_HEX);
6455 printf (" %-16u %lu\n",
6457 (unsigned long) section->sh_addralign);
6462 print_vma (section->sh_addr, LONG_HEX);
6463 if ((long) section->sh_offset == section->sh_offset)
6464 printf (" %8.8lx", (unsigned long) section->sh_offset);
6468 print_vma (section->sh_offset, LONG_HEX);
6471 print_vma (section->sh_size, LONG_HEX);
6473 print_vma (section->sh_entsize, LONG_HEX);
6475 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
6477 printf (" %2u %3u %lu\n",
6480 (unsigned long) section->sh_addralign);
6483 if (do_section_details)
6485 printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags));
6486 if ((section->sh_flags & SHF_COMPRESSED) != 0)
6488 /* Minimum section size is 12 bytes for 32-bit compression
6489 header + 12 bytes for compressed data header. */
6490 unsigned char buf[24];
6492 assert (sizeof (buf) >= sizeof (Elf64_External_Chdr));
6493 if (get_data (&buf, filedata, section->sh_offset, 1,
6494 sizeof (buf), _("compression header")))
6496 Elf_Internal_Chdr chdr;
6498 (void) get_compression_header (&chdr, buf, sizeof (buf));
6500 if (chdr.ch_type == ELFCOMPRESS_ZLIB)
6503 printf (_(" [<unknown>: 0x%x], "),
6505 print_vma (chdr.ch_size, LONG_HEX);
6506 printf (", %lu\n", (unsigned long) chdr.ch_addralign);
6512 if (!do_section_details)
6514 /* The ordering of the letters shown here matches the ordering of the
6515 corresponding SHF_xxx values, and hence the order in which these
6516 letters will be displayed to the user. */
6517 printf (_("Key to Flags:\n\
6518 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
6519 L (link order), O (extra OS processing required), G (group), T (TLS),\n\
6520 C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
6521 if (filedata->file_header.e_machine == EM_X86_64
6522 || filedata->file_header.e_machine == EM_L1OM
6523 || filedata->file_header.e_machine == EM_K1OM)
6524 printf (_("l (large), "));
6525 else if (filedata->file_header.e_machine == EM_ARM)
6526 printf (_("y (purecode), "));
6527 else if (filedata->file_header.e_machine == EM_PPC)
6528 printf (_("v (VLE), "));
6529 printf ("p (processor specific)\n");
6536 get_group_flags (unsigned int flags)
6538 static char buff[128];
6542 else if (flags == GRP_COMDAT)
6545 snprintf (buff, 14, _("[0x%x: "), flags);
6547 flags &= ~ GRP_COMDAT;
6548 if (flags & GRP_MASKOS)
6550 strcat (buff, "<OS specific>");
6551 flags &= ~ GRP_MASKOS;
6554 if (flags & GRP_MASKPROC)
6556 strcat (buff, "<PROC specific>");
6557 flags &= ~ GRP_MASKPROC;
6561 strcat (buff, "<unknown>");
6568 process_section_groups (Filedata * filedata)
6570 Elf_Internal_Shdr * section;
6572 struct group * group;
6573 Elf_Internal_Shdr * symtab_sec;
6574 Elf_Internal_Shdr * strtab_sec;
6575 Elf_Internal_Sym * symtab;
6576 unsigned long num_syms;
6580 /* Don't process section groups unless needed. */
6581 if (!do_unwind && !do_section_groups)
6584 if (filedata->file_header.e_shnum == 0)
6586 if (do_section_groups)
6587 printf (_("\nThere are no sections to group in this file.\n"));
6592 if (filedata->section_headers == NULL)
6594 error (_("Section headers are not available!\n"));
6595 /* PR 13622: This can happen with a corrupt ELF header. */
6599 section_headers_groups = (struct group **) calloc (filedata->file_header.e_shnum,
6600 sizeof (struct group *));
6602 if (section_headers_groups == NULL)
6604 error (_("Out of memory reading %u section group headers\n"),
6605 filedata->file_header.e_shnum);
6609 /* Scan the sections for the group section. */
6611 for (i = 0, section = filedata->section_headers;
6612 i < filedata->file_header.e_shnum;
6614 if (section->sh_type == SHT_GROUP)
6617 if (group_count == 0)
6619 if (do_section_groups)
6620 printf (_("\nThere are no section groups in this file.\n"));
6625 section_groups = (struct group *) calloc (group_count, sizeof (struct group));
6627 if (section_groups == NULL)
6629 error (_("Out of memory reading %lu groups\n"),
6630 (unsigned long) group_count);
6640 for (i = 0, section = filedata->section_headers, group = section_groups;
6641 i < filedata->file_header.e_shnum;
6644 if (section->sh_type == SHT_GROUP)
6646 const char * name = printable_section_name (filedata, section);
6647 const char * group_name;
6648 unsigned char * start;
6649 unsigned char * indices;
6650 unsigned int entry, j, size;
6651 Elf_Internal_Shdr * sec;
6652 Elf_Internal_Sym * sym;
6654 /* Get the symbol table. */
6655 if (section->sh_link >= filedata->file_header.e_shnum
6656 || ((sec = filedata->section_headers + section->sh_link)->sh_type
6659 error (_("Bad sh_link in group section `%s'\n"), name);
6663 if (symtab_sec != sec)
6668 symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms);
6673 error (_("Corrupt header in group section `%s'\n"), name);
6677 if (section->sh_info >= num_syms)
6679 error (_("Bad sh_info in group section `%s'\n"), name);
6683 sym = symtab + section->sh_info;
6685 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6687 if (sym->st_shndx == 0
6688 || sym->st_shndx >= filedata->file_header.e_shnum)
6690 error (_("Bad sh_info in group section `%s'\n"), name);
6694 group_name = SECTION_NAME (filedata->section_headers + sym->st_shndx);
6703 /* Get the string table. */
6704 if (symtab_sec->sh_link >= filedata->file_header.e_shnum)
6713 != (sec = filedata->section_headers + symtab_sec->sh_link))
6719 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
6720 1, strtab_sec->sh_size,
6722 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
6724 group_name = sym->st_name < strtab_size
6725 ? strtab + sym->st_name : _("<corrupt>");
6728 /* PR 17531: file: loop. */
6729 if (section->sh_entsize > section->sh_size)
6731 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
6732 printable_section_name (filedata, section),
6733 (unsigned long) section->sh_entsize,
6734 (unsigned long) section->sh_size);
6738 start = (unsigned char *) get_data (NULL, filedata, section->sh_offset,
6739 1, section->sh_size,
6745 size = (section->sh_size / section->sh_entsize) - 1;
6746 entry = byte_get (indices, 4);
6749 if (do_section_groups)
6751 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
6752 get_group_flags (entry), i, name, group_name, size);
6754 printf (_(" [Index] Name\n"));
6757 group->group_index = i;
6759 for (j = 0; j < size; j++)
6761 struct group_list * g;
6763 entry = byte_get (indices, 4);
6766 if (entry >= filedata->file_header.e_shnum)
6768 static unsigned num_group_errors = 0;
6770 if (num_group_errors ++ < 10)
6772 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
6773 entry, i, filedata->file_header.e_shnum - 1);
6774 if (num_group_errors == 10)
6775 warn (_("Further error messages about overlarge group section indicies suppressed\n"));
6780 if (section_headers_groups [entry] != NULL)
6784 static unsigned num_errs = 0;
6786 if (num_errs ++ < 10)
6788 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
6790 section_headers_groups [entry]->group_index);
6792 warn (_("Further error messages about already contained group sections suppressed\n"));
6798 /* Intel C/C++ compiler may put section 0 in a
6799 section group. We just warn it the first time
6800 and ignore it afterwards. */
6801 static bfd_boolean warned = FALSE;
6804 error (_("section 0 in group section [%5u]\n"),
6805 section_headers_groups [entry]->group_index);
6811 section_headers_groups [entry] = group;
6813 if (do_section_groups)
6815 sec = filedata->section_headers + entry;
6816 printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec));
6819 g = (struct group_list *) xmalloc (sizeof (struct group_list));
6820 g->section_index = entry;
6821 g->next = group->root;
6839 /* Data used to display dynamic fixups. */
6841 struct ia64_vms_dynfixup
6843 bfd_vma needed_ident; /* Library ident number. */
6844 bfd_vma needed; /* Index in the dstrtab of the library name. */
6845 bfd_vma fixup_needed; /* Index of the library. */
6846 bfd_vma fixup_rela_cnt; /* Number of fixups. */
6847 bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */
6850 /* Data used to display dynamic relocations. */
6852 struct ia64_vms_dynimgrela
6854 bfd_vma img_rela_cnt; /* Number of relocations. */
6855 bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */
6858 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
6862 dump_ia64_vms_dynamic_fixups (Filedata * filedata,
6863 struct ia64_vms_dynfixup * fixup,
6864 const char * strtab,
6865 unsigned int strtab_sz)
6867 Elf64_External_VMS_IMAGE_FIXUP * imfs;
6869 const char * lib_name;
6871 imfs = get_data (NULL, filedata, dynamic_addr + fixup->fixup_rela_off,
6872 1, fixup->fixup_rela_cnt * sizeof (*imfs),
6873 _("dynamic section image fixups"));
6877 if (fixup->needed < strtab_sz)
6878 lib_name = strtab + fixup->needed;
6881 warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
6882 (unsigned long) fixup->needed);
6885 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
6886 (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
6888 (_("Seg Offset Type SymVec DataType\n"));
6890 for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
6895 printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
6896 printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
6897 type = BYTE_GET (imfs [i].type);
6898 rtype = elf_ia64_reloc_type (type);
6900 printf (" 0x%08x ", type);
6902 printf (" %-32s ", rtype);
6903 printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
6904 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
6911 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
6914 dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela)
6916 Elf64_External_VMS_IMAGE_RELA *imrs;
6919 imrs = get_data (NULL, filedata, dynamic_addr + imgrela->img_rela_off,
6920 1, imgrela->img_rela_cnt * sizeof (*imrs),
6921 _("dynamic section image relocations"));
6925 printf (_("\nImage relocs\n"));
6927 (_("Seg Offset Type Addend Seg Sym Off\n"));
6929 for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
6934 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
6935 printf ("%08" BFD_VMA_FMT "x ",
6936 (bfd_vma) BYTE_GET (imrs [i].rela_offset));
6937 type = BYTE_GET (imrs [i].type);
6938 rtype = elf_ia64_reloc_type (type);
6940 printf ("0x%08x ", type);
6942 printf ("%-31s ", rtype);
6943 print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
6944 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
6945 printf ("%08" BFD_VMA_FMT "x\n",
6946 (bfd_vma) BYTE_GET (imrs [i].sym_offset));
6953 /* Display IA-64 OpenVMS dynamic relocations and fixups. */
6956 process_ia64_vms_dynamic_relocs (Filedata * filedata)
6958 struct ia64_vms_dynfixup fixup;
6959 struct ia64_vms_dynimgrela imgrela;
6960 Elf_Internal_Dyn *entry;
6961 bfd_vma strtab_off = 0;
6962 bfd_vma strtab_sz = 0;
6963 char *strtab = NULL;
6964 bfd_boolean res = TRUE;
6966 memset (&fixup, 0, sizeof (fixup));
6967 memset (&imgrela, 0, sizeof (imgrela));
6969 /* Note: the order of the entries is specified by the OpenVMS specs. */
6970 for (entry = dynamic_section;
6971 entry < dynamic_section + dynamic_nent;
6974 switch (entry->d_tag)
6976 case DT_IA_64_VMS_STRTAB_OFFSET:
6977 strtab_off = entry->d_un.d_val;
6980 strtab_sz = entry->d_un.d_val;
6982 strtab = get_data (NULL, filedata, dynamic_addr + strtab_off,
6983 1, strtab_sz, _("dynamic string section"));
6986 case DT_IA_64_VMS_NEEDED_IDENT:
6987 fixup.needed_ident = entry->d_un.d_val;
6990 fixup.needed = entry->d_un.d_val;
6992 case DT_IA_64_VMS_FIXUP_NEEDED:
6993 fixup.fixup_needed = entry->d_un.d_val;
6995 case DT_IA_64_VMS_FIXUP_RELA_CNT:
6996 fixup.fixup_rela_cnt = entry->d_un.d_val;
6998 case DT_IA_64_VMS_FIXUP_RELA_OFF:
6999 fixup.fixup_rela_off = entry->d_un.d_val;
7000 if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz))
7003 case DT_IA_64_VMS_IMG_RELA_CNT:
7004 imgrela.img_rela_cnt = entry->d_un.d_val;
7006 case DT_IA_64_VMS_IMG_RELA_OFF:
7007 imgrela.img_rela_off = entry->d_un.d_val;
7008 if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela))
7030 dynamic_relocations [] =
7032 { "REL", DT_REL, DT_RELSZ, FALSE },
7033 { "RELA", DT_RELA, DT_RELASZ, TRUE },
7034 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
7037 /* Process the reloc section. */
7040 process_relocs (Filedata * filedata)
7042 unsigned long rel_size;
7043 unsigned long rel_offset;
7048 if (do_using_dynamic)
7052 bfd_boolean has_dynamic_reloc;
7055 has_dynamic_reloc = FALSE;
7057 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
7059 is_rela = dynamic_relocations [i].rela;
7060 name = dynamic_relocations [i].name;
7061 rel_size = dynamic_info [dynamic_relocations [i].size];
7062 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
7065 has_dynamic_reloc = TRUE;
7067 if (is_rela == UNKNOWN)
7069 if (dynamic_relocations [i].reloc == DT_JMPREL)
7070 switch (dynamic_info[DT_PLTREL])
7084 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
7085 name, rel_offset, rel_size);
7087 dump_relocations (filedata,
7088 offset_from_vma (filedata, rel_offset, rel_size),
7090 dynamic_symbols, num_dynamic_syms,
7091 dynamic_strings, dynamic_strings_length,
7092 is_rela, TRUE /* is_dynamic */);
7096 if (is_ia64_vms (filedata))
7097 if (process_ia64_vms_dynamic_relocs (filedata))
7098 has_dynamic_reloc = TRUE;
7100 if (! has_dynamic_reloc)
7101 printf (_("\nThere are no dynamic relocations in this file.\n"));
7105 Elf_Internal_Shdr * section;
7107 bfd_boolean found = FALSE;
7109 for (i = 0, section = filedata->section_headers;
7110 i < filedata->file_header.e_shnum;
7113 if ( section->sh_type != SHT_RELA
7114 && section->sh_type != SHT_REL)
7117 rel_offset = section->sh_offset;
7118 rel_size = section->sh_size;
7122 Elf_Internal_Shdr * strsec;
7124 unsigned long num_rela;
7126 printf (_("\nRelocation section "));
7128 if (filedata->string_table == NULL)
7129 printf ("%d", section->sh_name);
7131 printf ("'%s'", printable_section_name (filedata, section));
7133 num_rela = rel_size / section->sh_entsize;
7134 printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
7135 " at offset 0x%lx contains %lu entries:\n",
7137 rel_offset, num_rela);
7139 is_rela = section->sh_type == SHT_RELA;
7141 if (section->sh_link != 0
7142 && section->sh_link < filedata->file_header.e_shnum)
7144 Elf_Internal_Shdr * symsec;
7145 Elf_Internal_Sym * symtab;
7146 unsigned long nsyms;
7147 unsigned long strtablen = 0;
7148 char * strtab = NULL;
7150 symsec = filedata->section_headers + section->sh_link;
7151 if (symsec->sh_type != SHT_SYMTAB
7152 && symsec->sh_type != SHT_DYNSYM)
7155 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms);
7160 if (symsec->sh_link != 0
7161 && symsec->sh_link < filedata->file_header.e_shnum)
7163 strsec = filedata->section_headers + symsec->sh_link;
7165 strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
7168 strtablen = strtab == NULL ? 0 : strsec->sh_size;
7171 dump_relocations (filedata, rel_offset, rel_size,
7172 symtab, nsyms, strtab, strtablen,
7174 symsec->sh_type == SHT_DYNSYM);
7180 dump_relocations (filedata, rel_offset, rel_size,
7181 NULL, 0, NULL, 0, is_rela,
7182 FALSE /* is_dynamic */);
7190 /* Users sometimes forget the -D option, so try to be helpful. */
7191 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
7193 if (dynamic_info [dynamic_relocations [i].size])
7195 printf (_("\nThere are no static relocations in this file."));
7196 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
7201 if (i == ARRAY_SIZE (dynamic_relocations))
7202 printf (_("\nThere are no relocations in this file.\n"));
7209 /* An absolute address consists of a section and an offset. If the
7210 section is NULL, the offset itself is the address, otherwise, the
7211 address equals to LOAD_ADDRESS(section) + offset. */
7215 unsigned short section;
7219 #define ABSADDR(a) \
7221 ? filedata->section_headers [(a).section].sh_addr + (a).offset \
7224 /* Find the nearest symbol at or below ADDR. Returns the symbol
7225 name, if found, and the offset from the symbol to ADDR. */
7228 find_symbol_for_address (Filedata * filedata,
7229 Elf_Internal_Sym * symtab,
7230 unsigned long nsyms,
7231 const char * strtab,
7232 unsigned long strtab_size,
7233 struct absaddr addr,
7234 const char ** symname,
7237 bfd_vma dist = 0x100000;
7238 Elf_Internal_Sym * sym;
7239 Elf_Internal_Sym * beg;
7240 Elf_Internal_Sym * end;
7241 Elf_Internal_Sym * best = NULL;
7243 REMOVE_ARCH_BITS (addr.offset);
7245 end = symtab + nsyms;
7251 sym = beg + (end - beg) / 2;
7253 value = sym->st_value;
7254 REMOVE_ARCH_BITS (value);
7256 if (sym->st_name != 0
7257 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
7258 && addr.offset >= value
7259 && addr.offset - value < dist)
7262 dist = addr.offset - value;
7267 if (addr.offset < value)
7275 *symname = (best->st_name >= strtab_size
7276 ? _("<corrupt>") : strtab + best->st_name);
7282 *offset = addr.offset;
7285 static /* signed */ int
7286 symcmp (const void *p, const void *q)
7288 Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p;
7289 Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q;
7291 return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
7294 /* Process the unwind section. */
7296 #include "unwind-ia64.h"
7298 struct ia64_unw_table_entry
7300 struct absaddr start;
7302 struct absaddr info;
7305 struct ia64_unw_aux_info
7307 struct ia64_unw_table_entry * table; /* Unwind table. */
7308 unsigned long table_len; /* Length of unwind table. */
7309 unsigned char * info; /* Unwind info. */
7310 unsigned long info_size; /* Size of unwind info. */
7311 bfd_vma info_addr; /* Starting address of unwind info. */
7312 bfd_vma seg_base; /* Starting address of segment. */
7313 Elf_Internal_Sym * symtab; /* The symbol table. */
7314 unsigned long nsyms; /* Number of symbols. */
7315 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
7316 unsigned long nfuns; /* Number of entries in funtab. */
7317 char * strtab; /* The string table. */
7318 unsigned long strtab_size; /* Size of string table. */
7322 dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux)
7324 struct ia64_unw_table_entry * tp;
7325 unsigned long j, nfuns;
7327 bfd_boolean res = TRUE;
7329 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
7330 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
7331 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
7332 aux->funtab[nfuns++] = aux->symtab[j];
7334 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
7336 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
7340 const unsigned char * dp;
7341 const unsigned char * head;
7342 const unsigned char * end;
7343 const char * procname;
7345 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
7346 aux->strtab_size, tp->start, &procname, &offset);
7348 fputs ("\n<", stdout);
7352 fputs (procname, stdout);
7355 printf ("+%lx", (unsigned long) offset);
7358 fputs (">: [", stdout);
7359 print_vma (tp->start.offset, PREFIX_HEX);
7360 fputc ('-', stdout);
7361 print_vma (tp->end.offset, PREFIX_HEX);
7362 printf ("], info at +0x%lx\n",
7363 (unsigned long) (tp->info.offset - aux->seg_base));
7365 /* PR 17531: file: 86232b32. */
7366 if (aux->info == NULL)
7369 /* PR 17531: file: 0997b4d1. */
7370 if ((ABSADDR (tp->info) - aux->info_addr) >= aux->info_size)
7372 warn (_("Invalid offset %lx in table entry %ld\n"),
7373 (long) tp->info.offset, (long) (tp - aux->table));
7378 head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
7379 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
7381 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
7382 (unsigned) UNW_VER (stamp),
7383 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
7384 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
7385 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
7386 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
7388 if (UNW_VER (stamp) != 1)
7390 printf (_("\tUnknown version.\n"));
7395 end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
7396 /* PR 17531: file: 16ceda89. */
7397 if (end > aux->info + aux->info_size)
7398 end = aux->info + aux->info_size;
7399 for (dp = head + 8; dp < end;)
7400 dp = unw_decode (dp, in_body, & in_body, end);
7409 slurp_ia64_unwind_table (Filedata * filedata,
7410 struct ia64_unw_aux_info * aux,
7411 Elf_Internal_Shdr * sec)
7413 unsigned long size, nrelas, i;
7414 Elf_Internal_Phdr * seg;
7415 struct ia64_unw_table_entry * tep;
7416 Elf_Internal_Shdr * relsec;
7417 Elf_Internal_Rela * rela;
7418 Elf_Internal_Rela * rp;
7419 unsigned char * table;
7421 Elf_Internal_Sym * sym;
7422 const char * relname;
7426 /* First, find the starting address of the segment that includes
7429 if (filedata->file_header.e_phnum)
7431 if (! get_program_headers (filedata))
7434 for (seg = filedata->program_headers;
7435 seg < filedata->program_headers + filedata->file_header.e_phnum;
7438 if (seg->p_type != PT_LOAD)
7441 if (sec->sh_addr >= seg->p_vaddr
7442 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
7444 aux->seg_base = seg->p_vaddr;
7450 /* Second, build the unwind table from the contents of the unwind section: */
7451 size = sec->sh_size;
7452 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
7457 aux->table_len = size / (3 * eh_addr_size);
7458 aux->table = (struct ia64_unw_table_entry *)
7459 xcmalloc (aux->table_len, sizeof (aux->table[0]));
7462 for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
7464 tep->start.section = SHN_UNDEF;
7465 tep->end.section = SHN_UNDEF;
7466 tep->info.section = SHN_UNDEF;
7467 tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7468 tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7469 tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
7470 tep->start.offset += aux->seg_base;
7471 tep->end.offset += aux->seg_base;
7472 tep->info.offset += aux->seg_base;
7476 /* Third, apply any relocations to the unwind table: */
7477 for (relsec = filedata->section_headers;
7478 relsec < filedata->section_headers + filedata->file_header.e_shnum;
7481 if (relsec->sh_type != SHT_RELA
7482 || relsec->sh_info >= filedata->file_header.e_shnum
7483 || filedata->section_headers + relsec->sh_info != sec)
7486 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
7495 for (rp = rela; rp < rela + nrelas; ++rp)
7497 relname = elf_ia64_reloc_type (get_reloc_type (filedata, rp->r_info));
7498 sym = aux->symtab + get_reloc_symindex (rp->r_info);
7500 /* PR 17531: file: 9fa67536. */
7501 if (relname == NULL)
7503 warn (_("Skipping unknown relocation type: %u\n"),
7504 get_reloc_type (filedata, rp->r_info));
7508 if (! const_strneq (relname, "R_IA64_SEGREL"))
7510 warn (_("Skipping unexpected relocation type: %s\n"), relname);
7514 i = rp->r_offset / (3 * eh_addr_size);
7516 /* PR 17531: file: 5bc8d9bf. */
7517 if (i >= aux->table_len)
7519 warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
7523 switch (rp->r_offset / eh_addr_size % 3)
7526 aux->table[i].start.section = sym->st_shndx;
7527 aux->table[i].start.offset = rp->r_addend + sym->st_value;
7530 aux->table[i].end.section = sym->st_shndx;
7531 aux->table[i].end.offset = rp->r_addend + sym->st_value;
7534 aux->table[i].info.section = sym->st_shndx;
7535 aux->table[i].info.offset = rp->r_addend + sym->st_value;
7549 ia64_process_unwind (Filedata * filedata)
7551 Elf_Internal_Shdr * sec;
7552 Elf_Internal_Shdr * unwsec = NULL;
7553 Elf_Internal_Shdr * strsec;
7554 unsigned long i, unwcount = 0, unwstart = 0;
7555 struct ia64_unw_aux_info aux;
7556 bfd_boolean res = TRUE;
7558 memset (& aux, 0, sizeof (aux));
7560 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
7562 if (sec->sh_type == SHT_SYMTAB
7563 && sec->sh_link < filedata->file_header.e_shnum)
7565 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
7567 strsec = filedata->section_headers + sec->sh_link;
7568 if (aux.strtab != NULL)
7570 error (_("Multiple auxillary string tables encountered\n"));
7574 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
7577 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
7579 else if (sec->sh_type == SHT_IA_64_UNWIND)
7584 printf (_("\nThere are no unwind sections in this file.\n"));
7586 while (unwcount-- > 0)
7591 for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL;
7592 i < filedata->file_header.e_shnum; ++i, ++sec)
7593 if (sec->sh_type == SHT_IA_64_UNWIND)
7598 /* We have already counted the number of SHT_IA64_UNWIND
7599 sections so the loop above should never fail. */
7600 assert (unwsec != NULL);
7603 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
7605 if ((unwsec->sh_flags & SHF_GROUP) != 0)
7607 /* We need to find which section group it is in. */
7608 struct group_list * g;
7610 if (section_headers_groups == NULL
7611 || section_headers_groups [i] == NULL)
7612 i = filedata->file_header.e_shnum;
7615 g = section_headers_groups [i]->root;
7617 for (; g != NULL; g = g->next)
7619 sec = filedata->section_headers + g->section_index;
7621 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
7626 i = filedata->file_header.e_shnum;
7629 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
7631 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
7632 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
7633 suffix = SECTION_NAME (unwsec) + len;
7634 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum;
7636 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
7637 && streq (SECTION_NAME (sec) + len2, suffix))
7642 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
7643 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
7644 len = sizeof (ELF_STRING_ia64_unwind) - 1;
7645 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
7647 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
7648 suffix = SECTION_NAME (unwsec) + len;
7649 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum;
7651 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
7652 && streq (SECTION_NAME (sec) + len2, suffix))
7656 if (i == filedata->file_header.e_shnum)
7658 printf (_("\nCould not find unwind info section for "));
7660 if (filedata->string_table == NULL)
7661 printf ("%d", unwsec->sh_name);
7663 printf ("'%s'", printable_section_name (filedata, unwsec));
7667 aux.info_addr = sec->sh_addr;
7668 aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1,
7671 aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
7673 printf (_("\nUnwind section "));
7675 if (filedata->string_table == NULL)
7676 printf ("%d", unwsec->sh_name);
7678 printf ("'%s'", printable_section_name (filedata, unwsec));
7680 printf (_(" at offset 0x%lx contains %lu entries:\n"),
7681 (unsigned long) unwsec->sh_offset,
7682 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
7684 if (slurp_ia64_unwind_table (filedata, & aux, unwsec)
7685 && aux.table_len > 0)
7686 dump_ia64_unwind (filedata, & aux);
7689 free ((char *) aux.table);
7691 free ((char *) aux.info);
7700 free ((char *) aux.strtab);
7705 struct hppa_unw_table_entry
7707 struct absaddr start;
7709 unsigned int Cannot_unwind:1; /* 0 */
7710 unsigned int Millicode:1; /* 1 */
7711 unsigned int Millicode_save_sr0:1; /* 2 */
7712 unsigned int Region_description:2; /* 3..4 */
7713 unsigned int reserved1:1; /* 5 */
7714 unsigned int Entry_SR:1; /* 6 */
7715 unsigned int Entry_FR:4; /* Number saved 7..10 */
7716 unsigned int Entry_GR:5; /* Number saved 11..15 */
7717 unsigned int Args_stored:1; /* 16 */
7718 unsigned int Variable_Frame:1; /* 17 */
7719 unsigned int Separate_Package_Body:1; /* 18 */
7720 unsigned int Frame_Extension_Millicode:1; /* 19 */
7721 unsigned int Stack_Overflow_Check:1; /* 20 */
7722 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
7723 unsigned int Ada_Region:1; /* 22 */
7724 unsigned int cxx_info:1; /* 23 */
7725 unsigned int cxx_try_catch:1; /* 24 */
7726 unsigned int sched_entry_seq:1; /* 25 */
7727 unsigned int reserved2:1; /* 26 */
7728 unsigned int Save_SP:1; /* 27 */
7729 unsigned int Save_RP:1; /* 28 */
7730 unsigned int Save_MRP_in_frame:1; /* 29 */
7731 unsigned int extn_ptr_defined:1; /* 30 */
7732 unsigned int Cleanup_defined:1; /* 31 */
7734 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
7735 unsigned int HP_UX_interrupt_marker:1; /* 1 */
7736 unsigned int Large_frame:1; /* 2 */
7737 unsigned int Pseudo_SP_Set:1; /* 3 */
7738 unsigned int reserved4:1; /* 4 */
7739 unsigned int Total_frame_size:27; /* 5..31 */
7742 struct hppa_unw_aux_info
7744 struct hppa_unw_table_entry * table; /* Unwind table. */
7745 unsigned long table_len; /* Length of unwind table. */
7746 bfd_vma seg_base; /* Starting address of segment. */
7747 Elf_Internal_Sym * symtab; /* The symbol table. */
7748 unsigned long nsyms; /* Number of symbols. */
7749 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
7750 unsigned long nfuns; /* Number of entries in funtab. */
7751 char * strtab; /* The string table. */
7752 unsigned long strtab_size; /* Size of string table. */
7756 dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux)
7758 struct hppa_unw_table_entry * tp;
7759 unsigned long j, nfuns;
7760 bfd_boolean res = TRUE;
7762 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
7763 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
7764 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
7765 aux->funtab[nfuns++] = aux->symtab[j];
7767 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
7769 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
7772 const char * procname;
7774 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
7775 aux->strtab_size, tp->start, &procname,
7778 fputs ("\n<", stdout);
7782 fputs (procname, stdout);
7785 printf ("+%lx", (unsigned long) offset);
7788 fputs (">: [", stdout);
7789 print_vma (tp->start.offset, PREFIX_HEX);
7790 fputc ('-', stdout);
7791 print_vma (tp->end.offset, PREFIX_HEX);
7794 #define PF(_m) if (tp->_m) printf (#_m " ");
7795 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
7798 PF(Millicode_save_sr0);
7799 /* PV(Region_description); */
7805 PF(Separate_Package_Body);
7806 PF(Frame_Extension_Millicode);
7807 PF(Stack_Overflow_Check);
7808 PF(Two_Instruction_SP_Increment);
7812 PF(sched_entry_seq);
7815 PF(Save_MRP_in_frame);
7816 PF(extn_ptr_defined);
7817 PF(Cleanup_defined);
7818 PF(MPE_XL_interrupt_marker);
7819 PF(HP_UX_interrupt_marker);
7822 PV(Total_frame_size);
7835 slurp_hppa_unwind_table (Filedata * filedata,
7836 struct hppa_unw_aux_info * aux,
7837 Elf_Internal_Shdr * sec)
7839 unsigned long size, unw_ent_size, nentries, nrelas, i;
7840 Elf_Internal_Phdr * seg;
7841 struct hppa_unw_table_entry * tep;
7842 Elf_Internal_Shdr * relsec;
7843 Elf_Internal_Rela * rela;
7844 Elf_Internal_Rela * rp;
7845 unsigned char * table;
7847 Elf_Internal_Sym * sym;
7848 const char * relname;
7850 /* First, find the starting address of the segment that includes
7852 if (filedata->file_header.e_phnum)
7854 if (! get_program_headers (filedata))
7857 for (seg = filedata->program_headers;
7858 seg < filedata->program_headers + filedata->file_header.e_phnum;
7861 if (seg->p_type != PT_LOAD)
7864 if (sec->sh_addr >= seg->p_vaddr
7865 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
7867 aux->seg_base = seg->p_vaddr;
7873 /* Second, build the unwind table from the contents of the unwind
7875 size = sec->sh_size;
7876 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
7882 nentries = size / unw_ent_size;
7883 size = unw_ent_size * nentries;
7885 tep = aux->table = (struct hppa_unw_table_entry *)
7886 xcmalloc (nentries, sizeof (aux->table[0]));
7888 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
7890 unsigned int tmp1, tmp2;
7892 tep->start.section = SHN_UNDEF;
7893 tep->end.section = SHN_UNDEF;
7895 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
7896 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
7897 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
7898 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
7900 tep->start.offset += aux->seg_base;
7901 tep->end.offset += aux->seg_base;
7903 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
7904 tep->Millicode = (tmp1 >> 30) & 0x1;
7905 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
7906 tep->Region_description = (tmp1 >> 27) & 0x3;
7907 tep->reserved1 = (tmp1 >> 26) & 0x1;
7908 tep->Entry_SR = (tmp1 >> 25) & 0x1;
7909 tep->Entry_FR = (tmp1 >> 21) & 0xf;
7910 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
7911 tep->Args_stored = (tmp1 >> 15) & 0x1;
7912 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
7913 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
7914 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
7915 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
7916 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
7917 tep->Ada_Region = (tmp1 >> 9) & 0x1;
7918 tep->cxx_info = (tmp1 >> 8) & 0x1;
7919 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
7920 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
7921 tep->reserved2 = (tmp1 >> 5) & 0x1;
7922 tep->Save_SP = (tmp1 >> 4) & 0x1;
7923 tep->Save_RP = (tmp1 >> 3) & 0x1;
7924 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
7925 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
7926 tep->Cleanup_defined = tmp1 & 0x1;
7928 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
7929 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
7930 tep->Large_frame = (tmp2 >> 29) & 0x1;
7931 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
7932 tep->reserved4 = (tmp2 >> 27) & 0x1;
7933 tep->Total_frame_size = tmp2 & 0x7ffffff;
7937 /* Third, apply any relocations to the unwind table. */
7938 for (relsec = filedata->section_headers;
7939 relsec < filedata->section_headers + filedata->file_header.e_shnum;
7942 if (relsec->sh_type != SHT_RELA
7943 || relsec->sh_info >= filedata->file_header.e_shnum
7944 || filedata->section_headers + relsec->sh_info != sec)
7947 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
7951 for (rp = rela; rp < rela + nrelas; ++rp)
7953 relname = elf_hppa_reloc_type (get_reloc_type (filedata, rp->r_info));
7954 sym = aux->symtab + get_reloc_symindex (rp->r_info);
7956 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
7957 if (! const_strneq (relname, "R_PARISC_SEGREL"))
7959 warn (_("Skipping unexpected relocation type %s\n"), relname);
7963 i = rp->r_offset / unw_ent_size;
7965 switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
7968 aux->table[i].start.section = sym->st_shndx;
7969 aux->table[i].start.offset = sym->st_value + rp->r_addend;
7972 aux->table[i].end.section = sym->st_shndx;
7973 aux->table[i].end.offset = sym->st_value + rp->r_addend;
7983 aux->table_len = nentries;
7989 hppa_process_unwind (Filedata * filedata)
7991 struct hppa_unw_aux_info aux;
7992 Elf_Internal_Shdr * unwsec = NULL;
7993 Elf_Internal_Shdr * strsec;
7994 Elf_Internal_Shdr * sec;
7996 bfd_boolean res = TRUE;
7998 if (filedata->string_table == NULL)
8001 memset (& aux, 0, sizeof (aux));
8003 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
8005 if (sec->sh_type == SHT_SYMTAB
8006 && sec->sh_link < filedata->file_header.e_shnum)
8008 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
8010 strsec = filedata->section_headers + sec->sh_link;
8011 if (aux.strtab != NULL)
8013 error (_("Multiple auxillary string tables encountered\n"));
8017 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
8020 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
8022 else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
8027 printf (_("\nThere are no unwind sections in this file.\n"));
8029 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
8031 if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
8033 unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size + 8);
8035 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
8036 "contains %lu entry:\n",
8037 "\nUnwind section '%s' at offset 0x%lx "
8038 "contains %lu entries:\n",
8040 printable_section_name (filedata, sec),
8041 (unsigned long) sec->sh_offset,
8044 if (! slurp_hppa_unwind_table (filedata, &aux, sec))
8047 if (aux.table_len > 0)
8049 if (! dump_hppa_unwind (filedata, &aux))
8054 free ((char *) aux.table);
8062 free ((char *) aux.strtab);
8069 unsigned char * data; /* The unwind data. */
8070 Elf_Internal_Shdr * sec; /* The cached unwind section header. */
8071 Elf_Internal_Rela * rela; /* The cached relocations for this section. */
8072 unsigned long nrelas; /* The number of relocations. */
8073 unsigned int rel_type; /* REL or RELA ? */
8074 Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */
8077 struct arm_unw_aux_info
8079 Filedata * filedata; /* The file containing the unwind sections. */
8080 Elf_Internal_Sym * symtab; /* The file's symbol table. */
8081 unsigned long nsyms; /* Number of symbols. */
8082 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
8083 unsigned long nfuns; /* Number of these symbols. */
8084 char * strtab; /* The file's string table. */
8085 unsigned long strtab_size; /* Size of string table. */
8089 arm_print_vma_and_name (Filedata * filedata,
8090 struct arm_unw_aux_info * aux,
8092 struct absaddr addr)
8094 const char *procname;
8097 if (addr.section == SHN_UNDEF)
8100 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
8101 aux->strtab_size, addr, &procname,
8104 print_vma (fn, PREFIX_HEX);
8108 fputs (" <", stdout);
8109 fputs (procname, stdout);
8112 printf ("+0x%lx", (unsigned long) sym_offset);
8113 fputc ('>', stdout);
8120 arm_free_section (struct arm_section *arm_sec)
8122 if (arm_sec->data != NULL)
8123 free (arm_sec->data);
8125 if (arm_sec->rela != NULL)
8126 free (arm_sec->rela);
8129 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
8130 cached section and install SEC instead.
8131 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
8132 and return its valued in * WORDP, relocating if necessary.
8133 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
8134 relocation's offset in ADDR.
8135 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
8136 into the string table of the symbol associated with the reloc. If no
8137 reloc was applied store -1 there.
8138 5) Return TRUE upon success, FALSE otherwise. */
8141 get_unwind_section_word (Filedata * filedata,
8142 struct arm_unw_aux_info * aux,
8143 struct arm_section * arm_sec,
8144 Elf_Internal_Shdr * sec,
8145 bfd_vma word_offset,
8146 unsigned int * wordp,
8147 struct absaddr * addr,
8150 Elf_Internal_Rela *rp;
8151 Elf_Internal_Sym *sym;
8152 const char * relname;
8154 bfd_boolean wrapped;
8156 if (sec == NULL || arm_sec == NULL)
8159 addr->section = SHN_UNDEF;
8162 if (sym_name != NULL)
8163 *sym_name = (bfd_vma) -1;
8165 /* If necessary, update the section cache. */
8166 if (sec != arm_sec->sec)
8168 Elf_Internal_Shdr *relsec;
8170 arm_free_section (arm_sec);
8173 arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1,
8174 sec->sh_size, _("unwind data"));
8175 arm_sec->rela = NULL;
8176 arm_sec->nrelas = 0;
8178 for (relsec = filedata->section_headers;
8179 relsec < filedata->section_headers + filedata->file_header.e_shnum;
8182 if (relsec->sh_info >= filedata->file_header.e_shnum
8183 || filedata->section_headers + relsec->sh_info != sec
8184 /* PR 15745: Check the section type as well. */
8185 || (relsec->sh_type != SHT_REL
8186 && relsec->sh_type != SHT_RELA))
8189 arm_sec->rel_type = relsec->sh_type;
8190 if (relsec->sh_type == SHT_REL)
8192 if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset,
8194 & arm_sec->rela, & arm_sec->nrelas))
8197 else /* relsec->sh_type == SHT_RELA */
8199 if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset,
8201 & arm_sec->rela, & arm_sec->nrelas))
8207 arm_sec->next_rela = arm_sec->rela;
8210 /* If there is no unwind data we can do nothing. */
8211 if (arm_sec->data == NULL)
8214 /* If the offset is invalid then fail. */
8215 if (/* PR 21343 *//* PR 18879 */
8217 || word_offset > (sec->sh_size - 4)
8218 || ((bfd_signed_vma) word_offset) < 0)
8221 /* Get the word at the required offset. */
8222 word = byte_get (arm_sec->data + word_offset, 4);
8224 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
8225 if (arm_sec->rela == NULL)
8231 /* Look through the relocs to find the one that applies to the provided offset. */
8233 for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
8235 bfd_vma prelval, offset;
8237 if (rp->r_offset > word_offset && !wrapped)
8242 if (rp->r_offset > word_offset)
8245 if (rp->r_offset & 3)
8247 warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
8248 (unsigned long) rp->r_offset);
8252 if (rp->r_offset < word_offset)
8255 /* PR 17531: file: 027-161405-0.004 */
8256 if (aux->symtab == NULL)
8259 if (arm_sec->rel_type == SHT_REL)
8261 offset = word & 0x7fffffff;
8262 if (offset & 0x40000000)
8263 offset |= ~ (bfd_vma) 0x7fffffff;
8265 else if (arm_sec->rel_type == SHT_RELA)
8266 offset = rp->r_addend;
8269 error (_("Unknown section relocation type %d encountered\n"),
8274 /* PR 17531 file: 027-1241568-0.004. */
8275 if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
8277 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
8278 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
8282 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
8283 offset += sym->st_value;
8284 prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
8286 /* Check that we are processing the expected reloc type. */
8287 if (filedata->file_header.e_machine == EM_ARM)
8289 relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
8290 if (relname == NULL)
8292 warn (_("Skipping unknown ARM relocation type: %d\n"),
8293 (int) ELF32_R_TYPE (rp->r_info));
8297 if (streq (relname, "R_ARM_NONE"))
8300 if (! streq (relname, "R_ARM_PREL31"))
8302 warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
8306 else if (filedata->file_header.e_machine == EM_TI_C6000)
8308 relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
8309 if (relname == NULL)
8311 warn (_("Skipping unknown C6000 relocation type: %d\n"),
8312 (int) ELF32_R_TYPE (rp->r_info));
8316 if (streq (relname, "R_C6000_NONE"))
8319 if (! streq (relname, "R_C6000_PREL31"))
8321 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
8329 /* This function currently only supports ARM and TI unwinders. */
8330 warn (_("Only TI and ARM unwinders are currently supported\n"));
8334 word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
8335 addr->section = sym->st_shndx;
8336 addr->offset = offset;
8339 * sym_name = sym->st_name;
8344 arm_sec->next_rela = rp;
8349 static const char *tic6x_unwind_regnames[16] =
8351 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
8352 "A14", "A13", "A12", "A11", "A10",
8353 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
8357 decode_tic6x_unwind_regmask (unsigned int mask)
8361 for (i = 12; mask; mask >>= 1, i--)
8365 fputs (tic6x_unwind_regnames[i], stdout);
8367 fputs (", ", stdout);
8373 if (remaining == 0 && more_words) \
8376 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
8377 data_offset, & word, & addr, NULL)) \
8383 #define GET_OP(OP) \
8388 (OP) = word >> 24; \
8393 printf (_("[Truncated opcode]\n")); \
8396 printf ("0x%02x ", OP)
8399 decode_arm_unwind_bytecode (Filedata * filedata,
8400 struct arm_unw_aux_info * aux,
8402 unsigned int remaining,
8403 unsigned int more_words,
8404 bfd_vma data_offset,
8405 Elf_Internal_Shdr * data_sec,
8406 struct arm_section * data_arm_sec)
8408 struct absaddr addr;
8409 bfd_boolean res = TRUE;
8411 /* Decode the unwinding instructions. */
8414 unsigned int op, op2;
8423 printf (" 0x%02x ", op);
8425 if ((op & 0xc0) == 0x00)
8427 int offset = ((op & 0x3f) << 2) + 4;
8429 printf (" vsp = vsp + %d", offset);
8431 else if ((op & 0xc0) == 0x40)
8433 int offset = ((op & 0x3f) << 2) + 4;
8435 printf (" vsp = vsp - %d", offset);
8437 else if ((op & 0xf0) == 0x80)
8440 if (op == 0x80 && op2 == 0)
8441 printf (_("Refuse to unwind"));
8444 unsigned int mask = ((op & 0x0f) << 8) | op2;
8445 bfd_boolean first = TRUE;
8449 for (i = 0; i < 12; i++)
8450 if (mask & (1 << i))
8456 printf ("r%d", 4 + i);
8461 else if ((op & 0xf0) == 0x90)
8463 if (op == 0x9d || op == 0x9f)
8464 printf (_(" [Reserved]"));
8466 printf (" vsp = r%d", op & 0x0f);
8468 else if ((op & 0xf0) == 0xa0)
8470 int end = 4 + (op & 0x07);
8471 bfd_boolean first = TRUE;
8475 for (i = 4; i <= end; i++)
8491 else if (op == 0xb0)
8492 printf (_(" finish"));
8493 else if (op == 0xb1)
8496 if (op2 == 0 || (op2 & 0xf0) != 0)
8497 printf (_("[Spare]"));
8500 unsigned int mask = op2 & 0x0f;
8501 bfd_boolean first = TRUE;
8505 for (i = 0; i < 12; i++)
8506 if (mask & (1 << i))
8517 else if (op == 0xb2)
8519 unsigned char buf[9];
8520 unsigned int i, len;
8521 unsigned long offset;
8523 for (i = 0; i < sizeof (buf); i++)
8526 if ((buf[i] & 0x80) == 0)
8529 if (i == sizeof (buf))
8531 error (_("corrupt change to vsp"));
8536 offset = read_uleb128 (buf, &len, buf + i + 1);
8537 assert (len == i + 1);
8538 offset = offset * 4 + 0x204;
8539 printf ("vsp = vsp + %ld", offset);
8542 else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
8544 unsigned int first, last;
8551 printf ("pop {D%d", first);
8553 printf ("-D%d", first + last);
8556 else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
8558 unsigned int count = op & 0x07;
8562 printf ("-D%d", 8 + count);
8565 else if (op >= 0xc0 && op <= 0xc5)
8567 unsigned int count = op & 0x07;
8569 printf (" pop {wR10");
8571 printf ("-wR%d", 10 + count);
8574 else if (op == 0xc6)
8576 unsigned int first, last;
8581 printf ("pop {wR%d", first);
8583 printf ("-wR%d", first + last);
8586 else if (op == 0xc7)
8589 if (op2 == 0 || (op2 & 0xf0) != 0)
8590 printf (_("[Spare]"));
8593 unsigned int mask = op2 & 0x0f;
8594 bfd_boolean first = TRUE;
8598 for (i = 0; i < 4; i++)
8599 if (mask & (1 << i))
8605 printf ("wCGR%d", i);
8612 printf (_(" [unsupported opcode]"));
8623 decode_tic6x_unwind_bytecode (Filedata * filedata,
8624 struct arm_unw_aux_info * aux,
8626 unsigned int remaining,
8627 unsigned int more_words,
8628 bfd_vma data_offset,
8629 Elf_Internal_Shdr * data_sec,
8630 struct arm_section * data_arm_sec)
8632 struct absaddr addr;
8634 /* Decode the unwinding instructions. */
8637 unsigned int op, op2;
8646 printf (" 0x%02x ", op);
8648 if ((op & 0xc0) == 0x00)
8650 int offset = ((op & 0x3f) << 3) + 8;
8651 printf (" sp = sp + %d", offset);
8653 else if ((op & 0xc0) == 0x80)
8656 if (op == 0x80 && op2 == 0)
8657 printf (_("Refuse to unwind"));
8660 unsigned int mask = ((op & 0x1f) << 8) | op2;
8662 printf ("pop compact {");
8666 decode_tic6x_unwind_regmask (mask);
8670 else if ((op & 0xf0) == 0xc0)
8678 unsigned int offset;
8682 /* Scan entire instruction first so that GET_OP output is not
8683 interleaved with disassembly. */
8685 for (i = 0; nregs < (op & 0xf); i++)
8691 regpos[nregs].offset = i * 2;
8692 regpos[nregs].reg = reg;
8699 regpos[nregs].offset = i * 2 + 1;
8700 regpos[nregs].reg = reg;
8705 printf (_("pop frame {"));
8707 for (i = i * 2; i > 0; i--)
8709 if (regpos[reg].offset == i - 1)
8711 name = tic6x_unwind_regnames[regpos[reg].reg];
8718 fputs (name, stdout);
8725 else if (op == 0xd0)
8726 printf (" MOV FP, SP");
8727 else if (op == 0xd1)
8728 printf (" __c6xabi_pop_rts");
8729 else if (op == 0xd2)
8731 unsigned char buf[9];
8732 unsigned int i, len;
8733 unsigned long offset;
8735 for (i = 0; i < sizeof (buf); i++)
8738 if ((buf[i] & 0x80) == 0)
8741 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
8742 if (i == sizeof (buf))
8744 warn (_("Corrupt stack pointer adjustment detected\n"));
8748 offset = read_uleb128 (buf, &len, buf + i + 1);
8749 assert (len == i + 1);
8750 offset = offset * 8 + 0x408;
8751 printf (_("sp = sp + %ld"), offset);
8753 else if ((op & 0xf0) == 0xe0)
8755 if ((op & 0x0f) == 7)
8758 printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
8762 printf (_(" [unsupported opcode]"));
8771 arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where)
8775 offset = word & 0x7fffffff;
8776 if (offset & 0x40000000)
8777 offset |= ~ (bfd_vma) 0x7fffffff;
8779 if (filedata->file_header.e_machine == EM_TI_C6000)
8782 return offset + where;
8786 decode_arm_unwind (Filedata * filedata,
8787 struct arm_unw_aux_info * aux,
8789 unsigned int remaining,
8790 bfd_vma data_offset,
8791 Elf_Internal_Shdr * data_sec,
8792 struct arm_section * data_arm_sec)
8795 unsigned int more_words = 0;
8796 struct absaddr addr;
8797 bfd_vma sym_name = (bfd_vma) -1;
8798 bfd_boolean res = TRUE;
8802 /* Fetch the first word.
8803 Note - when decoding an object file the address extracted
8804 here will always be 0. So we also pass in the sym_name
8805 parameter so that we can find the symbol associated with
8806 the personality routine. */
8807 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset,
8808 & word, & addr, & sym_name))
8814 if ((word & 0x80000000) == 0)
8816 /* Expand prel31 for personality routine. */
8818 const char *procname;
8820 fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset);
8821 printf (_(" Personality routine: "));
8823 && addr.section == SHN_UNDEF && addr.offset == 0
8824 && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
8826 procname = aux->strtab + sym_name;
8827 print_vma (fn, PREFIX_HEX);
8830 fputs (" <", stdout);
8831 fputs (procname, stdout);
8832 fputc ('>', stdout);
8836 procname = arm_print_vma_and_name (filedata, aux, fn, addr);
8837 fputc ('\n', stdout);
8839 /* The GCC personality routines use the standard compact
8840 encoding, starting with one byte giving the number of
8842 if (procname != NULL
8843 && (const_strneq (procname, "__gcc_personality_v0")
8844 || const_strneq (procname, "__gxx_personality_v0")
8845 || const_strneq (procname, "__gcj_personality_v0")
8846 || const_strneq (procname, "__gnu_objc_personality_v0")))
8853 printf (_(" [Truncated data]\n"));
8856 more_words = word >> 24;
8866 /* ARM EHABI Section 6.3:
8868 An exception-handling table entry for the compact model looks like:
8872 1 0 index Data for personalityRoutine[index] */
8874 if (filedata->file_header.e_machine == EM_ARM
8875 && (word & 0x70000000))
8877 warn (_("Corrupt ARM compact model table entry: %x \n"), word);
8881 per_index = (word >> 24) & 0x7f;
8882 printf (_(" Compact model index: %d\n"), per_index);
8889 else if (per_index < 3)
8891 more_words = (word >> 16) & 0xff;
8897 switch (filedata->file_header.e_machine)
8902 if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words,
8903 data_offset, data_sec, data_arm_sec))
8908 warn (_("Unknown ARM compact model index encountered\n"));
8909 printf (_(" [reserved]\n"));
8917 if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words,
8918 data_offset, data_sec, data_arm_sec))
8921 else if (per_index < 5)
8923 if (((word >> 17) & 0x7f) == 0x7f)
8924 printf (_(" Restore stack from frame pointer\n"));
8926 printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc);
8927 printf (_(" Registers restored: "));
8929 printf (" (compact) ");
8930 decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
8932 printf (_(" Return register: %s\n"),
8933 tic6x_unwind_regnames[word & 0xf]);
8936 printf (_(" [reserved (%d)]\n"), per_index);
8940 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
8941 filedata->file_header.e_machine);
8945 /* Decode the descriptors. Not implemented. */
8951 dump_arm_unwind (Filedata * filedata,
8952 struct arm_unw_aux_info * aux,
8953 Elf_Internal_Shdr * exidx_sec)
8955 struct arm_section exidx_arm_sec, extab_arm_sec;
8956 unsigned int i, exidx_len;
8957 unsigned long j, nfuns;
8958 bfd_boolean res = TRUE;
8960 memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
8961 memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
8962 exidx_len = exidx_sec->sh_size / 8;
8964 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
8965 for (nfuns = 0, j = 0; j < aux->nsyms; j++)
8966 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
8967 aux->funtab[nfuns++] = aux->symtab[j];
8969 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
8971 for (i = 0; i < exidx_len; i++)
8973 unsigned int exidx_fn, exidx_entry;
8974 struct absaddr fn_addr, entry_addr;
8977 fputc ('\n', stdout);
8979 if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
8980 8 * i, & exidx_fn, & fn_addr, NULL)
8981 || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
8982 8 * i + 4, & exidx_entry, & entry_addr, NULL))
8985 arm_free_section (& exidx_arm_sec);
8986 arm_free_section (& extab_arm_sec);
8990 /* ARM EHABI, Section 5:
8991 An index table entry consists of 2 words.
8992 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
8993 if (exidx_fn & 0x80000000)
8995 warn (_("corrupt index table entry: %x\n"), exidx_fn);
8999 fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i);
9001 arm_print_vma_and_name (filedata, aux, fn, fn_addr);
9002 fputs (": ", stdout);
9004 if (exidx_entry == 1)
9006 print_vma (exidx_entry, PREFIX_HEX);
9007 fputs (" [cantunwind]\n", stdout);
9009 else if (exidx_entry & 0x80000000)
9011 print_vma (exidx_entry, PREFIX_HEX);
9012 fputc ('\n', stdout);
9013 decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL);
9017 bfd_vma table, table_offset = 0;
9018 Elf_Internal_Shdr *table_sec;
9020 fputs ("@", stdout);
9021 table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
9022 print_vma (table, PREFIX_HEX);
9025 /* Locate the matching .ARM.extab. */
9026 if (entry_addr.section != SHN_UNDEF
9027 && entry_addr.section < filedata->file_header.e_shnum)
9029 table_sec = filedata->section_headers + entry_addr.section;
9030 table_offset = entry_addr.offset;
9032 if (table_offset > table_sec->sh_size
9033 || ((bfd_signed_vma) table_offset) < 0)
9035 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
9036 (unsigned long) table_offset,
9037 printable_section_name (filedata, table_sec));
9044 table_sec = find_section_by_address (filedata, table);
9045 if (table_sec != NULL)
9046 table_offset = table - table_sec->sh_addr;
9049 if (table_sec == NULL)
9051 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
9052 (unsigned long) table);
9057 if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec,
9066 arm_free_section (&exidx_arm_sec);
9067 arm_free_section (&extab_arm_sec);
9072 /* Used for both ARM and C6X unwinding tables. */
9075 arm_process_unwind (Filedata * filedata)
9077 struct arm_unw_aux_info aux;
9078 Elf_Internal_Shdr *unwsec = NULL;
9079 Elf_Internal_Shdr *strsec;
9080 Elf_Internal_Shdr *sec;
9082 unsigned int sec_type;
9083 bfd_boolean res = TRUE;
9085 switch (filedata->file_header.e_machine)
9088 sec_type = SHT_ARM_EXIDX;
9092 sec_type = SHT_C6000_UNWIND;
9096 error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
9097 filedata->file_header.e_machine);
9101 if (filedata->string_table == NULL)
9104 memset (& aux, 0, sizeof (aux));
9105 aux.filedata = filedata;
9107 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
9109 if (sec->sh_type == SHT_SYMTAB && sec->sh_link < filedata->file_header.e_shnum)
9111 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms);
9113 strsec = filedata->section_headers + sec->sh_link;
9115 /* PR binutils/17531 file: 011-12666-0.004. */
9116 if (aux.strtab != NULL)
9118 error (_("Multiple string tables found in file.\n"));
9122 aux.strtab = get_data (NULL, filedata, strsec->sh_offset,
9123 1, strsec->sh_size, _("string table"));
9124 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
9126 else if (sec->sh_type == sec_type)
9131 printf (_("\nThere are no unwind sections in this file.\n"));
9133 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
9135 if (sec->sh_type == sec_type)
9137 unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size);
9138 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
9139 "contains %lu entry:\n",
9140 "\nUnwind section '%s' at offset 0x%lx "
9141 "contains %lu entries:\n",
9143 printable_section_name (filedata, sec),
9144 (unsigned long) sec->sh_offset,
9147 if (! dump_arm_unwind (filedata, &aux, sec))
9155 free ((char *) aux.strtab);
9161 process_unwind (Filedata * filedata)
9163 struct unwind_handler
9165 unsigned int machtype;
9166 bfd_boolean (* handler)(Filedata *);
9169 { EM_ARM, arm_process_unwind },
9170 { EM_IA_64, ia64_process_unwind },
9171 { EM_PARISC, hppa_process_unwind },
9172 { EM_TI_C6000, arm_process_unwind },
9180 for (i = 0; handlers[i].handler != NULL; i++)
9181 if (filedata->file_header.e_machine == handlers[i].machtype)
9182 return handlers[i].handler (filedata);
9184 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
9185 get_machine_name (filedata->file_header.e_machine));
9190 dynamic_section_mips_val (Elf_Internal_Dyn * entry)
9192 switch (entry->d_tag)
9195 if (entry->d_un.d_val == 0)
9199 static const char * opts[] =
9201 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
9202 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
9203 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
9204 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
9208 bfd_boolean first = TRUE;
9210 for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
9211 if (entry->d_un.d_val & (1 << cnt))
9213 printf ("%s%s", first ? "" : " ", opts[cnt]);
9219 case DT_MIPS_IVERSION:
9220 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
9221 printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
9225 sprintf_vma (buf, entry->d_un.d_ptr);
9226 /* Note: coded this way so that there is a single string for translation. */
9227 printf (_("<corrupt: %s>"), buf);
9231 case DT_MIPS_TIME_STAMP:
9235 time_t atime = entry->d_un.d_val;
9237 tmp = gmtime (&atime);
9238 /* PR 17531: file: 6accc532. */
9240 snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
9242 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
9243 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9244 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
9245 printf (_("Time Stamp: %s"), timebuf);
9249 case DT_MIPS_RLD_VERSION:
9250 case DT_MIPS_LOCAL_GOTNO:
9251 case DT_MIPS_CONFLICTNO:
9252 case DT_MIPS_LIBLISTNO:
9253 case DT_MIPS_SYMTABNO:
9254 case DT_MIPS_UNREFEXTNO:
9255 case DT_MIPS_HIPAGENO:
9256 case DT_MIPS_DELTA_CLASS_NO:
9257 case DT_MIPS_DELTA_INSTANCE_NO:
9258 case DT_MIPS_DELTA_RELOC_NO:
9259 case DT_MIPS_DELTA_SYM_NO:
9260 case DT_MIPS_DELTA_CLASSSYM_NO:
9261 case DT_MIPS_COMPACT_SIZE:
9262 print_vma (entry->d_un.d_val, DEC);
9266 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9272 dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
9274 switch (entry->d_tag)
9276 case DT_HP_DLD_FLAGS:
9285 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
9286 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
9287 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
9288 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
9289 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
9290 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
9291 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
9292 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
9293 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
9294 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
9295 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
9296 { DT_HP_GST, "HP_GST" },
9297 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
9298 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
9299 { DT_HP_NODELETE, "HP_NODELETE" },
9300 { DT_HP_GROUP, "HP_GROUP" },
9301 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
9303 bfd_boolean first = TRUE;
9305 bfd_vma val = entry->d_un.d_val;
9307 for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
9308 if (val & flags[cnt].bit)
9312 fputs (flags[cnt].str, stdout);
9314 val ^= flags[cnt].bit;
9317 if (val != 0 || first)
9321 print_vma (val, HEX);
9327 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9335 /* VMS vs Unix time offset and factor. */
9337 #define VMS_EPOCH_OFFSET 35067168000000000LL
9338 #define VMS_GRANULARITY_FACTOR 10000000
9340 /* Display a VMS time in a human readable format. */
9343 print_vms_time (bfd_int64_t vmstime)
9348 unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
9349 tm = gmtime (&unxtime);
9350 printf ("%04u-%02u-%02uT%02u:%02u:%02u",
9351 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
9352 tm->tm_hour, tm->tm_min, tm->tm_sec);
9357 dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
9359 switch (entry->d_tag)
9361 case DT_IA_64_PLT_RESERVE:
9362 /* First 3 slots reserved. */
9363 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9365 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
9368 case DT_IA_64_VMS_LINKTIME:
9370 print_vms_time (entry->d_un.d_val);
9374 case DT_IA_64_VMS_LNKFLAGS:
9375 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9376 if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
9377 printf (" CALL_DEBUG");
9378 if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
9379 printf (" NOP0BUFS");
9380 if (entry->d_un.d_val & VMS_LF_P0IMAGE)
9381 printf (" P0IMAGE");
9382 if (entry->d_un.d_val & VMS_LF_MKTHREADS)
9383 printf (" MKTHREADS");
9384 if (entry->d_un.d_val & VMS_LF_UPCALLS)
9385 printf (" UPCALLS");
9386 if (entry->d_un.d_val & VMS_LF_IMGSTA)
9388 if (entry->d_un.d_val & VMS_LF_INITIALIZE)
9389 printf (" INITIALIZE");
9390 if (entry->d_un.d_val & VMS_LF_MAIN)
9392 if (entry->d_un.d_val & VMS_LF_EXE_INIT)
9393 printf (" EXE_INIT");
9394 if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
9395 printf (" TBK_IN_IMG");
9396 if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
9397 printf (" DBG_IN_IMG");
9398 if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
9399 printf (" TBK_IN_DSF");
9400 if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
9401 printf (" DBG_IN_DSF");
9402 if (entry->d_un.d_val & VMS_LF_SIGNATURES)
9403 printf (" SIGNATURES");
9404 if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
9405 printf (" REL_SEG_OFF");
9409 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
9416 get_32bit_dynamic_section (Filedata * filedata)
9418 Elf32_External_Dyn * edyn;
9419 Elf32_External_Dyn * ext;
9420 Elf_Internal_Dyn * entry;
9422 edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1,
9423 dynamic_size, _("dynamic section"));
9427 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9428 might not have the luxury of section headers. Look for the DT_NULL
9429 terminator to determine the number of entries. */
9430 for (ext = edyn, dynamic_nent = 0;
9431 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
9435 if (BYTE_GET (ext->d_tag) == DT_NULL)
9439 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
9441 if (dynamic_section == NULL)
9443 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9444 (unsigned long) dynamic_nent);
9449 for (ext = edyn, entry = dynamic_section;
9450 entry < dynamic_section + dynamic_nent;
9453 entry->d_tag = BYTE_GET (ext->d_tag);
9454 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
9463 get_64bit_dynamic_section (Filedata * filedata)
9465 Elf64_External_Dyn * edyn;
9466 Elf64_External_Dyn * ext;
9467 Elf_Internal_Dyn * entry;
9469 /* Read in the data. */
9470 edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1,
9471 dynamic_size, _("dynamic section"));
9475 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
9476 might not have the luxury of section headers. Look for the DT_NULL
9477 terminator to determine the number of entries. */
9478 for (ext = edyn, dynamic_nent = 0;
9479 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
9480 (char *) (ext + 1) <= (char *) edyn + dynamic_size;
9484 if (BYTE_GET (ext->d_tag) == DT_NULL)
9488 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
9490 if (dynamic_section == NULL)
9492 error (_("Out of memory allocating space for %lu dynamic entries\n"),
9493 (unsigned long) dynamic_nent);
9498 /* Convert from external to internal formats. */
9499 for (ext = edyn, entry = dynamic_section;
9500 entry < dynamic_section + dynamic_nent;
9503 entry->d_tag = BYTE_GET (ext->d_tag);
9504 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
9513 print_dynamic_flags (bfd_vma flags)
9515 bfd_boolean first = TRUE;
9521 flag = flags & - flags;
9531 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
9532 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
9533 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
9534 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
9535 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
9536 default: fputs (_("unknown"), stdout); break;
9542 /* Parse and display the contents of the dynamic section. */
9545 process_dynamic_section (Filedata * filedata)
9547 Elf_Internal_Dyn * entry;
9549 if (dynamic_size == 0)
9552 printf (_("\nThere is no dynamic section in this file.\n"));
9559 if (! get_32bit_dynamic_section (filedata))
9564 if (! get_64bit_dynamic_section (filedata))
9568 /* Find the appropriate symbol table. */
9569 if (dynamic_symbols == NULL)
9571 for (entry = dynamic_section;
9572 entry < dynamic_section + dynamic_nent;
9575 Elf_Internal_Shdr section;
9577 if (entry->d_tag != DT_SYMTAB)
9580 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
9582 /* Since we do not know how big the symbol table is,
9583 we default to reading in the entire file (!) and
9584 processing that. This is overkill, I know, but it
9586 section.sh_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
9587 if ((bfd_size_type) section.sh_offset > filedata->file_size)
9589 /* See PR 21379 for a reproducer. */
9590 error (_("Invalid DT_SYMTAB entry: %lx"), (long) section.sh_offset);
9594 if (archive_file_offset != 0)
9595 section.sh_size = archive_file_size - section.sh_offset;
9597 section.sh_size = filedata->file_size - section.sh_offset;
9600 section.sh_entsize = sizeof (Elf32_External_Sym);
9602 section.sh_entsize = sizeof (Elf64_External_Sym);
9603 section.sh_name = filedata->string_table_length;
9605 dynamic_symbols = GET_ELF_SYMBOLS (filedata, §ion, & num_dynamic_syms);
9606 if (num_dynamic_syms < 1)
9608 error (_("Unable to determine the number of symbols to load\n"));
9614 /* Similarly find a string table. */
9615 if (dynamic_strings == NULL)
9617 for (entry = dynamic_section;
9618 entry < dynamic_section + dynamic_nent;
9621 unsigned long offset;
9624 if (entry->d_tag != DT_STRTAB)
9627 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
9629 /* Since we do not know how big the string table is,
9630 we default to reading in the entire file (!) and
9631 processing that. This is overkill, I know, but it
9634 offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
9636 if (archive_file_offset != 0)
9637 str_tab_len = archive_file_size - offset;
9639 str_tab_len = filedata->file_size - offset;
9641 if (str_tab_len < 1)
9644 (_("Unable to determine the length of the dynamic string table\n"));
9648 dynamic_strings = (char *) get_data (NULL, filedata, offset, 1,
9650 _("dynamic string table"));
9651 dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
9656 /* And find the syminfo section if available. */
9657 if (dynamic_syminfo == NULL)
9659 unsigned long syminsz = 0;
9661 for (entry = dynamic_section;
9662 entry < dynamic_section + dynamic_nent;
9665 if (entry->d_tag == DT_SYMINENT)
9667 /* Note: these braces are necessary to avoid a syntax
9668 error from the SunOS4 C compiler. */
9669 /* PR binutils/17531: A corrupt file can trigger this test.
9670 So do not use an assert, instead generate an error message. */
9671 if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
9672 error (_("Bad value (%d) for SYMINENT entry\n"),
9673 (int) entry->d_un.d_val);
9675 else if (entry->d_tag == DT_SYMINSZ)
9676 syminsz = entry->d_un.d_val;
9677 else if (entry->d_tag == DT_SYMINFO)
9678 dynamic_syminfo_offset = offset_from_vma (filedata, entry->d_un.d_val,
9682 if (dynamic_syminfo_offset != 0 && syminsz != 0)
9684 Elf_External_Syminfo * extsyminfo;
9685 Elf_External_Syminfo * extsym;
9686 Elf_Internal_Syminfo * syminfo;
9688 /* There is a syminfo section. Read the data. */
9689 extsyminfo = (Elf_External_Syminfo *)
9690 get_data (NULL, filedata, dynamic_syminfo_offset, 1, syminsz,
9691 _("symbol information"));
9695 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
9696 if (dynamic_syminfo == NULL)
9698 error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
9699 (unsigned long) syminsz);
9703 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
9704 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
9705 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
9706 ++syminfo, ++extsym)
9708 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
9709 syminfo->si_flags = BYTE_GET (extsym->si_flags);
9716 if (do_dynamic && dynamic_addr)
9717 printf (ngettext ("\nDynamic section at offset 0x%lx "
9718 "contains %lu entry:\n",
9719 "\nDynamic section at offset 0x%lx "
9720 "contains %lu entries:\n",
9722 dynamic_addr, (unsigned long) dynamic_nent);
9724 printf (_(" Tag Type Name/Value\n"));
9726 for (entry = dynamic_section;
9727 entry < dynamic_section + dynamic_nent;
9735 print_vma (entry->d_tag, FULL_HEX);
9736 dtype = get_dynamic_type (filedata, entry->d_tag);
9737 printf (" (%s)%*s", dtype,
9738 ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " ");
9741 switch (entry->d_tag)
9745 print_dynamic_flags (entry->d_un.d_val);
9755 switch (entry->d_tag)
9758 printf (_("Auxiliary library"));
9762 printf (_("Filter library"));
9766 printf (_("Configuration file"));
9770 printf (_("Dependency audit library"));
9774 printf (_("Audit library"));
9778 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
9779 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
9783 print_vma (entry->d_un.d_val, PREFIX_HEX);
9792 printf (_("Flags:"));
9794 if (entry->d_un.d_val == 0)
9795 printf (_(" None\n"));
9798 unsigned long int val = entry->d_un.d_val;
9800 if (val & DTF_1_PARINIT)
9802 printf (" PARINIT");
9803 val ^= DTF_1_PARINIT;
9805 if (val & DTF_1_CONFEXP)
9807 printf (" CONFEXP");
9808 val ^= DTF_1_CONFEXP;
9811 printf (" %lx", val);
9820 printf (_("Flags:"));
9822 if (entry->d_un.d_val == 0)
9823 printf (_(" None\n"));
9826 unsigned long int val = entry->d_un.d_val;
9828 if (val & DF_P1_LAZYLOAD)
9830 printf (" LAZYLOAD");
9831 val ^= DF_P1_LAZYLOAD;
9833 if (val & DF_P1_GROUPPERM)
9835 printf (" GROUPPERM");
9836 val ^= DF_P1_GROUPPERM;
9839 printf (" %lx", val);
9848 printf (_("Flags:"));
9849 if (entry->d_un.d_val == 0)
9850 printf (_(" None\n"));
9853 unsigned long int val = entry->d_un.d_val;
9860 if (val & DF_1_GLOBAL)
9865 if (val & DF_1_GROUP)
9870 if (val & DF_1_NODELETE)
9872 printf (" NODELETE");
9873 val ^= DF_1_NODELETE;
9875 if (val & DF_1_LOADFLTR)
9877 printf (" LOADFLTR");
9878 val ^= DF_1_LOADFLTR;
9880 if (val & DF_1_INITFIRST)
9882 printf (" INITFIRST");
9883 val ^= DF_1_INITFIRST;
9885 if (val & DF_1_NOOPEN)
9890 if (val & DF_1_ORIGIN)
9895 if (val & DF_1_DIRECT)
9900 if (val & DF_1_TRANS)
9905 if (val & DF_1_INTERPOSE)
9907 printf (" INTERPOSE");
9908 val ^= DF_1_INTERPOSE;
9910 if (val & DF_1_NODEFLIB)
9912 printf (" NODEFLIB");
9913 val ^= DF_1_NODEFLIB;
9915 if (val & DF_1_NODUMP)
9920 if (val & DF_1_CONFALT)
9922 printf (" CONFALT");
9923 val ^= DF_1_CONFALT;
9925 if (val & DF_1_ENDFILTEE)
9927 printf (" ENDFILTEE");
9928 val ^= DF_1_ENDFILTEE;
9930 if (val & DF_1_DISPRELDNE)
9932 printf (" DISPRELDNE");
9933 val ^= DF_1_DISPRELDNE;
9935 if (val & DF_1_DISPRELPND)
9937 printf (" DISPRELPND");
9938 val ^= DF_1_DISPRELPND;
9940 if (val & DF_1_NODIRECT)
9942 printf (" NODIRECT");
9943 val ^= DF_1_NODIRECT;
9945 if (val & DF_1_IGNMULDEF)
9947 printf (" IGNMULDEF");
9948 val ^= DF_1_IGNMULDEF;
9950 if (val & DF_1_NOKSYMS)
9952 printf (" NOKSYMS");
9953 val ^= DF_1_NOKSYMS;
9955 if (val & DF_1_NOHDR)
9960 if (val & DF_1_EDITED)
9965 if (val & DF_1_NORELOC)
9967 printf (" NORELOC");
9968 val ^= DF_1_NORELOC;
9970 if (val & DF_1_SYMINTPOSE)
9972 printf (" SYMINTPOSE");
9973 val ^= DF_1_SYMINTPOSE;
9975 if (val & DF_1_GLOBAUDIT)
9977 printf (" GLOBAUDIT");
9978 val ^= DF_1_GLOBAUDIT;
9980 if (val & DF_1_SINGLETON)
9982 printf (" SINGLETON");
9983 val ^= DF_1_SINGLETON;
9985 if (val & DF_1_STUB)
9995 if (val & DF_1_KMOD)
10000 if (val & DF_1_WEAKFILTER)
10002 printf (" WEAKFILTER");
10003 val ^= DF_1_WEAKFILTER;
10005 if (val & DF_1_NOCOMMON)
10007 printf (" NOCOMMON");
10008 val ^= DF_1_NOCOMMON;
10011 printf (" %lx", val);
10018 dynamic_info[entry->d_tag] = entry->d_un.d_val;
10020 puts (get_dynamic_type (filedata, entry->d_un.d_val));
10040 dynamic_info[entry->d_tag] = entry->d_un.d_val;
10046 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
10047 name = GET_DYNAMIC_NAME (entry->d_un.d_val);
10053 switch (entry->d_tag)
10056 printf (_("Shared library: [%s]"), name);
10058 if (streq (name, program_interpreter))
10059 printf (_(" program interpreter"));
10063 printf (_("Library soname: [%s]"), name);
10067 printf (_("Library rpath: [%s]"), name);
10071 printf (_("Library runpath: [%s]"), name);
10075 print_vma (entry->d_un.d_val, PREFIX_HEX);
10080 print_vma (entry->d_un.d_val, PREFIX_HEX);
10093 dynamic_info[entry->d_tag] = entry->d_un.d_val;
10094 /* Fall through. */
10098 case DT_INIT_ARRAYSZ:
10099 case DT_FINI_ARRAYSZ:
10100 case DT_GNU_CONFLICTSZ:
10101 case DT_GNU_LIBLISTSZ:
10104 print_vma (entry->d_un.d_val, UNSIGNED);
10105 printf (_(" (bytes)\n"));
10110 case DT_VERNEEDNUM:
10115 print_vma (entry->d_un.d_val, UNSIGNED);
10124 case DT_INIT_ARRAY:
10125 case DT_FINI_ARRAY:
10128 if (entry->d_tag == DT_USED
10129 && VALID_DYNAMIC_NAME (entry->d_un.d_val))
10131 char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
10135 printf (_("Not needed object: [%s]\n"), name);
10140 print_vma (entry->d_un.d_val, PREFIX_HEX);
10146 /* The value of this entry is ignored. */
10151 case DT_GNU_PRELINKED:
10155 time_t atime = entry->d_un.d_val;
10157 tmp = gmtime (&atime);
10158 /* PR 17533 file: 041-1244816-0.004. */
10160 printf (_("<corrupt time val: %lx"),
10161 (unsigned long) atime);
10163 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
10164 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
10165 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
10171 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
10174 print_vma (entry->d_un.d_val, PREFIX_HEX);
10180 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
10181 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
10186 switch (filedata->file_header.e_machine)
10189 case EM_MIPS_RS3_LE:
10190 dynamic_section_mips_val (entry);
10193 dynamic_section_parisc_val (entry);
10196 dynamic_section_ia64_val (entry);
10199 print_vma (entry->d_un.d_val, PREFIX_HEX);
10211 get_ver_flags (unsigned int flags)
10213 static char buff[128];
10220 if (flags & VER_FLG_BASE)
10221 strcat (buff, "BASE");
10223 if (flags & VER_FLG_WEAK)
10225 if (flags & VER_FLG_BASE)
10226 strcat (buff, " | ");
10228 strcat (buff, "WEAK");
10231 if (flags & VER_FLG_INFO)
10233 if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
10234 strcat (buff, " | ");
10236 strcat (buff, "INFO");
10239 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
10241 if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
10242 strcat (buff, " | ");
10244 strcat (buff, _("<unknown>"));
10250 /* Display the contents of the version sections. */
10253 process_version_sections (Filedata * filedata)
10255 Elf_Internal_Shdr * section;
10257 bfd_boolean found = FALSE;
10262 for (i = 0, section = filedata->section_headers;
10263 i < filedata->file_header.e_shnum;
10266 switch (section->sh_type)
10268 case SHT_GNU_verdef:
10270 Elf_External_Verdef * edefs;
10277 printf (ngettext ("\nVersion definition section '%s' "
10278 "contains %u entry:\n",
10279 "\nVersion definition section '%s' "
10280 "contains %u entries:\n",
10282 printable_section_name (filedata, section),
10285 printf (_(" Addr: 0x"));
10286 printf_vma (section->sh_addr);
10287 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10288 (unsigned long) section->sh_offset, section->sh_link,
10289 printable_section_name_from_index (filedata, section->sh_link));
10291 edefs = (Elf_External_Verdef *)
10292 get_data (NULL, filedata, section->sh_offset, 1,section->sh_size,
10293 _("version definition section"));
10296 endbuf = (char *) edefs + section->sh_size;
10298 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
10301 Elf_External_Verdef * edef;
10302 Elf_Internal_Verdef ent;
10303 Elf_External_Verdaux * eaux;
10304 Elf_Internal_Verdaux aux;
10305 unsigned long isum;
10308 vstart = ((char *) edefs) + idx;
10309 if (vstart + sizeof (*edef) > endbuf)
10312 edef = (Elf_External_Verdef *) vstart;
10314 ent.vd_version = BYTE_GET (edef->vd_version);
10315 ent.vd_flags = BYTE_GET (edef->vd_flags);
10316 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
10317 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
10318 ent.vd_hash = BYTE_GET (edef->vd_hash);
10319 ent.vd_aux = BYTE_GET (edef->vd_aux);
10320 ent.vd_next = BYTE_GET (edef->vd_next);
10322 printf (_(" %#06lx: Rev: %d Flags: %s"),
10323 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
10325 printf (_(" Index: %d Cnt: %d "),
10326 ent.vd_ndx, ent.vd_cnt);
10328 /* Check for overflow. */
10329 if (ent.vd_aux > (size_t) (endbuf - vstart))
10332 vstart += ent.vd_aux;
10334 if (vstart + sizeof (*eaux) > endbuf)
10336 eaux = (Elf_External_Verdaux *) vstart;
10338 aux.vda_name = BYTE_GET (eaux->vda_name);
10339 aux.vda_next = BYTE_GET (eaux->vda_next);
10341 if (VALID_DYNAMIC_NAME (aux.vda_name))
10342 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
10344 printf (_("Name index: %ld\n"), aux.vda_name);
10346 isum = idx + ent.vd_aux;
10348 for (j = 1; j < ent.vd_cnt; j++)
10350 if (aux.vda_next < sizeof (*eaux)
10351 && !(j == ent.vd_cnt - 1 && aux.vda_next == 0))
10353 warn (_("Invalid vda_next field of %lx\n"),
10358 /* Check for overflow. */
10359 if (aux.vda_next > (size_t) (endbuf - vstart))
10362 isum += aux.vda_next;
10363 vstart += aux.vda_next;
10365 if (vstart + sizeof (*eaux) > endbuf)
10367 eaux = (Elf_External_Verdaux *) vstart;
10369 aux.vda_name = BYTE_GET (eaux->vda_name);
10370 aux.vda_next = BYTE_GET (eaux->vda_next);
10372 if (VALID_DYNAMIC_NAME (aux.vda_name))
10373 printf (_(" %#06lx: Parent %d: %s\n"),
10374 isum, j, GET_DYNAMIC_NAME (aux.vda_name));
10376 printf (_(" %#06lx: Parent %d, name index: %ld\n"),
10377 isum, j, aux.vda_name);
10380 if (j < ent.vd_cnt)
10381 printf (_(" Version def aux past end of section\n"));
10384 file: id:000001,src:000172+005151,op:splice,rep:2. */
10385 if (ent.vd_next < sizeof (*edef)
10386 && !(cnt == section->sh_info - 1 && ent.vd_next == 0))
10388 warn (_("Invalid vd_next field of %lx\n"), ent.vd_next);
10389 cnt = section->sh_info;
10392 if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx)))
10395 idx += ent.vd_next;
10398 if (cnt < section->sh_info)
10399 printf (_(" Version definition past end of section\n"));
10405 case SHT_GNU_verneed:
10407 Elf_External_Verneed * eneed;
10414 printf (ngettext ("\nVersion needs section '%s' "
10415 "contains %u entry:\n",
10416 "\nVersion needs section '%s' "
10417 "contains %u entries:\n",
10419 printable_section_name (filedata, section), section->sh_info);
10421 printf (_(" Addr: 0x"));
10422 printf_vma (section->sh_addr);
10423 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10424 (unsigned long) section->sh_offset, section->sh_link,
10425 printable_section_name_from_index (filedata, section->sh_link));
10427 eneed = (Elf_External_Verneed *) get_data (NULL, filedata,
10428 section->sh_offset, 1,
10430 _("Version Needs section"));
10433 endbuf = (char *) eneed + section->sh_size;
10435 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
10437 Elf_External_Verneed * entry;
10438 Elf_Internal_Verneed ent;
10439 unsigned long isum;
10443 vstart = ((char *) eneed) + idx;
10444 if (vstart + sizeof (*entry) > endbuf)
10447 entry = (Elf_External_Verneed *) vstart;
10449 ent.vn_version = BYTE_GET (entry->vn_version);
10450 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
10451 ent.vn_file = BYTE_GET (entry->vn_file);
10452 ent.vn_aux = BYTE_GET (entry->vn_aux);
10453 ent.vn_next = BYTE_GET (entry->vn_next);
10455 printf (_(" %#06lx: Version: %d"), idx, ent.vn_version);
10457 if (VALID_DYNAMIC_NAME (ent.vn_file))
10458 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
10460 printf (_(" File: %lx"), ent.vn_file);
10462 printf (_(" Cnt: %d\n"), ent.vn_cnt);
10464 /* Check for overflow. */
10465 if (ent.vn_aux > (size_t) (endbuf - vstart))
10467 vstart += ent.vn_aux;
10469 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
10471 Elf_External_Vernaux * eaux;
10472 Elf_Internal_Vernaux aux;
10474 if (vstart + sizeof (*eaux) > endbuf)
10476 eaux = (Elf_External_Vernaux *) vstart;
10478 aux.vna_hash = BYTE_GET (eaux->vna_hash);
10479 aux.vna_flags = BYTE_GET (eaux->vna_flags);
10480 aux.vna_other = BYTE_GET (eaux->vna_other);
10481 aux.vna_name = BYTE_GET (eaux->vna_name);
10482 aux.vna_next = BYTE_GET (eaux->vna_next);
10484 if (VALID_DYNAMIC_NAME (aux.vna_name))
10485 printf (_(" %#06lx: Name: %s"),
10486 isum, GET_DYNAMIC_NAME (aux.vna_name));
10488 printf (_(" %#06lx: Name index: %lx"),
10489 isum, aux.vna_name);
10491 printf (_(" Flags: %s Version: %d\n"),
10492 get_ver_flags (aux.vna_flags), aux.vna_other);
10494 if (aux.vna_next < sizeof (*eaux)
10495 && !(j == ent.vn_cnt - 1 && aux.vna_next == 0))
10497 warn (_("Invalid vna_next field of %lx\n"),
10502 /* Check for overflow. */
10503 if (aux.vna_next > (size_t) (endbuf - vstart))
10505 isum += aux.vna_next;
10506 vstart += aux.vna_next;
10509 if (j < ent.vn_cnt)
10510 warn (_("Missing Version Needs auxillary information\n"));
10512 if (ent.vn_next < sizeof (*entry)
10513 && !(cnt == section->sh_info - 1 && ent.vn_next == 0))
10515 warn (_("Invalid vn_next field of %lx\n"), ent.vn_next);
10516 cnt = section->sh_info;
10519 if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx)))
10521 idx += ent.vn_next;
10524 if (cnt < section->sh_info)
10525 warn (_("Missing Version Needs information\n"));
10531 case SHT_GNU_versym:
10533 Elf_Internal_Shdr * link_section;
10536 unsigned char * edata;
10537 unsigned short * data;
10539 Elf_Internal_Sym * symbols;
10540 Elf_Internal_Shdr * string_sec;
10541 unsigned long num_syms;
10544 if (section->sh_link >= filedata->file_header.e_shnum)
10547 link_section = filedata->section_headers + section->sh_link;
10548 total = section->sh_size / sizeof (Elf_External_Versym);
10550 if (link_section->sh_link >= filedata->file_header.e_shnum)
10555 symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms);
10556 if (symbols == NULL)
10559 string_sec = filedata->section_headers + link_section->sh_link;
10561 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
10562 string_sec->sh_size,
10563 _("version string table"));
10570 printf (ngettext ("\nVersion symbols section '%s' "
10571 "contains %lu entry:\n",
10572 "\nVersion symbols section '%s' "
10573 "contains %lu entries:\n",
10575 printable_section_name (filedata, section), (unsigned long) total);
10577 printf (_(" Addr: "));
10578 printf_vma (section->sh_addr);
10579 printf (_(" Offset: %#08lx Link: %u (%s)\n"),
10580 (unsigned long) section->sh_offset, section->sh_link,
10581 printable_section_name (filedata, link_section));
10583 off = offset_from_vma (filedata,
10584 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
10585 total * sizeof (short));
10586 edata = (unsigned char *) get_data (NULL, filedata, off, total,
10588 _("version symbol data"));
10596 data = (short unsigned int *) cmalloc (total, sizeof (short));
10598 for (cnt = total; cnt --;)
10599 data[cnt] = byte_get (edata + cnt * sizeof (short),
10604 for (cnt = 0; cnt < total; cnt += 4)
10608 char *invalid = _("*invalid*");
10610 printf (" %03x:", cnt);
10612 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
10613 switch (data[cnt + j])
10616 fputs (_(" 0 (*local*) "), stdout);
10620 fputs (_(" 1 (*global*) "), stdout);
10624 nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
10625 data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
10627 /* If this index value is greater than the size of the symbols
10628 array, break to avoid an out-of-bounds read. */
10629 if ((unsigned long)(cnt + j) >= num_syms)
10631 warn (_("invalid index into symbol array\n"));
10636 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
10638 Elf_Internal_Verneed ivn;
10639 unsigned long offset;
10641 offset = offset_from_vma
10642 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
10643 sizeof (Elf_External_Verneed));
10647 Elf_Internal_Vernaux ivna;
10648 Elf_External_Verneed evn;
10649 Elf_External_Vernaux evna;
10650 unsigned long a_off;
10652 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
10653 _("version need")) == NULL)
10656 ivn.vn_aux = BYTE_GET (evn.vn_aux);
10657 ivn.vn_next = BYTE_GET (evn.vn_next);
10659 a_off = offset + ivn.vn_aux;
10663 if (get_data (&evna, filedata, a_off, sizeof (evna),
10664 1, _("version need aux (2)")) == NULL)
10667 ivna.vna_other = 0;
10671 ivna.vna_next = BYTE_GET (evna.vna_next);
10672 ivna.vna_other = BYTE_GET (evna.vna_other);
10675 a_off += ivna.vna_next;
10677 while (ivna.vna_other != data[cnt + j]
10678 && ivna.vna_next != 0);
10680 if (ivna.vna_other == data[cnt + j])
10682 ivna.vna_name = BYTE_GET (evna.vna_name);
10684 if (ivna.vna_name >= string_sec->sh_size)
10687 name = strtab + ivna.vna_name;
10691 offset += ivn.vn_next;
10693 while (ivn.vn_next);
10696 if (data[cnt + j] != 0x8001
10697 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
10699 Elf_Internal_Verdef ivd;
10700 Elf_External_Verdef evd;
10701 unsigned long offset;
10703 offset = offset_from_vma
10704 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
10709 if (get_data (&evd, filedata, offset, sizeof (evd), 1,
10710 _("version def")) == NULL)
10713 /* PR 17531: file: 046-1082287-0.004. */
10714 ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1;
10719 ivd.vd_next = BYTE_GET (evd.vd_next);
10720 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
10723 offset += ivd.vd_next;
10725 while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
10726 && ivd.vd_next != 0);
10728 if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
10730 Elf_External_Verdaux evda;
10731 Elf_Internal_Verdaux ivda;
10733 ivd.vd_aux = BYTE_GET (evd.vd_aux);
10735 if (get_data (&evda, filedata,
10736 offset - ivd.vd_next + ivd.vd_aux,
10738 _("version def aux")) == NULL)
10741 ivda.vda_name = BYTE_GET (evda.vda_name);
10743 if (ivda.vda_name >= string_sec->sh_size)
10745 else if (name != NULL && name != invalid)
10746 name = _("*both*");
10748 name = strtab + ivda.vda_name;
10752 nn += printf ("(%s%-*s",
10754 12 - (int) strlen (name),
10758 printf ("%*c", 18 - nn, ' ');
10776 printf (_("\nNo version information found in this file.\n"));
10781 static const char *
10782 get_symbol_binding (Filedata * filedata, unsigned int binding)
10784 static char buff[32];
10788 case STB_LOCAL: return "LOCAL";
10789 case STB_GLOBAL: return "GLOBAL";
10790 case STB_WEAK: return "WEAK";
10792 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
10793 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
10795 else if (binding >= STB_LOOS && binding <= STB_HIOS)
10797 if (binding == STB_GNU_UNIQUE
10798 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
10799 /* GNU is still using the default value 0. */
10800 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
10802 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
10805 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
10810 static const char *
10811 get_symbol_type (Filedata * filedata, unsigned int type)
10813 static char buff[32];
10817 case STT_NOTYPE: return "NOTYPE";
10818 case STT_OBJECT: return "OBJECT";
10819 case STT_FUNC: return "FUNC";
10820 case STT_SECTION: return "SECTION";
10821 case STT_FILE: return "FILE";
10822 case STT_COMMON: return "COMMON";
10823 case STT_TLS: return "TLS";
10824 case STT_RELC: return "RELC";
10825 case STT_SRELC: return "SRELC";
10827 if (type >= STT_LOPROC && type <= STT_HIPROC)
10829 if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
10830 return "THUMB_FUNC";
10832 if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
10835 if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
10836 return "PARISC_MILLI";
10838 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
10840 else if (type >= STT_LOOS && type <= STT_HIOS)
10842 if (filedata->file_header.e_machine == EM_PARISC)
10844 if (type == STT_HP_OPAQUE)
10845 return "HP_OPAQUE";
10846 if (type == STT_HP_STUB)
10850 if (type == STT_GNU_IFUNC
10851 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
10852 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD
10853 /* GNU is still using the default value 0. */
10854 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
10857 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
10860 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
10865 static const char *
10866 get_symbol_visibility (unsigned int visibility)
10868 switch (visibility)
10870 case STV_DEFAULT: return "DEFAULT";
10871 case STV_INTERNAL: return "INTERNAL";
10872 case STV_HIDDEN: return "HIDDEN";
10873 case STV_PROTECTED: return "PROTECTED";
10875 error (_("Unrecognized visibility value: %u"), visibility);
10876 return _("<unknown>");
10880 static const char *
10881 get_solaris_symbol_visibility (unsigned int visibility)
10883 switch (visibility)
10885 case 4: return "EXPORTED";
10886 case 5: return "SINGLETON";
10887 case 6: return "ELIMINATE";
10888 default: return get_symbol_visibility (visibility);
10892 static const char *
10893 get_mips_symbol_other (unsigned int other)
10897 case STO_OPTIONAL: return "OPTIONAL";
10898 case STO_MIPS_PLT: return "MIPS PLT";
10899 case STO_MIPS_PIC: return "MIPS PIC";
10900 case STO_MICROMIPS: return "MICROMIPS";
10901 case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC";
10902 case STO_MIPS16: return "MIPS16";
10903 default: return NULL;
10907 static const char *
10908 get_ia64_symbol_other (Filedata * filedata, unsigned int other)
10910 if (is_ia64_vms (filedata))
10912 static char res[32];
10916 /* Function types is for images and .STB files only. */
10917 switch (filedata->file_header.e_type)
10921 switch (VMS_ST_FUNC_TYPE (other))
10923 case VMS_SFT_CODE_ADDR:
10924 strcat (res, " CA");
10926 case VMS_SFT_SYMV_IDX:
10927 strcat (res, " VEC");
10930 strcat (res, " FD");
10932 case VMS_SFT_RESERVE:
10933 strcat (res, " RSV");
10936 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
10937 VMS_ST_FUNC_TYPE (other));
10938 strcat (res, " <unknown>");
10945 switch (VMS_ST_LINKAGE (other))
10947 case VMS_STL_IGNORE:
10948 strcat (res, " IGN");
10950 case VMS_STL_RESERVE:
10951 strcat (res, " RSV");
10954 strcat (res, " STD");
10957 strcat (res, " LNK");
10960 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
10961 VMS_ST_LINKAGE (other));
10962 strcat (res, " <unknown>");
10974 static const char *
10975 get_ppc64_symbol_other (unsigned int other)
10977 if (PPC64_LOCAL_ENTRY_OFFSET (other) != 0)
10979 static char buf[32];
10980 snprintf (buf, sizeof buf, _("<localentry>: %d"),
10981 PPC64_LOCAL_ENTRY_OFFSET (other));
10987 static const char *
10988 get_symbol_other (Filedata * filedata, unsigned int other)
10990 const char * result = NULL;
10991 static char buff [32];
10996 switch (filedata->file_header.e_machine)
10999 result = get_mips_symbol_other (other);
11002 result = get_ia64_symbol_other (filedata, other);
11005 result = get_ppc64_symbol_other (other);
11015 snprintf (buff, sizeof buff, _("<other>: %x"), other);
11019 static const char *
11020 get_symbol_index_type (Filedata * filedata, unsigned int type)
11022 static char buff[32];
11026 case SHN_UNDEF: return "UND";
11027 case SHN_ABS: return "ABS";
11028 case SHN_COMMON: return "COM";
11030 if (type == SHN_IA_64_ANSI_COMMON
11031 && filedata->file_header.e_machine == EM_IA_64
11032 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
11034 else if ((filedata->file_header.e_machine == EM_X86_64
11035 || filedata->file_header.e_machine == EM_L1OM
11036 || filedata->file_header.e_machine == EM_K1OM)
11037 && type == SHN_X86_64_LCOMMON)
11038 return "LARGE_COM";
11039 else if ((type == SHN_MIPS_SCOMMON
11040 && filedata->file_header.e_machine == EM_MIPS)
11041 || (type == SHN_TIC6X_SCOMMON
11042 && filedata->file_header.e_machine == EM_TI_C6000))
11044 else if (type == SHN_MIPS_SUNDEFINED
11045 && filedata->file_header.e_machine == EM_MIPS)
11047 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
11048 sprintf (buff, "PRC[0x%04x]", type & 0xffff);
11049 else if (type >= SHN_LOOS && type <= SHN_HIOS)
11050 sprintf (buff, "OS [0x%04x]", type & 0xffff);
11051 else if (type >= SHN_LORESERVE)
11052 sprintf (buff, "RSV[0x%04x]", type & 0xffff);
11053 else if (type >= filedata->file_header.e_shnum)
11054 sprintf (buff, _("bad section index[%3d]"), type);
11056 sprintf (buff, "%3d", type);
11064 get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size)
11066 unsigned char * e_data;
11069 /* If the size_t type is smaller than the bfd_size_type, eg because
11070 you are building a 32-bit tool on a 64-bit host, then make sure
11071 that when (number) is cast to (size_t) no information is lost. */
11072 if (sizeof (size_t) < sizeof (bfd_size_type)
11073 && (bfd_size_type) ((size_t) number) != number)
11075 error (_("Size truncation prevents reading %s elements of size %u\n"),
11076 bfd_vmatoa ("u", number), ent_size);
11080 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
11081 attempting to allocate memory when the read is bound to fail. */
11082 if (ent_size * number > filedata->file_size)
11084 error (_("Invalid number of dynamic entries: %s\n"),
11085 bfd_vmatoa ("u", number));
11089 e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
11090 if (e_data == NULL)
11092 error (_("Out of memory reading %s dynamic entries\n"),
11093 bfd_vmatoa ("u", number));
11097 if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number)
11099 error (_("Unable to read in %s bytes of dynamic data\n"),
11100 bfd_vmatoa ("u", number * ent_size));
11105 i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
11106 if (i_data == NULL)
11108 error (_("Out of memory allocating space for %s dynamic entries\n"),
11109 bfd_vmatoa ("u", number));
11115 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
11123 print_dynamic_symbol (Filedata * filedata, bfd_vma si, unsigned long hn)
11125 Elf_Internal_Sym * psym;
11128 n = print_vma (si, DEC_5);
11130 fputs (&" "[n], stdout);
11131 printf (" %3lu: ", hn);
11133 if (dynamic_symbols == NULL || si >= num_dynamic_syms)
11135 printf (_("<No info available for dynamic symbol number %lu>\n"),
11136 (unsigned long) si);
11140 psym = dynamic_symbols + si;
11141 print_vma (psym->st_value, LONG_HEX);
11143 print_vma (psym->st_size, DEC_5);
11145 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
11146 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
11148 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
11149 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
11152 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
11154 printf (" %-7s", get_symbol_visibility (vis));
11155 /* Check to see if any other bits in the st_other field are set.
11156 Note - displaying this information disrupts the layout of the
11157 table being generated, but for the moment this case is very
11159 if (psym->st_other ^ vis)
11160 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
11163 printf (" %3.3s ", get_symbol_index_type (filedata, psym->st_shndx));
11164 if (VALID_DYNAMIC_NAME (psym->st_name))
11165 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
11167 printf (_(" <corrupt: %14ld>"), psym->st_name);
11171 static const char *
11172 get_symbol_version_string (Filedata * filedata,
11173 bfd_boolean is_dynsym,
11174 const char * strtab,
11175 unsigned long int strtab_size,
11177 Elf_Internal_Sym * psym,
11178 enum versioned_symbol_info * sym_info,
11179 unsigned short * vna_other)
11181 unsigned char data[2];
11182 unsigned short vers_data;
11183 unsigned long offset;
11186 || version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
11189 offset = offset_from_vma (filedata, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
11190 sizeof data + si * sizeof (vers_data));
11192 if (get_data (&data, filedata, offset + si * sizeof (vers_data),
11193 sizeof (data), 1, _("version data")) == NULL)
11196 vers_data = byte_get (data, 2);
11198 if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data <= 1)
11201 /* Usually we'd only see verdef for defined symbols, and verneed for
11202 undefined symbols. However, symbols defined by the linker in
11203 .dynbss for variables copied from a shared library in order to
11204 avoid text relocations are defined yet have verneed. We could
11205 use a heuristic to detect the special case, for example, check
11206 for verneed first on symbols defined in SHT_NOBITS sections, but
11207 it is simpler and more reliable to just look for both verdef and
11208 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
11210 if (psym->st_shndx != SHN_UNDEF
11211 && vers_data != 0x8001
11212 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
11214 Elf_Internal_Verdef ivd;
11215 Elf_Internal_Verdaux ivda;
11216 Elf_External_Verdaux evda;
11219 off = offset_from_vma (filedata,
11220 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
11221 sizeof (Elf_External_Verdef));
11225 Elf_External_Verdef evd;
11227 if (get_data (&evd, filedata, off, sizeof (evd), 1,
11228 _("version def")) == NULL)
11236 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
11237 ivd.vd_aux = BYTE_GET (evd.vd_aux);
11238 ivd.vd_next = BYTE_GET (evd.vd_next);
11241 off += ivd.vd_next;
11243 while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
11245 if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
11247 off -= ivd.vd_next;
11250 if (get_data (&evda, filedata, off, sizeof (evda), 1,
11251 _("version def aux")) != NULL)
11253 ivda.vda_name = BYTE_GET (evda.vda_name);
11255 if (psym->st_name != ivda.vda_name)
11257 *sym_info = ((vers_data & VERSYM_HIDDEN) != 0
11258 ? symbol_hidden : symbol_public);
11259 return (ivda.vda_name < strtab_size
11260 ? strtab + ivda.vda_name : _("<corrupt>"));
11266 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
11268 Elf_External_Verneed evn;
11269 Elf_Internal_Verneed ivn;
11270 Elf_Internal_Vernaux ivna;
11272 offset = offset_from_vma (filedata,
11273 version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
11277 unsigned long vna_off;
11279 if (get_data (&evn, filedata, offset, sizeof (evn), 1,
11280 _("version need")) == NULL)
11283 ivna.vna_other = 0;
11288 ivn.vn_aux = BYTE_GET (evn.vn_aux);
11289 ivn.vn_next = BYTE_GET (evn.vn_next);
11291 vna_off = offset + ivn.vn_aux;
11295 Elf_External_Vernaux evna;
11297 if (get_data (&evna, filedata, vna_off, sizeof (evna), 1,
11298 _("version need aux (3)")) == NULL)
11301 ivna.vna_other = 0;
11306 ivna.vna_other = BYTE_GET (evna.vna_other);
11307 ivna.vna_next = BYTE_GET (evna.vna_next);
11308 ivna.vna_name = BYTE_GET (evna.vna_name);
11311 vna_off += ivna.vna_next;
11313 while (ivna.vna_other != vers_data && ivna.vna_next != 0);
11315 if (ivna.vna_other == vers_data)
11318 offset += ivn.vn_next;
11320 while (ivn.vn_next != 0);
11322 if (ivna.vna_other == vers_data)
11324 *sym_info = symbol_undefined;
11325 *vna_other = ivna.vna_other;
11326 return (ivna.vna_name < strtab_size
11327 ? strtab + ivna.vna_name : _("<corrupt>"));
11333 /* Dump the symbol table. */
11335 process_symbol_table (Filedata * filedata)
11337 Elf_Internal_Shdr * section;
11338 bfd_size_type nbuckets = 0;
11339 bfd_size_type nchains = 0;
11340 bfd_vma * buckets = NULL;
11341 bfd_vma * chains = NULL;
11342 bfd_vma ngnubuckets = 0;
11343 bfd_vma * gnubuckets = NULL;
11344 bfd_vma * gnuchains = NULL;
11345 bfd_vma gnusymidx = 0;
11346 bfd_size_type ngnuchains = 0;
11348 if (!do_syms && !do_dyn_syms && !do_histogram)
11351 if (dynamic_info[DT_HASH]
11353 || (do_using_dynamic
11355 && dynamic_strings != NULL)))
11357 unsigned char nb[8];
11358 unsigned char nc[8];
11359 unsigned int hash_ent_size = 4;
11361 if ((filedata->file_header.e_machine == EM_ALPHA
11362 || filedata->file_header.e_machine == EM_S390
11363 || filedata->file_header.e_machine == EM_S390_OLD)
11364 && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64)
11367 if (fseek (filedata->handle,
11368 (archive_file_offset
11369 + offset_from_vma (filedata, dynamic_info[DT_HASH],
11370 sizeof nb + sizeof nc)),
11373 error (_("Unable to seek to start of dynamic information\n"));
11377 if (fread (nb, hash_ent_size, 1, filedata->handle) != 1)
11379 error (_("Failed to read in number of buckets\n"));
11383 if (fread (nc, hash_ent_size, 1, filedata->handle) != 1)
11385 error (_("Failed to read in number of chains\n"));
11389 nbuckets = byte_get (nb, hash_ent_size);
11390 nchains = byte_get (nc, hash_ent_size);
11392 buckets = get_dynamic_data (filedata, nbuckets, hash_ent_size);
11393 chains = get_dynamic_data (filedata, nchains, hash_ent_size);
11396 if (buckets == NULL || chains == NULL)
11398 if (do_using_dynamic)
11409 if (dynamic_info_DT_GNU_HASH
11411 || (do_using_dynamic
11413 && dynamic_strings != NULL)))
11415 unsigned char nb[16];
11416 bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
11417 bfd_vma buckets_vma;
11419 if (fseek (filedata->handle,
11420 (archive_file_offset
11421 + offset_from_vma (filedata, dynamic_info_DT_GNU_HASH,
11425 error (_("Unable to seek to start of dynamic information\n"));
11429 if (fread (nb, 16, 1, filedata->handle) != 1)
11431 error (_("Failed to read in number of buckets\n"));
11435 ngnubuckets = byte_get (nb, 4);
11436 gnusymidx = byte_get (nb + 4, 4);
11437 bitmaskwords = byte_get (nb + 8, 4);
11438 buckets_vma = dynamic_info_DT_GNU_HASH + 16;
11440 buckets_vma += bitmaskwords * 4;
11442 buckets_vma += bitmaskwords * 8;
11444 if (fseek (filedata->handle,
11445 (archive_file_offset
11446 + offset_from_vma (filedata, buckets_vma, 4)),
11449 error (_("Unable to seek to start of dynamic information\n"));
11453 gnubuckets = get_dynamic_data (filedata, ngnubuckets, 4);
11455 if (gnubuckets == NULL)
11458 for (i = 0; i < ngnubuckets; i++)
11459 if (gnubuckets[i] != 0)
11461 if (gnubuckets[i] < gnusymidx)
11464 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
11465 maxchain = gnubuckets[i];
11468 if (maxchain == 0xffffffff)
11471 maxchain -= gnusymidx;
11473 if (fseek (filedata->handle,
11474 (archive_file_offset
11475 + offset_from_vma (filedata, buckets_vma
11476 + 4 * (ngnubuckets + maxchain), 4)),
11479 error (_("Unable to seek to start of dynamic information\n"));
11485 if (fread (nb, 4, 1, filedata->handle) != 1)
11487 error (_("Failed to determine last chain length\n"));
11491 if (maxchain + 1 == 0)
11496 while ((byte_get (nb, 4) & 1) == 0);
11498 if (fseek (filedata->handle,
11499 (archive_file_offset
11500 + offset_from_vma (filedata, buckets_vma + 4 * ngnubuckets, 4)),
11503 error (_("Unable to seek to start of dynamic information\n"));
11507 gnuchains = get_dynamic_data (filedata, maxchain, 4);
11508 ngnuchains = maxchain;
11511 if (gnuchains == NULL)
11516 if (do_using_dynamic)
11521 if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
11523 && do_using_dynamic
11524 && dynamic_strings != NULL
11525 && dynamic_symbols != NULL)
11529 if (dynamic_info[DT_HASH])
11534 printf (_("\nSymbol table for image:\n"));
11536 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11538 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11540 visited = xcmalloc (nchains, 1);
11541 memset (visited, 0, nchains);
11542 for (hn = 0; hn < nbuckets; hn++)
11544 for (si = buckets[hn]; si > 0; si = chains[si])
11546 print_dynamic_symbol (filedata, si, hn);
11547 if (si >= nchains || visited[si])
11549 error (_("histogram chain is corrupt\n"));
11558 if (dynamic_info_DT_GNU_HASH)
11560 printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
11562 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11564 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
11566 for (hn = 0; hn < ngnubuckets; ++hn)
11567 if (gnubuckets[hn] != 0)
11569 bfd_vma si = gnubuckets[hn];
11570 bfd_vma off = si - gnusymidx;
11574 print_dynamic_symbol (filedata, si, hn);
11577 while (off < ngnuchains && (gnuchains[off++] & 1) == 0);
11581 else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
11582 && filedata->section_headers != NULL)
11586 for (i = 0, section = filedata->section_headers;
11587 i < filedata->file_header.e_shnum;
11591 char * strtab = NULL;
11592 unsigned long int strtab_size = 0;
11593 Elf_Internal_Sym * symtab;
11594 Elf_Internal_Sym * psym;
11595 unsigned long num_syms;
11597 if ((section->sh_type != SHT_SYMTAB
11598 && section->sh_type != SHT_DYNSYM)
11600 && section->sh_type == SHT_SYMTAB))
11603 if (section->sh_entsize == 0)
11605 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
11606 printable_section_name (filedata, section));
11610 num_syms = section->sh_size / section->sh_entsize;
11611 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
11612 "\nSymbol table '%s' contains %lu entries:\n",
11614 printable_section_name (filedata, section),
11618 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
11620 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
11622 symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms);
11623 if (symtab == NULL)
11626 if (section->sh_link == filedata->file_header.e_shstrndx)
11628 strtab = filedata->string_table;
11629 strtab_size = filedata->string_table_length;
11631 else if (section->sh_link < filedata->file_header.e_shnum)
11633 Elf_Internal_Shdr * string_sec;
11635 string_sec = filedata->section_headers + section->sh_link;
11637 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset,
11638 1, string_sec->sh_size,
11639 _("string table"));
11640 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
11643 for (si = 0, psym = symtab; si < num_syms; si++, psym++)
11645 const char *version_string;
11646 enum versioned_symbol_info sym_info;
11647 unsigned short vna_other;
11649 printf ("%6d: ", si);
11650 print_vma (psym->st_value, LONG_HEX);
11652 print_vma (psym->st_size, DEC_5);
11653 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
11654 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
11655 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
11656 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
11659 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
11661 printf (" %-7s", get_symbol_visibility (vis));
11662 /* Check to see if any other bits in the st_other field are set.
11663 Note - displaying this information disrupts the layout of the
11664 table being generated, but for the moment this case is very rare. */
11665 if (psym->st_other ^ vis)
11666 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
11668 printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));
11669 print_symbol (25, psym->st_name < strtab_size
11670 ? strtab + psym->st_name : _("<corrupt>"));
11673 = get_symbol_version_string (filedata,
11674 section->sh_type == SHT_DYNSYM,
11675 strtab, strtab_size, si,
11676 psym, &sym_info, &vna_other);
11677 if (version_string)
11679 if (sym_info == symbol_undefined)
11680 printf ("@%s (%d)", version_string, vna_other);
11682 printf (sym_info == symbol_hidden ? "@%s" : "@@%s",
11688 if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
11689 && si >= section->sh_info
11690 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
11691 && filedata->file_header.e_machine != EM_MIPS
11692 /* Solaris binaries have been found to violate this requirement as
11693 well. Not sure if this is a bug or an ABI requirement. */
11694 && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS)
11695 warn (_("local symbol %u found at index >= %s's sh_info value of %u\n"),
11696 si, printable_section_name (filedata, section), section->sh_info);
11700 if (strtab != filedata->string_table)
11706 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
11708 if (do_histogram && buckets != NULL)
11710 unsigned long * lengths;
11711 unsigned long * counts;
11714 unsigned long maxlength = 0;
11715 unsigned long nzero_counts = 0;
11716 unsigned long nsyms = 0;
11719 printf (ngettext ("\nHistogram for bucket list length "
11720 "(total of %lu bucket):\n",
11721 "\nHistogram for bucket list length "
11722 "(total of %lu buckets):\n",
11723 (unsigned long) nbuckets),
11724 (unsigned long) nbuckets);
11726 lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
11727 if (lengths == NULL)
11729 error (_("Out of memory allocating space for histogram buckets\n"));
11732 visited = xcmalloc (nchains, 1);
11733 memset (visited, 0, nchains);
11735 printf (_(" Length Number %% of total Coverage\n"));
11736 for (hn = 0; hn < nbuckets; ++hn)
11738 for (si = buckets[hn]; si > 0; si = chains[si])
11741 if (maxlength < ++lengths[hn])
11743 if (si >= nchains || visited[si])
11745 error (_("histogram chain is corrupt\n"));
11753 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
11754 if (counts == NULL)
11757 error (_("Out of memory allocating space for histogram counts\n"));
11761 for (hn = 0; hn < nbuckets; ++hn)
11762 ++counts[lengths[hn]];
11767 printf (" 0 %-10lu (%5.1f%%)\n",
11768 counts[0], (counts[0] * 100.0) / nbuckets);
11769 for (i = 1; i <= maxlength; ++i)
11771 nzero_counts += counts[i] * i;
11772 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
11773 i, counts[i], (counts[i] * 100.0) / nbuckets,
11774 (nzero_counts * 100.0) / nsyms);
11782 if (buckets != NULL)
11788 if (do_histogram && gnubuckets != NULL)
11790 unsigned long * lengths;
11791 unsigned long * counts;
11793 unsigned long maxlength = 0;
11794 unsigned long nzero_counts = 0;
11795 unsigned long nsyms = 0;
11797 printf (ngettext ("\nHistogram for `.gnu.hash' bucket list length "
11798 "(total of %lu bucket):\n",
11799 "\nHistogram for `.gnu.hash' bucket list length "
11800 "(total of %lu buckets):\n",
11801 (unsigned long) ngnubuckets),
11802 (unsigned long) ngnubuckets);
11804 lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
11805 if (lengths == NULL)
11807 error (_("Out of memory allocating space for gnu histogram buckets\n"));
11811 printf (_(" Length Number %% of total Coverage\n"));
11813 for (hn = 0; hn < ngnubuckets; ++hn)
11814 if (gnubuckets[hn] != 0)
11816 bfd_vma off, length = 1;
11818 for (off = gnubuckets[hn] - gnusymidx;
11819 /* PR 17531 file: 010-77222-0.004. */
11820 off < ngnuchains && (gnuchains[off] & 1) == 0;
11823 lengths[hn] = length;
11824 if (length > maxlength)
11825 maxlength = length;
11829 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
11830 if (counts == NULL)
11833 error (_("Out of memory allocating space for gnu histogram counts\n"));
11837 for (hn = 0; hn < ngnubuckets; ++hn)
11838 ++counts[lengths[hn]];
11840 if (ngnubuckets > 0)
11843 printf (" 0 %-10lu (%5.1f%%)\n",
11844 counts[0], (counts[0] * 100.0) / ngnubuckets);
11845 for (j = 1; j <= maxlength; ++j)
11847 nzero_counts += counts[j] * j;
11848 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
11849 j, counts[j], (counts[j] * 100.0) / ngnubuckets,
11850 (nzero_counts * 100.0) / nsyms);
11864 process_syminfo (Filedata * filedata ATTRIBUTE_UNUSED)
11868 if (dynamic_syminfo == NULL
11870 /* No syminfo, this is ok. */
11873 /* There better should be a dynamic symbol section. */
11874 if (dynamic_symbols == NULL || dynamic_strings == NULL)
11878 printf (ngettext ("\nDynamic info segment at offset 0x%lx "
11879 "contains %d entry:\n",
11880 "\nDynamic info segment at offset 0x%lx "
11881 "contains %d entries:\n",
11882 dynamic_syminfo_nent),
11883 dynamic_syminfo_offset, dynamic_syminfo_nent);
11885 printf (_(" Num: Name BoundTo Flags\n"));
11886 for (i = 0; i < dynamic_syminfo_nent; ++i)
11888 unsigned short int flags = dynamic_syminfo[i].si_flags;
11890 printf ("%4d: ", i);
11891 if (i >= num_dynamic_syms)
11892 printf (_("<corrupt index>"));
11893 else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
11894 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
11896 printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
11899 switch (dynamic_syminfo[i].si_boundto)
11901 case SYMINFO_BT_SELF:
11902 fputs ("SELF ", stdout);
11904 case SYMINFO_BT_PARENT:
11905 fputs ("PARENT ", stdout);
11908 if (dynamic_syminfo[i].si_boundto > 0
11909 && dynamic_syminfo[i].si_boundto < dynamic_nent
11910 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
11912 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
11916 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
11920 if (flags & SYMINFO_FLG_DIRECT)
11921 printf (" DIRECT");
11922 if (flags & SYMINFO_FLG_PASSTHRU)
11923 printf (" PASSTHRU");
11924 if (flags & SYMINFO_FLG_COPY)
11926 if (flags & SYMINFO_FLG_LAZYLOAD)
11927 printf (" LAZYLOAD");
11935 #define IN_RANGE(START,END,ADDR,OFF) \
11936 (((ADDR) >= (START)) && ((ADDR) + (OFF) < (END)))
11938 /* Check to see if the given reloc needs to be handled in a target specific
11939 manner. If so then process the reloc and return TRUE otherwise return
11942 If called with reloc == NULL, then this is a signal that reloc processing
11943 for the current section has finished, and any saved state should be
11947 target_specific_reloc_handling (Filedata * filedata,
11948 Elf_Internal_Rela * reloc,
11949 unsigned char * start,
11950 unsigned char * end,
11951 Elf_Internal_Sym * symtab,
11952 unsigned long num_syms)
11954 unsigned int reloc_type = 0;
11955 unsigned long sym_index = 0;
11959 reloc_type = get_reloc_type (filedata, reloc->r_info);
11960 sym_index = get_reloc_symindex (reloc->r_info);
11963 switch (filedata->file_header.e_machine)
11966 case EM_MSP430_OLD:
11968 static Elf_Internal_Sym * saved_sym = NULL;
11976 switch (reloc_type)
11978 case 10: /* R_MSP430_SYM_DIFF */
11979 if (uses_msp430x_relocs (filedata))
11981 /* Fall through. */
11982 case 21: /* R_MSP430X_SYM_DIFF */
11984 if (sym_index >= num_syms)
11985 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
11988 saved_sym = symtab + sym_index;
11991 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
11992 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
11993 goto handle_sym_diff;
11995 case 5: /* R_MSP430_16_BYTE */
11996 case 9: /* R_MSP430_8 */
11997 if (uses_msp430x_relocs (filedata))
11999 goto handle_sym_diff;
12001 case 2: /* R_MSP430_ABS16 */
12002 case 15: /* R_MSP430X_ABS16 */
12003 if (! uses_msp430x_relocs (filedata))
12005 goto handle_sym_diff;
12008 if (saved_sym != NULL)
12010 int reloc_size = reloc_type == 1 ? 4 : 2;
12013 if (sym_index >= num_syms)
12014 error (_("MSP430 reloc contains invalid symbol index %lu\n"),
12018 value = reloc->r_addend + (symtab[sym_index].st_value
12019 - saved_sym->st_value);
12021 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
12022 byte_put (start + reloc->r_offset, value, reloc_size);
12025 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
12026 (long) reloc->r_offset);
12035 if (saved_sym != NULL)
12036 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
12043 case EM_CYGNUS_MN10300:
12045 static Elf_Internal_Sym * saved_sym = NULL;
12053 switch (reloc_type)
12055 case 34: /* R_MN10300_ALIGN */
12057 case 33: /* R_MN10300_SYM_DIFF */
12058 if (sym_index >= num_syms)
12059 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
12062 saved_sym = symtab + sym_index;
12065 case 1: /* R_MN10300_32 */
12066 case 2: /* R_MN10300_16 */
12067 if (saved_sym != NULL)
12069 int reloc_size = reloc_type == 1 ? 4 : 2;
12072 if (sym_index >= num_syms)
12073 error (_("MN10300 reloc contains invalid symbol index %lu\n"),
12077 value = reloc->r_addend + (symtab[sym_index].st_value
12078 - saved_sym->st_value);
12080 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
12081 byte_put (start + reloc->r_offset, value, reloc_size);
12083 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
12084 (long) reloc->r_offset);
12092 if (saved_sym != NULL)
12093 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
12101 static bfd_vma saved_sym1 = 0;
12102 static bfd_vma saved_sym2 = 0;
12103 static bfd_vma value;
12107 saved_sym1 = saved_sym2 = 0;
12111 switch (reloc_type)
12113 case 0x80: /* R_RL78_SYM. */
12114 saved_sym1 = saved_sym2;
12115 if (sym_index >= num_syms)
12116 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
12120 saved_sym2 = symtab[sym_index].st_value;
12121 saved_sym2 += reloc->r_addend;
12125 case 0x83: /* R_RL78_OPsub. */
12126 value = saved_sym1 - saved_sym2;
12127 saved_sym2 = saved_sym1 = 0;
12131 case 0x41: /* R_RL78_ABS32. */
12132 if (IN_RANGE (start, end, start + reloc->r_offset, 4))
12133 byte_put (start + reloc->r_offset, value, 4);
12135 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12136 (long) reloc->r_offset);
12140 case 0x43: /* R_RL78_ABS16. */
12141 if (IN_RANGE (start, end, start + reloc->r_offset, 2))
12142 byte_put (start + reloc->r_offset, value, 2);
12144 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
12145 (long) reloc->r_offset);
12159 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
12160 DWARF debug sections. This is a target specific test. Note - we do not
12161 go through the whole including-target-headers-multiple-times route, (as
12162 we have already done with <elf/h8.h>) because this would become very
12163 messy and even then this function would have to contain target specific
12164 information (the names of the relocs instead of their numeric values).
12165 FIXME: This is not the correct way to solve this problem. The proper way
12166 is to have target specific reloc sizing and typing functions created by
12167 the reloc-macros.h header, in the same way that it already creates the
12168 reloc naming functions. */
12171 is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12173 /* Please keep this table alpha-sorted for ease of visual lookup. */
12174 switch (filedata->file_header.e_machine)
12178 return reloc_type == 1; /* R_386_32. */
12180 return reloc_type == 1; /* R_68K_32. */
12182 return (reloc_type == 258
12183 || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
12184 case EM_ADAPTEVA_EPIPHANY:
12185 return reloc_type == 3;
12187 return reloc_type == 1; /* R_ALPHA_REFLONG. */
12189 return reloc_type == 1; /* R_ARC_32. */
12190 case EM_ARC_COMPACT:
12191 case EM_ARC_COMPACT2:
12192 return reloc_type == 4; /* R_ARC_32. */
12194 return reloc_type == 2; /* R_ARM_ABS32 */
12197 return reloc_type == 1;
12199 return reloc_type == 0x12; /* R_byte4_data. */
12201 return reloc_type == 3; /* R_CRIS_32. */
12203 return reloc_type == 3; /* R_CR16_NUM32. */
12205 return reloc_type == 15; /* R_CRX_NUM32. */
12206 case EM_CYGNUS_FRV:
12207 return reloc_type == 1;
12208 case EM_CYGNUS_D10V:
12210 return reloc_type == 6; /* R_D10V_32. */
12211 case EM_CYGNUS_D30V:
12213 return reloc_type == 12; /* R_D30V_32_NORMAL. */
12215 return reloc_type == 3; /* R_DLX_RELOC_32. */
12216 case EM_CYGNUS_FR30:
12218 return reloc_type == 3; /* R_FR30_32. */
12220 return reloc_type == 1; /* R_FT32_32. */
12224 return reloc_type == 1; /* R_H8_DIR32. */
12226 return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */
12227 || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */
12228 || reloc_type == 0x24 /* R_IA64_DIR32MSB. */
12229 || reloc_type == 0x25 /* R_IA64_DIR32LSB. */);
12232 return reloc_type == 2; /* R_IP2K_32. */
12234 return reloc_type == 2; /* R_IQ2000_32. */
12235 case EM_LATTICEMICO32:
12236 return reloc_type == 3; /* R_LM32_32. */
12239 return reloc_type == 3; /* R_M32C_32. */
12241 return reloc_type == 34; /* R_M32R_32_RELA. */
12244 return reloc_type == 6; /* R_M68HC11_32. */
12246 return reloc_type == 1; /* R_MCORE_ADDR32. */
12247 case EM_CYGNUS_MEP:
12248 return reloc_type == 4; /* R_MEP_32. */
12250 return reloc_type == 2; /* R_METAG_ADDR32. */
12251 case EM_MICROBLAZE:
12252 return reloc_type == 1; /* R_MICROBLAZE_32. */
12254 return reloc_type == 2; /* R_MIPS_32. */
12256 return reloc_type == 4; /* R_MMIX_32. */
12257 case EM_CYGNUS_MN10200:
12259 return reloc_type == 1; /* R_MN10200_32. */
12260 case EM_CYGNUS_MN10300:
12262 return reloc_type == 1; /* R_MN10300_32. */
12264 return reloc_type == 1; /* R_MOXIE_32. */
12265 case EM_MSP430_OLD:
12267 return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */
12269 return reloc_type == 2; /* R_MT_32. */
12271 return reloc_type == 20; /* R_NDS32_RELA. */
12272 case EM_ALTERA_NIOS2:
12273 return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
12275 return reloc_type == 1; /* R_NIOS_32. */
12277 return reloc_type == 1; /* R_OR1K_32. */
12279 return (reloc_type == 1 /* R_PARISC_DIR32. */
12280 || reloc_type == 41); /* R_PARISC_SECREL32. */
12283 return reloc_type == 1; /* R_PJ_DATA_DIR32. */
12285 return reloc_type == 1; /* R_PPC64_ADDR32. */
12287 return reloc_type == 1; /* R_PPC_ADDR32. */
12289 return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */
12291 return reloc_type == 1; /* R_RISCV_32. */
12293 return reloc_type == 1; /* R_RL78_DIR32. */
12295 return reloc_type == 1; /* R_RX_DIR32. */
12298 return reloc_type == 4; /* R_S390_32. */
12300 return reloc_type == 8; /* R_SCORE_ABS32. */
12302 return reloc_type == 1; /* R_SH_DIR32. */
12303 case EM_SPARC32PLUS:
12306 return reloc_type == 3 /* R_SPARC_32. */
12307 || reloc_type == 23; /* R_SPARC_UA32. */
12309 return reloc_type == 6; /* R_SPU_ADDR32 */
12311 return reloc_type == 1; /* R_C6000_ABS32. */
12313 return reloc_type == 2; /* R_TILEGX_32. */
12315 return reloc_type == 1; /* R_TILEPRO_32. */
12316 case EM_CYGNUS_V850:
12318 return reloc_type == 6; /* R_V850_ABS32. */
12320 return reloc_type == 0x33; /* R_V810_WORD. */
12322 return reloc_type == 1; /* R_VAX_32. */
12324 return reloc_type == 3; /* R_VISIUM_32. */
12325 case EM_WEBASSEMBLY:
12326 return reloc_type == 1; /* R_WASM32_32. */
12330 return reloc_type == 10; /* R_X86_64_32. */
12333 return reloc_type == 3; /* R_XC16C_ABS_32. */
12335 return reloc_type == 4; /* R_XGATE_32. */
12337 return reloc_type == 1; /* R_XSTROMY16_32. */
12338 case EM_XTENSA_OLD:
12340 return reloc_type == 1; /* R_XTENSA_32. */
12343 static unsigned int prev_warn = 0;
12345 /* Avoid repeating the same warning multiple times. */
12346 if (prev_warn != filedata->file_header.e_machine)
12347 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
12348 filedata->file_header.e_machine);
12349 prev_warn = filedata->file_header.e_machine;
12355 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12356 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
12359 is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
12361 switch (filedata->file_header.e_machine)
12362 /* Please keep this table alpha-sorted for ease of visual lookup. */
12366 return reloc_type == 2; /* R_386_PC32. */
12368 return reloc_type == 4; /* R_68K_PC32. */
12370 return reloc_type == 261; /* R_AARCH64_PREL32 */
12371 case EM_ADAPTEVA_EPIPHANY:
12372 return reloc_type == 6;
12374 return reloc_type == 10; /* R_ALPHA_SREL32. */
12375 case EM_ARC_COMPACT:
12376 case EM_ARC_COMPACT2:
12377 return reloc_type == 49; /* R_ARC_32_PCREL. */
12379 return reloc_type == 3; /* R_ARM_REL32 */
12382 return reloc_type == 36; /* R_AVR_32_PCREL. */
12383 case EM_MICROBLAZE:
12384 return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */
12386 return reloc_type == 9; /* R_OR1K_32_PCREL. */
12388 return reloc_type == 9; /* R_PARISC_PCREL32. */
12390 return reloc_type == 26; /* R_PPC_REL32. */
12392 return reloc_type == 26; /* R_PPC64_REL32. */
12395 return reloc_type == 5; /* R_390_PC32. */
12397 return reloc_type == 2; /* R_SH_REL32. */
12398 case EM_SPARC32PLUS:
12401 return reloc_type == 6; /* R_SPARC_DISP32. */
12403 return reloc_type == 13; /* R_SPU_REL32. */
12405 return reloc_type == 6; /* R_TILEGX_32_PCREL. */
12407 return reloc_type == 4; /* R_TILEPRO_32_PCREL. */
12409 return reloc_type == 6; /* R_VISIUM_32_PCREL */
12413 return reloc_type == 2; /* R_X86_64_PC32. */
12414 case EM_XTENSA_OLD:
12416 return reloc_type == 14; /* R_XTENSA_32_PCREL. */
12418 /* Do not abort or issue an error message here. Not all targets use
12419 pc-relative 32-bit relocs in their DWARF debug information and we
12420 have already tested for target coverage in is_32bit_abs_reloc. A
12421 more helpful warning message will be generated by apply_relocations
12422 anyway, so just return. */
12427 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12428 a 64-bit absolute RELA relocation used in DWARF debug sections. */
12431 is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12433 switch (filedata->file_header.e_machine)
12436 return reloc_type == 257; /* R_AARCH64_ABS64. */
12438 return reloc_type == 2; /* R_ALPHA_REFQUAD. */
12440 return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */
12441 || reloc_type == 0x27 /* R_IA64_DIR64LSB. */);
12443 return reloc_type == 80; /* R_PARISC_DIR64. */
12445 return reloc_type == 38; /* R_PPC64_ADDR64. */
12447 return reloc_type == 2; /* R_RISCV_64. */
12448 case EM_SPARC32PLUS:
12451 return reloc_type == 32 /* R_SPARC_64. */
12452 || reloc_type == 54; /* R_SPARC_UA64. */
12456 return reloc_type == 1; /* R_X86_64_64. */
12459 return reloc_type == 22; /* R_S390_64. */
12461 return reloc_type == 1; /* R_TILEGX_64. */
12463 return reloc_type == 18; /* R_MIPS_64. */
12469 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
12470 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
12473 is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
12475 switch (filedata->file_header.e_machine)
12478 return reloc_type == 260; /* R_AARCH64_PREL64. */
12480 return reloc_type == 11; /* R_ALPHA_SREL64. */
12482 return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */
12483 || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */);
12485 return reloc_type == 72; /* R_PARISC_PCREL64. */
12487 return reloc_type == 44; /* R_PPC64_REL64. */
12488 case EM_SPARC32PLUS:
12491 return reloc_type == 46; /* R_SPARC_DISP64. */
12495 return reloc_type == 24; /* R_X86_64_PC64. */
12498 return reloc_type == 23; /* R_S390_PC64. */
12500 return reloc_type == 5; /* R_TILEGX_64_PCREL. */
12506 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12507 a 24-bit absolute RELA relocation used in DWARF debug sections. */
12510 is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12512 switch (filedata->file_header.e_machine)
12514 case EM_CYGNUS_MN10200:
12516 return reloc_type == 4; /* R_MN10200_24. */
12518 return reloc_type == 5; /* R_FT32_20. */
12524 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12525 a 16-bit absolute RELA relocation used in DWARF debug sections. */
12528 is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
12530 /* Please keep this table alpha-sorted for ease of visual lookup. */
12531 switch (filedata->file_header.e_machine)
12534 case EM_ARC_COMPACT:
12535 case EM_ARC_COMPACT2:
12536 return reloc_type == 2; /* R_ARC_16. */
12537 case EM_ADAPTEVA_EPIPHANY:
12538 return reloc_type == 5;
12541 return reloc_type == 4; /* R_AVR_16. */
12542 case EM_CYGNUS_D10V:
12544 return reloc_type == 3; /* R_D10V_16. */
12546 return reloc_type == 2; /* R_FT32_16. */
12550 return reloc_type == R_H8_DIR16;
12553 return reloc_type == 1; /* R_IP2K_16. */
12556 return reloc_type == 1; /* R_M32C_16 */
12557 case EM_CYGNUS_MN10200:
12559 return reloc_type == 2; /* R_MN10200_16. */
12560 case EM_CYGNUS_MN10300:
12562 return reloc_type == 2; /* R_MN10300_16. */
12564 if (uses_msp430x_relocs (filedata))
12565 return reloc_type == 2; /* R_MSP430_ABS16. */
12566 /* Fall through. */
12567 case EM_MSP430_OLD:
12568 return reloc_type == 5; /* R_MSP430_16_BYTE. */
12570 return reloc_type == 19; /* R_NDS32_RELA. */
12571 case EM_ALTERA_NIOS2:
12572 return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
12574 return reloc_type == 9; /* R_NIOS_16. */
12576 return reloc_type == 2; /* R_OR1K_16. */
12578 return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */
12580 return reloc_type == 2; /* R_C6000_ABS16. */
12582 return reloc_type == 2; /* R_VISIUM_16. */
12585 return reloc_type == 2; /* R_XC16C_ABS_16. */
12587 return reloc_type == 3; /* R_XGATE_16. */
12593 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12594 a 32-bit inplace add RELA relocation used in DWARF debug sections. */
12597 is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
12599 /* Please keep this table alpha-sorted for ease of visual lookup. */
12600 switch (filedata->file_header.e_machine)
12603 return reloc_type == 35; /* R_RISCV_ADD32. */
12609 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12610 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
12613 is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
12615 /* Please keep this table alpha-sorted for ease of visual lookup. */
12616 switch (filedata->file_header.e_machine)
12619 return reloc_type == 39; /* R_RISCV_SUB32. */
12625 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12626 a 64-bit inplace add RELA relocation used in DWARF debug sections. */
12629 is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
12631 /* Please keep this table alpha-sorted for ease of visual lookup. */
12632 switch (filedata->file_header.e_machine)
12635 return reloc_type == 36; /* R_RISCV_ADD64. */
12641 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12642 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
12645 is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
12647 /* Please keep this table alpha-sorted for ease of visual lookup. */
12648 switch (filedata->file_header.e_machine)
12651 return reloc_type == 40; /* R_RISCV_SUB64. */
12657 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12658 a 16-bit inplace add RELA relocation used in DWARF debug sections. */
12661 is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
12663 /* Please keep this table alpha-sorted for ease of visual lookup. */
12664 switch (filedata->file_header.e_machine)
12667 return reloc_type == 34; /* R_RISCV_ADD16. */
12673 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12674 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
12677 is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
12679 /* Please keep this table alpha-sorted for ease of visual lookup. */
12680 switch (filedata->file_header.e_machine)
12683 return reloc_type == 38; /* R_RISCV_SUB16. */
12689 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12690 a 8-bit inplace add RELA relocation used in DWARF debug sections. */
12693 is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
12695 /* Please keep this table alpha-sorted for ease of visual lookup. */
12696 switch (filedata->file_header.e_machine)
12699 return reloc_type == 33; /* R_RISCV_ADD8. */
12705 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
12706 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
12709 is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
12711 /* Please keep this table alpha-sorted for ease of visual lookup. */
12712 switch (filedata->file_header.e_machine)
12715 return reloc_type == 37; /* R_RISCV_SUB8. */
12721 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
12722 relocation entries (possibly formerly used for SHT_GROUP sections). */
12725 is_none_reloc (Filedata * filedata, unsigned int reloc_type)
12727 switch (filedata->file_header.e_machine)
12729 case EM_386: /* R_386_NONE. */
12730 case EM_68K: /* R_68K_NONE. */
12731 case EM_ADAPTEVA_EPIPHANY:
12732 case EM_ALPHA: /* R_ALPHA_NONE. */
12733 case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
12734 case EM_ARC: /* R_ARC_NONE. */
12735 case EM_ARC_COMPACT2: /* R_ARC_NONE. */
12736 case EM_ARC_COMPACT: /* R_ARC_NONE. */
12737 case EM_ARM: /* R_ARM_NONE. */
12738 case EM_C166: /* R_XC16X_NONE. */
12739 case EM_CRIS: /* R_CRIS_NONE. */
12740 case EM_FT32: /* R_FT32_NONE. */
12741 case EM_IA_64: /* R_IA64_NONE. */
12742 case EM_K1OM: /* R_X86_64_NONE. */
12743 case EM_L1OM: /* R_X86_64_NONE. */
12744 case EM_M32R: /* R_M32R_NONE. */
12745 case EM_MIPS: /* R_MIPS_NONE. */
12746 case EM_MN10300: /* R_MN10300_NONE. */
12747 case EM_MOXIE: /* R_MOXIE_NONE. */
12748 case EM_NIOS32: /* R_NIOS_NONE. */
12749 case EM_OR1K: /* R_OR1K_NONE. */
12750 case EM_PARISC: /* R_PARISC_NONE. */
12751 case EM_PPC64: /* R_PPC64_NONE. */
12752 case EM_PPC: /* R_PPC_NONE. */
12753 case EM_RISCV: /* R_RISCV_NONE. */
12754 case EM_S390: /* R_390_NONE. */
12756 case EM_SH: /* R_SH_NONE. */
12757 case EM_SPARC32PLUS:
12758 case EM_SPARC: /* R_SPARC_NONE. */
12760 case EM_TILEGX: /* R_TILEGX_NONE. */
12761 case EM_TILEPRO: /* R_TILEPRO_NONE. */
12762 case EM_TI_C6000:/* R_C6000_NONE. */
12763 case EM_X86_64: /* R_X86_64_NONE. */
12765 case EM_WEBASSEMBLY: /* R_WASM32_NONE. */
12766 return reloc_type == 0;
12769 return reloc_type == 0 || reloc_type == 256;
12772 return (reloc_type == 0 /* R_AVR_NONE. */
12773 || reloc_type == 30 /* R_AVR_DIFF8. */
12774 || reloc_type == 31 /* R_AVR_DIFF16. */
12775 || reloc_type == 32 /* R_AVR_DIFF32. */);
12777 return reloc_type == 3; /* R_METAG_NONE. */
12779 return (reloc_type == 0 /* R_XTENSA_NONE. */
12780 || reloc_type == 204 /* R_NDS32_DIFF8. */
12781 || reloc_type == 205 /* R_NDS32_DIFF16. */
12782 || reloc_type == 206 /* R_NDS32_DIFF32. */
12783 || reloc_type == 207 /* R_NDS32_ULEB128. */);
12785 return (reloc_type == 0 /* R_PRU_NONE. */
12786 || reloc_type == 65 /* R_PRU_DIFF8. */
12787 || reloc_type == 66 /* R_PRU_DIFF16. */
12788 || reloc_type == 67 /* R_PRU_DIFF32. */);
12789 case EM_XTENSA_OLD:
12791 return (reloc_type == 0 /* R_XTENSA_NONE. */
12792 || reloc_type == 17 /* R_XTENSA_DIFF8. */
12793 || reloc_type == 18 /* R_XTENSA_DIFF16. */
12794 || reloc_type == 19 /* R_XTENSA_DIFF32. */);
12799 /* Returns TRUE if there is a relocation against
12800 section NAME at OFFSET bytes. */
12803 reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
12805 Elf_Internal_Rela * relocs;
12806 Elf_Internal_Rela * rp;
12808 if (dsec == NULL || dsec->reloc_info == NULL)
12811 relocs = (Elf_Internal_Rela *) dsec->reloc_info;
12813 for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp)
12814 if (rp->r_offset == offset)
12820 /* Apply relocations to a section.
12821 Returns TRUE upon success, FALSE otherwise.
12822 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
12823 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
12824 will be set to the number of relocs loaded.
12826 Note: So far support has been added only for those relocations
12827 which can be found in debug sections. FIXME: Add support for
12828 more relocations ? */
12831 apply_relocations (Filedata * filedata,
12832 const Elf_Internal_Shdr * section,
12833 unsigned char * start,
12834 bfd_size_type size,
12835 void ** relocs_return,
12836 unsigned long * num_relocs_return)
12838 Elf_Internal_Shdr * relsec;
12839 unsigned char * end = start + size;
12840 bfd_boolean res = TRUE;
12842 if (relocs_return != NULL)
12844 * (Elf_Internal_Rela **) relocs_return = NULL;
12845 * num_relocs_return = 0;
12848 if (filedata->file_header.e_type != ET_REL)
12849 /* No relocs to apply. */
12852 /* Find the reloc section associated with the section. */
12853 for (relsec = filedata->section_headers;
12854 relsec < filedata->section_headers + filedata->file_header.e_shnum;
12857 bfd_boolean is_rela;
12858 unsigned long num_relocs;
12859 Elf_Internal_Rela * relocs;
12860 Elf_Internal_Rela * rp;
12861 Elf_Internal_Shdr * symsec;
12862 Elf_Internal_Sym * symtab;
12863 unsigned long num_syms;
12864 Elf_Internal_Sym * sym;
12866 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
12867 || relsec->sh_info >= filedata->file_header.e_shnum
12868 || filedata->section_headers + relsec->sh_info != section
12869 || relsec->sh_size == 0
12870 || relsec->sh_link >= filedata->file_header.e_shnum)
12873 is_rela = relsec->sh_type == SHT_RELA;
12877 if (!slurp_rela_relocs (filedata, relsec->sh_offset,
12878 relsec->sh_size, & relocs, & num_relocs))
12883 if (!slurp_rel_relocs (filedata, relsec->sh_offset,
12884 relsec->sh_size, & relocs, & num_relocs))
12888 /* SH uses RELA but uses in place value instead of the addend field. */
12889 if (filedata->file_header.e_machine == EM_SH)
12892 symsec = filedata->section_headers + relsec->sh_link;
12893 if (symsec->sh_type != SHT_SYMTAB
12894 && symsec->sh_type != SHT_DYNSYM)
12896 symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms);
12898 for (rp = relocs; rp < relocs + num_relocs; ++rp)
12901 unsigned int reloc_type;
12902 unsigned int reloc_size;
12903 bfd_boolean reloc_inplace = FALSE;
12904 bfd_boolean reloc_subtract = FALSE;
12905 unsigned char * rloc;
12906 unsigned long sym_index;
12908 reloc_type = get_reloc_type (filedata, rp->r_info);
12910 if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms))
12912 else if (is_none_reloc (filedata, reloc_type))
12914 else if (is_32bit_abs_reloc (filedata, reloc_type)
12915 || is_32bit_pcrel_reloc (filedata, reloc_type))
12917 else if (is_64bit_abs_reloc (filedata, reloc_type)
12918 || is_64bit_pcrel_reloc (filedata, reloc_type))
12920 else if (is_24bit_abs_reloc (filedata, reloc_type))
12922 else if (is_16bit_abs_reloc (filedata, reloc_type))
12924 else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata,
12926 || is_32bit_inplace_add_reloc (filedata, reloc_type))
12929 reloc_inplace = TRUE;
12931 else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata,
12933 || is_64bit_inplace_add_reloc (filedata, reloc_type))
12936 reloc_inplace = TRUE;
12938 else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata,
12940 || is_16bit_inplace_add_reloc (filedata, reloc_type))
12943 reloc_inplace = TRUE;
12945 else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata,
12947 || is_8bit_inplace_add_reloc (filedata, reloc_type))
12950 reloc_inplace = TRUE;
12954 static unsigned int prev_reloc = 0;
12956 if (reloc_type != prev_reloc)
12957 warn (_("unable to apply unsupported reloc type %d to section %s\n"),
12958 reloc_type, printable_section_name (filedata, section));
12959 prev_reloc = reloc_type;
12964 rloc = start + rp->r_offset;
12965 if ((rloc + reloc_size) > end || (rloc < start))
12967 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
12968 (unsigned long) rp->r_offset,
12969 printable_section_name (filedata, section));
12974 sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
12975 if (sym_index >= num_syms)
12977 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
12978 sym_index, printable_section_name (filedata, section));
12982 sym = symtab + sym_index;
12984 /* If the reloc has a symbol associated with it,
12985 make sure that it is of an appropriate type.
12987 Relocations against symbols without type can happen.
12988 Gcc -feliminate-dwarf2-dups may generate symbols
12989 without type for debug info.
12991 Icc generates relocations against function symbols
12992 instead of local labels.
12994 Relocations against object symbols can happen, eg when
12995 referencing a global array. For an example of this see
12996 the _clz.o binary in libgcc.a. */
12998 && ELF_ST_TYPE (sym->st_info) != STT_COMMON
12999 && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
13001 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
13002 get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)),
13003 printable_section_name (filedata, relsec),
13004 (long int)(rp - relocs));
13011 addend += rp->r_addend;
13012 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
13013 partial_inplace. */
13015 || (filedata->file_header.e_machine == EM_XTENSA
13016 && reloc_type == 1)
13017 || ((filedata->file_header.e_machine == EM_PJ
13018 || filedata->file_header.e_machine == EM_PJ_OLD)
13019 && reloc_type == 1)
13020 || ((filedata->file_header.e_machine == EM_D30V
13021 || filedata->file_header.e_machine == EM_CYGNUS_D30V)
13022 && reloc_type == 12)
13024 addend += byte_get (rloc, reloc_size);
13026 if (is_32bit_pcrel_reloc (filedata, reloc_type)
13027 || is_64bit_pcrel_reloc (filedata, reloc_type))
13029 /* On HPPA, all pc-relative relocations are biased by 8. */
13030 if (filedata->file_header.e_machine == EM_PARISC)
13032 byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
13035 else if (reloc_subtract)
13036 byte_put (rloc, addend - sym->st_value, reloc_size);
13038 byte_put (rloc, addend + sym->st_value, reloc_size);
13042 /* Let the target specific reloc processing code know that
13043 we have finished with these relocs. */
13044 target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0);
13048 * (Elf_Internal_Rela **) relocs_return = relocs;
13049 * num_relocs_return = num_relocs;
13060 #ifdef SUPPORT_DISASSEMBLY
13062 disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata)
13064 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section));
13066 /* FIXME: XXX -- to be done --- XXX */
13072 /* Reads in the contents of SECTION from FILE, returning a pointer
13073 to a malloc'ed buffer or NULL if something went wrong. */
13076 get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata)
13078 bfd_size_type num_bytes = section->sh_size;
13080 if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
13082 printf (_("Section '%s' has no data to dump.\n"),
13083 printable_section_name (filedata, section));
13087 return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes,
13088 _("section contents"));
13091 /* Uncompresses a section that was compressed using zlib, in place. */
13094 uncompress_section_contents (unsigned char ** buffer,
13095 dwarf_size_type uncompressed_size,
13096 dwarf_size_type * size)
13098 dwarf_size_type compressed_size = *size;
13099 unsigned char * compressed_buffer = *buffer;
13100 unsigned char * uncompressed_buffer;
13104 /* It is possible the section consists of several compressed
13105 buffers concatenated together, so we uncompress in a loop. */
13106 /* PR 18313: The state field in the z_stream structure is supposed
13107 to be invisible to the user (ie us), but some compilers will
13108 still complain about it being used without initialisation. So
13109 we first zero the entire z_stream structure and then set the fields
13111 memset (& strm, 0, sizeof strm);
13112 strm.avail_in = compressed_size;
13113 strm.next_in = (Bytef *) compressed_buffer;
13114 strm.avail_out = uncompressed_size;
13115 uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
13117 rc = inflateInit (& strm);
13118 while (strm.avail_in > 0)
13122 strm.next_out = ((Bytef *) uncompressed_buffer
13123 + (uncompressed_size - strm.avail_out));
13124 rc = inflate (&strm, Z_FINISH);
13125 if (rc != Z_STREAM_END)
13127 rc = inflateReset (& strm);
13129 rc = inflateEnd (& strm);
13131 || strm.avail_out != 0)
13134 *buffer = uncompressed_buffer;
13135 *size = uncompressed_size;
13139 free (uncompressed_buffer);
13140 /* Indicate decompression failure. */
13146 dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
13148 Elf_Internal_Shdr * relsec;
13149 bfd_size_type num_bytes;
13150 unsigned char * data;
13151 unsigned char * end;
13152 unsigned char * real_start;
13153 unsigned char * start;
13154 bfd_boolean some_strings_shown;
13156 real_start = start = (unsigned char *) get_section_contents (section, filedata);
13158 /* PR 21820: Do not fail if the section was empty. */
13159 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
13161 num_bytes = section->sh_size;
13163 printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata, section));
13165 if (decompress_dumps)
13167 dwarf_size_type new_size = num_bytes;
13168 dwarf_size_type uncompressed_size = 0;
13170 if ((section->sh_flags & SHF_COMPRESSED) != 0)
13172 Elf_Internal_Chdr chdr;
13173 unsigned int compression_header_size
13174 = get_compression_header (& chdr, (unsigned char *) start,
13177 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
13179 warn (_("section '%s' has unsupported compress type: %d\n"),
13180 printable_section_name (filedata, section), chdr.ch_type);
13183 else if (chdr.ch_addralign != section->sh_addralign)
13185 warn (_("compressed section '%s' is corrupted\n"),
13186 printable_section_name (filedata, section));
13189 uncompressed_size = chdr.ch_size;
13190 start += compression_header_size;
13191 new_size -= compression_header_size;
13193 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
13195 /* Read the zlib header. In this case, it should be "ZLIB"
13196 followed by the uncompressed section size, 8 bytes in
13197 big-endian order. */
13198 uncompressed_size = start[4]; uncompressed_size <<= 8;
13199 uncompressed_size += start[5]; uncompressed_size <<= 8;
13200 uncompressed_size += start[6]; uncompressed_size <<= 8;
13201 uncompressed_size += start[7]; uncompressed_size <<= 8;
13202 uncompressed_size += start[8]; uncompressed_size <<= 8;
13203 uncompressed_size += start[9]; uncompressed_size <<= 8;
13204 uncompressed_size += start[10]; uncompressed_size <<= 8;
13205 uncompressed_size += start[11];
13210 if (uncompressed_size)
13212 if (uncompress_section_contents (& start,
13213 uncompressed_size, & new_size))
13214 num_bytes = new_size;
13217 error (_("Unable to decompress section %s\n"),
13218 printable_section_name (filedata, section));
13223 start = real_start;
13226 /* If the section being dumped has relocations against it the user might
13227 be expecting these relocations to have been applied. Check for this
13228 case and issue a warning message in order to avoid confusion.
13229 FIXME: Maybe we ought to have an option that dumps a section with
13230 relocs applied ? */
13231 for (relsec = filedata->section_headers;
13232 relsec < filedata->section_headers + filedata->file_header.e_shnum;
13235 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
13236 || relsec->sh_info >= filedata->file_header.e_shnum
13237 || filedata->section_headers + relsec->sh_info != section
13238 || relsec->sh_size == 0
13239 || relsec->sh_link >= filedata->file_header.e_shnum)
13242 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13247 end = start + num_bytes;
13248 some_strings_shown = FALSE;
13252 while (!ISPRINT (* data))
13253 if (++ data >= end)
13258 size_t maxlen = end - data;
13261 /* PR 11128: Use two separate invocations in order to work
13262 around bugs in the Solaris 8 implementation of printf. */
13263 printf (" [%6tx] ", data - start);
13265 printf (" [%6Ix] ", (size_t) (data - start));
13269 print_symbol ((int) maxlen, (const char *) data);
13271 data += strnlen ((const char *) data, maxlen);
13275 printf (_("<corrupt>\n"));
13278 some_strings_shown = TRUE;
13282 if (! some_strings_shown)
13283 printf (_(" No strings found in this section."));
13292 dump_section_as_bytes (Elf_Internal_Shdr * section,
13293 Filedata * filedata,
13294 bfd_boolean relocate)
13296 Elf_Internal_Shdr * relsec;
13297 bfd_size_type bytes;
13298 bfd_size_type section_size;
13300 unsigned char * data;
13301 unsigned char * real_start;
13302 unsigned char * start;
13304 real_start = start = (unsigned char *) get_section_contents (section, filedata);
13306 /* PR 21820: Do not fail if the section was empty. */
13307 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
13309 section_size = section->sh_size;
13311 printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata, section));
13313 if (decompress_dumps)
13315 dwarf_size_type new_size = section_size;
13316 dwarf_size_type uncompressed_size = 0;
13318 if ((section->sh_flags & SHF_COMPRESSED) != 0)
13320 Elf_Internal_Chdr chdr;
13321 unsigned int compression_header_size
13322 = get_compression_header (& chdr, start, section_size);
13324 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
13326 warn (_("section '%s' has unsupported compress type: %d\n"),
13327 printable_section_name (filedata, section), chdr.ch_type);
13330 else if (chdr.ch_addralign != section->sh_addralign)
13332 warn (_("compressed section '%s' is corrupted\n"),
13333 printable_section_name (filedata, section));
13336 uncompressed_size = chdr.ch_size;
13337 start += compression_header_size;
13338 new_size -= compression_header_size;
13340 else if (new_size > 12 && streq ((char *) start, "ZLIB"))
13342 /* Read the zlib header. In this case, it should be "ZLIB"
13343 followed by the uncompressed section size, 8 bytes in
13344 big-endian order. */
13345 uncompressed_size = start[4]; uncompressed_size <<= 8;
13346 uncompressed_size += start[5]; uncompressed_size <<= 8;
13347 uncompressed_size += start[6]; uncompressed_size <<= 8;
13348 uncompressed_size += start[7]; uncompressed_size <<= 8;
13349 uncompressed_size += start[8]; uncompressed_size <<= 8;
13350 uncompressed_size += start[9]; uncompressed_size <<= 8;
13351 uncompressed_size += start[10]; uncompressed_size <<= 8;
13352 uncompressed_size += start[11];
13357 if (uncompressed_size)
13359 if (uncompress_section_contents (& start, uncompressed_size,
13362 section_size = new_size;
13366 error (_("Unable to decompress section %s\n"),
13367 printable_section_name (filedata, section));
13368 /* FIXME: Print the section anyway ? */
13373 start = real_start;
13378 if (! apply_relocations (filedata, section, start, section_size, NULL, NULL))
13383 /* If the section being dumped has relocations against it the user might
13384 be expecting these relocations to have been applied. Check for this
13385 case and issue a warning message in order to avoid confusion.
13386 FIXME: Maybe we ought to have an option that dumps a section with
13387 relocs applied ? */
13388 for (relsec = filedata->section_headers;
13389 relsec < filedata->section_headers + filedata->file_header.e_shnum;
13392 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
13393 || relsec->sh_info >= filedata->file_header.e_shnum
13394 || filedata->section_headers + relsec->sh_info != section
13395 || relsec->sh_size == 0
13396 || relsec->sh_link >= filedata->file_header.e_shnum)
13399 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
13404 addr = section->sh_addr;
13405 bytes = section_size;
13414 lbytes = (bytes > 16 ? 16 : bytes);
13416 printf (" 0x%8.8lx ", (unsigned long) addr);
13418 for (j = 0; j < 16; j++)
13421 printf ("%2.2x", data[j]);
13429 for (j = 0; j < lbytes; j++)
13432 if (k >= ' ' && k < 0x7f)
13452 load_specific_debug_section (enum dwarf_section_display_enum debug,
13453 const Elf_Internal_Shdr * sec,
13456 struct dwarf_section * section = &debug_displays [debug].section;
13458 Filedata * filedata = (Filedata *) data;
13460 if (section->start != NULL)
13462 /* If it is already loaded, do nothing. */
13463 if (streq (section->filename, filedata->file_name))
13465 free (section->start);
13468 snprintf (buf, sizeof (buf), _("%s section data"), section->name);
13469 section->address = sec->sh_addr;
13470 section->user_data = NULL;
13471 section->filename = filedata->file_name;
13472 section->start = (unsigned char *) get_data (NULL, filedata,
13474 sec->sh_size, buf);
13475 if (section->start == NULL)
13479 unsigned char *start = section->start;
13480 dwarf_size_type size = sec->sh_size;
13481 dwarf_size_type uncompressed_size = 0;
13483 if ((sec->sh_flags & SHF_COMPRESSED) != 0)
13485 Elf_Internal_Chdr chdr;
13486 unsigned int compression_header_size;
13488 if (size < (is_32bit_elf
13489 ? sizeof (Elf32_External_Chdr)
13490 : sizeof (Elf64_External_Chdr)))
13492 warn (_("compressed section %s is too small to contain a compression header"),
13497 compression_header_size = get_compression_header (&chdr, start, size);
13499 if (chdr.ch_type != ELFCOMPRESS_ZLIB)
13501 warn (_("section '%s' has unsupported compress type: %d\n"),
13502 section->name, chdr.ch_type);
13505 else if (chdr.ch_addralign != sec->sh_addralign)
13507 warn (_("compressed section '%s' is corrupted\n"),
13511 uncompressed_size = chdr.ch_size;
13512 start += compression_header_size;
13513 size -= compression_header_size;
13515 else if (size > 12 && streq ((char *) start, "ZLIB"))
13517 /* Read the zlib header. In this case, it should be "ZLIB"
13518 followed by the uncompressed section size, 8 bytes in
13519 big-endian order. */
13520 uncompressed_size = start[4]; uncompressed_size <<= 8;
13521 uncompressed_size += start[5]; uncompressed_size <<= 8;
13522 uncompressed_size += start[6]; uncompressed_size <<= 8;
13523 uncompressed_size += start[7]; uncompressed_size <<= 8;
13524 uncompressed_size += start[8]; uncompressed_size <<= 8;
13525 uncompressed_size += start[9]; uncompressed_size <<= 8;
13526 uncompressed_size += start[10]; uncompressed_size <<= 8;
13527 uncompressed_size += start[11];
13532 if (uncompressed_size)
13534 if (uncompress_section_contents (&start, uncompressed_size,
13537 /* Free the compressed buffer, update the section buffer
13538 and the section size if uncompress is successful. */
13539 free (section->start);
13540 section->start = start;
13544 error (_("Unable to decompress section %s\n"),
13545 printable_section_name (filedata, sec));
13550 section->size = size;
13553 if (section->start == NULL)
13556 if (debug_displays [debug].relocate)
13558 if (! apply_relocations (filedata, sec, section->start, section->size,
13559 & section->reloc_info, & section->num_relocs))
13564 section->reloc_info = NULL;
13565 section->num_relocs = 0;
13571 /* If this is not NULL, load_debug_section will only look for sections
13572 within the list of sections given here. */
13573 static unsigned int * section_subset = NULL;
13576 load_debug_section (enum dwarf_section_display_enum debug, void * data)
13578 struct dwarf_section * section = &debug_displays [debug].section;
13579 Elf_Internal_Shdr * sec;
13580 Filedata * filedata = (Filedata *) data;
13582 /* Without section headers we cannot find any sections. */
13583 if (filedata->section_headers == NULL)
13586 if (filedata->string_table == NULL
13587 && filedata->file_header.e_shstrndx != SHN_UNDEF
13588 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
13590 Elf_Internal_Shdr * strs;
13592 /* Read in the string table, so that we have section names to scan. */
13593 strs = filedata->section_headers + filedata->file_header.e_shstrndx;
13595 if (strs != NULL && strs->sh_size != 0)
13597 filedata->string_table
13598 = (char *) get_data (NULL, filedata, strs->sh_offset,
13599 1, strs->sh_size, _("string table"));
13601 filedata->string_table_length
13602 = filedata->string_table != NULL ? strs->sh_size : 0;
13606 /* Locate the debug section. */
13607 sec = find_section_in_set (filedata, section->uncompressed_name, section_subset);
13609 section->name = section->uncompressed_name;
13612 sec = find_section_in_set (filedata, section->compressed_name, section_subset);
13614 section->name = section->compressed_name;
13619 /* If we're loading from a subset of sections, and we've loaded
13620 a section matching this name before, it's likely that it's a
13622 if (section_subset != NULL)
13623 free_debug_section (debug);
13625 return load_specific_debug_section (debug, sec, data);
13629 free_debug_section (enum dwarf_section_display_enum debug)
13631 struct dwarf_section * section = &debug_displays [debug].section;
13633 if (section->start == NULL)
13636 free ((char *) section->start);
13637 section->start = NULL;
13638 section->address = 0;
13643 display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata)
13645 char * name = SECTION_NAME (section);
13646 const char * print_name = printable_section_name (filedata, section);
13647 bfd_size_type length;
13648 bfd_boolean result = TRUE;
13651 length = section->sh_size;
13654 printf (_("\nSection '%s' has no debugging data.\n"), print_name);
13657 if (section->sh_type == SHT_NOBITS)
13659 /* There is no point in dumping the contents of a debugging section
13660 which has the NOBITS type - the bits in the file will be random.
13661 This can happen when a file containing a .eh_frame section is
13662 stripped with the --only-keep-debug command line option. */
13663 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
13668 if (const_strneq (name, ".gnu.linkonce.wi."))
13669 name = ".debug_info";
13671 /* See if we know how to display the contents of this section. */
13672 for (i = 0; i < max; i++)
13674 enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i;
13675 struct dwarf_section_display * display = debug_displays + i;
13676 struct dwarf_section * sec = & display->section;
13678 if (streq (sec->uncompressed_name, name)
13679 || (id == line && const_strneq (name, ".debug_line."))
13680 || streq (sec->compressed_name, name))
13682 bfd_boolean secondary = (section != find_section (filedata, name));
13685 free_debug_section (id);
13687 if (i == line && const_strneq (name, ".debug_line."))
13689 else if (streq (sec->uncompressed_name, name))
13690 sec->name = sec->uncompressed_name;
13692 sec->name = sec->compressed_name;
13694 if (load_specific_debug_section (id, section, filedata))
13696 /* If this debug section is part of a CU/TU set in a .dwp file,
13697 restrict load_debug_section to the sections in that set. */
13698 section_subset = find_cu_tu_set (filedata, shndx);
13700 result &= display->display (sec, filedata);
13702 section_subset = NULL;
13704 if (secondary || (id != info && id != abbrev))
13705 free_debug_section (id);
13713 printf (_("Unrecognized debug section: %s\n"), print_name);
13720 /* Set DUMP_SECTS for all sections where dumps were requested
13721 based on section name. */
13724 initialise_dumps_byname (Filedata * filedata)
13726 struct dump_list_entry * cur;
13728 for (cur = dump_sects_byname; cur; cur = cur->next)
13731 bfd_boolean any = FALSE;
13733 for (i = 0; i < filedata->file_header.e_shnum; i++)
13734 if (streq (SECTION_NAME (filedata->section_headers + i), cur->name))
13736 request_dump_bynumber (filedata, i, cur->type);
13741 warn (_("Section '%s' was not dumped because it does not exist!\n"),
13747 process_section_contents (Filedata * filedata)
13749 Elf_Internal_Shdr * section;
13751 bfd_boolean res = TRUE;
13756 initialise_dumps_byname (filedata);
13758 for (i = 0, section = filedata->section_headers;
13759 i < filedata->file_header.e_shnum && i < filedata->num_dump_sects;
13762 dump_type dump = filedata->dump_sects[i];
13764 #ifdef SUPPORT_DISASSEMBLY
13765 if (dump & DISASS_DUMP)
13767 if (! disassemble_section (section, filedata))
13771 if (dump & HEX_DUMP)
13773 if (! dump_section_as_bytes (section, filedata, FALSE))
13777 if (dump & RELOC_DUMP)
13779 if (! dump_section_as_bytes (section, filedata, TRUE))
13783 if (dump & STRING_DUMP)
13785 if (! dump_section_as_strings (section, filedata))
13789 if (dump & DEBUG_DUMP)
13791 if (! display_debug_section (i, section, filedata))
13796 /* Check to see if the user requested a
13797 dump of a section that does not exist. */
13798 while (i < filedata->num_dump_sects)
13800 if (filedata->dump_sects[i])
13802 warn (_("Section %d was not dumped because it does not exist!\n"), i);
13812 process_mips_fpe_exception (int mask)
13816 bfd_boolean first = TRUE;
13818 if (mask & OEX_FPU_INEX)
13819 fputs ("INEX", stdout), first = FALSE;
13820 if (mask & OEX_FPU_UFLO)
13821 printf ("%sUFLO", first ? "" : "|"), first = FALSE;
13822 if (mask & OEX_FPU_OFLO)
13823 printf ("%sOFLO", first ? "" : "|"), first = FALSE;
13824 if (mask & OEX_FPU_DIV0)
13825 printf ("%sDIV0", first ? "" : "|"), first = FALSE;
13826 if (mask & OEX_FPU_INVAL)
13827 printf ("%sINVAL", first ? "" : "|");
13830 fputs ("0", stdout);
13833 /* Display's the value of TAG at location P. If TAG is
13834 greater than 0 it is assumed to be an unknown tag, and
13835 a message is printed to this effect. Otherwise it is
13836 assumed that a message has already been printed.
13838 If the bottom bit of TAG is set it assumed to have a
13839 string value, otherwise it is assumed to have an integer
13842 Returns an updated P pointing to the first unread byte
13843 beyond the end of TAG's value.
13845 Reads at or beyond END will not be made. */
13847 static unsigned char *
13848 display_tag_value (signed int tag,
13850 const unsigned char * const end)
13855 printf (" Tag_unknown_%d: ", tag);
13859 warn (_("<corrupt tag>\n"));
13863 /* PR 17531 file: 027-19978-0.004. */
13864 size_t maxlen = (end - p) - 1;
13869 print_symbol ((int) maxlen, (const char *) p);
13870 p += strnlen ((char *) p, maxlen) + 1;
13874 printf (_("<corrupt string tag>"));
13875 p = (unsigned char *) end;
13883 val = read_uleb128 (p, &len, end);
13885 printf ("%ld (0x%lx)\n", val, val);
13892 /* ARC ABI attributes section. */
13894 static unsigned char *
13895 display_arc_attribute (unsigned char * p,
13896 const unsigned char * const end)
13902 tag = read_uleb128 (p, &len, end);
13907 case Tag_ARC_PCS_config:
13908 val = read_uleb128 (p, &len, end);
13910 printf (" Tag_ARC_PCS_config: ");
13914 printf (_("Absent/Non standard\n"));
13917 printf (_("Bare metal/mwdt\n"));
13920 printf (_("Bare metal/newlib\n"));
13923 printf (_("Linux/uclibc\n"));
13926 printf (_("Linux/glibc\n"));
13929 printf (_("Unknown\n"));
13934 case Tag_ARC_CPU_base:
13935 val = read_uleb128 (p, &len, end);
13937 printf (" Tag_ARC_CPU_base: ");
13942 printf (_("Absent\n"));
13944 case TAG_CPU_ARC6xx:
13945 printf ("ARC6xx\n");
13947 case TAG_CPU_ARC7xx:
13948 printf ("ARC7xx\n");
13950 case TAG_CPU_ARCEM:
13951 printf ("ARCEM\n");
13953 case TAG_CPU_ARCHS:
13954 printf ("ARCHS\n");
13959 case Tag_ARC_CPU_variation:
13960 val = read_uleb128 (p, &len, end);
13962 printf (" Tag_ARC_CPU_variation: ");
13966 if (val > 0 && val < 16)
13967 printf ("Core%d\n", val);
13969 printf ("Unknown\n");
13973 printf (_("Absent\n"));
13978 case Tag_ARC_CPU_name:
13979 printf (" Tag_ARC_CPU_name: ");
13980 p = display_tag_value (-1, p, end);
13983 case Tag_ARC_ABI_rf16:
13984 val = read_uleb128 (p, &len, end);
13986 printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no"));
13989 case Tag_ARC_ABI_osver:
13990 val = read_uleb128 (p, &len, end);
13992 printf (" Tag_ARC_ABI_osver: v%d\n", val);
13995 case Tag_ARC_ABI_pic:
13996 case Tag_ARC_ABI_sda:
13997 val = read_uleb128 (p, &len, end);
13999 printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: "
14000 : " Tag_ARC_ABI_pic: ");
14004 printf (_("Absent\n"));
14013 printf (_("Unknown\n"));
14018 case Tag_ARC_ABI_tls:
14019 val = read_uleb128 (p, &len, end);
14021 printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none");
14024 case Tag_ARC_ABI_enumsize:
14025 val = read_uleb128 (p, &len, end);
14027 printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") :
14031 case Tag_ARC_ABI_exceptions:
14032 val = read_uleb128 (p, &len, end);
14034 printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP")
14038 case Tag_ARC_ABI_double_size:
14039 val = read_uleb128 (p, &len, end);
14041 printf (" Tag_ARC_ABI_double_size: %d\n", val);
14044 case Tag_ARC_ISA_config:
14045 printf (" Tag_ARC_ISA_config: ");
14046 p = display_tag_value (-1, p, end);
14049 case Tag_ARC_ISA_apex:
14050 printf (" Tag_ARC_ISA_apex: ");
14051 p = display_tag_value (-1, p, end);
14054 case Tag_ARC_ISA_mpy_option:
14055 val = read_uleb128 (p, &len, end);
14057 printf (" Tag_ARC_ISA_mpy_option: %d\n", val);
14061 return display_tag_value (tag & 1, p, end);
14067 /* ARM EABI attributes section. */
14072 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
14074 const char ** table;
14075 } arm_attr_public_tag;
14077 static const char * arm_attr_tag_CPU_arch[] =
14078 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
14079 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
14081 static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
14082 static const char * arm_attr_tag_THUMB_ISA_use[] =
14083 {"No", "Thumb-1", "Thumb-2", "Yes"};
14084 static const char * arm_attr_tag_FP_arch[] =
14085 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
14086 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
14087 static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
14088 static const char * arm_attr_tag_Advanced_SIMD_arch[] =
14089 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
14090 "NEON for ARMv8.1"};
14091 static const char * arm_attr_tag_PCS_config[] =
14092 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
14093 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
14094 static const char * arm_attr_tag_ABI_PCS_R9_use[] =
14095 {"V6", "SB", "TLS", "Unused"};
14096 static const char * arm_attr_tag_ABI_PCS_RW_data[] =
14097 {"Absolute", "PC-relative", "SB-relative", "None"};
14098 static const char * arm_attr_tag_ABI_PCS_RO_data[] =
14099 {"Absolute", "PC-relative", "None"};
14100 static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
14101 {"None", "direct", "GOT-indirect"};
14102 static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
14103 {"None", "??? 1", "2", "??? 3", "4"};
14104 static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
14105 static const char * arm_attr_tag_ABI_FP_denormal[] =
14106 {"Unused", "Needed", "Sign only"};
14107 static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
14108 static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
14109 static const char * arm_attr_tag_ABI_FP_number_model[] =
14110 {"Unused", "Finite", "RTABI", "IEEE 754"};
14111 static const char * arm_attr_tag_ABI_enum_size[] =
14112 {"Unused", "small", "int", "forced to int"};
14113 static const char * arm_attr_tag_ABI_HardFP_use[] =
14114 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
14115 static const char * arm_attr_tag_ABI_VFP_args[] =
14116 {"AAPCS", "VFP registers", "custom", "compatible"};
14117 static const char * arm_attr_tag_ABI_WMMX_args[] =
14118 {"AAPCS", "WMMX registers", "custom"};
14119 static const char * arm_attr_tag_ABI_optimization_goals[] =
14120 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14121 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
14122 static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
14123 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
14124 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
14125 static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
14126 static const char * arm_attr_tag_FP_HP_extension[] =
14127 {"Not Allowed", "Allowed"};
14128 static const char * arm_attr_tag_ABI_FP_16bit_format[] =
14129 {"None", "IEEE 754", "Alternative Format"};
14130 static const char * arm_attr_tag_DSP_extension[] =
14131 {"Follow architecture", "Allowed"};
14132 static const char * arm_attr_tag_MPextension_use[] =
14133 {"Not Allowed", "Allowed"};
14134 static const char * arm_attr_tag_DIV_use[] =
14135 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
14136 "Allowed in v7-A with integer division extension"};
14137 static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
14138 static const char * arm_attr_tag_Virtualization_use[] =
14139 {"Not Allowed", "TrustZone", "Virtualization Extensions",
14140 "TrustZone and Virtualization Extensions"};
14141 static const char * arm_attr_tag_MPextension_use_legacy[] =
14142 {"Not Allowed", "Allowed"};
14144 #define LOOKUP(id, name) \
14145 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
14146 static arm_attr_public_tag arm_attr_public_tags[] =
14148 {4, "CPU_raw_name", 1, NULL},
14149 {5, "CPU_name", 1, NULL},
14150 LOOKUP(6, CPU_arch),
14151 {7, "CPU_arch_profile", 0, NULL},
14152 LOOKUP(8, ARM_ISA_use),
14153 LOOKUP(9, THUMB_ISA_use),
14154 LOOKUP(10, FP_arch),
14155 LOOKUP(11, WMMX_arch),
14156 LOOKUP(12, Advanced_SIMD_arch),
14157 LOOKUP(13, PCS_config),
14158 LOOKUP(14, ABI_PCS_R9_use),
14159 LOOKUP(15, ABI_PCS_RW_data),
14160 LOOKUP(16, ABI_PCS_RO_data),
14161 LOOKUP(17, ABI_PCS_GOT_use),
14162 LOOKUP(18, ABI_PCS_wchar_t),
14163 LOOKUP(19, ABI_FP_rounding),
14164 LOOKUP(20, ABI_FP_denormal),
14165 LOOKUP(21, ABI_FP_exceptions),
14166 LOOKUP(22, ABI_FP_user_exceptions),
14167 LOOKUP(23, ABI_FP_number_model),
14168 {24, "ABI_align_needed", 0, NULL},
14169 {25, "ABI_align_preserved", 0, NULL},
14170 LOOKUP(26, ABI_enum_size),
14171 LOOKUP(27, ABI_HardFP_use),
14172 LOOKUP(28, ABI_VFP_args),
14173 LOOKUP(29, ABI_WMMX_args),
14174 LOOKUP(30, ABI_optimization_goals),
14175 LOOKUP(31, ABI_FP_optimization_goals),
14176 {32, "compatibility", 0, NULL},
14177 LOOKUP(34, CPU_unaligned_access),
14178 LOOKUP(36, FP_HP_extension),
14179 LOOKUP(38, ABI_FP_16bit_format),
14180 LOOKUP(42, MPextension_use),
14181 LOOKUP(44, DIV_use),
14182 LOOKUP(46, DSP_extension),
14183 {64, "nodefaults", 0, NULL},
14184 {65, "also_compatible_with", 0, NULL},
14185 LOOKUP(66, T2EE_use),
14186 {67, "conformance", 1, NULL},
14187 LOOKUP(68, Virtualization_use),
14188 LOOKUP(70, MPextension_use_legacy)
14192 static unsigned char *
14193 display_arm_attribute (unsigned char * p,
14194 const unsigned char * const end)
14199 arm_attr_public_tag * attr;
14203 tag = read_uleb128 (p, &len, end);
14206 for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
14208 if (arm_attr_public_tags[i].tag == tag)
14210 attr = &arm_attr_public_tags[i];
14217 printf (" Tag_%s: ", attr->name);
14218 switch (attr->type)
14223 case 7: /* Tag_CPU_arch_profile. */
14224 val = read_uleb128 (p, &len, end);
14228 case 0: printf (_("None\n")); break;
14229 case 'A': printf (_("Application\n")); break;
14230 case 'R': printf (_("Realtime\n")); break;
14231 case 'M': printf (_("Microcontroller\n")); break;
14232 case 'S': printf (_("Application or Realtime\n")); break;
14233 default: printf ("??? (%d)\n", val); break;
14237 case 24: /* Tag_align_needed. */
14238 val = read_uleb128 (p, &len, end);
14242 case 0: printf (_("None\n")); break;
14243 case 1: printf (_("8-byte\n")); break;
14244 case 2: printf (_("4-byte\n")); break;
14245 case 3: printf ("??? 3\n"); break;
14248 printf (_("8-byte and up to %d-byte extended\n"),
14251 printf ("??? (%d)\n", val);
14256 case 25: /* Tag_align_preserved. */
14257 val = read_uleb128 (p, &len, end);
14261 case 0: printf (_("None\n")); break;
14262 case 1: printf (_("8-byte, except leaf SP\n")); break;
14263 case 2: printf (_("8-byte\n")); break;
14264 case 3: printf ("??? 3\n"); break;
14267 printf (_("8-byte and up to %d-byte extended\n"),
14270 printf ("??? (%d)\n", val);
14275 case 32: /* Tag_compatibility. */
14277 val = read_uleb128 (p, &len, end);
14279 printf (_("flag = %d, vendor = "), val);
14282 size_t maxlen = (end - p) - 1;
14284 print_symbol ((int) maxlen, (const char *) p);
14285 p += strnlen ((char *) p, maxlen) + 1;
14289 printf (_("<corrupt>"));
14290 p = (unsigned char *) end;
14296 case 64: /* Tag_nodefaults. */
14297 /* PR 17531: file: 001-505008-0.01. */
14300 printf (_("True\n"));
14303 case 65: /* Tag_also_compatible_with. */
14304 val = read_uleb128 (p, &len, end);
14306 if (val == 6 /* Tag_CPU_arch. */)
14308 val = read_uleb128 (p, &len, end);
14310 if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
14311 printf ("??? (%d)\n", val);
14313 printf ("%s\n", arm_attr_tag_CPU_arch[val]);
14317 while (p < end && *(p++) != '\0' /* NUL terminator. */)
14322 printf (_("<unknown: %d>\n"), tag);
14328 return display_tag_value (-1, p, end);
14330 return display_tag_value (0, p, end);
14333 assert (attr->type & 0x80);
14334 val = read_uleb128 (p, &len, end);
14336 type = attr->type & 0x7f;
14338 printf ("??? (%d)\n", val);
14340 printf ("%s\n", attr->table[val]);
14345 return display_tag_value (tag, p, end);
14348 static unsigned char *
14349 display_gnu_attribute (unsigned char * p,
14350 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const),
14351 const unsigned char * const end)
14357 tag = read_uleb128 (p, &len, end);
14360 /* Tag_compatibility is the only generic GNU attribute defined at
14364 val = read_uleb128 (p, &len, end);
14367 printf (_("flag = %d, vendor = "), val);
14370 printf (_("<corrupt>\n"));
14371 warn (_("corrupt vendor attribute\n"));
14377 size_t maxlen = (end - p) - 1;
14379 print_symbol ((int) maxlen, (const char *) p);
14380 p += strnlen ((char *) p, maxlen) + 1;
14384 printf (_("<corrupt>"));
14385 p = (unsigned char *) end;
14392 if ((tag & 2) == 0 && display_proc_gnu_attribute)
14393 return display_proc_gnu_attribute (p, tag, end);
14395 return display_tag_value (tag, p, end);
14398 static unsigned char *
14399 display_power_gnu_attribute (unsigned char * p,
14401 const unsigned char * const end)
14406 if (tag == Tag_GNU_Power_ABI_FP)
14408 val = read_uleb128 (p, &len, end);
14410 printf (" Tag_GNU_Power_ABI_FP: ");
14413 printf (_("<corrupt>\n"));
14418 printf ("(%#x), ", val);
14423 printf (_("unspecified hard/soft float, "));
14426 printf (_("hard float, "));
14429 printf (_("soft float, "));
14432 printf (_("single-precision hard float, "));
14439 printf (_("unspecified long double\n"));
14442 printf (_("128-bit IBM long double\n"));
14445 printf (_("64-bit long double\n"));
14448 printf (_("128-bit IEEE long double\n"));
14454 if (tag == Tag_GNU_Power_ABI_Vector)
14456 val = read_uleb128 (p, &len, end);
14458 printf (" Tag_GNU_Power_ABI_Vector: ");
14461 printf (_("<corrupt>\n"));
14466 printf ("(%#x), ", val);
14471 printf (_("unspecified\n"));
14474 printf (_("generic\n"));
14477 printf ("AltiVec\n");
14486 if (tag == Tag_GNU_Power_ABI_Struct_Return)
14488 val = read_uleb128 (p, &len, end);
14490 printf (" Tag_GNU_Power_ABI_Struct_Return: ");
14493 printf (_("<corrupt>\n"));
14498 printf ("(%#x), ", val);
14503 printf (_("unspecified\n"));
14506 printf ("r3/r4\n");
14509 printf (_("memory\n"));
14518 return display_tag_value (tag & 1, p, end);
14521 static unsigned char *
14522 display_s390_gnu_attribute (unsigned char * p,
14524 const unsigned char * const end)
14529 if (tag == Tag_GNU_S390_ABI_Vector)
14531 val = read_uleb128 (p, &len, end);
14533 printf (" Tag_GNU_S390_ABI_Vector: ");
14538 printf (_("any\n"));
14541 printf (_("software\n"));
14544 printf (_("hardware\n"));
14547 printf ("??? (%d)\n", val);
14553 return display_tag_value (tag & 1, p, end);
14557 display_sparc_hwcaps (unsigned int mask)
14561 bfd_boolean first = TRUE;
14563 if (mask & ELF_SPARC_HWCAP_MUL32)
14564 fputs ("mul32", stdout), first = FALSE;
14565 if (mask & ELF_SPARC_HWCAP_DIV32)
14566 printf ("%sdiv32", first ? "" : "|"), first = FALSE;
14567 if (mask & ELF_SPARC_HWCAP_FSMULD)
14568 printf ("%sfsmuld", first ? "" : "|"), first = FALSE;
14569 if (mask & ELF_SPARC_HWCAP_V8PLUS)
14570 printf ("%sv8plus", first ? "" : "|"), first = FALSE;
14571 if (mask & ELF_SPARC_HWCAP_POPC)
14572 printf ("%spopc", first ? "" : "|"), first = FALSE;
14573 if (mask & ELF_SPARC_HWCAP_VIS)
14574 printf ("%svis", first ? "" : "|"), first = FALSE;
14575 if (mask & ELF_SPARC_HWCAP_VIS2)
14576 printf ("%svis2", first ? "" : "|"), first = FALSE;
14577 if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
14578 printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE;
14579 if (mask & ELF_SPARC_HWCAP_FMAF)
14580 printf ("%sfmaf", first ? "" : "|"), first = FALSE;
14581 if (mask & ELF_SPARC_HWCAP_VIS3)
14582 printf ("%svis3", first ? "" : "|"), first = FALSE;
14583 if (mask & ELF_SPARC_HWCAP_HPC)
14584 printf ("%shpc", first ? "" : "|"), first = FALSE;
14585 if (mask & ELF_SPARC_HWCAP_RANDOM)
14586 printf ("%srandom", first ? "" : "|"), first = FALSE;
14587 if (mask & ELF_SPARC_HWCAP_TRANS)
14588 printf ("%strans", first ? "" : "|"), first = FALSE;
14589 if (mask & ELF_SPARC_HWCAP_FJFMAU)
14590 printf ("%sfjfmau", first ? "" : "|"), first = FALSE;
14591 if (mask & ELF_SPARC_HWCAP_IMA)
14592 printf ("%sima", first ? "" : "|"), first = FALSE;
14593 if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
14594 printf ("%scspare", first ? "" : "|"), first = FALSE;
14597 fputc ('0', stdout);
14598 fputc ('\n', stdout);
14602 display_sparc_hwcaps2 (unsigned int mask)
14606 bfd_boolean first = TRUE;
14608 if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
14609 fputs ("fjathplus", stdout), first = FALSE;
14610 if (mask & ELF_SPARC_HWCAP2_VIS3B)
14611 printf ("%svis3b", first ? "" : "|"), first = FALSE;
14612 if (mask & ELF_SPARC_HWCAP2_ADP)
14613 printf ("%sadp", first ? "" : "|"), first = FALSE;
14614 if (mask & ELF_SPARC_HWCAP2_SPARC5)
14615 printf ("%ssparc5", first ? "" : "|"), first = FALSE;
14616 if (mask & ELF_SPARC_HWCAP2_MWAIT)
14617 printf ("%smwait", first ? "" : "|"), first = FALSE;
14618 if (mask & ELF_SPARC_HWCAP2_XMPMUL)
14619 printf ("%sxmpmul", first ? "" : "|"), first = FALSE;
14620 if (mask & ELF_SPARC_HWCAP2_XMONT)
14621 printf ("%sxmont2", first ? "" : "|"), first = FALSE;
14622 if (mask & ELF_SPARC_HWCAP2_NSEC)
14623 printf ("%snsec", first ? "" : "|"), first = FALSE;
14624 if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
14625 printf ("%sfjathhpc", first ? "" : "|"), first = FALSE;
14626 if (mask & ELF_SPARC_HWCAP2_FJDES)
14627 printf ("%sfjdes", first ? "" : "|"), first = FALSE;
14628 if (mask & ELF_SPARC_HWCAP2_FJAES)
14629 printf ("%sfjaes", first ? "" : "|"), first = FALSE;
14632 fputc ('0', stdout);
14633 fputc ('\n', stdout);
14636 static unsigned char *
14637 display_sparc_gnu_attribute (unsigned char * p,
14639 const unsigned char * const end)
14644 if (tag == Tag_GNU_Sparc_HWCAPS)
14646 val = read_uleb128 (p, &len, end);
14648 printf (" Tag_GNU_Sparc_HWCAPS: ");
14649 display_sparc_hwcaps (val);
14652 if (tag == Tag_GNU_Sparc_HWCAPS2)
14654 val = read_uleb128 (p, &len, end);
14656 printf (" Tag_GNU_Sparc_HWCAPS2: ");
14657 display_sparc_hwcaps2 (val);
14661 return display_tag_value (tag, p, end);
14665 print_mips_fp_abi_value (unsigned int val)
14669 case Val_GNU_MIPS_ABI_FP_ANY:
14670 printf (_("Hard or soft float\n"));
14672 case Val_GNU_MIPS_ABI_FP_DOUBLE:
14673 printf (_("Hard float (double precision)\n"));
14675 case Val_GNU_MIPS_ABI_FP_SINGLE:
14676 printf (_("Hard float (single precision)\n"));
14678 case Val_GNU_MIPS_ABI_FP_SOFT:
14679 printf (_("Soft float\n"));
14681 case Val_GNU_MIPS_ABI_FP_OLD_64:
14682 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
14684 case Val_GNU_MIPS_ABI_FP_XX:
14685 printf (_("Hard float (32-bit CPU, Any FPU)\n"));
14687 case Val_GNU_MIPS_ABI_FP_64:
14688 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
14690 case Val_GNU_MIPS_ABI_FP_64A:
14691 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
14693 case Val_GNU_MIPS_ABI_FP_NAN2008:
14694 printf (_("NaN 2008 compatibility\n"));
14697 printf ("??? (%d)\n", val);
14702 static unsigned char *
14703 display_mips_gnu_attribute (unsigned char * p,
14705 const unsigned char * const end)
14707 if (tag == Tag_GNU_MIPS_ABI_FP)
14712 val = read_uleb128 (p, &len, end);
14714 printf (" Tag_GNU_MIPS_ABI_FP: ");
14716 print_mips_fp_abi_value (val);
14721 if (tag == Tag_GNU_MIPS_ABI_MSA)
14726 val = read_uleb128 (p, &len, end);
14728 printf (" Tag_GNU_MIPS_ABI_MSA: ");
14732 case Val_GNU_MIPS_ABI_MSA_ANY:
14733 printf (_("Any MSA or not\n"));
14735 case Val_GNU_MIPS_ABI_MSA_128:
14736 printf (_("128-bit MSA\n"));
14739 printf ("??? (%d)\n", val);
14745 return display_tag_value (tag & 1, p, end);
14748 static unsigned char *
14749 display_tic6x_attribute (unsigned char * p,
14750 const unsigned char * const end)
14756 tag = read_uleb128 (p, &len, end);
14762 val = read_uleb128 (p, &len, end);
14764 printf (" Tag_ISA: ");
14768 case C6XABI_Tag_ISA_none:
14769 printf (_("None\n"));
14771 case C6XABI_Tag_ISA_C62X:
14774 case C6XABI_Tag_ISA_C67X:
14777 case C6XABI_Tag_ISA_C67XP:
14778 printf ("C67x+\n");
14780 case C6XABI_Tag_ISA_C64X:
14783 case C6XABI_Tag_ISA_C64XP:
14784 printf ("C64x+\n");
14786 case C6XABI_Tag_ISA_C674X:
14787 printf ("C674x\n");
14790 printf ("??? (%d)\n", val);
14795 case Tag_ABI_wchar_t:
14796 val = read_uleb128 (p, &len, end);
14798 printf (" Tag_ABI_wchar_t: ");
14802 printf (_("Not used\n"));
14805 printf (_("2 bytes\n"));
14808 printf (_("4 bytes\n"));
14811 printf ("??? (%d)\n", val);
14816 case Tag_ABI_stack_align_needed:
14817 val = read_uleb128 (p, &len, end);
14819 printf (" Tag_ABI_stack_align_needed: ");
14823 printf (_("8-byte\n"));
14826 printf (_("16-byte\n"));
14829 printf ("??? (%d)\n", val);
14834 case Tag_ABI_stack_align_preserved:
14835 val = read_uleb128 (p, &len, end);
14837 printf (" Tag_ABI_stack_align_preserved: ");
14841 printf (_("8-byte\n"));
14844 printf (_("16-byte\n"));
14847 printf ("??? (%d)\n", val);
14853 val = read_uleb128 (p, &len, end);
14855 printf (" Tag_ABI_DSBT: ");
14859 printf (_("DSBT addressing not used\n"));
14862 printf (_("DSBT addressing used\n"));
14865 printf ("??? (%d)\n", val);
14871 val = read_uleb128 (p, &len, end);
14873 printf (" Tag_ABI_PID: ");
14877 printf (_("Data addressing position-dependent\n"));
14880 printf (_("Data addressing position-independent, GOT near DP\n"));
14883 printf (_("Data addressing position-independent, GOT far from DP\n"));
14886 printf ("??? (%d)\n", val);
14892 val = read_uleb128 (p, &len, end);
14894 printf (" Tag_ABI_PIC: ");
14898 printf (_("Code addressing position-dependent\n"));
14901 printf (_("Code addressing position-independent\n"));
14904 printf ("??? (%d)\n", val);
14909 case Tag_ABI_array_object_alignment:
14910 val = read_uleb128 (p, &len, end);
14912 printf (" Tag_ABI_array_object_alignment: ");
14916 printf (_("8-byte\n"));
14919 printf (_("4-byte\n"));
14922 printf (_("16-byte\n"));
14925 printf ("??? (%d)\n", val);
14930 case Tag_ABI_array_object_align_expected:
14931 val = read_uleb128 (p, &len, end);
14933 printf (" Tag_ABI_array_object_align_expected: ");
14937 printf (_("8-byte\n"));
14940 printf (_("4-byte\n"));
14943 printf (_("16-byte\n"));
14946 printf ("??? (%d)\n", val);
14951 case Tag_ABI_compatibility:
14953 val = read_uleb128 (p, &len, end);
14955 printf (" Tag_ABI_compatibility: ");
14956 printf (_("flag = %d, vendor = "), val);
14959 size_t maxlen = (end - p) - 1;
14961 print_symbol ((int) maxlen, (const char *) p);
14962 p += strnlen ((char *) p, maxlen) + 1;
14966 printf (_("<corrupt>"));
14967 p = (unsigned char *) end;
14973 case Tag_ABI_conformance:
14975 printf (" Tag_ABI_conformance: \"");
14978 size_t maxlen = (end - p) - 1;
14980 print_symbol ((int) maxlen, (const char *) p);
14981 p += strnlen ((char *) p, maxlen) + 1;
14985 printf (_("<corrupt>"));
14986 p = (unsigned char *) end;
14993 return display_tag_value (tag, p, end);
14997 display_raw_attribute (unsigned char * p, unsigned char const * const end)
14999 unsigned long addr = 0;
15000 size_t bytes = end - p;
15007 int lbytes = (bytes > 16 ? 16 : bytes);
15009 printf (" 0x%8.8lx ", addr);
15011 for (j = 0; j < 16; j++)
15014 printf ("%2.2x", p[j]);
15022 for (j = 0; j < lbytes; j++)
15025 if (k >= ' ' && k < 0x7f)
15041 static unsigned char *
15042 display_msp430x_attribute (unsigned char * p,
15043 const unsigned char * const end)
15049 tag = read_uleb128 (p, & len, end);
15054 case OFBA_MSPABI_Tag_ISA:
15055 val = read_uleb128 (p, &len, end);
15057 printf (" Tag_ISA: ");
15060 case 0: printf (_("None\n")); break;
15061 case 1: printf (_("MSP430\n")); break;
15062 case 2: printf (_("MSP430X\n")); break;
15063 default: printf ("??? (%d)\n", val); break;
15067 case OFBA_MSPABI_Tag_Code_Model:
15068 val = read_uleb128 (p, &len, end);
15070 printf (" Tag_Code_Model: ");
15073 case 0: printf (_("None\n")); break;
15074 case 1: printf (_("Small\n")); break;
15075 case 2: printf (_("Large\n")); break;
15076 default: printf ("??? (%d)\n", val); break;
15080 case OFBA_MSPABI_Tag_Data_Model:
15081 val = read_uleb128 (p, &len, end);
15083 printf (" Tag_Data_Model: ");
15086 case 0: printf (_("None\n")); break;
15087 case 1: printf (_("Small\n")); break;
15088 case 2: printf (_("Large\n")); break;
15089 case 3: printf (_("Restricted Large\n")); break;
15090 default: printf ("??? (%d)\n", val); break;
15095 printf (_(" <unknown tag %d>: "), tag);
15102 size_t maxlen = (end - p) - 1;
15104 print_symbol ((int) maxlen, (const char *) p);
15105 p += strnlen ((char *) p, maxlen) + 1;
15109 printf (_("<corrupt>"));
15110 p = (unsigned char *) end;
15116 val = read_uleb128 (p, &len, end);
15118 printf ("%d (0x%x)\n", val, val);
15128 process_attributes (Filedata * filedata,
15129 const char * public_name,
15130 unsigned int proc_type,
15131 unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
15132 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))
15134 Elf_Internal_Shdr * sect;
15136 bfd_boolean res = TRUE;
15138 /* Find the section header so that we get the size. */
15139 for (i = 0, sect = filedata->section_headers;
15140 i < filedata->file_header.e_shnum;
15143 unsigned char * contents;
15146 if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
15149 contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1,
15150 sect->sh_size, _("attributes"));
15151 if (contents == NULL)
15158 /* The first character is the version of the attributes.
15159 Currently only version 1, (aka 'A') is recognised here. */
15162 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p);
15167 bfd_vma section_len;
15169 section_len = sect->sh_size - 1;
15172 while (section_len > 0)
15175 unsigned int namelen;
15176 bfd_boolean public_section;
15177 bfd_boolean gnu_section;
15179 if (section_len <= 4)
15181 error (_("Tag section ends prematurely\n"));
15185 attr_len = byte_get (p, 4);
15188 if (attr_len > section_len)
15190 error (_("Bad attribute length (%u > %u)\n"),
15191 (unsigned) attr_len, (unsigned) section_len);
15192 attr_len = section_len;
15195 /* PR 17531: file: 001-101425-0.004 */
15196 else if (attr_len < 5)
15198 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
15203 section_len -= attr_len;
15206 namelen = strnlen ((char *) p, attr_len) + 1;
15207 if (namelen == 0 || namelen >= attr_len)
15209 error (_("Corrupt attribute section name\n"));
15214 printf (_("Attribute Section: "));
15215 print_symbol (INT_MAX, (const char *) p);
15218 if (public_name && streq ((char *) p, public_name))
15219 public_section = TRUE;
15221 public_section = FALSE;
15223 if (streq ((char *) p, "gnu"))
15224 gnu_section = TRUE;
15226 gnu_section = FALSE;
15229 attr_len -= namelen;
15231 while (attr_len > 0 && p < contents + sect->sh_size)
15236 unsigned char * end;
15238 /* PR binutils/17531: Safe handling of corrupt files. */
15241 error (_("Unused bytes at end of section\n"));
15248 size = byte_get (p, 4);
15249 if (size > attr_len)
15251 error (_("Bad subsection length (%u > %u)\n"),
15252 (unsigned) size, (unsigned) attr_len);
15256 /* PR binutils/17531: Safe handling of corrupt files. */
15259 error (_("Bad subsection length (%u < 6)\n"),
15267 end = p + size - 1;
15268 assert (end <= contents + sect->sh_size);
15274 printf (_("File Attributes\n"));
15277 printf (_("Section Attributes:"));
15280 printf (_("Symbol Attributes:"));
15281 /* Fall through. */
15287 val = read_uleb128 (p, &j, end);
15291 printf (" %d", val);
15296 printf (_("Unknown tag: %d\n"), tag);
15297 public_section = FALSE;
15301 if (public_section && display_pub_attribute != NULL)
15304 p = display_pub_attribute (p, end);
15307 else if (gnu_section && display_proc_gnu_attribute != NULL)
15310 p = display_gnu_attribute (p,
15311 display_proc_gnu_attribute,
15317 printf (_(" Unknown attribute:\n"));
15318 display_raw_attribute (p, end);
15333 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
15334 Print the Address, Access and Initial fields of an entry at VMA ADDR
15335 and return the VMA of the next entry, or -1 if there was a problem.
15336 Does not read from DATA_END or beyond. */
15339 print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
15340 unsigned char * data_end)
15343 print_vma (addr, LONG_HEX);
15345 if (addr < pltgot + 0xfff0)
15346 printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
15348 printf ("%10s", "");
15351 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
15355 unsigned char * from = data + addr - pltgot;
15357 if (from + (is_32bit_elf ? 4 : 8) > data_end)
15359 warn (_("MIPS GOT entry extends beyond the end of available data\n"));
15360 printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
15361 return (bfd_vma) -1;
15365 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
15366 print_vma (entry, LONG_HEX);
15369 return addr + (is_32bit_elf ? 4 : 8);
15372 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
15373 PLTGOT. Print the Address and Initial fields of an entry at VMA
15374 ADDR and return the VMA of the next entry. */
15377 print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
15380 print_vma (addr, LONG_HEX);
15383 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
15388 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
15389 print_vma (entry, LONG_HEX);
15391 return addr + (is_32bit_elf ? 4 : 8);
15395 print_mips_ases (unsigned int mask)
15397 if (mask & AFL_ASE_DSP)
15398 fputs ("\n\tDSP ASE", stdout);
15399 if (mask & AFL_ASE_DSPR2)
15400 fputs ("\n\tDSP R2 ASE", stdout);
15401 if (mask & AFL_ASE_DSPR3)
15402 fputs ("\n\tDSP R3 ASE", stdout);
15403 if (mask & AFL_ASE_EVA)
15404 fputs ("\n\tEnhanced VA Scheme", stdout);
15405 if (mask & AFL_ASE_MCU)
15406 fputs ("\n\tMCU (MicroController) ASE", stdout);
15407 if (mask & AFL_ASE_MDMX)
15408 fputs ("\n\tMDMX ASE", stdout);
15409 if (mask & AFL_ASE_MIPS3D)
15410 fputs ("\n\tMIPS-3D ASE", stdout);
15411 if (mask & AFL_ASE_MT)
15412 fputs ("\n\tMT ASE", stdout);
15413 if (mask & AFL_ASE_SMARTMIPS)
15414 fputs ("\n\tSmartMIPS ASE", stdout);
15415 if (mask & AFL_ASE_VIRT)
15416 fputs ("\n\tVZ ASE", stdout);
15417 if (mask & AFL_ASE_MSA)
15418 fputs ("\n\tMSA ASE", stdout);
15419 if (mask & AFL_ASE_MIPS16)
15420 fputs ("\n\tMIPS16 ASE", stdout);
15421 if (mask & AFL_ASE_MICROMIPS)
15422 fputs ("\n\tMICROMIPS ASE", stdout);
15423 if (mask & AFL_ASE_XPA)
15424 fputs ("\n\tXPA ASE", stdout);
15425 if (mask & AFL_ASE_MIPS16E2)
15426 fputs ("\n\tMIPS16e2 ASE", stdout);
15428 fprintf (stdout, "\n\t%s", _("None"));
15429 else if ((mask & ~AFL_ASE_MASK) != 0)
15430 fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
15434 print_mips_isa_ext (unsigned int isa_ext)
15439 fputs (_("None"), stdout);
15442 fputs ("RMI XLR", stdout);
15444 case AFL_EXT_OCTEON3:
15445 fputs ("Cavium Networks Octeon3", stdout);
15447 case AFL_EXT_OCTEON2:
15448 fputs ("Cavium Networks Octeon2", stdout);
15450 case AFL_EXT_OCTEONP:
15451 fputs ("Cavium Networks OcteonP", stdout);
15453 case AFL_EXT_LOONGSON_3A:
15454 fputs ("Loongson 3A", stdout);
15456 case AFL_EXT_OCTEON:
15457 fputs ("Cavium Networks Octeon", stdout);
15460 fputs ("Toshiba R5900", stdout);
15463 fputs ("MIPS R4650", stdout);
15466 fputs ("LSI R4010", stdout);
15469 fputs ("NEC VR4100", stdout);
15472 fputs ("Toshiba R3900", stdout);
15474 case AFL_EXT_10000:
15475 fputs ("MIPS R10000", stdout);
15478 fputs ("Broadcom SB-1", stdout);
15481 fputs ("NEC VR4111/VR4181", stdout);
15484 fputs ("NEC VR4120", stdout);
15487 fputs ("NEC VR5400", stdout);
15490 fputs ("NEC VR5500", stdout);
15492 case AFL_EXT_LOONGSON_2E:
15493 fputs ("ST Microelectronics Loongson 2E", stdout);
15495 case AFL_EXT_LOONGSON_2F:
15496 fputs ("ST Microelectronics Loongson 2F", stdout);
15498 case AFL_EXT_INTERAPTIV_MR2:
15499 fputs ("Imagination interAptiv MR2", stdout);
15502 fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
15507 get_mips_reg_size (int reg_size)
15509 return (reg_size == AFL_REG_NONE) ? 0
15510 : (reg_size == AFL_REG_32) ? 32
15511 : (reg_size == AFL_REG_64) ? 64
15512 : (reg_size == AFL_REG_128) ? 128
15517 process_mips_specific (Filedata * filedata)
15519 Elf_Internal_Dyn * entry;
15520 Elf_Internal_Shdr *sect = NULL;
15521 size_t liblist_offset = 0;
15522 size_t liblistno = 0;
15523 size_t conflictsno = 0;
15524 size_t options_offset = 0;
15525 size_t conflicts_offset = 0;
15526 size_t pltrelsz = 0;
15528 bfd_vma pltgot = 0;
15529 bfd_vma mips_pltgot = 0;
15530 bfd_vma jmprel = 0;
15531 bfd_vma local_gotno = 0;
15532 bfd_vma gotsym = 0;
15533 bfd_vma symtabno = 0;
15534 bfd_boolean res = TRUE;
15536 if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
15537 display_mips_gnu_attribute))
15540 sect = find_section (filedata, ".MIPS.abiflags");
15544 Elf_External_ABIFlags_v0 *abiflags_ext;
15545 Elf_Internal_ABIFlags_v0 abiflags_in;
15547 if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
15549 error (_("Corrupt MIPS ABI Flags section.\n"));
15554 abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
15555 sect->sh_size, _("MIPS ABI Flags section"));
15558 abiflags_in.version = BYTE_GET (abiflags_ext->version);
15559 abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
15560 abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
15561 abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
15562 abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
15563 abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
15564 abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
15565 abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
15566 abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
15567 abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
15568 abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
15570 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
15571 printf ("\nISA: MIPS%d", abiflags_in.isa_level);
15572 if (abiflags_in.isa_rev > 1)
15573 printf ("r%d", abiflags_in.isa_rev);
15574 printf ("\nGPR size: %d",
15575 get_mips_reg_size (abiflags_in.gpr_size));
15576 printf ("\nCPR1 size: %d",
15577 get_mips_reg_size (abiflags_in.cpr1_size));
15578 printf ("\nCPR2 size: %d",
15579 get_mips_reg_size (abiflags_in.cpr2_size));
15580 fputs ("\nFP ABI: ", stdout);
15581 print_mips_fp_abi_value (abiflags_in.fp_abi);
15582 fputs ("ISA Extension: ", stdout);
15583 print_mips_isa_ext (abiflags_in.isa_ext);
15584 fputs ("\nASEs:", stdout);
15585 print_mips_ases (abiflags_in.ases);
15586 printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
15587 printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
15588 fputc ('\n', stdout);
15589 free (abiflags_ext);
15594 /* We have a lot of special sections. Thanks SGI! */
15595 if (dynamic_section == NULL)
15597 /* No dynamic information available. See if there is static GOT. */
15598 sect = find_section (filedata, ".got");
15601 unsigned char *data_end;
15602 unsigned char *data;
15606 pltgot = sect->sh_addr;
15609 addr_size = (is_32bit_elf ? 4 : 8);
15610 end = pltgot + sect->sh_size;
15612 data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset,
15614 _("Global Offset Table data"));
15615 /* PR 12855: Null data is handled gracefully throughout. */
15616 data_end = data + (end - pltgot);
15618 printf (_("\nStatic GOT:\n"));
15619 printf (_(" Canonical gp value: "));
15620 print_vma (ent + 0x7ff0, LONG_HEX);
15623 /* In a dynamic binary GOT[0] is reserved for the dynamic
15624 loader to store the lazy resolver pointer, however in
15625 a static binary it may well have been omitted and GOT
15626 reduced to a table of addresses.
15627 PR 21344: Check for the entry being fully available
15628 before fetching it. */
15630 && data + ent - pltgot + addr_size <= data_end
15631 && byte_get (data + ent - pltgot, addr_size) == 0)
15633 printf (_(" Reserved entries:\n"));
15634 printf (_(" %*s %10s %*s\n"),
15635 addr_size * 2, _("Address"), _("Access"),
15636 addr_size * 2, _("Value"));
15637 ent = print_mips_got_entry (data, pltgot, ent, data_end);
15639 if (ent == (bfd_vma) -1)
15640 goto sgot_print_fail;
15642 /* Check for the MSB of GOT[1] being set, identifying a
15643 GNU object. This entry will be used by some runtime
15644 loaders, to store the module pointer. Otherwise this
15645 is an ordinary local entry.
15646 PR 21344: Check for the entry being fully available
15647 before fetching it. */
15649 && data + ent - pltgot + addr_size <= data_end
15650 && (byte_get (data + ent - pltgot, addr_size)
15651 >> (addr_size * 8 - 1)) != 0)
15653 ent = print_mips_got_entry (data, pltgot, ent, data_end);
15655 if (ent == (bfd_vma) -1)
15656 goto sgot_print_fail;
15661 if (data != NULL && ent < end)
15663 printf (_(" Local entries:\n"));
15664 printf (" %*s %10s %*s\n",
15665 addr_size * 2, _("Address"), _("Access"),
15666 addr_size * 2, _("Value"));
15669 ent = print_mips_got_entry (data, pltgot, ent, data_end);
15671 if (ent == (bfd_vma) -1)
15672 goto sgot_print_fail;
15684 for (entry = dynamic_section;
15685 /* PR 17531 file: 012-50589-0.004. */
15686 entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL;
15688 switch (entry->d_tag)
15690 case DT_MIPS_LIBLIST:
15692 = offset_from_vma (filedata, entry->d_un.d_val,
15693 liblistno * sizeof (Elf32_External_Lib));
15695 case DT_MIPS_LIBLISTNO:
15696 liblistno = entry->d_un.d_val;
15698 case DT_MIPS_OPTIONS:
15699 options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
15701 case DT_MIPS_CONFLICT:
15703 = offset_from_vma (filedata, entry->d_un.d_val,
15704 conflictsno * sizeof (Elf32_External_Conflict));
15706 case DT_MIPS_CONFLICTNO:
15707 conflictsno = entry->d_un.d_val;
15710 pltgot = entry->d_un.d_ptr;
15712 case DT_MIPS_LOCAL_GOTNO:
15713 local_gotno = entry->d_un.d_val;
15715 case DT_MIPS_GOTSYM:
15716 gotsym = entry->d_un.d_val;
15718 case DT_MIPS_SYMTABNO:
15719 symtabno = entry->d_un.d_val;
15721 case DT_MIPS_PLTGOT:
15722 mips_pltgot = entry->d_un.d_ptr;
15725 pltrel = entry->d_un.d_val;
15728 pltrelsz = entry->d_un.d_val;
15731 jmprel = entry->d_un.d_ptr;
15737 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
15739 Elf32_External_Lib * elib;
15742 elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset,
15744 sizeof (Elf32_External_Lib),
15745 _("liblist section data"));
15748 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
15749 "\nSection '.liblist' contains %lu entries:\n",
15750 (unsigned long) liblistno),
15751 (unsigned long) liblistno);
15752 fputs (_(" Library Time Stamp Checksum Version Flags\n"),
15755 for (cnt = 0; cnt < liblistno; ++cnt)
15762 liblist.l_name = BYTE_GET (elib[cnt].l_name);
15763 atime = BYTE_GET (elib[cnt].l_time_stamp);
15764 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
15765 liblist.l_version = BYTE_GET (elib[cnt].l_version);
15766 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
15768 tmp = gmtime (&atime);
15769 snprintf (timebuf, sizeof (timebuf),
15770 "%04u-%02u-%02uT%02u:%02u:%02u",
15771 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
15772 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
15774 printf ("%3lu: ", (unsigned long) cnt);
15775 if (VALID_DYNAMIC_NAME (liblist.l_name))
15776 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
15778 printf (_("<corrupt: %9ld>"), liblist.l_name);
15779 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
15780 liblist.l_version);
15782 if (liblist.l_flags == 0)
15786 static const struct
15793 { " EXACT_MATCH", LL_EXACT_MATCH },
15794 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
15795 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
15796 { " EXPORTS", LL_EXPORTS },
15797 { " DELAY_LOAD", LL_DELAY_LOAD },
15798 { " DELTA", LL_DELTA }
15800 int flags = liblist.l_flags;
15803 for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
15804 if ((flags & l_flags_vals[fcnt].bit) != 0)
15806 fputs (l_flags_vals[fcnt].name, stdout);
15807 flags ^= l_flags_vals[fcnt].bit;
15810 printf (" %#x", (unsigned int) flags);
15822 if (options_offset != 0)
15824 Elf_External_Options * eopt;
15825 Elf_Internal_Options * iopt;
15826 Elf_Internal_Options * option;
15829 sect = filedata->section_headers;
15831 /* Find the section header so that we get the size. */
15832 sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS);
15833 /* PR 17533 file: 012-277276-0.004. */
15836 error (_("No MIPS_OPTIONS header found\n"));
15840 eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1,
15841 sect->sh_size, _("options"));
15844 iopt = (Elf_Internal_Options *)
15845 cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
15848 error (_("Out of memory allocating space for MIPS options\n"));
15855 while (offset <= sect->sh_size - sizeof (* eopt))
15857 Elf_External_Options * eoption;
15859 eoption = (Elf_External_Options *) ((char *) eopt + offset);
15861 option->kind = BYTE_GET (eoption->kind);
15862 option->size = BYTE_GET (eoption->size);
15863 option->section = BYTE_GET (eoption->section);
15864 option->info = BYTE_GET (eoption->info);
15866 /* PR 17531: file: ffa0fa3b. */
15867 if (option->size < sizeof (* eopt)
15868 || offset + option->size > sect->sh_size)
15870 error (_("Invalid size (%u) for MIPS option\n"), option->size);
15873 offset += option->size;
15879 printf (ngettext ("\nSection '%s' contains %d entry:\n",
15880 "\nSection '%s' contains %d entries:\n",
15882 printable_section_name (filedata, sect), cnt);
15891 switch (option->kind)
15894 /* This shouldn't happen. */
15895 printf (" NULL %d %lx", option->section, option->info);
15898 printf (" REGINFO ");
15899 if (filedata->file_header.e_machine == EM_MIPS)
15902 Elf32_External_RegInfo * ereg;
15903 Elf32_RegInfo reginfo;
15905 ereg = (Elf32_External_RegInfo *) (option + 1);
15906 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
15907 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
15908 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
15909 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
15910 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
15911 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
15913 printf ("GPR %08lx GP 0x%lx\n",
15914 reginfo.ri_gprmask,
15915 (unsigned long) reginfo.ri_gp_value);
15916 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
15917 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
15918 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
15923 Elf64_External_RegInfo * ereg;
15924 Elf64_Internal_RegInfo reginfo;
15926 ereg = (Elf64_External_RegInfo *) (option + 1);
15927 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
15928 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
15929 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
15930 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
15931 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
15932 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
15934 printf ("GPR %08lx GP 0x",
15935 reginfo.ri_gprmask);
15936 printf_vma (reginfo.ri_gp_value);
15939 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
15940 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
15941 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
15945 case ODK_EXCEPTIONS:
15946 fputs (" EXCEPTIONS fpe_min(", stdout);
15947 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
15948 fputs (") fpe_max(", stdout);
15949 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
15950 fputs (")", stdout);
15952 if (option->info & OEX_PAGE0)
15953 fputs (" PAGE0", stdout);
15954 if (option->info & OEX_SMM)
15955 fputs (" SMM", stdout);
15956 if (option->info & OEX_FPDBUG)
15957 fputs (" FPDBUG", stdout);
15958 if (option->info & OEX_DISMISS)
15959 fputs (" DISMISS", stdout);
15962 fputs (" PAD ", stdout);
15963 if (option->info & OPAD_PREFIX)
15964 fputs (" PREFIX", stdout);
15965 if (option->info & OPAD_POSTFIX)
15966 fputs (" POSTFIX", stdout);
15967 if (option->info & OPAD_SYMBOL)
15968 fputs (" SYMBOL", stdout);
15971 fputs (" HWPATCH ", stdout);
15972 if (option->info & OHW_R4KEOP)
15973 fputs (" R4KEOP", stdout);
15974 if (option->info & OHW_R8KPFETCH)
15975 fputs (" R8KPFETCH", stdout);
15976 if (option->info & OHW_R5KEOP)
15977 fputs (" R5KEOP", stdout);
15978 if (option->info & OHW_R5KCVTL)
15979 fputs (" R5KCVTL", stdout);
15982 fputs (" FILL ", stdout);
15983 /* XXX Print content of info word? */
15986 fputs (" TAGS ", stdout);
15987 /* XXX Print content of info word? */
15990 fputs (" HWAND ", stdout);
15991 if (option->info & OHWA0_R4KEOP_CHECKED)
15992 fputs (" R4KEOP_CHECKED", stdout);
15993 if (option->info & OHWA0_R4KEOP_CLEAN)
15994 fputs (" R4KEOP_CLEAN", stdout);
15997 fputs (" HWOR ", stdout);
15998 if (option->info & OHWA0_R4KEOP_CHECKED)
15999 fputs (" R4KEOP_CHECKED", stdout);
16000 if (option->info & OHWA0_R4KEOP_CLEAN)
16001 fputs (" R4KEOP_CLEAN", stdout);
16004 printf (" GP_GROUP %#06lx self-contained %#06lx",
16005 option->info & OGP_GROUP,
16006 (option->info & OGP_SELF) >> 16);
16009 printf (" IDENT %#06lx self-contained %#06lx",
16010 option->info & OGP_GROUP,
16011 (option->info & OGP_SELF) >> 16);
16014 /* This shouldn't happen. */
16015 printf (" %3d ??? %d %lx",
16016 option->kind, option->section, option->info);
16020 len = sizeof (* eopt);
16021 while (len < option->size)
16023 unsigned char datum = * ((unsigned char *) eopt + offset + len);
16025 if (ISPRINT (datum))
16026 printf ("%c", datum);
16028 printf ("\\%03o", datum);
16031 fputs ("\n", stdout);
16033 offset += option->size;
16043 if (conflicts_offset != 0 && conflictsno != 0)
16045 Elf32_Conflict * iconf;
16048 if (dynamic_symbols == NULL)
16050 error (_("conflict list found without a dynamic symbol table\n"));
16054 /* PR 21345 - print a slightly more helpful error message
16055 if we are sure that the cmalloc will fail. */
16056 if (conflictsno * sizeof (* iconf) > filedata->file_size)
16058 error (_("Overlarge number of conflicts detected: %lx\n"),
16059 (long) conflictsno);
16063 iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
16066 error (_("Out of memory allocating space for dynamic conflicts\n"));
16072 Elf32_External_Conflict * econf32;
16074 econf32 = (Elf32_External_Conflict *)
16075 get_data (NULL, filedata, conflicts_offset, conflictsno,
16076 sizeof (* econf32), _("conflict"));
16080 for (cnt = 0; cnt < conflictsno; ++cnt)
16081 iconf[cnt] = BYTE_GET (econf32[cnt]);
16087 Elf64_External_Conflict * econf64;
16089 econf64 = (Elf64_External_Conflict *)
16090 get_data (NULL, filedata, conflicts_offset, conflictsno,
16091 sizeof (* econf64), _("conflict"));
16095 for (cnt = 0; cnt < conflictsno; ++cnt)
16096 iconf[cnt] = BYTE_GET (econf64[cnt]);
16101 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
16102 "\nSection '.conflict' contains %lu entries:\n",
16103 (unsigned long) conflictsno),
16104 (unsigned long) conflictsno);
16105 puts (_(" Num: Index Value Name"));
16107 for (cnt = 0; cnt < conflictsno; ++cnt)
16109 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
16111 if (iconf[cnt] >= num_dynamic_syms)
16112 printf (_("<corrupt symbol index>"));
16115 Elf_Internal_Sym * psym;
16117 psym = & dynamic_symbols[iconf[cnt]];
16118 print_vma (psym->st_value, FULL_HEX);
16120 if (VALID_DYNAMIC_NAME (psym->st_name))
16121 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
16123 printf (_("<corrupt: %14ld>"), psym->st_name);
16131 if (pltgot != 0 && local_gotno != 0)
16133 bfd_vma ent, local_end, global_end;
16135 unsigned char * data;
16136 unsigned char * data_end;
16140 addr_size = (is_32bit_elf ? 4 : 8);
16141 local_end = pltgot + local_gotno * addr_size;
16143 /* PR binutils/17533 file: 012-111227-0.004 */
16144 if (symtabno < gotsym)
16146 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
16147 (unsigned long) gotsym, (unsigned long) symtabno);
16151 global_end = local_end + (symtabno - gotsym) * addr_size;
16152 /* PR 17531: file: 54c91a34. */
16153 if (global_end < local_end)
16155 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
16159 offset = offset_from_vma (filedata, pltgot, global_end - pltgot);
16160 data = (unsigned char *) get_data (NULL, filedata, offset,
16161 global_end - pltgot, 1,
16162 _("Global Offset Table data"));
16163 /* PR 12855: Null data is handled gracefully throughout. */
16164 data_end = data + (global_end - pltgot);
16166 printf (_("\nPrimary GOT:\n"));
16167 printf (_(" Canonical gp value: "));
16168 print_vma (pltgot + 0x7ff0, LONG_HEX);
16171 printf (_(" Reserved entries:\n"));
16172 printf (_(" %*s %10s %*s Purpose\n"),
16173 addr_size * 2, _("Address"), _("Access"),
16174 addr_size * 2, _("Initial"));
16175 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16176 printf (_(" Lazy resolver\n"));
16177 if (ent == (bfd_vma) -1)
16178 goto got_print_fail;
16180 /* Check for the MSB of GOT[1] being set, denoting a GNU object.
16181 This entry will be used by some runtime loaders, to store the
16182 module pointer. Otherwise this is an ordinary local entry.
16183 PR 21344: Check for the entry being fully available before
16186 && data + ent - pltgot + addr_size <= data_end
16187 && (byte_get (data + ent - pltgot, addr_size)
16188 >> (addr_size * 8 - 1)) != 0)
16190 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16191 printf (_(" Module pointer (GNU extension)\n"));
16192 if (ent == (bfd_vma) -1)
16193 goto got_print_fail;
16197 if (data != NULL && ent < local_end)
16199 printf (_(" Local entries:\n"));
16200 printf (" %*s %10s %*s\n",
16201 addr_size * 2, _("Address"), _("Access"),
16202 addr_size * 2, _("Initial"));
16203 while (ent < local_end)
16205 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16207 if (ent == (bfd_vma) -1)
16208 goto got_print_fail;
16213 if (data != NULL && gotsym < symtabno)
16217 printf (_(" Global entries:\n"));
16218 printf (" %*s %10s %*s %*s %-7s %3s %s\n",
16219 addr_size * 2, _("Address"),
16221 addr_size * 2, _("Initial"),
16222 addr_size * 2, _("Sym.Val."),
16224 /* Note for translators: "Ndx" = abbreviated form of "Index". */
16225 _("Ndx"), _("Name"));
16227 sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
16229 for (i = gotsym; i < symtabno; i++)
16231 ent = print_mips_got_entry (data, pltgot, ent, data_end);
16234 if (dynamic_symbols == NULL)
16235 printf (_("<no dynamic symbols>"));
16236 else if (i < num_dynamic_syms)
16238 Elf_Internal_Sym * psym = dynamic_symbols + i;
16240 print_vma (psym->st_value, LONG_HEX);
16241 printf (" %-7s %3s ",
16242 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
16243 get_symbol_index_type (filedata, psym->st_shndx));
16245 if (VALID_DYNAMIC_NAME (psym->st_name))
16246 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
16248 printf (_("<corrupt: %14ld>"), psym->st_name);
16251 printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
16252 (unsigned long) i);
16255 if (ent == (bfd_vma) -1)
16266 if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
16269 size_t offset, rel_offset;
16270 unsigned long count, i;
16271 unsigned char * data;
16272 int addr_size, sym_width;
16273 Elf_Internal_Rela * rels;
16275 rel_offset = offset_from_vma (filedata, jmprel, pltrelsz);
16276 if (pltrel == DT_RELA)
16278 if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
16283 if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
16288 addr_size = (is_32bit_elf ? 4 : 8);
16289 end = mips_pltgot + (2 + count) * addr_size;
16291 offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot);
16292 data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot,
16293 1, _("Procedure Linkage Table data"));
16297 printf ("\nPLT GOT:\n\n");
16298 printf (_(" Reserved entries:\n"));
16299 printf (_(" %*s %*s Purpose\n"),
16300 addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
16301 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
16302 printf (_(" PLT lazy resolver\n"));
16303 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
16304 printf (_(" Module pointer\n"));
16307 printf (_(" Entries:\n"));
16308 printf (" %*s %*s %*s %-7s %3s %s\n",
16309 addr_size * 2, _("Address"),
16310 addr_size * 2, _("Initial"),
16311 addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
16312 sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
16313 for (i = 0; i < count; i++)
16315 unsigned long idx = get_reloc_symindex (rels[i].r_info);
16317 ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
16320 if (idx >= num_dynamic_syms)
16321 printf (_("<corrupt symbol index: %lu>"), idx);
16324 Elf_Internal_Sym * psym = dynamic_symbols + idx;
16326 print_vma (psym->st_value, LONG_HEX);
16327 printf (" %-7s %3s ",
16328 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
16329 get_symbol_index_type (filedata, psym->st_shndx));
16330 if (VALID_DYNAMIC_NAME (psym->st_name))
16331 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
16333 printf (_("<corrupt: %14ld>"), psym->st_name);
16348 process_nds32_specific (Filedata * filedata)
16350 Elf_Internal_Shdr *sect = NULL;
16352 sect = find_section (filedata, ".nds32_e_flags");
16355 unsigned int *flag;
16357 printf ("\nNDS32 elf flags section:\n");
16358 flag = get_data (NULL, filedata, sect->sh_offset, 1,
16359 sect->sh_size, _("NDS32 elf flags section"));
16364 switch ((*flag) & 0x3)
16367 printf ("(VEC_SIZE):\tNo entry.\n");
16370 printf ("(VEC_SIZE):\t4 bytes\n");
16373 printf ("(VEC_SIZE):\t16 bytes\n");
16376 printf ("(VEC_SIZE):\treserved\n");
16385 process_gnu_liblist (Filedata * filedata)
16387 Elf_Internal_Shdr * section;
16388 Elf_Internal_Shdr * string_sec;
16389 Elf32_External_Lib * elib;
16391 size_t strtab_size;
16393 unsigned long num_liblist;
16395 bfd_boolean res = TRUE;
16400 for (i = 0, section = filedata->section_headers;
16401 i < filedata->file_header.e_shnum;
16404 switch (section->sh_type)
16406 case SHT_GNU_LIBLIST:
16407 if (section->sh_link >= filedata->file_header.e_shnum)
16410 elib = (Elf32_External_Lib *)
16411 get_data (NULL, filedata, section->sh_offset, 1, section->sh_size,
16412 _("liblist section data"));
16420 string_sec = filedata->section_headers + section->sh_link;
16421 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
16422 string_sec->sh_size,
16423 _("liblist string table"));
16425 || section->sh_entsize != sizeof (Elf32_External_Lib))
16432 strtab_size = string_sec->sh_size;
16434 num_liblist = section->sh_size / sizeof (Elf32_External_Lib);
16435 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
16436 "\nLibrary list section '%s' contains %lu entries:\n",
16438 printable_section_name (filedata, section),
16441 puts (_(" Library Time Stamp Checksum Version Flags"));
16443 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
16451 liblist.l_name = BYTE_GET (elib[cnt].l_name);
16452 atime = BYTE_GET (elib[cnt].l_time_stamp);
16453 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
16454 liblist.l_version = BYTE_GET (elib[cnt].l_version);
16455 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
16457 tmp = gmtime (&atime);
16458 snprintf (timebuf, sizeof (timebuf),
16459 "%04u-%02u-%02uT%02u:%02u:%02u",
16460 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
16461 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
16463 printf ("%3lu: ", (unsigned long) cnt);
16465 printf ("%-20s", liblist.l_name < strtab_size
16466 ? strtab + liblist.l_name : _("<corrupt>"));
16468 printf ("%-20.20s", liblist.l_name < strtab_size
16469 ? strtab + liblist.l_name : _("<corrupt>"));
16470 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
16471 liblist.l_version, liblist.l_flags);
16482 static const char *
16483 get_note_type (Filedata * filedata, unsigned e_type)
16485 static char buff[64];
16487 if (filedata->file_header.e_type == ET_CORE)
16491 return _("NT_AUXV (auxiliary vector)");
16493 return _("NT_PRSTATUS (prstatus structure)");
16495 return _("NT_FPREGSET (floating point registers)");
16497 return _("NT_PRPSINFO (prpsinfo structure)");
16498 case NT_TASKSTRUCT:
16499 return _("NT_TASKSTRUCT (task structure)");
16501 return _("NT_PRXFPREG (user_xfpregs structure)");
16503 return _("NT_PPC_VMX (ppc Altivec registers)");
16505 return _("NT_PPC_VSX (ppc VSX registers)");
16507 return _("NT_PPC_TAR (ppc TAR register)");
16509 return _("NT_PPC_PPR (ppc PPR register)");
16511 return _("NT_PPC_DSCR (ppc DSCR register)");
16513 return _("NT_PPC_EBB (ppc EBB registers)");
16515 return _("NT_PPC_PMU (ppc PMU registers)");
16516 case NT_PPC_TM_CGPR:
16517 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
16518 case NT_PPC_TM_CFPR:
16519 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
16520 case NT_PPC_TM_CVMX:
16521 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
16522 case NT_PPC_TM_CVSX:
16523 return _("NT_PPC_TM_VSX (ppc checkpointed VSX registers)");
16524 case NT_PPC_TM_SPR:
16525 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
16526 case NT_PPC_TM_CTAR:
16527 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
16528 case NT_PPC_TM_CPPR:
16529 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
16530 case NT_PPC_TM_CDSCR:
16531 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
16533 return _("NT_386_TLS (x86 TLS information)");
16534 case NT_386_IOPERM:
16535 return _("NT_386_IOPERM (x86 I/O permissions)");
16536 case NT_X86_XSTATE:
16537 return _("NT_X86_XSTATE (x86 XSAVE extended state)");
16538 case NT_S390_HIGH_GPRS:
16539 return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
16540 case NT_S390_TIMER:
16541 return _("NT_S390_TIMER (s390 timer register)");
16542 case NT_S390_TODCMP:
16543 return _("NT_S390_TODCMP (s390 TOD comparator register)");
16544 case NT_S390_TODPREG:
16545 return _("NT_S390_TODPREG (s390 TOD programmable register)");
16547 return _("NT_S390_CTRS (s390 control registers)");
16548 case NT_S390_PREFIX:
16549 return _("NT_S390_PREFIX (s390 prefix register)");
16550 case NT_S390_LAST_BREAK:
16551 return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
16552 case NT_S390_SYSTEM_CALL:
16553 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
16555 return _("NT_S390_TDB (s390 transaction diagnostic block)");
16556 case NT_S390_VXRS_LOW:
16557 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
16558 case NT_S390_VXRS_HIGH:
16559 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
16560 case NT_S390_GS_CB:
16561 return _("NT_S390_GS_CB (s390 guarded-storage registers)");
16562 case NT_S390_GS_BC:
16563 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
16565 return _("NT_ARM_VFP (arm VFP registers)");
16567 return _("NT_ARM_TLS (AArch TLS registers)");
16568 case NT_ARM_HW_BREAK:
16569 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
16570 case NT_ARM_HW_WATCH:
16571 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
16573 return _("NT_PSTATUS (pstatus structure)");
16575 return _("NT_FPREGS (floating point registers)");
16577 return _("NT_PSINFO (psinfo structure)");
16579 return _("NT_LWPSTATUS (lwpstatus_t structure)");
16581 return _("NT_LWPSINFO (lwpsinfo_t structure)");
16582 case NT_WIN32PSTATUS:
16583 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
16585 return _("NT_SIGINFO (siginfo_t data)");
16587 return _("NT_FILE (mapped files)");
16595 return _("NT_VERSION (version)");
16597 return _("NT_ARCH (architecture)");
16598 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
16600 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
16606 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
16611 print_core_note (Elf_Internal_Note *pnote)
16613 unsigned int addr_size = is_32bit_elf ? 4 : 8;
16614 bfd_vma count, page_size;
16615 unsigned char *descdata, *filenames, *descend;
16617 if (pnote->type != NT_FILE)
16627 printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
16628 /* Still "successful". */
16633 if (pnote->descsz < 2 * addr_size)
16635 error (_(" Malformed note - too short for header\n"));
16639 descdata = (unsigned char *) pnote->descdata;
16640 descend = descdata + pnote->descsz;
16642 if (descdata[pnote->descsz - 1] != '\0')
16644 error (_(" Malformed note - does not end with \\0\n"));
16648 count = byte_get (descdata, addr_size);
16649 descdata += addr_size;
16651 page_size = byte_get (descdata, addr_size);
16652 descdata += addr_size;
16654 if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size)
16655 || pnote->descsz < 2 * addr_size + count * 3 * addr_size)
16657 error (_(" Malformed note - too short for supplied file count\n"));
16661 printf (_(" Page size: "));
16662 print_vma (page_size, DEC);
16665 printf (_(" %*s%*s%*s\n"),
16666 (int) (2 + 2 * addr_size), _("Start"),
16667 (int) (4 + 2 * addr_size), _("End"),
16668 (int) (4 + 2 * addr_size), _("Page Offset"));
16669 filenames = descdata + count * 3 * addr_size;
16670 while (count-- > 0)
16672 bfd_vma start, end, file_ofs;
16674 if (filenames == descend)
16676 error (_(" Malformed note - filenames end too early\n"));
16680 start = byte_get (descdata, addr_size);
16681 descdata += addr_size;
16682 end = byte_get (descdata, addr_size);
16683 descdata += addr_size;
16684 file_ofs = byte_get (descdata, addr_size);
16685 descdata += addr_size;
16688 print_vma (start, FULL_HEX);
16690 print_vma (end, FULL_HEX);
16692 print_vma (file_ofs, FULL_HEX);
16693 printf ("\n %s\n", filenames);
16695 filenames += 1 + strlen ((char *) filenames);
16701 static const char *
16702 get_gnu_elf_note_type (unsigned e_type)
16704 /* NB/ Keep this switch statement in sync with print_gnu_note (). */
16707 case NT_GNU_ABI_TAG:
16708 return _("NT_GNU_ABI_TAG (ABI version tag)");
16710 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
16711 case NT_GNU_BUILD_ID:
16712 return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
16713 case NT_GNU_GOLD_VERSION:
16714 return _("NT_GNU_GOLD_VERSION (gold version)");
16715 case NT_GNU_PROPERTY_TYPE_0:
16716 return _("NT_GNU_PROPERTY_TYPE_0");
16717 case NT_GNU_BUILD_ATTRIBUTE_OPEN:
16718 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
16719 case NT_GNU_BUILD_ATTRIBUTE_FUNC:
16720 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
16723 static char buff[64];
16725 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
16732 decode_x86_isa (unsigned int bitmask)
16736 unsigned int bit = bitmask & (- bitmask);
16741 case GNU_PROPERTY_X86_ISA_1_486: printf ("i486"); break;
16742 case GNU_PROPERTY_X86_ISA_1_586: printf ("586"); break;
16743 case GNU_PROPERTY_X86_ISA_1_686: printf ("686"); break;
16744 case GNU_PROPERTY_X86_ISA_1_SSE: printf ("SSE"); break;
16745 case GNU_PROPERTY_X86_ISA_1_SSE2: printf ("SSE2"); break;
16746 case GNU_PROPERTY_X86_ISA_1_SSE3: printf ("SSE3"); break;
16747 case GNU_PROPERTY_X86_ISA_1_SSSE3: printf ("SSSE3"); break;
16748 case GNU_PROPERTY_X86_ISA_1_SSE4_1: printf ("SSE4_1"); break;
16749 case GNU_PROPERTY_X86_ISA_1_SSE4_2: printf ("SSE4_2"); break;
16750 case GNU_PROPERTY_X86_ISA_1_AVX: printf ("AVX"); break;
16751 case GNU_PROPERTY_X86_ISA_1_AVX2: printf ("AVX2"); break;
16752 case GNU_PROPERTY_X86_ISA_1_AVX512F: printf ("AVX512F"); break;
16753 case GNU_PROPERTY_X86_ISA_1_AVX512CD: printf ("AVX512CD"); break;
16754 case GNU_PROPERTY_X86_ISA_1_AVX512ER: printf ("AVX512ER"); break;
16755 case GNU_PROPERTY_X86_ISA_1_AVX512PF: printf ("AVX512PF"); break;
16756 case GNU_PROPERTY_X86_ISA_1_AVX512VL: printf ("AVX512VL"); break;
16757 case GNU_PROPERTY_X86_ISA_1_AVX512DQ: printf ("AVX512DQ"); break;
16758 case GNU_PROPERTY_X86_ISA_1_AVX512BW: printf ("AVX512BW"); break;
16759 default: printf (_("<unknown: %x>"), bit); break;
16767 decode_x86_feature (unsigned int type, unsigned int bitmask)
16771 unsigned int bit = bitmask & (- bitmask);
16776 case GNU_PROPERTY_X86_FEATURE_1_IBT:
16779 case GNU_PROPERTY_X86_FEATURE_1_AND:
16783 /* This should never happen. */
16787 case GNU_PROPERTY_X86_FEATURE_1_SHSTK:
16790 case GNU_PROPERTY_X86_FEATURE_1_AND:
16794 /* This should never happen. */
16799 printf (_("<unknown: %x>"), bit);
16808 print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
16810 unsigned char * ptr = (unsigned char *) pnote->descdata;
16811 unsigned char * ptr_end = ptr + pnote->descsz;
16812 unsigned int size = is_32bit_elf ? 4 : 8;
16814 printf (_(" Properties: "));
16816 if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
16818 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
16822 while (ptr < ptr_end)
16826 unsigned int datasz;
16828 if ((size_t) (ptr_end - ptr) < 8)
16830 printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
16834 type = byte_get (ptr, 4);
16835 datasz = byte_get (ptr + 4, 4);
16839 if (datasz > (size_t) (ptr_end - ptr))
16841 printf (_("<corrupt type (%#x) datasz: %#x>\n"),
16846 if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
16848 if (filedata->file_header.e_machine == EM_X86_64
16849 || filedata->file_header.e_machine == EM_IAMCU
16850 || filedata->file_header.e_machine == EM_386)
16854 case GNU_PROPERTY_X86_ISA_1_USED:
16855 printf ("x86 ISA used: ");
16857 printf (_("<corrupt length: %#x> "), datasz);
16859 decode_x86_isa (byte_get (ptr, 4));
16862 case GNU_PROPERTY_X86_ISA_1_NEEDED:
16863 printf ("x86 ISA needed: ");
16865 printf (_("<corrupt length: %#x> "), datasz);
16867 decode_x86_isa (byte_get (ptr, 4));
16870 case GNU_PROPERTY_X86_FEATURE_1_AND:
16871 printf ("x86 feature: ");
16873 printf (_("<corrupt length: %#x> "), datasz);
16875 decode_x86_feature (type, byte_get (ptr, 4));
16887 case GNU_PROPERTY_STACK_SIZE:
16888 printf (_("stack size: "));
16889 if (datasz != size)
16890 printf (_("<corrupt length: %#x> "), datasz);
16892 printf ("%#lx", (unsigned long) byte_get (ptr, size));
16895 case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
16896 printf ("no copy on protected ");
16898 printf (_("<corrupt length: %#x> "), datasz);
16906 if (type < GNU_PROPERTY_LOPROC)
16907 printf (_("<unknown type %#x data: "), type);
16908 else if (type < GNU_PROPERTY_LOUSER)
16909 printf (_("<procesor-specific type %#x data: "), type);
16911 printf (_("<application-specific type %#x data: "), type);
16912 for (j = 0; j < datasz; ++j)
16913 printf ("%02x ", ptr[j] & 0xff);
16917 ptr += ((datasz + (size - 1)) & ~ (size - 1));
16918 if (ptr == ptr_end)
16931 print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote)
16933 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
16934 switch (pnote->type)
16936 case NT_GNU_BUILD_ID:
16940 printf (_(" Build ID: "));
16941 for (i = 0; i < pnote->descsz; ++i)
16942 printf ("%02x", pnote->descdata[i] & 0xff);
16947 case NT_GNU_ABI_TAG:
16949 unsigned long os, major, minor, subminor;
16950 const char *osname;
16952 /* PR 17531: file: 030-599401-0.004. */
16953 if (pnote->descsz < 16)
16955 printf (_(" <corrupt GNU_ABI_TAG>\n"));
16959 os = byte_get ((unsigned char *) pnote->descdata, 4);
16960 major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
16961 minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
16962 subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
16966 case GNU_ABI_TAG_LINUX:
16969 case GNU_ABI_TAG_HURD:
16972 case GNU_ABI_TAG_SOLARIS:
16973 osname = "Solaris";
16975 case GNU_ABI_TAG_FREEBSD:
16976 osname = "FreeBSD";
16978 case GNU_ABI_TAG_NETBSD:
16981 case GNU_ABI_TAG_SYLLABLE:
16982 osname = "Syllable";
16984 case GNU_ABI_TAG_NACL:
16988 osname = "Unknown";
16992 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname,
16993 major, minor, subminor);
16997 case NT_GNU_GOLD_VERSION:
17001 printf (_(" Version: "));
17002 for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
17003 printf ("%c", pnote->descdata[i]);
17010 unsigned long num_entries, mask;
17012 /* Hardware capabilities information. Word 0 is the number of entries.
17013 Word 1 is a bitmask of enabled entries. The rest of the descriptor
17014 is a series of entries, where each entry is a single byte followed
17015 by a nul terminated string. The byte gives the bit number to test
17016 if enabled in the bitmask. */
17017 printf (_(" Hardware Capabilities: "));
17018 if (pnote->descsz < 8)
17020 error (_("<corrupt GNU_HWCAP>\n"));
17023 num_entries = byte_get ((unsigned char *) pnote->descdata, 4);
17024 mask = byte_get ((unsigned char *) pnote->descdata + 4, 4);
17025 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask);
17026 /* FIXME: Add code to display the entries... */
17030 case NT_GNU_PROPERTY_TYPE_0:
17031 print_gnu_property_note (filedata, pnote);
17035 /* Handle unrecognised types. An error message should have already been
17036 created by get_gnu_elf_note_type(), so all that we need to do is to
17037 display the data. */
17041 printf (_(" Description data: "));
17042 for (i = 0; i < pnote->descsz; ++i)
17043 printf ("%02x ", pnote->descdata[i] & 0xff);
17052 static const char *
17053 get_v850_elf_note_type (enum v850_notes n_type)
17055 static char buff[64];
17059 case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects");
17060 case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double");
17061 case V850_NOTE_FPU_INFO: return _("Type of FPU support needed");
17062 case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions");
17063 case V850_NOTE_CACHE_INFO: return _("Use of cache");
17064 case V850_NOTE_MMU_INFO: return _("Use of MMU");
17066 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type);
17072 print_v850_note (Elf_Internal_Note * pnote)
17076 if (pnote->descsz != 4)
17079 val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz);
17083 printf (_("not set\n"));
17087 switch (pnote->type)
17089 case V850_NOTE_ALIGNMENT:
17092 case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE;
17093 case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE;
17097 case V850_NOTE_DATA_SIZE:
17100 case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE;
17101 case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE;
17105 case V850_NOTE_FPU_INFO:
17108 case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE;
17109 case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE;
17113 case V850_NOTE_MMU_INFO:
17114 case V850_NOTE_CACHE_INFO:
17115 case V850_NOTE_SIMD_INFO:
17116 if (val == EF_RH850_SIMD)
17118 printf (_("yes\n"));
17124 /* An 'unknown note type' message will already have been displayed. */
17128 printf (_("unknown value: %x\n"), val);
17133 process_netbsd_elf_note (Elf_Internal_Note * pnote)
17135 unsigned int version;
17137 switch (pnote->type)
17139 case NT_NETBSD_IDENT:
17140 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
17141 if ((version / 10000) % 100)
17142 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
17143 version, version / 100000000, (version / 1000000) % 100,
17144 (version / 10000) % 100 > 26 ? "Z" : "",
17145 'A' + (version / 10000) % 26);
17147 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
17148 version, version / 100000000, (version / 1000000) % 100,
17149 (version / 100) % 100);
17152 case NT_NETBSD_MARCH:
17153 printf (" NetBSD\t0x%08lx\tMARCH <%s>\n", pnote->descsz,
17158 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz,
17164 static const char *
17165 get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
17169 case NT_FREEBSD_THRMISC:
17170 return _("NT_THRMISC (thrmisc structure)");
17171 case NT_FREEBSD_PROCSTAT_PROC:
17172 return _("NT_PROCSTAT_PROC (proc data)");
17173 case NT_FREEBSD_PROCSTAT_FILES:
17174 return _("NT_PROCSTAT_FILES (files data)");
17175 case NT_FREEBSD_PROCSTAT_VMMAP:
17176 return _("NT_PROCSTAT_VMMAP (vmmap data)");
17177 case NT_FREEBSD_PROCSTAT_GROUPS:
17178 return _("NT_PROCSTAT_GROUPS (groups data)");
17179 case NT_FREEBSD_PROCSTAT_UMASK:
17180 return _("NT_PROCSTAT_UMASK (umask data)");
17181 case NT_FREEBSD_PROCSTAT_RLIMIT:
17182 return _("NT_PROCSTAT_RLIMIT (rlimit data)");
17183 case NT_FREEBSD_PROCSTAT_OSREL:
17184 return _("NT_PROCSTAT_OSREL (osreldate data)");
17185 case NT_FREEBSD_PROCSTAT_PSSTRINGS:
17186 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
17187 case NT_FREEBSD_PROCSTAT_AUXV:
17188 return _("NT_PROCSTAT_AUXV (auxv data)");
17189 case NT_FREEBSD_PTLWPINFO:
17190 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
17192 return get_note_type (filedata, e_type);
17195 static const char *
17196 get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
17198 static char buff[64];
17200 if (e_type == NT_NETBSDCORE_PROCINFO)
17201 return _("NetBSD procinfo structure");
17203 /* As of Jan 2002 there are no other machine-independent notes
17204 defined for NetBSD core files. If the note type is less
17205 than the start of the machine-dependent note types, we don't
17208 if (e_type < NT_NETBSDCORE_FIRSTMACH)
17210 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17214 switch (filedata->file_header.e_machine)
17216 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
17217 and PT_GETFPREGS == mach+2. */
17222 case EM_SPARC32PLUS:
17226 case NT_NETBSDCORE_FIRSTMACH + 0:
17227 return _("PT_GETREGS (reg structure)");
17228 case NT_NETBSDCORE_FIRSTMACH + 2:
17229 return _("PT_GETFPREGS (fpreg structure)");
17235 /* On all other arch's, PT_GETREGS == mach+1 and
17236 PT_GETFPREGS == mach+3. */
17240 case NT_NETBSDCORE_FIRSTMACH + 1:
17241 return _("PT_GETREGS (reg structure)");
17242 case NT_NETBSDCORE_FIRSTMACH + 3:
17243 return _("PT_GETFPREGS (fpreg structure)");
17249 snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
17250 e_type - NT_NETBSDCORE_FIRSTMACH);
17254 static const char *
17255 get_stapsdt_note_type (unsigned e_type)
17257 static char buff[64];
17262 return _("NT_STAPSDT (SystemTap probe descriptors)");
17268 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17273 print_stapsdt_note (Elf_Internal_Note *pnote)
17275 int addr_size = is_32bit_elf ? 4 : 8;
17276 char *data = pnote->descdata;
17277 char *data_end = pnote->descdata + pnote->descsz;
17278 bfd_vma pc, base_addr, semaphore;
17279 char *provider, *probe, *arg_fmt;
17281 pc = byte_get ((unsigned char *) data, addr_size);
17283 base_addr = byte_get ((unsigned char *) data, addr_size);
17285 semaphore = byte_get ((unsigned char *) data, addr_size);
17289 data += strlen (data) + 1;
17291 data += strlen (data) + 1;
17293 data += strlen (data) + 1;
17295 printf (_(" Provider: %s\n"), provider);
17296 printf (_(" Name: %s\n"), probe);
17297 printf (_(" Location: "));
17298 print_vma (pc, FULL_HEX);
17299 printf (_(", Base: "));
17300 print_vma (base_addr, FULL_HEX);
17301 printf (_(", Semaphore: "));
17302 print_vma (semaphore, FULL_HEX);
17304 printf (_(" Arguments: %s\n"), arg_fmt);
17306 return data == data_end;
17309 static const char *
17310 get_ia64_vms_note_type (unsigned e_type)
17312 static char buff[64];
17317 return _("NT_VMS_MHD (module header)");
17319 return _("NT_VMS_LNM (language name)");
17321 return _("NT_VMS_SRC (source files)");
17323 return "NT_VMS_TITLE";
17325 return _("NT_VMS_EIDC (consistency check)");
17326 case NT_VMS_FPMODE:
17327 return _("NT_VMS_FPMODE (FP mode)");
17328 case NT_VMS_LINKTIME:
17329 return "NT_VMS_LINKTIME";
17330 case NT_VMS_IMGNAM:
17331 return _("NT_VMS_IMGNAM (image name)");
17333 return _("NT_VMS_IMGID (image id)");
17334 case NT_VMS_LINKID:
17335 return _("NT_VMS_LINKID (link id)");
17336 case NT_VMS_IMGBID:
17337 return _("NT_VMS_IMGBID (build id)");
17338 case NT_VMS_GSTNAM:
17339 return _("NT_VMS_GSTNAM (sym table name)");
17340 case NT_VMS_ORIG_DYN:
17341 return "NT_VMS_ORIG_DYN";
17342 case NT_VMS_PATCHTIME:
17343 return "NT_VMS_PATCHTIME";
17345 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
17351 print_ia64_vms_note (Elf_Internal_Note * pnote)
17353 switch (pnote->type)
17356 if (pnote->descsz > 36)
17358 size_t l = strlen (pnote->descdata + 34);
17359 printf (_(" Creation date : %.17s\n"), pnote->descdata);
17360 printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17);
17361 printf (_(" Module name : %s\n"), pnote->descdata + 34);
17362 printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1);
17365 printf (_(" Invalid size\n"));
17368 printf (_(" Language: %s\n"), pnote->descdata);
17371 case NT_VMS_FPMODE:
17372 printf (_(" Floating Point mode: "));
17373 printf ("0x%016" BFD_VMA_FMT "x\n",
17374 (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
17376 case NT_VMS_LINKTIME:
17377 printf (_(" Link time: "));
17379 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
17382 case NT_VMS_PATCHTIME:
17383 printf (_(" Patch time: "));
17385 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
17388 case NT_VMS_ORIG_DYN:
17389 printf (_(" Major id: %u, minor id: %u\n"),
17390 (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
17391 (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
17392 printf (_(" Last modified : "));
17394 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
17395 printf (_("\n Link flags : "));
17396 printf ("0x%016" BFD_VMA_FMT "x\n",
17397 (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
17398 printf (_(" Header flags: 0x%08x\n"),
17399 (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
17400 printf (_(" Image id : %s\n"), pnote->descdata + 32);
17403 case NT_VMS_IMGNAM:
17404 printf (_(" Image name: %s\n"), pnote->descdata);
17406 case NT_VMS_GSTNAM:
17407 printf (_(" Global symbol table name: %s\n"), pnote->descdata);
17410 printf (_(" Image id: %s\n"), pnote->descdata);
17412 case NT_VMS_LINKID:
17413 printf (_(" Linker id: %s\n"), pnote->descdata);
17421 /* Find the symbol associated with a build attribute that is attached
17422 to address OFFSET. If PNAME is non-NULL then store the name of
17423 the symbol (if found) in the provided pointer, Returns NULL if a
17424 symbol could not be found. */
17426 static Elf_Internal_Sym *
17427 get_symbol_for_build_attribute (Filedata * filedata,
17428 unsigned long offset,
17429 bfd_boolean is_open_attr,
17430 const char ** pname)
17432 static Filedata * saved_filedata = NULL;
17433 static char * strtab;
17434 static unsigned long strtablen;
17435 static Elf_Internal_Sym * symtab;
17436 static unsigned long nsyms;
17437 Elf_Internal_Sym * saved_sym = NULL;
17438 Elf_Internal_Sym * sym;
17440 if (filedata->section_headers != NULL
17441 && (saved_filedata == NULL || filedata != saved_filedata))
17443 Elf_Internal_Shdr * symsec;
17445 /* Load the symbol and string sections. */
17446 for (symsec = filedata->section_headers;
17447 symsec < filedata->section_headers + filedata->file_header.e_shnum;
17450 if (symsec->sh_type == SHT_SYMTAB)
17452 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms);
17454 if (symsec->sh_link < filedata->file_header.e_shnum)
17456 Elf_Internal_Shdr * strtab_sec = filedata->section_headers + symsec->sh_link;
17458 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
17459 1, strtab_sec->sh_size,
17460 _("string table"));
17461 strtablen = strtab != NULL ? strtab_sec->sh_size : 0;
17465 saved_filedata = filedata;
17468 if (symtab == NULL || strtab == NULL)
17471 /* Find a symbol whose value matches offset. */
17472 for (sym = symtab; sym < symtab + nsyms; sym ++)
17473 if (sym->st_value == offset)
17475 if (sym->st_name >= strtablen)
17476 /* Huh ? This should not happen. */
17479 if (strtab[sym->st_name] == 0)
17482 /* The AArch64 and ARM architectures define mapping symbols
17483 (eg $d, $x, $t) which we want to ignore. */
17484 if (strtab[sym->st_name] == '$'
17485 && strtab[sym->st_name + 1] != 0
17486 && strtab[sym->st_name + 2] == 0)
17491 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
17492 and FILE or OBJECT symbols over NOTYPE symbols. We skip
17493 FUNC symbols entirely. */
17494 switch (ELF_ST_TYPE (sym->st_info))
17501 /* If the symbol has a size associated
17502 with it then we can stop searching. */
17503 sym = symtab + nsyms;
17508 /* Ignore function symbols. */
17515 switch (ELF_ST_BIND (sym->st_info))
17518 if (saved_sym == NULL
17519 || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT)
17524 if (saved_sym == NULL)
17534 if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
17542 if (saved_sym && pname)
17543 * pname = strtab + saved_sym->st_name;
17549 print_gnu_build_attribute_description (Elf_Internal_Note * pnote,
17550 Filedata * filedata)
17552 static unsigned long global_offset = 0;
17553 static unsigned long global_end = 0;
17554 static unsigned long func_offset = 0;
17555 static unsigned long func_end = 0;
17557 Elf_Internal_Sym * sym;
17559 unsigned long start;
17561 bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN;
17563 switch (pnote->descsz)
17566 /* A zero-length description means that the range of
17567 the previous note of the same type should be used. */
17570 if (global_end > global_offset)
17571 printf (_(" Applies to region from %#lx to %#lx\n"),
17572 global_offset, global_end);
17574 printf (_(" Applies to region from %#lx\n"), global_offset);
17578 if (func_end > func_offset)
17579 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end);
17581 printf (_(" Applies to region from %#lx\n"), func_offset);
17586 start = byte_get ((unsigned char *) pnote->descdata, 4);
17593 /* FIXME: We should check that version 3+ notes are being used here... */
17594 start = byte_get ((unsigned char *) pnote->descdata, 4);
17595 end = byte_get ((unsigned char *) pnote->descdata + 4, 4);
17599 start = byte_get ((unsigned char *) pnote->descdata, 8);
17605 start = byte_get ((unsigned char *) pnote->descdata, 8);
17606 end = byte_get ((unsigned char *) pnote->descdata + 8, 8);
17610 error (_(" <invalid description size: %lx>\n"), pnote->descsz);
17611 printf (_(" <invalid descsz>"));
17616 sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name);
17617 /* As of version 5 of the annobin plugin, filename symbols are biased by 2
17618 in order to avoid them being confused with the start address of the
17619 first function in the file... */
17620 if (sym == NULL && is_open_attr)
17621 sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr,
17624 if (end == 0 && sym != NULL && sym->st_size > 0)
17625 end = start + sym->st_size;
17629 /* FIXME: Need to properly allow for section alignment. 16 is just the alignment used on x86_64. */
17630 if (global_end > 0 && start > BFD_ALIGN (global_end, 16))
17631 warn (_("Gap in build notes detected from %#lx to %#lx\n"),
17632 global_end + 1, start - 1);
17634 printf (_(" Applies to region from %#lx"), start);
17635 global_offset = start;
17639 printf (_(" to %#lx"), end);
17645 printf (_(" Applies to region from %#lx"), start);
17646 func_offset = start;
17650 printf (_(" to %#lx"), end);
17656 printf (_(" (%s)"), name);
17663 print_gnu_build_attribute_name (Elf_Internal_Note * pnote)
17665 static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 };
17666 static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 };
17667 static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 };
17669 char name_attribute;
17670 const char * expected_types;
17671 const char * name = pnote->namedata;
17675 if (name == NULL || pnote->namesz < 2)
17677 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
17678 print_symbol (-20, _(" <corrupt name>"));
17687 /* Version 2 of the spec adds a "GA" prefix to the name field. */
17688 if (name[0] == 'G' && name[1] == 'A')
17690 if (pnote->namesz < 4)
17692 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
17693 print_symbol (-20, _(" <corrupt name>"));
17702 switch ((name_type = * name))
17704 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
17705 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
17706 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
17707 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
17708 printf ("%c", * name);
17712 error (_("unrecognised attribute type in name field: %d\n"), name_type);
17713 print_symbol (-20, _("<unknown name type>"));
17720 switch ((name_attribute = * name))
17722 case GNU_BUILD_ATTRIBUTE_VERSION:
17723 text = _("<version>");
17724 expected_types = string_expected;
17727 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
17728 text = _("<stack prot>");
17729 expected_types = "!+*";
17732 case GNU_BUILD_ATTRIBUTE_RELRO:
17733 text = _("<relro>");
17734 expected_types = bool_expected;
17737 case GNU_BUILD_ATTRIBUTE_STACK_SIZE:
17738 text = _("<stack size>");
17739 expected_types = number_expected;
17742 case GNU_BUILD_ATTRIBUTE_TOOL:
17743 text = _("<tool>");
17744 expected_types = string_expected;
17747 case GNU_BUILD_ATTRIBUTE_ABI:
17749 expected_types = "$*";
17752 case GNU_BUILD_ATTRIBUTE_PIC:
17754 expected_types = number_expected;
17757 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM:
17758 text = _("<short enum>");
17759 expected_types = bool_expected;
17763 if (ISPRINT (* name))
17765 int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1;
17767 if (len > left && ! do_wide)
17769 printf ("%.*s:", len, name);
17775 static char tmpbuf [128];
17777 error (_("unrecognised byte in name field: %d\n"), * name);
17778 sprintf (tmpbuf, _("<unknown:_%d>"), * name);
17782 expected_types = "*$!+";
17787 left -= printf ("%s", text);
17789 if (strchr (expected_types, name_type) == NULL)
17790 warn (_("attribute does not have an expected type (%c)\n"), name_type);
17792 if ((unsigned long)(name - pnote->namedata) > pnote->namesz)
17794 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
17795 (unsigned long) pnote->namesz,
17796 (long) (name - pnote->namedata));
17800 if (left < 1 && ! do_wide)
17805 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
17807 unsigned int bytes;
17808 unsigned long long val = 0;
17809 unsigned int shift = 0;
17810 char * decoded = NULL;
17812 bytes = pnote->namesz - (name - pnote->namedata);
17814 /* The -1 is because the name field is always 0 terminated, and we
17815 want to be able to ensure that the shift in the while loop below
17816 will not overflow. */
17819 if (bytes > sizeof (val))
17821 error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
17823 bytes = sizeof (val);
17825 /* We do not bother to warn if bytes == 0 as this can
17826 happen with some early versions of the gcc plugin. */
17830 unsigned long byte = (* name ++) & 0xff;
17832 val |= byte << shift;
17836 switch (name_attribute)
17838 case GNU_BUILD_ATTRIBUTE_PIC:
17841 case 0: decoded = "static"; break;
17842 case 1: decoded = "pic"; break;
17843 case 2: decoded = "PIC"; break;
17844 case 3: decoded = "pie"; break;
17845 case 4: decoded = "PIE"; break;
17849 case GNU_BUILD_ATTRIBUTE_STACK_PROT:
17852 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
17853 case 0: decoded = "off"; break;
17854 case 1: decoded = "on"; break;
17855 case 2: decoded = "all"; break;
17856 case 3: decoded = "strong"; break;
17857 case 4: decoded = "explicit"; break;
17865 if (decoded != NULL)
17867 print_symbol (-left, decoded);
17878 left -= printf ("0x%llx", val);
17880 left -= printf ("0x%-.*llx", left, val);
17884 case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
17885 left -= print_symbol (- left, name);
17887 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
17888 left -= print_symbol (- left, "true");
17890 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
17891 left -= print_symbol (- left, "false");
17895 if (do_wide && left > 0)
17896 printf ("%-*s", left, " ");
17901 /* Note that by the ELF standard, the name field is already null byte
17902 terminated, and namesz includes the terminating null byte.
17903 I.E. the value of namesz for the name "FSF" is 4.
17905 If the value of namesz is zero, there is no name present. */
17908 process_note (Elf_Internal_Note * pnote,
17909 Filedata * filedata)
17911 const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
17914 if (pnote->namesz == 0)
17915 /* If there is no note name, then use the default set of
17916 note type strings. */
17917 nt = get_note_type (filedata, pnote->type);
17919 else if (const_strneq (pnote->namedata, "GNU"))
17920 /* GNU-specific object file notes. */
17921 nt = get_gnu_elf_note_type (pnote->type);
17923 else if (const_strneq (pnote->namedata, "FreeBSD"))
17924 /* FreeBSD-specific core file notes. */
17925 nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
17927 else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
17928 /* NetBSD-specific core file notes. */
17929 nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
17931 else if (const_strneq (pnote->namedata, "NetBSD"))
17932 /* NetBSD-specific core file notes. */
17933 return process_netbsd_elf_note (pnote);
17935 else if (strneq (pnote->namedata, "SPU/", 4))
17937 /* SPU-specific core file notes. */
17938 nt = pnote->namedata + 4;
17942 else if (const_strneq (pnote->namedata, "IPF/VMS"))
17943 /* VMS/ia64-specific file notes. */
17944 nt = get_ia64_vms_note_type (pnote->type);
17946 else if (const_strneq (pnote->namedata, "stapsdt"))
17947 nt = get_stapsdt_note_type (pnote->type);
17950 /* Don't recognize this note name; just use the default set of
17951 note type strings. */
17952 nt = get_note_type (filedata, pnote->type);
17956 if (((const_strneq (pnote->namedata, "GA")
17957 && strchr ("*$!+", pnote->namedata[2]) != NULL)
17958 || strchr ("*$!+", pnote->namedata[0]) != NULL)
17959 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
17960 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
17961 print_gnu_build_attribute_name (pnote);
17963 print_symbol (-20, name);
17966 printf (" 0x%08lx\t%s\t", pnote->descsz, nt);
17968 printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
17970 if (const_strneq (pnote->namedata, "IPF/VMS"))
17971 return print_ia64_vms_note (pnote);
17972 else if (const_strneq (pnote->namedata, "GNU"))
17973 return print_gnu_note (filedata, pnote);
17974 else if (const_strneq (pnote->namedata, "stapsdt"))
17975 return print_stapsdt_note (pnote);
17976 else if (const_strneq (pnote->namedata, "CORE"))
17977 return print_core_note (pnote);
17978 else if (((const_strneq (pnote->namedata, "GA")
17979 && strchr ("*$!+", pnote->namedata[2]) != NULL)
17980 || strchr ("*$!+", pnote->namedata[0]) != NULL)
17981 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
17982 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
17983 return print_gnu_build_attribute_description (pnote, filedata);
17989 printf (_(" description data: "));
17990 for (i = 0; i < pnote->descsz; i++)
17991 printf ("%02x ", pnote->descdata[i]);
18003 process_notes_at (Filedata * filedata,
18004 Elf_Internal_Shdr * section,
18009 Elf_External_Note * pnotes;
18010 Elf_External_Note * external;
18012 bfd_boolean res = TRUE;
18019 pnotes = (Elf_External_Note *) get_section_contents (section, filedata);
18022 if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL))
18027 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
18030 if (pnotes == NULL)
18036 printf (_("\nDisplaying notes found in: %s\n"), printable_section_name (filedata, section));
18038 printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
18039 (unsigned long) offset, (unsigned long) length);
18041 /* NB: Some note sections may have alignment value of 0 or 1. gABI
18042 specifies that notes should be aligned to 4 bytes in 32-bit
18043 objects and to 8 bytes in 64-bit objects. As a Linux extension,
18044 we also support 4 byte alignment in 64-bit objects. If section
18045 alignment is less than 4, we treate alignment as 4 bytes. */
18048 else if (align != 4 && align != 8)
18050 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
18055 printf (_(" %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
18057 end = (char *) pnotes + length;
18058 while ((char *) external < end)
18060 Elf_Internal_Note inote;
18063 char * temp = NULL;
18064 size_t data_remaining = end - (char *) external;
18066 if (!is_ia64_vms (filedata))
18068 /* PR binutils/15191
18069 Make sure that there is enough data to read. */
18070 min_notesz = offsetof (Elf_External_Note, name);
18071 if (data_remaining < min_notesz)
18073 warn (ngettext ("Corrupt note: only %ld byte remains, "
18074 "not enough for a full note\n",
18075 "Corrupt note: only %ld bytes remain, "
18076 "not enough for a full note\n",
18078 (long) data_remaining);
18081 data_remaining -= min_notesz;
18083 inote.type = BYTE_GET (external->type);
18084 inote.namesz = BYTE_GET (external->namesz);
18085 inote.namedata = external->name;
18086 inote.descsz = BYTE_GET (external->descsz);
18087 inote.descdata = ((char *) external
18088 + ELF_NOTE_DESC_OFFSET (inote.namesz, align));
18089 inote.descpos = offset + (inote.descdata - (char *) pnotes);
18090 next = ((char *) external
18091 + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align));
18095 Elf64_External_VMS_Note *vms_external;
18097 /* PR binutils/15191
18098 Make sure that there is enough data to read. */
18099 min_notesz = offsetof (Elf64_External_VMS_Note, name);
18100 if (data_remaining < min_notesz)
18102 warn (ngettext ("Corrupt note: only %ld byte remains, "
18103 "not enough for a full note\n",
18104 "Corrupt note: only %ld bytes remain, "
18105 "not enough for a full note\n",
18107 (long) data_remaining);
18110 data_remaining -= min_notesz;
18112 vms_external = (Elf64_External_VMS_Note *) external;
18113 inote.type = BYTE_GET (vms_external->type);
18114 inote.namesz = BYTE_GET (vms_external->namesz);
18115 inote.namedata = vms_external->name;
18116 inote.descsz = BYTE_GET (vms_external->descsz);
18117 inote.descdata = inote.namedata + align_power (inote.namesz, 3);
18118 inote.descpos = offset + (inote.descdata - (char *) pnotes);
18119 next = inote.descdata + align_power (inote.descsz, 3);
18122 /* PR 17531: file: 3443835e. */
18123 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
18124 if ((size_t) (inote.descdata - inote.namedata) < inote.namesz
18125 || (size_t) (inote.descdata - inote.namedata) > data_remaining
18126 || (size_t) (next - inote.descdata) < inote.descsz
18127 || ((size_t) (next - inote.descdata)
18128 > data_remaining - (size_t) (inote.descdata - inote.namedata)))
18130 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
18131 (unsigned long) ((char *) external - (char *) pnotes));
18132 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
18133 inote.type, inote.namesz, inote.descsz, (int) align);
18137 external = (Elf_External_Note *) next;
18139 /* Verify that name is null terminated. It appears that at least
18140 one version of Linux (RedHat 6.0) generates corefiles that don't
18141 comply with the ELF spec by failing to include the null byte in
18143 if (inote.namedata[inote.namesz - 1] != '\0')
18145 if ((size_t) (inote.descdata - inote.namedata) == inote.namesz)
18147 temp = (char *) malloc (inote.namesz + 1);
18150 error (_("Out of memory allocating space for inote name\n"));
18155 memcpy (temp, inote.namedata, inote.namesz);
18156 inote.namedata = temp;
18158 inote.namedata[inote.namesz] = 0;
18161 if (! process_note (& inote, filedata))
18177 process_corefile_note_segments (Filedata * filedata)
18179 Elf_Internal_Phdr * segment;
18181 bfd_boolean res = TRUE;
18183 if (! get_program_headers (filedata))
18186 for (i = 0, segment = filedata->program_headers;
18187 i < filedata->file_header.e_phnum;
18190 if (segment->p_type == PT_NOTE)
18191 if (! process_notes_at (filedata, NULL,
18192 (bfd_vma) segment->p_offset,
18193 (bfd_vma) segment->p_filesz,
18194 (bfd_vma) segment->p_align))
18202 process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length)
18204 Elf_External_Note * pnotes;
18205 Elf_External_Note * external;
18207 bfd_boolean res = TRUE;
18212 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
18214 if (pnotes == NULL)
18218 end = (char*) pnotes + length;
18220 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
18221 (unsigned long) offset, (unsigned long) length);
18223 while ((char *) external + sizeof (Elf_External_Note) < end)
18225 Elf_External_Note * next;
18226 Elf_Internal_Note inote;
18228 inote.type = BYTE_GET (external->type);
18229 inote.namesz = BYTE_GET (external->namesz);
18230 inote.namedata = external->name;
18231 inote.descsz = BYTE_GET (external->descsz);
18232 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
18233 inote.descpos = offset + (inote.descdata - (char *) pnotes);
18235 if (inote.descdata < (char *) pnotes || inote.descdata >= end)
18237 warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
18238 inote.descdata = inote.namedata;
18242 next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
18244 if ( ((char *) next > end)
18245 || ((char *) next < (char *) pnotes))
18247 warn (_("corrupt descsz found in note at offset 0x%lx\n"),
18248 (unsigned long) ((char *) external - (char *) pnotes));
18249 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
18250 inote.type, inote.namesz, inote.descsz);
18256 /* Prevent out-of-bounds indexing. */
18257 if ( inote.namedata + inote.namesz > end
18258 || inote.namedata + inote.namesz < inote.namedata)
18260 warn (_("corrupt namesz found in note at offset 0x%lx\n"),
18261 (unsigned long) ((char *) external - (char *) pnotes));
18262 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
18263 inote.type, inote.namesz, inote.descsz);
18267 printf (" %s: ", get_v850_elf_note_type (inote.type));
18269 if (! print_v850_note (& inote))
18272 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
18273 inote.namesz, inote.descsz);
18283 process_note_sections (Filedata * filedata)
18285 Elf_Internal_Shdr * section;
18287 unsigned int n = 0;
18288 bfd_boolean res = TRUE;
18290 for (i = 0, section = filedata->section_headers;
18291 i < filedata->file_header.e_shnum && section != NULL;
18294 if (section->sh_type == SHT_NOTE)
18296 if (! process_notes_at (filedata, section,
18297 (bfd_vma) section->sh_offset,
18298 (bfd_vma) section->sh_size,
18299 (bfd_vma) section->sh_addralign))
18304 if (( filedata->file_header.e_machine == EM_V800
18305 || filedata->file_header.e_machine == EM_V850
18306 || filedata->file_header.e_machine == EM_CYGNUS_V850)
18307 && section->sh_type == SHT_RENESAS_INFO)
18309 if (! process_v850_notes (filedata,
18310 (bfd_vma) section->sh_offset,
18311 (bfd_vma) section->sh_size))
18318 /* Try processing NOTE segments instead. */
18319 return process_corefile_note_segments (filedata);
18325 process_notes (Filedata * filedata)
18327 /* If we have not been asked to display the notes then do nothing. */
18331 if (filedata->file_header.e_type != ET_CORE)
18332 return process_note_sections (filedata);
18334 /* No program headers means no NOTE segment. */
18335 if (filedata->file_header.e_phnum > 0)
18336 return process_corefile_note_segments (filedata);
18338 printf (_("No note segments present in the core file.\n"));
18342 static unsigned char *
18343 display_public_gnu_attributes (unsigned char * start,
18344 const unsigned char * const end)
18346 printf (_(" Unknown GNU attribute: %s\n"), start);
18348 start += strnlen ((char *) start, end - start);
18349 display_raw_attribute (start, end);
18351 return (unsigned char *) end;
18354 static unsigned char *
18355 display_generic_attribute (unsigned char * start,
18357 const unsigned char * const end)
18360 return (unsigned char *) end;
18362 return display_tag_value (tag, start, end);
18366 process_arch_specific (Filedata * filedata)
18371 switch (filedata->file_header.e_machine)
18374 case EM_ARC_COMPACT:
18375 case EM_ARC_COMPACT2:
18376 return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES,
18377 display_arc_attribute,
18378 display_generic_attribute);
18380 return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES,
18381 display_arm_attribute,
18382 display_generic_attribute);
18385 case EM_MIPS_RS3_LE:
18386 return process_mips_specific (filedata);
18389 return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES,
18390 display_msp430x_attribute,
18391 display_generic_attribute);
18394 return process_nds32_specific (filedata);
18398 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
18399 display_power_gnu_attribute);
18403 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
18404 display_s390_gnu_attribute);
18407 case EM_SPARC32PLUS:
18409 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
18410 display_sparc_gnu_attribute);
18413 return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES,
18414 display_tic6x_attribute,
18415 display_generic_attribute);
18418 return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES,
18419 display_public_gnu_attributes,
18420 display_generic_attribute);
18425 get_file_header (Filedata * filedata)
18427 /* Read in the identity array. */
18428 if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1)
18431 /* Determine how to read the rest of the header. */
18432 switch (filedata->file_header.e_ident[EI_DATA])
18437 byte_get = byte_get_little_endian;
18438 byte_put = byte_put_little_endian;
18441 byte_get = byte_get_big_endian;
18442 byte_put = byte_put_big_endian;
18446 /* For now we only support 32 bit and 64 bit ELF files. */
18447 is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64);
18449 /* Read in the rest of the header. */
18452 Elf32_External_Ehdr ehdr32;
18454 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1)
18457 filedata->file_header.e_type = BYTE_GET (ehdr32.e_type);
18458 filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine);
18459 filedata->file_header.e_version = BYTE_GET (ehdr32.e_version);
18460 filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry);
18461 filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
18462 filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
18463 filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags);
18464 filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
18465 filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
18466 filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
18467 filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
18468 filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
18469 filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
18473 Elf64_External_Ehdr ehdr64;
18475 /* If we have been compiled with sizeof (bfd_vma) == 4, then
18476 we will not be able to cope with the 64bit data found in
18477 64 ELF files. Detect this now and abort before we start
18478 overwriting things. */
18479 if (sizeof (bfd_vma) < 8)
18481 error (_("This instance of readelf has been built without support for a\n\
18482 64 bit data type and so it cannot read 64 bit ELF files.\n"));
18486 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1)
18489 filedata->file_header.e_type = BYTE_GET (ehdr64.e_type);
18490 filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine);
18491 filedata->file_header.e_version = BYTE_GET (ehdr64.e_version);
18492 filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry);
18493 filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
18494 filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
18495 filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags);
18496 filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
18497 filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
18498 filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
18499 filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
18500 filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
18501 filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
18504 if (filedata->file_header.e_shoff)
18506 /* There may be some extensions in the first section header. Don't
18507 bomb if we can't read it. */
18509 get_32bit_section_headers (filedata, TRUE);
18511 get_64bit_section_headers (filedata, TRUE);
18518 close_file (Filedata * filedata)
18522 if (filedata->handle)
18523 fclose (filedata->handle);
18529 close_debug_file (void * data)
18531 close_file ((Filedata *) data);
18535 open_file (const char * pathname)
18537 struct stat statbuf;
18538 Filedata * filedata = NULL;
18540 if (stat (pathname, & statbuf) < 0
18541 || ! S_ISREG (statbuf.st_mode))
18544 filedata = calloc (1, sizeof * filedata);
18545 if (filedata == NULL)
18548 filedata->handle = fopen (pathname, "rb");
18549 if (filedata->handle == NULL)
18552 filedata->file_size = (bfd_size_type) statbuf.st_size;
18553 filedata->file_name = pathname;
18555 if (! get_file_header (filedata))
18558 if (filedata->file_header.e_shoff)
18562 /* Read the section headers again, this time for real. */
18564 res = get_32bit_section_headers (filedata, FALSE);
18566 res = get_64bit_section_headers (filedata, FALSE);
18577 if (filedata->handle)
18578 fclose (filedata->handle);
18585 open_debug_file (const char * pathname)
18587 return open_file (pathname);
18590 /* Process one ELF object file according to the command line options.
18591 This file may actually be stored in an archive. The file is
18592 positioned at the start of the ELF object. Returns TRUE if no
18593 problems were encountered, FALSE otherwise. */
18596 process_object (Filedata * filedata)
18598 Filedata * separates;
18600 bfd_boolean res = TRUE;
18602 if (! get_file_header (filedata))
18604 error (_("%s: Failed to read file header\n"), filedata->file_name);
18608 /* Initialise per file variables. */
18609 for (i = ARRAY_SIZE (version_info); i--;)
18610 version_info[i] = 0;
18612 for (i = ARRAY_SIZE (dynamic_info); i--;)
18613 dynamic_info[i] = 0;
18614 dynamic_info_DT_GNU_HASH = 0;
18616 /* Process the file. */
18618 printf (_("\nFile: %s\n"), filedata->file_name);
18620 /* Initialise the dump_sects array from the cmdline_dump_sects array.
18621 Note we do this even if cmdline_dump_sects is empty because we
18622 must make sure that the dump_sets array is zeroed out before each
18623 object file is processed. */
18624 if (filedata->num_dump_sects > cmdline.num_dump_sects)
18625 memset (filedata->dump_sects, 0, filedata->num_dump_sects * sizeof (* filedata->dump_sects));
18627 if (cmdline.num_dump_sects > 0)
18629 if (filedata->num_dump_sects == 0)
18630 /* A sneaky way of allocating the dump_sects array. */
18631 request_dump_bynumber (filedata, cmdline.num_dump_sects, 0);
18633 assert (filedata->num_dump_sects >= cmdline.num_dump_sects);
18634 memcpy (filedata->dump_sects, cmdline.dump_sects,
18635 cmdline.num_dump_sects * sizeof (* filedata->dump_sects));
18638 if (! process_file_header (filedata))
18641 if (! process_section_headers (filedata))
18643 /* Without loaded section headers we cannot process lots of things. */
18644 do_unwind = do_version = do_dump = do_arch = FALSE;
18646 if (! do_using_dynamic)
18647 do_syms = do_dyn_syms = do_reloc = FALSE;
18650 if (! process_section_groups (filedata))
18651 /* Without loaded section groups we cannot process unwind. */
18654 if (process_program_headers (filedata))
18655 process_dynamic_section (filedata);
18659 if (! process_relocs (filedata))
18662 if (! process_unwind (filedata))
18665 if (! process_symbol_table (filedata))
18668 if (! process_syminfo (filedata))
18671 if (! process_version_sections (filedata))
18674 if (filedata->file_header.e_shstrndx != SHN_UNDEF)
18675 separates = load_separate_debug_file (filedata, filedata->file_name);
18679 if (! process_section_contents (filedata))
18684 if (! process_section_headers (separates))
18686 else if (! process_section_contents (separates))
18690 if (! process_notes (filedata))
18693 if (! process_gnu_liblist (filedata))
18696 if (! process_arch_specific (filedata))
18699 free (filedata->program_headers);
18700 filedata->program_headers = NULL;
18702 free (filedata->section_headers);
18703 filedata->section_headers = NULL;
18705 free (filedata->string_table);
18706 filedata->string_table = NULL;
18707 filedata->string_table_length = 0;
18709 if (dynamic_strings)
18711 free (dynamic_strings);
18712 dynamic_strings = NULL;
18713 dynamic_strings_length = 0;
18716 if (dynamic_symbols)
18718 free (dynamic_symbols);
18719 dynamic_symbols = NULL;
18720 num_dynamic_syms = 0;
18723 if (dynamic_syminfo)
18725 free (dynamic_syminfo);
18726 dynamic_syminfo = NULL;
18729 if (dynamic_section)
18731 free (dynamic_section);
18732 dynamic_section = NULL;
18735 if (section_headers_groups)
18737 free (section_headers_groups);
18738 section_headers_groups = NULL;
18741 if (section_groups)
18743 struct group_list * g;
18744 struct group_list * next;
18746 for (i = 0; i < group_count; i++)
18748 for (g = section_groups [i].root; g != NULL; g = next)
18755 free (section_groups);
18756 section_groups = NULL;
18759 free_debug_memory ();
18764 /* Process an ELF archive.
18765 On entry the file is positioned just after the ARMAG string.
18766 Returns TRUE upon success, FALSE otherwise. */
18769 process_archive (Filedata * filedata, bfd_boolean is_thin_archive)
18771 struct archive_info arch;
18772 struct archive_info nested_arch;
18774 bfd_boolean ret = TRUE;
18778 /* The ARCH structure is used to hold information about this archive. */
18779 arch.file_name = NULL;
18781 arch.index_array = NULL;
18782 arch.sym_table = NULL;
18783 arch.longnames = NULL;
18785 /* The NESTED_ARCH structure is used as a single-item cache of information
18786 about a nested archive (when members of a thin archive reside within
18787 another regular archive file). */
18788 nested_arch.file_name = NULL;
18789 nested_arch.file = NULL;
18790 nested_arch.index_array = NULL;
18791 nested_arch.sym_table = NULL;
18792 nested_arch.longnames = NULL;
18794 if (setup_archive (&arch, filedata->file_name, filedata->handle,
18795 is_thin_archive, do_archive_index) != 0)
18801 if (do_archive_index)
18803 if (arch.sym_table == NULL)
18804 error (_("%s: unable to dump the index as none was found\n"), filedata->file_name);
18807 unsigned long i, l;
18808 unsigned long current_pos;
18810 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"),
18811 filedata->file_name, (unsigned long) arch.index_num, arch.sym_size);
18813 current_pos = ftell (filedata->handle);
18815 for (i = l = 0; i < arch.index_num; i++)
18817 if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
18819 char * member_name;
18821 member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
18823 if (member_name != NULL)
18825 char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
18827 if (qualified_name != NULL)
18829 printf (_("Contents of binary %s at offset "), qualified_name);
18830 (void) print_vma (arch.index_array[i], PREFIX_HEX);
18832 free (qualified_name);
18837 if (l >= arch.sym_size)
18839 error (_("%s: end of the symbol table reached before the end of the index\n"),
18840 filedata->file_name);
18844 /* PR 17531: file: 0b6630b2. */
18845 printf ("\t%.*s\n", (int) (arch.sym_size - l), arch.sym_table + l);
18846 l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
18849 if (arch.uses_64bit_indicies)
18854 if (l < arch.sym_size)
18856 error (ngettext ("%s: %ld byte remains in the symbol table, "
18857 "but without corresponding entries in "
18858 "the index table\n",
18859 "%s: %ld bytes remain in the symbol table, "
18860 "but without corresponding entries in "
18861 "the index table\n",
18862 arch.sym_size - l),
18863 filedata->file_name, arch.sym_size - l);
18867 if (fseek (filedata->handle, current_pos, SEEK_SET) != 0)
18869 error (_("%s: failed to seek back to start of object files in the archive\n"),
18870 filedata->file_name);
18876 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
18877 && !do_segments && !do_header && !do_dump && !do_version
18878 && !do_histogram && !do_debugging && !do_arch && !do_notes
18879 && !do_section_groups && !do_dyn_syms)
18881 ret = TRUE; /* Archive index only. */
18890 char * qualified_name;
18892 /* Read the next archive header. */
18893 if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0)
18895 error (_("%s: failed to seek to next archive header\n"), filedata->file_name);
18898 got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle);
18899 if (got != sizeof arch.arhdr)
18903 error (_("%s: failed to read archive header\n"), filedata->file_name);
18907 if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
18909 error (_("%s: did not find a valid archive header\n"), arch.file_name);
18914 arch.next_arhdr_offset += sizeof arch.arhdr;
18916 archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
18917 if (archive_file_size & 01)
18918 ++archive_file_size;
18920 name = get_archive_member_name (&arch, &nested_arch);
18923 error (_("%s: bad archive file name\n"), filedata->file_name);
18927 namelen = strlen (name);
18929 qualified_name = make_qualified_name (&arch, &nested_arch, name);
18930 if (qualified_name == NULL)
18932 error (_("%s: bad archive file name\n"), filedata->file_name);
18937 if (is_thin_archive && arch.nested_member_origin == 0)
18939 /* This is a proxy for an external member of a thin archive. */
18940 Filedata * member_filedata;
18941 char * member_file_name = adjust_relative_path
18942 (filedata->file_name, name, namelen);
18944 if (member_file_name == NULL)
18950 member_filedata = open_file (member_file_name);
18951 if (member_filedata == NULL)
18953 error (_("Input file '%s' is not readable.\n"), member_file_name);
18954 free (member_file_name);
18959 archive_file_offset = arch.nested_member_origin;
18960 member_filedata->file_name = qualified_name;
18962 if (! process_object (member_filedata))
18965 close_file (member_filedata);
18966 free (member_file_name);
18968 else if (is_thin_archive)
18970 Filedata thin_filedata;
18972 memset (&thin_filedata, 0, sizeof (thin_filedata));
18974 /* PR 15140: Allow for corrupt thin archives. */
18975 if (nested_arch.file == NULL)
18977 error (_("%s: contains corrupt thin archive: %s\n"),
18978 filedata->file_name, name);
18983 /* This is a proxy for a member of a nested archive. */
18984 archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
18986 /* The nested archive file will have been opened and setup by
18987 get_archive_member_name. */
18988 if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
18990 error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
18995 thin_filedata.handle = nested_arch.file;
18996 thin_filedata.file_name = qualified_name;
18998 if (! process_object (& thin_filedata))
19003 archive_file_offset = arch.next_arhdr_offset;
19004 arch.next_arhdr_offset += archive_file_size;
19006 filedata->file_name = qualified_name;
19007 if (! process_object (filedata))
19011 if (filedata->dump_sects != NULL)
19013 free (filedata->dump_sects);
19014 filedata->dump_sects = NULL;
19015 filedata->num_dump_sects = 0;
19018 free (qualified_name);
19022 if (nested_arch.file != NULL)
19023 fclose (nested_arch.file);
19024 release_archive (&nested_arch);
19025 release_archive (&arch);
19031 process_file (char * file_name)
19033 Filedata * filedata = NULL;
19034 struct stat statbuf;
19035 char armag[SARMAG];
19036 bfd_boolean ret = TRUE;
19038 if (stat (file_name, &statbuf) < 0)
19040 if (errno == ENOENT)
19041 error (_("'%s': No such file\n"), file_name);
19043 error (_("Could not locate '%s'. System error message: %s\n"),
19044 file_name, strerror (errno));
19048 if (! S_ISREG (statbuf.st_mode))
19050 error (_("'%s' is not an ordinary file\n"), file_name);
19054 filedata = calloc (1, sizeof * filedata);
19055 if (filedata == NULL)
19057 error (_("Out of memory allocating file data structure\n"));
19061 filedata->file_name = file_name;
19062 filedata->handle = fopen (file_name, "rb");
19063 if (filedata->handle == NULL)
19065 error (_("Input file '%s' is not readable.\n"), file_name);
19070 if (fread (armag, SARMAG, 1, filedata->handle) != 1)
19072 error (_("%s: Failed to read file's magic number\n"), file_name);
19073 fclose (filedata->handle);
19078 filedata->file_size = (bfd_size_type) statbuf.st_size;
19080 if (memcmp (armag, ARMAG, SARMAG) == 0)
19082 if (! process_archive (filedata, FALSE))
19085 else if (memcmp (armag, ARMAGT, SARMAG) == 0)
19087 if ( ! process_archive (filedata, TRUE))
19092 if (do_archive_index)
19093 error (_("File %s is not an archive so its index cannot be displayed.\n"),
19096 rewind (filedata->handle);
19097 archive_file_size = archive_file_offset = 0;
19099 if (! process_object (filedata))
19103 fclose (filedata->handle);
19109 #ifdef SUPPORT_DISASSEMBLY
19110 /* Needed by the i386 disassembler. For extra credit, someone could
19111 fix this so that we insert symbolic addresses here, esp for GOT/PLT
19115 print_address (unsigned int addr, FILE * outfile)
19117 fprintf (outfile,"0x%8.8x", addr);
19120 /* Needed by the i386 disassembler. */
19123 db_task_printsym (unsigned int addr)
19125 print_address (addr, stderr);
19130 main (int argc, char ** argv)
19134 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
19135 setlocale (LC_MESSAGES, "");
19137 #if defined (HAVE_SETLOCALE)
19138 setlocale (LC_CTYPE, "");
19140 bindtextdomain (PACKAGE, LOCALEDIR);
19141 textdomain (PACKAGE);
19143 expandargv (&argc, &argv);
19145 cmdline.file_name = "<cmdline>";
19146 parse_args (& cmdline, argc, argv);
19148 if (optind < (argc - 1))
19150 else if (optind >= argc)
19152 warn (_("Nothing to do.\n"));
19157 while (optind < argc)
19158 if (! process_file (argv[optind++]))
19161 if (cmdline.dump_sects != NULL)
19162 free (cmdline.dump_sects);
19164 return err ? EXIT_FAILURE : EXIT_SUCCESS;