Home | History | Annotate | Download | only in binutils
      1 /* readelf.c -- display contents of an ELF format file
      2    Copyright (C) 1998-2014 Free Software Foundation, Inc.
      3 
      4    Originally developed by Eric Youngdale <eric (at) andante.jic.com>
      5    Modifications by Nick Clifton <nickc (at) redhat.com>
      6 
      7    This file is part of GNU Binutils.
      8 
      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.
     13 
     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.
     18 
     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
     22    02110-1301, USA.  */
     23 
     24 /* The difference between readelf and objdump:
     26 
     27   Both programs are capable of displaying the contents of ELF format files,
     28   so why does the binutils project have two file dumpers ?
     29 
     30   The reason is that objdump sees an ELF file through a BFD filter of the
     31   world; if BFD has a bug where, say, it disagrees about a machine constant
     32   in e_flags, then the odds are good that it will remain internally
     33   consistent.  The linker sees it the BFD way, objdump sees it the BFD way,
     34   GAS sees it the BFD way.  There was need for a tool to go find out what
     35   the file actually says.
     36 
     37   This is why the readelf program does not link against the BFD library - it
     38   exists as an independent program to help verify the correct working of BFD.
     39 
     40   There is also the case that readelf can provide more information about an
     41   ELF file than is provided by objdump.  In particular it can display DWARF
     42   debugging information which (at the moment) objdump cannot.  */
     43 
     44 #include "sysdep.h"
     46 #include <assert.h>
     47 #include <time.h>
     48 #ifdef HAVE_ZLIB_H
     49 #include <zlib.h>
     50 #endif
     51 #ifdef HAVE_WCHAR_H
     52 #include <wchar.h>
     53 #endif
     54 
     55 #if __GNUC__ >= 2
     56 /* Define BFD64 here, even if our default architecture is 32 bit ELF
     57    as this will allow us to read in and parse 64bit and 32bit ELF files.
     58    Only do this if we believe that the compiler can support a 64 bit
     59    data type.  For now we only rely on GCC being able to do this.  */
     60 #define BFD64
     61 #endif
     62 
     63 #include "bfd.h"
     64 #include "bucomm.h"
     65 #include "elfcomm.h"
     66 #include "dwarf.h"
     67 
     68 #include "elf/common.h"
     69 #include "elf/external.h"
     70 #include "elf/internal.h"
     71 
     72 
     73 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
     74    we can obtain the H8 reloc numbers.  We need these for the
     75    get_reloc_size() function.  We include h8.h again after defining
     76    RELOC_MACROS_GEN_FUNC so that we get the naming function as well.  */
     77 
     78 #include "elf/h8.h"
     79 #undef _ELF_H8_H
     80 
     81 /* Undo the effects of #including reloc-macros.h.  */
     82 
     83 #undef START_RELOC_NUMBERS
     84 #undef RELOC_NUMBER
     85 #undef FAKE_RELOC
     86 #undef EMPTY_RELOC
     87 #undef END_RELOC_NUMBERS
     88 #undef _RELOC_MACROS_H
     89 
     90 /* The following headers use the elf/reloc-macros.h file to
     91    automatically generate relocation recognition functions
     92    such as elf_mips_reloc_type()  */
     93 
     94 #define RELOC_MACROS_GEN_FUNC
     95 
     96 #include "elf/aarch64.h"
     97 #include "elf/alpha.h"
     98 #include "elf/arc.h"
     99 #include "elf/arm.h"
    100 #include "elf/avr.h"
    101 #include "elf/bfin.h"
    102 #include "elf/cr16.h"
    103 #include "elf/cris.h"
    104 #include "elf/crx.h"
    105 #include "elf/d10v.h"
    106 #include "elf/d30v.h"
    107 #include "elf/dlx.h"
    108 #include "elf/epiphany.h"
    109 #include "elf/fr30.h"
    110 #include "elf/frv.h"
    111 #include "elf/h8.h"
    112 #include "elf/hppa.h"
    113 #include "elf/i386.h"
    114 #include "elf/i370.h"
    115 #include "elf/i860.h"
    116 #include "elf/i960.h"
    117 #include "elf/ia64.h"
    118 #include "elf/ip2k.h"
    119 #include "elf/lm32.h"
    120 #include "elf/iq2000.h"
    121 #include "elf/m32c.h"
    122 #include "elf/m32r.h"
    123 #include "elf/m68k.h"
    124 #include "elf/m68hc11.h"
    125 #include "elf/mcore.h"
    126 #include "elf/mep.h"
    127 #include "elf/metag.h"
    128 #include "elf/microblaze.h"
    129 #include "elf/mips.h"
    130 #include "elf/mmix.h"
    131 #include "elf/mn10200.h"
    132 #include "elf/mn10300.h"
    133 #include "elf/moxie.h"
    134 #include "elf/mt.h"
    135 #include "elf/msp430.h"
    136 #include "elf/nds32.h"
    137 #include "elf/nios2.h"
    138 #include "elf/or1k.h"
    139 #include "elf/pj.h"
    140 #include "elf/ppc.h"
    141 #include "elf/ppc64.h"
    142 #include "elf/rl78.h"
    143 #include "elf/rx.h"
    144 #include "elf/s390.h"
    145 #include "elf/score.h"
    146 #include "elf/sh.h"
    147 #include "elf/sparc.h"
    148 #include "elf/spu.h"
    149 #include "elf/tic6x.h"
    150 #include "elf/tilegx.h"
    151 #include "elf/tilepro.h"
    152 #include "elf/v850.h"
    153 #include "elf/vax.h"
    154 #include "elf/x86-64.h"
    155 #include "elf/xc16x.h"
    156 #include "elf/xgate.h"
    157 #include "elf/xstormy16.h"
    158 #include "elf/xtensa.h"
    159 
    160 #include "getopt.h"
    161 #include "libiberty.h"
    162 #include "safe-ctype.h"
    163 #include "filenames.h"
    164 
    165 #ifndef offsetof
    166 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
    167 #endif
    168 
    169 char * program_name = "readelf";
    170 static long archive_file_offset;
    171 static unsigned long archive_file_size;
    172 static bfd_size_type current_file_size;
    173 static unsigned long dynamic_addr;
    174 static bfd_size_type dynamic_size;
    175 static size_t dynamic_nent;
    176 static char * dynamic_strings;
    177 static unsigned long dynamic_strings_length;
    178 static char * string_table;
    179 static unsigned long string_table_length;
    180 static unsigned long num_dynamic_syms;
    181 static Elf_Internal_Sym * dynamic_symbols;
    182 static Elf_Internal_Syminfo * dynamic_syminfo;
    183 static unsigned long dynamic_syminfo_offset;
    184 static unsigned int dynamic_syminfo_nent;
    185 static char program_interpreter[PATH_MAX];
    186 static bfd_vma dynamic_info[DT_ENCODING];
    187 static bfd_vma dynamic_info_DT_GNU_HASH;
    188 static bfd_vma version_info[16];
    189 static Elf_Internal_Ehdr elf_header;
    190 static Elf_Internal_Shdr * section_headers;
    191 static Elf_Internal_Phdr * program_headers;
    192 static Elf_Internal_Dyn *  dynamic_section;
    193 static Elf_Internal_Shdr * symtab_shndx_hdr;
    194 static int show_name;
    195 static int do_dynamic;
    196 static int do_syms;
    197 static int do_dyn_syms;
    198 static int do_reloc;
    199 static int do_sections;
    200 static int do_section_groups;
    201 static int do_section_details;
    202 static int do_segments;
    203 static int do_unwind;
    204 static int do_using_dynamic;
    205 static int do_header;
    206 static int do_dump;
    207 static int do_version;
    208 static int do_histogram;
    209 static int do_debugging;
    210 static int do_arch;
    211 static int do_notes;
    212 static int do_archive_index;
    213 static int is_32bit_elf;
    214 
    215 struct group_list
    216 {
    217   struct group_list * next;
    218   unsigned int section_index;
    219 };
    220 
    221 struct group
    222 {
    223   struct group_list * root;
    224   unsigned int group_index;
    225 };
    226 
    227 static size_t group_count;
    228 static struct group * section_groups;
    229 static struct group ** section_headers_groups;
    230 
    231 
    232 /* Flag bits indicating particular types of dump.  */
    233 #define HEX_DUMP	(1 << 0)	/* The -x command line switch.  */
    234 #define DISASS_DUMP	(1 << 1)	/* The -i command line switch.  */
    235 #define DEBUG_DUMP	(1 << 2)	/* The -w command line switch.  */
    236 #define STRING_DUMP     (1 << 3)	/* The -p command line switch.  */
    237 #define RELOC_DUMP      (1 << 4)	/* The -R command line switch.  */
    238 
    239 typedef unsigned char dump_type;
    240 
    241 /* A linked list of the section names for which dumps were requested.  */
    242 struct dump_list_entry
    243 {
    244   char * name;
    245   dump_type type;
    246   struct dump_list_entry * next;
    247 };
    248 static struct dump_list_entry * dump_sects_byname;
    249 
    250 /* A dynamic array of flags indicating for which sections a dump
    251    has been requested via command line switches.  */
    252 static dump_type *   cmdline_dump_sects = NULL;
    253 static unsigned int  num_cmdline_dump_sects = 0;
    254 
    255 /* A dynamic array of flags indicating for which sections a dump of
    256    some kind has been requested.  It is reset on a per-object file
    257    basis and then initialised from the cmdline_dump_sects array,
    258    the results of interpreting the -w switch, and the
    259    dump_sects_byname list.  */
    260 static dump_type *   dump_sects = NULL;
    261 static unsigned int  num_dump_sects = 0;
    262 
    263 
    264 /* How to print a vma value.  */
    265 typedef enum print_mode
    266 {
    267   HEX,
    268   DEC,
    269   DEC_5,
    270   UNSIGNED,
    271   PREFIX_HEX,
    272   FULL_HEX,
    273   LONG_HEX
    274 }
    275 print_mode;
    276 
    277 #define UNKNOWN -1
    278 
    279 #define SECTION_NAME(X)						\
    280   ((X) == NULL ? _("<none>")					\
    281    : string_table == NULL ? _("<no-name>")			\
    282    : ((X)->sh_name >= string_table_length ? _("<corrupt>")	\
    283   : string_table + (X)->sh_name))
    284 
    285 #define DT_VERSIONTAGIDX(tag)	(DT_VERNEEDNUM - (tag))	/* Reverse order!  */
    286 
    287 #define GET_ELF_SYMBOLS(file, section, sym_count)			\
    288   (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count)	\
    289    : get_64bit_elf_symbols (file, section, sym_count))
    290 
    291 #define VALID_DYNAMIC_NAME(offset)	((dynamic_strings != NULL) && (offset < dynamic_strings_length))
    292 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
    293    already been called and verified that the string exists.  */
    294 #define GET_DYNAMIC_NAME(offset)	(dynamic_strings + offset)
    295 
    296 #define REMOVE_ARCH_BITS(ADDR)			\
    297   do						\
    298     {						\
    299       if (elf_header.e_machine == EM_ARM)	\
    300 	(ADDR) &= ~1;				\
    301     }						\
    302   while (0)
    303 
    304 /* Retrieve NMEMB structures, each SIZE bytes long from FILE starting at OFFSET.
    306    Put the retrieved data into VAR, if it is not NULL.  Otherwise allocate a buffer
    307    using malloc and fill that.  In either case return the pointer to the start of
    308    the retrieved data or NULL if something went wrong.  If something does go wrong
    309    emit an error message using REASON as part of the context.  */
    310 
    311 static void *
    312 get_data (void * var, FILE * file, long offset, size_t size, size_t nmemb,
    313 	  const char * reason)
    314 {
    315   void * mvar;
    316 
    317   if (size == 0 || nmemb == 0)
    318     return NULL;
    319 
    320   if (fseek (file, archive_file_offset + offset, SEEK_SET))
    321     {
    322       if (reason)
    323 	error (_("Unable to seek to 0x%lx for %s\n"),
    324 	       (unsigned long) archive_file_offset + offset, reason);
    325       return NULL;
    326     }
    327 
    328   /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
    329      attempting to allocate memory when the read is bound to fail.  */
    330   if (offset + archive_file_offset + size * nmemb > current_file_size)
    331     {
    332       if (reason)
    333 	error (_("Reading 0x%lx bytes extends past end of file for %s\n"),
    334 	       (unsigned long) (size * nmemb), reason);
    335       return NULL;
    336     }
    337 
    338   mvar = var;
    339   if (mvar == NULL)
    340     {
    341       /* Check for overflow.  */
    342       if (nmemb < (~(size_t) 0 - 1) / size)
    343 	/* + 1 so that we can '\0' terminate invalid string table sections.  */
    344 	mvar = malloc (size * nmemb + 1);
    345 
    346       if (mvar == NULL)
    347 	{
    348 	  if (reason)
    349 	    error (_("Out of memory allocating 0x%lx bytes for %s\n"),
    350 		   (unsigned long)(size * nmemb), reason);
    351 	  return NULL;
    352 	}
    353 
    354       ((char *) mvar)[size * nmemb] = '\0';
    355     }
    356 
    357   if (fread (mvar, size, nmemb, file) != nmemb)
    358     {
    359       if (reason)
    360 	error (_("Unable to read in 0x%lx bytes of %s\n"),
    361 	       (unsigned long)(size * nmemb), reason);
    362       if (mvar != var)
    363 	free (mvar);
    364       return NULL;
    365     }
    366 
    367   return mvar;
    368 }
    369 
    370 /* Print a VMA value.  */
    371 
    372 static int
    373 print_vma (bfd_vma vma, print_mode mode)
    374 {
    375   int nc = 0;
    376 
    377   switch (mode)
    378     {
    379     case FULL_HEX:
    380       nc = printf ("0x");
    381       /* Drop through.  */
    382 
    383     case LONG_HEX:
    384 #ifdef BFD64
    385       if (is_32bit_elf)
    386 	return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
    387 #endif
    388       printf_vma (vma);
    389       return nc + 16;
    390 
    391     case DEC_5:
    392       if (vma <= 99999)
    393 	return printf ("%5" BFD_VMA_FMT "d", vma);
    394       /* Drop through.  */
    395 
    396     case PREFIX_HEX:
    397       nc = printf ("0x");
    398       /* Drop through.  */
    399 
    400     case HEX:
    401       return nc + printf ("%" BFD_VMA_FMT "x", vma);
    402 
    403     case DEC:
    404       return printf ("%" BFD_VMA_FMT "d", vma);
    405 
    406     case UNSIGNED:
    407       return printf ("%" BFD_VMA_FMT "u", vma);
    408     }
    409   return 0;
    410 }
    411 
    412 /* Display a symbol on stdout.  Handles the display of control characters and
    413    multibye characters (assuming the host environment supports them).
    414 
    415    Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
    416 
    417    If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
    418    padding as necessary.
    419 
    420    Returns the number of emitted characters.  */
    421 
    422 static unsigned int
    423 print_symbol (int width, const char *symbol)
    424 {
    425   bfd_boolean extra_padding = FALSE;
    426   int num_printed = 0;
    427 #ifdef HAVE_MBSTATE_T
    428   mbstate_t state;
    429 #endif
    430   int width_remaining;
    431 
    432   if (width < 0)
    433     {
    434       /* Keep the width positive.  This also helps.  */
    435       width = - width;
    436       extra_padding = TRUE;
    437     }
    438   assert (width != 0);
    439 
    440   if (do_wide)
    441     /* Set the remaining width to a very large value.
    442        This simplifies the code below.  */
    443     width_remaining = INT_MAX;
    444   else
    445     width_remaining = width;
    446 
    447 #ifdef HAVE_MBSTATE_T
    448   /* Initialise the multibyte conversion state.  */
    449   memset (& state, 0, sizeof (state));
    450 #endif
    451 
    452   while (width_remaining)
    453     {
    454       size_t  n;
    455       const char c = *symbol++;
    456 
    457       if (c == 0)
    458 	break;
    459 
    460       /* Do not print control characters directly as they can affect terminal
    461 	 settings.  Such characters usually appear in the names generated
    462 	 by the assembler for local labels.  */
    463       if (ISCNTRL (c))
    464 	{
    465 	  if (width_remaining < 2)
    466 	    break;
    467 
    468 	  printf ("^%c", c + 0x40);
    469 	  width_remaining -= 2;
    470 	  num_printed += 2;
    471 	}
    472       else if (ISPRINT (c))
    473 	{
    474 	  putchar (c);
    475 	  width_remaining --;
    476 	  num_printed ++;
    477 	}
    478       else
    479 	{
    480 #ifdef HAVE_MBSTATE_T
    481 	  wchar_t w;
    482 #endif
    483 	  /* Let printf do the hard work of displaying multibyte characters.  */
    484 	  printf ("%.1s", symbol - 1);
    485 	  width_remaining --;
    486 	  num_printed ++;
    487 
    488 #ifdef HAVE_MBSTATE_T
    489 	  /* Try to find out how many bytes made up the character that was
    490 	     just printed.  Advance the symbol pointer past the bytes that
    491 	     were displayed.  */
    492 	  n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
    493 #else
    494 	  n = 1;
    495 #endif
    496 	  if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
    497 	    symbol += (n - 1);
    498 	}
    499     }
    500 
    501   if (extra_padding && num_printed < width)
    502     {
    503       /* Fill in the remaining spaces.  */
    504       printf ("%-*s", width - num_printed, " ");
    505       num_printed = width;
    506     }
    507 
    508   return num_printed;
    509 }
    510 
    511 /* Returns a pointer to a static buffer containing a  printable version of
    512    the given section's name.  Like print_symbol, except that it does not try
    513    to print multibyte characters, it just interprets them as hex values.  */
    514 
    515 static const char *
    516 printable_section_name (Elf_Internal_Shdr * sec)
    517 {
    518 #define MAX_PRINT_SEC_NAME_LEN 128
    519   static char  sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
    520   const char * name = SECTION_NAME (sec);
    521   char *       buf = sec_name_buf;
    522   char         c;
    523   unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
    524 
    525   while ((c = * name ++) != 0)
    526     {
    527       if (ISCNTRL (c))
    528 	{
    529 	  if (remaining < 2)
    530 	    break;
    531 
    532 	  * buf ++ = '^';
    533 	  * buf ++ = c + 0x40;
    534 	  remaining -= 2;
    535 	}
    536       else if (ISPRINT (c))
    537 	{
    538 	  * buf ++ = c;
    539 	  remaining -= 1;
    540 	}
    541       else
    542 	{
    543 	  static char hex[17] = "0123456789ABCDEF";
    544 
    545 	  if (remaining < 4)
    546 	    break;
    547 	  * buf ++ = '<';
    548 	  * buf ++ = hex[(c & 0xf0) >> 4];
    549 	  * buf ++ = hex[c & 0x0f];
    550 	  * buf ++ = '>';
    551 	  remaining -= 4;
    552 	}
    553 
    554       if (remaining == 0)
    555 	break;
    556     }
    557 
    558   * buf = 0;
    559   return sec_name_buf;
    560 }
    561 
    562 static const char *
    563 printable_section_name_from_index (unsigned long ndx)
    564 {
    565   if (ndx >= elf_header.e_shnum)
    566     return _("<corrupt>");
    567 
    568   return printable_section_name (section_headers + ndx);
    569 }
    570 
    571 /* Return a pointer to section NAME, or NULL if no such section exists.  */
    572 
    573 static Elf_Internal_Shdr *
    574 find_section (const char * name)
    575 {
    576   unsigned int i;
    577 
    578   for (i = 0; i < elf_header.e_shnum; i++)
    579     if (streq (SECTION_NAME (section_headers + i), name))
    580       return section_headers + i;
    581 
    582   return NULL;
    583 }
    584 
    585 /* Return a pointer to a section containing ADDR, or NULL if no such
    586    section exists.  */
    587 
    588 static Elf_Internal_Shdr *
    589 find_section_by_address (bfd_vma addr)
    590 {
    591   unsigned int i;
    592 
    593   for (i = 0; i < elf_header.e_shnum; i++)
    594     {
    595       Elf_Internal_Shdr *sec = section_headers + i;
    596       if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
    597 	return sec;
    598     }
    599 
    600   return NULL;
    601 }
    602 
    603 static Elf_Internal_Shdr *
    604 find_section_by_type (unsigned int type)
    605 {
    606   unsigned int i;
    607 
    608   for (i = 0; i < elf_header.e_shnum; i++)
    609     {
    610       Elf_Internal_Shdr *sec = section_headers + i;
    611       if (sec->sh_type == type)
    612 	return sec;
    613     }
    614 
    615   return NULL;
    616 }
    617 
    618 /* Return a pointer to section NAME, or NULL if no such section exists,
    619    restricted to the list of sections given in SET.  */
    620 
    621 static Elf_Internal_Shdr *
    622 find_section_in_set (const char * name, unsigned int * set)
    623 {
    624   unsigned int i;
    625 
    626   if (set != NULL)
    627     {
    628       while ((i = *set++) > 0)
    629 	if (streq (SECTION_NAME (section_headers + i), name))
    630 	  return section_headers + i;
    631     }
    632 
    633   return find_section (name);
    634 }
    635 
    636 /* Read an unsigned LEB128 encoded value from p.  Set *PLEN to the number of
    637    bytes read.  */
    638 
    639 static inline unsigned long
    640 read_uleb128 (unsigned char *data,
    641 	      unsigned int *length_return,
    642 	      const unsigned char * const end)
    643 {
    644   return read_leb128 (data, length_return, FALSE, end);
    645 }
    646 
    647 /* Return true if the current file is for IA-64 machine and OpenVMS ABI.
    648    This OS has so many departures from the ELF standard that we test it at
    649    many places.  */
    650 
    651 static inline int
    652 is_ia64_vms (void)
    653 {
    654   return elf_header.e_machine == EM_IA_64
    655     && elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
    656 }
    657 
    658 /* Guess the relocation size commonly used by the specific machines.  */
    659 
    660 static int
    661 guess_is_rela (unsigned int e_machine)
    662 {
    663   switch (e_machine)
    664     {
    665       /* Targets that use REL relocations.  */
    666     case EM_386:
    667     case EM_486:
    668     case EM_960:
    669     case EM_ARM:
    670     case EM_D10V:
    671     case EM_CYGNUS_D10V:
    672     case EM_DLX:
    673     case EM_MIPS:
    674     case EM_MIPS_RS3_LE:
    675     case EM_CYGNUS_M32R:
    676     case EM_SCORE:
    677     case EM_XGATE:
    678       return FALSE;
    679 
    680       /* Targets that use RELA relocations.  */
    681     case EM_68K:
    682     case EM_860:
    683     case EM_AARCH64:
    684     case EM_ADAPTEVA_EPIPHANY:
    685     case EM_ALPHA:
    686     case EM_ALTERA_NIOS2:
    687     case EM_AVR:
    688     case EM_AVR_OLD:
    689     case EM_BLACKFIN:
    690     case EM_CR16:
    691     case EM_CRIS:
    692     case EM_CRX:
    693     case EM_D30V:
    694     case EM_CYGNUS_D30V:
    695     case EM_FR30:
    696     case EM_CYGNUS_FR30:
    697     case EM_CYGNUS_FRV:
    698     case EM_H8S:
    699     case EM_H8_300:
    700     case EM_H8_300H:
    701     case EM_IA_64:
    702     case EM_IP2K:
    703     case EM_IP2K_OLD:
    704     case EM_IQ2000:
    705     case EM_LATTICEMICO32:
    706     case EM_M32C_OLD:
    707     case EM_M32C:
    708     case EM_M32R:
    709     case EM_MCORE:
    710     case EM_CYGNUS_MEP:
    711     case EM_METAG:
    712     case EM_MMIX:
    713     case EM_MN10200:
    714     case EM_CYGNUS_MN10200:
    715     case EM_MN10300:
    716     case EM_CYGNUS_MN10300:
    717     case EM_MOXIE:
    718     case EM_MSP430:
    719     case EM_MSP430_OLD:
    720     case EM_MT:
    721     case EM_NDS32:
    722     case EM_NIOS32:
    723     case EM_OR1K:
    724     case EM_PPC64:
    725     case EM_PPC:
    726     case EM_RL78:
    727     case EM_RX:
    728     case EM_S390:
    729     case EM_S390_OLD:
    730     case EM_SH:
    731     case EM_SPARC:
    732     case EM_SPARC32PLUS:
    733     case EM_SPARCV9:
    734     case EM_SPU:
    735     case EM_TI_C6000:
    736     case EM_TILEGX:
    737     case EM_TILEPRO:
    738     case EM_V800:
    739     case EM_V850:
    740     case EM_CYGNUS_V850:
    741     case EM_VAX:
    742     case EM_X86_64:
    743     case EM_L1OM:
    744     case EM_K1OM:
    745     case EM_XSTORMY16:
    746     case EM_XTENSA:
    747     case EM_XTENSA_OLD:
    748     case EM_MICROBLAZE:
    749     case EM_MICROBLAZE_OLD:
    750       return TRUE;
    751 
    752     case EM_68HC05:
    753     case EM_68HC08:
    754     case EM_68HC11:
    755     case EM_68HC16:
    756     case EM_FX66:
    757     case EM_ME16:
    758     case EM_MMA:
    759     case EM_NCPU:
    760     case EM_NDR1:
    761     case EM_PCP:
    762     case EM_ST100:
    763     case EM_ST19:
    764     case EM_ST7:
    765     case EM_ST9PLUS:
    766     case EM_STARCORE:
    767     case EM_SVX:
    768     case EM_TINYJ:
    769     default:
    770       warn (_("Don't know about relocations on this machine architecture\n"));
    771       return FALSE;
    772     }
    773 }
    774 
    775 static int
    776 slurp_rela_relocs (FILE * file,
    777 		   unsigned long rel_offset,
    778 		   unsigned long rel_size,
    779 		   Elf_Internal_Rela ** relasp,
    780 		   unsigned long * nrelasp)
    781 {
    782   Elf_Internal_Rela * relas;
    783   size_t nrelas;
    784   unsigned int i;
    785 
    786   if (is_32bit_elf)
    787     {
    788       Elf32_External_Rela * erelas;
    789 
    790       erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset, 1,
    791                                                  rel_size, _("32-bit relocation data"));
    792       if (!erelas)
    793 	return 0;
    794 
    795       nrelas = rel_size / sizeof (Elf32_External_Rela);
    796 
    797       relas = (Elf_Internal_Rela *) cmalloc (nrelas,
    798                                              sizeof (Elf_Internal_Rela));
    799 
    800       if (relas == NULL)
    801 	{
    802 	  free (erelas);
    803 	  error (_("out of memory parsing relocs\n"));
    804 	  return 0;
    805 	}
    806 
    807       for (i = 0; i < nrelas; i++)
    808 	{
    809 	  relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
    810 	  relas[i].r_info   = BYTE_GET (erelas[i].r_info);
    811 	  relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
    812 	}
    813 
    814       free (erelas);
    815     }
    816   else
    817     {
    818       Elf64_External_Rela * erelas;
    819 
    820       erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset, 1,
    821                                                  rel_size, _("64-bit relocation data"));
    822       if (!erelas)
    823 	return 0;
    824 
    825       nrelas = rel_size / sizeof (Elf64_External_Rela);
    826 
    827       relas = (Elf_Internal_Rela *) cmalloc (nrelas,
    828                                              sizeof (Elf_Internal_Rela));
    829 
    830       if (relas == NULL)
    831 	{
    832 	  free (erelas);
    833 	  error (_("out of memory parsing relocs\n"));
    834 	  return 0;
    835 	}
    836 
    837       for (i = 0; i < nrelas; i++)
    838 	{
    839 	  relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
    840 	  relas[i].r_info   = BYTE_GET (erelas[i].r_info);
    841 	  relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
    842 
    843 	  /* The #ifdef BFD64 below is to prevent a compile time
    844 	     warning.  We know that if we do not have a 64 bit data
    845 	     type that we will never execute this code anyway.  */
    846 #ifdef BFD64
    847 	  if (elf_header.e_machine == EM_MIPS
    848 	      && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
    849 	    {
    850 	      /* In little-endian objects, r_info isn't really a
    851 		 64-bit little-endian value: it has a 32-bit
    852 		 little-endian symbol index followed by four
    853 		 individual byte fields.  Reorder INFO
    854 		 accordingly.  */
    855 	      bfd_vma inf = relas[i].r_info;
    856 	      inf = (((inf & 0xffffffff) << 32)
    857 		      | ((inf >> 56) & 0xff)
    858 		      | ((inf >> 40) & 0xff00)
    859 		      | ((inf >> 24) & 0xff0000)
    860 		      | ((inf >> 8) & 0xff000000));
    861 	      relas[i].r_info = inf;
    862 	    }
    863 #endif /* BFD64 */
    864 	}
    865 
    866       free (erelas);
    867     }
    868   *relasp = relas;
    869   *nrelasp = nrelas;
    870   return 1;
    871 }
    872 
    873 static int
    874 slurp_rel_relocs (FILE * file,
    875 		  unsigned long rel_offset,
    876 		  unsigned long rel_size,
    877 		  Elf_Internal_Rela ** relsp,
    878 		  unsigned long * nrelsp)
    879 {
    880   Elf_Internal_Rela * rels;
    881   size_t nrels;
    882   unsigned int i;
    883 
    884   if (is_32bit_elf)
    885     {
    886       Elf32_External_Rel * erels;
    887 
    888       erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset, 1,
    889                                                rel_size, _("32-bit relocation data"));
    890       if (!erels)
    891 	return 0;
    892 
    893       nrels = rel_size / sizeof (Elf32_External_Rel);
    894 
    895       rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
    896 
    897       if (rels == NULL)
    898 	{
    899 	  free (erels);
    900 	  error (_("out of memory parsing relocs\n"));
    901 	  return 0;
    902 	}
    903 
    904       for (i = 0; i < nrels; i++)
    905 	{
    906 	  rels[i].r_offset = BYTE_GET (erels[i].r_offset);
    907 	  rels[i].r_info   = BYTE_GET (erels[i].r_info);
    908 	  rels[i].r_addend = 0;
    909 	}
    910 
    911       free (erels);
    912     }
    913   else
    914     {
    915       Elf64_External_Rel * erels;
    916 
    917       erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset, 1,
    918                                                rel_size, _("64-bit relocation data"));
    919       if (!erels)
    920 	return 0;
    921 
    922       nrels = rel_size / sizeof (Elf64_External_Rel);
    923 
    924       rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
    925 
    926       if (rels == NULL)
    927 	{
    928 	  free (erels);
    929 	  error (_("out of memory parsing relocs\n"));
    930 	  return 0;
    931 	}
    932 
    933       for (i = 0; i < nrels; i++)
    934 	{
    935 	  rels[i].r_offset = BYTE_GET (erels[i].r_offset);
    936 	  rels[i].r_info   = BYTE_GET (erels[i].r_info);
    937 	  rels[i].r_addend = 0;
    938 
    939 	  /* The #ifdef BFD64 below is to prevent a compile time
    940 	     warning.  We know that if we do not have a 64 bit data
    941 	     type that we will never execute this code anyway.  */
    942 #ifdef BFD64
    943 	  if (elf_header.e_machine == EM_MIPS
    944 	      && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
    945 	    {
    946 	      /* In little-endian objects, r_info isn't really a
    947 		 64-bit little-endian value: it has a 32-bit
    948 		 little-endian symbol index followed by four
    949 		 individual byte fields.  Reorder INFO
    950 		 accordingly.  */
    951 	      bfd_vma inf = rels[i].r_info;
    952 	      inf = (((inf & 0xffffffff) << 32)
    953 		     | ((inf >> 56) & 0xff)
    954 		     | ((inf >> 40) & 0xff00)
    955 		     | ((inf >> 24) & 0xff0000)
    956 		     | ((inf >> 8) & 0xff000000));
    957 	      rels[i].r_info = inf;
    958 	    }
    959 #endif /* BFD64 */
    960 	}
    961 
    962       free (erels);
    963     }
    964   *relsp = rels;
    965   *nrelsp = nrels;
    966   return 1;
    967 }
    968 
    969 /* Returns the reloc type extracted from the reloc info field.  */
    970 
    971 static unsigned int
    972 get_reloc_type (bfd_vma reloc_info)
    973 {
    974   if (is_32bit_elf)
    975     return ELF32_R_TYPE (reloc_info);
    976 
    977   switch (elf_header.e_machine)
    978     {
    979     case EM_MIPS:
    980       /* Note: We assume that reloc_info has already been adjusted for us.  */
    981       return ELF64_MIPS_R_TYPE (reloc_info);
    982 
    983     case EM_SPARCV9:
    984       return ELF64_R_TYPE_ID (reloc_info);
    985 
    986     default:
    987       return ELF64_R_TYPE (reloc_info);
    988     }
    989 }
    990 
    991 /* Return the symbol index extracted from the reloc info field.  */
    992 
    993 static bfd_vma
    994 get_reloc_symindex (bfd_vma reloc_info)
    995 {
    996   return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
    997 }
    998 
    999 static inline bfd_boolean
   1000 uses_msp430x_relocs (void)
   1001 {
   1002   return
   1003     elf_header.e_machine == EM_MSP430 /* Paranoia.  */
   1004     /* GCC uses osabi == ELFOSBI_STANDALONE.  */
   1005     && (((elf_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
   1006 	/* TI compiler uses ELFOSABI_NONE.  */
   1007 	|| (elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
   1008 }
   1009 
   1010 /* Display the contents of the relocation data found at the specified
   1011    offset.  */
   1012 
   1013 static void
   1014 dump_relocations (FILE * file,
   1015 		  unsigned long rel_offset,
   1016 		  unsigned long rel_size,
   1017 		  Elf_Internal_Sym * symtab,
   1018 		  unsigned long nsyms,
   1019 		  char * strtab,
   1020 		  unsigned long strtablen,
   1021 		  int is_rela)
   1022 {
   1023   unsigned int i;
   1024   Elf_Internal_Rela * rels;
   1025 
   1026   if (is_rela == UNKNOWN)
   1027     is_rela = guess_is_rela (elf_header.e_machine);
   1028 
   1029   if (is_rela)
   1030     {
   1031       if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
   1032 	return;
   1033     }
   1034   else
   1035     {
   1036       if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
   1037 	return;
   1038     }
   1039 
   1040   if (is_32bit_elf)
   1041     {
   1042       if (is_rela)
   1043 	{
   1044 	  if (do_wide)
   1045 	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name + Addend\n"));
   1046 	  else
   1047 	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
   1048 	}
   1049       else
   1050 	{
   1051 	  if (do_wide)
   1052 	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
   1053 	  else
   1054 	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
   1055 	}
   1056     }
   1057   else
   1058     {
   1059       if (is_rela)
   1060 	{
   1061 	  if (do_wide)
   1062 	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
   1063 	  else
   1064 	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n"));
   1065 	}
   1066       else
   1067 	{
   1068 	  if (do_wide)
   1069 	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name\n"));
   1070 	  else
   1071 	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name\n"));
   1072 	}
   1073     }
   1074 
   1075   for (i = 0; i < rel_size; i++)
   1076     {
   1077       const char * rtype;
   1078       bfd_vma offset;
   1079       bfd_vma inf;
   1080       bfd_vma symtab_index;
   1081       bfd_vma type;
   1082 
   1083       offset = rels[i].r_offset;
   1084       inf    = rels[i].r_info;
   1085 
   1086       type = get_reloc_type (inf);
   1087       symtab_index = get_reloc_symindex  (inf);
   1088 
   1089       if (is_32bit_elf)
   1090 	{
   1091 	  printf ("%8.8lx  %8.8lx ",
   1092 		  (unsigned long) offset & 0xffffffff,
   1093 		  (unsigned long) inf & 0xffffffff);
   1094 	}
   1095       else
   1096 	{
   1097 #if BFD_HOST_64BIT_LONG
   1098 	  printf (do_wide
   1099 		  ? "%16.16lx  %16.16lx "
   1100 		  : "%12.12lx  %12.12lx ",
   1101 		  offset, inf);
   1102 #elif BFD_HOST_64BIT_LONG_LONG
   1103 #ifndef __MSVCRT__
   1104 	  printf (do_wide
   1105 		  ? "%16.16llx  %16.16llx "
   1106 		  : "%12.12llx  %12.12llx ",
   1107 		  offset, inf);
   1108 #else
   1109 	  printf (do_wide
   1110 		  ? "%16.16I64x  %16.16I64x "
   1111 		  : "%12.12I64x  %12.12I64x ",
   1112 		  offset, inf);
   1113 #endif
   1114 #else
   1115 	  printf (do_wide
   1116 		  ? "%8.8lx%8.8lx  %8.8lx%8.8lx "
   1117 		  : "%4.4lx%8.8lx  %4.4lx%8.8lx ",
   1118 		  _bfd_int64_high (offset),
   1119 		  _bfd_int64_low (offset),
   1120 		  _bfd_int64_high (inf),
   1121 		  _bfd_int64_low (inf));
   1122 #endif
   1123 	}
   1124 
   1125       switch (elf_header.e_machine)
   1126 	{
   1127 	default:
   1128 	  rtype = NULL;
   1129 	  break;
   1130 
   1131 	case EM_AARCH64:
   1132 	  rtype = elf_aarch64_reloc_type (type);
   1133 	  break;
   1134 
   1135 	case EM_M32R:
   1136 	case EM_CYGNUS_M32R:
   1137 	  rtype = elf_m32r_reloc_type (type);
   1138 	  break;
   1139 
   1140 	case EM_386:
   1141 	case EM_486:
   1142 	  rtype = elf_i386_reloc_type (type);
   1143 	  break;
   1144 
   1145 	case EM_68HC11:
   1146 	case EM_68HC12:
   1147 	  rtype = elf_m68hc11_reloc_type (type);
   1148 	  break;
   1149 
   1150 	case EM_68K:
   1151 	  rtype = elf_m68k_reloc_type (type);
   1152 	  break;
   1153 
   1154 	case EM_960:
   1155 	  rtype = elf_i960_reloc_type (type);
   1156 	  break;
   1157 
   1158 	case EM_AVR:
   1159 	case EM_AVR_OLD:
   1160 	  rtype = elf_avr_reloc_type (type);
   1161 	  break;
   1162 
   1163 	case EM_OLD_SPARCV9:
   1164 	case EM_SPARC32PLUS:
   1165 	case EM_SPARCV9:
   1166 	case EM_SPARC:
   1167 	  rtype = elf_sparc_reloc_type (type);
   1168 	  break;
   1169 
   1170 	case EM_SPU:
   1171 	  rtype = elf_spu_reloc_type (type);
   1172 	  break;
   1173 
   1174 	case EM_V800:
   1175 	  rtype = v800_reloc_type (type);
   1176 	  break;
   1177 	case EM_V850:
   1178 	case EM_CYGNUS_V850:
   1179 	  rtype = v850_reloc_type (type);
   1180 	  break;
   1181 
   1182 	case EM_D10V:
   1183 	case EM_CYGNUS_D10V:
   1184 	  rtype = elf_d10v_reloc_type (type);
   1185 	  break;
   1186 
   1187 	case EM_D30V:
   1188 	case EM_CYGNUS_D30V:
   1189 	  rtype = elf_d30v_reloc_type (type);
   1190 	  break;
   1191 
   1192 	case EM_DLX:
   1193 	  rtype = elf_dlx_reloc_type (type);
   1194 	  break;
   1195 
   1196 	case EM_SH:
   1197 	  rtype = elf_sh_reloc_type (type);
   1198 	  break;
   1199 
   1200 	case EM_MN10300:
   1201 	case EM_CYGNUS_MN10300:
   1202 	  rtype = elf_mn10300_reloc_type (type);
   1203 	  break;
   1204 
   1205 	case EM_MN10200:
   1206 	case EM_CYGNUS_MN10200:
   1207 	  rtype = elf_mn10200_reloc_type (type);
   1208 	  break;
   1209 
   1210 	case EM_FR30:
   1211 	case EM_CYGNUS_FR30:
   1212 	  rtype = elf_fr30_reloc_type (type);
   1213 	  break;
   1214 
   1215 	case EM_CYGNUS_FRV:
   1216 	  rtype = elf_frv_reloc_type (type);
   1217 	  break;
   1218 
   1219 	case EM_MCORE:
   1220 	  rtype = elf_mcore_reloc_type (type);
   1221 	  break;
   1222 
   1223 	case EM_MMIX:
   1224 	  rtype = elf_mmix_reloc_type (type);
   1225 	  break;
   1226 
   1227 	case EM_MOXIE:
   1228 	  rtype = elf_moxie_reloc_type (type);
   1229 	  break;
   1230 
   1231 	case EM_MSP430:
   1232 	  if (uses_msp430x_relocs ())
   1233 	    {
   1234 	      rtype = elf_msp430x_reloc_type (type);
   1235 	      break;
   1236 	    }
   1237 	case EM_MSP430_OLD:
   1238 	  rtype = elf_msp430_reloc_type (type);
   1239 	  break;
   1240 
   1241 	case EM_NDS32:
   1242 	  rtype = elf_nds32_reloc_type (type);
   1243 	  break;
   1244 
   1245 	case EM_PPC:
   1246 	  rtype = elf_ppc_reloc_type (type);
   1247 	  break;
   1248 
   1249 	case EM_PPC64:
   1250 	  rtype = elf_ppc64_reloc_type (type);
   1251 	  break;
   1252 
   1253 	case EM_MIPS:
   1254 	case EM_MIPS_RS3_LE:
   1255 	  rtype = elf_mips_reloc_type (type);
   1256 	  break;
   1257 
   1258 	case EM_ALPHA:
   1259 	  rtype = elf_alpha_reloc_type (type);
   1260 	  break;
   1261 
   1262 	case EM_ARM:
   1263 	  rtype = elf_arm_reloc_type (type);
   1264 	  break;
   1265 
   1266 	case EM_ARC:
   1267 	  rtype = elf_arc_reloc_type (type);
   1268 	  break;
   1269 
   1270 	case EM_PARISC:
   1271 	  rtype = elf_hppa_reloc_type (type);
   1272 	  break;
   1273 
   1274 	case EM_H8_300:
   1275 	case EM_H8_300H:
   1276 	case EM_H8S:
   1277 	  rtype = elf_h8_reloc_type (type);
   1278 	  break;
   1279 
   1280 	case EM_OR1K:
   1281 	  rtype = elf_or1k_reloc_type (type);
   1282 	  break;
   1283 
   1284 	case EM_PJ:
   1285 	case EM_PJ_OLD:
   1286 	  rtype = elf_pj_reloc_type (type);
   1287 	  break;
   1288 	case EM_IA_64:
   1289 	  rtype = elf_ia64_reloc_type (type);
   1290 	  break;
   1291 
   1292 	case EM_CRIS:
   1293 	  rtype = elf_cris_reloc_type (type);
   1294 	  break;
   1295 
   1296 	case EM_860:
   1297 	  rtype = elf_i860_reloc_type (type);
   1298 	  break;
   1299 
   1300 	case EM_X86_64:
   1301 	case EM_L1OM:
   1302 	case EM_K1OM:
   1303 	  rtype = elf_x86_64_reloc_type (type);
   1304 	  break;
   1305 
   1306 	case EM_S370:
   1307 	  rtype = i370_reloc_type (type);
   1308 	  break;
   1309 
   1310 	case EM_S390_OLD:
   1311 	case EM_S390:
   1312 	  rtype = elf_s390_reloc_type (type);
   1313 	  break;
   1314 
   1315 	case EM_SCORE:
   1316 	  rtype = elf_score_reloc_type (type);
   1317 	  break;
   1318 
   1319 	case EM_XSTORMY16:
   1320 	  rtype = elf_xstormy16_reloc_type (type);
   1321 	  break;
   1322 
   1323 	case EM_CRX:
   1324 	  rtype = elf_crx_reloc_type (type);
   1325 	  break;
   1326 
   1327 	case EM_VAX:
   1328 	  rtype = elf_vax_reloc_type (type);
   1329 	  break;
   1330 
   1331 	case EM_ADAPTEVA_EPIPHANY:
   1332 	  rtype = elf_epiphany_reloc_type (type);
   1333 	  break;
   1334 
   1335 	case EM_IP2K:
   1336 	case EM_IP2K_OLD:
   1337 	  rtype = elf_ip2k_reloc_type (type);
   1338 	  break;
   1339 
   1340 	case EM_IQ2000:
   1341 	  rtype = elf_iq2000_reloc_type (type);
   1342 	  break;
   1343 
   1344 	case EM_XTENSA_OLD:
   1345 	case EM_XTENSA:
   1346 	  rtype = elf_xtensa_reloc_type (type);
   1347 	  break;
   1348 
   1349 	case EM_LATTICEMICO32:
   1350 	  rtype = elf_lm32_reloc_type (type);
   1351 	  break;
   1352 
   1353 	case EM_M32C_OLD:
   1354 	case EM_M32C:
   1355 	  rtype = elf_m32c_reloc_type (type);
   1356 	  break;
   1357 
   1358 	case EM_MT:
   1359 	  rtype = elf_mt_reloc_type (type);
   1360 	  break;
   1361 
   1362 	case EM_BLACKFIN:
   1363 	  rtype = elf_bfin_reloc_type (type);
   1364 	  break;
   1365 
   1366 	case EM_CYGNUS_MEP:
   1367 	  rtype = elf_mep_reloc_type (type);
   1368 	  break;
   1369 
   1370 	case EM_CR16:
   1371 	  rtype = elf_cr16_reloc_type (type);
   1372 	  break;
   1373 
   1374 	case EM_MICROBLAZE:
   1375 	case EM_MICROBLAZE_OLD:
   1376 	  rtype = elf_microblaze_reloc_type (type);
   1377 	  break;
   1378 
   1379 	case EM_RL78:
   1380 	  rtype = elf_rl78_reloc_type (type);
   1381 	  break;
   1382 
   1383 	case EM_RX:
   1384 	  rtype = elf_rx_reloc_type (type);
   1385 	  break;
   1386 
   1387 	case EM_METAG:
   1388 	  rtype = elf_metag_reloc_type (type);
   1389 	  break;
   1390 
   1391 	case EM_XC16X:
   1392 	case EM_C166:
   1393 	  rtype = elf_xc16x_reloc_type (type);
   1394 	  break;
   1395 
   1396 	case EM_TI_C6000:
   1397 	  rtype = elf_tic6x_reloc_type (type);
   1398 	  break;
   1399 
   1400 	case EM_TILEGX:
   1401 	  rtype = elf_tilegx_reloc_type (type);
   1402 	  break;
   1403 
   1404 	case EM_TILEPRO:
   1405 	  rtype = elf_tilepro_reloc_type (type);
   1406 	  break;
   1407 
   1408 	case EM_XGATE:
   1409 	  rtype = elf_xgate_reloc_type (type);
   1410 	  break;
   1411 
   1412 	case EM_ALTERA_NIOS2:
   1413 	  rtype = elf_nios2_reloc_type (type);
   1414 	  break;
   1415 	}
   1416 
   1417       if (rtype == NULL)
   1418 	printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
   1419       else
   1420 	printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
   1421 
   1422       if (elf_header.e_machine == EM_ALPHA
   1423 	  && rtype != NULL
   1424 	  && streq (rtype, "R_ALPHA_LITUSE")
   1425 	  && is_rela)
   1426 	{
   1427 	  switch (rels[i].r_addend)
   1428 	    {
   1429 	    case LITUSE_ALPHA_ADDR:   rtype = "ADDR";   break;
   1430 	    case LITUSE_ALPHA_BASE:   rtype = "BASE";   break;
   1431 	    case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
   1432 	    case LITUSE_ALPHA_JSR:    rtype = "JSR";    break;
   1433 	    case LITUSE_ALPHA_TLSGD:  rtype = "TLSGD";  break;
   1434 	    case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
   1435 	    case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
   1436 	    default: rtype = NULL;
   1437 	    }
   1438 	  if (rtype)
   1439 	    printf (" (%s)", rtype);
   1440 	  else
   1441 	    {
   1442 	      putchar (' ');
   1443 	      printf (_("<unknown addend: %lx>"),
   1444 		      (unsigned long) rels[i].r_addend);
   1445 	    }
   1446 	}
   1447       else if (symtab_index)
   1448 	{
   1449 	  if (symtab == NULL || symtab_index >= nsyms)
   1450 	    printf (_(" bad symbol index: %08lx"), (unsigned long) symtab_index);
   1451 	  else
   1452 	    {
   1453 	      Elf_Internal_Sym * psym;
   1454 
   1455 	      psym = symtab + symtab_index;
   1456 
   1457 	      printf (" ");
   1458 
   1459 	      if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
   1460 		{
   1461 		  const char * name;
   1462 		  unsigned int len;
   1463 		  unsigned int width = is_32bit_elf ? 8 : 14;
   1464 
   1465 		  /* Relocations against GNU_IFUNC symbols do not use the value
   1466 		     of the symbol as the address to relocate against.  Instead
   1467 		     they invoke the function named by the symbol and use its
   1468 		     result as the address for relocation.
   1469 
   1470 		     To indicate this to the user, do not display the value of
   1471 		     the symbol in the "Symbols's Value" field.  Instead show
   1472 		     its name followed by () as a hint that the symbol is
   1473 		     invoked.  */
   1474 
   1475 		  if (strtab == NULL
   1476 		      || psym->st_name == 0
   1477 		      || psym->st_name >= strtablen)
   1478 		    name = "??";
   1479 		  else
   1480 		    name = strtab + psym->st_name;
   1481 
   1482 		  len = print_symbol (width, name);
   1483 		  printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
   1484 		}
   1485 	      else
   1486 		{
   1487 		  print_vma (psym->st_value, LONG_HEX);
   1488 
   1489 		  printf (is_32bit_elf ? "   " : " ");
   1490 		}
   1491 
   1492 	      if (psym->st_name == 0)
   1493 		{
   1494 		  const char * sec_name = "<null>";
   1495 		  char name_buf[40];
   1496 
   1497 		  if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
   1498 		    {
   1499 		      if (psym->st_shndx < elf_header.e_shnum)
   1500 			sec_name = SECTION_NAME (section_headers + psym->st_shndx);
   1501 		      else if (psym->st_shndx == SHN_ABS)
   1502 			sec_name = "ABS";
   1503 		      else if (psym->st_shndx == SHN_COMMON)
   1504 			sec_name = "COMMON";
   1505 		      else if ((elf_header.e_machine == EM_MIPS
   1506 				&& psym->st_shndx == SHN_MIPS_SCOMMON)
   1507 			       || (elf_header.e_machine == EM_TI_C6000
   1508 				   && psym->st_shndx == SHN_TIC6X_SCOMMON))
   1509 			sec_name = "SCOMMON";
   1510 		      else if (elf_header.e_machine == EM_MIPS
   1511 			       && psym->st_shndx == SHN_MIPS_SUNDEFINED)
   1512 			sec_name = "SUNDEF";
   1513 		      else if ((elf_header.e_machine == EM_X86_64
   1514 				|| elf_header.e_machine == EM_L1OM
   1515 				|| elf_header.e_machine == EM_K1OM)
   1516 			       && psym->st_shndx == SHN_X86_64_LCOMMON)
   1517 			sec_name = "LARGE_COMMON";
   1518 		      else if (elf_header.e_machine == EM_IA_64
   1519 			       && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
   1520 			       && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
   1521 			sec_name = "ANSI_COM";
   1522 		      else if (is_ia64_vms ()
   1523 			       && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
   1524 			sec_name = "VMS_SYMVEC";
   1525 		      else
   1526 			{
   1527 			  sprintf (name_buf, "<section 0x%x>",
   1528 				   (unsigned int) psym->st_shndx);
   1529 			  sec_name = name_buf;
   1530 			}
   1531 		    }
   1532 		  print_symbol (22, sec_name);
   1533 		}
   1534 	      else if (strtab == NULL)
   1535 		printf (_("<string table index: %3ld>"), psym->st_name);
   1536 	      else if (psym->st_name >= strtablen)
   1537 		printf (_("<corrupt string table index: %3ld>"), psym->st_name);
   1538 	      else
   1539 		print_symbol (22, strtab + psym->st_name);
   1540 
   1541 	      if (is_rela)
   1542 		{
   1543 		  bfd_signed_vma off = rels[i].r_addend;
   1544 
   1545 		  if (off < 0)
   1546 		    printf (" - %" BFD_VMA_FMT "x", - off);
   1547 		  else
   1548 		    printf (" + %" BFD_VMA_FMT "x", off);
   1549 		}
   1550 	    }
   1551 	}
   1552       else if (is_rela)
   1553 	{
   1554 	  bfd_signed_vma off = rels[i].r_addend;
   1555 
   1556 	  printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
   1557 	  if (off < 0)
   1558 	    printf ("-%" BFD_VMA_FMT "x", - off);
   1559 	  else
   1560 	    printf ("%" BFD_VMA_FMT "x", off);
   1561 	}
   1562 
   1563       if (elf_header.e_machine == EM_SPARCV9
   1564 	  && rtype != NULL
   1565 	  && streq (rtype, "R_SPARC_OLO10"))
   1566 	printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
   1567 
   1568       putchar ('\n');
   1569 
   1570 #ifdef BFD64
   1571       if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
   1572 	{
   1573 	  bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
   1574 	  bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
   1575 	  const char * rtype2 = elf_mips_reloc_type (type2);
   1576 	  const char * rtype3 = elf_mips_reloc_type (type3);
   1577 
   1578 	  printf ("                    Type2: ");
   1579 
   1580 	  if (rtype2 == NULL)
   1581 	    printf (_("unrecognized: %-7lx"),
   1582 		    (unsigned long) type2 & 0xffffffff);
   1583 	  else
   1584 	    printf ("%-17.17s", rtype2);
   1585 
   1586 	  printf ("\n                    Type3: ");
   1587 
   1588 	  if (rtype3 == NULL)
   1589 	    printf (_("unrecognized: %-7lx"),
   1590 		    (unsigned long) type3 & 0xffffffff);
   1591 	  else
   1592 	    printf ("%-17.17s", rtype3);
   1593 
   1594 	  putchar ('\n');
   1595 	}
   1596 #endif /* BFD64 */
   1597     }
   1598 
   1599   free (rels);
   1600 }
   1601 
   1602 static const char *
   1603 get_mips_dynamic_type (unsigned long type)
   1604 {
   1605   switch (type)
   1606     {
   1607     case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
   1608     case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
   1609     case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
   1610     case DT_MIPS_IVERSION: return "MIPS_IVERSION";
   1611     case DT_MIPS_FLAGS: return "MIPS_FLAGS";
   1612     case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
   1613     case DT_MIPS_MSYM: return "MIPS_MSYM";
   1614     case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
   1615     case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
   1616     case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
   1617     case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
   1618     case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
   1619     case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
   1620     case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
   1621     case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
   1622     case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
   1623     case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
   1624     case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
   1625     case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
   1626     case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
   1627     case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
   1628     case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
   1629     case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
   1630     case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
   1631     case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
   1632     case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
   1633     case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
   1634     case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
   1635     case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
   1636     case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
   1637     case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
   1638     case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
   1639     case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
   1640     case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
   1641     case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
   1642     case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
   1643     case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
   1644     case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
   1645     case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
   1646     case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
   1647     case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
   1648     case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
   1649     case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
   1650     case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
   1651     case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
   1652     case DT_MIPS_RWPLT: return "MIPS_RWPLT";
   1653     default:
   1654       return NULL;
   1655     }
   1656 }
   1657 
   1658 static const char *
   1659 get_sparc64_dynamic_type (unsigned long type)
   1660 {
   1661   switch (type)
   1662     {
   1663     case DT_SPARC_REGISTER: return "SPARC_REGISTER";
   1664     default:
   1665       return NULL;
   1666     }
   1667 }
   1668 
   1669 static const char *
   1670 get_ppc_dynamic_type (unsigned long type)
   1671 {
   1672   switch (type)
   1673     {
   1674     case DT_PPC_GOT:    return "PPC_GOT";
   1675     case DT_PPC_OPT:    return "PPC_OPT";
   1676     default:
   1677       return NULL;
   1678     }
   1679 }
   1680 
   1681 static const char *
   1682 get_ppc64_dynamic_type (unsigned long type)
   1683 {
   1684   switch (type)
   1685     {
   1686     case DT_PPC64_GLINK:  return "PPC64_GLINK";
   1687     case DT_PPC64_OPD:    return "PPC64_OPD";
   1688     case DT_PPC64_OPDSZ:  return "PPC64_OPDSZ";
   1689     case DT_PPC64_OPT:    return "PPC64_OPT";
   1690     default:
   1691       return NULL;
   1692     }
   1693 }
   1694 
   1695 static const char *
   1696 get_parisc_dynamic_type (unsigned long type)
   1697 {
   1698   switch (type)
   1699     {
   1700     case DT_HP_LOAD_MAP:	return "HP_LOAD_MAP";
   1701     case DT_HP_DLD_FLAGS:	return "HP_DLD_FLAGS";
   1702     case DT_HP_DLD_HOOK:	return "HP_DLD_HOOK";
   1703     case DT_HP_UX10_INIT:	return "HP_UX10_INIT";
   1704     case DT_HP_UX10_INITSZ:	return "HP_UX10_INITSZ";
   1705     case DT_HP_PREINIT:		return "HP_PREINIT";
   1706     case DT_HP_PREINITSZ:	return "HP_PREINITSZ";
   1707     case DT_HP_NEEDED:		return "HP_NEEDED";
   1708     case DT_HP_TIME_STAMP:	return "HP_TIME_STAMP";
   1709     case DT_HP_CHECKSUM:	return "HP_CHECKSUM";
   1710     case DT_HP_GST_SIZE:	return "HP_GST_SIZE";
   1711     case DT_HP_GST_VERSION:	return "HP_GST_VERSION";
   1712     case DT_HP_GST_HASHVAL:	return "HP_GST_HASHVAL";
   1713     case DT_HP_EPLTREL:		return "HP_GST_EPLTREL";
   1714     case DT_HP_EPLTRELSZ:	return "HP_GST_EPLTRELSZ";
   1715     case DT_HP_FILTERED:	return "HP_FILTERED";
   1716     case DT_HP_FILTER_TLS:	return "HP_FILTER_TLS";
   1717     case DT_HP_COMPAT_FILTERED:	return "HP_COMPAT_FILTERED";
   1718     case DT_HP_LAZYLOAD:	return "HP_LAZYLOAD";
   1719     case DT_HP_BIND_NOW_COUNT:	return "HP_BIND_NOW_COUNT";
   1720     case DT_PLT:		return "PLT";
   1721     case DT_PLT_SIZE:		return "PLT_SIZE";
   1722     case DT_DLT:		return "DLT";
   1723     case DT_DLT_SIZE:		return "DLT_SIZE";
   1724     default:
   1725       return NULL;
   1726     }
   1727 }
   1728 
   1729 static const char *
   1730 get_ia64_dynamic_type (unsigned long type)
   1731 {
   1732   switch (type)
   1733     {
   1734     case DT_IA_64_PLT_RESERVE:         return "IA_64_PLT_RESERVE";
   1735     case DT_IA_64_VMS_SUBTYPE:         return "VMS_SUBTYPE";
   1736     case DT_IA_64_VMS_IMGIOCNT:        return "VMS_IMGIOCNT";
   1737     case DT_IA_64_VMS_LNKFLAGS:        return "VMS_LNKFLAGS";
   1738     case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
   1739     case DT_IA_64_VMS_IDENT:           return "VMS_IDENT";
   1740     case DT_IA_64_VMS_NEEDED_IDENT:    return "VMS_NEEDED_IDENT";
   1741     case DT_IA_64_VMS_IMG_RELA_CNT:    return "VMS_IMG_RELA_CNT";
   1742     case DT_IA_64_VMS_SEG_RELA_CNT:    return "VMS_SEG_RELA_CNT";
   1743     case DT_IA_64_VMS_FIXUP_RELA_CNT:  return "VMS_FIXUP_RELA_CNT";
   1744     case DT_IA_64_VMS_FIXUP_NEEDED:    return "VMS_FIXUP_NEEDED";
   1745     case DT_IA_64_VMS_SYMVEC_CNT:      return "VMS_SYMVEC_CNT";
   1746     case DT_IA_64_VMS_XLATED:          return "VMS_XLATED";
   1747     case DT_IA_64_VMS_STACKSIZE:       return "VMS_STACKSIZE";
   1748     case DT_IA_64_VMS_UNWINDSZ:        return "VMS_UNWINDSZ";
   1749     case DT_IA_64_VMS_UNWIND_CODSEG:   return "VMS_UNWIND_CODSEG";
   1750     case DT_IA_64_VMS_UNWIND_INFOSEG:  return "VMS_UNWIND_INFOSEG";
   1751     case DT_IA_64_VMS_LINKTIME:        return "VMS_LINKTIME";
   1752     case DT_IA_64_VMS_SEG_NO:          return "VMS_SEG_NO";
   1753     case DT_IA_64_VMS_SYMVEC_OFFSET:   return "VMS_SYMVEC_OFFSET";
   1754     case DT_IA_64_VMS_SYMVEC_SEG:      return "VMS_SYMVEC_SEG";
   1755     case DT_IA_64_VMS_UNWIND_OFFSET:   return "VMS_UNWIND_OFFSET";
   1756     case DT_IA_64_VMS_UNWIND_SEG:      return "VMS_UNWIND_SEG";
   1757     case DT_IA_64_VMS_STRTAB_OFFSET:   return "VMS_STRTAB_OFFSET";
   1758     case DT_IA_64_VMS_SYSVER_OFFSET:   return "VMS_SYSVER_OFFSET";
   1759     case DT_IA_64_VMS_IMG_RELA_OFF:    return "VMS_IMG_RELA_OFF";
   1760     case DT_IA_64_VMS_SEG_RELA_OFF:    return "VMS_SEG_RELA_OFF";
   1761     case DT_IA_64_VMS_FIXUP_RELA_OFF:  return "VMS_FIXUP_RELA_OFF";
   1762     case DT_IA_64_VMS_PLTGOT_OFFSET:   return "VMS_PLTGOT_OFFSET";
   1763     case DT_IA_64_VMS_PLTGOT_SEG:      return "VMS_PLTGOT_SEG";
   1764     case DT_IA_64_VMS_FPMODE:          return "VMS_FPMODE";
   1765     default:
   1766       return NULL;
   1767     }
   1768 }
   1769 
   1770 static const char *
   1771 get_alpha_dynamic_type (unsigned long type)
   1772 {
   1773   switch (type)
   1774     {
   1775     case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
   1776     default:
   1777       return NULL;
   1778     }
   1779 }
   1780 
   1781 static const char *
   1782 get_score_dynamic_type (unsigned long type)
   1783 {
   1784   switch (type)
   1785     {
   1786     case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
   1787     case DT_SCORE_LOCAL_GOTNO:  return "SCORE_LOCAL_GOTNO";
   1788     case DT_SCORE_SYMTABNO:     return "SCORE_SYMTABNO";
   1789     case DT_SCORE_GOTSYM:       return "SCORE_GOTSYM";
   1790     case DT_SCORE_UNREFEXTNO:   return "SCORE_UNREFEXTNO";
   1791     case DT_SCORE_HIPAGENO:     return "SCORE_HIPAGENO";
   1792     default:
   1793       return NULL;
   1794     }
   1795 }
   1796 
   1797 static const char *
   1798 get_tic6x_dynamic_type (unsigned long type)
   1799 {
   1800   switch (type)
   1801     {
   1802     case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
   1803     case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
   1804     case DT_C6000_DSBT_BASE:   return "C6000_DSBT_BASE";
   1805     case DT_C6000_DSBT_SIZE:   return "C6000_DSBT_SIZE";
   1806     case DT_C6000_PREEMPTMAP:  return "C6000_PREEMPTMAP";
   1807     case DT_C6000_DSBT_INDEX:  return "C6000_DSBT_INDEX";
   1808     default:
   1809       return NULL;
   1810     }
   1811 }
   1812 
   1813 static const char *
   1814 get_nios2_dynamic_type (unsigned long type)
   1815 {
   1816   switch (type)
   1817     {
   1818     case DT_NIOS2_GP: return "NIOS2_GP";
   1819     default:
   1820       return NULL;
   1821     }
   1822 }
   1823 
   1824 static const char *
   1825 get_dynamic_type (unsigned long type)
   1826 {
   1827   static char buff[64];
   1828 
   1829   switch (type)
   1830     {
   1831     case DT_NULL:	return "NULL";
   1832     case DT_NEEDED:	return "NEEDED";
   1833     case DT_PLTRELSZ:	return "PLTRELSZ";
   1834     case DT_PLTGOT:	return "PLTGOT";
   1835     case DT_HASH:	return "HASH";
   1836     case DT_STRTAB:	return "STRTAB";
   1837     case DT_SYMTAB:	return "SYMTAB";
   1838     case DT_RELA:	return "RELA";
   1839     case DT_RELASZ:	return "RELASZ";
   1840     case DT_RELAENT:	return "RELAENT";
   1841     case DT_STRSZ:	return "STRSZ";
   1842     case DT_SYMENT:	return "SYMENT";
   1843     case DT_INIT:	return "INIT";
   1844     case DT_FINI:	return "FINI";
   1845     case DT_SONAME:	return "SONAME";
   1846     case DT_RPATH:	return "RPATH";
   1847     case DT_SYMBOLIC:	return "SYMBOLIC";
   1848     case DT_REL:	return "REL";
   1849     case DT_RELSZ:	return "RELSZ";
   1850     case DT_RELENT:	return "RELENT";
   1851     case DT_PLTREL:	return "PLTREL";
   1852     case DT_DEBUG:	return "DEBUG";
   1853     case DT_TEXTREL:	return "TEXTREL";
   1854     case DT_JMPREL:	return "JMPREL";
   1855     case DT_BIND_NOW:   return "BIND_NOW";
   1856     case DT_INIT_ARRAY: return "INIT_ARRAY";
   1857     case DT_FINI_ARRAY: return "FINI_ARRAY";
   1858     case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
   1859     case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
   1860     case DT_RUNPATH:    return "RUNPATH";
   1861     case DT_FLAGS:      return "FLAGS";
   1862 
   1863     case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
   1864     case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
   1865 
   1866     case DT_CHECKSUM:	return "CHECKSUM";
   1867     case DT_PLTPADSZ:	return "PLTPADSZ";
   1868     case DT_MOVEENT:	return "MOVEENT";
   1869     case DT_MOVESZ:	return "MOVESZ";
   1870     case DT_FEATURE:	return "FEATURE";
   1871     case DT_POSFLAG_1:	return "POSFLAG_1";
   1872     case DT_SYMINSZ:	return "SYMINSZ";
   1873     case DT_SYMINENT:	return "SYMINENT"; /* aka VALRNGHI */
   1874 
   1875     case DT_ADDRRNGLO:  return "ADDRRNGLO";
   1876     case DT_CONFIG:	return "CONFIG";
   1877     case DT_DEPAUDIT:	return "DEPAUDIT";
   1878     case DT_AUDIT:	return "AUDIT";
   1879     case DT_PLTPAD:	return "PLTPAD";
   1880     case DT_MOVETAB:	return "MOVETAB";
   1881     case DT_SYMINFO:	return "SYMINFO"; /* aka ADDRRNGHI */
   1882 
   1883     case DT_VERSYM:	return "VERSYM";
   1884 
   1885     case DT_TLSDESC_GOT: return "TLSDESC_GOT";
   1886     case DT_TLSDESC_PLT: return "TLSDESC_PLT";
   1887     case DT_RELACOUNT:	return "RELACOUNT";
   1888     case DT_RELCOUNT:	return "RELCOUNT";
   1889     case DT_FLAGS_1:	return "FLAGS_1";
   1890     case DT_VERDEF:	return "VERDEF";
   1891     case DT_VERDEFNUM:	return "VERDEFNUM";
   1892     case DT_VERNEED:	return "VERNEED";
   1893     case DT_VERNEEDNUM:	return "VERNEEDNUM";
   1894 
   1895     case DT_AUXILIARY:	return "AUXILIARY";
   1896     case DT_USED:	return "USED";
   1897     case DT_FILTER:	return "FILTER";
   1898 
   1899     case DT_GNU_PRELINKED: return "GNU_PRELINKED";
   1900     case DT_GNU_CONFLICT: return "GNU_CONFLICT";
   1901     case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
   1902     case DT_GNU_LIBLIST: return "GNU_LIBLIST";
   1903     case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
   1904     case DT_GNU_HASH:	return "GNU_HASH";
   1905 
   1906     default:
   1907       if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
   1908 	{
   1909 	  const char * result;
   1910 
   1911 	  switch (elf_header.e_machine)
   1912 	    {
   1913 	    case EM_MIPS:
   1914 	    case EM_MIPS_RS3_LE:
   1915 	      result = get_mips_dynamic_type (type);
   1916 	      break;
   1917 	    case EM_SPARCV9:
   1918 	      result = get_sparc64_dynamic_type (type);
   1919 	      break;
   1920 	    case EM_PPC:
   1921 	      result = get_ppc_dynamic_type (type);
   1922 	      break;
   1923 	    case EM_PPC64:
   1924 	      result = get_ppc64_dynamic_type (type);
   1925 	      break;
   1926 	    case EM_IA_64:
   1927 	      result = get_ia64_dynamic_type (type);
   1928 	      break;
   1929 	    case EM_ALPHA:
   1930 	      result = get_alpha_dynamic_type (type);
   1931 	      break;
   1932 	    case EM_SCORE:
   1933 	      result = get_score_dynamic_type (type);
   1934 	      break;
   1935 	    case EM_TI_C6000:
   1936 	      result = get_tic6x_dynamic_type (type);
   1937 	      break;
   1938 	    case EM_ALTERA_NIOS2:
   1939 	      result = get_nios2_dynamic_type (type);
   1940 	      break;
   1941 	    default:
   1942 	      result = NULL;
   1943 	      break;
   1944 	    }
   1945 
   1946 	  if (result != NULL)
   1947 	    return result;
   1948 
   1949 	  snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
   1950 	}
   1951       else if (((type >= DT_LOOS) && (type <= DT_HIOS))
   1952 	       || (elf_header.e_machine == EM_PARISC
   1953 		   && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
   1954 	{
   1955 	  const char * result;
   1956 
   1957 	  switch (elf_header.e_machine)
   1958 	    {
   1959 	    case EM_PARISC:
   1960 	      result = get_parisc_dynamic_type (type);
   1961 	      break;
   1962 	    case EM_IA_64:
   1963 	      result = get_ia64_dynamic_type (type);
   1964 	      break;
   1965 	    default:
   1966 	      result = NULL;
   1967 	      break;
   1968 	    }
   1969 
   1970 	  if (result != NULL)
   1971 	    return result;
   1972 
   1973 	  snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
   1974 		    type);
   1975 	}
   1976       else
   1977 	snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
   1978 
   1979       return buff;
   1980     }
   1981 }
   1982 
   1983 static char *
   1984 get_file_type (unsigned e_type)
   1985 {
   1986   static char buff[32];
   1987 
   1988   switch (e_type)
   1989     {
   1990     case ET_NONE:	return _("NONE (None)");
   1991     case ET_REL:	return _("REL (Relocatable file)");
   1992     case ET_EXEC:	return _("EXEC (Executable file)");
   1993     case ET_DYN:	return _("DYN (Shared object file)");
   1994     case ET_CORE:	return _("CORE (Core file)");
   1995 
   1996     default:
   1997       if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
   1998 	snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
   1999       else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
   2000 	snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
   2001       else
   2002 	snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
   2003       return buff;
   2004     }
   2005 }
   2006 
   2007 static char *
   2008 get_machine_name (unsigned e_machine)
   2009 {
   2010   static char buff[64]; /* XXX */
   2011 
   2012   switch (e_machine)
   2013     {
   2014     case EM_NONE:		return _("None");
   2015     case EM_AARCH64:		return "AArch64";
   2016     case EM_M32:		return "WE32100";
   2017     case EM_SPARC:		return "Sparc";
   2018     case EM_SPU:		return "SPU";
   2019     case EM_386:		return "Intel 80386";
   2020     case EM_68K:		return "MC68000";
   2021     case EM_88K:		return "MC88000";
   2022     case EM_486:		return "Intel 80486";
   2023     case EM_860:		return "Intel 80860";
   2024     case EM_MIPS:		return "MIPS R3000";
   2025     case EM_S370:		return "IBM System/370";
   2026     case EM_MIPS_RS3_LE:	return "MIPS R4000 big-endian";
   2027     case EM_OLD_SPARCV9:	return "Sparc v9 (old)";
   2028     case EM_PARISC:		return "HPPA";
   2029     case EM_PPC_OLD:		return "Power PC (old)";
   2030     case EM_SPARC32PLUS:	return "Sparc v8+" ;
   2031     case EM_960:		return "Intel 90860";
   2032     case EM_PPC:		return "PowerPC";
   2033     case EM_PPC64:		return "PowerPC64";
   2034     case EM_FR20:		return "Fujitsu FR20";
   2035     case EM_RH32:		return "TRW RH32";
   2036     case EM_MCORE:		return "MCORE";
   2037     case EM_ARM:		return "ARM";
   2038     case EM_OLD_ALPHA:		return "Digital Alpha (old)";
   2039     case EM_SH:			return "Renesas / SuperH SH";
   2040     case EM_SPARCV9:		return "Sparc v9";
   2041     case EM_TRICORE:		return "Siemens Tricore";
   2042     case EM_ARC:		return "ARC";
   2043     case EM_H8_300:		return "Renesas H8/300";
   2044     case EM_H8_300H:		return "Renesas H8/300H";
   2045     case EM_H8S:		return "Renesas H8S";
   2046     case EM_H8_500:		return "Renesas H8/500";
   2047     case EM_IA_64:		return "Intel IA-64";
   2048     case EM_MIPS_X:		return "Stanford MIPS-X";
   2049     case EM_COLDFIRE:		return "Motorola Coldfire";
   2050     case EM_ALPHA:		return "Alpha";
   2051     case EM_CYGNUS_D10V:
   2052     case EM_D10V:		return "d10v";
   2053     case EM_CYGNUS_D30V:
   2054     case EM_D30V:		return "d30v";
   2055     case EM_CYGNUS_M32R:
   2056     case EM_M32R:		return "Renesas M32R (formerly Mitsubishi M32r)";
   2057     case EM_CYGNUS_V850:
   2058     case EM_V800:		return "Renesas V850 (using RH850 ABI)";
   2059     case EM_V850:		return "Renesas V850";
   2060     case EM_CYGNUS_MN10300:
   2061     case EM_MN10300:		return "mn10300";
   2062     case EM_CYGNUS_MN10200:
   2063     case EM_MN10200:		return "mn10200";
   2064     case EM_MOXIE:		return "Moxie";
   2065     case EM_CYGNUS_FR30:
   2066     case EM_FR30:		return "Fujitsu FR30";
   2067     case EM_CYGNUS_FRV:		return "Fujitsu FR-V";
   2068     case EM_PJ_OLD:
   2069     case EM_PJ:			return "picoJava";
   2070     case EM_MMA:		return "Fujitsu Multimedia Accelerator";
   2071     case EM_PCP:		return "Siemens PCP";
   2072     case EM_NCPU:		return "Sony nCPU embedded RISC processor";
   2073     case EM_NDR1:		return "Denso NDR1 microprocesspr";
   2074     case EM_STARCORE:		return "Motorola Star*Core processor";
   2075     case EM_ME16:		return "Toyota ME16 processor";
   2076     case EM_ST100:		return "STMicroelectronics ST100 processor";
   2077     case EM_TINYJ:		return "Advanced Logic Corp. TinyJ embedded processor";
   2078     case EM_PDSP:		return "Sony DSP processor";
   2079     case EM_PDP10:		return "Digital Equipment Corp. PDP-10";
   2080     case EM_PDP11:		return "Digital Equipment Corp. PDP-11";
   2081     case EM_FX66:		return "Siemens FX66 microcontroller";
   2082     case EM_ST9PLUS:		return "STMicroelectronics ST9+ 8/16 bit microcontroller";
   2083     case EM_ST7:		return "STMicroelectronics ST7 8-bit microcontroller";
   2084     case EM_68HC16:		return "Motorola MC68HC16 Microcontroller";
   2085     case EM_68HC12:		return "Motorola MC68HC12 Microcontroller";
   2086     case EM_68HC11:		return "Motorola MC68HC11 Microcontroller";
   2087     case EM_68HC08:		return "Motorola MC68HC08 Microcontroller";
   2088     case EM_68HC05:		return "Motorola MC68HC05 Microcontroller";
   2089     case EM_SVX:		return "Silicon Graphics SVx";
   2090     case EM_ST19:		return "STMicroelectronics ST19 8-bit microcontroller";
   2091     case EM_VAX:		return "Digital VAX";
   2092     case EM_AVR_OLD:
   2093     case EM_AVR:		return "Atmel AVR 8-bit microcontroller";
   2094     case EM_CRIS:		return "Axis Communications 32-bit embedded processor";
   2095     case EM_JAVELIN:		return "Infineon Technologies 32-bit embedded cpu";
   2096     case EM_FIREPATH:		return "Element 14 64-bit DSP processor";
   2097     case EM_ZSP:		return "LSI Logic's 16-bit DSP processor";
   2098     case EM_MMIX:		return "Donald Knuth's educational 64-bit processor";
   2099     case EM_HUANY:		return "Harvard Universitys's machine-independent object format";
   2100     case EM_PRISM:		return "Vitesse Prism";
   2101     case EM_X86_64:		return "Advanced Micro Devices X86-64";
   2102     case EM_L1OM:		return "Intel L1OM";
   2103     case EM_K1OM:		return "Intel K1OM";
   2104     case EM_S390_OLD:
   2105     case EM_S390:		return "IBM S/390";
   2106     case EM_SCORE:		return "SUNPLUS S+Core";
   2107     case EM_XSTORMY16:		return "Sanyo XStormy16 CPU core";
   2108     case EM_OR1K:		return "OpenRISC 1000";
   2109     case EM_ARC_A5:		return "ARC International ARCompact processor";
   2110     case EM_CRX:		return "National Semiconductor CRX microprocessor";
   2111     case EM_ADAPTEVA_EPIPHANY:	return "Adapteva EPIPHANY";
   2112     case EM_DLX:		return "OpenDLX";
   2113     case EM_IP2K_OLD:
   2114     case EM_IP2K:		return "Ubicom IP2xxx 8-bit microcontrollers";
   2115     case EM_IQ2000:       	return "Vitesse IQ2000";
   2116     case EM_XTENSA_OLD:
   2117     case EM_XTENSA:		return "Tensilica Xtensa Processor";
   2118     case EM_VIDEOCORE:		return "Alphamosaic VideoCore processor";
   2119     case EM_TMM_GPP:		return "Thompson Multimedia General Purpose Processor";
   2120     case EM_NS32K:		return "National Semiconductor 32000 series";
   2121     case EM_TPC:		return "Tenor Network TPC processor";
   2122     case EM_ST200:		return "STMicroelectronics ST200 microcontroller";
   2123     case EM_MAX:		return "MAX Processor";
   2124     case EM_CR:			return "National Semiconductor CompactRISC";
   2125     case EM_F2MC16:		return "Fujitsu F2MC16";
   2126     case EM_MSP430:		return "Texas Instruments msp430 microcontroller";
   2127     case EM_LATTICEMICO32:	return "Lattice Mico32";
   2128     case EM_M32C_OLD:
   2129     case EM_M32C:	        return "Renesas M32c";
   2130     case EM_MT:                 return "Morpho Techologies MT processor";
   2131     case EM_BLACKFIN:		return "Analog Devices Blackfin";
   2132     case EM_SE_C33:		return "S1C33 Family of Seiko Epson processors";
   2133     case EM_SEP:		return "Sharp embedded microprocessor";
   2134     case EM_ARCA:		return "Arca RISC microprocessor";
   2135     case EM_UNICORE:		return "Unicore";
   2136     case EM_EXCESS:		return "eXcess 16/32/64-bit configurable embedded CPU";
   2137     case EM_DXP:		return "Icera Semiconductor Inc. Deep Execution Processor";
   2138     case EM_NIOS32:		return "Altera Nios";
   2139     case EM_ALTERA_NIOS2:	return "Altera Nios II";
   2140     case EM_C166:
   2141     case EM_XC16X:		return "Infineon Technologies xc16x";
   2142     case EM_M16C:		return "Renesas M16C series microprocessors";
   2143     case EM_DSPIC30F:		return "Microchip Technology dsPIC30F Digital Signal Controller";
   2144     case EM_CE:			return "Freescale Communication Engine RISC core";
   2145     case EM_TSK3000:		return "Altium TSK3000 core";
   2146     case EM_RS08:		return "Freescale RS08 embedded processor";
   2147     case EM_ECOG2:		return "Cyan Technology eCOG2 microprocessor";
   2148     case EM_DSP24:		return "New Japan Radio (NJR) 24-bit DSP Processor";
   2149     case EM_VIDEOCORE3:		return "Broadcom VideoCore III processor";
   2150     case EM_SE_C17:		return "Seiko Epson C17 family";
   2151     case EM_TI_C6000:		return "Texas Instruments TMS320C6000 DSP family";
   2152     case EM_TI_C2000:		return "Texas Instruments TMS320C2000 DSP family";
   2153     case EM_TI_C5500:		return "Texas Instruments TMS320C55x DSP family";
   2154     case EM_MMDSP_PLUS:		return "STMicroelectronics 64bit VLIW Data Signal Processor";
   2155     case EM_CYPRESS_M8C:	return "Cypress M8C microprocessor";
   2156     case EM_R32C:		return "Renesas R32C series microprocessors";
   2157     case EM_TRIMEDIA:		return "NXP Semiconductors TriMedia architecture family";
   2158     case EM_QDSP6:		return "QUALCOMM DSP6 Processor";
   2159     case EM_8051:		return "Intel 8051 and variants";
   2160     case EM_STXP7X:		return "STMicroelectronics STxP7x family";
   2161     case EM_NDS32:		return "Andes Technology compact code size embedded RISC processor family";
   2162     case EM_ECOG1X:		return "Cyan Technology eCOG1X family";
   2163     case EM_MAXQ30:		return "Dallas Semiconductor MAXQ30 Core microcontrollers";
   2164     case EM_XIMO16:		return "New Japan Radio (NJR) 16-bit DSP Processor";
   2165     case EM_MANIK:		return "M2000 Reconfigurable RISC Microprocessor";
   2166     case EM_CRAYNV2:		return "Cray Inc. NV2 vector architecture";
   2167     case EM_CYGNUS_MEP:         return "Toshiba MeP Media Engine";
   2168     case EM_CR16:
   2169     case EM_MICROBLAZE:
   2170     case EM_MICROBLAZE_OLD:	return "Xilinx MicroBlaze";
   2171     case EM_RL78:		return "Renesas RL78";
   2172     case EM_RX:			return "Renesas RX";
   2173     case EM_METAG:		return "Imagination Technologies Meta processor architecture";
   2174     case EM_MCST_ELBRUS:	return "MCST Elbrus general purpose hardware architecture";
   2175     case EM_ECOG16:		return "Cyan Technology eCOG16 family";
   2176     case EM_ETPU:		return "Freescale Extended Time Processing Unit";
   2177     case EM_SLE9X:		return "Infineon Technologies SLE9X core";
   2178     case EM_AVR32:		return "Atmel Corporation 32-bit microprocessor family";
   2179     case EM_STM8:		return "STMicroeletronics STM8 8-bit microcontroller";
   2180     case EM_TILE64:		return "Tilera TILE64 multicore architecture family";
   2181     case EM_TILEPRO:		return "Tilera TILEPro multicore architecture family";
   2182     case EM_TILEGX:		return "Tilera TILE-Gx multicore architecture family";
   2183     case EM_CUDA:		return "NVIDIA CUDA architecture";
   2184     case EM_XGATE:		return "Motorola XGATE embedded processor";
   2185     default:
   2186       snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
   2187       return buff;
   2188     }
   2189 }
   2190 
   2191 static void
   2192 decode_ARM_machine_flags (unsigned e_flags, char buf[])
   2193 {
   2194   unsigned eabi;
   2195   int unknown = 0;
   2196 
   2197   eabi = EF_ARM_EABI_VERSION (e_flags);
   2198   e_flags &= ~ EF_ARM_EABIMASK;
   2199 
   2200   /* Handle "generic" ARM flags.  */
   2201   if (e_flags & EF_ARM_RELEXEC)
   2202     {
   2203       strcat (buf, ", relocatable executable");
   2204       e_flags &= ~ EF_ARM_RELEXEC;
   2205     }
   2206 
   2207   if (e_flags & EF_ARM_HASENTRY)
   2208     {
   2209       strcat (buf, ", has entry point");
   2210       e_flags &= ~ EF_ARM_HASENTRY;
   2211     }
   2212 
   2213   /* Now handle EABI specific flags.  */
   2214   switch (eabi)
   2215     {
   2216     default:
   2217       strcat (buf, ", <unrecognized EABI>");
   2218       if (e_flags)
   2219 	unknown = 1;
   2220       break;
   2221 
   2222     case EF_ARM_EABI_VER1:
   2223       strcat (buf, ", Version1 EABI");
   2224       while (e_flags)
   2225 	{
   2226 	  unsigned flag;
   2227 
   2228 	  /* Process flags one bit at a time.  */
   2229 	  flag = e_flags & - e_flags;
   2230 	  e_flags &= ~ flag;
   2231 
   2232 	  switch (flag)
   2233 	    {
   2234 	    case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK.  */
   2235 	      strcat (buf, ", sorted symbol tables");
   2236 	      break;
   2237 
   2238 	    default:
   2239 	      unknown = 1;
   2240 	      break;
   2241 	    }
   2242 	}
   2243       break;
   2244 
   2245     case EF_ARM_EABI_VER2:
   2246       strcat (buf, ", Version2 EABI");
   2247       while (e_flags)
   2248 	{
   2249 	  unsigned flag;
   2250 
   2251 	  /* Process flags one bit at a time.  */
   2252 	  flag = e_flags & - e_flags;
   2253 	  e_flags &= ~ flag;
   2254 
   2255 	  switch (flag)
   2256 	    {
   2257 	    case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK.  */
   2258 	      strcat (buf, ", sorted symbol tables");
   2259 	      break;
   2260 
   2261 	    case EF_ARM_DYNSYMSUSESEGIDX:
   2262 	      strcat (buf, ", dynamic symbols use segment index");
   2263 	      break;
   2264 
   2265 	    case EF_ARM_MAPSYMSFIRST:
   2266 	      strcat (buf, ", mapping symbols precede others");
   2267 	      break;
   2268 
   2269 	    default:
   2270 	      unknown = 1;
   2271 	      break;
   2272 	    }
   2273 	}
   2274       break;
   2275 
   2276     case EF_ARM_EABI_VER3:
   2277       strcat (buf, ", Version3 EABI");
   2278       break;
   2279 
   2280     case EF_ARM_EABI_VER4:
   2281       strcat (buf, ", Version4 EABI");
   2282       while (e_flags)
   2283 	{
   2284 	  unsigned flag;
   2285 
   2286 	  /* Process flags one bit at a time.  */
   2287 	  flag = e_flags & - e_flags;
   2288 	  e_flags &= ~ flag;
   2289 
   2290 	  switch (flag)
   2291 	    {
   2292 	    case EF_ARM_BE8:
   2293 	      strcat (buf, ", BE8");
   2294 	      break;
   2295 
   2296 	    case EF_ARM_LE8:
   2297 	      strcat (buf, ", LE8");
   2298 	      break;
   2299 
   2300 	    default:
   2301 	      unknown = 1;
   2302 	      break;
   2303 	    }
   2304       break;
   2305 	}
   2306       break;
   2307 
   2308     case EF_ARM_EABI_VER5:
   2309       strcat (buf, ", Version5 EABI");
   2310       while (e_flags)
   2311 	{
   2312 	  unsigned flag;
   2313 
   2314 	  /* Process flags one bit at a time.  */
   2315 	  flag = e_flags & - e_flags;
   2316 	  e_flags &= ~ flag;
   2317 
   2318 	  switch (flag)
   2319 	    {
   2320 	    case EF_ARM_BE8:
   2321 	      strcat (buf, ", BE8");
   2322 	      break;
   2323 
   2324 	    case EF_ARM_LE8:
   2325 	      strcat (buf, ", LE8");
   2326 	      break;
   2327 
   2328 	    case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT.  */
   2329 	      strcat (buf, ", soft-float ABI");
   2330 	      break;
   2331 
   2332 	    case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT.  */
   2333 	      strcat (buf, ", hard-float ABI");
   2334 	      break;
   2335 
   2336 	    default:
   2337 	      unknown = 1;
   2338 	      break;
   2339 	    }
   2340 	}
   2341       break;
   2342 
   2343     case EF_ARM_EABI_UNKNOWN:
   2344       strcat (buf, ", GNU EABI");
   2345       while (e_flags)
   2346 	{
   2347 	  unsigned flag;
   2348 
   2349 	  /* Process flags one bit at a time.  */
   2350 	  flag = e_flags & - e_flags;
   2351 	  e_flags &= ~ flag;
   2352 
   2353 	  switch (flag)
   2354 	    {
   2355 	    case EF_ARM_INTERWORK:
   2356 	      strcat (buf, ", interworking enabled");
   2357 	      break;
   2358 
   2359 	    case EF_ARM_APCS_26:
   2360 	      strcat (buf, ", uses APCS/26");
   2361 	      break;
   2362 
   2363 	    case EF_ARM_APCS_FLOAT:
   2364 	      strcat (buf, ", uses APCS/float");
   2365 	      break;
   2366 
   2367 	    case EF_ARM_PIC:
   2368 	      strcat (buf, ", position independent");
   2369 	      break;
   2370 
   2371 	    case EF_ARM_ALIGN8:
   2372 	      strcat (buf, ", 8 bit structure alignment");
   2373 	      break;
   2374 
   2375 	    case EF_ARM_NEW_ABI:
   2376 	      strcat (buf, ", uses new ABI");
   2377 	      break;
   2378 
   2379 	    case EF_ARM_OLD_ABI:
   2380 	      strcat (buf, ", uses old ABI");
   2381 	      break;
   2382 
   2383 	    case EF_ARM_SOFT_FLOAT:
   2384 	      strcat (buf, ", software FP");
   2385 	      break;
   2386 
   2387 	    case EF_ARM_VFP_FLOAT:
   2388 	      strcat (buf, ", VFP");
   2389 	      break;
   2390 
   2391 	    case EF_ARM_MAVERICK_FLOAT:
   2392 	      strcat (buf, ", Maverick FP");
   2393 	      break;
   2394 
   2395 	    default:
   2396 	      unknown = 1;
   2397 	      break;
   2398 	    }
   2399 	}
   2400     }
   2401 
   2402   if (unknown)
   2403     strcat (buf,_(", <unknown>"));
   2404 }
   2405 
   2406 static void
   2407 decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
   2408 {
   2409   unsigned abi;
   2410   unsigned arch;
   2411   unsigned config;
   2412   unsigned version;
   2413   int has_fpu = 0;
   2414   int r = 0;
   2415 
   2416   static const char *ABI_STRINGS[] =
   2417   {
   2418     "ABI v0", /* use r5 as return register; only used in N1213HC */
   2419     "ABI v1", /* use r0 as return register */
   2420     "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
   2421     "ABI v2fp", /* for FPU */
   2422     "AABI",
   2423     "ABI2 FP+"
   2424   };
   2425   static const char *VER_STRINGS[] =
   2426   {
   2427     "Andes ELF V1.3 or older",
   2428     "Andes ELF V1.3.1",
   2429     "Andes ELF V1.4"
   2430   };
   2431   static const char *ARCH_STRINGS[] =
   2432   {
   2433     "",
   2434     "Andes Star v1.0",
   2435     "Andes Star v2.0",
   2436     "Andes Star v3.0",
   2437     "Andes Star v3.0m"
   2438   };
   2439 
   2440   abi = EF_NDS_ABI & e_flags;
   2441   arch = EF_NDS_ARCH & e_flags;
   2442   config = EF_NDS_INST & e_flags;
   2443   version = EF_NDS32_ELF_VERSION & e_flags;
   2444 
   2445   memset (buf, 0, size);
   2446 
   2447   switch (abi)
   2448     {
   2449     case E_NDS_ABI_V0:
   2450     case E_NDS_ABI_V1:
   2451     case E_NDS_ABI_V2:
   2452     case E_NDS_ABI_V2FP:
   2453     case E_NDS_ABI_AABI:
   2454     case E_NDS_ABI_V2FP_PLUS:
   2455       /* In case there are holes in the array.  */
   2456       r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
   2457       break;
   2458 
   2459     default:
   2460       r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
   2461       break;
   2462     }
   2463 
   2464   switch (version)
   2465     {
   2466     case E_NDS32_ELF_VER_1_2:
   2467     case E_NDS32_ELF_VER_1_3:
   2468     case E_NDS32_ELF_VER_1_4:
   2469       r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
   2470       break;
   2471 
   2472     default:
   2473       r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
   2474       break;
   2475     }
   2476 
   2477   if (E_NDS_ABI_V0 == abi)
   2478     {
   2479       /* OLD ABI; only used in N1213HC, has performance extension 1.  */
   2480       r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
   2481       if (arch == E_NDS_ARCH_STAR_V1_0)
   2482 	r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
   2483       return;
   2484     }
   2485 
   2486   switch (arch)
   2487     {
   2488     case E_NDS_ARCH_STAR_V1_0:
   2489     case E_NDS_ARCH_STAR_V2_0:
   2490     case E_NDS_ARCH_STAR_V3_0:
   2491     case E_NDS_ARCH_STAR_V3_M:
   2492       r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
   2493       break;
   2494 
   2495     default:
   2496       r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
   2497       /* ARCH version determines how the e_flags are interpreted.
   2498 	 If it is unknown, we cannot proceed.  */
   2499       return;
   2500     }
   2501 
   2502   /* Newer ABI; Now handle architecture specific flags.  */
   2503   if (arch == E_NDS_ARCH_STAR_V1_0)
   2504     {
   2505       if (config & E_NDS32_HAS_MFUSR_PC_INST)
   2506 	r += snprintf (buf + r, size -r, ", MFUSR_PC");
   2507 
   2508       if (!(config & E_NDS32_HAS_NO_MAC_INST))
   2509 	r += snprintf (buf + r, size -r, ", MAC");
   2510 
   2511       if (config & E_NDS32_HAS_DIV_INST)
   2512 	r += snprintf (buf + r, size -r, ", DIV");
   2513 
   2514       if (config & E_NDS32_HAS_16BIT_INST)
   2515 	r += snprintf (buf + r, size -r, ", 16b");
   2516     }
   2517   else
   2518     {
   2519       if (config & E_NDS32_HAS_MFUSR_PC_INST)
   2520 	{
   2521 	  if (version <= E_NDS32_ELF_VER_1_3)
   2522 	    r += snprintf (buf + r, size -r, ", [B8]");
   2523 	  else
   2524 	    r += snprintf (buf + r, size -r, ", EX9");
   2525 	}
   2526 
   2527       if (config & E_NDS32_HAS_MAC_DX_INST)
   2528 	r += snprintf (buf + r, size -r, ", MAC_DX");
   2529 
   2530       if (config & E_NDS32_HAS_DIV_DX_INST)
   2531 	r += snprintf (buf + r, size -r, ", DIV_DX");
   2532 
   2533       if (config & E_NDS32_HAS_16BIT_INST)
   2534 	{
   2535 	  if (version <= E_NDS32_ELF_VER_1_3)
   2536 	    r += snprintf (buf + r, size -r, ", 16b");
   2537 	  else
   2538 	    r += snprintf (buf + r, size -r, ", IFC");
   2539 	}
   2540     }
   2541 
   2542   if (config & E_NDS32_HAS_EXT_INST)
   2543     r += snprintf (buf + r, size -r, ", PERF1");
   2544 
   2545   if (config & E_NDS32_HAS_EXT2_INST)
   2546     r += snprintf (buf + r, size -r, ", PERF2");
   2547 
   2548   if (config & E_NDS32_HAS_FPU_INST)
   2549     {
   2550       has_fpu = 1;
   2551       r += snprintf (buf + r, size -r, ", FPU_SP");
   2552     }
   2553 
   2554   if (config & E_NDS32_HAS_FPU_DP_INST)
   2555     {
   2556       has_fpu = 1;
   2557       r += snprintf (buf + r, size -r, ", FPU_DP");
   2558     }
   2559 
   2560   if (config & E_NDS32_HAS_FPU_MAC_INST)
   2561     {
   2562       has_fpu = 1;
   2563       r += snprintf (buf + r, size -r, ", FPU_MAC");
   2564     }
   2565 
   2566   if (has_fpu)
   2567     {
   2568       switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
   2569 	{
   2570 	case E_NDS32_FPU_REG_8SP_4DP:
   2571 	  r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
   2572 	  break;
   2573 	case E_NDS32_FPU_REG_16SP_8DP:
   2574 	  r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
   2575 	  break;
   2576 	case E_NDS32_FPU_REG_32SP_16DP:
   2577 	  r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
   2578 	  break;
   2579 	case E_NDS32_FPU_REG_32SP_32DP:
   2580 	  r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
   2581 	  break;
   2582 	}
   2583     }
   2584 
   2585   if (config & E_NDS32_HAS_AUDIO_INST)
   2586     r += snprintf (buf + r, size -r, ", AUDIO");
   2587 
   2588   if (config & E_NDS32_HAS_STRING_INST)
   2589     r += snprintf (buf + r, size -r, ", STR");
   2590 
   2591   if (config & E_NDS32_HAS_REDUCED_REGS)
   2592     r += snprintf (buf + r, size -r, ", 16REG");
   2593 
   2594   if (config & E_NDS32_HAS_VIDEO_INST)
   2595     {
   2596       if (version <= E_NDS32_ELF_VER_1_3)
   2597 	r += snprintf (buf + r, size -r, ", VIDEO");
   2598       else
   2599 	r += snprintf (buf + r, size -r, ", SATURATION");
   2600     }
   2601 
   2602   if (config & E_NDS32_HAS_ENCRIPT_INST)
   2603     r += snprintf (buf + r, size -r, ", ENCRP");
   2604 
   2605   if (config & E_NDS32_HAS_L2C_INST)
   2606     r += snprintf (buf + r, size -r, ", L2C");
   2607 }
   2608 
   2609 static char *
   2610 get_machine_flags (unsigned e_flags, unsigned e_machine)
   2611 {
   2612   static char buf[1024];
   2613 
   2614   buf[0] = '\0';
   2615 
   2616   if (e_flags)
   2617     {
   2618       switch (e_machine)
   2619 	{
   2620 	default:
   2621 	  break;
   2622 
   2623 	case EM_ARM:
   2624 	  decode_ARM_machine_flags (e_flags, buf);
   2625 	  break;
   2626 
   2627 	case EM_BLACKFIN:
   2628 	  if (e_flags & EF_BFIN_PIC)
   2629 	    strcat (buf, ", PIC");
   2630 
   2631 	  if (e_flags & EF_BFIN_FDPIC)
   2632 	    strcat (buf, ", FDPIC");
   2633 
   2634 	  if (e_flags & EF_BFIN_CODE_IN_L1)
   2635 	    strcat (buf, ", code in L1");
   2636 
   2637 	  if (e_flags & EF_BFIN_DATA_IN_L1)
   2638 	    strcat (buf, ", data in L1");
   2639 
   2640 	  break;
   2641 
   2642 	case EM_CYGNUS_FRV:
   2643 	  switch (e_flags & EF_FRV_CPU_MASK)
   2644 	    {
   2645 	    case EF_FRV_CPU_GENERIC:
   2646 	      break;
   2647 
   2648 	    default:
   2649 	      strcat (buf, ", fr???");
   2650 	      break;
   2651 
   2652 	    case EF_FRV_CPU_FR300:
   2653 	      strcat (buf, ", fr300");
   2654 	      break;
   2655 
   2656 	    case EF_FRV_CPU_FR400:
   2657 	      strcat (buf, ", fr400");
   2658 	      break;
   2659 	    case EF_FRV_CPU_FR405:
   2660 	      strcat (buf, ", fr405");
   2661 	      break;
   2662 
   2663 	    case EF_FRV_CPU_FR450:
   2664 	      strcat (buf, ", fr450");
   2665 	      break;
   2666 
   2667 	    case EF_FRV_CPU_FR500:
   2668 	      strcat (buf, ", fr500");
   2669 	      break;
   2670 	    case EF_FRV_CPU_FR550:
   2671 	      strcat (buf, ", fr550");
   2672 	      break;
   2673 
   2674 	    case EF_FRV_CPU_SIMPLE:
   2675 	      strcat (buf, ", simple");
   2676 	      break;
   2677 	    case EF_FRV_CPU_TOMCAT:
   2678 	      strcat (buf, ", tomcat");
   2679 	      break;
   2680 	    }
   2681 	  break;
   2682 
   2683 	case EM_68K:
   2684 	  if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
   2685 	    strcat (buf, ", m68000");
   2686 	  else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
   2687 	    strcat (buf, ", cpu32");
   2688 	  else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
   2689 	    strcat (buf, ", fido_a");
   2690 	  else
   2691 	    {
   2692 	      char const * isa = _("unknown");
   2693 	      char const * mac = _("unknown mac");
   2694 	      char const * additional = NULL;
   2695 
   2696 	      switch (e_flags & EF_M68K_CF_ISA_MASK)
   2697 		{
   2698 		case EF_M68K_CF_ISA_A_NODIV:
   2699 		  isa = "A";
   2700 		  additional = ", nodiv";
   2701 		  break;
   2702 		case EF_M68K_CF_ISA_A:
   2703 		  isa = "A";
   2704 		  break;
   2705 		case EF_M68K_CF_ISA_A_PLUS:
   2706 		  isa = "A+";
   2707 		  break;
   2708 		case EF_M68K_CF_ISA_B_NOUSP:
   2709 		  isa = "B";
   2710 		  additional = ", nousp";
   2711 		  break;
   2712 		case EF_M68K_CF_ISA_B:
   2713 		  isa = "B";
   2714 		  break;
   2715 		case EF_M68K_CF_ISA_C:
   2716 		  isa = "C";
   2717 		  break;
   2718 		case EF_M68K_CF_ISA_C_NODIV:
   2719 		  isa = "C";
   2720 		  additional = ", nodiv";
   2721 		  break;
   2722 		}
   2723 	      strcat (buf, ", cf, isa ");
   2724 	      strcat (buf, isa);
   2725 	      if (additional)
   2726 		strcat (buf, additional);
   2727 	      if (e_flags & EF_M68K_CF_FLOAT)
   2728 		strcat (buf, ", float");
   2729 	      switch (e_flags & EF_M68K_CF_MAC_MASK)
   2730 		{
   2731 		case 0:
   2732 		  mac = NULL;
   2733 		  break;
   2734 		case EF_M68K_CF_MAC:
   2735 		  mac = "mac";
   2736 		  break;
   2737 		case EF_M68K_CF_EMAC:
   2738 		  mac = "emac";
   2739 		  break;
   2740 		case EF_M68K_CF_EMAC_B:
   2741 		  mac = "emac_b";
   2742 		  break;
   2743 		}
   2744 	      if (mac)
   2745 		{
   2746 		  strcat (buf, ", ");
   2747 		  strcat (buf, mac);
   2748 		}
   2749 	    }
   2750 	  break;
   2751 
   2752 	case EM_PPC:
   2753 	  if (e_flags & EF_PPC_EMB)
   2754 	    strcat (buf, ", emb");
   2755 
   2756 	  if (e_flags & EF_PPC_RELOCATABLE)
   2757 	    strcat (buf, _(", relocatable"));
   2758 
   2759 	  if (e_flags & EF_PPC_RELOCATABLE_LIB)
   2760 	    strcat (buf, _(", relocatable-lib"));
   2761 	  break;
   2762 
   2763 	case EM_PPC64:
   2764 	  if (e_flags & EF_PPC64_ABI)
   2765 	    {
   2766 	      char abi[] = ", abiv0";
   2767 
   2768 	      abi[6] += e_flags & EF_PPC64_ABI;
   2769 	      strcat (buf, abi);
   2770 	    }
   2771 	  break;
   2772 
   2773 	case EM_V800:
   2774 	  if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
   2775 	    strcat (buf, ", RH850 ABI");
   2776 
   2777 	  if (e_flags & EF_V800_850E3)
   2778 	    strcat (buf, ", V3 architecture");
   2779 
   2780 	  if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
   2781 	    strcat (buf, ", FPU not used");
   2782 
   2783 	  if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
   2784 	    strcat (buf, ", regmode: COMMON");
   2785 
   2786 	  if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
   2787 	    strcat (buf, ", r4 not used");
   2788 
   2789 	  if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
   2790 	    strcat (buf, ", r30 not used");
   2791 
   2792 	  if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
   2793 	    strcat (buf, ", r5 not used");
   2794 
   2795 	  if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
   2796 	    strcat (buf, ", r2 not used");
   2797 
   2798 	  for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
   2799 	    {
   2800 	      switch (e_flags & - e_flags)
   2801 		{
   2802 		case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
   2803 		case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
   2804 		case EF_RH850_SIMD: strcat (buf, ", SIMD"); break;
   2805 		case EF_RH850_CACHE: strcat (buf, ", CACHE"); break;
   2806 		case EF_RH850_MMU: strcat (buf, ", MMU"); break;
   2807 		case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
   2808 		case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
   2809 		case EF_RH850_DATA_ALIGN8: strcat (buf, ", 8-byte alignment"); break;
   2810 		case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
   2811 		case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
   2812 		case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
   2813 		case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
   2814 		case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
   2815 		case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
   2816 		case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
   2817 		case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
   2818 		default: break;
   2819 		}
   2820 	    }
   2821 	  break;
   2822 
   2823 	case EM_V850:
   2824 	case EM_CYGNUS_V850:
   2825 	  switch (e_flags & EF_V850_ARCH)
   2826 	    {
   2827 	    case E_V850E3V5_ARCH:
   2828 	      strcat (buf, ", v850e3v5");
   2829 	      break;
   2830 	    case E_V850E2V3_ARCH:
   2831 	      strcat (buf, ", v850e2v3");
   2832 	      break;
   2833 	    case E_V850E2_ARCH:
   2834 	      strcat (buf, ", v850e2");
   2835 	      break;
   2836             case E_V850E1_ARCH:
   2837               strcat (buf, ", v850e1");
   2838 	      break;
   2839 	    case E_V850E_ARCH:
   2840 	      strcat (buf, ", v850e");
   2841 	      break;
   2842 	    case E_V850_ARCH:
   2843 	      strcat (buf, ", v850");
   2844 	      break;
   2845 	    default:
   2846 	      strcat (buf, _(", unknown v850 architecture variant"));
   2847 	      break;
   2848 	    }
   2849 	  break;
   2850 
   2851 	case EM_M32R:
   2852 	case EM_CYGNUS_M32R:
   2853 	  if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
   2854 	    strcat (buf, ", m32r");
   2855 	  break;
   2856 
   2857 	case EM_MIPS:
   2858 	case EM_MIPS_RS3_LE:
   2859 	  if (e_flags & EF_MIPS_NOREORDER)
   2860 	    strcat (buf, ", noreorder");
   2861 
   2862 	  if (e_flags & EF_MIPS_PIC)
   2863 	    strcat (buf, ", pic");
   2864 
   2865 	  if (e_flags & EF_MIPS_CPIC)
   2866 	    strcat (buf, ", cpic");
   2867 
   2868 	  if (e_flags & EF_MIPS_UCODE)
   2869 	    strcat (buf, ", ugen_reserved");
   2870 
   2871 	  if (e_flags & EF_MIPS_ABI2)
   2872 	    strcat (buf, ", abi2");
   2873 
   2874 	  if (e_flags & EF_MIPS_OPTIONS_FIRST)
   2875 	    strcat (buf, ", odk first");
   2876 
   2877 	  if (e_flags & EF_MIPS_32BITMODE)
   2878 	    strcat (buf, ", 32bitmode");
   2879 
   2880 	  if (e_flags & EF_MIPS_NAN2008)
   2881 	    strcat (buf, ", nan2008");
   2882 
   2883 	  if (e_flags & EF_MIPS_FP64)
   2884 	    strcat (buf, ", fp64");
   2885 
   2886 	  switch ((e_flags & EF_MIPS_MACH))
   2887 	    {
   2888 	    case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
   2889 	    case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
   2890 	    case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
   2891 	    case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
   2892 	    case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
   2893 	    case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
   2894 	    case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
   2895 	    case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
   2896 	    case E_MIPS_MACH_SB1:  strcat (buf, ", sb1");  break;
   2897 	    case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
   2898   	    case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
   2899   	    case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
   2900   	    case E_MIPS_MACH_LS3A: strcat (buf, ", loongson-3a"); break;
   2901 	    case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
   2902 	    case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
   2903 	    case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
   2904 	    case E_MIPS_MACH_XLR:  strcat (buf, ", xlr"); break;
   2905 	    case 0:
   2906 	    /* We simply ignore the field in this case to avoid confusion:
   2907 	       MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
   2908 	       extension.  */
   2909 	      break;
   2910 	    default: strcat (buf, _(", unknown CPU")); break;
   2911 	    }
   2912 
   2913 	  switch ((e_flags & EF_MIPS_ABI))
   2914 	    {
   2915 	    case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
   2916 	    case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
   2917 	    case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
   2918 	    case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
   2919 	    case 0:
   2920 	    /* We simply ignore the field in this case to avoid confusion:
   2921 	       MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
   2922 	       This means it is likely to be an o32 file, but not for
   2923 	       sure.  */
   2924 	      break;
   2925 	    default: strcat (buf, _(", unknown ABI")); break;
   2926 	    }
   2927 
   2928 	  if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
   2929 	    strcat (buf, ", mdmx");
   2930 
   2931 	  if (e_flags & EF_MIPS_ARCH_ASE_M16)
   2932 	    strcat (buf, ", mips16");
   2933 
   2934 	  if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
   2935 	    strcat (buf, ", micromips");
   2936 
   2937 	  switch ((e_flags & EF_MIPS_ARCH))
   2938 	    {
   2939 	    case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
   2940 	    case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
   2941 	    case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
   2942 	    case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
   2943 	    case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
   2944 	    case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
   2945 	    case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
   2946 	    case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
   2947 	    case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
   2948 	    case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
   2949 	    case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
   2950 	    default: strcat (buf, _(", unknown ISA")); break;
   2951 	    }
   2952 	  break;
   2953 
   2954 	case EM_NDS32:
   2955 	  decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
   2956 	  break;
   2957 
   2958 	case EM_SH:
   2959 	  switch ((e_flags & EF_SH_MACH_MASK))
   2960 	    {
   2961 	    case EF_SH1: strcat (buf, ", sh1"); break;
   2962 	    case EF_SH2: strcat (buf, ", sh2"); break;
   2963 	    case EF_SH3: strcat (buf, ", sh3"); break;
   2964 	    case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
   2965 	    case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
   2966 	    case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
   2967 	    case EF_SH3E: strcat (buf, ", sh3e"); break;
   2968 	    case EF_SH4: strcat (buf, ", sh4"); break;
   2969 	    case EF_SH5: strcat (buf, ", sh5"); break;
   2970 	    case EF_SH2E: strcat (buf, ", sh2e"); break;
   2971 	    case EF_SH4A: strcat (buf, ", sh4a"); break;
   2972 	    case EF_SH2A: strcat (buf, ", sh2a"); break;
   2973 	    case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
   2974 	    case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
   2975 	    case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
   2976 	    case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
   2977 	    case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
   2978 	    case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
   2979 	    case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
   2980 	    case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
   2981 	    case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
   2982 	    default: strcat (buf, _(", unknown ISA")); break;
   2983 	    }
   2984 
   2985 	  if (e_flags & EF_SH_PIC)
   2986 	    strcat (buf, ", pic");
   2987 
   2988 	  if (e_flags & EF_SH_FDPIC)
   2989 	    strcat (buf, ", fdpic");
   2990 	  break;
   2991 
   2992         case EM_OR1K:
   2993           if (e_flags & EF_OR1K_NODELAY)
   2994             strcat (buf, ", no delay");
   2995           break;
   2996 
   2997 	case EM_SPARCV9:
   2998 	  if (e_flags & EF_SPARC_32PLUS)
   2999 	    strcat (buf, ", v8+");
   3000 
   3001 	  if (e_flags & EF_SPARC_SUN_US1)
   3002 	    strcat (buf, ", ultrasparcI");
   3003 
   3004 	  if (e_flags & EF_SPARC_SUN_US3)
   3005 	    strcat (buf, ", ultrasparcIII");
   3006 
   3007 	  if (e_flags & EF_SPARC_HAL_R1)
   3008 	    strcat (buf, ", halr1");
   3009 
   3010 	  if (e_flags & EF_SPARC_LEDATA)
   3011 	    strcat (buf, ", ledata");
   3012 
   3013 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
   3014 	    strcat (buf, ", tso");
   3015 
   3016 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
   3017 	    strcat (buf, ", pso");
   3018 
   3019 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
   3020 	    strcat (buf, ", rmo");
   3021 	  break;
   3022 
   3023 	case EM_PARISC:
   3024 	  switch (e_flags & EF_PARISC_ARCH)
   3025 	    {
   3026 	    case EFA_PARISC_1_0:
   3027 	      strcpy (buf, ", PA-RISC 1.0");
   3028 	      break;
   3029 	    case EFA_PARISC_1_1:
   3030 	      strcpy (buf, ", PA-RISC 1.1");
   3031 	      break;
   3032 	    case EFA_PARISC_2_0:
   3033 	      strcpy (buf, ", PA-RISC 2.0");
   3034 	      break;
   3035 	    default:
   3036 	      break;
   3037 	    }
   3038 	  if (e_flags & EF_PARISC_TRAPNIL)
   3039 	    strcat (buf, ", trapnil");
   3040 	  if (e_flags & EF_PARISC_EXT)
   3041 	    strcat (buf, ", ext");
   3042 	  if (e_flags & EF_PARISC_LSB)
   3043 	    strcat (buf, ", lsb");
   3044 	  if (e_flags & EF_PARISC_WIDE)
   3045 	    strcat (buf, ", wide");
   3046 	  if (e_flags & EF_PARISC_NO_KABP)
   3047 	    strcat (buf, ", no kabp");
   3048 	  if (e_flags & EF_PARISC_LAZYSWAP)
   3049 	    strcat (buf, ", lazyswap");
   3050 	  break;
   3051 
   3052 	case EM_PJ:
   3053 	case EM_PJ_OLD:
   3054 	  if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
   3055 	    strcat (buf, ", new calling convention");
   3056 
   3057 	  if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
   3058 	    strcat (buf, ", gnu calling convention");
   3059 	  break;
   3060 
   3061 	case EM_IA_64:
   3062 	  if ((e_flags & EF_IA_64_ABI64))
   3063 	    strcat (buf, ", 64-bit");
   3064 	  else
   3065 	    strcat (buf, ", 32-bit");
   3066 	  if ((e_flags & EF_IA_64_REDUCEDFP))
   3067 	    strcat (buf, ", reduced fp model");
   3068 	  if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
   3069 	    strcat (buf, ", no function descriptors, constant gp");
   3070 	  else if ((e_flags & EF_IA_64_CONS_GP))
   3071 	    strcat (buf, ", constant gp");
   3072 	  if ((e_flags & EF_IA_64_ABSOLUTE))
   3073 	    strcat (buf, ", absolute");
   3074           if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
   3075             {
   3076               if ((e_flags & EF_IA_64_VMS_LINKAGES))
   3077                 strcat (buf, ", vms_linkages");
   3078               switch ((e_flags & EF_IA_64_VMS_COMCOD))
   3079                 {
   3080                 case EF_IA_64_VMS_COMCOD_SUCCESS:
   3081                   break;
   3082                 case EF_IA_64_VMS_COMCOD_WARNING:
   3083                   strcat (buf, ", warning");
   3084                   break;
   3085                 case EF_IA_64_VMS_COMCOD_ERROR:
   3086                   strcat (buf, ", error");
   3087                   break;
   3088                 case EF_IA_64_VMS_COMCOD_ABORT:
   3089                   strcat (buf, ", abort");
   3090                   break;
   3091                 default:
   3092                   abort ();
   3093                 }
   3094             }
   3095 	  break;
   3096 
   3097 	case EM_VAX:
   3098 	  if ((e_flags & EF_VAX_NONPIC))
   3099 	    strcat (buf, ", non-PIC");
   3100 	  if ((e_flags & EF_VAX_DFLOAT))
   3101 	    strcat (buf, ", D-Float");
   3102 	  if ((e_flags & EF_VAX_GFLOAT))
   3103 	    strcat (buf, ", G-Float");
   3104 	  break;
   3105 
   3106 	case EM_RL78:
   3107 	  if (e_flags & E_FLAG_RL78_G10)
   3108 	    strcat (buf, ", G10");
   3109 	  if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
   3110 	    strcat (buf, ", 64-bit doubles");
   3111 	  break;
   3112 
   3113 	case EM_RX:
   3114 	  if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
   3115 	    strcat (buf, ", 64-bit doubles");
   3116 	  if (e_flags & E_FLAG_RX_DSP)
   3117 	    strcat (buf, ", dsp");
   3118 	  if (e_flags & E_FLAG_RX_PID)
   3119 	    strcat (buf, ", pid");
   3120 	  if (e_flags & E_FLAG_RX_ABI)
   3121 	    strcat (buf, ", RX ABI");
   3122 	  break;
   3123 
   3124 	case EM_S390:
   3125 	  if (e_flags & EF_S390_HIGH_GPRS)
   3126 	    strcat (buf, ", highgprs");
   3127 	  break;
   3128 
   3129 	case EM_TI_C6000:
   3130 	  if ((e_flags & EF_C6000_REL))
   3131 	    strcat (buf, ", relocatable module");
   3132 	  break;
   3133 
   3134 	case EM_MSP430:
   3135 	  strcat (buf, _(": architecture variant: "));
   3136 	  switch (e_flags & EF_MSP430_MACH)
   3137 	    {
   3138 	    case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
   3139 	    case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
   3140 	    case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
   3141 	    case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
   3142 	    case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
   3143 	    case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
   3144 	    case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
   3145 	    case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
   3146 	    case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
   3147 	    case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
   3148 	    case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
   3149 	    case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
   3150 	    case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
   3151 	    case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
   3152 	    case E_MSP430_MACH_MSP430X  : strcat (buf, "MSP430X"); break;
   3153 	    default:
   3154 	      strcat (buf, _(": unknown")); break;
   3155 	    }
   3156 
   3157 	  if (e_flags & ~ EF_MSP430_MACH)
   3158 	    strcat (buf, _(": unknown extra flag bits also present"));
   3159 	}
   3160     }
   3161 
   3162   return buf;
   3163 }
   3164 
   3165 static const char *
   3166 get_osabi_name (unsigned int osabi)
   3167 {
   3168   static char buff[32];
   3169 
   3170   switch (osabi)
   3171     {
   3172     case ELFOSABI_NONE:		return "UNIX - System V";
   3173     case ELFOSABI_HPUX:		return "UNIX - HP-UX";
   3174     case ELFOSABI_NETBSD:	return "UNIX - NetBSD";
   3175     case ELFOSABI_GNU:		return "UNIX - GNU";
   3176     case ELFOSABI_SOLARIS:	return "UNIX - Solaris";
   3177     case ELFOSABI_AIX:		return "UNIX - AIX";
   3178     case ELFOSABI_IRIX:		return "UNIX - IRIX";
   3179     case ELFOSABI_FREEBSD:	return "UNIX - FreeBSD";
   3180     case ELFOSABI_TRU64:	return "UNIX - TRU64";
   3181     case ELFOSABI_MODESTO:	return "Novell - Modesto";
   3182     case ELFOSABI_OPENBSD:	return "UNIX - OpenBSD";
   3183     case ELFOSABI_OPENVMS:	return "VMS - OpenVMS";
   3184     case ELFOSABI_NSK:		return "HP - Non-Stop Kernel";
   3185     case ELFOSABI_AROS:		return "AROS";
   3186     case ELFOSABI_FENIXOS:	return "FenixOS";
   3187     default:
   3188       if (osabi >= 64)
   3189 	switch (elf_header.e_machine)
   3190 	  {
   3191 	  case EM_ARM:
   3192 	    switch (osabi)
   3193 	      {
   3194 	      case ELFOSABI_ARM:	return "ARM";
   3195 	      default:
   3196 		break;
   3197 	      }
   3198 	    break;
   3199 
   3200 	  case EM_MSP430:
   3201 	  case EM_MSP430_OLD:
   3202 	    switch (osabi)
   3203 	      {
   3204 	      case ELFOSABI_STANDALONE:	return _("Standalone App");
   3205 	      default:
   3206 		break;
   3207 	      }
   3208 	    break;
   3209 
   3210 	  case EM_TI_C6000:
   3211 	    switch (osabi)
   3212 	      {
   3213 	      case ELFOSABI_C6000_ELFABI:	return _("Bare-metal C6000");
   3214 	      case ELFOSABI_C6000_LINUX:	return "Linux C6000";
   3215 	      default:
   3216 		break;
   3217 	      }
   3218 	    break;
   3219 
   3220 	  default:
   3221 	    break;
   3222 	  }
   3223       snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
   3224       return buff;
   3225     }
   3226 }
   3227 
   3228 static const char *
   3229 get_aarch64_segment_type (unsigned long type)
   3230 {
   3231   switch (type)
   3232     {
   3233     case PT_AARCH64_ARCHEXT:
   3234       return "AARCH64_ARCHEXT";
   3235     default:
   3236       break;
   3237     }
   3238 
   3239   return NULL;
   3240 }
   3241 
   3242 static const char *
   3243 get_arm_segment_type (unsigned long type)
   3244 {
   3245   switch (type)
   3246     {
   3247     case PT_ARM_EXIDX:
   3248       return "EXIDX";
   3249     default:
   3250       break;
   3251     }
   3252 
   3253   return NULL;
   3254 }
   3255 
   3256 static const char *
   3257 get_mips_segment_type (unsigned long type)
   3258 {
   3259   switch (type)
   3260     {
   3261     case PT_MIPS_REGINFO:
   3262       return "REGINFO";
   3263     case PT_MIPS_RTPROC:
   3264       return "RTPROC";
   3265     case PT_MIPS_OPTIONS:
   3266       return "OPTIONS";
   3267     case PT_MIPS_ABIFLAGS:
   3268       return "ABIFLAGS";
   3269     default:
   3270       break;
   3271     }
   3272 
   3273   return NULL;
   3274 }
   3275 
   3276 static const char *
   3277 get_parisc_segment_type (unsigned long type)
   3278 {
   3279   switch (type)
   3280     {
   3281     case PT_HP_TLS:		return "HP_TLS";
   3282     case PT_HP_CORE_NONE:	return "HP_CORE_NONE";
   3283     case PT_HP_CORE_VERSION:	return "HP_CORE_VERSION";
   3284     case PT_HP_CORE_KERNEL:	return "HP_CORE_KERNEL";
   3285     case PT_HP_CORE_COMM:	return "HP_CORE_COMM";
   3286     case PT_HP_CORE_PROC:	return "HP_CORE_PROC";
   3287     case PT_HP_CORE_LOADABLE:	return "HP_CORE_LOADABLE";
   3288     case PT_HP_CORE_STACK:	return "HP_CORE_STACK";
   3289     case PT_HP_CORE_SHM:	return "HP_CORE_SHM";
   3290     case PT_HP_CORE_MMF:	return "HP_CORE_MMF";
   3291     case PT_HP_PARALLEL:	return "HP_PARALLEL";
   3292     case PT_HP_FASTBIND:	return "HP_FASTBIND";
   3293     case PT_HP_OPT_ANNOT:	return "HP_OPT_ANNOT";
   3294     case PT_HP_HSL_ANNOT:	return "HP_HSL_ANNOT";
   3295     case PT_HP_STACK:		return "HP_STACK";
   3296     case PT_HP_CORE_UTSNAME:	return "HP_CORE_UTSNAME";
   3297     case PT_PARISC_ARCHEXT:	return "PARISC_ARCHEXT";
   3298     case PT_PARISC_UNWIND:	return "PARISC_UNWIND";
   3299     case PT_PARISC_WEAKORDER:	return "PARISC_WEAKORDER";
   3300     default:
   3301       break;
   3302     }
   3303 
   3304   return NULL;
   3305 }
   3306 
   3307 static const char *
   3308 get_ia64_segment_type (unsigned long type)
   3309 {
   3310   switch (type)
   3311     {
   3312     case PT_IA_64_ARCHEXT:	return "IA_64_ARCHEXT";
   3313     case PT_IA_64_UNWIND:	return "IA_64_UNWIND";
   3314     case PT_HP_TLS:		return "HP_TLS";
   3315     case PT_IA_64_HP_OPT_ANOT:	return "HP_OPT_ANNOT";
   3316     case PT_IA_64_HP_HSL_ANOT:	return "HP_HSL_ANNOT";
   3317     case PT_IA_64_HP_STACK:	return "HP_STACK";
   3318     default:
   3319       break;
   3320     }
   3321 
   3322   return NULL;
   3323 }
   3324 
   3325 static const char *
   3326 get_tic6x_segment_type (unsigned long type)
   3327 {
   3328   switch (type)
   3329     {
   3330     case PT_C6000_PHATTR:	return "C6000_PHATTR";
   3331     default:
   3332       break;
   3333     }
   3334 
   3335   return NULL;
   3336 }
   3337 
   3338 static const char *
   3339 get_segment_type (unsigned long p_type)
   3340 {
   3341   static char buff[32];
   3342 
   3343   switch (p_type)
   3344     {
   3345     case PT_NULL:	return "NULL";
   3346     case PT_LOAD:	return "LOAD";
   3347     case PT_DYNAMIC:	return "DYNAMIC";
   3348     case PT_INTERP:	return "INTERP";
   3349     case PT_NOTE:	return "NOTE";
   3350     case PT_SHLIB:	return "SHLIB";
   3351     case PT_PHDR:	return "PHDR";
   3352     case PT_TLS:	return "TLS";
   3353 
   3354     case PT_GNU_EH_FRAME:
   3355 			return "GNU_EH_FRAME";
   3356     case PT_GNU_STACK:	return "GNU_STACK";
   3357     case PT_GNU_RELRO:  return "GNU_RELRO";
   3358 
   3359     default:
   3360       if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
   3361 	{
   3362 	  const char * result;
   3363 
   3364 	  switch (elf_header.e_machine)
   3365 	    {
   3366 	    case EM_AARCH64:
   3367 	      result = get_aarch64_segment_type (p_type);
   3368 	      break;
   3369 	    case EM_ARM:
   3370 	      result = get_arm_segment_type (p_type);
   3371 	      break;
   3372 	    case EM_MIPS:
   3373 	    case EM_MIPS_RS3_LE:
   3374 	      result = get_mips_segment_type (p_type);
   3375 	      break;
   3376 	    case EM_PARISC:
   3377 	      result = get_parisc_segment_type (p_type);
   3378 	      break;
   3379 	    case EM_IA_64:
   3380 	      result = get_ia64_segment_type (p_type);
   3381 	      break;
   3382 	    case EM_TI_C6000:
   3383 	      result = get_tic6x_segment_type (p_type);
   3384 	      break;
   3385 	    default:
   3386 	      result = NULL;
   3387 	      break;
   3388 	    }
   3389 
   3390 	  if (result != NULL)
   3391 	    return result;
   3392 
   3393 	  sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
   3394 	}
   3395       else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
   3396 	{
   3397 	  const char * result;
   3398 
   3399 	  switch (elf_header.e_machine)
   3400 	    {
   3401 	    case EM_PARISC:
   3402 	      result = get_parisc_segment_type (p_type);
   3403 	      break;
   3404 	    case EM_IA_64:
   3405 	      result = get_ia64_segment_type (p_type);
   3406 	      break;
   3407 	    default:
   3408 	      result = NULL;
   3409 	      break;
   3410 	    }
   3411 
   3412 	  if (result != NULL)
   3413 	    return result;
   3414 
   3415 	  sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
   3416 	}
   3417       else
   3418 	snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
   3419 
   3420       return buff;
   3421     }
   3422 }
   3423 
   3424 static const char *
   3425 get_mips_section_type_name (unsigned int sh_type)
   3426 {
   3427   switch (sh_type)
   3428     {
   3429     case SHT_MIPS_LIBLIST:	 return "MIPS_LIBLIST";
   3430     case SHT_MIPS_MSYM:		 return "MIPS_MSYM";
   3431     case SHT_MIPS_CONFLICT:	 return "MIPS_CONFLICT";
   3432     case SHT_MIPS_GPTAB:	 return "MIPS_GPTAB";
   3433     case SHT_MIPS_UCODE:	 return "MIPS_UCODE";
   3434     case SHT_MIPS_DEBUG:	 return "MIPS_DEBUG";
   3435     case SHT_MIPS_REGINFO:	 return "MIPS_REGINFO";
   3436     case SHT_MIPS_PACKAGE:	 return "MIPS_PACKAGE";
   3437     case SHT_MIPS_PACKSYM:	 return "MIPS_PACKSYM";
   3438     case SHT_MIPS_RELD:		 return "MIPS_RELD";
   3439     case SHT_MIPS_IFACE:	 return "MIPS_IFACE";
   3440     case SHT_MIPS_CONTENT:	 return "MIPS_CONTENT";
   3441     case SHT_MIPS_OPTIONS:	 return "MIPS_OPTIONS";
   3442     case SHT_MIPS_SHDR:		 return "MIPS_SHDR";
   3443     case SHT_MIPS_FDESC:	 return "MIPS_FDESC";
   3444     case SHT_MIPS_EXTSYM:	 return "MIPS_EXTSYM";
   3445     case SHT_MIPS_DENSE:	 return "MIPS_DENSE";
   3446     case SHT_MIPS_PDESC:	 return "MIPS_PDESC";
   3447     case SHT_MIPS_LOCSYM:	 return "MIPS_LOCSYM";
   3448     case SHT_MIPS_AUXSYM:	 return "MIPS_AUXSYM";
   3449     case SHT_MIPS_OPTSYM:	 return "MIPS_OPTSYM";
   3450     case SHT_MIPS_LOCSTR:	 return "MIPS_LOCSTR";
   3451     case SHT_MIPS_LINE:		 return "MIPS_LINE";
   3452     case SHT_MIPS_RFDESC:	 return "MIPS_RFDESC";
   3453     case SHT_MIPS_DELTASYM:	 return "MIPS_DELTASYM";
   3454     case SHT_MIPS_DELTAINST:	 return "MIPS_DELTAINST";
   3455     case SHT_MIPS_DELTACLASS:	 return "MIPS_DELTACLASS";
   3456     case SHT_MIPS_DWARF:	 return "MIPS_DWARF";
   3457     case SHT_MIPS_DELTADECL:	 return "MIPS_DELTADECL";
   3458     case SHT_MIPS_SYMBOL_LIB:	 return "MIPS_SYMBOL_LIB";
   3459     case SHT_MIPS_EVENTS:	 return "MIPS_EVENTS";
   3460     case SHT_MIPS_TRANSLATE:	 return "MIPS_TRANSLATE";
   3461     case SHT_MIPS_PIXIE:	 return "MIPS_PIXIE";
   3462     case SHT_MIPS_XLATE:	 return "MIPS_XLATE";
   3463     case SHT_MIPS_XLATE_DEBUG:	 return "MIPS_XLATE_DEBUG";
   3464     case SHT_MIPS_WHIRL:	 return "MIPS_WHIRL";
   3465     case SHT_MIPS_EH_REGION:	 return "MIPS_EH_REGION";
   3466     case SHT_MIPS_XLATE_OLD:	 return "MIPS_XLATE_OLD";
   3467     case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
   3468     case SHT_MIPS_ABIFLAGS:	 return "MIPS_ABIFLAGS";
   3469     default:
   3470       break;
   3471     }
   3472   return NULL;
   3473 }
   3474 
   3475 static const char *
   3476 get_parisc_section_type_name (unsigned int sh_type)
   3477 {
   3478   switch (sh_type)
   3479     {
   3480     case SHT_PARISC_EXT:	return "PARISC_EXT";
   3481     case SHT_PARISC_UNWIND:	return "PARISC_UNWIND";
   3482     case SHT_PARISC_DOC:	return "PARISC_DOC";
   3483     case SHT_PARISC_ANNOT:	return "PARISC_ANNOT";
   3484     case SHT_PARISC_SYMEXTN:	return "PARISC_SYMEXTN";
   3485     case SHT_PARISC_STUBS:	return "PARISC_STUBS";
   3486     case SHT_PARISC_DLKM:	return "PARISC_DLKM";
   3487     default:
   3488       break;
   3489     }
   3490   return NULL;
   3491 }
   3492 
   3493 static const char *
   3494 get_ia64_section_type_name (unsigned int sh_type)
   3495 {
   3496   /* If the top 8 bits are 0x78 the next 8 are the os/abi ID.  */
   3497   if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
   3498     return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
   3499 
   3500   switch (sh_type)
   3501     {
   3502     case SHT_IA_64_EXT:		       return "IA_64_EXT";
   3503     case SHT_IA_64_UNWIND:	       return "IA_64_UNWIND";
   3504     case SHT_IA_64_PRIORITY_INIT:      return "IA_64_PRIORITY_INIT";
   3505     case SHT_IA_64_VMS_TRACE:          return "VMS_TRACE";
   3506     case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
   3507     case SHT_IA_64_VMS_DEBUG:          return "VMS_DEBUG";
   3508     case SHT_IA_64_VMS_DEBUG_STR:      return "VMS_DEBUG_STR";
   3509     case SHT_IA_64_VMS_LINKAGES:       return "VMS_LINKAGES";
   3510     case SHT_IA_64_VMS_SYMBOL_VECTOR:  return "VMS_SYMBOL_VECTOR";
   3511     case SHT_IA_64_VMS_FIXUP:          return "VMS_FIXUP";
   3512     default:
   3513       break;
   3514     }
   3515   return NULL;
   3516 }
   3517 
   3518 static const char *
   3519 get_x86_64_section_type_name (unsigned int sh_type)
   3520 {
   3521   switch (sh_type)
   3522     {
   3523     case SHT_X86_64_UNWIND:	return "X86_64_UNWIND";
   3524     default:
   3525       break;
   3526     }
   3527   return NULL;
   3528 }
   3529 
   3530 static const char *
   3531 get_aarch64_section_type_name (unsigned int sh_type)
   3532 {
   3533   switch (sh_type)
   3534     {
   3535     case SHT_AARCH64_ATTRIBUTES:
   3536       return "AARCH64_ATTRIBUTES";
   3537     default:
   3538       break;
   3539     }
   3540   return NULL;
   3541 }
   3542 
   3543 static const char *
   3544 get_arm_section_type_name (unsigned int sh_type)
   3545 {
   3546   switch (sh_type)
   3547     {
   3548     case SHT_ARM_EXIDX:           return "ARM_EXIDX";
   3549     case SHT_ARM_PREEMPTMAP:      return "ARM_PREEMPTMAP";
   3550     case SHT_ARM_ATTRIBUTES:      return "ARM_ATTRIBUTES";
   3551     case SHT_ARM_DEBUGOVERLAY:    return "ARM_DEBUGOVERLAY";
   3552     case SHT_ARM_OVERLAYSECTION:  return "ARM_OVERLAYSECTION";
   3553     default:
   3554       break;
   3555     }
   3556   return NULL;
   3557 }
   3558 
   3559 static const char *
   3560 get_tic6x_section_type_name (unsigned int sh_type)
   3561 {
   3562   switch (sh_type)
   3563     {
   3564     case SHT_C6000_UNWIND:
   3565       return "C6000_UNWIND";
   3566     case SHT_C6000_PREEMPTMAP:
   3567       return "C6000_PREEMPTMAP";
   3568     case SHT_C6000_ATTRIBUTES:
   3569       return "C6000_ATTRIBUTES";
   3570     case SHT_TI_ICODE:
   3571       return "TI_ICODE";
   3572     case SHT_TI_XREF:
   3573       return "TI_XREF";
   3574     case SHT_TI_HANDLER:
   3575       return "TI_HANDLER";
   3576     case SHT_TI_INITINFO:
   3577       return "TI_INITINFO";
   3578     case SHT_TI_PHATTRS:
   3579       return "TI_PHATTRS";
   3580     default:
   3581       break;
   3582     }
   3583   return NULL;
   3584 }
   3585 
   3586 static const char *
   3587 get_msp430x_section_type_name (unsigned int sh_type)
   3588 {
   3589   switch (sh_type)
   3590     {
   3591     case SHT_MSP430_SEC_FLAGS:   return "MSP430_SEC_FLAGS";
   3592     case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
   3593     case SHT_MSP430_ATTRIBUTES:  return "MSP430_ATTRIBUTES";
   3594     default: return NULL;
   3595     }
   3596 }
   3597 
   3598 static const char *
   3599 get_section_type_name (unsigned int sh_type)
   3600 {
   3601   static char buff[32];
   3602 
   3603   switch (sh_type)
   3604     {
   3605     case SHT_NULL:		return "NULL";
   3606     case SHT_PROGBITS:		return "PROGBITS";
   3607     case SHT_SYMTAB:		return "SYMTAB";
   3608     case SHT_STRTAB:		return "STRTAB";
   3609     case SHT_RELA:		return "RELA";
   3610     case SHT_HASH:		return "HASH";
   3611     case SHT_DYNAMIC:		return "DYNAMIC";
   3612     case SHT_NOTE:		return "NOTE";
   3613     case SHT_NOBITS:		return "NOBITS";
   3614     case SHT_REL:		return "REL";
   3615     case SHT_SHLIB:		return "SHLIB";
   3616     case SHT_DYNSYM:		return "DYNSYM";
   3617     case SHT_INIT_ARRAY:	return "INIT_ARRAY";
   3618     case SHT_FINI_ARRAY:	return "FINI_ARRAY";
   3619     case SHT_PREINIT_ARRAY:	return "PREINIT_ARRAY";
   3620     case SHT_GNU_HASH:		return "GNU_HASH";
   3621     case SHT_GROUP:		return "GROUP";
   3622     case SHT_SYMTAB_SHNDX:	return "SYMTAB SECTION INDICIES";
   3623     case SHT_GNU_verdef:	return "VERDEF";
   3624     case SHT_GNU_verneed:	return "VERNEED";
   3625     case SHT_GNU_versym:	return "VERSYM";
   3626     case 0x6ffffff0:		return "VERSYM";
   3627     case 0x6ffffffc:		return "VERDEF";
   3628     case 0x7ffffffd:		return "AUXILIARY";
   3629     case 0x7fffffff:		return "FILTER";
   3630     case SHT_GNU_LIBLIST:	return "GNU_LIBLIST";
   3631 
   3632     default:
   3633       if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
   3634 	{
   3635 	  const char * result;
   3636 
   3637 	  switch (elf_header.e_machine)
   3638 	    {
   3639 	    case EM_MIPS:
   3640 	    case EM_MIPS_RS3_LE:
   3641 	      result = get_mips_section_type_name (sh_type);
   3642 	      break;
   3643 	    case EM_PARISC:
   3644 	      result = get_parisc_section_type_name (sh_type);
   3645 	      break;
   3646 	    case EM_IA_64:
   3647 	      result = get_ia64_section_type_name (sh_type);
   3648 	      break;
   3649 	    case EM_X86_64:
   3650 	    case EM_L1OM:
   3651 	    case EM_K1OM:
   3652 	      result = get_x86_64_section_type_name (sh_type);
   3653 	      break;
   3654 	    case EM_AARCH64:
   3655 	      result = get_aarch64_section_type_name (sh_type);
   3656 	      break;
   3657 	    case EM_ARM:
   3658 	      result = get_arm_section_type_name (sh_type);
   3659 	      break;
   3660 	    case EM_TI_C6000:
   3661 	      result = get_tic6x_section_type_name (sh_type);
   3662 	      break;
   3663 	    case EM_MSP430:
   3664 	      result = get_msp430x_section_type_name (sh_type);
   3665 	      break;
   3666 	    default:
   3667 	      result = NULL;
   3668 	      break;
   3669 	    }
   3670 
   3671 	  if (result != NULL)
   3672 	    return result;
   3673 
   3674 	  sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
   3675 	}
   3676       else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
   3677 	{
   3678 	  const char * result;
   3679 
   3680 	  switch (elf_header.e_machine)
   3681 	    {
   3682 	    case EM_IA_64:
   3683 	      result = get_ia64_section_type_name (sh_type);
   3684 	      break;
   3685 	    default:
   3686 	      result = NULL;
   3687 	      break;
   3688 	    }
   3689 
   3690 	  if (result != NULL)
   3691 	    return result;
   3692 
   3693 	  sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
   3694 	}
   3695       else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
   3696 	sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
   3697       else
   3698 	/* This message is probably going to be displayed in a 15
   3699 	   character wide field, so put the hex value first.  */
   3700 	snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
   3701 
   3702       return buff;
   3703     }
   3704 }
   3705 
   3706 #define OPTION_DEBUG_DUMP	512
   3707 #define OPTION_DYN_SYMS		513
   3708 #define OPTION_DWARF_DEPTH	514
   3709 #define OPTION_DWARF_START	515
   3710 #define OPTION_DWARF_CHECK	516
   3711 
   3712 static struct option options[] =
   3713 {
   3714   {"all",	       no_argument, 0, 'a'},
   3715   {"file-header",      no_argument, 0, 'h'},
   3716   {"program-headers",  no_argument, 0, 'l'},
   3717   {"headers",	       no_argument, 0, 'e'},
   3718   {"histogram",	       no_argument, 0, 'I'},
   3719   {"segments",	       no_argument, 0, 'l'},
   3720   {"sections",	       no_argument, 0, 'S'},
   3721   {"section-headers",  no_argument, 0, 'S'},
   3722   {"section-groups",   no_argument, 0, 'g'},
   3723   {"section-details",  no_argument, 0, 't'},
   3724   {"full-section-name",no_argument, 0, 'N'},
   3725   {"symbols",	       no_argument, 0, 's'},
   3726   {"syms",	       no_argument, 0, 's'},
   3727   {"dyn-syms",	       no_argument, 0, OPTION_DYN_SYMS},
   3728   {"relocs",	       no_argument, 0, 'r'},
   3729   {"notes",	       no_argument, 0, 'n'},
   3730   {"dynamic",	       no_argument, 0, 'd'},
   3731   {"arch-specific",    no_argument, 0, 'A'},
   3732   {"version-info",     no_argument, 0, 'V'},
   3733   {"use-dynamic",      no_argument, 0, 'D'},
   3734   {"unwind",	       no_argument, 0, 'u'},
   3735   {"archive-index",    no_argument, 0, 'c'},
   3736   {"hex-dump",	       required_argument, 0, 'x'},
   3737   {"relocated-dump",   required_argument, 0, 'R'},
   3738   {"string-dump",      required_argument, 0, 'p'},
   3739 #ifdef SUPPORT_DISASSEMBLY
   3740   {"instruction-dump", required_argument, 0, 'i'},
   3741 #endif
   3742   {"debug-dump",       optional_argument, 0, OPTION_DEBUG_DUMP},
   3743 
   3744   {"dwarf-depth",      required_argument, 0, OPTION_DWARF_DEPTH},
   3745   {"dwarf-start",      required_argument, 0, OPTION_DWARF_START},
   3746   {"dwarf-check",      no_argument, 0, OPTION_DWARF_CHECK},
   3747 
   3748   {"version",	       no_argument, 0, 'v'},
   3749   {"wide",	       no_argument, 0, 'W'},
   3750   {"help",	       no_argument, 0, 'H'},
   3751   {0,		       no_argument, 0, 0}
   3752 };
   3753 
   3754 static void
   3755 usage (FILE * stream)
   3756 {
   3757   fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
   3758   fprintf (stream, _(" Display information about the contents of ELF format files\n"));
   3759   fprintf (stream, _(" Options are:\n\
   3760   -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I\n\
   3761   -h --file-header       Display the ELF file header\n\
   3762   -l --program-headers   Display the program headers\n\
   3763      --segments          An alias for --program-headers\n\
   3764   -S --section-headers   Display the sections' header\n\
   3765      --sections          An alias for --section-headers\n\
   3766   -g --section-groups    Display the section groups\n\
   3767   -t --section-details   Display the section details\n\
   3768   -e --headers           Equivalent to: -h -l -S\n\
   3769   -s --syms              Display the symbol table\n\
   3770      --symbols           An alias for --syms\n\
   3771   --dyn-syms             Display the dynamic symbol table\n\
   3772   -n --notes             Display the core notes (if present)\n\
   3773   -r --relocs            Display the relocations (if present)\n\
   3774   -u --unwind            Display the unwind info (if present)\n\
   3775   -d --dynamic           Display the dynamic section (if present)\n\
   3776   -V --version-info      Display the version sections (if present)\n\
   3777   -A --arch-specific     Display architecture specific information (if any)\n\
   3778   -c --archive-index     Display the symbol/file index in an archive\n\
   3779   -D --use-dynamic       Use the dynamic section info when displaying symbols\n\
   3780   -x --hex-dump=<number|name>\n\
   3781                          Dump the contents of section <number|name> as bytes\n\
   3782   -p --string-dump=<number|name>\n\
   3783                          Dump the contents of section <number|name> as strings\n\
   3784   -R --relocated-dump=<number|name>\n\
   3785                          Dump the contents of section <number|name> as relocated bytes\n\
   3786   -w[lLiaprmfFsoRt] or\n\
   3787   --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
   3788                =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
   3789                =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
   3790                =addr,=cu_index]\n\
   3791                          Display the contents of DWARF2 debug sections\n"));
   3792   fprintf (stream, _("\
   3793   --dwarf-depth=N        Do not display DIEs at depth N or greater\n\
   3794   --dwarf-start=N        Display DIEs starting with N, at the same depth\n\
   3795                          or deeper\n"));
   3796 #ifdef SUPPORT_DISASSEMBLY
   3797   fprintf (stream, _("\
   3798   -i --instruction-dump=<number|name>\n\
   3799                          Disassemble the contents of section <number|name>\n"));
   3800 #endif
   3801   fprintf (stream, _("\
   3802   -I --histogram         Display histogram of bucket list lengths\n\
   3803   -W --wide              Allow output width to exceed 80 characters\n\
   3804   @<file>                Read options from <file>\n\
   3805   -H --help              Display this information\n\
   3806   -v --version           Display the version number of readelf\n"));
   3807 
   3808   if (REPORT_BUGS_TO[0] && stream == stdout)
   3809     fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
   3810 
   3811   exit (stream == stdout ? 0 : 1);
   3812 }
   3813 
   3814 /* Record the fact that the user wants the contents of section number
   3815    SECTION to be displayed using the method(s) encoded as flags bits
   3816    in TYPE.  Note, TYPE can be zero if we are creating the array for
   3817    the first time.  */
   3818 
   3819 static void
   3820 request_dump_bynumber (unsigned int section, dump_type type)
   3821 {
   3822   if (section >= num_dump_sects)
   3823     {
   3824       dump_type * new_dump_sects;
   3825 
   3826       new_dump_sects = (dump_type *) calloc (section + 1,
   3827                                              sizeof (* dump_sects));
   3828 
   3829       if (new_dump_sects == NULL)
   3830 	error (_("Out of memory allocating dump request table.\n"));
   3831       else
   3832 	{
   3833 	  /* Copy current flag settings.  */
   3834 	  memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects));
   3835 
   3836 	  free (dump_sects);
   3837 
   3838 	  dump_sects = new_dump_sects;
   3839 	  num_dump_sects = section + 1;
   3840 	}
   3841     }
   3842 
   3843   if (dump_sects)
   3844     dump_sects[section] |= type;
   3845 
   3846   return;
   3847 }
   3848 
   3849 /* Request a dump by section name.  */
   3850 
   3851 static void
   3852 request_dump_byname (const char * section, dump_type type)
   3853 {
   3854   struct dump_list_entry * new_request;
   3855 
   3856   new_request = (struct dump_list_entry *)
   3857       malloc (sizeof (struct dump_list_entry));
   3858   if (!new_request)
   3859     error (_("Out of memory allocating dump request table.\n"));
   3860 
   3861   new_request->name = strdup (section);
   3862   if (!new_request->name)
   3863     error (_("Out of memory allocating dump request table.\n"));
   3864 
   3865   new_request->type = type;
   3866 
   3867   new_request->next = dump_sects_byname;
   3868   dump_sects_byname = new_request;
   3869 }
   3870 
   3871 static inline void
   3872 request_dump (dump_type type)
   3873 {
   3874   int section;
   3875   char * cp;
   3876 
   3877   do_dump++;
   3878   section = strtoul (optarg, & cp, 0);
   3879 
   3880   if (! *cp && section >= 0)
   3881     request_dump_bynumber (section, type);
   3882   else
   3883     request_dump_byname (optarg, type);
   3884 }
   3885 
   3886 
   3887 static void
   3888 parse_args (int argc, char ** argv)
   3889 {
   3890   int c;
   3891 
   3892   if (argc < 2)
   3893     usage (stderr);
   3894 
   3895   while ((c = getopt_long
   3896 	  (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:", options, NULL)) != EOF)
   3897     {
   3898       switch (c)
   3899 	{
   3900 	case 0:
   3901 	  /* Long options.  */
   3902 	  break;
   3903 	case 'H':
   3904 	  usage (stdout);
   3905 	  break;
   3906 
   3907 	case 'a':
   3908 	  do_syms++;
   3909 	  do_reloc++;
   3910 	  do_unwind++;
   3911 	  do_dynamic++;
   3912 	  do_header++;
   3913 	  do_sections++;
   3914 	  do_section_groups++;
   3915 	  do_segments++;
   3916 	  do_version++;
   3917 	  do_histogram++;
   3918 	  do_arch++;
   3919 	  do_notes++;
   3920 	  break;
   3921 	case 'g':
   3922 	  do_section_groups++;
   3923 	  break;
   3924 	case 't':
   3925 	case 'N':
   3926 	  do_sections++;
   3927 	  do_section_details++;
   3928 	  break;
   3929 	case 'e':
   3930 	  do_header++;
   3931 	  do_sections++;
   3932 	  do_segments++;
   3933 	  break;
   3934 	case 'A':
   3935 	  do_arch++;
   3936 	  break;
   3937 	case 'D':
   3938 	  do_using_dynamic++;
   3939 	  break;
   3940 	case 'r':
   3941 	  do_reloc++;
   3942 	  break;
   3943 	case 'u':
   3944 	  do_unwind++;
   3945 	  break;
   3946 	case 'h':
   3947 	  do_header++;
   3948 	  break;
   3949 	case 'l':
   3950 	  do_segments++;
   3951 	  break;
   3952 	case 's':
   3953 	  do_syms++;
   3954 	  break;
   3955 	case 'S':
   3956 	  do_sections++;
   3957 	  break;
   3958 	case 'd':
   3959 	  do_dynamic++;
   3960 	  break;
   3961 	case 'I':
   3962 	  do_histogram++;
   3963 	  break;
   3964 	case 'n':
   3965 	  do_notes++;
   3966 	  break;
   3967 	case 'c':
   3968 	  do_archive_index++;
   3969 	  break;
   3970 	case 'x':
   3971 	  request_dump (HEX_DUMP);
   3972 	  break;
   3973 	case 'p':
   3974 	  request_dump (STRING_DUMP);
   3975 	  break;
   3976 	case 'R':
   3977 	  request_dump (RELOC_DUMP);
   3978 	  break;
   3979 	case 'w':
   3980 	  do_dump++;
   3981 	  if (optarg == 0)
   3982 	    {
   3983 	      do_debugging = 1;
   3984 	      dwarf_select_sections_all ();
   3985 	    }
   3986 	  else
   3987 	    {
   3988 	      do_debugging = 0;
   3989 	      dwarf_select_sections_by_letters (optarg);
   3990 	    }
   3991 	  break;
   3992 	case OPTION_DEBUG_DUMP:
   3993 	  do_dump++;
   3994 	  if (optarg == 0)
   3995 	    do_debugging = 1;
   3996 	  else
   3997 	    {
   3998 	      do_debugging = 0;
   3999 	      dwarf_select_sections_by_names (optarg);
   4000 	    }
   4001 	  break;
   4002 	case OPTION_DWARF_DEPTH:
   4003 	  {
   4004 	    char *cp;
   4005 
   4006 	    dwarf_cutoff_level = strtoul (optarg, & cp, 0);
   4007 	  }
   4008 	  break;
   4009 	case OPTION_DWARF_START:
   4010 	  {
   4011 	    char *cp;
   4012 
   4013 	    dwarf_start_die = strtoul (optarg, & cp, 0);
   4014 	  }
   4015 	  break;
   4016 	case OPTION_DWARF_CHECK:
   4017 	  dwarf_check = 1;
   4018 	  break;
   4019 	case OPTION_DYN_SYMS:
   4020 	  do_dyn_syms++;
   4021 	  break;
   4022 #ifdef SUPPORT_DISASSEMBLY
   4023 	case 'i':
   4024 	  request_dump (DISASS_DUMP);
   4025 	  break;
   4026 #endif
   4027 	case 'v':
   4028 	  print_version (program_name);
   4029 	  break;
   4030 	case 'V':
   4031 	  do_version++;
   4032 	  break;
   4033 	case 'W':
   4034 	  do_wide++;
   4035 	  break;
   4036 	default:
   4037 	  /* xgettext:c-format */
   4038 	  error (_("Invalid option '-%c'\n"), c);
   4039 	  /* Drop through.  */
   4040 	case '?':
   4041 	  usage (stderr);
   4042 	}
   4043     }
   4044 
   4045   if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
   4046       && !do_segments && !do_header && !do_dump && !do_version
   4047       && !do_histogram && !do_debugging && !do_arch && !do_notes
   4048       && !do_section_groups && !do_archive_index
   4049       && !do_dyn_syms)
   4050     usage (stderr);
   4051   else if (argc < 3)
   4052     {
   4053       warn (_("Nothing to do.\n"));
   4054       usage (stderr);
   4055     }
   4056 }
   4057 
   4058 static const char *
   4059 get_elf_class (unsigned int elf_class)
   4060 {
   4061   static char buff[32];
   4062 
   4063   switch (elf_class)
   4064     {
   4065     case ELFCLASSNONE: return _("none");
   4066     case ELFCLASS32:   return "ELF32";
   4067     case ELFCLASS64:   return "ELF64";
   4068     default:
   4069       snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
   4070       return buff;
   4071     }
   4072 }
   4073 
   4074 static const char *
   4075 get_data_encoding (unsigned int encoding)
   4076 {
   4077   static char buff[32];
   4078 
   4079   switch (encoding)
   4080     {
   4081     case ELFDATANONE: return _("none");
   4082     case ELFDATA2LSB: return _("2's complement, little endian");
   4083     case ELFDATA2MSB: return _("2's complement, big endian");
   4084     default:
   4085       snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
   4086       return buff;
   4087     }
   4088 }
   4089 
   4090 /* Decode the data held in 'elf_header'.  */
   4091 
   4092 static int
   4093 process_file_header (void)
   4094 {
   4095   if (   elf_header.e_ident[EI_MAG0] != ELFMAG0
   4096       || elf_header.e_ident[EI_MAG1] != ELFMAG1
   4097       || elf_header.e_ident[EI_MAG2] != ELFMAG2
   4098       || elf_header.e_ident[EI_MAG3] != ELFMAG3)
   4099     {
   4100       error
   4101 	(_("Not an ELF file - it has the wrong magic bytes at the start\n"));
   4102       return 0;
   4103     }
   4104 
   4105   init_dwarf_regnames (elf_header.e_machine);
   4106 
   4107   if (do_header)
   4108     {
   4109       int i;
   4110 
   4111       printf (_("ELF Header:\n"));
   4112       printf (_("  Magic:   "));
   4113       for (i = 0; i < EI_NIDENT; i++)
   4114 	printf ("%2.2x ", elf_header.e_ident[i]);
   4115       printf ("\n");
   4116       printf (_("  Class:                             %s\n"),
   4117 	      get_elf_class (elf_header.e_ident[EI_CLASS]));
   4118       printf (_("  Data:                              %s\n"),
   4119 	      get_data_encoding (elf_header.e_ident[EI_DATA]));
   4120       printf (_("  Version:                           %d %s\n"),
   4121 	      elf_header.e_ident[EI_VERSION],
   4122 	      (elf_header.e_ident[EI_VERSION] == EV_CURRENT
   4123 	       ? "(current)"
   4124 	       : (elf_header.e_ident[EI_VERSION] != EV_NONE
   4125 		  ? _("<unknown: %lx>")
   4126 		  : "")));
   4127       printf (_("  OS/ABI:                            %s\n"),
   4128 	      get_osabi_name (elf_header.e_ident[EI_OSABI]));
   4129       printf (_("  ABI Version:                       %d\n"),
   4130 	      elf_header.e_ident[EI_ABIVERSION]);
   4131       printf (_("  Type:                              %s\n"),
   4132 	      get_file_type (elf_header.e_type));
   4133       printf (_("  Machine:                           %s\n"),
   4134 	      get_machine_name (elf_header.e_machine));
   4135       printf (_("  Version:                           0x%lx\n"),
   4136 	      (unsigned long) elf_header.e_version);
   4137 
   4138       printf (_("  Entry point address:               "));
   4139       print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
   4140       printf (_("\n  Start of program headers:          "));
   4141       print_vma ((bfd_vma) elf_header.e_phoff, DEC);
   4142       printf (_(" (bytes into file)\n  Start of section headers:          "));
   4143       print_vma ((bfd_vma) elf_header.e_shoff, DEC);
   4144       printf (_(" (bytes into file)\n"));
   4145 
   4146       printf (_("  Flags:                             0x%lx%s\n"),
   4147 	      (unsigned long) elf_header.e_flags,
   4148 	      get_machine_flags (elf_header.e_flags, elf_header.e_machine));
   4149       printf (_("  Size of this header:               %ld (bytes)\n"),
   4150 	      (long) elf_header.e_ehsize);
   4151       printf (_("  Size of program headers:           %ld (bytes)\n"),
   4152 	      (long) elf_header.e_phentsize);
   4153       printf (_("  Number of program headers:         %ld"),
   4154 	      (long) elf_header.e_phnum);
   4155       if (section_headers != NULL
   4156 	  && elf_header.e_phnum == PN_XNUM
   4157 	  && section_headers[0].sh_info != 0)
   4158 	printf (" (%ld)", (long) section_headers[0].sh_info);
   4159       putc ('\n', stdout);
   4160       printf (_("  Size of section headers:           %ld (bytes)\n"),
   4161 	      (long) elf_header.e_shentsize);
   4162       printf (_("  Number of section headers:         %ld"),
   4163 	      (long) elf_header.e_shnum);
   4164       if (section_headers != NULL && elf_header.e_shnum == SHN_UNDEF)
   4165 	printf (" (%ld)", (long) section_headers[0].sh_size);
   4166       putc ('\n', stdout);
   4167       printf (_("  Section header string table index: %ld"),
   4168 	      (long) elf_header.e_shstrndx);
   4169       if (section_headers != NULL
   4170 	  && elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
   4171 	printf (" (%u)", section_headers[0].sh_link);
   4172       else if (elf_header.e_shstrndx != SHN_UNDEF
   4173 	       && elf_header.e_shstrndx >= elf_header.e_shnum)
   4174 	printf (_(" <corrupt: out of range>"));
   4175       putc ('\n', stdout);
   4176     }
   4177 
   4178   if (section_headers != NULL)
   4179     {
   4180       if (elf_header.e_phnum == PN_XNUM
   4181 	  && section_headers[0].sh_info != 0)
   4182 	elf_header.e_phnum = section_headers[0].sh_info;
   4183       if (elf_header.e_shnum == SHN_UNDEF)
   4184 	elf_header.e_shnum = section_headers[0].sh_size;
   4185       if (elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
   4186 	elf_header.e_shstrndx = section_headers[0].sh_link;
   4187       else if (elf_header.e_shstrndx >= elf_header.e_shnum)
   4188 	elf_header.e_shstrndx = SHN_UNDEF;
   4189       free (section_headers);
   4190       section_headers = NULL;
   4191     }
   4192 
   4193   return 1;
   4194 }
   4195 
   4196 static bfd_boolean
   4197 get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
   4198 {
   4199   Elf32_External_Phdr * phdrs;
   4200   Elf32_External_Phdr * external;
   4201   Elf_Internal_Phdr *   internal;
   4202   unsigned int i;
   4203   unsigned int size = elf_header.e_phentsize;
   4204   unsigned int num  = elf_header.e_phnum;
   4205 
   4206   /* PR binutils/17531: Cope with unexpected section header sizes.  */
   4207   if (size == 0 || num == 0)
   4208     return FALSE;
   4209   if (size < sizeof * phdrs)
   4210     {
   4211       error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
   4212       return FALSE;
   4213     }
   4214   if (size > sizeof * phdrs)
   4215     warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
   4216 
   4217   phdrs = (Elf32_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
   4218                                             size, num, _("program headers"));
   4219   if (phdrs == NULL)
   4220     return FALSE;
   4221 
   4222   for (i = 0, internal = pheaders, external = phdrs;
   4223        i < elf_header.e_phnum;
   4224        i++, internal++, external++)
   4225     {
   4226       internal->p_type   = BYTE_GET (external->p_type);
   4227       internal->p_offset = BYTE_GET (external->p_offset);
   4228       internal->p_vaddr  = BYTE_GET (external->p_vaddr);
   4229       internal->p_paddr  = BYTE_GET (external->p_paddr);
   4230       internal->p_filesz = BYTE_GET (external->p_filesz);
   4231       internal->p_memsz  = BYTE_GET (external->p_memsz);
   4232       internal->p_flags  = BYTE_GET (external->p_flags);
   4233       internal->p_align  = BYTE_GET (external->p_align);
   4234     }
   4235 
   4236   free (phdrs);
   4237   return TRUE;
   4238 }
   4239 
   4240 static bfd_boolean
   4241 get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
   4242 {
   4243   Elf64_External_Phdr * phdrs;
   4244   Elf64_External_Phdr * external;
   4245   Elf_Internal_Phdr *   internal;
   4246   unsigned int i;
   4247   unsigned int size = elf_header.e_phentsize;
   4248   unsigned int num  = elf_header.e_phnum;
   4249 
   4250   /* PR binutils/17531: Cope with unexpected section header sizes.  */
   4251   if (size == 0 || num == 0)
   4252     return FALSE;
   4253   if (size < sizeof * phdrs)
   4254     {
   4255       error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
   4256       return FALSE;
   4257     }
   4258   if (size > sizeof * phdrs)
   4259     warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
   4260 
   4261   phdrs = (Elf64_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
   4262                                             size, num, _("program headers"));
   4263   if (!phdrs)
   4264     return FALSE;
   4265 
   4266   for (i = 0, internal = pheaders, external = phdrs;
   4267        i < elf_header.e_phnum;
   4268        i++, internal++, external++)
   4269     {
   4270       internal->p_type   = BYTE_GET (external->p_type);
   4271       internal->p_flags  = BYTE_GET (external->p_flags);
   4272       internal->p_offset = BYTE_GET (external->p_offset);
   4273       internal->p_vaddr  = BYTE_GET (external->p_vaddr);
   4274       internal->p_paddr  = BYTE_GET (external->p_paddr);
   4275       internal->p_filesz = BYTE_GET (external->p_filesz);
   4276       internal->p_memsz  = BYTE_GET (external->p_memsz);
   4277       internal->p_align  = BYTE_GET (external->p_align);
   4278     }
   4279 
   4280   free (phdrs);
   4281   return TRUE;
   4282 }
   4283 
   4284 /* Returns 1 if the program headers were read into `program_headers'.  */
   4285 
   4286 static int
   4287 get_program_headers (FILE * file)
   4288 {
   4289   Elf_Internal_Phdr * phdrs;
   4290 
   4291   /* Check cache of prior read.  */
   4292   if (program_headers != NULL)
   4293     return 1;
   4294 
   4295   phdrs = (Elf_Internal_Phdr *) cmalloc (elf_header.e_phnum,
   4296                                          sizeof (Elf_Internal_Phdr));
   4297 
   4298   if (phdrs == NULL)
   4299     {
   4300       error (_("Out of memory reading %u program headers\n"),
   4301 	     elf_header.e_phnum);
   4302       return 0;
   4303     }
   4304 
   4305   if (is_32bit_elf
   4306       ? get_32bit_program_headers (file, phdrs)
   4307       : get_64bit_program_headers (file, phdrs))
   4308     {
   4309       program_headers = phdrs;
   4310       return 1;
   4311     }
   4312 
   4313   free (phdrs);
   4314   return 0;
   4315 }
   4316 
   4317 /* Returns 1 if the program headers were loaded.  */
   4318 
   4319 static int
   4320 process_program_headers (FILE * file)
   4321 {
   4322   Elf_Internal_Phdr * segment;
   4323   unsigned int i;
   4324 
   4325   if (elf_header.e_phnum == 0)
   4326     {
   4327       /* PR binutils/12467.  */
   4328       if (elf_header.e_phoff != 0)
   4329 	warn (_("possibly corrupt ELF header - it has a non-zero program"
   4330 		" header offset, but no program headers"));
   4331       else if (do_segments)
   4332 	printf (_("\nThere are no program headers in this file.\n"));
   4333       return 0;
   4334     }
   4335 
   4336   if (do_segments && !do_header)
   4337     {
   4338       printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
   4339       printf (_("Entry point "));
   4340       print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
   4341       printf (_("\nThere are %d program headers, starting at offset "),
   4342 	      elf_header.e_phnum);
   4343       print_vma ((bfd_vma) elf_header.e_phoff, DEC);
   4344       printf ("\n");
   4345     }
   4346 
   4347   if (! get_program_headers (file))
   4348       return 0;
   4349 
   4350   if (do_segments)
   4351     {
   4352       if (elf_header.e_phnum > 1)
   4353 	printf (_("\nProgram Headers:\n"));
   4354       else
   4355 	printf (_("\nProgram Headers:\n"));
   4356 
   4357       if (is_32bit_elf)
   4358 	printf
   4359 	  (_("  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align\n"));
   4360       else if (do_wide)
   4361 	printf
   4362 	  (_("  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align\n"));
   4363       else
   4364 	{
   4365 	  printf
   4366 	    (_("  Type           Offset             VirtAddr           PhysAddr\n"));
   4367 	  printf
   4368 	    (_("                 FileSiz            MemSiz              Flags  Align\n"));
   4369 	}
   4370     }
   4371 
   4372   dynamic_addr = 0;
   4373   dynamic_size = 0;
   4374 
   4375   for (i = 0, segment = program_headers;
   4376        i < elf_header.e_phnum;
   4377        i++, segment++)
   4378     {
   4379       if (do_segments)
   4380 	{
   4381 	  printf ("  %-14.14s ", get_segment_type (segment->p_type));
   4382 
   4383 	  if (is_32bit_elf)
   4384 	    {
   4385 	      printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
   4386 	      printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
   4387 	      printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
   4388 	      printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
   4389 	      printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
   4390 	      printf ("%c%c%c ",
   4391 		      (segment->p_flags & PF_R ? 'R' : ' '),
   4392 		      (segment->p_flags & PF_W ? 'W' : ' '),
   4393 		      (segment->p_flags & PF_X ? 'E' : ' '));
   4394 	      printf ("%#lx", (unsigned long) segment->p_align);
   4395 	    }
   4396 	  else if (do_wide)
   4397 	    {
   4398 	      if ((unsigned long) segment->p_offset == segment->p_offset)
   4399 		printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
   4400 	      else
   4401 		{
   4402 		  print_vma (segment->p_offset, FULL_HEX);
   4403 		  putchar (' ');
   4404 		}
   4405 
   4406 	      print_vma (segment->p_vaddr, FULL_HEX);
   4407 	      putchar (' ');
   4408 	      print_vma (segment->p_paddr, FULL_HEX);
   4409 	      putchar (' ');
   4410 
   4411 	      if ((unsigned long) segment->p_filesz == segment->p_filesz)
   4412 		printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
   4413 	      else
   4414 		{
   4415 		  print_vma (segment->p_filesz, FULL_HEX);
   4416 		  putchar (' ');
   4417 		}
   4418 
   4419 	      if ((unsigned long) segment->p_memsz == segment->p_memsz)
   4420 		printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
   4421 	      else
   4422 		{
   4423 		  print_vma (segment->p_memsz, FULL_HEX);
   4424 		}
   4425 
   4426 	      printf (" %c%c%c ",
   4427 		      (segment->p_flags & PF_R ? 'R' : ' '),
   4428 		      (segment->p_flags & PF_W ? 'W' : ' '),
   4429 		      (segment->p_flags & PF_X ? 'E' : ' '));
   4430 
   4431 	      if ((unsigned long) segment->p_align == segment->p_align)
   4432 		printf ("%#lx", (unsigned long) segment->p_align);
   4433 	      else
   4434 		{
   4435 		  print_vma (segment->p_align, PREFIX_HEX);
   4436 		}
   4437 	    }
   4438 	  else
   4439 	    {
   4440 	      print_vma (segment->p_offset, FULL_HEX);
   4441 	      putchar (' ');
   4442 	      print_vma (segment->p_vaddr, FULL_HEX);
   4443 	      putchar (' ');
   4444 	      print_vma (segment->p_paddr, FULL_HEX);
   4445 	      printf ("\n                 ");
   4446 	      print_vma (segment->p_filesz, FULL_HEX);
   4447 	      putchar (' ');
   4448 	      print_vma (segment->p_memsz, FULL_HEX);
   4449 	      printf ("  %c%c%c    ",
   4450 		      (segment->p_flags & PF_R ? 'R' : ' '),
   4451 		      (segment->p_flags & PF_W ? 'W' : ' '),
   4452 		      (segment->p_flags & PF_X ? 'E' : ' '));
   4453 	      print_vma (segment->p_align, HEX);
   4454 	    }
   4455 	}
   4456 
   4457       if (do_segments)
   4458 	putc ('\n', stdout);
   4459 
   4460       switch (segment->p_type)
   4461 	{
   4462 	case PT_DYNAMIC:
   4463 	  if (dynamic_addr)
   4464 	    error (_("more than one dynamic segment\n"));
   4465 
   4466 	  /* By default, assume that the .dynamic section is the first
   4467 	     section in the DYNAMIC segment.  */
   4468 	  dynamic_addr = segment->p_offset;
   4469 	  dynamic_size = segment->p_filesz;
   4470 	  /* PR binutils/17512: Avoid corrupt dynamic section info in the segment.  */
   4471 	  if (dynamic_addr + dynamic_size >= current_file_size)
   4472 	    {
   4473 	      error (_("the dynamic segment offset + size exceeds the size of the file\n"));
   4474 	      dynamic_addr = dynamic_size = 0;
   4475 	    }
   4476 
   4477 	  /* Try to locate the .dynamic section. If there is
   4478 	     a section header table, we can easily locate it.  */
   4479 	  if (section_headers != NULL)
   4480 	    {
   4481 	      Elf_Internal_Shdr * sec;
   4482 
   4483 	      sec = find_section (".dynamic");
   4484 	      if (sec == NULL || sec->sh_size == 0)
   4485 		{
   4486                   /* A corresponding .dynamic section is expected, but on
   4487                      IA-64/OpenVMS it is OK for it to be missing.  */
   4488                   if (!is_ia64_vms ())
   4489                     error (_("no .dynamic section in the dynamic segment\n"));
   4490 		  break;
   4491 		}
   4492 
   4493 	      if (sec->sh_type == SHT_NOBITS)
   4494 		{
   4495 		  dynamic_size = 0;
   4496 		  break;
   4497 		}
   4498 
   4499 	      dynamic_addr = sec->sh_offset;
   4500 	      dynamic_size = sec->sh_size;
   4501 
   4502 	      if (dynamic_addr < segment->p_offset
   4503 		  || dynamic_addr > segment->p_offset + segment->p_filesz)
   4504 		warn (_("the .dynamic section is not contained"
   4505 			" within the dynamic segment\n"));
   4506 	      else if (dynamic_addr > segment->p_offset)
   4507 		warn (_("the .dynamic section is not the first section"
   4508 			" in the dynamic segment.\n"));
   4509 	    }
   4510 	  break;
   4511 
   4512 	case PT_INTERP:
   4513 	  if (fseek (file, archive_file_offset + (long) segment->p_offset,
   4514 		     SEEK_SET))
   4515 	    error (_("Unable to find program interpreter name\n"));
   4516 	  else
   4517 	    {
   4518 	      char fmt [32];
   4519 	      int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
   4520 
   4521 	      if (ret >= (int) sizeof (fmt) || ret < 0)
   4522 		error (_("Internal error: failed to create format string to display program interpreter\n"));
   4523 
   4524 	      program_interpreter[0] = 0;
   4525 	      if (fscanf (file, fmt, program_interpreter) <= 0)
   4526 		error (_("Unable to read program interpreter name\n"));
   4527 
   4528 	      if (do_segments)
   4529 		printf (_("      [Requesting program interpreter: %s]\n"),
   4530 		    program_interpreter);
   4531 	    }
   4532 	  break;
   4533 	}
   4534     }
   4535 
   4536   if (do_segments && section_headers != NULL && string_table != NULL)
   4537     {
   4538       printf (_("\n Section to Segment mapping:\n"));
   4539       printf (_("  Segment Sections...\n"));
   4540 
   4541       for (i = 0; i < elf_header.e_phnum; i++)
   4542 	{
   4543 	  unsigned int j;
   4544 	  Elf_Internal_Shdr * section;
   4545 
   4546 	  segment = program_headers + i;
   4547 	  section = section_headers + 1;
   4548 
   4549 	  printf ("   %2.2d     ", i);
   4550 
   4551 	  for (j = 1; j < elf_header.e_shnum; j++, section++)
   4552 	    {
   4553 	      if (!ELF_TBSS_SPECIAL (section, segment)
   4554 		  && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
   4555 		printf ("%s ", printable_section_name (section));
   4556 	    }
   4557 
   4558 	  putc ('\n',stdout);
   4559 	}
   4560     }
   4561 
   4562   return 1;
   4563 }
   4564 
   4565 
   4566 /* Find the file offset corresponding to VMA by using the program headers.  */
   4567 
   4568 static long
   4569 offset_from_vma (FILE * file, bfd_vma vma, bfd_size_type size)
   4570 {
   4571   Elf_Internal_Phdr * seg;
   4572 
   4573   if (! get_program_headers (file))
   4574     {
   4575       warn (_("Cannot interpret virtual addresses without program headers.\n"));
   4576       return (long) vma;
   4577     }
   4578 
   4579   for (seg = program_headers;
   4580        seg < program_headers + elf_header.e_phnum;
   4581        ++seg)
   4582     {
   4583       if (seg->p_type != PT_LOAD)
   4584 	continue;
   4585 
   4586       if (vma >= (seg->p_vaddr & -seg->p_align)
   4587 	  && vma + size <= seg->p_vaddr + seg->p_filesz)
   4588 	return vma - seg->p_vaddr + seg->p_offset;
   4589     }
   4590 
   4591   warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
   4592 	(unsigned long) vma);
   4593   return (long) vma;
   4594 }
   4595 
   4596 
   4597 /* Allocate memory and load the sections headers into the global pointer
   4598    SECTION_HEADERS.  If PROBE is true, this is just a probe and we do not
   4599    generate any error messages if the load fails.  */
   4600 
   4601 static bfd_boolean
   4602 get_32bit_section_headers (FILE * file, bfd_boolean probe)
   4603 {
   4604   Elf32_External_Shdr * shdrs;
   4605   Elf_Internal_Shdr *   internal;
   4606   unsigned int i;
   4607   unsigned int size = elf_header.e_shentsize;
   4608   unsigned int num = probe ? 1 : elf_header.e_shnum;
   4609 
   4610   /* PR binutils/17531: Cope with unexpected section header sizes.  */
   4611   if (size == 0 || num == 0)
   4612     return FALSE;
   4613   if (size < sizeof * shdrs)
   4614     {
   4615       if (! probe)
   4616 	error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
   4617       return FALSE;
   4618     }
   4619   if (!probe && size > sizeof * shdrs)
   4620     warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
   4621 
   4622   shdrs = (Elf32_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
   4623                                             size, num,
   4624 					    probe ? NULL : _("section headers"));
   4625   if (shdrs == NULL)
   4626     return FALSE;
   4627 
   4628   if (section_headers != NULL)
   4629     free (section_headers);
   4630   section_headers = (Elf_Internal_Shdr *) cmalloc (num,
   4631                                                    sizeof (Elf_Internal_Shdr));
   4632   if (section_headers == NULL)
   4633     {
   4634       if (!probe)
   4635 	error (_("Out of memory reading %u section headers\n"), num);
   4636       return FALSE;
   4637     }
   4638 
   4639   for (i = 0, internal = section_headers;
   4640        i < num;
   4641        i++, internal++)
   4642     {
   4643       internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
   4644       internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
   4645       internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
   4646       internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
   4647       internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
   4648       internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
   4649       internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
   4650       internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
   4651       internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
   4652       internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
   4653     }
   4654 
   4655   free (shdrs);
   4656   return TRUE;
   4657 }
   4658 
   4659 static bfd_boolean
   4660 get_64bit_section_headers (FILE * file, bfd_boolean probe)
   4661 {
   4662   Elf64_External_Shdr * shdrs;
   4663   Elf_Internal_Shdr *   internal;
   4664   unsigned int i;
   4665   unsigned int size = elf_header.e_shentsize;
   4666   unsigned int num = probe ? 1 : elf_header.e_shnum;
   4667 
   4668   /* PR binutils/17531: Cope with unexpected section header sizes.  */
   4669   if (size == 0 || num == 0)
   4670     return FALSE;
   4671   if (size < sizeof * shdrs)
   4672     {
   4673       if (! probe)
   4674 	error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
   4675       return FALSE;
   4676     }
   4677   if (! probe && size > sizeof * shdrs)
   4678     warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
   4679 
   4680   shdrs = (Elf64_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
   4681                                             size, num,
   4682 					    probe ? NULL : _("section headers"));
   4683   if (shdrs == NULL)
   4684     return FALSE;
   4685 
   4686   if (section_headers != NULL)
   4687     free (section_headers);
   4688   section_headers = (Elf_Internal_Shdr *) cmalloc (num,
   4689                                                    sizeof (Elf_Internal_Shdr));
   4690   if (section_headers == NULL)
   4691     {
   4692       if (! probe)
   4693 	error (_("Out of memory reading %u section headers\n"), num);
   4694       return FALSE;
   4695     }
   4696 
   4697   for (i = 0, internal = section_headers;
   4698        i < num;
   4699        i++, internal++)
   4700     {
   4701       internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
   4702       internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
   4703       internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
   4704       internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
   4705       internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
   4706       internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
   4707       internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
   4708       internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
   4709       internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
   4710       internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
   4711     }
   4712 
   4713   free (shdrs);
   4714   return TRUE;
   4715 }
   4716 
   4717 static Elf_Internal_Sym *
   4718 get_32bit_elf_symbols (FILE * file,
   4719 		       Elf_Internal_Shdr * section,
   4720 		       unsigned long * num_syms_return)
   4721 {
   4722   unsigned long number = 0;
   4723   Elf32_External_Sym * esyms = NULL;
   4724   Elf_External_Sym_Shndx * shndx = NULL;
   4725   Elf_Internal_Sym * isyms = NULL;
   4726   Elf_Internal_Sym * psym;
   4727   unsigned int j;
   4728 
   4729   /* Run some sanity checks first.  */
   4730   if (section->sh_entsize == 0)
   4731     {
   4732       error (_("sh_entsize is zero\n"));
   4733       goto exit_point;
   4734     }
   4735 
   4736   if (section->sh_size > current_file_size)
   4737     {
   4738       error (_("Section %s has an invalid sh_size of 0x%lx\n"),
   4739 	     printable_section_name (section), (unsigned long) section->sh_size);
   4740       goto exit_point;
   4741     }
   4742 
   4743   number = section->sh_size / section->sh_entsize;
   4744 
   4745   if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
   4746     {
   4747       error (_("Invalid sh_entsize\n"));
   4748       goto exit_point;
   4749     }
   4750 
   4751   esyms = (Elf32_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
   4752                                            section->sh_size, _("symbols"));
   4753   if (esyms == NULL)
   4754     goto exit_point;
   4755 
   4756   shndx = NULL;
   4757   if (symtab_shndx_hdr != NULL
   4758       && (symtab_shndx_hdr->sh_link
   4759 	  == (unsigned long) (section - section_headers)))
   4760     {
   4761       shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
   4762                                                    symtab_shndx_hdr->sh_offset,
   4763                                                    1, symtab_shndx_hdr->sh_size,
   4764                                                    _("symbol table section indicies"));
   4765       if (shndx == NULL)
   4766 	goto exit_point;
   4767     }
   4768 
   4769   isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
   4770 
   4771   if (isyms == NULL)
   4772     {
   4773       error (_("Out of memory reading %lu symbols\n"),
   4774 	     (unsigned long) number);
   4775       goto exit_point;
   4776     }
   4777 
   4778   for (j = 0, psym = isyms; j < number; j++, psym++)
   4779     {
   4780       psym->st_name  = BYTE_GET (esyms[j].st_name);
   4781       psym->st_value = BYTE_GET (esyms[j].st_value);
   4782       psym->st_size  = BYTE_GET (esyms[j].st_size);
   4783       psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
   4784       if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
   4785 	psym->st_shndx
   4786 	  = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
   4787       else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
   4788 	psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
   4789       psym->st_info  = BYTE_GET (esyms[j].st_info);
   4790       psym->st_other = BYTE_GET (esyms[j].st_other);
   4791     }
   4792 
   4793  exit_point:
   4794   if (shndx != NULL)
   4795     free (shndx);
   4796   if (esyms != NULL)
   4797     free (esyms);
   4798 
   4799   if (num_syms_return != NULL)
   4800     * num_syms_return = isyms == NULL ? 0 : number;
   4801 
   4802   return isyms;
   4803 }
   4804 
   4805 static Elf_Internal_Sym *
   4806 get_64bit_elf_symbols (FILE * file,
   4807 		       Elf_Internal_Shdr * section,
   4808 		       unsigned long * num_syms_return)
   4809 {
   4810   unsigned long number = 0;
   4811   Elf64_External_Sym * esyms = NULL;
   4812   Elf_External_Sym_Shndx * shndx = NULL;
   4813   Elf_Internal_Sym * isyms = NULL;
   4814   Elf_Internal_Sym * psym;
   4815   unsigned int j;
   4816 
   4817   /* Run some sanity checks first.  */
   4818   if (section->sh_entsize == 0)
   4819     {
   4820       error (_("sh_entsize is zero\n"));
   4821       goto exit_point;
   4822     }
   4823 
   4824   if (section->sh_size > current_file_size)
   4825     {
   4826       error (_("Section %s has an invalid sh_size of 0x%lx\n"),
   4827 	     printable_section_name (section), (unsigned long) section->sh_size);
   4828       goto exit_point;
   4829     }
   4830 
   4831   number = section->sh_size / section->sh_entsize;
   4832 
   4833   if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
   4834     {
   4835       error (_("Invalid sh_entsize\n"));
   4836       goto exit_point;
   4837     }
   4838 
   4839   esyms = (Elf64_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
   4840                                            section->sh_size, _("symbols"));
   4841   if (!esyms)
   4842     goto exit_point;
   4843 
   4844   if (symtab_shndx_hdr != NULL
   4845       && (symtab_shndx_hdr->sh_link
   4846 	  == (unsigned long) (section - section_headers)))
   4847     {
   4848       shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
   4849                                                    symtab_shndx_hdr->sh_offset,
   4850                                                    1, symtab_shndx_hdr->sh_size,
   4851                                                    _("symbol table section indicies"));
   4852       if (shndx == NULL)
   4853 	goto exit_point;
   4854     }
   4855 
   4856   isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
   4857 
   4858   if (isyms == NULL)
   4859     {
   4860       error (_("Out of memory reading %lu symbols\n"),
   4861 	     (unsigned long) number);
   4862       goto exit_point;
   4863     }
   4864 
   4865   for (j = 0, psym = isyms; j < number; j++, psym++)
   4866     {
   4867       psym->st_name  = BYTE_GET (esyms[j].st_name);
   4868       psym->st_info  = BYTE_GET (esyms[j].st_info);
   4869       psym->st_other = BYTE_GET (esyms[j].st_other);
   4870       psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
   4871 
   4872       if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
   4873 	psym->st_shndx
   4874 	  = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
   4875       else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
   4876 	psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
   4877 
   4878       psym->st_value = BYTE_GET (esyms[j].st_value);
   4879       psym->st_size  = BYTE_GET (esyms[j].st_size);
   4880     }
   4881 
   4882  exit_point:
   4883   if (shndx != NULL)
   4884     free (shndx);
   4885   if (esyms != NULL)
   4886     free (esyms);
   4887 
   4888   if (num_syms_return != NULL)
   4889     * num_syms_return = isyms == NULL ? 0 : number;
   4890 
   4891   return isyms;
   4892 }
   4893 
   4894 static const char *
   4895 get_elf_section_flags (bfd_vma sh_flags)
   4896 {
   4897   static char buff[1024];
   4898   char * p = buff;
   4899   int field_size = is_32bit_elf ? 8 : 16;
   4900   int sindex;
   4901   int size = sizeof (buff) - (field_size + 4 + 1);
   4902   bfd_vma os_flags = 0;
   4903   bfd_vma proc_flags = 0;
   4904   bfd_vma unknown_flags = 0;
   4905   static const struct
   4906     {
   4907       const char * str;
   4908       int len;
   4909     }
   4910   flags [] =
   4911     {
   4912       /*  0 */ { STRING_COMMA_LEN ("WRITE") },
   4913       /*  1 */ { STRING_COMMA_LEN ("ALLOC") },
   4914       /*  2 */ { STRING_COMMA_LEN ("EXEC") },
   4915       /*  3 */ { STRING_COMMA_LEN ("MERGE") },
   4916       /*  4 */ { STRING_COMMA_LEN ("STRINGS") },
   4917       /*  5 */ { STRING_COMMA_LEN ("INFO LINK") },
   4918       /*  6 */ { STRING_COMMA_LEN ("LINK ORDER") },
   4919       /*  7 */ { STRING_COMMA_LEN ("OS NONCONF") },
   4920       /*  8 */ { STRING_COMMA_LEN ("GROUP") },
   4921       /*  9 */ { STRING_COMMA_LEN ("TLS") },
   4922       /* IA-64 specific.  */
   4923       /* 10 */ { STRING_COMMA_LEN ("SHORT") },
   4924       /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
   4925       /* IA-64 OpenVMS specific.  */
   4926       /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
   4927       /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
   4928       /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
   4929       /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
   4930       /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
   4931       /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
   4932       /* Generic.  */
   4933       /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
   4934       /* SPARC specific.  */
   4935       /* 19 */ { STRING_COMMA_LEN ("ORDERED") }
   4936     };
   4937 
   4938   if (do_section_details)
   4939     {
   4940       sprintf (buff, "[%*.*lx]: ",
   4941 	       field_size, field_size, (unsigned long) sh_flags);
   4942       p += field_size + 4;
   4943     }
   4944 
   4945   while (sh_flags)
   4946     {
   4947       bfd_vma flag;
   4948 
   4949       flag = sh_flags & - sh_flags;
   4950       sh_flags &= ~ flag;
   4951 
   4952       if (do_section_details)
   4953 	{
   4954 	  switch (flag)
   4955 	    {
   4956 	    case SHF_WRITE:		sindex = 0; break;
   4957 	    case SHF_ALLOC:		sindex = 1; break;
   4958 	    case SHF_EXECINSTR:		sindex = 2; break;
   4959 	    case SHF_MERGE:		sindex = 3; break;
   4960 	    case SHF_STRINGS:		sindex = 4; break;
   4961 	    case SHF_INFO_LINK:		sindex = 5; break;
   4962 	    case SHF_LINK_ORDER:	sindex = 6; break;
   4963 	    case SHF_OS_NONCONFORMING:	sindex = 7; break;
   4964 	    case SHF_GROUP:		sindex = 8; break;
   4965 	    case SHF_TLS:		sindex = 9; break;
   4966 	    case SHF_EXCLUDE:		sindex = 18; break;
   4967 
   4968 	    default:
   4969 	      sindex = -1;
   4970 	      switch (elf_header.e_machine)
   4971 		{
   4972 		case EM_IA_64:
   4973 		  if (flag == SHF_IA_64_SHORT)
   4974 		    sindex = 10;
   4975 		  else if (flag == SHF_IA_64_NORECOV)
   4976 		    sindex = 11;
   4977 #ifdef BFD64
   4978 		  else if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
   4979 		    switch (flag)
   4980 		      {
   4981 		      case SHF_IA_64_VMS_GLOBAL:      sindex = 12; break;
   4982 		      case SHF_IA_64_VMS_OVERLAID:    sindex = 13; break;
   4983 		      case SHF_IA_64_VMS_SHARED:      sindex = 14; break;
   4984 		      case SHF_IA_64_VMS_VECTOR:      sindex = 15; break;
   4985 		      case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
   4986 		      case SHF_IA_64_VMS_PROTECTED:   sindex = 17; break;
   4987 		      default:                        break;
   4988 		      }
   4989 #endif
   4990 		  break;
   4991 
   4992 		case EM_386:
   4993 		case EM_486:
   4994 		case EM_X86_64:
   4995 		case EM_L1OM:
   4996 		case EM_K1OM:
   4997 		case EM_OLD_SPARCV9:
   4998 		case EM_SPARC32PLUS:
   4999 		case EM_SPARCV9:
   5000 		case EM_SPARC:
   5001 		  if (flag == SHF_ORDERED)
   5002 		    sindex = 19;
   5003 		  break;
   5004 		default:
   5005 		  break;
   5006 		}
   5007 	    }
   5008 
   5009 	  if (sindex != -1)
   5010 	    {
   5011 	      if (p != buff + field_size + 4)
   5012 		{
   5013 		  if (size < (10 + 2))
   5014 		    abort ();
   5015 		  size -= 2;
   5016 		  *p++ = ',';
   5017 		  *p++ = ' ';
   5018 		}
   5019 
   5020 	      size -= flags [sindex].len;
   5021 	      p = stpcpy (p, flags [sindex].str);
   5022 	    }
   5023 	  else if (flag & SHF_MASKOS)
   5024 	    os_flags |= flag;
   5025 	  else if (flag & SHF_MASKPROC)
   5026 	    proc_flags |= flag;
   5027 	  else
   5028 	    unknown_flags |= flag;
   5029 	}
   5030       else
   5031 	{
   5032 	  switch (flag)
   5033 	    {
   5034 	    case SHF_WRITE:		*p = 'W'; break;
   5035 	    case SHF_ALLOC:		*p = 'A'; break;
   5036 	    case SHF_EXECINSTR:		*p = 'X'; break;
   5037 	    case SHF_MERGE:		*p = 'M'; break;
   5038 	    case SHF_STRINGS:		*p = 'S'; break;
   5039 	    case SHF_INFO_LINK:		*p = 'I'; break;
   5040 	    case SHF_LINK_ORDER:	*p = 'L'; break;
   5041 	    case SHF_OS_NONCONFORMING:	*p = 'O'; break;
   5042 	    case SHF_GROUP:		*p = 'G'; break;
   5043 	    case SHF_TLS:		*p = 'T'; break;
   5044 	    case SHF_EXCLUDE:		*p = 'E'; break;
   5045 
   5046 	    default:
   5047 	      if ((elf_header.e_machine == EM_X86_64
   5048 		   || elf_header.e_machine == EM_L1OM
   5049 		   || elf_header.e_machine == EM_K1OM)
   5050 		  && flag == SHF_X86_64_LARGE)
   5051 		*p = 'l';
   5052 	      else if (flag & SHF_MASKOS)
   5053 		{
   5054 		  *p = 'o';
   5055 		  sh_flags &= ~ SHF_MASKOS;
   5056 		}
   5057 	      else if (flag & SHF_MASKPROC)
   5058 		{
   5059 		  *p = 'p';
   5060 		  sh_flags &= ~ SHF_MASKPROC;
   5061 		}
   5062 	      else
   5063 		*p = 'x';
   5064 	      break;
   5065 	    }
   5066 	  p++;
   5067 	}
   5068     }
   5069 
   5070   if (do_section_details)
   5071     {
   5072       if (os_flags)
   5073 	{
   5074 	  size -= 5 + field_size;
   5075 	  if (p != buff + field_size + 4)
   5076 	    {
   5077 	      if (size < (2 + 1))
   5078 		abort ();
   5079 	      size -= 2;
   5080 	      *p++ = ',';
   5081 	      *p++ = ' ';
   5082 	    }
   5083 	  sprintf (p, "OS (%*.*lx)", field_size, field_size,
   5084 		   (unsigned long) os_flags);
   5085 	  p += 5 + field_size;
   5086 	}
   5087       if (proc_flags)
   5088 	{
   5089 	  size -= 7 + field_size;
   5090 	  if (p != buff + field_size + 4)
   5091 	    {
   5092 	      if (size < (2 + 1))
   5093 		abort ();
   5094 	      size -= 2;
   5095 	      *p++ = ',';
   5096 	      *p++ = ' ';
   5097 	    }
   5098 	  sprintf (p, "PROC (%*.*lx)", field_size, field_size,
   5099 		   (unsigned long) proc_flags);
   5100 	  p += 7 + field_size;
   5101 	}
   5102       if (unknown_flags)
   5103 	{
   5104 	  size -= 10 + field_size;
   5105 	  if (p != buff + field_size + 4)
   5106 	    {
   5107 	      if (size < (2 + 1))
   5108 		abort ();
   5109 	      size -= 2;
   5110 	      *p++ = ',';
   5111 	      *p++ = ' ';
   5112 	    }
   5113 	  sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
   5114 		   (unsigned long) unknown_flags);
   5115 	  p += 10 + field_size;
   5116 	}
   5117     }
   5118 
   5119   *p = '\0';
   5120   return buff;
   5121 }
   5122 
   5123 static int
   5124 process_section_headers (FILE * file)
   5125 {
   5126   Elf_Internal_Shdr * section;
   5127   unsigned int i;
   5128 
   5129   section_headers = NULL;
   5130 
   5131   if (elf_header.e_shnum == 0)
   5132     {
   5133       /* PR binutils/12467.  */
   5134       if (elf_header.e_shoff != 0)
   5135 	warn (_("possibly corrupt ELF file header - it has a non-zero"
   5136 		" section header offset, but no section headers\n"));
   5137       else if (do_sections)
   5138 	printf (_("\nThere are no sections in this file.\n"));
   5139 
   5140       return 1;
   5141     }
   5142 
   5143   if (do_sections && !do_header)
   5144     printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
   5145 	    elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
   5146 
   5147   if (is_32bit_elf)
   5148     {
   5149       if (! get_32bit_section_headers (file, FALSE))
   5150 	return 0;
   5151     }
   5152   else if (! get_64bit_section_headers (file, FALSE))
   5153     return 0;
   5154 
   5155   /* Read in the string table, so that we have names to display.  */
   5156   if (elf_header.e_shstrndx != SHN_UNDEF
   5157        && elf_header.e_shstrndx < elf_header.e_shnum)
   5158     {
   5159       section = section_headers + elf_header.e_shstrndx;
   5160 
   5161       if (section->sh_size != 0)
   5162 	{
   5163 	  string_table = (char *) get_data (NULL, file, section->sh_offset,
   5164                                             1, section->sh_size,
   5165                                             _("string table"));
   5166 
   5167 	  string_table_length = string_table != NULL ? section->sh_size : 0;
   5168 	}
   5169     }
   5170 
   5171   /* Scan the sections for the dynamic symbol table
   5172      and dynamic string table and debug sections.  */
   5173   dynamic_symbols = NULL;
   5174   dynamic_strings = NULL;
   5175   dynamic_syminfo = NULL;
   5176   symtab_shndx_hdr = NULL;
   5177 
   5178   eh_addr_size = is_32bit_elf ? 4 : 8;
   5179   switch (elf_header.e_machine)
   5180     {
   5181     case EM_MIPS:
   5182     case EM_MIPS_RS3_LE:
   5183       /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
   5184 	 FDE addresses.  However, the ABI also has a semi-official ILP32
   5185 	 variant for which the normal FDE address size rules apply.
   5186 
   5187 	 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
   5188 	 section, where XX is the size of longs in bits.  Unfortunately,
   5189 	 earlier compilers provided no way of distinguishing ILP32 objects
   5190 	 from LP64 objects, so if there's any doubt, we should assume that
   5191 	 the official LP64 form is being used.  */
   5192       if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
   5193 	  && find_section (".gcc_compiled_long32") == NULL)
   5194 	eh_addr_size = 8;
   5195       break;
   5196 
   5197     case EM_H8_300:
   5198     case EM_H8_300H:
   5199       switch (elf_header.e_flags & EF_H8_MACH)
   5200 	{
   5201 	case E_H8_MACH_H8300:
   5202 	case E_H8_MACH_H8300HN:
   5203 	case E_H8_MACH_H8300SN:
   5204 	case E_H8_MACH_H8300SXN:
   5205 	  eh_addr_size = 2;
   5206 	  break;
   5207 	case E_H8_MACH_H8300H:
   5208 	case E_H8_MACH_H8300S:
   5209 	case E_H8_MACH_H8300SX:
   5210 	  eh_addr_size = 4;
   5211 	  break;
   5212 	}
   5213       break;
   5214 
   5215     case EM_M32C_OLD:
   5216     case EM_M32C:
   5217       switch (elf_header.e_flags & EF_M32C_CPU_MASK)
   5218 	{
   5219 	case EF_M32C_CPU_M16C:
   5220 	  eh_addr_size = 2;
   5221 	  break;
   5222 	}
   5223       break;
   5224     }
   5225 
   5226 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64)		\
   5227   do									\
   5228     {									\
   5229       bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64;	\
   5230       if (section->sh_entsize != expected_entsize)			\
   5231 	{								\
   5232 	  char buf[40];							\
   5233 	  sprintf_vma (buf, section->sh_entsize);			\
   5234 	  /* Note: coded this way so that there is a single string for  \
   5235 	     translation.  */ \
   5236 	  error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
   5237 	  error (_("(Using the expected size of %u for the rest of this dump)\n"), \
   5238 		   (unsigned) expected_entsize);			\
   5239 	  section->sh_entsize = expected_entsize;			\
   5240 	}								\
   5241     }									\
   5242   while (0)
   5243 
   5244 #define CHECK_ENTSIZE(section, i, type)					\
   5245   CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type),	    \
   5246 			sizeof (Elf64_External_##type))
   5247 
   5248   for (i = 0, section = section_headers;
   5249        i < elf_header.e_shnum;
   5250        i++, section++)
   5251     {
   5252       char * name = SECTION_NAME (section);
   5253 
   5254       if (section->sh_type == SHT_DYNSYM)
   5255 	{
   5256 	  if (dynamic_symbols != NULL)
   5257 	    {
   5258 	      error (_("File contains multiple dynamic symbol tables\n"));
   5259 	      continue;
   5260 	    }
   5261 
   5262 	  CHECK_ENTSIZE (section, i, Sym);
   5263 	  dynamic_symbols = GET_ELF_SYMBOLS (file, section, & num_dynamic_syms);
   5264 	}
   5265       else if (section->sh_type == SHT_STRTAB
   5266 	       && streq (name, ".dynstr"))
   5267 	{
   5268 	  if (dynamic_strings != NULL)
   5269 	    {
   5270 	      error (_("File contains multiple dynamic string tables\n"));
   5271 	      continue;
   5272 	    }
   5273 
   5274 	  dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
   5275                                                1, section->sh_size,
   5276                                                _("dynamic strings"));
   5277 	  dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
   5278 	}
   5279       else if (section->sh_type == SHT_SYMTAB_SHNDX)
   5280 	{
   5281 	  if (symtab_shndx_hdr != NULL)
   5282 	    {
   5283 	      error (_("File contains multiple symtab shndx tables\n"));
   5284 	      continue;
   5285 	    }
   5286 	  symtab_shndx_hdr = section;
   5287 	}
   5288       else if (section->sh_type == SHT_SYMTAB)
   5289 	CHECK_ENTSIZE (section, i, Sym);
   5290       else if (section->sh_type == SHT_GROUP)
   5291 	CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
   5292       else if (section->sh_type == SHT_REL)
   5293 	CHECK_ENTSIZE (section, i, Rel);
   5294       else if (section->sh_type == SHT_RELA)
   5295 	CHECK_ENTSIZE (section, i, Rela);
   5296       else if ((do_debugging || do_debug_info || do_debug_abbrevs
   5297 		|| do_debug_lines || do_debug_pubnames || do_debug_pubtypes
   5298 		|| do_debug_aranges || do_debug_frames || do_debug_macinfo
   5299 		|| do_debug_str || do_debug_loc || do_debug_ranges
   5300 		|| do_debug_addr || do_debug_cu_index)
   5301 	       && (const_strneq (name, ".debug_")
   5302                    || const_strneq (name, ".zdebug_")))
   5303 	{
   5304           if (name[1] == 'z')
   5305             name += sizeof (".zdebug_") - 1;
   5306           else
   5307             name += sizeof (".debug_") - 1;
   5308 
   5309 	  if (do_debugging
   5310 	      || (do_debug_info     && const_strneq (name, "info"))
   5311 	      || (do_debug_info     && const_strneq (name, "types"))
   5312 	      || (do_debug_abbrevs  && const_strneq (name, "abbrev"))
   5313 	      || (do_debug_lines    && strcmp (name, "line") == 0)
   5314 	      || (do_debug_lines    && const_strneq (name, "line."))
   5315 	      || (do_debug_pubnames && const_strneq (name, "pubnames"))
   5316 	      || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
   5317 	      || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
   5318 	      || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
   5319 	      || (do_debug_aranges  && const_strneq (name, "aranges"))
   5320 	      || (do_debug_ranges   && const_strneq (name, "ranges"))
   5321 	      || (do_debug_frames   && const_strneq (name, "frame"))
   5322 	      || (do_debug_macinfo  && const_strneq (name, "macinfo"))
   5323 	      || (do_debug_macinfo  && const_strneq (name, "macro"))
   5324 	      || (do_debug_str      && const_strneq (name, "str"))
   5325 	      || (do_debug_str      && const_strneq (name, "line_str"))
   5326 	      || (do_debug_loc      && const_strneq (name, "loc"))
   5327 	      || (do_debug_addr     && const_strneq (name, "addr"))
   5328 	      || (do_debug_cu_index && const_strneq (name, "cu_index"))
   5329 	      || (do_debug_cu_index && const_strneq (name, "tu_index"))
   5330 	      )
   5331 	    request_dump_bynumber (i, DEBUG_DUMP);
   5332 	}
   5333       /* Linkonce section to be combined with .debug_info at link time.  */
   5334       else if ((do_debugging || do_debug_info)
   5335 	       && const_strneq (name, ".gnu.linkonce.wi."))
   5336 	request_dump_bynumber (i, DEBUG_DUMP);
   5337       else if (do_debug_frames && streq (name, ".eh_frame"))
   5338 	request_dump_bynumber (i, DEBUG_DUMP);
   5339       else if (do_gdb_index && streq (name, ".gdb_index"))
   5340 	request_dump_bynumber (i, DEBUG_DUMP);
   5341       /* Trace sections for Itanium VMS.  */
   5342       else if ((do_debugging || do_trace_info || do_trace_abbrevs
   5343                 || do_trace_aranges)
   5344 	       && const_strneq (name, ".trace_"))
   5345 	{
   5346           name += sizeof (".trace_") - 1;
   5347 
   5348 	  if (do_debugging
   5349 	      || (do_trace_info     && streq (name, "info"))
   5350 	      || (do_trace_abbrevs  && streq (name, "abbrev"))
   5351 	      || (do_trace_aranges  && streq (name, "aranges"))
   5352 	      )
   5353 	    request_dump_bynumber (i, DEBUG_DUMP);
   5354 	}
   5355     }
   5356 
   5357   if (! do_sections)
   5358     return 1;
   5359 
   5360   if (elf_header.e_shnum > 1)
   5361     printf (_("\nSection Headers:\n"));
   5362   else
   5363     printf (_("\nSection Header:\n"));
   5364 
   5365   if (is_32bit_elf)
   5366     {
   5367       if (do_section_details)
   5368 	{
   5369 	  printf (_("  [Nr] Name\n"));
   5370 	  printf (_("       Type            Addr     Off    Size   ES   Lk Inf Al\n"));
   5371 	}
   5372       else
   5373 	printf
   5374 	  (_("  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al\n"));
   5375     }
   5376   else if (do_wide)
   5377     {
   5378       if (do_section_details)
   5379 	{
   5380 	  printf (_("  [Nr] Name\n"));
   5381 	  printf (_("       Type            Address          Off    Size   ES   Lk Inf Al\n"));
   5382 	}
   5383       else
   5384 	printf
   5385 	  (_("  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al\n"));
   5386     }
   5387   else
   5388     {
   5389       if (do_section_details)
   5390 	{
   5391 	  printf (_("  [Nr] Name\n"));
   5392 	  printf (_("       Type              Address          Offset            Link\n"));
   5393 	  printf (_("       Size              EntSize          Info              Align\n"));
   5394 	}
   5395       else
   5396 	{
   5397 	  printf (_("  [Nr] Name              Type             Address           Offset\n"));
   5398 	  printf (_("       Size              EntSize          Flags  Link  Info  Align\n"));
   5399 	}
   5400     }
   5401 
   5402   if (do_section_details)
   5403     printf (_("       Flags\n"));
   5404 
   5405   for (i = 0, section = section_headers;
   5406        i < elf_header.e_shnum;
   5407        i++, section++)
   5408     {
   5409       printf ("  [%2u] ", i);
   5410       if (do_section_details)
   5411 	printf ("%s\n      ", printable_section_name (section));
   5412       else
   5413 	print_symbol (-17, SECTION_NAME (section));
   5414 
   5415       printf (do_wide ? " %-15s " : " %-15.15s ",
   5416 	      get_section_type_name (section->sh_type));
   5417 
   5418       if (is_32bit_elf)
   5419 	{
   5420 	  const char * link_too_big = NULL;
   5421 
   5422 	  print_vma (section->sh_addr, LONG_HEX);
   5423 
   5424 	  printf ( " %6.6lx %6.6lx %2.2lx",
   5425 		   (unsigned long) section->sh_offset,
   5426 		   (unsigned long) section->sh_size,
   5427 		   (unsigned long) section->sh_entsize);
   5428 
   5429 	  if (do_section_details)
   5430 	    fputs ("  ", stdout);
   5431 	  else
   5432 	    printf (" %3s ", get_elf_section_flags (section->sh_flags));
   5433 
   5434 	  if (section->sh_link >= elf_header.e_shnum)
   5435 	    {
   5436 	      link_too_big = "";
   5437 	      /* The sh_link value is out of range.  Normally this indicates
   5438 		 an error but it can have special values in Solaris binaries.  */
   5439 	      switch (elf_header.e_machine)
   5440 		{
   5441 		case EM_386:
   5442 		case EM_486:
   5443 		case EM_X86_64:
   5444 		case EM_L1OM:
   5445 		case EM_K1OM:
   5446 		case EM_OLD_SPARCV9:
   5447 		case EM_SPARC32PLUS:
   5448 		case EM_SPARCV9:
   5449 		case EM_SPARC:
   5450 		  if (section->sh_link == (SHN_BEFORE & 0xffff))
   5451 		    link_too_big = "BEFORE";
   5452 		  else if (section->sh_link == (SHN_AFTER & 0xffff))
   5453 		    link_too_big = "AFTER";
   5454 		  break;
   5455 		default:
   5456 		  break;
   5457 		}
   5458 	    }
   5459 
   5460 	  if (do_section_details)
   5461 	    {
   5462 	      if (link_too_big != NULL && * link_too_big)
   5463 		printf ("<%s> ", link_too_big);
   5464 	      else
   5465 		printf ("%2u ", section->sh_link);
   5466 	      printf ("%3u %2lu\n", section->sh_info,
   5467 		      (unsigned long) section->sh_addralign);
   5468 	    }
   5469 	  else
   5470 	    printf ("%2u %3u %2lu\n",
   5471 		    section->sh_link,
   5472 		    section->sh_info,
   5473 		    (unsigned long) section->sh_addralign);
   5474 
   5475 	  if (link_too_big && ! * link_too_big)
   5476 	    warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
   5477 		  i, section->sh_link);
   5478 	}
   5479       else if (do_wide)
   5480 	{
   5481 	  print_vma (section->sh_addr, LONG_HEX);
   5482 
   5483 	  if ((long) section->sh_offset == section->sh_offset)
   5484 	    printf (" %6.6lx", (unsigned long) section->sh_offset);
   5485 	  else
   5486 	    {
   5487 	      putchar (' ');
   5488 	      print_vma (section->sh_offset, LONG_HEX);
   5489 	    }
   5490 
   5491 	  if ((unsigned long) section->sh_size == section->sh_size)
   5492 	    printf (" %6.6lx", (unsigned long) section->sh_size);
   5493 	  else
   5494 	    {
   5495 	      putchar (' ');
   5496 	      print_vma (section->sh_size, LONG_HEX);
   5497 	    }
   5498 
   5499 	  if ((unsigned long) section->sh_entsize == section->sh_entsize)
   5500 	    printf (" %2.2lx", (unsigned long) section->sh_entsize);
   5501 	  else
   5502 	    {
   5503 	      putchar (' ');
   5504 	      print_vma (section->sh_entsize, LONG_HEX);
   5505 	    }
   5506 
   5507 	  if (do_section_details)
   5508 	    fputs ("  ", stdout);
   5509 	  else
   5510 	    printf (" %3s ", get_elf_section_flags (section->sh_flags));
   5511 
   5512 	  printf ("%2u %3u ", section->sh_link, section->sh_info);
   5513 
   5514 	  if ((unsigned long) section->sh_addralign == section->sh_addralign)
   5515 	    printf ("%2lu\n", (unsigned long) section->sh_addralign);
   5516 	  else
   5517 	    {
   5518 	      print_vma (section->sh_addralign, DEC);
   5519 	      putchar ('\n');
   5520 	    }
   5521 	}
   5522       else if (do_section_details)
   5523 	{
   5524 	  printf ("       %-15.15s  ",
   5525 		  get_section_type_name (section->sh_type));
   5526 	  print_vma (section->sh_addr, LONG_HEX);
   5527 	  if ((long) section->sh_offset == section->sh_offset)
   5528 	    printf ("  %16.16lx", (unsigned long) section->sh_offset);
   5529 	  else
   5530 	    {
   5531 	      printf ("  ");
   5532 	      print_vma (section->sh_offset, LONG_HEX);
   5533 	    }
   5534 	  printf ("  %u\n       ", section->sh_link);
   5535 	  print_vma (section->sh_size, LONG_HEX);
   5536 	  putchar (' ');
   5537 	  print_vma (section->sh_entsize, LONG_HEX);
   5538 
   5539 	  printf ("  %-16u  %lu\n",
   5540 		  section->sh_info,
   5541 		  (unsigned long) section->sh_addralign);
   5542 	}
   5543       else
   5544 	{
   5545 	  putchar (' ');
   5546 	  print_vma (section->sh_addr, LONG_HEX);
   5547 	  if ((long) section->sh_offset == section->sh_offset)
   5548 	    printf ("  %8.8lx", (unsigned long) section->sh_offset);
   5549 	  else
   5550 	    {
   5551 	      printf ("  ");
   5552 	      print_vma (section->sh_offset, LONG_HEX);
   5553 	    }
   5554 	  printf ("\n       ");
   5555 	  print_vma (section->sh_size, LONG_HEX);
   5556 	  printf ("  ");
   5557 	  print_vma (section->sh_entsize, LONG_HEX);
   5558 
   5559 	  printf (" %3s ", get_elf_section_flags (section->sh_flags));
   5560 
   5561 	  printf ("     %2u   %3u     %lu\n",
   5562 		  section->sh_link,
   5563 		  section->sh_info,
   5564 		  (unsigned long) section->sh_addralign);
   5565 	}
   5566 
   5567       if (do_section_details)
   5568 	printf ("       %s\n", get_elf_section_flags (section->sh_flags));
   5569     }
   5570 
   5571   if (!do_section_details)
   5572     {
   5573       if (elf_header.e_machine == EM_X86_64
   5574 	  || elf_header.e_machine == EM_L1OM
   5575 	  || elf_header.e_machine == EM_K1OM)
   5576 	printf (_("Key to Flags:\n\
   5577   W (write), A (alloc), X (execute), M (merge), S (strings), l (large)\n\
   5578   I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n\
   5579   O (extra OS processing required) o (OS specific), p (processor specific)\n"));
   5580       else
   5581 	printf (_("Key to Flags:\n\
   5582   W (write), A (alloc), X (execute), M (merge), S (strings)\n\
   5583   I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n\
   5584   O (extra OS processing required) o (OS specific), p (processor specific)\n"));
   5585     }
   5586 
   5587   return 1;
   5588 }
   5589 
   5590 static const char *
   5591 get_group_flags (unsigned int flags)
   5592 {
   5593   static char buff[32];
   5594   switch (flags)
   5595     {
   5596     case 0:
   5597       return "";
   5598 
   5599     case GRP_COMDAT:
   5600       return "COMDAT ";
   5601 
   5602    default:
   5603       snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x] "), flags);
   5604       break;
   5605     }
   5606   return buff;
   5607 }
   5608 
   5609 static int
   5610 process_section_groups (FILE * file)
   5611 {
   5612   Elf_Internal_Shdr * section;
   5613   unsigned int i;
   5614   struct group * group;
   5615   Elf_Internal_Shdr * symtab_sec;
   5616   Elf_Internal_Shdr * strtab_sec;
   5617   Elf_Internal_Sym * symtab;
   5618   unsigned long num_syms;
   5619   char * strtab;
   5620   size_t strtab_size;
   5621 
   5622   /* Don't process section groups unless needed.  */
   5623   if (!do_unwind && !do_section_groups)
   5624     return 1;
   5625 
   5626   if (elf_header.e_shnum == 0)
   5627     {
   5628       if (do_section_groups)
   5629 	printf (_("\nThere are no sections to group in this file.\n"));
   5630 
   5631       return 1;
   5632     }
   5633 
   5634   if (section_headers == NULL)
   5635     {
   5636       error (_("Section headers are not available!\n"));
   5637       /* PR 13622: This can happen with a corrupt ELF header.  */
   5638       return 0;
   5639     }
   5640 
   5641   section_headers_groups = (struct group **) calloc (elf_header.e_shnum,
   5642                                                      sizeof (struct group *));
   5643 
   5644   if (section_headers_groups == NULL)
   5645     {
   5646       error (_("Out of memory reading %u section group headers\n"),
   5647 	     elf_header.e_shnum);
   5648       return 0;
   5649     }
   5650 
   5651   /* Scan the sections for the group section.  */
   5652   group_count = 0;
   5653   for (i = 0, section = section_headers;
   5654        i < elf_header.e_shnum;
   5655        i++, section++)
   5656     if (section->sh_type == SHT_GROUP)
   5657       group_count++;
   5658 
   5659   if (group_count == 0)
   5660     {
   5661       if (do_section_groups)
   5662 	printf (_("\nThere are no section groups in this file.\n"));
   5663 
   5664       return 1;
   5665     }
   5666 
   5667   section_groups = (struct group *) calloc (group_count, sizeof (struct group));
   5668 
   5669   if (section_groups == NULL)
   5670     {
   5671       error (_("Out of memory reading %lu groups\n"),
   5672 	     (unsigned long) group_count);
   5673       return 0;
   5674     }
   5675 
   5676   symtab_sec = NULL;
   5677   strtab_sec = NULL;
   5678   symtab = NULL;
   5679   num_syms = 0;
   5680   strtab = NULL;
   5681   strtab_size = 0;
   5682   for (i = 0, section = section_headers, group = section_groups;
   5683        i < elf_header.e_shnum;
   5684        i++, section++)
   5685     {
   5686       if (section->sh_type == SHT_GROUP)
   5687 	{
   5688 	  const char * name = printable_section_name (section);
   5689 	  const char * group_name;
   5690 	  unsigned char * start;
   5691 	  unsigned char * indices;
   5692 	  unsigned int entry, j, size;
   5693 	  Elf_Internal_Shdr * sec;
   5694 	  Elf_Internal_Sym * sym;
   5695 
   5696 	  /* Get the symbol table.  */
   5697 	  if (section->sh_link >= elf_header.e_shnum
   5698 	      || ((sec = section_headers + section->sh_link)->sh_type
   5699 		  != SHT_SYMTAB))
   5700 	    {
   5701 	      error (_("Bad sh_link in group section `%s'\n"), name);
   5702 	      continue;
   5703 	    }
   5704 
   5705 	  if (symtab_sec != sec)
   5706 	    {
   5707 	      symtab_sec = sec;
   5708 	      if (symtab)
   5709 		free (symtab);
   5710 	      symtab = GET_ELF_SYMBOLS (file, symtab_sec, & num_syms);
   5711 	    }
   5712 
   5713 	  if (symtab == NULL)
   5714 	    {
   5715 	      error (_("Corrupt header in group section `%s'\n"), name);
   5716 	      continue;
   5717 	    }
   5718 
   5719 	  if (section->sh_info >= num_syms)
   5720 	    {
   5721 	      error (_("Bad sh_info in group section `%s'\n"), name);
   5722 	      continue;
   5723 	    }
   5724 
   5725 	  sym = symtab + section->sh_info;
   5726 
   5727 	  if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
   5728 	    {
   5729 	      if (sym->st_shndx == 0
   5730 		  || sym->st_shndx >= elf_header.e_shnum)
   5731 		{
   5732 		  error (_("Bad sh_info in group section `%s'\n"), name);
   5733 		  continue;
   5734 		}
   5735 
   5736 	      group_name = SECTION_NAME (section_headers + sym->st_shndx);
   5737 	      strtab_sec = NULL;
   5738 	      if (strtab)
   5739 		free (strtab);
   5740 	      strtab = NULL;
   5741 	      strtab_size = 0;
   5742 	    }
   5743 	  else
   5744 	    {
   5745 	      /* Get the string table.  */
   5746 	      if (symtab_sec->sh_link >= elf_header.e_shnum)
   5747 		{
   5748 		  strtab_sec = NULL;
   5749 		  if (strtab)
   5750 		    free (strtab);
   5751 		  strtab = NULL;
   5752 		  strtab_size = 0;
   5753 		}
   5754 	      else if (strtab_sec
   5755 		       != (sec = section_headers + symtab_sec->sh_link))
   5756 		{
   5757 		  strtab_sec = sec;
   5758 		  if (strtab)
   5759 		    free (strtab);
   5760 
   5761 		  strtab = (char *) get_data (NULL, file, strtab_sec->sh_offset,
   5762 					      1, strtab_sec->sh_size,
   5763 					      _("string table"));
   5764 		  strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
   5765 		}
   5766 	      group_name = sym->st_name < strtab_size
   5767 		? strtab + sym->st_name : _("<corrupt>");
   5768 	    }
   5769 
   5770 	  start = (unsigned char *) get_data (NULL, file, section->sh_offset,
   5771                                               1, section->sh_size,
   5772                                               _("section data"));
   5773 	  if (start == NULL)
   5774 	    continue;
   5775 
   5776 	  indices = start;
   5777 	  size = (section->sh_size / section->sh_entsize) - 1;
   5778 	  entry = byte_get (indices, 4);
   5779 	  indices += 4;
   5780 
   5781 	  if (do_section_groups)
   5782 	    {
   5783 	      printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
   5784 		      get_group_flags (entry), i, name, group_name, size);
   5785 
   5786 	      printf (_("   [Index]    Name\n"));
   5787 	    }
   5788 
   5789 	  group->group_index = i;
   5790 
   5791 	  for (j = 0; j < size; j++)
   5792 	    {
   5793 	      struct group_list * g;
   5794 
   5795 	      entry = byte_get (indices, 4);
   5796 	      indices += 4;
   5797 
   5798 	      if (entry >= elf_header.e_shnum)
   5799 		{
   5800 		  error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
   5801 			 entry, i, elf_header.e_shnum - 1);
   5802 		  continue;
   5803 		}
   5804 
   5805 	      if (section_headers_groups [entry] != NULL)
   5806 		{
   5807 		  if (entry)
   5808 		    {
   5809 		      error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
   5810 			     entry, i,
   5811 			     section_headers_groups [entry]->group_index);
   5812 		      continue;
   5813 		    }
   5814 		  else
   5815 		    {
   5816 		      /* Intel C/C++ compiler may put section 0 in a
   5817 			 section group. We just warn it the first time
   5818 			 and ignore it afterwards.  */
   5819 		      static int warned = 0;
   5820 		      if (!warned)
   5821 			{
   5822 			  error (_("section 0 in group section [%5u]\n"),
   5823 				 section_headers_groups [entry]->group_index);
   5824 			  warned++;
   5825 			}
   5826 		    }
   5827 		}
   5828 
   5829 	      section_headers_groups [entry] = group;
   5830 
   5831 	      if (do_section_groups)
   5832 		{
   5833 		  sec = section_headers + entry;
   5834 		  printf ("   [%5u]   %s\n", entry, printable_section_name (sec));
   5835 		}
   5836 
   5837 	      g = (struct group_list *) xmalloc (sizeof (struct group_list));
   5838 	      g->section_index = entry;
   5839 	      g->next = group->root;
   5840 	      group->root = g;
   5841 	    }
   5842 
   5843 	  if (start)
   5844 	    free (start);
   5845 
   5846 	  group++;
   5847 	}
   5848     }
   5849 
   5850   if (symtab)
   5851     free (symtab);
   5852   if (strtab)
   5853     free (strtab);
   5854   return 1;
   5855 }
   5856 
   5857 /* Data used to display dynamic fixups.  */
   5858 
   5859 struct ia64_vms_dynfixup
   5860 {
   5861   bfd_vma needed_ident;		/* Library ident number.  */
   5862   bfd_vma needed;		/* Index in the dstrtab of the library name.  */
   5863   bfd_vma fixup_needed;		/* Index of the library.  */
   5864   bfd_vma fixup_rela_cnt;	/* Number of fixups.  */
   5865   bfd_vma fixup_rela_off;	/* Fixups offset in the dynamic segment.  */
   5866 };
   5867 
   5868 /* Data used to display dynamic relocations.  */
   5869 
   5870 struct ia64_vms_dynimgrela
   5871 {
   5872   bfd_vma img_rela_cnt;		/* Number of relocations.  */
   5873   bfd_vma img_rela_off;		/* Reloc offset in the dynamic segment.  */
   5874 };
   5875 
   5876 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
   5877    library).  */
   5878 
   5879 static void
   5880 dump_ia64_vms_dynamic_fixups (FILE *file, struct ia64_vms_dynfixup *fixup,
   5881                               const char *strtab, unsigned int strtab_sz)
   5882 {
   5883   Elf64_External_VMS_IMAGE_FIXUP *imfs;
   5884   long i;
   5885   const char *lib_name;
   5886 
   5887   imfs = get_data (NULL, file, dynamic_addr + fixup->fixup_rela_off,
   5888 		   1, fixup->fixup_rela_cnt * sizeof (*imfs),
   5889 		   _("dynamic section image fixups"));
   5890   if (!imfs)
   5891     return;
   5892 
   5893   if (fixup->needed < strtab_sz)
   5894     lib_name = strtab + fixup->needed;
   5895   else
   5896     {
   5897       warn ("corrupt library name index of 0x%lx found in dynamic entry",
   5898             (unsigned long) fixup->needed);
   5899       lib_name = "???";
   5900     }
   5901   printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
   5902 	  (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
   5903   printf
   5904     (_("Seg Offset           Type                             SymVec DataType\n"));
   5905 
   5906   for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
   5907     {
   5908       unsigned int type;
   5909       const char *rtype;
   5910 
   5911       printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
   5912       printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
   5913       type = BYTE_GET (imfs [i].type);
   5914       rtype = elf_ia64_reloc_type (type);
   5915       if (rtype == NULL)
   5916         printf (" 0x%08x                       ", type);
   5917       else
   5918         printf (" %-32s ", rtype);
   5919       printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
   5920       printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
   5921     }
   5922 
   5923   free (imfs);
   5924 }
   5925 
   5926 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image).  */
   5927 
   5928 static void
   5929 dump_ia64_vms_dynamic_relocs (FILE *file, struct ia64_vms_dynimgrela *imgrela)
   5930 {
   5931   Elf64_External_VMS_IMAGE_RELA *imrs;
   5932   long i;
   5933 
   5934   imrs = get_data (NULL, file, dynamic_addr + imgrela->img_rela_off,
   5935 		   1, imgrela->img_rela_cnt * sizeof (*imrs),
   5936 		   _("dynamic section image relocations"));
   5937   if (!imrs)
   5938     return;
   5939 
   5940   printf (_("\nImage relocs\n"));
   5941   printf
   5942     (_("Seg Offset   Type                            Addend            Seg Sym Off\n"));
   5943 
   5944   for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
   5945     {
   5946       unsigned int type;
   5947       const char *rtype;
   5948 
   5949       printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
   5950       printf ("%08" BFD_VMA_FMT "x ",
   5951               (bfd_vma) BYTE_GET (imrs [i].rela_offset));
   5952       type = BYTE_GET (imrs [i].type);
   5953       rtype = elf_ia64_reloc_type (type);
   5954       if (rtype == NULL)
   5955         printf ("0x%08x                      ", type);
   5956       else
   5957         printf ("%-31s ", rtype);
   5958       print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
   5959       printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
   5960       printf ("%08" BFD_VMA_FMT "x\n",
   5961               (bfd_vma) BYTE_GET (imrs [i].sym_offset));
   5962     }
   5963 
   5964   free (imrs);
   5965 }
   5966 
   5967 /* Display IA-64 OpenVMS dynamic relocations and fixups.  */
   5968 
   5969 static int
   5970 process_ia64_vms_dynamic_relocs (FILE *file)
   5971 {
   5972   struct ia64_vms_dynfixup fixup;
   5973   struct ia64_vms_dynimgrela imgrela;
   5974   Elf_Internal_Dyn *entry;
   5975   int res = 0;
   5976   bfd_vma strtab_off = 0;
   5977   bfd_vma strtab_sz = 0;
   5978   char *strtab = NULL;
   5979 
   5980   memset (&fixup, 0, sizeof (fixup));
   5981   memset (&imgrela, 0, sizeof (imgrela));
   5982 
   5983   /* Note: the order of the entries is specified by the OpenVMS specs.  */
   5984   for (entry = dynamic_section;
   5985        entry < dynamic_section + dynamic_nent;
   5986        entry++)
   5987     {
   5988       switch (entry->d_tag)
   5989         {
   5990         case DT_IA_64_VMS_STRTAB_OFFSET:
   5991           strtab_off = entry->d_un.d_val;
   5992           break;
   5993         case DT_STRSZ:
   5994           strtab_sz = entry->d_un.d_val;
   5995           if (strtab == NULL)
   5996             strtab = get_data (NULL, file, dynamic_addr + strtab_off,
   5997                                1, strtab_sz, _("dynamic string section"));
   5998           break;
   5999 
   6000         case DT_IA_64_VMS_NEEDED_IDENT:
   6001           fixup.needed_ident = entry->d_un.d_val;
   6002           break;
   6003         case DT_NEEDED:
   6004           fixup.needed = entry->d_un.d_val;
   6005           break;
   6006         case DT_IA_64_VMS_FIXUP_NEEDED:
   6007           fixup.fixup_needed = entry->d_un.d_val;
   6008           break;
   6009         case DT_IA_64_VMS_FIXUP_RELA_CNT:
   6010           fixup.fixup_rela_cnt = entry->d_un.d_val;
   6011           break;
   6012         case DT_IA_64_VMS_FIXUP_RELA_OFF:
   6013           fixup.fixup_rela_off = entry->d_un.d_val;
   6014           res++;
   6015           dump_ia64_vms_dynamic_fixups (file, &fixup, strtab, strtab_sz);
   6016           break;
   6017 
   6018         case DT_IA_64_VMS_IMG_RELA_CNT:
   6019 	  imgrela.img_rela_cnt = entry->d_un.d_val;
   6020           break;
   6021         case DT_IA_64_VMS_IMG_RELA_OFF:
   6022 	  imgrela.img_rela_off = entry->d_un.d_val;
   6023           res++;
   6024           dump_ia64_vms_dynamic_relocs (file, &imgrela);
   6025           break;
   6026 
   6027         default:
   6028           break;
   6029 	}
   6030     }
   6031 
   6032   if (strtab != NULL)
   6033     free (strtab);
   6034 
   6035   return res;
   6036 }
   6037 
   6038 static struct
   6039 {
   6040   const char * name;
   6041   int reloc;
   6042   int size;
   6043   int rela;
   6044 } dynamic_relocations [] =
   6045 {
   6046     { "REL", DT_REL, DT_RELSZ, FALSE },
   6047     { "RELA", DT_RELA, DT_RELASZ, TRUE },
   6048     { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
   6049 };
   6050 
   6051 /* Process the reloc section.  */
   6052 
   6053 static int
   6054 process_relocs (FILE * file)
   6055 {
   6056   unsigned long rel_size;
   6057   unsigned long rel_offset;
   6058 
   6059 
   6060   if (!do_reloc)
   6061     return 1;
   6062 
   6063   if (do_using_dynamic)
   6064     {
   6065       int is_rela;
   6066       const char * name;
   6067       int has_dynamic_reloc;
   6068       unsigned int i;
   6069 
   6070       has_dynamic_reloc = 0;
   6071 
   6072       for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
   6073 	{
   6074 	  is_rela = dynamic_relocations [i].rela;
   6075 	  name = dynamic_relocations [i].name;
   6076 	  rel_size = dynamic_info [dynamic_relocations [i].size];
   6077 	  rel_offset = dynamic_info [dynamic_relocations [i].reloc];
   6078 
   6079 	  has_dynamic_reloc |= rel_size;
   6080 
   6081 	  if (is_rela == UNKNOWN)
   6082 	    {
   6083 	      if (dynamic_relocations [i].reloc == DT_JMPREL)
   6084 		switch (dynamic_info[DT_PLTREL])
   6085 		  {
   6086 		  case DT_REL:
   6087 		    is_rela = FALSE;
   6088 		    break;
   6089 		  case DT_RELA:
   6090 		    is_rela = TRUE;
   6091 		    break;
   6092 		  }
   6093 	    }
   6094 
   6095 	  if (rel_size)
   6096 	    {
   6097 	      printf
   6098 		(_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
   6099 		 name, rel_offset, rel_size);
   6100 
   6101 	      dump_relocations (file,
   6102 				offset_from_vma (file, rel_offset, rel_size),
   6103 				rel_size,
   6104 				dynamic_symbols, num_dynamic_syms,
   6105 				dynamic_strings, dynamic_strings_length, is_rela);
   6106 	    }
   6107 	}
   6108 
   6109       if (is_ia64_vms ())
   6110         has_dynamic_reloc |= process_ia64_vms_dynamic_relocs (file);
   6111 
   6112       if (! has_dynamic_reloc)
   6113 	printf (_("\nThere are no dynamic relocations in this file.\n"));
   6114     }
   6115   else
   6116     {
   6117       Elf_Internal_Shdr * section;
   6118       unsigned long i;
   6119       int found = 0;
   6120 
   6121       for (i = 0, section = section_headers;
   6122 	   i < elf_header.e_shnum;
   6123 	   i++, section++)
   6124 	{
   6125 	  if (   section->sh_type != SHT_RELA
   6126 	      && section->sh_type != SHT_REL)
   6127 	    continue;
   6128 
   6129 	  rel_offset = section->sh_offset;
   6130 	  rel_size   = section->sh_size;
   6131 
   6132 	  if (rel_size)
   6133 	    {
   6134 	      Elf_Internal_Shdr * strsec;
   6135 	      int is_rela;
   6136 
   6137 	      printf (_("\nRelocation section "));
   6138 
   6139 	      if (string_table == NULL)
   6140 		printf ("%d", section->sh_name);
   6141 	      else
   6142 		printf ("'%s'", printable_section_name (section));
   6143 
   6144 	      printf (_(" at offset 0x%lx contains %lu entries:\n"),
   6145 		 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
   6146 
   6147 	      is_rela = section->sh_type == SHT_RELA;
   6148 
   6149 	      if (section->sh_link != 0
   6150 		  && section->sh_link < elf_header.e_shnum)
   6151 		{
   6152 		  Elf_Internal_Shdr * symsec;
   6153 		  Elf_Internal_Sym *  symtab;
   6154 		  unsigned long nsyms;
   6155 		  unsigned long strtablen = 0;
   6156 		  char * strtab = NULL;
   6157 
   6158 		  symsec = section_headers + section->sh_link;
   6159 		  if (symsec->sh_type != SHT_SYMTAB
   6160 		      && symsec->sh_type != SHT_DYNSYM)
   6161                     continue;
   6162 
   6163 		  symtab = GET_ELF_SYMBOLS (file, symsec, & nsyms);
   6164 
   6165 		  if (symtab == NULL)
   6166 		    continue;
   6167 
   6168 		  if (symsec->sh_link != 0
   6169 		      && symsec->sh_link < elf_header.e_shnum)
   6170 		    {
   6171 		      strsec = section_headers + symsec->sh_link;
   6172 
   6173 		      strtab = (char *) get_data (NULL, file, strsec->sh_offset,
   6174 						  1, strsec->sh_size,
   6175 						  _("string table"));
   6176 		      strtablen = strtab == NULL ? 0 : strsec->sh_size;
   6177 		    }
   6178 
   6179 		  dump_relocations (file, rel_offset, rel_size,
   6180 				    symtab, nsyms, strtab, strtablen, is_rela);
   6181 		  if (strtab)
   6182 		    free (strtab);
   6183 		  free (symtab);
   6184 		}
   6185 	      else
   6186 		dump_relocations (file, rel_offset, rel_size,
   6187 				  NULL, 0, NULL, 0, is_rela);
   6188 
   6189 	      found = 1;
   6190 	    }
   6191 	}
   6192 
   6193       if (! found)
   6194 	printf (_("\nThere are no relocations in this file.\n"));
   6195     }
   6196 
   6197   return 1;
   6198 }
   6199 
   6200 /* Process the unwind section.  */
   6201 
   6202 #include "unwind-ia64.h"
   6203 
   6204 /* An absolute address consists of a section and an offset.  If the
   6205    section is NULL, the offset itself is the address, otherwise, the
   6206    address equals to LOAD_ADDRESS(section) + offset.  */
   6207 
   6208 struct absaddr
   6209   {
   6210     unsigned short section;
   6211     bfd_vma offset;
   6212   };
   6213 
   6214 #define ABSADDR(a) \
   6215   ((a).section \
   6216    ? section_headers [(a).section].sh_addr + (a).offset \
   6217    : (a).offset)
   6218 
   6219 struct ia64_unw_table_entry
   6220   {
   6221     struct absaddr start;
   6222     struct absaddr end;
   6223     struct absaddr info;
   6224   };
   6225 
   6226 struct ia64_unw_aux_info
   6227   {
   6228 
   6229     struct ia64_unw_table_entry *table;	/* Unwind table.  */
   6230     unsigned long table_len;	/* Length of unwind table.  */
   6231     unsigned char * info;	/* Unwind info.  */
   6232     unsigned long info_size;	/* Size of unwind info.  */
   6233     bfd_vma info_addr;		/* starting address of unwind info.  */
   6234     bfd_vma seg_base;		/* Starting address of segment.  */
   6235     Elf_Internal_Sym * symtab;	/* The symbol table.  */
   6236     unsigned long nsyms;	/* Number of symbols.  */
   6237     char * strtab;		/* The string table.  */
   6238     unsigned long strtab_size;	/* Size of string table.  */
   6239   };
   6240 
   6241 static void
   6242 find_symbol_for_address (Elf_Internal_Sym * symtab,
   6243 			 unsigned long nsyms,
   6244 			 const char * strtab,
   6245 			 unsigned long strtab_size,
   6246 			 struct absaddr addr,
   6247 			 const char ** symname,
   6248 			 bfd_vma * offset)
   6249 {
   6250   bfd_vma dist = 0x100000;
   6251   Elf_Internal_Sym * sym;
   6252   Elf_Internal_Sym * best = NULL;
   6253   unsigned long i;
   6254 
   6255   REMOVE_ARCH_BITS (addr.offset);
   6256 
   6257   for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
   6258     {
   6259       bfd_vma value = sym->st_value;
   6260 
   6261       REMOVE_ARCH_BITS (value);
   6262 
   6263       if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
   6264 	  && sym->st_name != 0
   6265 	  && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
   6266 	  && addr.offset >= value
   6267 	  && addr.offset - value < dist)
   6268 	{
   6269 	  best = sym;
   6270 	  dist = addr.offset - value;
   6271 	  if (!dist)
   6272 	    break;
   6273 	}
   6274     }
   6275 
   6276   if (best)
   6277     {
   6278       *symname = (best->st_name >= strtab_size
   6279 		  ? _("<corrupt>") : strtab + best->st_name);
   6280       *offset = dist;
   6281       return;
   6282     }
   6283 
   6284   *symname = NULL;
   6285   *offset = addr.offset;
   6286 }
   6287 
   6288 static void
   6289 dump_ia64_unwind (struct ia64_unw_aux_info * aux)
   6290 {
   6291   struct ia64_unw_table_entry * tp;
   6292   int in_body;
   6293 
   6294   for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
   6295     {
   6296       bfd_vma stamp;
   6297       bfd_vma offset;
   6298       const unsigned char * dp;
   6299       const unsigned char * head;
   6300       const char * procname;
   6301 
   6302       find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
   6303 			       aux->strtab_size, tp->start, &procname, &offset);
   6304 
   6305       fputs ("\n<", stdout);
   6306 
   6307       if (procname)
   6308 	{
   6309 	  fputs (procname, stdout);
   6310 
   6311 	  if (offset)
   6312 	    printf ("+%lx", (unsigned long) offset);
   6313 	}
   6314 
   6315       fputs (">: [", stdout);
   6316       print_vma (tp->start.offset, PREFIX_HEX);
   6317       fputc ('-', stdout);
   6318       print_vma (tp->end.offset, PREFIX_HEX);
   6319       printf ("], info at +0x%lx\n",
   6320 	      (unsigned long) (tp->info.offset - aux->seg_base));
   6321 
   6322       head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
   6323       stamp = byte_get ((unsigned char *) head, sizeof (stamp));
   6324 
   6325       printf ("  v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
   6326 	      (unsigned) UNW_VER (stamp),
   6327 	      (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
   6328 	      UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
   6329 	      UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
   6330 	      (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
   6331 
   6332       if (UNW_VER (stamp) != 1)
   6333 	{
   6334 	  printf (_("\tUnknown version.\n"));
   6335 	  continue;
   6336 	}
   6337 
   6338       in_body = 0;
   6339       for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp);)
   6340 	dp = unw_decode (dp, in_body, & in_body);
   6341     }
   6342 }
   6343 
   6344 static int
   6345 slurp_ia64_unwind_table (FILE * file,
   6346 			 struct ia64_unw_aux_info * aux,
   6347 			 Elf_Internal_Shdr * sec)
   6348 {
   6349   unsigned long size, nrelas, i;
   6350   Elf_Internal_Phdr * seg;
   6351   struct ia64_unw_table_entry * tep;
   6352   Elf_Internal_Shdr * relsec;
   6353   Elf_Internal_Rela * rela;
   6354   Elf_Internal_Rela * rp;
   6355   unsigned char * table;
   6356   unsigned char * tp;
   6357   Elf_Internal_Sym * sym;
   6358   const char * relname;
   6359 
   6360   /* First, find the starting address of the segment that includes
   6361      this section: */
   6362 
   6363   if (elf_header.e_phnum)
   6364     {
   6365       if (! get_program_headers (file))
   6366 	  return 0;
   6367 
   6368       for (seg = program_headers;
   6369 	   seg < program_headers + elf_header.e_phnum;
   6370 	   ++seg)
   6371 	{
   6372 	  if (seg->p_type != PT_LOAD)
   6373 	    continue;
   6374 
   6375 	  if (sec->sh_addr >= seg->p_vaddr
   6376 	      && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
   6377 	    {
   6378 	      aux->seg_base = seg->p_vaddr;
   6379 	      break;
   6380 	    }
   6381 	}
   6382     }
   6383 
   6384   /* Second, build the unwind table from the contents of the unwind section:  */
   6385   size = sec->sh_size;
   6386   table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
   6387                                       _("unwind table"));
   6388   if (!table)
   6389     return 0;
   6390 
   6391   aux->table = (struct ia64_unw_table_entry *)
   6392       xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0]));
   6393   tep = aux->table;
   6394   for (tp = table; tp < table + size; ++tep)
   6395     {
   6396       tep->start.section = SHN_UNDEF;
   6397       tep->end.section   = SHN_UNDEF;
   6398       tep->info.section  = SHN_UNDEF;
   6399       tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
   6400       tep->end.offset   = byte_get (tp, eh_addr_size); tp += eh_addr_size;
   6401       tep->info.offset  = byte_get (tp, eh_addr_size); tp += eh_addr_size;
   6402       tep->start.offset += aux->seg_base;
   6403       tep->end.offset   += aux->seg_base;
   6404       tep->info.offset  += aux->seg_base;
   6405     }
   6406   free (table);
   6407 
   6408   /* Third, apply any relocations to the unwind table:  */
   6409   for (relsec = section_headers;
   6410        relsec < section_headers + elf_header.e_shnum;
   6411        ++relsec)
   6412     {
   6413       if (relsec->sh_type != SHT_RELA
   6414 	  || relsec->sh_info >= elf_header.e_shnum
   6415 	  || section_headers + relsec->sh_info != sec)
   6416 	continue;
   6417 
   6418       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
   6419 			      & rela, & nrelas))
   6420 	return 0;
   6421 
   6422       for (rp = rela; rp < rela + nrelas; ++rp)
   6423 	{
   6424 	  relname = elf_ia64_reloc_type (get_reloc_type (rp->r_info));
   6425 	  sym = aux->symtab + get_reloc_symindex (rp->r_info);
   6426 
   6427 	  if (! const_strneq (relname, "R_IA64_SEGREL"))
   6428 	    {
   6429 	      warn (_("Skipping unexpected relocation type %s\n"), relname);
   6430 	      continue;
   6431 	    }
   6432 
   6433 	  i = rp->r_offset / (3 * eh_addr_size);
   6434 
   6435 	  switch (rp->r_offset/eh_addr_size % 3)
   6436 	    {
   6437 	    case 0:
   6438 	      aux->table[i].start.section = sym->st_shndx;
   6439 	      aux->table[i].start.offset  = rp->r_addend + sym->st_value;
   6440 	      break;
   6441 	    case 1:
   6442 	      aux->table[i].end.section   = sym->st_shndx;
   6443 	      aux->table[i].end.offset    = rp->r_addend + sym->st_value;
   6444 	      break;
   6445 	    case 2:
   6446 	      aux->table[i].info.section  = sym->st_shndx;
   6447 	      aux->table[i].info.offset   = rp->r_addend + sym->st_value;
   6448 	      break;
   6449 	    default:
   6450 	      break;
   6451 	    }
   6452 	}
   6453 
   6454       free (rela);
   6455     }
   6456 
   6457   aux->table_len = size / (3 * eh_addr_size);
   6458   return 1;
   6459 }
   6460 
   6461 static void
   6462 ia64_process_unwind (FILE * file)
   6463 {
   6464   Elf_Internal_Shdr * sec;
   6465   Elf_Internal_Shdr * unwsec = NULL;
   6466   Elf_Internal_Shdr * strsec;
   6467   unsigned long i, unwcount = 0, unwstart = 0;
   6468   struct ia64_unw_aux_info aux;
   6469 
   6470   memset (& aux, 0, sizeof (aux));
   6471 
   6472   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   6473     {
   6474       if (sec->sh_type == SHT_SYMTAB
   6475 	  && sec->sh_link < elf_header.e_shnum)
   6476 	{
   6477 	  aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
   6478 
   6479 	  strsec = section_headers + sec->sh_link;
   6480 	  if (aux.strtab != NULL)
   6481 	    {
   6482 	      error (_("Multiple auxillary string tables encountered\n"));
   6483 	      free (aux.strtab);
   6484 	    }
   6485 	  aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
   6486                                           1, strsec->sh_size,
   6487                                           _("string table"));
   6488 	  aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
   6489 	}
   6490       else if (sec->sh_type == SHT_IA_64_UNWIND)
   6491 	unwcount++;
   6492     }
   6493 
   6494   if (!unwcount)
   6495     printf (_("\nThere are no unwind sections in this file.\n"));
   6496 
   6497   while (unwcount-- > 0)
   6498     {
   6499       char * suffix;
   6500       size_t len, len2;
   6501 
   6502       for (i = unwstart, sec = section_headers + unwstart, unwsec = NULL;
   6503 	   i < elf_header.e_shnum; ++i, ++sec)
   6504 	if (sec->sh_type == SHT_IA_64_UNWIND)
   6505 	  {
   6506 	    unwsec = sec;
   6507 	    break;
   6508 	  }
   6509       /* We have already counted the number of SHT_IA64_UNWIND
   6510 	 sections so the loop above should never fail.  */
   6511       assert (unwsec != NULL);
   6512 
   6513       unwstart = i + 1;
   6514       len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
   6515 
   6516       if ((unwsec->sh_flags & SHF_GROUP) != 0)
   6517 	{
   6518 	  /* We need to find which section group it is in.  */
   6519 	  struct group_list * g;
   6520 
   6521 	  if (section_headers_groups == NULL
   6522 	      || section_headers_groups [i] == NULL)
   6523 	    i = elf_header.e_shnum;
   6524 	  else
   6525 	    {
   6526 	      g = section_headers_groups [i]->root;
   6527 
   6528 	      for (; g != NULL; g = g->next)
   6529 		{
   6530 		  sec = section_headers + g->section_index;
   6531 
   6532 		  if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
   6533 		    break;
   6534 		}
   6535 
   6536 	      if (g == NULL)
   6537 		i = elf_header.e_shnum;
   6538 	    }
   6539 	}
   6540       else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
   6541 	{
   6542 	  /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO.  */
   6543 	  len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
   6544 	  suffix = SECTION_NAME (unwsec) + len;
   6545 	  for (i = 0, sec = section_headers; i < elf_header.e_shnum;
   6546 	       ++i, ++sec)
   6547 	    if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
   6548 		&& streq (SECTION_NAME (sec) + len2, suffix))
   6549 	      break;
   6550 	}
   6551       else
   6552 	{
   6553 	  /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
   6554 	     .IA_64.unwind or BAR -> .IA_64.unwind_info.  */
   6555 	  len = sizeof (ELF_STRING_ia64_unwind) - 1;
   6556 	  len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
   6557 	  suffix = "";
   6558 	  if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
   6559 	    suffix = SECTION_NAME (unwsec) + len;
   6560 	  for (i = 0, sec = section_headers; i < elf_header.e_shnum;
   6561 	       ++i, ++sec)
   6562 	    if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
   6563 		&& streq (SECTION_NAME (sec) + len2, suffix))
   6564 	      break;
   6565 	}
   6566 
   6567       if (i == elf_header.e_shnum)
   6568 	{
   6569 	  printf (_("\nCould not find unwind info section for "));
   6570 
   6571 	  if (string_table == NULL)
   6572 	    printf ("%d", unwsec->sh_name);
   6573 	  else
   6574 	    printf ("'%s'", printable_section_name (unwsec));
   6575 	}
   6576       else
   6577 	{
   6578 	  aux.info_addr = sec->sh_addr;
   6579 	  aux.info = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1,
   6580 						 sec->sh_size,
   6581 						 _("unwind info"));
   6582 	  aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
   6583 
   6584 	  printf (_("\nUnwind section "));
   6585 
   6586 	  if (string_table == NULL)
   6587 	    printf ("%d", unwsec->sh_name);
   6588 	  else
   6589 	    printf ("'%s'", printable_section_name (unwsec));
   6590 
   6591 	  printf (_(" at offset 0x%lx contains %lu entries:\n"),
   6592 		  (unsigned long) unwsec->sh_offset,
   6593 		  (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
   6594 
   6595 	  (void) slurp_ia64_unwind_table (file, & aux, unwsec);
   6596 
   6597 	  if (aux.table_len > 0)
   6598 	    dump_ia64_unwind (& aux);
   6599 
   6600 	  if (aux.table)
   6601 	    free ((char *) aux.table);
   6602 	  if (aux.info)
   6603 	    free ((char *) aux.info);
   6604 	  aux.table = NULL;
   6605 	  aux.info = NULL;
   6606 	}
   6607     }
   6608 
   6609   if (aux.symtab)
   6610     free (aux.symtab);
   6611   if (aux.strtab)
   6612     free ((char *) aux.strtab);
   6613 }
   6614 
   6615 struct hppa_unw_table_entry
   6616   {
   6617     struct absaddr start;
   6618     struct absaddr end;
   6619     unsigned int Cannot_unwind:1;			/* 0 */
   6620     unsigned int Millicode:1;			/* 1 */
   6621     unsigned int Millicode_save_sr0:1;		/* 2 */
   6622     unsigned int Region_description:2;		/* 3..4 */
   6623     unsigned int reserved1:1;			/* 5 */
   6624     unsigned int Entry_SR:1;			/* 6 */
   6625     unsigned int Entry_FR:4;     /* number saved */	/* 7..10 */
   6626     unsigned int Entry_GR:5;     /* number saved */	/* 11..15 */
   6627     unsigned int Args_stored:1;			/* 16 */
   6628     unsigned int Variable_Frame:1;			/* 17 */
   6629     unsigned int Separate_Package_Body:1;		/* 18 */
   6630     unsigned int Frame_Extension_Millicode:1;	/* 19 */
   6631     unsigned int Stack_Overflow_Check:1;		/* 20 */
   6632     unsigned int Two_Instruction_SP_Increment:1;	/* 21 */
   6633     unsigned int Ada_Region:1;			/* 22 */
   6634     unsigned int cxx_info:1;			/* 23 */
   6635     unsigned int cxx_try_catch:1;			/* 24 */
   6636     unsigned int sched_entry_seq:1;			/* 25 */
   6637     unsigned int reserved2:1;			/* 26 */
   6638     unsigned int Save_SP:1;				/* 27 */
   6639     unsigned int Save_RP:1;				/* 28 */
   6640     unsigned int Save_MRP_in_frame:1;		/* 29 */
   6641     unsigned int extn_ptr_defined:1;		/* 30 */
   6642     unsigned int Cleanup_defined:1;			/* 31 */
   6643 
   6644     unsigned int MPE_XL_interrupt_marker:1;		/* 0 */
   6645     unsigned int HP_UX_interrupt_marker:1;		/* 1 */
   6646     unsigned int Large_frame:1;			/* 2 */
   6647     unsigned int Pseudo_SP_Set:1;			/* 3 */
   6648     unsigned int reserved4:1;			/* 4 */
   6649     unsigned int Total_frame_size:27;		/* 5..31 */
   6650   };
   6651 
   6652 struct hppa_unw_aux_info
   6653   {
   6654     struct hppa_unw_table_entry *table;	/* Unwind table.  */
   6655     unsigned long table_len;	/* Length of unwind table.  */
   6656     bfd_vma seg_base;		/* Starting address of segment.  */
   6657     Elf_Internal_Sym * symtab;	/* The symbol table.  */
   6658     unsigned long nsyms;	/* Number of symbols.  */
   6659     char * strtab;		/* The string table.  */
   6660     unsigned long strtab_size;	/* Size of string table.  */
   6661   };
   6662 
   6663 static void
   6664 dump_hppa_unwind (struct hppa_unw_aux_info * aux)
   6665 {
   6666   struct hppa_unw_table_entry * tp;
   6667 
   6668   for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
   6669     {
   6670       bfd_vma offset;
   6671       const char * procname;
   6672 
   6673       find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
   6674 			       aux->strtab_size, tp->start, &procname,
   6675 			       &offset);
   6676 
   6677       fputs ("\n<", stdout);
   6678 
   6679       if (procname)
   6680 	{
   6681 	  fputs (procname, stdout);
   6682 
   6683 	  if (offset)
   6684 	    printf ("+%lx", (unsigned long) offset);
   6685 	}
   6686 
   6687       fputs (">: [", stdout);
   6688       print_vma (tp->start.offset, PREFIX_HEX);
   6689       fputc ('-', stdout);
   6690       print_vma (tp->end.offset, PREFIX_HEX);
   6691       printf ("]\n\t");
   6692 
   6693 #define PF(_m) if (tp->_m) printf (#_m " ");
   6694 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
   6695       PF(Cannot_unwind);
   6696       PF(Millicode);
   6697       PF(Millicode_save_sr0);
   6698       /* PV(Region_description);  */
   6699       PF(Entry_SR);
   6700       PV(Entry_FR);
   6701       PV(Entry_GR);
   6702       PF(Args_stored);
   6703       PF(Variable_Frame);
   6704       PF(Separate_Package_Body);
   6705       PF(Frame_Extension_Millicode);
   6706       PF(Stack_Overflow_Check);
   6707       PF(Two_Instruction_SP_Increment);
   6708       PF(Ada_Region);
   6709       PF(cxx_info);
   6710       PF(cxx_try_catch);
   6711       PF(sched_entry_seq);
   6712       PF(Save_SP);
   6713       PF(Save_RP);
   6714       PF(Save_MRP_in_frame);
   6715       PF(extn_ptr_defined);
   6716       PF(Cleanup_defined);
   6717       PF(MPE_XL_interrupt_marker);
   6718       PF(HP_UX_interrupt_marker);
   6719       PF(Large_frame);
   6720       PF(Pseudo_SP_Set);
   6721       PV(Total_frame_size);
   6722 #undef PF
   6723 #undef PV
   6724     }
   6725 
   6726   printf ("\n");
   6727 }
   6728 
   6729 static int
   6730 slurp_hppa_unwind_table (FILE * file,
   6731 			 struct hppa_unw_aux_info * aux,
   6732 			 Elf_Internal_Shdr * sec)
   6733 {
   6734   unsigned long size, unw_ent_size, nentries, nrelas, i;
   6735   Elf_Internal_Phdr * seg;
   6736   struct hppa_unw_table_entry * tep;
   6737   Elf_Internal_Shdr * relsec;
   6738   Elf_Internal_Rela * rela;
   6739   Elf_Internal_Rela * rp;
   6740   unsigned char * table;
   6741   unsigned char * tp;
   6742   Elf_Internal_Sym * sym;
   6743   const char * relname;
   6744 
   6745   /* First, find the starting address of the segment that includes
   6746      this section.  */
   6747 
   6748   if (elf_header.e_phnum)
   6749     {
   6750       if (! get_program_headers (file))
   6751 	return 0;
   6752 
   6753       for (seg = program_headers;
   6754 	   seg < program_headers + elf_header.e_phnum;
   6755 	   ++seg)
   6756 	{
   6757 	  if (seg->p_type != PT_LOAD)
   6758 	    continue;
   6759 
   6760 	  if (sec->sh_addr >= seg->p_vaddr
   6761 	      && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
   6762 	    {
   6763 	      aux->seg_base = seg->p_vaddr;
   6764 	      break;
   6765 	    }
   6766 	}
   6767     }
   6768 
   6769   /* Second, build the unwind table from the contents of the unwind
   6770      section.  */
   6771   size = sec->sh_size;
   6772   table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
   6773                                       _("unwind table"));
   6774   if (!table)
   6775     return 0;
   6776 
   6777   unw_ent_size = 16;
   6778   nentries = size / unw_ent_size;
   6779   size = unw_ent_size * nentries;
   6780 
   6781   tep = aux->table = (struct hppa_unw_table_entry *)
   6782       xcmalloc (nentries, sizeof (aux->table[0]));
   6783 
   6784   for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
   6785     {
   6786       unsigned int tmp1, tmp2;
   6787 
   6788       tep->start.section = SHN_UNDEF;
   6789       tep->end.section   = SHN_UNDEF;
   6790 
   6791       tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
   6792       tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
   6793       tmp1 = byte_get ((unsigned char *) tp + 8, 4);
   6794       tmp2 = byte_get ((unsigned char *) tp + 12, 4);
   6795 
   6796       tep->start.offset += aux->seg_base;
   6797       tep->end.offset   += aux->seg_base;
   6798 
   6799       tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
   6800       tep->Millicode = (tmp1 >> 30) & 0x1;
   6801       tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
   6802       tep->Region_description = (tmp1 >> 27) & 0x3;
   6803       tep->reserved1 = (tmp1 >> 26) & 0x1;
   6804       tep->Entry_SR = (tmp1 >> 25) & 0x1;
   6805       tep->Entry_FR = (tmp1 >> 21) & 0xf;
   6806       tep->Entry_GR = (tmp1 >> 16) & 0x1f;
   6807       tep->Args_stored = (tmp1 >> 15) & 0x1;
   6808       tep->Variable_Frame = (tmp1 >> 14) & 0x1;
   6809       tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
   6810       tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
   6811       tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
   6812       tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
   6813       tep->Ada_Region = (tmp1 >> 9) & 0x1;
   6814       tep->cxx_info = (tmp1 >> 8) & 0x1;
   6815       tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
   6816       tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
   6817       tep->reserved2 = (tmp1 >> 5) & 0x1;
   6818       tep->Save_SP = (tmp1 >> 4) & 0x1;
   6819       tep->Save_RP = (tmp1 >> 3) & 0x1;
   6820       tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
   6821       tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
   6822       tep->Cleanup_defined = tmp1 & 0x1;
   6823 
   6824       tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
   6825       tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
   6826       tep->Large_frame = (tmp2 >> 29) & 0x1;
   6827       tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
   6828       tep->reserved4 = (tmp2 >> 27) & 0x1;
   6829       tep->Total_frame_size = tmp2 & 0x7ffffff;
   6830     }
   6831   free (table);
   6832 
   6833   /* Third, apply any relocations to the unwind table.  */
   6834   for (relsec = section_headers;
   6835        relsec < section_headers + elf_header.e_shnum;
   6836        ++relsec)
   6837     {
   6838       if (relsec->sh_type != SHT_RELA
   6839 	  || relsec->sh_info >= elf_header.e_shnum
   6840 	  || section_headers + relsec->sh_info != sec)
   6841 	continue;
   6842 
   6843       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
   6844 			      & rela, & nrelas))
   6845 	return 0;
   6846 
   6847       for (rp = rela; rp < rela + nrelas; ++rp)
   6848 	{
   6849 	  relname = elf_hppa_reloc_type (get_reloc_type (rp->r_info));
   6850 	  sym = aux->symtab + get_reloc_symindex (rp->r_info);
   6851 
   6852 	  /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64.  */
   6853 	  if (! const_strneq (relname, "R_PARISC_SEGREL"))
   6854 	    {
   6855 	      warn (_("Skipping unexpected relocation type %s\n"), relname);
   6856 	      continue;
   6857 	    }
   6858 
   6859 	  i = rp->r_offset / unw_ent_size;
   6860 
   6861 	  switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
   6862 	    {
   6863 	    case 0:
   6864 	      aux->table[i].start.section = sym->st_shndx;
   6865 	      aux->table[i].start.offset  = sym->st_value + rp->r_addend;
   6866 	      break;
   6867 	    case 1:
   6868 	      aux->table[i].end.section   = sym->st_shndx;
   6869 	      aux->table[i].end.offset    = sym->st_value + rp->r_addend;
   6870 	      break;
   6871 	    default:
   6872 	      break;
   6873 	    }
   6874 	}
   6875 
   6876       free (rela);
   6877     }
   6878 
   6879   aux->table_len = nentries;
   6880 
   6881   return 1;
   6882 }
   6883 
   6884 static void
   6885 hppa_process_unwind (FILE * file)
   6886 {
   6887   struct hppa_unw_aux_info aux;
   6888   Elf_Internal_Shdr * unwsec = NULL;
   6889   Elf_Internal_Shdr * strsec;
   6890   Elf_Internal_Shdr * sec;
   6891   unsigned long i;
   6892 
   6893   if (string_table == NULL)
   6894     return;
   6895 
   6896   memset (& aux, 0, sizeof (aux));
   6897 
   6898   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   6899     {
   6900       if (sec->sh_type == SHT_SYMTAB
   6901 	  && sec->sh_link < elf_header.e_shnum)
   6902 	{
   6903 	  aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
   6904 
   6905 	  strsec = section_headers + sec->sh_link;
   6906 	  if (aux.strtab != NULL)
   6907 	    {
   6908 	      error (_("Multiple auxillary string tables encountered\n"));
   6909 	      free (aux.strtab);
   6910 	    }
   6911 	  aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
   6912                                           1, strsec->sh_size,
   6913                                           _("string table"));
   6914 	  aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
   6915 	}
   6916       else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
   6917 	unwsec = sec;
   6918     }
   6919 
   6920   if (!unwsec)
   6921     printf (_("\nThere are no unwind sections in this file.\n"));
   6922 
   6923   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   6924     {
   6925       if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
   6926 	{
   6927 	  printf (_("\nUnwind section '%s' at offset 0x%lx contains %lu entries:\n"),
   6928 		  printable_section_name (sec),
   6929 		  (unsigned long) sec->sh_offset,
   6930 		  (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
   6931 
   6932           slurp_hppa_unwind_table (file, &aux, sec);
   6933 	  if (aux.table_len > 0)
   6934 	    dump_hppa_unwind (&aux);
   6935 
   6936 	  if (aux.table)
   6937 	    free ((char *) aux.table);
   6938 	  aux.table = NULL;
   6939 	}
   6940     }
   6941 
   6942   if (aux.symtab)
   6943     free (aux.symtab);
   6944   if (aux.strtab)
   6945     free ((char *) aux.strtab);
   6946 }
   6947 
   6948 struct arm_section
   6949 {
   6950   unsigned char *      data;		/* The unwind data.  */
   6951   Elf_Internal_Shdr *  sec;		/* The cached unwind section header.  */
   6952   Elf_Internal_Rela *  rela;		/* The cached relocations for this section.  */
   6953   unsigned long        nrelas;		/* The number of relocations.  */
   6954   unsigned int         rel_type;	/* REL or RELA ?  */
   6955   Elf_Internal_Rela *  next_rela;	/* Cyclic pointer to the next reloc to process.  */
   6956 };
   6957 
   6958 struct arm_unw_aux_info
   6959 {
   6960   FILE *              file;		/* The file containing the unwind sections.  */
   6961   Elf_Internal_Sym *  symtab;		/* The file's symbol table.  */
   6962   unsigned long       nsyms;		/* Number of symbols.  */
   6963   char *              strtab;		/* The file's string table.  */
   6964   unsigned long       strtab_size;	/* Size of string table.  */
   6965 };
   6966 
   6967 static const char *
   6968 arm_print_vma_and_name (struct arm_unw_aux_info *aux,
   6969 			bfd_vma fn, struct absaddr addr)
   6970 {
   6971   const char *procname;
   6972   bfd_vma sym_offset;
   6973 
   6974   if (addr.section == SHN_UNDEF)
   6975     addr.offset = fn;
   6976 
   6977   find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
   6978 			   aux->strtab_size, addr, &procname,
   6979 			   &sym_offset);
   6980 
   6981   print_vma (fn, PREFIX_HEX);
   6982 
   6983   if (procname)
   6984     {
   6985       fputs (" <", stdout);
   6986       fputs (procname, stdout);
   6987 
   6988       if (sym_offset)
   6989 	printf ("+0x%lx", (unsigned long) sym_offset);
   6990       fputc ('>', stdout);
   6991     }
   6992 
   6993   return procname;
   6994 }
   6995 
   6996 static void
   6997 arm_free_section (struct arm_section *arm_sec)
   6998 {
   6999   if (arm_sec->data != NULL)
   7000     free (arm_sec->data);
   7001 
   7002   if (arm_sec->rela != NULL)
   7003     free (arm_sec->rela);
   7004 }
   7005 
   7006 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
   7007       cached section and install SEC instead.
   7008    2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
   7009       and return its valued in * WORDP, relocating if necessary.
   7010    3) Update the NEXT_RELA field in ARM_SEC and store the section index and
   7011       relocation's offset in ADDR.
   7012    4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
   7013       into the string table of the symbol associated with the reloc.  If no
   7014       reloc was applied store -1 there.
   7015    5) Return TRUE upon success, FALSE otherwise.  */
   7016 
   7017 static bfd_boolean
   7018 get_unwind_section_word (struct arm_unw_aux_info *  aux,
   7019 			 struct arm_section *       arm_sec,
   7020 			 Elf_Internal_Shdr *        sec,
   7021 			 bfd_vma 		    word_offset,
   7022 			 unsigned int *             wordp,
   7023 			 struct absaddr *           addr,
   7024 			 bfd_vma *		    sym_name)
   7025 {
   7026   Elf_Internal_Rela *rp;
   7027   Elf_Internal_Sym *sym;
   7028   const char * relname;
   7029   unsigned int word;
   7030   bfd_boolean wrapped;
   7031 
   7032   if (sec == NULL || arm_sec == NULL)
   7033     return FALSE;
   7034 
   7035   addr->section = SHN_UNDEF;
   7036   addr->offset = 0;
   7037 
   7038   if (sym_name != NULL)
   7039     *sym_name = (bfd_vma) -1;
   7040 
   7041   /* If necessary, update the section cache.  */
   7042   if (sec != arm_sec->sec)
   7043     {
   7044       Elf_Internal_Shdr *relsec;
   7045 
   7046       arm_free_section (arm_sec);
   7047 
   7048       arm_sec->sec = sec;
   7049       arm_sec->data = get_data (NULL, aux->file, sec->sh_offset, 1,
   7050 				sec->sh_size, _("unwind data"));
   7051       arm_sec->rela = NULL;
   7052       arm_sec->nrelas = 0;
   7053 
   7054       for (relsec = section_headers;
   7055 	   relsec < section_headers + elf_header.e_shnum;
   7056 	   ++relsec)
   7057 	{
   7058 	  if (relsec->sh_info >= elf_header.e_shnum
   7059 	      || section_headers + relsec->sh_info != sec
   7060 	      /* PR 15745: Check the section type as well.  */
   7061 	      || (relsec->sh_type != SHT_REL
   7062 		  && relsec->sh_type != SHT_RELA))
   7063 	    continue;
   7064 
   7065 	  arm_sec->rel_type = relsec->sh_type;
   7066 	  if (relsec->sh_type == SHT_REL)
   7067 	    {
   7068 	      if (!slurp_rel_relocs (aux->file, relsec->sh_offset,
   7069 				     relsec->sh_size,
   7070 				     & arm_sec->rela, & arm_sec->nrelas))
   7071 		return FALSE;
   7072 	    }
   7073 	  else /* relsec->sh_type == SHT_RELA */
   7074 	    {
   7075 	      if (!slurp_rela_relocs (aux->file, relsec->sh_offset,
   7076 				      relsec->sh_size,
   7077 				      & arm_sec->rela, & arm_sec->nrelas))
   7078 		return FALSE;
   7079 	    }
   7080 	  break;
   7081 	}
   7082 
   7083       arm_sec->next_rela = arm_sec->rela;
   7084     }
   7085 
   7086   /* If there is no unwind data we can do nothing.  */
   7087   if (arm_sec->data == NULL)
   7088     return FALSE;
   7089 
   7090   /* If the offset is invalid then fail.  */
   7091   if (word_offset > sec->sh_size - 4)
   7092     return FALSE;
   7093 
   7094   /* Get the word at the required offset.  */
   7095   word = byte_get (arm_sec->data + word_offset, 4);
   7096 
   7097   /* Look through the relocs to find the one that applies to the provided offset.  */
   7098   wrapped = FALSE;
   7099   for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
   7100     {
   7101       bfd_vma prelval, offset;
   7102 
   7103       if (rp->r_offset > word_offset && !wrapped)
   7104 	{
   7105 	  rp = arm_sec->rela;
   7106 	  wrapped = TRUE;
   7107 	}
   7108       if (rp->r_offset > word_offset)
   7109 	break;
   7110 
   7111       if (rp->r_offset & 3)
   7112 	{
   7113 	  warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
   7114 		(unsigned long) rp->r_offset);
   7115 	  continue;
   7116 	}
   7117 
   7118       if (rp->r_offset < word_offset)
   7119 	continue;
   7120 
   7121       /* PR 17531: file: 027-161405-0.004  */
   7122       if (aux->symtab == NULL)
   7123 	continue;
   7124 
   7125       if (arm_sec->rel_type == SHT_REL)
   7126 	{
   7127 	  offset = word & 0x7fffffff;
   7128 	  if (offset & 0x40000000)
   7129 	    offset |= ~ (bfd_vma) 0x7fffffff;
   7130 	}
   7131       else if (arm_sec->rel_type == SHT_RELA)
   7132 	offset = rp->r_addend;
   7133       else
   7134 	{
   7135 	  error (_("Unknown section relocation type %d encountered\n"),
   7136 		 arm_sec->rel_type);
   7137 	  break;
   7138 	}
   7139 
   7140       /* PR 17531 file: 027-1241568-0.004.  */
   7141       if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
   7142 	{
   7143 	  error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
   7144 		 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
   7145 	  break;
   7146 	}
   7147 
   7148       sym = aux->symtab + ELF32_R_SYM (rp->r_info);
   7149       offset += sym->st_value;
   7150       prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
   7151 
   7152       /* Check that we are processing the expected reloc type.  */
   7153       if (elf_header.e_machine == EM_ARM)
   7154 	{
   7155 	  relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
   7156 	  if (relname == NULL)
   7157 	    {
   7158 	      warn (_("Skipping unknown ARM relocation type: %d\n"),
   7159 		    (int) ELF32_R_TYPE (rp->r_info));
   7160 	      continue;
   7161 	    }
   7162 
   7163 	  if (streq (relname, "R_ARM_NONE"))
   7164 	      continue;
   7165 
   7166 	  if (! streq (relname, "R_ARM_PREL31"))
   7167 	    {
   7168 	      warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
   7169 	      continue;
   7170 	    }
   7171 	}
   7172       else if (elf_header.e_machine == EM_TI_C6000)
   7173 	{
   7174 	  relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
   7175 	  if (relname == NULL)
   7176 	    {
   7177 	      warn (_("Skipping unknown C6000 relocation type: %d\n"),
   7178 		    (int) ELF32_R_TYPE (rp->r_info));
   7179 	      continue;
   7180 	    }
   7181 
   7182 	  if (streq (relname, "R_C6000_NONE"))
   7183 	    continue;
   7184 
   7185 	  if (! streq (relname, "R_C6000_PREL31"))
   7186 	    {
   7187 	      warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
   7188 	      continue;
   7189 	    }
   7190 
   7191 	  prelval >>= 1;
   7192 	}
   7193       else
   7194 	{
   7195 	  /* This function currently only supports ARM and TI unwinders.  */
   7196 	  warn (_("Only TI and ARM unwinders are currently supported\n"));
   7197 	  break;
   7198 	}
   7199 
   7200       word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
   7201       addr->section = sym->st_shndx;
   7202       addr->offset = offset;
   7203 
   7204       if (sym_name)
   7205 	* sym_name = sym->st_name;
   7206       break;
   7207     }
   7208 
   7209   *wordp = word;
   7210   arm_sec->next_rela = rp;
   7211 
   7212   return TRUE;
   7213 }
   7214 
   7215 static const char *tic6x_unwind_regnames[16] =
   7216 {
   7217   "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
   7218   "A14", "A13", "A12", "A11", "A10",
   7219   "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
   7220 };
   7221 
   7222 static void
   7223 decode_tic6x_unwind_regmask (unsigned int mask)
   7224 {
   7225   int i;
   7226 
   7227   for (i = 12; mask; mask >>= 1, i--)
   7228     {
   7229       if (mask & 1)
   7230 	{
   7231 	  fputs (tic6x_unwind_regnames[i], stdout);
   7232 	  if (mask > 1)
   7233 	    fputs (", ", stdout);
   7234 	}
   7235     }
   7236 }
   7237 
   7238 #define ADVANCE							\
   7239   if (remaining == 0 && more_words)				\
   7240     {								\
   7241       data_offset += 4;						\
   7242       if (! get_unwind_section_word (aux, data_arm_sec, data_sec,	\
   7243 				     data_offset, & word, & addr, NULL))	\
   7244 	return;							\
   7245       remaining = 4;						\
   7246       more_words--;						\
   7247     }								\
   7248 
   7249 #define GET_OP(OP)			\
   7250   ADVANCE;				\
   7251   if (remaining)			\
   7252     {					\
   7253       remaining--;			\
   7254       (OP) = word >> 24;		\
   7255       word <<= 8;			\
   7256     }					\
   7257   else					\
   7258     {					\
   7259       printf (_("[Truncated opcode]\n"));	\
   7260       return;				\
   7261     }					\
   7262   printf ("0x%02x ", OP)
   7263 
   7264 static void
   7265 decode_arm_unwind_bytecode (struct arm_unw_aux_info *aux,
   7266 			    unsigned int word, unsigned int remaining,
   7267 			    unsigned int more_words,
   7268 			    bfd_vma data_offset, Elf_Internal_Shdr *data_sec,
   7269 			    struct arm_section *data_arm_sec)
   7270 {
   7271   struct absaddr addr;
   7272 
   7273   /* Decode the unwinding instructions.  */
   7274   while (1)
   7275     {
   7276       unsigned int op, op2;
   7277 
   7278       ADVANCE;
   7279       if (remaining == 0)
   7280 	break;
   7281       remaining--;
   7282       op = word >> 24;
   7283       word <<= 8;
   7284 
   7285       printf ("  0x%02x ", op);
   7286 
   7287       if ((op & 0xc0) == 0x00)
   7288 	{
   7289 	  int offset = ((op & 0x3f) << 2) + 4;
   7290 
   7291 	  printf ("     vsp = vsp + %d", offset);
   7292 	}
   7293       else if ((op & 0xc0) == 0x40)
   7294 	{
   7295 	  int offset = ((op & 0x3f) << 2) + 4;
   7296 
   7297 	  printf ("     vsp = vsp - %d", offset);
   7298 	}
   7299       else if ((op & 0xf0) == 0x80)
   7300 	{
   7301 	  GET_OP (op2);
   7302 	  if (op == 0x80 && op2 == 0)
   7303 	    printf (_("Refuse to unwind"));
   7304 	  else
   7305 	    {
   7306 	      unsigned int mask = ((op & 0x0f) << 8) | op2;
   7307 	      int first = 1;
   7308 	      int i;
   7309 
   7310 	      printf ("pop {");
   7311 	      for (i = 0; i < 12; i++)
   7312 		if (mask & (1 << i))
   7313 		  {
   7314 		    if (first)
   7315 		      first = 0;
   7316 		    else
   7317 		      printf (", ");
   7318 		    printf ("r%d", 4 + i);
   7319 		  }
   7320 	      printf ("}");
   7321 	    }
   7322 	}
   7323       else if ((op & 0xf0) == 0x90)
   7324 	{
   7325 	  if (op == 0x9d || op == 0x9f)
   7326 	    printf (_("     [Reserved]"));
   7327 	  else
   7328 	    printf ("     vsp = r%d", op & 0x0f);
   7329 	}
   7330       else if ((op & 0xf0) == 0xa0)
   7331 	{
   7332 	  int end = 4 + (op & 0x07);
   7333 	  int first = 1;
   7334 	  int i;
   7335 
   7336 	  printf ("     pop {");
   7337 	  for (i = 4; i <= end; i++)
   7338 	    {
   7339 	      if (first)
   7340 		first = 0;
   7341 	      else
   7342 		printf (", ");
   7343 	      printf ("r%d", i);
   7344 	    }
   7345 	  if (op & 0x08)
   7346 	    {
   7347 	      if (!first)
   7348 		printf (", ");
   7349 	      printf ("r14");
   7350 	    }
   7351 	  printf ("}");
   7352 	}
   7353       else if (op == 0xb0)
   7354 	printf (_("     finish"));
   7355       else if (op == 0xb1)
   7356 	{
   7357 	  GET_OP (op2);
   7358 	  if (op2 == 0 || (op2 & 0xf0) != 0)
   7359 	    printf (_("[Spare]"));
   7360 	  else
   7361 	    {
   7362 	      unsigned int mask = op2 & 0x0f;
   7363 	      int first = 1;
   7364 	      int i;
   7365 
   7366 	      printf ("pop {");
   7367 	      for (i = 0; i < 12; i++)
   7368 		if (mask & (1 << i))
   7369 		  {
   7370 		    if (first)
   7371 		      first = 0;
   7372 		    else
   7373 		      printf (", ");
   7374 		    printf ("r%d", i);
   7375 		  }
   7376 	      printf ("}");
   7377 	    }
   7378 	}
   7379       else if (op == 0xb2)
   7380 	{
   7381 	  unsigned char buf[9];
   7382 	  unsigned int i, len;
   7383 	  unsigned long offset;
   7384 
   7385 	  for (i = 0; i < sizeof (buf); i++)
   7386 	    {
   7387 	      GET_OP (buf[i]);
   7388 	      if ((buf[i] & 0x80) == 0)
   7389 		break;
   7390 	    }
   7391 	  if (i == sizeof (buf))
   7392 	    printf (_("corrupt change to vsp"));
   7393 	  else
   7394 	    {
   7395 	      offset = read_uleb128 (buf, &len, buf + i + 1);
   7396 	      assert (len == i + 1);
   7397 	      offset = offset * 4 + 0x204;
   7398 	      printf ("vsp = vsp + %ld", offset);
   7399 	    }
   7400 	}
   7401       else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
   7402 	{
   7403 	  unsigned int first, last;
   7404 
   7405 	  GET_OP (op2);
   7406 	  first = op2 >> 4;
   7407 	  last = op2 & 0x0f;
   7408 	  if (op == 0xc8)
   7409 	    first = first + 16;
   7410 	  printf ("pop {D%d", first);
   7411 	  if (last)
   7412 	    printf ("-D%d", first + last);
   7413 	  printf ("}");
   7414 	}
   7415       else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
   7416 	{
   7417 	  unsigned int count = op & 0x07;
   7418 
   7419 	  printf ("pop {D8");
   7420 	  if (count)
   7421 	    printf ("-D%d", 8 + count);
   7422 	  printf ("}");
   7423 	}
   7424       else if (op >= 0xc0 && op <= 0xc5)
   7425 	{
   7426 	  unsigned int count = op & 0x07;
   7427 
   7428 	  printf ("     pop {wR10");
   7429 	  if (count)
   7430 	    printf ("-wR%d", 10 + count);
   7431 	  printf ("}");
   7432 	}
   7433       else if (op == 0xc6)
   7434 	{
   7435 	  unsigned int first, last;
   7436 
   7437 	  GET_OP (op2);
   7438 	  first = op2 >> 4;
   7439 	  last = op2 & 0x0f;
   7440 	  printf ("pop {wR%d", first);
   7441 	  if (last)
   7442 	    printf ("-wR%d", first + last);
   7443 	  printf ("}");
   7444 	}
   7445       else if (op == 0xc7)
   7446 	{
   7447 	  GET_OP (op2);
   7448 	  if (op2 == 0 || (op2 & 0xf0) != 0)
   7449 	    printf (_("[Spare]"));
   7450 	  else
   7451 	    {
   7452 	      unsigned int mask = op2 & 0x0f;
   7453 	      int first = 1;
   7454 	      int i;
   7455 
   7456 	      printf ("pop {");
   7457 	      for (i = 0; i < 4; i++)
   7458 		if (mask & (1 << i))
   7459 		  {
   7460 		    if (first)
   7461 		      first = 0;
   7462 		    else
   7463 		      printf (", ");
   7464 		    printf ("wCGR%d", i);
   7465 		  }
   7466 	      printf ("}");
   7467 	    }
   7468 	}
   7469       else
   7470 	printf (_("     [unsupported opcode]"));
   7471       printf ("\n");
   7472     }
   7473 }
   7474 
   7475 static void
   7476 decode_tic6x_unwind_bytecode (struct arm_unw_aux_info *aux,
   7477 			    unsigned int word, unsigned int remaining,
   7478 			    unsigned int more_words,
   7479 			    bfd_vma data_offset, Elf_Internal_Shdr *data_sec,
   7480 			    struct arm_section *data_arm_sec)
   7481 {
   7482   struct absaddr addr;
   7483 
   7484   /* Decode the unwinding instructions.  */
   7485   while (1)
   7486     {
   7487       unsigned int op, op2;
   7488 
   7489       ADVANCE;
   7490       if (remaining == 0)
   7491 	break;
   7492       remaining--;
   7493       op = word >> 24;
   7494       word <<= 8;
   7495 
   7496       printf ("  0x%02x ", op);
   7497 
   7498       if ((op & 0xc0) == 0x00)
   7499 	{
   7500 	  int offset = ((op & 0x3f) << 3) + 8;
   7501 	  printf ("     sp = sp + %d", offset);
   7502 	}
   7503       else if ((op & 0xc0) == 0x80)
   7504 	{
   7505 	  GET_OP (op2);
   7506 	  if (op == 0x80 && op2 == 0)
   7507 	    printf (_("Refuse to unwind"));
   7508 	  else
   7509 	    {
   7510 	      unsigned int mask = ((op & 0x1f) << 8) | op2;
   7511 	      if (op & 0x20)
   7512 		printf ("pop compact {");
   7513 	      else
   7514 		printf ("pop {");
   7515 
   7516 	      decode_tic6x_unwind_regmask (mask);
   7517 	      printf("}");
   7518 	    }
   7519 	}
   7520       else if ((op & 0xf0) == 0xc0)
   7521 	{
   7522 	  unsigned int reg;
   7523 	  unsigned int nregs;
   7524 	  unsigned int i;
   7525 	  const char *name;
   7526 	  struct
   7527 	  {
   7528 	      unsigned int offset;
   7529 	      unsigned int reg;
   7530 	  } regpos[16];
   7531 
   7532 	  /* Scan entire instruction first so that GET_OP output is not
   7533 	     interleaved with disassembly.  */
   7534 	  nregs = 0;
   7535 	  for (i = 0; nregs < (op & 0xf); i++)
   7536 	    {
   7537 	      GET_OP (op2);
   7538 	      reg = op2 >> 4;
   7539 	      if (reg != 0xf)
   7540 		{
   7541 		  regpos[nregs].offset = i * 2;
   7542 		  regpos[nregs].reg = reg;
   7543 		  nregs++;
   7544 		}
   7545 
   7546 	      reg = op2 & 0xf;
   7547 	      if (reg != 0xf)
   7548 		{
   7549 		  regpos[nregs].offset = i * 2 + 1;
   7550 		  regpos[nregs].reg = reg;
   7551 		  nregs++;
   7552 		}
   7553 	    }
   7554 
   7555 	  printf (_("pop frame {"));
   7556 	  reg = nregs - 1;
   7557 	  for (i = i * 2; i > 0; i--)
   7558 	    {
   7559 	      if (regpos[reg].offset == i - 1)
   7560 		{
   7561 		  name = tic6x_unwind_regnames[regpos[reg].reg];
   7562 		  if (reg > 0)
   7563 		    reg--;
   7564 		}
   7565 	      else
   7566 		name = _("[pad]");
   7567 
   7568 	      fputs (name, stdout);
   7569 	      if (i > 1)
   7570 		printf (", ");
   7571 	    }
   7572 
   7573 	  printf ("}");
   7574 	}
   7575       else if (op == 0xd0)
   7576 	printf ("     MOV FP, SP");
   7577       else if (op == 0xd1)
   7578 	printf ("     __c6xabi_pop_rts");
   7579       else if (op == 0xd2)
   7580 	{
   7581 	  unsigned char buf[9];
   7582 	  unsigned int i, len;
   7583 	  unsigned long offset;
   7584 
   7585 	  for (i = 0; i < sizeof (buf); i++)
   7586 	    {
   7587 	      GET_OP (buf[i]);
   7588 	      if ((buf[i] & 0x80) == 0)
   7589 		break;
   7590 	    }
   7591 	  assert (i < sizeof (buf));
   7592 	  offset = read_uleb128 (buf, &len, buf + i + 1);
   7593 	  assert (len == i + 1);
   7594 	  offset = offset * 8 + 0x408;
   7595 	  printf (_("sp = sp + %ld"), offset);
   7596 	}
   7597       else if ((op & 0xf0) == 0xe0)
   7598 	{
   7599 	  if ((op & 0x0f) == 7)
   7600 	    printf ("     RETURN");
   7601 	  else
   7602 	    printf ("     MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
   7603 	}
   7604       else
   7605 	{
   7606 	  printf (_("     [unsupported opcode]"));
   7607 	}
   7608       putchar ('\n');
   7609     }
   7610 }
   7611 
   7612 static bfd_vma
   7613 arm_expand_prel31 (bfd_vma word, bfd_vma where)
   7614 {
   7615   bfd_vma offset;
   7616 
   7617   offset = word & 0x7fffffff;
   7618   if (offset & 0x40000000)
   7619     offset |= ~ (bfd_vma) 0x7fffffff;
   7620 
   7621   if (elf_header.e_machine == EM_TI_C6000)
   7622     offset <<= 1;
   7623 
   7624   return offset + where;
   7625 }
   7626 
   7627 static void
   7628 decode_arm_unwind (struct arm_unw_aux_info *  aux,
   7629 		   unsigned int               word,
   7630 		   unsigned int               remaining,
   7631 		   bfd_vma                    data_offset,
   7632 		   Elf_Internal_Shdr *        data_sec,
   7633 		   struct arm_section *       data_arm_sec)
   7634 {
   7635   int per_index;
   7636   unsigned int more_words = 0;
   7637   struct absaddr addr;
   7638   bfd_vma sym_name = (bfd_vma) -1;
   7639 
   7640   if (remaining == 0)
   7641     {
   7642       /* Fetch the first word.
   7643 	 Note - when decoding an object file the address extracted
   7644 	 here will always be 0.  So we also pass in the sym_name
   7645 	 parameter so that we can find the symbol associated with
   7646 	 the personality routine.  */
   7647       if (! get_unwind_section_word (aux, data_arm_sec, data_sec, data_offset,
   7648 				     & word, & addr, & sym_name))
   7649 	return;
   7650 
   7651       remaining = 4;
   7652     }
   7653 
   7654   if ((word & 0x80000000) == 0)
   7655     {
   7656       /* Expand prel31 for personality routine.  */
   7657       bfd_vma fn;
   7658       const char *procname;
   7659 
   7660       fn = arm_expand_prel31 (word, data_sec->sh_addr + data_offset);
   7661       printf (_("  Personality routine: "));
   7662       if (fn == 0
   7663 	  && addr.section == SHN_UNDEF && addr.offset == 0
   7664 	  && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
   7665 	{
   7666 	  procname = aux->strtab + sym_name;
   7667 	  print_vma (fn, PREFIX_HEX);
   7668 	  if (procname)
   7669 	    {
   7670 	      fputs (" <", stdout);
   7671 	      fputs (procname, stdout);
   7672 	      fputc ('>', stdout);
   7673 	    }
   7674 	}
   7675       else
   7676 	procname = arm_print_vma_and_name (aux, fn, addr);
   7677       fputc ('\n', stdout);
   7678 
   7679       /* The GCC personality routines use the standard compact
   7680 	 encoding, starting with one byte giving the number of
   7681 	 words.  */
   7682       if (procname != NULL
   7683 	  && (const_strneq (procname, "__gcc_personality_v0")
   7684 	      || const_strneq (procname, "__gxx_personality_v0")
   7685 	      || const_strneq (procname, "__gcj_personality_v0")
   7686 	      || const_strneq (procname, "__gnu_objc_personality_v0")))
   7687 	{
   7688 	  remaining = 0;
   7689 	  more_words = 1;
   7690 	  ADVANCE;
   7691 	  if (!remaining)
   7692 	    {
   7693 	      printf (_("  [Truncated data]\n"));
   7694 	      return;
   7695 	    }
   7696 	  more_words = word >> 24;
   7697 	  word <<= 8;
   7698 	  remaining--;
   7699 	  per_index = -1;
   7700 	}
   7701       else
   7702 	return;
   7703     }
   7704   else
   7705     {
   7706       /* ARM EHABI Section 6.3:
   7707 
   7708 	 An exception-handling table entry for the compact model looks like:
   7709 
   7710            31 30-28 27-24 23-0
   7711 	   -- ----- ----- ----
   7712             1   0   index Data for personalityRoutine[index]    */
   7713 
   7714       if (elf_header.e_machine == EM_ARM
   7715 	  && (word & 0x70000000))
   7716 	warn (_("Corrupt ARM compact model table entry: %x \n"), word);
   7717 
   7718       per_index = (word >> 24) & 0x7f;
   7719       printf (_("  Compact model index: %d\n"), per_index);
   7720       if (per_index == 0)
   7721 	{
   7722 	  more_words = 0;
   7723 	  word <<= 8;
   7724 	  remaining--;
   7725 	}
   7726       else if (per_index < 3)
   7727 	{
   7728 	  more_words = (word >> 16) & 0xff;
   7729 	  word <<= 16;
   7730 	  remaining -= 2;
   7731 	}
   7732     }
   7733 
   7734   switch (elf_header.e_machine)
   7735     {
   7736     case EM_ARM:
   7737       if (per_index < 3)
   7738 	{
   7739 	  decode_arm_unwind_bytecode (aux, word, remaining, more_words,
   7740 				      data_offset, data_sec, data_arm_sec);
   7741 	}
   7742       else
   7743 	{
   7744 	  warn (_("Unknown ARM compact model index encountered\n"));
   7745 	  printf (_("  [reserved]\n"));
   7746 	}
   7747       break;
   7748 
   7749     case EM_TI_C6000:
   7750       if (per_index < 3)
   7751 	{
   7752 	  decode_tic6x_unwind_bytecode (aux, word, remaining, more_words,
   7753 					data_offset, data_sec, data_arm_sec);
   7754 	}
   7755       else if (per_index < 5)
   7756 	{
   7757 	  if (((word >> 17) & 0x7f) == 0x7f)
   7758 	    printf (_("  Restore stack from frame pointer\n"));
   7759 	  else
   7760 	    printf (_("  Stack increment %d\n"), (word >> 14) & 0x1fc);
   7761 	  printf (_("  Registers restored: "));
   7762 	  if (per_index == 4)
   7763 	    printf (" (compact) ");
   7764 	  decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
   7765 	  putchar ('\n');
   7766 	  printf (_("  Return register: %s\n"),
   7767 		  tic6x_unwind_regnames[word & 0xf]);
   7768 	}
   7769       else
   7770 	printf (_("  [reserved (%d)]\n"), per_index);
   7771       break;
   7772 
   7773     default:
   7774       error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
   7775 	     elf_header.e_machine);
   7776     }
   7777 
   7778   /* Decode the descriptors.  Not implemented.  */
   7779 }
   7780 
   7781 static void
   7782 dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec)
   7783 {
   7784   struct arm_section exidx_arm_sec, extab_arm_sec;
   7785   unsigned int i, exidx_len;
   7786 
   7787   memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
   7788   memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
   7789   exidx_len = exidx_sec->sh_size / 8;
   7790 
   7791   for (i = 0; i < exidx_len; i++)
   7792     {
   7793       unsigned int exidx_fn, exidx_entry;
   7794       struct absaddr fn_addr, entry_addr;
   7795       bfd_vma fn;
   7796 
   7797       fputc ('\n', stdout);
   7798 
   7799       if (! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
   7800 				     8 * i, & exidx_fn, & fn_addr, NULL)
   7801 	  || ! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
   7802 					8 * i + 4, & exidx_entry, & entry_addr, NULL))
   7803 	{
   7804 	  arm_free_section (& exidx_arm_sec);
   7805 	  arm_free_section (& extab_arm_sec);
   7806 	  return;
   7807 	}
   7808 
   7809       /* ARM EHABI, Section 5:
   7810 	 An index table entry consists of 2 words.
   7811          The first word contains a prel31 offset to the start of a function, with bit 31 clear.  */
   7812       if (exidx_fn & 0x80000000)
   7813 	warn (_("corrupt index table entry: %x\n"), exidx_fn);
   7814 
   7815       fn = arm_expand_prel31 (exidx_fn, exidx_sec->sh_addr + 8 * i);
   7816 
   7817       arm_print_vma_and_name (aux, fn, fn_addr);
   7818       fputs (": ", stdout);
   7819 
   7820       if (exidx_entry == 1)
   7821 	{
   7822 	  print_vma (exidx_entry, PREFIX_HEX);
   7823 	  fputs (" [cantunwind]\n", stdout);
   7824 	}
   7825       else if (exidx_entry & 0x80000000)
   7826 	{
   7827 	  print_vma (exidx_entry, PREFIX_HEX);
   7828 	  fputc ('\n', stdout);
   7829 	  decode_arm_unwind (aux, exidx_entry, 4, 0, NULL, NULL);
   7830 	}
   7831       else
   7832 	{
   7833 	  bfd_vma table, table_offset = 0;
   7834 	  Elf_Internal_Shdr *table_sec;
   7835 
   7836 	  fputs ("@", stdout);
   7837 	  table = arm_expand_prel31 (exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
   7838 	  print_vma (table, PREFIX_HEX);
   7839 	  printf ("\n");
   7840 
   7841 	  /* Locate the matching .ARM.extab.  */
   7842 	  if (entry_addr.section != SHN_UNDEF
   7843 	      && entry_addr.section < elf_header.e_shnum)
   7844 	    {
   7845 	      table_sec = section_headers + entry_addr.section;
   7846 	      table_offset = entry_addr.offset;
   7847 	    }
   7848 	  else
   7849 	    {
   7850 	      table_sec = find_section_by_address (table);
   7851 	      if (table_sec != NULL)
   7852 		table_offset = table - table_sec->sh_addr;
   7853 	    }
   7854 	  if (table_sec == NULL)
   7855 	    {
   7856 	      warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
   7857 		    (unsigned long) table);
   7858 	      continue;
   7859 	    }
   7860 	  decode_arm_unwind (aux, 0, 0, table_offset, table_sec,
   7861 			     &extab_arm_sec);
   7862 	}
   7863     }
   7864 
   7865   printf ("\n");
   7866 
   7867   arm_free_section (&exidx_arm_sec);
   7868   arm_free_section (&extab_arm_sec);
   7869 }
   7870 
   7871 /* Used for both ARM and C6X unwinding tables.  */
   7872 
   7873 static void
   7874 arm_process_unwind (FILE *file)
   7875 {
   7876   struct arm_unw_aux_info aux;
   7877   Elf_Internal_Shdr *unwsec = NULL;
   7878   Elf_Internal_Shdr *strsec;
   7879   Elf_Internal_Shdr *sec;
   7880   unsigned long i;
   7881   unsigned int sec_type;
   7882 
   7883   switch (elf_header.e_machine)
   7884     {
   7885     case EM_ARM:
   7886       sec_type = SHT_ARM_EXIDX;
   7887       break;
   7888 
   7889     case EM_TI_C6000:
   7890       sec_type = SHT_C6000_UNWIND;
   7891       break;
   7892 
   7893     default:
   7894       error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
   7895 	     elf_header.e_machine);
   7896       return;
   7897     }
   7898 
   7899   if (string_table == NULL)
   7900     return;
   7901 
   7902   memset (& aux, 0, sizeof (aux));
   7903   aux.file = file;
   7904 
   7905   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   7906     {
   7907       if (sec->sh_type == SHT_SYMTAB && sec->sh_link < elf_header.e_shnum)
   7908 	{
   7909 	  aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
   7910 
   7911 	  strsec = section_headers + sec->sh_link;
   7912 
   7913 	  /* PR binutils/17531 file: 011-12666-0.004.  */
   7914 	  if (aux.strtab != NULL)
   7915 	    {
   7916 	      error (_("Multiple string tables found in file.\n"));
   7917 	      free (aux.strtab);
   7918 	    }
   7919 	  aux.strtab = get_data (NULL, file, strsec->sh_offset,
   7920 				 1, strsec->sh_size, _("string table"));
   7921 	  aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
   7922 	}
   7923       else if (sec->sh_type == sec_type)
   7924 	unwsec = sec;
   7925     }
   7926 
   7927   if (unwsec == NULL)
   7928     printf (_("\nThere are no unwind sections in this file.\n"));
   7929   else
   7930     for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   7931       {
   7932 	if (sec->sh_type == sec_type)
   7933 	  {
   7934 	    printf (_("\nUnwind table index '%s' at offset 0x%lx contains %lu entries:\n"),
   7935 		    printable_section_name (sec),
   7936 		    (unsigned long) sec->sh_offset,
   7937 		    (unsigned long) (sec->sh_size / (2 * eh_addr_size)));
   7938 
   7939 	    dump_arm_unwind (&aux, sec);
   7940 	  }
   7941       }
   7942 
   7943   if (aux.symtab)
   7944     free (aux.symtab);
   7945   if (aux.strtab)
   7946     free ((char *) aux.strtab);
   7947 }
   7948 
   7949 static void
   7950 process_unwind (FILE * file)
   7951 {
   7952   struct unwind_handler
   7953   {
   7954     int machtype;
   7955     void (* handler)(FILE *);
   7956   } handlers[] =
   7957   {
   7958     { EM_ARM, arm_process_unwind },
   7959     { EM_IA_64, ia64_process_unwind },
   7960     { EM_PARISC, hppa_process_unwind },
   7961     { EM_TI_C6000, arm_process_unwind },
   7962     { 0, 0 }
   7963   };
   7964   int i;
   7965 
   7966   if (!do_unwind)
   7967     return;
   7968 
   7969   for (i = 0; handlers[i].handler != NULL; i++)
   7970     if (elf_header.e_machine == handlers[i].machtype)
   7971       {
   7972 	handlers[i].handler (file);
   7973 	return;
   7974       }
   7975 
   7976   printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
   7977 	  get_machine_name (elf_header.e_machine));
   7978 }
   7979 
   7980 static void
   7981 dynamic_section_mips_val (Elf_Internal_Dyn * entry)
   7982 {
   7983   switch (entry->d_tag)
   7984     {
   7985     case DT_MIPS_FLAGS:
   7986       if (entry->d_un.d_val == 0)
   7987 	printf (_("NONE"));
   7988       else
   7989 	{
   7990 	  static const char * opts[] =
   7991 	  {
   7992 	    "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
   7993 	    "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
   7994 	    "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
   7995 	    "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
   7996 	    "RLD_ORDER_SAFE"
   7997 	  };
   7998 	  unsigned int cnt;
   7999 	  int first = 1;
   8000 
   8001 	  for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
   8002 	    if (entry->d_un.d_val & (1 << cnt))
   8003 	      {
   8004 		printf ("%s%s", first ? "" : " ", opts[cnt]);
   8005 		first = 0;
   8006 	      }
   8007 	}
   8008       break;
   8009 
   8010     case DT_MIPS_IVERSION:
   8011       if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
   8012 	printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
   8013       else
   8014 	{
   8015 	  char buf[40];
   8016 	  sprintf_vma (buf, entry->d_un.d_ptr);
   8017 	  /* Note: coded this way so that there is a single string for translation.  */
   8018 	  printf (_("<corrupt: %s>"), buf);
   8019 	}
   8020       break;
   8021 
   8022     case DT_MIPS_TIME_STAMP:
   8023       {
   8024 	char timebuf[20];
   8025 	struct tm * tmp;
   8026 
   8027 	time_t atime = entry->d_un.d_val;
   8028 	tmp = gmtime (&atime);
   8029 	snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
   8030 		  tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
   8031 		  tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
   8032 	printf (_("Time Stamp: %s"), timebuf);
   8033       }
   8034       break;
   8035 
   8036     case DT_MIPS_RLD_VERSION:
   8037     case DT_MIPS_LOCAL_GOTNO:
   8038     case DT_MIPS_CONFLICTNO:
   8039     case DT_MIPS_LIBLISTNO:
   8040     case DT_MIPS_SYMTABNO:
   8041     case DT_MIPS_UNREFEXTNO:
   8042     case DT_MIPS_HIPAGENO:
   8043     case DT_MIPS_DELTA_CLASS_NO:
   8044     case DT_MIPS_DELTA_INSTANCE_NO:
   8045     case DT_MIPS_DELTA_RELOC_NO:
   8046     case DT_MIPS_DELTA_SYM_NO:
   8047     case DT_MIPS_DELTA_CLASSSYM_NO:
   8048     case DT_MIPS_COMPACT_SIZE:
   8049       print_vma (entry->d_un.d_ptr, DEC);
   8050       break;
   8051 
   8052     default:
   8053       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8054     }
   8055     putchar ('\n');
   8056 }
   8057 
   8058 static void
   8059 dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
   8060 {
   8061   switch (entry->d_tag)
   8062     {
   8063     case DT_HP_DLD_FLAGS:
   8064       {
   8065 	static struct
   8066 	{
   8067 	  long int bit;
   8068 	  const char * str;
   8069 	}
   8070 	flags[] =
   8071 	{
   8072 	  { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
   8073 	  { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
   8074 	  { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
   8075 	  { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
   8076 	  { DT_HP_BIND_NOW, "HP_BIND_NOW" },
   8077 	  { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
   8078 	  { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
   8079 	  { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
   8080 	  { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
   8081 	  { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
   8082 	  { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
   8083 	  { DT_HP_GST, "HP_GST" },
   8084 	  { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
   8085 	  { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
   8086 	  { DT_HP_NODELETE, "HP_NODELETE" },
   8087 	  { DT_HP_GROUP, "HP_GROUP" },
   8088 	  { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
   8089 	};
   8090 	int first = 1;
   8091 	size_t cnt;
   8092 	bfd_vma val = entry->d_un.d_val;
   8093 
   8094 	for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
   8095 	  if (val & flags[cnt].bit)
   8096 	    {
   8097 	      if (! first)
   8098 		putchar (' ');
   8099 	      fputs (flags[cnt].str, stdout);
   8100 	      first = 0;
   8101 	      val ^= flags[cnt].bit;
   8102 	    }
   8103 
   8104 	if (val != 0 || first)
   8105 	  {
   8106 	    if (! first)
   8107 	      putchar (' ');
   8108 	    print_vma (val, HEX);
   8109 	  }
   8110       }
   8111       break;
   8112 
   8113     default:
   8114       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8115       break;
   8116     }
   8117   putchar ('\n');
   8118 }
   8119 
   8120 #ifdef BFD64
   8121 
   8122 /* VMS vs Unix time offset and factor.  */
   8123 
   8124 #define VMS_EPOCH_OFFSET 35067168000000000LL
   8125 #define VMS_GRANULARITY_FACTOR 10000000
   8126 
   8127 /* Display a VMS time in a human readable format.  */
   8128 
   8129 static void
   8130 print_vms_time (bfd_int64_t vmstime)
   8131 {
   8132   struct tm *tm;
   8133   time_t unxtime;
   8134 
   8135   unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
   8136   tm = gmtime (&unxtime);
   8137   printf ("%04u-%02u-%02uT%02u:%02u:%02u",
   8138           tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
   8139           tm->tm_hour, tm->tm_min, tm->tm_sec);
   8140 }
   8141 #endif /* BFD64 */
   8142 
   8143 static void
   8144 dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
   8145 {
   8146   switch (entry->d_tag)
   8147     {
   8148     case DT_IA_64_PLT_RESERVE:
   8149       /* First 3 slots reserved.  */
   8150       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8151       printf (" -- ");
   8152       print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
   8153       break;
   8154 
   8155     case DT_IA_64_VMS_LINKTIME:
   8156 #ifdef BFD64
   8157       print_vms_time (entry->d_un.d_val);
   8158 #endif
   8159       break;
   8160 
   8161     case DT_IA_64_VMS_LNKFLAGS:
   8162       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8163       if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
   8164         printf (" CALL_DEBUG");
   8165       if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
   8166         printf (" NOP0BUFS");
   8167       if (entry->d_un.d_val & VMS_LF_P0IMAGE)
   8168         printf (" P0IMAGE");
   8169       if (entry->d_un.d_val & VMS_LF_MKTHREADS)
   8170         printf (" MKTHREADS");
   8171       if (entry->d_un.d_val & VMS_LF_UPCALLS)
   8172         printf (" UPCALLS");
   8173       if (entry->d_un.d_val & VMS_LF_IMGSTA)
   8174         printf (" IMGSTA");
   8175       if (entry->d_un.d_val & VMS_LF_INITIALIZE)
   8176         printf (" INITIALIZE");
   8177       if (entry->d_un.d_val & VMS_LF_MAIN)
   8178         printf (" MAIN");
   8179       if (entry->d_un.d_val & VMS_LF_EXE_INIT)
   8180         printf (" EXE_INIT");
   8181       if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
   8182         printf (" TBK_IN_IMG");
   8183       if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
   8184         printf (" DBG_IN_IMG");
   8185       if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
   8186         printf (" TBK_IN_DSF");
   8187       if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
   8188         printf (" DBG_IN_DSF");
   8189       if (entry->d_un.d_val & VMS_LF_SIGNATURES)
   8190         printf (" SIGNATURES");
   8191       if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
   8192         printf (" REL_SEG_OFF");
   8193       break;
   8194 
   8195     default:
   8196       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8197       break;
   8198     }
   8199   putchar ('\n');
   8200 }
   8201 
   8202 static int
   8203 get_32bit_dynamic_section (FILE * file)
   8204 {
   8205   Elf32_External_Dyn * edyn;
   8206   Elf32_External_Dyn * ext;
   8207   Elf_Internal_Dyn * entry;
   8208 
   8209   edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
   8210                                           dynamic_size, _("dynamic section"));
   8211   if (!edyn)
   8212     return 0;
   8213 
   8214   /* SGI's ELF has more than one section in the DYNAMIC segment, and we
   8215      might not have the luxury of section headers.  Look for the DT_NULL
   8216      terminator to determine the number of entries.  */
   8217   for (ext = edyn, dynamic_nent = 0;
   8218        (char *) ext < (char *) edyn + dynamic_size - sizeof (* entry);
   8219        ext++)
   8220     {
   8221       dynamic_nent++;
   8222       if (BYTE_GET (ext->d_tag) == DT_NULL)
   8223 	break;
   8224     }
   8225 
   8226   dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
   8227                                                   sizeof (* entry));
   8228   if (dynamic_section == NULL)
   8229     {
   8230       error (_("Out of memory allocating space for %lu dynamic entries\n"),
   8231 	     (unsigned long) dynamic_nent);
   8232       free (edyn);
   8233       return 0;
   8234     }
   8235 
   8236   for (ext = edyn, entry = dynamic_section;
   8237        entry < dynamic_section + dynamic_nent;
   8238        ext++, entry++)
   8239     {
   8240       entry->d_tag      = BYTE_GET (ext->d_tag);
   8241       entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
   8242     }
   8243 
   8244   free (edyn);
   8245 
   8246   return 1;
   8247 }
   8248 
   8249 static int
   8250 get_64bit_dynamic_section (FILE * file)
   8251 {
   8252   Elf64_External_Dyn * edyn;
   8253   Elf64_External_Dyn * ext;
   8254   Elf_Internal_Dyn * entry;
   8255 
   8256   /* Read in the data.  */
   8257   edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
   8258                                           dynamic_size, _("dynamic section"));
   8259   if (!edyn)
   8260     return 0;
   8261 
   8262   /* SGI's ELF has more than one section in the DYNAMIC segment, and we
   8263      might not have the luxury of section headers.  Look for the DT_NULL
   8264      terminator to determine the number of entries.  */
   8265   for (ext = edyn, dynamic_nent = 0;
   8266        /* PR 17533 file: 033-67080-0.004 - do not read off the end of the buffer.  */
   8267        (char *) ext < ((char *) edyn) + dynamic_size - sizeof (* ext);
   8268        ext++)
   8269     {
   8270       dynamic_nent++;
   8271       if (BYTE_GET (ext->d_tag) == DT_NULL)
   8272 	break;
   8273     }
   8274 
   8275   dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
   8276                                                   sizeof (* entry));
   8277   if (dynamic_section == NULL)
   8278     {
   8279       error (_("Out of memory allocating space for %lu dynamic entries\n"),
   8280 	     (unsigned long) dynamic_nent);
   8281       free (edyn);
   8282       return 0;
   8283     }
   8284 
   8285   /* Convert from external to internal formats.  */
   8286   for (ext = edyn, entry = dynamic_section;
   8287        entry < dynamic_section + dynamic_nent;
   8288        ext++, entry++)
   8289     {
   8290       entry->d_tag      = BYTE_GET (ext->d_tag);
   8291       entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
   8292     }
   8293 
   8294   free (edyn);
   8295 
   8296   return 1;
   8297 }
   8298 
   8299 static void
   8300 print_dynamic_flags (bfd_vma flags)
   8301 {
   8302   int first = 1;
   8303 
   8304   while (flags)
   8305     {
   8306       bfd_vma flag;
   8307 
   8308       flag = flags & - flags;
   8309       flags &= ~ flag;
   8310 
   8311       if (first)
   8312 	first = 0;
   8313       else
   8314 	putc (' ', stdout);
   8315 
   8316       switch (flag)
   8317 	{
   8318 	case DF_ORIGIN:		fputs ("ORIGIN", stdout); break;
   8319 	case DF_SYMBOLIC:	fputs ("SYMBOLIC", stdout); break;
   8320 	case DF_TEXTREL:	fputs ("TEXTREL", stdout); break;
   8321 	case DF_BIND_NOW:	fputs ("BIND_NOW", stdout); break;
   8322 	case DF_STATIC_TLS:	fputs ("STATIC_TLS", stdout); break;
   8323 	default:		fputs (_("unknown"), stdout); break;
   8324 	}
   8325     }
   8326   puts ("");
   8327 }
   8328 
   8329 /* Parse and display the contents of the dynamic section.  */
   8330 
   8331 static int
   8332 process_dynamic_section (FILE * file)
   8333 {
   8334   Elf_Internal_Dyn * entry;
   8335 
   8336   if (dynamic_size == 0)
   8337     {
   8338       if (do_dynamic)
   8339 	printf (_("\nThere is no dynamic section in this file.\n"));
   8340 
   8341       return 1;
   8342     }
   8343 
   8344   if (is_32bit_elf)
   8345     {
   8346       if (! get_32bit_dynamic_section (file))
   8347 	return 0;
   8348     }
   8349   else if (! get_64bit_dynamic_section (file))
   8350     return 0;
   8351 
   8352   /* Find the appropriate symbol table.  */
   8353   if (dynamic_symbols == NULL)
   8354     {
   8355       for (entry = dynamic_section;
   8356 	   entry < dynamic_section + dynamic_nent;
   8357 	   ++entry)
   8358 	{
   8359 	  Elf_Internal_Shdr section;
   8360 
   8361 	  if (entry->d_tag != DT_SYMTAB)
   8362 	    continue;
   8363 
   8364 	  dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
   8365 
   8366 	  /* Since we do not know how big the symbol table is,
   8367 	     we default to reading in the entire file (!) and
   8368 	     processing that.  This is overkill, I know, but it
   8369 	     should work.  */
   8370 	  section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
   8371 
   8372 	  if (archive_file_offset != 0)
   8373 	    section.sh_size = archive_file_size - section.sh_offset;
   8374 	  else
   8375 	    {
   8376 	      if (fseek (file, 0, SEEK_END))
   8377 		error (_("Unable to seek to end of file!\n"));
   8378 
   8379 	      section.sh_size = ftell (file) - section.sh_offset;
   8380 	    }
   8381 
   8382 	  if (is_32bit_elf)
   8383 	    section.sh_entsize = sizeof (Elf32_External_Sym);
   8384 	  else
   8385 	    section.sh_entsize = sizeof (Elf64_External_Sym);
   8386 	  section.sh_name = string_table_length;
   8387 
   8388 	  dynamic_symbols = GET_ELF_SYMBOLS (file, &section, & num_dynamic_syms);
   8389 	  if (num_dynamic_syms < 1)
   8390 	    {
   8391 	      error (_("Unable to determine the number of symbols to load\n"));
   8392 	      continue;
   8393 	    }
   8394 	}
   8395     }
   8396 
   8397   /* Similarly find a string table.  */
   8398   if (dynamic_strings == NULL)
   8399     {
   8400       for (entry = dynamic_section;
   8401 	   entry < dynamic_section + dynamic_nent;
   8402 	   ++entry)
   8403 	{
   8404 	  unsigned long offset;
   8405 	  long str_tab_len;
   8406 
   8407 	  if (entry->d_tag != DT_STRTAB)
   8408 	    continue;
   8409 
   8410 	  dynamic_info[DT_STRTAB] = entry->d_un.d_val;
   8411 
   8412 	  /* Since we do not know how big the string table is,
   8413 	     we default to reading in the entire file (!) and
   8414 	     processing that.  This is overkill, I know, but it
   8415 	     should work.  */
   8416 
   8417 	  offset = offset_from_vma (file, entry->d_un.d_val, 0);
   8418 
   8419 	  if (archive_file_offset != 0)
   8420 	    str_tab_len = archive_file_size - offset;
   8421 	  else
   8422 	    {
   8423 	      if (fseek (file, 0, SEEK_END))
   8424 		error (_("Unable to seek to end of file\n"));
   8425 	      str_tab_len = ftell (file) - offset;
   8426 	    }
   8427 
   8428 	  if (str_tab_len < 1)
   8429 	    {
   8430 	      error
   8431 		(_("Unable to determine the length of the dynamic string table\n"));
   8432 	      continue;
   8433 	    }
   8434 
   8435 	  dynamic_strings = (char *) get_data (NULL, file, offset, 1,
   8436                                                str_tab_len,
   8437                                                _("dynamic string table"));
   8438 	  dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
   8439 	  break;
   8440 	}
   8441     }
   8442 
   8443   /* And find the syminfo section if available.  */
   8444   if (dynamic_syminfo == NULL)
   8445     {
   8446       unsigned long syminsz = 0;
   8447 
   8448       for (entry = dynamic_section;
   8449 	   entry < dynamic_section + dynamic_nent;
   8450 	   ++entry)
   8451 	{
   8452 	  if (entry->d_tag == DT_SYMINENT)
   8453 	    {
   8454 	      /* Note: these braces are necessary to avoid a syntax
   8455 		 error from the SunOS4 C compiler.  */
   8456 	      /* PR binutils/17531: A corrupt file can trigger this test.
   8457 		 So do not use an assert, instead generate an error message.  */
   8458 	      if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
   8459 		error (_("Bad value (%d) for SYMINENT entry\n"),
   8460 		       (int) entry->d_un.d_val);
   8461 	    }
   8462 	  else if (entry->d_tag == DT_SYMINSZ)
   8463 	    syminsz = entry->d_un.d_val;
   8464 	  else if (entry->d_tag == DT_SYMINFO)
   8465 	    dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
   8466 						      syminsz);
   8467 	}
   8468 
   8469       if (dynamic_syminfo_offset != 0 && syminsz != 0)
   8470 	{
   8471 	  Elf_External_Syminfo * extsyminfo;
   8472 	  Elf_External_Syminfo * extsym;
   8473 	  Elf_Internal_Syminfo * syminfo;
   8474 
   8475 	  /* There is a syminfo section.  Read the data.  */
   8476 	  extsyminfo = (Elf_External_Syminfo *)
   8477               get_data (NULL, file, dynamic_syminfo_offset, 1, syminsz,
   8478                         _("symbol information"));
   8479 	  if (!extsyminfo)
   8480 	    return 0;
   8481 
   8482 	  dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
   8483 	  if (dynamic_syminfo == NULL)
   8484 	    {
   8485 	      error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
   8486 		     (unsigned long) syminsz);
   8487 	      return 0;
   8488 	    }
   8489 
   8490 	  dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
   8491 	  for (syminfo = dynamic_syminfo, extsym = extsyminfo;
   8492 	       syminfo < dynamic_syminfo + dynamic_syminfo_nent;
   8493 	       ++syminfo, ++extsym)
   8494 	    {
   8495 	      syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
   8496 	      syminfo->si_flags = BYTE_GET (extsym->si_flags);
   8497 	    }
   8498 
   8499 	  free (extsyminfo);
   8500 	}
   8501     }
   8502 
   8503   if (do_dynamic && dynamic_addr)
   8504     printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"),
   8505 	    dynamic_addr, (unsigned long) dynamic_nent);
   8506   if (do_dynamic)
   8507     printf (_("  Tag        Type                         Name/Value\n"));
   8508 
   8509   for (entry = dynamic_section;
   8510        entry < dynamic_section + dynamic_nent;
   8511        entry++)
   8512     {
   8513       if (do_dynamic)
   8514 	{
   8515 	  const char * dtype;
   8516 
   8517 	  putchar (' ');
   8518 	  print_vma (entry->d_tag, FULL_HEX);
   8519 	  dtype = get_dynamic_type (entry->d_tag);
   8520 	  printf (" (%s)%*s", dtype,
   8521 		  ((is_32bit_elf ? 27 : 19)
   8522 		   - (int) strlen (dtype)),
   8523 		  " ");
   8524 	}
   8525 
   8526       switch (entry->d_tag)
   8527 	{
   8528 	case DT_FLAGS:
   8529 	  if (do_dynamic)
   8530 	    print_dynamic_flags (entry->d_un.d_val);
   8531 	  break;
   8532 
   8533 	case DT_AUXILIARY:
   8534 	case DT_FILTER:
   8535 	case DT_CONFIG:
   8536 	case DT_DEPAUDIT:
   8537 	case DT_AUDIT:
   8538 	  if (do_dynamic)
   8539 	    {
   8540 	      switch (entry->d_tag)
   8541 		{
   8542 		case DT_AUXILIARY:
   8543 		  printf (_("Auxiliary library"));
   8544 		  break;
   8545 
   8546 		case DT_FILTER:
   8547 		  printf (_("Filter library"));
   8548 		  break;
   8549 
   8550 		case DT_CONFIG:
   8551 		  printf (_("Configuration file"));
   8552 		  break;
   8553 
   8554 		case DT_DEPAUDIT:
   8555 		  printf (_("Dependency audit library"));
   8556 		  break;
   8557 
   8558 		case DT_AUDIT:
   8559 		  printf (_("Audit library"));
   8560 		  break;
   8561 		}
   8562 
   8563 	      if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
   8564 		printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
   8565 	      else
   8566 		{
   8567 		  printf (": ");
   8568 		  print_vma (entry->d_un.d_val, PREFIX_HEX);
   8569 		  putchar ('\n');
   8570 		}
   8571 	    }
   8572 	  break;
   8573 
   8574 	case DT_FEATURE:
   8575 	  if (do_dynamic)
   8576 	    {
   8577 	      printf (_("Flags:"));
   8578 
   8579 	      if (entry->d_un.d_val == 0)
   8580 		printf (_(" None\n"));
   8581 	      else
   8582 		{
   8583 		  unsigned long int val = entry->d_un.d_val;
   8584 
   8585 		  if (val & DTF_1_PARINIT)
   8586 		    {
   8587 		      printf (" PARINIT");
   8588 		      val ^= DTF_1_PARINIT;
   8589 		    }
   8590 		  if (val & DTF_1_CONFEXP)
   8591 		    {
   8592 		      printf (" CONFEXP");
   8593 		      val ^= DTF_1_CONFEXP;
   8594 		    }
   8595 		  if (val != 0)
   8596 		    printf (" %lx", val);
   8597 		  puts ("");
   8598 		}
   8599 	    }
   8600 	  break;
   8601 
   8602 	case DT_POSFLAG_1:
   8603 	  if (do_dynamic)
   8604 	    {
   8605 	      printf (_("Flags:"));
   8606 
   8607 	      if (entry->d_un.d_val == 0)
   8608 		printf (_(" None\n"));
   8609 	      else
   8610 		{
   8611 		  unsigned long int val = entry->d_un.d_val;
   8612 
   8613 		  if (val & DF_P1_LAZYLOAD)
   8614 		    {
   8615 		      printf (" LAZYLOAD");
   8616 		      val ^= DF_P1_LAZYLOAD;
   8617 		    }
   8618 		  if (val & DF_P1_GROUPPERM)
   8619 		    {
   8620 		      printf (" GROUPPERM");
   8621 		      val ^= DF_P1_GROUPPERM;
   8622 		    }
   8623 		  if (val != 0)
   8624 		    printf (" %lx", val);
   8625 		  puts ("");
   8626 		}
   8627 	    }
   8628 	  break;
   8629 
   8630 	case DT_FLAGS_1:
   8631 	  if (do_dynamic)
   8632 	    {
   8633 	      printf (_("Flags:"));
   8634 	      if (entry->d_un.d_val == 0)
   8635 		printf (_(" None\n"));
   8636 	      else
   8637 		{
   8638 		  unsigned long int val = entry->d_un.d_val;
   8639 
   8640 		  if (val & DF_1_NOW)
   8641 		    {
   8642 		      printf (" NOW");
   8643 		      val ^= DF_1_NOW;
   8644 		    }
   8645 		  if (val & DF_1_GLOBAL)
   8646 		    {
   8647 		      printf (" GLOBAL");
   8648 		      val ^= DF_1_GLOBAL;
   8649 		    }
   8650 		  if (val & DF_1_GROUP)
   8651 		    {
   8652 		      printf (" GROUP");
   8653 		      val ^= DF_1_GROUP;
   8654 		    }
   8655 		  if (val & DF_1_NODELETE)
   8656 		    {
   8657 		      printf (" NODELETE");
   8658 		      val ^= DF_1_NODELETE;
   8659 		    }
   8660 		  if (val & DF_1_LOADFLTR)
   8661 		    {
   8662 		      printf (" LOADFLTR");
   8663 		      val ^= DF_1_LOADFLTR;
   8664 		    }
   8665 		  if (val & DF_1_INITFIRST)
   8666 		    {
   8667 		      printf (" INITFIRST");
   8668 		      val ^= DF_1_INITFIRST;
   8669 		    }
   8670 		  if (val & DF_1_NOOPEN)
   8671 		    {
   8672 		      printf (" NOOPEN");
   8673 		      val ^= DF_1_NOOPEN;
   8674 		    }
   8675 		  if (val & DF_1_ORIGIN)
   8676 		    {
   8677 		      printf (" ORIGIN");
   8678 		      val ^= DF_1_ORIGIN;
   8679 		    }
   8680 		  if (val & DF_1_DIRECT)
   8681 		    {
   8682 		      printf (" DIRECT");
   8683 		      val ^= DF_1_DIRECT;
   8684 		    }
   8685 		  if (val & DF_1_TRANS)
   8686 		    {
   8687 		      printf (" TRANS");
   8688 		      val ^= DF_1_TRANS;
   8689 		    }
   8690 		  if (val & DF_1_INTERPOSE)
   8691 		    {
   8692 		      printf (" INTERPOSE");
   8693 		      val ^= DF_1_INTERPOSE;
   8694 		    }
   8695 		  if (val & DF_1_NODEFLIB)
   8696 		    {
   8697 		      printf (" NODEFLIB");
   8698 		      val ^= DF_1_NODEFLIB;
   8699 		    }
   8700 		  if (val & DF_1_NODUMP)
   8701 		    {
   8702 		      printf (" NODUMP");
   8703 		      val ^= DF_1_NODUMP;
   8704 		    }
   8705 		  if (val & DF_1_CONFALT)
   8706 		    {
   8707 		      printf (" CONFALT");
   8708 		      val ^= DF_1_CONFALT;
   8709 		    }
   8710 		  if (val & DF_1_ENDFILTEE)
   8711 		    {
   8712 		      printf (" ENDFILTEE");
   8713 		      val ^= DF_1_ENDFILTEE;
   8714 		    }
   8715 		  if (val & DF_1_DISPRELDNE)
   8716 		    {
   8717 		      printf (" DISPRELDNE");
   8718 		      val ^= DF_1_DISPRELDNE;
   8719 		    }
   8720 		  if (val & DF_1_DISPRELPND)
   8721 		    {
   8722 		      printf (" DISPRELPND");
   8723 		      val ^= DF_1_DISPRELPND;
   8724 		    }
   8725 		  if (val & DF_1_NODIRECT)
   8726 		    {
   8727 		      printf (" NODIRECT");
   8728 		      val ^= DF_1_NODIRECT;
   8729 		    }
   8730 		  if (val & DF_1_IGNMULDEF)
   8731 		    {
   8732 		      printf (" IGNMULDEF");
   8733 		      val ^= DF_1_IGNMULDEF;
   8734 		    }
   8735 		  if (val & DF_1_NOKSYMS)
   8736 		    {
   8737 		      printf (" NOKSYMS");
   8738 		      val ^= DF_1_NOKSYMS;
   8739 		    }
   8740 		  if (val & DF_1_NOHDR)
   8741 		    {
   8742 		      printf (" NOHDR");
   8743 		      val ^= DF_1_NOHDR;
   8744 		    }
   8745 		  if (val & DF_1_EDITED)
   8746 		    {
   8747 		      printf (" EDITED");
   8748 		      val ^= DF_1_EDITED;
   8749 		    }
   8750 		  if (val & DF_1_NORELOC)
   8751 		    {
   8752 		      printf (" NORELOC");
   8753 		      val ^= DF_1_NORELOC;
   8754 		    }
   8755 		  if (val & DF_1_SYMINTPOSE)
   8756 		    {
   8757 		      printf (" SYMINTPOSE");
   8758 		      val ^= DF_1_SYMINTPOSE;
   8759 		    }
   8760 		  if (val & DF_1_GLOBAUDIT)
   8761 		    {
   8762 		      printf (" GLOBAUDIT");
   8763 		      val ^= DF_1_GLOBAUDIT;
   8764 		    }
   8765 		  if (val & DF_1_SINGLETON)
   8766 		    {
   8767 		      printf (" SINGLETON");
   8768 		      val ^= DF_1_SINGLETON;
   8769 		    }
   8770 		  if (val != 0)
   8771 		    printf (" %lx", val);
   8772 		  puts ("");
   8773 		}
   8774 	    }
   8775 	  break;
   8776 
   8777 	case DT_PLTREL:
   8778 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
   8779 	  if (do_dynamic)
   8780 	    puts (get_dynamic_type (entry->d_un.d_val));
   8781 	  break;
   8782 
   8783 	case DT_NULL	:
   8784 	case DT_NEEDED	:
   8785 	case DT_PLTGOT	:
   8786 	case DT_HASH	:
   8787 	case DT_STRTAB	:
   8788 	case DT_SYMTAB	:
   8789 	case DT_RELA	:
   8790 	case DT_INIT	:
   8791 	case DT_FINI	:
   8792 	case DT_SONAME	:
   8793 	case DT_RPATH	:
   8794 	case DT_SYMBOLIC:
   8795 	case DT_REL	:
   8796 	case DT_DEBUG	:
   8797 	case DT_TEXTREL	:
   8798 	case DT_JMPREL	:
   8799 	case DT_RUNPATH	:
   8800 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
   8801 
   8802 	  if (do_dynamic)
   8803 	    {
   8804 	      char * name;
   8805 
   8806 	      if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
   8807 		name = GET_DYNAMIC_NAME (entry->d_un.d_val);
   8808 	      else
   8809 		name = NULL;
   8810 
   8811 	      if (name)
   8812 		{
   8813 		  switch (entry->d_tag)
   8814 		    {
   8815 		    case DT_NEEDED:
   8816 		      printf (_("Shared library: [%s]"), name);
   8817 
   8818 		      if (streq (name, program_interpreter))
   8819 			printf (_(" program interpreter"));
   8820 		      break;
   8821 
   8822 		    case DT_SONAME:
   8823 		      printf (_("Library soname: [%s]"), name);
   8824 		      break;
   8825 
   8826 		    case DT_RPATH:
   8827 		      printf (_("Library rpath: [%s]"), name);
   8828 		      break;
   8829 
   8830 		    case DT_RUNPATH:
   8831 		      printf (_("Library runpath: [%s]"), name);
   8832 		      break;
   8833 
   8834 		    default:
   8835 		      print_vma (entry->d_un.d_val, PREFIX_HEX);
   8836 		      break;
   8837 		    }
   8838 		}
   8839 	      else
   8840 		print_vma (entry->d_un.d_val, PREFIX_HEX);
   8841 
   8842 	      putchar ('\n');
   8843 	    }
   8844 	  break;
   8845 
   8846 	case DT_PLTRELSZ:
   8847 	case DT_RELASZ	:
   8848 	case DT_STRSZ	:
   8849 	case DT_RELSZ	:
   8850 	case DT_RELAENT	:
   8851 	case DT_SYMENT	:
   8852 	case DT_RELENT	:
   8853 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
   8854 	case DT_PLTPADSZ:
   8855 	case DT_MOVEENT	:
   8856 	case DT_MOVESZ	:
   8857 	case DT_INIT_ARRAYSZ:
   8858 	case DT_FINI_ARRAYSZ:
   8859 	case DT_GNU_CONFLICTSZ:
   8860 	case DT_GNU_LIBLISTSZ:
   8861 	  if (do_dynamic)
   8862 	    {
   8863 	      print_vma (entry->d_un.d_val, UNSIGNED);
   8864 	      printf (_(" (bytes)\n"));
   8865 	    }
   8866 	  break;
   8867 
   8868 	case DT_VERDEFNUM:
   8869 	case DT_VERNEEDNUM:
   8870 	case DT_RELACOUNT:
   8871 	case DT_RELCOUNT:
   8872 	  if (do_dynamic)
   8873 	    {
   8874 	      print_vma (entry->d_un.d_val, UNSIGNED);
   8875 	      putchar ('\n');
   8876 	    }
   8877 	  break;
   8878 
   8879 	case DT_SYMINSZ:
   8880 	case DT_SYMINENT:
   8881 	case DT_SYMINFO:
   8882 	case DT_USED:
   8883 	case DT_INIT_ARRAY:
   8884 	case DT_FINI_ARRAY:
   8885 	  if (do_dynamic)
   8886 	    {
   8887 	      if (entry->d_tag == DT_USED
   8888 		  && VALID_DYNAMIC_NAME (entry->d_un.d_val))
   8889 		{
   8890 		  char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
   8891 
   8892 		  if (*name)
   8893 		    {
   8894 		      printf (_("Not needed object: [%s]\n"), name);
   8895 		      break;
   8896 		    }
   8897 		}
   8898 
   8899 	      print_vma (entry->d_un.d_val, PREFIX_HEX);
   8900 	      putchar ('\n');
   8901 	    }
   8902 	  break;
   8903 
   8904 	case DT_BIND_NOW:
   8905 	  /* The value of this entry is ignored.  */
   8906 	  if (do_dynamic)
   8907 	    putchar ('\n');
   8908 	  break;
   8909 
   8910 	case DT_GNU_PRELINKED:
   8911 	  if (do_dynamic)
   8912 	    {
   8913 	      struct tm * tmp;
   8914 	      time_t atime = entry->d_un.d_val;
   8915 
   8916 	      tmp = gmtime (&atime);
   8917 	      /* PR 17533 file: 041-1244816-0.004.  */
   8918 	      if (tmp == NULL)
   8919 		printf (_("<corrupt time val: %lx"),
   8920 			(unsigned long) atime);
   8921 	      else
   8922 		printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
   8923 			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
   8924 			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
   8925 
   8926 	    }
   8927 	  break;
   8928 
   8929 	case DT_GNU_HASH:
   8930 	  dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
   8931 	  if (do_dynamic)
   8932 	    {
   8933 	      print_vma (entry->d_un.d_val, PREFIX_HEX);
   8934 	      putchar ('\n');
   8935 	    }
   8936 	  break;
   8937 
   8938 	default:
   8939 	  if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
   8940 	    version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
   8941 	      entry->d_un.d_val;
   8942 
   8943 	  if (do_dynamic)
   8944 	    {
   8945 	      switch (elf_header.e_machine)
   8946 		{
   8947 		case EM_MIPS:
   8948 		case EM_MIPS_RS3_LE:
   8949 		  dynamic_section_mips_val (entry);
   8950 		  break;
   8951 		case EM_PARISC:
   8952 		  dynamic_section_parisc_val (entry);
   8953 		  break;
   8954 		case EM_IA_64:
   8955 		  dynamic_section_ia64_val (entry);
   8956 		  break;
   8957 		default:
   8958 		  print_vma (entry->d_un.d_val, PREFIX_HEX);
   8959 		  putchar ('\n');
   8960 		}
   8961 	    }
   8962 	  break;
   8963 	}
   8964     }
   8965 
   8966   return 1;
   8967 }
   8968 
   8969 static char *
   8970 get_ver_flags (unsigned int flags)
   8971 {
   8972   static char buff[32];
   8973 
   8974   buff[0] = 0;
   8975 
   8976   if (flags == 0)
   8977     return _("none");
   8978 
   8979   if (flags & VER_FLG_BASE)
   8980     strcat (buff, "BASE ");
   8981 
   8982   if (flags & VER_FLG_WEAK)
   8983     {
   8984       if (flags & VER_FLG_BASE)
   8985 	strcat (buff, "| ");
   8986 
   8987       strcat (buff, "WEAK ");
   8988     }
   8989 
   8990   if (flags & VER_FLG_INFO)
   8991     {
   8992       if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
   8993 	strcat (buff, "| ");
   8994 
   8995       strcat (buff, "INFO ");
   8996     }
   8997 
   8998   if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
   8999     strcat (buff, _("| <unknown>"));
   9000 
   9001   return buff;
   9002 }
   9003 
   9004 /* Display the contents of the version sections.  */
   9005 
   9006 static int
   9007 process_version_sections (FILE * file)
   9008 {
   9009   Elf_Internal_Shdr * section;
   9010   unsigned i;
   9011   int found = 0;
   9012 
   9013   if (! do_version)
   9014     return 1;
   9015 
   9016   for (i = 0, section = section_headers;
   9017        i < elf_header.e_shnum;
   9018        i++, section++)
   9019     {
   9020       switch (section->sh_type)
   9021 	{
   9022 	case SHT_GNU_verdef:
   9023 	  {
   9024 	    Elf_External_Verdef * edefs;
   9025 	    unsigned int idx;
   9026 	    unsigned int cnt;
   9027 	    char * endbuf;
   9028 
   9029 	    found = 1;
   9030 
   9031 	    printf (_("\nVersion definition section '%s' contains %u entries:\n"),
   9032 		    printable_section_name (section),
   9033 		    section->sh_info);
   9034 
   9035 	    printf (_("  Addr: 0x"));
   9036 	    printf_vma (section->sh_addr);
   9037 	    printf (_("  Offset: %#08lx  Link: %u (%s)"),
   9038 		    (unsigned long) section->sh_offset, section->sh_link,
   9039 		    printable_section_name_from_index (section->sh_link));
   9040 
   9041 	    edefs = (Elf_External_Verdef *)
   9042                 get_data (NULL, file, section->sh_offset, 1,section->sh_size,
   9043                           _("version definition section"));
   9044 	    if (!edefs)
   9045 	      break;
   9046 	    endbuf = (char *) edefs + section->sh_size;
   9047 
   9048 	    for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
   9049 	      {
   9050 		char * vstart;
   9051 		Elf_External_Verdef * edef;
   9052 		Elf_Internal_Verdef ent;
   9053 		Elf_External_Verdaux * eaux;
   9054 		Elf_Internal_Verdaux aux;
   9055 		int j;
   9056 		int isum;
   9057 
   9058 		/* Check for very large indicies.  */
   9059 		if (idx > (size_t) (endbuf - (char *) edefs))
   9060 		  break;
   9061 
   9062 		vstart = ((char *) edefs) + idx;
   9063 		if (vstart + sizeof (*edef) > endbuf)
   9064 		  break;
   9065 
   9066 		edef = (Elf_External_Verdef *) vstart;
   9067 
   9068 		ent.vd_version = BYTE_GET (edef->vd_version);
   9069 		ent.vd_flags   = BYTE_GET (edef->vd_flags);
   9070 		ent.vd_ndx     = BYTE_GET (edef->vd_ndx);
   9071 		ent.vd_cnt     = BYTE_GET (edef->vd_cnt);
   9072 		ent.vd_hash    = BYTE_GET (edef->vd_hash);
   9073 		ent.vd_aux     = BYTE_GET (edef->vd_aux);
   9074 		ent.vd_next    = BYTE_GET (edef->vd_next);
   9075 
   9076 		printf (_("  %#06x: Rev: %d  Flags: %s"),
   9077 			idx, ent.vd_version, get_ver_flags (ent.vd_flags));
   9078 
   9079 		printf (_("  Index: %d  Cnt: %d  "),
   9080 			ent.vd_ndx, ent.vd_cnt);
   9081 
   9082 		/* Check for overflow.  */
   9083 		if (ent.vd_aux > (size_t) (endbuf - vstart))
   9084 		  break;
   9085 
   9086 		vstart += ent.vd_aux;
   9087 
   9088 		eaux = (Elf_External_Verdaux *) vstart;
   9089 
   9090 		aux.vda_name = BYTE_GET (eaux->vda_name);
   9091 		aux.vda_next = BYTE_GET (eaux->vda_next);
   9092 
   9093 		if (VALID_DYNAMIC_NAME (aux.vda_name))
   9094 		  printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
   9095 		else
   9096 		  printf (_("Name index: %ld\n"), aux.vda_name);
   9097 
   9098 		isum = idx + ent.vd_aux;
   9099 
   9100 		for (j = 1; j < ent.vd_cnt; j++)
   9101 		  {
   9102 		    /* Check for overflow.  */
   9103 		    if (aux.vda_next > (size_t) (endbuf - vstart))
   9104 		      break;
   9105 
   9106 		    isum   += aux.vda_next;
   9107 		    vstart += aux.vda_next;
   9108 
   9109 		    eaux = (Elf_External_Verdaux *) vstart;
   9110 		    if (vstart + sizeof (*eaux) > endbuf)
   9111 		      break;
   9112 
   9113 		    aux.vda_name = BYTE_GET (eaux->vda_name);
   9114 		    aux.vda_next = BYTE_GET (eaux->vda_next);
   9115 
   9116 		    if (VALID_DYNAMIC_NAME (aux.vda_name))
   9117 		      printf (_("  %#06x: Parent %d: %s\n"),
   9118 			      isum, j, GET_DYNAMIC_NAME (aux.vda_name));
   9119 		    else
   9120 		      printf (_("  %#06x: Parent %d, name index: %ld\n"),
   9121 			      isum, j, aux.vda_name);
   9122 		  }
   9123 
   9124 		if (j < ent.vd_cnt)
   9125 		  printf (_("  Version def aux past end of section\n"));
   9126 
   9127 		idx += ent.vd_next;
   9128 	      }
   9129 
   9130 	    if (cnt < section->sh_info)
   9131 	      printf (_("  Version definition past end of section\n"));
   9132 
   9133 	    free (edefs);
   9134 	  }
   9135 	  break;
   9136 
   9137 	case SHT_GNU_verneed:
   9138 	  {
   9139 	    Elf_External_Verneed * eneed;
   9140 	    unsigned int idx;
   9141 	    unsigned int cnt;
   9142 	    char * endbuf;
   9143 
   9144 	    found = 1;
   9145 
   9146 	    printf (_("\nVersion needs section '%s' contains %u entries:\n"),
   9147 		    printable_section_name (section), section->sh_info);
   9148 
   9149 	    printf (_(" Addr: 0x"));
   9150 	    printf_vma (section->sh_addr);
   9151 	    printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
   9152 		    (unsigned long) section->sh_offset, section->sh_link,
   9153 		    printable_section_name_from_index (section->sh_link));
   9154 
   9155 	    eneed = (Elf_External_Verneed *) get_data (NULL, file,
   9156                                                        section->sh_offset, 1,
   9157                                                        section->sh_size,
   9158                                                        _("Version Needs section"));
   9159 	    if (!eneed)
   9160 	      break;
   9161 	    endbuf = (char *) eneed + section->sh_size;
   9162 
   9163 	    for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
   9164 	      {
   9165 		Elf_External_Verneed * entry;
   9166 		Elf_Internal_Verneed ent;
   9167 		int j;
   9168 		int isum;
   9169 		char * vstart;
   9170 
   9171 		if (idx > (size_t) (endbuf - (char *) eneed))
   9172 		  break;
   9173 
   9174 		vstart = ((char *) eneed) + idx;
   9175 		if (vstart + sizeof (*entry) > endbuf)
   9176 		  break;
   9177 
   9178 		entry = (Elf_External_Verneed *) vstart;
   9179 
   9180 		ent.vn_version = BYTE_GET (entry->vn_version);
   9181 		ent.vn_cnt     = BYTE_GET (entry->vn_cnt);
   9182 		ent.vn_file    = BYTE_GET (entry->vn_file);
   9183 		ent.vn_aux     = BYTE_GET (entry->vn_aux);
   9184 		ent.vn_next    = BYTE_GET (entry->vn_next);
   9185 
   9186 		printf (_("  %#06x: Version: %d"), idx, ent.vn_version);
   9187 
   9188 		if (VALID_DYNAMIC_NAME (ent.vn_file))
   9189 		  printf (_("  File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
   9190 		else
   9191 		  printf (_("  File: %lx"), ent.vn_file);
   9192 
   9193 		printf (_("  Cnt: %d\n"), ent.vn_cnt);
   9194 
   9195 		/* Check for overflow.  */
   9196 		if (ent.vn_aux > (size_t) (endbuf - vstart))
   9197 		  break;
   9198 
   9199 		vstart += ent.vn_aux;
   9200 
   9201 		for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
   9202 		  {
   9203 		    Elf_External_Vernaux * eaux;
   9204 		    Elf_Internal_Vernaux aux;
   9205 
   9206 		    if (vstart + sizeof (*eaux) > endbuf)
   9207 		      break;
   9208 		    eaux = (Elf_External_Vernaux *) vstart;
   9209 
   9210 		    aux.vna_hash  = BYTE_GET (eaux->vna_hash);
   9211 		    aux.vna_flags = BYTE_GET (eaux->vna_flags);
   9212 		    aux.vna_other = BYTE_GET (eaux->vna_other);
   9213 		    aux.vna_name  = BYTE_GET (eaux->vna_name);
   9214 		    aux.vna_next  = BYTE_GET (eaux->vna_next);
   9215 
   9216 		    if (VALID_DYNAMIC_NAME (aux.vna_name))
   9217 		      printf (_("  %#06x:   Name: %s"),
   9218 			      isum, GET_DYNAMIC_NAME (aux.vna_name));
   9219 		    else
   9220 		      printf (_("  %#06x:   Name index: %lx"),
   9221 			      isum, aux.vna_name);
   9222 
   9223 		    printf (_("  Flags: %s  Version: %d\n"),
   9224 			    get_ver_flags (aux.vna_flags), aux.vna_other);
   9225 
   9226 		    /* Check for overflow.  */
   9227 		    if (aux.vna_next > (size_t) (endbuf - vstart))
   9228 		      break;
   9229 
   9230 		    isum   += aux.vna_next;
   9231 		    vstart += aux.vna_next;
   9232 		  }
   9233 
   9234 		if (j < ent.vn_cnt)
   9235 		  warn (_("Missing Version Needs auxillary information\n"));
   9236 
   9237 		if (ent.vn_next == 0 && cnt < section->sh_info - 1)
   9238 		  {
   9239 		    warn (_("Corrupt Version Needs structure - offset to next structure is zero with entries still left to be processed\n"));
   9240 		    cnt = section->sh_info;
   9241 		    break;
   9242 		  }
   9243 		idx += ent.vn_next;
   9244 	      }
   9245 
   9246 	    if (cnt < section->sh_info)
   9247 	      warn (_("Missing Version Needs information\n"));
   9248 
   9249 	    free (eneed);
   9250 	  }
   9251 	  break;
   9252 
   9253 	case SHT_GNU_versym:
   9254 	  {
   9255 	    Elf_Internal_Shdr * link_section;
   9256 	    size_t total;
   9257 	    unsigned int cnt;
   9258 	    unsigned char * edata;
   9259 	    unsigned short * data;
   9260 	    char * strtab;
   9261 	    Elf_Internal_Sym * symbols;
   9262 	    Elf_Internal_Shdr * string_sec;
   9263 	    unsigned long num_syms;
   9264 	    long off;
   9265 
   9266 	    if (section->sh_link >= elf_header.e_shnum)
   9267 	      break;
   9268 
   9269 	    link_section = section_headers + section->sh_link;
   9270 	    total = section->sh_size / sizeof (Elf_External_Versym);
   9271 
   9272 	    if (link_section->sh_link >= elf_header.e_shnum)
   9273 	      break;
   9274 
   9275 	    found = 1;
   9276 
   9277 	    symbols = GET_ELF_SYMBOLS (file, link_section, & num_syms);
   9278 	    if (symbols == NULL)
   9279 	      break;
   9280 
   9281 	    string_sec = section_headers + link_section->sh_link;
   9282 
   9283 	    strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
   9284                                         string_sec->sh_size,
   9285                                         _("version string table"));
   9286 	    if (!strtab)
   9287 	      {
   9288 		free (symbols);
   9289 		break;
   9290 	      }
   9291 
   9292 	    printf (_("\nVersion symbols section '%s' contains %lu entries:\n"),
   9293 		    printable_section_name (section), (unsigned long) total);
   9294 
   9295 	    printf (_(" Addr: "));
   9296 	    printf_vma (section->sh_addr);
   9297 	    printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
   9298 		    (unsigned long) section->sh_offset, section->sh_link,
   9299 		    printable_section_name (link_section));
   9300 
   9301 	    off = offset_from_vma (file,
   9302 				   version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
   9303 				   total * sizeof (short));
   9304 	    edata = (unsigned char *) get_data (NULL, file, off, total,
   9305                                                 sizeof (short),
   9306                                                 _("version symbol data"));
   9307 	    if (!edata)
   9308 	      {
   9309 		free (strtab);
   9310 		free (symbols);
   9311 		break;
   9312 	      }
   9313 
   9314 	    data = (short unsigned int *) cmalloc (total, sizeof (short));
   9315 
   9316 	    for (cnt = total; cnt --;)
   9317 	      data[cnt] = byte_get (edata + cnt * sizeof (short),
   9318 				    sizeof (short));
   9319 
   9320 	    free (edata);
   9321 
   9322 	    for (cnt = 0; cnt < total; cnt += 4)
   9323 	      {
   9324 		int j, nn;
   9325 		int check_def, check_need;
   9326 		char * name;
   9327 
   9328 		printf ("  %03x:", cnt);
   9329 
   9330 		for (j = 0; (j < 4) && (cnt + j) < total; ++j)
   9331 		  switch (data[cnt + j])
   9332 		    {
   9333 		    case 0:
   9334 		      fputs (_("   0 (*local*)    "), stdout);
   9335 		      break;
   9336 
   9337 		    case 1:
   9338 		      fputs (_("   1 (*global*)   "), stdout);
   9339 		      break;
   9340 
   9341 		    default:
   9342 		      nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
   9343 				   data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
   9344 
   9345 		      /* If this index value is greater than the size of the symbols
   9346 		         array, break to avoid an out-of-bounds read.  */
   9347 		      if ((unsigned long)(cnt + j) >= num_syms)
   9348 		        {
   9349 		          warn (_("invalid index into symbol array\n"));
   9350 		          break;
   9351 			}
   9352 
   9353 		      check_def = 1;
   9354 		      check_need = 1;
   9355 		      if (symbols[cnt + j].st_shndx >= elf_header.e_shnum
   9356 			  || section_headers[symbols[cnt + j].st_shndx].sh_type
   9357 			     != SHT_NOBITS)
   9358 			{
   9359 			  if (symbols[cnt + j].st_shndx == SHN_UNDEF)
   9360 			    check_def = 0;
   9361 			  else
   9362 			    check_need = 0;
   9363 			}
   9364 
   9365 		      if (check_need
   9366 			  && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
   9367 			{
   9368 			  Elf_Internal_Verneed ivn;
   9369 			  unsigned long offset;
   9370 
   9371 			  offset = offset_from_vma
   9372 			    (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
   9373 			     sizeof (Elf_External_Verneed));
   9374 
   9375 			  do
   9376 			    {
   9377 			      Elf_Internal_Vernaux ivna;
   9378 			      Elf_External_Verneed evn;
   9379 			      Elf_External_Vernaux evna;
   9380 			      unsigned long a_off;
   9381 
   9382 			      if (get_data (&evn, file, offset, sizeof (evn), 1,
   9383 					    _("version need")) == NULL)
   9384 				break;
   9385 
   9386 			      ivn.vn_aux  = BYTE_GET (evn.vn_aux);
   9387 			      ivn.vn_next = BYTE_GET (evn.vn_next);
   9388 
   9389 			      a_off = offset + ivn.vn_aux;
   9390 
   9391 			      do
   9392 				{
   9393 				  if (get_data (&evna, file, a_off, sizeof (evna),
   9394 						1, _("version need aux (2)")) == NULL)
   9395 				    {
   9396 				      ivna.vna_next  = 0;
   9397 				      ivna.vna_other = 0;
   9398 				    }
   9399 				  else
   9400 				    {
   9401 				      ivna.vna_next  = BYTE_GET (evna.vna_next);
   9402 				      ivna.vna_other = BYTE_GET (evna.vna_other);
   9403 				    }
   9404 
   9405 				  a_off += ivna.vna_next;
   9406 				}
   9407 			      while (ivna.vna_other != data[cnt + j]
   9408 				     && ivna.vna_next != 0);
   9409 
   9410 			      if (ivna.vna_other == data[cnt + j])
   9411 				{
   9412 				  ivna.vna_name = BYTE_GET (evna.vna_name);
   9413 
   9414 				  if (ivna.vna_name >= string_sec->sh_size)
   9415 				    name = _("*invalid*");
   9416 				  else
   9417 				    name = strtab + ivna.vna_name;
   9418 				  nn += printf ("(%s%-*s",
   9419 						name,
   9420 						12 - (int) strlen (name),
   9421 						")");
   9422 				  check_def = 0;
   9423 				  break;
   9424 				}
   9425 
   9426 			      offset += ivn.vn_next;
   9427 			    }
   9428 			  while (ivn.vn_next);
   9429 			}
   9430 
   9431 		      if (check_def && data[cnt + j] != 0x8001
   9432 			  && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
   9433 			{
   9434 			  Elf_Internal_Verdef ivd;
   9435 			  Elf_External_Verdef evd;
   9436 			  unsigned long offset;
   9437 
   9438 			  offset = offset_from_vma
   9439 			    (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
   9440 			     sizeof evd);
   9441 
   9442 			  do
   9443 			    {
   9444 			      if (get_data (&evd, file, offset, sizeof (evd), 1,
   9445 					    _("version def")) == NULL)
   9446 				{
   9447 				  ivd.vd_next = 0;
   9448 				  /* PR 17531: file: 046-1082287-0.004.  */
   9449 				  ivd.vd_ndx  = (data[cnt + j] & VERSYM_VERSION) + 1;
   9450 				  break;
   9451 				}
   9452 			      else
   9453 				{
   9454 				  ivd.vd_next = BYTE_GET (evd.vd_next);
   9455 				  ivd.vd_ndx  = BYTE_GET (evd.vd_ndx);
   9456 				}
   9457 
   9458 			      offset += ivd.vd_next;
   9459 			    }
   9460 			  while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
   9461 				 && ivd.vd_next != 0);
   9462 
   9463 			  if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
   9464 			    {
   9465 			      Elf_External_Verdaux evda;
   9466 			      Elf_Internal_Verdaux ivda;
   9467 
   9468 			      ivd.vd_aux = BYTE_GET (evd.vd_aux);
   9469 
   9470 			      if (get_data (&evda, file,
   9471 					    offset - ivd.vd_next + ivd.vd_aux,
   9472 					    sizeof (evda), 1,
   9473 					    _("version def aux")) == NULL)
   9474 				break;
   9475 
   9476 			      ivda.vda_name = BYTE_GET (evda.vda_name);
   9477 
   9478 			      if (ivda.vda_name >= string_sec->sh_size)
   9479 				name = _("*invalid*");
   9480 			      else
   9481 				name = strtab + ivda.vda_name;
   9482 			      nn += printf ("(%s%-*s",
   9483 					    name,
   9484 					    12 - (int) strlen (name),
   9485 					    ")");
   9486 			    }
   9487 			}
   9488 
   9489 		      if (nn < 18)
   9490 			printf ("%*c", 18 - nn, ' ');
   9491 		    }
   9492 
   9493 		putchar ('\n');
   9494 	      }
   9495 
   9496 	    free (data);
   9497 	    free (strtab);
   9498 	    free (symbols);
   9499 	  }
   9500 	  break;
   9501 
   9502 	default:
   9503 	  break;
   9504 	}
   9505     }
   9506 
   9507   if (! found)
   9508     printf (_("\nNo version information found in this file.\n"));
   9509 
   9510   return 1;
   9511 }
   9512 
   9513 static const char *
   9514 get_symbol_binding (unsigned int binding)
   9515 {
   9516   static char buff[32];
   9517 
   9518   switch (binding)
   9519     {
   9520     case STB_LOCAL:	return "LOCAL";
   9521     case STB_GLOBAL:	return "GLOBAL";
   9522     case STB_WEAK:	return "WEAK";
   9523     default:
   9524       if (binding >= STB_LOPROC && binding <= STB_HIPROC)
   9525 	snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
   9526 		  binding);
   9527       else if (binding >= STB_LOOS && binding <= STB_HIOS)
   9528 	{
   9529 	  if (binding == STB_GNU_UNIQUE
   9530 	      && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
   9531 		  /* GNU is still using the default value 0.  */
   9532 		  || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
   9533 	    return "UNIQUE";
   9534 	  snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
   9535 	}
   9536       else
   9537 	snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
   9538       return buff;
   9539     }
   9540 }
   9541 
   9542 static const char *
   9543 get_symbol_type (unsigned int type)
   9544 {
   9545   static char buff[32];
   9546 
   9547   switch (type)
   9548     {
   9549     case STT_NOTYPE:	return "NOTYPE";
   9550     case STT_OBJECT:	return "OBJECT";
   9551     case STT_FUNC:	return "FUNC";
   9552     case STT_SECTION:	return "SECTION";
   9553     case STT_FILE:	return "FILE";
   9554     case STT_COMMON:	return "COMMON";
   9555     case STT_TLS:	return "TLS";
   9556     case STT_RELC:      return "RELC";
   9557     case STT_SRELC:     return "SRELC";
   9558     default:
   9559       if (type >= STT_LOPROC && type <= STT_HIPROC)
   9560 	{
   9561 	  if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
   9562 	    return "THUMB_FUNC";
   9563 
   9564 	  if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
   9565 	    return "REGISTER";
   9566 
   9567 	  if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
   9568 	    return "PARISC_MILLI";
   9569 
   9570 	  snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
   9571 	}
   9572       else if (type >= STT_LOOS && type <= STT_HIOS)
   9573 	{
   9574 	  if (elf_header.e_machine == EM_PARISC)
   9575 	    {
   9576 	      if (type == STT_HP_OPAQUE)
   9577 		return "HP_OPAQUE";
   9578 	      if (type == STT_HP_STUB)
   9579 		return "HP_STUB";
   9580 	    }
   9581 
   9582 	  if (type == STT_GNU_IFUNC
   9583 	      && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
   9584 		  || elf_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD
   9585 		  /* GNU is still using the default value 0.  */
   9586 		  || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
   9587 	    return "IFUNC";
   9588 
   9589 	  snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
   9590 	}
   9591       else
   9592 	snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
   9593       return buff;
   9594     }
   9595 }
   9596 
   9597 static const char *
   9598 get_symbol_visibility (unsigned int visibility)
   9599 {
   9600   switch (visibility)
   9601     {
   9602     case STV_DEFAULT:	return "DEFAULT";
   9603     case STV_INTERNAL:	return "INTERNAL";
   9604     case STV_HIDDEN:	return "HIDDEN";
   9605     case STV_PROTECTED: return "PROTECTED";
   9606     default: abort ();
   9607     }
   9608 }
   9609 
   9610 static const char *
   9611 get_mips_symbol_other (unsigned int other)
   9612 {
   9613   switch (other)
   9614     {
   9615     case STO_OPTIONAL:
   9616       return "OPTIONAL";
   9617     case STO_MIPS_PLT:
   9618       return "MIPS PLT";
   9619     case STO_MIPS_PIC:
   9620       return "MIPS PIC";
   9621     case STO_MICROMIPS:
   9622       return "MICROMIPS";
   9623     case STO_MICROMIPS | STO_MIPS_PIC:
   9624       return "MICROMIPS, MIPS PIC";
   9625     case STO_MIPS16:
   9626       return "MIPS16";
   9627     default:
   9628       return NULL;
   9629     }
   9630 }
   9631 
   9632 static const char *
   9633 get_ia64_symbol_other (unsigned int other)
   9634 {
   9635   if (is_ia64_vms ())
   9636     {
   9637       static char res[32];
   9638 
   9639       res[0] = 0;
   9640 
   9641       /* Function types is for images and .STB files only.  */
   9642       switch (elf_header.e_type)
   9643         {
   9644         case ET_DYN:
   9645         case ET_EXEC:
   9646           switch (VMS_ST_FUNC_TYPE (other))
   9647             {
   9648             case VMS_SFT_CODE_ADDR:
   9649               strcat (res, " CA");
   9650               break;
   9651             case VMS_SFT_SYMV_IDX:
   9652               strcat (res, " VEC");
   9653               break;
   9654             case VMS_SFT_FD:
   9655               strcat (res, " FD");
   9656               break;
   9657             case VMS_SFT_RESERVE:
   9658               strcat (res, " RSV");
   9659               break;
   9660             default:
   9661               abort ();
   9662             }
   9663           break;
   9664         default:
   9665           break;
   9666         }
   9667       switch (VMS_ST_LINKAGE (other))
   9668         {
   9669         case VMS_STL_IGNORE:
   9670           strcat (res, " IGN");
   9671           break;
   9672         case VMS_STL_RESERVE:
   9673           strcat (res, " RSV");
   9674           break;
   9675         case VMS_STL_STD:
   9676           strcat (res, " STD");
   9677           break;
   9678         case VMS_STL_LNK:
   9679           strcat (res, " LNK");
   9680           break;
   9681         default:
   9682           abort ();
   9683         }
   9684 
   9685       if (res[0] != 0)
   9686         return res + 1;
   9687       else
   9688         return res;
   9689     }
   9690   return NULL;
   9691 }
   9692 
   9693 static const char *
   9694 get_ppc64_symbol_other (unsigned int other)
   9695 {
   9696   if (PPC64_LOCAL_ENTRY_OFFSET (other) != 0)
   9697     {
   9698       static char buf[32];
   9699       snprintf (buf, sizeof buf, _("<localentry>: %d"),
   9700 		PPC64_LOCAL_ENTRY_OFFSET (other));
   9701       return buf;
   9702     }
   9703   return NULL;
   9704 }
   9705 
   9706 static const char *
   9707 get_symbol_other (unsigned int other)
   9708 {
   9709   const char * result = NULL;
   9710   static char buff [32];
   9711 
   9712   if (other == 0)
   9713     return "";
   9714 
   9715   switch (elf_header.e_machine)
   9716     {
   9717     case EM_MIPS:
   9718       result = get_mips_symbol_other (other);
   9719       break;
   9720     case EM_IA_64:
   9721       result = get_ia64_symbol_other (other);
   9722       break;
   9723     case EM_PPC64:
   9724       result = get_ppc64_symbol_other (other);
   9725       break;
   9726     default:
   9727       break;
   9728     }
   9729 
   9730   if (result)
   9731     return result;
   9732 
   9733   snprintf (buff, sizeof buff, _("<other>: %x"), other);
   9734   return buff;
   9735 }
   9736 
   9737 static const char *
   9738 get_symbol_index_type (unsigned int type)
   9739 {
   9740   static char buff[32];
   9741 
   9742   switch (type)
   9743     {
   9744     case SHN_UNDEF:	return "UND";
   9745     case SHN_ABS:	return "ABS";
   9746     case SHN_COMMON:	return "COM";
   9747     default:
   9748       if (type == SHN_IA_64_ANSI_COMMON
   9749 	  && elf_header.e_machine == EM_IA_64
   9750 	  && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
   9751 	return "ANSI_COM";
   9752       else if ((elf_header.e_machine == EM_X86_64
   9753 		|| elf_header.e_machine == EM_L1OM
   9754 		|| elf_header.e_machine == EM_K1OM)
   9755 	       && type == SHN_X86_64_LCOMMON)
   9756 	return "LARGE_COM";
   9757       else if ((type == SHN_MIPS_SCOMMON
   9758 		&& elf_header.e_machine == EM_MIPS)
   9759 	       || (type == SHN_TIC6X_SCOMMON
   9760 		   && elf_header.e_machine == EM_TI_C6000))
   9761 	return "SCOM";
   9762       else if (type == SHN_MIPS_SUNDEFINED
   9763 	       && elf_header.e_machine == EM_MIPS)
   9764 	return "SUND";
   9765       else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
   9766 	sprintf (buff, "PRC[0x%04x]", type & 0xffff);
   9767       else if (type >= SHN_LOOS && type <= SHN_HIOS)
   9768 	sprintf (buff, "OS [0x%04x]", type & 0xffff);
   9769       else if (type >= SHN_LORESERVE)
   9770 	sprintf (buff, "RSV[0x%04x]", type & 0xffff);
   9771       else if (type >= elf_header.e_shnum)
   9772 	sprintf (buff, _("bad section index[%3d]"), type);
   9773       else
   9774 	sprintf (buff, "%3d", type);
   9775       break;
   9776     }
   9777 
   9778   return buff;
   9779 }
   9780 
   9781 static bfd_vma *
   9782 get_dynamic_data (FILE * file, size_t number, unsigned int ent_size)
   9783 {
   9784   unsigned char * e_data;
   9785   bfd_vma * i_data;
   9786 
   9787   /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
   9788      attempting to allocate memory when the read is bound to fail.  */
   9789   if (ent_size * number > current_file_size)
   9790     {
   9791       error (_("Invalid number of dynamic entries: %lu\n"),
   9792 	     (unsigned long) number);
   9793       return NULL;
   9794     }
   9795 
   9796   e_data = (unsigned char *) cmalloc (number, ent_size);
   9797   if (e_data == NULL)
   9798     {
   9799       error (_("Out of memory reading %lu dynamic entries\n"),
   9800 	     (unsigned long) number);
   9801       return NULL;
   9802     }
   9803 
   9804   if (fread (e_data, ent_size, number, file) != number)
   9805     {
   9806       error (_("Unable to read in %lu bytes of dynamic data\n"),
   9807 	     (unsigned long) (number * ent_size));
   9808       free (e_data);
   9809       return NULL;
   9810     }
   9811 
   9812   i_data = (bfd_vma *) cmalloc (number, sizeof (*i_data));
   9813   if (i_data == NULL)
   9814     {
   9815       error (_("Out of memory allocating space for %lu dynamic entries\n"),
   9816 	     (unsigned long) number);
   9817       free (e_data);
   9818       return NULL;
   9819     }
   9820 
   9821   while (number--)
   9822     i_data[number] = byte_get (e_data + number * ent_size, ent_size);
   9823 
   9824   free (e_data);
   9825 
   9826   return i_data;
   9827 }
   9828 
   9829 static void
   9830 print_dynamic_symbol (bfd_vma si, unsigned long hn)
   9831 {
   9832   Elf_Internal_Sym * psym;
   9833   int n;
   9834 
   9835   n = print_vma (si, DEC_5);
   9836   if (n < 5)
   9837     fputs (&"     "[n], stdout);
   9838   printf (" %3lu: ", hn);
   9839 
   9840   if (dynamic_symbols == NULL || si >= num_dynamic_syms)
   9841     {
   9842       printf (_("<No info available for dynamic symbol number %lu>\n"),
   9843 	      (unsigned long) si);
   9844       return;
   9845     }
   9846 
   9847   psym = dynamic_symbols + si;
   9848   print_vma (psym->st_value, LONG_HEX);
   9849   putchar (' ');
   9850   print_vma (psym->st_size, DEC_5);
   9851 
   9852   printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
   9853   printf (" %-6s",  get_symbol_binding (ELF_ST_BIND (psym->st_info)));
   9854   printf (" %-7s",  get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
   9855   /* Check to see if any other bits in the st_other field are set.
   9856      Note - displaying this information disrupts the layout of the
   9857      table being generated, but for the moment this case is very
   9858      rare.  */
   9859   if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
   9860     printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
   9861   printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
   9862   if (VALID_DYNAMIC_NAME (psym->st_name))
   9863     print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
   9864   else
   9865     printf (_(" <corrupt: %14ld>"), psym->st_name);
   9866   putchar ('\n');
   9867 }
   9868 
   9869 /* Dump the symbol table.  */
   9870 static int
   9871 process_symbol_table (FILE * file)
   9872 {
   9873   Elf_Internal_Shdr * section;
   9874   bfd_size_type nbuckets = 0;
   9875   bfd_size_type nchains = 0;
   9876   bfd_vma * buckets = NULL;
   9877   bfd_vma * chains = NULL;
   9878   bfd_vma ngnubuckets = 0;
   9879   bfd_vma * gnubuckets = NULL;
   9880   bfd_vma * gnuchains = NULL;
   9881   bfd_vma gnusymidx = 0;
   9882   bfd_size_type ngnuchains = 0;
   9883 
   9884   if (!do_syms && !do_dyn_syms && !do_histogram)
   9885     return 1;
   9886 
   9887   if (dynamic_info[DT_HASH]
   9888       && (do_histogram
   9889 	  || (do_using_dynamic
   9890 	      && !do_dyn_syms
   9891 	      && dynamic_strings != NULL)))
   9892     {
   9893       unsigned char nb[8];
   9894       unsigned char nc[8];
   9895       unsigned int hash_ent_size = 4;
   9896 
   9897       if ((elf_header.e_machine == EM_ALPHA
   9898 	   || elf_header.e_machine == EM_S390
   9899 	   || elf_header.e_machine == EM_S390_OLD)
   9900 	  && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
   9901 	hash_ent_size = 8;
   9902 
   9903       if (fseek (file,
   9904 		 (archive_file_offset
   9905 		  + offset_from_vma (file, dynamic_info[DT_HASH],
   9906 				     sizeof nb + sizeof nc)),
   9907 		 SEEK_SET))
   9908 	{
   9909 	  error (_("Unable to seek to start of dynamic information\n"));
   9910 	  goto no_hash;
   9911 	}
   9912 
   9913       if (fread (nb, hash_ent_size, 1, file) != 1)
   9914 	{
   9915 	  error (_("Failed to read in number of buckets\n"));
   9916 	  goto no_hash;
   9917 	}
   9918 
   9919       if (fread (nc, hash_ent_size, 1, file) != 1)
   9920 	{
   9921 	  error (_("Failed to read in number of chains\n"));
   9922 	  goto no_hash;
   9923 	}
   9924 
   9925       nbuckets = byte_get (nb, hash_ent_size);
   9926       nchains  = byte_get (nc, hash_ent_size);
   9927 
   9928       buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
   9929       chains  = get_dynamic_data (file, nchains, hash_ent_size);
   9930 
   9931     no_hash:
   9932       if (buckets == NULL || chains == NULL)
   9933 	{
   9934 	  if (do_using_dynamic)
   9935 	    return 0;
   9936 	  free (buckets);
   9937 	  free (chains);
   9938 	  buckets = NULL;
   9939 	  chains = NULL;
   9940 	  nbuckets = 0;
   9941 	  nchains = 0;
   9942 	}
   9943     }
   9944 
   9945   if (dynamic_info_DT_GNU_HASH
   9946       && (do_histogram
   9947 	  || (do_using_dynamic
   9948 	      && !do_dyn_syms
   9949 	      && dynamic_strings != NULL)))
   9950     {
   9951       unsigned char nb[16];
   9952       bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
   9953       bfd_vma buckets_vma;
   9954 
   9955       if (fseek (file,
   9956 		 (archive_file_offset
   9957 		  + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
   9958 				     sizeof nb)),
   9959 		 SEEK_SET))
   9960 	{
   9961 	  error (_("Unable to seek to start of dynamic information\n"));
   9962 	  goto no_gnu_hash;
   9963 	}
   9964 
   9965       if (fread (nb, 16, 1, file) != 1)
   9966 	{
   9967 	  error (_("Failed to read in number of buckets\n"));
   9968 	  goto no_gnu_hash;
   9969 	}
   9970 
   9971       ngnubuckets = byte_get (nb, 4);
   9972       gnusymidx = byte_get (nb + 4, 4);
   9973       bitmaskwords = byte_get (nb + 8, 4);
   9974       buckets_vma = dynamic_info_DT_GNU_HASH + 16;
   9975       if (is_32bit_elf)
   9976 	buckets_vma += bitmaskwords * 4;
   9977       else
   9978 	buckets_vma += bitmaskwords * 8;
   9979 
   9980       if (fseek (file,
   9981 		 (archive_file_offset
   9982 		  + offset_from_vma (file, buckets_vma, 4)),
   9983 		 SEEK_SET))
   9984 	{
   9985 	  error (_("Unable to seek to start of dynamic information\n"));
   9986 	  goto no_gnu_hash;
   9987 	}
   9988 
   9989       gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
   9990 
   9991       if (gnubuckets == NULL)
   9992 	goto no_gnu_hash;
   9993 
   9994       for (i = 0; i < ngnubuckets; i++)
   9995 	if (gnubuckets[i] != 0)
   9996 	  {
   9997 	    if (gnubuckets[i] < gnusymidx)
   9998 	      return 0;
   9999 
   10000 	    if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
   10001 	      maxchain = gnubuckets[i];
   10002 	  }
   10003 
   10004       if (maxchain == 0xffffffff)
   10005 	goto no_gnu_hash;
   10006 
   10007       maxchain -= gnusymidx;
   10008 
   10009       if (fseek (file,
   10010 		 (archive_file_offset
   10011 		  + offset_from_vma (file, buckets_vma
   10012 					   + 4 * (ngnubuckets + maxchain), 4)),
   10013 		 SEEK_SET))
   10014 	{
   10015 	  error (_("Unable to seek to start of dynamic information\n"));
   10016 	  goto no_gnu_hash;
   10017 	}
   10018 
   10019       do
   10020 	{
   10021 	  if (fread (nb, 4, 1, file) != 1)
   10022 	    {
   10023 	      error (_("Failed to determine last chain length\n"));
   10024 	      goto no_gnu_hash;
   10025 	    }
   10026 
   10027 	  if (maxchain + 1 == 0)
   10028 	    goto no_gnu_hash;
   10029 
   10030 	  ++maxchain;
   10031 	}
   10032       while ((byte_get (nb, 4) & 1) == 0);
   10033 
   10034       if (fseek (file,
   10035 		 (archive_file_offset
   10036 		  + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
   10037 		 SEEK_SET))
   10038 	{
   10039 	  error (_("Unable to seek to start of dynamic information\n"));
   10040 	  goto no_gnu_hash;
   10041 	}
   10042 
   10043       gnuchains = get_dynamic_data (file, maxchain, 4);
   10044       ngnuchains = maxchain;
   10045 
   10046     no_gnu_hash:
   10047       if (gnuchains == NULL)
   10048 	{
   10049 	  free (gnubuckets);
   10050 	  gnubuckets = NULL;
   10051 	  ngnubuckets = 0;
   10052 	  if (do_using_dynamic)
   10053 	    return 0;
   10054 	}
   10055     }
   10056 
   10057   if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
   10058       && do_syms
   10059       && do_using_dynamic
   10060       && dynamic_strings != NULL
   10061       && dynamic_symbols != NULL)
   10062     {
   10063       unsigned long hn;
   10064 
   10065       if (dynamic_info[DT_HASH])
   10066 	{
   10067 	  bfd_vma si;
   10068 
   10069 	  printf (_("\nSymbol table for image:\n"));
   10070 	  if (is_32bit_elf)
   10071 	    printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
   10072 	  else
   10073 	    printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
   10074 
   10075 	  for (hn = 0; hn < nbuckets; hn++)
   10076 	    {
   10077 	      if (! buckets[hn])
   10078 		continue;
   10079 
   10080 	      for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
   10081 		print_dynamic_symbol (si, hn);
   10082 	    }
   10083 	}
   10084 
   10085       if (dynamic_info_DT_GNU_HASH)
   10086 	{
   10087 	  printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
   10088 	  if (is_32bit_elf)
   10089 	    printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
   10090 	  else
   10091 	    printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
   10092 
   10093 	  for (hn = 0; hn < ngnubuckets; ++hn)
   10094 	    if (gnubuckets[hn] != 0)
   10095 	      {
   10096 		bfd_vma si = gnubuckets[hn];
   10097 		bfd_vma off = si - gnusymidx;
   10098 
   10099 		do
   10100 		  {
   10101 		    print_dynamic_symbol (si, hn);
   10102 		    si++;
   10103 		  }
   10104 		while (off < ngnuchains && (gnuchains[off++] & 1) == 0);
   10105 	      }
   10106 	}
   10107     }
   10108   else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
   10109 	   && section_headers != NULL)
   10110     {
   10111       unsigned int i;
   10112 
   10113       for (i = 0, section = section_headers;
   10114 	   i < elf_header.e_shnum;
   10115 	   i++, section++)
   10116 	{
   10117 	  unsigned int si;
   10118 	  char * strtab = NULL;
   10119 	  unsigned long int strtab_size = 0;
   10120 	  Elf_Internal_Sym * symtab;
   10121 	  Elf_Internal_Sym * psym;
   10122 	  unsigned long num_syms;
   10123 
   10124 	  if ((section->sh_type != SHT_SYMTAB
   10125 	       && section->sh_type != SHT_DYNSYM)
   10126 	      || (!do_syms
   10127 		  && section->sh_type == SHT_SYMTAB))
   10128 	    continue;
   10129 
   10130 	  if (section->sh_entsize == 0)
   10131 	    {
   10132 	      printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
   10133 		      printable_section_name (section));
   10134 	      continue;
   10135 	    }
   10136 
   10137 	  printf (_("\nSymbol table '%s' contains %lu entries:\n"),
   10138 		  printable_section_name (section),
   10139 		  (unsigned long) (section->sh_size / section->sh_entsize));
   10140 
   10141 	  if (is_32bit_elf)
   10142 	    printf (_("   Num:    Value  Size Type    Bind   Vis      Ndx Name\n"));
   10143 	  else
   10144 	    printf (_("   Num:    Value          Size Type    Bind   Vis      Ndx Name\n"));
   10145 
   10146 	  symtab = GET_ELF_SYMBOLS (file, section, & num_syms);
   10147 	  if (symtab == NULL)
   10148 	    continue;
   10149 
   10150 	  if (section->sh_link == elf_header.e_shstrndx)
   10151 	    {
   10152 	      strtab = string_table;
   10153 	      strtab_size = string_table_length;
   10154 	    }
   10155 	  else if (section->sh_link < elf_header.e_shnum)
   10156 	    {
   10157 	      Elf_Internal_Shdr * string_sec;
   10158 
   10159 	      string_sec = section_headers + section->sh_link;
   10160 
   10161 	      strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
   10162                                           1, string_sec->sh_size,
   10163                                           _("string table"));
   10164 	      strtab_size = strtab != NULL ? string_sec->sh_size : 0;
   10165 	    }
   10166 
   10167 	  for (si = 0, psym = symtab; si < num_syms; si++, psym++)
   10168 	    {
   10169 	      printf ("%6d: ", si);
   10170 	      print_vma (psym->st_value, LONG_HEX);
   10171 	      putchar (' ');
   10172 	      print_vma (psym->st_size, DEC_5);
   10173 	      printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
   10174 	      printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
   10175 	      printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
   10176 	      /* Check to see if any other bits in the st_other field are set.
   10177 	         Note - displaying this information disrupts the layout of the
   10178 	         table being generated, but for the moment this case is very rare.  */
   10179 	      if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
   10180 		printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
   10181 	      printf (" %4s ", get_symbol_index_type (psym->st_shndx));
   10182 	      print_symbol (25, psym->st_name < strtab_size
   10183 			    ? strtab + psym->st_name : _("<corrupt>"));
   10184 
   10185 	      if (section->sh_type == SHT_DYNSYM
   10186 		  && version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
   10187 		{
   10188 		  unsigned char data[2];
   10189 		  unsigned short vers_data;
   10190 		  unsigned long offset;
   10191 		  int is_nobits;
   10192 		  int check_def;
   10193 
   10194 		  offset = offset_from_vma
   10195 		    (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
   10196 		     sizeof data + si * sizeof (vers_data));
   10197 
   10198 		  if (get_data (&data, file, offset + si * sizeof (vers_data),
   10199 				sizeof (data), 1, _("version data")) == NULL)
   10200 		    break;
   10201 
   10202 		  vers_data = byte_get (data, 2);
   10203 
   10204 		  is_nobits = (psym->st_shndx < elf_header.e_shnum
   10205 			       && section_headers[psym->st_shndx].sh_type
   10206 				  == SHT_NOBITS);
   10207 
   10208 		  check_def = (psym->st_shndx != SHN_UNDEF);
   10209 
   10210 		  if ((vers_data & VERSYM_HIDDEN) || vers_data > 1)
   10211 		    {
   10212 		      if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
   10213 			  && (is_nobits || ! check_def))
   10214 			{
   10215 			  Elf_External_Verneed evn;
   10216 			  Elf_Internal_Verneed ivn;
   10217 			  Elf_Internal_Vernaux ivna;
   10218 
   10219 			  /* We must test both.  */
   10220 			  offset = offset_from_vma
   10221 			    (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
   10222 			     sizeof evn);
   10223 
   10224 			  do
   10225 			    {
   10226 			      unsigned long vna_off;
   10227 
   10228 			      if (get_data (&evn, file, offset, sizeof (evn), 1,
   10229 					    _("version need")) == NULL)
   10230 				{
   10231 				  ivna.vna_next = 0;
   10232 				  ivna.vna_other = 0;
   10233 				  ivna.vna_name = 0;
   10234 				  break;
   10235 				}
   10236 
   10237 			      ivn.vn_aux  = BYTE_GET (evn.vn_aux);
   10238 			      ivn.vn_next = BYTE_GET (evn.vn_next);
   10239 
   10240 			      vna_off = offset + ivn.vn_aux;
   10241 
   10242 			      do
   10243 				{
   10244 				  Elf_External_Vernaux evna;
   10245 
   10246 				  if (get_data (&evna, file, vna_off,
   10247 						sizeof (evna), 1,
   10248 						_("version need aux (3)")) == NULL)
   10249 				    {
   10250 				      ivna.vna_next = 0;
   10251 				      ivna.vna_other = 0;
   10252 				      ivna.vna_name = 0;
   10253 				    }
   10254 				  else
   10255 				    {
   10256 				      ivna.vna_other = BYTE_GET (evna.vna_other);
   10257 				      ivna.vna_next  = BYTE_GET (evna.vna_next);
   10258 				      ivna.vna_name  = BYTE_GET (evna.vna_name);
   10259 				    }
   10260 
   10261 				  vna_off += ivna.vna_next;
   10262 				}
   10263 			      while (ivna.vna_other != vers_data
   10264 				     && ivna.vna_next != 0);
   10265 
   10266 			      if (ivna.vna_other == vers_data)
   10267 				break;
   10268 
   10269 			      offset += ivn.vn_next;
   10270 			    }
   10271 			  while (ivn.vn_next != 0);
   10272 
   10273 			  if (ivna.vna_other == vers_data)
   10274 			    {
   10275 			      printf ("@%s (%d)",
   10276 				      ivna.vna_name < strtab_size
   10277 				      ? strtab + ivna.vna_name : _("<corrupt>"),
   10278 				      ivna.vna_other);
   10279 			      check_def = 0;
   10280 			    }
   10281 			  else if (! is_nobits)
   10282 			    error (_("bad dynamic symbol\n"));
   10283 			  else
   10284 			    check_def = 1;
   10285 			}
   10286 
   10287 		      if (check_def)
   10288 			{
   10289 			  if (vers_data != 0x8001
   10290 			      && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
   10291 			    {
   10292 			      Elf_Internal_Verdef ivd;
   10293 			      Elf_Internal_Verdaux ivda;
   10294 			      Elf_External_Verdaux evda;
   10295 			      unsigned long off;
   10296 
   10297 			      off = offset_from_vma
   10298 				(file,
   10299 				 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
   10300 				 sizeof (Elf_External_Verdef));
   10301 
   10302 			      do
   10303 				{
   10304 				  Elf_External_Verdef evd;
   10305 
   10306 				  if (get_data (&evd, file, off, sizeof (evd),
   10307 						1, _("version def")) == NULL)
   10308 				    {
   10309 				      ivd.vd_ndx = 0;
   10310 				      ivd.vd_aux = 0;
   10311 				      ivd.vd_next = 0;
   10312 				    }
   10313 				  else
   10314 				    {
   10315 				      ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
   10316 				      ivd.vd_aux = BYTE_GET (evd.vd_aux);
   10317 				      ivd.vd_next = BYTE_GET (evd.vd_next);
   10318 				    }
   10319 
   10320 				  off += ivd.vd_next;
   10321 				}
   10322 			      while (ivd.vd_ndx != (vers_data & VERSYM_VERSION)
   10323 				     && ivd.vd_next != 0);
   10324 
   10325 			      off -= ivd.vd_next;
   10326 			      off += ivd.vd_aux;
   10327 
   10328 			      if (get_data (&evda, file, off, sizeof (evda),
   10329 					    1, _("version def aux")) == NULL)
   10330 				break;
   10331 
   10332 			      ivda.vda_name = BYTE_GET (evda.vda_name);
   10333 
   10334 			      if (psym->st_name != ivda.vda_name)
   10335 				printf ((vers_data & VERSYM_HIDDEN)
   10336 					? "@%s" : "@@%s",
   10337 					ivda.vda_name < strtab_size
   10338 					? strtab + ivda.vda_name : _("<corrupt>"));
   10339 			    }
   10340 			}
   10341 		    }
   10342 		}
   10343 
   10344 	      putchar ('\n');
   10345 	    }
   10346 
   10347 	  free (symtab);
   10348 	  if (strtab != string_table)
   10349 	    free (strtab);
   10350 	}
   10351     }
   10352   else if (do_syms)
   10353     printf
   10354       (_("\nDynamic symbol information is not available for displaying symbols.\n"));
   10355 
   10356   if (do_histogram && buckets != NULL)
   10357     {
   10358       unsigned long * lengths;
   10359       unsigned long * counts;
   10360       unsigned long hn;
   10361       bfd_vma si;
   10362       unsigned long maxlength = 0;
   10363       unsigned long nzero_counts = 0;
   10364       unsigned long nsyms = 0;
   10365 
   10366       printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
   10367 	      (unsigned long) nbuckets);
   10368 
   10369       lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
   10370       if (lengths == NULL)
   10371 	{
   10372 	  error (_("Out of memory allocating space for histogram buckets\n"));
   10373 	  return 0;
   10374 	}
   10375 
   10376       printf (_(" Length  Number     %% of total  Coverage\n"));
   10377       for (hn = 0; hn < nbuckets; ++hn)
   10378 	{
   10379 	  for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
   10380 	    {
   10381 	      ++nsyms;
   10382 	      if (maxlength < ++lengths[hn])
   10383 		++maxlength;
   10384 
   10385 	      /* PR binutils/17531: A corrupt binary could contain broken
   10386 		 histogram data.  Do not go into an infinite loop trying
   10387 		 to process it.  */
   10388 	      if (chains[si] == si)
   10389 		{
   10390 		  error (_("histogram chain links to itself\n"));
   10391 		  break;
   10392 		}
   10393 	    }
   10394 	}
   10395 
   10396       counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
   10397       if (counts == NULL)
   10398 	{
   10399 	  free (lengths);
   10400 	  error (_("Out of memory allocating space for histogram counts\n"));
   10401 	  return 0;
   10402 	}
   10403 
   10404       for (hn = 0; hn < nbuckets; ++hn)
   10405 	++counts[lengths[hn]];
   10406 
   10407       if (nbuckets > 0)
   10408 	{
   10409 	  unsigned long i;
   10410 	  printf ("      0  %-10lu (%5.1f%%)\n",
   10411 		  counts[0], (counts[0] * 100.0) / nbuckets);
   10412 	  for (i = 1; i <= maxlength; ++i)
   10413 	    {
   10414 	      nzero_counts += counts[i] * i;
   10415 	      printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
   10416 		      i, counts[i], (counts[i] * 100.0) / nbuckets,
   10417 		      (nzero_counts * 100.0) / nsyms);
   10418 	    }
   10419 	}
   10420 
   10421       free (counts);
   10422       free (lengths);
   10423     }
   10424 
   10425   if (buckets != NULL)
   10426     {
   10427       free (buckets);
   10428       free (chains);
   10429     }
   10430 
   10431   if (do_histogram && gnubuckets != NULL)
   10432     {
   10433       unsigned long * lengths;
   10434       unsigned long * counts;
   10435       unsigned long hn;
   10436       unsigned long maxlength = 0;
   10437       unsigned long nzero_counts = 0;
   10438       unsigned long nsyms = 0;
   10439 
   10440       printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
   10441 	      (unsigned long) ngnubuckets);
   10442 
   10443       lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
   10444       if (lengths == NULL)
   10445 	{
   10446 	  error (_("Out of memory allocating space for gnu histogram buckets\n"));
   10447 	  return 0;
   10448 	}
   10449 
   10450       printf (_(" Length  Number     %% of total  Coverage\n"));
   10451 
   10452       for (hn = 0; hn < ngnubuckets; ++hn)
   10453 	if (gnubuckets[hn] != 0)
   10454 	  {
   10455 	    bfd_vma off, length = 1;
   10456 
   10457 	    for (off = gnubuckets[hn] - gnusymidx;
   10458 		 /* PR 17531 file: 010-77222-0.004.  */
   10459 		 off < ngnuchains && (gnuchains[off] & 1) == 0;
   10460 		 ++off)
   10461 	      ++length;
   10462 	    lengths[hn] = length;
   10463 	    if (length > maxlength)
   10464 	      maxlength = length;
   10465 	    nsyms += length;
   10466 	  }
   10467 
   10468       counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
   10469       if (counts == NULL)
   10470 	{
   10471 	  free (lengths);
   10472 	  error (_("Out of memory allocating space for gnu histogram counts\n"));
   10473 	  return 0;
   10474 	}
   10475 
   10476       for (hn = 0; hn < ngnubuckets; ++hn)
   10477 	++counts[lengths[hn]];
   10478 
   10479       if (ngnubuckets > 0)
   10480 	{
   10481 	  unsigned long j;
   10482 	  printf ("      0  %-10lu (%5.1f%%)\n",
   10483 		  counts[0], (counts[0] * 100.0) / ngnubuckets);
   10484 	  for (j = 1; j <= maxlength; ++j)
   10485 	    {
   10486 	      nzero_counts += counts[j] * j;
   10487 	      printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
   10488 		      j, counts[j], (counts[j] * 100.0) / ngnubuckets,
   10489 		      (nzero_counts * 100.0) / nsyms);
   10490 	    }
   10491 	}
   10492 
   10493       free (counts);
   10494       free (lengths);
   10495       free (gnubuckets);
   10496       free (gnuchains);
   10497     }
   10498 
   10499   return 1;
   10500 }
   10501 
   10502 static int
   10503 process_syminfo (FILE * file ATTRIBUTE_UNUSED)
   10504 {
   10505   unsigned int i;
   10506 
   10507   if (dynamic_syminfo == NULL
   10508       || !do_dynamic)
   10509     /* No syminfo, this is ok.  */
   10510     return 1;
   10511 
   10512   /* There better should be a dynamic symbol section.  */
   10513   if (dynamic_symbols == NULL || dynamic_strings == NULL)
   10514     return 0;
   10515 
   10516   if (dynamic_addr)
   10517     printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
   10518 	    dynamic_syminfo_offset, dynamic_syminfo_nent);
   10519 
   10520   printf (_(" Num: Name                           BoundTo     Flags\n"));
   10521   for (i = 0; i < dynamic_syminfo_nent; ++i)
   10522     {
   10523       unsigned short int flags = dynamic_syminfo[i].si_flags;
   10524 
   10525       printf ("%4d: ", i);
   10526       if (i >= num_dynamic_syms)
   10527 	printf (_("<corrupt index>"));
   10528       else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
   10529 	print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
   10530       else
   10531 	printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
   10532       putchar (' ');
   10533 
   10534       switch (dynamic_syminfo[i].si_boundto)
   10535 	{
   10536 	case SYMINFO_BT_SELF:
   10537 	  fputs ("SELF       ", stdout);
   10538 	  break;
   10539 	case SYMINFO_BT_PARENT:
   10540 	  fputs ("PARENT     ", stdout);
   10541 	  break;
   10542 	default:
   10543 	  if (dynamic_syminfo[i].si_boundto > 0
   10544 	      && dynamic_syminfo[i].si_boundto < dynamic_nent
   10545 	      && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
   10546 	    {
   10547 	      print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
   10548 	      putchar (' ' );
   10549 	    }
   10550 	  else
   10551 	    printf ("%-10d ", dynamic_syminfo[i].si_boundto);
   10552 	  break;
   10553 	}
   10554 
   10555       if (flags & SYMINFO_FLG_DIRECT)
   10556 	printf (" DIRECT");
   10557       if (flags & SYMINFO_FLG_PASSTHRU)
   10558 	printf (" PASSTHRU");
   10559       if (flags & SYMINFO_FLG_COPY)
   10560 	printf (" COPY");
   10561       if (flags & SYMINFO_FLG_LAZYLOAD)
   10562 	printf (" LAZYLOAD");
   10563 
   10564       puts ("");
   10565     }
   10566 
   10567   return 1;
   10568 }
   10569 
   10570 /* Check to see if the given reloc needs to be handled in a target specific
   10571    manner.  If so then process the reloc and return TRUE otherwise return
   10572    FALSE.  */
   10573 
   10574 static bfd_boolean
   10575 target_specific_reloc_handling (Elf_Internal_Rela * reloc,
   10576 				unsigned char *     start,
   10577 				Elf_Internal_Sym *  symtab)
   10578 {
   10579   unsigned int reloc_type = get_reloc_type (reloc->r_info);
   10580 
   10581   switch (elf_header.e_machine)
   10582     {
   10583     case EM_MSP430:
   10584     case EM_MSP430_OLD:
   10585       {
   10586 	static Elf_Internal_Sym * saved_sym = NULL;
   10587 
   10588 	switch (reloc_type)
   10589 	  {
   10590 	  case 10: /* R_MSP430_SYM_DIFF */
   10591 	    if (uses_msp430x_relocs ())
   10592 	      break;
   10593 	  case 21: /* R_MSP430X_SYM_DIFF */
   10594 	    saved_sym = symtab + get_reloc_symindex (reloc->r_info);
   10595 	    return TRUE;
   10596 
   10597 	  case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
   10598 	  case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
   10599 	    goto handle_sym_diff;
   10600 
   10601 	  case 5: /* R_MSP430_16_BYTE */
   10602 	  case 9: /* R_MSP430_8 */
   10603 	    if (uses_msp430x_relocs ())
   10604 	      break;
   10605 	    goto handle_sym_diff;
   10606 
   10607 	  case 2: /* R_MSP430_ABS16 */
   10608 	  case 15: /* R_MSP430X_ABS16 */
   10609 	    if (! uses_msp430x_relocs ())
   10610 	      break;
   10611 	    goto handle_sym_diff;
   10612 
   10613 	  handle_sym_diff:
   10614 	    if (saved_sym != NULL)
   10615 	      {
   10616 		bfd_vma value;
   10617 
   10618 		value = reloc->r_addend
   10619 		  + (symtab[get_reloc_symindex (reloc->r_info)].st_value
   10620 		     - saved_sym->st_value);
   10621 
   10622 		byte_put (start + reloc->r_offset, value, reloc_type == 1 ? 4 : 2);
   10623 
   10624 		saved_sym = NULL;
   10625 		return TRUE;
   10626 	      }
   10627 	    break;
   10628 
   10629 	  default:
   10630 	    if (saved_sym != NULL)
   10631 	      error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
   10632 	    break;
   10633 	  }
   10634 	break;
   10635       }
   10636 
   10637     case EM_MN10300:
   10638     case EM_CYGNUS_MN10300:
   10639       {
   10640 	static Elf_Internal_Sym * saved_sym = NULL;
   10641 
   10642 	switch (reloc_type)
   10643 	  {
   10644 	  case 34: /* R_MN10300_ALIGN */
   10645 	    return TRUE;
   10646 	  case 33: /* R_MN10300_SYM_DIFF */
   10647 	    saved_sym = symtab + get_reloc_symindex (reloc->r_info);
   10648 	    return TRUE;
   10649 	  case 1: /* R_MN10300_32 */
   10650 	  case 2: /* R_MN10300_16 */
   10651 	    if (saved_sym != NULL)
   10652 	      {
   10653 		bfd_vma value;
   10654 
   10655 		value = reloc->r_addend
   10656 		  + (symtab[get_reloc_symindex (reloc->r_info)].st_value
   10657 		     - saved_sym->st_value);
   10658 
   10659 		byte_put (start + reloc->r_offset, value, reloc_type == 1 ? 4 : 2);
   10660 
   10661 		saved_sym = NULL;
   10662 		return TRUE;
   10663 	      }
   10664 	    break;
   10665 	  default:
   10666 	    if (saved_sym != NULL)
   10667 	      error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
   10668 	    break;
   10669 	  }
   10670 	break;
   10671       }
   10672     }
   10673 
   10674   return FALSE;
   10675 }
   10676 
   10677 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
   10678    DWARF debug sections.  This is a target specific test.  Note - we do not
   10679    go through the whole including-target-headers-multiple-times route, (as
   10680    we have already done with <elf/h8.h>) because this would become very
   10681    messy and even then this function would have to contain target specific
   10682    information (the names of the relocs instead of their numeric values).
   10683    FIXME: This is not the correct way to solve this problem.  The proper way
   10684    is to have target specific reloc sizing and typing functions created by
   10685    the reloc-macros.h header, in the same way that it already creates the
   10686    reloc naming functions.  */
   10687 
   10688 static bfd_boolean
   10689 is_32bit_abs_reloc (unsigned int reloc_type)
   10690 {
   10691   switch (elf_header.e_machine)
   10692     {
   10693     case EM_386:
   10694     case EM_486:
   10695       return reloc_type == 1; /* R_386_32.  */
   10696     case EM_68K:
   10697       return reloc_type == 1; /* R_68K_32.  */
   10698     case EM_860:
   10699       return reloc_type == 1; /* R_860_32.  */
   10700     case EM_960:
   10701       return reloc_type == 2; /* R_960_32.  */
   10702     case EM_AARCH64:
   10703       return reloc_type == 258; /* R_AARCH64_ABS32 */
   10704     case EM_ALPHA:
   10705       return reloc_type == 1; /* R_ALPHA_REFLONG.  */
   10706     case EM_ARC:
   10707       return reloc_type == 1; /* R_ARC_32.  */
   10708     case EM_ARM:
   10709       return reloc_type == 2; /* R_ARM_ABS32 */
   10710     case EM_AVR_OLD:
   10711     case EM_AVR:
   10712       return reloc_type == 1;
   10713     case EM_ADAPTEVA_EPIPHANY:
   10714       return reloc_type == 3;
   10715     case EM_BLACKFIN:
   10716       return reloc_type == 0x12; /* R_byte4_data.  */
   10717     case EM_CRIS:
   10718       return reloc_type == 3; /* R_CRIS_32.  */
   10719     case EM_CR16:
   10720       return reloc_type == 3; /* R_CR16_NUM32.  */
   10721     case EM_CRX:
   10722       return reloc_type == 15; /* R_CRX_NUM32.  */
   10723     case EM_CYGNUS_FRV:
   10724       return reloc_type == 1;
   10725     case EM_CYGNUS_D10V:
   10726     case EM_D10V:
   10727       return reloc_type == 6; /* R_D10V_32.  */
   10728     case EM_CYGNUS_D30V:
   10729     case EM_D30V:
   10730       return reloc_type == 12; /* R_D30V_32_NORMAL.  */
   10731     case EM_DLX:
   10732       return reloc_type == 3; /* R_DLX_RELOC_32.  */
   10733     case EM_CYGNUS_FR30:
   10734     case EM_FR30:
   10735       return reloc_type == 3; /* R_FR30_32.  */
   10736     case EM_H8S:
   10737     case EM_H8_300:
   10738     case EM_H8_300H:
   10739       return reloc_type == 1; /* R_H8_DIR32.  */
   10740     case EM_IA_64:
   10741       return reloc_type == 0x65; /* R_IA64_SECREL32LSB.  */
   10742     case EM_IP2K_OLD:
   10743     case EM_IP2K:
   10744       return reloc_type == 2; /* R_IP2K_32.  */
   10745     case EM_IQ2000:
   10746       return reloc_type == 2; /* R_IQ2000_32.  */
   10747     case EM_LATTICEMICO32:
   10748       return reloc_type == 3; /* R_LM32_32.  */
   10749     case EM_M32C_OLD:
   10750     case EM_M32C:
   10751       return reloc_type == 3; /* R_M32C_32.  */
   10752     case EM_M32R:
   10753       return reloc_type == 34; /* R_M32R_32_RELA.  */
   10754     case EM_MCORE:
   10755       return reloc_type == 1; /* R_MCORE_ADDR32.  */
   10756     case EM_CYGNUS_MEP:
   10757       return reloc_type == 4; /* R_MEP_32.  */
   10758     case EM_METAG:
   10759       return reloc_type == 2; /* R_METAG_ADDR32.  */
   10760     case EM_MICROBLAZE:
   10761       return reloc_type == 1; /* R_MICROBLAZE_32.  */
   10762     case EM_MIPS:
   10763       return reloc_type == 2; /* R_MIPS_32.  */
   10764     case EM_MMIX:
   10765       return reloc_type == 4; /* R_MMIX_32.  */
   10766     case EM_CYGNUS_MN10200:
   10767     case EM_MN10200:
   10768       return reloc_type == 1; /* R_MN10200_32.  */
   10769     case EM_CYGNUS_MN10300:
   10770     case EM_MN10300:
   10771       return reloc_type == 1; /* R_MN10300_32.  */
   10772     case EM_MOXIE:
   10773       return reloc_type == 1; /* R_MOXIE_32.  */
   10774     case EM_MSP430_OLD:
   10775     case EM_MSP430:
   10776       return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32.  */
   10777     case EM_MT:
   10778       return reloc_type == 2; /* R_MT_32.  */
   10779     case EM_NDS32:
   10780       return reloc_type == 20; /* R_NDS32_RELA.  */
   10781     case EM_ALTERA_NIOS2:
   10782       return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32.  */
   10783     case EM_NIOS32:
   10784       return reloc_type == 1; /* R_NIOS_32.  */
   10785     case EM_OR1K:
   10786       return reloc_type == 1; /* R_OR1K_32.  */
   10787     case EM_PARISC:
   10788       return (reloc_type == 1 /* R_PARISC_DIR32.  */
   10789 	      || reloc_type == 41); /* R_PARISC_SECREL32.  */
   10790     case EM_PJ:
   10791     case EM_PJ_OLD:
   10792       return reloc_type == 1; /* R_PJ_DATA_DIR32.  */
   10793     case EM_PPC64:
   10794       return reloc_type == 1; /* R_PPC64_ADDR32.  */
   10795     case EM_PPC:
   10796       return reloc_type == 1; /* R_PPC_ADDR32.  */
   10797     case EM_RL78:
   10798       return reloc_type == 1; /* R_RL78_DIR32.  */
   10799     case EM_RX:
   10800       return reloc_type == 1; /* R_RX_DIR32.  */
   10801     case EM_S370:
   10802       return reloc_type == 1; /* R_I370_ADDR31.  */
   10803     case EM_S390_OLD:
   10804     case EM_S390:
   10805       return reloc_type == 4; /* R_S390_32.  */
   10806     case EM_SCORE:
   10807       return reloc_type == 8; /* R_SCORE_ABS32.  */
   10808     case EM_SH:
   10809       return reloc_type == 1; /* R_SH_DIR32.  */
   10810     case EM_SPARC32PLUS:
   10811     case EM_SPARCV9:
   10812     case EM_SPARC:
   10813       return reloc_type == 3 /* R_SPARC_32.  */
   10814 	|| reloc_type == 23; /* R_SPARC_UA32.  */
   10815     case EM_SPU:
   10816       return reloc_type == 6; /* R_SPU_ADDR32 */
   10817     case EM_TI_C6000:
   10818       return reloc_type == 1; /* R_C6000_ABS32.  */
   10819     case EM_TILEGX:
   10820       return reloc_type == 2; /* R_TILEGX_32.  */
   10821     case EM_TILEPRO:
   10822       return reloc_type == 1; /* R_TILEPRO_32.  */
   10823     case EM_CYGNUS_V850:
   10824     case EM_V850:
   10825       return reloc_type == 6; /* R_V850_ABS32.  */
   10826     case EM_V800:
   10827       return reloc_type == 0x33; /* R_V810_WORD.  */
   10828     case EM_VAX:
   10829       return reloc_type == 1; /* R_VAX_32.  */
   10830     case EM_X86_64:
   10831     case EM_L1OM:
   10832     case EM_K1OM:
   10833       return reloc_type == 10; /* R_X86_64_32.  */
   10834     case EM_XC16X:
   10835     case EM_C166:
   10836       return reloc_type == 3; /* R_XC16C_ABS_32.  */
   10837     case EM_XGATE:
   10838       return reloc_type == 4; /* R_XGATE_32.  */
   10839     case EM_XSTORMY16:
   10840       return reloc_type == 1; /* R_XSTROMY16_32.  */
   10841     case EM_XTENSA_OLD:
   10842     case EM_XTENSA:
   10843       return reloc_type == 1; /* R_XTENSA_32.  */
   10844     default:
   10845       error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
   10846 	     elf_header.e_machine);
   10847       abort ();
   10848     }
   10849 }
   10850 
   10851 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
   10852    a 32-bit pc-relative RELA relocation used in DWARF debug sections.  */
   10853 
   10854 static bfd_boolean
   10855 is_32bit_pcrel_reloc (unsigned int reloc_type)
   10856 {
   10857   switch (elf_header.e_machine)
   10858     {
   10859     case EM_386:
   10860     case EM_486:
   10861       return reloc_type == 2;  /* R_386_PC32.  */
   10862     case EM_68K:
   10863       return reloc_type == 4;  /* R_68K_PC32.  */
   10864     case EM_AARCH64:
   10865       return reloc_type == 261; /* R_AARCH64_PREL32 */
   10866     case EM_ADAPTEVA_EPIPHANY:
   10867       return reloc_type == 6;
   10868     case EM_ALPHA:
   10869       return reloc_type == 10; /* R_ALPHA_SREL32.  */
   10870     case EM_ARM:
   10871       return reloc_type == 3;  /* R_ARM_REL32 */
   10872     case EM_MICROBLAZE:
   10873       return reloc_type == 2;  /* R_MICROBLAZE_32_PCREL.  */
   10874     case EM_OR1K:
   10875       return reloc_type == 9; /* R_OR1K_32_PCREL.  */
   10876     case EM_PARISC:
   10877       return reloc_type == 9;  /* R_PARISC_PCREL32.  */
   10878     case EM_PPC:
   10879       return reloc_type == 26; /* R_PPC_REL32.  */
   10880     case EM_PPC64:
   10881       return reloc_type == 26; /* R_PPC64_REL32.  */
   10882     case EM_S390_OLD:
   10883     case EM_S390:
   10884       return reloc_type == 5;  /* R_390_PC32.  */
   10885     case EM_SH:
   10886       return reloc_type == 2;  /* R_SH_REL32.  */
   10887     case EM_SPARC32PLUS:
   10888     case EM_SPARCV9:
   10889     case EM_SPARC:
   10890       return reloc_type == 6;  /* R_SPARC_DISP32.  */
   10891     case EM_SPU:
   10892       return reloc_type == 13; /* R_SPU_REL32.  */
   10893     case EM_TILEGX:
   10894       return reloc_type == 6; /* R_TILEGX_32_PCREL.  */
   10895     case EM_TILEPRO:
   10896       return reloc_type == 4; /* R_TILEPRO_32_PCREL.  */
   10897     case EM_X86_64:
   10898     case EM_L1OM:
   10899     case EM_K1OM:
   10900       return reloc_type == 2;  /* R_X86_64_PC32.  */
   10901     case EM_XTENSA_OLD:
   10902     case EM_XTENSA:
   10903       return reloc_type == 14; /* R_XTENSA_32_PCREL.  */
   10904     default:
   10905       /* Do not abort or issue an error message here.  Not all targets use
   10906 	 pc-relative 32-bit relocs in their DWARF debug information and we
   10907 	 have already tested for target coverage in is_32bit_abs_reloc.  A
   10908 	 more helpful warning message will be generated by apply_relocations
   10909 	 anyway, so just return.  */
   10910       return FALSE;
   10911     }
   10912 }
   10913 
   10914 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
   10915    a 64-bit absolute RELA relocation used in DWARF debug sections.  */
   10916 
   10917 static bfd_boolean
   10918 is_64bit_abs_reloc (unsigned int reloc_type)
   10919 {
   10920   switch (elf_header.e_machine)
   10921     {
   10922     case EM_AARCH64:
   10923       return reloc_type == 257;	/* R_AARCH64_ABS64.  */
   10924     case EM_ALPHA:
   10925       return reloc_type == 2; /* R_ALPHA_REFQUAD.  */
   10926     case EM_IA_64:
   10927       return reloc_type == 0x27; /* R_IA64_DIR64LSB.  */
   10928     case EM_PARISC:
   10929       return reloc_type == 80; /* R_PARISC_DIR64.  */
   10930     case EM_PPC64:
   10931       return reloc_type == 38; /* R_PPC64_ADDR64.  */
   10932     case EM_SPARC32PLUS:
   10933     case EM_SPARCV9:
   10934     case EM_SPARC:
   10935       return reloc_type == 54; /* R_SPARC_UA64.  */
   10936     case EM_X86_64:
   10937     case EM_L1OM:
   10938     case EM_K1OM:
   10939       return reloc_type == 1; /* R_X86_64_64.  */
   10940     case EM_S390_OLD:
   10941     case EM_S390:
   10942       return reloc_type == 22;	/* R_S390_64.  */
   10943     case EM_TILEGX:
   10944       return reloc_type == 1; /* R_TILEGX_64.  */
   10945     case EM_MIPS:
   10946       return reloc_type == 18;	/* R_MIPS_64.  */
   10947     default:
   10948       return FALSE;
   10949     }
   10950 }
   10951 
   10952 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
   10953    a 64-bit pc-relative RELA relocation used in DWARF debug sections.  */
   10954 
   10955 static bfd_boolean
   10956 is_64bit_pcrel_reloc (unsigned int reloc_type)
   10957 {
   10958   switch (elf_header.e_machine)
   10959     {
   10960     case EM_AARCH64:
   10961       return reloc_type == 260;	/* R_AARCH64_PREL64.  */
   10962     case EM_ALPHA:
   10963       return reloc_type == 11; /* R_ALPHA_SREL64.  */
   10964     case EM_IA_64:
   10965       return reloc_type == 0x4f; /* R_IA64_PCREL64LSB.  */
   10966     case EM_PARISC:
   10967       return reloc_type == 72; /* R_PARISC_PCREL64.  */
   10968     case EM_PPC64:
   10969       return reloc_type == 44; /* R_PPC64_REL64.  */
   10970     case EM_SPARC32PLUS:
   10971     case EM_SPARCV9:
   10972     case EM_SPARC:
   10973       return reloc_type == 46; /* R_SPARC_DISP64.  */
   10974     case EM_X86_64:
   10975     case EM_L1OM:
   10976     case EM_K1OM:
   10977       return reloc_type == 24; /* R_X86_64_PC64.  */
   10978     case EM_S390_OLD:
   10979     case EM_S390:
   10980       return reloc_type == 23;	/* R_S390_PC64.  */
   10981     case EM_TILEGX:
   10982       return reloc_type == 5;  /* R_TILEGX_64_PCREL.  */
   10983     default:
   10984       return FALSE;
   10985     }
   10986 }
   10987 
   10988 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
   10989    a 24-bit absolute RELA relocation used in DWARF debug sections.  */
   10990 
   10991 static bfd_boolean
   10992 is_24bit_abs_reloc (unsigned int reloc_type)
   10993 {
   10994   switch (elf_header.e_machine)
   10995     {
   10996     case EM_CYGNUS_MN10200:
   10997     case EM_MN10200:
   10998       return reloc_type == 4; /* R_MN10200_24.  */
   10999     default:
   11000       return FALSE;
   11001     }
   11002 }
   11003 
   11004 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
   11005    a 16-bit absolute RELA relocation used in DWARF debug sections.  */
   11006 
   11007 static bfd_boolean
   11008 is_16bit_abs_reloc (unsigned int reloc_type)
   11009 {
   11010   switch (elf_header.e_machine)
   11011     {
   11012     case EM_AVR_OLD:
   11013     case EM_AVR:
   11014       return reloc_type == 4; /* R_AVR_16.  */
   11015     case EM_ADAPTEVA_EPIPHANY:
   11016       return reloc_type == 5;
   11017     case EM_CYGNUS_D10V:
   11018     case EM_D10V:
   11019       return reloc_type == 3; /* R_D10V_16.  */
   11020     case EM_H8S:
   11021     case EM_H8_300:
   11022     case EM_H8_300H:
   11023       return reloc_type == R_H8_DIR16;
   11024     case EM_IP2K_OLD:
   11025     case EM_IP2K:
   11026       return reloc_type == 1; /* R_IP2K_16.  */
   11027     case EM_M32C_OLD:
   11028     case EM_M32C:
   11029       return reloc_type == 1; /* R_M32C_16 */
   11030     case EM_MSP430:
   11031       if (uses_msp430x_relocs ())
   11032 	return reloc_type == 2; /* R_MSP430_ABS16.  */
   11033     case EM_MSP430_OLD:
   11034       return reloc_type == 5; /* R_MSP430_16_BYTE.  */
   11035     case EM_NDS32:
   11036       return reloc_type == 19; /* R_NDS32_RELA.  */
   11037     case EM_ALTERA_NIOS2:
   11038       return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16.  */
   11039     case EM_NIOS32:
   11040       return reloc_type == 9; /* R_NIOS_16.  */
   11041     case EM_OR1K:
   11042       return reloc_type == 2; /* R_OR1K_16.  */
   11043     case EM_TI_C6000:
   11044       return reloc_type == 2; /* R_C6000_ABS16.  */
   11045     case EM_XC16X:
   11046     case EM_C166:
   11047       return reloc_type == 2; /* R_XC16C_ABS_16.  */
   11048     case EM_CYGNUS_MN10200:
   11049     case EM_MN10200:
   11050       return reloc_type == 2; /* R_MN10200_16.  */
   11051     case EM_CYGNUS_MN10300:
   11052     case EM_MN10300:
   11053       return reloc_type == 2; /* R_MN10300_16.  */
   11054     case EM_XGATE:
   11055       return reloc_type == 3; /* R_XGATE_16.  */
   11056     default:
   11057       return FALSE;
   11058     }
   11059 }
   11060 
   11061 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
   11062    relocation entries (possibly formerly used for SHT_GROUP sections).  */
   11063 
   11064 static bfd_boolean
   11065 is_none_reloc (unsigned int reloc_type)
   11066 {
   11067   switch (elf_header.e_machine)
   11068     {
   11069     case EM_68K:     /* R_68K_NONE.  */
   11070     case EM_386:     /* R_386_NONE.  */
   11071     case EM_SPARC32PLUS:
   11072     case EM_SPARCV9:
   11073     case EM_SPARC:   /* R_SPARC_NONE.  */
   11074     case EM_MIPS:    /* R_MIPS_NONE.  */
   11075     case EM_PARISC:  /* R_PARISC_NONE.  */
   11076     case EM_ALPHA:   /* R_ALPHA_NONE.  */
   11077     case EM_ADAPTEVA_EPIPHANY:
   11078     case EM_PPC:     /* R_PPC_NONE.  */
   11079     case EM_PPC64:   /* R_PPC64_NONE.  */
   11080     case EM_ARM:     /* R_ARM_NONE.  */
   11081     case EM_IA_64:   /* R_IA64_NONE.  */
   11082     case EM_SH:      /* R_SH_NONE.  */
   11083     case EM_S390_OLD:
   11084     case EM_S390:    /* R_390_NONE.  */
   11085     case EM_CRIS:    /* R_CRIS_NONE.  */
   11086     case EM_X86_64:  /* R_X86_64_NONE.  */
   11087     case EM_L1OM:    /* R_X86_64_NONE.  */
   11088     case EM_K1OM:    /* R_X86_64_NONE.  */
   11089     case EM_MN10300: /* R_MN10300_NONE.  */
   11090     case EM_MOXIE:   /* R_MOXIE_NONE.  */
   11091     case EM_M32R:    /* R_M32R_NONE.  */
   11092     case EM_TI_C6000:/* R_C6000_NONE.  */
   11093     case EM_TILEGX:  /* R_TILEGX_NONE.  */
   11094     case EM_TILEPRO: /* R_TILEPRO_NONE.  */
   11095     case EM_XC16X:
   11096     case EM_C166:    /* R_XC16X_NONE.  */
   11097     case EM_ALTERA_NIOS2: /* R_NIOS2_NONE.  */
   11098     case EM_NIOS32:  /* R_NIOS_NONE.  */
   11099     case EM_OR1K:    /* R_OR1K_NONE. */
   11100       return reloc_type == 0;
   11101     case EM_AARCH64:
   11102       return reloc_type == 0 || reloc_type == 256;
   11103     case EM_NDS32:
   11104       return (reloc_type == 0       /* R_XTENSA_NONE.  */
   11105 	      || reloc_type == 204  /* R_NDS32_DIFF8.  */
   11106 	      || reloc_type == 205  /* R_NDS32_DIFF16.  */
   11107 	      || reloc_type == 206  /* R_NDS32_DIFF32.  */
   11108 	      || reloc_type == 207  /* R_NDS32_ULEB128.  */);
   11109     case EM_XTENSA_OLD:
   11110     case EM_XTENSA:
   11111       return (reloc_type == 0      /* R_XTENSA_NONE.  */
   11112 	      || reloc_type == 17  /* R_XTENSA_DIFF8.  */
   11113 	      || reloc_type == 18  /* R_XTENSA_DIFF16.  */
   11114 	      || reloc_type == 19  /* R_XTENSA_DIFF32.  */);
   11115     case EM_METAG:
   11116       return reloc_type == 3; /* R_METAG_NONE.  */
   11117     }
   11118   return FALSE;
   11119 }
   11120 
   11121 /* Apply relocations to a section.
   11122    Note: So far support has been added only for those relocations
   11123    which can be found in debug sections.
   11124    FIXME: Add support for more relocations ?  */
   11125 
   11126 static void
   11127 apply_relocations (void * file,
   11128 		   Elf_Internal_Shdr * section,
   11129 		   unsigned char * start)
   11130 {
   11131   Elf_Internal_Shdr * relsec;
   11132   unsigned char * end = start + section->sh_size;
   11133 
   11134   if (elf_header.e_type != ET_REL)
   11135     return;
   11136 
   11137   /* Find the reloc section associated with the section.  */
   11138   for (relsec = section_headers;
   11139        relsec < section_headers + elf_header.e_shnum;
   11140        ++relsec)
   11141     {
   11142       bfd_boolean is_rela;
   11143       unsigned long num_relocs;
   11144       Elf_Internal_Rela * relocs;
   11145       Elf_Internal_Rela * rp;
   11146       Elf_Internal_Shdr * symsec;
   11147       Elf_Internal_Sym * symtab;
   11148       unsigned long num_syms;
   11149       Elf_Internal_Sym * sym;
   11150 
   11151       if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
   11152 	  || relsec->sh_info >= elf_header.e_shnum
   11153 	  || section_headers + relsec->sh_info != section
   11154 	  || relsec->sh_size == 0
   11155 	  || relsec->sh_link >= elf_header.e_shnum)
   11156 	continue;
   11157 
   11158       is_rela = relsec->sh_type == SHT_RELA;
   11159 
   11160       if (is_rela)
   11161 	{
   11162 	  if (!slurp_rela_relocs ((FILE *) file, relsec->sh_offset,
   11163                                   relsec->sh_size, & relocs, & num_relocs))
   11164 	    return;
   11165 	}
   11166       else
   11167 	{
   11168 	  if (!slurp_rel_relocs ((FILE *) file, relsec->sh_offset,
   11169                                  relsec->sh_size, & relocs, & num_relocs))
   11170 	    return;
   11171 	}
   11172 
   11173       /* SH uses RELA but uses in place value instead of the addend field.  */
   11174       if (elf_header.e_machine == EM_SH)
   11175 	is_rela = FALSE;
   11176 
   11177       symsec = section_headers + relsec->sh_link;
   11178       symtab = GET_ELF_SYMBOLS ((FILE *) file, symsec, & num_syms);
   11179 
   11180       for (rp = relocs; rp < relocs + num_relocs; ++rp)
   11181 	{
   11182 	  bfd_vma         addend;
   11183 	  unsigned int    reloc_type;
   11184 	  unsigned int    reloc_size;
   11185 	  unsigned char * rloc;
   11186 	  unsigned long   sym_index;
   11187 
   11188 	  reloc_type = get_reloc_type (rp->r_info);
   11189 
   11190 	  if (target_specific_reloc_handling (rp, start, symtab))
   11191 	    continue;
   11192 	  else if (is_none_reloc (reloc_type))
   11193 	    continue;
   11194 	  else if (is_32bit_abs_reloc (reloc_type)
   11195 		   || is_32bit_pcrel_reloc (reloc_type))
   11196 	    reloc_size = 4;
   11197 	  else if (is_64bit_abs_reloc (reloc_type)
   11198 		   || is_64bit_pcrel_reloc (reloc_type))
   11199 	    reloc_size = 8;
   11200 	  else if (is_24bit_abs_reloc (reloc_type))
   11201 	    reloc_size = 3;
   11202 	  else if (is_16bit_abs_reloc (reloc_type))
   11203 	    reloc_size = 2;
   11204 	  else
   11205 	    {
   11206 	      warn (_("unable to apply unsupported reloc type %d to section %s\n"),
   11207 		    reloc_type, printable_section_name (section));
   11208 	      continue;
   11209 	    }
   11210 
   11211 	  rloc = start + rp->r_offset;
   11212 	  if ((rloc + reloc_size) > end || (rloc < start))
   11213 	    {
   11214 	      warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
   11215 		    (unsigned long) rp->r_offset,
   11216 		    printable_section_name (section));
   11217 	      continue;
   11218 	    }
   11219 
   11220 	  sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
   11221 	  if (sym_index >= num_syms)
   11222 	    {
   11223 	      warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
   11224 		    sym_index, printable_section_name (section));
   11225 	      continue;
   11226 	    }
   11227 	  sym = symtab + sym_index;
   11228 
   11229 	  /* If the reloc has a symbol associated with it,
   11230 	     make sure that it is of an appropriate type.
   11231 
   11232 	     Relocations against symbols without type can happen.
   11233 	     Gcc -feliminate-dwarf2-dups may generate symbols
   11234 	     without type for debug info.
   11235 
   11236 	     Icc generates relocations against function symbols
   11237 	     instead of local labels.
   11238 
   11239 	     Relocations against object symbols can happen, eg when
   11240 	     referencing a global array.  For an example of this see
   11241 	     the _clz.o binary in libgcc.a.  */
   11242 	  if (sym != symtab
   11243 	      && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
   11244 	    {
   11245 	      warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
   11246 		    get_symbol_type (ELF_ST_TYPE (sym->st_info)),
   11247 		    (long int)(rp - relocs),
   11248 		    printable_section_name (relsec));
   11249 	      continue;
   11250 	    }
   11251 
   11252 	  addend = 0;
   11253 	  if (is_rela)
   11254 	    addend += rp->r_addend;
   11255 	  /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
   11256 	     partial_inplace.  */
   11257 	  if (!is_rela
   11258 	      || (elf_header.e_machine == EM_XTENSA
   11259 		  && reloc_type == 1)
   11260 	      || ((elf_header.e_machine == EM_PJ
   11261 		   || elf_header.e_machine == EM_PJ_OLD)
   11262 		  && reloc_type == 1)
   11263 	      || ((elf_header.e_machine == EM_D30V
   11264 		   || elf_header.e_machine == EM_CYGNUS_D30V)
   11265 		  && reloc_type == 12))
   11266 	    addend += byte_get (rloc, reloc_size);
   11267 
   11268 	  if (is_32bit_pcrel_reloc (reloc_type)
   11269 	      || is_64bit_pcrel_reloc (reloc_type))
   11270 	    {
   11271 	      /* On HPPA, all pc-relative relocations are biased by 8.  */
   11272 	      if (elf_header.e_machine == EM_PARISC)
   11273 		addend -= 8;
   11274 	      byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
   11275 		        reloc_size);
   11276 	    }
   11277 	  else
   11278 	    byte_put (rloc, addend + sym->st_value, reloc_size);
   11279 	}
   11280 
   11281       free (symtab);
   11282       free (relocs);
   11283       break;
   11284     }
   11285 }
   11286 
   11287 #ifdef SUPPORT_DISASSEMBLY
   11288 static int
   11289 disassemble_section (Elf_Internal_Shdr * section, FILE * file)
   11290 {
   11291   printf (_("\nAssembly dump of section %s\n"), printable_section_name (section));
   11292 
   11293   /* FIXME: XXX -- to be done --- XXX */
   11294 
   11295   return 1;
   11296 }
   11297 #endif
   11298 
   11299 /* Reads in the contents of SECTION from FILE, returning a pointer
   11300    to a malloc'ed buffer or NULL if something went wrong.  */
   11301 
   11302 static char *
   11303 get_section_contents (Elf_Internal_Shdr * section, FILE * file)
   11304 {
   11305   bfd_size_type num_bytes;
   11306 
   11307   num_bytes = section->sh_size;
   11308 
   11309   if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
   11310     {
   11311       printf (_("\nSection '%s' has no data to dump.\n"),
   11312 	      printable_section_name (section));
   11313       return NULL;
   11314     }
   11315 
   11316   return  (char *) get_data (NULL, file, section->sh_offset, 1, num_bytes,
   11317                              _("section contents"));
   11318 }
   11319 
   11320 
   11321 static void
   11322 dump_section_as_strings (Elf_Internal_Shdr * section, FILE * file)
   11323 {
   11324   Elf_Internal_Shdr * relsec;
   11325   bfd_size_type num_bytes;
   11326   char * data;
   11327   char * end;
   11328   char * start;
   11329   bfd_boolean some_strings_shown;
   11330 
   11331   start = get_section_contents (section, file);
   11332   if (start == NULL)
   11333     return;
   11334 
   11335   printf (_("\nString dump of section '%s':\n"), printable_section_name (section));
   11336 
   11337   /* If the section being dumped has relocations against it the user might
   11338      be expecting these relocations to have been applied.  Check for this
   11339      case and issue a warning message in order to avoid confusion.
   11340      FIXME: Maybe we ought to have an option that dumps a section with
   11341      relocs applied ?  */
   11342   for (relsec = section_headers;
   11343        relsec < section_headers + elf_header.e_shnum;
   11344        ++relsec)
   11345     {
   11346       if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
   11347 	  || relsec->sh_info >= elf_header.e_shnum
   11348 	  || section_headers + relsec->sh_info != section
   11349 	  || relsec->sh_size == 0
   11350 	  || relsec->sh_link >= elf_header.e_shnum)
   11351 	continue;
   11352 
   11353       printf (_("  Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
   11354       break;
   11355     }
   11356 
   11357   num_bytes = section->sh_size;
   11358   data = start;
   11359   end  = start + num_bytes;
   11360   some_strings_shown = FALSE;
   11361 
   11362   while (data < end)
   11363     {
   11364       while (!ISPRINT (* data))
   11365 	if (++ data >= end)
   11366 	  break;
   11367 
   11368       if (data < end)
   11369 	{
   11370 	  size_t maxlen = end - data;
   11371 
   11372 #ifndef __MSVCRT__
   11373 	  /* PR 11128: Use two separate invocations in order to work
   11374              around bugs in the Solaris 8 implementation of printf.  */
   11375 	  printf ("  [%6tx]  ", data - start);
   11376 #else
   11377 	  printf ("  [%6Ix]  ", (size_t) (data - start));
   11378 #endif
   11379 	  if (maxlen > 0)
   11380 	    {
   11381 	      print_symbol ((int) maxlen, data);
   11382 	      putchar ('\n');
   11383 	      data += strnlen (data, maxlen);
   11384 	    }
   11385 	  else
   11386 	    {
   11387 	      printf (_("<corrupt>\n"));
   11388 	      data = end;
   11389 	    }
   11390 	  some_strings_shown = TRUE;
   11391 	}
   11392     }
   11393 
   11394   if (! some_strings_shown)
   11395     printf (_("  No strings found in this section."));
   11396 
   11397   free (start);
   11398 
   11399   putchar ('\n');
   11400 }
   11401 
   11402 static void
   11403 dump_section_as_bytes (Elf_Internal_Shdr * section,
   11404 		       FILE * file,
   11405 		       bfd_boolean relocate)
   11406 {
   11407   Elf_Internal_Shdr * relsec;
   11408   bfd_size_type bytes;
   11409   bfd_vma addr;
   11410   unsigned char * data;
   11411   unsigned char * start;
   11412 
   11413   start = (unsigned char *) get_section_contents (section, file);
   11414   if (start == NULL)
   11415     return;
   11416 
   11417   printf (_("\nHex dump of section '%s':\n"), printable_section_name (section));
   11418 
   11419   if (relocate)
   11420     {
   11421       apply_relocations (file, section, start);
   11422     }
   11423   else
   11424     {
   11425       /* If the section being dumped has relocations against it the user might
   11426 	 be expecting these relocations to have been applied.  Check for this
   11427 	 case and issue a warning message in order to avoid confusion.
   11428 	 FIXME: Maybe we ought to have an option that dumps a section with
   11429 	 relocs applied ?  */
   11430       for (relsec = section_headers;
   11431 	   relsec < section_headers + elf_header.e_shnum;
   11432 	   ++relsec)
   11433 	{
   11434 	  if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
   11435 	      || relsec->sh_info >= elf_header.e_shnum
   11436 	      || section_headers + relsec->sh_info != section
   11437 	      || relsec->sh_size == 0
   11438 	      || relsec->sh_link >= elf_header.e_shnum)
   11439 	    continue;
   11440 
   11441 	  printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
   11442 	  break;
   11443 	}
   11444     }
   11445 
   11446   addr = section->sh_addr;
   11447   bytes = section->sh_size;
   11448   data = start;
   11449 
   11450   while (bytes)
   11451     {
   11452       int j;
   11453       int k;
   11454       int lbytes;
   11455 
   11456       lbytes = (bytes > 16 ? 16 : bytes);
   11457 
   11458       printf ("  0x%8.8lx ", (unsigned long) addr);
   11459 
   11460       for (j = 0; j < 16; j++)
   11461 	{
   11462 	  if (j < lbytes)
   11463 	    printf ("%2.2x", data[j]);
   11464 	  else
   11465 	    printf ("  ");
   11466 
   11467 	  if ((j & 3) == 3)
   11468 	    printf (" ");
   11469 	}
   11470 
   11471       for (j = 0; j < lbytes; j++)
   11472 	{
   11473 	  k = data[j];
   11474 	  if (k >= ' ' && k < 0x7f)
   11475 	    printf ("%c", k);
   11476 	  else
   11477 	    printf (".");
   11478 	}
   11479 
   11480       putchar ('\n');
   11481 
   11482       data  += lbytes;
   11483       addr  += lbytes;
   11484       bytes -= lbytes;
   11485     }
   11486 
   11487   free (start);
   11488 
   11489   putchar ('\n');
   11490 }
   11491 
   11492 /* Uncompresses a section that was compressed using zlib, in place.  */
   11493 
   11494 static int
   11495 uncompress_section_contents (unsigned char **buffer ATTRIBUTE_UNUSED,
   11496 			     dwarf_size_type *size ATTRIBUTE_UNUSED)
   11497 {
   11498 #ifndef HAVE_ZLIB_H
   11499   return FALSE;
   11500 #else
   11501   dwarf_size_type compressed_size = *size;
   11502   unsigned char * compressed_buffer = *buffer;
   11503   dwarf_size_type uncompressed_size;
   11504   unsigned char * uncompressed_buffer;
   11505   z_stream strm;
   11506   int rc;
   11507   dwarf_size_type header_size = 12;
   11508 
   11509   /* Read the zlib header.  In this case, it should be "ZLIB" followed
   11510      by the uncompressed section size, 8 bytes in big-endian order.  */
   11511   if (compressed_size < header_size
   11512       || ! streq ((char *) compressed_buffer, "ZLIB"))
   11513     return 0;
   11514 
   11515   uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
   11516   uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
   11517   uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
   11518   uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
   11519   uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
   11520   uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
   11521   uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
   11522   uncompressed_size += compressed_buffer[11];
   11523 
   11524   /* It is possible the section consists of several compressed
   11525      buffers concatenated together, so we uncompress in a loop.  */
   11526   strm.zalloc = NULL;
   11527   strm.zfree = NULL;
   11528   strm.opaque = NULL;
   11529   strm.avail_in = compressed_size - header_size;
   11530   strm.next_in = (Bytef *) compressed_buffer + header_size;
   11531   strm.avail_out = uncompressed_size;
   11532   uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
   11533 
   11534   rc = inflateInit (& strm);
   11535   while (strm.avail_in > 0)
   11536     {
   11537       if (rc != Z_OK)
   11538         goto fail;
   11539       strm.next_out = ((Bytef *) uncompressed_buffer
   11540                        + (uncompressed_size - strm.avail_out));
   11541       rc = inflate (&strm, Z_FINISH);
   11542       if (rc != Z_STREAM_END)
   11543         goto fail;
   11544       rc = inflateReset (& strm);
   11545     }
   11546   rc = inflateEnd (& strm);
   11547   if (rc != Z_OK
   11548       || strm.avail_out != 0)
   11549     goto fail;
   11550 
   11551   free (compressed_buffer);
   11552   *buffer = uncompressed_buffer;
   11553   *size = uncompressed_size;
   11554   return 1;
   11555 
   11556  fail:
   11557   free (uncompressed_buffer);
   11558   /* Indicate decompression failure.  */
   11559   *buffer = NULL;
   11560   return 0;
   11561 #endif  /* HAVE_ZLIB_H */
   11562 }
   11563 
   11564 static int
   11565 load_specific_debug_section (enum dwarf_section_display_enum debug,
   11566 			     Elf_Internal_Shdr * sec, void * file)
   11567 {
   11568   struct dwarf_section * section = &debug_displays [debug].section;
   11569   char buf [64];
   11570 
   11571   /* If it is already loaded, do nothing.  */
   11572   if (section->start != NULL)
   11573     return 1;
   11574 
   11575   snprintf (buf, sizeof (buf), _("%s section data"), section->name);
   11576   section->address = sec->sh_addr;
   11577   section->start = (unsigned char *) get_data (NULL, (FILE *) file,
   11578                                                sec->sh_offset, 1,
   11579                                                sec->sh_size, buf);
   11580   if (section->start == NULL)
   11581     section->size = 0;
   11582   else
   11583     {
   11584       section->size = sec->sh_size;
   11585       if (uncompress_section_contents (&section->start, &section->size))
   11586 	sec->sh_size = section->size;
   11587     }
   11588 
   11589   if (section->start == NULL)
   11590     return 0;
   11591 
   11592   if (debug_displays [debug].relocate)
   11593     apply_relocations ((FILE *) file, sec, section->start);
   11594 
   11595   return 1;
   11596 }
   11597 
   11598 /* If this is not NULL, load_debug_section will only look for sections
   11599    within the list of sections given here.  */
   11600 unsigned int *section_subset = NULL;
   11601 
   11602 int
   11603 load_debug_section (enum dwarf_section_display_enum debug, void * file)
   11604 {
   11605   struct dwarf_section * section = &debug_displays [debug].section;
   11606   Elf_Internal_Shdr * sec;
   11607 
   11608   /* Locate the debug section.  */
   11609   sec = find_section_in_set (section->uncompressed_name, section_subset);
   11610   if (sec != NULL)
   11611     section->name = section->uncompressed_name;
   11612   else
   11613     {
   11614       sec = find_section_in_set (section->compressed_name, section_subset);
   11615       if (sec != NULL)
   11616 	section->name = section->compressed_name;
   11617     }
   11618   if (sec == NULL)
   11619     return 0;
   11620 
   11621   /* If we're loading from a subset of sections, and we've loaded
   11622      a section matching this name before, it's likely that it's a
   11623      different one.  */
   11624   if (section_subset != NULL)
   11625     free_debug_section (debug);
   11626 
   11627   return load_specific_debug_section (debug, sec, (FILE *) file);
   11628 }
   11629 
   11630 void
   11631 free_debug_section (enum dwarf_section_display_enum debug)
   11632 {
   11633   struct dwarf_section * section = &debug_displays [debug].section;
   11634 
   11635   if (section->start == NULL)
   11636     return;
   11637 
   11638   free ((char *) section->start);
   11639   section->start = NULL;
   11640   section->address = 0;
   11641   section->size = 0;
   11642 }
   11643 
   11644 static int
   11645 display_debug_section (int shndx, Elf_Internal_Shdr * section, FILE * file)
   11646 {
   11647   char * name = SECTION_NAME (section);
   11648   const char * print_name = printable_section_name (section);
   11649   bfd_size_type length;
   11650   int result = 1;
   11651   int i;
   11652 
   11653   length = section->sh_size;
   11654   if (length == 0)
   11655     {
   11656       printf (_("\nSection '%s' has no debugging data.\n"), print_name);
   11657       return 0;
   11658     }
   11659   if (section->sh_type == SHT_NOBITS)
   11660     {
   11661       /* There is no point in dumping the contents of a debugging section
   11662 	 which has the NOBITS type - the bits in the file will be random.
   11663 	 This can happen when a file containing a .eh_frame section is
   11664 	 stripped with the --only-keep-debug command line option.  */
   11665       printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
   11666 	      print_name);
   11667       return 0;
   11668     }
   11669 
   11670   if (const_strneq (name, ".gnu.linkonce.wi."))
   11671     name = ".debug_info";
   11672 
   11673   /* See if we know how to display the contents of this section.  */
   11674   for (i = 0; i < max; i++)
   11675     if (streq (debug_displays[i].section.uncompressed_name, name)
   11676 	|| (i == line && const_strneq (name, ".debug_line."))
   11677         || streq (debug_displays[i].section.compressed_name, name))
   11678       {
   11679 	struct dwarf_section * sec = &debug_displays [i].section;
   11680 	int secondary = (section != find_section (name));
   11681 
   11682 	if (secondary)
   11683 	  free_debug_section ((enum dwarf_section_display_enum) i);
   11684 
   11685 	if (i == line && const_strneq (name, ".debug_line."))
   11686 	  sec->name = name;
   11687 	else if (streq (sec->uncompressed_name, name))
   11688 	  sec->name = sec->uncompressed_name;
   11689 	else
   11690 	  sec->name = sec->compressed_name;
   11691 	if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
   11692                                          section, file))
   11693 	  {
   11694 	    /* If this debug section is part of a CU/TU set in a .dwp file,
   11695 	       restrict load_debug_section to the sections in that set.  */
   11696 	    section_subset = find_cu_tu_set (file, shndx);
   11697 
   11698 	    result &= debug_displays[i].display (sec, file);
   11699 
   11700 	    section_subset = NULL;
   11701 
   11702 	    if (secondary || (i != info && i != abbrev))
   11703 	      free_debug_section ((enum dwarf_section_display_enum) i);
   11704 	  }
   11705 
   11706 	break;
   11707       }
   11708 
   11709   if (i == max)
   11710     {
   11711       printf (_("Unrecognized debug section: %s\n"), print_name);
   11712       result = 0;
   11713     }
   11714 
   11715   return result;
   11716 }
   11717 
   11718 /* Set DUMP_SECTS for all sections where dumps were requested
   11719    based on section name.  */
   11720 
   11721 static void
   11722 initialise_dumps_byname (void)
   11723 {
   11724   struct dump_list_entry * cur;
   11725 
   11726   for (cur = dump_sects_byname; cur; cur = cur->next)
   11727     {
   11728       unsigned int i;
   11729       int any;
   11730 
   11731       for (i = 0, any = 0; i < elf_header.e_shnum; i++)
   11732 	if (streq (SECTION_NAME (section_headers + i), cur->name))
   11733 	  {
   11734 	    request_dump_bynumber (i, cur->type);
   11735 	    any = 1;
   11736 	  }
   11737 
   11738       if (!any)
   11739 	warn (_("Section '%s' was not dumped because it does not exist!\n"),
   11740 	      cur->name);
   11741     }
   11742 }
   11743 
   11744 static void
   11745 process_section_contents (FILE * file)
   11746 {
   11747   Elf_Internal_Shdr * section;
   11748   unsigned int i;
   11749 
   11750   if (! do_dump)
   11751     return;
   11752 
   11753   initialise_dumps_byname ();
   11754 
   11755   for (i = 0, section = section_headers;
   11756        i < elf_header.e_shnum && i < num_dump_sects;
   11757        i++, section++)
   11758     {
   11759 #ifdef SUPPORT_DISASSEMBLY
   11760       if (dump_sects[i] & DISASS_DUMP)
   11761 	disassemble_section (section, file);
   11762 #endif
   11763       if (dump_sects[i] & HEX_DUMP)
   11764 	dump_section_as_bytes (section, file, FALSE);
   11765 
   11766       if (dump_sects[i] & RELOC_DUMP)
   11767 	dump_section_as_bytes (section, file, TRUE);
   11768 
   11769       if (dump_sects[i] & STRING_DUMP)
   11770 	dump_section_as_strings (section, file);
   11771 
   11772       if (dump_sects[i] & DEBUG_DUMP)
   11773 	display_debug_section (i, section, file);
   11774     }
   11775 
   11776   /* Check to see if the user requested a
   11777      dump of a section that does not exist.  */
   11778   while (i++ < num_dump_sects)
   11779     if (dump_sects[i])
   11780       warn (_("Section %d was not dumped because it does not exist!\n"), i);
   11781 }
   11782 
   11783 static void
   11784 process_mips_fpe_exception (int mask)
   11785 {
   11786   if (mask)
   11787     {
   11788       int first = 1;
   11789       if (mask & OEX_FPU_INEX)
   11790 	fputs ("INEX", stdout), first = 0;
   11791       if (mask & OEX_FPU_UFLO)
   11792 	printf ("%sUFLO", first ? "" : "|"), first = 0;
   11793       if (mask & OEX_FPU_OFLO)
   11794 	printf ("%sOFLO", first ? "" : "|"), first = 0;
   11795       if (mask & OEX_FPU_DIV0)
   11796 	printf ("%sDIV0", first ? "" : "|"), first = 0;
   11797       if (mask & OEX_FPU_INVAL)
   11798 	printf ("%sINVAL", first ? "" : "|");
   11799     }
   11800   else
   11801     fputs ("0", stdout);
   11802 }
   11803 
   11804 /* Display's the value of TAG at location P.  If TAG is
   11805    greater than 0 it is assumed to be an unknown tag, and
   11806    a message is printed to this effect.  Otherwise it is
   11807    assumed that a message has already been printed.
   11808 
   11809    If the bottom bit of TAG is set it assumed to have a
   11810    string value, otherwise it is assumed to have an integer
   11811    value.
   11812 
   11813    Returns an updated P pointing to the first unread byte
   11814    beyond the end of TAG's value.
   11815 
   11816    Reads at or beyond END will not be made.  */
   11817 
   11818 static unsigned char *
   11819 display_tag_value (int tag,
   11820 		   unsigned char * p,
   11821 		   const unsigned char * const end)
   11822 {
   11823   unsigned long val;
   11824 
   11825   if (tag > 0)
   11826     printf ("  Tag_unknown_%d: ", tag);
   11827 
   11828   if (p >= end)
   11829     {
   11830       warn (_("<corrupt tag>\n"));
   11831     }
   11832   else if (tag & 1)
   11833     {
   11834       /* PR 17531 file: 027-19978-0.004.  */
   11835       size_t maxlen = (end - p) - 1;
   11836 
   11837       putchar ('"');
   11838       if (maxlen > 0)
   11839 	{
   11840 	  print_symbol ((int) maxlen, (const char *) p);
   11841 	  p += strnlen ((char *) p, maxlen) + 1;
   11842 	}
   11843       else
   11844 	{
   11845 	  printf (_("<corrupt string tag>"));
   11846 	  p = (unsigned char *) end;
   11847 	}
   11848       printf ("\"\n");
   11849     }
   11850   else
   11851     {
   11852       unsigned int len;
   11853 
   11854       val = read_uleb128 (p, &len, end);
   11855       p += len;
   11856       printf ("%ld (0x%lx)\n", val, val);
   11857     }
   11858 
   11859   assert (p <= end);
   11860   return p;
   11861 }
   11862 
   11863 /* ARM EABI attributes section.  */
   11864 typedef struct
   11865 {
   11866   unsigned int tag;
   11867   const char * name;
   11868   /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup.  */
   11869   unsigned int type;
   11870   const char ** table;
   11871 } arm_attr_public_tag;
   11872 
   11873 static const char * arm_attr_tag_CPU_arch[] =
   11874   {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
   11875    "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8"};
   11876 static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
   11877 static const char * arm_attr_tag_THUMB_ISA_use[] =
   11878   {"No", "Thumb-1", "Thumb-2"};
   11879 static const char * arm_attr_tag_FP_arch[] =
   11880   {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
   11881    "FP for ARMv8"};
   11882 static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
   11883 static const char * arm_attr_tag_Advanced_SIMD_arch[] =
   11884   {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8"};
   11885 static const char * arm_attr_tag_PCS_config[] =
   11886   {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
   11887    "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
   11888 static const char * arm_attr_tag_ABI_PCS_R9_use[] =
   11889   {"V6", "SB", "TLS", "Unused"};
   11890 static const char * arm_attr_tag_ABI_PCS_RW_data[] =
   11891   {"Absolute", "PC-relative", "SB-relative", "None"};
   11892 static const char * arm_attr_tag_ABI_PCS_RO_data[] =
   11893   {"Absolute", "PC-relative", "None"};
   11894 static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
   11895   {"None", "direct", "GOT-indirect"};
   11896 static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
   11897   {"None", "??? 1", "2", "??? 3", "4"};
   11898 static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
   11899 static const char * arm_attr_tag_ABI_FP_denormal[] =
   11900   {"Unused", "Needed", "Sign only"};
   11901 static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
   11902 static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
   11903 static const char * arm_attr_tag_ABI_FP_number_model[] =
   11904   {"Unused", "Finite", "RTABI", "IEEE 754"};
   11905 static const char * arm_attr_tag_ABI_enum_size[] =
   11906   {"Unused", "small", "int", "forced to int"};
   11907 static const char * arm_attr_tag_ABI_HardFP_use[] =
   11908   {"As Tag_FP_arch", "SP only", "DP only", "SP and DP"};
   11909 static const char * arm_attr_tag_ABI_VFP_args[] =
   11910   {"AAPCS", "VFP registers", "custom", "compatible"};
   11911 static const char * arm_attr_tag_ABI_WMMX_args[] =
   11912   {"AAPCS", "WMMX registers", "custom"};
   11913 static const char * arm_attr_tag_ABI_optimization_goals[] =
   11914   {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
   11915     "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
   11916 static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
   11917   {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
   11918     "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
   11919 static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
   11920 static const char * arm_attr_tag_FP_HP_extension[] =
   11921   {"Not Allowed", "Allowed"};
   11922 static const char * arm_attr_tag_ABI_FP_16bit_format[] =
   11923   {"None", "IEEE 754", "Alternative Format"};
   11924 static const char * arm_attr_tag_MPextension_use[] =
   11925   {"Not Allowed", "Allowed"};
   11926 static const char * arm_attr_tag_DIV_use[] =
   11927   {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
   11928     "Allowed in v7-A with integer division extension"};
   11929 static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
   11930 static const char * arm_attr_tag_Virtualization_use[] =
   11931   {"Not Allowed", "TrustZone", "Virtualization Extensions",
   11932     "TrustZone and Virtualization Extensions"};
   11933 static const char * arm_attr_tag_MPextension_use_legacy[] =
   11934   {"Not Allowed", "Allowed"};
   11935 
   11936 #define LOOKUP(id, name) \
   11937   {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
   11938 static arm_attr_public_tag arm_attr_public_tags[] =
   11939 {
   11940   {4, "CPU_raw_name", 1, NULL},
   11941   {5, "CPU_name", 1, NULL},
   11942   LOOKUP(6, CPU_arch),
   11943   {7, "CPU_arch_profile", 0, NULL},
   11944   LOOKUP(8, ARM_ISA_use),
   11945   LOOKUP(9, THUMB_ISA_use),
   11946   LOOKUP(10, FP_arch),
   11947   LOOKUP(11, WMMX_arch),
   11948   LOOKUP(12, Advanced_SIMD_arch),
   11949   LOOKUP(13, PCS_config),
   11950   LOOKUP(14, ABI_PCS_R9_use),
   11951   LOOKUP(15, ABI_PCS_RW_data),
   11952   LOOKUP(16, ABI_PCS_RO_data),
   11953   LOOKUP(17, ABI_PCS_GOT_use),
   11954   LOOKUP(18, ABI_PCS_wchar_t),
   11955   LOOKUP(19, ABI_FP_rounding),
   11956   LOOKUP(20, ABI_FP_denormal),
   11957   LOOKUP(21, ABI_FP_exceptions),
   11958   LOOKUP(22, ABI_FP_user_exceptions),
   11959   LOOKUP(23, ABI_FP_number_model),
   11960   {24, "ABI_align_needed", 0, NULL},
   11961   {25, "ABI_align_preserved", 0, NULL},
   11962   LOOKUP(26, ABI_enum_size),
   11963   LOOKUP(27, ABI_HardFP_use),
   11964   LOOKUP(28, ABI_VFP_args),
   11965   LOOKUP(29, ABI_WMMX_args),
   11966   LOOKUP(30, ABI_optimization_goals),
   11967   LOOKUP(31, ABI_FP_optimization_goals),
   11968   {32, "compatibility", 0, NULL},
   11969   LOOKUP(34, CPU_unaligned_access),
   11970   LOOKUP(36, FP_HP_extension),
   11971   LOOKUP(38, ABI_FP_16bit_format),
   11972   LOOKUP(42, MPextension_use),
   11973   LOOKUP(44, DIV_use),
   11974   {64, "nodefaults", 0, NULL},
   11975   {65, "also_compatible_with", 0, NULL},
   11976   LOOKUP(66, T2EE_use),
   11977   {67, "conformance", 1, NULL},
   11978   LOOKUP(68, Virtualization_use),
   11979   LOOKUP(70, MPextension_use_legacy)
   11980 };
   11981 #undef LOOKUP
   11982 
   11983 static unsigned char *
   11984 display_arm_attribute (unsigned char * p,
   11985 		       const unsigned char * const end)
   11986 {
   11987   unsigned int tag;
   11988   unsigned int len;
   11989   unsigned int val;
   11990   arm_attr_public_tag * attr;
   11991   unsigned i;
   11992   unsigned int type;
   11993 
   11994   tag = read_uleb128 (p, &len, end);
   11995   p += len;
   11996   attr = NULL;
   11997   for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
   11998     {
   11999       if (arm_attr_public_tags[i].tag == tag)
   12000 	{
   12001 	  attr = &arm_attr_public_tags[i];
   12002 	  break;
   12003 	}
   12004     }
   12005 
   12006   if (attr)
   12007     {
   12008       printf ("  Tag_%s: ", attr->name);
   12009       switch (attr->type)
   12010 	{
   12011 	case 0:
   12012 	  switch (tag)
   12013 	    {
   12014 	    case 7: /* Tag_CPU_arch_profile.  */
   12015 	      val = read_uleb128 (p, &len, end);
   12016 	      p += len;
   12017 	      switch (val)
   12018 		{
   12019 		case 0: printf (_("None\n")); break;
   12020 		case 'A': printf (_("Application\n")); break;
   12021 		case 'R': printf (_("Realtime\n")); break;
   12022 		case 'M': printf (_("Microcontroller\n")); break;
   12023 		case 'S': printf (_("Application or Realtime\n")); break;
   12024 		default: printf ("??? (%d)\n", val); break;
   12025 		}
   12026 	      break;
   12027 
   12028 	    case 24: /* Tag_align_needed.  */
   12029 	      val = read_uleb128 (p, &len, end);
   12030 	      p += len;
   12031 	      switch (val)
   12032 		{
   12033 		case 0: printf (_("None\n")); break;
   12034 		case 1: printf (_("8-byte\n")); break;
   12035 		case 2: printf (_("4-byte\n")); break;
   12036 		case 3: printf ("??? 3\n"); break;
   12037 		default:
   12038 		  if (val <= 12)
   12039 		    printf (_("8-byte and up to %d-byte extended\n"),
   12040 			    1 << val);
   12041 		  else
   12042 		    printf ("??? (%d)\n", val);
   12043 		  break;
   12044 		}
   12045 	      break;
   12046 
   12047 	    case 25: /* Tag_align_preserved.  */
   12048 	      val = read_uleb128 (p, &len, end);
   12049 	      p += len;
   12050 	      switch (val)
   12051 		{
   12052 		case 0: printf (_("None\n")); break;
   12053 		case 1: printf (_("8-byte, except leaf SP\n")); break;
   12054 		case 2: printf (_("8-byte\n")); break;
   12055 		case 3: printf ("??? 3\n"); break;
   12056 		default:
   12057 		  if (val <= 12)
   12058 		    printf (_("8-byte and up to %d-byte extended\n"),
   12059 			    1 << val);
   12060 		  else
   12061 		    printf ("??? (%d)\n", val);
   12062 		  break;
   12063 		}
   12064 	      break;
   12065 
   12066 	    case 32: /* Tag_compatibility.  */
   12067 	      {
   12068 		val = read_uleb128 (p, &len, end);
   12069 		p += len;
   12070 		printf (_("flag = %d, vendor = "), val);
   12071 		if (p < end - 1)
   12072 		  {
   12073 		    size_t maxlen = (end - p) - 1;
   12074 
   12075 		    print_symbol ((int) maxlen, (const char *) p);
   12076 		    p += strnlen ((char *) p, maxlen) + 1;
   12077 		  }
   12078 		else
   12079 		  {
   12080 		    printf (_("<corrupt>"));
   12081 		    p = (unsigned char *) end;
   12082 		  }
   12083 		putchar ('\n');
   12084 	      }
   12085 	      break;
   12086 
   12087 	    case 64: /* Tag_nodefaults.  */
   12088 	      /* PR 17531: file: 001-505008-0.01.  */
   12089 	      if (p < end)
   12090 		p++;
   12091 	      printf (_("True\n"));
   12092 	      break;
   12093 
   12094 	    case 65: /* Tag_also_compatible_with.  */
   12095 	      val = read_uleb128 (p, &len, end);
   12096 	      p += len;
   12097 	      if (val == 6 /* Tag_CPU_arch.  */)
   12098 		{
   12099 		  val = read_uleb128 (p, &len, end);
   12100 		  p += len;
   12101 		  if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
   12102 		    printf ("??? (%d)\n", val);
   12103 		  else
   12104 		    printf ("%s\n", arm_attr_tag_CPU_arch[val]);
   12105 		}
   12106 	      else
   12107 		printf ("???\n");
   12108 	      while (p < end && *(p++) != '\0' /* NUL terminator.  */)
   12109 		;
   12110 	      break;
   12111 
   12112 	    default:
   12113 	      abort ();
   12114 	    }
   12115 	  return p;
   12116 
   12117 	case 1:
   12118 	  return display_tag_value (-1, p, end);
   12119 	case 2:
   12120 	  return display_tag_value (0, p, end);
   12121 
   12122 	default:
   12123 	  assert (attr->type & 0x80);
   12124 	  val = read_uleb128 (p, &len, end);
   12125 	  p += len;
   12126 	  type = attr->type & 0x7f;
   12127 	  if (val >= type)
   12128 	    printf ("??? (%d)\n", val);
   12129 	  else
   12130 	    printf ("%s\n", attr->table[val]);
   12131 	  return p;
   12132 	}
   12133     }
   12134 
   12135   return display_tag_value (tag, p, end);
   12136 }
   12137 
   12138 static unsigned char *
   12139 display_gnu_attribute (unsigned char * p,
   12140 		       unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int, const unsigned char * const),
   12141 		       const unsigned char * const end)
   12142 {
   12143   int tag;
   12144   unsigned int len;
   12145   int val;
   12146 
   12147   tag = read_uleb128 (p, &len, end);
   12148   p += len;
   12149 
   12150   /* Tag_compatibility is the only generic GNU attribute defined at
   12151      present.  */
   12152   if (tag == 32)
   12153     {
   12154       val = read_uleb128 (p, &len, end);
   12155       p += len;
   12156 
   12157       printf (_("flag = %d, vendor = "), val);
   12158       if (p == end)
   12159 	{
   12160 	  printf (_("<corrupt>\n"));
   12161 	  warn (_("corrupt vendor attribute\n"));
   12162 	}
   12163       else
   12164 	{
   12165 	  if (p < end - 1)
   12166 	    {
   12167 	      size_t maxlen = (end - p) - 1;
   12168 
   12169 	      print_symbol ((int) maxlen, (const char *) p);
   12170 	      p += strnlen ((char *) p, maxlen) + 1;
   12171 	    }
   12172 	  else
   12173 	    {
   12174 	      printf (_("<corrupt>"));
   12175 	      p = (unsigned char *) end;
   12176 	    }
   12177 	  putchar ('\n');
   12178 	}
   12179       return p;
   12180     }
   12181 
   12182   if ((tag & 2) == 0 && display_proc_gnu_attribute)
   12183     return display_proc_gnu_attribute (p, tag, end);
   12184 
   12185   return display_tag_value (tag, p, end);
   12186 }
   12187 
   12188 static unsigned char *
   12189 display_power_gnu_attribute (unsigned char * p,
   12190 			     int tag,
   12191 			     const unsigned char * const end)
   12192 {
   12193   unsigned int len;
   12194   int val;
   12195 
   12196   if (tag == Tag_GNU_Power_ABI_FP)
   12197     {
   12198       val = read_uleb128 (p, &len, end);
   12199       p += len;
   12200       printf ("  Tag_GNU_Power_ABI_FP: ");
   12201 
   12202       switch (val)
   12203 	{
   12204 	case 0:
   12205 	  printf (_("Hard or soft float\n"));
   12206 	  break;
   12207 	case 1:
   12208 	  printf (_("Hard float\n"));
   12209 	  break;
   12210 	case 2:
   12211 	  printf (_("Soft float\n"));
   12212 	  break;
   12213 	case 3:
   12214 	  printf (_("Single-precision hard float\n"));
   12215 	  break;
   12216 	default:
   12217 	  printf ("??? (%d)\n", val);
   12218 	  break;
   12219 	}
   12220       return p;
   12221    }
   12222 
   12223   if (tag == Tag_GNU_Power_ABI_Vector)
   12224     {
   12225       val = read_uleb128 (p, &len, end);
   12226       p += len;
   12227       printf ("  Tag_GNU_Power_ABI_Vector: ");
   12228       switch (val)
   12229 	{
   12230 	case 0:
   12231 	  printf (_("Any\n"));
   12232 	  break;
   12233 	case 1:
   12234 	  printf (_("Generic\n"));
   12235 	  break;
   12236 	case 2:
   12237 	  printf ("AltiVec\n");
   12238 	  break;
   12239 	case 3:
   12240 	  printf ("SPE\n");
   12241 	  break;
   12242 	default:
   12243 	  printf ("??? (%d)\n", val);
   12244 	  break;
   12245 	}
   12246       return p;
   12247    }
   12248 
   12249   if (tag == Tag_GNU_Power_ABI_Struct_Return)
   12250     {
   12251       if (p == end)
   12252 	{
   12253 	  warn (_("corrupt Tag_GNU_Power_ABI_Struct_Return\n"));
   12254 	  return p;
   12255 	}
   12256 
   12257       val = read_uleb128 (p, &len, end);
   12258       p += len;
   12259       printf ("  Tag_GNU_Power_ABI_Struct_Return: ");
   12260       switch (val)
   12261        {
   12262        case 0:
   12263          printf (_("Any\n"));
   12264          break;
   12265        case 1:
   12266          printf ("r3/r4\n");
   12267          break;
   12268        case 2:
   12269          printf (_("Memory\n"));
   12270          break;
   12271        default:
   12272          printf ("??? (%d)\n", val);
   12273          break;
   12274        }
   12275       return p;
   12276     }
   12277 
   12278   return display_tag_value (tag & 1, p, end);
   12279 }
   12280 
   12281 static void
   12282 display_sparc_hwcaps (int mask)
   12283 {
   12284   if (mask)
   12285     {
   12286       int first = 1;
   12287 
   12288       if (mask & ELF_SPARC_HWCAP_MUL32)
   12289 	fputs ("mul32", stdout), first = 0;
   12290       if (mask & ELF_SPARC_HWCAP_DIV32)
   12291 	printf ("%sdiv32", first ? "" : "|"), first = 0;
   12292       if (mask & ELF_SPARC_HWCAP_FSMULD)
   12293 	printf ("%sfsmuld", first ? "" : "|"), first = 0;
   12294       if (mask & ELF_SPARC_HWCAP_V8PLUS)
   12295 	printf ("%sv8plus", first ? "" : "|"), first = 0;
   12296       if (mask & ELF_SPARC_HWCAP_POPC)
   12297 	printf ("%spopc", first ? "" : "|"), first = 0;
   12298       if (mask & ELF_SPARC_HWCAP_VIS)
   12299 	printf ("%svis", first ? "" : "|"), first = 0;
   12300       if (mask & ELF_SPARC_HWCAP_VIS2)
   12301 	printf ("%svis2", first ? "" : "|"), first = 0;
   12302       if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
   12303 	printf ("%sASIBlkInit", first ? "" : "|"), first = 0;
   12304       if (mask & ELF_SPARC_HWCAP_FMAF)
   12305 	printf ("%sfmaf", first ? "" : "|"), first = 0;
   12306       if (mask & ELF_SPARC_HWCAP_VIS3)
   12307 	printf ("%svis3", first ? "" : "|"), first = 0;
   12308       if (mask & ELF_SPARC_HWCAP_HPC)
   12309 	printf ("%shpc", first ? "" : "|"), first = 0;
   12310       if (mask & ELF_SPARC_HWCAP_RANDOM)
   12311 	printf ("%srandom", first ? "" : "|"), first = 0;
   12312       if (mask & ELF_SPARC_HWCAP_TRANS)
   12313 	printf ("%strans", first ? "" : "|"), first = 0;
   12314       if (mask & ELF_SPARC_HWCAP_FJFMAU)
   12315 	printf ("%sfjfmau", first ? "" : "|"), first = 0;
   12316       if (mask & ELF_SPARC_HWCAP_IMA)
   12317 	printf ("%sima", first ? "" : "|"), first = 0;
   12318       if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
   12319 	printf ("%scspare", first ? "" : "|"), first = 0;
   12320     }
   12321   else
   12322     fputc ('0', stdout);
   12323   fputc ('\n', stdout);
   12324 }
   12325 
   12326 static void
   12327 display_sparc_hwcaps2 (int mask)
   12328 {
   12329   if (mask)
   12330     {
   12331       int first = 1;
   12332 
   12333       if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
   12334 	fputs ("fjathplus", stdout), first = 0;
   12335       if (mask & ELF_SPARC_HWCAP2_VIS3B)
   12336 	printf ("%svis3b", first ? "" : "|"), first = 0;
   12337       if (mask & ELF_SPARC_HWCAP2_ADP)
   12338 	printf ("%sadp", first ? "" : "|"), first = 0;
   12339       if (mask & ELF_SPARC_HWCAP2_SPARC5)
   12340 	printf ("%ssparc5", first ? "" : "|"), first = 0;
   12341       if (mask & ELF_SPARC_HWCAP2_MWAIT)
   12342 	printf ("%smwait", first ? "" : "|"), first = 0;
   12343       if (mask & ELF_SPARC_HWCAP2_XMPMUL)
   12344 	printf ("%sxmpmul", first ? "" : "|"), first = 0;
   12345       if (mask & ELF_SPARC_HWCAP2_XMONT)
   12346 	printf ("%sxmont2", first ? "" : "|"), first = 0;
   12347       if (mask & ELF_SPARC_HWCAP2_NSEC)
   12348 	printf ("%snsec", first ? "" : "|"), first = 0;
   12349       if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
   12350 	printf ("%sfjathhpc", first ? "" : "|"), first = 0;
   12351       if (mask & ELF_SPARC_HWCAP2_FJDES)
   12352 	printf ("%sfjdes", first ? "" : "|"), first = 0;
   12353       if (mask & ELF_SPARC_HWCAP2_FJAES)
   12354 	printf ("%sfjaes", first ? "" : "|"), first = 0;
   12355     }
   12356   else
   12357     fputc ('0', stdout);
   12358   fputc ('\n', stdout);
   12359 }
   12360 
   12361 static unsigned char *
   12362 display_sparc_gnu_attribute (unsigned char * p,
   12363 			     int tag,
   12364 			     const unsigned char * const end)
   12365 {
   12366   unsigned int len;
   12367   int val;
   12368 
   12369   if (tag == Tag_GNU_Sparc_HWCAPS)
   12370     {
   12371       val = read_uleb128 (p, &len, end);
   12372       p += len;
   12373       printf ("  Tag_GNU_Sparc_HWCAPS: ");
   12374       display_sparc_hwcaps (val);
   12375       return p;
   12376     }
   12377   if (tag == Tag_GNU_Sparc_HWCAPS2)
   12378     {
   12379       val = read_uleb128 (p, &len, end);
   12380       p += len;
   12381       printf ("  Tag_GNU_Sparc_HWCAPS2: ");
   12382       display_sparc_hwcaps2 (val);
   12383       return p;
   12384     }
   12385 
   12386   return display_tag_value (tag, p, end);
   12387 }
   12388 
   12389 static void
   12390 print_mips_fp_abi_value (int val)
   12391 {
   12392   switch (val)
   12393     {
   12394     case Val_GNU_MIPS_ABI_FP_ANY:
   12395       printf (_("Hard or soft float\n"));
   12396       break;
   12397     case Val_GNU_MIPS_ABI_FP_DOUBLE:
   12398       printf (_("Hard float (double precision)\n"));
   12399       break;
   12400     case Val_GNU_MIPS_ABI_FP_SINGLE:
   12401       printf (_("Hard float (single precision)\n"));
   12402       break;
   12403     case Val_GNU_MIPS_ABI_FP_SOFT:
   12404       printf (_("Soft float\n"));
   12405       break;
   12406     case Val_GNU_MIPS_ABI_FP_OLD_64:
   12407       printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
   12408       break;
   12409     case Val_GNU_MIPS_ABI_FP_XX:
   12410       printf (_("Hard float (32-bit CPU, Any FPU)\n"));
   12411       break;
   12412     case Val_GNU_MIPS_ABI_FP_64:
   12413       printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
   12414       break;
   12415     case Val_GNU_MIPS_ABI_FP_64A:
   12416       printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
   12417       break;
   12418     default:
   12419       printf ("??? (%d)\n", val);
   12420       break;
   12421     }
   12422 }
   12423 
   12424 static unsigned char *
   12425 display_mips_gnu_attribute (unsigned char * p,
   12426 			    int tag,
   12427 			    const unsigned char * const end)
   12428 {
   12429   if (tag == Tag_GNU_MIPS_ABI_FP)
   12430     {
   12431       unsigned int len;
   12432       int val;
   12433 
   12434       val = read_uleb128 (p, &len, end);
   12435       p += len;
   12436       printf ("  Tag_GNU_MIPS_ABI_FP: ");
   12437 
   12438       print_mips_fp_abi_value (val);
   12439 
   12440       return p;
   12441    }
   12442 
   12443   if (tag == Tag_GNU_MIPS_ABI_MSA)
   12444     {
   12445       unsigned int len;
   12446       int val;
   12447 
   12448       val = read_uleb128 (p, &len, end);
   12449       p += len;
   12450       printf ("  Tag_GNU_MIPS_ABI_MSA: ");
   12451 
   12452       switch (val)
   12453 	{
   12454 	case Val_GNU_MIPS_ABI_MSA_ANY:
   12455 	  printf (_("Any MSA or not\n"));
   12456 	  break;
   12457 	case Val_GNU_MIPS_ABI_MSA_128:
   12458 	  printf (_("128-bit MSA\n"));
   12459 	  break;
   12460 	default:
   12461 	  printf ("??? (%d)\n", val);
   12462 	  break;
   12463 	}
   12464       return p;
   12465     }
   12466 
   12467   return display_tag_value (tag & 1, p, end);
   12468 }
   12469 
   12470 static unsigned char *
   12471 display_tic6x_attribute (unsigned char * p,
   12472 			 const unsigned char * const end)
   12473 {
   12474   int tag;
   12475   unsigned int len;
   12476   int val;
   12477 
   12478   tag = read_uleb128 (p, &len, end);
   12479   p += len;
   12480 
   12481   switch (tag)
   12482     {
   12483     case Tag_ISA:
   12484       val = read_uleb128 (p, &len, end);
   12485       p += len;
   12486       printf ("  Tag_ISA: ");
   12487 
   12488       switch (val)
   12489 	{
   12490 	case C6XABI_Tag_ISA_none:
   12491 	  printf (_("None\n"));
   12492 	  break;
   12493 	case C6XABI_Tag_ISA_C62X:
   12494 	  printf ("C62x\n");
   12495 	  break;
   12496 	case C6XABI_Tag_ISA_C67X:
   12497 	  printf ("C67x\n");
   12498 	  break;
   12499 	case C6XABI_Tag_ISA_C67XP:
   12500 	  printf ("C67x+\n");
   12501 	  break;
   12502 	case C6XABI_Tag_ISA_C64X:
   12503 	  printf ("C64x\n");
   12504 	  break;
   12505 	case C6XABI_Tag_ISA_C64XP:
   12506 	  printf ("C64x+\n");
   12507 	  break;
   12508 	case C6XABI_Tag_ISA_C674X:
   12509 	  printf ("C674x\n");
   12510 	  break;
   12511 	default:
   12512 	  printf ("??? (%d)\n", val);
   12513 	  break;
   12514 	}
   12515       return p;
   12516 
   12517     case Tag_ABI_wchar_t:
   12518       val = read_uleb128 (p, &len, end);
   12519       p += len;
   12520       printf ("  Tag_ABI_wchar_t: ");
   12521       switch (val)
   12522 	{
   12523 	case 0:
   12524 	  printf (_("Not used\n"));
   12525 	  break;
   12526 	case 1:
   12527 	  printf (_("2 bytes\n"));
   12528 	  break;
   12529 	case 2:
   12530 	  printf (_("4 bytes\n"));
   12531 	  break;
   12532 	default:
   12533 	  printf ("??? (%d)\n", val);
   12534 	  break;
   12535 	}
   12536       return p;
   12537 
   12538     case Tag_ABI_stack_align_needed:
   12539       val = read_uleb128 (p, &len, end);
   12540       p += len;
   12541       printf ("  Tag_ABI_stack_align_needed: ");
   12542       switch (val)
   12543 	{
   12544 	case 0:
   12545 	  printf (_("8-byte\n"));
   12546 	  break;
   12547 	case 1:
   12548 	  printf (_("16-byte\n"));
   12549 	  break;
   12550 	default:
   12551 	  printf ("??? (%d)\n", val);
   12552 	  break;
   12553 	}
   12554       return p;
   12555 
   12556     case Tag_ABI_stack_align_preserved:
   12557       val = read_uleb128 (p, &len, end);
   12558       p += len;
   12559       printf ("  Tag_ABI_stack_align_preserved: ");
   12560       switch (val)
   12561 	{
   12562 	case 0:
   12563 	  printf (_("8-byte\n"));
   12564 	  break;
   12565 	case 1:
   12566 	  printf (_("16-byte\n"));
   12567 	  break;
   12568 	default:
   12569 	  printf ("??? (%d)\n", val);
   12570 	  break;
   12571 	}
   12572       return p;
   12573 
   12574     case Tag_ABI_DSBT:
   12575       val = read_uleb128 (p, &len, end);
   12576       p += len;
   12577       printf ("  Tag_ABI_DSBT: ");
   12578       switch (val)
   12579 	{
   12580 	case 0:
   12581 	  printf (_("DSBT addressing not used\n"));
   12582 	  break;
   12583 	case 1:
   12584 	  printf (_("DSBT addressing used\n"));
   12585 	  break;
   12586 	default:
   12587 	  printf ("??? (%d)\n", val);
   12588 	  break;
   12589 	}
   12590       return p;
   12591 
   12592     case Tag_ABI_PID:
   12593       val = read_uleb128 (p, &len, end);
   12594       p += len;
   12595       printf ("  Tag_ABI_PID: ");
   12596       switch (val)
   12597 	{
   12598 	case 0:
   12599 	  printf (_("Data addressing position-dependent\n"));
   12600 	  break;
   12601 	case 1:
   12602 	  printf (_("Data addressing position-independent, GOT near DP\n"));
   12603 	  break;
   12604 	case 2:
   12605 	  printf (_("Data addressing position-independent, GOT far from DP\n"));
   12606 	  break;
   12607 	default:
   12608 	  printf ("??? (%d)\n", val);
   12609 	  break;
   12610 	}
   12611       return p;
   12612 
   12613     case Tag_ABI_PIC:
   12614       val = read_uleb128 (p, &len, end);
   12615       p += len;
   12616       printf ("  Tag_ABI_PIC: ");
   12617       switch (val)
   12618 	{
   12619 	case 0:
   12620 	  printf (_("Code addressing position-dependent\n"));
   12621 	  break;
   12622 	case 1:
   12623 	  printf (_("Code addressing position-independent\n"));
   12624 	  break;
   12625 	default:
   12626 	  printf ("??? (%d)\n", val);
   12627 	  break;
   12628 	}
   12629       return p;
   12630 
   12631     case Tag_ABI_array_object_alignment:
   12632       val = read_uleb128 (p, &len, end);
   12633       p += len;
   12634       printf ("  Tag_ABI_array_object_alignment: ");
   12635       switch (val)
   12636 	{
   12637 	case 0:
   12638 	  printf (_("8-byte\n"));
   12639 	  break;
   12640 	case 1:
   12641 	  printf (_("4-byte\n"));
   12642 	  break;
   12643 	case 2:
   12644 	  printf (_("16-byte\n"));
   12645 	  break;
   12646 	default:
   12647 	  printf ("??? (%d)\n", val);
   12648 	  break;
   12649 	}
   12650       return p;
   12651 
   12652     case Tag_ABI_array_object_align_expected:
   12653       val = read_uleb128 (p, &len, end);
   12654       p += len;
   12655       printf ("  Tag_ABI_array_object_align_expected: ");
   12656       switch (val)
   12657 	{
   12658 	case 0:
   12659 	  printf (_("8-byte\n"));
   12660 	  break;
   12661 	case 1:
   12662 	  printf (_("4-byte\n"));
   12663 	  break;
   12664 	case 2:
   12665 	  printf (_("16-byte\n"));
   12666 	  break;
   12667 	default:
   12668 	  printf ("??? (%d)\n", val);
   12669 	  break;
   12670 	}
   12671       return p;
   12672 
   12673     case Tag_ABI_compatibility:
   12674       {
   12675 	val = read_uleb128 (p, &len, end);
   12676 	p += len;
   12677 	printf ("  Tag_ABI_compatibility: ");
   12678 	printf (_("flag = %d, vendor = "), val);
   12679 	if (p < end - 1)
   12680 	  {
   12681 	    size_t maxlen = (end - p) - 1;
   12682 
   12683 	    print_symbol ((int) maxlen, (const char *) p);
   12684 	    p += strnlen ((char *) p, maxlen) + 1;
   12685 	  }
   12686 	else
   12687 	  {
   12688 	    printf (_("<corrupt>"));
   12689 	    p = (unsigned char *) end;
   12690 	  }
   12691 	putchar ('\n');
   12692 	return p;
   12693       }
   12694 
   12695     case Tag_ABI_conformance:
   12696       {
   12697 	printf ("  Tag_ABI_conformance: \"");
   12698 	if (p < end - 1)
   12699 	  {
   12700 	    size_t maxlen = (end - p) - 1;
   12701 
   12702 	    print_symbol ((int) maxlen, (const char *) p);
   12703 	    p += strnlen ((char *) p, maxlen) + 1;
   12704 	  }
   12705 	else
   12706 	  {
   12707 	    printf (_("<corrupt>"));
   12708 	    p = (unsigned char *) end;
   12709 	  }
   12710 	printf ("\"\n");
   12711 	return p;
   12712       }
   12713     }
   12714 
   12715   return display_tag_value (tag, p, end);
   12716 }
   12717 
   12718 static void
   12719 display_raw_attribute (unsigned char * p, unsigned char * end)
   12720 {
   12721   unsigned long addr = 0;
   12722   size_t bytes = end - p;
   12723 
   12724   assert (end > p);
   12725   while (bytes)
   12726     {
   12727       int j;
   12728       int k;
   12729       int lbytes = (bytes > 16 ? 16 : bytes);
   12730 
   12731       printf ("  0x%8.8lx ", addr);
   12732 
   12733       for (j = 0; j < 16; j++)
   12734 	{
   12735 	  if (j < lbytes)
   12736 	    printf ("%2.2x", p[j]);
   12737 	  else
   12738 	    printf ("  ");
   12739 
   12740 	  if ((j & 3) == 3)
   12741 	    printf (" ");
   12742 	}
   12743 
   12744       for (j = 0; j < lbytes; j++)
   12745 	{
   12746 	  k = p[j];
   12747 	  if (k >= ' ' && k < 0x7f)
   12748 	    printf ("%c", k);
   12749 	  else
   12750 	    printf (".");
   12751 	}
   12752 
   12753       putchar ('\n');
   12754 
   12755       p  += lbytes;
   12756       bytes -= lbytes;
   12757       addr += lbytes;
   12758     }
   12759 
   12760   putchar ('\n');
   12761 }
   12762 
   12763 static unsigned char *
   12764 display_msp430x_attribute (unsigned char * p,
   12765 			   const unsigned char * const end)
   12766 {
   12767   unsigned int len;
   12768   int val;
   12769   int tag;
   12770 
   12771   tag = read_uleb128 (p, & len, end);
   12772   p += len;
   12773 
   12774   switch (tag)
   12775     {
   12776     case OFBA_MSPABI_Tag_ISA:
   12777       val = read_uleb128 (p, &len, end);
   12778       p += len;
   12779       printf ("  Tag_ISA: ");
   12780       switch (val)
   12781 	{
   12782 	case 0: printf (_("None\n")); break;
   12783 	case 1: printf (_("MSP430\n")); break;
   12784 	case 2: printf (_("MSP430X\n")); break;
   12785 	default: printf ("??? (%d)\n", val); break;
   12786 	}
   12787       break;
   12788 
   12789     case OFBA_MSPABI_Tag_Code_Model:
   12790       val = read_uleb128 (p, &len, end);
   12791       p += len;
   12792       printf ("  Tag_Code_Model: ");
   12793       switch (val)
   12794 	{
   12795 	case 0: printf (_("None\n")); break;
   12796 	case 1: printf (_("Small\n")); break;
   12797 	case 2: printf (_("Large\n")); break;
   12798 	default: printf ("??? (%d)\n", val); break;
   12799 	}
   12800       break;
   12801 
   12802     case OFBA_MSPABI_Tag_Data_Model:
   12803       val = read_uleb128 (p, &len, end);
   12804       p += len;
   12805       printf ("  Tag_Data_Model: ");
   12806       switch (val)
   12807 	{
   12808 	case 0: printf (_("None\n")); break;
   12809 	case 1: printf (_("Small\n")); break;
   12810 	case 2: printf (_("Large\n")); break;
   12811 	case 3: printf (_("Restricted Large\n")); break;
   12812 	default: printf ("??? (%d)\n", val); break;
   12813 	}
   12814       break;
   12815 
   12816     default:
   12817       printf (_("  <unknown tag %d>: "), tag);
   12818 
   12819       if (tag & 1)
   12820 	{
   12821 	  putchar ('"');
   12822 	  if (p < end - 1)
   12823 	    {
   12824 	      size_t maxlen = (end - p) - 1;
   12825 
   12826 	      print_symbol ((int) maxlen, (const char *) p);
   12827 	      p += strnlen ((char *) p, maxlen) + 1;
   12828 	    }
   12829 	  else
   12830 	    {
   12831 	      printf (_("<corrupt>"));
   12832 	      p = (unsigned char *) end;
   12833 	    }
   12834 	  printf ("\"\n");
   12835 	}
   12836       else
   12837 	{
   12838 	  val = read_uleb128 (p, &len, end);
   12839 	  p += len;
   12840 	  printf ("%d (0x%x)\n", val, val);
   12841 	}
   12842       break;
   12843    }
   12844 
   12845   assert (p <= end);
   12846   return p;
   12847 }
   12848 
   12849 static int
   12850 process_attributes (FILE * file,
   12851 		    const char * public_name,
   12852 		    unsigned int proc_type,
   12853 		    unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
   12854 		    unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int, const unsigned char * const))
   12855 {
   12856   Elf_Internal_Shdr * sect;
   12857   unsigned i;
   12858 
   12859   /* Find the section header so that we get the size.  */
   12860   for (i = 0, sect = section_headers;
   12861        i < elf_header.e_shnum;
   12862        i++, sect++)
   12863     {
   12864       unsigned char * contents;
   12865       unsigned char * p;
   12866 
   12867       if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
   12868 	continue;
   12869 
   12870       contents = (unsigned char *) get_data (NULL, file, sect->sh_offset, 1,
   12871                                              sect->sh_size, _("attributes"));
   12872       if (contents == NULL)
   12873 	continue;
   12874 
   12875       p = contents;
   12876       if (*p == 'A')
   12877 	{
   12878 	  bfd_vma section_len;
   12879 
   12880 	  section_len = sect->sh_size - 1;
   12881 	  p++;
   12882 
   12883 	  while (section_len > 0)
   12884 	    {
   12885 	      bfd_vma attr_len;
   12886 	      unsigned int namelen;
   12887 	      bfd_boolean public_section;
   12888 	      bfd_boolean gnu_section;
   12889 
   12890 	      if (section_len <= 4)
   12891 		{
   12892 		  error (_("Tag section ends prematurely\n"));
   12893 		  break;
   12894 		}
   12895 	      attr_len = byte_get (p, 4);
   12896 	      p += 4;
   12897 
   12898 	      if (attr_len > section_len)
   12899 		{
   12900 		  error (_("Bad attribute length (%u > %u)\n"),
   12901 			  (unsigned) attr_len, (unsigned) section_len);
   12902 		  attr_len = section_len;
   12903 		}
   12904 	      /* PR 17531: file: 001-101425-0.004  */
   12905 	      else if (attr_len < 5)
   12906 		{
   12907 		  error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
   12908 		  break;
   12909 		}
   12910 
   12911 	      section_len -= attr_len;
   12912 	      attr_len -= 4;
   12913 
   12914 	      namelen = strnlen ((char *) p, attr_len) + 1;
   12915 	      if (namelen == 0 || namelen >= attr_len)
   12916 		{
   12917 		  error (_("Corrupt attribute section name\n"));
   12918 		  break;
   12919 		}
   12920 
   12921 	      printf (_("Attribute Section: "));
   12922 	      print_symbol (INT_MAX, (const char *) p);
   12923 	      putchar ('\n');
   12924 
   12925 	      if (public_name && streq ((char *) p, public_name))
   12926 		public_section = TRUE;
   12927 	      else
   12928 		public_section = FALSE;
   12929 
   12930 	      if (streq ((char *) p, "gnu"))
   12931 		gnu_section = TRUE;
   12932 	      else
   12933 		gnu_section = FALSE;
   12934 
   12935 	      p += namelen;
   12936 	      attr_len -= namelen;
   12937 
   12938 	      while (attr_len > 0 && p < contents + sect->sh_size)
   12939 		{
   12940 		  int tag;
   12941 		  int val;
   12942 		  bfd_vma size;
   12943 		  unsigned char * end;
   12944 
   12945 		  /* PR binutils/17531: Safe handling of corrupt files.  */
   12946 		  if (attr_len < 6)
   12947 		    {
   12948 		      error (_("Unused bytes at end of section\n"));
   12949 		      section_len = 0;
   12950 		      break;
   12951 		    }
   12952 
   12953 		  tag = *(p++);
   12954 		  size = byte_get (p, 4);
   12955 		  if (size > attr_len)
   12956 		    {
   12957 		      error (_("Bad subsection length (%u > %u)\n"),
   12958 			      (unsigned) size, (unsigned) attr_len);
   12959 		      size = attr_len;
   12960 		    }
   12961 		  /* PR binutils/17531: Safe handling of corrupt files.  */
   12962 		  if (size < 6)
   12963 		    {
   12964 		      error (_("Bad subsection length (%u < 6)\n"),
   12965 			      (unsigned) size);
   12966 		      section_len = 0;
   12967 		      break;
   12968 		    }
   12969 
   12970 		  attr_len -= size;
   12971 		  end = p + size - 1;
   12972 		  assert (end <= contents + sect->sh_size);
   12973 		  p += 4;
   12974 
   12975 		  switch (tag)
   12976 		    {
   12977 		    case 1:
   12978 		      printf (_("File Attributes\n"));
   12979 		      break;
   12980 		    case 2:
   12981 		      printf (_("Section Attributes:"));
   12982 		      goto do_numlist;
   12983 		    case 3:
   12984 		      printf (_("Symbol Attributes:"));
   12985 		    do_numlist:
   12986 		      for (;;)
   12987 			{
   12988 			  unsigned int j;
   12989 
   12990 			  val = read_uleb128 (p, &j, end);
   12991 			  p += j;
   12992 			  if (val == 0)
   12993 			    break;
   12994 			  printf (" %d", val);
   12995 			}
   12996 		      printf ("\n");
   12997 		      break;
   12998 		    default:
   12999 		      printf (_("Unknown tag: %d\n"), tag);
   13000 		      public_section = FALSE;
   13001 		      break;
   13002 		    }
   13003 
   13004 		  if (public_section && display_pub_attribute != NULL)
   13005 		    {
   13006 		      while (p < end)
   13007 			p = display_pub_attribute (p, end);
   13008 		      assert (p <= end);
   13009 		    }
   13010 		  else if (gnu_section && display_proc_gnu_attribute != NULL)
   13011 		    {
   13012 		      while (p < end)
   13013 			p = display_gnu_attribute (p,
   13014 						   display_proc_gnu_attribute,
   13015 						   end);
   13016 		      assert (p <= end);
   13017 		    }
   13018 		  else if (p < end)
   13019 		    {
   13020 		      printf (_("  Unknown attribute:\n"));
   13021 		      display_raw_attribute (p, end);
   13022 		      p = end;
   13023 		    }
   13024 		  else
   13025 		    attr_len = 0;
   13026 		}
   13027 	    }
   13028 	}
   13029       else
   13030 	printf (_("Unknown format '%c' (%d)\n"), *p, *p);
   13031 
   13032       free (contents);
   13033     }
   13034   return 1;
   13035 }
   13036 
   13037 static int
   13038 process_arm_specific (FILE * file)
   13039 {
   13040   return process_attributes (file, "aeabi", SHT_ARM_ATTRIBUTES,
   13041 			     display_arm_attribute, NULL);
   13042 }
   13043 
   13044 static int
   13045 process_power_specific (FILE * file)
   13046 {
   13047   return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
   13048 			     display_power_gnu_attribute);
   13049 }
   13050 
   13051 static int
   13052 process_sparc_specific (FILE * file)
   13053 {
   13054   return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
   13055 			     display_sparc_gnu_attribute);
   13056 }
   13057 
   13058 static int
   13059 process_tic6x_specific (FILE * file)
   13060 {
   13061   return process_attributes (file, "c6xabi", SHT_C6000_ATTRIBUTES,
   13062 			     display_tic6x_attribute, NULL);
   13063 }
   13064 
   13065 static int
   13066 process_msp430x_specific (FILE * file)
   13067 {
   13068   return process_attributes (file, "mspabi", SHT_MSP430_ATTRIBUTES,
   13069 			     display_msp430x_attribute, NULL);
   13070 }
   13071 
   13072 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
   13073    Print the Address, Access and Initial fields of an entry at VMA ADDR
   13074    and return the VMA of the next entry.  */
   13075 
   13076 static bfd_vma
   13077 print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
   13078 {
   13079   printf ("  ");
   13080   print_vma (addr, LONG_HEX);
   13081   printf (" ");
   13082   if (addr < pltgot + 0xfff0)
   13083     printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
   13084   else
   13085     printf ("%10s", "");
   13086   printf (" ");
   13087   if (data == NULL)
   13088     printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
   13089   else
   13090     {
   13091       bfd_vma entry;
   13092 
   13093       entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
   13094       print_vma (entry, LONG_HEX);
   13095     }
   13096   return addr + (is_32bit_elf ? 4 : 8);
   13097 }
   13098 
   13099 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
   13100    PLTGOT.  Print the Address and Initial fields of an entry at VMA
   13101    ADDR and return the VMA of the next entry.  */
   13102 
   13103 static bfd_vma
   13104 print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
   13105 {
   13106   printf ("  ");
   13107   print_vma (addr, LONG_HEX);
   13108   printf (" ");
   13109   if (data == NULL)
   13110     printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
   13111   else
   13112     {
   13113       bfd_vma entry;
   13114 
   13115       entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
   13116       print_vma (entry, LONG_HEX);
   13117     }
   13118   return addr + (is_32bit_elf ? 4 : 8);
   13119 }
   13120 
   13121 static void
   13122 print_mips_ases (unsigned int mask)
   13123 {
   13124   if (mask & AFL_ASE_DSP)
   13125     fputs ("\n\tDSP ASE", stdout);
   13126   if (mask & AFL_ASE_DSPR2)
   13127     fputs ("\n\tDSP R2 ASE", stdout);
   13128   if (mask & AFL_ASE_DSPR6)
   13129     fputs ("\n\tDSP R6 ASE", stdout);
   13130   if (mask & AFL_ASE_EVA)
   13131     fputs ("\n\tEnhanced VA Scheme", stdout);
   13132   if (mask & AFL_ASE_MCU)
   13133     fputs ("\n\tMCU (MicroController) ASE", stdout);
   13134   if (mask & AFL_ASE_MDMX)
   13135     fputs ("\n\tMDMX ASE", stdout);
   13136   if (mask & AFL_ASE_MIPS3D)
   13137     fputs ("\n\tMIPS-3D ASE", stdout);
   13138   if (mask & AFL_ASE_MT)
   13139     fputs ("\n\tMT ASE", stdout);
   13140   if (mask & AFL_ASE_SMARTMIPS)
   13141     fputs ("\n\tSmartMIPS ASE", stdout);
   13142   if (mask & AFL_ASE_VIRT)
   13143     fputs ("\n\tVZ ASE", stdout);
   13144   if (mask & AFL_ASE_MSA)
   13145     fputs ("\n\tMSA ASE", stdout);
   13146   if (mask & AFL_ASE_MIPS16)
   13147     fputs ("\n\tMIPS16 ASE", stdout);
   13148   if (mask & AFL_ASE_MICROMIPS)
   13149     fputs ("\n\tMICROMIPS ASE", stdout);
   13150   if (mask & AFL_ASE_XPA)
   13151     fputs ("\n\tXPA ASE", stdout);
   13152   if (mask == 0)
   13153     fprintf (stdout, "\n\t%s", _("None"));
   13154   else if ((mask & ~AFL_ASE_MASK) != 0)
   13155     fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
   13156 }
   13157 
   13158 static void
   13159 print_mips_isa_ext (unsigned int isa_ext)
   13160 {
   13161   switch (isa_ext)
   13162     {
   13163     case 0:
   13164       fputs (_("None"), stdout);
   13165       break;
   13166     case AFL_EXT_XLR:
   13167       fputs ("RMI XLR", stdout);
   13168       break;
   13169     case AFL_EXT_OCTEON3:
   13170       fputs ("Cavium Networks Octeon3", stdout);
   13171       break;
   13172     case AFL_EXT_OCTEON2:
   13173       fputs ("Cavium Networks Octeon2", stdout);
   13174       break;
   13175     case AFL_EXT_OCTEONP:
   13176       fputs ("Cavium Networks OcteonP", stdout);
   13177       break;
   13178     case AFL_EXT_LOONGSON_3A:
   13179       fputs ("Loongson 3A", stdout);
   13180       break;
   13181     case AFL_EXT_OCTEON:
   13182       fputs ("Cavium Networks Octeon", stdout);
   13183       break;
   13184     case AFL_EXT_5900:
   13185       fputs ("Toshiba R5900", stdout);
   13186       break;
   13187     case AFL_EXT_4650:
   13188       fputs ("MIPS R4650", stdout);
   13189       break;
   13190     case AFL_EXT_4010:
   13191       fputs ("LSI R4010", stdout);
   13192       break;
   13193     case AFL_EXT_4100:
   13194       fputs ("NEC VR4100", stdout);
   13195       break;
   13196     case AFL_EXT_3900:
   13197       fputs ("Toshiba R3900", stdout);
   13198       break;
   13199     case AFL_EXT_10000:
   13200       fputs ("MIPS R10000", stdout);
   13201       break;
   13202     case AFL_EXT_SB1:
   13203       fputs ("Broadcom SB-1", stdout);
   13204       break;
   13205     case AFL_EXT_4111:
   13206       fputs ("NEC VR4111/VR4181", stdout);
   13207       break;
   13208     case AFL_EXT_4120:
   13209       fputs ("NEC VR4120", stdout);
   13210       break;
   13211     case AFL_EXT_5400:
   13212       fputs ("NEC VR5400", stdout);
   13213       break;
   13214     case AFL_EXT_5500:
   13215       fputs ("NEC VR5500", stdout);
   13216       break;
   13217     case AFL_EXT_LOONGSON_2E:
   13218       fputs ("ST Microelectronics Loongson 2E", stdout);
   13219       break;
   13220     case AFL_EXT_LOONGSON_2F:
   13221       fputs ("ST Microelectronics Loongson 2F", stdout);
   13222       break;
   13223     default:
   13224       fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
   13225     }
   13226 }
   13227 
   13228 static int
   13229 get_mips_reg_size (int reg_size)
   13230 {
   13231   return (reg_size == AFL_REG_NONE) ? 0
   13232 	 : (reg_size == AFL_REG_32) ? 32
   13233 	 : (reg_size == AFL_REG_64) ? 64
   13234 	 : (reg_size == AFL_REG_128) ? 128
   13235 	 : -1;
   13236 }
   13237 
   13238 static int
   13239 process_mips_specific (FILE * file)
   13240 {
   13241   Elf_Internal_Dyn * entry;
   13242   Elf_Internal_Shdr *sect = NULL;
   13243   size_t liblist_offset = 0;
   13244   size_t liblistno = 0;
   13245   size_t conflictsno = 0;
   13246   size_t options_offset = 0;
   13247   size_t conflicts_offset = 0;
   13248   size_t pltrelsz = 0;
   13249   size_t pltrel = 0;
   13250   bfd_vma pltgot = 0;
   13251   bfd_vma mips_pltgot = 0;
   13252   bfd_vma jmprel = 0;
   13253   bfd_vma local_gotno = 0;
   13254   bfd_vma gotsym = 0;
   13255   bfd_vma symtabno = 0;
   13256 
   13257   process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
   13258 		      display_mips_gnu_attribute);
   13259 
   13260   sect = find_section (".MIPS.abiflags");
   13261 
   13262   if (sect != NULL)
   13263     {
   13264       Elf_External_ABIFlags_v0 *abiflags_ext;
   13265       Elf_Internal_ABIFlags_v0 abiflags_in;
   13266 
   13267       if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
   13268 	fputs ("\nCorrupt ABI Flags section.\n", stdout);
   13269       else
   13270 	{
   13271 	  abiflags_ext = get_data (NULL, file, sect->sh_offset, 1,
   13272 				   sect->sh_size, _("MIPS ABI Flags section"));
   13273 	  if (abiflags_ext)
   13274 	    {
   13275 	      abiflags_in.version = BYTE_GET (abiflags_ext->version);
   13276 	      abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
   13277 	      abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
   13278 	      abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
   13279 	      abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
   13280 	      abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
   13281 	      abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
   13282 	      abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
   13283 	      abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
   13284 	      abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
   13285 	      abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
   13286 
   13287 	      printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
   13288 	      printf ("\nISA: MIPS%d", abiflags_in.isa_level);
   13289 	      if (abiflags_in.isa_rev > 1)
   13290 		printf ("r%d", abiflags_in.isa_rev);
   13291 	      printf ("\nGPR size: %d",
   13292 		      get_mips_reg_size (abiflags_in.gpr_size));
   13293 	      printf ("\nCPR1 size: %d",
   13294 		      get_mips_reg_size (abiflags_in.cpr1_size));
   13295 	      printf ("\nCPR2 size: %d",
   13296 		      get_mips_reg_size (abiflags_in.cpr2_size));
   13297 	      fputs ("\nFP ABI: ", stdout);
   13298 	      print_mips_fp_abi_value (abiflags_in.fp_abi);
   13299 	      fputs ("ISA Extension: ", stdout);
   13300 	      print_mips_isa_ext (abiflags_in.isa_ext);
   13301 	      fputs ("\nASEs:", stdout);
   13302 	      print_mips_ases (abiflags_in.ases);
   13303 	      printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
   13304 	      printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
   13305 	      fputc ('\n', stdout);
   13306 	      free (abiflags_ext);
   13307 	    }
   13308 	}
   13309     }
   13310 
   13311   /* We have a lot of special sections.  Thanks SGI!  */
   13312   if (dynamic_section == NULL)
   13313     /* No information available.  */
   13314     return 0;
   13315 
   13316   for (entry = dynamic_section;
   13317        /* PR 17531 file: 012-50589-0.004.  */
   13318        entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL;
   13319        ++entry)
   13320     switch (entry->d_tag)
   13321       {
   13322       case DT_MIPS_LIBLIST:
   13323 	liblist_offset
   13324 	  = offset_from_vma (file, entry->d_un.d_val,
   13325 			     liblistno * sizeof (Elf32_External_Lib));
   13326 	break;
   13327       case DT_MIPS_LIBLISTNO:
   13328 	liblistno = entry->d_un.d_val;
   13329 	break;
   13330       case DT_MIPS_OPTIONS:
   13331 	options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
   13332 	break;
   13333       case DT_MIPS_CONFLICT:
   13334 	conflicts_offset
   13335 	  = offset_from_vma (file, entry->d_un.d_val,
   13336 			     conflictsno * sizeof (Elf32_External_Conflict));
   13337 	break;
   13338       case DT_MIPS_CONFLICTNO:
   13339 	conflictsno = entry->d_un.d_val;
   13340 	break;
   13341       case DT_PLTGOT:
   13342 	pltgot = entry->d_un.d_ptr;
   13343 	break;
   13344       case DT_MIPS_LOCAL_GOTNO:
   13345 	local_gotno = entry->d_un.d_val;
   13346 	break;
   13347       case DT_MIPS_GOTSYM:
   13348 	gotsym = entry->d_un.d_val;
   13349 	break;
   13350       case DT_MIPS_SYMTABNO:
   13351 	symtabno = entry->d_un.d_val;
   13352 	break;
   13353       case DT_MIPS_PLTGOT:
   13354 	mips_pltgot = entry->d_un.d_ptr;
   13355 	break;
   13356       case DT_PLTREL:
   13357 	pltrel = entry->d_un.d_val;
   13358 	break;
   13359       case DT_PLTRELSZ:
   13360 	pltrelsz = entry->d_un.d_val;
   13361 	break;
   13362       case DT_JMPREL:
   13363 	jmprel = entry->d_un.d_ptr;
   13364 	break;
   13365       default:
   13366 	break;
   13367       }
   13368 
   13369   if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
   13370     {
   13371       Elf32_External_Lib * elib;
   13372       size_t cnt;
   13373 
   13374       elib = (Elf32_External_Lib *) get_data (NULL, file, liblist_offset,
   13375                                               liblistno,
   13376                                               sizeof (Elf32_External_Lib),
   13377                                               _("liblist section data"));
   13378       if (elib)
   13379 	{
   13380 	  printf (_("\nSection '.liblist' contains %lu entries:\n"),
   13381 		  (unsigned long) liblistno);
   13382 	  fputs (_("     Library              Time Stamp          Checksum   Version Flags\n"),
   13383 		 stdout);
   13384 
   13385 	  for (cnt = 0; cnt < liblistno; ++cnt)
   13386 	    {
   13387 	      Elf32_Lib liblist;
   13388 	      time_t atime;
   13389 	      char timebuf[20];
   13390 	      struct tm * tmp;
   13391 
   13392 	      liblist.l_name = BYTE_GET (elib[cnt].l_name);
   13393 	      atime = BYTE_GET (elib[cnt].l_time_stamp);
   13394 	      liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
   13395 	      liblist.l_version = BYTE_GET (elib[cnt].l_version);
   13396 	      liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
   13397 
   13398 	      tmp = gmtime (&atime);
   13399 	      snprintf (timebuf, sizeof (timebuf),
   13400 			"%04u-%02u-%02uT%02u:%02u:%02u",
   13401 			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
   13402 			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
   13403 
   13404 	      printf ("%3lu: ", (unsigned long) cnt);
   13405 	      if (VALID_DYNAMIC_NAME (liblist.l_name))
   13406 		print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
   13407 	      else
   13408 		printf (_("<corrupt: %9ld>"), liblist.l_name);
   13409 	      printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
   13410 		      liblist.l_version);
   13411 
   13412 	      if (liblist.l_flags == 0)
   13413 		puts (_(" NONE"));
   13414 	      else
   13415 		{
   13416 		  static const struct
   13417 		  {
   13418 		    const char * name;
   13419 		    int bit;
   13420 		  }
   13421 		  l_flags_vals[] =
   13422 		  {
   13423 		    { " EXACT_MATCH", LL_EXACT_MATCH },
   13424 		    { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
   13425 		    { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
   13426 		    { " EXPORTS", LL_EXPORTS },
   13427 		    { " DELAY_LOAD", LL_DELAY_LOAD },
   13428 		    { " DELTA", LL_DELTA }
   13429 		  };
   13430 		  int flags = liblist.l_flags;
   13431 		  size_t fcnt;
   13432 
   13433 		  for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
   13434 		    if ((flags & l_flags_vals[fcnt].bit) != 0)
   13435 		      {
   13436 			fputs (l_flags_vals[fcnt].name, stdout);
   13437 			flags ^= l_flags_vals[fcnt].bit;
   13438 		      }
   13439 		  if (flags != 0)
   13440 		    printf (" %#x", (unsigned int) flags);
   13441 
   13442 		  puts ("");
   13443 		}
   13444 	    }
   13445 
   13446 	  free (elib);
   13447 	}
   13448     }
   13449 
   13450   if (options_offset != 0)
   13451     {
   13452       Elf_External_Options * eopt;
   13453       Elf_Internal_Options * iopt;
   13454       Elf_Internal_Options * option;
   13455       size_t offset;
   13456       int cnt;
   13457       sect = section_headers;
   13458 
   13459       /* Find the section header so that we get the size.  */
   13460       sect = find_section_by_type (SHT_MIPS_OPTIONS);
   13461       /* PR 17533 file: 012-277276-0.004.  */
   13462       if (sect == NULL)
   13463 	{
   13464 	  error (_("No MIPS_OPTIONS header found\n"));
   13465 	  return 0;
   13466 	}
   13467 
   13468       eopt = (Elf_External_Options *) get_data (NULL, file, options_offset, 1,
   13469                                                 sect->sh_size, _("options"));
   13470       if (eopt)
   13471 	{
   13472 	  iopt = (Elf_Internal_Options *)
   13473               cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
   13474 	  if (iopt == NULL)
   13475 	    {
   13476 	      error (_("Out of memory allocatinf space for MIPS options\n"));
   13477 	      return 0;
   13478 	    }
   13479 
   13480 	  offset = cnt = 0;
   13481 	  option = iopt;
   13482 
   13483 	  while (offset < sect->sh_size)
   13484 	    {
   13485 	      Elf_External_Options * eoption;
   13486 
   13487 	      eoption = (Elf_External_Options *) ((char *) eopt + offset);
   13488 
   13489 	      option->kind = BYTE_GET (eoption->kind);
   13490 	      option->size = BYTE_GET (eoption->size);
   13491 	      option->section = BYTE_GET (eoption->section);
   13492 	      option->info = BYTE_GET (eoption->info);
   13493 
   13494 	      offset += option->size;
   13495 
   13496 	      ++option;
   13497 	      ++cnt;
   13498 	    }
   13499 
   13500 	  printf (_("\nSection '%s' contains %d entries:\n"),
   13501 		  printable_section_name (sect), cnt);
   13502 
   13503 	  option = iopt;
   13504 
   13505 	  while (cnt-- > 0)
   13506 	    {
   13507 	      size_t len;
   13508 
   13509 	      switch (option->kind)
   13510 		{
   13511 		case ODK_NULL:
   13512 		  /* This shouldn't happen.  */
   13513 		  printf (" NULL       %d %lx", option->section, option->info);
   13514 		  break;
   13515 		case ODK_REGINFO:
   13516 		  printf (" REGINFO    ");
   13517 		  if (elf_header.e_machine == EM_MIPS)
   13518 		    {
   13519 		      /* 32bit form.  */
   13520 		      Elf32_External_RegInfo * ereg;
   13521 		      Elf32_RegInfo reginfo;
   13522 
   13523 		      ereg = (Elf32_External_RegInfo *) (option + 1);
   13524 		      reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
   13525 		      reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
   13526 		      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
   13527 		      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
   13528 		      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
   13529 		      reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
   13530 
   13531 		      printf ("GPR %08lx  GP 0x%lx\n",
   13532 			      reginfo.ri_gprmask,
   13533 			      (unsigned long) reginfo.ri_gp_value);
   13534 		      printf ("            CPR0 %08lx  CPR1 %08lx  CPR2 %08lx  CPR3 %08lx\n",
   13535 			      reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
   13536 			      reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
   13537 		    }
   13538 		  else
   13539 		    {
   13540 		      /* 64 bit form.  */
   13541 		      Elf64_External_RegInfo * ereg;
   13542 		      Elf64_Internal_RegInfo reginfo;
   13543 
   13544 		      ereg = (Elf64_External_RegInfo *) (option + 1);
   13545 		      reginfo.ri_gprmask    = BYTE_GET (ereg->ri_gprmask);
   13546 		      reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
   13547 		      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
   13548 		      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
   13549 		      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
   13550 		      reginfo.ri_gp_value   = BYTE_GET (ereg->ri_gp_value);
   13551 
   13552 		      printf ("GPR %08lx  GP 0x",
   13553 			      reginfo.ri_gprmask);
   13554 		      printf_vma (reginfo.ri_gp_value);
   13555 		      printf ("\n");
   13556 
   13557 		      printf ("            CPR0 %08lx  CPR1 %08lx  CPR2 %08lx  CPR3 %08lx\n",
   13558 			      reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
   13559 			      reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
   13560 		    }
   13561 		  ++option;
   13562 		  continue;
   13563 		case ODK_EXCEPTIONS:
   13564 		  fputs (" EXCEPTIONS fpe_min(", stdout);
   13565 		  process_mips_fpe_exception (option->info & OEX_FPU_MIN);
   13566 		  fputs (") fpe_max(", stdout);
   13567 		  process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
   13568 		  fputs (")", stdout);
   13569 
   13570 		  if (option->info & OEX_PAGE0)
   13571 		    fputs (" PAGE0", stdout);
   13572 		  if (option->info & OEX_SMM)
   13573 		    fputs (" SMM", stdout);
   13574 		  if (option->info & OEX_FPDBUG)
   13575 		    fputs (" FPDBUG", stdout);
   13576 		  if (option->info & OEX_DISMISS)
   13577 		    fputs (" DISMISS", stdout);
   13578 		  break;
   13579 		case ODK_PAD:
   13580 		  fputs (" PAD       ", stdout);
   13581 		  if (option->info & OPAD_PREFIX)
   13582 		    fputs (" PREFIX", stdout);
   13583 		  if (option->info & OPAD_POSTFIX)
   13584 		    fputs (" POSTFIX", stdout);
   13585 		  if (option->info & OPAD_SYMBOL)
   13586 		    fputs (" SYMBOL", stdout);
   13587 		  break;
   13588 		case ODK_HWPATCH:
   13589 		  fputs (" HWPATCH   ", stdout);
   13590 		  if (option->info & OHW_R4KEOP)
   13591 		    fputs (" R4KEOP", stdout);
   13592 		  if (option->info & OHW_R8KPFETCH)
   13593 		    fputs (" R8KPFETCH", stdout);
   13594 		  if (option->info & OHW_R5KEOP)
   13595 		    fputs (" R5KEOP", stdout);
   13596 		  if (option->info & OHW_R5KCVTL)
   13597 		    fputs (" R5KCVTL", stdout);
   13598 		  break;
   13599 		case ODK_FILL:
   13600 		  fputs (" FILL       ", stdout);
   13601 		  /* XXX Print content of info word?  */
   13602 		  break;
   13603 		case ODK_TAGS:
   13604 		  fputs (" TAGS       ", stdout);
   13605 		  /* XXX Print content of info word?  */
   13606 		  break;
   13607 		case ODK_HWAND:
   13608 		  fputs (" HWAND     ", stdout);
   13609 		  if (option->info & OHWA0_R4KEOP_CHECKED)
   13610 		    fputs (" R4KEOP_CHECKED", stdout);
   13611 		  if (option->info & OHWA0_R4KEOP_CLEAN)
   13612 		    fputs (" R4KEOP_CLEAN", stdout);
   13613 		  break;
   13614 		case ODK_HWOR:
   13615 		  fputs (" HWOR      ", stdout);
   13616 		  if (option->info & OHWA0_R4KEOP_CHECKED)
   13617 		    fputs (" R4KEOP_CHECKED", stdout);
   13618 		  if (option->info & OHWA0_R4KEOP_CLEAN)
   13619 		    fputs (" R4KEOP_CLEAN", stdout);
   13620 		  break;
   13621 		case ODK_GP_GROUP:
   13622 		  printf (" GP_GROUP  %#06lx  self-contained %#06lx",
   13623 			  option->info & OGP_GROUP,
   13624 			  (option->info & OGP_SELF) >> 16);
   13625 		  break;
   13626 		case ODK_IDENT:
   13627 		  printf (" IDENT     %#06lx  self-contained %#06lx",
   13628 			  option->info & OGP_GROUP,
   13629 			  (option->info & OGP_SELF) >> 16);
   13630 		  break;
   13631 		default:
   13632 		  /* This shouldn't happen.  */
   13633 		  printf (" %3d ???     %d %lx",
   13634 			  option->kind, option->section, option->info);
   13635 		  break;
   13636 		}
   13637 
   13638 	      len = sizeof (* eopt);
   13639 	      while (len < option->size)
   13640 		if (((char *) option)[len] >= ' '
   13641 		    && ((char *) option)[len] < 0x7f)
   13642 		  printf ("%c", ((char *) option)[len++]);
   13643 		else
   13644 		  printf ("\\%03o", ((char *) option)[len++]);
   13645 
   13646 	      fputs ("\n", stdout);
   13647 	      ++option;
   13648 	    }
   13649 
   13650 	  free (eopt);
   13651 	}
   13652     }
   13653 
   13654   if (conflicts_offset != 0 && conflictsno != 0)
   13655     {
   13656       Elf32_Conflict * iconf;
   13657       size_t cnt;
   13658 
   13659       if (dynamic_symbols == NULL)
   13660 	{
   13661 	  error (_("conflict list found without a dynamic symbol table\n"));
   13662 	  return 0;
   13663 	}
   13664 
   13665       iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
   13666       if (iconf == NULL)
   13667 	{
   13668 	  error (_("Out of memory allocating space for dynamic conflicts\n"));
   13669 	  return 0;
   13670 	}
   13671 
   13672       if (is_32bit_elf)
   13673 	{
   13674 	  Elf32_External_Conflict * econf32;
   13675 
   13676 	  econf32 = (Elf32_External_Conflict *)
   13677               get_data (NULL, file, conflicts_offset, conflictsno,
   13678                         sizeof (* econf32), _("conflict"));
   13679 	  if (!econf32)
   13680 	    return 0;
   13681 
   13682 	  for (cnt = 0; cnt < conflictsno; ++cnt)
   13683 	    iconf[cnt] = BYTE_GET (econf32[cnt]);
   13684 
   13685 	  free (econf32);
   13686 	}
   13687       else
   13688 	{
   13689 	  Elf64_External_Conflict * econf64;
   13690 
   13691 	  econf64 = (Elf64_External_Conflict *)
   13692               get_data (NULL, file, conflicts_offset, conflictsno,
   13693                         sizeof (* econf64), _("conflict"));
   13694 	  if (!econf64)
   13695 	    return 0;
   13696 
   13697 	  for (cnt = 0; cnt < conflictsno; ++cnt)
   13698 	    iconf[cnt] = BYTE_GET (econf64[cnt]);
   13699 
   13700 	  free (econf64);
   13701 	}
   13702 
   13703       printf (_("\nSection '.conflict' contains %lu entries:\n"),
   13704 	      (unsigned long) conflictsno);
   13705       puts (_("  Num:    Index       Value  Name"));
   13706 
   13707       for (cnt = 0; cnt < conflictsno; ++cnt)
   13708 	{
   13709 	  printf ("%5lu: %8lu  ", (unsigned long) cnt, iconf[cnt]);
   13710 
   13711 	  if (iconf[cnt] >= num_dynamic_syms)
   13712 	    printf (_("<corrupt symbol index>"));
   13713 	  else
   13714 	    {
   13715 	      Elf_Internal_Sym * psym;
   13716 
   13717 	      psym = & dynamic_symbols[iconf[cnt]];
   13718 	      print_vma (psym->st_value, FULL_HEX);
   13719 	      putchar (' ');
   13720 	      if (VALID_DYNAMIC_NAME (psym->st_name))
   13721 		print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
   13722 	      else
   13723 		printf (_("<corrupt: %14ld>"), psym->st_name);
   13724 	    }
   13725 	  putchar ('\n');
   13726 	}
   13727 
   13728       free (iconf);
   13729     }
   13730 
   13731   if (pltgot != 0 && local_gotno != 0)
   13732     {
   13733       bfd_vma ent, local_end, global_end;
   13734       size_t i, offset;
   13735       unsigned char * data;
   13736       int addr_size;
   13737 
   13738       ent = pltgot;
   13739       addr_size = (is_32bit_elf ? 4 : 8);
   13740       local_end = pltgot + local_gotno * addr_size;
   13741 
   13742       /* PR binutils/17533 file: 012-111227-0.004  */
   13743       if (symtabno < gotsym)
   13744 	{
   13745 	  error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
   13746 		 (long) gotsym, (long) symtabno);
   13747 	  return 0;
   13748 	}
   13749 
   13750       global_end = local_end + (symtabno - gotsym) * addr_size;
   13751       assert (global_end >= local_end);
   13752       offset = offset_from_vma (file, pltgot, global_end - pltgot);
   13753       data = (unsigned char *) get_data (NULL, file, offset,
   13754                                          global_end - pltgot, 1,
   13755 					 _("Global Offset Table data"));
   13756       if (data == NULL)
   13757 	return 0;
   13758 
   13759       printf (_("\nPrimary GOT:\n"));
   13760       printf (_(" Canonical gp value: "));
   13761       print_vma (pltgot + 0x7ff0, LONG_HEX);
   13762       printf ("\n\n");
   13763 
   13764       printf (_(" Reserved entries:\n"));
   13765       printf (_("  %*s %10s %*s Purpose\n"),
   13766 	      addr_size * 2, _("Address"), _("Access"),
   13767 	      addr_size * 2, _("Initial"));
   13768       ent = print_mips_got_entry (data, pltgot, ent);
   13769       printf (_(" Lazy resolver\n"));
   13770       if (data
   13771 	  && (byte_get (data + ent - pltgot, addr_size)
   13772 	      >> (addr_size * 8 - 1)) != 0)
   13773 	{
   13774 	  ent = print_mips_got_entry (data, pltgot, ent);
   13775 	  printf (_(" Module pointer (GNU extension)\n"));
   13776 	}
   13777       printf ("\n");
   13778 
   13779       if (ent < local_end)
   13780 	{
   13781 	  printf (_(" Local entries:\n"));
   13782 	  printf ("  %*s %10s %*s\n",
   13783 		  addr_size * 2, _("Address"), _("Access"),
   13784 		  addr_size * 2, _("Initial"));
   13785 	  while (ent < local_end)
   13786 	    {
   13787 	      ent = print_mips_got_entry (data, pltgot, ent);
   13788 	      printf ("\n");
   13789 	    }
   13790 	  printf ("\n");
   13791 	}
   13792 
   13793       if (gotsym < symtabno)
   13794 	{
   13795 	  int sym_width;
   13796 
   13797 	  printf (_(" Global entries:\n"));
   13798 	  printf ("  %*s %10s %*s %*s %-7s %3s %s\n",
   13799 		  addr_size * 2, _("Address"),
   13800 		  _("Access"),
   13801 		  addr_size * 2, _("Initial"),
   13802 		  addr_size * 2, _("Sym.Val."),
   13803 		  _("Type"),
   13804 		  /* Note for translators: "Ndx" = abbreviated form of "Index".  */
   13805 		  _("Ndx"), _("Name"));
   13806 
   13807 	  sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
   13808 
   13809 	  for (i = gotsym; i < symtabno; i++)
   13810 	    {
   13811 	      ent = print_mips_got_entry (data, pltgot, ent);
   13812 	      printf (" ");
   13813 
   13814 	      if (dynamic_symbols == NULL)
   13815 		printf (_("<no dynamic symbols>"));
   13816 	      else if (i < num_dynamic_syms)
   13817 		{
   13818 		  Elf_Internal_Sym * psym = dynamic_symbols + i;
   13819 
   13820 		  print_vma (psym->st_value, LONG_HEX);
   13821 		  printf (" %-7s %3s ",
   13822 			  get_symbol_type (ELF_ST_TYPE (psym->st_info)),
   13823 			  get_symbol_index_type (psym->st_shndx));
   13824 
   13825 		  if (VALID_DYNAMIC_NAME (psym->st_name))
   13826 		    print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
   13827 		  else
   13828 		    printf (_("<corrupt: %14ld>"), psym->st_name);
   13829 		}
   13830 	      else
   13831 		printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
   13832 			(unsigned long) i);
   13833 
   13834 	      printf ("\n");
   13835 	    }
   13836 	  printf ("\n");
   13837 	}
   13838 
   13839       if (data)
   13840 	free (data);
   13841     }
   13842 
   13843   if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
   13844     {
   13845       bfd_vma ent, end;
   13846       size_t offset, rel_offset;
   13847       unsigned long count, i;
   13848       unsigned char * data;
   13849       int addr_size, sym_width;
   13850       Elf_Internal_Rela * rels;
   13851 
   13852       rel_offset = offset_from_vma (file, jmprel, pltrelsz);
   13853       if (pltrel == DT_RELA)
   13854 	{
   13855 	  if (!slurp_rela_relocs (file, rel_offset, pltrelsz, &rels, &count))
   13856 	    return 0;
   13857 	}
   13858       else
   13859 	{
   13860 	  if (!slurp_rel_relocs (file, rel_offset, pltrelsz, &rels, &count))
   13861 	    return 0;
   13862 	}
   13863 
   13864       ent = mips_pltgot;
   13865       addr_size = (is_32bit_elf ? 4 : 8);
   13866       end = mips_pltgot + (2 + count) * addr_size;
   13867 
   13868       offset = offset_from_vma (file, mips_pltgot, end - mips_pltgot);
   13869       data = (unsigned char *) get_data (NULL, file, offset, end - mips_pltgot,
   13870                                          1, _("Procedure Linkage Table data"));
   13871       if (data == NULL)
   13872 	return 0;
   13873 
   13874       printf ("\nPLT GOT:\n\n");
   13875       printf (_(" Reserved entries:\n"));
   13876       printf (_("  %*s %*s Purpose\n"),
   13877 	      addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
   13878       ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
   13879       printf (_(" PLT lazy resolver\n"));
   13880       ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
   13881       printf (_(" Module pointer\n"));
   13882       printf ("\n");
   13883 
   13884       printf (_(" Entries:\n"));
   13885       printf ("  %*s %*s %*s %-7s %3s %s\n",
   13886 	      addr_size * 2, _("Address"),
   13887 	      addr_size * 2, _("Initial"),
   13888 	      addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
   13889       sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
   13890       for (i = 0; i < count; i++)
   13891 	{
   13892 	  unsigned long idx = get_reloc_symindex (rels[i].r_info);
   13893 
   13894 	  ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
   13895 	  printf (" ");
   13896 
   13897 	  if (idx >= num_dynamic_syms)
   13898 	    printf (_("<corrupt symbol index: %lu>"), idx);
   13899 	  else
   13900 	    {
   13901 	      Elf_Internal_Sym * psym = dynamic_symbols + idx;
   13902 
   13903 	      print_vma (psym->st_value, LONG_HEX);
   13904 	      printf (" %-7s %3s ",
   13905 		      get_symbol_type (ELF_ST_TYPE (psym->st_info)),
   13906 		      get_symbol_index_type (psym->st_shndx));
   13907 	      if (VALID_DYNAMIC_NAME (psym->st_name))
   13908 		print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
   13909 	      else
   13910 		printf (_("<corrupt: %14ld>"), psym->st_name);
   13911 	    }
   13912 	  printf ("\n");
   13913 	}
   13914       printf ("\n");
   13915 
   13916       if (data)
   13917 	free (data);
   13918       free (rels);
   13919     }
   13920 
   13921   return 1;
   13922 }
   13923 
   13924 static int
   13925 process_nds32_specific (FILE * file)
   13926 {
   13927   Elf_Internal_Shdr *sect = NULL;
   13928 
   13929   sect = find_section (".nds32_e_flags");
   13930   if (sect != NULL)
   13931     {
   13932       unsigned int *flag;
   13933 
   13934       printf ("\nNDS32 elf flags section:\n");
   13935       flag = get_data (NULL, file, sect->sh_offset, 1,
   13936 		       sect->sh_size, _("NDS32 elf flags section"));
   13937 
   13938       switch ((*flag) & 0x3)
   13939 	{
   13940 	case 0:
   13941 	  printf ("(VEC_SIZE):\tNo entry.\n");
   13942 	  break;
   13943 	case 1:
   13944 	  printf ("(VEC_SIZE):\t4 bytes\n");
   13945 	  break;
   13946 	case 2:
   13947 	  printf ("(VEC_SIZE):\t16 bytes\n");
   13948 	  break;
   13949 	case 3:
   13950 	  printf ("(VEC_SIZE):\treserved\n");
   13951 	  break;
   13952 	}
   13953     }
   13954 
   13955   return TRUE;
   13956 }
   13957 
   13958 static int
   13959 process_gnu_liblist (FILE * file)
   13960 {
   13961   Elf_Internal_Shdr * section;
   13962   Elf_Internal_Shdr * string_sec;
   13963   Elf32_External_Lib * elib;
   13964   char * strtab;
   13965   size_t strtab_size;
   13966   size_t cnt;
   13967   unsigned i;
   13968 
   13969   if (! do_arch)
   13970     return 0;
   13971 
   13972   for (i = 0, section = section_headers;
   13973        i < elf_header.e_shnum;
   13974        i++, section++)
   13975     {
   13976       switch (section->sh_type)
   13977 	{
   13978 	case SHT_GNU_LIBLIST:
   13979 	  if (section->sh_link >= elf_header.e_shnum)
   13980 	    break;
   13981 
   13982 	  elib = (Elf32_External_Lib *)
   13983               get_data (NULL, file, section->sh_offset, 1, section->sh_size,
   13984                         _("liblist section data"));
   13985 
   13986 	  if (elib == NULL)
   13987 	    break;
   13988 	  string_sec = section_headers + section->sh_link;
   13989 
   13990 	  strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
   13991                                       string_sec->sh_size,
   13992                                       _("liblist string table"));
   13993 	  if (strtab == NULL
   13994 	      || section->sh_entsize != sizeof (Elf32_External_Lib))
   13995 	    {
   13996 	      free (elib);
   13997 	      free (strtab);
   13998 	      break;
   13999 	    }
   14000 	  strtab_size = string_sec->sh_size;
   14001 
   14002 	  printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
   14003 		  printable_section_name (section),
   14004 		  (unsigned long) (section->sh_size / sizeof (Elf32_External_Lib)));
   14005 
   14006 	  puts (_("     Library              Time Stamp          Checksum   Version Flags"));
   14007 
   14008 	  for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
   14009 	       ++cnt)
   14010 	    {
   14011 	      Elf32_Lib liblist;
   14012 	      time_t atime;
   14013 	      char timebuf[20];
   14014 	      struct tm * tmp;
   14015 
   14016 	      liblist.l_name = BYTE_GET (elib[cnt].l_name);
   14017 	      atime = BYTE_GET (elib[cnt].l_time_stamp);
   14018 	      liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
   14019 	      liblist.l_version = BYTE_GET (elib[cnt].l_version);
   14020 	      liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
   14021 
   14022 	      tmp = gmtime (&atime);
   14023 	      snprintf (timebuf, sizeof (timebuf),
   14024 			"%04u-%02u-%02uT%02u:%02u:%02u",
   14025 			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
   14026 			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
   14027 
   14028 	      printf ("%3lu: ", (unsigned long) cnt);
   14029 	      if (do_wide)
   14030 		printf ("%-20s", liblist.l_name < strtab_size
   14031 			? strtab + liblist.l_name : _("<corrupt>"));
   14032 	      else
   14033 		printf ("%-20.20s", liblist.l_name < strtab_size
   14034 			? strtab + liblist.l_name : _("<corrupt>"));
   14035 	      printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
   14036 		      liblist.l_version, liblist.l_flags);
   14037 	    }
   14038 
   14039 	  free (elib);
   14040 	  free (strtab);
   14041 	}
   14042     }
   14043 
   14044   return 1;
   14045 }
   14046 
   14047 static const char *
   14048 get_note_type (unsigned e_type)
   14049 {
   14050   static char buff[64];
   14051 
   14052   if (elf_header.e_type == ET_CORE)
   14053     switch (e_type)
   14054       {
   14055       case NT_AUXV:
   14056 	return _("NT_AUXV (auxiliary vector)");
   14057       case NT_PRSTATUS:
   14058 	return _("NT_PRSTATUS (prstatus structure)");
   14059       case NT_FPREGSET:
   14060 	return _("NT_FPREGSET (floating point registers)");
   14061       case NT_PRPSINFO:
   14062 	return _("NT_PRPSINFO (prpsinfo structure)");
   14063       case NT_TASKSTRUCT:
   14064 	return _("NT_TASKSTRUCT (task structure)");
   14065       case NT_PRXFPREG:
   14066 	return _("NT_PRXFPREG (user_xfpregs structure)");
   14067       case NT_PPC_VMX:
   14068 	return _("NT_PPC_VMX (ppc Altivec registers)");
   14069       case NT_PPC_VSX:
   14070 	return _("NT_PPC_VSX (ppc VSX registers)");
   14071       case NT_386_TLS:
   14072 	return _("NT_386_TLS (x86 TLS information)");
   14073       case NT_386_IOPERM:
   14074 	return _("NT_386_IOPERM (x86 I/O permissions)");
   14075       case NT_X86_XSTATE:
   14076 	return _("NT_X86_XSTATE (x86 XSAVE extended state)");
   14077       case NT_S390_HIGH_GPRS:
   14078 	return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
   14079       case NT_S390_TIMER:
   14080 	return _("NT_S390_TIMER (s390 timer register)");
   14081       case NT_S390_TODCMP:
   14082 	return _("NT_S390_TODCMP (s390 TOD comparator register)");
   14083       case NT_S390_TODPREG:
   14084 	return _("NT_S390_TODPREG (s390 TOD programmable register)");
   14085       case NT_S390_CTRS:
   14086 	return _("NT_S390_CTRS (s390 control registers)");
   14087       case NT_S390_PREFIX:
   14088 	return _("NT_S390_PREFIX (s390 prefix register)");
   14089       case NT_S390_LAST_BREAK:
   14090 	return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
   14091       case NT_S390_SYSTEM_CALL:
   14092 	return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
   14093       case NT_S390_TDB:
   14094 	return _("NT_S390_TDB (s390 transaction diagnostic block)");
   14095       case NT_ARM_VFP:
   14096 	return _("NT_ARM_VFP (arm VFP registers)");
   14097       case NT_ARM_TLS:
   14098 	return _("NT_ARM_TLS (AArch TLS registers)");
   14099       case NT_ARM_HW_BREAK:
   14100 	return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
   14101       case NT_ARM_HW_WATCH:
   14102 	return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
   14103       case NT_PSTATUS:
   14104 	return _("NT_PSTATUS (pstatus structure)");
   14105       case NT_FPREGS:
   14106 	return _("NT_FPREGS (floating point registers)");
   14107       case NT_PSINFO:
   14108 	return _("NT_PSINFO (psinfo structure)");
   14109       case NT_LWPSTATUS:
   14110 	return _("NT_LWPSTATUS (lwpstatus_t structure)");
   14111       case NT_LWPSINFO:
   14112 	return _("NT_LWPSINFO (lwpsinfo_t structure)");
   14113       case NT_WIN32PSTATUS:
   14114 	return _("NT_WIN32PSTATUS (win32_pstatus structure)");
   14115       case NT_SIGINFO:
   14116 	return _("NT_SIGINFO (siginfo_t data)");
   14117       case NT_FILE:
   14118 	return _("NT_FILE (mapped files)");
   14119       default:
   14120 	break;
   14121       }
   14122   else
   14123     switch (e_type)
   14124       {
   14125       case NT_VERSION:
   14126 	return _("NT_VERSION (version)");
   14127       case NT_ARCH:
   14128 	return _("NT_ARCH (architecture)");
   14129       default:
   14130 	break;
   14131       }
   14132 
   14133   snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   14134   return buff;
   14135 }
   14136 
   14137 static int
   14138 print_core_note (Elf_Internal_Note *pnote)
   14139 {
   14140   unsigned int addr_size = is_32bit_elf ? 4 : 8;
   14141   bfd_vma count, page_size;
   14142   unsigned char *descdata, *filenames, *descend;
   14143 
   14144   if (pnote->type != NT_FILE)
   14145     return 1;
   14146 
   14147 #ifndef BFD64
   14148   if (!is_32bit_elf)
   14149     {
   14150       printf (_("    Cannot decode 64-bit note in 32-bit build\n"));
   14151       /* Still "successful".  */
   14152       return 1;
   14153     }
   14154 #endif
   14155 
   14156   if (pnote->descsz < 2 * addr_size)
   14157     {
   14158       printf (_("    Malformed note - too short for header\n"));
   14159       return 0;
   14160     }
   14161 
   14162   descdata = (unsigned char *) pnote->descdata;
   14163   descend = descdata + pnote->descsz;
   14164 
   14165   if (descdata[pnote->descsz - 1] != '\0')
   14166     {
   14167       printf (_("    Malformed note - does not end with \\0\n"));
   14168       return 0;
   14169     }
   14170 
   14171   count = byte_get (descdata, addr_size);
   14172   descdata += addr_size;
   14173 
   14174   page_size = byte_get (descdata, addr_size);
   14175   descdata += addr_size;
   14176 
   14177   if (pnote->descsz < 2 * addr_size + count * 3 * addr_size)
   14178     {
   14179       printf (_("    Malformed note - too short for supplied file count\n"));
   14180       return 0;
   14181     }
   14182 
   14183   printf (_("    Page size: "));
   14184   print_vma (page_size, DEC);
   14185   printf ("\n");
   14186 
   14187   printf (_("    %*s%*s%*s\n"),
   14188 	  (int) (2 + 2 * addr_size), _("Start"),
   14189 	  (int) (4 + 2 * addr_size), _("End"),
   14190 	  (int) (4 + 2 * addr_size), _("Page Offset"));
   14191   filenames = descdata + count * 3 * addr_size;
   14192   while (--count > 0)
   14193     {
   14194       bfd_vma start, end, file_ofs;
   14195 
   14196       if (filenames == descend)
   14197 	{
   14198 	  printf (_("    Malformed note - filenames end too early\n"));
   14199 	  return 0;
   14200 	}
   14201 
   14202       start = byte_get (descdata, addr_size);
   14203       descdata += addr_size;
   14204       end = byte_get (descdata, addr_size);
   14205       descdata += addr_size;
   14206       file_ofs = byte_get (descdata, addr_size);
   14207       descdata += addr_size;
   14208 
   14209       printf ("    ");
   14210       print_vma (start, FULL_HEX);
   14211       printf ("  ");
   14212       print_vma (end, FULL_HEX);
   14213       printf ("  ");
   14214       print_vma (file_ofs, FULL_HEX);
   14215       printf ("\n        %s\n", filenames);
   14216 
   14217       filenames += 1 + strlen ((char *) filenames);
   14218     }
   14219 
   14220   return 1;
   14221 }
   14222 
   14223 static const char *
   14224 get_gnu_elf_note_type (unsigned e_type)
   14225 {
   14226   static char buff[64];
   14227 
   14228   switch (e_type)
   14229     {
   14230     case NT_GNU_ABI_TAG:
   14231       return _("NT_GNU_ABI_TAG (ABI version tag)");
   14232     case NT_GNU_HWCAP:
   14233       return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
   14234     case NT_GNU_BUILD_ID:
   14235       return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
   14236     case NT_GNU_GOLD_VERSION:
   14237       return _("NT_GNU_GOLD_VERSION (gold version)");
   14238     default:
   14239       break;
   14240     }
   14241 
   14242   snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   14243   return buff;
   14244 }
   14245 
   14246 static int
   14247 print_gnu_note (Elf_Internal_Note *pnote)
   14248 {
   14249   switch (pnote->type)
   14250     {
   14251     case NT_GNU_BUILD_ID:
   14252       {
   14253 	unsigned long i;
   14254 
   14255 	printf (_("    Build ID: "));
   14256 	for (i = 0; i < pnote->descsz; ++i)
   14257 	  printf ("%02x", pnote->descdata[i] & 0xff);
   14258 	printf ("\n");
   14259       }
   14260       break;
   14261 
   14262     case NT_GNU_ABI_TAG:
   14263       {
   14264 	unsigned long os, major, minor, subminor;
   14265 	const char *osname;
   14266 
   14267 	/* PR 17531: file: 030-599401-0.004.  */
   14268 	if (pnote->descsz < 16)
   14269 	  {
   14270 	    printf (_("    <corrupt GNU_ABI_TAG>\n"));
   14271 	    break;
   14272 	  }
   14273 
   14274 	os = byte_get ((unsigned char *) pnote->descdata, 4);
   14275 	major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
   14276 	minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
   14277 	subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
   14278 
   14279 	switch (os)
   14280 	  {
   14281 	  case GNU_ABI_TAG_LINUX:
   14282 	    osname = "Linux";
   14283 	    break;
   14284 	  case GNU_ABI_TAG_HURD:
   14285 	    osname = "Hurd";
   14286 	    break;
   14287 	  case GNU_ABI_TAG_SOLARIS:
   14288 	    osname = "Solaris";
   14289 	    break;
   14290 	  case GNU_ABI_TAG_FREEBSD:
   14291 	    osname = "FreeBSD";
   14292 	    break;
   14293 	  case GNU_ABI_TAG_NETBSD:
   14294 	    osname = "NetBSD";
   14295 	    break;
   14296 	  default:
   14297 	    osname = "Unknown";
   14298 	    break;
   14299 	  }
   14300 
   14301 	printf (_("    OS: %s, ABI: %ld.%ld.%ld\n"), osname,
   14302 		major, minor, subminor);
   14303       }
   14304       break;
   14305 
   14306     case NT_GNU_GOLD_VERSION:
   14307       {
   14308 	unsigned long i;
   14309 
   14310 	printf (_("    Version: "));
   14311 	for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
   14312 	  printf ("%c", pnote->descdata[i]);
   14313 	printf ("\n");
   14314       }
   14315       break;
   14316     }
   14317 
   14318   return 1;
   14319 }
   14320 
   14321 static const char *
   14322 get_netbsd_elfcore_note_type (unsigned e_type)
   14323 {
   14324   static char buff[64];
   14325 
   14326   if (e_type == NT_NETBSDCORE_PROCINFO)
   14327     {
   14328       /* NetBSD core "procinfo" structure.  */
   14329       return _("NetBSD procinfo structure");
   14330     }
   14331 
   14332   /* As of Jan 2002 there are no other machine-independent notes
   14333      defined for NetBSD core files.  If the note type is less
   14334      than the start of the machine-dependent note types, we don't
   14335      understand it.  */
   14336 
   14337   if (e_type < NT_NETBSDCORE_FIRSTMACH)
   14338     {
   14339       snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   14340       return buff;
   14341     }
   14342 
   14343   switch (elf_header.e_machine)
   14344     {
   14345     /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
   14346        and PT_GETFPREGS == mach+2.  */
   14347 
   14348     case EM_OLD_ALPHA:
   14349     case EM_ALPHA:
   14350     case EM_SPARC:
   14351     case EM_SPARC32PLUS:
   14352     case EM_SPARCV9:
   14353       switch (e_type)
   14354 	{
   14355 	case NT_NETBSDCORE_FIRSTMACH + 0:
   14356 	  return _("PT_GETREGS (reg structure)");
   14357 	case NT_NETBSDCORE_FIRSTMACH + 2:
   14358 	  return _("PT_GETFPREGS (fpreg structure)");
   14359 	default:
   14360 	  break;
   14361 	}
   14362       break;
   14363 
   14364     /* On all other arch's, PT_GETREGS == mach+1 and
   14365        PT_GETFPREGS == mach+3.  */
   14366     default:
   14367       switch (e_type)
   14368 	{
   14369 	case NT_NETBSDCORE_FIRSTMACH + 1:
   14370 	  return _("PT_GETREGS (reg structure)");
   14371 	case NT_NETBSDCORE_FIRSTMACH + 3:
   14372 	  return _("PT_GETFPREGS (fpreg structure)");
   14373 	default:
   14374 	  break;
   14375 	}
   14376     }
   14377 
   14378   snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
   14379 	    e_type - NT_NETBSDCORE_FIRSTMACH);
   14380   return buff;
   14381 }
   14382 
   14383 static const char *
   14384 get_stapsdt_note_type (unsigned e_type)
   14385 {
   14386   static char buff[64];
   14387 
   14388   switch (e_type)
   14389     {
   14390     case NT_STAPSDT:
   14391       return _("NT_STAPSDT (SystemTap probe descriptors)");
   14392 
   14393     default:
   14394       break;
   14395     }
   14396 
   14397   snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   14398   return buff;
   14399 }
   14400 
   14401 static int
   14402 print_stapsdt_note (Elf_Internal_Note *pnote)
   14403 {
   14404   int addr_size = is_32bit_elf ? 4 : 8;
   14405   char *data = pnote->descdata;
   14406   char *data_end = pnote->descdata + pnote->descsz;
   14407   bfd_vma pc, base_addr, semaphore;
   14408   char *provider, *probe, *arg_fmt;
   14409 
   14410   pc = byte_get ((unsigned char *) data, addr_size);
   14411   data += addr_size;
   14412   base_addr = byte_get ((unsigned char *) data, addr_size);
   14413   data += addr_size;
   14414   semaphore = byte_get ((unsigned char *) data, addr_size);
   14415   data += addr_size;
   14416 
   14417   provider = data;
   14418   data += strlen (data) + 1;
   14419   probe = data;
   14420   data += strlen (data) + 1;
   14421   arg_fmt = data;
   14422   data += strlen (data) + 1;
   14423 
   14424   printf (_("    Provider: %s\n"), provider);
   14425   printf (_("    Name: %s\n"), probe);
   14426   printf (_("    Location: "));
   14427   print_vma (pc, FULL_HEX);
   14428   printf (_(", Base: "));
   14429   print_vma (base_addr, FULL_HEX);
   14430   printf (_(", Semaphore: "));
   14431   print_vma (semaphore, FULL_HEX);
   14432   printf ("\n");
   14433   printf (_("    Arguments: %s\n"), arg_fmt);
   14434 
   14435   return data == data_end;
   14436 }
   14437 
   14438 static const char *
   14439 get_ia64_vms_note_type (unsigned e_type)
   14440 {
   14441   static char buff[64];
   14442 
   14443   switch (e_type)
   14444     {
   14445     case NT_VMS_MHD:
   14446       return _("NT_VMS_MHD (module header)");
   14447     case NT_VMS_LNM:
   14448       return _("NT_VMS_LNM (language name)");
   14449     case NT_VMS_SRC:
   14450       return _("NT_VMS_SRC (source files)");
   14451     case NT_VMS_TITLE:
   14452       return "NT_VMS_TITLE";
   14453     case NT_VMS_EIDC:
   14454       return _("NT_VMS_EIDC (consistency check)");
   14455     case NT_VMS_FPMODE:
   14456       return _("NT_VMS_FPMODE (FP mode)");
   14457     case NT_VMS_LINKTIME:
   14458       return "NT_VMS_LINKTIME";
   14459     case NT_VMS_IMGNAM:
   14460       return _("NT_VMS_IMGNAM (image name)");
   14461     case NT_VMS_IMGID:
   14462       return _("NT_VMS_IMGID (image id)");
   14463     case NT_VMS_LINKID:
   14464       return _("NT_VMS_LINKID (link id)");
   14465     case NT_VMS_IMGBID:
   14466       return _("NT_VMS_IMGBID (build id)");
   14467     case NT_VMS_GSTNAM:
   14468       return _("NT_VMS_GSTNAM (sym table name)");
   14469     case NT_VMS_ORIG_DYN:
   14470       return "NT_VMS_ORIG_DYN";
   14471     case NT_VMS_PATCHTIME:
   14472       return "NT_VMS_PATCHTIME";
   14473     default:
   14474       snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   14475       return buff;
   14476     }
   14477 }
   14478 
   14479 static int
   14480 print_ia64_vms_note (Elf_Internal_Note * pnote)
   14481 {
   14482   switch (pnote->type)
   14483     {
   14484     case NT_VMS_MHD:
   14485       if (pnote->descsz > 36)
   14486         {
   14487           size_t l = strlen (pnote->descdata + 34);
   14488           printf (_("    Creation date  : %.17s\n"), pnote->descdata);
   14489           printf (_("    Last patch date: %.17s\n"), pnote->descdata + 17);
   14490           printf (_("    Module name    : %s\n"), pnote->descdata + 34);
   14491           printf (_("    Module version : %s\n"), pnote->descdata + 34 + l + 1);
   14492         }
   14493       else
   14494         printf (_("    Invalid size\n"));
   14495       break;
   14496     case NT_VMS_LNM:
   14497       printf (_("   Language: %s\n"), pnote->descdata);
   14498       break;
   14499 #ifdef BFD64
   14500     case NT_VMS_FPMODE:
   14501       printf (_("   Floating Point mode: "));
   14502       printf ("0x%016" BFD_VMA_FMT "x\n",
   14503               (bfd_vma)byte_get ((unsigned char *)pnote->descdata, 8));
   14504       break;
   14505     case NT_VMS_LINKTIME:
   14506       printf (_("   Link time: "));
   14507       print_vms_time
   14508         ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
   14509       printf ("\n");
   14510       break;
   14511     case NT_VMS_PATCHTIME:
   14512       printf (_("   Patch time: "));
   14513       print_vms_time
   14514         ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
   14515       printf ("\n");
   14516       break;
   14517     case NT_VMS_ORIG_DYN:
   14518       printf (_("   Major id: %u,  minor id: %u\n"),
   14519               (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
   14520               (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
   14521       printf (_("   Last modified  : "));
   14522       print_vms_time
   14523         ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
   14524       printf (_("\n   Link flags  : "));
   14525       printf ("0x%016" BFD_VMA_FMT "x\n",
   14526               (bfd_vma)byte_get ((unsigned char *)pnote->descdata + 16, 8));
   14527       printf (_("   Header flags: 0x%08x\n"),
   14528               (unsigned)byte_get ((unsigned char *)pnote->descdata + 24, 4));
   14529       printf (_("   Image id    : %s\n"), pnote->descdata + 32);
   14530       break;
   14531 #endif
   14532     case NT_VMS_IMGNAM:
   14533       printf (_("    Image name: %s\n"), pnote->descdata);
   14534       break;
   14535     case NT_VMS_GSTNAM:
   14536       printf (_("    Global symbol table name: %s\n"), pnote->descdata);
   14537       break;
   14538     case NT_VMS_IMGID:
   14539       printf (_("    Image id: %s\n"), pnote->descdata);
   14540       break;
   14541     case NT_VMS_LINKID:
   14542       printf (_("    Linker id: %s\n"), pnote->descdata);
   14543       break;
   14544     default:
   14545       break;
   14546     }
   14547   return 1;
   14548 }
   14549 
   14550 /* Note that by the ELF standard, the name field is already null byte
   14551    terminated, and namesz includes the terminating null byte.
   14552    I.E. the value of namesz for the name "FSF" is 4.
   14553 
   14554    If the value of namesz is zero, there is no name present.  */
   14555 static int
   14556 process_note (Elf_Internal_Note * pnote)
   14557 {
   14558   const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
   14559   const char * nt;
   14560 
   14561   if (pnote->namesz == 0)
   14562     /* If there is no note name, then use the default set of
   14563        note type strings.  */
   14564     nt = get_note_type (pnote->type);
   14565 
   14566   else if (const_strneq (pnote->namedata, "GNU"))
   14567     /* GNU-specific object file notes.  */
   14568     nt = get_gnu_elf_note_type (pnote->type);
   14569 
   14570   else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
   14571     /* NetBSD-specific core file notes.  */
   14572     nt = get_netbsd_elfcore_note_type (pnote->type);
   14573 
   14574   else if (strneq (pnote->namedata, "SPU/", 4))
   14575     {
   14576       /* SPU-specific core file notes.  */
   14577       nt = pnote->namedata + 4;
   14578       name = "SPU";
   14579     }
   14580 
   14581   else if (const_strneq (pnote->namedata, "IPF/VMS"))
   14582     /* VMS/ia64-specific file notes.  */
   14583     nt = get_ia64_vms_note_type (pnote->type);
   14584 
   14585   else if (const_strneq (pnote->namedata, "stapsdt"))
   14586     nt = get_stapsdt_note_type (pnote->type);
   14587 
   14588   else
   14589     /* Don't recognize this note name; just use the default set of
   14590        note type strings.  */
   14591     nt = get_note_type (pnote->type);
   14592 
   14593   printf ("  %-20s 0x%08lx\t%s\n", name, pnote->descsz, nt);
   14594 
   14595   if (const_strneq (pnote->namedata, "IPF/VMS"))
   14596     return print_ia64_vms_note (pnote);
   14597   else if (const_strneq (pnote->namedata, "GNU"))
   14598     return print_gnu_note (pnote);
   14599   else if (const_strneq (pnote->namedata, "stapsdt"))
   14600     return print_stapsdt_note (pnote);
   14601   else if (const_strneq (pnote->namedata, "CORE"))
   14602     return print_core_note (pnote);
   14603   else
   14604     return 1;
   14605 }
   14606 
   14607 
   14608 static int
   14609 process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length)
   14610 {
   14611   Elf_External_Note * pnotes;
   14612   Elf_External_Note * external;
   14613   int res = 1;
   14614 
   14615   if (length <= 0)
   14616     return 0;
   14617 
   14618   pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length,
   14619 					   _("notes"));
   14620   if (pnotes == NULL)
   14621     return 0;
   14622 
   14623   external = pnotes;
   14624 
   14625   printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
   14626 	  (unsigned long) offset, (unsigned long) length);
   14627   printf (_("  %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
   14628 
   14629   while ((char *) external < (char *) pnotes + length)
   14630     {
   14631       Elf_Internal_Note inote;
   14632       size_t min_notesz;
   14633       char *next;
   14634       char * temp = NULL;
   14635       size_t data_remaining = ((char *) pnotes + length) - (char *) external;
   14636 
   14637       if (!is_ia64_vms ())
   14638 	{
   14639 	  /* PR binutils/15191
   14640 	     Make sure that there is enough data to read.  */
   14641 	  min_notesz = offsetof (Elf_External_Note, name);
   14642 	  if (data_remaining < min_notesz)
   14643 	    {
   14644 	      warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
   14645 		    (int) data_remaining);
   14646 	      break;
   14647 	    }
   14648 	  inote.type     = BYTE_GET (external->type);
   14649 	  inote.namesz   = BYTE_GET (external->namesz);
   14650 	  inote.namedata = external->name;
   14651 	  inote.descsz   = BYTE_GET (external->descsz);
   14652 	  inote.descdata = inote.namedata + align_power (inote.namesz, 2);
   14653 	  inote.descpos  = offset + (inote.descdata - (char *) pnotes);
   14654 	  next = inote.descdata + align_power (inote.descsz, 2);
   14655 	}
   14656       else
   14657 	{
   14658 	  Elf64_External_VMS_Note *vms_external;
   14659 
   14660 	  /* PR binutils/15191
   14661 	     Make sure that there is enough data to read.  */
   14662 	  min_notesz = offsetof (Elf64_External_VMS_Note, name);
   14663 	  if (data_remaining < min_notesz)
   14664 	    {
   14665 	      warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
   14666 		    (int) data_remaining);
   14667 	      break;
   14668 	    }
   14669 
   14670 	  vms_external = (Elf64_External_VMS_Note *) external;
   14671 	  inote.type     = BYTE_GET (vms_external->type);
   14672 	  inote.namesz   = BYTE_GET (vms_external->namesz);
   14673 	  inote.namedata = vms_external->name;
   14674 	  inote.descsz   = BYTE_GET (vms_external->descsz);
   14675 	  inote.descdata = inote.namedata + align_power (inote.namesz, 3);
   14676 	  inote.descpos  = offset + (inote.descdata - (char *) pnotes);
   14677 	  next = inote.descdata + align_power (inote.descsz, 3);
   14678 	}
   14679 
   14680       if (inote.descdata < (char *) external + min_notesz
   14681 	  || next < (char *) external + min_notesz
   14682 	  || data_remaining < (size_t)(next - (char *) external))
   14683 	{
   14684 	  warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
   14685 		(unsigned long) ((char *) external - (char *) pnotes));
   14686 	  warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx\n"),
   14687 		inote.type, inote.namesz, inote.descsz);
   14688 	  break;
   14689 	}
   14690 
   14691       external = (Elf_External_Note *) next;
   14692 
   14693       /* Verify that name is null terminated.  It appears that at least
   14694 	 one version of Linux (RedHat 6.0) generates corefiles that don't
   14695 	 comply with the ELF spec by failing to include the null byte in
   14696 	 namesz.  */
   14697       if (inote.namedata[inote.namesz - 1] != '\0')
   14698 	{
   14699 	  temp = (char *) malloc (inote.namesz + 1);
   14700 
   14701 	  if (temp == NULL)
   14702 	    {
   14703 	      error (_("Out of memory allocating space for inote name\n"));
   14704 	      res = 0;
   14705 	      break;
   14706 	    }
   14707 
   14708 	  strncpy (temp, inote.namedata, inote.namesz);
   14709 	  temp[inote.namesz] = 0;
   14710 
   14711 	  /* warn (_("'%s' NOTE name not properly null terminated\n"), temp);  */
   14712 	  inote.namedata = temp;
   14713 	}
   14714 
   14715       res &= process_note (& inote);
   14716 
   14717       if (temp != NULL)
   14718 	{
   14719 	  free (temp);
   14720 	  temp = NULL;
   14721 	}
   14722     }
   14723 
   14724   free (pnotes);
   14725 
   14726   return res;
   14727 }
   14728 
   14729 static int
   14730 process_corefile_note_segments (FILE * file)
   14731 {
   14732   Elf_Internal_Phdr * segment;
   14733   unsigned int i;
   14734   int res = 1;
   14735 
   14736   if (! get_program_headers (file))
   14737       return 0;
   14738 
   14739   for (i = 0, segment = program_headers;
   14740        i < elf_header.e_phnum;
   14741        i++, segment++)
   14742     {
   14743       if (segment->p_type == PT_NOTE)
   14744 	res &= process_corefile_note_segment (file,
   14745 					      (bfd_vma) segment->p_offset,
   14746 					      (bfd_vma) segment->p_filesz);
   14747     }
   14748 
   14749   return res;
   14750 }
   14751 
   14752 static int
   14753 process_note_sections (FILE * file)
   14754 {
   14755   Elf_Internal_Shdr * section;
   14756   unsigned long i;
   14757   int n = 0;
   14758   int res = 1;
   14759 
   14760   for (i = 0, section = section_headers;
   14761        i < elf_header.e_shnum && section != NULL;
   14762        i++, section++)
   14763     if (section->sh_type == SHT_NOTE)
   14764       {
   14765 	res &= process_corefile_note_segment (file,
   14766 					      (bfd_vma) section->sh_offset,
   14767 					      (bfd_vma) section->sh_size);
   14768 	n++;
   14769       }
   14770 
   14771   if (n == 0)
   14772     /* Try processing NOTE segments instead.  */
   14773     return process_corefile_note_segments (file);
   14774 
   14775   return res;
   14776 }
   14777 
   14778 static int
   14779 process_notes (FILE * file)
   14780 {
   14781   /* If we have not been asked to display the notes then do nothing.  */
   14782   if (! do_notes)
   14783     return 1;
   14784 
   14785   if (elf_header.e_type != ET_CORE)
   14786     return process_note_sections (file);
   14787 
   14788   /* No program headers means no NOTE segment.  */
   14789   if (elf_header.e_phnum > 0)
   14790     return process_corefile_note_segments (file);
   14791 
   14792   printf (_("No note segments present in the core file.\n"));
   14793   return 1;
   14794 }
   14795 
   14796 static int
   14797 process_arch_specific (FILE * file)
   14798 {
   14799   if (! do_arch)
   14800     return 1;
   14801 
   14802   switch (elf_header.e_machine)
   14803     {
   14804     case EM_ARM:
   14805       return process_arm_specific (file);
   14806     case EM_MIPS:
   14807     case EM_MIPS_RS3_LE:
   14808       return process_mips_specific (file);
   14809       break;
   14810     case EM_NDS32:
   14811       return process_nds32_specific (file);
   14812       break;
   14813     case EM_PPC:
   14814       return process_power_specific (file);
   14815       break;
   14816     case EM_SPARC:
   14817     case EM_SPARC32PLUS:
   14818     case EM_SPARCV9:
   14819       return process_sparc_specific (file);
   14820       break;
   14821     case EM_TI_C6000:
   14822       return process_tic6x_specific (file);
   14823       break;
   14824     case EM_MSP430:
   14825       return process_msp430x_specific (file);
   14826     default:
   14827       break;
   14828     }
   14829   return 1;
   14830 }
   14831 
   14832 static int
   14833 get_file_header (FILE * file)
   14834 {
   14835   /* Read in the identity array.  */
   14836   if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
   14837     return 0;
   14838 
   14839   /* Determine how to read the rest of the header.  */
   14840   switch (elf_header.e_ident[EI_DATA])
   14841     {
   14842     default: /* fall through */
   14843     case ELFDATANONE: /* fall through */
   14844     case ELFDATA2LSB:
   14845       byte_get = byte_get_little_endian;
   14846       byte_put = byte_put_little_endian;
   14847       break;
   14848     case ELFDATA2MSB:
   14849       byte_get = byte_get_big_endian;
   14850       byte_put = byte_put_big_endian;
   14851       break;
   14852     }
   14853 
   14854   /* For now we only support 32 bit and 64 bit ELF files.  */
   14855   is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
   14856 
   14857   /* Read in the rest of the header.  */
   14858   if (is_32bit_elf)
   14859     {
   14860       Elf32_External_Ehdr ehdr32;
   14861 
   14862       if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
   14863 	return 0;
   14864 
   14865       elf_header.e_type      = BYTE_GET (ehdr32.e_type);
   14866       elf_header.e_machine   = BYTE_GET (ehdr32.e_machine);
   14867       elf_header.e_version   = BYTE_GET (ehdr32.e_version);
   14868       elf_header.e_entry     = BYTE_GET (ehdr32.e_entry);
   14869       elf_header.e_phoff     = BYTE_GET (ehdr32.e_phoff);
   14870       elf_header.e_shoff     = BYTE_GET (ehdr32.e_shoff);
   14871       elf_header.e_flags     = BYTE_GET (ehdr32.e_flags);
   14872       elf_header.e_ehsize    = BYTE_GET (ehdr32.e_ehsize);
   14873       elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
   14874       elf_header.e_phnum     = BYTE_GET (ehdr32.e_phnum);
   14875       elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
   14876       elf_header.e_shnum     = BYTE_GET (ehdr32.e_shnum);
   14877       elf_header.e_shstrndx  = BYTE_GET (ehdr32.e_shstrndx);
   14878     }
   14879   else
   14880     {
   14881       Elf64_External_Ehdr ehdr64;
   14882 
   14883       /* If we have been compiled with sizeof (bfd_vma) == 4, then
   14884 	 we will not be able to cope with the 64bit data found in
   14885 	 64 ELF files.  Detect this now and abort before we start
   14886 	 overwriting things.  */
   14887       if (sizeof (bfd_vma) < 8)
   14888 	{
   14889 	  error (_("This instance of readelf has been built without support for a\n\
   14890 64 bit data type and so it cannot read 64 bit ELF files.\n"));
   14891 	  return 0;
   14892 	}
   14893 
   14894       if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
   14895 	return 0;
   14896 
   14897       elf_header.e_type      = BYTE_GET (ehdr64.e_type);
   14898       elf_header.e_machine   = BYTE_GET (ehdr64.e_machine);
   14899       elf_header.e_version   = BYTE_GET (ehdr64.e_version);
   14900       elf_header.e_entry     = BYTE_GET (ehdr64.e_entry);
   14901       elf_header.e_phoff     = BYTE_GET (ehdr64.e_phoff);
   14902       elf_header.e_shoff     = BYTE_GET (ehdr64.e_shoff);
   14903       elf_header.e_flags     = BYTE_GET (ehdr64.e_flags);
   14904       elf_header.e_ehsize    = BYTE_GET (ehdr64.e_ehsize);
   14905       elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
   14906       elf_header.e_phnum     = BYTE_GET (ehdr64.e_phnum);
   14907       elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
   14908       elf_header.e_shnum     = BYTE_GET (ehdr64.e_shnum);
   14909       elf_header.e_shstrndx  = BYTE_GET (ehdr64.e_shstrndx);
   14910     }
   14911 
   14912   if (elf_header.e_shoff)
   14913     {
   14914       /* There may be some extensions in the first section header.  Don't
   14915 	 bomb if we can't read it.  */
   14916       if (is_32bit_elf)
   14917 	get_32bit_section_headers (file, TRUE);
   14918       else
   14919 	get_64bit_section_headers (file, TRUE);
   14920     }
   14921 
   14922   return 1;
   14923 }
   14924 
   14925 /* Process one ELF object file according to the command line options.
   14926    This file may actually be stored in an archive.  The file is
   14927    positioned at the start of the ELF object.  */
   14928 
   14929 static int
   14930 process_object (char * file_name, FILE * file)
   14931 {
   14932   unsigned int i;
   14933 
   14934   if (! get_file_header (file))
   14935     {
   14936       error (_("%s: Failed to read file header\n"), file_name);
   14937       return 1;
   14938     }
   14939 
   14940   /* Initialise per file variables.  */
   14941   for (i = ARRAY_SIZE (version_info); i--;)
   14942     version_info[i] = 0;
   14943 
   14944   for (i = ARRAY_SIZE (dynamic_info); i--;)
   14945     dynamic_info[i] = 0;
   14946   dynamic_info_DT_GNU_HASH = 0;
   14947 
   14948   /* Process the file.  */
   14949   if (show_name)
   14950     printf (_("\nFile: %s\n"), file_name);
   14951 
   14952   /* Initialise the dump_sects array from the cmdline_dump_sects array.
   14953      Note we do this even if cmdline_dump_sects is empty because we
   14954      must make sure that the dump_sets array is zeroed out before each
   14955      object file is processed.  */
   14956   if (num_dump_sects > num_cmdline_dump_sects)
   14957     memset (dump_sects, 0, num_dump_sects * sizeof (* dump_sects));
   14958 
   14959   if (num_cmdline_dump_sects > 0)
   14960     {
   14961       if (num_dump_sects == 0)
   14962 	/* A sneaky way of allocating the dump_sects array.  */
   14963 	request_dump_bynumber (num_cmdline_dump_sects, 0);
   14964 
   14965       assert (num_dump_sects >= num_cmdline_dump_sects);
   14966       memcpy (dump_sects, cmdline_dump_sects,
   14967 	      num_cmdline_dump_sects * sizeof (* dump_sects));
   14968     }
   14969 
   14970   if (! process_file_header ())
   14971     return 1;
   14972 
   14973   if (! process_section_headers (file))
   14974     {
   14975       /* Without loaded section headers we cannot process lots of
   14976 	 things.  */
   14977       do_unwind = do_version = do_dump = do_arch = 0;
   14978 
   14979       if (! do_using_dynamic)
   14980 	do_syms = do_dyn_syms = do_reloc = 0;
   14981     }
   14982 
   14983   if (! process_section_groups (file))
   14984     {
   14985       /* Without loaded section groups we cannot process unwind.  */
   14986       do_unwind = 0;
   14987     }
   14988 
   14989   if (process_program_headers (file))
   14990     process_dynamic_section (file);
   14991 
   14992   process_relocs (file);
   14993 
   14994   process_unwind (file);
   14995 
   14996   process_symbol_table (file);
   14997 
   14998   process_syminfo (file);
   14999 
   15000   process_version_sections (file);
   15001 
   15002   process_section_contents (file);
   15003 
   15004   process_notes (file);
   15005 
   15006   process_gnu_liblist (file);
   15007 
   15008   process_arch_specific (file);
   15009 
   15010   if (program_headers)
   15011     {
   15012       free (program_headers);
   15013       program_headers = NULL;
   15014     }
   15015 
   15016   if (section_headers)
   15017     {
   15018       free (section_headers);
   15019       section_headers = NULL;
   15020     }
   15021 
   15022   if (string_table)
   15023     {
   15024       free (string_table);
   15025       string_table = NULL;
   15026       string_table_length = 0;
   15027     }
   15028 
   15029   if (dynamic_strings)
   15030     {
   15031       free (dynamic_strings);
   15032       dynamic_strings = NULL;
   15033       dynamic_strings_length = 0;
   15034     }
   15035 
   15036   if (dynamic_symbols)
   15037     {
   15038       free (dynamic_symbols);
   15039       dynamic_symbols = NULL;
   15040       num_dynamic_syms = 0;
   15041     }
   15042 
   15043   if (dynamic_syminfo)
   15044     {
   15045       free (dynamic_syminfo);
   15046       dynamic_syminfo = NULL;
   15047     }
   15048 
   15049   if (dynamic_section)
   15050     {
   15051       free (dynamic_section);
   15052       dynamic_section = NULL;
   15053     }
   15054 
   15055   if (section_headers_groups)
   15056     {
   15057       free (section_headers_groups);
   15058       section_headers_groups = NULL;
   15059     }
   15060 
   15061   if (section_groups)
   15062     {
   15063       struct group_list * g;
   15064       struct group_list * next;
   15065 
   15066       for (i = 0; i < group_count; i++)
   15067 	{
   15068 	  for (g = section_groups [i].root; g != NULL; g = next)
   15069 	    {
   15070 	      next = g->next;
   15071 	      free (g);
   15072 	    }
   15073 	}
   15074 
   15075       free (section_groups);
   15076       section_groups = NULL;
   15077     }
   15078 
   15079   free_debug_memory ();
   15080 
   15081   return 0;
   15082 }
   15083 
   15084 /* Process an ELF archive.
   15085    On entry the file is positioned just after the ARMAG string.  */
   15086 
   15087 static int
   15088 process_archive (char * file_name, FILE * file, bfd_boolean is_thin_archive)
   15089 {
   15090   struct archive_info arch;
   15091   struct archive_info nested_arch;
   15092   size_t got;
   15093   int ret;
   15094 
   15095   show_name = 1;
   15096 
   15097   /* The ARCH structure is used to hold information about this archive.  */
   15098   arch.file_name = NULL;
   15099   arch.file = NULL;
   15100   arch.index_array = NULL;
   15101   arch.sym_table = NULL;
   15102   arch.longnames = NULL;
   15103 
   15104   /* The NESTED_ARCH structure is used as a single-item cache of information
   15105      about a nested archive (when members of a thin archive reside within
   15106      another regular archive file).  */
   15107   nested_arch.file_name = NULL;
   15108   nested_arch.file = NULL;
   15109   nested_arch.index_array = NULL;
   15110   nested_arch.sym_table = NULL;
   15111   nested_arch.longnames = NULL;
   15112 
   15113   if (setup_archive (&arch, file_name, file, is_thin_archive, do_archive_index) != 0)
   15114     {
   15115       ret = 1;
   15116       goto out;
   15117     }
   15118 
   15119   if (do_archive_index)
   15120     {
   15121       if (arch.sym_table == NULL)
   15122 	error (_("%s: unable to dump the index as none was found\n"), file_name);
   15123       else
   15124 	{
   15125 	  unsigned int i, l;
   15126 	  unsigned long current_pos;
   15127 
   15128 	  printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
   15129 		  file_name, (long) arch.index_num, arch.sym_size);
   15130 	  current_pos = ftell (file);
   15131 
   15132 	  for (i = l = 0; i < arch.index_num; i++)
   15133 	    {
   15134 	      if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
   15135 	        {
   15136 	          char * member_name;
   15137 
   15138 		  member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
   15139 
   15140                   if (member_name != NULL)
   15141                     {
   15142 	              char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
   15143 
   15144                       if (qualified_name != NULL)
   15145                         {
   15146 		          printf (_("Contents of binary %s at offset "), qualified_name);
   15147 			  (void) print_vma (arch.index_array[i], PREFIX_HEX);
   15148 			  putchar ('\n');
   15149 		          free (qualified_name);
   15150 		        }
   15151 		    }
   15152 		}
   15153 
   15154 	      if (l >= arch.sym_size)
   15155 		{
   15156 		  error (_("%s: end of the symbol table reached before the end of the index\n"),
   15157 			 file_name);
   15158 		  break;
   15159 		}
   15160 	      printf ("\t%s\n", arch.sym_table + l);
   15161 	      l += strlen (arch.sym_table + l) + 1;
   15162 	    }
   15163 
   15164 	  if (arch.uses_64bit_indicies)
   15165 	    l = (l + 7) & ~ 7;
   15166 	  else
   15167 	    l += l & 1;
   15168 
   15169 	  if (l < arch.sym_size)
   15170 	    error (_("%s: %ld bytes remain in the symbol table, but without corresponding entries in the index table\n"),
   15171 		   file_name, arch.sym_size - l);
   15172 
   15173 	  if (fseek (file, current_pos, SEEK_SET) != 0)
   15174 	    {
   15175 	      error (_("%s: failed to seek back to start of object files in the archive\n"), file_name);
   15176 	      ret = 1;
   15177 	      goto out;
   15178 	    }
   15179 	}
   15180 
   15181       if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
   15182 	  && !do_segments && !do_header && !do_dump && !do_version
   15183 	  && !do_histogram && !do_debugging && !do_arch && !do_notes
   15184 	  && !do_section_groups && !do_dyn_syms)
   15185 	{
   15186 	  ret = 0; /* Archive index only.  */
   15187 	  goto out;
   15188 	}
   15189     }
   15190 
   15191   ret = 0;
   15192 
   15193   while (1)
   15194     {
   15195       char * name;
   15196       size_t namelen;
   15197       char * qualified_name;
   15198 
   15199       /* Read the next archive header.  */
   15200       if (fseek (file, arch.next_arhdr_offset, SEEK_SET) != 0)
   15201         {
   15202           error (_("%s: failed to seek to next archive header\n"), file_name);
   15203           return 1;
   15204         }
   15205       got = fread (&arch.arhdr, 1, sizeof arch.arhdr, file);
   15206       if (got != sizeof arch.arhdr)
   15207         {
   15208           if (got == 0)
   15209 	    break;
   15210           error (_("%s: failed to read archive header\n"), file_name);
   15211           ret = 1;
   15212           break;
   15213         }
   15214       if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
   15215         {
   15216           error (_("%s: did not find a valid archive header\n"), arch.file_name);
   15217           ret = 1;
   15218           break;
   15219         }
   15220 
   15221       arch.next_arhdr_offset += sizeof arch.arhdr;
   15222 
   15223       archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
   15224       if (archive_file_size & 01)
   15225         ++archive_file_size;
   15226 
   15227       name = get_archive_member_name (&arch, &nested_arch);
   15228       if (name == NULL)
   15229 	{
   15230 	  error (_("%s: bad archive file name\n"), file_name);
   15231 	  ret = 1;
   15232 	  break;
   15233 	}
   15234       namelen = strlen (name);
   15235 
   15236       qualified_name = make_qualified_name (&arch, &nested_arch, name);
   15237       if (qualified_name == NULL)
   15238 	{
   15239 	  error (_("%s: bad archive file name\n"), file_name);
   15240 	  ret = 1;
   15241 	  break;
   15242 	}
   15243 
   15244       if (is_thin_archive && arch.nested_member_origin == 0)
   15245         {
   15246           /* This is a proxy for an external member of a thin archive.  */
   15247           FILE * member_file;
   15248           char * member_file_name = adjust_relative_path (file_name, name, namelen);
   15249           if (member_file_name == NULL)
   15250             {
   15251               ret = 1;
   15252               break;
   15253             }
   15254 
   15255           member_file = fopen (member_file_name, "rb");
   15256           if (member_file == NULL)
   15257             {
   15258               error (_("Input file '%s' is not readable.\n"), member_file_name);
   15259               free (member_file_name);
   15260               ret = 1;
   15261               break;
   15262             }
   15263 
   15264           archive_file_offset = arch.nested_member_origin;
   15265 
   15266           ret |= process_object (qualified_name, member_file);
   15267 
   15268           fclose (member_file);
   15269           free (member_file_name);
   15270         }
   15271       else if (is_thin_archive)
   15272         {
   15273 	  /* PR 15140: Allow for corrupt thin archives.  */
   15274 	  if (nested_arch.file == NULL)
   15275 	    {
   15276 	      error (_("%s: contains corrupt thin archive: %s\n"),
   15277 		     file_name, name);
   15278 	      ret = 1;
   15279 	      break;
   15280 	    }
   15281 
   15282           /* This is a proxy for a member of a nested archive.  */
   15283           archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
   15284 
   15285           /* The nested archive file will have been opened and setup by
   15286              get_archive_member_name.  */
   15287           if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
   15288             {
   15289               error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
   15290               ret = 1;
   15291               break;
   15292             }
   15293 
   15294           ret |= process_object (qualified_name, nested_arch.file);
   15295         }
   15296       else
   15297         {
   15298           archive_file_offset = arch.next_arhdr_offset;
   15299           arch.next_arhdr_offset += archive_file_size;
   15300 
   15301           ret |= process_object (qualified_name, file);
   15302         }
   15303 
   15304       if (dump_sects != NULL)
   15305 	{
   15306 	  free (dump_sects);
   15307 	  dump_sects = NULL;
   15308 	  num_dump_sects = 0;
   15309 	}
   15310 
   15311       free (qualified_name);
   15312     }
   15313 
   15314  out:
   15315   if (nested_arch.file != NULL)
   15316     fclose (nested_arch.file);
   15317   release_archive (&nested_arch);
   15318   release_archive (&arch);
   15319 
   15320   return ret;
   15321 }
   15322 
   15323 static int
   15324 process_file (char * file_name)
   15325 {
   15326   FILE * file;
   15327   struct stat statbuf;
   15328   char armag[SARMAG];
   15329   int ret;
   15330 
   15331   if (stat (file_name, &statbuf) < 0)
   15332     {
   15333       if (errno == ENOENT)
   15334 	error (_("'%s': No such file\n"), file_name);
   15335       else
   15336 	error (_("Could not locate '%s'.  System error message: %s\n"),
   15337 	       file_name, strerror (errno));
   15338       return 1;
   15339     }
   15340 
   15341   if (! S_ISREG (statbuf.st_mode))
   15342     {
   15343       error (_("'%s' is not an ordinary file\n"), file_name);
   15344       return 1;
   15345     }
   15346 
   15347   file = fopen (file_name, "rb");
   15348   if (file == NULL)
   15349     {
   15350       error (_("Input file '%s' is not readable.\n"), file_name);
   15351       return 1;
   15352     }
   15353 
   15354   if (fread (armag, SARMAG, 1, file) != 1)
   15355     {
   15356       error (_("%s: Failed to read file's magic number\n"), file_name);
   15357       fclose (file);
   15358       return 1;
   15359     }
   15360 
   15361   current_file_size = (bfd_size_type) statbuf.st_size;
   15362 
   15363   if (memcmp (armag, ARMAG, SARMAG) == 0)
   15364     ret = process_archive (file_name, file, FALSE);
   15365   else if (memcmp (armag, ARMAGT, SARMAG) == 0)
   15366     ret = process_archive (file_name, file, TRUE);
   15367   else
   15368     {
   15369       if (do_archive_index)
   15370 	error (_("File %s is not an archive so its index cannot be displayed.\n"),
   15371 	       file_name);
   15372 
   15373       rewind (file);
   15374       archive_file_size = archive_file_offset = 0;
   15375       ret = process_object (file_name, file);
   15376     }
   15377 
   15378   fclose (file);
   15379 
   15380   current_file_size = 0;
   15381   return ret;
   15382 }
   15383 
   15384 #ifdef SUPPORT_DISASSEMBLY
   15385 /* Needed by the i386 disassembler.  For extra credit, someone could
   15386    fix this so that we insert symbolic addresses here, esp for GOT/PLT
   15387    symbols.  */
   15388 
   15389 void
   15390 print_address (unsigned int addr, FILE * outfile)
   15391 {
   15392   fprintf (outfile,"0x%8.8x", addr);
   15393 }
   15394 
   15395 /* Needed by the i386 disassembler.  */
   15396 void
   15397 db_task_printsym (unsigned int addr)
   15398 {
   15399   print_address (addr, stderr);
   15400 }
   15401 #endif
   15402 
   15403 int
   15404 main (int argc, char ** argv)
   15405 {
   15406   int err;
   15407 
   15408 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
   15409   setlocale (LC_MESSAGES, "");
   15410 #endif
   15411 #if defined (HAVE_SETLOCALE)
   15412   setlocale (LC_CTYPE, "");
   15413 #endif
   15414   bindtextdomain (PACKAGE, LOCALEDIR);
   15415   textdomain (PACKAGE);
   15416 
   15417   expandargv (&argc, &argv);
   15418 
   15419   parse_args (argc, argv);
   15420 
   15421   if (num_dump_sects > 0)
   15422     {
   15423       /* Make a copy of the dump_sects array.  */
   15424       cmdline_dump_sects = (dump_type *)
   15425           malloc (num_dump_sects * sizeof (* dump_sects));
   15426       if (cmdline_dump_sects == NULL)
   15427 	error (_("Out of memory allocating dump request table.\n"));
   15428       else
   15429 	{
   15430 	  memcpy (cmdline_dump_sects, dump_sects,
   15431 		  num_dump_sects * sizeof (* dump_sects));
   15432 	  num_cmdline_dump_sects = num_dump_sects;
   15433 	}
   15434     }
   15435 
   15436   if (optind < (argc - 1))
   15437     show_name = 1;
   15438 
   15439   err = 0;
   15440   while (optind < argc)
   15441     err |= process_file (argv[optind++]);
   15442 
   15443   if (dump_sects != NULL)
   15444     free (dump_sects);
   15445   if (cmdline_dump_sects != NULL)
   15446     free (cmdline_dump_sects);
   15447 
   15448   return err;
   15449 }
   15450