Home | History | Annotate | Download | only in binutils
      1 /* readelf.c -- display contents of an ELF format file
      2    Copyright (C) 1998-2016 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 #include <zlib.h>
     49 #ifdef HAVE_WCHAR_H
     50 #include <wchar.h>
     51 #endif
     52 
     53 #if __GNUC__ >= 2
     54 /* Define BFD64 here, even if our default architecture is 32 bit ELF
     55    as this will allow us to read in and parse 64bit and 32bit ELF files.
     56    Only do this if we believe that the compiler can support a 64 bit
     57    data type.  For now we only rely on GCC being able to do this.  */
     58 #define BFD64
     59 #endif
     60 
     61 #include "bfd.h"
     62 #include "bucomm.h"
     63 #include "elfcomm.h"
     64 #include "dwarf.h"
     65 
     66 #include "elf/common.h"
     67 #include "elf/external.h"
     68 #include "elf/internal.h"
     69 
     70 
     71 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
     72    we can obtain the H8 reloc numbers.  We need these for the
     73    get_reloc_size() function.  We include h8.h again after defining
     74    RELOC_MACROS_GEN_FUNC so that we get the naming function as well.  */
     75 
     76 #include "elf/h8.h"
     77 #undef _ELF_H8_H
     78 
     79 /* Undo the effects of #including reloc-macros.h.  */
     80 
     81 #undef START_RELOC_NUMBERS
     82 #undef RELOC_NUMBER
     83 #undef FAKE_RELOC
     84 #undef EMPTY_RELOC
     85 #undef END_RELOC_NUMBERS
     86 #undef _RELOC_MACROS_H
     87 
     88 /* The following headers use the elf/reloc-macros.h file to
     89    automatically generate relocation recognition functions
     90    such as elf_mips_reloc_type()  */
     91 
     92 #define RELOC_MACROS_GEN_FUNC
     93 
     94 #include "elf/aarch64.h"
     95 #include "elf/alpha.h"
     96 #include "elf/arc.h"
     97 #include "elf/arm.h"
     98 #include "elf/avr.h"
     99 #include "elf/bfin.h"
    100 #include "elf/cr16.h"
    101 #include "elf/cris.h"
    102 #include "elf/crx.h"
    103 #include "elf/d10v.h"
    104 #include "elf/d30v.h"
    105 #include "elf/dlx.h"
    106 #include "elf/epiphany.h"
    107 #include "elf/fr30.h"
    108 #include "elf/frv.h"
    109 #include "elf/ft32.h"
    110 #include "elf/h8.h"
    111 #include "elf/hppa.h"
    112 #include "elf/i386.h"
    113 #include "elf/i370.h"
    114 #include "elf/i860.h"
    115 #include "elf/i960.h"
    116 #include "elf/ia64.h"
    117 #include "elf/ip2k.h"
    118 #include "elf/lm32.h"
    119 #include "elf/iq2000.h"
    120 #include "elf/m32c.h"
    121 #include "elf/m32r.h"
    122 #include "elf/m68k.h"
    123 #include "elf/m68hc11.h"
    124 #include "elf/mcore.h"
    125 #include "elf/mep.h"
    126 #include "elf/metag.h"
    127 #include "elf/microblaze.h"
    128 #include "elf/mips.h"
    129 #include "elf/mmix.h"
    130 #include "elf/mn10200.h"
    131 #include "elf/mn10300.h"
    132 #include "elf/moxie.h"
    133 #include "elf/mt.h"
    134 #include "elf/msp430.h"
    135 #include "elf/nds32.h"
    136 #include "elf/nios2.h"
    137 #include "elf/or1k.h"
    138 #include "elf/pj.h"
    139 #include "elf/ppc.h"
    140 #include "elf/ppc64.h"
    141 #include "elf/rl78.h"
    142 #include "elf/rx.h"
    143 #include "elf/s390.h"
    144 #include "elf/score.h"
    145 #include "elf/sh.h"
    146 #include "elf/sparc.h"
    147 #include "elf/spu.h"
    148 #include "elf/tic6x.h"
    149 #include "elf/tilegx.h"
    150 #include "elf/tilepro.h"
    151 #include "elf/v850.h"
    152 #include "elf/vax.h"
    153 #include "elf/visium.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 typedef struct elf_section_list
    170 {
    171   Elf_Internal_Shdr * hdr;
    172   struct elf_section_list * next;
    173 } elf_section_list;
    174 
    175 char * program_name = "readelf";
    176 static unsigned long archive_file_offset;
    177 static unsigned long archive_file_size;
    178 static bfd_size_type current_file_size;
    179 static unsigned long dynamic_addr;
    180 static bfd_size_type dynamic_size;
    181 static size_t dynamic_nent;
    182 static char * dynamic_strings;
    183 static unsigned long dynamic_strings_length;
    184 static char * string_table;
    185 static unsigned long string_table_length;
    186 static unsigned long num_dynamic_syms;
    187 static Elf_Internal_Sym * dynamic_symbols;
    188 static Elf_Internal_Syminfo * dynamic_syminfo;
    189 static unsigned long dynamic_syminfo_offset;
    190 static unsigned int dynamic_syminfo_nent;
    191 static char program_interpreter[PATH_MAX];
    192 static bfd_vma dynamic_info[DT_ENCODING];
    193 static bfd_vma dynamic_info_DT_GNU_HASH;
    194 static bfd_vma version_info[16];
    195 static Elf_Internal_Ehdr elf_header;
    196 static Elf_Internal_Shdr * section_headers;
    197 static Elf_Internal_Phdr * program_headers;
    198 static Elf_Internal_Dyn *  dynamic_section;
    199 static elf_section_list * symtab_shndx_list;
    200 static int show_name;
    201 static int do_dynamic;
    202 static int do_syms;
    203 static int do_dyn_syms;
    204 static int do_reloc;
    205 static int do_sections;
    206 static int do_section_groups;
    207 static int do_section_details;
    208 static int do_segments;
    209 static int do_unwind;
    210 static int do_using_dynamic;
    211 static int do_header;
    212 static int do_dump;
    213 static int do_version;
    214 static int do_histogram;
    215 static int do_debugging;
    216 static int do_arch;
    217 static int do_notes;
    218 static int do_archive_index;
    219 static int is_32bit_elf;
    220 static int decompress_dumps;
    221 
    222 struct group_list
    223 {
    224   struct group_list * next;
    225   unsigned int section_index;
    226 };
    227 
    228 struct group
    229 {
    230   struct group_list * root;
    231   unsigned int group_index;
    232 };
    233 
    234 static size_t group_count;
    235 static struct group * section_groups;
    236 static struct group ** section_headers_groups;
    237 
    238 
    239 /* Flag bits indicating particular types of dump.  */
    240 #define HEX_DUMP	(1 << 0)	/* The -x command line switch.  */
    241 #define DISASS_DUMP	(1 << 1)	/* The -i command line switch.  */
    242 #define DEBUG_DUMP	(1 << 2)	/* The -w command line switch.  */
    243 #define STRING_DUMP     (1 << 3)	/* The -p command line switch.  */
    244 #define RELOC_DUMP      (1 << 4)	/* The -R command line switch.  */
    245 
    246 typedef unsigned char dump_type;
    247 
    248 /* A linked list of the section names for which dumps were requested.  */
    249 struct dump_list_entry
    250 {
    251   char * name;
    252   dump_type type;
    253   struct dump_list_entry * next;
    254 };
    255 static struct dump_list_entry * dump_sects_byname;
    256 
    257 /* A dynamic array of flags indicating for which sections a dump
    258    has been requested via command line switches.  */
    259 static dump_type *   cmdline_dump_sects = NULL;
    260 static unsigned int  num_cmdline_dump_sects = 0;
    261 
    262 /* A dynamic array of flags indicating for which sections a dump of
    263    some kind has been requested.  It is reset on a per-object file
    264    basis and then initialised from the cmdline_dump_sects array,
    265    the results of interpreting the -w switch, and the
    266    dump_sects_byname list.  */
    267 static dump_type *   dump_sects = NULL;
    268 static unsigned int  num_dump_sects = 0;
    269 
    270 
    271 /* How to print a vma value.  */
    272 typedef enum print_mode
    273 {
    274   HEX,
    275   DEC,
    276   DEC_5,
    277   UNSIGNED,
    278   PREFIX_HEX,
    279   FULL_HEX,
    280   LONG_HEX
    281 }
    282 print_mode;
    283 
    284 /* Versioned symbol info.  */
    285 enum versioned_symbol_info
    286 {
    287   symbol_undefined,
    288   symbol_hidden,
    289   symbol_public
    290 };
    291 
    292 static const char *get_symbol_version_string
    293   (FILE *file, int is_dynsym, const char *strtab,
    294    unsigned long int strtab_size, unsigned int si,
    295    Elf_Internal_Sym *psym, enum versioned_symbol_info *sym_info,
    296    unsigned short *vna_other);
    297 
    298 #define UNKNOWN -1
    299 
    300 #define SECTION_NAME(X)						\
    301   ((X) == NULL ? _("<none>")					\
    302    : string_table == NULL ? _("<no-name>")			\
    303    : ((X)->sh_name >= string_table_length ? _("<corrupt>")	\
    304   : string_table + (X)->sh_name))
    305 
    306 #define DT_VERSIONTAGIDX(tag)	(DT_VERNEEDNUM - (tag))	/* Reverse order!  */
    307 
    308 #define GET_ELF_SYMBOLS(file, section, sym_count)			\
    309   (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count)	\
    310    : get_64bit_elf_symbols (file, section, sym_count))
    311 
    312 #define VALID_DYNAMIC_NAME(offset)	((dynamic_strings != NULL) && (offset < dynamic_strings_length))
    313 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
    314    already been called and verified that the string exists.  */
    315 #define GET_DYNAMIC_NAME(offset)	(dynamic_strings + offset)
    316 
    317 #define REMOVE_ARCH_BITS(ADDR)			\
    318   do						\
    319     {						\
    320       if (elf_header.e_machine == EM_ARM)	\
    321 	(ADDR) &= ~1;				\
    322     }						\
    323   while (0)
    324 
    325 /* Retrieve NMEMB structures, each SIZE bytes long from FILE starting at OFFSET +
    327    the offset of the current archive member, if we are examining an archive.
    328    Put the retrieved data into VAR, if it is not NULL.  Otherwise allocate a buffer
    329    using malloc and fill that.  In either case return the pointer to the start of
    330    the retrieved data or NULL if something went wrong.  If something does go wrong
    331    and REASON is not NULL then emit an error message using REASON as part of the
    332    context.  */
    333 
    334 static void *
    335 get_data (void * var, FILE * file, unsigned long offset, bfd_size_type size,
    336 	  bfd_size_type nmemb, const char * reason)
    337 {
    338   void * mvar;
    339   bfd_size_type amt = size * nmemb;
    340 
    341   if (size == 0 || nmemb == 0)
    342     return NULL;
    343 
    344   /* If the size_t type is smaller than the bfd_size_type, eg because
    345      you are building a 32-bit tool on a 64-bit host, then make sure
    346      that when the sizes are cast to (size_t) no information is lost.  */
    347   if (sizeof (size_t) < sizeof (bfd_size_type)
    348       && (   (bfd_size_type) ((size_t) size) != size
    349 	  || (bfd_size_type) ((size_t) nmemb) != nmemb))
    350     {
    351       if (reason)
    352 	error (_("Size truncation prevents reading 0x%" BFD_VMA_FMT "x"
    353 		 " elements of size 0x%" BFD_VMA_FMT "x for %s\n"),
    354 	       nmemb, size, reason);
    355       return NULL;
    356     }
    357 
    358   /* Check for size overflow.  */
    359   if (amt < nmemb)
    360     {
    361       if (reason)
    362 	error (_("Size overflow prevents reading 0x%" BFD_VMA_FMT "x"
    363 		 " elements of size 0x%" BFD_VMA_FMT "x for %s\n"),
    364 	       nmemb, size, reason);
    365       return NULL;
    366     }
    367 
    368   /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
    369      attempting to allocate memory when the read is bound to fail.  */
    370   if (amt > current_file_size
    371       || offset + archive_file_offset + amt > current_file_size)
    372     {
    373       if (reason)
    374 	error (_("Reading 0x%" BFD_VMA_FMT "x"
    375 		 " bytes extends past end of file for %s\n"),
    376 	       amt, reason);
    377       return NULL;
    378     }
    379 
    380   if (fseek (file, archive_file_offset + offset, SEEK_SET))
    381     {
    382       if (reason)
    383 	error (_("Unable to seek to 0x%lx for %s\n"),
    384 	       archive_file_offset + offset, reason);
    385       return NULL;
    386     }
    387 
    388   mvar = var;
    389   if (mvar == NULL)
    390     {
    391       /* Check for overflow.  */
    392       if (nmemb < (~(bfd_size_type) 0 - 1) / size)
    393 	/* + 1 so that we can '\0' terminate invalid string table sections.  */
    394 	mvar = malloc ((size_t) amt + 1);
    395 
    396       if (mvar == NULL)
    397 	{
    398 	  if (reason)
    399 	    error (_("Out of memory allocating 0x%" BFD_VMA_FMT "x"
    400 		     " bytes for %s\n"),
    401 		   amt, reason);
    402 	  return NULL;
    403 	}
    404 
    405       ((char *) mvar)[amt] = '\0';
    406     }
    407 
    408   if (fread (mvar, (size_t) size, (size_t) nmemb, file) != nmemb)
    409     {
    410       if (reason)
    411 	error (_("Unable to read in 0x%" BFD_VMA_FMT "x bytes of %s\n"),
    412 	       amt, reason);
    413       if (mvar != var)
    414 	free (mvar);
    415       return NULL;
    416     }
    417 
    418   return mvar;
    419 }
    420 
    421 /* Print a VMA value.  */
    422 
    423 static int
    424 print_vma (bfd_vma vma, print_mode mode)
    425 {
    426   int nc = 0;
    427 
    428   switch (mode)
    429     {
    430     case FULL_HEX:
    431       nc = printf ("0x");
    432       /* Drop through.  */
    433 
    434     case LONG_HEX:
    435 #ifdef BFD64
    436       if (is_32bit_elf)
    437 	return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
    438 #endif
    439       printf_vma (vma);
    440       return nc + 16;
    441 
    442     case DEC_5:
    443       if (vma <= 99999)
    444 	return printf ("%5" BFD_VMA_FMT "d", vma);
    445       /* Drop through.  */
    446 
    447     case PREFIX_HEX:
    448       nc = printf ("0x");
    449       /* Drop through.  */
    450 
    451     case HEX:
    452       return nc + printf ("%" BFD_VMA_FMT "x", vma);
    453 
    454     case DEC:
    455       return printf ("%" BFD_VMA_FMT "d", vma);
    456 
    457     case UNSIGNED:
    458       return printf ("%" BFD_VMA_FMT "u", vma);
    459     }
    460   return 0;
    461 }
    462 
    463 /* Display a symbol on stdout.  Handles the display of control characters and
    464    multibye characters (assuming the host environment supports them).
    465 
    466    Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
    467 
    468    If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
    469    padding as necessary.
    470 
    471    Returns the number of emitted characters.  */
    472 
    473 static unsigned int
    474 print_symbol (int width, const char *symbol)
    475 {
    476   bfd_boolean extra_padding = FALSE;
    477   int num_printed = 0;
    478 #ifdef HAVE_MBSTATE_T
    479   mbstate_t state;
    480 #endif
    481   int width_remaining;
    482 
    483   if (width < 0)
    484     {
    485       /* Keep the width positive.  This also helps.  */
    486       width = - width;
    487       extra_padding = TRUE;
    488     }
    489   assert (width != 0);
    490 
    491   if (do_wide)
    492     /* Set the remaining width to a very large value.
    493        This simplifies the code below.  */
    494     width_remaining = INT_MAX;
    495   else
    496     width_remaining = width;
    497 
    498 #ifdef HAVE_MBSTATE_T
    499   /* Initialise the multibyte conversion state.  */
    500   memset (& state, 0, sizeof (state));
    501 #endif
    502 
    503   while (width_remaining)
    504     {
    505       size_t  n;
    506       const char c = *symbol++;
    507 
    508       if (c == 0)
    509 	break;
    510 
    511       /* Do not print control characters directly as they can affect terminal
    512 	 settings.  Such characters usually appear in the names generated
    513 	 by the assembler for local labels.  */
    514       if (ISCNTRL (c))
    515 	{
    516 	  if (width_remaining < 2)
    517 	    break;
    518 
    519 	  printf ("^%c", c + 0x40);
    520 	  width_remaining -= 2;
    521 	  num_printed += 2;
    522 	}
    523       else if (ISPRINT (c))
    524 	{
    525 	  putchar (c);
    526 	  width_remaining --;
    527 	  num_printed ++;
    528 	}
    529       else
    530 	{
    531 #ifdef HAVE_MBSTATE_T
    532 	  wchar_t w;
    533 #endif
    534 	  /* Let printf do the hard work of displaying multibyte characters.  */
    535 	  printf ("%.1s", symbol - 1);
    536 	  width_remaining --;
    537 	  num_printed ++;
    538 
    539 #ifdef HAVE_MBSTATE_T
    540 	  /* Try to find out how many bytes made up the character that was
    541 	     just printed.  Advance the symbol pointer past the bytes that
    542 	     were displayed.  */
    543 	  n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
    544 #else
    545 	  n = 1;
    546 #endif
    547 	  if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
    548 	    symbol += (n - 1);
    549 	}
    550     }
    551 
    552   if (extra_padding && num_printed < width)
    553     {
    554       /* Fill in the remaining spaces.  */
    555       printf ("%-*s", width - num_printed, " ");
    556       num_printed = width;
    557     }
    558 
    559   return num_printed;
    560 }
    561 
    562 /* Returns a pointer to a static buffer containing a  printable version of
    563    the given section's name.  Like print_symbol, except that it does not try
    564    to print multibyte characters, it just interprets them as hex values.  */
    565 
    566 static const char *
    567 printable_section_name (const Elf_Internal_Shdr * sec)
    568 {
    569 #define MAX_PRINT_SEC_NAME_LEN 128
    570   static char  sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
    571   const char * name = SECTION_NAME (sec);
    572   char *       buf = sec_name_buf;
    573   char         c;
    574   unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
    575 
    576   while ((c = * name ++) != 0)
    577     {
    578       if (ISCNTRL (c))
    579 	{
    580 	  if (remaining < 2)
    581 	    break;
    582 
    583 	  * buf ++ = '^';
    584 	  * buf ++ = c + 0x40;
    585 	  remaining -= 2;
    586 	}
    587       else if (ISPRINT (c))
    588 	{
    589 	  * buf ++ = c;
    590 	  remaining -= 1;
    591 	}
    592       else
    593 	{
    594 	  static char hex[17] = "0123456789ABCDEF";
    595 
    596 	  if (remaining < 4)
    597 	    break;
    598 	  * buf ++ = '<';
    599 	  * buf ++ = hex[(c & 0xf0) >> 4];
    600 	  * buf ++ = hex[c & 0x0f];
    601 	  * buf ++ = '>';
    602 	  remaining -= 4;
    603 	}
    604 
    605       if (remaining == 0)
    606 	break;
    607     }
    608 
    609   * buf = 0;
    610   return sec_name_buf;
    611 }
    612 
    613 static const char *
    614 printable_section_name_from_index (unsigned long ndx)
    615 {
    616   if (ndx >= elf_header.e_shnum)
    617     return _("<corrupt>");
    618 
    619   return printable_section_name (section_headers + ndx);
    620 }
    621 
    622 /* Return a pointer to section NAME, or NULL if no such section exists.  */
    623 
    624 static Elf_Internal_Shdr *
    625 find_section (const char * name)
    626 {
    627   unsigned int i;
    628 
    629   for (i = 0; i < elf_header.e_shnum; i++)
    630     if (streq (SECTION_NAME (section_headers + i), name))
    631       return section_headers + i;
    632 
    633   return NULL;
    634 }
    635 
    636 /* Return a pointer to a section containing ADDR, or NULL if no such
    637    section exists.  */
    638 
    639 static Elf_Internal_Shdr *
    640 find_section_by_address (bfd_vma addr)
    641 {
    642   unsigned int i;
    643 
    644   for (i = 0; i < elf_header.e_shnum; i++)
    645     {
    646       Elf_Internal_Shdr *sec = section_headers + i;
    647       if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
    648 	return sec;
    649     }
    650 
    651   return NULL;
    652 }
    653 
    654 static Elf_Internal_Shdr *
    655 find_section_by_type (unsigned int type)
    656 {
    657   unsigned int i;
    658 
    659   for (i = 0; i < elf_header.e_shnum; i++)
    660     {
    661       Elf_Internal_Shdr *sec = section_headers + i;
    662       if (sec->sh_type == type)
    663 	return sec;
    664     }
    665 
    666   return NULL;
    667 }
    668 
    669 /* Return a pointer to section NAME, or NULL if no such section exists,
    670    restricted to the list of sections given in SET.  */
    671 
    672 static Elf_Internal_Shdr *
    673 find_section_in_set (const char * name, unsigned int * set)
    674 {
    675   unsigned int i;
    676 
    677   if (set != NULL)
    678     {
    679       while ((i = *set++) > 0)
    680 	if (streq (SECTION_NAME (section_headers + i), name))
    681 	  return section_headers + i;
    682     }
    683 
    684   return find_section (name);
    685 }
    686 
    687 /* Read an unsigned LEB128 encoded value from p.  Set *PLEN to the number of
    688    bytes read.  */
    689 
    690 static inline unsigned long
    691 read_uleb128 (unsigned char *data,
    692 	      unsigned int *length_return,
    693 	      const unsigned char * const end)
    694 {
    695   return read_leb128 (data, length_return, FALSE, end);
    696 }
    697 
    698 /* Return true if the current file is for IA-64 machine and OpenVMS ABI.
    699    This OS has so many departures from the ELF standard that we test it at
    700    many places.  */
    701 
    702 static inline int
    703 is_ia64_vms (void)
    704 {
    705   return elf_header.e_machine == EM_IA_64
    706     && elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
    707 }
    708 
    709 /* Guess the relocation size commonly used by the specific machines.  */
    710 
    711 static int
    712 guess_is_rela (unsigned int e_machine)
    713 {
    714   switch (e_machine)
    715     {
    716       /* Targets that use REL relocations.  */
    717     case EM_386:
    718     case EM_IAMCU:
    719     case EM_960:
    720     case EM_ARM:
    721     case EM_D10V:
    722     case EM_CYGNUS_D10V:
    723     case EM_DLX:
    724     case EM_MIPS:
    725     case EM_MIPS_RS3_LE:
    726     case EM_CYGNUS_M32R:
    727     case EM_SCORE:
    728     case EM_XGATE:
    729       return FALSE;
    730 
    731       /* Targets that use RELA relocations.  */
    732     case EM_68K:
    733     case EM_860:
    734     case EM_AARCH64:
    735     case EM_ADAPTEVA_EPIPHANY:
    736     case EM_ALPHA:
    737     case EM_ALTERA_NIOS2:
    738     case EM_ARC:
    739     case EM_ARC_COMPACT:
    740     case EM_ARC_COMPACT2:
    741     case EM_AVR:
    742     case EM_AVR_OLD:
    743     case EM_BLACKFIN:
    744     case EM_CR16:
    745     case EM_CRIS:
    746     case EM_CRX:
    747     case EM_D30V:
    748     case EM_CYGNUS_D30V:
    749     case EM_FR30:
    750     case EM_FT32:
    751     case EM_CYGNUS_FR30:
    752     case EM_CYGNUS_FRV:
    753     case EM_H8S:
    754     case EM_H8_300:
    755     case EM_H8_300H:
    756     case EM_IA_64:
    757     case EM_IP2K:
    758     case EM_IP2K_OLD:
    759     case EM_IQ2000:
    760     case EM_LATTICEMICO32:
    761     case EM_M32C_OLD:
    762     case EM_M32C:
    763     case EM_M32R:
    764     case EM_MCORE:
    765     case EM_CYGNUS_MEP:
    766     case EM_METAG:
    767     case EM_MMIX:
    768     case EM_MN10200:
    769     case EM_CYGNUS_MN10200:
    770     case EM_MN10300:
    771     case EM_CYGNUS_MN10300:
    772     case EM_MOXIE:
    773     case EM_MSP430:
    774     case EM_MSP430_OLD:
    775     case EM_MT:
    776     case EM_NDS32:
    777     case EM_NIOS32:
    778     case EM_OR1K:
    779     case EM_PPC64:
    780     case EM_PPC:
    781     case EM_RL78:
    782     case EM_RX:
    783     case EM_S390:
    784     case EM_S390_OLD:
    785     case EM_SH:
    786     case EM_SPARC:
    787     case EM_SPARC32PLUS:
    788     case EM_SPARCV9:
    789     case EM_SPU:
    790     case EM_TI_C6000:
    791     case EM_TILEGX:
    792     case EM_TILEPRO:
    793     case EM_V800:
    794     case EM_V850:
    795     case EM_CYGNUS_V850:
    796     case EM_VAX:
    797     case EM_VISIUM:
    798     case EM_X86_64:
    799     case EM_L1OM:
    800     case EM_K1OM:
    801     case EM_XSTORMY16:
    802     case EM_XTENSA:
    803     case EM_XTENSA_OLD:
    804     case EM_MICROBLAZE:
    805     case EM_MICROBLAZE_OLD:
    806       return TRUE;
    807 
    808     case EM_68HC05:
    809     case EM_68HC08:
    810     case EM_68HC11:
    811     case EM_68HC16:
    812     case EM_FX66:
    813     case EM_ME16:
    814     case EM_MMA:
    815     case EM_NCPU:
    816     case EM_NDR1:
    817     case EM_PCP:
    818     case EM_ST100:
    819     case EM_ST19:
    820     case EM_ST7:
    821     case EM_ST9PLUS:
    822     case EM_STARCORE:
    823     case EM_SVX:
    824     case EM_TINYJ:
    825     default:
    826       warn (_("Don't know about relocations on this machine architecture\n"));
    827       return FALSE;
    828     }
    829 }
    830 
    831 static int
    832 slurp_rela_relocs (FILE * file,
    833 		   unsigned long rel_offset,
    834 		   unsigned long rel_size,
    835 		   Elf_Internal_Rela ** relasp,
    836 		   unsigned long * nrelasp)
    837 {
    838   Elf_Internal_Rela * relas;
    839   size_t nrelas;
    840   unsigned int i;
    841 
    842   if (is_32bit_elf)
    843     {
    844       Elf32_External_Rela * erelas;
    845 
    846       erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset, 1,
    847                                                  rel_size, _("32-bit relocation data"));
    848       if (!erelas)
    849 	return 0;
    850 
    851       nrelas = rel_size / sizeof (Elf32_External_Rela);
    852 
    853       relas = (Elf_Internal_Rela *) cmalloc (nrelas,
    854                                              sizeof (Elf_Internal_Rela));
    855 
    856       if (relas == NULL)
    857 	{
    858 	  free (erelas);
    859 	  error (_("out of memory parsing relocs\n"));
    860 	  return 0;
    861 	}
    862 
    863       for (i = 0; i < nrelas; i++)
    864 	{
    865 	  relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
    866 	  relas[i].r_info   = BYTE_GET (erelas[i].r_info);
    867 	  relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
    868 	}
    869 
    870       free (erelas);
    871     }
    872   else
    873     {
    874       Elf64_External_Rela * erelas;
    875 
    876       erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset, 1,
    877                                                  rel_size, _("64-bit relocation data"));
    878       if (!erelas)
    879 	return 0;
    880 
    881       nrelas = rel_size / sizeof (Elf64_External_Rela);
    882 
    883       relas = (Elf_Internal_Rela *) cmalloc (nrelas,
    884                                              sizeof (Elf_Internal_Rela));
    885 
    886       if (relas == NULL)
    887 	{
    888 	  free (erelas);
    889 	  error (_("out of memory parsing relocs\n"));
    890 	  return 0;
    891 	}
    892 
    893       for (i = 0; i < nrelas; i++)
    894 	{
    895 	  relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
    896 	  relas[i].r_info   = BYTE_GET (erelas[i].r_info);
    897 	  relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
    898 
    899 	  /* The #ifdef BFD64 below is to prevent a compile time
    900 	     warning.  We know that if we do not have a 64 bit data
    901 	     type that we will never execute this code anyway.  */
    902 #ifdef BFD64
    903 	  if (elf_header.e_machine == EM_MIPS
    904 	      && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
    905 	    {
    906 	      /* In little-endian objects, r_info isn't really a
    907 		 64-bit little-endian value: it has a 32-bit
    908 		 little-endian symbol index followed by four
    909 		 individual byte fields.  Reorder INFO
    910 		 accordingly.  */
    911 	      bfd_vma inf = relas[i].r_info;
    912 	      inf = (((inf & 0xffffffff) << 32)
    913 		      | ((inf >> 56) & 0xff)
    914 		      | ((inf >> 40) & 0xff00)
    915 		      | ((inf >> 24) & 0xff0000)
    916 		      | ((inf >> 8) & 0xff000000));
    917 	      relas[i].r_info = inf;
    918 	    }
    919 #endif /* BFD64 */
    920 	}
    921 
    922       free (erelas);
    923     }
    924   *relasp = relas;
    925   *nrelasp = nrelas;
    926   return 1;
    927 }
    928 
    929 static int
    930 slurp_rel_relocs (FILE * file,
    931 		  unsigned long rel_offset,
    932 		  unsigned long rel_size,
    933 		  Elf_Internal_Rela ** relsp,
    934 		  unsigned long * nrelsp)
    935 {
    936   Elf_Internal_Rela * rels;
    937   size_t nrels;
    938   unsigned int i;
    939 
    940   if (is_32bit_elf)
    941     {
    942       Elf32_External_Rel * erels;
    943 
    944       erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset, 1,
    945                                                rel_size, _("32-bit relocation data"));
    946       if (!erels)
    947 	return 0;
    948 
    949       nrels = rel_size / sizeof (Elf32_External_Rel);
    950 
    951       rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
    952 
    953       if (rels == NULL)
    954 	{
    955 	  free (erels);
    956 	  error (_("out of memory parsing relocs\n"));
    957 	  return 0;
    958 	}
    959 
    960       for (i = 0; i < nrels; i++)
    961 	{
    962 	  rels[i].r_offset = BYTE_GET (erels[i].r_offset);
    963 	  rels[i].r_info   = BYTE_GET (erels[i].r_info);
    964 	  rels[i].r_addend = 0;
    965 	}
    966 
    967       free (erels);
    968     }
    969   else
    970     {
    971       Elf64_External_Rel * erels;
    972 
    973       erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset, 1,
    974                                                rel_size, _("64-bit relocation data"));
    975       if (!erels)
    976 	return 0;
    977 
    978       nrels = rel_size / sizeof (Elf64_External_Rel);
    979 
    980       rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
    981 
    982       if (rels == NULL)
    983 	{
    984 	  free (erels);
    985 	  error (_("out of memory parsing relocs\n"));
    986 	  return 0;
    987 	}
    988 
    989       for (i = 0; i < nrels; i++)
    990 	{
    991 	  rels[i].r_offset = BYTE_GET (erels[i].r_offset);
    992 	  rels[i].r_info   = BYTE_GET (erels[i].r_info);
    993 	  rels[i].r_addend = 0;
    994 
    995 	  /* The #ifdef BFD64 below is to prevent a compile time
    996 	     warning.  We know that if we do not have a 64 bit data
    997 	     type that we will never execute this code anyway.  */
    998 #ifdef BFD64
    999 	  if (elf_header.e_machine == EM_MIPS
   1000 	      && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
   1001 	    {
   1002 	      /* In little-endian objects, r_info isn't really a
   1003 		 64-bit little-endian value: it has a 32-bit
   1004 		 little-endian symbol index followed by four
   1005 		 individual byte fields.  Reorder INFO
   1006 		 accordingly.  */
   1007 	      bfd_vma inf = rels[i].r_info;
   1008 	      inf = (((inf & 0xffffffff) << 32)
   1009 		     | ((inf >> 56) & 0xff)
   1010 		     | ((inf >> 40) & 0xff00)
   1011 		     | ((inf >> 24) & 0xff0000)
   1012 		     | ((inf >> 8) & 0xff000000));
   1013 	      rels[i].r_info = inf;
   1014 	    }
   1015 #endif /* BFD64 */
   1016 	}
   1017 
   1018       free (erels);
   1019     }
   1020   *relsp = rels;
   1021   *nrelsp = nrels;
   1022   return 1;
   1023 }
   1024 
   1025 static bfd_boolean
   1026 slurp_relr_relocs (FILE * file,
   1027 		   unsigned long relr_offset,
   1028 		   unsigned long relr_size,
   1029 		   Elf_Internal_Rela ** relrsp,
   1030 		   unsigned long * nrelrsp)
   1031 {
   1032   Elf_Internal_Rela * relrs;
   1033   size_t nrelrs;
   1034   unsigned int i;
   1035 
   1036   if (is_32bit_elf)
   1037     {
   1038       Elf32_External_Relr * erelrs;
   1039 
   1040       erelrs = (Elf32_External_Relr *) get_data (NULL, file, relr_offset, 1,
   1041                                                  relr_size, _("32-bit relocation data"));
   1042       if (!erelrs)
   1043 	return FALSE;
   1044 
   1045       nrelrs = relr_size / sizeof (Elf32_External_Relr);
   1046 
   1047       relrs = (Elf_Internal_Rela *) cmalloc (nrelrs, sizeof (Elf_Internal_Rela));
   1048 
   1049       if (relrs == NULL)
   1050 	{
   1051 	  free (erelrs);
   1052 	  error (_("out of memory parsing relocs\n"));
   1053 	  return FALSE;
   1054 	}
   1055 
   1056       for (i = 0; i < nrelrs; i++)
   1057 	{
   1058 	  relrs[i].r_offset = BYTE_GET (erelrs[i].r_data);
   1059 	  relrs[i].r_info   = 0;
   1060 	  relrs[i].r_addend = 0;
   1061 	}
   1062 
   1063       free (erelrs);
   1064     }
   1065   else
   1066     {
   1067       Elf64_External_Relr * erelrs;
   1068 
   1069       erelrs = (Elf64_External_Relr *) get_data (NULL, file, relr_offset, 1,
   1070                                                  relr_size, _("64-bit relocation data"));
   1071       if (!erelrs)
   1072 	return FALSE;
   1073 
   1074       nrelrs = relr_size / sizeof (Elf64_External_Relr);
   1075 
   1076       relrs = (Elf_Internal_Rela *) cmalloc (nrelrs, sizeof (Elf_Internal_Rela));
   1077 
   1078       if (relrs == NULL)
   1079 	{
   1080 	  free (erelrs);
   1081 	  error (_("out of memory parsing relocs\n"));
   1082 	  return FALSE;
   1083 	}
   1084 
   1085       for (i = 0; i < nrelrs; i++)
   1086 	{
   1087 	  relrs[i].r_offset = BYTE_GET (erelrs[i].r_data);
   1088 	  relrs[i].r_info   = 0;
   1089 	  relrs[i].r_addend = 0;
   1090 	}
   1091 
   1092       free (erelrs);
   1093     }
   1094   *relrsp = relrs;
   1095   *nrelrsp = nrelrs;
   1096   return 1;
   1097 }
   1098 
   1099 /* Returns the reloc type extracted from the reloc info field.  */
   1100 
   1101 static unsigned int
   1102 get_reloc_type (bfd_vma reloc_info)
   1103 {
   1104   if (is_32bit_elf)
   1105     return ELF32_R_TYPE (reloc_info);
   1106 
   1107   switch (elf_header.e_machine)
   1108     {
   1109     case EM_MIPS:
   1110       /* Note: We assume that reloc_info has already been adjusted for us.  */
   1111       return ELF64_MIPS_R_TYPE (reloc_info);
   1112 
   1113     case EM_SPARCV9:
   1114       return ELF64_R_TYPE_ID (reloc_info);
   1115 
   1116     default:
   1117       return ELF64_R_TYPE (reloc_info);
   1118     }
   1119 }
   1120 
   1121 /* Return the symbol index extracted from the reloc info field.  */
   1122 
   1123 static bfd_vma
   1124 get_reloc_symindex (bfd_vma reloc_info)
   1125 {
   1126   return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
   1127 }
   1128 
   1129 static inline bfd_boolean
   1130 uses_msp430x_relocs (void)
   1131 {
   1132   return
   1133     elf_header.e_machine == EM_MSP430 /* Paranoia.  */
   1134     /* GCC uses osabi == ELFOSBI_STANDALONE.  */
   1135     && (((elf_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
   1136 	/* TI compiler uses ELFOSABI_NONE.  */
   1137 	|| (elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
   1138 }
   1139 
   1140 /* Display the contents of the relocation data found at the specified
   1141    offset.  */
   1142 
   1143 static void
   1144 dump_relocations (FILE * file,
   1145 		  unsigned long rel_offset,
   1146 		  unsigned long rel_size,
   1147 		  Elf_Internal_Sym * symtab,
   1148 		  unsigned long nsyms,
   1149 		  char * strtab,
   1150 		  unsigned long strtablen,
   1151 		  int is_rela,
   1152 		  int is_relr,
   1153 		  int is_dynsym)
   1154 {
   1155   unsigned int i;
   1156   Elf_Internal_Rela * rels;
   1157 
   1158   if (is_rela == UNKNOWN)
   1159     is_rela = guess_is_rela (elf_header.e_machine);
   1160 
   1161   if (is_rela)
   1162     {
   1163       if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
   1164 	return;
   1165     }
   1166   else if (is_relr)
   1167     {
   1168       if (!slurp_relr_relocs (file, rel_offset, rel_size, &rels, &rel_size))
   1169 	return;
   1170     }
   1171   else
   1172     {
   1173       if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
   1174 	return;
   1175     }
   1176 
   1177   if (is_32bit_elf)
   1178     {
   1179       if (is_rela)
   1180 	{
   1181 	  if (do_wide)
   1182 	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name + Addend\n"));
   1183 	  else
   1184 	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
   1185 	}
   1186       else if (is_relr)
   1187 	{
   1188 	  if (do_wide)
   1189 	    printf (_(" Data       Info    Type\n"));
   1190 	  else
   1191 	    printf (_(" Data       Info    Type\n"));
   1192 	}
   1193       else
   1194 	{
   1195 	  if (do_wide)
   1196 	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
   1197 	  else
   1198 	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
   1199 	}
   1200     }
   1201   else
   1202     {
   1203       if (is_rela)
   1204 	{
   1205 	  if (do_wide)
   1206 	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
   1207 	  else
   1208 	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n"));
   1209 	}
   1210       else if (is_relr)
   1211 	{
   1212 	  if (do_wide)
   1213 	    printf (_("    Data               Info             Type\n"));
   1214 	  else
   1215 	    printf (_("  Data            Info           Type\n"));
   1216 	}
   1217       else
   1218 	{
   1219 	  if (do_wide)
   1220 	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name\n"));
   1221 	  else
   1222 	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name\n"));
   1223 	}
   1224     }
   1225 
   1226   for (i = 0; i < rel_size; i++)
   1227     {
   1228       const char * rtype;
   1229       bfd_vma offset;
   1230       bfd_vma inf;
   1231       bfd_vma symtab_index;
   1232       bfd_vma type;
   1233 
   1234       offset = rels[i].r_offset;
   1235       inf    = rels[i].r_info;
   1236 
   1237       type = get_reloc_type (inf);
   1238       symtab_index = get_reloc_symindex  (inf);
   1239 
   1240       if (is_32bit_elf)
   1241 	{
   1242 	  printf ("%8.8lx  %8.8lx ",
   1243 		  (unsigned long) offset & 0xffffffff,
   1244 		  (unsigned long) inf & 0xffffffff);
   1245 	}
   1246       else
   1247 	{
   1248 #if BFD_HOST_64BIT_LONG
   1249 	  printf (do_wide
   1250 		  ? "%16.16lx  %16.16lx "
   1251 		  : "%12.12lx  %12.12lx ",
   1252 		  offset, inf);
   1253 #elif BFD_HOST_64BIT_LONG_LONG
   1254 #ifndef __MSVCRT__
   1255 	  printf (do_wide
   1256 		  ? "%16.16llx  %16.16llx "
   1257 		  : "%12.12llx  %12.12llx ",
   1258 		  offset, inf);
   1259 #else
   1260 	  printf (do_wide
   1261 		  ? "%16.16I64x  %16.16I64x "
   1262 		  : "%12.12I64x  %12.12I64x ",
   1263 		  offset, inf);
   1264 #endif
   1265 #else
   1266 	  printf (do_wide
   1267 		  ? "%8.8lx%8.8lx  %8.8lx%8.8lx "
   1268 		  : "%4.4lx%8.8lx  %4.4lx%8.8lx ",
   1269 		  _bfd_int64_high (offset),
   1270 		  _bfd_int64_low (offset),
   1271 		  _bfd_int64_high (inf),
   1272 		  _bfd_int64_low (inf));
   1273 #endif
   1274 	}
   1275 
   1276       switch (elf_header.e_machine)
   1277 	{
   1278 	default:
   1279 	  rtype = NULL;
   1280 	  break;
   1281 
   1282 	case EM_AARCH64:
   1283 	  rtype = elf_aarch64_reloc_type (type);
   1284 	  break;
   1285 
   1286 	case EM_M32R:
   1287 	case EM_CYGNUS_M32R:
   1288 	  rtype = elf_m32r_reloc_type (type);
   1289 	  break;
   1290 
   1291 	case EM_386:
   1292 	case EM_IAMCU:
   1293 	  rtype = elf_i386_reloc_type (type);
   1294 	  break;
   1295 
   1296 	case EM_68HC11:
   1297 	case EM_68HC12:
   1298 	  rtype = elf_m68hc11_reloc_type (type);
   1299 	  break;
   1300 
   1301 	case EM_68K:
   1302 	  rtype = elf_m68k_reloc_type (type);
   1303 	  break;
   1304 
   1305 	case EM_960:
   1306 	  rtype = elf_i960_reloc_type (type);
   1307 	  break;
   1308 
   1309 	case EM_AVR:
   1310 	case EM_AVR_OLD:
   1311 	  rtype = elf_avr_reloc_type (type);
   1312 	  break;
   1313 
   1314 	case EM_OLD_SPARCV9:
   1315 	case EM_SPARC32PLUS:
   1316 	case EM_SPARCV9:
   1317 	case EM_SPARC:
   1318 	  rtype = elf_sparc_reloc_type (type);
   1319 	  break;
   1320 
   1321 	case EM_SPU:
   1322 	  rtype = elf_spu_reloc_type (type);
   1323 	  break;
   1324 
   1325 	case EM_V800:
   1326 	  rtype = v800_reloc_type (type);
   1327 	  break;
   1328 	case EM_V850:
   1329 	case EM_CYGNUS_V850:
   1330 	  rtype = v850_reloc_type (type);
   1331 	  break;
   1332 
   1333 	case EM_D10V:
   1334 	case EM_CYGNUS_D10V:
   1335 	  rtype = elf_d10v_reloc_type (type);
   1336 	  break;
   1337 
   1338 	case EM_D30V:
   1339 	case EM_CYGNUS_D30V:
   1340 	  rtype = elf_d30v_reloc_type (type);
   1341 	  break;
   1342 
   1343 	case EM_DLX:
   1344 	  rtype = elf_dlx_reloc_type (type);
   1345 	  break;
   1346 
   1347 	case EM_SH:
   1348 	  rtype = elf_sh_reloc_type (type);
   1349 	  break;
   1350 
   1351 	case EM_MN10300:
   1352 	case EM_CYGNUS_MN10300:
   1353 	  rtype = elf_mn10300_reloc_type (type);
   1354 	  break;
   1355 
   1356 	case EM_MN10200:
   1357 	case EM_CYGNUS_MN10200:
   1358 	  rtype = elf_mn10200_reloc_type (type);
   1359 	  break;
   1360 
   1361 	case EM_FR30:
   1362 	case EM_CYGNUS_FR30:
   1363 	  rtype = elf_fr30_reloc_type (type);
   1364 	  break;
   1365 
   1366 	case EM_CYGNUS_FRV:
   1367 	  rtype = elf_frv_reloc_type (type);
   1368 	  break;
   1369 
   1370 	case EM_FT32:
   1371 	  rtype = elf_ft32_reloc_type (type);
   1372 	  break;
   1373 
   1374 	case EM_MCORE:
   1375 	  rtype = elf_mcore_reloc_type (type);
   1376 	  break;
   1377 
   1378 	case EM_MMIX:
   1379 	  rtype = elf_mmix_reloc_type (type);
   1380 	  break;
   1381 
   1382 	case EM_MOXIE:
   1383 	  rtype = elf_moxie_reloc_type (type);
   1384 	  break;
   1385 
   1386 	case EM_MSP430:
   1387 	  if (uses_msp430x_relocs ())
   1388 	    {
   1389 	      rtype = elf_msp430x_reloc_type (type);
   1390 	      break;
   1391 	    }
   1392 	case EM_MSP430_OLD:
   1393 	  rtype = elf_msp430_reloc_type (type);
   1394 	  break;
   1395 
   1396 	case EM_NDS32:
   1397 	  rtype = elf_nds32_reloc_type (type);
   1398 	  break;
   1399 
   1400 	case EM_PPC:
   1401 	  rtype = elf_ppc_reloc_type (type);
   1402 	  break;
   1403 
   1404 	case EM_PPC64:
   1405 	  rtype = elf_ppc64_reloc_type (type);
   1406 	  break;
   1407 
   1408 	case EM_MIPS:
   1409 	case EM_MIPS_RS3_LE:
   1410 	  rtype = elf_mips_reloc_type (type);
   1411 	  break;
   1412 
   1413 	case EM_ALPHA:
   1414 	  rtype = elf_alpha_reloc_type (type);
   1415 	  break;
   1416 
   1417 	case EM_ARM:
   1418 	  rtype = elf_arm_reloc_type (type);
   1419 	  break;
   1420 
   1421 	case EM_ARC:
   1422 	case EM_ARC_COMPACT:
   1423 	case EM_ARC_COMPACT2:
   1424 	  rtype = elf_arc_reloc_type (type);
   1425 	  break;
   1426 
   1427 	case EM_PARISC:
   1428 	  rtype = elf_hppa_reloc_type (type);
   1429 	  break;
   1430 
   1431 	case EM_H8_300:
   1432 	case EM_H8_300H:
   1433 	case EM_H8S:
   1434 	  rtype = elf_h8_reloc_type (type);
   1435 	  break;
   1436 
   1437 	case EM_OR1K:
   1438 	  rtype = elf_or1k_reloc_type (type);
   1439 	  break;
   1440 
   1441 	case EM_PJ:
   1442 	case EM_PJ_OLD:
   1443 	  rtype = elf_pj_reloc_type (type);
   1444 	  break;
   1445 	case EM_IA_64:
   1446 	  rtype = elf_ia64_reloc_type (type);
   1447 	  break;
   1448 
   1449 	case EM_CRIS:
   1450 	  rtype = elf_cris_reloc_type (type);
   1451 	  break;
   1452 
   1453 	case EM_860:
   1454 	  rtype = elf_i860_reloc_type (type);
   1455 	  break;
   1456 
   1457 	case EM_X86_64:
   1458 	case EM_L1OM:
   1459 	case EM_K1OM:
   1460 	  rtype = elf_x86_64_reloc_type (type);
   1461 	  break;
   1462 
   1463 	case EM_S370:
   1464 	  rtype = i370_reloc_type (type);
   1465 	  break;
   1466 
   1467 	case EM_S390_OLD:
   1468 	case EM_S390:
   1469 	  rtype = elf_s390_reloc_type (type);
   1470 	  break;
   1471 
   1472 	case EM_SCORE:
   1473 	  rtype = elf_score_reloc_type (type);
   1474 	  break;
   1475 
   1476 	case EM_XSTORMY16:
   1477 	  rtype = elf_xstormy16_reloc_type (type);
   1478 	  break;
   1479 
   1480 	case EM_CRX:
   1481 	  rtype = elf_crx_reloc_type (type);
   1482 	  break;
   1483 
   1484 	case EM_VAX:
   1485 	  rtype = elf_vax_reloc_type (type);
   1486 	  break;
   1487 
   1488 	case EM_VISIUM:
   1489 	  rtype = elf_visium_reloc_type (type);
   1490 	  break;
   1491 
   1492 	case EM_ADAPTEVA_EPIPHANY:
   1493 	  rtype = elf_epiphany_reloc_type (type);
   1494 	  break;
   1495 
   1496 	case EM_IP2K:
   1497 	case EM_IP2K_OLD:
   1498 	  rtype = elf_ip2k_reloc_type (type);
   1499 	  break;
   1500 
   1501 	case EM_IQ2000:
   1502 	  rtype = elf_iq2000_reloc_type (type);
   1503 	  break;
   1504 
   1505 	case EM_XTENSA_OLD:
   1506 	case EM_XTENSA:
   1507 	  rtype = elf_xtensa_reloc_type (type);
   1508 	  break;
   1509 
   1510 	case EM_LATTICEMICO32:
   1511 	  rtype = elf_lm32_reloc_type (type);
   1512 	  break;
   1513 
   1514 	case EM_M32C_OLD:
   1515 	case EM_M32C:
   1516 	  rtype = elf_m32c_reloc_type (type);
   1517 	  break;
   1518 
   1519 	case EM_MT:
   1520 	  rtype = elf_mt_reloc_type (type);
   1521 	  break;
   1522 
   1523 	case EM_BLACKFIN:
   1524 	  rtype = elf_bfin_reloc_type (type);
   1525 	  break;
   1526 
   1527 	case EM_CYGNUS_MEP:
   1528 	  rtype = elf_mep_reloc_type (type);
   1529 	  break;
   1530 
   1531 	case EM_CR16:
   1532 	  rtype = elf_cr16_reloc_type (type);
   1533 	  break;
   1534 
   1535 	case EM_MICROBLAZE:
   1536 	case EM_MICROBLAZE_OLD:
   1537 	  rtype = elf_microblaze_reloc_type (type);
   1538 	  break;
   1539 
   1540 	case EM_RL78:
   1541 	  rtype = elf_rl78_reloc_type (type);
   1542 	  break;
   1543 
   1544 	case EM_RX:
   1545 	  rtype = elf_rx_reloc_type (type);
   1546 	  break;
   1547 
   1548 	case EM_METAG:
   1549 	  rtype = elf_metag_reloc_type (type);
   1550 	  break;
   1551 
   1552 	case EM_XC16X:
   1553 	case EM_C166:
   1554 	  rtype = elf_xc16x_reloc_type (type);
   1555 	  break;
   1556 
   1557 	case EM_TI_C6000:
   1558 	  rtype = elf_tic6x_reloc_type (type);
   1559 	  break;
   1560 
   1561 	case EM_TILEGX:
   1562 	  rtype = elf_tilegx_reloc_type (type);
   1563 	  break;
   1564 
   1565 	case EM_TILEPRO:
   1566 	  rtype = elf_tilepro_reloc_type (type);
   1567 	  break;
   1568 
   1569 	case EM_XGATE:
   1570 	  rtype = elf_xgate_reloc_type (type);
   1571 	  break;
   1572 
   1573 	case EM_ALTERA_NIOS2:
   1574 	  rtype = elf_nios2_reloc_type (type);
   1575 	  break;
   1576 	}
   1577 
   1578       if (is_relr)
   1579         printf (do_wide ? "RELATIVE COMPRESSED" : "RELR");
   1580       else if (rtype == NULL)
   1581 	printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
   1582       else
   1583 	printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
   1584 
   1585       if (elf_header.e_machine == EM_ALPHA
   1586 	  && rtype != NULL
   1587 	  && streq (rtype, "R_ALPHA_LITUSE")
   1588 	  && is_rela)
   1589 	{
   1590 	  switch (rels[i].r_addend)
   1591 	    {
   1592 	    case LITUSE_ALPHA_ADDR:   rtype = "ADDR";   break;
   1593 	    case LITUSE_ALPHA_BASE:   rtype = "BASE";   break;
   1594 	    case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
   1595 	    case LITUSE_ALPHA_JSR:    rtype = "JSR";    break;
   1596 	    case LITUSE_ALPHA_TLSGD:  rtype = "TLSGD";  break;
   1597 	    case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
   1598 	    case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
   1599 	    default: rtype = NULL;
   1600 	    }
   1601 	  if (rtype)
   1602 	    printf (" (%s)", rtype);
   1603 	  else
   1604 	    {
   1605 	      putchar (' ');
   1606 	      printf (_("<unknown addend: %lx>"),
   1607 		      (unsigned long) rels[i].r_addend);
   1608 	    }
   1609 	}
   1610       else if (symtab_index)
   1611 	{
   1612 	  if (symtab == NULL || symtab_index >= nsyms)
   1613 	    printf (_(" bad symbol index: %08lx"), (unsigned long) symtab_index);
   1614 	  else
   1615 	    {
   1616 	      Elf_Internal_Sym * psym;
   1617 	      const char * version_string;
   1618 	      enum versioned_symbol_info sym_info;
   1619 	      unsigned short vna_other;
   1620 
   1621 	      psym = symtab + symtab_index;
   1622 
   1623 	      version_string
   1624 		= get_symbol_version_string (file, is_dynsym,
   1625 					     strtab, strtablen,
   1626 					     symtab_index,
   1627 					     psym,
   1628 					     &sym_info,
   1629 					     &vna_other);
   1630 
   1631 	      printf (" ");
   1632 
   1633 	      if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
   1634 		{
   1635 		  const char * name;
   1636 		  unsigned int len;
   1637 		  unsigned int width = is_32bit_elf ? 8 : 14;
   1638 
   1639 		  /* Relocations against GNU_IFUNC symbols do not use the value
   1640 		     of the symbol as the address to relocate against.  Instead
   1641 		     they invoke the function named by the symbol and use its
   1642 		     result as the address for relocation.
   1643 
   1644 		     To indicate this to the user, do not display the value of
   1645 		     the symbol in the "Symbols's Value" field.  Instead show
   1646 		     its name followed by () as a hint that the symbol is
   1647 		     invoked.  */
   1648 
   1649 		  if (strtab == NULL
   1650 		      || psym->st_name == 0
   1651 		      || psym->st_name >= strtablen)
   1652 		    name = "??";
   1653 		  else
   1654 		    name = strtab + psym->st_name;
   1655 
   1656 		  len = print_symbol (width, name);
   1657 		  if (version_string)
   1658 		    printf (sym_info == symbol_public ? "@@%s" : "@%s",
   1659 			    version_string);
   1660 		  printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
   1661 		}
   1662 	      else
   1663 		{
   1664 		  print_vma (psym->st_value, LONG_HEX);
   1665 
   1666 		  printf (is_32bit_elf ? "   " : " ");
   1667 		}
   1668 
   1669 	      if (psym->st_name == 0)
   1670 		{
   1671 		  const char * sec_name = "<null>";
   1672 		  char name_buf[40];
   1673 
   1674 		  if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
   1675 		    {
   1676 		      if (psym->st_shndx < elf_header.e_shnum)
   1677 			sec_name = SECTION_NAME (section_headers + psym->st_shndx);
   1678 		      else if (psym->st_shndx == SHN_ABS)
   1679 			sec_name = "ABS";
   1680 		      else if (psym->st_shndx == SHN_COMMON)
   1681 			sec_name = "COMMON";
   1682 		      else if ((elf_header.e_machine == EM_MIPS
   1683 				&& psym->st_shndx == SHN_MIPS_SCOMMON)
   1684 			       || (elf_header.e_machine == EM_TI_C6000
   1685 				   && psym->st_shndx == SHN_TIC6X_SCOMMON))
   1686 			sec_name = "SCOMMON";
   1687 		      else if (elf_header.e_machine == EM_MIPS
   1688 			       && psym->st_shndx == SHN_MIPS_SUNDEFINED)
   1689 			sec_name = "SUNDEF";
   1690 		      else if ((elf_header.e_machine == EM_X86_64
   1691 				|| elf_header.e_machine == EM_L1OM
   1692 				|| elf_header.e_machine == EM_K1OM)
   1693 			       && psym->st_shndx == SHN_X86_64_LCOMMON)
   1694 			sec_name = "LARGE_COMMON";
   1695 		      else if (elf_header.e_machine == EM_IA_64
   1696 			       && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
   1697 			       && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
   1698 			sec_name = "ANSI_COM";
   1699 		      else if (is_ia64_vms ()
   1700 			       && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
   1701 			sec_name = "VMS_SYMVEC";
   1702 		      else
   1703 			{
   1704 			  sprintf (name_buf, "<section 0x%x>",
   1705 				   (unsigned int) psym->st_shndx);
   1706 			  sec_name = name_buf;
   1707 			}
   1708 		    }
   1709 		  print_symbol (22, sec_name);
   1710 		}
   1711 	      else if (strtab == NULL)
   1712 		printf (_("<string table index: %3ld>"), psym->st_name);
   1713 	      else if (psym->st_name >= strtablen)
   1714 		printf (_("<corrupt string table index: %3ld>"), psym->st_name);
   1715 	      else
   1716 		{
   1717 		  print_symbol (22, strtab + psym->st_name);
   1718 		  if (version_string)
   1719 		    printf (sym_info == symbol_public ? "@@%s" : "@%s",
   1720 			    version_string);
   1721 		}
   1722 
   1723 	      if (is_rela)
   1724 		{
   1725 		  bfd_vma off = rels[i].r_addend;
   1726 
   1727 		  if ((bfd_signed_vma) off < 0)
   1728 		    printf (" - %" BFD_VMA_FMT "x", - off);
   1729 		  else
   1730 		    printf (" + %" BFD_VMA_FMT "x", off);
   1731 		}
   1732 	    }
   1733 	}
   1734       else if (is_rela)
   1735 	{
   1736 	  bfd_vma off = rels[i].r_addend;
   1737 
   1738 	  printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
   1739 	  if ((bfd_signed_vma) off < 0)
   1740 	    printf ("-%" BFD_VMA_FMT "x", - off);
   1741 	  else
   1742 	    printf ("%" BFD_VMA_FMT "x", off);
   1743 	}
   1744 
   1745       if (elf_header.e_machine == EM_SPARCV9
   1746 	  && rtype != NULL
   1747 	  && streq (rtype, "R_SPARC_OLO10"))
   1748 	printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
   1749 
   1750       putchar ('\n');
   1751 
   1752 #ifdef BFD64
   1753       if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
   1754 	{
   1755 	  bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
   1756 	  bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
   1757 	  const char * rtype2 = elf_mips_reloc_type (type2);
   1758 	  const char * rtype3 = elf_mips_reloc_type (type3);
   1759 
   1760 	  printf ("                    Type2: ");
   1761 
   1762 	  if (rtype2 == NULL)
   1763 	    printf (_("unrecognized: %-7lx"),
   1764 		    (unsigned long) type2 & 0xffffffff);
   1765 	  else
   1766 	    printf ("%-17.17s", rtype2);
   1767 
   1768 	  printf ("\n                    Type3: ");
   1769 
   1770 	  if (rtype3 == NULL)
   1771 	    printf (_("unrecognized: %-7lx"),
   1772 		    (unsigned long) type3 & 0xffffffff);
   1773 	  else
   1774 	    printf ("%-17.17s", rtype3);
   1775 
   1776 	  putchar ('\n');
   1777 	}
   1778 #endif /* BFD64 */
   1779     }
   1780 
   1781   free (rels);
   1782 }
   1783 
   1784 static const char *
   1785 get_mips_dynamic_type (unsigned long type)
   1786 {
   1787   switch (type)
   1788     {
   1789     case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
   1790     case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
   1791     case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
   1792     case DT_MIPS_IVERSION: return "MIPS_IVERSION";
   1793     case DT_MIPS_FLAGS: return "MIPS_FLAGS";
   1794     case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
   1795     case DT_MIPS_MSYM: return "MIPS_MSYM";
   1796     case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
   1797     case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
   1798     case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
   1799     case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
   1800     case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
   1801     case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
   1802     case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
   1803     case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
   1804     case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
   1805     case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
   1806     case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
   1807     case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
   1808     case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
   1809     case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
   1810     case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
   1811     case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
   1812     case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
   1813     case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
   1814     case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
   1815     case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
   1816     case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
   1817     case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
   1818     case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
   1819     case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
   1820     case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
   1821     case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
   1822     case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
   1823     case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
   1824     case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
   1825     case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
   1826     case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
   1827     case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
   1828     case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
   1829     case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
   1830     case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
   1831     case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
   1832     case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
   1833     case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
   1834     case DT_MIPS_RWPLT: return "MIPS_RWPLT";
   1835     default:
   1836       return NULL;
   1837     }
   1838 }
   1839 
   1840 static const char *
   1841 get_sparc64_dynamic_type (unsigned long type)
   1842 {
   1843   switch (type)
   1844     {
   1845     case DT_SPARC_REGISTER: return "SPARC_REGISTER";
   1846     default:
   1847       return NULL;
   1848     }
   1849 }
   1850 
   1851 static const char *
   1852 get_ppc_dynamic_type (unsigned long type)
   1853 {
   1854   switch (type)
   1855     {
   1856     case DT_PPC_GOT:    return "PPC_GOT";
   1857     case DT_PPC_OPT:    return "PPC_OPT";
   1858     default:
   1859       return NULL;
   1860     }
   1861 }
   1862 
   1863 static const char *
   1864 get_ppc64_dynamic_type (unsigned long type)
   1865 {
   1866   switch (type)
   1867     {
   1868     case DT_PPC64_GLINK:  return "PPC64_GLINK";
   1869     case DT_PPC64_OPD:    return "PPC64_OPD";
   1870     case DT_PPC64_OPDSZ:  return "PPC64_OPDSZ";
   1871     case DT_PPC64_OPT:    return "PPC64_OPT";
   1872     default:
   1873       return NULL;
   1874     }
   1875 }
   1876 
   1877 static const char *
   1878 get_parisc_dynamic_type (unsigned long type)
   1879 {
   1880   switch (type)
   1881     {
   1882     case DT_HP_LOAD_MAP:	return "HP_LOAD_MAP";
   1883     case DT_HP_DLD_FLAGS:	return "HP_DLD_FLAGS";
   1884     case DT_HP_DLD_HOOK:	return "HP_DLD_HOOK";
   1885     case DT_HP_UX10_INIT:	return "HP_UX10_INIT";
   1886     case DT_HP_UX10_INITSZ:	return "HP_UX10_INITSZ";
   1887     case DT_HP_PREINIT:		return "HP_PREINIT";
   1888     case DT_HP_PREINITSZ:	return "HP_PREINITSZ";
   1889     case DT_HP_NEEDED:		return "HP_NEEDED";
   1890     case DT_HP_TIME_STAMP:	return "HP_TIME_STAMP";
   1891     case DT_HP_CHECKSUM:	return "HP_CHECKSUM";
   1892     case DT_HP_GST_SIZE:	return "HP_GST_SIZE";
   1893     case DT_HP_GST_VERSION:	return "HP_GST_VERSION";
   1894     case DT_HP_GST_HASHVAL:	return "HP_GST_HASHVAL";
   1895     case DT_HP_EPLTREL:		return "HP_GST_EPLTREL";
   1896     case DT_HP_EPLTRELSZ:	return "HP_GST_EPLTRELSZ";
   1897     case DT_HP_FILTERED:	return "HP_FILTERED";
   1898     case DT_HP_FILTER_TLS:	return "HP_FILTER_TLS";
   1899     case DT_HP_COMPAT_FILTERED:	return "HP_COMPAT_FILTERED";
   1900     case DT_HP_LAZYLOAD:	return "HP_LAZYLOAD";
   1901     case DT_HP_BIND_NOW_COUNT:	return "HP_BIND_NOW_COUNT";
   1902     case DT_PLT:		return "PLT";
   1903     case DT_PLT_SIZE:		return "PLT_SIZE";
   1904     case DT_DLT:		return "DLT";
   1905     case DT_DLT_SIZE:		return "DLT_SIZE";
   1906     default:
   1907       return NULL;
   1908     }
   1909 }
   1910 
   1911 static const char *
   1912 get_ia64_dynamic_type (unsigned long type)
   1913 {
   1914   switch (type)
   1915     {
   1916     case DT_IA_64_PLT_RESERVE:         return "IA_64_PLT_RESERVE";
   1917     case DT_IA_64_VMS_SUBTYPE:         return "VMS_SUBTYPE";
   1918     case DT_IA_64_VMS_IMGIOCNT:        return "VMS_IMGIOCNT";
   1919     case DT_IA_64_VMS_LNKFLAGS:        return "VMS_LNKFLAGS";
   1920     case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
   1921     case DT_IA_64_VMS_IDENT:           return "VMS_IDENT";
   1922     case DT_IA_64_VMS_NEEDED_IDENT:    return "VMS_NEEDED_IDENT";
   1923     case DT_IA_64_VMS_IMG_RELA_CNT:    return "VMS_IMG_RELA_CNT";
   1924     case DT_IA_64_VMS_SEG_RELA_CNT:    return "VMS_SEG_RELA_CNT";
   1925     case DT_IA_64_VMS_FIXUP_RELA_CNT:  return "VMS_FIXUP_RELA_CNT";
   1926     case DT_IA_64_VMS_FIXUP_NEEDED:    return "VMS_FIXUP_NEEDED";
   1927     case DT_IA_64_VMS_SYMVEC_CNT:      return "VMS_SYMVEC_CNT";
   1928     case DT_IA_64_VMS_XLATED:          return "VMS_XLATED";
   1929     case DT_IA_64_VMS_STACKSIZE:       return "VMS_STACKSIZE";
   1930     case DT_IA_64_VMS_UNWINDSZ:        return "VMS_UNWINDSZ";
   1931     case DT_IA_64_VMS_UNWIND_CODSEG:   return "VMS_UNWIND_CODSEG";
   1932     case DT_IA_64_VMS_UNWIND_INFOSEG:  return "VMS_UNWIND_INFOSEG";
   1933     case DT_IA_64_VMS_LINKTIME:        return "VMS_LINKTIME";
   1934     case DT_IA_64_VMS_SEG_NO:          return "VMS_SEG_NO";
   1935     case DT_IA_64_VMS_SYMVEC_OFFSET:   return "VMS_SYMVEC_OFFSET";
   1936     case DT_IA_64_VMS_SYMVEC_SEG:      return "VMS_SYMVEC_SEG";
   1937     case DT_IA_64_VMS_UNWIND_OFFSET:   return "VMS_UNWIND_OFFSET";
   1938     case DT_IA_64_VMS_UNWIND_SEG:      return "VMS_UNWIND_SEG";
   1939     case DT_IA_64_VMS_STRTAB_OFFSET:   return "VMS_STRTAB_OFFSET";
   1940     case DT_IA_64_VMS_SYSVER_OFFSET:   return "VMS_SYSVER_OFFSET";
   1941     case DT_IA_64_VMS_IMG_RELA_OFF:    return "VMS_IMG_RELA_OFF";
   1942     case DT_IA_64_VMS_SEG_RELA_OFF:    return "VMS_SEG_RELA_OFF";
   1943     case DT_IA_64_VMS_FIXUP_RELA_OFF:  return "VMS_FIXUP_RELA_OFF";
   1944     case DT_IA_64_VMS_PLTGOT_OFFSET:   return "VMS_PLTGOT_OFFSET";
   1945     case DT_IA_64_VMS_PLTGOT_SEG:      return "VMS_PLTGOT_SEG";
   1946     case DT_IA_64_VMS_FPMODE:          return "VMS_FPMODE";
   1947     default:
   1948       return NULL;
   1949     }
   1950 }
   1951 
   1952 static const char *
   1953 get_solaris_section_type (unsigned long type)
   1954 {
   1955   switch (type)
   1956     {
   1957     case 0x6fffffee: return "SUNW_ancillary";
   1958     case 0x6fffffef: return "SUNW_capchain";
   1959     case 0x6ffffff0: return "SUNW_capinfo";
   1960     case 0x6ffffff1: return "SUNW_symsort";
   1961     case 0x6ffffff2: return "SUNW_tlssort";
   1962     case 0x6ffffff3: return "SUNW_LDYNSYM";
   1963     case 0x6ffffff4: return "SUNW_dof";
   1964     case 0x6ffffff5: return "SUNW_cap";
   1965     case 0x6ffffff6: return "SUNW_SIGNATURE";
   1966     case 0x6ffffff7: return "SUNW_ANNOTATE";
   1967     case 0x6ffffff8: return "SUNW_DEBUGSTR";
   1968     case 0x6ffffff9: return "SUNW_DEBUG";
   1969     case 0x6ffffffa: return "SUNW_move";
   1970     case 0x6ffffffb: return "SUNW_COMDAT";
   1971     case 0x6ffffffc: return "SUNW_syminfo";
   1972     case 0x6ffffffd: return "SUNW_verdef";
   1973     case 0x6ffffffe: return "SUNW_verneed";
   1974     case 0x6fffffff: return "SUNW_versym";
   1975     case 0x70000000: return "SPARC_GOTDATA";
   1976     default: return NULL;
   1977     }
   1978 }
   1979 
   1980 static const char *
   1981 get_alpha_dynamic_type (unsigned long type)
   1982 {
   1983   switch (type)
   1984     {
   1985     case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
   1986     default:
   1987       return NULL;
   1988     }
   1989 }
   1990 
   1991 static const char *
   1992 get_score_dynamic_type (unsigned long type)
   1993 {
   1994   switch (type)
   1995     {
   1996     case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
   1997     case DT_SCORE_LOCAL_GOTNO:  return "SCORE_LOCAL_GOTNO";
   1998     case DT_SCORE_SYMTABNO:     return "SCORE_SYMTABNO";
   1999     case DT_SCORE_GOTSYM:       return "SCORE_GOTSYM";
   2000     case DT_SCORE_UNREFEXTNO:   return "SCORE_UNREFEXTNO";
   2001     case DT_SCORE_HIPAGENO:     return "SCORE_HIPAGENO";
   2002     default:
   2003       return NULL;
   2004     }
   2005 }
   2006 
   2007 static const char *
   2008 get_tic6x_dynamic_type (unsigned long type)
   2009 {
   2010   switch (type)
   2011     {
   2012     case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
   2013     case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
   2014     case DT_C6000_DSBT_BASE:   return "C6000_DSBT_BASE";
   2015     case DT_C6000_DSBT_SIZE:   return "C6000_DSBT_SIZE";
   2016     case DT_C6000_PREEMPTMAP:  return "C6000_PREEMPTMAP";
   2017     case DT_C6000_DSBT_INDEX:  return "C6000_DSBT_INDEX";
   2018     default:
   2019       return NULL;
   2020     }
   2021 }
   2022 
   2023 static const char *
   2024 get_nios2_dynamic_type (unsigned long type)
   2025 {
   2026   switch (type)
   2027     {
   2028     case DT_NIOS2_GP: return "NIOS2_GP";
   2029     default:
   2030       return NULL;
   2031     }
   2032 }
   2033 
   2034 static const char *
   2035 get_solaris_dynamic_type (unsigned long type)
   2036 {
   2037   switch (type)
   2038     {
   2039     case 0x6000000d: return "SUNW_AUXILIARY";
   2040     case 0x6000000e: return "SUNW_RTLDINF";
   2041     case 0x6000000f: return "SUNW_FILTER";
   2042     case 0x60000010: return "SUNW_CAP";
   2043     case 0x60000011: return "SUNW_SYMTAB";
   2044     case 0x60000012: return "SUNW_SYMSZ";
   2045     case 0x60000013: return "SUNW_SORTENT";
   2046     case 0x60000014: return "SUNW_SYMSORT";
   2047     case 0x60000015: return "SUNW_SYMSORTSZ";
   2048     case 0x60000016: return "SUNW_TLSSORT";
   2049     case 0x60000017: return "SUNW_TLSSORTSZ";
   2050     case 0x60000018: return "SUNW_CAPINFO";
   2051     case 0x60000019: return "SUNW_STRPAD";
   2052     case 0x6000001a: return "SUNW_CAPCHAIN";
   2053     case 0x6000001b: return "SUNW_LDMACH";
   2054     case 0x6000001d: return "SUNW_CAPCHAINENT";
   2055     case 0x6000001f: return "SUNW_CAPCHAINSZ";
   2056     case 0x60000021: return "SUNW_PARENT";
   2057     case 0x60000023: return "SUNW_ASLR";
   2058     case 0x60000025: return "SUNW_RELAX";
   2059     case 0x60000029: return "SUNW_NXHEAP";
   2060     case 0x6000002b: return "SUNW_NXSTACK";
   2061 
   2062     case 0x70000001: return "SPARC_REGISTER";
   2063     case 0x7ffffffd: return "AUXILIARY";
   2064     case 0x7ffffffe: return "USED";
   2065     case 0x7fffffff: return "FILTER";
   2066 
   2067     default: return NULL;
   2068     }
   2069 }
   2070 
   2071 static const char *
   2072 get_dynamic_type (unsigned long type)
   2073 {
   2074   static char buff[64];
   2075 
   2076   switch (type)
   2077     {
   2078     case DT_NULL:	return "NULL";
   2079     case DT_NEEDED:	return "NEEDED";
   2080     case DT_PLTRELSZ:	return "PLTRELSZ";
   2081     case DT_PLTGOT:	return "PLTGOT";
   2082     case DT_HASH:	return "HASH";
   2083     case DT_STRTAB:	return "STRTAB";
   2084     case DT_SYMTAB:	return "SYMTAB";
   2085     case DT_RELA:	return "RELA";
   2086     case DT_RELASZ:	return "RELASZ";
   2087     case DT_RELAENT:	return "RELAENT";
   2088     case DT_STRSZ:	return "STRSZ";
   2089     case DT_SYMENT:	return "SYMENT";
   2090     case DT_INIT:	return "INIT";
   2091     case DT_FINI:	return "FINI";
   2092     case DT_SONAME:	return "SONAME";
   2093     case DT_RPATH:	return "RPATH";
   2094     case DT_SYMBOLIC:	return "SYMBOLIC";
   2095     case DT_REL:	return "REL";
   2096     case DT_RELSZ:	return "RELSZ";
   2097     case DT_RELENT:	return "RELENT";
   2098     case DT_RELR:	return "RELR";
   2099     case DT_RELRSZ:	return "RELRSZ";
   2100     case DT_RELRENT:	return "RELRENT";
   2101     case DT_PLTREL:	return "PLTREL";
   2102     case DT_DEBUG:	return "DEBUG";
   2103     case DT_TEXTREL:	return "TEXTREL";
   2104     case DT_JMPREL:	return "JMPREL";
   2105     case DT_BIND_NOW:   return "BIND_NOW";
   2106     case DT_INIT_ARRAY: return "INIT_ARRAY";
   2107     case DT_FINI_ARRAY: return "FINI_ARRAY";
   2108     case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
   2109     case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
   2110     case DT_RUNPATH:    return "RUNPATH";
   2111     case DT_FLAGS:      return "FLAGS";
   2112 
   2113     case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
   2114     case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
   2115 
   2116     case DT_CHECKSUM:	return "CHECKSUM";
   2117     case DT_PLTPADSZ:	return "PLTPADSZ";
   2118     case DT_MOVEENT:	return "MOVEENT";
   2119     case DT_MOVESZ:	return "MOVESZ";
   2120     case DT_FEATURE:	return "FEATURE";
   2121     case DT_POSFLAG_1:	return "POSFLAG_1";
   2122     case DT_SYMINSZ:	return "SYMINSZ";
   2123     case DT_SYMINENT:	return "SYMINENT"; /* aka VALRNGHI */
   2124 
   2125     case DT_ADDRRNGLO:  return "ADDRRNGLO";
   2126     case DT_CONFIG:	return "CONFIG";
   2127     case DT_DEPAUDIT:	return "DEPAUDIT";
   2128     case DT_AUDIT:	return "AUDIT";
   2129     case DT_PLTPAD:	return "PLTPAD";
   2130     case DT_MOVETAB:	return "MOVETAB";
   2131     case DT_SYMINFO:	return "SYMINFO"; /* aka ADDRRNGHI */
   2132 
   2133     case DT_VERSYM:	return "VERSYM";
   2134 
   2135     case DT_TLSDESC_GOT: return "TLSDESC_GOT";
   2136     case DT_TLSDESC_PLT: return "TLSDESC_PLT";
   2137     case DT_RELRCOUNT:	return "RELRCOUNT";
   2138     case DT_RELACOUNT:	return "RELACOUNT";
   2139     case DT_RELCOUNT:	return "RELCOUNT";
   2140     case DT_FLAGS_1:	return "FLAGS_1";
   2141     case DT_VERDEF:	return "VERDEF";
   2142     case DT_VERDEFNUM:	return "VERDEFNUM";
   2143     case DT_VERNEED:	return "VERNEED";
   2144     case DT_VERNEEDNUM:	return "VERNEEDNUM";
   2145 
   2146     case DT_AUXILIARY:	return "AUXILIARY";
   2147     case DT_USED:	return "USED";
   2148     case DT_FILTER:	return "FILTER";
   2149 
   2150     case DT_GNU_PRELINKED: return "GNU_PRELINKED";
   2151     case DT_GNU_CONFLICT: return "GNU_CONFLICT";
   2152     case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
   2153     case DT_GNU_LIBLIST: return "GNU_LIBLIST";
   2154     case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
   2155     case DT_GNU_HASH:	return "GNU_HASH";
   2156 
   2157     default:
   2158       if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
   2159 	{
   2160 	  const char * result;
   2161 
   2162 	  switch (elf_header.e_machine)
   2163 	    {
   2164 	    case EM_MIPS:
   2165 	    case EM_MIPS_RS3_LE:
   2166 	      result = get_mips_dynamic_type (type);
   2167 	      break;
   2168 	    case EM_SPARCV9:
   2169 	      result = get_sparc64_dynamic_type (type);
   2170 	      break;
   2171 	    case EM_PPC:
   2172 	      result = get_ppc_dynamic_type (type);
   2173 	      break;
   2174 	    case EM_PPC64:
   2175 	      result = get_ppc64_dynamic_type (type);
   2176 	      break;
   2177 	    case EM_IA_64:
   2178 	      result = get_ia64_dynamic_type (type);
   2179 	      break;
   2180 	    case EM_ALPHA:
   2181 	      result = get_alpha_dynamic_type (type);
   2182 	      break;
   2183 	    case EM_SCORE:
   2184 	      result = get_score_dynamic_type (type);
   2185 	      break;
   2186 	    case EM_TI_C6000:
   2187 	      result = get_tic6x_dynamic_type (type);
   2188 	      break;
   2189 	    case EM_ALTERA_NIOS2:
   2190 	      result = get_nios2_dynamic_type (type);
   2191 	      break;
   2192 	    default:
   2193 	      if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
   2194 		result = get_solaris_dynamic_type (type);
   2195 	      else
   2196 		result = NULL;
   2197 	      break;
   2198 	    }
   2199 
   2200 	  if (result != NULL)
   2201 	    return result;
   2202 
   2203 	  snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
   2204 	}
   2205       else if (((type >= DT_LOOS) && (type <= DT_HIOS))
   2206 	       || (elf_header.e_machine == EM_PARISC
   2207 		   && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
   2208 	{
   2209 	  const char * result;
   2210 
   2211 	  switch (elf_header.e_machine)
   2212 	    {
   2213 	    case EM_PARISC:
   2214 	      result = get_parisc_dynamic_type (type);
   2215 	      break;
   2216 	    case EM_IA_64:
   2217 	      result = get_ia64_dynamic_type (type);
   2218 	      break;
   2219 	    default:
   2220 	      if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
   2221 		result = get_solaris_dynamic_type (type);
   2222 	      else
   2223 		result = NULL;
   2224 	      break;
   2225 	    }
   2226 
   2227 	  if (result != NULL)
   2228 	    return result;
   2229 
   2230 	  snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
   2231 		    type);
   2232 	}
   2233       else
   2234 	snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
   2235 
   2236       return buff;
   2237     }
   2238 }
   2239 
   2240 static char *
   2241 get_file_type (unsigned e_type)
   2242 {
   2243   static char buff[32];
   2244 
   2245   switch (e_type)
   2246     {
   2247     case ET_NONE:	return _("NONE (None)");
   2248     case ET_REL:	return _("REL (Relocatable file)");
   2249     case ET_EXEC:	return _("EXEC (Executable file)");
   2250     case ET_DYN:	return _("DYN (Shared object file)");
   2251     case ET_CORE:	return _("CORE (Core file)");
   2252 
   2253     default:
   2254       if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
   2255 	snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
   2256       else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
   2257 	snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
   2258       else
   2259 	snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
   2260       return buff;
   2261     }
   2262 }
   2263 
   2264 static char *
   2265 get_machine_name (unsigned e_machine)
   2266 {
   2267   static char buff[64]; /* XXX */
   2268 
   2269   switch (e_machine)
   2270     {
   2271     case EM_NONE:		return _("None");
   2272     case EM_AARCH64:		return "AArch64";
   2273     case EM_M32:		return "WE32100";
   2274     case EM_SPARC:		return "Sparc";
   2275     case EM_SPU:		return "SPU";
   2276     case EM_386:		return "Intel 80386";
   2277     case EM_68K:		return "MC68000";
   2278     case EM_88K:		return "MC88000";
   2279     case EM_IAMCU:		return "Intel MCU";
   2280     case EM_860:		return "Intel 80860";
   2281     case EM_MIPS:		return "MIPS R3000";
   2282     case EM_S370:		return "IBM System/370";
   2283     case EM_MIPS_RS3_LE:	return "MIPS R4000 big-endian";
   2284     case EM_OLD_SPARCV9:	return "Sparc v9 (old)";
   2285     case EM_PARISC:		return "HPPA";
   2286     case EM_PPC_OLD:		return "Power PC (old)";
   2287     case EM_SPARC32PLUS:	return "Sparc v8+" ;
   2288     case EM_960:		return "Intel 90860";
   2289     case EM_PPC:		return "PowerPC";
   2290     case EM_PPC64:		return "PowerPC64";
   2291     case EM_FR20:		return "Fujitsu FR20";
   2292     case EM_FT32:		return "FTDI FT32";
   2293     case EM_RH32:		return "TRW RH32";
   2294     case EM_MCORE:		return "MCORE";
   2295     case EM_ARM:		return "ARM";
   2296     case EM_OLD_ALPHA:		return "Digital Alpha (old)";
   2297     case EM_SH:			return "Renesas / SuperH SH";
   2298     case EM_SPARCV9:		return "Sparc v9";
   2299     case EM_TRICORE:		return "Siemens Tricore";
   2300     case EM_ARC:		return "ARC";
   2301     case EM_ARC_COMPACT:	return "ARCompact";
   2302     case EM_ARC_COMPACT2:	return "ARCv2";
   2303     case EM_H8_300:		return "Renesas H8/300";
   2304     case EM_H8_300H:		return "Renesas H8/300H";
   2305     case EM_H8S:		return "Renesas H8S";
   2306     case EM_H8_500:		return "Renesas H8/500";
   2307     case EM_IA_64:		return "Intel IA-64";
   2308     case EM_MIPS_X:		return "Stanford MIPS-X";
   2309     case EM_COLDFIRE:		return "Motorola Coldfire";
   2310     case EM_ALPHA:		return "Alpha";
   2311     case EM_CYGNUS_D10V:
   2312     case EM_D10V:		return "d10v";
   2313     case EM_CYGNUS_D30V:
   2314     case EM_D30V:		return "d30v";
   2315     case EM_CYGNUS_M32R:
   2316     case EM_M32R:		return "Renesas M32R (formerly Mitsubishi M32r)";
   2317     case EM_CYGNUS_V850:
   2318     case EM_V800:		return "Renesas V850 (using RH850 ABI)";
   2319     case EM_V850:		return "Renesas V850";
   2320     case EM_CYGNUS_MN10300:
   2321     case EM_MN10300:		return "mn10300";
   2322     case EM_CYGNUS_MN10200:
   2323     case EM_MN10200:		return "mn10200";
   2324     case EM_MOXIE:		return "Moxie";
   2325     case EM_CYGNUS_FR30:
   2326     case EM_FR30:		return "Fujitsu FR30";
   2327     case EM_CYGNUS_FRV:		return "Fujitsu FR-V";
   2328     case EM_PJ_OLD:
   2329     case EM_PJ:			return "picoJava";
   2330     case EM_MMA:		return "Fujitsu Multimedia Accelerator";
   2331     case EM_PCP:		return "Siemens PCP";
   2332     case EM_NCPU:		return "Sony nCPU embedded RISC processor";
   2333     case EM_NDR1:		return "Denso NDR1 microprocesspr";
   2334     case EM_STARCORE:		return "Motorola Star*Core processor";
   2335     case EM_ME16:		return "Toyota ME16 processor";
   2336     case EM_ST100:		return "STMicroelectronics ST100 processor";
   2337     case EM_TINYJ:		return "Advanced Logic Corp. TinyJ embedded processor";
   2338     case EM_PDSP:		return "Sony DSP processor";
   2339     case EM_PDP10:		return "Digital Equipment Corp. PDP-10";
   2340     case EM_PDP11:		return "Digital Equipment Corp. PDP-11";
   2341     case EM_FX66:		return "Siemens FX66 microcontroller";
   2342     case EM_ST9PLUS:		return "STMicroelectronics ST9+ 8/16 bit microcontroller";
   2343     case EM_ST7:		return "STMicroelectronics ST7 8-bit microcontroller";
   2344     case EM_68HC16:		return "Motorola MC68HC16 Microcontroller";
   2345     case EM_68HC12:		return "Motorola MC68HC12 Microcontroller";
   2346     case EM_68HC11:		return "Motorola MC68HC11 Microcontroller";
   2347     case EM_68HC08:		return "Motorola MC68HC08 Microcontroller";
   2348     case EM_68HC05:		return "Motorola MC68HC05 Microcontroller";
   2349     case EM_SVX:		return "Silicon Graphics SVx";
   2350     case EM_ST19:		return "STMicroelectronics ST19 8-bit microcontroller";
   2351     case EM_VAX:		return "Digital VAX";
   2352     case EM_VISIUM:		return "CDS VISIUMcore processor";
   2353     case EM_AVR_OLD:
   2354     case EM_AVR:		return "Atmel AVR 8-bit microcontroller";
   2355     case EM_CRIS:		return "Axis Communications 32-bit embedded processor";
   2356     case EM_JAVELIN:		return "Infineon Technologies 32-bit embedded cpu";
   2357     case EM_FIREPATH:		return "Element 14 64-bit DSP processor";
   2358     case EM_ZSP:		return "LSI Logic's 16-bit DSP processor";
   2359     case EM_MMIX:		return "Donald Knuth's educational 64-bit processor";
   2360     case EM_HUANY:		return "Harvard Universitys's machine-independent object format";
   2361     case EM_PRISM:		return "Vitesse Prism";
   2362     case EM_X86_64:		return "Advanced Micro Devices X86-64";
   2363     case EM_L1OM:		return "Intel L1OM";
   2364     case EM_K1OM:		return "Intel K1OM";
   2365     case EM_S390_OLD:
   2366     case EM_S390:		return "IBM S/390";
   2367     case EM_SCORE:		return "SUNPLUS S+Core";
   2368     case EM_XSTORMY16:		return "Sanyo XStormy16 CPU core";
   2369     case EM_OR1K:		return "OpenRISC 1000";
   2370     case EM_CRX:		return "National Semiconductor CRX microprocessor";
   2371     case EM_ADAPTEVA_EPIPHANY:	return "Adapteva EPIPHANY";
   2372     case EM_DLX:		return "OpenDLX";
   2373     case EM_IP2K_OLD:
   2374     case EM_IP2K:		return "Ubicom IP2xxx 8-bit microcontrollers";
   2375     case EM_IQ2000:       	return "Vitesse IQ2000";
   2376     case EM_XTENSA_OLD:
   2377     case EM_XTENSA:		return "Tensilica Xtensa Processor";
   2378     case EM_VIDEOCORE:		return "Alphamosaic VideoCore processor";
   2379     case EM_TMM_GPP:		return "Thompson Multimedia General Purpose Processor";
   2380     case EM_NS32K:		return "National Semiconductor 32000 series";
   2381     case EM_TPC:		return "Tenor Network TPC processor";
   2382     case EM_ST200:		return "STMicroelectronics ST200 microcontroller";
   2383     case EM_MAX:		return "MAX Processor";
   2384     case EM_CR:			return "National Semiconductor CompactRISC";
   2385     case EM_F2MC16:		return "Fujitsu F2MC16";
   2386     case EM_MSP430:		return "Texas Instruments msp430 microcontroller";
   2387     case EM_LATTICEMICO32:	return "Lattice Mico32";
   2388     case EM_M32C_OLD:
   2389     case EM_M32C:	        return "Renesas M32c";
   2390     case EM_MT:                 return "Morpho Techologies MT processor";
   2391     case EM_BLACKFIN:		return "Analog Devices Blackfin";
   2392     case EM_SE_C33:		return "S1C33 Family of Seiko Epson processors";
   2393     case EM_SEP:		return "Sharp embedded microprocessor";
   2394     case EM_ARCA:		return "Arca RISC microprocessor";
   2395     case EM_UNICORE:		return "Unicore";
   2396     case EM_EXCESS:		return "eXcess 16/32/64-bit configurable embedded CPU";
   2397     case EM_DXP:		return "Icera Semiconductor Inc. Deep Execution Processor";
   2398     case EM_NIOS32:		return "Altera Nios";
   2399     case EM_ALTERA_NIOS2:	return "Altera Nios II";
   2400     case EM_C166:
   2401     case EM_XC16X:		return "Infineon Technologies xc16x";
   2402     case EM_M16C:		return "Renesas M16C series microprocessors";
   2403     case EM_DSPIC30F:		return "Microchip Technology dsPIC30F Digital Signal Controller";
   2404     case EM_CE:			return "Freescale Communication Engine RISC core";
   2405     case EM_TSK3000:		return "Altium TSK3000 core";
   2406     case EM_RS08:		return "Freescale RS08 embedded processor";
   2407     case EM_ECOG2:		return "Cyan Technology eCOG2 microprocessor";
   2408     case EM_DSP24:		return "New Japan Radio (NJR) 24-bit DSP Processor";
   2409     case EM_VIDEOCORE3:		return "Broadcom VideoCore III processor";
   2410     case EM_SE_C17:		return "Seiko Epson C17 family";
   2411     case EM_TI_C6000:		return "Texas Instruments TMS320C6000 DSP family";
   2412     case EM_TI_C2000:		return "Texas Instruments TMS320C2000 DSP family";
   2413     case EM_TI_C5500:		return "Texas Instruments TMS320C55x DSP family";
   2414     case EM_MMDSP_PLUS:		return "STMicroelectronics 64bit VLIW Data Signal Processor";
   2415     case EM_CYPRESS_M8C:	return "Cypress M8C microprocessor";
   2416     case EM_R32C:		return "Renesas R32C series microprocessors";
   2417     case EM_TRIMEDIA:		return "NXP Semiconductors TriMedia architecture family";
   2418     case EM_QDSP6:		return "QUALCOMM DSP6 Processor";
   2419     case EM_8051:		return "Intel 8051 and variants";
   2420     case EM_STXP7X:		return "STMicroelectronics STxP7x family";
   2421     case EM_NDS32:		return "Andes Technology compact code size embedded RISC processor family";
   2422     case EM_ECOG1X:		return "Cyan Technology eCOG1X family";
   2423     case EM_MAXQ30:		return "Dallas Semiconductor MAXQ30 Core microcontrollers";
   2424     case EM_XIMO16:		return "New Japan Radio (NJR) 16-bit DSP Processor";
   2425     case EM_MANIK:		return "M2000 Reconfigurable RISC Microprocessor";
   2426     case EM_CRAYNV2:		return "Cray Inc. NV2 vector architecture";
   2427     case EM_CYGNUS_MEP:         return "Toshiba MeP Media Engine";
   2428     case EM_CR16:
   2429     case EM_MICROBLAZE:
   2430     case EM_MICROBLAZE_OLD:	return "Xilinx MicroBlaze";
   2431     case EM_RL78:		return "Renesas RL78";
   2432     case EM_RX:			return "Renesas RX";
   2433     case EM_METAG:		return "Imagination Technologies Meta processor architecture";
   2434     case EM_MCST_ELBRUS:	return "MCST Elbrus general purpose hardware architecture";
   2435     case EM_ECOG16:		return "Cyan Technology eCOG16 family";
   2436     case EM_ETPU:		return "Freescale Extended Time Processing Unit";
   2437     case EM_SLE9X:		return "Infineon Technologies SLE9X core";
   2438     case EM_AVR32:		return "Atmel Corporation 32-bit microprocessor family";
   2439     case EM_STM8:		return "STMicroeletronics STM8 8-bit microcontroller";
   2440     case EM_TILE64:		return "Tilera TILE64 multicore architecture family";
   2441     case EM_TILEPRO:		return "Tilera TILEPro multicore architecture family";
   2442     case EM_TILEGX:		return "Tilera TILE-Gx multicore architecture family";
   2443     case EM_CUDA:		return "NVIDIA CUDA architecture";
   2444     case EM_XGATE:		return "Motorola XGATE embedded processor";
   2445     default:
   2446       snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
   2447       return buff;
   2448     }
   2449 }
   2450 
   2451 static void
   2452 decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[])
   2453 {
   2454   /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2.  Some
   2455      other compilers don't a specific architecture type in the e_flags, and
   2456      instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
   2457      architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
   2458      architectures.
   2459 
   2460      Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
   2461      but also sets a specific architecture type in the e_flags field.
   2462 
   2463      However, when decoding the flags we don't worry if we see an
   2464      unexpected pairing, for example EM_ARC_COMPACT machine type, with
   2465      ARCEM architecture type.  */
   2466 
   2467   switch (e_flags & EF_ARC_MACH_MSK)
   2468     {
   2469       /* We only expect these to occur for EM_ARC_COMPACT2.  */
   2470     case EF_ARC_CPU_ARCV2EM:
   2471       strcat (buf, ", ARC EM");
   2472       break;
   2473     case EF_ARC_CPU_ARCV2HS:
   2474       strcat (buf, ", ARC HS");
   2475       break;
   2476 
   2477       /* We only expect these to occur for EM_ARC_COMPACT.  */
   2478     case E_ARC_MACH_ARC600:
   2479       strcat (buf, ", ARC600");
   2480       break;
   2481     case E_ARC_MACH_ARC601:
   2482       strcat (buf, ", ARC601");
   2483       break;
   2484     case E_ARC_MACH_ARC700:
   2485       strcat (buf, ", ARC700");
   2486       break;
   2487 
   2488       /* The only times we should end up here are (a) A corrupt ELF, (b) A
   2489          new ELF with new architecture being read by an old version of
   2490          readelf, or (c) An ELF built with non-GNU compiler that does not
   2491          set the architecture in the e_flags.  */
   2492     default:
   2493       if (e_machine == EM_ARC_COMPACT)
   2494         strcat (buf, ", Unknown ARCompact");
   2495       else
   2496         strcat (buf, ", Unknown ARC");
   2497       break;
   2498     }
   2499 
   2500   switch (e_flags & EF_ARC_OSABI_MSK)
   2501     {
   2502     case E_ARC_OSABI_ORIG:
   2503       strcat (buf, ", (ABI:legacy)");
   2504       break;
   2505     case E_ARC_OSABI_V2:
   2506       strcat (buf, ", (ABI:v2)");
   2507       break;
   2508       /* Only upstream 3.9+ kernels will support ARCv2 ISA.  */
   2509     case E_ARC_OSABI_V3:
   2510       strcat (buf, ", v3 no-legacy-syscalls ABI");
   2511       break;
   2512     default:
   2513       strcat (buf, ", unrecognised ARC OSABI flag");
   2514       break;
   2515     }
   2516 }
   2517 
   2518 static void
   2519 decode_ARM_machine_flags (unsigned e_flags, char buf[])
   2520 {
   2521   unsigned eabi;
   2522   int unknown = 0;
   2523 
   2524   eabi = EF_ARM_EABI_VERSION (e_flags);
   2525   e_flags &= ~ EF_ARM_EABIMASK;
   2526 
   2527   /* Handle "generic" ARM flags.  */
   2528   if (e_flags & EF_ARM_RELEXEC)
   2529     {
   2530       strcat (buf, ", relocatable executable");
   2531       e_flags &= ~ EF_ARM_RELEXEC;
   2532     }
   2533 
   2534   /* Now handle EABI specific flags.  */
   2535   switch (eabi)
   2536     {
   2537     default:
   2538       strcat (buf, ", <unrecognized EABI>");
   2539       if (e_flags)
   2540 	unknown = 1;
   2541       break;
   2542 
   2543     case EF_ARM_EABI_VER1:
   2544       strcat (buf, ", Version1 EABI");
   2545       while (e_flags)
   2546 	{
   2547 	  unsigned flag;
   2548 
   2549 	  /* Process flags one bit at a time.  */
   2550 	  flag = e_flags & - e_flags;
   2551 	  e_flags &= ~ flag;
   2552 
   2553 	  switch (flag)
   2554 	    {
   2555 	    case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK.  */
   2556 	      strcat (buf, ", sorted symbol tables");
   2557 	      break;
   2558 
   2559 	    default:
   2560 	      unknown = 1;
   2561 	      break;
   2562 	    }
   2563 	}
   2564       break;
   2565 
   2566     case EF_ARM_EABI_VER2:
   2567       strcat (buf, ", Version2 EABI");
   2568       while (e_flags)
   2569 	{
   2570 	  unsigned flag;
   2571 
   2572 	  /* Process flags one bit at a time.  */
   2573 	  flag = e_flags & - e_flags;
   2574 	  e_flags &= ~ flag;
   2575 
   2576 	  switch (flag)
   2577 	    {
   2578 	    case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK.  */
   2579 	      strcat (buf, ", sorted symbol tables");
   2580 	      break;
   2581 
   2582 	    case EF_ARM_DYNSYMSUSESEGIDX:
   2583 	      strcat (buf, ", dynamic symbols use segment index");
   2584 	      break;
   2585 
   2586 	    case EF_ARM_MAPSYMSFIRST:
   2587 	      strcat (buf, ", mapping symbols precede others");
   2588 	      break;
   2589 
   2590 	    default:
   2591 	      unknown = 1;
   2592 	      break;
   2593 	    }
   2594 	}
   2595       break;
   2596 
   2597     case EF_ARM_EABI_VER3:
   2598       strcat (buf, ", Version3 EABI");
   2599       break;
   2600 
   2601     case EF_ARM_EABI_VER4:
   2602       strcat (buf, ", Version4 EABI");
   2603       while (e_flags)
   2604 	{
   2605 	  unsigned flag;
   2606 
   2607 	  /* Process flags one bit at a time.  */
   2608 	  flag = e_flags & - e_flags;
   2609 	  e_flags &= ~ flag;
   2610 
   2611 	  switch (flag)
   2612 	    {
   2613 	    case EF_ARM_BE8:
   2614 	      strcat (buf, ", BE8");
   2615 	      break;
   2616 
   2617 	    case EF_ARM_LE8:
   2618 	      strcat (buf, ", LE8");
   2619 	      break;
   2620 
   2621 	    default:
   2622 	      unknown = 1;
   2623 	      break;
   2624 	    }
   2625       break;
   2626 	}
   2627       break;
   2628 
   2629     case EF_ARM_EABI_VER5:
   2630       strcat (buf, ", Version5 EABI");
   2631       while (e_flags)
   2632 	{
   2633 	  unsigned flag;
   2634 
   2635 	  /* Process flags one bit at a time.  */
   2636 	  flag = e_flags & - e_flags;
   2637 	  e_flags &= ~ flag;
   2638 
   2639 	  switch (flag)
   2640 	    {
   2641 	    case EF_ARM_BE8:
   2642 	      strcat (buf, ", BE8");
   2643 	      break;
   2644 
   2645 	    case EF_ARM_LE8:
   2646 	      strcat (buf, ", LE8");
   2647 	      break;
   2648 
   2649 	    case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT.  */
   2650 	      strcat (buf, ", soft-float ABI");
   2651 	      break;
   2652 
   2653 	    case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT.  */
   2654 	      strcat (buf, ", hard-float ABI");
   2655 	      break;
   2656 
   2657 	    default:
   2658 	      unknown = 1;
   2659 	      break;
   2660 	    }
   2661 	}
   2662       break;
   2663 
   2664     case EF_ARM_EABI_UNKNOWN:
   2665       strcat (buf, ", GNU EABI");
   2666       while (e_flags)
   2667 	{
   2668 	  unsigned flag;
   2669 
   2670 	  /* Process flags one bit at a time.  */
   2671 	  flag = e_flags & - e_flags;
   2672 	  e_flags &= ~ flag;
   2673 
   2674 	  switch (flag)
   2675 	    {
   2676 	    case EF_ARM_INTERWORK:
   2677 	      strcat (buf, ", interworking enabled");
   2678 	      break;
   2679 
   2680 	    case EF_ARM_APCS_26:
   2681 	      strcat (buf, ", uses APCS/26");
   2682 	      break;
   2683 
   2684 	    case EF_ARM_APCS_FLOAT:
   2685 	      strcat (buf, ", uses APCS/float");
   2686 	      break;
   2687 
   2688 	    case EF_ARM_PIC:
   2689 	      strcat (buf, ", position independent");
   2690 	      break;
   2691 
   2692 	    case EF_ARM_ALIGN8:
   2693 	      strcat (buf, ", 8 bit structure alignment");
   2694 	      break;
   2695 
   2696 	    case EF_ARM_NEW_ABI:
   2697 	      strcat (buf, ", uses new ABI");
   2698 	      break;
   2699 
   2700 	    case EF_ARM_OLD_ABI:
   2701 	      strcat (buf, ", uses old ABI");
   2702 	      break;
   2703 
   2704 	    case EF_ARM_SOFT_FLOAT:
   2705 	      strcat (buf, ", software FP");
   2706 	      break;
   2707 
   2708 	    case EF_ARM_VFP_FLOAT:
   2709 	      strcat (buf, ", VFP");
   2710 	      break;
   2711 
   2712 	    case EF_ARM_MAVERICK_FLOAT:
   2713 	      strcat (buf, ", Maverick FP");
   2714 	      break;
   2715 
   2716 	    default:
   2717 	      unknown = 1;
   2718 	      break;
   2719 	    }
   2720 	}
   2721     }
   2722 
   2723   if (unknown)
   2724     strcat (buf,_(", <unknown>"));
   2725 }
   2726 
   2727 static void
   2728 decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size)
   2729 {
   2730   --size; /* Leave space for null terminator.  */
   2731 
   2732   switch (e_flags & EF_AVR_MACH)
   2733     {
   2734     case E_AVR_MACH_AVR1:
   2735       strncat (buf, ", avr:1", size);
   2736       break;
   2737     case E_AVR_MACH_AVR2:
   2738       strncat (buf, ", avr:2", size);
   2739       break;
   2740     case E_AVR_MACH_AVR25:
   2741       strncat (buf, ", avr:25", size);
   2742       break;
   2743     case E_AVR_MACH_AVR3:
   2744       strncat (buf, ", avr:3", size);
   2745       break;
   2746     case E_AVR_MACH_AVR31:
   2747       strncat (buf, ", avr:31", size);
   2748       break;
   2749     case E_AVR_MACH_AVR35:
   2750       strncat (buf, ", avr:35", size);
   2751       break;
   2752     case E_AVR_MACH_AVR4:
   2753       strncat (buf, ", avr:4", size);
   2754       break;
   2755     case E_AVR_MACH_AVR5:
   2756       strncat (buf, ", avr:5", size);
   2757       break;
   2758     case E_AVR_MACH_AVR51:
   2759       strncat (buf, ", avr:51", size);
   2760       break;
   2761     case E_AVR_MACH_AVR6:
   2762       strncat (buf, ", avr:6", size);
   2763       break;
   2764     case E_AVR_MACH_AVRTINY:
   2765       strncat (buf, ", avr:100", size);
   2766       break;
   2767     case E_AVR_MACH_XMEGA1:
   2768       strncat (buf, ", avr:101", size);
   2769       break;
   2770     case E_AVR_MACH_XMEGA2:
   2771       strncat (buf, ", avr:102", size);
   2772       break;
   2773     case E_AVR_MACH_XMEGA3:
   2774       strncat (buf, ", avr:103", size);
   2775       break;
   2776     case E_AVR_MACH_XMEGA4:
   2777       strncat (buf, ", avr:104", size);
   2778       break;
   2779     case E_AVR_MACH_XMEGA5:
   2780       strncat (buf, ", avr:105", size);
   2781       break;
   2782     case E_AVR_MACH_XMEGA6:
   2783       strncat (buf, ", avr:106", size);
   2784       break;
   2785     case E_AVR_MACH_XMEGA7:
   2786       strncat (buf, ", avr:107", size);
   2787       break;
   2788     default:
   2789       strncat (buf, ", avr:<unknown>", size);
   2790       break;
   2791     }
   2792 
   2793   size -= strlen (buf);
   2794   if (e_flags & EF_AVR_LINKRELAX_PREPARED)
   2795     strncat (buf, ", link-relax", size);
   2796 }
   2797 
   2798 static void
   2799 decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
   2800 {
   2801   unsigned abi;
   2802   unsigned arch;
   2803   unsigned config;
   2804   unsigned version;
   2805   int has_fpu = 0;
   2806   int r = 0;
   2807 
   2808   static const char *ABI_STRINGS[] =
   2809   {
   2810     "ABI v0", /* use r5 as return register; only used in N1213HC */
   2811     "ABI v1", /* use r0 as return register */
   2812     "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
   2813     "ABI v2fp", /* for FPU */
   2814     "AABI",
   2815     "ABI2 FP+"
   2816   };
   2817   static const char *VER_STRINGS[] =
   2818   {
   2819     "Andes ELF V1.3 or older",
   2820     "Andes ELF V1.3.1",
   2821     "Andes ELF V1.4"
   2822   };
   2823   static const char *ARCH_STRINGS[] =
   2824   {
   2825     "",
   2826     "Andes Star v1.0",
   2827     "Andes Star v2.0",
   2828     "Andes Star v3.0",
   2829     "Andes Star v3.0m"
   2830   };
   2831 
   2832   abi = EF_NDS_ABI & e_flags;
   2833   arch = EF_NDS_ARCH & e_flags;
   2834   config = EF_NDS_INST & e_flags;
   2835   version = EF_NDS32_ELF_VERSION & e_flags;
   2836 
   2837   memset (buf, 0, size);
   2838 
   2839   switch (abi)
   2840     {
   2841     case E_NDS_ABI_V0:
   2842     case E_NDS_ABI_V1:
   2843     case E_NDS_ABI_V2:
   2844     case E_NDS_ABI_V2FP:
   2845     case E_NDS_ABI_AABI:
   2846     case E_NDS_ABI_V2FP_PLUS:
   2847       /* In case there are holes in the array.  */
   2848       r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
   2849       break;
   2850 
   2851     default:
   2852       r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
   2853       break;
   2854     }
   2855 
   2856   switch (version)
   2857     {
   2858     case E_NDS32_ELF_VER_1_2:
   2859     case E_NDS32_ELF_VER_1_3:
   2860     case E_NDS32_ELF_VER_1_4:
   2861       r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
   2862       break;
   2863 
   2864     default:
   2865       r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
   2866       break;
   2867     }
   2868 
   2869   if (E_NDS_ABI_V0 == abi)
   2870     {
   2871       /* OLD ABI; only used in N1213HC, has performance extension 1.  */
   2872       r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
   2873       if (arch == E_NDS_ARCH_STAR_V1_0)
   2874 	r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
   2875       return;
   2876     }
   2877 
   2878   switch (arch)
   2879     {
   2880     case E_NDS_ARCH_STAR_V1_0:
   2881     case E_NDS_ARCH_STAR_V2_0:
   2882     case E_NDS_ARCH_STAR_V3_0:
   2883     case E_NDS_ARCH_STAR_V3_M:
   2884       r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
   2885       break;
   2886 
   2887     default:
   2888       r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
   2889       /* ARCH version determines how the e_flags are interpreted.
   2890 	 If it is unknown, we cannot proceed.  */
   2891       return;
   2892     }
   2893 
   2894   /* Newer ABI; Now handle architecture specific flags.  */
   2895   if (arch == E_NDS_ARCH_STAR_V1_0)
   2896     {
   2897       if (config & E_NDS32_HAS_MFUSR_PC_INST)
   2898 	r += snprintf (buf + r, size -r, ", MFUSR_PC");
   2899 
   2900       if (!(config & E_NDS32_HAS_NO_MAC_INST))
   2901 	r += snprintf (buf + r, size -r, ", MAC");
   2902 
   2903       if (config & E_NDS32_HAS_DIV_INST)
   2904 	r += snprintf (buf + r, size -r, ", DIV");
   2905 
   2906       if (config & E_NDS32_HAS_16BIT_INST)
   2907 	r += snprintf (buf + r, size -r, ", 16b");
   2908     }
   2909   else
   2910     {
   2911       if (config & E_NDS32_HAS_MFUSR_PC_INST)
   2912 	{
   2913 	  if (version <= E_NDS32_ELF_VER_1_3)
   2914 	    r += snprintf (buf + r, size -r, ", [B8]");
   2915 	  else
   2916 	    r += snprintf (buf + r, size -r, ", EX9");
   2917 	}
   2918 
   2919       if (config & E_NDS32_HAS_MAC_DX_INST)
   2920 	r += snprintf (buf + r, size -r, ", MAC_DX");
   2921 
   2922       if (config & E_NDS32_HAS_DIV_DX_INST)
   2923 	r += snprintf (buf + r, size -r, ", DIV_DX");
   2924 
   2925       if (config & E_NDS32_HAS_16BIT_INST)
   2926 	{
   2927 	  if (version <= E_NDS32_ELF_VER_1_3)
   2928 	    r += snprintf (buf + r, size -r, ", 16b");
   2929 	  else
   2930 	    r += snprintf (buf + r, size -r, ", IFC");
   2931 	}
   2932     }
   2933 
   2934   if (config & E_NDS32_HAS_EXT_INST)
   2935     r += snprintf (buf + r, size -r, ", PERF1");
   2936 
   2937   if (config & E_NDS32_HAS_EXT2_INST)
   2938     r += snprintf (buf + r, size -r, ", PERF2");
   2939 
   2940   if (config & E_NDS32_HAS_FPU_INST)
   2941     {
   2942       has_fpu = 1;
   2943       r += snprintf (buf + r, size -r, ", FPU_SP");
   2944     }
   2945 
   2946   if (config & E_NDS32_HAS_FPU_DP_INST)
   2947     {
   2948       has_fpu = 1;
   2949       r += snprintf (buf + r, size -r, ", FPU_DP");
   2950     }
   2951 
   2952   if (config & E_NDS32_HAS_FPU_MAC_INST)
   2953     {
   2954       has_fpu = 1;
   2955       r += snprintf (buf + r, size -r, ", FPU_MAC");
   2956     }
   2957 
   2958   if (has_fpu)
   2959     {
   2960       switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
   2961 	{
   2962 	case E_NDS32_FPU_REG_8SP_4DP:
   2963 	  r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
   2964 	  break;
   2965 	case E_NDS32_FPU_REG_16SP_8DP:
   2966 	  r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
   2967 	  break;
   2968 	case E_NDS32_FPU_REG_32SP_16DP:
   2969 	  r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
   2970 	  break;
   2971 	case E_NDS32_FPU_REG_32SP_32DP:
   2972 	  r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
   2973 	  break;
   2974 	}
   2975     }
   2976 
   2977   if (config & E_NDS32_HAS_AUDIO_INST)
   2978     r += snprintf (buf + r, size -r, ", AUDIO");
   2979 
   2980   if (config & E_NDS32_HAS_STRING_INST)
   2981     r += snprintf (buf + r, size -r, ", STR");
   2982 
   2983   if (config & E_NDS32_HAS_REDUCED_REGS)
   2984     r += snprintf (buf + r, size -r, ", 16REG");
   2985 
   2986   if (config & E_NDS32_HAS_VIDEO_INST)
   2987     {
   2988       if (version <= E_NDS32_ELF_VER_1_3)
   2989 	r += snprintf (buf + r, size -r, ", VIDEO");
   2990       else
   2991 	r += snprintf (buf + r, size -r, ", SATURATION");
   2992     }
   2993 
   2994   if (config & E_NDS32_HAS_ENCRIPT_INST)
   2995     r += snprintf (buf + r, size -r, ", ENCRP");
   2996 
   2997   if (config & E_NDS32_HAS_L2C_INST)
   2998     r += snprintf (buf + r, size -r, ", L2C");
   2999 }
   3000 
   3001 static char *
   3002 get_machine_flags (unsigned e_flags, unsigned e_machine)
   3003 {
   3004   static char buf[1024];
   3005 
   3006   buf[0] = '\0';
   3007 
   3008   if (e_flags)
   3009     {
   3010       switch (e_machine)
   3011 	{
   3012 	default:
   3013 	  break;
   3014 
   3015 	case EM_ARC_COMPACT2:
   3016 	case EM_ARC_COMPACT:
   3017           decode_ARC_machine_flags (e_flags, e_machine, buf);
   3018           break;
   3019 
   3020 	case EM_ARM:
   3021 	  decode_ARM_machine_flags (e_flags, buf);
   3022 	  break;
   3023 
   3024         case EM_AVR:
   3025           decode_AVR_machine_flags (e_flags, buf, sizeof buf);
   3026           break;
   3027 
   3028 	case EM_BLACKFIN:
   3029 	  if (e_flags & EF_BFIN_PIC)
   3030 	    strcat (buf, ", PIC");
   3031 
   3032 	  if (e_flags & EF_BFIN_FDPIC)
   3033 	    strcat (buf, ", FDPIC");
   3034 
   3035 	  if (e_flags & EF_BFIN_CODE_IN_L1)
   3036 	    strcat (buf, ", code in L1");
   3037 
   3038 	  if (e_flags & EF_BFIN_DATA_IN_L1)
   3039 	    strcat (buf, ", data in L1");
   3040 
   3041 	  break;
   3042 
   3043 	case EM_CYGNUS_FRV:
   3044 	  switch (e_flags & EF_FRV_CPU_MASK)
   3045 	    {
   3046 	    case EF_FRV_CPU_GENERIC:
   3047 	      break;
   3048 
   3049 	    default:
   3050 	      strcat (buf, ", fr???");
   3051 	      break;
   3052 
   3053 	    case EF_FRV_CPU_FR300:
   3054 	      strcat (buf, ", fr300");
   3055 	      break;
   3056 
   3057 	    case EF_FRV_CPU_FR400:
   3058 	      strcat (buf, ", fr400");
   3059 	      break;
   3060 	    case EF_FRV_CPU_FR405:
   3061 	      strcat (buf, ", fr405");
   3062 	      break;
   3063 
   3064 	    case EF_FRV_CPU_FR450:
   3065 	      strcat (buf, ", fr450");
   3066 	      break;
   3067 
   3068 	    case EF_FRV_CPU_FR500:
   3069 	      strcat (buf, ", fr500");
   3070 	      break;
   3071 	    case EF_FRV_CPU_FR550:
   3072 	      strcat (buf, ", fr550");
   3073 	      break;
   3074 
   3075 	    case EF_FRV_CPU_SIMPLE:
   3076 	      strcat (buf, ", simple");
   3077 	      break;
   3078 	    case EF_FRV_CPU_TOMCAT:
   3079 	      strcat (buf, ", tomcat");
   3080 	      break;
   3081 	    }
   3082 	  break;
   3083 
   3084 	case EM_68K:
   3085 	  if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
   3086 	    strcat (buf, ", m68000");
   3087 	  else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
   3088 	    strcat (buf, ", cpu32");
   3089 	  else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
   3090 	    strcat (buf, ", fido_a");
   3091 	  else
   3092 	    {
   3093 	      char const * isa = _("unknown");
   3094 	      char const * mac = _("unknown mac");
   3095 	      char const * additional = NULL;
   3096 
   3097 	      switch (e_flags & EF_M68K_CF_ISA_MASK)
   3098 		{
   3099 		case EF_M68K_CF_ISA_A_NODIV:
   3100 		  isa = "A";
   3101 		  additional = ", nodiv";
   3102 		  break;
   3103 		case EF_M68K_CF_ISA_A:
   3104 		  isa = "A";
   3105 		  break;
   3106 		case EF_M68K_CF_ISA_A_PLUS:
   3107 		  isa = "A+";
   3108 		  break;
   3109 		case EF_M68K_CF_ISA_B_NOUSP:
   3110 		  isa = "B";
   3111 		  additional = ", nousp";
   3112 		  break;
   3113 		case EF_M68K_CF_ISA_B:
   3114 		  isa = "B";
   3115 		  break;
   3116 		case EF_M68K_CF_ISA_C:
   3117 		  isa = "C";
   3118 		  break;
   3119 		case EF_M68K_CF_ISA_C_NODIV:
   3120 		  isa = "C";
   3121 		  additional = ", nodiv";
   3122 		  break;
   3123 		}
   3124 	      strcat (buf, ", cf, isa ");
   3125 	      strcat (buf, isa);
   3126 	      if (additional)
   3127 		strcat (buf, additional);
   3128 	      if (e_flags & EF_M68K_CF_FLOAT)
   3129 		strcat (buf, ", float");
   3130 	      switch (e_flags & EF_M68K_CF_MAC_MASK)
   3131 		{
   3132 		case 0:
   3133 		  mac = NULL;
   3134 		  break;
   3135 		case EF_M68K_CF_MAC:
   3136 		  mac = "mac";
   3137 		  break;
   3138 		case EF_M68K_CF_EMAC:
   3139 		  mac = "emac";
   3140 		  break;
   3141 		case EF_M68K_CF_EMAC_B:
   3142 		  mac = "emac_b";
   3143 		  break;
   3144 		}
   3145 	      if (mac)
   3146 		{
   3147 		  strcat (buf, ", ");
   3148 		  strcat (buf, mac);
   3149 		}
   3150 	    }
   3151 	  break;
   3152 
   3153 	case EM_CYGNUS_MEP:
   3154 	  switch (e_flags & EF_MEP_CPU_MASK)
   3155 	    {
   3156 	    case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break;
   3157 	    case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break;
   3158 	    case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break;
   3159 	    case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break;
   3160 	    case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break;
   3161 	    case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break;
   3162 	    default: strcat (buf, _(", <unknown MeP cpu type>")); break;
   3163 	    }
   3164 
   3165 	  switch (e_flags & EF_MEP_COP_MASK)
   3166 	    {
   3167 	    case EF_MEP_COP_NONE: break;
   3168 	    case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break;
   3169 	    case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break;
   3170 	    case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break;
   3171 	    case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break;
   3172 	    default: strcat (buf, _("<unknown MeP copro type>")); break;
   3173 	    }
   3174 
   3175 	  if (e_flags & EF_MEP_LIBRARY)
   3176 	    strcat (buf, ", Built for Library");
   3177 
   3178 	  if (e_flags & EF_MEP_INDEX_MASK)
   3179 	    sprintf (buf + strlen (buf), ", Configuration Index: %#x",
   3180 		     e_flags & EF_MEP_INDEX_MASK);
   3181 
   3182 	  if (e_flags & ~ EF_MEP_ALL_FLAGS)
   3183 	    sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
   3184 		     e_flags & ~ EF_MEP_ALL_FLAGS);
   3185 	  break;
   3186 
   3187 	case EM_PPC:
   3188 	  if (e_flags & EF_PPC_EMB)
   3189 	    strcat (buf, ", emb");
   3190 
   3191 	  if (e_flags & EF_PPC_RELOCATABLE)
   3192 	    strcat (buf, _(", relocatable"));
   3193 
   3194 	  if (e_flags & EF_PPC_RELOCATABLE_LIB)
   3195 	    strcat (buf, _(", relocatable-lib"));
   3196 	  break;
   3197 
   3198 	case EM_PPC64:
   3199 	  if (e_flags & EF_PPC64_ABI)
   3200 	    {
   3201 	      char abi[] = ", abiv0";
   3202 
   3203 	      abi[6] += e_flags & EF_PPC64_ABI;
   3204 	      strcat (buf, abi);
   3205 	    }
   3206 	  break;
   3207 
   3208 	case EM_V800:
   3209 	  if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
   3210 	    strcat (buf, ", RH850 ABI");
   3211 
   3212 	  if (e_flags & EF_V800_850E3)
   3213 	    strcat (buf, ", V3 architecture");
   3214 
   3215 	  if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
   3216 	    strcat (buf, ", FPU not used");
   3217 
   3218 	  if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
   3219 	    strcat (buf, ", regmode: COMMON");
   3220 
   3221 	  if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
   3222 	    strcat (buf, ", r4 not used");
   3223 
   3224 	  if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
   3225 	    strcat (buf, ", r30 not used");
   3226 
   3227 	  if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
   3228 	    strcat (buf, ", r5 not used");
   3229 
   3230 	  if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
   3231 	    strcat (buf, ", r2 not used");
   3232 
   3233 	  for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
   3234 	    {
   3235 	      switch (e_flags & - e_flags)
   3236 		{
   3237 		case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
   3238 		case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
   3239 		case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
   3240 		case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
   3241 		case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
   3242 		case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
   3243 		case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
   3244 		case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
   3245 		case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
   3246 		case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
   3247 		case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
   3248 		case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
   3249 		default: break;
   3250 		}
   3251 	    }
   3252 	  break;
   3253 
   3254 	case EM_V850:
   3255 	case EM_CYGNUS_V850:
   3256 	  switch (e_flags & EF_V850_ARCH)
   3257 	    {
   3258 	    case E_V850E3V5_ARCH:
   3259 	      strcat (buf, ", v850e3v5");
   3260 	      break;
   3261 	    case E_V850E2V3_ARCH:
   3262 	      strcat (buf, ", v850e2v3");
   3263 	      break;
   3264 	    case E_V850E2_ARCH:
   3265 	      strcat (buf, ", v850e2");
   3266 	      break;
   3267             case E_V850E1_ARCH:
   3268               strcat (buf, ", v850e1");
   3269 	      break;
   3270 	    case E_V850E_ARCH:
   3271 	      strcat (buf, ", v850e");
   3272 	      break;
   3273 	    case E_V850_ARCH:
   3274 	      strcat (buf, ", v850");
   3275 	      break;
   3276 	    default:
   3277 	      strcat (buf, _(", unknown v850 architecture variant"));
   3278 	      break;
   3279 	    }
   3280 	  break;
   3281 
   3282 	case EM_M32R:
   3283 	case EM_CYGNUS_M32R:
   3284 	  if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
   3285 	    strcat (buf, ", m32r");
   3286 	  break;
   3287 
   3288 	case EM_MIPS:
   3289 	case EM_MIPS_RS3_LE:
   3290 	  if (e_flags & EF_MIPS_NOREORDER)
   3291 	    strcat (buf, ", noreorder");
   3292 
   3293 	  if (e_flags & EF_MIPS_PIC)
   3294 	    strcat (buf, ", pic");
   3295 
   3296 	  if (e_flags & EF_MIPS_CPIC)
   3297 	    strcat (buf, ", cpic");
   3298 
   3299 	  if (e_flags & EF_MIPS_UCODE)
   3300 	    strcat (buf, ", ugen_reserved");
   3301 
   3302 	  if (e_flags & EF_MIPS_ABI2)
   3303 	    strcat (buf, ", abi2");
   3304 
   3305 	  if (e_flags & EF_MIPS_OPTIONS_FIRST)
   3306 	    strcat (buf, ", odk first");
   3307 
   3308 	  if (e_flags & EF_MIPS_32BITMODE)
   3309 	    strcat (buf, ", 32bitmode");
   3310 
   3311 	  if (e_flags & EF_MIPS_NAN2008)
   3312 	    strcat (buf, ", nan2008");
   3313 
   3314 	  if (e_flags & EF_MIPS_FP64)
   3315 	    strcat (buf, ", fp64");
   3316 
   3317 	  switch ((e_flags & EF_MIPS_MACH))
   3318 	    {
   3319 	    case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
   3320 	    case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
   3321 	    case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
   3322 	    case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
   3323 	    case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
   3324 	    case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
   3325 	    case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
   3326 	    case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
   3327 	    case E_MIPS_MACH_SB1:  strcat (buf, ", sb1");  break;
   3328 	    case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
   3329   	    case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
   3330   	    case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
   3331   	    case E_MIPS_MACH_LS3A: strcat (buf, ", loongson-3a"); break;
   3332 	    case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
   3333 	    case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
   3334 	    case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
   3335 	    case E_MIPS_MACH_XLR:  strcat (buf, ", xlr"); break;
   3336 	    case 0:
   3337 	    /* We simply ignore the field in this case to avoid confusion:
   3338 	       MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
   3339 	       extension.  */
   3340 	      break;
   3341 	    default: strcat (buf, _(", unknown CPU")); break;
   3342 	    }
   3343 
   3344 	  switch ((e_flags & EF_MIPS_ABI))
   3345 	    {
   3346 	    case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
   3347 	    case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
   3348 	    case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
   3349 	    case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
   3350 	    case 0:
   3351 	    /* We simply ignore the field in this case to avoid confusion:
   3352 	       MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
   3353 	       This means it is likely to be an o32 file, but not for
   3354 	       sure.  */
   3355 	      break;
   3356 	    default: strcat (buf, _(", unknown ABI")); break;
   3357 	    }
   3358 
   3359 	  if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
   3360 	    strcat (buf, ", mdmx");
   3361 
   3362 	  if (e_flags & EF_MIPS_ARCH_ASE_M16)
   3363 	    strcat (buf, ", mips16");
   3364 
   3365 	  if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
   3366 	    strcat (buf, ", micromips");
   3367 
   3368 	  switch ((e_flags & EF_MIPS_ARCH))
   3369 	    {
   3370 	    case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
   3371 	    case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
   3372 	    case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
   3373 	    case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
   3374 	    case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
   3375 	    case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
   3376 	    case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
   3377 	    case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
   3378 	    case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
   3379 	    case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
   3380 	    case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
   3381 	    default: strcat (buf, _(", unknown ISA")); break;
   3382 	    }
   3383 	  break;
   3384 
   3385 	case EM_NDS32:
   3386 	  decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
   3387 	  break;
   3388 
   3389 	case EM_SH:
   3390 	  switch ((e_flags & EF_SH_MACH_MASK))
   3391 	    {
   3392 	    case EF_SH1: strcat (buf, ", sh1"); break;
   3393 	    case EF_SH2: strcat (buf, ", sh2"); break;
   3394 	    case EF_SH3: strcat (buf, ", sh3"); break;
   3395 	    case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
   3396 	    case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
   3397 	    case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
   3398 	    case EF_SH3E: strcat (buf, ", sh3e"); break;
   3399 	    case EF_SH4: strcat (buf, ", sh4"); break;
   3400 	    case EF_SH5: strcat (buf, ", sh5"); break;
   3401 	    case EF_SH2E: strcat (buf, ", sh2e"); break;
   3402 	    case EF_SH4A: strcat (buf, ", sh4a"); break;
   3403 	    case EF_SH2A: strcat (buf, ", sh2a"); break;
   3404 	    case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
   3405 	    case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
   3406 	    case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
   3407 	    case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
   3408 	    case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
   3409 	    case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
   3410 	    case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
   3411 	    case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
   3412 	    case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
   3413 	    default: strcat (buf, _(", unknown ISA")); break;
   3414 	    }
   3415 
   3416 	  if (e_flags & EF_SH_PIC)
   3417 	    strcat (buf, ", pic");
   3418 
   3419 	  if (e_flags & EF_SH_FDPIC)
   3420 	    strcat (buf, ", fdpic");
   3421 	  break;
   3422 
   3423         case EM_OR1K:
   3424           if (e_flags & EF_OR1K_NODELAY)
   3425             strcat (buf, ", no delay");
   3426           break;
   3427 
   3428 	case EM_SPARCV9:
   3429 	  if (e_flags & EF_SPARC_32PLUS)
   3430 	    strcat (buf, ", v8+");
   3431 
   3432 	  if (e_flags & EF_SPARC_SUN_US1)
   3433 	    strcat (buf, ", ultrasparcI");
   3434 
   3435 	  if (e_flags & EF_SPARC_SUN_US3)
   3436 	    strcat (buf, ", ultrasparcIII");
   3437 
   3438 	  if (e_flags & EF_SPARC_HAL_R1)
   3439 	    strcat (buf, ", halr1");
   3440 
   3441 	  if (e_flags & EF_SPARC_LEDATA)
   3442 	    strcat (buf, ", ledata");
   3443 
   3444 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
   3445 	    strcat (buf, ", tso");
   3446 
   3447 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
   3448 	    strcat (buf, ", pso");
   3449 
   3450 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
   3451 	    strcat (buf, ", rmo");
   3452 	  break;
   3453 
   3454 	case EM_PARISC:
   3455 	  switch (e_flags & EF_PARISC_ARCH)
   3456 	    {
   3457 	    case EFA_PARISC_1_0:
   3458 	      strcpy (buf, ", PA-RISC 1.0");
   3459 	      break;
   3460 	    case EFA_PARISC_1_1:
   3461 	      strcpy (buf, ", PA-RISC 1.1");
   3462 	      break;
   3463 	    case EFA_PARISC_2_0:
   3464 	      strcpy (buf, ", PA-RISC 2.0");
   3465 	      break;
   3466 	    default:
   3467 	      break;
   3468 	    }
   3469 	  if (e_flags & EF_PARISC_TRAPNIL)
   3470 	    strcat (buf, ", trapnil");
   3471 	  if (e_flags & EF_PARISC_EXT)
   3472 	    strcat (buf, ", ext");
   3473 	  if (e_flags & EF_PARISC_LSB)
   3474 	    strcat (buf, ", lsb");
   3475 	  if (e_flags & EF_PARISC_WIDE)
   3476 	    strcat (buf, ", wide");
   3477 	  if (e_flags & EF_PARISC_NO_KABP)
   3478 	    strcat (buf, ", no kabp");
   3479 	  if (e_flags & EF_PARISC_LAZYSWAP)
   3480 	    strcat (buf, ", lazyswap");
   3481 	  break;
   3482 
   3483 	case EM_PJ:
   3484 	case EM_PJ_OLD:
   3485 	  if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
   3486 	    strcat (buf, ", new calling convention");
   3487 
   3488 	  if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
   3489 	    strcat (buf, ", gnu calling convention");
   3490 	  break;
   3491 
   3492 	case EM_IA_64:
   3493 	  if ((e_flags & EF_IA_64_ABI64))
   3494 	    strcat (buf, ", 64-bit");
   3495 	  else
   3496 	    strcat (buf, ", 32-bit");
   3497 	  if ((e_flags & EF_IA_64_REDUCEDFP))
   3498 	    strcat (buf, ", reduced fp model");
   3499 	  if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
   3500 	    strcat (buf, ", no function descriptors, constant gp");
   3501 	  else if ((e_flags & EF_IA_64_CONS_GP))
   3502 	    strcat (buf, ", constant gp");
   3503 	  if ((e_flags & EF_IA_64_ABSOLUTE))
   3504 	    strcat (buf, ", absolute");
   3505           if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
   3506             {
   3507               if ((e_flags & EF_IA_64_VMS_LINKAGES))
   3508                 strcat (buf, ", vms_linkages");
   3509               switch ((e_flags & EF_IA_64_VMS_COMCOD))
   3510                 {
   3511                 case EF_IA_64_VMS_COMCOD_SUCCESS:
   3512                   break;
   3513                 case EF_IA_64_VMS_COMCOD_WARNING:
   3514                   strcat (buf, ", warning");
   3515                   break;
   3516                 case EF_IA_64_VMS_COMCOD_ERROR:
   3517                   strcat (buf, ", error");
   3518                   break;
   3519                 case EF_IA_64_VMS_COMCOD_ABORT:
   3520                   strcat (buf, ", abort");
   3521                   break;
   3522                 default:
   3523 		  warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
   3524 			e_flags & EF_IA_64_VMS_COMCOD);
   3525 		  strcat (buf, ", <unknown>");
   3526                 }
   3527             }
   3528 	  break;
   3529 
   3530 	case EM_VAX:
   3531 	  if ((e_flags & EF_VAX_NONPIC))
   3532 	    strcat (buf, ", non-PIC");
   3533 	  if ((e_flags & EF_VAX_DFLOAT))
   3534 	    strcat (buf, ", D-Float");
   3535 	  if ((e_flags & EF_VAX_GFLOAT))
   3536 	    strcat (buf, ", G-Float");
   3537 	  break;
   3538 
   3539         case EM_VISIUM:
   3540 	  if (e_flags & EF_VISIUM_ARCH_MCM)
   3541 	    strcat (buf, ", mcm");
   3542 	  else if (e_flags & EF_VISIUM_ARCH_MCM24)
   3543 	    strcat (buf, ", mcm24");
   3544 	  if (e_flags & EF_VISIUM_ARCH_GR6)
   3545 	    strcat (buf, ", gr6");
   3546 	  break;
   3547 
   3548 	case EM_RL78:
   3549 	  switch (e_flags & E_FLAG_RL78_CPU_MASK)
   3550 	    {
   3551 	    case E_FLAG_RL78_ANY_CPU: break;
   3552 	    case E_FLAG_RL78_G10: strcat (buf, ", G10"); break;
   3553 	    case E_FLAG_RL78_G13: strcat (buf, ", G13"); break;
   3554 	    case E_FLAG_RL78_G14: strcat (buf, ", G14"); break;
   3555 	    }
   3556 	  if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
   3557 	    strcat (buf, ", 64-bit doubles");
   3558 	  break;
   3559 
   3560 	case EM_RX:
   3561 	  if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
   3562 	    strcat (buf, ", 64-bit doubles");
   3563 	  if (e_flags & E_FLAG_RX_DSP)
   3564 	    strcat (buf, ", dsp");
   3565 	  if (e_flags & E_FLAG_RX_PID)
   3566 	    strcat (buf, ", pid");
   3567 	  if (e_flags & E_FLAG_RX_ABI)
   3568 	    strcat (buf, ", RX ABI");
   3569 	  if (e_flags & E_FLAG_RX_SINSNS_SET)
   3570 	    strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES
   3571 		    ? ", uses String instructions" : ", bans String instructions");
   3572 	  if (e_flags & E_FLAG_RX_V2)
   3573 	    strcat (buf, ", V2");
   3574 	  break;
   3575 
   3576 	case EM_S390:
   3577 	  if (e_flags & EF_S390_HIGH_GPRS)
   3578 	    strcat (buf, ", highgprs");
   3579 	  break;
   3580 
   3581 	case EM_TI_C6000:
   3582 	  if ((e_flags & EF_C6000_REL))
   3583 	    strcat (buf, ", relocatable module");
   3584 	  break;
   3585 
   3586 	case EM_MSP430:
   3587 	  strcat (buf, _(": architecture variant: "));
   3588 	  switch (e_flags & EF_MSP430_MACH)
   3589 	    {
   3590 	    case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
   3591 	    case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
   3592 	    case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
   3593 	    case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
   3594 	    case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
   3595 	    case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
   3596 	    case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
   3597 	    case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
   3598 	    case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
   3599 	    case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
   3600 	    case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
   3601 	    case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
   3602 	    case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
   3603 	    case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
   3604 	    case E_MSP430_MACH_MSP430X  : strcat (buf, "MSP430X"); break;
   3605 	    default:
   3606 	      strcat (buf, _(": unknown")); break;
   3607 	    }
   3608 
   3609 	  if (e_flags & ~ EF_MSP430_MACH)
   3610 	    strcat (buf, _(": unknown extra flag bits also present"));
   3611 	}
   3612     }
   3613 
   3614   return buf;
   3615 }
   3616 
   3617 static const char *
   3618 get_osabi_name (unsigned int osabi)
   3619 {
   3620   static char buff[32];
   3621 
   3622   switch (osabi)
   3623     {
   3624     case ELFOSABI_NONE:		return "UNIX - System V";
   3625     case ELFOSABI_HPUX:		return "UNIX - HP-UX";
   3626     case ELFOSABI_NETBSD:	return "UNIX - NetBSD";
   3627     case ELFOSABI_GNU:		return "UNIX - GNU";
   3628     case ELFOSABI_SOLARIS:	return "UNIX - Solaris";
   3629     case ELFOSABI_AIX:		return "UNIX - AIX";
   3630     case ELFOSABI_IRIX:		return "UNIX - IRIX";
   3631     case ELFOSABI_FREEBSD:	return "UNIX - FreeBSD";
   3632     case ELFOSABI_TRU64:	return "UNIX - TRU64";
   3633     case ELFOSABI_MODESTO:	return "Novell - Modesto";
   3634     case ELFOSABI_OPENBSD:	return "UNIX - OpenBSD";
   3635     case ELFOSABI_OPENVMS:	return "VMS - OpenVMS";
   3636     case ELFOSABI_NSK:		return "HP - Non-Stop Kernel";
   3637     case ELFOSABI_AROS:		return "AROS";
   3638     case ELFOSABI_FENIXOS:	return "FenixOS";
   3639     default:
   3640       if (osabi >= 64)
   3641 	switch (elf_header.e_machine)
   3642 	  {
   3643 	  case EM_ARM:
   3644 	    switch (osabi)
   3645 	      {
   3646 	      case ELFOSABI_ARM:	return "ARM";
   3647 	      default:
   3648 		break;
   3649 	      }
   3650 	    break;
   3651 
   3652 	  case EM_MSP430:
   3653 	  case EM_MSP430_OLD:
   3654 	  case EM_VISIUM:
   3655 	    switch (osabi)
   3656 	      {
   3657 	      case ELFOSABI_STANDALONE:	return _("Standalone App");
   3658 	      default:
   3659 		break;
   3660 	      }
   3661 	    break;
   3662 
   3663 	  case EM_TI_C6000:
   3664 	    switch (osabi)
   3665 	      {
   3666 	      case ELFOSABI_C6000_ELFABI:	return _("Bare-metal C6000");
   3667 	      case ELFOSABI_C6000_LINUX:	return "Linux C6000";
   3668 	      default:
   3669 		break;
   3670 	      }
   3671 	    break;
   3672 
   3673 	  default:
   3674 	    break;
   3675 	  }
   3676       snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
   3677       return buff;
   3678     }
   3679 }
   3680 
   3681 static const char *
   3682 get_aarch64_segment_type (unsigned long type)
   3683 {
   3684   switch (type)
   3685     {
   3686     case PT_AARCH64_ARCHEXT:
   3687       return "AARCH64_ARCHEXT";
   3688     default:
   3689       break;
   3690     }
   3691 
   3692   return NULL;
   3693 }
   3694 
   3695 static const char *
   3696 get_arm_segment_type (unsigned long type)
   3697 {
   3698   switch (type)
   3699     {
   3700     case PT_ARM_EXIDX:
   3701       return "EXIDX";
   3702     default:
   3703       break;
   3704     }
   3705 
   3706   return NULL;
   3707 }
   3708 
   3709 static const char *
   3710 get_mips_segment_type (unsigned long type)
   3711 {
   3712   switch (type)
   3713     {
   3714     case PT_MIPS_REGINFO:
   3715       return "REGINFO";
   3716     case PT_MIPS_RTPROC:
   3717       return "RTPROC";
   3718     case PT_MIPS_OPTIONS:
   3719       return "OPTIONS";
   3720     case PT_MIPS_ABIFLAGS:
   3721       return "ABIFLAGS";
   3722     default:
   3723       break;
   3724     }
   3725 
   3726   return NULL;
   3727 }
   3728 
   3729 static const char *
   3730 get_parisc_segment_type (unsigned long type)
   3731 {
   3732   switch (type)
   3733     {
   3734     case PT_HP_TLS:		return "HP_TLS";
   3735     case PT_HP_CORE_NONE:	return "HP_CORE_NONE";
   3736     case PT_HP_CORE_VERSION:	return "HP_CORE_VERSION";
   3737     case PT_HP_CORE_KERNEL:	return "HP_CORE_KERNEL";
   3738     case PT_HP_CORE_COMM:	return "HP_CORE_COMM";
   3739     case PT_HP_CORE_PROC:	return "HP_CORE_PROC";
   3740     case PT_HP_CORE_LOADABLE:	return "HP_CORE_LOADABLE";
   3741     case PT_HP_CORE_STACK:	return "HP_CORE_STACK";
   3742     case PT_HP_CORE_SHM:	return "HP_CORE_SHM";
   3743     case PT_HP_CORE_MMF:	return "HP_CORE_MMF";
   3744     case PT_HP_PARALLEL:	return "HP_PARALLEL";
   3745     case PT_HP_FASTBIND:	return "HP_FASTBIND";
   3746     case PT_HP_OPT_ANNOT:	return "HP_OPT_ANNOT";
   3747     case PT_HP_HSL_ANNOT:	return "HP_HSL_ANNOT";
   3748     case PT_HP_STACK:		return "HP_STACK";
   3749     case PT_HP_CORE_UTSNAME:	return "HP_CORE_UTSNAME";
   3750     case PT_PARISC_ARCHEXT:	return "PARISC_ARCHEXT";
   3751     case PT_PARISC_UNWIND:	return "PARISC_UNWIND";
   3752     case PT_PARISC_WEAKORDER:	return "PARISC_WEAKORDER";
   3753     default:
   3754       break;
   3755     }
   3756 
   3757   return NULL;
   3758 }
   3759 
   3760 static const char *
   3761 get_ia64_segment_type (unsigned long type)
   3762 {
   3763   switch (type)
   3764     {
   3765     case PT_IA_64_ARCHEXT:	return "IA_64_ARCHEXT";
   3766     case PT_IA_64_UNWIND:	return "IA_64_UNWIND";
   3767     case PT_HP_TLS:		return "HP_TLS";
   3768     case PT_IA_64_HP_OPT_ANOT:	return "HP_OPT_ANNOT";
   3769     case PT_IA_64_HP_HSL_ANOT:	return "HP_HSL_ANNOT";
   3770     case PT_IA_64_HP_STACK:	return "HP_STACK";
   3771     default:
   3772       break;
   3773     }
   3774 
   3775   return NULL;
   3776 }
   3777 
   3778 static const char *
   3779 get_tic6x_segment_type (unsigned long type)
   3780 {
   3781   switch (type)
   3782     {
   3783     case PT_C6000_PHATTR:	return "C6000_PHATTR";
   3784     default:
   3785       break;
   3786     }
   3787 
   3788   return NULL;
   3789 }
   3790 
   3791 static const char *
   3792 get_solaris_segment_type (unsigned long type)
   3793 {
   3794   switch (type)
   3795     {
   3796     case 0x6464e550: return "PT_SUNW_UNWIND";
   3797     case 0x6474e550: return "PT_SUNW_EH_FRAME";
   3798     case 0x6ffffff7: return "PT_LOSUNW";
   3799     case 0x6ffffffa: return "PT_SUNWBSS";
   3800     case 0x6ffffffb: return "PT_SUNWSTACK";
   3801     case 0x6ffffffc: return "PT_SUNWDTRACE";
   3802     case 0x6ffffffd: return "PT_SUNWCAP";
   3803     case 0x6fffffff: return "PT_HISUNW";
   3804     default: return NULL;
   3805     }
   3806 }
   3807 
   3808 static const char *
   3809 get_segment_type (unsigned long p_type)
   3810 {
   3811   static char buff[32];
   3812 
   3813   switch (p_type)
   3814     {
   3815     case PT_NULL:	return "NULL";
   3816     case PT_LOAD:	return "LOAD";
   3817     case PT_DYNAMIC:	return "DYNAMIC";
   3818     case PT_INTERP:	return "INTERP";
   3819     case PT_NOTE:	return "NOTE";
   3820     case PT_SHLIB:	return "SHLIB";
   3821     case PT_PHDR:	return "PHDR";
   3822     case PT_TLS:	return "TLS";
   3823 
   3824     case PT_GNU_EH_FRAME:
   3825 			return "GNU_EH_FRAME";
   3826     case PT_GNU_STACK:	return "GNU_STACK";
   3827     case PT_GNU_RELRO:  return "GNU_RELRO";
   3828 
   3829     default:
   3830       if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
   3831 	{
   3832 	  const char * result;
   3833 
   3834 	  switch (elf_header.e_machine)
   3835 	    {
   3836 	    case EM_AARCH64:
   3837 	      result = get_aarch64_segment_type (p_type);
   3838 	      break;
   3839 	    case EM_ARM:
   3840 	      result = get_arm_segment_type (p_type);
   3841 	      break;
   3842 	    case EM_MIPS:
   3843 	    case EM_MIPS_RS3_LE:
   3844 	      result = get_mips_segment_type (p_type);
   3845 	      break;
   3846 	    case EM_PARISC:
   3847 	      result = get_parisc_segment_type (p_type);
   3848 	      break;
   3849 	    case EM_IA_64:
   3850 	      result = get_ia64_segment_type (p_type);
   3851 	      break;
   3852 	    case EM_TI_C6000:
   3853 	      result = get_tic6x_segment_type (p_type);
   3854 	      break;
   3855 	    default:
   3856 	      result = NULL;
   3857 	      break;
   3858 	    }
   3859 
   3860 	  if (result != NULL)
   3861 	    return result;
   3862 
   3863 	  sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
   3864 	}
   3865       else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
   3866 	{
   3867 	  const char * result;
   3868 
   3869 	  switch (elf_header.e_machine)
   3870 	    {
   3871 	    case EM_PARISC:
   3872 	      result = get_parisc_segment_type (p_type);
   3873 	      break;
   3874 	    case EM_IA_64:
   3875 	      result = get_ia64_segment_type (p_type);
   3876 	      break;
   3877 	    default:
   3878 	      if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
   3879 		result = get_solaris_segment_type (p_type);
   3880 	      else
   3881 		result = NULL;
   3882 	      break;
   3883 	    }
   3884 
   3885 	  if (result != NULL)
   3886 	    return result;
   3887 
   3888 	  sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
   3889 	}
   3890       else
   3891 	snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
   3892 
   3893       return buff;
   3894     }
   3895 }
   3896 
   3897 static const char *
   3898 get_mips_section_type_name (unsigned int sh_type)
   3899 {
   3900   switch (sh_type)
   3901     {
   3902     case SHT_MIPS_LIBLIST:	 return "MIPS_LIBLIST";
   3903     case SHT_MIPS_MSYM:		 return "MIPS_MSYM";
   3904     case SHT_MIPS_CONFLICT:	 return "MIPS_CONFLICT";
   3905     case SHT_MIPS_GPTAB:	 return "MIPS_GPTAB";
   3906     case SHT_MIPS_UCODE:	 return "MIPS_UCODE";
   3907     case SHT_MIPS_DEBUG:	 return "MIPS_DEBUG";
   3908     case SHT_MIPS_REGINFO:	 return "MIPS_REGINFO";
   3909     case SHT_MIPS_PACKAGE:	 return "MIPS_PACKAGE";
   3910     case SHT_MIPS_PACKSYM:	 return "MIPS_PACKSYM";
   3911     case SHT_MIPS_RELD:		 return "MIPS_RELD";
   3912     case SHT_MIPS_IFACE:	 return "MIPS_IFACE";
   3913     case SHT_MIPS_CONTENT:	 return "MIPS_CONTENT";
   3914     case SHT_MIPS_OPTIONS:	 return "MIPS_OPTIONS";
   3915     case SHT_MIPS_SHDR:		 return "MIPS_SHDR";
   3916     case SHT_MIPS_FDESC:	 return "MIPS_FDESC";
   3917     case SHT_MIPS_EXTSYM:	 return "MIPS_EXTSYM";
   3918     case SHT_MIPS_DENSE:	 return "MIPS_DENSE";
   3919     case SHT_MIPS_PDESC:	 return "MIPS_PDESC";
   3920     case SHT_MIPS_LOCSYM:	 return "MIPS_LOCSYM";
   3921     case SHT_MIPS_AUXSYM:	 return "MIPS_AUXSYM";
   3922     case SHT_MIPS_OPTSYM:	 return "MIPS_OPTSYM";
   3923     case SHT_MIPS_LOCSTR:	 return "MIPS_LOCSTR";
   3924     case SHT_MIPS_LINE:		 return "MIPS_LINE";
   3925     case SHT_MIPS_RFDESC:	 return "MIPS_RFDESC";
   3926     case SHT_MIPS_DELTASYM:	 return "MIPS_DELTASYM";
   3927     case SHT_MIPS_DELTAINST:	 return "MIPS_DELTAINST";
   3928     case SHT_MIPS_DELTACLASS:	 return "MIPS_DELTACLASS";
   3929     case SHT_MIPS_DWARF:	 return "MIPS_DWARF";
   3930     case SHT_MIPS_DELTADECL:	 return "MIPS_DELTADECL";
   3931     case SHT_MIPS_SYMBOL_LIB:	 return "MIPS_SYMBOL_LIB";
   3932     case SHT_MIPS_EVENTS:	 return "MIPS_EVENTS";
   3933     case SHT_MIPS_TRANSLATE:	 return "MIPS_TRANSLATE";
   3934     case SHT_MIPS_PIXIE:	 return "MIPS_PIXIE";
   3935     case SHT_MIPS_XLATE:	 return "MIPS_XLATE";
   3936     case SHT_MIPS_XLATE_DEBUG:	 return "MIPS_XLATE_DEBUG";
   3937     case SHT_MIPS_WHIRL:	 return "MIPS_WHIRL";
   3938     case SHT_MIPS_EH_REGION:	 return "MIPS_EH_REGION";
   3939     case SHT_MIPS_XLATE_OLD:	 return "MIPS_XLATE_OLD";
   3940     case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
   3941     case SHT_MIPS_ABIFLAGS:	 return "MIPS_ABIFLAGS";
   3942     default:
   3943       break;
   3944     }
   3945   return NULL;
   3946 }
   3947 
   3948 static const char *
   3949 get_parisc_section_type_name (unsigned int sh_type)
   3950 {
   3951   switch (sh_type)
   3952     {
   3953     case SHT_PARISC_EXT:	return "PARISC_EXT";
   3954     case SHT_PARISC_UNWIND:	return "PARISC_UNWIND";
   3955     case SHT_PARISC_DOC:	return "PARISC_DOC";
   3956     case SHT_PARISC_ANNOT:	return "PARISC_ANNOT";
   3957     case SHT_PARISC_SYMEXTN:	return "PARISC_SYMEXTN";
   3958     case SHT_PARISC_STUBS:	return "PARISC_STUBS";
   3959     case SHT_PARISC_DLKM:	return "PARISC_DLKM";
   3960     default:
   3961       break;
   3962     }
   3963   return NULL;
   3964 }
   3965 
   3966 static const char *
   3967 get_ia64_section_type_name (unsigned int sh_type)
   3968 {
   3969   /* If the top 8 bits are 0x78 the next 8 are the os/abi ID.  */
   3970   if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
   3971     return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
   3972 
   3973   switch (sh_type)
   3974     {
   3975     case SHT_IA_64_EXT:		       return "IA_64_EXT";
   3976     case SHT_IA_64_UNWIND:	       return "IA_64_UNWIND";
   3977     case SHT_IA_64_PRIORITY_INIT:      return "IA_64_PRIORITY_INIT";
   3978     case SHT_IA_64_VMS_TRACE:          return "VMS_TRACE";
   3979     case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
   3980     case SHT_IA_64_VMS_DEBUG:          return "VMS_DEBUG";
   3981     case SHT_IA_64_VMS_DEBUG_STR:      return "VMS_DEBUG_STR";
   3982     case SHT_IA_64_VMS_LINKAGES:       return "VMS_LINKAGES";
   3983     case SHT_IA_64_VMS_SYMBOL_VECTOR:  return "VMS_SYMBOL_VECTOR";
   3984     case SHT_IA_64_VMS_FIXUP:          return "VMS_FIXUP";
   3985     default:
   3986       break;
   3987     }
   3988   return NULL;
   3989 }
   3990 
   3991 static const char *
   3992 get_x86_64_section_type_name (unsigned int sh_type)
   3993 {
   3994   switch (sh_type)
   3995     {
   3996     case SHT_X86_64_UNWIND:	return "X86_64_UNWIND";
   3997     default:
   3998       break;
   3999     }
   4000   return NULL;
   4001 }
   4002 
   4003 static const char *
   4004 get_aarch64_section_type_name (unsigned int sh_type)
   4005 {
   4006   switch (sh_type)
   4007     {
   4008     case SHT_AARCH64_ATTRIBUTES:
   4009       return "AARCH64_ATTRIBUTES";
   4010     default:
   4011       break;
   4012     }
   4013   return NULL;
   4014 }
   4015 
   4016 static const char *
   4017 get_arm_section_type_name (unsigned int sh_type)
   4018 {
   4019   switch (sh_type)
   4020     {
   4021     case SHT_ARM_EXIDX:           return "ARM_EXIDX";
   4022     case SHT_ARM_PREEMPTMAP:      return "ARM_PREEMPTMAP";
   4023     case SHT_ARM_ATTRIBUTES:      return "ARM_ATTRIBUTES";
   4024     case SHT_ARM_DEBUGOVERLAY:    return "ARM_DEBUGOVERLAY";
   4025     case SHT_ARM_OVERLAYSECTION:  return "ARM_OVERLAYSECTION";
   4026     default:
   4027       break;
   4028     }
   4029   return NULL;
   4030 }
   4031 
   4032 static const char *
   4033 get_tic6x_section_type_name (unsigned int sh_type)
   4034 {
   4035   switch (sh_type)
   4036     {
   4037     case SHT_C6000_UNWIND:
   4038       return "C6000_UNWIND";
   4039     case SHT_C6000_PREEMPTMAP:
   4040       return "C6000_PREEMPTMAP";
   4041     case SHT_C6000_ATTRIBUTES:
   4042       return "C6000_ATTRIBUTES";
   4043     case SHT_TI_ICODE:
   4044       return "TI_ICODE";
   4045     case SHT_TI_XREF:
   4046       return "TI_XREF";
   4047     case SHT_TI_HANDLER:
   4048       return "TI_HANDLER";
   4049     case SHT_TI_INITINFO:
   4050       return "TI_INITINFO";
   4051     case SHT_TI_PHATTRS:
   4052       return "TI_PHATTRS";
   4053     default:
   4054       break;
   4055     }
   4056   return NULL;
   4057 }
   4058 
   4059 static const char *
   4060 get_msp430x_section_type_name (unsigned int sh_type)
   4061 {
   4062   switch (sh_type)
   4063     {
   4064     case SHT_MSP430_SEC_FLAGS:   return "MSP430_SEC_FLAGS";
   4065     case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
   4066     case SHT_MSP430_ATTRIBUTES:  return "MSP430_ATTRIBUTES";
   4067     default: return NULL;
   4068     }
   4069 }
   4070 
   4071 static const char *
   4072 get_v850_section_type_name (unsigned int sh_type)
   4073 {
   4074   switch (sh_type)
   4075     {
   4076     case SHT_V850_SCOMMON: return "V850 Small Common";
   4077     case SHT_V850_TCOMMON: return "V850 Tiny Common";
   4078     case SHT_V850_ZCOMMON: return "V850 Zero Common";
   4079     case SHT_RENESAS_IOP:  return "RENESAS IOP";
   4080     case SHT_RENESAS_INFO: return "RENESAS INFO";
   4081     default: return NULL;
   4082     }
   4083 }
   4084 
   4085 static const char *
   4086 get_section_type_name (unsigned int sh_type)
   4087 {
   4088   static char buff[32];
   4089   const char * result;
   4090 
   4091   switch (sh_type)
   4092     {
   4093     case SHT_NULL:		return "NULL";
   4094     case SHT_PROGBITS:		return "PROGBITS";
   4095     case SHT_SYMTAB:		return "SYMTAB";
   4096     case SHT_STRTAB:		return "STRTAB";
   4097     case SHT_RELA:		return "RELA";
   4098     case SHT_RELR:		return "RELR";
   4099     case SHT_HASH:		return "HASH";
   4100     case SHT_DYNAMIC:		return "DYNAMIC";
   4101     case SHT_NOTE:		return "NOTE";
   4102     case SHT_NOBITS:		return "NOBITS";
   4103     case SHT_REL:		return "REL";
   4104     case SHT_SHLIB:		return "SHLIB";
   4105     case SHT_DYNSYM:		return "DYNSYM";
   4106     case SHT_INIT_ARRAY:	return "INIT_ARRAY";
   4107     case SHT_FINI_ARRAY:	return "FINI_ARRAY";
   4108     case SHT_PREINIT_ARRAY:	return "PREINIT_ARRAY";
   4109     case SHT_GNU_HASH:		return "GNU_HASH";
   4110     case SHT_GROUP:		return "GROUP";
   4111     case SHT_SYMTAB_SHNDX:	return "SYMTAB SECTION INDICIES";
   4112     case SHT_GNU_verdef:	return "VERDEF";
   4113     case SHT_GNU_verneed:	return "VERNEED";
   4114     case SHT_GNU_versym:	return "VERSYM";
   4115     case 0x6ffffff0:		return "VERSYM";
   4116     case 0x6ffffffc:		return "VERDEF";
   4117     case 0x7ffffffd:		return "AUXILIARY";
   4118     case 0x7fffffff:		return "FILTER";
   4119     case SHT_GNU_LIBLIST:	return "GNU_LIBLIST";
   4120 
   4121     default:
   4122       if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
   4123 	{
   4124 	  switch (elf_header.e_machine)
   4125 	    {
   4126 	    case EM_MIPS:
   4127 	    case EM_MIPS_RS3_LE:
   4128 	      result = get_mips_section_type_name (sh_type);
   4129 	      break;
   4130 	    case EM_PARISC:
   4131 	      result = get_parisc_section_type_name (sh_type);
   4132 	      break;
   4133 	    case EM_IA_64:
   4134 	      result = get_ia64_section_type_name (sh_type);
   4135 	      break;
   4136 	    case EM_X86_64:
   4137 	    case EM_L1OM:
   4138 	    case EM_K1OM:
   4139 	      result = get_x86_64_section_type_name (sh_type);
   4140 	      break;
   4141 	    case EM_AARCH64:
   4142 	      result = get_aarch64_section_type_name (sh_type);
   4143 	      break;
   4144 	    case EM_ARM:
   4145 	      result = get_arm_section_type_name (sh_type);
   4146 	      break;
   4147 	    case EM_TI_C6000:
   4148 	      result = get_tic6x_section_type_name (sh_type);
   4149 	      break;
   4150 	    case EM_MSP430:
   4151 	      result = get_msp430x_section_type_name (sh_type);
   4152 	      break;
   4153 	    case EM_V800:
   4154 	    case EM_V850:
   4155 	    case EM_CYGNUS_V850:
   4156 	      result = get_v850_section_type_name (sh_type);
   4157 	      break;
   4158 	    default:
   4159 	      result = NULL;
   4160 	      break;
   4161 	    }
   4162 
   4163 	  if (result != NULL)
   4164 	    return result;
   4165 
   4166 	  sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC);
   4167 	}
   4168       else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
   4169 	{
   4170 	  switch (elf_header.e_machine)
   4171 	    {
   4172 	    case EM_IA_64:
   4173 	      result = get_ia64_section_type_name (sh_type);
   4174 	      break;
   4175 	    default:
   4176 	      if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
   4177 		result = get_solaris_section_type (sh_type);
   4178 	      else
   4179 		result = NULL;
   4180 	      break;
   4181 	    }
   4182 
   4183 	  if (result != NULL)
   4184 	    return result;
   4185 
   4186 	  sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS);
   4187 	}
   4188       else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
   4189 	{
   4190 	  switch (elf_header.e_machine)
   4191 	    {
   4192 	    case EM_V800:
   4193 	    case EM_V850:
   4194 	    case EM_CYGNUS_V850:
   4195 	      result = get_v850_section_type_name (sh_type);
   4196 	      break;
   4197 	    default:
   4198 	      result = NULL;
   4199 	      break;
   4200 	    }
   4201 
   4202 	  if (result != NULL)
   4203 	    return result;
   4204 
   4205 	  sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER);
   4206 	}
   4207       else
   4208 	/* This message is probably going to be displayed in a 15
   4209 	   character wide field, so put the hex value first.  */
   4210 	snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
   4211 
   4212       return buff;
   4213     }
   4214 }
   4215 
   4216 #define OPTION_DEBUG_DUMP	512
   4217 #define OPTION_DYN_SYMS		513
   4218 #define OPTION_DWARF_DEPTH	514
   4219 #define OPTION_DWARF_START	515
   4220 #define OPTION_DWARF_CHECK	516
   4221 
   4222 static struct option options[] =
   4223 {
   4224   {"all",	       no_argument, 0, 'a'},
   4225   {"file-header",      no_argument, 0, 'h'},
   4226   {"program-headers",  no_argument, 0, 'l'},
   4227   {"headers",	       no_argument, 0, 'e'},
   4228   {"histogram",	       no_argument, 0, 'I'},
   4229   {"segments",	       no_argument, 0, 'l'},
   4230   {"sections",	       no_argument, 0, 'S'},
   4231   {"section-headers",  no_argument, 0, 'S'},
   4232   {"section-groups",   no_argument, 0, 'g'},
   4233   {"section-details",  no_argument, 0, 't'},
   4234   {"full-section-name",no_argument, 0, 'N'},
   4235   {"symbols",	       no_argument, 0, 's'},
   4236   {"syms",	       no_argument, 0, 's'},
   4237   {"dyn-syms",	       no_argument, 0, OPTION_DYN_SYMS},
   4238   {"relocs",	       no_argument, 0, 'r'},
   4239   {"notes",	       no_argument, 0, 'n'},
   4240   {"dynamic",	       no_argument, 0, 'd'},
   4241   {"arch-specific",    no_argument, 0, 'A'},
   4242   {"version-info",     no_argument, 0, 'V'},
   4243   {"use-dynamic",      no_argument, 0, 'D'},
   4244   {"unwind",	       no_argument, 0, 'u'},
   4245   {"archive-index",    no_argument, 0, 'c'},
   4246   {"hex-dump",	       required_argument, 0, 'x'},
   4247   {"relocated-dump",   required_argument, 0, 'R'},
   4248   {"string-dump",      required_argument, 0, 'p'},
   4249   {"decompress",       no_argument, 0, 'z'},
   4250 #ifdef SUPPORT_DISASSEMBLY
   4251   {"instruction-dump", required_argument, 0, 'i'},
   4252 #endif
   4253   {"debug-dump",       optional_argument, 0, OPTION_DEBUG_DUMP},
   4254 
   4255   {"dwarf-depth",      required_argument, 0, OPTION_DWARF_DEPTH},
   4256   {"dwarf-start",      required_argument, 0, OPTION_DWARF_START},
   4257   {"dwarf-check",      no_argument, 0, OPTION_DWARF_CHECK},
   4258 
   4259   {"version",	       no_argument, 0, 'v'},
   4260   {"wide",	       no_argument, 0, 'W'},
   4261   {"help",	       no_argument, 0, 'H'},
   4262   {0,		       no_argument, 0, 0}
   4263 };
   4264 
   4265 static void
   4266 usage (FILE * stream)
   4267 {
   4268   fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
   4269   fprintf (stream, _(" Display information about the contents of ELF format files\n"));
   4270   fprintf (stream, _(" Options are:\n\
   4271   -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I\n\
   4272   -h --file-header       Display the ELF file header\n\
   4273   -l --program-headers   Display the program headers\n\
   4274      --segments          An alias for --program-headers\n\
   4275   -S --section-headers   Display the sections' header\n\
   4276      --sections          An alias for --section-headers\n\
   4277   -g --section-groups    Display the section groups\n\
   4278   -t --section-details   Display the section details\n\
   4279   -e --headers           Equivalent to: -h -l -S\n\
   4280   -s --syms              Display the symbol table\n\
   4281      --symbols           An alias for --syms\n\
   4282   --dyn-syms             Display the dynamic symbol table\n\
   4283   -n --notes             Display the core notes (if present)\n\
   4284   -r --relocs            Display the relocations (if present)\n\
   4285   -u --unwind            Display the unwind info (if present)\n\
   4286   -d --dynamic           Display the dynamic section (if present)\n\
   4287   -V --version-info      Display the version sections (if present)\n\
   4288   -A --arch-specific     Display architecture specific information (if any)\n\
   4289   -c --archive-index     Display the symbol/file index in an archive\n\
   4290   -D --use-dynamic       Use the dynamic section info when displaying symbols\n\
   4291   -x --hex-dump=<number|name>\n\
   4292                          Dump the contents of section <number|name> as bytes\n\
   4293   -p --string-dump=<number|name>\n\
   4294                          Dump the contents of section <number|name> as strings\n\
   4295   -R --relocated-dump=<number|name>\n\
   4296                          Dump the contents of section <number|name> as relocated bytes\n\
   4297   -z --decompress        Decompress section before dumping it\n\
   4298   -w[lLiaprmfFsoRt] or\n\
   4299   --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
   4300                =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
   4301                =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
   4302                =addr,=cu_index]\n\
   4303                          Display the contents of DWARF2 debug sections\n"));
   4304   fprintf (stream, _("\
   4305   --dwarf-depth=N        Do not display DIEs at depth N or greater\n\
   4306   --dwarf-start=N        Display DIEs starting with N, at the same depth\n\
   4307                          or deeper\n"));
   4308 #ifdef SUPPORT_DISASSEMBLY
   4309   fprintf (stream, _("\
   4310   -i --instruction-dump=<number|name>\n\
   4311                          Disassemble the contents of section <number|name>\n"));
   4312 #endif
   4313   fprintf (stream, _("\
   4314   -I --histogram         Display histogram of bucket list lengths\n\
   4315   -W --wide              Allow output width to exceed 80 characters\n\
   4316   @<file>                Read options from <file>\n\
   4317   -H --help              Display this information\n\
   4318   -v --version           Display the version number of readelf\n"));
   4319 
   4320   if (REPORT_BUGS_TO[0] && stream == stdout)
   4321     fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
   4322 
   4323   exit (stream == stdout ? 0 : 1);
   4324 }
   4325 
   4326 /* Record the fact that the user wants the contents of section number
   4327    SECTION to be displayed using the method(s) encoded as flags bits
   4328    in TYPE.  Note, TYPE can be zero if we are creating the array for
   4329    the first time.  */
   4330 
   4331 static void
   4332 request_dump_bynumber (unsigned int section, dump_type type)
   4333 {
   4334   if (section >= num_dump_sects)
   4335     {
   4336       dump_type * new_dump_sects;
   4337 
   4338       new_dump_sects = (dump_type *) calloc (section + 1,
   4339                                              sizeof (* dump_sects));
   4340 
   4341       if (new_dump_sects == NULL)
   4342 	error (_("Out of memory allocating dump request table.\n"));
   4343       else
   4344 	{
   4345 	  /* Copy current flag settings.  */
   4346 	  memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects));
   4347 
   4348 	  free (dump_sects);
   4349 
   4350 	  dump_sects = new_dump_sects;
   4351 	  num_dump_sects = section + 1;
   4352 	}
   4353     }
   4354 
   4355   if (dump_sects)
   4356     dump_sects[section] |= type;
   4357 
   4358   return;
   4359 }
   4360 
   4361 /* Request a dump by section name.  */
   4362 
   4363 static void
   4364 request_dump_byname (const char * section, dump_type type)
   4365 {
   4366   struct dump_list_entry * new_request;
   4367 
   4368   new_request = (struct dump_list_entry *)
   4369       malloc (sizeof (struct dump_list_entry));
   4370   if (!new_request)
   4371     error (_("Out of memory allocating dump request table.\n"));
   4372 
   4373   new_request->name = strdup (section);
   4374   if (!new_request->name)
   4375     error (_("Out of memory allocating dump request table.\n"));
   4376 
   4377   new_request->type = type;
   4378 
   4379   new_request->next = dump_sects_byname;
   4380   dump_sects_byname = new_request;
   4381 }
   4382 
   4383 static inline void
   4384 request_dump (dump_type type)
   4385 {
   4386   int section;
   4387   char * cp;
   4388 
   4389   do_dump++;
   4390   section = strtoul (optarg, & cp, 0);
   4391 
   4392   if (! *cp && section >= 0)
   4393     request_dump_bynumber (section, type);
   4394   else
   4395     request_dump_byname (optarg, type);
   4396 }
   4397 
   4398 
   4399 static void
   4400 parse_args (int argc, char ** argv)
   4401 {
   4402   int c;
   4403 
   4404   if (argc < 2)
   4405     usage (stderr);
   4406 
   4407   while ((c = getopt_long
   4408 	  (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
   4409     {
   4410       switch (c)
   4411 	{
   4412 	case 0:
   4413 	  /* Long options.  */
   4414 	  break;
   4415 	case 'H':
   4416 	  usage (stdout);
   4417 	  break;
   4418 
   4419 	case 'a':
   4420 	  do_syms++;
   4421 	  do_reloc++;
   4422 	  do_unwind++;
   4423 	  do_dynamic++;
   4424 	  do_header++;
   4425 	  do_sections++;
   4426 	  do_section_groups++;
   4427 	  do_segments++;
   4428 	  do_version++;
   4429 	  do_histogram++;
   4430 	  do_arch++;
   4431 	  do_notes++;
   4432 	  break;
   4433 	case 'g':
   4434 	  do_section_groups++;
   4435 	  break;
   4436 	case 't':
   4437 	case 'N':
   4438 	  do_sections++;
   4439 	  do_section_details++;
   4440 	  break;
   4441 	case 'e':
   4442 	  do_header++;
   4443 	  do_sections++;
   4444 	  do_segments++;
   4445 	  break;
   4446 	case 'A':
   4447 	  do_arch++;
   4448 	  break;
   4449 	case 'D':
   4450 	  do_using_dynamic++;
   4451 	  break;
   4452 	case 'r':
   4453 	  do_reloc++;
   4454 	  break;
   4455 	case 'u':
   4456 	  do_unwind++;
   4457 	  break;
   4458 	case 'h':
   4459 	  do_header++;
   4460 	  break;
   4461 	case 'l':
   4462 	  do_segments++;
   4463 	  break;
   4464 	case 's':
   4465 	  do_syms++;
   4466 	  break;
   4467 	case 'S':
   4468 	  do_sections++;
   4469 	  break;
   4470 	case 'd':
   4471 	  do_dynamic++;
   4472 	  break;
   4473 	case 'I':
   4474 	  do_histogram++;
   4475 	  break;
   4476 	case 'n':
   4477 	  do_notes++;
   4478 	  break;
   4479 	case 'c':
   4480 	  do_archive_index++;
   4481 	  break;
   4482 	case 'x':
   4483 	  request_dump (HEX_DUMP);
   4484 	  break;
   4485 	case 'p':
   4486 	  request_dump (STRING_DUMP);
   4487 	  break;
   4488 	case 'R':
   4489 	  request_dump (RELOC_DUMP);
   4490 	  break;
   4491 	case 'z':
   4492 	  decompress_dumps++;
   4493 	  break;
   4494 	case 'w':
   4495 	  do_dump++;
   4496 	  if (optarg == 0)
   4497 	    {
   4498 	      do_debugging = 1;
   4499 	      dwarf_select_sections_all ();
   4500 	    }
   4501 	  else
   4502 	    {
   4503 	      do_debugging = 0;
   4504 	      dwarf_select_sections_by_letters (optarg);
   4505 	    }
   4506 	  break;
   4507 	case OPTION_DEBUG_DUMP:
   4508 	  do_dump++;
   4509 	  if (optarg == 0)
   4510 	    do_debugging = 1;
   4511 	  else
   4512 	    {
   4513 	      do_debugging = 0;
   4514 	      dwarf_select_sections_by_names (optarg);
   4515 	    }
   4516 	  break;
   4517 	case OPTION_DWARF_DEPTH:
   4518 	  {
   4519 	    char *cp;
   4520 
   4521 	    dwarf_cutoff_level = strtoul (optarg, & cp, 0);
   4522 	  }
   4523 	  break;
   4524 	case OPTION_DWARF_START:
   4525 	  {
   4526 	    char *cp;
   4527 
   4528 	    dwarf_start_die = strtoul (optarg, & cp, 0);
   4529 	  }
   4530 	  break;
   4531 	case OPTION_DWARF_CHECK:
   4532 	  dwarf_check = 1;
   4533 	  break;
   4534 	case OPTION_DYN_SYMS:
   4535 	  do_dyn_syms++;
   4536 	  break;
   4537 #ifdef SUPPORT_DISASSEMBLY
   4538 	case 'i':
   4539 	  request_dump (DISASS_DUMP);
   4540 	  break;
   4541 #endif
   4542 	case 'v':
   4543 	  print_version (program_name);
   4544 	  break;
   4545 	case 'V':
   4546 	  do_version++;
   4547 	  break;
   4548 	case 'W':
   4549 	  do_wide++;
   4550 	  break;
   4551 	default:
   4552 	  /* xgettext:c-format */
   4553 	  error (_("Invalid option '-%c'\n"), c);
   4554 	  /* Drop through.  */
   4555 	case '?':
   4556 	  usage (stderr);
   4557 	}
   4558     }
   4559 
   4560   if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
   4561       && !do_segments && !do_header && !do_dump && !do_version
   4562       && !do_histogram && !do_debugging && !do_arch && !do_notes
   4563       && !do_section_groups && !do_archive_index
   4564       && !do_dyn_syms)
   4565     usage (stderr);
   4566 }
   4567 
   4568 static const char *
   4569 get_elf_class (unsigned int elf_class)
   4570 {
   4571   static char buff[32];
   4572 
   4573   switch (elf_class)
   4574     {
   4575     case ELFCLASSNONE: return _("none");
   4576     case ELFCLASS32:   return "ELF32";
   4577     case ELFCLASS64:   return "ELF64";
   4578     default:
   4579       snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
   4580       return buff;
   4581     }
   4582 }
   4583 
   4584 static const char *
   4585 get_data_encoding (unsigned int encoding)
   4586 {
   4587   static char buff[32];
   4588 
   4589   switch (encoding)
   4590     {
   4591     case ELFDATANONE: return _("none");
   4592     case ELFDATA2LSB: return _("2's complement, little endian");
   4593     case ELFDATA2MSB: return _("2's complement, big endian");
   4594     default:
   4595       snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
   4596       return buff;
   4597     }
   4598 }
   4599 
   4600 /* Decode the data held in 'elf_header'.  */
   4601 
   4602 static int
   4603 process_file_header (void)
   4604 {
   4605   if (   elf_header.e_ident[EI_MAG0] != ELFMAG0
   4606       || elf_header.e_ident[EI_MAG1] != ELFMAG1
   4607       || elf_header.e_ident[EI_MAG2] != ELFMAG2
   4608       || elf_header.e_ident[EI_MAG3] != ELFMAG3)
   4609     {
   4610       error
   4611 	(_("Not an ELF file - it has the wrong magic bytes at the start\n"));
   4612       return 0;
   4613     }
   4614 
   4615   init_dwarf_regnames (elf_header.e_machine);
   4616 
   4617   if (do_header)
   4618     {
   4619       int i;
   4620 
   4621       printf (_("ELF Header:\n"));
   4622       printf (_("  Magic:   "));
   4623       for (i = 0; i < EI_NIDENT; i++)
   4624 	printf ("%2.2x ", elf_header.e_ident[i]);
   4625       printf ("\n");
   4626       printf (_("  Class:                             %s\n"),
   4627 	      get_elf_class (elf_header.e_ident[EI_CLASS]));
   4628       printf (_("  Data:                              %s\n"),
   4629 	      get_data_encoding (elf_header.e_ident[EI_DATA]));
   4630       printf (_("  Version:                           %d %s\n"),
   4631 	      elf_header.e_ident[EI_VERSION],
   4632 	      (elf_header.e_ident[EI_VERSION] == EV_CURRENT
   4633 	       ? "(current)"
   4634 	       : (elf_header.e_ident[EI_VERSION] != EV_NONE
   4635 		  ? _("<unknown: %lx>")
   4636 		  : "")));
   4637       printf (_("  OS/ABI:                            %s\n"),
   4638 	      get_osabi_name (elf_header.e_ident[EI_OSABI]));
   4639       printf (_("  ABI Version:                       %d\n"),
   4640 	      elf_header.e_ident[EI_ABIVERSION]);
   4641       printf (_("  Type:                              %s\n"),
   4642 	      get_file_type (elf_header.e_type));
   4643       printf (_("  Machine:                           %s\n"),
   4644 	      get_machine_name (elf_header.e_machine));
   4645       printf (_("  Version:                           0x%lx\n"),
   4646 	      (unsigned long) elf_header.e_version);
   4647 
   4648       printf (_("  Entry point address:               "));
   4649       print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
   4650       printf (_("\n  Start of program headers:          "));
   4651       print_vma ((bfd_vma) elf_header.e_phoff, DEC);
   4652       printf (_(" (bytes into file)\n  Start of section headers:          "));
   4653       print_vma ((bfd_vma) elf_header.e_shoff, DEC);
   4654       printf (_(" (bytes into file)\n"));
   4655 
   4656       printf (_("  Flags:                             0x%lx%s\n"),
   4657 	      (unsigned long) elf_header.e_flags,
   4658 	      get_machine_flags (elf_header.e_flags, elf_header.e_machine));
   4659       printf (_("  Size of this header:               %ld (bytes)\n"),
   4660 	      (long) elf_header.e_ehsize);
   4661       printf (_("  Size of program headers:           %ld (bytes)\n"),
   4662 	      (long) elf_header.e_phentsize);
   4663       printf (_("  Number of program headers:         %ld"),
   4664 	      (long) elf_header.e_phnum);
   4665       if (section_headers != NULL
   4666 	  && elf_header.e_phnum == PN_XNUM
   4667 	  && section_headers[0].sh_info != 0)
   4668 	printf (" (%ld)", (long) section_headers[0].sh_info);
   4669       putc ('\n', stdout);
   4670       printf (_("  Size of section headers:           %ld (bytes)\n"),
   4671 	      (long) elf_header.e_shentsize);
   4672       printf (_("  Number of section headers:         %ld"),
   4673 	      (long) elf_header.e_shnum);
   4674       if (section_headers != NULL && elf_header.e_shnum == SHN_UNDEF)
   4675 	printf (" (%ld)", (long) section_headers[0].sh_size);
   4676       putc ('\n', stdout);
   4677       printf (_("  Section header string table index: %ld"),
   4678 	      (long) elf_header.e_shstrndx);
   4679       if (section_headers != NULL
   4680 	  && elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
   4681 	printf (" (%u)", section_headers[0].sh_link);
   4682       else if (elf_header.e_shstrndx != SHN_UNDEF
   4683 	       && elf_header.e_shstrndx >= elf_header.e_shnum)
   4684 	printf (_(" <corrupt: out of range>"));
   4685       putc ('\n', stdout);
   4686     }
   4687 
   4688   if (section_headers != NULL)
   4689     {
   4690       if (elf_header.e_phnum == PN_XNUM
   4691 	  && section_headers[0].sh_info != 0)
   4692 	elf_header.e_phnum = section_headers[0].sh_info;
   4693       if (elf_header.e_shnum == SHN_UNDEF)
   4694 	elf_header.e_shnum = section_headers[0].sh_size;
   4695       if (elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
   4696 	elf_header.e_shstrndx = section_headers[0].sh_link;
   4697       else if (elf_header.e_shstrndx >= elf_header.e_shnum)
   4698 	elf_header.e_shstrndx = SHN_UNDEF;
   4699       free (section_headers);
   4700       section_headers = NULL;
   4701     }
   4702 
   4703   return 1;
   4704 }
   4705 
   4706 static bfd_boolean
   4707 get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
   4708 {
   4709   Elf32_External_Phdr * phdrs;
   4710   Elf32_External_Phdr * external;
   4711   Elf_Internal_Phdr *   internal;
   4712   unsigned int i;
   4713   unsigned int size = elf_header.e_phentsize;
   4714   unsigned int num  = elf_header.e_phnum;
   4715 
   4716   /* PR binutils/17531: Cope with unexpected section header sizes.  */
   4717   if (size == 0 || num == 0)
   4718     return FALSE;
   4719   if (size < sizeof * phdrs)
   4720     {
   4721       error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
   4722       return FALSE;
   4723     }
   4724   if (size > sizeof * phdrs)
   4725     warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
   4726 
   4727   phdrs = (Elf32_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
   4728                                             size, num, _("program headers"));
   4729   if (phdrs == NULL)
   4730     return FALSE;
   4731 
   4732   for (i = 0, internal = pheaders, external = phdrs;
   4733        i < elf_header.e_phnum;
   4734        i++, internal++, external++)
   4735     {
   4736       internal->p_type   = BYTE_GET (external->p_type);
   4737       internal->p_offset = BYTE_GET (external->p_offset);
   4738       internal->p_vaddr  = BYTE_GET (external->p_vaddr);
   4739       internal->p_paddr  = BYTE_GET (external->p_paddr);
   4740       internal->p_filesz = BYTE_GET (external->p_filesz);
   4741       internal->p_memsz  = BYTE_GET (external->p_memsz);
   4742       internal->p_flags  = BYTE_GET (external->p_flags);
   4743       internal->p_align  = BYTE_GET (external->p_align);
   4744     }
   4745 
   4746   free (phdrs);
   4747   return TRUE;
   4748 }
   4749 
   4750 static bfd_boolean
   4751 get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
   4752 {
   4753   Elf64_External_Phdr * phdrs;
   4754   Elf64_External_Phdr * external;
   4755   Elf_Internal_Phdr *   internal;
   4756   unsigned int i;
   4757   unsigned int size = elf_header.e_phentsize;
   4758   unsigned int num  = elf_header.e_phnum;
   4759 
   4760   /* PR binutils/17531: Cope with unexpected section header sizes.  */
   4761   if (size == 0 || num == 0)
   4762     return FALSE;
   4763   if (size < sizeof * phdrs)
   4764     {
   4765       error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
   4766       return FALSE;
   4767     }
   4768   if (size > sizeof * phdrs)
   4769     warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
   4770 
   4771   phdrs = (Elf64_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
   4772                                             size, num, _("program headers"));
   4773   if (!phdrs)
   4774     return FALSE;
   4775 
   4776   for (i = 0, internal = pheaders, external = phdrs;
   4777        i < elf_header.e_phnum;
   4778        i++, internal++, external++)
   4779     {
   4780       internal->p_type   = BYTE_GET (external->p_type);
   4781       internal->p_flags  = BYTE_GET (external->p_flags);
   4782       internal->p_offset = BYTE_GET (external->p_offset);
   4783       internal->p_vaddr  = BYTE_GET (external->p_vaddr);
   4784       internal->p_paddr  = BYTE_GET (external->p_paddr);
   4785       internal->p_filesz = BYTE_GET (external->p_filesz);
   4786       internal->p_memsz  = BYTE_GET (external->p_memsz);
   4787       internal->p_align  = BYTE_GET (external->p_align);
   4788     }
   4789 
   4790   free (phdrs);
   4791   return TRUE;
   4792 }
   4793 
   4794 /* Returns 1 if the program headers were read into `program_headers'.  */
   4795 
   4796 static int
   4797 get_program_headers (FILE * file)
   4798 {
   4799   Elf_Internal_Phdr * phdrs;
   4800 
   4801   /* Check cache of prior read.  */
   4802   if (program_headers != NULL)
   4803     return 1;
   4804 
   4805   phdrs = (Elf_Internal_Phdr *) cmalloc (elf_header.e_phnum,
   4806                                          sizeof (Elf_Internal_Phdr));
   4807 
   4808   if (phdrs == NULL)
   4809     {
   4810       error (_("Out of memory reading %u program headers\n"),
   4811 	     elf_header.e_phnum);
   4812       return 0;
   4813     }
   4814 
   4815   if (is_32bit_elf
   4816       ? get_32bit_program_headers (file, phdrs)
   4817       : get_64bit_program_headers (file, phdrs))
   4818     {
   4819       program_headers = phdrs;
   4820       return 1;
   4821     }
   4822 
   4823   free (phdrs);
   4824   return 0;
   4825 }
   4826 
   4827 /* Returns 1 if the program headers were loaded.  */
   4828 
   4829 static int
   4830 process_program_headers (FILE * file)
   4831 {
   4832   Elf_Internal_Phdr * segment;
   4833   unsigned int i;
   4834 
   4835   if (elf_header.e_phnum == 0)
   4836     {
   4837       /* PR binutils/12467.  */
   4838       if (elf_header.e_phoff != 0)
   4839 	warn (_("possibly corrupt ELF header - it has a non-zero program"
   4840 		" header offset, but no program headers\n"));
   4841       else if (do_segments)
   4842 	printf (_("\nThere are no program headers in this file.\n"));
   4843       return 0;
   4844     }
   4845 
   4846   if (do_segments && !do_header)
   4847     {
   4848       printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
   4849       printf (_("Entry point "));
   4850       print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
   4851       printf (_("\nThere are %d program headers, starting at offset "),
   4852 	      elf_header.e_phnum);
   4853       print_vma ((bfd_vma) elf_header.e_phoff, DEC);
   4854       printf ("\n");
   4855     }
   4856 
   4857   if (! get_program_headers (file))
   4858       return 0;
   4859 
   4860   if (do_segments)
   4861     {
   4862       if (elf_header.e_phnum > 1)
   4863 	printf (_("\nProgram Headers:\n"));
   4864       else
   4865 	printf (_("\nProgram Headers:\n"));
   4866 
   4867       if (is_32bit_elf)
   4868 	printf
   4869 	  (_("  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align\n"));
   4870       else if (do_wide)
   4871 	printf
   4872 	  (_("  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align\n"));
   4873       else
   4874 	{
   4875 	  printf
   4876 	    (_("  Type           Offset             VirtAddr           PhysAddr\n"));
   4877 	  printf
   4878 	    (_("                 FileSiz            MemSiz              Flags  Align\n"));
   4879 	}
   4880     }
   4881 
   4882   dynamic_addr = 0;
   4883   dynamic_size = 0;
   4884 
   4885   for (i = 0, segment = program_headers;
   4886        i < elf_header.e_phnum;
   4887        i++, segment++)
   4888     {
   4889       if (do_segments)
   4890 	{
   4891 	  printf ("  %-14.14s ", get_segment_type (segment->p_type));
   4892 
   4893 	  if (is_32bit_elf)
   4894 	    {
   4895 	      printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
   4896 	      printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
   4897 	      printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
   4898 	      printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
   4899 	      printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
   4900 	      printf ("%c%c%c ",
   4901 		      (segment->p_flags & PF_R ? 'R' : ' '),
   4902 		      (segment->p_flags & PF_W ? 'W' : ' '),
   4903 		      (segment->p_flags & PF_X ? 'E' : ' '));
   4904 	      printf ("%#lx", (unsigned long) segment->p_align);
   4905 	    }
   4906 	  else if (do_wide)
   4907 	    {
   4908 	      if ((unsigned long) segment->p_offset == segment->p_offset)
   4909 		printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
   4910 	      else
   4911 		{
   4912 		  print_vma (segment->p_offset, FULL_HEX);
   4913 		  putchar (' ');
   4914 		}
   4915 
   4916 	      print_vma (segment->p_vaddr, FULL_HEX);
   4917 	      putchar (' ');
   4918 	      print_vma (segment->p_paddr, FULL_HEX);
   4919 	      putchar (' ');
   4920 
   4921 	      if ((unsigned long) segment->p_filesz == segment->p_filesz)
   4922 		printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
   4923 	      else
   4924 		{
   4925 		  print_vma (segment->p_filesz, FULL_HEX);
   4926 		  putchar (' ');
   4927 		}
   4928 
   4929 	      if ((unsigned long) segment->p_memsz == segment->p_memsz)
   4930 		printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
   4931 	      else
   4932 		{
   4933 		  print_vma (segment->p_memsz, FULL_HEX);
   4934 		}
   4935 
   4936 	      printf (" %c%c%c ",
   4937 		      (segment->p_flags & PF_R ? 'R' : ' '),
   4938 		      (segment->p_flags & PF_W ? 'W' : ' '),
   4939 		      (segment->p_flags & PF_X ? 'E' : ' '));
   4940 
   4941 	      if ((unsigned long) segment->p_align == segment->p_align)
   4942 		printf ("%#lx", (unsigned long) segment->p_align);
   4943 	      else
   4944 		{
   4945 		  print_vma (segment->p_align, PREFIX_HEX);
   4946 		}
   4947 	    }
   4948 	  else
   4949 	    {
   4950 	      print_vma (segment->p_offset, FULL_HEX);
   4951 	      putchar (' ');
   4952 	      print_vma (segment->p_vaddr, FULL_HEX);
   4953 	      putchar (' ');
   4954 	      print_vma (segment->p_paddr, FULL_HEX);
   4955 	      printf ("\n                 ");
   4956 	      print_vma (segment->p_filesz, FULL_HEX);
   4957 	      putchar (' ');
   4958 	      print_vma (segment->p_memsz, FULL_HEX);
   4959 	      printf ("  %c%c%c    ",
   4960 		      (segment->p_flags & PF_R ? 'R' : ' '),
   4961 		      (segment->p_flags & PF_W ? 'W' : ' '),
   4962 		      (segment->p_flags & PF_X ? 'E' : ' '));
   4963 	      print_vma (segment->p_align, HEX);
   4964 	    }
   4965 	}
   4966 
   4967       if (do_segments)
   4968 	putc ('\n', stdout);
   4969 
   4970       switch (segment->p_type)
   4971 	{
   4972 	case PT_DYNAMIC:
   4973 	  if (dynamic_addr)
   4974 	    error (_("more than one dynamic segment\n"));
   4975 
   4976 	  /* By default, assume that the .dynamic section is the first
   4977 	     section in the DYNAMIC segment.  */
   4978 	  dynamic_addr = segment->p_offset;
   4979 	  dynamic_size = segment->p_filesz;
   4980 	  /* PR binutils/17512: Avoid corrupt dynamic section info in the segment.  */
   4981 	  if (dynamic_addr + dynamic_size >= current_file_size)
   4982 	    {
   4983 	      error (_("the dynamic segment offset + size exceeds the size of the file\n"));
   4984 	      dynamic_addr = dynamic_size = 0;
   4985 	    }
   4986 
   4987 	  /* Try to locate the .dynamic section. If there is
   4988 	     a section header table, we can easily locate it.  */
   4989 	  if (section_headers != NULL)
   4990 	    {
   4991 	      Elf_Internal_Shdr * sec;
   4992 
   4993 	      sec = find_section (".dynamic");
   4994 	      if (sec == NULL || sec->sh_size == 0)
   4995 		{
   4996                   /* A corresponding .dynamic section is expected, but on
   4997                      IA-64/OpenVMS it is OK for it to be missing.  */
   4998                   if (!is_ia64_vms ())
   4999                     error (_("no .dynamic section in the dynamic segment\n"));
   5000 		  break;
   5001 		}
   5002 
   5003 	      if (sec->sh_type == SHT_NOBITS)
   5004 		{
   5005 		  dynamic_size = 0;
   5006 		  break;
   5007 		}
   5008 
   5009 	      dynamic_addr = sec->sh_offset;
   5010 	      dynamic_size = sec->sh_size;
   5011 
   5012 	      if (dynamic_addr < segment->p_offset
   5013 		  || dynamic_addr > segment->p_offset + segment->p_filesz)
   5014 		warn (_("the .dynamic section is not contained"
   5015 			" within the dynamic segment\n"));
   5016 	      else if (dynamic_addr > segment->p_offset)
   5017 		warn (_("the .dynamic section is not the first section"
   5018 			" in the dynamic segment.\n"));
   5019 	    }
   5020 	  break;
   5021 
   5022 	case PT_INTERP:
   5023 	  if (fseek (file, archive_file_offset + (long) segment->p_offset,
   5024 		     SEEK_SET))
   5025 	    error (_("Unable to find program interpreter name\n"));
   5026 	  else
   5027 	    {
   5028 	      char fmt [32];
   5029 	      int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
   5030 
   5031 	      if (ret >= (int) sizeof (fmt) || ret < 0)
   5032 		error (_("Internal error: failed to create format string to display program interpreter\n"));
   5033 
   5034 	      program_interpreter[0] = 0;
   5035 	      if (fscanf (file, fmt, program_interpreter) <= 0)
   5036 		error (_("Unable to read program interpreter name\n"));
   5037 
   5038 	      if (do_segments)
   5039 		printf (_("      [Requesting program interpreter: %s]\n"),
   5040 		    program_interpreter);
   5041 	    }
   5042 	  break;
   5043 	}
   5044     }
   5045 
   5046   if (do_segments && section_headers != NULL && string_table != NULL)
   5047     {
   5048       printf (_("\n Section to Segment mapping:\n"));
   5049       printf (_("  Segment Sections...\n"));
   5050 
   5051       for (i = 0; i < elf_header.e_phnum; i++)
   5052 	{
   5053 	  unsigned int j;
   5054 	  Elf_Internal_Shdr * section;
   5055 
   5056 	  segment = program_headers + i;
   5057 	  section = section_headers + 1;
   5058 
   5059 	  printf ("   %2.2d     ", i);
   5060 
   5061 	  for (j = 1; j < elf_header.e_shnum; j++, section++)
   5062 	    {
   5063 	      if (!ELF_TBSS_SPECIAL (section, segment)
   5064 		  && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
   5065 		printf ("%s ", printable_section_name (section));
   5066 	    }
   5067 
   5068 	  putc ('\n',stdout);
   5069 	}
   5070     }
   5071 
   5072   return 1;
   5073 }
   5074 
   5075 
   5076 /* Find the file offset corresponding to VMA by using the program headers.  */
   5077 
   5078 static long
   5079 offset_from_vma (FILE * file, bfd_vma vma, bfd_size_type size)
   5080 {
   5081   Elf_Internal_Phdr * seg;
   5082 
   5083   if (! get_program_headers (file))
   5084     {
   5085       warn (_("Cannot interpret virtual addresses without program headers.\n"));
   5086       return (long) vma;
   5087     }
   5088 
   5089   for (seg = program_headers;
   5090        seg < program_headers + elf_header.e_phnum;
   5091        ++seg)
   5092     {
   5093       if (seg->p_type != PT_LOAD)
   5094 	continue;
   5095 
   5096       if (vma >= (seg->p_vaddr & -seg->p_align)
   5097 	  && vma + size <= seg->p_vaddr + seg->p_filesz)
   5098 	return vma - seg->p_vaddr + seg->p_offset;
   5099     }
   5100 
   5101   warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
   5102 	(unsigned long) vma);
   5103   return (long) vma;
   5104 }
   5105 
   5106 
   5107 /* Allocate memory and load the sections headers into the global pointer
   5108    SECTION_HEADERS.  If PROBE is true, this is just a probe and we do not
   5109    generate any error messages if the load fails.  */
   5110 
   5111 static bfd_boolean
   5112 get_32bit_section_headers (FILE * file, bfd_boolean probe)
   5113 {
   5114   Elf32_External_Shdr * shdrs;
   5115   Elf_Internal_Shdr *   internal;
   5116   unsigned int i;
   5117   unsigned int size = elf_header.e_shentsize;
   5118   unsigned int num = probe ? 1 : elf_header.e_shnum;
   5119 
   5120   /* PR binutils/17531: Cope with unexpected section header sizes.  */
   5121   if (size == 0 || num == 0)
   5122     return FALSE;
   5123   if (size < sizeof * shdrs)
   5124     {
   5125       if (! probe)
   5126 	error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
   5127       return FALSE;
   5128     }
   5129   if (!probe && size > sizeof * shdrs)
   5130     warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
   5131 
   5132   shdrs = (Elf32_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
   5133                                             size, num,
   5134 					    probe ? NULL : _("section headers"));
   5135   if (shdrs == NULL)
   5136     return FALSE;
   5137 
   5138   if (section_headers != NULL)
   5139     free (section_headers);
   5140   section_headers = (Elf_Internal_Shdr *) cmalloc (num,
   5141                                                    sizeof (Elf_Internal_Shdr));
   5142   if (section_headers == NULL)
   5143     {
   5144       if (!probe)
   5145 	error (_("Out of memory reading %u section headers\n"), num);
   5146       return FALSE;
   5147     }
   5148 
   5149   for (i = 0, internal = section_headers;
   5150        i < num;
   5151        i++, internal++)
   5152     {
   5153       internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
   5154       internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
   5155       internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
   5156       internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
   5157       internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
   5158       internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
   5159       internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
   5160       internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
   5161       internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
   5162       internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
   5163       if (!probe && internal->sh_link > num)
   5164 	warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
   5165       if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
   5166 	warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
   5167     }
   5168 
   5169   free (shdrs);
   5170   return TRUE;
   5171 }
   5172 
   5173 static bfd_boolean
   5174 get_64bit_section_headers (FILE * file, bfd_boolean probe)
   5175 {
   5176   Elf64_External_Shdr * shdrs;
   5177   Elf_Internal_Shdr *   internal;
   5178   unsigned int i;
   5179   unsigned int size = elf_header.e_shentsize;
   5180   unsigned int num = probe ? 1 : elf_header.e_shnum;
   5181 
   5182   /* PR binutils/17531: Cope with unexpected section header sizes.  */
   5183   if (size == 0 || num == 0)
   5184     return FALSE;
   5185   if (size < sizeof * shdrs)
   5186     {
   5187       if (! probe)
   5188 	error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
   5189       return FALSE;
   5190     }
   5191   if (! probe && size > sizeof * shdrs)
   5192     warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
   5193 
   5194   shdrs = (Elf64_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
   5195                                             size, num,
   5196 					    probe ? NULL : _("section headers"));
   5197   if (shdrs == NULL)
   5198     return FALSE;
   5199 
   5200   if (section_headers != NULL)
   5201     free (section_headers);
   5202   section_headers = (Elf_Internal_Shdr *) cmalloc (num,
   5203                                                    sizeof (Elf_Internal_Shdr));
   5204   if (section_headers == NULL)
   5205     {
   5206       if (! probe)
   5207 	error (_("Out of memory reading %u section headers\n"), num);
   5208       return FALSE;
   5209     }
   5210 
   5211   for (i = 0, internal = section_headers;
   5212        i < num;
   5213        i++, internal++)
   5214     {
   5215       internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
   5216       internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
   5217       internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
   5218       internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
   5219       internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
   5220       internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
   5221       internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
   5222       internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
   5223       internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
   5224       internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
   5225       if (!probe && internal->sh_link > num)
   5226 	warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
   5227       if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
   5228 	warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
   5229     }
   5230 
   5231   free (shdrs);
   5232   return TRUE;
   5233 }
   5234 
   5235 static Elf_Internal_Sym *
   5236 get_32bit_elf_symbols (FILE * file,
   5237 		       Elf_Internal_Shdr * section,
   5238 		       unsigned long * num_syms_return)
   5239 {
   5240   unsigned long number = 0;
   5241   Elf32_External_Sym * esyms = NULL;
   5242   Elf_External_Sym_Shndx * shndx = NULL;
   5243   Elf_Internal_Sym * isyms = NULL;
   5244   Elf_Internal_Sym * psym;
   5245   unsigned int j;
   5246 
   5247   if (section->sh_size == 0)
   5248     {
   5249       if (num_syms_return != NULL)
   5250 	* num_syms_return = 0;
   5251       return NULL;
   5252     }
   5253 
   5254   /* Run some sanity checks first.  */
   5255   if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
   5256     {
   5257       error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
   5258 	     printable_section_name (section), (unsigned long) section->sh_entsize);
   5259       goto exit_point;
   5260     }
   5261 
   5262   if (section->sh_size > current_file_size)
   5263     {
   5264       error (_("Section %s has an invalid sh_size of 0x%lx\n"),
   5265 	     printable_section_name (section), (unsigned long) section->sh_size);
   5266       goto exit_point;
   5267     }
   5268 
   5269   number = section->sh_size / section->sh_entsize;
   5270 
   5271   if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
   5272     {
   5273       error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
   5274 	     (unsigned long) section->sh_size,
   5275 	     printable_section_name (section),
   5276 	     (unsigned long) section->sh_entsize);
   5277       goto exit_point;
   5278     }
   5279 
   5280   esyms = (Elf32_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
   5281                                            section->sh_size, _("symbols"));
   5282   if (esyms == NULL)
   5283     goto exit_point;
   5284 
   5285   {
   5286     elf_section_list * entry;
   5287 
   5288     shndx = NULL;
   5289     for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
   5290       if (entry->hdr->sh_link == (unsigned long) (section - section_headers))
   5291 	{
   5292 	  shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
   5293 						       entry->hdr->sh_offset,
   5294 						       1, entry->hdr->sh_size,
   5295 						       _("symbol table section indicies"));
   5296 	  if (shndx == NULL)
   5297 	    goto exit_point;
   5298 	  /* PR17531: file: heap-buffer-overflow */
   5299 	  else if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
   5300 	    {
   5301 	      error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
   5302 		     printable_section_name (entry->hdr),
   5303 		     (unsigned long) entry->hdr->sh_size,
   5304 		     (unsigned long) section->sh_size);
   5305 	      goto exit_point;
   5306 	    }
   5307 	}
   5308   }
   5309 
   5310   isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
   5311 
   5312   if (isyms == NULL)
   5313     {
   5314       error (_("Out of memory reading %lu symbols\n"),
   5315 	     (unsigned long) number);
   5316       goto exit_point;
   5317     }
   5318 
   5319   for (j = 0, psym = isyms; j < number; j++, psym++)
   5320     {
   5321       psym->st_name  = BYTE_GET (esyms[j].st_name);
   5322       psym->st_value = BYTE_GET (esyms[j].st_value);
   5323       psym->st_size  = BYTE_GET (esyms[j].st_size);
   5324       psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
   5325       if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
   5326 	psym->st_shndx
   5327 	  = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
   5328       else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
   5329 	psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
   5330       psym->st_info  = BYTE_GET (esyms[j].st_info);
   5331       psym->st_other = BYTE_GET (esyms[j].st_other);
   5332     }
   5333 
   5334  exit_point:
   5335   if (shndx != NULL)
   5336     free (shndx);
   5337   if (esyms != NULL)
   5338     free (esyms);
   5339 
   5340   if (num_syms_return != NULL)
   5341     * num_syms_return = isyms == NULL ? 0 : number;
   5342 
   5343   return isyms;
   5344 }
   5345 
   5346 static Elf_Internal_Sym *
   5347 get_64bit_elf_symbols (FILE * file,
   5348 		       Elf_Internal_Shdr * section,
   5349 		       unsigned long * num_syms_return)
   5350 {
   5351   unsigned long number = 0;
   5352   Elf64_External_Sym * esyms = NULL;
   5353   Elf_External_Sym_Shndx * shndx = NULL;
   5354   Elf_Internal_Sym * isyms = NULL;
   5355   Elf_Internal_Sym * psym;
   5356   unsigned int j;
   5357 
   5358   if (section->sh_size == 0)
   5359     {
   5360       if (num_syms_return != NULL)
   5361 	* num_syms_return = 0;
   5362       return NULL;
   5363     }
   5364 
   5365   /* Run some sanity checks first.  */
   5366   if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
   5367     {
   5368       error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
   5369 	     printable_section_name (section),
   5370 	     (unsigned long) section->sh_entsize);
   5371       goto exit_point;
   5372     }
   5373 
   5374   if (section->sh_size > current_file_size)
   5375     {
   5376       error (_("Section %s has an invalid sh_size of 0x%lx\n"),
   5377 	     printable_section_name (section),
   5378 	     (unsigned long) section->sh_size);
   5379       goto exit_point;
   5380     }
   5381 
   5382   number = section->sh_size / section->sh_entsize;
   5383 
   5384   if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
   5385     {
   5386       error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
   5387 	     (unsigned long) section->sh_size,
   5388 	     printable_section_name (section),
   5389 	     (unsigned long) section->sh_entsize);
   5390       goto exit_point;
   5391     }
   5392 
   5393   esyms = (Elf64_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
   5394                                            section->sh_size, _("symbols"));
   5395   if (!esyms)
   5396     goto exit_point;
   5397 
   5398   {
   5399     elf_section_list * entry;
   5400 
   5401     shndx = NULL;
   5402     for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
   5403       if (entry->hdr->sh_link == (unsigned long) (section - section_headers))
   5404 	{
   5405 	  shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
   5406 						       entry->hdr->sh_offset,
   5407 						       1, entry->hdr->sh_size,
   5408 						       _("symbol table section indicies"));
   5409 	  if (shndx == NULL)
   5410 	    goto exit_point;
   5411 	  /* PR17531: file: heap-buffer-overflow */
   5412 	  else if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
   5413 	    {
   5414 	      error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
   5415 		     printable_section_name (entry->hdr),
   5416 		     (unsigned long) entry->hdr->sh_size,
   5417 		     (unsigned long) section->sh_size);
   5418 	      goto exit_point;
   5419 	    }
   5420 	}
   5421   }
   5422 
   5423   isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
   5424 
   5425   if (isyms == NULL)
   5426     {
   5427       error (_("Out of memory reading %lu symbols\n"),
   5428 	     (unsigned long) number);
   5429       goto exit_point;
   5430     }
   5431 
   5432   for (j = 0, psym = isyms; j < number; j++, psym++)
   5433     {
   5434       psym->st_name  = BYTE_GET (esyms[j].st_name);
   5435       psym->st_info  = BYTE_GET (esyms[j].st_info);
   5436       psym->st_other = BYTE_GET (esyms[j].st_other);
   5437       psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
   5438 
   5439       if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
   5440 	psym->st_shndx
   5441 	  = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
   5442       else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
   5443 	psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
   5444 
   5445       psym->st_value = BYTE_GET (esyms[j].st_value);
   5446       psym->st_size  = BYTE_GET (esyms[j].st_size);
   5447     }
   5448 
   5449  exit_point:
   5450   if (shndx != NULL)
   5451     free (shndx);
   5452   if (esyms != NULL)
   5453     free (esyms);
   5454 
   5455   if (num_syms_return != NULL)
   5456     * num_syms_return = isyms == NULL ? 0 : number;
   5457 
   5458   return isyms;
   5459 }
   5460 
   5461 static const char *
   5462 get_elf_section_flags (bfd_vma sh_flags)
   5463 {
   5464   static char buff[1024];
   5465   char * p = buff;
   5466   int field_size = is_32bit_elf ? 8 : 16;
   5467   int sindex;
   5468   int size = sizeof (buff) - (field_size + 4 + 1);
   5469   bfd_vma os_flags = 0;
   5470   bfd_vma proc_flags = 0;
   5471   bfd_vma unknown_flags = 0;
   5472   static const struct
   5473     {
   5474       const char * str;
   5475       int len;
   5476     }
   5477   flags [] =
   5478     {
   5479       /*  0 */ { STRING_COMMA_LEN ("WRITE") },
   5480       /*  1 */ { STRING_COMMA_LEN ("ALLOC") },
   5481       /*  2 */ { STRING_COMMA_LEN ("EXEC") },
   5482       /*  3 */ { STRING_COMMA_LEN ("MERGE") },
   5483       /*  4 */ { STRING_COMMA_LEN ("STRINGS") },
   5484       /*  5 */ { STRING_COMMA_LEN ("INFO LINK") },
   5485       /*  6 */ { STRING_COMMA_LEN ("LINK ORDER") },
   5486       /*  7 */ { STRING_COMMA_LEN ("OS NONCONF") },
   5487       /*  8 */ { STRING_COMMA_LEN ("GROUP") },
   5488       /*  9 */ { STRING_COMMA_LEN ("TLS") },
   5489       /* IA-64 specific.  */
   5490       /* 10 */ { STRING_COMMA_LEN ("SHORT") },
   5491       /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
   5492       /* IA-64 OpenVMS specific.  */
   5493       /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
   5494       /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
   5495       /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
   5496       /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
   5497       /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
   5498       /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
   5499       /* Generic.  */
   5500       /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
   5501       /* SPARC specific.  */
   5502       /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
   5503       /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
   5504       /* ARM specific.  */
   5505       /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
   5506       /* 22 */ { STRING_COMMA_LEN ("ARM_NOREAD") },
   5507       /* 23 */ { STRING_COMMA_LEN ("COMDEF") }
   5508     };
   5509 
   5510   if (do_section_details)
   5511     {
   5512       sprintf (buff, "[%*.*lx]: ",
   5513 	       field_size, field_size, (unsigned long) sh_flags);
   5514       p += field_size + 4;
   5515     }
   5516 
   5517   while (sh_flags)
   5518     {
   5519       bfd_vma flag;
   5520 
   5521       flag = sh_flags & - sh_flags;
   5522       sh_flags &= ~ flag;
   5523 
   5524       if (do_section_details)
   5525 	{
   5526 	  switch (flag)
   5527 	    {
   5528 	    case SHF_WRITE:		sindex = 0; break;
   5529 	    case SHF_ALLOC:		sindex = 1; break;
   5530 	    case SHF_EXECINSTR:		sindex = 2; break;
   5531 	    case SHF_MERGE:		sindex = 3; break;
   5532 	    case SHF_STRINGS:		sindex = 4; break;
   5533 	    case SHF_INFO_LINK:		sindex = 5; break;
   5534 	    case SHF_LINK_ORDER:	sindex = 6; break;
   5535 	    case SHF_OS_NONCONFORMING:	sindex = 7; break;
   5536 	    case SHF_GROUP:		sindex = 8; break;
   5537 	    case SHF_TLS:		sindex = 9; break;
   5538 	    case SHF_EXCLUDE:		sindex = 18; break;
   5539 	    case SHF_COMPRESSED:	sindex = 20; break;
   5540 
   5541 	    default:
   5542 	      sindex = -1;
   5543 	      switch (elf_header.e_machine)
   5544 		{
   5545 		case EM_IA_64:
   5546 		  if (flag == SHF_IA_64_SHORT)
   5547 		    sindex = 10;
   5548 		  else if (flag == SHF_IA_64_NORECOV)
   5549 		    sindex = 11;
   5550 #ifdef BFD64
   5551 		  else if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
   5552 		    switch (flag)
   5553 		      {
   5554 		      case SHF_IA_64_VMS_GLOBAL:      sindex = 12; break;
   5555 		      case SHF_IA_64_VMS_OVERLAID:    sindex = 13; break;
   5556 		      case SHF_IA_64_VMS_SHARED:      sindex = 14; break;
   5557 		      case SHF_IA_64_VMS_VECTOR:      sindex = 15; break;
   5558 		      case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
   5559 		      case SHF_IA_64_VMS_PROTECTED:   sindex = 17; break;
   5560 		      default:                        break;
   5561 		      }
   5562 #endif
   5563 		  break;
   5564 
   5565 		case EM_386:
   5566 		case EM_IAMCU:
   5567 		case EM_X86_64:
   5568 		case EM_L1OM:
   5569 		case EM_K1OM:
   5570 		case EM_OLD_SPARCV9:
   5571 		case EM_SPARC32PLUS:
   5572 		case EM_SPARCV9:
   5573 		case EM_SPARC:
   5574 		  if (flag == SHF_ORDERED)
   5575 		    sindex = 19;
   5576 		  break;
   5577 
   5578 		case EM_ARM:
   5579 		  switch (flag)
   5580 		    {
   5581 		    case SHF_ENTRYSECT: sindex = 21; break;
   5582 		    case SHF_ARM_NOREAD: sindex = 22; break;
   5583 		    case SHF_COMDEF: sindex = 23; break;
   5584 		    default: break;
   5585 		    }
   5586 		  break;
   5587 
   5588 		default:
   5589 		  break;
   5590 		}
   5591 	    }
   5592 
   5593 	  if (sindex != -1)
   5594 	    {
   5595 	      if (p != buff + field_size + 4)
   5596 		{
   5597 		  if (size < (10 + 2))
   5598 		    {
   5599 		      warn (_("Internal error: not enough buffer room for section flag info"));
   5600 		      return _("<unknown>");
   5601 		    }
   5602 		  size -= 2;
   5603 		  *p++ = ',';
   5604 		  *p++ = ' ';
   5605 		}
   5606 
   5607 	      size -= flags [sindex].len;
   5608 	      p = stpcpy (p, flags [sindex].str);
   5609 	    }
   5610 	  else if (flag & SHF_MASKOS)
   5611 	    os_flags |= flag;
   5612 	  else if (flag & SHF_MASKPROC)
   5613 	    proc_flags |= flag;
   5614 	  else
   5615 	    unknown_flags |= flag;
   5616 	}
   5617       else
   5618 	{
   5619 	  switch (flag)
   5620 	    {
   5621 	    case SHF_WRITE:		*p = 'W'; break;
   5622 	    case SHF_ALLOC:		*p = 'A'; break;
   5623 	    case SHF_EXECINSTR:		*p = 'X'; break;
   5624 	    case SHF_MERGE:		*p = 'M'; break;
   5625 	    case SHF_STRINGS:		*p = 'S'; break;
   5626 	    case SHF_INFO_LINK:		*p = 'I'; break;
   5627 	    case SHF_LINK_ORDER:	*p = 'L'; break;
   5628 	    case SHF_OS_NONCONFORMING:	*p = 'O'; break;
   5629 	    case SHF_GROUP:		*p = 'G'; break;
   5630 	    case SHF_TLS:		*p = 'T'; break;
   5631 	    case SHF_EXCLUDE:		*p = 'E'; break;
   5632 	    case SHF_COMPRESSED:	*p = 'C'; break;
   5633 
   5634 	    default:
   5635 	      if ((elf_header.e_machine == EM_X86_64
   5636 		   || elf_header.e_machine == EM_L1OM
   5637 		   || elf_header.e_machine == EM_K1OM)
   5638 		  && flag == SHF_X86_64_LARGE)
   5639 		*p = 'l';
   5640 	      else if (elf_header.e_machine == EM_ARM
   5641 		       && flag == SHF_ARM_NOREAD)
   5642 		  *p = 'y';
   5643 	      else if (flag & SHF_MASKOS)
   5644 		{
   5645 		  *p = 'o';
   5646 		  sh_flags &= ~ SHF_MASKOS;
   5647 		}
   5648 	      else if (flag & SHF_MASKPROC)
   5649 		{
   5650 		  *p = 'p';
   5651 		  sh_flags &= ~ SHF_MASKPROC;
   5652 		}
   5653 	      else
   5654 		*p = 'x';
   5655 	      break;
   5656 	    }
   5657 	  p++;
   5658 	}
   5659     }
   5660 
   5661   if (do_section_details)
   5662     {
   5663       if (os_flags)
   5664 	{
   5665 	  size -= 5 + field_size;
   5666 	  if (p != buff + field_size + 4)
   5667 	    {
   5668 	      if (size < (2 + 1))
   5669 		{
   5670 		  warn (_("Internal error: not enough buffer room for section flag info"));
   5671 		  return _("<unknown>");
   5672 		}
   5673 	      size -= 2;
   5674 	      *p++ = ',';
   5675 	      *p++ = ' ';
   5676 	    }
   5677 	  sprintf (p, "OS (%*.*lx)", field_size, field_size,
   5678 		   (unsigned long) os_flags);
   5679 	  p += 5 + field_size;
   5680 	}
   5681       if (proc_flags)
   5682 	{
   5683 	  size -= 7 + field_size;
   5684 	  if (p != buff + field_size + 4)
   5685 	    {
   5686 	      if (size < (2 + 1))
   5687 		{
   5688 		  warn (_("Internal error: not enough buffer room for section flag info"));
   5689 		  return _("<unknown>");
   5690 		}
   5691 	      size -= 2;
   5692 	      *p++ = ',';
   5693 	      *p++ = ' ';
   5694 	    }
   5695 	  sprintf (p, "PROC (%*.*lx)", field_size, field_size,
   5696 		   (unsigned long) proc_flags);
   5697 	  p += 7 + field_size;
   5698 	}
   5699       if (unknown_flags)
   5700 	{
   5701 	  size -= 10 + field_size;
   5702 	  if (p != buff + field_size + 4)
   5703 	    {
   5704 	      if (size < (2 + 1))
   5705 		{
   5706 		  warn (_("Internal error: not enough buffer room for section flag info"));
   5707 		  return _("<unknown>");
   5708 		}
   5709 	      size -= 2;
   5710 	      *p++ = ',';
   5711 	      *p++ = ' ';
   5712 	    }
   5713 	  sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
   5714 		   (unsigned long) unknown_flags);
   5715 	  p += 10 + field_size;
   5716 	}
   5717     }
   5718 
   5719   *p = '\0';
   5720   return buff;
   5721 }
   5722 
   5723 static unsigned int
   5724 get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf)
   5725 {
   5726   if (is_32bit_elf)
   5727     {
   5728       Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf;
   5729       chdr->ch_type = BYTE_GET (echdr->ch_type);
   5730       chdr->ch_size = BYTE_GET (echdr->ch_size);
   5731       chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
   5732       return sizeof (*echdr);
   5733     }
   5734   else
   5735     {
   5736       Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf;
   5737       chdr->ch_type = BYTE_GET (echdr->ch_type);
   5738       chdr->ch_size = BYTE_GET (echdr->ch_size);
   5739       chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
   5740       return sizeof (*echdr);
   5741     }
   5742 }
   5743 
   5744 static int
   5745 process_section_headers (FILE * file)
   5746 {
   5747   Elf_Internal_Shdr * section;
   5748   unsigned int i;
   5749 
   5750   section_headers = NULL;
   5751 
   5752   if (elf_header.e_shnum == 0)
   5753     {
   5754       /* PR binutils/12467.  */
   5755       if (elf_header.e_shoff != 0)
   5756 	warn (_("possibly corrupt ELF file header - it has a non-zero"
   5757 		" section header offset, but no section headers\n"));
   5758       else if (do_sections)
   5759 	printf (_("\nThere are no sections in this file.\n"));
   5760 
   5761       return 1;
   5762     }
   5763 
   5764   if (do_sections && !do_header)
   5765     printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
   5766 	    elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
   5767 
   5768   if (is_32bit_elf)
   5769     {
   5770       if (! get_32bit_section_headers (file, FALSE))
   5771 	return 0;
   5772     }
   5773   else if (! get_64bit_section_headers (file, FALSE))
   5774     return 0;
   5775 
   5776   /* Read in the string table, so that we have names to display.  */
   5777   if (elf_header.e_shstrndx != SHN_UNDEF
   5778        && elf_header.e_shstrndx < elf_header.e_shnum)
   5779     {
   5780       section = section_headers + elf_header.e_shstrndx;
   5781 
   5782       if (section->sh_size != 0)
   5783 	{
   5784 	  string_table = (char *) get_data (NULL, file, section->sh_offset,
   5785                                             1, section->sh_size,
   5786                                             _("string table"));
   5787 
   5788 	  string_table_length = string_table != NULL ? section->sh_size : 0;
   5789 	}
   5790     }
   5791 
   5792   /* Scan the sections for the dynamic symbol table
   5793      and dynamic string table and debug sections.  */
   5794   dynamic_symbols = NULL;
   5795   dynamic_strings = NULL;
   5796   dynamic_syminfo = NULL;
   5797   symtab_shndx_list = NULL;
   5798 
   5799   eh_addr_size = is_32bit_elf ? 4 : 8;
   5800   switch (elf_header.e_machine)
   5801     {
   5802     case EM_MIPS:
   5803     case EM_MIPS_RS3_LE:
   5804       /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
   5805 	 FDE addresses.  However, the ABI also has a semi-official ILP32
   5806 	 variant for which the normal FDE address size rules apply.
   5807 
   5808 	 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
   5809 	 section, where XX is the size of longs in bits.  Unfortunately,
   5810 	 earlier compilers provided no way of distinguishing ILP32 objects
   5811 	 from LP64 objects, so if there's any doubt, we should assume that
   5812 	 the official LP64 form is being used.  */
   5813       if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
   5814 	  && find_section (".gcc_compiled_long32") == NULL)
   5815 	eh_addr_size = 8;
   5816       break;
   5817 
   5818     case EM_H8_300:
   5819     case EM_H8_300H:
   5820       switch (elf_header.e_flags & EF_H8_MACH)
   5821 	{
   5822 	case E_H8_MACH_H8300:
   5823 	case E_H8_MACH_H8300HN:
   5824 	case E_H8_MACH_H8300SN:
   5825 	case E_H8_MACH_H8300SXN:
   5826 	  eh_addr_size = 2;
   5827 	  break;
   5828 	case E_H8_MACH_H8300H:
   5829 	case E_H8_MACH_H8300S:
   5830 	case E_H8_MACH_H8300SX:
   5831 	  eh_addr_size = 4;
   5832 	  break;
   5833 	}
   5834       break;
   5835 
   5836     case EM_M32C_OLD:
   5837     case EM_M32C:
   5838       switch (elf_header.e_flags & EF_M32C_CPU_MASK)
   5839 	{
   5840 	case EF_M32C_CPU_M16C:
   5841 	  eh_addr_size = 2;
   5842 	  break;
   5843 	}
   5844       break;
   5845     }
   5846 
   5847 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64)		\
   5848   do									\
   5849     {									\
   5850       bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64;	\
   5851       if (section->sh_entsize != expected_entsize)			\
   5852 	{								\
   5853 	  char buf[40];							\
   5854 	  sprintf_vma (buf, section->sh_entsize);			\
   5855 	  /* Note: coded this way so that there is a single string for  \
   5856 	     translation.  */ \
   5857 	  error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
   5858 	  error (_("(Using the expected size of %u for the rest of this dump)\n"), \
   5859 		   (unsigned) expected_entsize);			\
   5860 	  section->sh_entsize = expected_entsize;			\
   5861 	}								\
   5862     }									\
   5863   while (0)
   5864 
   5865 #define CHECK_ENTSIZE(section, i, type)					\
   5866   CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type),	    \
   5867 			sizeof (Elf64_External_##type))
   5868 
   5869   for (i = 0, section = section_headers;
   5870        i < elf_header.e_shnum;
   5871        i++, section++)
   5872     {
   5873       char * name = SECTION_NAME (section);
   5874 
   5875       if (section->sh_type == SHT_DYNSYM)
   5876 	{
   5877 	  if (dynamic_symbols != NULL)
   5878 	    {
   5879 	      error (_("File contains multiple dynamic symbol tables\n"));
   5880 	      continue;
   5881 	    }
   5882 
   5883 	  CHECK_ENTSIZE (section, i, Sym);
   5884 	  dynamic_symbols = GET_ELF_SYMBOLS (file, section, & num_dynamic_syms);
   5885 	}
   5886       else if (section->sh_type == SHT_STRTAB
   5887 	       && streq (name, ".dynstr"))
   5888 	{
   5889 	  if (dynamic_strings != NULL)
   5890 	    {
   5891 	      error (_("File contains multiple dynamic string tables\n"));
   5892 	      continue;
   5893 	    }
   5894 
   5895 	  dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
   5896                                                1, section->sh_size,
   5897                                                _("dynamic strings"));
   5898 	  dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
   5899 	}
   5900       else if (section->sh_type == SHT_SYMTAB_SHNDX)
   5901 	{
   5902 	  elf_section_list * entry = xmalloc (sizeof * entry);
   5903 	  entry->hdr = section;
   5904 	  entry->next = symtab_shndx_list;
   5905 	  symtab_shndx_list = entry;
   5906 	}
   5907       else if (section->sh_type == SHT_SYMTAB)
   5908 	CHECK_ENTSIZE (section, i, Sym);
   5909       else if (section->sh_type == SHT_GROUP)
   5910 	CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
   5911       else if (section->sh_type == SHT_REL)
   5912 	CHECK_ENTSIZE (section, i, Rel);
   5913       else if (section->sh_type == SHT_RELA)
   5914 	CHECK_ENTSIZE (section, i, Rela);
   5915       else if ((do_debugging || do_debug_info || do_debug_abbrevs
   5916 		|| do_debug_lines || do_debug_pubnames || do_debug_pubtypes
   5917 		|| do_debug_aranges || do_debug_frames || do_debug_macinfo
   5918 		|| do_debug_str || do_debug_loc || do_debug_ranges
   5919 		|| do_debug_addr || do_debug_cu_index)
   5920 	       && (const_strneq (name, ".debug_")
   5921                    || const_strneq (name, ".zdebug_")))
   5922 	{
   5923           if (name[1] == 'z')
   5924             name += sizeof (".zdebug_") - 1;
   5925           else
   5926             name += sizeof (".debug_") - 1;
   5927 
   5928 	  if (do_debugging
   5929 	      || (do_debug_info     && const_strneq (name, "info"))
   5930 	      || (do_debug_info     && const_strneq (name, "types"))
   5931 	      || (do_debug_abbrevs  && const_strneq (name, "abbrev"))
   5932 	      || (do_debug_lines    && strcmp (name, "line") == 0)
   5933 	      || (do_debug_lines    && const_strneq (name, "line."))
   5934 	      || (do_debug_pubnames && const_strneq (name, "pubnames"))
   5935 	      || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
   5936 	      || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
   5937 	      || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
   5938 	      || (do_debug_aranges  && const_strneq (name, "aranges"))
   5939 	      || (do_debug_ranges   && const_strneq (name, "ranges"))
   5940 	      || (do_debug_frames   && const_strneq (name, "frame"))
   5941 	      || (do_debug_macinfo  && const_strneq (name, "macinfo"))
   5942 	      || (do_debug_macinfo  && const_strneq (name, "macro"))
   5943 	      || (do_debug_str      && const_strneq (name, "str"))
   5944 	      || (do_debug_str      && const_strneq (name, "line_str"))
   5945 	      || (do_debug_loc      && const_strneq (name, "loc"))
   5946 	      || (do_debug_addr     && const_strneq (name, "addr"))
   5947 	      || (do_debug_cu_index && const_strneq (name, "cu_index"))
   5948 	      || (do_debug_cu_index && const_strneq (name, "tu_index"))
   5949 	      )
   5950 	    request_dump_bynumber (i, DEBUG_DUMP);
   5951 	}
   5952       /* Linkonce section to be combined with .debug_info at link time.  */
   5953       else if ((do_debugging || do_debug_info)
   5954 	       && const_strneq (name, ".gnu.linkonce.wi."))
   5955 	request_dump_bynumber (i, DEBUG_DUMP);
   5956       else if (do_debug_frames && streq (name, ".eh_frame"))
   5957 	request_dump_bynumber (i, DEBUG_DUMP);
   5958       else if (do_gdb_index && streq (name, ".gdb_index"))
   5959 	request_dump_bynumber (i, DEBUG_DUMP);
   5960       /* Trace sections for Itanium VMS.  */
   5961       else if ((do_debugging || do_trace_info || do_trace_abbrevs
   5962                 || do_trace_aranges)
   5963 	       && const_strneq (name, ".trace_"))
   5964 	{
   5965           name += sizeof (".trace_") - 1;
   5966 
   5967 	  if (do_debugging
   5968 	      || (do_trace_info     && streq (name, "info"))
   5969 	      || (do_trace_abbrevs  && streq (name, "abbrev"))
   5970 	      || (do_trace_aranges  && streq (name, "aranges"))
   5971 	      )
   5972 	    request_dump_bynumber (i, DEBUG_DUMP);
   5973 	}
   5974     }
   5975 
   5976   if (! do_sections)
   5977     return 1;
   5978 
   5979   if (elf_header.e_shnum > 1)
   5980     printf (_("\nSection Headers:\n"));
   5981   else
   5982     printf (_("\nSection Header:\n"));
   5983 
   5984   if (is_32bit_elf)
   5985     {
   5986       if (do_section_details)
   5987 	{
   5988 	  printf (_("  [Nr] Name\n"));
   5989 	  printf (_("       Type            Addr     Off    Size   ES   Lk Inf Al\n"));
   5990 	}
   5991       else
   5992 	printf
   5993 	  (_("  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al\n"));
   5994     }
   5995   else if (do_wide)
   5996     {
   5997       if (do_section_details)
   5998 	{
   5999 	  printf (_("  [Nr] Name\n"));
   6000 	  printf (_("       Type            Address          Off    Size   ES   Lk Inf Al\n"));
   6001 	}
   6002       else
   6003 	printf
   6004 	  (_("  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al\n"));
   6005     }
   6006   else
   6007     {
   6008       if (do_section_details)
   6009 	{
   6010 	  printf (_("  [Nr] Name\n"));
   6011 	  printf (_("       Type              Address          Offset            Link\n"));
   6012 	  printf (_("       Size              EntSize          Info              Align\n"));
   6013 	}
   6014       else
   6015 	{
   6016 	  printf (_("  [Nr] Name              Type             Address           Offset\n"));
   6017 	  printf (_("       Size              EntSize          Flags  Link  Info  Align\n"));
   6018 	}
   6019     }
   6020 
   6021   if (do_section_details)
   6022     printf (_("       Flags\n"));
   6023 
   6024   for (i = 0, section = section_headers;
   6025        i < elf_header.e_shnum;
   6026        i++, section++)
   6027     {
   6028       printf ("  [%2u] ", i);
   6029       if (do_section_details)
   6030 	printf ("%s\n      ", printable_section_name (section));
   6031       else
   6032 	print_symbol (-17, SECTION_NAME (section));
   6033 
   6034       printf (do_wide ? " %-15s " : " %-15.15s ",
   6035 	      get_section_type_name (section->sh_type));
   6036 
   6037       if (is_32bit_elf)
   6038 	{
   6039 	  const char * link_too_big = NULL;
   6040 
   6041 	  print_vma (section->sh_addr, LONG_HEX);
   6042 
   6043 	  printf ( " %6.6lx %6.6lx %2.2lx",
   6044 		   (unsigned long) section->sh_offset,
   6045 		   (unsigned long) section->sh_size,
   6046 		   (unsigned long) section->sh_entsize);
   6047 
   6048 	  if (do_section_details)
   6049 	    fputs ("  ", stdout);
   6050 	  else
   6051 	    printf (" %3s ", get_elf_section_flags (section->sh_flags));
   6052 
   6053 	  if (section->sh_link >= elf_header.e_shnum)
   6054 	    {
   6055 	      link_too_big = "";
   6056 	      /* The sh_link value is out of range.  Normally this indicates
   6057 		 an error but it can have special values in Solaris binaries.  */
   6058 	      switch (elf_header.e_machine)
   6059 		{
   6060 		case EM_386:
   6061 		case EM_IAMCU:
   6062 		case EM_X86_64:
   6063 		case EM_L1OM:
   6064 		case EM_K1OM:
   6065 		case EM_OLD_SPARCV9:
   6066 		case EM_SPARC32PLUS:
   6067 		case EM_SPARCV9:
   6068 		case EM_SPARC:
   6069 		  if (section->sh_link == (SHN_BEFORE & 0xffff))
   6070 		    link_too_big = "BEFORE";
   6071 		  else if (section->sh_link == (SHN_AFTER & 0xffff))
   6072 		    link_too_big = "AFTER";
   6073 		  break;
   6074 		default:
   6075 		  break;
   6076 		}
   6077 	    }
   6078 
   6079 	  if (do_section_details)
   6080 	    {
   6081 	      if (link_too_big != NULL && * link_too_big)
   6082 		printf ("<%s> ", link_too_big);
   6083 	      else
   6084 		printf ("%2u ", section->sh_link);
   6085 	      printf ("%3u %2lu\n", section->sh_info,
   6086 		      (unsigned long) section->sh_addralign);
   6087 	    }
   6088 	  else
   6089 	    printf ("%2u %3u %2lu\n",
   6090 		    section->sh_link,
   6091 		    section->sh_info,
   6092 		    (unsigned long) section->sh_addralign);
   6093 
   6094 	  if (link_too_big && ! * link_too_big)
   6095 	    warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
   6096 		  i, section->sh_link);
   6097 	}
   6098       else if (do_wide)
   6099 	{
   6100 	  print_vma (section->sh_addr, LONG_HEX);
   6101 
   6102 	  if ((long) section->sh_offset == section->sh_offset)
   6103 	    printf (" %6.6lx", (unsigned long) section->sh_offset);
   6104 	  else
   6105 	    {
   6106 	      putchar (' ');
   6107 	      print_vma (section->sh_offset, LONG_HEX);
   6108 	    }
   6109 
   6110 	  if ((unsigned long) section->sh_size == section->sh_size)
   6111 	    printf (" %6.6lx", (unsigned long) section->sh_size);
   6112 	  else
   6113 	    {
   6114 	      putchar (' ');
   6115 	      print_vma (section->sh_size, LONG_HEX);
   6116 	    }
   6117 
   6118 	  if ((unsigned long) section->sh_entsize == section->sh_entsize)
   6119 	    printf (" %2.2lx", (unsigned long) section->sh_entsize);
   6120 	  else
   6121 	    {
   6122 	      putchar (' ');
   6123 	      print_vma (section->sh_entsize, LONG_HEX);
   6124 	    }
   6125 
   6126 	  if (do_section_details)
   6127 	    fputs ("  ", stdout);
   6128 	  else
   6129 	    printf (" %3s ", get_elf_section_flags (section->sh_flags));
   6130 
   6131 	  printf ("%2u %3u ", section->sh_link, section->sh_info);
   6132 
   6133 	  if ((unsigned long) section->sh_addralign == section->sh_addralign)
   6134 	    printf ("%2lu\n", (unsigned long) section->sh_addralign);
   6135 	  else
   6136 	    {
   6137 	      print_vma (section->sh_addralign, DEC);
   6138 	      putchar ('\n');
   6139 	    }
   6140 	}
   6141       else if (do_section_details)
   6142 	{
   6143 	  printf ("       %-15.15s  ",
   6144 		  get_section_type_name (section->sh_type));
   6145 	  print_vma (section->sh_addr, LONG_HEX);
   6146 	  if ((long) section->sh_offset == section->sh_offset)
   6147 	    printf ("  %16.16lx", (unsigned long) section->sh_offset);
   6148 	  else
   6149 	    {
   6150 	      printf ("  ");
   6151 	      print_vma (section->sh_offset, LONG_HEX);
   6152 	    }
   6153 	  printf ("  %u\n       ", section->sh_link);
   6154 	  print_vma (section->sh_size, LONG_HEX);
   6155 	  putchar (' ');
   6156 	  print_vma (section->sh_entsize, LONG_HEX);
   6157 
   6158 	  printf ("  %-16u  %lu\n",
   6159 		  section->sh_info,
   6160 		  (unsigned long) section->sh_addralign);
   6161 	}
   6162       else
   6163 	{
   6164 	  putchar (' ');
   6165 	  print_vma (section->sh_addr, LONG_HEX);
   6166 	  if ((long) section->sh_offset == section->sh_offset)
   6167 	    printf ("  %8.8lx", (unsigned long) section->sh_offset);
   6168 	  else
   6169 	    {
   6170 	      printf ("  ");
   6171 	      print_vma (section->sh_offset, LONG_HEX);
   6172 	    }
   6173 	  printf ("\n       ");
   6174 	  print_vma (section->sh_size, LONG_HEX);
   6175 	  printf ("  ");
   6176 	  print_vma (section->sh_entsize, LONG_HEX);
   6177 
   6178 	  printf (" %3s ", get_elf_section_flags (section->sh_flags));
   6179 
   6180 	  printf ("     %2u   %3u     %lu\n",
   6181 		  section->sh_link,
   6182 		  section->sh_info,
   6183 		  (unsigned long) section->sh_addralign);
   6184 	}
   6185 
   6186       if (do_section_details)
   6187 	{
   6188 	  printf ("       %s\n", get_elf_section_flags (section->sh_flags));
   6189 	  if ((section->sh_flags & SHF_COMPRESSED) != 0)
   6190 	    {
   6191 	      /* Minimum section size is 12 bytes for 32-bit compression
   6192 		 header + 12 bytes for compressed data header.  */
   6193 	      unsigned char buf[24];
   6194 	      assert (sizeof (buf) >= sizeof (Elf64_External_Chdr));
   6195 	      if (get_data (&buf, (FILE *) file, section->sh_offset, 1,
   6196 			    sizeof (buf), _("compression header")))
   6197 		{
   6198 		  Elf_Internal_Chdr chdr;
   6199 		  get_compression_header (&chdr, buf);
   6200 		  if (chdr.ch_type == ELFCOMPRESS_ZLIB)
   6201 		    printf ("       ZLIB, ");
   6202 		  else
   6203 		    printf (_("       [<unknown>: 0x%x], "),
   6204 			    chdr.ch_type);
   6205 		  print_vma (chdr.ch_size, LONG_HEX);
   6206 		  printf (", %lu\n", (unsigned long) chdr.ch_addralign);
   6207 		}
   6208 	    }
   6209 	}
   6210     }
   6211 
   6212   if (!do_section_details)
   6213     {
   6214       /* The ordering of the letters shown here matches the ordering of the
   6215 	 corresponding SHF_xxx values, and hence the order in which these
   6216 	 letters will be displayed to the user.  */
   6217       printf (_("Key to Flags:\n\
   6218   W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
   6219   L (link order), O (extra OS processing required), G (group), T (TLS),\n\
   6220   C (compressed), x (unknown), o (OS specific), E (exclude),\n  "));
   6221       if (elf_header.e_machine == EM_X86_64
   6222 	  || elf_header.e_machine == EM_L1OM
   6223 	  || elf_header.e_machine == EM_K1OM)
   6224 	printf (_("l (large), "));
   6225       else if (elf_header.e_machine == EM_ARM)
   6226 	printf (_("y (noread), "));
   6227       printf ("p (processor specific)\n");
   6228     }
   6229 
   6230   return 1;
   6231 }
   6232 
   6233 static const char *
   6234 get_group_flags (unsigned int flags)
   6235 {
   6236   static char buff[32];
   6237   switch (flags)
   6238     {
   6239     case 0:
   6240       return "";
   6241 
   6242     case GRP_COMDAT:
   6243       return "COMDAT ";
   6244 
   6245    default:
   6246       snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x] "), flags);
   6247       break;
   6248     }
   6249   return buff;
   6250 }
   6251 
   6252 static int
   6253 process_section_groups (FILE * file)
   6254 {
   6255   Elf_Internal_Shdr * section;
   6256   unsigned int i;
   6257   struct group * group;
   6258   Elf_Internal_Shdr * symtab_sec;
   6259   Elf_Internal_Shdr * strtab_sec;
   6260   Elf_Internal_Sym * symtab;
   6261   unsigned long num_syms;
   6262   char * strtab;
   6263   size_t strtab_size;
   6264 
   6265   /* Don't process section groups unless needed.  */
   6266   if (!do_unwind && !do_section_groups)
   6267     return 1;
   6268 
   6269   if (elf_header.e_shnum == 0)
   6270     {
   6271       if (do_section_groups)
   6272 	printf (_("\nThere are no sections to group in this file.\n"));
   6273 
   6274       return 1;
   6275     }
   6276 
   6277   if (section_headers == NULL)
   6278     {
   6279       error (_("Section headers are not available!\n"));
   6280       /* PR 13622: This can happen with a corrupt ELF header.  */
   6281       return 0;
   6282     }
   6283 
   6284   section_headers_groups = (struct group **) calloc (elf_header.e_shnum,
   6285                                                      sizeof (struct group *));
   6286 
   6287   if (section_headers_groups == NULL)
   6288     {
   6289       error (_("Out of memory reading %u section group headers\n"),
   6290 	     elf_header.e_shnum);
   6291       return 0;
   6292     }
   6293 
   6294   /* Scan the sections for the group section.  */
   6295   group_count = 0;
   6296   for (i = 0, section = section_headers;
   6297        i < elf_header.e_shnum;
   6298        i++, section++)
   6299     if (section->sh_type == SHT_GROUP)
   6300       group_count++;
   6301 
   6302   if (group_count == 0)
   6303     {
   6304       if (do_section_groups)
   6305 	printf (_("\nThere are no section groups in this file.\n"));
   6306 
   6307       return 1;
   6308     }
   6309 
   6310   section_groups = (struct group *) calloc (group_count, sizeof (struct group));
   6311 
   6312   if (section_groups == NULL)
   6313     {
   6314       error (_("Out of memory reading %lu groups\n"),
   6315 	     (unsigned long) group_count);
   6316       return 0;
   6317     }
   6318 
   6319   symtab_sec = NULL;
   6320   strtab_sec = NULL;
   6321   symtab = NULL;
   6322   num_syms = 0;
   6323   strtab = NULL;
   6324   strtab_size = 0;
   6325   for (i = 0, section = section_headers, group = section_groups;
   6326        i < elf_header.e_shnum;
   6327        i++, section++)
   6328     {
   6329       if (section->sh_type == SHT_GROUP)
   6330 	{
   6331 	  const char * name = printable_section_name (section);
   6332 	  const char * group_name;
   6333 	  unsigned char * start;
   6334 	  unsigned char * indices;
   6335 	  unsigned int entry, j, size;
   6336 	  Elf_Internal_Shdr * sec;
   6337 	  Elf_Internal_Sym * sym;
   6338 
   6339 	  /* Get the symbol table.  */
   6340 	  if (section->sh_link >= elf_header.e_shnum
   6341 	      || ((sec = section_headers + section->sh_link)->sh_type
   6342 		  != SHT_SYMTAB))
   6343 	    {
   6344 	      error (_("Bad sh_link in group section `%s'\n"), name);
   6345 	      continue;
   6346 	    }
   6347 
   6348 	  if (symtab_sec != sec)
   6349 	    {
   6350 	      symtab_sec = sec;
   6351 	      if (symtab)
   6352 		free (symtab);
   6353 	      symtab = GET_ELF_SYMBOLS (file, symtab_sec, & num_syms);
   6354 	    }
   6355 
   6356 	  if (symtab == NULL)
   6357 	    {
   6358 	      error (_("Corrupt header in group section `%s'\n"), name);
   6359 	      continue;
   6360 	    }
   6361 
   6362 	  if (section->sh_info >= num_syms)
   6363 	    {
   6364 	      error (_("Bad sh_info in group section `%s'\n"), name);
   6365 	      continue;
   6366 	    }
   6367 
   6368 	  sym = symtab + section->sh_info;
   6369 
   6370 	  if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
   6371 	    {
   6372 	      if (sym->st_shndx == 0
   6373 		  || sym->st_shndx >= elf_header.e_shnum)
   6374 		{
   6375 		  error (_("Bad sh_info in group section `%s'\n"), name);
   6376 		  continue;
   6377 		}
   6378 
   6379 	      group_name = SECTION_NAME (section_headers + sym->st_shndx);
   6380 	      strtab_sec = NULL;
   6381 	      if (strtab)
   6382 		free (strtab);
   6383 	      strtab = NULL;
   6384 	      strtab_size = 0;
   6385 	    }
   6386 	  else
   6387 	    {
   6388 	      /* Get the string table.  */
   6389 	      if (symtab_sec->sh_link >= elf_header.e_shnum)
   6390 		{
   6391 		  strtab_sec = NULL;
   6392 		  if (strtab)
   6393 		    free (strtab);
   6394 		  strtab = NULL;
   6395 		  strtab_size = 0;
   6396 		}
   6397 	      else if (strtab_sec
   6398 		       != (sec = section_headers + symtab_sec->sh_link))
   6399 		{
   6400 		  strtab_sec = sec;
   6401 		  if (strtab)
   6402 		    free (strtab);
   6403 
   6404 		  strtab = (char *) get_data (NULL, file, strtab_sec->sh_offset,
   6405 					      1, strtab_sec->sh_size,
   6406 					      _("string table"));
   6407 		  strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
   6408 		}
   6409 	      group_name = sym->st_name < strtab_size
   6410 		? strtab + sym->st_name : _("<corrupt>");
   6411 	    }
   6412 
   6413 	  /* PR 17531: file: loop.  */
   6414 	  if (section->sh_entsize > section->sh_size)
   6415 	    {
   6416 	      error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
   6417 		     printable_section_name (section),
   6418 		     (unsigned long) section->sh_entsize,
   6419 		     (unsigned long) section->sh_size);
   6420 	      break;
   6421 	    }
   6422 
   6423 	  start = (unsigned char *) get_data (NULL, file, section->sh_offset,
   6424                                               1, section->sh_size,
   6425                                               _("section data"));
   6426 	  if (start == NULL)
   6427 	    continue;
   6428 
   6429 	  indices = start;
   6430 	  size = (section->sh_size / section->sh_entsize) - 1;
   6431 	  entry = byte_get (indices, 4);
   6432 	  indices += 4;
   6433 
   6434 	  if (do_section_groups)
   6435 	    {
   6436 	      printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
   6437 		      get_group_flags (entry), i, name, group_name, size);
   6438 
   6439 	      printf (_("   [Index]    Name\n"));
   6440 	    }
   6441 
   6442 	  group->group_index = i;
   6443 
   6444 	  for (j = 0; j < size; j++)
   6445 	    {
   6446 	      struct group_list * g;
   6447 
   6448 	      entry = byte_get (indices, 4);
   6449 	      indices += 4;
   6450 
   6451 	      if (entry >= elf_header.e_shnum)
   6452 		{
   6453 		  static unsigned num_group_errors = 0;
   6454 
   6455 		  if (num_group_errors ++ < 10)
   6456 		    {
   6457 		      error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
   6458 			     entry, i, elf_header.e_shnum - 1);
   6459 		      if (num_group_errors == 10)
   6460 			warn (_("Futher error messages about overlarge group section indicies suppressed\n"));
   6461 		    }
   6462 		  continue;
   6463 		}
   6464 
   6465 	      if (section_headers_groups [entry] != NULL)
   6466 		{
   6467 		  if (entry)
   6468 		    {
   6469 		      static unsigned num_errs = 0;
   6470 
   6471 		      if (num_errs ++ < 10)
   6472 			{
   6473 			  error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
   6474 				 entry, i,
   6475 				 section_headers_groups [entry]->group_index);
   6476 			  if (num_errs == 10)
   6477 			    warn (_("Further error messages about already contained group sections suppressed\n"));
   6478 			}
   6479 		      continue;
   6480 		    }
   6481 		  else
   6482 		    {
   6483 		      /* Intel C/C++ compiler may put section 0 in a
   6484 			 section group. We just warn it the first time
   6485 			 and ignore it afterwards.  */
   6486 		      static int warned = 0;
   6487 		      if (!warned)
   6488 			{
   6489 			  error (_("section 0 in group section [%5u]\n"),
   6490 				 section_headers_groups [entry]->group_index);
   6491 			  warned++;
   6492 			}
   6493 		    }
   6494 		}
   6495 
   6496 	      section_headers_groups [entry] = group;
   6497 
   6498 	      if (do_section_groups)
   6499 		{
   6500 		  sec = section_headers + entry;
   6501 		  printf ("   [%5u]   %s\n", entry, printable_section_name (sec));
   6502 		}
   6503 
   6504 	      g = (struct group_list *) xmalloc (sizeof (struct group_list));
   6505 	      g->section_index = entry;
   6506 	      g->next = group->root;
   6507 	      group->root = g;
   6508 	    }
   6509 
   6510 	  if (start)
   6511 	    free (start);
   6512 
   6513 	  group++;
   6514 	}
   6515     }
   6516 
   6517   if (symtab)
   6518     free (symtab);
   6519   if (strtab)
   6520     free (strtab);
   6521   return 1;
   6522 }
   6523 
   6524 /* Data used to display dynamic fixups.  */
   6525 
   6526 struct ia64_vms_dynfixup
   6527 {
   6528   bfd_vma needed_ident;		/* Library ident number.  */
   6529   bfd_vma needed;		/* Index in the dstrtab of the library name.  */
   6530   bfd_vma fixup_needed;		/* Index of the library.  */
   6531   bfd_vma fixup_rela_cnt;	/* Number of fixups.  */
   6532   bfd_vma fixup_rela_off;	/* Fixups offset in the dynamic segment.  */
   6533 };
   6534 
   6535 /* Data used to display dynamic relocations.  */
   6536 
   6537 struct ia64_vms_dynimgrela
   6538 {
   6539   bfd_vma img_rela_cnt;		/* Number of relocations.  */
   6540   bfd_vma img_rela_off;		/* Reloc offset in the dynamic segment.  */
   6541 };
   6542 
   6543 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
   6544    library).  */
   6545 
   6546 static void
   6547 dump_ia64_vms_dynamic_fixups (FILE *file, struct ia64_vms_dynfixup *fixup,
   6548                               const char *strtab, unsigned int strtab_sz)
   6549 {
   6550   Elf64_External_VMS_IMAGE_FIXUP *imfs;
   6551   long i;
   6552   const char *lib_name;
   6553 
   6554   imfs = get_data (NULL, file, dynamic_addr + fixup->fixup_rela_off,
   6555 		   1, fixup->fixup_rela_cnt * sizeof (*imfs),
   6556 		   _("dynamic section image fixups"));
   6557   if (!imfs)
   6558     return;
   6559 
   6560   if (fixup->needed < strtab_sz)
   6561     lib_name = strtab + fixup->needed;
   6562   else
   6563     {
   6564       warn ("corrupt library name index of 0x%lx found in dynamic entry",
   6565             (unsigned long) fixup->needed);
   6566       lib_name = "???";
   6567     }
   6568   printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
   6569 	  (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
   6570   printf
   6571     (_("Seg Offset           Type                             SymVec DataType\n"));
   6572 
   6573   for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
   6574     {
   6575       unsigned int type;
   6576       const char *rtype;
   6577 
   6578       printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
   6579       printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
   6580       type = BYTE_GET (imfs [i].type);
   6581       rtype = elf_ia64_reloc_type (type);
   6582       if (rtype == NULL)
   6583         printf (" 0x%08x                       ", type);
   6584       else
   6585         printf (" %-32s ", rtype);
   6586       printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
   6587       printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
   6588     }
   6589 
   6590   free (imfs);
   6591 }
   6592 
   6593 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image).  */
   6594 
   6595 static void
   6596 dump_ia64_vms_dynamic_relocs (FILE *file, struct ia64_vms_dynimgrela *imgrela)
   6597 {
   6598   Elf64_External_VMS_IMAGE_RELA *imrs;
   6599   long i;
   6600 
   6601   imrs = get_data (NULL, file, dynamic_addr + imgrela->img_rela_off,
   6602 		   1, imgrela->img_rela_cnt * sizeof (*imrs),
   6603 		   _("dynamic section image relocations"));
   6604   if (!imrs)
   6605     return;
   6606 
   6607   printf (_("\nImage relocs\n"));
   6608   printf
   6609     (_("Seg Offset   Type                            Addend            Seg Sym Off\n"));
   6610 
   6611   for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
   6612     {
   6613       unsigned int type;
   6614       const char *rtype;
   6615 
   6616       printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
   6617       printf ("%08" BFD_VMA_FMT "x ",
   6618               (bfd_vma) BYTE_GET (imrs [i].rela_offset));
   6619       type = BYTE_GET (imrs [i].type);
   6620       rtype = elf_ia64_reloc_type (type);
   6621       if (rtype == NULL)
   6622         printf ("0x%08x                      ", type);
   6623       else
   6624         printf ("%-31s ", rtype);
   6625       print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
   6626       printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
   6627       printf ("%08" BFD_VMA_FMT "x\n",
   6628               (bfd_vma) BYTE_GET (imrs [i].sym_offset));
   6629     }
   6630 
   6631   free (imrs);
   6632 }
   6633 
   6634 /* Display IA-64 OpenVMS dynamic relocations and fixups.  */
   6635 
   6636 static int
   6637 process_ia64_vms_dynamic_relocs (FILE *file)
   6638 {
   6639   struct ia64_vms_dynfixup fixup;
   6640   struct ia64_vms_dynimgrela imgrela;
   6641   Elf_Internal_Dyn *entry;
   6642   int res = 0;
   6643   bfd_vma strtab_off = 0;
   6644   bfd_vma strtab_sz = 0;
   6645   char *strtab = NULL;
   6646 
   6647   memset (&fixup, 0, sizeof (fixup));
   6648   memset (&imgrela, 0, sizeof (imgrela));
   6649 
   6650   /* Note: the order of the entries is specified by the OpenVMS specs.  */
   6651   for (entry = dynamic_section;
   6652        entry < dynamic_section + dynamic_nent;
   6653        entry++)
   6654     {
   6655       switch (entry->d_tag)
   6656         {
   6657         case DT_IA_64_VMS_STRTAB_OFFSET:
   6658           strtab_off = entry->d_un.d_val;
   6659           break;
   6660         case DT_STRSZ:
   6661           strtab_sz = entry->d_un.d_val;
   6662           if (strtab == NULL)
   6663             strtab = get_data (NULL, file, dynamic_addr + strtab_off,
   6664                                1, strtab_sz, _("dynamic string section"));
   6665           break;
   6666 
   6667         case DT_IA_64_VMS_NEEDED_IDENT:
   6668           fixup.needed_ident = entry->d_un.d_val;
   6669           break;
   6670         case DT_NEEDED:
   6671           fixup.needed = entry->d_un.d_val;
   6672           break;
   6673         case DT_IA_64_VMS_FIXUP_NEEDED:
   6674           fixup.fixup_needed = entry->d_un.d_val;
   6675           break;
   6676         case DT_IA_64_VMS_FIXUP_RELA_CNT:
   6677           fixup.fixup_rela_cnt = entry->d_un.d_val;
   6678           break;
   6679         case DT_IA_64_VMS_FIXUP_RELA_OFF:
   6680           fixup.fixup_rela_off = entry->d_un.d_val;
   6681           res++;
   6682           dump_ia64_vms_dynamic_fixups (file, &fixup, strtab, strtab_sz);
   6683           break;
   6684 
   6685         case DT_IA_64_VMS_IMG_RELA_CNT:
   6686 	  imgrela.img_rela_cnt = entry->d_un.d_val;
   6687           break;
   6688         case DT_IA_64_VMS_IMG_RELA_OFF:
   6689 	  imgrela.img_rela_off = entry->d_un.d_val;
   6690           res++;
   6691           dump_ia64_vms_dynamic_relocs (file, &imgrela);
   6692           break;
   6693 
   6694         default:
   6695           break;
   6696 	}
   6697     }
   6698 
   6699   if (strtab != NULL)
   6700     free (strtab);
   6701 
   6702   return res;
   6703 }
   6704 
   6705 static struct
   6706 {
   6707   const char * name;
   6708   int reloc;
   6709   int size;
   6710   int rela;
   6711   int relr;
   6712 } dynamic_relocations [] =
   6713 {
   6714     { "REL", DT_REL, DT_RELSZ, FALSE, FALSE },
   6715     { "RELA", DT_RELA, DT_RELASZ, TRUE, FALSE },
   6716     { "RELR", DT_RELR, DT_RELRSZ, FALSE, TRUE },
   6717     { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN, FALSE }
   6718 };
   6719 
   6720 /* Process the reloc section.  */
   6721 
   6722 static int
   6723 process_relocs (FILE * file)
   6724 {
   6725   unsigned long rel_size;
   6726   unsigned long rel_offset;
   6727 
   6728 
   6729   if (!do_reloc)
   6730     return 1;
   6731 
   6732   if (do_using_dynamic)
   6733     {
   6734       int is_rela, is_relr;
   6735       const char * name;
   6736       int has_dynamic_reloc;
   6737       unsigned int i;
   6738 
   6739       has_dynamic_reloc = 0;
   6740 
   6741       for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
   6742 	{
   6743 	  is_rela = dynamic_relocations [i].rela;
   6744 	  is_relr = dynamic_relocations [i].relr;
   6745 	  name = dynamic_relocations [i].name;
   6746 	  rel_size = dynamic_info [dynamic_relocations [i].size];
   6747 	  rel_offset = dynamic_info [dynamic_relocations [i].reloc];
   6748 
   6749 	  has_dynamic_reloc |= rel_size;
   6750 
   6751 	  if (is_rela == UNKNOWN)
   6752 	    {
   6753 	      if (dynamic_relocations [i].reloc == DT_JMPREL)
   6754 		switch (dynamic_info[DT_PLTREL])
   6755 		  {
   6756 		  case DT_REL:
   6757 		    is_rela = FALSE;
   6758 		    break;
   6759 		  case DT_RELA:
   6760 		    is_rela = TRUE;
   6761 		    break;
   6762 		  }
   6763 	    }
   6764 
   6765 	  if (rel_size)
   6766 	    {
   6767 	      printf
   6768 		(_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
   6769 		 name, rel_offset, rel_size);
   6770 
   6771 	      dump_relocations (file,
   6772 				offset_from_vma (file, rel_offset, rel_size),
   6773 				rel_size,
   6774 				dynamic_symbols, num_dynamic_syms,
   6775 				dynamic_strings, dynamic_strings_length,
   6776 				is_rela, is_relr, 1);
   6777 	    }
   6778 	}
   6779 
   6780       if (is_ia64_vms ())
   6781         has_dynamic_reloc |= process_ia64_vms_dynamic_relocs (file);
   6782 
   6783       if (! has_dynamic_reloc)
   6784 	printf (_("\nThere are no dynamic relocations in this file.\n"));
   6785     }
   6786   else
   6787     {
   6788       Elf_Internal_Shdr * section;
   6789       unsigned long i;
   6790       int found = 0;
   6791 
   6792       for (i = 0, section = section_headers;
   6793 	   i < elf_header.e_shnum;
   6794 	   i++, section++)
   6795 	{
   6796 	  if (   section->sh_type != SHT_RELA
   6797 	      && section->sh_type != SHT_REL
   6798 	      && section->sh_type != SHT_RELR)
   6799 	    continue;
   6800 
   6801 	  rel_offset = section->sh_offset;
   6802 	  rel_size   = section->sh_size;
   6803 
   6804 	  if (rel_size)
   6805 	    {
   6806 	      Elf_Internal_Shdr * strsec;
   6807 	      int is_rela, is_relr;
   6808 
   6809 	      printf (_("\nRelocation section "));
   6810 
   6811 	      if (string_table == NULL)
   6812 		printf ("%d", section->sh_name);
   6813 	      else
   6814 		printf ("'%s'", printable_section_name (section));
   6815 
   6816 	      printf (_(" at offset 0x%lx contains %lu entries:\n"),
   6817 		 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
   6818 
   6819 	      is_rela = section->sh_type == SHT_RELA;
   6820 	      is_relr = section->sh_type == SHT_RELR;
   6821 
   6822 	      if (section->sh_link != 0
   6823 		  && section->sh_link < elf_header.e_shnum)
   6824 		{
   6825 		  Elf_Internal_Shdr * symsec;
   6826 		  Elf_Internal_Sym *  symtab;
   6827 		  unsigned long nsyms;
   6828 		  unsigned long strtablen = 0;
   6829 		  char * strtab = NULL;
   6830 
   6831 		  symsec = section_headers + section->sh_link;
   6832 		  if (symsec->sh_type != SHT_SYMTAB
   6833 		      && symsec->sh_type != SHT_DYNSYM)
   6834                     continue;
   6835 
   6836 		  symtab = GET_ELF_SYMBOLS (file, symsec, & nsyms);
   6837 
   6838 		  if (symtab == NULL)
   6839 		    continue;
   6840 
   6841 		  if (symsec->sh_link != 0
   6842 		      && symsec->sh_link < elf_header.e_shnum)
   6843 		    {
   6844 		      strsec = section_headers + symsec->sh_link;
   6845 
   6846 		      strtab = (char *) get_data (NULL, file, strsec->sh_offset,
   6847 						  1, strsec->sh_size,
   6848 						  _("string table"));
   6849 		      strtablen = strtab == NULL ? 0 : strsec->sh_size;
   6850 		    }
   6851 
   6852 		  dump_relocations (file, rel_offset, rel_size,
   6853 				    symtab, nsyms, strtab, strtablen,
   6854 				    is_rela, is_relr,
   6855 				    symsec->sh_type == SHT_DYNSYM);
   6856 		  if (strtab)
   6857 		    free (strtab);
   6858 		  free (symtab);
   6859 		}
   6860 	      else
   6861 		dump_relocations (file, rel_offset, rel_size,
   6862 				  NULL, 0, NULL, 0,
   6863 				  is_rela, is_relr,
   6864 				  0);
   6865 
   6866 	      found = 1;
   6867 	    }
   6868 	}
   6869 
   6870       if (! found)
   6871 	printf (_("\nThere are no relocations in this file.\n"));
   6872     }
   6873 
   6874   return 1;
   6875 }
   6876 
   6877 /* An absolute address consists of a section and an offset.  If the
   6878    section is NULL, the offset itself is the address, otherwise, the
   6879    address equals to LOAD_ADDRESS(section) + offset.  */
   6880 
   6881 struct absaddr
   6882 {
   6883   unsigned short section;
   6884   bfd_vma offset;
   6885 };
   6886 
   6887 #define ABSADDR(a) \
   6888   ((a).section \
   6889    ? section_headers [(a).section].sh_addr + (a).offset \
   6890    : (a).offset)
   6891 
   6892 /* Find the nearest symbol at or below ADDR.  Returns the symbol
   6893    name, if found, and the offset from the symbol to ADDR.  */
   6894 
   6895 static void
   6896 find_symbol_for_address (Elf_Internal_Sym * symtab,
   6897 			 unsigned long      nsyms,
   6898 			 const char *       strtab,
   6899 			 unsigned long      strtab_size,
   6900 			 struct absaddr     addr,
   6901 			 const char **      symname,
   6902 			 bfd_vma *          offset)
   6903 {
   6904   bfd_vma dist = 0x100000;
   6905   Elf_Internal_Sym * sym;
   6906   Elf_Internal_Sym * beg;
   6907   Elf_Internal_Sym * end;
   6908   Elf_Internal_Sym * best = NULL;
   6909 
   6910   REMOVE_ARCH_BITS (addr.offset);
   6911   beg = symtab;
   6912   end = symtab + nsyms;
   6913 
   6914   while (beg < end)
   6915     {
   6916       bfd_vma value;
   6917 
   6918       sym = beg + (end - beg) / 2;
   6919 
   6920       value = sym->st_value;
   6921       REMOVE_ARCH_BITS (value);
   6922 
   6923       if (sym->st_name != 0
   6924 	  && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
   6925 	  && addr.offset >= value
   6926 	  && addr.offset - value < dist)
   6927 	{
   6928 	  best = sym;
   6929 	  dist = addr.offset - value;
   6930 	  if (!dist)
   6931 	    break;
   6932 	}
   6933 
   6934       if (addr.offset < value)
   6935 	end = sym;
   6936       else
   6937 	beg = sym + 1;
   6938     }
   6939 
   6940   if (best)
   6941     {
   6942       *symname = (best->st_name >= strtab_size
   6943 		  ? _("<corrupt>") : strtab + best->st_name);
   6944       *offset = dist;
   6945       return;
   6946     }
   6947 
   6948   *symname = NULL;
   6949   *offset = addr.offset;
   6950 }
   6951 
   6952 static int
   6953 symcmp (const void *p, const void *q)
   6954 {
   6955   Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p;
   6956   Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q;
   6957 
   6958   return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
   6959 }
   6960 
   6961 /* Process the unwind section.  */
   6962 
   6963 #include "unwind-ia64.h"
   6964 
   6965 struct ia64_unw_table_entry
   6966 {
   6967   struct absaddr start;
   6968   struct absaddr end;
   6969   struct absaddr info;
   6970 };
   6971 
   6972 struct ia64_unw_aux_info
   6973 {
   6974   struct ia64_unw_table_entry *table;	/* Unwind table.  */
   6975   unsigned long table_len;		/* Length of unwind table.  */
   6976   unsigned char * info;			/* Unwind info.  */
   6977   unsigned long info_size;		/* Size of unwind info.  */
   6978   bfd_vma info_addr;			/* Starting address of unwind info.  */
   6979   bfd_vma seg_base;			/* Starting address of segment.  */
   6980   Elf_Internal_Sym * symtab;		/* The symbol table.  */
   6981   unsigned long nsyms;			/* Number of symbols.  */
   6982   Elf_Internal_Sym * funtab;		/* Sorted table of STT_FUNC symbols.  */
   6983   unsigned long nfuns;			/* Number of entries in funtab.  */
   6984   char * strtab;			/* The string table.  */
   6985   unsigned long strtab_size;		/* Size of string table.  */
   6986 };
   6987 
   6988 static void
   6989 dump_ia64_unwind (struct ia64_unw_aux_info * aux)
   6990 {
   6991   struct ia64_unw_table_entry * tp;
   6992   unsigned long j, nfuns;
   6993   int in_body;
   6994 
   6995   aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
   6996   for (nfuns = 0, j = 0; j < aux->nsyms; j++)
   6997     if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
   6998       aux->funtab[nfuns++] = aux->symtab[j];
   6999   aux->nfuns = nfuns;
   7000   qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
   7001 
   7002   for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
   7003     {
   7004       bfd_vma stamp;
   7005       bfd_vma offset;
   7006       const unsigned char * dp;
   7007       const unsigned char * head;
   7008       const unsigned char * end;
   7009       const char * procname;
   7010 
   7011       find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab,
   7012 			       aux->strtab_size, tp->start, &procname, &offset);
   7013 
   7014       fputs ("\n<", stdout);
   7015 
   7016       if (procname)
   7017 	{
   7018 	  fputs (procname, stdout);
   7019 
   7020 	  if (offset)
   7021 	    printf ("+%lx", (unsigned long) offset);
   7022 	}
   7023 
   7024       fputs (">: [", stdout);
   7025       print_vma (tp->start.offset, PREFIX_HEX);
   7026       fputc ('-', stdout);
   7027       print_vma (tp->end.offset, PREFIX_HEX);
   7028       printf ("], info at +0x%lx\n",
   7029 	      (unsigned long) (tp->info.offset - aux->seg_base));
   7030 
   7031       /* PR 17531: file: 86232b32.  */
   7032       if (aux->info == NULL)
   7033 	continue;
   7034 
   7035       /* PR 17531: file: 0997b4d1.  */
   7036       if ((ABSADDR (tp->info) - aux->info_addr) >= aux->info_size)
   7037 	{
   7038 	  warn (_("Invalid offset %lx in table entry %ld\n"),
   7039 		(long) tp->info.offset, (long) (tp - aux->table));
   7040 	  continue;
   7041 	}
   7042 
   7043       head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
   7044       stamp = byte_get ((unsigned char *) head, sizeof (stamp));
   7045 
   7046       printf ("  v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
   7047 	      (unsigned) UNW_VER (stamp),
   7048 	      (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
   7049 	      UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
   7050 	      UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
   7051 	      (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
   7052 
   7053       if (UNW_VER (stamp) != 1)
   7054 	{
   7055 	  printf (_("\tUnknown version.\n"));
   7056 	  continue;
   7057 	}
   7058 
   7059       in_body = 0;
   7060       end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
   7061       /* PR 17531: file: 16ceda89.  */
   7062       if (end > aux->info + aux->info_size)
   7063 	end = aux->info + aux->info_size;
   7064       for (dp = head + 8; dp < end;)
   7065 	dp = unw_decode (dp, in_body, & in_body, end);
   7066     }
   7067 
   7068   free (aux->funtab);
   7069 }
   7070 
   7071 static bfd_boolean
   7072 slurp_ia64_unwind_table (FILE * file,
   7073 			 struct ia64_unw_aux_info * aux,
   7074 			 Elf_Internal_Shdr * sec)
   7075 {
   7076   unsigned long size, nrelas, i;
   7077   Elf_Internal_Phdr * seg;
   7078   struct ia64_unw_table_entry * tep;
   7079   Elf_Internal_Shdr * relsec;
   7080   Elf_Internal_Rela * rela;
   7081   Elf_Internal_Rela * rp;
   7082   unsigned char * table;
   7083   unsigned char * tp;
   7084   Elf_Internal_Sym * sym;
   7085   const char * relname;
   7086 
   7087   aux->table_len = 0;
   7088 
   7089   /* First, find the starting address of the segment that includes
   7090      this section: */
   7091 
   7092   if (elf_header.e_phnum)
   7093     {
   7094       if (! get_program_headers (file))
   7095 	  return FALSE;
   7096 
   7097       for (seg = program_headers;
   7098 	   seg < program_headers + elf_header.e_phnum;
   7099 	   ++seg)
   7100 	{
   7101 	  if (seg->p_type != PT_LOAD)
   7102 	    continue;
   7103 
   7104 	  if (sec->sh_addr >= seg->p_vaddr
   7105 	      && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
   7106 	    {
   7107 	      aux->seg_base = seg->p_vaddr;
   7108 	      break;
   7109 	    }
   7110 	}
   7111     }
   7112 
   7113   /* Second, build the unwind table from the contents of the unwind section:  */
   7114   size = sec->sh_size;
   7115   table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
   7116                                       _("unwind table"));
   7117   if (!table)
   7118     return FALSE;
   7119 
   7120   aux->table_len = size / (3 * eh_addr_size);
   7121   aux->table = (struct ia64_unw_table_entry *)
   7122     xcmalloc (aux->table_len, sizeof (aux->table[0]));
   7123   tep = aux->table;
   7124 
   7125   for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
   7126     {
   7127       tep->start.section = SHN_UNDEF;
   7128       tep->end.section   = SHN_UNDEF;
   7129       tep->info.section  = SHN_UNDEF;
   7130       tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
   7131       tep->end.offset   = byte_get (tp, eh_addr_size); tp += eh_addr_size;
   7132       tep->info.offset  = byte_get (tp, eh_addr_size); tp += eh_addr_size;
   7133       tep->start.offset += aux->seg_base;
   7134       tep->end.offset   += aux->seg_base;
   7135       tep->info.offset  += aux->seg_base;
   7136     }
   7137   free (table);
   7138 
   7139   /* Third, apply any relocations to the unwind table:  */
   7140   for (relsec = section_headers;
   7141        relsec < section_headers + elf_header.e_shnum;
   7142        ++relsec)
   7143     {
   7144       if (relsec->sh_type != SHT_RELA
   7145 	  || relsec->sh_info >= elf_header.e_shnum
   7146 	  || section_headers + relsec->sh_info != sec)
   7147 	continue;
   7148 
   7149       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
   7150 			      & rela, & nrelas))
   7151 	{
   7152 	  free (aux->table);
   7153 	  aux->table = NULL;
   7154 	  aux->table_len = 0;
   7155 	  return FALSE;
   7156 	}
   7157 
   7158       for (rp = rela; rp < rela + nrelas; ++rp)
   7159 	{
   7160 	  relname = elf_ia64_reloc_type (get_reloc_type (rp->r_info));
   7161 	  sym = aux->symtab + get_reloc_symindex (rp->r_info);
   7162 
   7163 	  /* PR 17531: file: 9fa67536.  */
   7164 	  if (relname == NULL)
   7165 	    {
   7166 	      warn (_("Skipping unknown relocation type: %u\n"), get_reloc_type (rp->r_info));
   7167 	      continue;
   7168 	    }
   7169 
   7170 	  if (! const_strneq (relname, "R_IA64_SEGREL"))
   7171 	    {
   7172 	      warn (_("Skipping unexpected relocation type: %s\n"), relname);
   7173 	      continue;
   7174 	    }
   7175 
   7176 	  i = rp->r_offset / (3 * eh_addr_size);
   7177 
   7178 	  /* PR 17531: file: 5bc8d9bf.  */
   7179 	  if (i >= aux->table_len)
   7180 	    {
   7181 	      warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
   7182 	      continue;
   7183 	    }
   7184 
   7185 	  switch (rp->r_offset / eh_addr_size % 3)
   7186 	    {
   7187 	    case 0:
   7188 	      aux->table[i].start.section = sym->st_shndx;
   7189 	      aux->table[i].start.offset  = rp->r_addend + sym->st_value;
   7190 	      break;
   7191 	    case 1:
   7192 	      aux->table[i].end.section   = sym->st_shndx;
   7193 	      aux->table[i].end.offset    = rp->r_addend + sym->st_value;
   7194 	      break;
   7195 	    case 2:
   7196 	      aux->table[i].info.section  = sym->st_shndx;
   7197 	      aux->table[i].info.offset   = rp->r_addend + sym->st_value;
   7198 	      break;
   7199 	    default:
   7200 	      break;
   7201 	    }
   7202 	}
   7203 
   7204       free (rela);
   7205     }
   7206 
   7207   return TRUE;
   7208 }
   7209 
   7210 static void
   7211 ia64_process_unwind (FILE * file)
   7212 {
   7213   Elf_Internal_Shdr * sec;
   7214   Elf_Internal_Shdr * unwsec = NULL;
   7215   Elf_Internal_Shdr * strsec;
   7216   unsigned long i, unwcount = 0, unwstart = 0;
   7217   struct ia64_unw_aux_info aux;
   7218 
   7219   memset (& aux, 0, sizeof (aux));
   7220 
   7221   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   7222     {
   7223       if (sec->sh_type == SHT_SYMTAB
   7224 	  && sec->sh_link < elf_header.e_shnum)
   7225 	{
   7226 	  aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
   7227 
   7228 	  strsec = section_headers + sec->sh_link;
   7229 	  if (aux.strtab != NULL)
   7230 	    {
   7231 	      error (_("Multiple auxillary string tables encountered\n"));
   7232 	      free (aux.strtab);
   7233 	    }
   7234 	  aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
   7235                                           1, strsec->sh_size,
   7236                                           _("string table"));
   7237 	  aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
   7238 	}
   7239       else if (sec->sh_type == SHT_IA_64_UNWIND)
   7240 	unwcount++;
   7241     }
   7242 
   7243   if (!unwcount)
   7244     printf (_("\nThere are no unwind sections in this file.\n"));
   7245 
   7246   while (unwcount-- > 0)
   7247     {
   7248       char * suffix;
   7249       size_t len, len2;
   7250 
   7251       for (i = unwstart, sec = section_headers + unwstart, unwsec = NULL;
   7252 	   i < elf_header.e_shnum; ++i, ++sec)
   7253 	if (sec->sh_type == SHT_IA_64_UNWIND)
   7254 	  {
   7255 	    unwsec = sec;
   7256 	    break;
   7257 	  }
   7258       /* We have already counted the number of SHT_IA64_UNWIND
   7259 	 sections so the loop above should never fail.  */
   7260       assert (unwsec != NULL);
   7261 
   7262       unwstart = i + 1;
   7263       len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
   7264 
   7265       if ((unwsec->sh_flags & SHF_GROUP) != 0)
   7266 	{
   7267 	  /* We need to find which section group it is in.  */
   7268 	  struct group_list * g;
   7269 
   7270 	  if (section_headers_groups == NULL
   7271 	      || section_headers_groups [i] == NULL)
   7272 	    i = elf_header.e_shnum;
   7273 	  else
   7274 	    {
   7275 	      g = section_headers_groups [i]->root;
   7276 
   7277 	      for (; g != NULL; g = g->next)
   7278 		{
   7279 		  sec = section_headers + g->section_index;
   7280 
   7281 		  if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
   7282 		    break;
   7283 		}
   7284 
   7285 	      if (g == NULL)
   7286 		i = elf_header.e_shnum;
   7287 	    }
   7288 	}
   7289       else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
   7290 	{
   7291 	  /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO.  */
   7292 	  len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
   7293 	  suffix = SECTION_NAME (unwsec) + len;
   7294 	  for (i = 0, sec = section_headers; i < elf_header.e_shnum;
   7295 	       ++i, ++sec)
   7296 	    if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
   7297 		&& streq (SECTION_NAME (sec) + len2, suffix))
   7298 	      break;
   7299 	}
   7300       else
   7301 	{
   7302 	  /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
   7303 	     .IA_64.unwind or BAR -> .IA_64.unwind_info.  */
   7304 	  len = sizeof (ELF_STRING_ia64_unwind) - 1;
   7305 	  len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
   7306 	  suffix = "";
   7307 	  if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
   7308 	    suffix = SECTION_NAME (unwsec) + len;
   7309 	  for (i = 0, sec = section_headers; i < elf_header.e_shnum;
   7310 	       ++i, ++sec)
   7311 	    if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
   7312 		&& streq (SECTION_NAME (sec) + len2, suffix))
   7313 	      break;
   7314 	}
   7315 
   7316       if (i == elf_header.e_shnum)
   7317 	{
   7318 	  printf (_("\nCould not find unwind info section for "));
   7319 
   7320 	  if (string_table == NULL)
   7321 	    printf ("%d", unwsec->sh_name);
   7322 	  else
   7323 	    printf ("'%s'", printable_section_name (unwsec));
   7324 	}
   7325       else
   7326 	{
   7327 	  aux.info_addr = sec->sh_addr;
   7328 	  aux.info = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1,
   7329 						 sec->sh_size,
   7330 						 _("unwind info"));
   7331 	  aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
   7332 
   7333 	  printf (_("\nUnwind section "));
   7334 
   7335 	  if (string_table == NULL)
   7336 	    printf ("%d", unwsec->sh_name);
   7337 	  else
   7338 	    printf ("'%s'", printable_section_name (unwsec));
   7339 
   7340 	  printf (_(" at offset 0x%lx contains %lu entries:\n"),
   7341 		  (unsigned long) unwsec->sh_offset,
   7342 		  (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
   7343 
   7344 	  if (slurp_ia64_unwind_table (file, & aux, unwsec)
   7345 	      && aux.table_len > 0)
   7346 	    dump_ia64_unwind (& aux);
   7347 
   7348 	  if (aux.table)
   7349 	    free ((char *) aux.table);
   7350 	  if (aux.info)
   7351 	    free ((char *) aux.info);
   7352 	  aux.table = NULL;
   7353 	  aux.info = NULL;
   7354 	}
   7355     }
   7356 
   7357   if (aux.symtab)
   7358     free (aux.symtab);
   7359   if (aux.strtab)
   7360     free ((char *) aux.strtab);
   7361 }
   7362 
   7363 struct hppa_unw_table_entry
   7364   {
   7365     struct absaddr start;
   7366     struct absaddr end;
   7367     unsigned int Cannot_unwind:1;		/* 0 */
   7368     unsigned int Millicode:1;			/* 1 */
   7369     unsigned int Millicode_save_sr0:1;		/* 2 */
   7370     unsigned int Region_description:2;		/* 3..4 */
   7371     unsigned int reserved1:1;			/* 5 */
   7372     unsigned int Entry_SR:1;			/* 6 */
   7373     unsigned int Entry_FR:4;     /* number saved */	/* 7..10 */
   7374     unsigned int Entry_GR:5;     /* number saved */	/* 11..15 */
   7375     unsigned int Args_stored:1;			/* 16 */
   7376     unsigned int Variable_Frame:1;		/* 17 */
   7377     unsigned int Separate_Package_Body:1;	/* 18 */
   7378     unsigned int Frame_Extension_Millicode:1;	/* 19 */
   7379     unsigned int Stack_Overflow_Check:1;	/* 20 */
   7380     unsigned int Two_Instruction_SP_Increment:1;/* 21 */
   7381     unsigned int Ada_Region:1;			/* 22 */
   7382     unsigned int cxx_info:1;			/* 23 */
   7383     unsigned int cxx_try_catch:1;		/* 24 */
   7384     unsigned int sched_entry_seq:1;		/* 25 */
   7385     unsigned int reserved2:1;			/* 26 */
   7386     unsigned int Save_SP:1;			/* 27 */
   7387     unsigned int Save_RP:1;			/* 28 */
   7388     unsigned int Save_MRP_in_frame:1;		/* 29 */
   7389     unsigned int extn_ptr_defined:1;		/* 30 */
   7390     unsigned int Cleanup_defined:1;		/* 31 */
   7391 
   7392     unsigned int MPE_XL_interrupt_marker:1;	/* 0 */
   7393     unsigned int HP_UX_interrupt_marker:1;	/* 1 */
   7394     unsigned int Large_frame:1;			/* 2 */
   7395     unsigned int Pseudo_SP_Set:1;		/* 3 */
   7396     unsigned int reserved4:1;			/* 4 */
   7397     unsigned int Total_frame_size:27;		/* 5..31 */
   7398   };
   7399 
   7400 struct hppa_unw_aux_info
   7401 {
   7402   struct hppa_unw_table_entry * table;	/* Unwind table.  */
   7403   unsigned long table_len;		/* Length of unwind table.  */
   7404   bfd_vma seg_base;			/* Starting address of segment.  */
   7405   Elf_Internal_Sym * symtab;		/* The symbol table.  */
   7406   unsigned long nsyms;			/* Number of symbols.  */
   7407   Elf_Internal_Sym * funtab;		/* Sorted table of STT_FUNC symbols.  */
   7408   unsigned long nfuns;			/* Number of entries in funtab.  */
   7409   char * strtab;			/* The string table.  */
   7410   unsigned long strtab_size;		/* Size of string table.  */
   7411 };
   7412 
   7413 static void
   7414 dump_hppa_unwind (struct hppa_unw_aux_info * aux)
   7415 {
   7416   struct hppa_unw_table_entry * tp;
   7417   unsigned long j, nfuns;
   7418 
   7419   aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
   7420   for (nfuns = 0, j = 0; j < aux->nsyms; j++)
   7421     if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
   7422       aux->funtab[nfuns++] = aux->symtab[j];
   7423   aux->nfuns = nfuns;
   7424   qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
   7425 
   7426   for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
   7427     {
   7428       bfd_vma offset;
   7429       const char * procname;
   7430 
   7431       find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab,
   7432 			       aux->strtab_size, tp->start, &procname,
   7433 			       &offset);
   7434 
   7435       fputs ("\n<", stdout);
   7436 
   7437       if (procname)
   7438 	{
   7439 	  fputs (procname, stdout);
   7440 
   7441 	  if (offset)
   7442 	    printf ("+%lx", (unsigned long) offset);
   7443 	}
   7444 
   7445       fputs (">: [", stdout);
   7446       print_vma (tp->start.offset, PREFIX_HEX);
   7447       fputc ('-', stdout);
   7448       print_vma (tp->end.offset, PREFIX_HEX);
   7449       printf ("]\n\t");
   7450 
   7451 #define PF(_m) if (tp->_m) printf (#_m " ");
   7452 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
   7453       PF(Cannot_unwind);
   7454       PF(Millicode);
   7455       PF(Millicode_save_sr0);
   7456       /* PV(Region_description);  */
   7457       PF(Entry_SR);
   7458       PV(Entry_FR);
   7459       PV(Entry_GR);
   7460       PF(Args_stored);
   7461       PF(Variable_Frame);
   7462       PF(Separate_Package_Body);
   7463       PF(Frame_Extension_Millicode);
   7464       PF(Stack_Overflow_Check);
   7465       PF(Two_Instruction_SP_Increment);
   7466       PF(Ada_Region);
   7467       PF(cxx_info);
   7468       PF(cxx_try_catch);
   7469       PF(sched_entry_seq);
   7470       PF(Save_SP);
   7471       PF(Save_RP);
   7472       PF(Save_MRP_in_frame);
   7473       PF(extn_ptr_defined);
   7474       PF(Cleanup_defined);
   7475       PF(MPE_XL_interrupt_marker);
   7476       PF(HP_UX_interrupt_marker);
   7477       PF(Large_frame);
   7478       PF(Pseudo_SP_Set);
   7479       PV(Total_frame_size);
   7480 #undef PF
   7481 #undef PV
   7482     }
   7483 
   7484   printf ("\n");
   7485 
   7486   free (aux->funtab);
   7487 }
   7488 
   7489 static int
   7490 slurp_hppa_unwind_table (FILE * file,
   7491 			 struct hppa_unw_aux_info * aux,
   7492 			 Elf_Internal_Shdr * sec)
   7493 {
   7494   unsigned long size, unw_ent_size, nentries, nrelas, i;
   7495   Elf_Internal_Phdr * seg;
   7496   struct hppa_unw_table_entry * tep;
   7497   Elf_Internal_Shdr * relsec;
   7498   Elf_Internal_Rela * rela;
   7499   Elf_Internal_Rela * rp;
   7500   unsigned char * table;
   7501   unsigned char * tp;
   7502   Elf_Internal_Sym * sym;
   7503   const char * relname;
   7504 
   7505   /* First, find the starting address of the segment that includes
   7506      this section.  */
   7507 
   7508   if (elf_header.e_phnum)
   7509     {
   7510       if (! get_program_headers (file))
   7511 	return 0;
   7512 
   7513       for (seg = program_headers;
   7514 	   seg < program_headers + elf_header.e_phnum;
   7515 	   ++seg)
   7516 	{
   7517 	  if (seg->p_type != PT_LOAD)
   7518 	    continue;
   7519 
   7520 	  if (sec->sh_addr >= seg->p_vaddr
   7521 	      && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
   7522 	    {
   7523 	      aux->seg_base = seg->p_vaddr;
   7524 	      break;
   7525 	    }
   7526 	}
   7527     }
   7528 
   7529   /* Second, build the unwind table from the contents of the unwind
   7530      section.  */
   7531   size = sec->sh_size;
   7532   table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
   7533                                       _("unwind table"));
   7534   if (!table)
   7535     return 0;
   7536 
   7537   unw_ent_size = 16;
   7538   nentries = size / unw_ent_size;
   7539   size = unw_ent_size * nentries;
   7540 
   7541   tep = aux->table = (struct hppa_unw_table_entry *)
   7542       xcmalloc (nentries, sizeof (aux->table[0]));
   7543 
   7544   for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
   7545     {
   7546       unsigned int tmp1, tmp2;
   7547 
   7548       tep->start.section = SHN_UNDEF;
   7549       tep->end.section   = SHN_UNDEF;
   7550 
   7551       tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
   7552       tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
   7553       tmp1 = byte_get ((unsigned char *) tp + 8, 4);
   7554       tmp2 = byte_get ((unsigned char *) tp + 12, 4);
   7555 
   7556       tep->start.offset += aux->seg_base;
   7557       tep->end.offset   += aux->seg_base;
   7558 
   7559       tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
   7560       tep->Millicode = (tmp1 >> 30) & 0x1;
   7561       tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
   7562       tep->Region_description = (tmp1 >> 27) & 0x3;
   7563       tep->reserved1 = (tmp1 >> 26) & 0x1;
   7564       tep->Entry_SR = (tmp1 >> 25) & 0x1;
   7565       tep->Entry_FR = (tmp1 >> 21) & 0xf;
   7566       tep->Entry_GR = (tmp1 >> 16) & 0x1f;
   7567       tep->Args_stored = (tmp1 >> 15) & 0x1;
   7568       tep->Variable_Frame = (tmp1 >> 14) & 0x1;
   7569       tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
   7570       tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
   7571       tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
   7572       tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
   7573       tep->Ada_Region = (tmp1 >> 9) & 0x1;
   7574       tep->cxx_info = (tmp1 >> 8) & 0x1;
   7575       tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
   7576       tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
   7577       tep->reserved2 = (tmp1 >> 5) & 0x1;
   7578       tep->Save_SP = (tmp1 >> 4) & 0x1;
   7579       tep->Save_RP = (tmp1 >> 3) & 0x1;
   7580       tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
   7581       tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
   7582       tep->Cleanup_defined = tmp1 & 0x1;
   7583 
   7584       tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
   7585       tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
   7586       tep->Large_frame = (tmp2 >> 29) & 0x1;
   7587       tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
   7588       tep->reserved4 = (tmp2 >> 27) & 0x1;
   7589       tep->Total_frame_size = tmp2 & 0x7ffffff;
   7590     }
   7591   free (table);
   7592 
   7593   /* Third, apply any relocations to the unwind table.  */
   7594   for (relsec = section_headers;
   7595        relsec < section_headers + elf_header.e_shnum;
   7596        ++relsec)
   7597     {
   7598       if (relsec->sh_type != SHT_RELA
   7599 	  || relsec->sh_info >= elf_header.e_shnum
   7600 	  || section_headers + relsec->sh_info != sec)
   7601 	continue;
   7602 
   7603       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
   7604 			      & rela, & nrelas))
   7605 	return 0;
   7606 
   7607       for (rp = rela; rp < rela + nrelas; ++rp)
   7608 	{
   7609 	  relname = elf_hppa_reloc_type (get_reloc_type (rp->r_info));
   7610 	  sym = aux->symtab + get_reloc_symindex (rp->r_info);
   7611 
   7612 	  /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64.  */
   7613 	  if (! const_strneq (relname, "R_PARISC_SEGREL"))
   7614 	    {
   7615 	      warn (_("Skipping unexpected relocation type %s\n"), relname);
   7616 	      continue;
   7617 	    }
   7618 
   7619 	  i = rp->r_offset / unw_ent_size;
   7620 
   7621 	  switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
   7622 	    {
   7623 	    case 0:
   7624 	      aux->table[i].start.section = sym->st_shndx;
   7625 	      aux->table[i].start.offset  = sym->st_value + rp->r_addend;
   7626 	      break;
   7627 	    case 1:
   7628 	      aux->table[i].end.section   = sym->st_shndx;
   7629 	      aux->table[i].end.offset    = sym->st_value + rp->r_addend;
   7630 	      break;
   7631 	    default:
   7632 	      break;
   7633 	    }
   7634 	}
   7635 
   7636       free (rela);
   7637     }
   7638 
   7639   aux->table_len = nentries;
   7640 
   7641   return 1;
   7642 }
   7643 
   7644 static void
   7645 hppa_process_unwind (FILE * file)
   7646 {
   7647   struct hppa_unw_aux_info aux;
   7648   Elf_Internal_Shdr * unwsec = NULL;
   7649   Elf_Internal_Shdr * strsec;
   7650   Elf_Internal_Shdr * sec;
   7651   unsigned long i;
   7652 
   7653   if (string_table == NULL)
   7654     return;
   7655 
   7656   memset (& aux, 0, sizeof (aux));
   7657 
   7658   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   7659     {
   7660       if (sec->sh_type == SHT_SYMTAB
   7661 	  && sec->sh_link < elf_header.e_shnum)
   7662 	{
   7663 	  aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
   7664 
   7665 	  strsec = section_headers + sec->sh_link;
   7666 	  if (aux.strtab != NULL)
   7667 	    {
   7668 	      error (_("Multiple auxillary string tables encountered\n"));
   7669 	      free (aux.strtab);
   7670 	    }
   7671 	  aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
   7672                                           1, strsec->sh_size,
   7673                                           _("string table"));
   7674 	  aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
   7675 	}
   7676       else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
   7677 	unwsec = sec;
   7678     }
   7679 
   7680   if (!unwsec)
   7681     printf (_("\nThere are no unwind sections in this file.\n"));
   7682 
   7683   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   7684     {
   7685       if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
   7686 	{
   7687 	  printf (_("\nUnwind section '%s' at offset 0x%lx contains %lu entries:\n"),
   7688 		  printable_section_name (sec),
   7689 		  (unsigned long) sec->sh_offset,
   7690 		  (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
   7691 
   7692           slurp_hppa_unwind_table (file, &aux, sec);
   7693 	  if (aux.table_len > 0)
   7694 	    dump_hppa_unwind (&aux);
   7695 
   7696 	  if (aux.table)
   7697 	    free ((char *) aux.table);
   7698 	  aux.table = NULL;
   7699 	}
   7700     }
   7701 
   7702   if (aux.symtab)
   7703     free (aux.symtab);
   7704   if (aux.strtab)
   7705     free ((char *) aux.strtab);
   7706 }
   7707 
   7708 struct arm_section
   7709 {
   7710   unsigned char *      data;		/* The unwind data.  */
   7711   Elf_Internal_Shdr *  sec;		/* The cached unwind section header.  */
   7712   Elf_Internal_Rela *  rela;		/* The cached relocations for this section.  */
   7713   unsigned long        nrelas;		/* The number of relocations.  */
   7714   unsigned int         rel_type;	/* REL or RELA ?  */
   7715   Elf_Internal_Rela *  next_rela;	/* Cyclic pointer to the next reloc to process.  */
   7716 };
   7717 
   7718 struct arm_unw_aux_info
   7719 {
   7720   FILE *              file;		/* The file containing the unwind sections.  */
   7721   Elf_Internal_Sym *  symtab;		/* The file's symbol table.  */
   7722   unsigned long       nsyms;		/* Number of symbols.  */
   7723   Elf_Internal_Sym *  funtab;		/* Sorted table of STT_FUNC symbols.  */
   7724   unsigned long       nfuns;		/* Number of these symbols.  */
   7725   char *              strtab;		/* The file's string table.  */
   7726   unsigned long       strtab_size;	/* Size of string table.  */
   7727 };
   7728 
   7729 static const char *
   7730 arm_print_vma_and_name (struct arm_unw_aux_info *aux,
   7731 			bfd_vma fn, struct absaddr addr)
   7732 {
   7733   const char *procname;
   7734   bfd_vma sym_offset;
   7735 
   7736   if (addr.section == SHN_UNDEF)
   7737     addr.offset = fn;
   7738 
   7739   find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab,
   7740 			   aux->strtab_size, addr, &procname,
   7741 			   &sym_offset);
   7742 
   7743   print_vma (fn, PREFIX_HEX);
   7744 
   7745   if (procname)
   7746     {
   7747       fputs (" <", stdout);
   7748       fputs (procname, stdout);
   7749 
   7750       if (sym_offset)
   7751 	printf ("+0x%lx", (unsigned long) sym_offset);
   7752       fputc ('>', stdout);
   7753     }
   7754 
   7755   return procname;
   7756 }
   7757 
   7758 static void
   7759 arm_free_section (struct arm_section *arm_sec)
   7760 {
   7761   if (arm_sec->data != NULL)
   7762     free (arm_sec->data);
   7763 
   7764   if (arm_sec->rela != NULL)
   7765     free (arm_sec->rela);
   7766 }
   7767 
   7768 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
   7769       cached section and install SEC instead.
   7770    2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
   7771       and return its valued in * WORDP, relocating if necessary.
   7772    3) Update the NEXT_RELA field in ARM_SEC and store the section index and
   7773       relocation's offset in ADDR.
   7774    4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
   7775       into the string table of the symbol associated with the reloc.  If no
   7776       reloc was applied store -1 there.
   7777    5) Return TRUE upon success, FALSE otherwise.  */
   7778 
   7779 static bfd_boolean
   7780 get_unwind_section_word (struct arm_unw_aux_info *  aux,
   7781 			 struct arm_section *       arm_sec,
   7782 			 Elf_Internal_Shdr *        sec,
   7783 			 bfd_vma 		    word_offset,
   7784 			 unsigned int *             wordp,
   7785 			 struct absaddr *           addr,
   7786 			 bfd_vma *		    sym_name)
   7787 {
   7788   Elf_Internal_Rela *rp;
   7789   Elf_Internal_Sym *sym;
   7790   const char * relname;
   7791   unsigned int word;
   7792   bfd_boolean wrapped;
   7793 
   7794   if (sec == NULL || arm_sec == NULL)
   7795     return FALSE;
   7796 
   7797   addr->section = SHN_UNDEF;
   7798   addr->offset = 0;
   7799 
   7800   if (sym_name != NULL)
   7801     *sym_name = (bfd_vma) -1;
   7802 
   7803   /* If necessary, update the section cache.  */
   7804   if (sec != arm_sec->sec)
   7805     {
   7806       Elf_Internal_Shdr *relsec;
   7807 
   7808       arm_free_section (arm_sec);
   7809 
   7810       arm_sec->sec = sec;
   7811       arm_sec->data = get_data (NULL, aux->file, sec->sh_offset, 1,
   7812 				sec->sh_size, _("unwind data"));
   7813       arm_sec->rela = NULL;
   7814       arm_sec->nrelas = 0;
   7815 
   7816       for (relsec = section_headers;
   7817 	   relsec < section_headers + elf_header.e_shnum;
   7818 	   ++relsec)
   7819 	{
   7820 	  if (relsec->sh_info >= elf_header.e_shnum
   7821 	      || section_headers + relsec->sh_info != sec
   7822 	      /* PR 15745: Check the section type as well.  */
   7823 	      || (relsec->sh_type != SHT_REL
   7824 		  && relsec->sh_type != SHT_RELA))
   7825 	    continue;
   7826 
   7827 	  arm_sec->rel_type = relsec->sh_type;
   7828 	  if (relsec->sh_type == SHT_REL)
   7829 	    {
   7830 	      if (!slurp_rel_relocs (aux->file, relsec->sh_offset,
   7831 				     relsec->sh_size,
   7832 				     & arm_sec->rela, & arm_sec->nrelas))
   7833 		return FALSE;
   7834 	    }
   7835 	  else /* relsec->sh_type == SHT_RELA */
   7836 	    {
   7837 	      if (!slurp_rela_relocs (aux->file, relsec->sh_offset,
   7838 				      relsec->sh_size,
   7839 				      & arm_sec->rela, & arm_sec->nrelas))
   7840 		return FALSE;
   7841 	    }
   7842 	  break;
   7843 	}
   7844 
   7845       arm_sec->next_rela = arm_sec->rela;
   7846     }
   7847 
   7848   /* If there is no unwind data we can do nothing.  */
   7849   if (arm_sec->data == NULL)
   7850     return FALSE;
   7851 
   7852   /* If the offset is invalid then fail.  */
   7853   if (word_offset > (sec->sh_size - 4)
   7854       /* PR 18879 */
   7855       || (sec->sh_size < 5 && word_offset >= sec->sh_size)
   7856       || ((bfd_signed_vma) word_offset) < 0)
   7857     return FALSE;
   7858 
   7859   /* Get the word at the required offset.  */
   7860   word = byte_get (arm_sec->data + word_offset, 4);
   7861 
   7862   /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128.  */
   7863   if (arm_sec->rela == NULL)
   7864     {
   7865       * wordp = word;
   7866       return TRUE;
   7867     }
   7868 
   7869   /* Look through the relocs to find the one that applies to the provided offset.  */
   7870   wrapped = FALSE;
   7871   for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
   7872     {
   7873       bfd_vma prelval, offset;
   7874 
   7875       if (rp->r_offset > word_offset && !wrapped)
   7876 	{
   7877 	  rp = arm_sec->rela;
   7878 	  wrapped = TRUE;
   7879 	}
   7880       if (rp->r_offset > word_offset)
   7881 	break;
   7882 
   7883       if (rp->r_offset & 3)
   7884 	{
   7885 	  warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
   7886 		(unsigned long) rp->r_offset);
   7887 	  continue;
   7888 	}
   7889 
   7890       if (rp->r_offset < word_offset)
   7891 	continue;
   7892 
   7893       /* PR 17531: file: 027-161405-0.004  */
   7894       if (aux->symtab == NULL)
   7895 	continue;
   7896 
   7897       if (arm_sec->rel_type == SHT_REL)
   7898 	{
   7899 	  offset = word & 0x7fffffff;
   7900 	  if (offset & 0x40000000)
   7901 	    offset |= ~ (bfd_vma) 0x7fffffff;
   7902 	}
   7903       else if (arm_sec->rel_type == SHT_RELA)
   7904 	offset = rp->r_addend;
   7905       else
   7906 	{
   7907 	  error (_("Unknown section relocation type %d encountered\n"),
   7908 		 arm_sec->rel_type);
   7909 	  break;
   7910 	}
   7911 
   7912       /* PR 17531 file: 027-1241568-0.004.  */
   7913       if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
   7914 	{
   7915 	  error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
   7916 		 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
   7917 	  break;
   7918 	}
   7919 
   7920       sym = aux->symtab + ELF32_R_SYM (rp->r_info);
   7921       offset += sym->st_value;
   7922       prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
   7923 
   7924       /* Check that we are processing the expected reloc type.  */
   7925       if (elf_header.e_machine == EM_ARM)
   7926 	{
   7927 	  relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
   7928 	  if (relname == NULL)
   7929 	    {
   7930 	      warn (_("Skipping unknown ARM relocation type: %d\n"),
   7931 		    (int) ELF32_R_TYPE (rp->r_info));
   7932 	      continue;
   7933 	    }
   7934 
   7935 	  if (streq (relname, "R_ARM_NONE"))
   7936 	      continue;
   7937 
   7938 	  if (! streq (relname, "R_ARM_PREL31"))
   7939 	    {
   7940 	      warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
   7941 	      continue;
   7942 	    }
   7943 	}
   7944       else if (elf_header.e_machine == EM_TI_C6000)
   7945 	{
   7946 	  relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
   7947 	  if (relname == NULL)
   7948 	    {
   7949 	      warn (_("Skipping unknown C6000 relocation type: %d\n"),
   7950 		    (int) ELF32_R_TYPE (rp->r_info));
   7951 	      continue;
   7952 	    }
   7953 
   7954 	  if (streq (relname, "R_C6000_NONE"))
   7955 	    continue;
   7956 
   7957 	  if (! streq (relname, "R_C6000_PREL31"))
   7958 	    {
   7959 	      warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
   7960 	      continue;
   7961 	    }
   7962 
   7963 	  prelval >>= 1;
   7964 	}
   7965       else
   7966 	{
   7967 	  /* This function currently only supports ARM and TI unwinders.  */
   7968 	  warn (_("Only TI and ARM unwinders are currently supported\n"));
   7969 	  break;
   7970 	}
   7971 
   7972       word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
   7973       addr->section = sym->st_shndx;
   7974       addr->offset = offset;
   7975 
   7976       if (sym_name)
   7977 	* sym_name = sym->st_name;
   7978       break;
   7979     }
   7980 
   7981   *wordp = word;
   7982   arm_sec->next_rela = rp;
   7983 
   7984   return TRUE;
   7985 }
   7986 
   7987 static const char *tic6x_unwind_regnames[16] =
   7988 {
   7989   "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
   7990   "A14", "A13", "A12", "A11", "A10",
   7991   "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
   7992 };
   7993 
   7994 static void
   7995 decode_tic6x_unwind_regmask (unsigned int mask)
   7996 {
   7997   int i;
   7998 
   7999   for (i = 12; mask; mask >>= 1, i--)
   8000     {
   8001       if (mask & 1)
   8002 	{
   8003 	  fputs (tic6x_unwind_regnames[i], stdout);
   8004 	  if (mask > 1)
   8005 	    fputs (", ", stdout);
   8006 	}
   8007     }
   8008 }
   8009 
   8010 #define ADVANCE							\
   8011   if (remaining == 0 && more_words)				\
   8012     {								\
   8013       data_offset += 4;						\
   8014       if (! get_unwind_section_word (aux, data_arm_sec, data_sec,	\
   8015 				     data_offset, & word, & addr, NULL))	\
   8016 	return;							\
   8017       remaining = 4;						\
   8018       more_words--;						\
   8019     }								\
   8020 
   8021 #define GET_OP(OP)			\
   8022   ADVANCE;				\
   8023   if (remaining)			\
   8024     {					\
   8025       remaining--;			\
   8026       (OP) = word >> 24;		\
   8027       word <<= 8;			\
   8028     }					\
   8029   else					\
   8030     {					\
   8031       printf (_("[Truncated opcode]\n"));	\
   8032       return;				\
   8033     }					\
   8034   printf ("0x%02x ", OP)
   8035 
   8036 static void
   8037 decode_arm_unwind_bytecode (struct arm_unw_aux_info *  aux,
   8038 			    unsigned int               word,
   8039 			    unsigned int               remaining,
   8040 			    unsigned int               more_words,
   8041 			    bfd_vma                    data_offset,
   8042 			    Elf_Internal_Shdr *        data_sec,
   8043 			    struct arm_section *       data_arm_sec)
   8044 {
   8045   struct absaddr addr;
   8046 
   8047   /* Decode the unwinding instructions.  */
   8048   while (1)
   8049     {
   8050       unsigned int op, op2;
   8051 
   8052       ADVANCE;
   8053       if (remaining == 0)
   8054 	break;
   8055       remaining--;
   8056       op = word >> 24;
   8057       word <<= 8;
   8058 
   8059       printf ("  0x%02x ", op);
   8060 
   8061       if ((op & 0xc0) == 0x00)
   8062 	{
   8063 	  int offset = ((op & 0x3f) << 2) + 4;
   8064 
   8065 	  printf ("     vsp = vsp + %d", offset);
   8066 	}
   8067       else if ((op & 0xc0) == 0x40)
   8068 	{
   8069 	  int offset = ((op & 0x3f) << 2) + 4;
   8070 
   8071 	  printf ("     vsp = vsp - %d", offset);
   8072 	}
   8073       else if ((op & 0xf0) == 0x80)
   8074 	{
   8075 	  GET_OP (op2);
   8076 	  if (op == 0x80 && op2 == 0)
   8077 	    printf (_("Refuse to unwind"));
   8078 	  else
   8079 	    {
   8080 	      unsigned int mask = ((op & 0x0f) << 8) | op2;
   8081 	      int first = 1;
   8082 	      int i;
   8083 
   8084 	      printf ("pop {");
   8085 	      for (i = 0; i < 12; i++)
   8086 		if (mask & (1 << i))
   8087 		  {
   8088 		    if (first)
   8089 		      first = 0;
   8090 		    else
   8091 		      printf (", ");
   8092 		    printf ("r%d", 4 + i);
   8093 		  }
   8094 	      printf ("}");
   8095 	    }
   8096 	}
   8097       else if ((op & 0xf0) == 0x90)
   8098 	{
   8099 	  if (op == 0x9d || op == 0x9f)
   8100 	    printf (_("     [Reserved]"));
   8101 	  else
   8102 	    printf ("     vsp = r%d", op & 0x0f);
   8103 	}
   8104       else if ((op & 0xf0) == 0xa0)
   8105 	{
   8106 	  int end = 4 + (op & 0x07);
   8107 	  int first = 1;
   8108 	  int i;
   8109 
   8110 	  printf ("     pop {");
   8111 	  for (i = 4; i <= end; i++)
   8112 	    {
   8113 	      if (first)
   8114 		first = 0;
   8115 	      else
   8116 		printf (", ");
   8117 	      printf ("r%d", i);
   8118 	    }
   8119 	  if (op & 0x08)
   8120 	    {
   8121 	      if (!first)
   8122 		printf (", ");
   8123 	      printf ("r14");
   8124 	    }
   8125 	  printf ("}");
   8126 	}
   8127       else if (op == 0xb0)
   8128 	printf (_("     finish"));
   8129       else if (op == 0xb1)
   8130 	{
   8131 	  GET_OP (op2);
   8132 	  if (op2 == 0 || (op2 & 0xf0) != 0)
   8133 	    printf (_("[Spare]"));
   8134 	  else
   8135 	    {
   8136 	      unsigned int mask = op2 & 0x0f;
   8137 	      int first = 1;
   8138 	      int i;
   8139 
   8140 	      printf ("pop {");
   8141 	      for (i = 0; i < 12; i++)
   8142 		if (mask & (1 << i))
   8143 		  {
   8144 		    if (first)
   8145 		      first = 0;
   8146 		    else
   8147 		      printf (", ");
   8148 		    printf ("r%d", i);
   8149 		  }
   8150 	      printf ("}");
   8151 	    }
   8152 	}
   8153       else if (op == 0xb2)
   8154 	{
   8155 	  unsigned char buf[9];
   8156 	  unsigned int i, len;
   8157 	  unsigned long offset;
   8158 
   8159 	  for (i = 0; i < sizeof (buf); i++)
   8160 	    {
   8161 	      GET_OP (buf[i]);
   8162 	      if ((buf[i] & 0x80) == 0)
   8163 		break;
   8164 	    }
   8165 	  if (i == sizeof (buf))
   8166 	    printf (_("corrupt change to vsp"));
   8167 	  else
   8168 	    {
   8169 	      offset = read_uleb128 (buf, &len, buf + i + 1);
   8170 	      assert (len == i + 1);
   8171 	      offset = offset * 4 + 0x204;
   8172 	      printf ("vsp = vsp + %ld", offset);
   8173 	    }
   8174 	}
   8175       else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
   8176 	{
   8177 	  unsigned int first, last;
   8178 
   8179 	  GET_OP (op2);
   8180 	  first = op2 >> 4;
   8181 	  last = op2 & 0x0f;
   8182 	  if (op == 0xc8)
   8183 	    first = first + 16;
   8184 	  printf ("pop {D%d", first);
   8185 	  if (last)
   8186 	    printf ("-D%d", first + last);
   8187 	  printf ("}");
   8188 	}
   8189       else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
   8190 	{
   8191 	  unsigned int count = op & 0x07;
   8192 
   8193 	  printf ("pop {D8");
   8194 	  if (count)
   8195 	    printf ("-D%d", 8 + count);
   8196 	  printf ("}");
   8197 	}
   8198       else if (op >= 0xc0 && op <= 0xc5)
   8199 	{
   8200 	  unsigned int count = op & 0x07;
   8201 
   8202 	  printf ("     pop {wR10");
   8203 	  if (count)
   8204 	    printf ("-wR%d", 10 + count);
   8205 	  printf ("}");
   8206 	}
   8207       else if (op == 0xc6)
   8208 	{
   8209 	  unsigned int first, last;
   8210 
   8211 	  GET_OP (op2);
   8212 	  first = op2 >> 4;
   8213 	  last = op2 & 0x0f;
   8214 	  printf ("pop {wR%d", first);
   8215 	  if (last)
   8216 	    printf ("-wR%d", first + last);
   8217 	  printf ("}");
   8218 	}
   8219       else if (op == 0xc7)
   8220 	{
   8221 	  GET_OP (op2);
   8222 	  if (op2 == 0 || (op2 & 0xf0) != 0)
   8223 	    printf (_("[Spare]"));
   8224 	  else
   8225 	    {
   8226 	      unsigned int mask = op2 & 0x0f;
   8227 	      int first = 1;
   8228 	      int i;
   8229 
   8230 	      printf ("pop {");
   8231 	      for (i = 0; i < 4; i++)
   8232 		if (mask & (1 << i))
   8233 		  {
   8234 		    if (first)
   8235 		      first = 0;
   8236 		    else
   8237 		      printf (", ");
   8238 		    printf ("wCGR%d", i);
   8239 		  }
   8240 	      printf ("}");
   8241 	    }
   8242 	}
   8243       else
   8244 	printf (_("     [unsupported opcode]"));
   8245       printf ("\n");
   8246     }
   8247 }
   8248 
   8249 static void
   8250 decode_tic6x_unwind_bytecode (struct arm_unw_aux_info *  aux,
   8251 			      unsigned int               word,
   8252 			      unsigned int               remaining,
   8253 			      unsigned int               more_words,
   8254 			      bfd_vma                    data_offset,
   8255 			      Elf_Internal_Shdr *        data_sec,
   8256 			      struct arm_section *       data_arm_sec)
   8257 {
   8258   struct absaddr addr;
   8259 
   8260   /* Decode the unwinding instructions.  */
   8261   while (1)
   8262     {
   8263       unsigned int op, op2;
   8264 
   8265       ADVANCE;
   8266       if (remaining == 0)
   8267 	break;
   8268       remaining--;
   8269       op = word >> 24;
   8270       word <<= 8;
   8271 
   8272       printf ("  0x%02x ", op);
   8273 
   8274       if ((op & 0xc0) == 0x00)
   8275 	{
   8276 	  int offset = ((op & 0x3f) << 3) + 8;
   8277 	  printf ("     sp = sp + %d", offset);
   8278 	}
   8279       else if ((op & 0xc0) == 0x80)
   8280 	{
   8281 	  GET_OP (op2);
   8282 	  if (op == 0x80 && op2 == 0)
   8283 	    printf (_("Refuse to unwind"));
   8284 	  else
   8285 	    {
   8286 	      unsigned int mask = ((op & 0x1f) << 8) | op2;
   8287 	      if (op & 0x20)
   8288 		printf ("pop compact {");
   8289 	      else
   8290 		printf ("pop {");
   8291 
   8292 	      decode_tic6x_unwind_regmask (mask);
   8293 	      printf("}");
   8294 	    }
   8295 	}
   8296       else if ((op & 0xf0) == 0xc0)
   8297 	{
   8298 	  unsigned int reg;
   8299 	  unsigned int nregs;
   8300 	  unsigned int i;
   8301 	  const char *name;
   8302 	  struct
   8303 	  {
   8304 	      unsigned int offset;
   8305 	      unsigned int reg;
   8306 	  } regpos[16];
   8307 
   8308 	  /* Scan entire instruction first so that GET_OP output is not
   8309 	     interleaved with disassembly.  */
   8310 	  nregs = 0;
   8311 	  for (i = 0; nregs < (op & 0xf); i++)
   8312 	    {
   8313 	      GET_OP (op2);
   8314 	      reg = op2 >> 4;
   8315 	      if (reg != 0xf)
   8316 		{
   8317 		  regpos[nregs].offset = i * 2;
   8318 		  regpos[nregs].reg = reg;
   8319 		  nregs++;
   8320 		}
   8321 
   8322 	      reg = op2 & 0xf;
   8323 	      if (reg != 0xf)
   8324 		{
   8325 		  regpos[nregs].offset = i * 2 + 1;
   8326 		  regpos[nregs].reg = reg;
   8327 		  nregs++;
   8328 		}
   8329 	    }
   8330 
   8331 	  printf (_("pop frame {"));
   8332 	  reg = nregs - 1;
   8333 	  for (i = i * 2; i > 0; i--)
   8334 	    {
   8335 	      if (regpos[reg].offset == i - 1)
   8336 		{
   8337 		  name = tic6x_unwind_regnames[regpos[reg].reg];
   8338 		  if (reg > 0)
   8339 		    reg--;
   8340 		}
   8341 	      else
   8342 		name = _("[pad]");
   8343 
   8344 	      fputs (name, stdout);
   8345 	      if (i > 1)
   8346 		printf (", ");
   8347 	    }
   8348 
   8349 	  printf ("}");
   8350 	}
   8351       else if (op == 0xd0)
   8352 	printf ("     MOV FP, SP");
   8353       else if (op == 0xd1)
   8354 	printf ("     __c6xabi_pop_rts");
   8355       else if (op == 0xd2)
   8356 	{
   8357 	  unsigned char buf[9];
   8358 	  unsigned int i, len;
   8359 	  unsigned long offset;
   8360 
   8361 	  for (i = 0; i < sizeof (buf); i++)
   8362 	    {
   8363 	      GET_OP (buf[i]);
   8364 	      if ((buf[i] & 0x80) == 0)
   8365 		break;
   8366 	    }
   8367 	  /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2.  */
   8368 	  if (i == sizeof (buf))
   8369 	    {
   8370 	      printf ("<corrupt sp adjust>\n");
   8371 	      warn (_("Corrupt stack pointer adjustment detected\n"));
   8372 	      return;
   8373 	    }
   8374 
   8375 	  offset = read_uleb128 (buf, &len, buf + i + 1);
   8376 	  assert (len == i + 1);
   8377 	  offset = offset * 8 + 0x408;
   8378 	  printf (_("sp = sp + %ld"), offset);
   8379 	}
   8380       else if ((op & 0xf0) == 0xe0)
   8381 	{
   8382 	  if ((op & 0x0f) == 7)
   8383 	    printf ("     RETURN");
   8384 	  else
   8385 	    printf ("     MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
   8386 	}
   8387       else
   8388 	{
   8389 	  printf (_("     [unsupported opcode]"));
   8390 	}
   8391       putchar ('\n');
   8392     }
   8393 }
   8394 
   8395 static bfd_vma
   8396 arm_expand_prel31 (bfd_vma word, bfd_vma where)
   8397 {
   8398   bfd_vma offset;
   8399 
   8400   offset = word & 0x7fffffff;
   8401   if (offset & 0x40000000)
   8402     offset |= ~ (bfd_vma) 0x7fffffff;
   8403 
   8404   if (elf_header.e_machine == EM_TI_C6000)
   8405     offset <<= 1;
   8406 
   8407   return offset + where;
   8408 }
   8409 
   8410 static void
   8411 decode_arm_unwind (struct arm_unw_aux_info *  aux,
   8412 		   unsigned int               word,
   8413 		   unsigned int               remaining,
   8414 		   bfd_vma                    data_offset,
   8415 		   Elf_Internal_Shdr *        data_sec,
   8416 		   struct arm_section *       data_arm_sec)
   8417 {
   8418   int per_index;
   8419   unsigned int more_words = 0;
   8420   struct absaddr addr;
   8421   bfd_vma sym_name = (bfd_vma) -1;
   8422 
   8423   if (remaining == 0)
   8424     {
   8425       /* Fetch the first word.
   8426 	 Note - when decoding an object file the address extracted
   8427 	 here will always be 0.  So we also pass in the sym_name
   8428 	 parameter so that we can find the symbol associated with
   8429 	 the personality routine.  */
   8430       if (! get_unwind_section_word (aux, data_arm_sec, data_sec, data_offset,
   8431 				     & word, & addr, & sym_name))
   8432 	return;
   8433 
   8434       remaining = 4;
   8435     }
   8436 
   8437   if ((word & 0x80000000) == 0)
   8438     {
   8439       /* Expand prel31 for personality routine.  */
   8440       bfd_vma fn;
   8441       const char *procname;
   8442 
   8443       fn = arm_expand_prel31 (word, data_sec->sh_addr + data_offset);
   8444       printf (_("  Personality routine: "));
   8445       if (fn == 0
   8446 	  && addr.section == SHN_UNDEF && addr.offset == 0
   8447 	  && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
   8448 	{
   8449 	  procname = aux->strtab + sym_name;
   8450 	  print_vma (fn, PREFIX_HEX);
   8451 	  if (procname)
   8452 	    {
   8453 	      fputs (" <", stdout);
   8454 	      fputs (procname, stdout);
   8455 	      fputc ('>', stdout);
   8456 	    }
   8457 	}
   8458       else
   8459 	procname = arm_print_vma_and_name (aux, fn, addr);
   8460       fputc ('\n', stdout);
   8461 
   8462       /* The GCC personality routines use the standard compact
   8463 	 encoding, starting with one byte giving the number of
   8464 	 words.  */
   8465       if (procname != NULL
   8466 	  && (const_strneq (procname, "__gcc_personality_v0")
   8467 	      || const_strneq (procname, "__gxx_personality_v0")
   8468 	      || const_strneq (procname, "__gcj_personality_v0")
   8469 	      || const_strneq (procname, "__gnu_objc_personality_v0")))
   8470 	{
   8471 	  remaining = 0;
   8472 	  more_words = 1;
   8473 	  ADVANCE;
   8474 	  if (!remaining)
   8475 	    {
   8476 	      printf (_("  [Truncated data]\n"));
   8477 	      return;
   8478 	    }
   8479 	  more_words = word >> 24;
   8480 	  word <<= 8;
   8481 	  remaining--;
   8482 	  per_index = -1;
   8483 	}
   8484       else
   8485 	return;
   8486     }
   8487   else
   8488     {
   8489       /* ARM EHABI Section 6.3:
   8490 
   8491 	 An exception-handling table entry for the compact model looks like:
   8492 
   8493            31 30-28 27-24 23-0
   8494 	   -- ----- ----- ----
   8495             1   0   index Data for personalityRoutine[index]    */
   8496 
   8497       if (elf_header.e_machine == EM_ARM
   8498 	  && (word & 0x70000000))
   8499 	warn (_("Corrupt ARM compact model table entry: %x \n"), word);
   8500 
   8501       per_index = (word >> 24) & 0x7f;
   8502       printf (_("  Compact model index: %d\n"), per_index);
   8503       if (per_index == 0)
   8504 	{
   8505 	  more_words = 0;
   8506 	  word <<= 8;
   8507 	  remaining--;
   8508 	}
   8509       else if (per_index < 3)
   8510 	{
   8511 	  more_words = (word >> 16) & 0xff;
   8512 	  word <<= 16;
   8513 	  remaining -= 2;
   8514 	}
   8515     }
   8516 
   8517   switch (elf_header.e_machine)
   8518     {
   8519     case EM_ARM:
   8520       if (per_index < 3)
   8521 	{
   8522 	  decode_arm_unwind_bytecode (aux, word, remaining, more_words,
   8523 				      data_offset, data_sec, data_arm_sec);
   8524 	}
   8525       else
   8526 	{
   8527 	  warn (_("Unknown ARM compact model index encountered\n"));
   8528 	  printf (_("  [reserved]\n"));
   8529 	}
   8530       break;
   8531 
   8532     case EM_TI_C6000:
   8533       if (per_index < 3)
   8534 	{
   8535 	  decode_tic6x_unwind_bytecode (aux, word, remaining, more_words,
   8536 					data_offset, data_sec, data_arm_sec);
   8537 	}
   8538       else if (per_index < 5)
   8539 	{
   8540 	  if (((word >> 17) & 0x7f) == 0x7f)
   8541 	    printf (_("  Restore stack from frame pointer\n"));
   8542 	  else
   8543 	    printf (_("  Stack increment %d\n"), (word >> 14) & 0x1fc);
   8544 	  printf (_("  Registers restored: "));
   8545 	  if (per_index == 4)
   8546 	    printf (" (compact) ");
   8547 	  decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
   8548 	  putchar ('\n');
   8549 	  printf (_("  Return register: %s\n"),
   8550 		  tic6x_unwind_regnames[word & 0xf]);
   8551 	}
   8552       else
   8553 	printf (_("  [reserved (%d)]\n"), per_index);
   8554       break;
   8555 
   8556     default:
   8557       error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
   8558 	     elf_header.e_machine);
   8559     }
   8560 
   8561   /* Decode the descriptors.  Not implemented.  */
   8562 }
   8563 
   8564 static void
   8565 dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec)
   8566 {
   8567   struct arm_section exidx_arm_sec, extab_arm_sec;
   8568   unsigned int i, exidx_len;
   8569   unsigned long j, nfuns;
   8570 
   8571   memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
   8572   memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
   8573   exidx_len = exidx_sec->sh_size / 8;
   8574 
   8575   aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
   8576   for (nfuns = 0, j = 0; j < aux->nsyms; j++)
   8577     if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
   8578       aux->funtab[nfuns++] = aux->symtab[j];
   8579   aux->nfuns = nfuns;
   8580   qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
   8581 
   8582   for (i = 0; i < exidx_len; i++)
   8583     {
   8584       unsigned int exidx_fn, exidx_entry;
   8585       struct absaddr fn_addr, entry_addr;
   8586       bfd_vma fn;
   8587 
   8588       fputc ('\n', stdout);
   8589 
   8590       if (! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
   8591 				     8 * i, & exidx_fn, & fn_addr, NULL)
   8592 	  || ! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
   8593 					8 * i + 4, & exidx_entry, & entry_addr, NULL))
   8594 	{
   8595 	  free (aux->funtab);
   8596 	  arm_free_section (& exidx_arm_sec);
   8597 	  arm_free_section (& extab_arm_sec);
   8598 	  return;
   8599 	}
   8600 
   8601       /* ARM EHABI, Section 5:
   8602 	 An index table entry consists of 2 words.
   8603          The first word contains a prel31 offset to the start of a function, with bit 31 clear.  */
   8604       if (exidx_fn & 0x80000000)
   8605 	warn (_("corrupt index table entry: %x\n"), exidx_fn);
   8606 
   8607       fn = arm_expand_prel31 (exidx_fn, exidx_sec->sh_addr + 8 * i);
   8608 
   8609       arm_print_vma_and_name (aux, fn, fn_addr);
   8610       fputs (": ", stdout);
   8611 
   8612       if (exidx_entry == 1)
   8613 	{
   8614 	  print_vma (exidx_entry, PREFIX_HEX);
   8615 	  fputs (" [cantunwind]\n", stdout);
   8616 	}
   8617       else if (exidx_entry & 0x80000000)
   8618 	{
   8619 	  print_vma (exidx_entry, PREFIX_HEX);
   8620 	  fputc ('\n', stdout);
   8621 	  decode_arm_unwind (aux, exidx_entry, 4, 0, NULL, NULL);
   8622 	}
   8623       else
   8624 	{
   8625 	  bfd_vma table, table_offset = 0;
   8626 	  Elf_Internal_Shdr *table_sec;
   8627 
   8628 	  fputs ("@", stdout);
   8629 	  table = arm_expand_prel31 (exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
   8630 	  print_vma (table, PREFIX_HEX);
   8631 	  printf ("\n");
   8632 
   8633 	  /* Locate the matching .ARM.extab.  */
   8634 	  if (entry_addr.section != SHN_UNDEF
   8635 	      && entry_addr.section < elf_header.e_shnum)
   8636 	    {
   8637 	      table_sec = section_headers + entry_addr.section;
   8638 	      table_offset = entry_addr.offset;
   8639 	      /* PR 18879 */
   8640 	      if (table_offset > table_sec->sh_size
   8641 		  || ((bfd_signed_vma) table_offset) < 0)
   8642 		{
   8643 		  warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
   8644 			(unsigned long) table_offset,
   8645 			printable_section_name (table_sec));
   8646 		  continue;
   8647 		}
   8648 	    }
   8649 	  else
   8650 	    {
   8651 	      table_sec = find_section_by_address (table);
   8652 	      if (table_sec != NULL)
   8653 		table_offset = table - table_sec->sh_addr;
   8654 	    }
   8655 	  if (table_sec == NULL)
   8656 	    {
   8657 	      warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
   8658 		    (unsigned long) table);
   8659 	      continue;
   8660 	    }
   8661 	  decode_arm_unwind (aux, 0, 0, table_offset, table_sec,
   8662 			     &extab_arm_sec);
   8663 	}
   8664     }
   8665 
   8666   printf ("\n");
   8667 
   8668   free (aux->funtab);
   8669   arm_free_section (&exidx_arm_sec);
   8670   arm_free_section (&extab_arm_sec);
   8671 }
   8672 
   8673 /* Used for both ARM and C6X unwinding tables.  */
   8674 
   8675 static void
   8676 arm_process_unwind (FILE *file)
   8677 {
   8678   struct arm_unw_aux_info aux;
   8679   Elf_Internal_Shdr *unwsec = NULL;
   8680   Elf_Internal_Shdr *strsec;
   8681   Elf_Internal_Shdr *sec;
   8682   unsigned long i;
   8683   unsigned int sec_type;
   8684 
   8685   switch (elf_header.e_machine)
   8686     {
   8687     case EM_ARM:
   8688       sec_type = SHT_ARM_EXIDX;
   8689       break;
   8690 
   8691     case EM_TI_C6000:
   8692       sec_type = SHT_C6000_UNWIND;
   8693       break;
   8694 
   8695     default:
   8696       error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
   8697 	     elf_header.e_machine);
   8698       return;
   8699     }
   8700 
   8701   if (string_table == NULL)
   8702     return;
   8703 
   8704   memset (& aux, 0, sizeof (aux));
   8705   aux.file = file;
   8706 
   8707   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   8708     {
   8709       if (sec->sh_type == SHT_SYMTAB && sec->sh_link < elf_header.e_shnum)
   8710 	{
   8711 	  aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
   8712 
   8713 	  strsec = section_headers + sec->sh_link;
   8714 
   8715 	  /* PR binutils/17531 file: 011-12666-0.004.  */
   8716 	  if (aux.strtab != NULL)
   8717 	    {
   8718 	      error (_("Multiple string tables found in file.\n"));
   8719 	      free (aux.strtab);
   8720 	    }
   8721 	  aux.strtab = get_data (NULL, file, strsec->sh_offset,
   8722 				 1, strsec->sh_size, _("string table"));
   8723 	  aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
   8724 	}
   8725       else if (sec->sh_type == sec_type)
   8726 	unwsec = sec;
   8727     }
   8728 
   8729   if (unwsec == NULL)
   8730     printf (_("\nThere are no unwind sections in this file.\n"));
   8731   else
   8732     for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
   8733       {
   8734 	if (sec->sh_type == sec_type)
   8735 	  {
   8736 	    printf (_("\nUnwind table index '%s' at offset 0x%lx contains %lu entries:\n"),
   8737 		    printable_section_name (sec),
   8738 		    (unsigned long) sec->sh_offset,
   8739 		    (unsigned long) (sec->sh_size / (2 * eh_addr_size)));
   8740 
   8741 	    dump_arm_unwind (&aux, sec);
   8742 	  }
   8743       }
   8744 
   8745   if (aux.symtab)
   8746     free (aux.symtab);
   8747   if (aux.strtab)
   8748     free ((char *) aux.strtab);
   8749 }
   8750 
   8751 static void
   8752 process_unwind (FILE * file)
   8753 {
   8754   struct unwind_handler
   8755   {
   8756     int machtype;
   8757     void (* handler)(FILE *);
   8758   } handlers[] =
   8759   {
   8760     { EM_ARM, arm_process_unwind },
   8761     { EM_IA_64, ia64_process_unwind },
   8762     { EM_PARISC, hppa_process_unwind },
   8763     { EM_TI_C6000, arm_process_unwind },
   8764     { 0, 0 }
   8765   };
   8766   int i;
   8767 
   8768   if (!do_unwind)
   8769     return;
   8770 
   8771   for (i = 0; handlers[i].handler != NULL; i++)
   8772     if (elf_header.e_machine == handlers[i].machtype)
   8773       {
   8774 	handlers[i].handler (file);
   8775 	return;
   8776       }
   8777 
   8778   printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
   8779 	  get_machine_name (elf_header.e_machine));
   8780 }
   8781 
   8782 static void
   8783 dynamic_section_mips_val (Elf_Internal_Dyn * entry)
   8784 {
   8785   switch (entry->d_tag)
   8786     {
   8787     case DT_MIPS_FLAGS:
   8788       if (entry->d_un.d_val == 0)
   8789 	printf (_("NONE"));
   8790       else
   8791 	{
   8792 	  static const char * opts[] =
   8793 	  {
   8794 	    "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
   8795 	    "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
   8796 	    "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
   8797 	    "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
   8798 	    "RLD_ORDER_SAFE"
   8799 	  };
   8800 	  unsigned int cnt;
   8801 	  int first = 1;
   8802 
   8803 	  for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
   8804 	    if (entry->d_un.d_val & (1 << cnt))
   8805 	      {
   8806 		printf ("%s%s", first ? "" : " ", opts[cnt]);
   8807 		first = 0;
   8808 	      }
   8809 	}
   8810       break;
   8811 
   8812     case DT_MIPS_IVERSION:
   8813       if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
   8814 	printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
   8815       else
   8816 	{
   8817 	  char buf[40];
   8818 	  sprintf_vma (buf, entry->d_un.d_ptr);
   8819 	  /* Note: coded this way so that there is a single string for translation.  */
   8820 	  printf (_("<corrupt: %s>"), buf);
   8821 	}
   8822       break;
   8823 
   8824     case DT_MIPS_TIME_STAMP:
   8825       {
   8826 	char timebuf[128];
   8827 	struct tm * tmp;
   8828 	time_t atime = entry->d_un.d_val;
   8829 
   8830 	tmp = gmtime (&atime);
   8831 	/* PR 17531: file: 6accc532.  */
   8832 	if (tmp == NULL)
   8833 	  snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
   8834 	else
   8835 	  snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
   8836 		    tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
   8837 		    tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
   8838 	printf (_("Time Stamp: %s"), timebuf);
   8839       }
   8840       break;
   8841 
   8842     case DT_MIPS_RLD_VERSION:
   8843     case DT_MIPS_LOCAL_GOTNO:
   8844     case DT_MIPS_CONFLICTNO:
   8845     case DT_MIPS_LIBLISTNO:
   8846     case DT_MIPS_SYMTABNO:
   8847     case DT_MIPS_UNREFEXTNO:
   8848     case DT_MIPS_HIPAGENO:
   8849     case DT_MIPS_DELTA_CLASS_NO:
   8850     case DT_MIPS_DELTA_INSTANCE_NO:
   8851     case DT_MIPS_DELTA_RELOC_NO:
   8852     case DT_MIPS_DELTA_SYM_NO:
   8853     case DT_MIPS_DELTA_CLASSSYM_NO:
   8854     case DT_MIPS_COMPACT_SIZE:
   8855       print_vma (entry->d_un.d_val, DEC);
   8856       break;
   8857 
   8858     default:
   8859       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8860     }
   8861     putchar ('\n');
   8862 }
   8863 
   8864 static void
   8865 dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
   8866 {
   8867   switch (entry->d_tag)
   8868     {
   8869     case DT_HP_DLD_FLAGS:
   8870       {
   8871 	static struct
   8872 	{
   8873 	  long int bit;
   8874 	  const char * str;
   8875 	}
   8876 	flags[] =
   8877 	{
   8878 	  { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
   8879 	  { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
   8880 	  { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
   8881 	  { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
   8882 	  { DT_HP_BIND_NOW, "HP_BIND_NOW" },
   8883 	  { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
   8884 	  { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
   8885 	  { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
   8886 	  { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
   8887 	  { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
   8888 	  { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
   8889 	  { DT_HP_GST, "HP_GST" },
   8890 	  { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
   8891 	  { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
   8892 	  { DT_HP_NODELETE, "HP_NODELETE" },
   8893 	  { DT_HP_GROUP, "HP_GROUP" },
   8894 	  { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
   8895 	};
   8896 	int first = 1;
   8897 	size_t cnt;
   8898 	bfd_vma val = entry->d_un.d_val;
   8899 
   8900 	for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
   8901 	  if (val & flags[cnt].bit)
   8902 	    {
   8903 	      if (! first)
   8904 		putchar (' ');
   8905 	      fputs (flags[cnt].str, stdout);
   8906 	      first = 0;
   8907 	      val ^= flags[cnt].bit;
   8908 	    }
   8909 
   8910 	if (val != 0 || first)
   8911 	  {
   8912 	    if (! first)
   8913 	      putchar (' ');
   8914 	    print_vma (val, HEX);
   8915 	  }
   8916       }
   8917       break;
   8918 
   8919     default:
   8920       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8921       break;
   8922     }
   8923   putchar ('\n');
   8924 }
   8925 
   8926 #ifdef BFD64
   8927 
   8928 /* VMS vs Unix time offset and factor.  */
   8929 
   8930 #define VMS_EPOCH_OFFSET 35067168000000000LL
   8931 #define VMS_GRANULARITY_FACTOR 10000000
   8932 
   8933 /* Display a VMS time in a human readable format.  */
   8934 
   8935 static void
   8936 print_vms_time (bfd_int64_t vmstime)
   8937 {
   8938   struct tm *tm;
   8939   time_t unxtime;
   8940 
   8941   unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
   8942   tm = gmtime (&unxtime);
   8943   printf ("%04u-%02u-%02uT%02u:%02u:%02u",
   8944           tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
   8945           tm->tm_hour, tm->tm_min, tm->tm_sec);
   8946 }
   8947 #endif /* BFD64 */
   8948 
   8949 static void
   8950 dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
   8951 {
   8952   switch (entry->d_tag)
   8953     {
   8954     case DT_IA_64_PLT_RESERVE:
   8955       /* First 3 slots reserved.  */
   8956       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8957       printf (" -- ");
   8958       print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
   8959       break;
   8960 
   8961     case DT_IA_64_VMS_LINKTIME:
   8962 #ifdef BFD64
   8963       print_vms_time (entry->d_un.d_val);
   8964 #endif
   8965       break;
   8966 
   8967     case DT_IA_64_VMS_LNKFLAGS:
   8968       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   8969       if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
   8970         printf (" CALL_DEBUG");
   8971       if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
   8972         printf (" NOP0BUFS");
   8973       if (entry->d_un.d_val & VMS_LF_P0IMAGE)
   8974         printf (" P0IMAGE");
   8975       if (entry->d_un.d_val & VMS_LF_MKTHREADS)
   8976         printf (" MKTHREADS");
   8977       if (entry->d_un.d_val & VMS_LF_UPCALLS)
   8978         printf (" UPCALLS");
   8979       if (entry->d_un.d_val & VMS_LF_IMGSTA)
   8980         printf (" IMGSTA");
   8981       if (entry->d_un.d_val & VMS_LF_INITIALIZE)
   8982         printf (" INITIALIZE");
   8983       if (entry->d_un.d_val & VMS_LF_MAIN)
   8984         printf (" MAIN");
   8985       if (entry->d_un.d_val & VMS_LF_EXE_INIT)
   8986         printf (" EXE_INIT");
   8987       if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
   8988         printf (" TBK_IN_IMG");
   8989       if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
   8990         printf (" DBG_IN_IMG");
   8991       if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
   8992         printf (" TBK_IN_DSF");
   8993       if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
   8994         printf (" DBG_IN_DSF");
   8995       if (entry->d_un.d_val & VMS_LF_SIGNATURES)
   8996         printf (" SIGNATURES");
   8997       if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
   8998         printf (" REL_SEG_OFF");
   8999       break;
   9000 
   9001     default:
   9002       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
   9003       break;
   9004     }
   9005   putchar ('\n');
   9006 }
   9007 
   9008 static int
   9009 get_32bit_dynamic_section (FILE * file)
   9010 {
   9011   Elf32_External_Dyn * edyn;
   9012   Elf32_External_Dyn * ext;
   9013   Elf_Internal_Dyn * entry;
   9014 
   9015   edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
   9016                                           dynamic_size, _("dynamic section"));
   9017   if (!edyn)
   9018     return 0;
   9019 
   9020   /* SGI's ELF has more than one section in the DYNAMIC segment, and we
   9021      might not have the luxury of section headers.  Look for the DT_NULL
   9022      terminator to determine the number of entries.  */
   9023   for (ext = edyn, dynamic_nent = 0;
   9024        (char *) (ext + 1) <= (char *) edyn + dynamic_size;
   9025        ext++)
   9026     {
   9027       dynamic_nent++;
   9028       if (BYTE_GET (ext->d_tag) == DT_NULL)
   9029 	break;
   9030     }
   9031 
   9032   dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
   9033                                                   sizeof (* entry));
   9034   if (dynamic_section == NULL)
   9035     {
   9036       error (_("Out of memory allocating space for %lu dynamic entries\n"),
   9037 	     (unsigned long) dynamic_nent);
   9038       free (edyn);
   9039       return 0;
   9040     }
   9041 
   9042   for (ext = edyn, entry = dynamic_section;
   9043        entry < dynamic_section + dynamic_nent;
   9044        ext++, entry++)
   9045     {
   9046       entry->d_tag      = BYTE_GET (ext->d_tag);
   9047       entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
   9048     }
   9049 
   9050   free (edyn);
   9051 
   9052   return 1;
   9053 }
   9054 
   9055 static int
   9056 get_64bit_dynamic_section (FILE * file)
   9057 {
   9058   Elf64_External_Dyn * edyn;
   9059   Elf64_External_Dyn * ext;
   9060   Elf_Internal_Dyn * entry;
   9061 
   9062   /* Read in the data.  */
   9063   edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
   9064                                           dynamic_size, _("dynamic section"));
   9065   if (!edyn)
   9066     return 0;
   9067 
   9068   /* SGI's ELF has more than one section in the DYNAMIC segment, and we
   9069      might not have the luxury of section headers.  Look for the DT_NULL
   9070      terminator to determine the number of entries.  */
   9071   for (ext = edyn, dynamic_nent = 0;
   9072        /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer.  */
   9073        (char *) (ext + 1) <= (char *) edyn + dynamic_size;
   9074        ext++)
   9075     {
   9076       dynamic_nent++;
   9077       if (BYTE_GET (ext->d_tag) == DT_NULL)
   9078 	break;
   9079     }
   9080 
   9081   dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
   9082                                                   sizeof (* entry));
   9083   if (dynamic_section == NULL)
   9084     {
   9085       error (_("Out of memory allocating space for %lu dynamic entries\n"),
   9086 	     (unsigned long) dynamic_nent);
   9087       free (edyn);
   9088       return 0;
   9089     }
   9090 
   9091   /* Convert from external to internal formats.  */
   9092   for (ext = edyn, entry = dynamic_section;
   9093        entry < dynamic_section + dynamic_nent;
   9094        ext++, entry++)
   9095     {
   9096       entry->d_tag      = BYTE_GET (ext->d_tag);
   9097       entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
   9098     }
   9099 
   9100   free (edyn);
   9101 
   9102   return 1;
   9103 }
   9104 
   9105 static void
   9106 print_dynamic_flags (bfd_vma flags)
   9107 {
   9108   int first = 1;
   9109 
   9110   while (flags)
   9111     {
   9112       bfd_vma flag;
   9113 
   9114       flag = flags & - flags;
   9115       flags &= ~ flag;
   9116 
   9117       if (first)
   9118 	first = 0;
   9119       else
   9120 	putc (' ', stdout);
   9121 
   9122       switch (flag)
   9123 	{
   9124 	case DF_ORIGIN:		fputs ("ORIGIN", stdout); break;
   9125 	case DF_SYMBOLIC:	fputs ("SYMBOLIC", stdout); break;
   9126 	case DF_TEXTREL:	fputs ("TEXTREL", stdout); break;
   9127 	case DF_BIND_NOW:	fputs ("BIND_NOW", stdout); break;
   9128 	case DF_STATIC_TLS:	fputs ("STATIC_TLS", stdout); break;
   9129 	default:		fputs (_("unknown"), stdout); break;
   9130 	}
   9131     }
   9132   puts ("");
   9133 }
   9134 
   9135 /* Parse and display the contents of the dynamic section.  */
   9136 
   9137 static int
   9138 process_dynamic_section (FILE * file)
   9139 {
   9140   Elf_Internal_Dyn * entry;
   9141 
   9142   if (dynamic_size == 0)
   9143     {
   9144       if (do_dynamic)
   9145 	printf (_("\nThere is no dynamic section in this file.\n"));
   9146 
   9147       return 1;
   9148     }
   9149 
   9150   if (is_32bit_elf)
   9151     {
   9152       if (! get_32bit_dynamic_section (file))
   9153 	return 0;
   9154     }
   9155   else if (! get_64bit_dynamic_section (file))
   9156     return 0;
   9157 
   9158   /* Find the appropriate symbol table.  */
   9159   if (dynamic_symbols == NULL)
   9160     {
   9161       for (entry = dynamic_section;
   9162 	   entry < dynamic_section + dynamic_nent;
   9163 	   ++entry)
   9164 	{
   9165 	  Elf_Internal_Shdr section;
   9166 
   9167 	  if (entry->d_tag != DT_SYMTAB)
   9168 	    continue;
   9169 
   9170 	  dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
   9171 
   9172 	  /* Since we do not know how big the symbol table is,
   9173 	     we default to reading in the entire file (!) and
   9174 	     processing that.  This is overkill, I know, but it
   9175 	     should work.  */
   9176 	  section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
   9177 
   9178 	  if (archive_file_offset != 0)
   9179 	    section.sh_size = archive_file_size - section.sh_offset;
   9180 	  else
   9181 	    {
   9182 	      if (fseek (file, 0, SEEK_END))
   9183 		error (_("Unable to seek to end of file!\n"));
   9184 
   9185 	      section.sh_size = ftell (file) - section.sh_offset;
   9186 	    }
   9187 
   9188 	  if (is_32bit_elf)
   9189 	    section.sh_entsize = sizeof (Elf32_External_Sym);
   9190 	  else
   9191 	    section.sh_entsize = sizeof (Elf64_External_Sym);
   9192 	  section.sh_name = string_table_length;
   9193 
   9194 	  dynamic_symbols = GET_ELF_SYMBOLS (file, &section, & num_dynamic_syms);
   9195 	  if (num_dynamic_syms < 1)
   9196 	    {
   9197 	      error (_("Unable to determine the number of symbols to load\n"));
   9198 	      continue;
   9199 	    }
   9200 	}
   9201     }
   9202 
   9203   /* Similarly find a string table.  */
   9204   if (dynamic_strings == NULL)
   9205     {
   9206       for (entry = dynamic_section;
   9207 	   entry < dynamic_section + dynamic_nent;
   9208 	   ++entry)
   9209 	{
   9210 	  unsigned long offset;
   9211 	  long str_tab_len;
   9212 
   9213 	  if (entry->d_tag != DT_STRTAB)
   9214 	    continue;
   9215 
   9216 	  dynamic_info[DT_STRTAB] = entry->d_un.d_val;
   9217 
   9218 	  /* Since we do not know how big the string table is,
   9219 	     we default to reading in the entire file (!) and
   9220 	     processing that.  This is overkill, I know, but it
   9221 	     should work.  */
   9222 
   9223 	  offset = offset_from_vma (file, entry->d_un.d_val, 0);
   9224 
   9225 	  if (archive_file_offset != 0)
   9226 	    str_tab_len = archive_file_size - offset;
   9227 	  else
   9228 	    {
   9229 	      if (fseek (file, 0, SEEK_END))
   9230 		error (_("Unable to seek to end of file\n"));
   9231 	      str_tab_len = ftell (file) - offset;
   9232 	    }
   9233 
   9234 	  if (str_tab_len < 1)
   9235 	    {
   9236 	      error
   9237 		(_("Unable to determine the length of the dynamic string table\n"));
   9238 	      continue;
   9239 	    }
   9240 
   9241 	  dynamic_strings = (char *) get_data (NULL, file, offset, 1,
   9242                                                str_tab_len,
   9243                                                _("dynamic string table"));
   9244 	  dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
   9245 	  break;
   9246 	}
   9247     }
   9248 
   9249   /* And find the syminfo section if available.  */
   9250   if (dynamic_syminfo == NULL)
   9251     {
   9252       unsigned long syminsz = 0;
   9253 
   9254       for (entry = dynamic_section;
   9255 	   entry < dynamic_section + dynamic_nent;
   9256 	   ++entry)
   9257 	{
   9258 	  if (entry->d_tag == DT_SYMINENT)
   9259 	    {
   9260 	      /* Note: these braces are necessary to avoid a syntax
   9261 		 error from the SunOS4 C compiler.  */
   9262 	      /* PR binutils/17531: A corrupt file can trigger this test.
   9263 		 So do not use an assert, instead generate an error message.  */
   9264 	      if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
   9265 		error (_("Bad value (%d) for SYMINENT entry\n"),
   9266 		       (int) entry->d_un.d_val);
   9267 	    }
   9268 	  else if (entry->d_tag == DT_SYMINSZ)
   9269 	    syminsz = entry->d_un.d_val;
   9270 	  else if (entry->d_tag == DT_SYMINFO)
   9271 	    dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
   9272 						      syminsz);
   9273 	}
   9274 
   9275       if (dynamic_syminfo_offset != 0 && syminsz != 0)
   9276 	{
   9277 	  Elf_External_Syminfo * extsyminfo;
   9278 	  Elf_External_Syminfo * extsym;
   9279 	  Elf_Internal_Syminfo * syminfo;
   9280 
   9281 	  /* There is a syminfo section.  Read the data.  */
   9282 	  extsyminfo = (Elf_External_Syminfo *)
   9283               get_data (NULL, file, dynamic_syminfo_offset, 1, syminsz,
   9284                         _("symbol information"));
   9285 	  if (!extsyminfo)
   9286 	    return 0;
   9287 
   9288 	  dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
   9289 	  if (dynamic_syminfo == NULL)
   9290 	    {
   9291 	      error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
   9292 		     (unsigned long) syminsz);
   9293 	      return 0;
   9294 	    }
   9295 
   9296 	  dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
   9297 	  for (syminfo = dynamic_syminfo, extsym = extsyminfo;
   9298 	       syminfo < dynamic_syminfo + dynamic_syminfo_nent;
   9299 	       ++syminfo, ++extsym)
   9300 	    {
   9301 	      syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
   9302 	      syminfo->si_flags = BYTE_GET (extsym->si_flags);
   9303 	    }
   9304 
   9305 	  free (extsyminfo);
   9306 	}
   9307     }
   9308 
   9309   if (do_dynamic && dynamic_addr)
   9310     printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"),
   9311 	    dynamic_addr, (unsigned long) dynamic_nent);
   9312   if (do_dynamic)
   9313     printf (_("  Tag        Type                         Name/Value\n"));
   9314 
   9315   for (entry = dynamic_section;
   9316        entry < dynamic_section + dynamic_nent;
   9317        entry++)
   9318     {
   9319       if (do_dynamic)
   9320 	{
   9321 	  const char * dtype;
   9322 
   9323 	  putchar (' ');
   9324 	  print_vma (entry->d_tag, FULL_HEX);
   9325 	  dtype = get_dynamic_type (entry->d_tag);
   9326 	  printf (" (%s)%*s", dtype,
   9327 		  ((is_32bit_elf ? 27 : 19)
   9328 		   - (int) strlen (dtype)),
   9329 		  " ");
   9330 	}
   9331 
   9332       switch (entry->d_tag)
   9333 	{
   9334 	case DT_FLAGS:
   9335 	  if (do_dynamic)
   9336 	    print_dynamic_flags (entry->d_un.d_val);
   9337 	  break;
   9338 
   9339 	case DT_AUXILIARY:
   9340 	case DT_FILTER:
   9341 	case DT_CONFIG:
   9342 	case DT_DEPAUDIT:
   9343 	case DT_AUDIT:
   9344 	  if (do_dynamic)
   9345 	    {
   9346 	      switch (entry->d_tag)
   9347 		{
   9348 		case DT_AUXILIARY:
   9349 		  printf (_("Auxiliary library"));
   9350 		  break;
   9351 
   9352 		case DT_FILTER:
   9353 		  printf (_("Filter library"));
   9354 		  break;
   9355 
   9356 		case DT_CONFIG:
   9357 		  printf (_("Configuration file"));
   9358 		  break;
   9359 
   9360 		case DT_DEPAUDIT:
   9361 		  printf (_("Dependency audit library"));
   9362 		  break;
   9363 
   9364 		case DT_AUDIT:
   9365 		  printf (_("Audit library"));
   9366 		  break;
   9367 		}
   9368 
   9369 	      if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
   9370 		printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
   9371 	      else
   9372 		{
   9373 		  printf (": ");
   9374 		  print_vma (entry->d_un.d_val, PREFIX_HEX);
   9375 		  putchar ('\n');
   9376 		}
   9377 	    }
   9378 	  break;
   9379 
   9380 	case DT_FEATURE:
   9381 	  if (do_dynamic)
   9382 	    {
   9383 	      printf (_("Flags:"));
   9384 
   9385 	      if (entry->d_un.d_val == 0)
   9386 		printf (_(" None\n"));
   9387 	      else
   9388 		{
   9389 		  unsigned long int val = entry->d_un.d_val;
   9390 
   9391 		  if (val & DTF_1_PARINIT)
   9392 		    {
   9393 		      printf (" PARINIT");
   9394 		      val ^= DTF_1_PARINIT;
   9395 		    }
   9396 		  if (val & DTF_1_CONFEXP)
   9397 		    {
   9398 		      printf (" CONFEXP");
   9399 		      val ^= DTF_1_CONFEXP;
   9400 		    }
   9401 		  if (val != 0)
   9402 		    printf (" %lx", val);
   9403 		  puts ("");
   9404 		}
   9405 	    }
   9406 	  break;
   9407 
   9408 	case DT_POSFLAG_1:
   9409 	  if (do_dynamic)
   9410 	    {
   9411 	      printf (_("Flags:"));
   9412 
   9413 	      if (entry->d_un.d_val == 0)
   9414 		printf (_(" None\n"));
   9415 	      else
   9416 		{
   9417 		  unsigned long int val = entry->d_un.d_val;
   9418 
   9419 		  if (val & DF_P1_LAZYLOAD)
   9420 		    {
   9421 		      printf (" LAZYLOAD");
   9422 		      val ^= DF_P1_LAZYLOAD;
   9423 		    }
   9424 		  if (val & DF_P1_GROUPPERM)
   9425 		    {
   9426 		      printf (" GROUPPERM");
   9427 		      val ^= DF_P1_GROUPPERM;
   9428 		    }
   9429 		  if (val != 0)
   9430 		    printf (" %lx", val);
   9431 		  puts ("");
   9432 		}
   9433 	    }
   9434 	  break;
   9435 
   9436 	case DT_FLAGS_1:
   9437 	  if (do_dynamic)
   9438 	    {
   9439 	      printf (_("Flags:"));
   9440 	      if (entry->d_un.d_val == 0)
   9441 		printf (_(" None\n"));
   9442 	      else
   9443 		{
   9444 		  unsigned long int val = entry->d_un.d_val;
   9445 
   9446 		  if (val & DF_1_NOW)
   9447 		    {
   9448 		      printf (" NOW");
   9449 		      val ^= DF_1_NOW;
   9450 		    }
   9451 		  if (val & DF_1_GLOBAL)
   9452 		    {
   9453 		      printf (" GLOBAL");
   9454 		      val ^= DF_1_GLOBAL;
   9455 		    }
   9456 		  if (val & DF_1_GROUP)
   9457 		    {
   9458 		      printf (" GROUP");
   9459 		      val ^= DF_1_GROUP;
   9460 		    }
   9461 		  if (val & DF_1_NODELETE)
   9462 		    {
   9463 		      printf (" NODELETE");
   9464 		      val ^= DF_1_NODELETE;
   9465 		    }
   9466 		  if (val & DF_1_LOADFLTR)
   9467 		    {
   9468 		      printf (" LOADFLTR");
   9469 		      val ^= DF_1_LOADFLTR;
   9470 		    }
   9471 		  if (val & DF_1_INITFIRST)
   9472 		    {
   9473 		      printf (" INITFIRST");
   9474 		      val ^= DF_1_INITFIRST;
   9475 		    }
   9476 		  if (val & DF_1_NOOPEN)
   9477 		    {
   9478 		      printf (" NOOPEN");
   9479 		      val ^= DF_1_NOOPEN;
   9480 		    }
   9481 		  if (val & DF_1_ORIGIN)
   9482 		    {
   9483 		      printf (" ORIGIN");
   9484 		      val ^= DF_1_ORIGIN;
   9485 		    }
   9486 		  if (val & DF_1_DIRECT)
   9487 		    {
   9488 		      printf (" DIRECT");
   9489 		      val ^= DF_1_DIRECT;
   9490 		    }
   9491 		  if (val & DF_1_TRANS)
   9492 		    {
   9493 		      printf (" TRANS");
   9494 		      val ^= DF_1_TRANS;
   9495 		    }
   9496 		  if (val & DF_1_INTERPOSE)
   9497 		    {
   9498 		      printf (" INTERPOSE");
   9499 		      val ^= DF_1_INTERPOSE;
   9500 		    }
   9501 		  if (val & DF_1_NODEFLIB)
   9502 		    {
   9503 		      printf (" NODEFLIB");
   9504 		      val ^= DF_1_NODEFLIB;
   9505 		    }
   9506 		  if (val & DF_1_NODUMP)
   9507 		    {
   9508 		      printf (" NODUMP");
   9509 		      val ^= DF_1_NODUMP;
   9510 		    }
   9511 		  if (val & DF_1_CONFALT)
   9512 		    {
   9513 		      printf (" CONFALT");
   9514 		      val ^= DF_1_CONFALT;
   9515 		    }
   9516 		  if (val & DF_1_ENDFILTEE)
   9517 		    {
   9518 		      printf (" ENDFILTEE");
   9519 		      val ^= DF_1_ENDFILTEE;
   9520 		    }
   9521 		  if (val & DF_1_DISPRELDNE)
   9522 		    {
   9523 		      printf (" DISPRELDNE");
   9524 		      val ^= DF_1_DISPRELDNE;
   9525 		    }
   9526 		  if (val & DF_1_DISPRELPND)
   9527 		    {
   9528 		      printf (" DISPRELPND");
   9529 		      val ^= DF_1_DISPRELPND;
   9530 		    }
   9531 		  if (val & DF_1_NODIRECT)
   9532 		    {
   9533 		      printf (" NODIRECT");
   9534 		      val ^= DF_1_NODIRECT;
   9535 		    }
   9536 		  if (val & DF_1_IGNMULDEF)
   9537 		    {
   9538 		      printf (" IGNMULDEF");
   9539 		      val ^= DF_1_IGNMULDEF;
   9540 		    }
   9541 		  if (val & DF_1_NOKSYMS)
   9542 		    {
   9543 		      printf (" NOKSYMS");
   9544 		      val ^= DF_1_NOKSYMS;
   9545 		    }
   9546 		  if (val & DF_1_NOHDR)
   9547 		    {
   9548 		      printf (" NOHDR");
   9549 		      val ^= DF_1_NOHDR;
   9550 		    }
   9551 		  if (val & DF_1_EDITED)
   9552 		    {
   9553 		      printf (" EDITED");
   9554 		      val ^= DF_1_EDITED;
   9555 		    }
   9556 		  if (val & DF_1_NORELOC)
   9557 		    {
   9558 		      printf (" NORELOC");
   9559 		      val ^= DF_1_NORELOC;
   9560 		    }
   9561 		  if (val & DF_1_SYMINTPOSE)
   9562 		    {
   9563 		      printf (" SYMINTPOSE");
   9564 		      val ^= DF_1_SYMINTPOSE;
   9565 		    }
   9566 		  if (val & DF_1_GLOBAUDIT)
   9567 		    {
   9568 		      printf (" GLOBAUDIT");
   9569 		      val ^= DF_1_GLOBAUDIT;
   9570 		    }
   9571 		  if (val & DF_1_SINGLETON)
   9572 		    {
   9573 		      printf (" SINGLETON");
   9574 		      val ^= DF_1_SINGLETON;
   9575 		    }
   9576 		  if (val & DF_1_STUB)
   9577 		    {
   9578 		      printf (" STUB");
   9579 		      val ^= DF_1_STUB;
   9580 		    }
   9581 		  if (val & DF_1_PIE)
   9582 		    {
   9583 		      printf (" PIE");
   9584 		      val ^= DF_1_PIE;
   9585 		    }
   9586 		  if (val != 0)
   9587 		    printf (" %lx", val);
   9588 		  puts ("");
   9589 		}
   9590 	    }
   9591 	  break;
   9592 
   9593 	case DT_PLTREL:
   9594 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
   9595 	  if (do_dynamic)
   9596 	    puts (get_dynamic_type (entry->d_un.d_val));
   9597 	  break;
   9598 
   9599 	case DT_NULL	:
   9600 	case DT_NEEDED	:
   9601 	case DT_PLTGOT	:
   9602 	case DT_HASH	:
   9603 	case DT_STRTAB	:
   9604 	case DT_SYMTAB	:
   9605 	case DT_RELA	:
   9606 	case DT_INIT	:
   9607 	case DT_FINI	:
   9608 	case DT_SONAME	:
   9609 	case DT_RPATH	:
   9610 	case DT_SYMBOLIC:
   9611 	case DT_REL	:
   9612 	case DT_DEBUG	:
   9613 	case DT_TEXTREL	:
   9614 	case DT_JMPREL	:
   9615 	case DT_RUNPATH	:
   9616 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
   9617 
   9618 	  if (do_dynamic)
   9619 	    {
   9620 	      char * name;
   9621 
   9622 	      if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
   9623 		name = GET_DYNAMIC_NAME (entry->d_un.d_val);
   9624 	      else
   9625 		name = NULL;
   9626 
   9627 	      if (name)
   9628 		{
   9629 		  switch (entry->d_tag)
   9630 		    {
   9631 		    case DT_NEEDED:
   9632 		      printf (_("Shared library: [%s]"), name);
   9633 
   9634 		      if (streq (name, program_interpreter))
   9635 			printf (_(" program interpreter"));
   9636 		      break;
   9637 
   9638 		    case DT_SONAME:
   9639 		      printf (_("Library soname: [%s]"), name);
   9640 		      break;
   9641 
   9642 		    case DT_RPATH:
   9643 		      printf (_("Library rpath: [%s]"), name);
   9644 		      break;
   9645 
   9646 		    case DT_RUNPATH:
   9647 		      printf (_("Library runpath: [%s]"), name);
   9648 		      break;
   9649 
   9650 		    default:
   9651 		      print_vma (entry->d_un.d_val, PREFIX_HEX);
   9652 		      break;
   9653 		    }
   9654 		}
   9655 	      else
   9656 		print_vma (entry->d_un.d_val, PREFIX_HEX);
   9657 
   9658 	      putchar ('\n');
   9659 	    }
   9660 	  break;
   9661 
   9662 	case DT_PLTRELSZ:
   9663 	case DT_RELASZ	:
   9664 	case DT_STRSZ	:
   9665 	case DT_RELSZ	:
   9666 	case DT_RELAENT	:
   9667 	case DT_SYMENT	:
   9668 	case DT_RELENT	:
   9669 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
   9670 	case DT_PLTPADSZ:
   9671 	case DT_MOVEENT	:
   9672 	case DT_MOVESZ	:
   9673 	case DT_INIT_ARRAYSZ:
   9674 	case DT_FINI_ARRAYSZ:
   9675 	case DT_GNU_CONFLICTSZ:
   9676 	case DT_GNU_LIBLISTSZ:
   9677 	  if (do_dynamic)
   9678 	    {
   9679 	      print_vma (entry->d_un.d_val, UNSIGNED);
   9680 	      printf (_(" (bytes)\n"));
   9681 	    }
   9682 	  break;
   9683 
   9684 	case DT_VERDEFNUM:
   9685 	case DT_VERNEEDNUM:
   9686 	case DT_RELACOUNT:
   9687 	case DT_RELCOUNT:
   9688 	  if (do_dynamic)
   9689 	    {
   9690 	      print_vma (entry->d_un.d_val, UNSIGNED);
   9691 	      putchar ('\n');
   9692 	    }
   9693 	  break;
   9694 
   9695 	case DT_SYMINSZ:
   9696 	case DT_SYMINENT:
   9697 	case DT_SYMINFO:
   9698 	case DT_USED:
   9699 	case DT_INIT_ARRAY:
   9700 	case DT_FINI_ARRAY:
   9701 	  if (do_dynamic)
   9702 	    {
   9703 	      if (entry->d_tag == DT_USED
   9704 		  && VALID_DYNAMIC_NAME (entry->d_un.d_val))
   9705 		{
   9706 		  char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
   9707 
   9708 		  if (*name)
   9709 		    {
   9710 		      printf (_("Not needed object: [%s]\n"), name);
   9711 		      break;
   9712 		    }
   9713 		}
   9714 
   9715 	      print_vma (entry->d_un.d_val, PREFIX_HEX);
   9716 	      putchar ('\n');
   9717 	    }
   9718 	  break;
   9719 
   9720 	case DT_BIND_NOW:
   9721 	  /* The value of this entry is ignored.  */
   9722 	  if (do_dynamic)
   9723 	    putchar ('\n');
   9724 	  break;
   9725 
   9726 	case DT_GNU_PRELINKED:
   9727 	  if (do_dynamic)
   9728 	    {
   9729 	      struct tm * tmp;
   9730 	      time_t atime = entry->d_un.d_val;
   9731 
   9732 	      tmp = gmtime (&atime);
   9733 	      /* PR 17533 file: 041-1244816-0.004.  */
   9734 	      if (tmp == NULL)
   9735 		printf (_("<corrupt time val: %lx"),
   9736 			(unsigned long) atime);
   9737 	      else
   9738 		printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
   9739 			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
   9740 			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
   9741 
   9742 	    }
   9743 	  break;
   9744 
   9745 	case DT_GNU_HASH:
   9746 	  dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
   9747 	  if (do_dynamic)
   9748 	    {
   9749 	      print_vma (entry->d_un.d_val, PREFIX_HEX);
   9750 	      putchar ('\n');
   9751 	    }
   9752 	  break;
   9753 
   9754 	default:
   9755 	  if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
   9756 	    version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
   9757 	      entry->d_un.d_val;
   9758 
   9759 	  if (do_dynamic)
   9760 	    {
   9761 	      switch (elf_header.e_machine)
   9762 		{
   9763 		case EM_MIPS:
   9764 		case EM_MIPS_RS3_LE:
   9765 		  dynamic_section_mips_val (entry);
   9766 		  break;
   9767 		case EM_PARISC:
   9768 		  dynamic_section_parisc_val (entry);
   9769 		  break;
   9770 		case EM_IA_64:
   9771 		  dynamic_section_ia64_val (entry);
   9772 		  break;
   9773 		default:
   9774 		  print_vma (entry->d_un.d_val, PREFIX_HEX);
   9775 		  putchar ('\n');
   9776 		}
   9777 	    }
   9778 	  break;
   9779 	}
   9780     }
   9781 
   9782   return 1;
   9783 }
   9784 
   9785 static char *
   9786 get_ver_flags (unsigned int flags)
   9787 {
   9788   static char buff[32];
   9789 
   9790   buff[0] = 0;
   9791 
   9792   if (flags == 0)
   9793     return _("none");
   9794 
   9795   if (flags & VER_FLG_BASE)
   9796     strcat (buff, "BASE ");
   9797 
   9798   if (flags & VER_FLG_WEAK)
   9799     {
   9800       if (flags & VER_FLG_BASE)
   9801 	strcat (buff, "| ");
   9802 
   9803       strcat (buff, "WEAK ");
   9804     }
   9805 
   9806   if (flags & VER_FLG_INFO)
   9807     {
   9808       if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
   9809 	strcat (buff, "| ");
   9810 
   9811       strcat (buff, "INFO ");
   9812     }
   9813 
   9814   if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
   9815     strcat (buff, _("| <unknown>"));
   9816 
   9817   return buff;
   9818 }
   9819 
   9820 /* Display the contents of the version sections.  */
   9821 
   9822 static int
   9823 process_version_sections (FILE * file)
   9824 {
   9825   Elf_Internal_Shdr * section;
   9826   unsigned i;
   9827   int found = 0;
   9828 
   9829   if (! do_version)
   9830     return 1;
   9831 
   9832   for (i = 0, section = section_headers;
   9833        i < elf_header.e_shnum;
   9834        i++, section++)
   9835     {
   9836       switch (section->sh_type)
   9837 	{
   9838 	case SHT_GNU_verdef:
   9839 	  {
   9840 	    Elf_External_Verdef * edefs;
   9841 	    unsigned int idx;
   9842 	    unsigned int cnt;
   9843 	    char * endbuf;
   9844 
   9845 	    found = 1;
   9846 
   9847 	    printf (_("\nVersion definition section '%s' contains %u entries:\n"),
   9848 		    printable_section_name (section),
   9849 		    section->sh_info);
   9850 
   9851 	    printf (_("  Addr: 0x"));
   9852 	    printf_vma (section->sh_addr);
   9853 	    printf (_("  Offset: %#08lx  Link: %u (%s)"),
   9854 		    (unsigned long) section->sh_offset, section->sh_link,
   9855 		    printable_section_name_from_index (section->sh_link));
   9856 
   9857 	    edefs = (Elf_External_Verdef *)
   9858                 get_data (NULL, file, section->sh_offset, 1,section->sh_size,
   9859                           _("version definition section"));
   9860 	    if (!edefs)
   9861 	      break;
   9862 	    endbuf = (char *) edefs + section->sh_size;
   9863 
   9864 	    for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
   9865 	      {
   9866 		char * vstart;
   9867 		Elf_External_Verdef * edef;
   9868 		Elf_Internal_Verdef ent;
   9869 		Elf_External_Verdaux * eaux;
   9870 		Elf_Internal_Verdaux aux;
   9871 		int j;
   9872 		int isum;
   9873 
   9874 		/* Check for very large indicies.  */
   9875 		if (idx > (size_t) (endbuf - (char *) edefs))
   9876 		  break;
   9877 
   9878 		vstart = ((char *) edefs) + idx;
   9879 		if (vstart + sizeof (*edef) > endbuf)
   9880 		  break;
   9881 
   9882 		edef = (Elf_External_Verdef *) vstart;
   9883 
   9884 		ent.vd_version = BYTE_GET (edef->vd_version);
   9885 		ent.vd_flags   = BYTE_GET (edef->vd_flags);
   9886 		ent.vd_ndx     = BYTE_GET (edef->vd_ndx);
   9887 		ent.vd_cnt     = BYTE_GET (edef->vd_cnt);
   9888 		ent.vd_hash    = BYTE_GET (edef->vd_hash);
   9889 		ent.vd_aux     = BYTE_GET (edef->vd_aux);
   9890 		ent.vd_next    = BYTE_GET (edef->vd_next);
   9891 
   9892 		printf (_("  %#06x: Rev: %d  Flags: %s"),
   9893 			idx, ent.vd_version, get_ver_flags (ent.vd_flags));
   9894 
   9895 		printf (_("  Index: %d  Cnt: %d  "),
   9896 			ent.vd_ndx, ent.vd_cnt);
   9897 
   9898 		/* Check for overflow.  */
   9899 		if (ent.vd_aux > (size_t) (endbuf - vstart))
   9900 		  break;
   9901 
   9902 		vstart += ent.vd_aux;
   9903 
   9904 		eaux = (Elf_External_Verdaux *) vstart;
   9905 
   9906 		aux.vda_name = BYTE_GET (eaux->vda_name);
   9907 		aux.vda_next = BYTE_GET (eaux->vda_next);
   9908 
   9909 		if (VALID_DYNAMIC_NAME (aux.vda_name))
   9910 		  printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
   9911 		else
   9912 		  printf (_("Name index: %ld\n"), aux.vda_name);
   9913 
   9914 		isum = idx + ent.vd_aux;
   9915 
   9916 		for (j = 1; j < ent.vd_cnt; j++)
   9917 		  {
   9918 		    /* Check for overflow.  */
   9919 		    if (aux.vda_next > (size_t) (endbuf - vstart))
   9920 		      break;
   9921 
   9922 		    isum   += aux.vda_next;
   9923 		    vstart += aux.vda_next;
   9924 
   9925 		    eaux = (Elf_External_Verdaux *) vstart;
   9926 		    if (vstart + sizeof (*eaux) > endbuf)
   9927 		      break;
   9928 
   9929 		    aux.vda_name = BYTE_GET (eaux->vda_name);
   9930 		    aux.vda_next = BYTE_GET (eaux->vda_next);
   9931 
   9932 		    if (VALID_DYNAMIC_NAME (aux.vda_name))
   9933 		      printf (_("  %#06x: Parent %d: %s\n"),
   9934 			      isum, j, GET_DYNAMIC_NAME (aux.vda_name));
   9935 		    else
   9936 		      printf (_("  %#06x: Parent %d, name index: %ld\n"),
   9937 			      isum, j, aux.vda_name);
   9938 		  }
   9939 
   9940 		if (j < ent.vd_cnt)
   9941 		  printf (_("  Version def aux past end of section\n"));
   9942 
   9943 		/* PR 17531: file: id:000001,src:000172+005151,op:splice,rep:2.  */
   9944 		if (idx + ent.vd_next <= idx)
   9945 		  break;
   9946 
   9947 		idx += ent.vd_next;
   9948 	      }
   9949 
   9950 	    if (cnt < section->sh_info)
   9951 	      printf (_("  Version definition past end of section\n"));
   9952 
   9953 	    free (edefs);
   9954 	  }
   9955 	  break;
   9956 
   9957 	case SHT_GNU_verneed:
   9958 	  {
   9959 	    Elf_External_Verneed * eneed;
   9960 	    unsigned int idx;
   9961 	    unsigned int cnt;
   9962 	    char * endbuf;
   9963 
   9964 	    found = 1;
   9965 
   9966 	    printf (_("\nVersion needs section '%s' contains %u entries:\n"),
   9967 		    printable_section_name (section), section->sh_info);
   9968 
   9969 	    printf (_(" Addr: 0x"));
   9970 	    printf_vma (section->sh_addr);
   9971 	    printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
   9972 		    (unsigned long) section->sh_offset, section->sh_link,
   9973 		    printable_section_name_from_index (section->sh_link));
   9974 
   9975 	    eneed = (Elf_External_Verneed *) get_data (NULL, file,
   9976                                                        section->sh_offset, 1,
   9977                                                        section->sh_size,
   9978                                                        _("Version Needs section"));
   9979 	    if (!eneed)
   9980 	      break;
   9981 	    endbuf = (char *) eneed + section->sh_size;
   9982 
   9983 	    for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
   9984 	      {
   9985 		Elf_External_Verneed * entry;
   9986 		Elf_Internal_Verneed ent;
   9987 		int j;
   9988 		int isum;
   9989 		char * vstart;
   9990 
   9991 		if (idx > (size_t) (endbuf - (char *) eneed))
   9992 		  break;
   9993 
   9994 		vstart = ((char *) eneed) + idx;
   9995 		if (vstart + sizeof (*entry) > endbuf)
   9996 		  break;
   9997 
   9998 		entry = (Elf_External_Verneed *) vstart;
   9999 
   10000 		ent.vn_version = BYTE_GET (entry->vn_version);
   10001 		ent.vn_cnt     = BYTE_GET (entry->vn_cnt);
   10002 		ent.vn_file    = BYTE_GET (entry->vn_file);
   10003 		ent.vn_aux     = BYTE_GET (entry->vn_aux);
   10004 		ent.vn_next    = BYTE_GET (entry->vn_next);
   10005 
   10006 		printf (_("  %#06x: Version: %d"), idx, ent.vn_version);
   10007 
   10008 		if (VALID_DYNAMIC_NAME (ent.vn_file))
   10009 		  printf (_("  File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
   10010 		else
   10011 		  printf (_("  File: %lx"), ent.vn_file);
   10012 
   10013 		printf (_("  Cnt: %d\n"), ent.vn_cnt);
   10014 
   10015 		/* Check for overflow.  */
   10016 		if (ent.vn_aux > (size_t) (endbuf - vstart))
   10017 		  break;
   10018 		vstart += ent.vn_aux;
   10019 
   10020 		for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
   10021 		  {
   10022 		    Elf_External_Vernaux * eaux;
   10023 		    Elf_Internal_Vernaux aux;
   10024 
   10025 		    if (vstart + sizeof (*eaux) > endbuf)
   10026 		      break;
   10027 		    eaux = (Elf_External_Vernaux *) vstart;
   10028 
   10029 		    aux.vna_hash  = BYTE_GET (eaux->vna_hash);
   10030 		    aux.vna_flags = BYTE_GET (eaux->vna_flags);
   10031 		    aux.vna_other = BYTE_GET (eaux->vna_other);
   10032 		    aux.vna_name  = BYTE_GET (eaux->vna_name);
   10033 		    aux.vna_next  = BYTE_GET (eaux->vna_next);
   10034 
   10035 		    if (VALID_DYNAMIC_NAME (aux.vna_name))
   10036 		      printf (_("  %#06x:   Name: %s"),
   10037 			      isum, GET_DYNAMIC_NAME (aux.vna_name));
   10038 		    else
   10039 		      printf (_("  %#06x:   Name index: %lx"),
   10040 			      isum, aux.vna_name);
   10041 
   10042 		    printf (_("  Flags: %s  Version: %d\n"),
   10043 			    get_ver_flags (aux.vna_flags), aux.vna_other);
   10044 
   10045 		    /* Check for overflow.  */
   10046 		    if (aux.vna_next > (size_t) (endbuf - vstart)
   10047 			|| (aux.vna_next == 0 && j < ent.vn_cnt - 1))
   10048 		      {
   10049 			warn (_("Invalid vna_next field of %lx\n"),
   10050 			      aux.vna_next);
   10051 			j = ent.vn_cnt;
   10052 			break;
   10053 		      }
   10054 		    isum   += aux.vna_next;
   10055 		    vstart += aux.vna_next;
   10056 		  }
   10057 
   10058 		if (j < ent.vn_cnt)
   10059 		  warn (_("Missing Version Needs auxillary information\n"));
   10060 
   10061 		if (ent.vn_next == 0 && cnt < section->sh_info - 1)
   10062 		  {
   10063 		    warn (_("Corrupt Version Needs structure - offset to next structure is zero with entries still left to be processed\n"));
   10064 		    cnt = section->sh_info;
   10065 		    break;
   10066 		  }
   10067 		idx += ent.vn_next;
   10068 	      }
   10069 
   10070 	    if (cnt < section->sh_info)
   10071 	      warn (_("Missing Version Needs information\n"));
   10072 
   10073 	    free (eneed);
   10074 	  }
   10075 	  break;
   10076 
   10077 	case SHT_GNU_versym:
   10078 	  {
   10079 	    Elf_Internal_Shdr * link_section;
   10080 	    size_t total;
   10081 	    unsigned int cnt;
   10082 	    unsigned char * edata;
   10083 	    unsigned short * data;
   10084 	    char * strtab;
   10085 	    Elf_Internal_Sym * symbols;
   10086 	    Elf_Internal_Shdr * string_sec;
   10087 	    unsigned long num_syms;
   10088 	    long off;
   10089 
   10090 	    if (section->sh_link >= elf_header.e_shnum)
   10091 	      break;
   10092 
   10093 	    link_section = section_headers + section->sh_link;
   10094 	    total = section->sh_size / sizeof (Elf_External_Versym);
   10095 
   10096 	    if (link_section->sh_link >= elf_header.e_shnum)
   10097 	      break;
   10098 
   10099 	    found = 1;
   10100 
   10101 	    symbols = GET_ELF_SYMBOLS (file, link_section, & num_syms);
   10102 	    if (symbols == NULL)
   10103 	      break;
   10104 
   10105 	    string_sec = section_headers + link_section->sh_link;
   10106 
   10107 	    strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
   10108                                         string_sec->sh_size,
   10109                                         _("version string table"));
   10110 	    if (!strtab)
   10111 	      {
   10112 		free (symbols);
   10113 		break;
   10114 	      }
   10115 
   10116 	    printf (_("\nVersion symbols section '%s' contains %lu entries:\n"),
   10117 		    printable_section_name (section), (unsigned long) total);
   10118 
   10119 	    printf (_(" Addr: "));
   10120 	    printf_vma (section->sh_addr);
   10121 	    printf (_("  Offset: %#08lx  Link: %u (%s)\n"),
   10122 		    (unsigned long) section->sh_offset, section->sh_link,
   10123 		    printable_section_name (link_section));
   10124 
   10125 	    off = offset_from_vma (file,
   10126 				   version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
   10127 				   total * sizeof (short));
   10128 	    edata = (unsigned char *) get_data (NULL, file, off, total,
   10129                                                 sizeof (short),
   10130                                                 _("version symbol data"));
   10131 	    if (!edata)
   10132 	      {
   10133 		free (strtab);
   10134 		free (symbols);
   10135 		break;
   10136 	      }
   10137 
   10138 	    data = (short unsigned int *) cmalloc (total, sizeof (short));
   10139 
   10140 	    for (cnt = total; cnt --;)
   10141 	      data[cnt] = byte_get (edata + cnt * sizeof (short),
   10142 				    sizeof (short));
   10143 
   10144 	    free (edata);
   10145 
   10146 	    for (cnt = 0; cnt < total; cnt += 4)
   10147 	      {
   10148 		int j, nn;
   10149 		char *name;
   10150 		char *invalid = _("*invalid*");
   10151 
   10152 		printf ("  %03x:", cnt);
   10153 
   10154 		for (j = 0; (j < 4) && (cnt + j) < total; ++j)
   10155 		  switch (data[cnt + j])
   10156 		    {
   10157 		    case 0:
   10158 		      fputs (_("   0 (*local*)    "), stdout);
   10159 		      break;
   10160 
   10161 		    case 1:
   10162 		      fputs (_("   1 (*global*)   "), stdout);
   10163 		      break;
   10164 
   10165 		    default:
   10166 		      nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
   10167 				   data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
   10168 
   10169 		      /* If this index value is greater than the size of the symbols
   10170 		         array, break to avoid an out-of-bounds read.  */
   10171 		      if ((unsigned long)(cnt + j) >= num_syms)
   10172 		        {
   10173 		          warn (_("invalid index into symbol array\n"));
   10174 		          break;
   10175 			}
   10176 
   10177 		      name = NULL;
   10178 		      if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
   10179 			{
   10180 			  Elf_Internal_Verneed ivn;
   10181 			  unsigned long offset;
   10182 
   10183 			  offset = offset_from_vma
   10184 			    (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
   10185 			     sizeof (Elf_External_Verneed));
   10186 
   10187 			  do
   10188 			    {
   10189 			      Elf_Internal_Vernaux ivna;
   10190 			      Elf_External_Verneed evn;
   10191 			      Elf_External_Vernaux evna;
   10192 			      unsigned long a_off;
   10193 
   10194 			      if (get_data (&evn, file, offset, sizeof (evn), 1,
   10195 					    _("version need")) == NULL)
   10196 				break;
   10197 
   10198 			      ivn.vn_aux  = BYTE_GET (evn.vn_aux);
   10199 			      ivn.vn_next = BYTE_GET (evn.vn_next);
   10200 
   10201 			      a_off = offset + ivn.vn_aux;
   10202 
   10203 			      do
   10204 				{
   10205 				  if (get_data (&evna, file, a_off, sizeof (evna),
   10206 						1, _("version need aux (2)")) == NULL)
   10207 				    {
   10208 				      ivna.vna_next  = 0;
   10209 				      ivna.vna_other = 0;
   10210 				    }
   10211 				  else
   10212 				    {
   10213 				      ivna.vna_next  = BYTE_GET (evna.vna_next);
   10214 				      ivna.vna_other = BYTE_GET (evna.vna_other);
   10215 				    }
   10216 
   10217 				  a_off += ivna.vna_next;
   10218 				}
   10219 			      while (ivna.vna_other != data[cnt + j]
   10220 				     && ivna.vna_next != 0);
   10221 
   10222 			      if (ivna.vna_other == data[cnt + j])
   10223 				{
   10224 				  ivna.vna_name = BYTE_GET (evna.vna_name);
   10225 
   10226 				  if (ivna.vna_name >= string_sec->sh_size)
   10227 				    name = invalid;
   10228 				  else
   10229 				    name = strtab + ivna.vna_name;
   10230 				  break;
   10231 				}
   10232 
   10233 			      offset += ivn.vn_next;
   10234 			    }
   10235 			  while (ivn.vn_next);
   10236 			}
   10237 
   10238 		      if (data[cnt + j] != 0x8001
   10239 			  && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
   10240 			{
   10241 			  Elf_Internal_Verdef ivd;
   10242 			  Elf_External_Verdef evd;
   10243 			  unsigned long offset;
   10244 
   10245 			  offset = offset_from_vma
   10246 			    (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
   10247 			     sizeof evd);
   10248 
   10249 			  do
   10250 			    {
   10251 			      if (get_data (&evd, file, offset, sizeof (evd), 1,
   10252 					    _("version def")) == NULL)
   10253 				{
   10254 				  ivd.vd_next = 0;
   10255 				  /* PR 17531: file: 046-1082287-0.004.  */
   10256 				  ivd.vd_ndx  = (data[cnt + j] & VERSYM_VERSION) + 1;
   10257 				  break;
   10258 				}
   10259 			      else
   10260 				{
   10261 				  ivd.vd_next = BYTE_GET (evd.vd_next);
   10262 				  ivd.vd_ndx  = BYTE_GET (evd.vd_ndx);
   10263 				}
   10264 
   10265 			      offset += ivd.vd_next;
   10266 			    }
   10267 			  while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
   10268 				 && ivd.vd_next != 0);
   10269 
   10270 			  if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
   10271 			    {
   10272 			      Elf_External_Verdaux evda;
   10273 			      Elf_Internal_Verdaux ivda;
   10274 
   10275 			      ivd.vd_aux = BYTE_GET (evd.vd_aux);
   10276 
   10277 			      if (get_data (&evda, file,
   10278 					    offset - ivd.vd_next + ivd.vd_aux,
   10279 					    sizeof (evda), 1,
   10280 					    _("version def aux")) == NULL)
   10281 				break;
   10282 
   10283 			      ivda.vda_name = BYTE_GET (evda.vda_name);
   10284 
   10285 			      if (ivda.vda_name >= string_sec->sh_size)
   10286 				name = invalid;
   10287 			      else if (name != NULL && name != invalid)
   10288 				name = _("*both*");
   10289 			      else
   10290 				name = strtab + ivda.vda_name;
   10291 			    }
   10292 			}
   10293 		      if (name != NULL)
   10294 			nn += printf ("(%s%-*s",
   10295 				      name,
   10296 				      12 - (int) strlen (name),
   10297 				      ")");
   10298 
   10299 		      if (nn < 18)
   10300 			printf ("%*c", 18 - nn, ' ');
   10301 		    }
   10302 
   10303 		putchar ('\n');
   10304 	      }
   10305 
   10306 	    free (data);
   10307 	    free (strtab);
   10308 	    free (symbols);
   10309 	  }
   10310 	  break;
   10311 
   10312 	default:
   10313 	  break;
   10314 	}
   10315     }
   10316 
   10317   if (! found)
   10318     printf (_("\nNo version information found in this file.\n"));
   10319 
   10320   return 1;
   10321 }
   10322 
   10323 static const char *
   10324 get_symbol_binding (unsigned int binding)
   10325 {
   10326   static char buff[32];
   10327 
   10328   switch (binding)
   10329     {
   10330     case STB_LOCAL:	return "LOCAL";
   10331     case STB_GLOBAL:	return "GLOBAL";
   10332     case STB_WEAK:	return "WEAK";
   10333     default:
   10334       if (binding >= STB_LOPROC && binding <= STB_HIPROC)
   10335 	snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
   10336 		  binding);
   10337       else if (binding >= STB_LOOS && binding <= STB_HIOS)
   10338 	{
   10339 	  if (binding == STB_GNU_UNIQUE
   10340 	      && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
   10341 		  /* GNU is still using the default value 0.  */
   10342 		  || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
   10343 	    return "UNIQUE";
   10344 	  snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
   10345 	}
   10346       else
   10347 	snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
   10348       return buff;
   10349     }
   10350 }
   10351 
   10352 static const char *
   10353 get_symbol_type (unsigned int type)
   10354 {
   10355   static char buff[32];
   10356 
   10357   switch (type)
   10358     {
   10359     case STT_NOTYPE:	return "NOTYPE";
   10360     case STT_OBJECT:	return "OBJECT";
   10361     case STT_FUNC:	return "FUNC";
   10362     case STT_SECTION:	return "SECTION";
   10363     case STT_FILE:	return "FILE";
   10364     case STT_COMMON:	return "COMMON";
   10365     case STT_TLS:	return "TLS";
   10366     case STT_RELC:      return "RELC";
   10367     case STT_SRELC:     return "SRELC";
   10368     default:
   10369       if (type >= STT_LOPROC && type <= STT_HIPROC)
   10370 	{
   10371 	  if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
   10372 	    return "THUMB_FUNC";
   10373 
   10374 	  if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
   10375 	    return "REGISTER";
   10376 
   10377 	  if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
   10378 	    return "PARISC_MILLI";
   10379 
   10380 	  snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
   10381 	}
   10382       else if (type >= STT_LOOS && type <= STT_HIOS)
   10383 	{
   10384 	  if (elf_header.e_machine == EM_PARISC)
   10385 	    {
   10386 	      if (type == STT_HP_OPAQUE)
   10387 		return "HP_OPAQUE";
   10388 	      if (type == STT_HP_STUB)
   10389 		return "HP_STUB";
   10390 	    }
   10391 
   10392 	  if (type == STT_GNU_IFUNC
   10393 	      && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
   10394 		  || elf_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD
   10395 		  /* GNU is still using the default value 0.  */
   10396 		  || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
   10397 	    return "IFUNC";
   10398 
   10399 	  snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
   10400 	}
   10401       else
   10402 	snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
   10403       return buff;
   10404     }
   10405 }
   10406 
   10407 static const char *
   10408 get_symbol_visibility (unsigned int visibility)
   10409 {
   10410   switch (visibility)
   10411     {
   10412     case STV_DEFAULT:	return "DEFAULT";
   10413     case STV_INTERNAL:	return "INTERNAL";
   10414     case STV_HIDDEN:	return "HIDDEN";
   10415     case STV_PROTECTED: return "PROTECTED";
   10416     default:
   10417       error (_("Unrecognized visibility value: %u"), visibility);
   10418       return _("<unknown>");
   10419     }
   10420 }
   10421 
   10422 static const char *
   10423 get_solaris_symbol_visibility (unsigned int visibility)
   10424 {
   10425   switch (visibility)
   10426     {
   10427     case 4: return "EXPORTED";
   10428     case 5: return "SINGLETON";
   10429     case 6: return "ELIMINATE";
   10430     default: return get_symbol_visibility (visibility);
   10431     }
   10432 }
   10433 
   10434 static const char *
   10435 get_mips_symbol_other (unsigned int other)
   10436 {
   10437   switch (other)
   10438     {
   10439     case STO_OPTIONAL:
   10440       return "OPTIONAL";
   10441     case STO_MIPS_PLT:
   10442       return "MIPS PLT";
   10443     case STO_MIPS_PIC:
   10444       return "MIPS PIC";
   10445     case STO_MICROMIPS:
   10446       return "MICROMIPS";
   10447     case STO_MICROMIPS | STO_MIPS_PIC:
   10448       return "MICROMIPS, MIPS PIC";
   10449     case STO_MIPS16:
   10450       return "MIPS16";
   10451     default:
   10452       return NULL;
   10453     }
   10454 }
   10455 
   10456 static const char *
   10457 get_ia64_symbol_other (unsigned int other)
   10458 {
   10459   if (is_ia64_vms ())
   10460     {
   10461       static char res[32];
   10462 
   10463       res[0] = 0;
   10464 
   10465       /* Function types is for images and .STB files only.  */
   10466       switch (elf_header.e_type)
   10467         {
   10468         case ET_DYN:
   10469         case ET_EXEC:
   10470           switch (VMS_ST_FUNC_TYPE (other))
   10471             {
   10472             case VMS_SFT_CODE_ADDR:
   10473               strcat (res, " CA");
   10474               break;
   10475             case VMS_SFT_SYMV_IDX:
   10476               strcat (res, " VEC");
   10477               break;
   10478             case VMS_SFT_FD:
   10479               strcat (res, " FD");
   10480               break;
   10481             case VMS_SFT_RESERVE:
   10482               strcat (res, " RSV");
   10483               break;
   10484             default:
   10485 	      warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
   10486 		    VMS_ST_FUNC_TYPE (other));
   10487 	      strcat (res, " <unknown>");
   10488 	      break;
   10489             }
   10490           break;
   10491         default:
   10492           break;
   10493         }
   10494       switch (VMS_ST_LINKAGE (other))
   10495         {
   10496         case VMS_STL_IGNORE:
   10497           strcat (res, " IGN");
   10498           break;
   10499         case VMS_STL_RESERVE:
   10500           strcat (res, " RSV");
   10501           break;
   10502         case VMS_STL_STD:
   10503           strcat (res, " STD");
   10504           break;
   10505         case VMS_STL_LNK:
   10506           strcat (res, " LNK");
   10507           break;
   10508         default:
   10509 	  warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
   10510 		VMS_ST_LINKAGE (other));
   10511 	  strcat (res, " <unknown>");
   10512 	  break;
   10513         }
   10514 
   10515       if (res[0] != 0)
   10516         return res + 1;
   10517       else
   10518         return res;
   10519     }
   10520   return NULL;
   10521 }
   10522 
   10523 static const char *
   10524 get_ppc64_symbol_other (unsigned int other)
   10525 {
   10526   if (PPC64_LOCAL_ENTRY_OFFSET (other) != 0)
   10527     {
   10528       static char buf[32];
   10529       snprintf (buf, sizeof buf, _("<localentry>: %d"),
   10530 		PPC64_LOCAL_ENTRY_OFFSET (other));
   10531       return buf;
   10532     }
   10533   return NULL;
   10534 }
   10535 
   10536 static const char *
   10537 get_symbol_other (unsigned int other)
   10538 {
   10539   const char * result = NULL;
   10540   static char buff [32];
   10541 
   10542   if (other == 0)
   10543     return "";
   10544 
   10545   switch (elf_header.e_machine)
   10546     {
   10547     case EM_MIPS:
   10548       result = get_mips_symbol_other (other);
   10549       break;
   10550     case EM_IA_64:
   10551       result = get_ia64_symbol_other (other);
   10552       break;
   10553     case EM_PPC64:
   10554       result = get_ppc64_symbol_other (other);
   10555       break;
   10556     default:
   10557       result = NULL;
   10558       break;
   10559     }
   10560 
   10561   if (result)
   10562     return result;
   10563 
   10564   snprintf (buff, sizeof buff, _("<other>: %x"), other);
   10565   return buff;
   10566 }
   10567 
   10568 static const char *
   10569 get_symbol_index_type (unsigned int type)
   10570 {
   10571   static char buff[32];
   10572 
   10573   switch (type)
   10574     {
   10575     case SHN_UNDEF:	return "UND";
   10576     case SHN_ABS:	return "ABS";
   10577     case SHN_COMMON:	return "COM";
   10578     default:
   10579       if (type == SHN_IA_64_ANSI_COMMON
   10580 	  && elf_header.e_machine == EM_IA_64
   10581 	  && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
   10582 	return "ANSI_COM";
   10583       else if ((elf_header.e_machine == EM_X86_64
   10584 		|| elf_header.e_machine == EM_L1OM
   10585 		|| elf_header.e_machine == EM_K1OM)
   10586 	       && type == SHN_X86_64_LCOMMON)
   10587 	return "LARGE_COM";
   10588       else if ((type == SHN_MIPS_SCOMMON
   10589 		&& elf_header.e_machine == EM_MIPS)
   10590 	       || (type == SHN_TIC6X_SCOMMON
   10591 		   && elf_header.e_machine == EM_TI_C6000))
   10592 	return "SCOM";
   10593       else if (type == SHN_MIPS_SUNDEFINED
   10594 	       && elf_header.e_machine == EM_MIPS)
   10595 	return "SUND";
   10596       else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
   10597 	sprintf (buff, "PRC[0x%04x]", type & 0xffff);
   10598       else if (type >= SHN_LOOS && type <= SHN_HIOS)
   10599 	sprintf (buff, "OS [0x%04x]", type & 0xffff);
   10600       else if (type >= SHN_LORESERVE)
   10601 	sprintf (buff, "RSV[0x%04x]", type & 0xffff);
   10602       else if (type >= elf_header.e_shnum)
   10603 	sprintf (buff, _("bad section index[%3d]"), type);
   10604       else
   10605 	sprintf (buff, "%3d", type);
   10606       break;
   10607     }
   10608 
   10609   return buff;
   10610 }
   10611 
   10612 static bfd_vma *
   10613 get_dynamic_data (FILE * file, bfd_size_type number, unsigned int ent_size)
   10614 {
   10615   unsigned char * e_data;
   10616   bfd_vma * i_data;
   10617 
   10618   /* If the size_t type is smaller than the bfd_size_type, eg because
   10619      you are building a 32-bit tool on a 64-bit host, then make sure
   10620      that when (number) is cast to (size_t) no information is lost.  */
   10621   if (sizeof (size_t) < sizeof (bfd_size_type)
   10622       && (bfd_size_type) ((size_t) number) != number)
   10623     {
   10624       error (_("Size truncation prevents reading %" BFD_VMA_FMT "u"
   10625 	       " elements of size %u\n"),
   10626 	     number, ent_size);
   10627       return NULL;
   10628     }
   10629 
   10630   /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
   10631      attempting to allocate memory when the read is bound to fail.  */
   10632   if (ent_size * number > current_file_size)
   10633     {
   10634       error (_("Invalid number of dynamic entries: %" BFD_VMA_FMT "u\n"),
   10635 	     number);
   10636       return NULL;
   10637     }
   10638 
   10639   e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
   10640   if (e_data == NULL)
   10641     {
   10642       error (_("Out of memory reading %" BFD_VMA_FMT "u dynamic entries\n"),
   10643 	     number);
   10644       return NULL;
   10645     }
   10646 
   10647   if (fread (e_data, ent_size, (size_t) number, file) != number)
   10648     {
   10649       error (_("Unable to read in %" BFD_VMA_FMT "u bytes of dynamic data\n"),
   10650 	     number * ent_size);
   10651       free (e_data);
   10652       return NULL;
   10653     }
   10654 
   10655   i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
   10656   if (i_data == NULL)
   10657     {
   10658       error (_("Out of memory allocating space for %" BFD_VMA_FMT "u"
   10659 	       " dynamic entries\n"),
   10660 	     number);
   10661       free (e_data);
   10662       return NULL;
   10663     }
   10664 
   10665   while (number--)
   10666     i_data[number] = byte_get (e_data + number * ent_size, ent_size);
   10667 
   10668   free (e_data);
   10669 
   10670   return i_data;
   10671 }
   10672 
   10673 static void
   10674 print_dynamic_symbol (bfd_vma si, unsigned long hn)
   10675 {
   10676   Elf_Internal_Sym * psym;
   10677   int n;
   10678 
   10679   n = print_vma (si, DEC_5);
   10680   if (n < 5)
   10681     fputs (&"     "[n], stdout);
   10682   printf (" %3lu: ", hn);
   10683 
   10684   if (dynamic_symbols == NULL || si >= num_dynamic_syms)
   10685     {
   10686       printf (_("<No info available for dynamic symbol number %lu>\n"),
   10687 	      (unsigned long) si);
   10688       return;
   10689     }
   10690 
   10691   psym = dynamic_symbols + si;
   10692   print_vma (psym->st_value, LONG_HEX);
   10693   putchar (' ');
   10694   print_vma (psym->st_size, DEC_5);
   10695 
   10696   printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
   10697   printf (" %-6s",  get_symbol_binding (ELF_ST_BIND (psym->st_info)));
   10698 
   10699   if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
   10700     printf (" %-7s",  get_solaris_symbol_visibility (psym->st_other));
   10701   else
   10702     {
   10703       unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
   10704 
   10705       printf (" %-7s",  get_symbol_visibility (vis));
   10706       /* Check to see if any other bits in the st_other field are set.
   10707 	 Note - displaying this information disrupts the layout of the
   10708 	 table being generated, but for the moment this case is very
   10709 	 rare.  */
   10710       if (psym->st_other ^ vis)
   10711 	printf (" [%s] ", get_symbol_other (psym->st_other ^ vis));
   10712     }
   10713 
   10714   printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
   10715   if (VALID_DYNAMIC_NAME (psym->st_name))
   10716     print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
   10717   else
   10718     printf (_(" <corrupt: %14ld>"), psym->st_name);
   10719   putchar ('\n');
   10720 }
   10721 
   10722 static const char *
   10723 get_symbol_version_string (FILE *file, int is_dynsym,
   10724 			   const char *strtab,
   10725 			   unsigned long int strtab_size,
   10726 			   unsigned int si, Elf_Internal_Sym *psym,
   10727 			   enum versioned_symbol_info *sym_info,
   10728 			   unsigned short *vna_other)
   10729 {
   10730   unsigned char data[2];
   10731   unsigned short vers_data;
   10732   unsigned long offset;
   10733 
   10734   if (!is_dynsym
   10735       || version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
   10736     return NULL;
   10737 
   10738   offset = offset_from_vma (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
   10739 			    sizeof data + si * sizeof (vers_data));
   10740 
   10741   if (get_data (&data, file, offset + si * sizeof (vers_data),
   10742 		sizeof (data), 1, _("version data")) == NULL)
   10743     return NULL;
   10744 
   10745   vers_data = byte_get (data, 2);
   10746 
   10747   if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data <= 1)
   10748     return NULL;
   10749 
   10750   /* Usually we'd only see verdef for defined symbols, and verneed for
   10751      undefined symbols.  However, symbols defined by the linker in
   10752      .dynbss for variables copied from a shared library in order to
   10753      avoid text relocations are defined yet have verneed.  We could
   10754      use a heuristic to detect the special case, for example, check
   10755      for verneed first on symbols defined in SHT_NOBITS sections, but
   10756      it is simpler and more reliable to just look for both verdef and
   10757      verneed.  .dynbss might not be mapped to a SHT_NOBITS section.  */
   10758 
   10759   if (psym->st_shndx != SHN_UNDEF
   10760       && vers_data != 0x8001
   10761       && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
   10762     {
   10763       Elf_Internal_Verdef ivd;
   10764       Elf_Internal_Verdaux ivda;
   10765       Elf_External_Verdaux evda;
   10766       unsigned long off;
   10767 
   10768       off = offset_from_vma (file,
   10769 			     version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
   10770 			     sizeof (Elf_External_Verdef));
   10771 
   10772       do
   10773 	{
   10774 	  Elf_External_Verdef evd;
   10775 
   10776 	  if (get_data (&evd, file, off, sizeof (evd), 1,
   10777 			_("version def")) == NULL)
   10778 	    {
   10779 	      ivd.vd_ndx = 0;
   10780 	      ivd.vd_aux = 0;
   10781 	      ivd.vd_next = 0;
   10782 	    }
   10783 	  else
   10784 	    {
   10785 	      ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
   10786 	      ivd.vd_aux = BYTE_GET (evd.vd_aux);
   10787 	      ivd.vd_next = BYTE_GET (evd.vd_next);
   10788 	    }
   10789 
   10790 	  off += ivd.vd_next;
   10791 	}
   10792       while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
   10793 
   10794       if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
   10795 	{
   10796 	  off -= ivd.vd_next;
   10797 	  off += ivd.vd_aux;
   10798 
   10799 	  if (get_data (&evda, file, off, sizeof (evda), 1,
   10800 			_("version def aux")) != NULL)
   10801 	    {
   10802 	      ivda.vda_name = BYTE_GET (evda.vda_name);
   10803 
   10804 	      if (psym->st_name != ivda.vda_name)
   10805 		{
   10806 		  *sym_info = ((vers_data & VERSYM_HIDDEN) != 0
   10807 			       ? symbol_hidden : symbol_public);
   10808 		  return (ivda.vda_name < strtab_size
   10809 			  ? strtab + ivda.vda_name : _("<corrupt>"));
   10810 		}
   10811 	    }
   10812 	}
   10813     }
   10814 
   10815   if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
   10816     {
   10817       Elf_External_Verneed evn;
   10818       Elf_Internal_Verneed ivn;
   10819       Elf_Internal_Vernaux ivna;
   10820 
   10821       offset = offset_from_vma (file,
   10822 				version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
   10823 				sizeof evn);
   10824       do
   10825 	{
   10826 	  unsigned long vna_off;
   10827 
   10828 	  if (get_data (&evn, file, offset, sizeof (evn), 1,
   10829 			_("version need")) == NULL)
   10830 	    {
   10831 	      ivna.vna_next = 0;
   10832 	      ivna.vna_other = 0;
   10833 	      ivna.vna_name = 0;
   10834 	      break;
   10835 	    }
   10836 
   10837 	  ivn.vn_aux  = BYTE_GET (evn.vn_aux);
   10838 	  ivn.vn_next = BYTE_GET (evn.vn_next);
   10839 
   10840 	  vna_off = offset + ivn.vn_aux;
   10841 
   10842 	  do
   10843 	    {
   10844 	      Elf_External_Vernaux evna;
   10845 
   10846 	      if (get_data (&evna, file, vna_off, sizeof (evna), 1,
   10847 			    _("version need aux (3)")) == NULL)
   10848 		{
   10849 		  ivna.vna_next = 0;
   10850 		  ivna.vna_other = 0;
   10851 		  ivna.vna_name = 0;
   10852 		}
   10853 	      else
   10854 		{
   10855 		  ivna.vna_other = BYTE_GET (evna.vna_other);
   10856 		  ivna.vna_next  = BYTE_GET (evna.vna_next);
   10857 		  ivna.vna_name  = BYTE_GET (evna.vna_name);
   10858 		}
   10859 
   10860 	      vna_off += ivna.vna_next;
   10861 	    }
   10862 	  while (ivna.vna_other != vers_data && ivna.vna_next != 0);
   10863 
   10864 	  if (ivna.vna_other == vers_data)
   10865 	    break;
   10866 
   10867 	  offset += ivn.vn_next;
   10868 	}
   10869       while (ivn.vn_next != 0);
   10870 
   10871       if (ivna.vna_other == vers_data)
   10872 	{
   10873 	  *sym_info = symbol_undefined;
   10874 	  *vna_other = ivna.vna_other;
   10875 	  return (ivna.vna_name < strtab_size
   10876 		  ? strtab + ivna.vna_name : _("<corrupt>"));
   10877 	}
   10878     }
   10879   return NULL;
   10880 }
   10881 
   10882 /* Dump the symbol table.  */
   10883 static int
   10884 process_symbol_table (FILE * file)
   10885 {
   10886   Elf_Internal_Shdr * section;
   10887   bfd_size_type nbuckets = 0;
   10888   bfd_size_type nchains = 0;
   10889   bfd_vma * buckets = NULL;
   10890   bfd_vma * chains = NULL;
   10891   bfd_vma ngnubuckets = 0;
   10892   bfd_vma * gnubuckets = NULL;
   10893   bfd_vma * gnuchains = NULL;
   10894   bfd_vma gnusymidx = 0;
   10895   bfd_size_type ngnuchains = 0;
   10896 
   10897   if (!do_syms && !do_dyn_syms && !do_histogram)
   10898     return 1;
   10899 
   10900   if (dynamic_info[DT_HASH]
   10901       && (do_histogram
   10902 	  || (do_using_dynamic
   10903 	      && !do_dyn_syms
   10904 	      && dynamic_strings != NULL)))
   10905     {
   10906       unsigned char nb[8];
   10907       unsigned char nc[8];
   10908       unsigned int hash_ent_size = 4;
   10909 
   10910       if ((elf_header.e_machine == EM_ALPHA
   10911 	   || elf_header.e_machine == EM_S390
   10912 	   || elf_header.e_machine == EM_S390_OLD)
   10913 	  && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
   10914 	hash_ent_size = 8;
   10915 
   10916       if (fseek (file,
   10917 		 (archive_file_offset
   10918 		  + offset_from_vma (file, dynamic_info[DT_HASH],
   10919 				     sizeof nb + sizeof nc)),
   10920 		 SEEK_SET))
   10921 	{
   10922 	  error (_("Unable to seek to start of dynamic information\n"));
   10923 	  goto no_hash;
   10924 	}
   10925 
   10926       if (fread (nb, hash_ent_size, 1, file) != 1)
   10927 	{
   10928 	  error (_("Failed to read in number of buckets\n"));
   10929 	  goto no_hash;
   10930 	}
   10931 
   10932       if (fread (nc, hash_ent_size, 1, file) != 1)
   10933 	{
   10934 	  error (_("Failed to read in number of chains\n"));
   10935 	  goto no_hash;
   10936 	}
   10937 
   10938       nbuckets = byte_get (nb, hash_ent_size);
   10939       nchains  = byte_get (nc, hash_ent_size);
   10940 
   10941       buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
   10942       chains  = get_dynamic_data (file, nchains, hash_ent_size);
   10943 
   10944     no_hash:
   10945       if (buckets == NULL || chains == NULL)
   10946 	{
   10947 	  if (do_using_dynamic)
   10948 	    return 0;
   10949 	  free (buckets);
   10950 	  free (chains);
   10951 	  buckets = NULL;
   10952 	  chains = NULL;
   10953 	  nbuckets = 0;
   10954 	  nchains = 0;
   10955 	}
   10956     }
   10957 
   10958   if (dynamic_info_DT_GNU_HASH
   10959       && (do_histogram
   10960 	  || (do_using_dynamic
   10961 	      && !do_dyn_syms
   10962 	      && dynamic_strings != NULL)))
   10963     {
   10964       unsigned char nb[16];
   10965       bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
   10966       bfd_vma buckets_vma;
   10967 
   10968       if (fseek (file,
   10969 		 (archive_file_offset
   10970 		  + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
   10971 				     sizeof nb)),
   10972 		 SEEK_SET))
   10973 	{
   10974 	  error (_("Unable to seek to start of dynamic information\n"));
   10975 	  goto no_gnu_hash;
   10976 	}
   10977 
   10978       if (fread (nb, 16, 1, file) != 1)
   10979 	{
   10980 	  error (_("Failed to read in number of buckets\n"));
   10981 	  goto no_gnu_hash;
   10982 	}
   10983 
   10984       ngnubuckets = byte_get (nb, 4);
   10985       gnusymidx = byte_get (nb + 4, 4);
   10986       bitmaskwords = byte_get (nb + 8, 4);
   10987       buckets_vma = dynamic_info_DT_GNU_HASH + 16;
   10988       if (is_32bit_elf)
   10989 	buckets_vma += bitmaskwords * 4;
   10990       else
   10991 	buckets_vma += bitmaskwords * 8;
   10992 
   10993       if (fseek (file,
   10994 		 (archive_file_offset
   10995 		  + offset_from_vma (file, buckets_vma, 4)),
   10996 		 SEEK_SET))
   10997 	{
   10998 	  error (_("Unable to seek to start of dynamic information\n"));
   10999 	  goto no_gnu_hash;
   11000 	}
   11001 
   11002       gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
   11003 
   11004       if (gnubuckets == NULL)
   11005 	goto no_gnu_hash;
   11006 
   11007       for (i = 0; i < ngnubuckets; i++)
   11008 	if (gnubuckets[i] != 0)
   11009 	  {
   11010 	    if (gnubuckets[i] < gnusymidx)
   11011 	      return 0;
   11012 
   11013 	    if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
   11014 	      maxchain = gnubuckets[i];
   11015 	  }
   11016 
   11017       if (maxchain == 0xffffffff)
   11018 	goto no_gnu_hash;
   11019 
   11020       maxchain -= gnusymidx;
   11021 
   11022       if (fseek (file,
   11023 		 (archive_file_offset
   11024 		  + offset_from_vma (file, buckets_vma
   11025 					   + 4 * (ngnubuckets + maxchain), 4)),
   11026 		 SEEK_SET))
   11027 	{
   11028 	  error (_("Unable to seek to start of dynamic information\n"));
   11029 	  goto no_gnu_hash;
   11030 	}
   11031 
   11032       do
   11033 	{
   11034 	  if (fread (nb, 4, 1, file) != 1)
   11035 	    {
   11036 	      error (_("Failed to determine last chain length\n"));
   11037 	      goto no_gnu_hash;
   11038 	    }
   11039 
   11040 	  if (maxchain + 1 == 0)
   11041 	    goto no_gnu_hash;
   11042 
   11043 	  ++maxchain;
   11044 	}
   11045       while ((byte_get (nb, 4) & 1) == 0);
   11046 
   11047       if (fseek (file,
   11048 		 (archive_file_offset
   11049 		  + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
   11050 		 SEEK_SET))
   11051 	{
   11052 	  error (_("Unable to seek to start of dynamic information\n"));
   11053 	  goto no_gnu_hash;
   11054 	}
   11055 
   11056       gnuchains = get_dynamic_data (file, maxchain, 4);
   11057       ngnuchains = maxchain;
   11058 
   11059     no_gnu_hash:
   11060       if (gnuchains == NULL)
   11061 	{
   11062 	  free (gnubuckets);
   11063 	  gnubuckets = NULL;
   11064 	  ngnubuckets = 0;
   11065 	  if (do_using_dynamic)
   11066 	    return 0;
   11067 	}
   11068     }
   11069 
   11070   if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
   11071       && do_syms
   11072       && do_using_dynamic
   11073       && dynamic_strings != NULL
   11074       && dynamic_symbols != NULL)
   11075     {
   11076       unsigned long hn;
   11077 
   11078       if (dynamic_info[DT_HASH])
   11079 	{
   11080 	  bfd_vma si;
   11081 
   11082 	  printf (_("\nSymbol table for image:\n"));
   11083 	  if (is_32bit_elf)
   11084 	    printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
   11085 	  else
   11086 	    printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
   11087 
   11088 	  for (hn = 0; hn < nbuckets; hn++)
   11089 	    {
   11090 	      if (! buckets[hn])
   11091 		continue;
   11092 
   11093 	      for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
   11094 		print_dynamic_symbol (si, hn);
   11095 	    }
   11096 	}
   11097 
   11098       if (dynamic_info_DT_GNU_HASH)
   11099 	{
   11100 	  printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
   11101 	  if (is_32bit_elf)
   11102 	    printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
   11103 	  else
   11104 	    printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
   11105 
   11106 	  for (hn = 0; hn < ngnubuckets; ++hn)
   11107 	    if (gnubuckets[hn] != 0)
   11108 	      {
   11109 		bfd_vma si = gnubuckets[hn];
   11110 		bfd_vma off = si - gnusymidx;
   11111 
   11112 		do
   11113 		  {
   11114 		    print_dynamic_symbol (si, hn);
   11115 		    si++;
   11116 		  }
   11117 		while (off < ngnuchains && (gnuchains[off++] & 1) == 0);
   11118 	      }
   11119 	}
   11120     }
   11121   else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
   11122 	   && section_headers != NULL)
   11123     {
   11124       unsigned int i;
   11125 
   11126       for (i = 0, section = section_headers;
   11127 	   i < elf_header.e_shnum;
   11128 	   i++, section++)
   11129 	{
   11130 	  unsigned int si;
   11131 	  char * strtab = NULL;
   11132 	  unsigned long int strtab_size = 0;
   11133 	  Elf_Internal_Sym * symtab;
   11134 	  Elf_Internal_Sym * psym;
   11135 	  unsigned long num_syms;
   11136 
   11137 	  if ((section->sh_type != SHT_SYMTAB
   11138 	       && section->sh_type != SHT_DYNSYM)
   11139 	      || (!do_syms
   11140 		  && section->sh_type == SHT_SYMTAB))
   11141 	    continue;
   11142 
   11143 	  if (section->sh_entsize == 0)
   11144 	    {
   11145 	      printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
   11146 		      printable_section_name (section));
   11147 	      continue;
   11148 	    }
   11149 
   11150 	  printf (_("\nSymbol table '%s' contains %lu entries:\n"),
   11151 		  printable_section_name (section),
   11152 		  (unsigned long) (section->sh_size / section->sh_entsize));
   11153 
   11154 	  if (is_32bit_elf)
   11155 	    printf (_("   Num:    Value  Size Type    Bind   Vis      Ndx Name\n"));
   11156 	  else
   11157 	    printf (_("   Num:    Value          Size Type    Bind   Vis      Ndx Name\n"));
   11158 
   11159 	  symtab = GET_ELF_SYMBOLS (file, section, & num_syms);
   11160 	  if (symtab == NULL)
   11161 	    continue;
   11162 
   11163 	  if (section->sh_link == elf_header.e_shstrndx)
   11164 	    {
   11165 	      strtab = string_table;
   11166 	      strtab_size = string_table_length;
   11167 	    }
   11168 	  else if (section->sh_link < elf_header.e_shnum)
   11169 	    {
   11170 	      Elf_Internal_Shdr * string_sec;
   11171 
   11172 	      string_sec = section_headers + section->sh_link;
   11173 
   11174 	      strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
   11175                                           1, string_sec->sh_size,
   11176                                           _("string table"));
   11177 	      strtab_size = strtab != NULL ? string_sec->sh_size : 0;
   11178 	    }
   11179 
   11180 	  for (si = 0, psym = symtab; si < num_syms; si++, psym++)
   11181 	    {
   11182 	      const char *version_string;
   11183 	      enum versioned_symbol_info sym_info;
   11184 	      unsigned short vna_other;
   11185 
   11186 	      printf ("%6d: ", si);
   11187 	      print_vma (psym->st_value, LONG_HEX);
   11188 	      putchar (' ');
   11189 	      print_vma (psym->st_size, DEC_5);
   11190 	      printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
   11191 	      printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
   11192 	      if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
   11193 		printf (" %-7s",  get_solaris_symbol_visibility (psym->st_other));
   11194 	      else
   11195 		{
   11196 		  unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
   11197 
   11198 		  printf (" %-7s", get_symbol_visibility (vis));
   11199 		  /* Check to see if any other bits in the st_other field are set.
   11200 		     Note - displaying this information disrupts the layout of the
   11201 		     table being generated, but for the moment this case is very rare.  */
   11202 		  if (psym->st_other ^ vis)
   11203 		    printf (" [%s] ", get_symbol_other (psym->st_other ^ vis));
   11204 		}
   11205 	      printf (" %4s ", get_symbol_index_type (psym->st_shndx));
   11206 	      print_symbol (25, psym->st_name < strtab_size
   11207 			    ? strtab + psym->st_name : _("<corrupt>"));
   11208 
   11209 	      version_string
   11210 		= get_symbol_version_string (file,
   11211 					     section->sh_type == SHT_DYNSYM,
   11212 					     strtab, strtab_size, si,
   11213 					     psym, &sym_info, &vna_other);
   11214 	      if (version_string)
   11215 		{
   11216 		  if (sym_info == symbol_undefined)
   11217 		    printf ("@%s (%d)", version_string, vna_other);
   11218 		  else
   11219 		    printf (sym_info == symbol_hidden ? "@%s" : "@@%s",
   11220 			    version_string);
   11221 		}
   11222 
   11223 	      putchar ('\n');
   11224 	    }
   11225 
   11226 	  free (symtab);
   11227 	  if (strtab != string_table)
   11228 	    free (strtab);
   11229 	}
   11230     }
   11231   else if (do_syms)
   11232     printf
   11233       (_("\nDynamic symbol information is not available for displaying symbols.\n"));
   11234 
   11235   if (do_histogram && buckets != NULL)
   11236     {
   11237       unsigned long * lengths;
   11238       unsigned long * counts;
   11239       unsigned long hn;
   11240       bfd_vma si;
   11241       unsigned long maxlength = 0;
   11242       unsigned long nzero_counts = 0;
   11243       unsigned long nsyms = 0;
   11244       unsigned long chained;
   11245 
   11246       printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
   11247 	      (unsigned long) nbuckets);
   11248 
   11249       lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
   11250       if (lengths == NULL)
   11251 	{
   11252 	  error (_("Out of memory allocating space for histogram buckets\n"));
   11253 	  return 0;
   11254 	}
   11255 
   11256       printf (_(" Length  Number     %% of total  Coverage\n"));
   11257       for (hn = 0; hn < nbuckets; ++hn)
   11258 	{
   11259 	  for (si = buckets[hn], chained = 0;
   11260 	       si > 0 && si < nchains && si < nbuckets && chained <= nchains;
   11261 	       si = chains[si], ++chained)
   11262 	    {
   11263 	      ++nsyms;
   11264 	      if (maxlength < ++lengths[hn])
   11265 		++maxlength;
   11266 	    }
   11267 
   11268 	    /* PR binutils/17531: A corrupt binary could contain broken
   11269 	       histogram data.  Do not go into an infinite loop trying
   11270 	       to process it.  */
   11271 	    if (chained > nchains)
   11272 	      {
   11273 		error (_("histogram chain is corrupt\n"));
   11274 		break;
   11275 	      }
   11276 	}
   11277 
   11278       counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
   11279       if (counts == NULL)
   11280 	{
   11281 	  free (lengths);
   11282 	  error (_("Out of memory allocating space for histogram counts\n"));
   11283 	  return 0;
   11284 	}
   11285 
   11286       for (hn = 0; hn < nbuckets; ++hn)
   11287 	++counts[lengths[hn]];
   11288 
   11289       if (nbuckets > 0)
   11290 	{
   11291 	  unsigned long i;
   11292 	  printf ("      0  %-10lu (%5.1f%%)\n",
   11293 		  counts[0], (counts[0] * 100.0) / nbuckets);
   11294 	  for (i = 1; i <= maxlength; ++i)
   11295 	    {
   11296 	      nzero_counts += counts[i] * i;
   11297 	      printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
   11298 		      i, counts[i], (counts[i] * 100.0) / nbuckets,
   11299 		      (nzero_counts * 100.0) / nsyms);
   11300 	    }
   11301 	}
   11302 
   11303       free (counts);
   11304       free (lengths);
   11305     }
   11306 
   11307   if (buckets != NULL)
   11308     {
   11309       free (buckets);
   11310       free (chains);
   11311     }
   11312 
   11313   if (do_histogram && gnubuckets != NULL)
   11314     {
   11315       unsigned long * lengths;
   11316       unsigned long * counts;
   11317       unsigned long hn;
   11318       unsigned long maxlength = 0;
   11319       unsigned long nzero_counts = 0;
   11320       unsigned long nsyms = 0;
   11321 
   11322       printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
   11323 	      (unsigned long) ngnubuckets);
   11324 
   11325       lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
   11326       if (lengths == NULL)
   11327 	{
   11328 	  error (_("Out of memory allocating space for gnu histogram buckets\n"));
   11329 	  return 0;
   11330 	}
   11331 
   11332       printf (_(" Length  Number     %% of total  Coverage\n"));
   11333 
   11334       for (hn = 0; hn < ngnubuckets; ++hn)
   11335 	if (gnubuckets[hn] != 0)
   11336 	  {
   11337 	    bfd_vma off, length = 1;
   11338 
   11339 	    for (off = gnubuckets[hn] - gnusymidx;
   11340 		 /* PR 17531 file: 010-77222-0.004.  */
   11341 		 off < ngnuchains && (gnuchains[off] & 1) == 0;
   11342 		 ++off)
   11343 	      ++length;
   11344 	    lengths[hn] = length;
   11345 	    if (length > maxlength)
   11346 	      maxlength = length;
   11347 	    nsyms += length;
   11348 	  }
   11349 
   11350       counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
   11351       if (counts == NULL)
   11352 	{
   11353 	  free (lengths);
   11354 	  error (_("Out of memory allocating space for gnu histogram counts\n"));
   11355 	  return 0;
   11356 	}
   11357 
   11358       for (hn = 0; hn < ngnubuckets; ++hn)
   11359 	++counts[lengths[hn]];
   11360 
   11361       if (ngnubuckets > 0)
   11362 	{
   11363 	  unsigned long j;
   11364 	  printf ("      0  %-10lu (%5.1f%%)\n",
   11365 		  counts[0], (counts[0] * 100.0) / ngnubuckets);
   11366 	  for (j = 1; j <= maxlength; ++j)
   11367 	    {
   11368 	      nzero_counts += counts[j] * j;
   11369 	      printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
   11370 		      j, counts[j], (counts[j] * 100.0) / ngnubuckets,
   11371 		      (nzero_counts * 100.0) / nsyms);
   11372 	    }
   11373 	}
   11374 
   11375       free (counts);
   11376       free (lengths);
   11377       free (gnubuckets);
   11378       free (gnuchains);
   11379     }
   11380 
   11381   return 1;
   11382 }
   11383 
   11384 static int
   11385 process_syminfo (FILE * file ATTRIBUTE_UNUSED)
   11386 {
   11387   unsigned int i;
   11388 
   11389   if (dynamic_syminfo == NULL
   11390       || !do_dynamic)
   11391     /* No syminfo, this is ok.  */
   11392     return 1;
   11393 
   11394   /* There better should be a dynamic symbol section.  */
   11395   if (dynamic_symbols == NULL || dynamic_strings == NULL)
   11396     return 0;
   11397 
   11398   if (dynamic_addr)
   11399     printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
   11400 	    dynamic_syminfo_offset, dynamic_syminfo_nent);
   11401 
   11402   printf (_(" Num: Name                           BoundTo     Flags\n"));
   11403   for (i = 0; i < dynamic_syminfo_nent; ++i)
   11404     {
   11405       unsigned short int flags = dynamic_syminfo[i].si_flags;
   11406 
   11407       printf ("%4d: ", i);
   11408       if (i >= num_dynamic_syms)
   11409 	printf (_("<corrupt index>"));
   11410       else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
   11411 	print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
   11412       else
   11413 	printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
   11414       putchar (' ');
   11415 
   11416       switch (dynamic_syminfo[i].si_boundto)
   11417 	{
   11418 	case SYMINFO_BT_SELF:
   11419 	  fputs ("SELF       ", stdout);
   11420 	  break;
   11421 	case SYMINFO_BT_PARENT:
   11422 	  fputs ("PARENT     ", stdout);
   11423 	  break;
   11424 	default:
   11425 	  if (dynamic_syminfo[i].si_boundto > 0
   11426 	      && dynamic_syminfo[i].si_boundto < dynamic_nent
   11427 	      && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
   11428 	    {
   11429 	      print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
   11430 	      putchar (' ' );
   11431 	    }
   11432 	  else
   11433 	    printf ("%-10d ", dynamic_syminfo[i].si_boundto);
   11434 	  break;
   11435 	}
   11436 
   11437       if (flags & SYMINFO_FLG_DIRECT)
   11438 	printf (" DIRECT");
   11439       if (flags & SYMINFO_FLG_PASSTHRU)
   11440 	printf (" PASSTHRU");
   11441       if (flags & SYMINFO_FLG_COPY)
   11442 	printf (" COPY");
   11443       if (flags & SYMINFO_FLG_LAZYLOAD)
   11444 	printf (" LAZYLOAD");
   11445 
   11446       puts ("");
   11447     }
   11448 
   11449   return 1;
   11450 }
   11451 
   11452 /* Check to see if the given reloc needs to be handled in a target specific
   11453    manner.  If so then process the reloc and return TRUE otherwise return
   11454    FALSE.  */
   11455 
   11456 static bfd_boolean
   11457 target_specific_reloc_handling (Elf_Internal_Rela * reloc,
   11458 				unsigned char *     start,
   11459 				Elf_Internal_Sym *  symtab)
   11460 {
   11461   unsigned int reloc_type = get_reloc_type (reloc->r_info);
   11462 
   11463   switch (elf_header.e_machine)
   11464     {
   11465     case EM_MSP430:
   11466     case EM_MSP430_OLD:
   11467       {
   11468 	static Elf_Internal_Sym * saved_sym = NULL;
   11469 
   11470 	switch (reloc_type)
   11471 	  {
   11472 	  case 10: /* R_MSP430_SYM_DIFF */
   11473 	    if (uses_msp430x_relocs ())
   11474 	      break;
   11475 	  case 21: /* R_MSP430X_SYM_DIFF */
   11476 	    saved_sym = symtab + get_reloc_symindex (reloc->r_info);
   11477 	    return TRUE;
   11478 
   11479 	  case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
   11480 	  case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
   11481 	    goto handle_sym_diff;
   11482 
   11483 	  case 5: /* R_MSP430_16_BYTE */
   11484 	  case 9: /* R_MSP430_8 */
   11485 	    if (uses_msp430x_relocs ())
   11486 	      break;
   11487 	    goto handle_sym_diff;
   11488 
   11489 	  case 2: /* R_MSP430_ABS16 */
   11490 	  case 15: /* R_MSP430X_ABS16 */
   11491 	    if (! uses_msp430x_relocs ())
   11492 	      break;
   11493 	    goto handle_sym_diff;
   11494 
   11495 	  handle_sym_diff:
   11496 	    if (saved_sym != NULL)
   11497 	      {
   11498 		bfd_vma value;
   11499 
   11500 		value = reloc->r_addend
   11501 		  + (symtab[get_reloc_symindex (reloc->r_info)].st_value
   11502 		     - saved_sym->st_value);
   11503 
   11504 		byte_put (start + reloc->r_offset, value, reloc_type == 1 ? 4 : 2);
   11505 
   11506 		saved_sym = NULL;
   11507 		return TRUE;
   11508 	      }
   11509 	    break;
   11510 
   11511 	  default:
   11512 	    if (saved_sym != NULL)
   11513 	      error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
   11514 	    break;
   11515 	  }
   11516 	break;
   11517       }
   11518 
   11519     case EM_MN10300:
   11520     case EM_CYGNUS_MN10300:
   11521       {
   11522 	static Elf_Internal_Sym * saved_sym = NULL;
   11523 
   11524 	switch (reloc_type)
   11525 	  {
   11526 	  case 34: /* R_MN10300_ALIGN */
   11527 	    return TRUE;
   11528 	  case 33: /* R_MN10300_SYM_DIFF */
   11529 	    saved_sym = symtab + get_reloc_symindex (reloc->r_info);
   11530 	    return TRUE;
   11531 	  case 1: /* R_MN10300_32 */
   11532 	  case 2: /* R_MN10300_16 */
   11533 	    if (saved_sym != NULL)
   11534 	      {
   11535 		bfd_vma value;
   11536 
   11537 		value = reloc->r_addend
   11538 		  + (symtab[get_reloc_symindex (reloc->r_info)].st_value
   11539 		     - saved_sym->st_value);
   11540 
   11541 		byte_put (start + reloc->r_offset, value, reloc_type == 1 ? 4 : 2);
   11542 
   11543 		saved_sym = NULL;
   11544 		return TRUE;
   11545 	      }
   11546 	    break;
   11547 	  default:
   11548 	    if (saved_sym != NULL)
   11549 	      error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
   11550 	    break;
   11551 	  }
   11552 	break;
   11553       }
   11554 
   11555     case EM_RL78:
   11556       {
   11557 	static bfd_vma saved_sym1 = 0;
   11558 	static bfd_vma saved_sym2 = 0;
   11559 	static bfd_vma value;
   11560 
   11561 	switch (reloc_type)
   11562 	  {
   11563 	  case 0x80: /* R_RL78_SYM.  */
   11564 	    saved_sym1 = saved_sym2;
   11565 	    saved_sym2 = symtab[get_reloc_symindex (reloc->r_info)].st_value;
   11566 	    saved_sym2 += reloc->r_addend;
   11567 	    return TRUE;
   11568 
   11569 	  case 0x83: /* R_RL78_OPsub.  */
   11570 	    value = saved_sym1 - saved_sym2;
   11571 	    saved_sym2 = saved_sym1 = 0;
   11572 	    return TRUE;
   11573 	    break;
   11574 
   11575 	  case 0x41: /* R_RL78_ABS32.  */
   11576 	    byte_put (start + reloc->r_offset, value, 4);
   11577 	    value = 0;
   11578 	    return TRUE;
   11579 
   11580 	  case 0x43: /* R_RL78_ABS16.  */
   11581 	    byte_put (start + reloc->r_offset, value, 2);
   11582 	    value = 0;
   11583 	    return TRUE;
   11584 
   11585 	  default:
   11586 	    break;
   11587 	  }
   11588 	break;
   11589       }
   11590     }
   11591 
   11592   return FALSE;
   11593 }
   11594 
   11595 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
   11596    DWARF debug sections.  This is a target specific test.  Note - we do not
   11597    go through the whole including-target-headers-multiple-times route, (as
   11598    we have already done with <elf/h8.h>) because this would become very
   11599    messy and even then this function would have to contain target specific
   11600    information (the names of the relocs instead of their numeric values).
   11601    FIXME: This is not the correct way to solve this problem.  The proper way
   11602    is to have target specific reloc sizing and typing functions created by
   11603    the reloc-macros.h header, in the same way that it already creates the
   11604    reloc naming functions.  */
   11605 
   11606 static bfd_boolean
   11607 is_32bit_abs_reloc (unsigned int reloc_type)
   11608 {
   11609   /* Please keep this table alpha-sorted for ease of visual lookup.  */
   11610   switch (elf_header.e_machine)
   11611     {
   11612     case EM_386:
   11613     case EM_IAMCU:
   11614       return reloc_type == 1; /* R_386_32.  */
   11615     case EM_68K:
   11616       return reloc_type == 1; /* R_68K_32.  */
   11617     case EM_860:
   11618       return reloc_type == 1; /* R_860_32.  */
   11619     case EM_960:
   11620       return reloc_type == 2; /* R_960_32.  */
   11621     case EM_AARCH64:
   11622       return reloc_type == 258; /* R_AARCH64_ABS32 */
   11623     case EM_ADAPTEVA_EPIPHANY:
   11624       return reloc_type == 3;
   11625     case EM_ALPHA:
   11626       return reloc_type == 1; /* R_ALPHA_REFLONG.  */
   11627     case EM_ARC:
   11628       return reloc_type == 1; /* R_ARC_32.  */
   11629     case EM_ARC_COMPACT:
   11630     case EM_ARC_COMPACT2:
   11631       return reloc_type == 4; /* R_ARC_32.  */
   11632     case EM_ARM:
   11633       return reloc_type == 2; /* R_ARM_ABS32 */
   11634     case EM_AVR_OLD:
   11635     case EM_AVR:
   11636       return reloc_type == 1;
   11637     case EM_BLACKFIN:
   11638       return reloc_type == 0x12; /* R_byte4_data.  */
   11639     case EM_CRIS:
   11640       return reloc_type == 3; /* R_CRIS_32.  */
   11641     case EM_CR16:
   11642       return reloc_type == 3; /* R_CR16_NUM32.  */
   11643     case EM_CRX:
   11644       return reloc_type == 15; /* R_CRX_NUM32.  */
   11645     case EM_CYGNUS_FRV:
   11646       return reloc_type == 1;
   11647     case EM_CYGNUS_D10V:
   11648     case EM_D10V:
   11649       return reloc_type == 6; /* R_D10V_32.  */
   11650     case EM_CYGNUS_D30V:
   11651     case EM_D30V:
   11652       return reloc_type == 12; /* R_D30V_32_NORMAL.  */
   11653     case EM_DLX:
   11654       return reloc_type == 3; /* R_DLX_RELOC_32.  */
   11655     case EM_CYGNUS_FR30:
   11656     case EM_FR30:
   11657       return reloc_type == 3; /* R_FR30_32.  */
   11658     case EM_FT32:
   11659       return reloc_type == 1; /* R_FT32_32.  */
   11660     case EM_H8S:
   11661     case EM_H8_300:
   11662     case EM_H8_300H:
   11663       return reloc_type == 1; /* R_H8_DIR32.  */
   11664     case EM_IA_64:
   11665       return reloc_type == 0x65 /* R_IA64_SECREL32LSB.  */
   11666 	|| reloc_type == 0x25;  /* R_IA64_DIR32LSB.  */
   11667     case EM_IP2K_OLD:
   11668     case EM_IP2K:
   11669       return reloc_type == 2; /* R_IP2K_32.  */
   11670     case EM_IQ2000:
   11671       return reloc_type == 2; /* R_IQ2000_32.  */
   11672     case EM_LATTICEMICO32:
   11673       return reloc_type == 3; /* R_LM32_32.  */
   11674     case EM_M32C_OLD:
   11675     case EM_M32C:
   11676       return reloc_type == 3; /* R_M32C_32.  */
   11677     case EM_M32R:
   11678       return reloc_type == 34; /* R_M32R_32_RELA.  */
   11679     case EM_68HC11:
   11680     case EM_68HC12:
   11681       return reloc_type == 6; /* R_M68HC11_32.  */
   11682     case EM_MCORE:
   11683       return reloc_type == 1; /* R_MCORE_ADDR32.  */
   11684     case EM_CYGNUS_MEP:
   11685       return reloc_type == 4; /* R_MEP_32.  */
   11686     case EM_METAG:
   11687       return reloc_type == 2; /* R_METAG_ADDR32.  */
   11688     case EM_MICROBLAZE:
   11689       return reloc_type == 1; /* R_MICROBLAZE_32.  */
   11690     case EM_MIPS:
   11691       return reloc_type == 2; /* R_MIPS_32.  */
   11692     case EM_MMIX:
   11693       return reloc_type == 4; /* R_MMIX_32.  */
   11694     case EM_CYGNUS_MN10200:
   11695     case EM_MN10200:
   11696       return reloc_type == 1; /* R_MN10200_32.  */
   11697     case EM_CYGNUS_MN10300:
   11698     case EM_MN10300:
   11699       return reloc_type == 1; /* R_MN10300_32.  */
   11700     case EM_MOXIE:
   11701       return reloc_type == 1; /* R_MOXIE_32.  */
   11702     case EM_MSP430_OLD:
   11703     case EM_MSP430:
   11704       return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32.  */
   11705     case EM_MT:
   11706       return reloc_type == 2; /* R_MT_32.  */
   11707     case EM_NDS32:
   11708       return reloc_type == 20; /* R_NDS32_RELA.  */
   11709     case EM_ALTERA_NIOS2:
   11710       return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32.  */
   11711     case EM_NIOS32:
   11712       return reloc_type == 1; /* R_NIOS_32.  */
   11713     case EM_OR1K:
   11714       return reloc_type == 1; /* R_OR1K_32.  */
   11715     case EM_PARISC:
   11716       return (reloc_type == 1 /* R_PARISC_DIR32.  */
   11717 	      || reloc_type == 41); /* R_PARISC_SECREL32.  */
   11718     case EM_PJ:
   11719     case EM_PJ_OLD:
   11720       return reloc_type == 1; /* R_PJ_DATA_DIR32.  */
   11721     case EM_PPC64:
   11722       return reloc_type == 1; /* R_PPC64_ADDR32.  */
   11723     case EM_PPC:
   11724       return reloc_type == 1; /* R_PPC_ADDR32.  */
   11725     case EM_RL78:
   11726       return reloc_type == 1; /* R_RL78_DIR32.  */
   11727     case EM_RX:
   11728       return reloc_type == 1; /* R_RX_DIR32.  */
   11729     case EM_S370:
   11730       return reloc_type == 1; /* R_I370_ADDR31.  */
   11731     case EM_S390_OLD:
   11732     case EM_S390:
   11733       return reloc_type == 4; /* R_S390_32.  */
   11734     case EM_SCORE:
   11735       return reloc_type == 8; /* R_SCORE_ABS32.  */
   11736     case EM_SH:
   11737       return reloc_type == 1; /* R_SH_DIR32.  */
   11738     case EM_SPARC32PLUS:
   11739     case EM_SPARCV9:
   11740     case EM_SPARC:
   11741       return reloc_type == 3 /* R_SPARC_32.  */
   11742 	|| reloc_type == 23; /* R_SPARC_UA32.  */
   11743     case EM_SPU:
   11744       return reloc_type == 6; /* R_SPU_ADDR32 */
   11745     case EM_TI_C6000:
   11746       return reloc_type == 1; /* R_C6000_ABS32.  */
   11747     case EM_TILEGX:
   11748       return reloc_type == 2; /* R_TILEGX_32.  */
   11749     case EM_TILEPRO:
   11750       return reloc_type == 1; /* R_TILEPRO_32.  */
   11751     case EM_CYGNUS_V850:
   11752     case EM_V850:
   11753       return reloc_type == 6; /* R_V850_ABS32.  */
   11754     case EM_V800:
   11755       return reloc_type == 0x33; /* R_V810_WORD.  */
   11756     case EM_VAX:
   11757       return reloc_type == 1; /* R_VAX_32.  */
   11758     case EM_VISIUM:
   11759       return reloc_type == 3;  /* R_VISIUM_32. */
   11760     case EM_X86_64:
   11761     case EM_L1OM:
   11762     case EM_K1OM:
   11763       return reloc_type == 10; /* R_X86_64_32.  */
   11764     case EM_XC16X:
   11765     case EM_C166:
   11766       return reloc_type == 3; /* R_XC16C_ABS_32.  */
   11767     case EM_XGATE:
   11768       return reloc_type == 4; /* R_XGATE_32.  */
   11769     case EM_XSTORMY16:
   11770       return reloc_type == 1; /* R_XSTROMY16_32.  */
   11771     case EM_XTENSA_OLD:
   11772     case EM_XTENSA:
   11773       return reloc_type == 1; /* R_XTENSA_32.  */
   11774     default:
   11775       {
   11776 	static unsigned int prev_warn = 0;
   11777 
   11778 	/* Avoid repeating the same warning multiple times.  */
   11779 	if (prev_warn != elf_header.e_machine)
   11780 	  error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
   11781 		 elf_header.e_machine);
   11782 	prev_warn = elf_header.e_machine;
   11783 	return FALSE;
   11784       }
   11785     }
   11786 }
   11787 
   11788 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
   11789    a 32-bit pc-relative RELA relocation used in DWARF debug sections.  */
   11790 
   11791 static bfd_boolean
   11792 is_32bit_pcrel_reloc (unsigned int reloc_type)
   11793 {
   11794   switch (elf_header.e_machine)
   11795   /* Please keep this table alpha-sorted for ease of visual lookup.  */
   11796     {
   11797     case EM_386:
   11798     case EM_IAMCU:
   11799       return reloc_type == 2;  /* R_386_PC32.  */
   11800     case EM_68K:
   11801       return reloc_type == 4;  /* R_68K_PC32.  */
   11802     case EM_AARCH64:
   11803       return reloc_type == 261; /* R_AARCH64_PREL32 */
   11804     case EM_ADAPTEVA_EPIPHANY:
   11805       return reloc_type == 6;
   11806     case EM_ALPHA:
   11807       return reloc_type == 10; /* R_ALPHA_SREL32.  */
   11808     case EM_ARC_COMPACT:
   11809     case EM_ARC_COMPACT2:
   11810       return reloc_type == 49; /* R_ARC_32_PCREL.  */
   11811     case EM_ARM:
   11812       return reloc_type == 3;  /* R_ARM_REL32 */
   11813     case EM_AVR_OLD:
   11814     case EM_AVR:
   11815       return reloc_type == 36; /* R_AVR_32_PCREL.  */
   11816     case EM_MICROBLAZE:
   11817       return reloc_type == 2;  /* R_MICROBLAZE_32_PCREL.  */
   11818     case EM_OR1K:
   11819       return reloc_type == 9; /* R_OR1K_32_PCREL.  */
   11820     case EM_PARISC:
   11821       return reloc_type == 9;  /* R_PARISC_PCREL32.  */
   11822     case EM_PPC:
   11823       return reloc_type == 26; /* R_PPC_REL32.  */
   11824     case EM_PPC64:
   11825       return reloc_type == 26; /* R_PPC64_REL32.  */
   11826     case EM_S390_OLD:
   11827     case EM_S390:
   11828       return reloc_type == 5;  /* R_390_PC32.  */
   11829     case EM_SH:
   11830       return reloc_type == 2;  /* R_SH_REL32.  */
   11831     case EM_SPARC32PLUS:
   11832     case EM_SPARCV9:
   11833     case EM_SPARC:
   11834       return reloc_type == 6;  /* R_SPARC_DISP32.  */
   11835     case EM_SPU:
   11836       return reloc_type == 13; /* R_SPU_REL32.  */
   11837     case EM_TILEGX:
   11838       return reloc_type == 6; /* R_TILEGX_32_PCREL.  */
   11839     case EM_TILEPRO:
   11840       return reloc_type == 4; /* R_TILEPRO_32_PCREL.  */
   11841     case EM_VISIUM:
   11842       return reloc_type == 6;  /* R_VISIUM_32_PCREL */
   11843     case EM_X86_64:
   11844     case EM_L1OM:
   11845     case EM_K1OM:
   11846       return reloc_type == 2;  /* R_X86_64_PC32.  */
   11847     case EM_XTENSA_OLD:
   11848     case EM_XTENSA:
   11849       return reloc_type == 14; /* R_XTENSA_32_PCREL.  */
   11850     default:
   11851       /* Do not abort or issue an error message here.  Not all targets use
   11852 	 pc-relative 32-bit relocs in their DWARF debug information and we
   11853 	 have already tested for target coverage in is_32bit_abs_reloc.  A
   11854 	 more helpful warning message will be generated by apply_relocations
   11855 	 anyway, so just return.  */
   11856       return FALSE;
   11857     }
   11858 }
   11859 
   11860 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
   11861    a 64-bit absolute RELA relocation used in DWARF debug sections.  */
   11862 
   11863 static bfd_boolean
   11864 is_64bit_abs_reloc (unsigned int reloc_type)
   11865 {
   11866   switch (elf_header.e_machine)
   11867     {
   11868     case EM_AARCH64:
   11869       return reloc_type == 257;	/* R_AARCH64_ABS64.  */
   11870     case EM_ALPHA:
   11871       return reloc_type == 2; /* R_ALPHA_REFQUAD.  */
   11872     case EM_IA_64:
   11873       return reloc_type == 0x27; /* R_IA64_DIR64LSB.  */
   11874     case EM_PARISC:
   11875       return reloc_type == 80; /* R_PARISC_DIR64.  */
   11876     case EM_PPC64:
   11877       return reloc_type == 38; /* R_PPC64_ADDR64.  */
   11878     case EM_SPARC32PLUS:
   11879     case EM_SPARCV9:
   11880     case EM_SPARC:
   11881       return reloc_type == 54; /* R_SPARC_UA64.  */
   11882     case EM_X86_64:
   11883     case EM_L1OM:
   11884     case EM_K1OM:
   11885       return reloc_type == 1; /* R_X86_64_64.  */
   11886     case EM_S390_OLD:
   11887     case EM_S390:
   11888       return reloc_type == 22;	/* R_S390_64.  */
   11889     case EM_TILEGX:
   11890       return reloc_type == 1; /* R_TILEGX_64.  */
   11891     case EM_MIPS:
   11892       return reloc_type == 18;	/* R_MIPS_64.  */
   11893     default:
   11894       return FALSE;
   11895     }
   11896 }
   11897 
   11898 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
   11899    a 64-bit pc-relative RELA relocation used in DWARF debug sections.  */
   11900 
   11901 static bfd_boolean
   11902 is_64bit_pcrel_reloc (unsigned int reloc_type)
   11903 {
   11904   switch (elf_header.e_machine)
   11905     {
   11906     case EM_AARCH64:
   11907       return reloc_type == 260;	/* R_AARCH64_PREL64.  */
   11908     case EM_ALPHA:
   11909       return reloc_type == 11; /* R_ALPHA_SREL64.  */
   11910     case EM_IA_64:
   11911       return reloc_type == 0x4f; /* R_IA64_PCREL64LSB.  */
   11912     case EM_PARISC:
   11913       return reloc_type == 72; /* R_PARISC_PCREL64.  */
   11914     case EM_PPC64:
   11915       return reloc_type == 44; /* R_PPC64_REL64.  */
   11916     case EM_SPARC32PLUS:
   11917     case EM_SPARCV9:
   11918     case EM_SPARC:
   11919       return reloc_type == 46; /* R_SPARC_DISP64.  */
   11920     case EM_X86_64:
   11921     case EM_L1OM:
   11922     case EM_K1OM:
   11923       return reloc_type == 24; /* R_X86_64_PC64.  */
   11924     case EM_S390_OLD:
   11925     case EM_S390:
   11926       return reloc_type == 23;	/* R_S390_PC64.  */
   11927     case EM_TILEGX:
   11928       return reloc_type == 5;  /* R_TILEGX_64_PCREL.  */
   11929     default:
   11930       return FALSE;
   11931     }
   11932 }
   11933 
   11934 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
   11935    a 24-bit absolute RELA relocation used in DWARF debug sections.  */
   11936 
   11937 static bfd_boolean
   11938 is_24bit_abs_reloc (unsigned int reloc_type)
   11939 {
   11940   switch (elf_header.e_machine)
   11941     {
   11942     case EM_CYGNUS_MN10200:
   11943     case EM_MN10200:
   11944       return reloc_type == 4; /* R_MN10200_24.  */
   11945     case EM_FT32:
   11946       return reloc_type == 5; /* R_FT32_20.  */
   11947     default:
   11948       return FALSE;
   11949     }
   11950 }
   11951 
   11952 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
   11953    a 16-bit absolute RELA relocation used in DWARF debug sections.  */
   11954 
   11955 static bfd_boolean
   11956 is_16bit_abs_reloc (unsigned int reloc_type)
   11957 {
   11958   /* Please keep this table alpha-sorted for ease of visual lookup.  */
   11959   switch (elf_header.e_machine)
   11960     {
   11961     case EM_ARC:
   11962     case EM_ARC_COMPACT:
   11963     case EM_ARC_COMPACT2:
   11964       return reloc_type == 2; /* R_ARC_16.  */
   11965     case EM_ADAPTEVA_EPIPHANY:
   11966       return reloc_type == 5;
   11967     case EM_AVR_OLD:
   11968     case EM_AVR:
   11969       return reloc_type == 4; /* R_AVR_16.  */
   11970     case EM_CYGNUS_D10V:
   11971     case EM_D10V:
   11972       return reloc_type == 3; /* R_D10V_16.  */
   11973     case EM_H8S:
   11974     case EM_H8_300:
   11975     case EM_H8_300H:
   11976       return reloc_type == R_H8_DIR16;
   11977     case EM_IP2K_OLD:
   11978     case EM_IP2K:
   11979       return reloc_type == 1; /* R_IP2K_16.  */
   11980     case EM_M32C_OLD:
   11981     case EM_M32C:
   11982       return reloc_type == 1; /* R_M32C_16 */
   11983     case EM_CYGNUS_MN10200:
   11984     case EM_MN10200:
   11985       return reloc_type == 2; /* R_MN10200_16.  */
   11986     case EM_CYGNUS_MN10300:
   11987     case EM_MN10300:
   11988       return reloc_type == 2; /* R_MN10300_16.  */
   11989     case EM_MSP430:
   11990       if (uses_msp430x_relocs ())
   11991 	return reloc_type == 2; /* R_MSP430_ABS16.  */
   11992     case EM_MSP430_OLD:
   11993       return reloc_type == 5; /* R_MSP430_16_BYTE.  */
   11994     case EM_NDS32:
   11995       return reloc_type == 19; /* R_NDS32_RELA.  */
   11996     case EM_ALTERA_NIOS2:
   11997       return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16.  */
   11998     case EM_NIOS32:
   11999       return reloc_type == 9; /* R_NIOS_16.  */
   12000     case EM_OR1K:
   12001       return reloc_type == 2; /* R_OR1K_16.  */
   12002     case EM_TI_C6000:
   12003       return reloc_type == 2; /* R_C6000_ABS16.  */
   12004     case EM_VISIUM:
   12005       return reloc_type == 2; /* R_VISIUM_16. */
   12006     case EM_XC16X:
   12007     case EM_C166:
   12008       return reloc_type == 2; /* R_XC16C_ABS_16.  */
   12009     case EM_XGATE:
   12010       return reloc_type == 3; /* R_XGATE_16.  */
   12011     default:
   12012       return FALSE;
   12013     }
   12014 }
   12015 
   12016 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
   12017    relocation entries (possibly formerly used for SHT_GROUP sections).  */
   12018 
   12019 static bfd_boolean
   12020 is_none_reloc (unsigned int reloc_type)
   12021 {
   12022   switch (elf_header.e_machine)
   12023     {
   12024     case EM_386:     /* R_386_NONE.  */
   12025     case EM_68K:     /* R_68K_NONE.  */
   12026     case EM_ADAPTEVA_EPIPHANY:
   12027     case EM_ALPHA:   /* R_ALPHA_NONE.  */
   12028     case EM_ALTERA_NIOS2: /* R_NIOS2_NONE.  */
   12029     case EM_ARC:     /* R_ARC_NONE.  */
   12030     case EM_ARC_COMPACT2: /* R_ARC_NONE.  */
   12031     case EM_ARC_COMPACT: /* R_ARC_NONE.  */
   12032     case EM_ARM:     /* R_ARM_NONE.  */
   12033     case EM_C166:    /* R_XC16X_NONE.  */
   12034     case EM_CRIS:    /* R_CRIS_NONE.  */
   12035     case EM_FT32:    /* R_FT32_NONE.  */
   12036     case EM_IA_64:   /* R_IA64_NONE.  */
   12037     case EM_K1OM:    /* R_X86_64_NONE.  */
   12038     case EM_L1OM:    /* R_X86_64_NONE.  */
   12039     case EM_M32R:    /* R_M32R_NONE.  */
   12040     case EM_MIPS:    /* R_MIPS_NONE.  */
   12041     case EM_MN10300: /* R_MN10300_NONE.  */
   12042     case EM_MOXIE:   /* R_MOXIE_NONE.  */
   12043     case EM_NIOS32:  /* R_NIOS_NONE.  */
   12044     case EM_OR1K:    /* R_OR1K_NONE. */
   12045     case EM_PARISC:  /* R_PARISC_NONE.  */
   12046     case EM_PPC64:   /* R_PPC64_NONE.  */
   12047     case EM_PPC:     /* R_PPC_NONE.  */
   12048     case EM_S390:    /* R_390_NONE.  */
   12049     case EM_S390_OLD:
   12050     case EM_SH:      /* R_SH_NONE.  */
   12051     case EM_SPARC32PLUS:
   12052     case EM_SPARC:   /* R_SPARC_NONE.  */
   12053     case EM_SPARCV9:
   12054     case EM_TILEGX:  /* R_TILEGX_NONE.  */
   12055     case EM_TILEPRO: /* R_TILEPRO_NONE.  */
   12056     case EM_TI_C6000:/* R_C6000_NONE.  */
   12057     case EM_X86_64:  /* R_X86_64_NONE.  */
   12058     case EM_XC16X:
   12059       return reloc_type == 0;
   12060 
   12061     case EM_AARCH64:
   12062       return reloc_type == 0 || reloc_type == 256;
   12063     case EM_AVR_OLD:
   12064     case EM_AVR:
   12065       return (reloc_type == 0 /* R_AVR_NONE.  */
   12066 	      || reloc_type == 30 /* R_AVR_DIFF8.  */
   12067 	      || reloc_type == 31 /* R_AVR_DIFF16.  */
   12068 	      || reloc_type == 32 /* R_AVR_DIFF32.  */);
   12069     case EM_METAG:
   12070       return reloc_type == 3; /* R_METAG_NONE.  */
   12071     case EM_NDS32:
   12072       return (reloc_type == 0       /* R_XTENSA_NONE.  */
   12073 	      || reloc_type == 204  /* R_NDS32_DIFF8.  */
   12074 	      || reloc_type == 205  /* R_NDS32_DIFF16.  */
   12075 	      || reloc_type == 206  /* R_NDS32_DIFF32.  */
   12076 	      || reloc_type == 207  /* R_NDS32_ULEB128.  */);
   12077     case EM_XTENSA_OLD:
   12078     case EM_XTENSA:
   12079       return (reloc_type == 0      /* R_XTENSA_NONE.  */
   12080 	      || reloc_type == 17  /* R_XTENSA_DIFF8.  */
   12081 	      || reloc_type == 18  /* R_XTENSA_DIFF16.  */
   12082 	      || reloc_type == 19  /* R_XTENSA_DIFF32.  */);
   12083     }
   12084   return FALSE;
   12085 }
   12086 
   12087 /* Returns TRUE if there is a relocation against
   12088    section NAME at OFFSET bytes.  */
   12089 
   12090 bfd_boolean
   12091 reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
   12092 {
   12093   Elf_Internal_Rela * relocs;
   12094   Elf_Internal_Rela * rp;
   12095 
   12096   if (dsec == NULL || dsec->reloc_info == NULL)
   12097     return FALSE;
   12098 
   12099   relocs = (Elf_Internal_Rela *) dsec->reloc_info;
   12100 
   12101   for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp)
   12102     if (rp->r_offset == offset)
   12103       return TRUE;
   12104 
   12105    return FALSE;
   12106 }
   12107 
   12108 /* Apply relocations to a section.
   12109    Note: So far support has been added only for those relocations
   12110    which can be found in debug sections.
   12111    If RELOCS_RETURN is non-NULL then returns in it a pointer to the
   12112    loaded relocs.  It is then the caller's responsibility to free them.
   12113    FIXME: Add support for more relocations ?  */
   12114 
   12115 static void
   12116 apply_relocations (void *                     file,
   12117 		   const Elf_Internal_Shdr *  section,
   12118 		   unsigned char *            start,
   12119 		   bfd_size_type              size,
   12120 		   void **                     relocs_return,
   12121 		   unsigned long *            num_relocs_return)
   12122 {
   12123   Elf_Internal_Shdr * relsec;
   12124   unsigned char * end = start + size;
   12125 
   12126   if (relocs_return != NULL)
   12127     {
   12128       * (Elf_Internal_Rela **) relocs_return = NULL;
   12129       * num_relocs_return = 0;
   12130     }
   12131 
   12132   if (elf_header.e_type != ET_REL)
   12133     return;
   12134 
   12135   /* Find the reloc section associated with the section.  */
   12136   for (relsec = section_headers;
   12137        relsec < section_headers + elf_header.e_shnum;
   12138        ++relsec)
   12139     {
   12140       bfd_boolean is_rela;
   12141       unsigned long num_relocs;
   12142       Elf_Internal_Rela * relocs;
   12143       Elf_Internal_Rela * rp;
   12144       Elf_Internal_Shdr * symsec;
   12145       Elf_Internal_Sym * symtab;
   12146       unsigned long num_syms;
   12147       Elf_Internal_Sym * sym;
   12148 
   12149       if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
   12150 	  || relsec->sh_info >= elf_header.e_shnum
   12151 	  || section_headers + relsec->sh_info != section
   12152 	  || relsec->sh_size == 0
   12153 	  || relsec->sh_link >= elf_header.e_shnum)
   12154 	continue;
   12155 
   12156       is_rela = relsec->sh_type == SHT_RELA;
   12157 
   12158       if (is_rela)
   12159 	{
   12160 	  if (!slurp_rela_relocs ((FILE *) file, relsec->sh_offset,
   12161                                   relsec->sh_size, & relocs, & num_relocs))
   12162 	    return;
   12163 	}
   12164       else
   12165 	{
   12166 	  if (!slurp_rel_relocs ((FILE *) file, relsec->sh_offset,
   12167                                  relsec->sh_size, & relocs, & num_relocs))
   12168 	    return;
   12169 	}
   12170 
   12171       /* SH uses RELA but uses in place value instead of the addend field.  */
   12172       if (elf_header.e_machine == EM_SH)
   12173 	is_rela = FALSE;
   12174 
   12175       symsec = section_headers + relsec->sh_link;
   12176       symtab = GET_ELF_SYMBOLS ((FILE *) file, symsec, & num_syms);
   12177 
   12178       for (rp = relocs; rp < relocs + num_relocs; ++rp)
   12179 	{
   12180 	  bfd_vma         addend;
   12181 	  unsigned int    reloc_type;
   12182 	  unsigned int    reloc_size;
   12183 	  unsigned char * rloc;
   12184 	  unsigned long   sym_index;
   12185 
   12186 	  reloc_type = get_reloc_type (rp->r_info);
   12187 
   12188 	  if (target_specific_reloc_handling (rp, start, symtab))
   12189 	    continue;
   12190 	  else if (is_none_reloc (reloc_type))
   12191 	    continue;
   12192 	  else if (is_32bit_abs_reloc (reloc_type)
   12193 		   || is_32bit_pcrel_reloc (reloc_type))
   12194 	    reloc_size = 4;
   12195 	  else if (is_64bit_abs_reloc (reloc_type)
   12196 		   || is_64bit_pcrel_reloc (reloc_type))
   12197 	    reloc_size = 8;
   12198 	  else if (is_24bit_abs_reloc (reloc_type))
   12199 	    reloc_size = 3;
   12200 	  else if (is_16bit_abs_reloc (reloc_type))
   12201 	    reloc_size = 2;
   12202 	  else
   12203 	    {
   12204 	      static unsigned int prev_reloc = 0;
   12205 	      if (reloc_type != prev_reloc)
   12206 		warn (_("unable to apply unsupported reloc type %d to section %s\n"),
   12207 		      reloc_type, printable_section_name (section));
   12208 	      prev_reloc = reloc_type;
   12209 	      continue;
   12210 	    }
   12211 
   12212 	  rloc = start + rp->r_offset;
   12213 	  if ((rloc + reloc_size) > end || (rloc < start))
   12214 	    {
   12215 	      warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
   12216 		    (unsigned long) rp->r_offset,
   12217 		    printable_section_name (section));
   12218 	      continue;
   12219 	    }
   12220 
   12221 	  sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
   12222 	  if (sym_index >= num_syms)
   12223 	    {
   12224 	      warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
   12225 		    sym_index, printable_section_name (section));
   12226 	      continue;
   12227 	    }
   12228 	  sym = symtab + sym_index;
   12229 
   12230 	  /* If the reloc has a symbol associated with it,
   12231 	     make sure that it is of an appropriate type.
   12232 
   12233 	     Relocations against symbols without type can happen.
   12234 	     Gcc -feliminate-dwarf2-dups may generate symbols
   12235 	     without type for debug info.
   12236 
   12237 	     Icc generates relocations against function symbols
   12238 	     instead of local labels.
   12239 
   12240 	     Relocations against object symbols can happen, eg when
   12241 	     referencing a global array.  For an example of this see
   12242 	     the _clz.o binary in libgcc.a.  */
   12243 	  if (sym != symtab
   12244 	      && ELF_ST_TYPE (sym->st_info) != STT_COMMON
   12245 	      && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
   12246 	    {
   12247 	      warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
   12248 		    get_symbol_type (ELF_ST_TYPE (sym->st_info)),
   12249 		    (long int)(rp - relocs),
   12250 		    printable_section_name (relsec));
   12251 	      continue;
   12252 	    }
   12253 
   12254 	  addend = 0;
   12255 	  if (is_rela)
   12256 	    addend += rp->r_addend;
   12257 	  /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
   12258 	     partial_inplace.  */
   12259 	  if (!is_rela
   12260 	      || (elf_header.e_machine == EM_XTENSA
   12261 		  && reloc_type == 1)
   12262 	      || ((elf_header.e_machine == EM_PJ
   12263 		   || elf_header.e_machine == EM_PJ_OLD)
   12264 		  && reloc_type == 1)
   12265 	      || ((elf_header.e_machine == EM_D30V
   12266 		   || elf_header.e_machine == EM_CYGNUS_D30V)
   12267 		  && reloc_type == 12))
   12268 	    addend += byte_get (rloc, reloc_size);
   12269 
   12270 	  if (is_32bit_pcrel_reloc (reloc_type)
   12271 	      || is_64bit_pcrel_reloc (reloc_type))
   12272 	    {
   12273 	      /* On HPPA, all pc-relative relocations are biased by 8.  */
   12274 	      if (elf_header.e_machine == EM_PARISC)
   12275 		addend -= 8;
   12276 	      byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
   12277 		        reloc_size);
   12278 	    }
   12279 	  else
   12280 	    byte_put (rloc, addend + sym->st_value, reloc_size);
   12281 	}
   12282 
   12283       free (symtab);
   12284 
   12285       if (relocs_return)
   12286 	{
   12287 	  * (Elf_Internal_Rela **) relocs_return = relocs;
   12288 	  * num_relocs_return = num_relocs;
   12289 	}
   12290       else
   12291 	free (relocs);
   12292 
   12293       break;
   12294     }
   12295 }
   12296 
   12297 #ifdef SUPPORT_DISASSEMBLY
   12298 static int
   12299 disassemble_section (Elf_Internal_Shdr * section, FILE * file)
   12300 {
   12301   printf (_("\nAssembly dump of section %s\n"), printable_section_name (section));
   12302 
   12303   /* FIXME: XXX -- to be done --- XXX */
   12304 
   12305   return 1;
   12306 }
   12307 #endif
   12308 
   12309 /* Reads in the contents of SECTION from FILE, returning a pointer
   12310    to a malloc'ed buffer or NULL if something went wrong.  */
   12311 
   12312 static char *
   12313 get_section_contents (Elf_Internal_Shdr * section, FILE * file)
   12314 {
   12315   bfd_size_type num_bytes;
   12316 
   12317   num_bytes = section->sh_size;
   12318 
   12319   if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
   12320     {
   12321       printf (_("\nSection '%s' has no data to dump.\n"),
   12322 	      printable_section_name (section));
   12323       return NULL;
   12324     }
   12325 
   12326   return  (char *) get_data (NULL, file, section->sh_offset, 1, num_bytes,
   12327                              _("section contents"));
   12328 }
   12329 
   12330 /* Uncompresses a section that was compressed using zlib, in place.  */
   12331 
   12332 static bfd_boolean
   12333 uncompress_section_contents (unsigned char **buffer,
   12334 			     dwarf_size_type uncompressed_size,
   12335 			     dwarf_size_type *size)
   12336 {
   12337   dwarf_size_type compressed_size = *size;
   12338   unsigned char * compressed_buffer = *buffer;
   12339   unsigned char * uncompressed_buffer;
   12340   z_stream strm;
   12341   int rc;
   12342 
   12343   /* It is possible the section consists of several compressed
   12344      buffers concatenated together, so we uncompress in a loop.  */
   12345   /* PR 18313: The state field in the z_stream structure is supposed
   12346      to be invisible to the user (ie us), but some compilers will
   12347      still complain about it being used without initialisation.  So
   12348      we first zero the entire z_stream structure and then set the fields
   12349      that we need.  */
   12350   memset (& strm, 0, sizeof strm);
   12351   strm.avail_in = compressed_size;
   12352   strm.next_in = (Bytef *) compressed_buffer;
   12353   strm.avail_out = uncompressed_size;
   12354   uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
   12355 
   12356   rc = inflateInit (& strm);
   12357   while (strm.avail_in > 0)
   12358     {
   12359       if (rc != Z_OK)
   12360         goto fail;
   12361       strm.next_out = ((Bytef *) uncompressed_buffer
   12362                        + (uncompressed_size - strm.avail_out));
   12363       rc = inflate (&strm, Z_FINISH);
   12364       if (rc != Z_STREAM_END)
   12365         goto fail;
   12366       rc = inflateReset (& strm);
   12367     }
   12368   rc = inflateEnd (& strm);
   12369   if (rc != Z_OK
   12370       || strm.avail_out != 0)
   12371     goto fail;
   12372 
   12373   *buffer = uncompressed_buffer;
   12374   *size = uncompressed_size;
   12375   return TRUE;
   12376 
   12377  fail:
   12378   free (uncompressed_buffer);
   12379   /* Indicate decompression failure.  */
   12380   *buffer = NULL;
   12381   return FALSE;
   12382 }
   12383 
   12384 static void
   12385 dump_section_as_strings (Elf_Internal_Shdr * section, FILE * file)
   12386 {
   12387   Elf_Internal_Shdr *  relsec;
   12388   bfd_size_type        num_bytes;
   12389   unsigned char *      data;
   12390   unsigned char *      end;
   12391   unsigned char *      real_start;
   12392   unsigned char *      start;
   12393   bfd_boolean          some_strings_shown;
   12394 
   12395   real_start = start = (unsigned char *) get_section_contents (section,
   12396 							       file);
   12397   if (start == NULL)
   12398     return;
   12399   num_bytes = section->sh_size;
   12400 
   12401   printf (_("\nString dump of section '%s':\n"), printable_section_name (section));
   12402 
   12403   if (decompress_dumps)
   12404     {
   12405       dwarf_size_type new_size = num_bytes;
   12406       dwarf_size_type uncompressed_size = 0;
   12407 
   12408       if ((section->sh_flags & SHF_COMPRESSED) != 0)
   12409 	{
   12410 	  Elf_Internal_Chdr chdr;
   12411 	  unsigned int compression_header_size
   12412 	    = get_compression_header (& chdr, (unsigned char *) start);
   12413 
   12414 	  if (chdr.ch_type != ELFCOMPRESS_ZLIB)
   12415 	    {
   12416 	      warn (_("section '%s' has unsupported compress type: %d\n"),
   12417 		    printable_section_name (section), chdr.ch_type);
   12418 	      return;
   12419 	    }
   12420 	  else if (chdr.ch_addralign != section->sh_addralign)
   12421 	    {
   12422 	      warn (_("compressed section '%s' is corrupted\n"),
   12423 		    printable_section_name (section));
   12424 	      return;
   12425 	    }
   12426 	  uncompressed_size = chdr.ch_size;
   12427 	  start += compression_header_size;
   12428 	  new_size -= compression_header_size;
   12429 	}
   12430       else if (new_size > 12 && streq ((char *) start, "ZLIB"))
   12431 	{
   12432 	  /* Read the zlib header.  In this case, it should be "ZLIB"
   12433 	     followed by the uncompressed section size, 8 bytes in
   12434 	     big-endian order.  */
   12435 	  uncompressed_size = start[4]; uncompressed_size <<= 8;
   12436 	  uncompressed_size += start[5]; uncompressed_size <<= 8;
   12437 	  uncompressed_size += start[6]; uncompressed_size <<= 8;
   12438 	  uncompressed_size += start[7]; uncompressed_size <<= 8;
   12439 	  uncompressed_size += start[8]; uncompressed_size <<= 8;
   12440 	  uncompressed_size += start[9]; uncompressed_size <<= 8;
   12441 	  uncompressed_size += start[10]; uncompressed_size <<= 8;
   12442 	  uncompressed_size += start[11];
   12443 	  start += 12;
   12444 	  new_size -= 12;
   12445 	}
   12446 
   12447       if (uncompressed_size
   12448 	  && uncompress_section_contents (& start,
   12449 					  uncompressed_size, & new_size))
   12450 	num_bytes = new_size;
   12451     }
   12452 
   12453   /* If the section being dumped has relocations against it the user might
   12454      be expecting these relocations to have been applied.  Check for this
   12455      case and issue a warning message in order to avoid confusion.
   12456      FIXME: Maybe we ought to have an option that dumps a section with
   12457      relocs applied ?  */
   12458   for (relsec = section_headers;
   12459        relsec < section_headers + elf_header.e_shnum;
   12460        ++relsec)
   12461     {
   12462       if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
   12463 	  || relsec->sh_info >= elf_header.e_shnum
   12464 	  || section_headers + relsec->sh_info != section
   12465 	  || relsec->sh_size == 0
   12466 	  || relsec->sh_link >= elf_header.e_shnum)
   12467 	continue;
   12468 
   12469       printf (_("  Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
   12470       break;
   12471     }
   12472 
   12473   data = start;
   12474   end  = start + num_bytes;
   12475   some_strings_shown = FALSE;
   12476 
   12477   while (data < end)
   12478     {
   12479       while (!ISPRINT (* data))
   12480 	if (++ data >= end)
   12481 	  break;
   12482 
   12483       if (data < end)
   12484 	{
   12485 	  size_t maxlen = end - data;
   12486 
   12487 #ifndef __MSVCRT__
   12488 	  /* PR 11128: Use two separate invocations in order to work
   12489              around bugs in the Solaris 8 implementation of printf.  */
   12490 	  printf ("  [%6tx]  ", data - start);
   12491 #else
   12492 	  printf ("  [%6Ix]  ", (size_t) (data - start));
   12493 #endif
   12494 	  if (maxlen > 0)
   12495 	    {
   12496 	      print_symbol ((int) maxlen, (const char *) data);
   12497 	      putchar ('\n');
   12498 	      data += strnlen ((const char *) data, maxlen);
   12499 	    }
   12500 	  else
   12501 	    {
   12502 	      printf (_("<corrupt>\n"));
   12503 	      data = end;
   12504 	    }
   12505 	  some_strings_shown = TRUE;
   12506 	}
   12507     }
   12508 
   12509   if (! some_strings_shown)
   12510     printf (_("  No strings found in this section."));
   12511 
   12512   free (real_start);
   12513 
   12514   putchar ('\n');
   12515 }
   12516 
   12517 static void
   12518 dump_section_as_bytes (Elf_Internal_Shdr * section,
   12519 		       FILE * file,
   12520 		       bfd_boolean relocate)
   12521 {
   12522   Elf_Internal_Shdr * relsec;
   12523   bfd_size_type       bytes;
   12524   bfd_size_type       section_size;
   12525   bfd_vma             addr;
   12526   unsigned char *     data;
   12527   unsigned char *     real_start;
   12528   unsigned char *     start;
   12529 
   12530   real_start = start = (unsigned char *) get_section_contents (section, file);
   12531   if (start == NULL)
   12532     return;
   12533   section_size = section->sh_size;
   12534 
   12535   printf (_("\nHex dump of section '%s':\n"), printable_section_name (section));
   12536 
   12537   if (decompress_dumps)
   12538     {
   12539       dwarf_size_type new_size = section_size;
   12540       dwarf_size_type uncompressed_size = 0;
   12541 
   12542       if ((section->sh_flags & SHF_COMPRESSED) != 0)
   12543 	{
   12544 	  Elf_Internal_Chdr chdr;
   12545 	  unsigned int compression_header_size
   12546 	    = get_compression_header (& chdr, start);
   12547 
   12548 	  if (chdr.ch_type != ELFCOMPRESS_ZLIB)
   12549 	    {
   12550 	      warn (_("section '%s' has unsupported compress type: %d\n"),
   12551 		    printable_section_name (section), chdr.ch_type);
   12552 	      return;
   12553 	    }
   12554 	  else if (chdr.ch_addralign != section->sh_addralign)
   12555 	    {
   12556 	      warn (_("compressed section '%s' is corrupted\n"),
   12557 		    printable_section_name (section));
   12558 	      return;
   12559 	    }
   12560 	  uncompressed_size = chdr.ch_size;
   12561 	  start += compression_header_size;
   12562 	  new_size -= compression_header_size;
   12563 	}
   12564       else if (new_size > 12 && streq ((char *) start, "ZLIB"))
   12565 	{
   12566 	  /* Read the zlib header.  In this case, it should be "ZLIB"
   12567 	     followed by the uncompressed section size, 8 bytes in
   12568 	     big-endian order.  */
   12569 	  uncompressed_size = start[4]; uncompressed_size <<= 8;
   12570 	  uncompressed_size += start[5]; uncompressed_size <<= 8;
   12571 	  uncompressed_size += start[6]; uncompressed_size <<= 8;
   12572 	  uncompressed_size += start[7]; uncompressed_size <<= 8;
   12573 	  uncompressed_size += start[8]; uncompressed_size <<= 8;
   12574 	  uncompressed_size += start[9]; uncompressed_size <<= 8;
   12575 	  uncompressed_size += start[10]; uncompressed_size <<= 8;
   12576 	  uncompressed_size += start[11];
   12577 	  start += 12;
   12578 	  new_size -= 12;
   12579 	}
   12580 
   12581       if (uncompressed_size
   12582 	  && uncompress_section_contents (& start, uncompressed_size,
   12583 					  & new_size))
   12584 	section_size = new_size;
   12585     }
   12586 
   12587   if (relocate)
   12588     {
   12589       apply_relocations (file, section, start, section_size, NULL, NULL);
   12590     }
   12591   else
   12592     {
   12593       /* If the section being dumped has relocations against it the user might
   12594 	 be expecting these relocations to have been applied.  Check for this
   12595 	 case and issue a warning message in order to avoid confusion.
   12596 	 FIXME: Maybe we ought to have an option that dumps a section with
   12597 	 relocs applied ?  */
   12598       for (relsec = section_headers;
   12599 	   relsec < section_headers + elf_header.e_shnum;
   12600 	   ++relsec)
   12601 	{
   12602 	  if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
   12603 	      || relsec->sh_info >= elf_header.e_shnum
   12604 	      || section_headers + relsec->sh_info != section
   12605 	      || relsec->sh_size == 0
   12606 	      || relsec->sh_link >= elf_header.e_shnum)
   12607 	    continue;
   12608 
   12609 	  printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
   12610 	  break;
   12611 	}
   12612     }
   12613 
   12614   addr = section->sh_addr;
   12615   bytes = section_size;
   12616   data = start;
   12617 
   12618   while (bytes)
   12619     {
   12620       int j;
   12621       int k;
   12622       int lbytes;
   12623 
   12624       lbytes = (bytes > 16 ? 16 : bytes);
   12625 
   12626       printf ("  0x%8.8lx ", (unsigned long) addr);
   12627 
   12628       for (j = 0; j < 16; j++)
   12629 	{
   12630 	  if (j < lbytes)
   12631 	    printf ("%2.2x", data[j]);
   12632 	  else
   12633 	    printf ("  ");
   12634 
   12635 	  if ((j & 3) == 3)
   12636 	    printf (" ");
   12637 	}
   12638 
   12639       for (j = 0; j < lbytes; j++)
   12640 	{
   12641 	  k = data[j];
   12642 	  if (k >= ' ' && k < 0x7f)
   12643 	    printf ("%c", k);
   12644 	  else
   12645 	    printf (".");
   12646 	}
   12647 
   12648       putchar ('\n');
   12649 
   12650       data  += lbytes;
   12651       addr  += lbytes;
   12652       bytes -= lbytes;
   12653     }
   12654 
   12655   free (real_start);
   12656 
   12657   putchar ('\n');
   12658 }
   12659 
   12660 static int
   12661 load_specific_debug_section (enum dwarf_section_display_enum debug,
   12662 			     const Elf_Internal_Shdr * sec, void * file)
   12663 {
   12664   struct dwarf_section * section = &debug_displays [debug].section;
   12665   char buf [64];
   12666 
   12667   /* If it is already loaded, do nothing.  */
   12668   if (section->start != NULL)
   12669     return 1;
   12670 
   12671   snprintf (buf, sizeof (buf), _("%s section data"), section->name);
   12672   section->address = sec->sh_addr;
   12673   section->user_data = NULL;
   12674   section->start = (unsigned char *) get_data (NULL, (FILE *) file,
   12675                                                sec->sh_offset, 1,
   12676                                                sec->sh_size, buf);
   12677   if (section->start == NULL)
   12678     section->size = 0;
   12679   else
   12680     {
   12681       unsigned char *start = section->start;
   12682       dwarf_size_type size = sec->sh_size;
   12683       dwarf_size_type uncompressed_size = 0;
   12684 
   12685       if ((sec->sh_flags & SHF_COMPRESSED) != 0)
   12686 	{
   12687 	  Elf_Internal_Chdr chdr;
   12688 	  unsigned int compression_header_size
   12689 	    = get_compression_header (&chdr, start);
   12690 	  if (chdr.ch_type != ELFCOMPRESS_ZLIB)
   12691 	    {
   12692 	      warn (_("section '%s' has unsupported compress type: %d\n"),
   12693 		    section->name, chdr.ch_type);
   12694 	      return 0;
   12695 	    }
   12696 	  else if (chdr.ch_addralign != sec->sh_addralign)
   12697 	    {
   12698 	      warn (_("compressed section '%s' is corrupted\n"),
   12699 		    section->name);
   12700 	      return 0;
   12701 	    }
   12702 	  uncompressed_size = chdr.ch_size;
   12703 	  start += compression_header_size;
   12704 	  size -= compression_header_size;
   12705 	}
   12706       else if (size > 12 && streq ((char *) start, "ZLIB"))
   12707 	{
   12708 	  /* Read the zlib header.  In this case, it should be "ZLIB"
   12709 	     followed by the uncompressed section size, 8 bytes in
   12710 	     big-endian order.  */
   12711 	  uncompressed_size = start[4]; uncompressed_size <<= 8;
   12712 	  uncompressed_size += start[5]; uncompressed_size <<= 8;
   12713 	  uncompressed_size += start[6]; uncompressed_size <<= 8;
   12714 	  uncompressed_size += start[7]; uncompressed_size <<= 8;
   12715 	  uncompressed_size += start[8]; uncompressed_size <<= 8;
   12716 	  uncompressed_size += start[9]; uncompressed_size <<= 8;
   12717 	  uncompressed_size += start[10]; uncompressed_size <<= 8;
   12718 	  uncompressed_size += start[11];
   12719 	  start += 12;
   12720 	  size -= 12;
   12721 	}
   12722 
   12723       if (uncompressed_size
   12724 	  && uncompress_section_contents (&start, uncompressed_size,
   12725 					  &size))
   12726 	{
   12727 	  /* Free the compressed buffer, update the section buffer
   12728 	     and the section size if uncompress is successful.  */
   12729 	  free (section->start);
   12730 	  section->start = start;
   12731 	}
   12732       section->size = size;
   12733     }
   12734 
   12735   if (section->start == NULL)
   12736     return 0;
   12737 
   12738   if (debug_displays [debug].relocate)
   12739     apply_relocations ((FILE *) file, sec, section->start, section->size,
   12740 		       & section->reloc_info, & section->num_relocs);
   12741   else
   12742     {
   12743       section->reloc_info = NULL;
   12744       section->num_relocs = 0;
   12745     }
   12746 
   12747   return 1;
   12748 }
   12749 
   12750 /* If this is not NULL, load_debug_section will only look for sections
   12751    within the list of sections given here.  */
   12752 unsigned int *section_subset = NULL;
   12753 
   12754 int
   12755 load_debug_section (enum dwarf_section_display_enum debug, void * file)
   12756 {
   12757   struct dwarf_section * section = &debug_displays [debug].section;
   12758   Elf_Internal_Shdr * sec;
   12759 
   12760   /* Locate the debug section.  */
   12761   sec = find_section_in_set (section->uncompressed_name, section_subset);
   12762   if (sec != NULL)
   12763     section->name = section->uncompressed_name;
   12764   else
   12765     {
   12766       sec = find_section_in_set (section->compressed_name, section_subset);
   12767       if (sec != NULL)
   12768 	section->name = section->compressed_name;
   12769     }
   12770   if (sec == NULL)
   12771     return 0;
   12772 
   12773   /* If we're loading from a subset of sections, and we've loaded
   12774      a section matching this name before, it's likely that it's a
   12775      different one.  */
   12776   if (section_subset != NULL)
   12777     free_debug_section (debug);
   12778 
   12779   return load_specific_debug_section (debug, sec, (FILE *) file);
   12780 }
   12781 
   12782 void
   12783 free_debug_section (enum dwarf_section_display_enum debug)
   12784 {
   12785   struct dwarf_section * section = &debug_displays [debug].section;
   12786 
   12787   if (section->start == NULL)
   12788     return;
   12789 
   12790   free ((char *) section->start);
   12791   section->start = NULL;
   12792   section->address = 0;
   12793   section->size = 0;
   12794 }
   12795 
   12796 static int
   12797 display_debug_section (int shndx, Elf_Internal_Shdr * section, FILE * file)
   12798 {
   12799   char * name = SECTION_NAME (section);
   12800   const char * print_name = printable_section_name (section);
   12801   bfd_size_type length;
   12802   int result = 1;
   12803   int i;
   12804 
   12805   length = section->sh_size;
   12806   if (length == 0)
   12807     {
   12808       printf (_("\nSection '%s' has no debugging data.\n"), print_name);
   12809       return 0;
   12810     }
   12811   if (section->sh_type == SHT_NOBITS)
   12812     {
   12813       /* There is no point in dumping the contents of a debugging section
   12814 	 which has the NOBITS type - the bits in the file will be random.
   12815 	 This can happen when a file containing a .eh_frame section is
   12816 	 stripped with the --only-keep-debug command line option.  */
   12817       printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
   12818 	      print_name);
   12819       return 0;
   12820     }
   12821 
   12822   if (const_strneq (name, ".gnu.linkonce.wi."))
   12823     name = ".debug_info";
   12824 
   12825   /* See if we know how to display the contents of this section.  */
   12826   for (i = 0; i < max; i++)
   12827     if (streq (debug_displays[i].section.uncompressed_name, name)
   12828 	|| (i == line && const_strneq (name, ".debug_line."))
   12829         || streq (debug_displays[i].section.compressed_name, name))
   12830       {
   12831 	struct dwarf_section * sec = &debug_displays [i].section;
   12832 	int secondary = (section != find_section (name));
   12833 
   12834 	if (secondary)
   12835 	  free_debug_section ((enum dwarf_section_display_enum) i);
   12836 
   12837 	if (i == line && const_strneq (name, ".debug_line."))
   12838 	  sec->name = name;
   12839 	else if (streq (sec->uncompressed_name, name))
   12840 	  sec->name = sec->uncompressed_name;
   12841 	else
   12842 	  sec->name = sec->compressed_name;
   12843 	if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
   12844                                          section, file))
   12845 	  {
   12846 	    /* If this debug section is part of a CU/TU set in a .dwp file,
   12847 	       restrict load_debug_section to the sections in that set.  */
   12848 	    section_subset = find_cu_tu_set (file, shndx);
   12849 
   12850 	    result &= debug_displays[i].display (sec, file);
   12851 
   12852 	    section_subset = NULL;
   12853 
   12854 	    if (secondary || (i != info && i != abbrev))
   12855 	      free_debug_section ((enum dwarf_section_display_enum) i);
   12856 	  }
   12857 
   12858 	break;
   12859       }
   12860 
   12861   if (i == max)
   12862     {
   12863       printf (_("Unrecognized debug section: %s\n"), print_name);
   12864       result = 0;
   12865     }
   12866 
   12867   return result;
   12868 }
   12869 
   12870 /* Set DUMP_SECTS for all sections where dumps were requested
   12871    based on section name.  */
   12872 
   12873 static void
   12874 initialise_dumps_byname (void)
   12875 {
   12876   struct dump_list_entry * cur;
   12877 
   12878   for (cur = dump_sects_byname; cur; cur = cur->next)
   12879     {
   12880       unsigned int i;
   12881       int any;
   12882 
   12883       for (i = 0, any = 0; i < elf_header.e_shnum; i++)
   12884 	if (streq (SECTION_NAME (section_headers + i), cur->name))
   12885 	  {
   12886 	    request_dump_bynumber (i, cur->type);
   12887 	    any = 1;
   12888 	  }
   12889 
   12890       if (!any)
   12891 	warn (_("Section '%s' was not dumped because it does not exist!\n"),
   12892 	      cur->name);
   12893     }
   12894 }
   12895 
   12896 static void
   12897 process_section_contents (FILE * file)
   12898 {
   12899   Elf_Internal_Shdr * section;
   12900   unsigned int i;
   12901 
   12902   if (! do_dump)
   12903     return;
   12904 
   12905   initialise_dumps_byname ();
   12906 
   12907   for (i = 0, section = section_headers;
   12908        i < elf_header.e_shnum && i < num_dump_sects;
   12909        i++, section++)
   12910     {
   12911 #ifdef SUPPORT_DISASSEMBLY
   12912       if (dump_sects[i] & DISASS_DUMP)
   12913 	disassemble_section (section, file);
   12914 #endif
   12915       if (dump_sects[i] & HEX_DUMP)
   12916 	dump_section_as_bytes (section, file, FALSE);
   12917 
   12918       if (dump_sects[i] & RELOC_DUMP)
   12919 	dump_section_as_bytes (section, file, TRUE);
   12920 
   12921       if (dump_sects[i] & STRING_DUMP)
   12922 	dump_section_as_strings (section, file);
   12923 
   12924       if (dump_sects[i] & DEBUG_DUMP)
   12925 	display_debug_section (i, section, file);
   12926     }
   12927 
   12928   /* Check to see if the user requested a
   12929      dump of a section that does not exist.  */
   12930   while (i++ < num_dump_sects)
   12931     if (dump_sects[i])
   12932       warn (_("Section %d was not dumped because it does not exist!\n"), i);
   12933 }
   12934 
   12935 static void
   12936 process_mips_fpe_exception (int mask)
   12937 {
   12938   if (mask)
   12939     {
   12940       int first = 1;
   12941       if (mask & OEX_FPU_INEX)
   12942 	fputs ("INEX", stdout), first = 0;
   12943       if (mask & OEX_FPU_UFLO)
   12944 	printf ("%sUFLO", first ? "" : "|"), first = 0;
   12945       if (mask & OEX_FPU_OFLO)
   12946 	printf ("%sOFLO", first ? "" : "|"), first = 0;
   12947       if (mask & OEX_FPU_DIV0)
   12948 	printf ("%sDIV0", first ? "" : "|"), first = 0;
   12949       if (mask & OEX_FPU_INVAL)
   12950 	printf ("%sINVAL", first ? "" : "|");
   12951     }
   12952   else
   12953     fputs ("0", stdout);
   12954 }
   12955 
   12956 /* Display's the value of TAG at location P.  If TAG is
   12957    greater than 0 it is assumed to be an unknown tag, and
   12958    a message is printed to this effect.  Otherwise it is
   12959    assumed that a message has already been printed.
   12960 
   12961    If the bottom bit of TAG is set it assumed to have a
   12962    string value, otherwise it is assumed to have an integer
   12963    value.
   12964 
   12965    Returns an updated P pointing to the first unread byte
   12966    beyond the end of TAG's value.
   12967 
   12968    Reads at or beyond END will not be made.  */
   12969 
   12970 static unsigned char *
   12971 display_tag_value (int tag,
   12972 		   unsigned char * p,
   12973 		   const unsigned char * const end)
   12974 {
   12975   unsigned long val;
   12976 
   12977   if (tag > 0)
   12978     printf ("  Tag_unknown_%d: ", tag);
   12979 
   12980   if (p >= end)
   12981     {
   12982       warn (_("<corrupt tag>\n"));
   12983     }
   12984   else if (tag & 1)
   12985     {
   12986       /* PR 17531 file: 027-19978-0.004.  */
   12987       size_t maxlen = (end - p) - 1;
   12988 
   12989       putchar ('"');
   12990       if (maxlen > 0)
   12991 	{
   12992 	  print_symbol ((int) maxlen, (const char *) p);
   12993 	  p += strnlen ((char *) p, maxlen) + 1;
   12994 	}
   12995       else
   12996 	{
   12997 	  printf (_("<corrupt string tag>"));
   12998 	  p = (unsigned char *) end;
   12999 	}
   13000       printf ("\"\n");
   13001     }
   13002   else
   13003     {
   13004       unsigned int len;
   13005 
   13006       val = read_uleb128 (p, &len, end);
   13007       p += len;
   13008       printf ("%ld (0x%lx)\n", val, val);
   13009     }
   13010 
   13011   assert (p <= end);
   13012   return p;
   13013 }
   13014 
   13015 /* ARM EABI attributes section.  */
   13016 typedef struct
   13017 {
   13018   unsigned int tag;
   13019   const char * name;
   13020   /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup.  */
   13021   unsigned int type;
   13022   const char ** table;
   13023 } arm_attr_public_tag;
   13024 
   13025 static const char * arm_attr_tag_CPU_arch[] =
   13026   {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
   13027    "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "", "v8-M.baseline",
   13028    "v8-M.mainline"};
   13029 static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
   13030 static const char * arm_attr_tag_THUMB_ISA_use[] =
   13031   {"No", "Thumb-1", "Thumb-2", "Yes"};
   13032 static const char * arm_attr_tag_FP_arch[] =
   13033   {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
   13034    "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
   13035 static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
   13036 static const char * arm_attr_tag_Advanced_SIMD_arch[] =
   13037   {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
   13038    "NEON for ARMv8.1"};
   13039 static const char * arm_attr_tag_PCS_config[] =
   13040   {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
   13041    "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
   13042 static const char * arm_attr_tag_ABI_PCS_R9_use[] =
   13043   {"V6", "SB", "TLS", "Unused"};
   13044 static const char * arm_attr_tag_ABI_PCS_RW_data[] =
   13045   {"Absolute", "PC-relative", "SB-relative", "None"};
   13046 static const char * arm_attr_tag_ABI_PCS_RO_data[] =
   13047   {"Absolute", "PC-relative", "None"};
   13048 static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
   13049   {"None", "direct", "GOT-indirect"};
   13050 static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
   13051   {"None", "??? 1", "2", "??? 3", "4"};
   13052 static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
   13053 static const char * arm_attr_tag_ABI_FP_denormal[] =
   13054   {"Unused", "Needed", "Sign only"};
   13055 static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
   13056 static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
   13057 static const char * arm_attr_tag_ABI_FP_number_model[] =
   13058   {"Unused", "Finite", "RTABI", "IEEE 754"};
   13059 static const char * arm_attr_tag_ABI_enum_size[] =
   13060   {"Unused", "small", "int", "forced to int"};
   13061 static const char * arm_attr_tag_ABI_HardFP_use[] =
   13062   {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
   13063 static const char * arm_attr_tag_ABI_VFP_args[] =
   13064   {"AAPCS", "VFP registers", "custom", "compatible"};
   13065 static const char * arm_attr_tag_ABI_WMMX_args[] =
   13066   {"AAPCS", "WMMX registers", "custom"};
   13067 static const char * arm_attr_tag_ABI_optimization_goals[] =
   13068   {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
   13069     "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
   13070 static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
   13071   {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
   13072     "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
   13073 static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
   13074 static const char * arm_attr_tag_FP_HP_extension[] =
   13075   {"Not Allowed", "Allowed"};
   13076 static const char * arm_attr_tag_ABI_FP_16bit_format[] =
   13077   {"None", "IEEE 754", "Alternative Format"};
   13078 static const char * arm_attr_tag_DSP_extension[] =
   13079   {"Follow architecture", "Allowed"};
   13080 static const char * arm_attr_tag_MPextension_use[] =
   13081   {"Not Allowed", "Allowed"};
   13082 static const char * arm_attr_tag_DIV_use[] =
   13083   {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
   13084     "Allowed in v7-A with integer division extension"};
   13085 static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
   13086 static const char * arm_attr_tag_Virtualization_use[] =
   13087   {"Not Allowed", "TrustZone", "Virtualization Extensions",
   13088     "TrustZone and Virtualization Extensions"};
   13089 static const char * arm_attr_tag_MPextension_use_legacy[] =
   13090   {"Not Allowed", "Allowed"};
   13091 
   13092 #define LOOKUP(id, name) \
   13093   {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
   13094 static arm_attr_public_tag arm_attr_public_tags[] =
   13095 {
   13096   {4, "CPU_raw_name", 1, NULL},
   13097   {5, "CPU_name", 1, NULL},
   13098   LOOKUP(6, CPU_arch),
   13099   {7, "CPU_arch_profile", 0, NULL},
   13100   LOOKUP(8, ARM_ISA_use),
   13101   LOOKUP(9, THUMB_ISA_use),
   13102   LOOKUP(10, FP_arch),
   13103   LOOKUP(11, WMMX_arch),
   13104   LOOKUP(12, Advanced_SIMD_arch),
   13105   LOOKUP(13, PCS_config),
   13106   LOOKUP(14, ABI_PCS_R9_use),
   13107   LOOKUP(15, ABI_PCS_RW_data),
   13108   LOOKUP(16, ABI_PCS_RO_data),
   13109   LOOKUP(17, ABI_PCS_GOT_use),
   13110   LOOKUP(18, ABI_PCS_wchar_t),
   13111   LOOKUP(19, ABI_FP_rounding),
   13112   LOOKUP(20, ABI_FP_denormal),
   13113   LOOKUP(21, ABI_FP_exceptions),
   13114   LOOKUP(22, ABI_FP_user_exceptions),
   13115   LOOKUP(23, ABI_FP_number_model),
   13116   {24, "ABI_align_needed", 0, NULL},
   13117   {25, "ABI_align_preserved", 0, NULL},
   13118   LOOKUP(26, ABI_enum_size),
   13119   LOOKUP(27, ABI_HardFP_use),
   13120   LOOKUP(28, ABI_VFP_args),
   13121   LOOKUP(29, ABI_WMMX_args),
   13122   LOOKUP(30, ABI_optimization_goals),
   13123   LOOKUP(31, ABI_FP_optimization_goals),
   13124   {32, "compatibility", 0, NULL},
   13125   LOOKUP(34, CPU_unaligned_access),
   13126   LOOKUP(36, FP_HP_extension),
   13127   LOOKUP(38, ABI_FP_16bit_format),
   13128   LOOKUP(42, MPextension_use),
   13129   LOOKUP(44, DIV_use),
   13130   LOOKUP(46, DSP_extension),
   13131   {64, "nodefaults", 0, NULL},
   13132   {65, "also_compatible_with", 0, NULL},
   13133   LOOKUP(66, T2EE_use),
   13134   {67, "conformance", 1, NULL},
   13135   LOOKUP(68, Virtualization_use),
   13136   LOOKUP(70, MPextension_use_legacy)
   13137 };
   13138 #undef LOOKUP
   13139 
   13140 static unsigned char *
   13141 display_arm_attribute (unsigned char * p,
   13142 		       const unsigned char * const end)
   13143 {
   13144   unsigned int tag;
   13145   unsigned int len;
   13146   unsigned int val;
   13147   arm_attr_public_tag * attr;
   13148   unsigned i;
   13149   unsigned int type;
   13150 
   13151   tag = read_uleb128 (p, &len, end);
   13152   p += len;
   13153   attr = NULL;
   13154   for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
   13155     {
   13156       if (arm_attr_public_tags[i].tag == tag)
   13157 	{
   13158 	  attr = &arm_attr_public_tags[i];
   13159 	  break;
   13160 	}
   13161     }
   13162 
   13163   if (attr)
   13164     {
   13165       printf ("  Tag_%s: ", attr->name);
   13166       switch (attr->type)
   13167 	{
   13168 	case 0:
   13169 	  switch (tag)
   13170 	    {
   13171 	    case 7: /* Tag_CPU_arch_profile.  */
   13172 	      val = read_uleb128 (p, &len, end);
   13173 	      p += len;
   13174 	      switch (val)
   13175 		{
   13176 		case 0: printf (_("None\n")); break;
   13177 		case 'A': printf (_("Application\n")); break;
   13178 		case 'R': printf (_("Realtime\n")); break;
   13179 		case 'M': printf (_("Microcontroller\n")); break;
   13180 		case 'S': printf (_("Application or Realtime\n")); break;
   13181 		default: printf ("??? (%d)\n", val); break;
   13182 		}
   13183 	      break;
   13184 
   13185 	    case 24: /* Tag_align_needed.  */
   13186 	      val = read_uleb128 (p, &len, end);
   13187 	      p += len;
   13188 	      switch (val)
   13189 		{
   13190 		case 0: printf (_("None\n")); break;
   13191 		case 1: printf (_("8-byte\n")); break;
   13192 		case 2: printf (_("4-byte\n")); break;
   13193 		case 3: printf ("??? 3\n"); break;
   13194 		default:
   13195 		  if (val <= 12)
   13196 		    printf (_("8-byte and up to %d-byte extended\n"),
   13197 			    1 << val);
   13198 		  else
   13199 		    printf ("??? (%d)\n", val);
   13200 		  break;
   13201 		}
   13202 	      break;
   13203 
   13204 	    case 25: /* Tag_align_preserved.  */
   13205 	      val = read_uleb128 (p, &len, end);
   13206 	      p += len;
   13207 	      switch (val)
   13208 		{
   13209 		case 0: printf (_("None\n")); break;
   13210 		case 1: printf (_("8-byte, except leaf SP\n")); break;
   13211 		case 2: printf (_("8-byte\n")); break;
   13212 		case 3: printf ("??? 3\n"); break;
   13213 		default:
   13214 		  if (val <= 12)
   13215 		    printf (_("8-byte and up to %d-byte extended\n"),
   13216 			    1 << val);
   13217 		  else
   13218 		    printf ("??? (%d)\n", val);
   13219 		  break;
   13220 		}
   13221 	      break;
   13222 
   13223 	    case 32: /* Tag_compatibility.  */
   13224 	      {
   13225 		val = read_uleb128 (p, &len, end);
   13226 		p += len;
   13227 		printf (_("flag = %d, vendor = "), val);
   13228 		if (p < end - 1)
   13229 		  {
   13230 		    size_t maxlen = (end - p) - 1;
   13231 
   13232 		    print_symbol ((int) maxlen, (const char *) p);
   13233 		    p += strnlen ((char *) p, maxlen) + 1;
   13234 		  }
   13235 		else
   13236 		  {
   13237 		    printf (_("<corrupt>"));
   13238 		    p = (unsigned char *) end;
   13239 		  }
   13240 		putchar ('\n');
   13241 	      }
   13242 	      break;
   13243 
   13244 	    case 64: /* Tag_nodefaults.  */
   13245 	      /* PR 17531: file: 001-505008-0.01.  */
   13246 	      if (p < end)
   13247 		p++;
   13248 	      printf (_("True\n"));
   13249 	      break;
   13250 
   13251 	    case 65: /* Tag_also_compatible_with.  */
   13252 	      val = read_uleb128 (p, &len, end);
   13253 	      p += len;
   13254 	      if (val == 6 /* Tag_CPU_arch.  */)
   13255 		{
   13256 		  val = read_uleb128 (p, &len, end);
   13257 		  p += len;
   13258 		  if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
   13259 		    printf ("??? (%d)\n", val);
   13260 		  else
   13261 		    printf ("%s\n", arm_attr_tag_CPU_arch[val]);
   13262 		}
   13263 	      else
   13264 		printf ("???\n");
   13265 	      while (p < end && *(p++) != '\0' /* NUL terminator.  */)
   13266 		;
   13267 	      break;
   13268 
   13269 	    default:
   13270 	      printf (_("<unknown: %d>\n"), tag);
   13271 	      break;
   13272 	    }
   13273 	  return p;
   13274 
   13275 	case 1:
   13276 	  return display_tag_value (-1, p, end);
   13277 	case 2:
   13278 	  return display_tag_value (0, p, end);
   13279 
   13280 	default:
   13281 	  assert (attr->type & 0x80);
   13282 	  val = read_uleb128 (p, &len, end);
   13283 	  p += len;
   13284 	  type = attr->type & 0x7f;
   13285 	  if (val >= type)
   13286 	    printf ("??? (%d)\n", val);
   13287 	  else
   13288 	    printf ("%s\n", attr->table[val]);
   13289 	  return p;
   13290 	}
   13291     }
   13292 
   13293   return display_tag_value (tag, p, end);
   13294 }
   13295 
   13296 static unsigned char *
   13297 display_gnu_attribute (unsigned char * p,
   13298 		       unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int, const unsigned char * const),
   13299 		       const unsigned char * const end)
   13300 {
   13301   int tag;
   13302   unsigned int len;
   13303   int val;
   13304 
   13305   tag = read_uleb128 (p, &len, end);
   13306   p += len;
   13307 
   13308   /* Tag_compatibility is the only generic GNU attribute defined at
   13309      present.  */
   13310   if (tag == 32)
   13311     {
   13312       val = read_uleb128 (p, &len, end);
   13313       p += len;
   13314 
   13315       printf (_("flag = %d, vendor = "), val);
   13316       if (p == end)
   13317 	{
   13318 	  printf (_("<corrupt>\n"));
   13319 	  warn (_("corrupt vendor attribute\n"));
   13320 	}
   13321       else
   13322 	{
   13323 	  if (p < end - 1)
   13324 	    {
   13325 	      size_t maxlen = (end - p) - 1;
   13326 
   13327 	      print_symbol ((int) maxlen, (const char *) p);
   13328 	      p += strnlen ((char *) p, maxlen) + 1;
   13329 	    }
   13330 	  else
   13331 	    {
   13332 	      printf (_("<corrupt>"));
   13333 	      p = (unsigned char *) end;
   13334 	    }
   13335 	  putchar ('\n');
   13336 	}
   13337       return p;
   13338     }
   13339 
   13340   if ((tag & 2) == 0 && display_proc_gnu_attribute)
   13341     return display_proc_gnu_attribute (p, tag, end);
   13342 
   13343   return display_tag_value (tag, p, end);
   13344 }
   13345 
   13346 static unsigned char *
   13347 display_power_gnu_attribute (unsigned char * p,
   13348 			     int tag,
   13349 			     const unsigned char * const end)
   13350 {
   13351   unsigned int len;
   13352   unsigned int val;
   13353 
   13354   if (tag == Tag_GNU_Power_ABI_FP)
   13355     {
   13356       val = read_uleb128 (p, &len, end);
   13357       p += len;
   13358       printf ("  Tag_GNU_Power_ABI_FP: ");
   13359       if (len == 0)
   13360 	{
   13361 	  printf (_("<corrupt>\n"));
   13362 	  return p;
   13363 	}
   13364 
   13365       if (val > 15)
   13366 	printf ("(%#x), ", val);
   13367 
   13368       switch (val & 3)
   13369 	{
   13370 	case 0:
   13371 	  printf (_("unspecified hard/soft float, "));
   13372 	  break;
   13373 	case 1:
   13374 	  printf (_("hard float, "));
   13375 	  break;
   13376 	case 2:
   13377 	  printf (_("soft float, "));
   13378 	  break;
   13379 	case 3:
   13380 	  printf (_("single-precision hard float, "));
   13381 	  break;
   13382 	}
   13383 
   13384       switch (val & 0xC)
   13385 	{
   13386 	case 0:
   13387 	  printf (_("unspecified long double\n"));
   13388 	  break;
   13389 	case 4:
   13390 	  printf (_("128-bit IBM long double\n"));
   13391 	  break;
   13392 	case 8:
   13393 	  printf (_("64-bit long double\n"));
   13394 	  break;
   13395 	case 12:
   13396 	  printf (_("128-bit IEEE long double\n"));
   13397 	  break;
   13398 	}
   13399       return p;
   13400     }
   13401 
   13402   if (tag == Tag_GNU_Power_ABI_Vector)
   13403     {
   13404       val = read_uleb128 (p, &len, end);
   13405       p += len;
   13406       printf ("  Tag_GNU_Power_ABI_Vector: ");
   13407       if (len == 0)
   13408 	{
   13409 	  printf (_("<corrupt>\n"));
   13410 	  return p;
   13411 	}
   13412 
   13413       if (val > 3)
   13414 	printf ("(%#x), ", val);
   13415 
   13416       switch (val & 3)
   13417 	{
   13418 	case 0:
   13419 	  printf (_("unspecified\n"));
   13420 	  break;
   13421 	case 1:
   13422 	  printf (_("generic\n"));
   13423 	  break;
   13424 	case 2:
   13425 	  printf ("AltiVec\n");
   13426 	  break;
   13427 	case 3:
   13428 	  printf ("SPE\n");
   13429 	  break;
   13430 	}
   13431       return p;
   13432     }
   13433 
   13434   if (tag == Tag_GNU_Power_ABI_Struct_Return)
   13435     {
   13436       val = read_uleb128 (p, &len, end);
   13437       p += len;
   13438       printf ("  Tag_GNU_Power_ABI_Struct_Return: ");
   13439       if (len == 0)
   13440 	{
   13441 	  printf (_("<corrupt>\n"));
   13442 	  return p;
   13443 	}
   13444 
   13445       if (val > 2)
   13446 	printf ("(%#x), ", val);
   13447 
   13448       switch (val & 3)
   13449 	{
   13450 	case 0:
   13451 	  printf (_("unspecified\n"));
   13452 	  break;
   13453 	case 1:
   13454 	  printf ("r3/r4\n");
   13455 	  break;
   13456 	case 2:
   13457 	  printf (_("memory\n"));
   13458 	  break;
   13459 	case 3:
   13460 	  printf ("???\n");
   13461 	  break;
   13462 	}
   13463       return p;
   13464     }
   13465 
   13466   return display_tag_value (tag & 1, p, end);
   13467 }
   13468 
   13469 static unsigned char *
   13470 display_s390_gnu_attribute (unsigned char * p,
   13471 			    int tag,
   13472 			    const unsigned char * const end)
   13473 {
   13474   unsigned int len;
   13475   int val;
   13476 
   13477   if (tag == Tag_GNU_S390_ABI_Vector)
   13478     {
   13479       val = read_uleb128 (p, &len, end);
   13480       p += len;
   13481       printf ("  Tag_GNU_S390_ABI_Vector: ");
   13482 
   13483       switch (val)
   13484 	{
   13485 	case 0:
   13486 	  printf (_("any\n"));
   13487 	  break;
   13488 	case 1:
   13489 	  printf (_("software\n"));
   13490 	  break;
   13491 	case 2:
   13492 	  printf (_("hardware\n"));
   13493 	  break;
   13494 	default:
   13495 	  printf ("??? (%d)\n", val);
   13496 	  break;
   13497 	}
   13498       return p;
   13499    }
   13500 
   13501   return display_tag_value (tag & 1, p, end);
   13502 }
   13503 
   13504 static void
   13505 display_sparc_hwcaps (int mask)
   13506 {
   13507   if (mask)
   13508     {
   13509       int first = 1;
   13510 
   13511       if (mask & ELF_SPARC_HWCAP_MUL32)
   13512 	fputs ("mul32", stdout), first = 0;
   13513       if (mask & ELF_SPARC_HWCAP_DIV32)
   13514 	printf ("%sdiv32", first ? "" : "|"), first = 0;
   13515       if (mask & ELF_SPARC_HWCAP_FSMULD)
   13516 	printf ("%sfsmuld", first ? "" : "|"), first = 0;
   13517       if (mask & ELF_SPARC_HWCAP_V8PLUS)
   13518 	printf ("%sv8plus", first ? "" : "|"), first = 0;
   13519       if (mask & ELF_SPARC_HWCAP_POPC)
   13520 	printf ("%spopc", first ? "" : "|"), first = 0;
   13521       if (mask & ELF_SPARC_HWCAP_VIS)
   13522 	printf ("%svis", first ? "" : "|"), first = 0;
   13523       if (mask & ELF_SPARC_HWCAP_VIS2)
   13524 	printf ("%svis2", first ? "" : "|"), first = 0;
   13525       if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
   13526 	printf ("%sASIBlkInit", first ? "" : "|"), first = 0;
   13527       if (mask & ELF_SPARC_HWCAP_FMAF)
   13528 	printf ("%sfmaf", first ? "" : "|"), first = 0;
   13529       if (mask & ELF_SPARC_HWCAP_VIS3)
   13530 	printf ("%svis3", first ? "" : "|"), first = 0;
   13531       if (mask & ELF_SPARC_HWCAP_HPC)
   13532 	printf ("%shpc", first ? "" : "|"), first = 0;
   13533       if (mask & ELF_SPARC_HWCAP_RANDOM)
   13534 	printf ("%srandom", first ? "" : "|"), first = 0;
   13535       if (mask & ELF_SPARC_HWCAP_TRANS)
   13536 	printf ("%strans", first ? "" : "|"), first = 0;
   13537       if (mask & ELF_SPARC_HWCAP_FJFMAU)
   13538 	printf ("%sfjfmau", first ? "" : "|"), first = 0;
   13539       if (mask & ELF_SPARC_HWCAP_IMA)
   13540 	printf ("%sima", first ? "" : "|"), first = 0;
   13541       if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
   13542 	printf ("%scspare", first ? "" : "|"), first = 0;
   13543     }
   13544   else
   13545     fputc ('0', stdout);
   13546   fputc ('\n', stdout);
   13547 }
   13548 
   13549 static void
   13550 display_sparc_hwcaps2 (int mask)
   13551 {
   13552   if (mask)
   13553     {
   13554       int first = 1;
   13555 
   13556       if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
   13557 	fputs ("fjathplus", stdout), first = 0;
   13558       if (mask & ELF_SPARC_HWCAP2_VIS3B)
   13559 	printf ("%svis3b", first ? "" : "|"), first = 0;
   13560       if (mask & ELF_SPARC_HWCAP2_ADP)
   13561 	printf ("%sadp", first ? "" : "|"), first = 0;
   13562       if (mask & ELF_SPARC_HWCAP2_SPARC5)
   13563 	printf ("%ssparc5", first ? "" : "|"), first = 0;
   13564       if (mask & ELF_SPARC_HWCAP2_MWAIT)
   13565 	printf ("%smwait", first ? "" : "|"), first = 0;
   13566       if (mask & ELF_SPARC_HWCAP2_XMPMUL)
   13567 	printf ("%sxmpmul", first ? "" : "|"), first = 0;
   13568       if (mask & ELF_SPARC_HWCAP2_XMONT)
   13569 	printf ("%sxmont2", first ? "" : "|"), first = 0;
   13570       if (mask & ELF_SPARC_HWCAP2_NSEC)
   13571 	printf ("%snsec", first ? "" : "|"), first = 0;
   13572       if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
   13573 	printf ("%sfjathhpc", first ? "" : "|"), first = 0;
   13574       if (mask & ELF_SPARC_HWCAP2_FJDES)
   13575 	printf ("%sfjdes", first ? "" : "|"), first = 0;
   13576       if (mask & ELF_SPARC_HWCAP2_FJAES)
   13577 	printf ("%sfjaes", first ? "" : "|"), first = 0;
   13578     }
   13579   else
   13580     fputc ('0', stdout);
   13581   fputc ('\n', stdout);
   13582 }
   13583 
   13584 static unsigned char *
   13585 display_sparc_gnu_attribute (unsigned char * p,
   13586 			     int tag,
   13587 			     const unsigned char * const end)
   13588 {
   13589   unsigned int len;
   13590   int val;
   13591 
   13592   if (tag == Tag_GNU_Sparc_HWCAPS)
   13593     {
   13594       val = read_uleb128 (p, &len, end);
   13595       p += len;
   13596       printf ("  Tag_GNU_Sparc_HWCAPS: ");
   13597       display_sparc_hwcaps (val);
   13598       return p;
   13599     }
   13600   if (tag == Tag_GNU_Sparc_HWCAPS2)
   13601     {
   13602       val = read_uleb128 (p, &len, end);
   13603       p += len;
   13604       printf ("  Tag_GNU_Sparc_HWCAPS2: ");
   13605       display_sparc_hwcaps2 (val);
   13606       return p;
   13607     }
   13608 
   13609   return display_tag_value (tag, p, end);
   13610 }
   13611 
   13612 static void
   13613 print_mips_fp_abi_value (int val)
   13614 {
   13615   switch (val)
   13616     {
   13617     case Val_GNU_MIPS_ABI_FP_ANY:
   13618       printf (_("Hard or soft float\n"));
   13619       break;
   13620     case Val_GNU_MIPS_ABI_FP_DOUBLE:
   13621       printf (_("Hard float (double precision)\n"));
   13622       break;
   13623     case Val_GNU_MIPS_ABI_FP_SINGLE:
   13624       printf (_("Hard float (single precision)\n"));
   13625       break;
   13626     case Val_GNU_MIPS_ABI_FP_SOFT:
   13627       printf (_("Soft float\n"));
   13628       break;
   13629     case Val_GNU_MIPS_ABI_FP_OLD_64:
   13630       printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
   13631       break;
   13632     case Val_GNU_MIPS_ABI_FP_XX:
   13633       printf (_("Hard float (32-bit CPU, Any FPU)\n"));
   13634       break;
   13635     case Val_GNU_MIPS_ABI_FP_64:
   13636       printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
   13637       break;
   13638     case Val_GNU_MIPS_ABI_FP_64A:
   13639       printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
   13640       break;
   13641     case Val_GNU_MIPS_ABI_FP_NAN2008:
   13642       printf (_("NaN 2008 compatibility\n"));
   13643       break;
   13644     default:
   13645       printf ("??? (%d)\n", val);
   13646       break;
   13647     }
   13648 }
   13649 
   13650 static unsigned char *
   13651 display_mips_gnu_attribute (unsigned char * p,
   13652 			    int tag,
   13653 			    const unsigned char * const end)
   13654 {
   13655   if (tag == Tag_GNU_MIPS_ABI_FP)
   13656     {
   13657       unsigned int len;
   13658       int val;
   13659 
   13660       val = read_uleb128 (p, &len, end);
   13661       p += len;
   13662       printf ("  Tag_GNU_MIPS_ABI_FP: ");
   13663 
   13664       print_mips_fp_abi_value (val);
   13665 
   13666       return p;
   13667    }
   13668 
   13669   if (tag == Tag_GNU_MIPS_ABI_MSA)
   13670     {
   13671       unsigned int len;
   13672       int val;
   13673 
   13674       val = read_uleb128 (p, &len, end);
   13675       p += len;
   13676       printf ("  Tag_GNU_MIPS_ABI_MSA: ");
   13677 
   13678       switch (val)
   13679 	{
   13680 	case Val_GNU_MIPS_ABI_MSA_ANY:
   13681 	  printf (_("Any MSA or not\n"));
   13682 	  break;
   13683 	case Val_GNU_MIPS_ABI_MSA_128:
   13684 	  printf (_("128-bit MSA\n"));
   13685 	  break;
   13686 	default:
   13687 	  printf ("??? (%d)\n", val);
   13688 	  break;
   13689 	}
   13690       return p;
   13691     }
   13692 
   13693   return display_tag_value (tag & 1, p, end);
   13694 }
   13695 
   13696 static unsigned char *
   13697 display_tic6x_attribute (unsigned char * p,
   13698 			 const unsigned char * const end)
   13699 {
   13700   int tag;
   13701   unsigned int len;
   13702   int val;
   13703 
   13704   tag = read_uleb128 (p, &len, end);
   13705   p += len;
   13706 
   13707   switch (tag)
   13708     {
   13709     case Tag_ISA:
   13710       val = read_uleb128 (p, &len, end);
   13711       p += len;
   13712       printf ("  Tag_ISA: ");
   13713 
   13714       switch (val)
   13715 	{
   13716 	case C6XABI_Tag_ISA_none:
   13717 	  printf (_("None\n"));
   13718 	  break;
   13719 	case C6XABI_Tag_ISA_C62X:
   13720 	  printf ("C62x\n");
   13721 	  break;
   13722 	case C6XABI_Tag_ISA_C67X:
   13723 	  printf ("C67x\n");
   13724 	  break;
   13725 	case C6XABI_Tag_ISA_C67XP:
   13726 	  printf ("C67x+\n");
   13727 	  break;
   13728 	case C6XABI_Tag_ISA_C64X:
   13729 	  printf ("C64x\n");
   13730 	  break;
   13731 	case C6XABI_Tag_ISA_C64XP:
   13732 	  printf ("C64x+\n");
   13733 	  break;
   13734 	case C6XABI_Tag_ISA_C674X:
   13735 	  printf ("C674x\n");
   13736 	  break;
   13737 	default:
   13738 	  printf ("??? (%d)\n", val);
   13739 	  break;
   13740 	}
   13741       return p;
   13742 
   13743     case Tag_ABI_wchar_t:
   13744       val = read_uleb128 (p, &len, end);
   13745       p += len;
   13746       printf ("  Tag_ABI_wchar_t: ");
   13747       switch (val)
   13748 	{
   13749 	case 0:
   13750 	  printf (_("Not used\n"));
   13751 	  break;
   13752 	case 1:
   13753 	  printf (_("2 bytes\n"));
   13754 	  break;
   13755 	case 2:
   13756 	  printf (_("4 bytes\n"));
   13757 	  break;
   13758 	default:
   13759 	  printf ("??? (%d)\n", val);
   13760 	  break;
   13761 	}
   13762       return p;
   13763 
   13764     case Tag_ABI_stack_align_needed:
   13765       val = read_uleb128 (p, &len, end);
   13766       p += len;
   13767       printf ("  Tag_ABI_stack_align_needed: ");
   13768       switch (val)
   13769 	{
   13770 	case 0:
   13771 	  printf (_("8-byte\n"));
   13772 	  break;
   13773 	case 1:
   13774 	  printf (_("16-byte\n"));
   13775 	  break;
   13776 	default:
   13777 	  printf ("??? (%d)\n", val);
   13778 	  break;
   13779 	}
   13780       return p;
   13781 
   13782     case Tag_ABI_stack_align_preserved:
   13783       val = read_uleb128 (p, &len, end);
   13784       p += len;
   13785       printf ("  Tag_ABI_stack_align_preserved: ");
   13786       switch (val)
   13787 	{
   13788 	case 0:
   13789 	  printf (_("8-byte\n"));
   13790 	  break;
   13791 	case 1:
   13792 	  printf (_("16-byte\n"));
   13793 	  break;
   13794 	default:
   13795 	  printf ("??? (%d)\n", val);
   13796 	  break;
   13797 	}
   13798       return p;
   13799 
   13800     case Tag_ABI_DSBT:
   13801       val = read_uleb128 (p, &len, end);
   13802       p += len;
   13803       printf ("  Tag_ABI_DSBT: ");
   13804       switch (val)
   13805 	{
   13806 	case 0:
   13807 	  printf (_("DSBT addressing not used\n"));
   13808 	  break;
   13809 	case 1:
   13810 	  printf (_("DSBT addressing used\n"));
   13811 	  break;
   13812 	default:
   13813 	  printf ("??? (%d)\n", val);
   13814 	  break;
   13815 	}
   13816       return p;
   13817 
   13818     case Tag_ABI_PID:
   13819       val = read_uleb128 (p, &len, end);
   13820       p += len;
   13821       printf ("  Tag_ABI_PID: ");
   13822       switch (val)
   13823 	{
   13824 	case 0:
   13825 	  printf (_("Data addressing position-dependent\n"));
   13826 	  break;
   13827 	case 1:
   13828 	  printf (_("Data addressing position-independent, GOT near DP\n"));
   13829 	  break;
   13830 	case 2:
   13831 	  printf (_("Data addressing position-independent, GOT far from DP\n"));
   13832 	  break;
   13833 	default:
   13834 	  printf ("??? (%d)\n", val);
   13835 	  break;
   13836 	}
   13837       return p;
   13838 
   13839     case Tag_ABI_PIC:
   13840       val = read_uleb128 (p, &len, end);
   13841       p += len;
   13842       printf ("  Tag_ABI_PIC: ");
   13843       switch (val)
   13844 	{
   13845 	case 0:
   13846 	  printf (_("Code addressing position-dependent\n"));
   13847 	  break;
   13848 	case 1:
   13849 	  printf (_("Code addressing position-independent\n"));
   13850 	  break;
   13851 	default:
   13852 	  printf ("??? (%d)\n", val);
   13853 	  break;
   13854 	}
   13855       return p;
   13856 
   13857     case Tag_ABI_array_object_alignment:
   13858       val = read_uleb128 (p, &len, end);
   13859       p += len;
   13860       printf ("  Tag_ABI_array_object_alignment: ");
   13861       switch (val)
   13862 	{
   13863 	case 0:
   13864 	  printf (_("8-byte\n"));
   13865 	  break;
   13866 	case 1:
   13867 	  printf (_("4-byte\n"));
   13868 	  break;
   13869 	case 2:
   13870 	  printf (_("16-byte\n"));
   13871 	  break;
   13872 	default:
   13873 	  printf ("??? (%d)\n", val);
   13874 	  break;
   13875 	}
   13876       return p;
   13877 
   13878     case Tag_ABI_array_object_align_expected:
   13879       val = read_uleb128 (p, &len, end);
   13880       p += len;
   13881       printf ("  Tag_ABI_array_object_align_expected: ");
   13882       switch (val)
   13883 	{
   13884 	case 0:
   13885 	  printf (_("8-byte\n"));
   13886 	  break;
   13887 	case 1:
   13888 	  printf (_("4-byte\n"));
   13889 	  break;
   13890 	case 2:
   13891 	  printf (_("16-byte\n"));
   13892 	  break;
   13893 	default:
   13894 	  printf ("??? (%d)\n", val);
   13895 	  break;
   13896 	}
   13897       return p;
   13898 
   13899     case Tag_ABI_compatibility:
   13900       {
   13901 	val = read_uleb128 (p, &len, end);
   13902 	p += len;
   13903 	printf ("  Tag_ABI_compatibility: ");
   13904 	printf (_("flag = %d, vendor = "), val);
   13905 	if (p < end - 1)
   13906 	  {
   13907 	    size_t maxlen = (end - p) - 1;
   13908 
   13909 	    print_symbol ((int) maxlen, (const char *) p);
   13910 	    p += strnlen ((char *) p, maxlen) + 1;
   13911 	  }
   13912 	else
   13913 	  {
   13914 	    printf (_("<corrupt>"));
   13915 	    p = (unsigned char *) end;
   13916 	  }
   13917 	putchar ('\n');
   13918 	return p;
   13919       }
   13920 
   13921     case Tag_ABI_conformance:
   13922       {
   13923 	printf ("  Tag_ABI_conformance: \"");
   13924 	if (p < end - 1)
   13925 	  {
   13926 	    size_t maxlen = (end - p) - 1;
   13927 
   13928 	    print_symbol ((int) maxlen, (const char *) p);
   13929 	    p += strnlen ((char *) p, maxlen) + 1;
   13930 	  }
   13931 	else
   13932 	  {
   13933 	    printf (_("<corrupt>"));
   13934 	    p = (unsigned char *) end;
   13935 	  }
   13936 	printf ("\"\n");
   13937 	return p;
   13938       }
   13939     }
   13940 
   13941   return display_tag_value (tag, p, end);
   13942 }
   13943 
   13944 static void
   13945 display_raw_attribute (unsigned char * p, unsigned char * end)
   13946 {
   13947   unsigned long addr = 0;
   13948   size_t bytes = end - p;
   13949 
   13950   assert (end > p);
   13951   while (bytes)
   13952     {
   13953       int j;
   13954       int k;
   13955       int lbytes = (bytes > 16 ? 16 : bytes);
   13956 
   13957       printf ("  0x%8.8lx ", addr);
   13958 
   13959       for (j = 0; j < 16; j++)
   13960 	{
   13961 	  if (j < lbytes)
   13962 	    printf ("%2.2x", p[j]);
   13963 	  else
   13964 	    printf ("  ");
   13965 
   13966 	  if ((j & 3) == 3)
   13967 	    printf (" ");
   13968 	}
   13969 
   13970       for (j = 0; j < lbytes; j++)
   13971 	{
   13972 	  k = p[j];
   13973 	  if (k >= ' ' && k < 0x7f)
   13974 	    printf ("%c", k);
   13975 	  else
   13976 	    printf (".");
   13977 	}
   13978 
   13979       putchar ('\n');
   13980 
   13981       p  += lbytes;
   13982       bytes -= lbytes;
   13983       addr += lbytes;
   13984     }
   13985 
   13986   putchar ('\n');
   13987 }
   13988 
   13989 static unsigned char *
   13990 display_msp430x_attribute (unsigned char * p,
   13991 			   const unsigned char * const end)
   13992 {
   13993   unsigned int len;
   13994   int val;
   13995   int tag;
   13996 
   13997   tag = read_uleb128 (p, & len, end);
   13998   p += len;
   13999 
   14000   switch (tag)
   14001     {
   14002     case OFBA_MSPABI_Tag_ISA:
   14003       val = read_uleb128 (p, &len, end);
   14004       p += len;
   14005       printf ("  Tag_ISA: ");
   14006       switch (val)
   14007 	{
   14008 	case 0: printf (_("None\n")); break;
   14009 	case 1: printf (_("MSP430\n")); break;
   14010 	case 2: printf (_("MSP430X\n")); break;
   14011 	default: printf ("??? (%d)\n", val); break;
   14012 	}
   14013       break;
   14014 
   14015     case OFBA_MSPABI_Tag_Code_Model:
   14016       val = read_uleb128 (p, &len, end);
   14017       p += len;
   14018       printf ("  Tag_Code_Model: ");
   14019       switch (val)
   14020 	{
   14021 	case 0: printf (_("None\n")); break;
   14022 	case 1: printf (_("Small\n")); break;
   14023 	case 2: printf (_("Large\n")); break;
   14024 	default: printf ("??? (%d)\n", val); break;
   14025 	}
   14026       break;
   14027 
   14028     case OFBA_MSPABI_Tag_Data_Model:
   14029       val = read_uleb128 (p, &len, end);
   14030       p += len;
   14031       printf ("  Tag_Data_Model: ");
   14032       switch (val)
   14033 	{
   14034 	case 0: printf (_("None\n")); break;
   14035 	case 1: printf (_("Small\n")); break;
   14036 	case 2: printf (_("Large\n")); break;
   14037 	case 3: printf (_("Restricted Large\n")); break;
   14038 	default: printf ("??? (%d)\n", val); break;
   14039 	}
   14040       break;
   14041 
   14042     default:
   14043       printf (_("  <unknown tag %d>: "), tag);
   14044 
   14045       if (tag & 1)
   14046 	{
   14047 	  putchar ('"');
   14048 	  if (p < end - 1)
   14049 	    {
   14050 	      size_t maxlen = (end - p) - 1;
   14051 
   14052 	      print_symbol ((int) maxlen, (const char *) p);
   14053 	      p += strnlen ((char *) p, maxlen) + 1;
   14054 	    }
   14055 	  else
   14056 	    {
   14057 	      printf (_("<corrupt>"));
   14058 	      p = (unsigned char *) end;
   14059 	    }
   14060 	  printf ("\"\n");
   14061 	}
   14062       else
   14063 	{
   14064 	  val = read_uleb128 (p, &len, end);
   14065 	  p += len;
   14066 	  printf ("%d (0x%x)\n", val, val);
   14067 	}
   14068       break;
   14069    }
   14070 
   14071   assert (p <= end);
   14072   return p;
   14073 }
   14074 
   14075 static int
   14076 process_attributes (FILE * file,
   14077 		    const char * public_name,
   14078 		    unsigned int proc_type,
   14079 		    unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
   14080 		    unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int, const unsigned char * const))
   14081 {
   14082   Elf_Internal_Shdr * sect;
   14083   unsigned i;
   14084 
   14085   /* Find the section header so that we get the size.  */
   14086   for (i = 0, sect = section_headers;
   14087        i < elf_header.e_shnum;
   14088        i++, sect++)
   14089     {
   14090       unsigned char * contents;
   14091       unsigned char * p;
   14092 
   14093       if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
   14094 	continue;
   14095 
   14096       contents = (unsigned char *) get_data (NULL, file, sect->sh_offset, 1,
   14097                                              sect->sh_size, _("attributes"));
   14098       if (contents == NULL)
   14099 	continue;
   14100 
   14101       p = contents;
   14102       if (*p == 'A')
   14103 	{
   14104 	  bfd_vma section_len;
   14105 
   14106 	  section_len = sect->sh_size - 1;
   14107 	  p++;
   14108 
   14109 	  while (section_len > 0)
   14110 	    {
   14111 	      bfd_vma attr_len;
   14112 	      unsigned int namelen;
   14113 	      bfd_boolean public_section;
   14114 	      bfd_boolean gnu_section;
   14115 
   14116 	      if (section_len <= 4)
   14117 		{
   14118 		  error (_("Tag section ends prematurely\n"));
   14119 		  break;
   14120 		}
   14121 	      attr_len = byte_get (p, 4);
   14122 	      p += 4;
   14123 
   14124 	      if (attr_len > section_len)
   14125 		{
   14126 		  error (_("Bad attribute length (%u > %u)\n"),
   14127 			  (unsigned) attr_len, (unsigned) section_len);
   14128 		  attr_len = section_len;
   14129 		}
   14130 	      /* PR 17531: file: 001-101425-0.004  */
   14131 	      else if (attr_len < 5)
   14132 		{
   14133 		  error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
   14134 		  break;
   14135 		}
   14136 
   14137 	      section_len -= attr_len;
   14138 	      attr_len -= 4;
   14139 
   14140 	      namelen = strnlen ((char *) p, attr_len) + 1;
   14141 	      if (namelen == 0 || namelen >= attr_len)
   14142 		{
   14143 		  error (_("Corrupt attribute section name\n"));
   14144 		  break;
   14145 		}
   14146 
   14147 	      printf (_("Attribute Section: "));
   14148 	      print_symbol (INT_MAX, (const char *) p);
   14149 	      putchar ('\n');
   14150 
   14151 	      if (public_name && streq ((char *) p, public_name))
   14152 		public_section = TRUE;
   14153 	      else
   14154 		public_section = FALSE;
   14155 
   14156 	      if (streq ((char *) p, "gnu"))
   14157 		gnu_section = TRUE;
   14158 	      else
   14159 		gnu_section = FALSE;
   14160 
   14161 	      p += namelen;
   14162 	      attr_len -= namelen;
   14163 
   14164 	      while (attr_len > 0 && p < contents + sect->sh_size)
   14165 		{
   14166 		  int tag;
   14167 		  int val;
   14168 		  bfd_vma size;
   14169 		  unsigned char * end;
   14170 
   14171 		  /* PR binutils/17531: Safe handling of corrupt files.  */
   14172 		  if (attr_len < 6)
   14173 		    {
   14174 		      error (_("Unused bytes at end of section\n"));
   14175 		      section_len = 0;
   14176 		      break;
   14177 		    }
   14178 
   14179 		  tag = *(p++);
   14180 		  size = byte_get (p, 4);
   14181 		  if (size > attr_len)
   14182 		    {
   14183 		      error (_("Bad subsection length (%u > %u)\n"),
   14184 			      (unsigned) size, (unsigned) attr_len);
   14185 		      size = attr_len;
   14186 		    }
   14187 		  /* PR binutils/17531: Safe handling of corrupt files.  */
   14188 		  if (size < 6)
   14189 		    {
   14190 		      error (_("Bad subsection length (%u < 6)\n"),
   14191 			      (unsigned) size);
   14192 		      section_len = 0;
   14193 		      break;
   14194 		    }
   14195 
   14196 		  attr_len -= size;
   14197 		  end = p + size - 1;
   14198 		  assert (end <= contents + sect->sh_size);
   14199 		  p += 4;
   14200 
   14201 		  switch (tag)
   14202 		    {
   14203 		    case 1:
   14204 		      printf (_("File Attributes\n"));
   14205 		      break;
   14206 		    case 2:
   14207 		      printf (_("Section Attributes:"));
   14208 		      goto do_numlist;
   14209 		    case 3:
   14210 		      printf (_("Symbol Attributes:"));
   14211 		    do_numlist:
   14212 		      for (;;)
   14213 			{
   14214 			  unsigned int j;
   14215 
   14216 			  val = read_uleb128 (p, &j, end);
   14217 			  p += j;
   14218 			  if (val == 0)
   14219 			    break;
   14220 			  printf (" %d", val);
   14221 			}
   14222 		      printf ("\n");
   14223 		      break;
   14224 		    default:
   14225 		      printf (_("Unknown tag: %d\n"), tag);
   14226 		      public_section = FALSE;
   14227 		      break;
   14228 		    }
   14229 
   14230 		  if (public_section && display_pub_attribute != NULL)
   14231 		    {
   14232 		      while (p < end)
   14233 			p = display_pub_attribute (p, end);
   14234 		      assert (p <= end);
   14235 		    }
   14236 		  else if (gnu_section && display_proc_gnu_attribute != NULL)
   14237 		    {
   14238 		      while (p < end)
   14239 			p = display_gnu_attribute (p,
   14240 						   display_proc_gnu_attribute,
   14241 						   end);
   14242 		      assert (p <= end);
   14243 		    }
   14244 		  else if (p < end)
   14245 		    {
   14246 		      printf (_("  Unknown attribute:\n"));
   14247 		      display_raw_attribute (p, end);
   14248 		      p = end;
   14249 		    }
   14250 		  else
   14251 		    attr_len = 0;
   14252 		}
   14253 	    }
   14254 	}
   14255       else
   14256 	printf (_("Unknown format '%c' (%d)\n"), *p, *p);
   14257 
   14258       free (contents);
   14259     }
   14260   return 1;
   14261 }
   14262 
   14263 static int
   14264 process_arm_specific (FILE * file)
   14265 {
   14266   return process_attributes (file, "aeabi", SHT_ARM_ATTRIBUTES,
   14267 			     display_arm_attribute, NULL);
   14268 }
   14269 
   14270 static int
   14271 process_power_specific (FILE * file)
   14272 {
   14273   return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
   14274 			     display_power_gnu_attribute);
   14275 }
   14276 
   14277 static int
   14278 process_s390_specific (FILE * file)
   14279 {
   14280   return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
   14281 			     display_s390_gnu_attribute);
   14282 }
   14283 
   14284 static int
   14285 process_sparc_specific (FILE * file)
   14286 {
   14287   return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
   14288 			     display_sparc_gnu_attribute);
   14289 }
   14290 
   14291 static int
   14292 process_tic6x_specific (FILE * file)
   14293 {
   14294   return process_attributes (file, "c6xabi", SHT_C6000_ATTRIBUTES,
   14295 			     display_tic6x_attribute, NULL);
   14296 }
   14297 
   14298 static int
   14299 process_msp430x_specific (FILE * file)
   14300 {
   14301   return process_attributes (file, "mspabi", SHT_MSP430_ATTRIBUTES,
   14302 			     display_msp430x_attribute, NULL);
   14303 }
   14304 
   14305 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
   14306    Print the Address, Access and Initial fields of an entry at VMA ADDR
   14307    and return the VMA of the next entry, or -1 if there was a problem.
   14308    Does not read from DATA_END or beyond.  */
   14309 
   14310 static bfd_vma
   14311 print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
   14312 		      unsigned char * data_end)
   14313 {
   14314   printf ("  ");
   14315   print_vma (addr, LONG_HEX);
   14316   printf (" ");
   14317   if (addr < pltgot + 0xfff0)
   14318     printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
   14319   else
   14320     printf ("%10s", "");
   14321   printf (" ");
   14322   if (data == NULL)
   14323     printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
   14324   else
   14325     {
   14326       bfd_vma entry;
   14327       unsigned char * from = data + addr - pltgot;
   14328 
   14329       if (from + (is_32bit_elf ? 4 : 8) > data_end)
   14330 	{
   14331 	  warn (_("MIPS GOT entry extends beyond the end of available data\n"));
   14332 	  printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
   14333 	  return (bfd_vma) -1;
   14334 	}
   14335       else
   14336 	{
   14337 	  entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
   14338 	  print_vma (entry, LONG_HEX);
   14339 	}
   14340     }
   14341   return addr + (is_32bit_elf ? 4 : 8);
   14342 }
   14343 
   14344 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
   14345    PLTGOT.  Print the Address and Initial fields of an entry at VMA
   14346    ADDR and return the VMA of the next entry.  */
   14347 
   14348 static bfd_vma
   14349 print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
   14350 {
   14351   printf ("  ");
   14352   print_vma (addr, LONG_HEX);
   14353   printf (" ");
   14354   if (data == NULL)
   14355     printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
   14356   else
   14357     {
   14358       bfd_vma entry;
   14359 
   14360       entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
   14361       print_vma (entry, LONG_HEX);
   14362     }
   14363   return addr + (is_32bit_elf ? 4 : 8);
   14364 }
   14365 
   14366 static void
   14367 print_mips_ases (unsigned int mask)
   14368 {
   14369   if (mask & AFL_ASE_DSP)
   14370     fputs ("\n\tDSP ASE", stdout);
   14371   if (mask & AFL_ASE_DSPR2)
   14372     fputs ("\n\tDSP R2 ASE", stdout);
   14373   if (mask & AFL_ASE_DSPR3)
   14374     fputs ("\n\tDSP R3 ASE", stdout);
   14375   if (mask & AFL_ASE_EVA)
   14376     fputs ("\n\tEnhanced VA Scheme", stdout);
   14377   if (mask & AFL_ASE_MCU)
   14378     fputs ("\n\tMCU (MicroController) ASE", stdout);
   14379   if (mask & AFL_ASE_MDMX)
   14380     fputs ("\n\tMDMX ASE", stdout);
   14381   if (mask & AFL_ASE_MIPS3D)
   14382     fputs ("\n\tMIPS-3D ASE", stdout);
   14383   if (mask & AFL_ASE_MT)
   14384     fputs ("\n\tMT ASE", stdout);
   14385   if (mask & AFL_ASE_SMARTMIPS)
   14386     fputs ("\n\tSmartMIPS ASE", stdout);
   14387   if (mask & AFL_ASE_VIRT)
   14388     fputs ("\n\tVZ ASE", stdout);
   14389   if (mask & AFL_ASE_MSA)
   14390     fputs ("\n\tMSA ASE", stdout);
   14391   if (mask & AFL_ASE_MIPS16)
   14392     fputs ("\n\tMIPS16 ASE", stdout);
   14393   if (mask & AFL_ASE_MICROMIPS)
   14394     fputs ("\n\tMICROMIPS ASE", stdout);
   14395   if (mask & AFL_ASE_XPA)
   14396     fputs ("\n\tXPA ASE", stdout);
   14397   if (mask == 0)
   14398     fprintf (stdout, "\n\t%s", _("None"));
   14399   else if ((mask & ~AFL_ASE_MASK) != 0)
   14400     fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
   14401 }
   14402 
   14403 static void
   14404 print_mips_isa_ext (unsigned int isa_ext)
   14405 {
   14406   switch (isa_ext)
   14407     {
   14408     case 0:
   14409       fputs (_("None"), stdout);
   14410       break;
   14411     case AFL_EXT_XLR:
   14412       fputs ("RMI XLR", stdout);
   14413       break;
   14414     case AFL_EXT_OCTEON3:
   14415       fputs ("Cavium Networks Octeon3", stdout);
   14416       break;
   14417     case AFL_EXT_OCTEON2:
   14418       fputs ("Cavium Networks Octeon2", stdout);
   14419       break;
   14420     case AFL_EXT_OCTEONP:
   14421       fputs ("Cavium Networks OcteonP", stdout);
   14422       break;
   14423     case AFL_EXT_LOONGSON_3A:
   14424       fputs ("Loongson 3A", stdout);
   14425       break;
   14426     case AFL_EXT_OCTEON:
   14427       fputs ("Cavium Networks Octeon", stdout);
   14428       break;
   14429     case AFL_EXT_5900:
   14430       fputs ("Toshiba R5900", stdout);
   14431       break;
   14432     case AFL_EXT_4650:
   14433       fputs ("MIPS R4650", stdout);
   14434       break;
   14435     case AFL_EXT_4010:
   14436       fputs ("LSI R4010", stdout);
   14437       break;
   14438     case AFL_EXT_4100:
   14439       fputs ("NEC VR4100", stdout);
   14440       break;
   14441     case AFL_EXT_3900:
   14442       fputs ("Toshiba R3900", stdout);
   14443       break;
   14444     case AFL_EXT_10000:
   14445       fputs ("MIPS R10000", stdout);
   14446       break;
   14447     case AFL_EXT_SB1:
   14448       fputs ("Broadcom SB-1", stdout);
   14449       break;
   14450     case AFL_EXT_4111:
   14451       fputs ("NEC VR4111/VR4181", stdout);
   14452       break;
   14453     case AFL_EXT_4120:
   14454       fputs ("NEC VR4120", stdout);
   14455       break;
   14456     case AFL_EXT_5400:
   14457       fputs ("NEC VR5400", stdout);
   14458       break;
   14459     case AFL_EXT_5500:
   14460       fputs ("NEC VR5500", stdout);
   14461       break;
   14462     case AFL_EXT_LOONGSON_2E:
   14463       fputs ("ST Microelectronics Loongson 2E", stdout);
   14464       break;
   14465     case AFL_EXT_LOONGSON_2F:
   14466       fputs ("ST Microelectronics Loongson 2F", stdout);
   14467       break;
   14468     default:
   14469       fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
   14470     }
   14471 }
   14472 
   14473 static int
   14474 get_mips_reg_size (int reg_size)
   14475 {
   14476   return (reg_size == AFL_REG_NONE) ? 0
   14477 	 : (reg_size == AFL_REG_32) ? 32
   14478 	 : (reg_size == AFL_REG_64) ? 64
   14479 	 : (reg_size == AFL_REG_128) ? 128
   14480 	 : -1;
   14481 }
   14482 
   14483 static int
   14484 process_mips_specific (FILE * file)
   14485 {
   14486   Elf_Internal_Dyn * entry;
   14487   Elf_Internal_Shdr *sect = NULL;
   14488   size_t liblist_offset = 0;
   14489   size_t liblistno = 0;
   14490   size_t conflictsno = 0;
   14491   size_t options_offset = 0;
   14492   size_t conflicts_offset = 0;
   14493   size_t pltrelsz = 0;
   14494   size_t pltrel = 0;
   14495   bfd_vma pltgot = 0;
   14496   bfd_vma mips_pltgot = 0;
   14497   bfd_vma jmprel = 0;
   14498   bfd_vma local_gotno = 0;
   14499   bfd_vma gotsym = 0;
   14500   bfd_vma symtabno = 0;
   14501 
   14502   process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
   14503 		      display_mips_gnu_attribute);
   14504 
   14505   sect = find_section (".MIPS.abiflags");
   14506 
   14507   if (sect != NULL)
   14508     {
   14509       Elf_External_ABIFlags_v0 *abiflags_ext;
   14510       Elf_Internal_ABIFlags_v0 abiflags_in;
   14511 
   14512       if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
   14513 	fputs ("\nCorrupt ABI Flags section.\n", stdout);
   14514       else
   14515 	{
   14516 	  abiflags_ext = get_data (NULL, file, sect->sh_offset, 1,
   14517 				   sect->sh_size, _("MIPS ABI Flags section"));
   14518 	  if (abiflags_ext)
   14519 	    {
   14520 	      abiflags_in.version = BYTE_GET (abiflags_ext->version);
   14521 	      abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
   14522 	      abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
   14523 	      abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
   14524 	      abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
   14525 	      abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
   14526 	      abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
   14527 	      abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
   14528 	      abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
   14529 	      abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
   14530 	      abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
   14531 
   14532 	      printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
   14533 	      printf ("\nISA: MIPS%d", abiflags_in.isa_level);
   14534 	      if (abiflags_in.isa_rev > 1)
   14535 		printf ("r%d", abiflags_in.isa_rev);
   14536 	      printf ("\nGPR size: %d",
   14537 		      get_mips_reg_size (abiflags_in.gpr_size));
   14538 	      printf ("\nCPR1 size: %d",
   14539 		      get_mips_reg_size (abiflags_in.cpr1_size));
   14540 	      printf ("\nCPR2 size: %d",
   14541 		      get_mips_reg_size (abiflags_in.cpr2_size));
   14542 	      fputs ("\nFP ABI: ", stdout);
   14543 	      print_mips_fp_abi_value (abiflags_in.fp_abi);
   14544 	      fputs ("ISA Extension: ", stdout);
   14545 	      print_mips_isa_ext (abiflags_in.isa_ext);
   14546 	      fputs ("\nASEs:", stdout);
   14547 	      print_mips_ases (abiflags_in.ases);
   14548 	      printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
   14549 	      printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
   14550 	      fputc ('\n', stdout);
   14551 	      free (abiflags_ext);
   14552 	    }
   14553 	}
   14554     }
   14555 
   14556   /* We have a lot of special sections.  Thanks SGI!  */
   14557   if (dynamic_section == NULL)
   14558     /* No information available.  */
   14559     return 0;
   14560 
   14561   for (entry = dynamic_section;
   14562        /* PR 17531 file: 012-50589-0.004.  */
   14563        entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL;
   14564        ++entry)
   14565     switch (entry->d_tag)
   14566       {
   14567       case DT_MIPS_LIBLIST:
   14568 	liblist_offset
   14569 	  = offset_from_vma (file, entry->d_un.d_val,
   14570 			     liblistno * sizeof (Elf32_External_Lib));
   14571 	break;
   14572       case DT_MIPS_LIBLISTNO:
   14573 	liblistno = entry->d_un.d_val;
   14574 	break;
   14575       case DT_MIPS_OPTIONS:
   14576 	options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
   14577 	break;
   14578       case DT_MIPS_CONFLICT:
   14579 	conflicts_offset
   14580 	  = offset_from_vma (file, entry->d_un.d_val,
   14581 			     conflictsno * sizeof (Elf32_External_Conflict));
   14582 	break;
   14583       case DT_MIPS_CONFLICTNO:
   14584 	conflictsno = entry->d_un.d_val;
   14585 	break;
   14586       case DT_PLTGOT:
   14587 	pltgot = entry->d_un.d_ptr;
   14588 	break;
   14589       case DT_MIPS_LOCAL_GOTNO:
   14590 	local_gotno = entry->d_un.d_val;
   14591 	break;
   14592       case DT_MIPS_GOTSYM:
   14593 	gotsym = entry->d_un.d_val;
   14594 	break;
   14595       case DT_MIPS_SYMTABNO:
   14596 	symtabno = entry->d_un.d_val;
   14597 	break;
   14598       case DT_MIPS_PLTGOT:
   14599 	mips_pltgot = entry->d_un.d_ptr;
   14600 	break;
   14601       case DT_PLTREL:
   14602 	pltrel = entry->d_un.d_val;
   14603 	break;
   14604       case DT_PLTRELSZ:
   14605 	pltrelsz = entry->d_un.d_val;
   14606 	break;
   14607       case DT_JMPREL:
   14608 	jmprel = entry->d_un.d_ptr;
   14609 	break;
   14610       default:
   14611 	break;
   14612       }
   14613 
   14614   if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
   14615     {
   14616       Elf32_External_Lib * elib;
   14617       size_t cnt;
   14618 
   14619       elib = (Elf32_External_Lib *) get_data (NULL, file, liblist_offset,
   14620                                               liblistno,
   14621                                               sizeof (Elf32_External_Lib),
   14622                                               _("liblist section data"));
   14623       if (elib)
   14624 	{
   14625 	  printf (_("\nSection '.liblist' contains %lu entries:\n"),
   14626 		  (unsigned long) liblistno);
   14627 	  fputs (_("     Library              Time Stamp          Checksum   Version Flags\n"),
   14628 		 stdout);
   14629 
   14630 	  for (cnt = 0; cnt < liblistno; ++cnt)
   14631 	    {
   14632 	      Elf32_Lib liblist;
   14633 	      time_t atime;
   14634 	      char timebuf[128];
   14635 	      struct tm * tmp;
   14636 
   14637 	      liblist.l_name = BYTE_GET (elib[cnt].l_name);
   14638 	      atime = BYTE_GET (elib[cnt].l_time_stamp);
   14639 	      liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
   14640 	      liblist.l_version = BYTE_GET (elib[cnt].l_version);
   14641 	      liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
   14642 
   14643 	      tmp = gmtime (&atime);
   14644 	      snprintf (timebuf, sizeof (timebuf),
   14645 			"%04u-%02u-%02uT%02u:%02u:%02u",
   14646 			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
   14647 			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
   14648 
   14649 	      printf ("%3lu: ", (unsigned long) cnt);
   14650 	      if (VALID_DYNAMIC_NAME (liblist.l_name))
   14651 		print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
   14652 	      else
   14653 		printf (_("<corrupt: %9ld>"), liblist.l_name);
   14654 	      printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
   14655 		      liblist.l_version);
   14656 
   14657 	      if (liblist.l_flags == 0)
   14658 		puts (_(" NONE"));
   14659 	      else
   14660 		{
   14661 		  static const struct
   14662 		  {
   14663 		    const char * name;
   14664 		    int bit;
   14665 		  }
   14666 		  l_flags_vals[] =
   14667 		  {
   14668 		    { " EXACT_MATCH", LL_EXACT_MATCH },
   14669 		    { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
   14670 		    { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
   14671 		    { " EXPORTS", LL_EXPORTS },
   14672 		    { " DELAY_LOAD", LL_DELAY_LOAD },
   14673 		    { " DELTA", LL_DELTA }
   14674 		  };
   14675 		  int flags = liblist.l_flags;
   14676 		  size_t fcnt;
   14677 
   14678 		  for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
   14679 		    if ((flags & l_flags_vals[fcnt].bit) != 0)
   14680 		      {
   14681 			fputs (l_flags_vals[fcnt].name, stdout);
   14682 			flags ^= l_flags_vals[fcnt].bit;
   14683 		      }
   14684 		  if (flags != 0)
   14685 		    printf (" %#x", (unsigned int) flags);
   14686 
   14687 		  puts ("");
   14688 		}
   14689 	    }
   14690 
   14691 	  free (elib);
   14692 	}
   14693     }
   14694 
   14695   if (options_offset != 0)
   14696     {
   14697       Elf_External_Options * eopt;
   14698       Elf_Internal_Options * iopt;
   14699       Elf_Internal_Options * option;
   14700       size_t offset;
   14701       int cnt;
   14702       sect = section_headers;
   14703 
   14704       /* Find the section header so that we get the size.  */
   14705       sect = find_section_by_type (SHT_MIPS_OPTIONS);
   14706       /* PR 17533 file: 012-277276-0.004.  */
   14707       if (sect == NULL)
   14708 	{
   14709 	  error (_("No MIPS_OPTIONS header found\n"));
   14710 	  return 0;
   14711 	}
   14712 
   14713       eopt = (Elf_External_Options *) get_data (NULL, file, options_offset, 1,
   14714                                                 sect->sh_size, _("options"));
   14715       if (eopt)
   14716 	{
   14717 	  iopt = (Elf_Internal_Options *)
   14718               cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
   14719 	  if (iopt == NULL)
   14720 	    {
   14721 	      error (_("Out of memory allocatinf space for MIPS options\n"));
   14722 	      return 0;
   14723 	    }
   14724 
   14725 	  offset = cnt = 0;
   14726 	  option = iopt;
   14727 
   14728 	  while (offset <= sect->sh_size - sizeof (* eopt))
   14729 	    {
   14730 	      Elf_External_Options * eoption;
   14731 
   14732 	      eoption = (Elf_External_Options *) ((char *) eopt + offset);
   14733 
   14734 	      option->kind = BYTE_GET (eoption->kind);
   14735 	      option->size = BYTE_GET (eoption->size);
   14736 	      option->section = BYTE_GET (eoption->section);
   14737 	      option->info = BYTE_GET (eoption->info);
   14738 
   14739 	      /* PR 17531: file: ffa0fa3b.  */
   14740 	      if (option->size < sizeof (* eopt)
   14741 		  || offset + option->size > sect->sh_size)
   14742 		{
   14743 		  error (_("Invalid size (%u) for MIPS option\n"), option->size);
   14744 		  return 0;
   14745 		}
   14746 	      offset += option->size;
   14747 
   14748 	      ++option;
   14749 	      ++cnt;
   14750 	    }
   14751 
   14752 	  printf (_("\nSection '%s' contains %d entries:\n"),
   14753 		  printable_section_name (sect), cnt);
   14754 
   14755 	  option = iopt;
   14756 	  offset = 0;
   14757 
   14758 	  while (cnt-- > 0)
   14759 	    {
   14760 	      size_t len;
   14761 
   14762 	      switch (option->kind)
   14763 		{
   14764 		case ODK_NULL:
   14765 		  /* This shouldn't happen.  */
   14766 		  printf (" NULL       %d %lx", option->section, option->info);
   14767 		  break;
   14768 		case ODK_REGINFO:
   14769 		  printf (" REGINFO    ");
   14770 		  if (elf_header.e_machine == EM_MIPS)
   14771 		    {
   14772 		      /* 32bit form.  */
   14773 		      Elf32_External_RegInfo * ereg;
   14774 		      Elf32_RegInfo reginfo;
   14775 
   14776 		      ereg = (Elf32_External_RegInfo *) (option + 1);
   14777 		      reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
   14778 		      reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
   14779 		      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
   14780 		      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
   14781 		      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
   14782 		      reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
   14783 
   14784 		      printf ("GPR %08lx  GP 0x%lx\n",
   14785 			      reginfo.ri_gprmask,
   14786 			      (unsigned long) reginfo.ri_gp_value);
   14787 		      printf ("            CPR0 %08lx  CPR1 %08lx  CPR2 %08lx  CPR3 %08lx\n",
   14788 			      reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
   14789 			      reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
   14790 		    }
   14791 		  else
   14792 		    {
   14793 		      /* 64 bit form.  */
   14794 		      Elf64_External_RegInfo * ereg;
   14795 		      Elf64_Internal_RegInfo reginfo;
   14796 
   14797 		      ereg = (Elf64_External_RegInfo *) (option + 1);
   14798 		      reginfo.ri_gprmask    = BYTE_GET (ereg->ri_gprmask);
   14799 		      reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
   14800 		      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
   14801 		      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
   14802 		      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
   14803 		      reginfo.ri_gp_value   = BYTE_GET (ereg->ri_gp_value);
   14804 
   14805 		      printf ("GPR %08lx  GP 0x",
   14806 			      reginfo.ri_gprmask);
   14807 		      printf_vma (reginfo.ri_gp_value);
   14808 		      printf ("\n");
   14809 
   14810 		      printf ("            CPR0 %08lx  CPR1 %08lx  CPR2 %08lx  CPR3 %08lx\n",
   14811 			      reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
   14812 			      reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
   14813 		    }
   14814 		  ++option;
   14815 		  continue;
   14816 		case ODK_EXCEPTIONS:
   14817 		  fputs (" EXCEPTIONS fpe_min(", stdout);
   14818 		  process_mips_fpe_exception (option->info & OEX_FPU_MIN);
   14819 		  fputs (") fpe_max(", stdout);
   14820 		  process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
   14821 		  fputs (")", stdout);
   14822 
   14823 		  if (option->info & OEX_PAGE0)
   14824 		    fputs (" PAGE0", stdout);
   14825 		  if (option->info & OEX_SMM)
   14826 		    fputs (" SMM", stdout);
   14827 		  if (option->info & OEX_FPDBUG)
   14828 		    fputs (" FPDBUG", stdout);
   14829 		  if (option->info & OEX_DISMISS)
   14830 		    fputs (" DISMISS", stdout);
   14831 		  break;
   14832 		case ODK_PAD:
   14833 		  fputs (" PAD       ", stdout);
   14834 		  if (option->info & OPAD_PREFIX)
   14835 		    fputs (" PREFIX", stdout);
   14836 		  if (option->info & OPAD_POSTFIX)
   14837 		    fputs (" POSTFIX", stdout);
   14838 		  if (option->info & OPAD_SYMBOL)
   14839 		    fputs (" SYMBOL", stdout);
   14840 		  break;
   14841 		case ODK_HWPATCH:
   14842 		  fputs (" HWPATCH   ", stdout);
   14843 		  if (option->info & OHW_R4KEOP)
   14844 		    fputs (" R4KEOP", stdout);
   14845 		  if (option->info & OHW_R8KPFETCH)
   14846 		    fputs (" R8KPFETCH", stdout);
   14847 		  if (option->info & OHW_R5KEOP)
   14848 		    fputs (" R5KEOP", stdout);
   14849 		  if (option->info & OHW_R5KCVTL)
   14850 		    fputs (" R5KCVTL", stdout);
   14851 		  break;
   14852 		case ODK_FILL:
   14853 		  fputs (" FILL       ", stdout);
   14854 		  /* XXX Print content of info word?  */
   14855 		  break;
   14856 		case ODK_TAGS:
   14857 		  fputs (" TAGS       ", stdout);
   14858 		  /* XXX Print content of info word?  */
   14859 		  break;
   14860 		case ODK_HWAND:
   14861 		  fputs (" HWAND     ", stdout);
   14862 		  if (option->info & OHWA0_R4KEOP_CHECKED)
   14863 		    fputs (" R4KEOP_CHECKED", stdout);
   14864 		  if (option->info & OHWA0_R4KEOP_CLEAN)
   14865 		    fputs (" R4KEOP_CLEAN", stdout);
   14866 		  break;
   14867 		case ODK_HWOR:
   14868 		  fputs (" HWOR      ", stdout);
   14869 		  if (option->info & OHWA0_R4KEOP_CHECKED)
   14870 		    fputs (" R4KEOP_CHECKED", stdout);
   14871 		  if (option->info & OHWA0_R4KEOP_CLEAN)
   14872 		    fputs (" R4KEOP_CLEAN", stdout);
   14873 		  break;
   14874 		case ODK_GP_GROUP:
   14875 		  printf (" GP_GROUP  %#06lx  self-contained %#06lx",
   14876 			  option->info & OGP_GROUP,
   14877 			  (option->info & OGP_SELF) >> 16);
   14878 		  break;
   14879 		case ODK_IDENT:
   14880 		  printf (" IDENT     %#06lx  self-contained %#06lx",
   14881 			  option->info & OGP_GROUP,
   14882 			  (option->info & OGP_SELF) >> 16);
   14883 		  break;
   14884 		default:
   14885 		  /* This shouldn't happen.  */
   14886 		  printf (" %3d ???     %d %lx",
   14887 			  option->kind, option->section, option->info);
   14888 		  break;
   14889 		}
   14890 
   14891 	      len = sizeof (* eopt);
   14892 	      while (len < option->size)
   14893 		{
   14894 		  unsigned char datum = * ((unsigned char *) eopt + offset + len);
   14895 
   14896 		  if (ISPRINT (datum))
   14897 		    printf ("%c", datum);
   14898 		  else
   14899 		    printf ("\\%03o", datum);
   14900 		  len ++;
   14901 		}
   14902 	      fputs ("\n", stdout);
   14903 
   14904 	      offset += option->size;
   14905 	      ++option;
   14906 	    }
   14907 
   14908 	  free (eopt);
   14909 	}
   14910     }
   14911 
   14912   if (conflicts_offset != 0 && conflictsno != 0)
   14913     {
   14914       Elf32_Conflict * iconf;
   14915       size_t cnt;
   14916 
   14917       if (dynamic_symbols == NULL)
   14918 	{
   14919 	  error (_("conflict list found without a dynamic symbol table\n"));
   14920 	  return 0;
   14921 	}
   14922 
   14923       iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
   14924       if (iconf == NULL)
   14925 	{
   14926 	  error (_("Out of memory allocating space for dynamic conflicts\n"));
   14927 	  return 0;
   14928 	}
   14929 
   14930       if (is_32bit_elf)
   14931 	{
   14932 	  Elf32_External_Conflict * econf32;
   14933 
   14934 	  econf32 = (Elf32_External_Conflict *)
   14935               get_data (NULL, file, conflicts_offset, conflictsno,
   14936                         sizeof (* econf32), _("conflict"));
   14937 	  if (!econf32)
   14938 	    return 0;
   14939 
   14940 	  for (cnt = 0; cnt < conflictsno; ++cnt)
   14941 	    iconf[cnt] = BYTE_GET (econf32[cnt]);
   14942 
   14943 	  free (econf32);
   14944 	}
   14945       else
   14946 	{
   14947 	  Elf64_External_Conflict * econf64;
   14948 
   14949 	  econf64 = (Elf64_External_Conflict *)
   14950               get_data (NULL, file, conflicts_offset, conflictsno,
   14951                         sizeof (* econf64), _("conflict"));
   14952 	  if (!econf64)
   14953 	    return 0;
   14954 
   14955 	  for (cnt = 0; cnt < conflictsno; ++cnt)
   14956 	    iconf[cnt] = BYTE_GET (econf64[cnt]);
   14957 
   14958 	  free (econf64);
   14959 	}
   14960 
   14961       printf (_("\nSection '.conflict' contains %lu entries:\n"),
   14962 	      (unsigned long) conflictsno);
   14963       puts (_("  Num:    Index       Value  Name"));
   14964 
   14965       for (cnt = 0; cnt < conflictsno; ++cnt)
   14966 	{
   14967 	  printf ("%5lu: %8lu  ", (unsigned long) cnt, iconf[cnt]);
   14968 
   14969 	  if (iconf[cnt] >= num_dynamic_syms)
   14970 	    printf (_("<corrupt symbol index>"));
   14971 	  else
   14972 	    {
   14973 	      Elf_Internal_Sym * psym;
   14974 
   14975 	      psym = & dynamic_symbols[iconf[cnt]];
   14976 	      print_vma (psym->st_value, FULL_HEX);
   14977 	      putchar (' ');
   14978 	      if (VALID_DYNAMIC_NAME (psym->st_name))
   14979 		print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
   14980 	      else
   14981 		printf (_("<corrupt: %14ld>"), psym->st_name);
   14982 	    }
   14983 	  putchar ('\n');
   14984 	}
   14985 
   14986       free (iconf);
   14987     }
   14988 
   14989   if (pltgot != 0 && local_gotno != 0)
   14990     {
   14991       bfd_vma ent, local_end, global_end;
   14992       size_t i, offset;
   14993       unsigned char * data;
   14994       unsigned char * data_end;
   14995       int addr_size;
   14996 
   14997       ent = pltgot;
   14998       addr_size = (is_32bit_elf ? 4 : 8);
   14999       local_end = pltgot + local_gotno * addr_size;
   15000 
   15001       /* PR binutils/17533 file: 012-111227-0.004  */
   15002       if (symtabno < gotsym)
   15003 	{
   15004 	  error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
   15005 		 (unsigned long) gotsym, (unsigned long) symtabno);
   15006 	  return 0;
   15007 	}
   15008 
   15009       global_end = local_end + (symtabno - gotsym) * addr_size;
   15010       /* PR 17531: file: 54c91a34.  */
   15011       if (global_end < local_end)
   15012 	{
   15013 	  error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
   15014 	  return 0;
   15015 	}
   15016 
   15017       offset = offset_from_vma (file, pltgot, global_end - pltgot);
   15018       data = (unsigned char *) get_data (NULL, file, offset,
   15019                                          global_end - pltgot, 1,
   15020 					 _("Global Offset Table data"));
   15021       if (data == NULL)
   15022 	return 0;
   15023       data_end = data + (global_end - pltgot);
   15024 
   15025       printf (_("\nPrimary GOT:\n"));
   15026       printf (_(" Canonical gp value: "));
   15027       print_vma (pltgot + 0x7ff0, LONG_HEX);
   15028       printf ("\n\n");
   15029 
   15030       printf (_(" Reserved entries:\n"));
   15031       printf (_("  %*s %10s %*s Purpose\n"),
   15032 	      addr_size * 2, _("Address"), _("Access"),
   15033 	      addr_size * 2, _("Initial"));
   15034       ent = print_mips_got_entry (data, pltgot, ent, data_end);
   15035       printf (_(" Lazy resolver\n"));
   15036       if (ent == (bfd_vma) -1)
   15037 	goto got_print_fail;
   15038       if (data
   15039 	  && (byte_get (data + ent - pltgot, addr_size)
   15040 	      >> (addr_size * 8 - 1)) != 0)
   15041 	{
   15042 	  ent = print_mips_got_entry (data, pltgot, ent, data_end);
   15043 	  printf (_(" Module pointer (GNU extension)\n"));
   15044 	  if (ent == (bfd_vma) -1)
   15045 	    goto got_print_fail;
   15046 	}
   15047       printf ("\n");
   15048 
   15049       if (ent < local_end)
   15050 	{
   15051 	  printf (_(" Local entries:\n"));
   15052 	  printf ("  %*s %10s %*s\n",
   15053 		  addr_size * 2, _("Address"), _("Access"),
   15054 		  addr_size * 2, _("Initial"));
   15055 	  while (ent < local_end)
   15056 	    {
   15057 	      ent = print_mips_got_entry (data, pltgot, ent, data_end);
   15058 	      printf ("\n");
   15059 	      if (ent == (bfd_vma) -1)
   15060 		goto got_print_fail;
   15061 	    }
   15062 	  printf ("\n");
   15063 	}
   15064 
   15065       if (gotsym < symtabno)
   15066 	{
   15067 	  int sym_width;
   15068 
   15069 	  printf (_(" Global entries:\n"));
   15070 	  printf ("  %*s %10s %*s %*s %-7s %3s %s\n",
   15071 		  addr_size * 2, _("Address"),
   15072 		  _("Access"),
   15073 		  addr_size * 2, _("Initial"),
   15074 		  addr_size * 2, _("Sym.Val."),
   15075 		  _("Type"),
   15076 		  /* Note for translators: "Ndx" = abbreviated form of "Index".  */
   15077 		  _("Ndx"), _("Name"));
   15078 
   15079 	  sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
   15080 
   15081 	  for (i = gotsym; i < symtabno; i++)
   15082 	    {
   15083 	      ent = print_mips_got_entry (data, pltgot, ent, data_end);
   15084 	      printf (" ");
   15085 
   15086 	      if (dynamic_symbols == NULL)
   15087 		printf (_("<no dynamic symbols>"));
   15088 	      else if (i < num_dynamic_syms)
   15089 		{
   15090 		  Elf_Internal_Sym * psym = dynamic_symbols + i;
   15091 
   15092 		  print_vma (psym->st_value, LONG_HEX);
   15093 		  printf (" %-7s %3s ",
   15094 			  get_symbol_type (ELF_ST_TYPE (psym->st_info)),
   15095 			  get_symbol_index_type (psym->st_shndx));
   15096 
   15097 		  if (VALID_DYNAMIC_NAME (psym->st_name))
   15098 		    print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
   15099 		  else
   15100 		    printf (_("<corrupt: %14ld>"), psym->st_name);
   15101 		}
   15102 	      else
   15103 		printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
   15104 			(unsigned long) i);
   15105 
   15106 	      printf ("\n");
   15107 	      if (ent == (bfd_vma) -1)
   15108 		break;
   15109 	    }
   15110 	  printf ("\n");
   15111 	}
   15112 
   15113     got_print_fail:
   15114       if (data)
   15115 	free (data);
   15116     }
   15117 
   15118   if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
   15119     {
   15120       bfd_vma ent, end;
   15121       size_t offset, rel_offset;
   15122       unsigned long count, i;
   15123       unsigned char * data;
   15124       int addr_size, sym_width;
   15125       Elf_Internal_Rela * rels;
   15126 
   15127       rel_offset = offset_from_vma (file, jmprel, pltrelsz);
   15128       if (pltrel == DT_RELA)
   15129 	{
   15130 	  if (!slurp_rela_relocs (file, rel_offset, pltrelsz, &rels, &count))
   15131 	    return 0;
   15132 	}
   15133       else
   15134 	{
   15135 	  if (!slurp_rel_relocs (file, rel_offset, pltrelsz, &rels, &count))
   15136 	    return 0;
   15137 	}
   15138 
   15139       ent = mips_pltgot;
   15140       addr_size = (is_32bit_elf ? 4 : 8);
   15141       end = mips_pltgot + (2 + count) * addr_size;
   15142 
   15143       offset = offset_from_vma (file, mips_pltgot, end - mips_pltgot);
   15144       data = (unsigned char *) get_data (NULL, file, offset, end - mips_pltgot,
   15145                                          1, _("Procedure Linkage Table data"));
   15146       if (data == NULL)
   15147 	return 0;
   15148 
   15149       printf ("\nPLT GOT:\n\n");
   15150       printf (_(" Reserved entries:\n"));
   15151       printf (_("  %*s %*s Purpose\n"),
   15152 	      addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
   15153       ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
   15154       printf (_(" PLT lazy resolver\n"));
   15155       ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
   15156       printf (_(" Module pointer\n"));
   15157       printf ("\n");
   15158 
   15159       printf (_(" Entries:\n"));
   15160       printf ("  %*s %*s %*s %-7s %3s %s\n",
   15161 	      addr_size * 2, _("Address"),
   15162 	      addr_size * 2, _("Initial"),
   15163 	      addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
   15164       sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
   15165       for (i = 0; i < count; i++)
   15166 	{
   15167 	  unsigned long idx = get_reloc_symindex (rels[i].r_info);
   15168 
   15169 	  ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
   15170 	  printf (" ");
   15171 
   15172 	  if (idx >= num_dynamic_syms)
   15173 	    printf (_("<corrupt symbol index: %lu>"), idx);
   15174 	  else
   15175 	    {
   15176 	      Elf_Internal_Sym * psym = dynamic_symbols + idx;
   15177 
   15178 	      print_vma (psym->st_value, LONG_HEX);
   15179 	      printf (" %-7s %3s ",
   15180 		      get_symbol_type (ELF_ST_TYPE (psym->st_info)),
   15181 		      get_symbol_index_type (psym->st_shndx));
   15182 	      if (VALID_DYNAMIC_NAME (psym->st_name))
   15183 		print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
   15184 	      else
   15185 		printf (_("<corrupt: %14ld>"), psym->st_name);
   15186 	    }
   15187 	  printf ("\n");
   15188 	}
   15189       printf ("\n");
   15190 
   15191       if (data)
   15192 	free (data);
   15193       free (rels);
   15194     }
   15195 
   15196   return 1;
   15197 }
   15198 
   15199 static int
   15200 process_nds32_specific (FILE * file)
   15201 {
   15202   Elf_Internal_Shdr *sect = NULL;
   15203 
   15204   sect = find_section (".nds32_e_flags");
   15205   if (sect != NULL)
   15206     {
   15207       unsigned int *flag;
   15208 
   15209       printf ("\nNDS32 elf flags section:\n");
   15210       flag = get_data (NULL, file, sect->sh_offset, 1,
   15211 		       sect->sh_size, _("NDS32 elf flags section"));
   15212 
   15213       switch ((*flag) & 0x3)
   15214 	{
   15215 	case 0:
   15216 	  printf ("(VEC_SIZE):\tNo entry.\n");
   15217 	  break;
   15218 	case 1:
   15219 	  printf ("(VEC_SIZE):\t4 bytes\n");
   15220 	  break;
   15221 	case 2:
   15222 	  printf ("(VEC_SIZE):\t16 bytes\n");
   15223 	  break;
   15224 	case 3:
   15225 	  printf ("(VEC_SIZE):\treserved\n");
   15226 	  break;
   15227 	}
   15228     }
   15229 
   15230   return TRUE;
   15231 }
   15232 
   15233 static int
   15234 process_gnu_liblist (FILE * file)
   15235 {
   15236   Elf_Internal_Shdr * section;
   15237   Elf_Internal_Shdr * string_sec;
   15238   Elf32_External_Lib * elib;
   15239   char * strtab;
   15240   size_t strtab_size;
   15241   size_t cnt;
   15242   unsigned i;
   15243 
   15244   if (! do_arch)
   15245     return 0;
   15246 
   15247   for (i = 0, section = section_headers;
   15248        i < elf_header.e_shnum;
   15249        i++, section++)
   15250     {
   15251       switch (section->sh_type)
   15252 	{
   15253 	case SHT_GNU_LIBLIST:
   15254 	  if (section->sh_link >= elf_header.e_shnum)
   15255 	    break;
   15256 
   15257 	  elib = (Elf32_External_Lib *)
   15258               get_data (NULL, file, section->sh_offset, 1, section->sh_size,
   15259                         _("liblist section data"));
   15260 
   15261 	  if (elib == NULL)
   15262 	    break;
   15263 	  string_sec = section_headers + section->sh_link;
   15264 
   15265 	  strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
   15266                                       string_sec->sh_size,
   15267                                       _("liblist string table"));
   15268 	  if (strtab == NULL
   15269 	      || section->sh_entsize != sizeof (Elf32_External_Lib))
   15270 	    {
   15271 	      free (elib);
   15272 	      free (strtab);
   15273 	      break;
   15274 	    }
   15275 	  strtab_size = string_sec->sh_size;
   15276 
   15277 	  printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
   15278 		  printable_section_name (section),
   15279 		  (unsigned long) (section->sh_size / sizeof (Elf32_External_Lib)));
   15280 
   15281 	  puts (_("     Library              Time Stamp          Checksum   Version Flags"));
   15282 
   15283 	  for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
   15284 	       ++cnt)
   15285 	    {
   15286 	      Elf32_Lib liblist;
   15287 	      time_t atime;
   15288 	      char timebuf[128];
   15289 	      struct tm * tmp;
   15290 
   15291 	      liblist.l_name = BYTE_GET (elib[cnt].l_name);
   15292 	      atime = BYTE_GET (elib[cnt].l_time_stamp);
   15293 	      liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
   15294 	      liblist.l_version = BYTE_GET (elib[cnt].l_version);
   15295 	      liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
   15296 
   15297 	      tmp = gmtime (&atime);
   15298 	      snprintf (timebuf, sizeof (timebuf),
   15299 			"%04u-%02u-%02uT%02u:%02u:%02u",
   15300 			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
   15301 			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
   15302 
   15303 	      printf ("%3lu: ", (unsigned long) cnt);
   15304 	      if (do_wide)
   15305 		printf ("%-20s", liblist.l_name < strtab_size
   15306 			? strtab + liblist.l_name : _("<corrupt>"));
   15307 	      else
   15308 		printf ("%-20.20s", liblist.l_name < strtab_size
   15309 			? strtab + liblist.l_name : _("<corrupt>"));
   15310 	      printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
   15311 		      liblist.l_version, liblist.l_flags);
   15312 	    }
   15313 
   15314 	  free (elib);
   15315 	  free (strtab);
   15316 	}
   15317     }
   15318 
   15319   return 1;
   15320 }
   15321 
   15322 static const char *
   15323 get_note_type (unsigned e_type)
   15324 {
   15325   static char buff[64];
   15326 
   15327   if (elf_header.e_type == ET_CORE)
   15328     switch (e_type)
   15329       {
   15330       case NT_AUXV:
   15331 	return _("NT_AUXV (auxiliary vector)");
   15332       case NT_PRSTATUS:
   15333 	return _("NT_PRSTATUS (prstatus structure)");
   15334       case NT_FPREGSET:
   15335 	return _("NT_FPREGSET (floating point registers)");
   15336       case NT_PRPSINFO:
   15337 	return _("NT_PRPSINFO (prpsinfo structure)");
   15338       case NT_TASKSTRUCT:
   15339 	return _("NT_TASKSTRUCT (task structure)");
   15340       case NT_PRXFPREG:
   15341 	return _("NT_PRXFPREG (user_xfpregs structure)");
   15342       case NT_PPC_VMX:
   15343 	return _("NT_PPC_VMX (ppc Altivec registers)");
   15344       case NT_PPC_VSX:
   15345 	return _("NT_PPC_VSX (ppc VSX registers)");
   15346       case NT_386_TLS:
   15347 	return _("NT_386_TLS (x86 TLS information)");
   15348       case NT_386_IOPERM:
   15349 	return _("NT_386_IOPERM (x86 I/O permissions)");
   15350       case NT_X86_XSTATE:
   15351 	return _("NT_X86_XSTATE (x86 XSAVE extended state)");
   15352       case NT_S390_HIGH_GPRS:
   15353 	return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
   15354       case NT_S390_TIMER:
   15355 	return _("NT_S390_TIMER (s390 timer register)");
   15356       case NT_S390_TODCMP:
   15357 	return _("NT_S390_TODCMP (s390 TOD comparator register)");
   15358       case NT_S390_TODPREG:
   15359 	return _("NT_S390_TODPREG (s390 TOD programmable register)");
   15360       case NT_S390_CTRS:
   15361 	return _("NT_S390_CTRS (s390 control registers)");
   15362       case NT_S390_PREFIX:
   15363 	return _("NT_S390_PREFIX (s390 prefix register)");
   15364       case NT_S390_LAST_BREAK:
   15365 	return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
   15366       case NT_S390_SYSTEM_CALL:
   15367 	return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
   15368       case NT_S390_TDB:
   15369 	return _("NT_S390_TDB (s390 transaction diagnostic block)");
   15370       case NT_S390_VXRS_LOW:
   15371 	return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
   15372       case NT_S390_VXRS_HIGH:
   15373 	return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
   15374       case NT_ARM_VFP:
   15375 	return _("NT_ARM_VFP (arm VFP registers)");
   15376       case NT_ARM_TLS:
   15377 	return _("NT_ARM_TLS (AArch TLS registers)");
   15378       case NT_ARM_HW_BREAK:
   15379 	return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
   15380       case NT_ARM_HW_WATCH:
   15381 	return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
   15382       case NT_PSTATUS:
   15383 	return _("NT_PSTATUS (pstatus structure)");
   15384       case NT_FPREGS:
   15385 	return _("NT_FPREGS (floating point registers)");
   15386       case NT_PSINFO:
   15387 	return _("NT_PSINFO (psinfo structure)");
   15388       case NT_LWPSTATUS:
   15389 	return _("NT_LWPSTATUS (lwpstatus_t structure)");
   15390       case NT_LWPSINFO:
   15391 	return _("NT_LWPSINFO (lwpsinfo_t structure)");
   15392       case NT_WIN32PSTATUS:
   15393 	return _("NT_WIN32PSTATUS (win32_pstatus structure)");
   15394       case NT_SIGINFO:
   15395 	return _("NT_SIGINFO (siginfo_t data)");
   15396       case NT_FILE:
   15397 	return _("NT_FILE (mapped files)");
   15398       default:
   15399 	break;
   15400       }
   15401   else
   15402     switch (e_type)
   15403       {
   15404       case NT_VERSION:
   15405 	return _("NT_VERSION (version)");
   15406       case NT_ARCH:
   15407 	return _("NT_ARCH (architecture)");
   15408       default:
   15409 	break;
   15410       }
   15411 
   15412   snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   15413   return buff;
   15414 }
   15415 
   15416 static int
   15417 print_core_note (Elf_Internal_Note *pnote)
   15418 {
   15419   unsigned int addr_size = is_32bit_elf ? 4 : 8;
   15420   bfd_vma count, page_size;
   15421   unsigned char *descdata, *filenames, *descend;
   15422 
   15423   if (pnote->type != NT_FILE)
   15424     return 1;
   15425 
   15426 #ifndef BFD64
   15427   if (!is_32bit_elf)
   15428     {
   15429       printf (_("    Cannot decode 64-bit note in 32-bit build\n"));
   15430       /* Still "successful".  */
   15431       return 1;
   15432     }
   15433 #endif
   15434 
   15435   if (pnote->descsz < 2 * addr_size)
   15436     {
   15437       printf (_("    Malformed note - too short for header\n"));
   15438       return 0;
   15439     }
   15440 
   15441   descdata = (unsigned char *) pnote->descdata;
   15442   descend = descdata + pnote->descsz;
   15443 
   15444   if (descdata[pnote->descsz - 1] != '\0')
   15445     {
   15446       printf (_("    Malformed note - does not end with \\0\n"));
   15447       return 0;
   15448     }
   15449 
   15450   count = byte_get (descdata, addr_size);
   15451   descdata += addr_size;
   15452 
   15453   page_size = byte_get (descdata, addr_size);
   15454   descdata += addr_size;
   15455 
   15456   if (pnote->descsz < 2 * addr_size + count * 3 * addr_size)
   15457     {
   15458       printf (_("    Malformed note - too short for supplied file count\n"));
   15459       return 0;
   15460     }
   15461 
   15462   printf (_("    Page size: "));
   15463   print_vma (page_size, DEC);
   15464   printf ("\n");
   15465 
   15466   printf (_("    %*s%*s%*s\n"),
   15467 	  (int) (2 + 2 * addr_size), _("Start"),
   15468 	  (int) (4 + 2 * addr_size), _("End"),
   15469 	  (int) (4 + 2 * addr_size), _("Page Offset"));
   15470   filenames = descdata + count * 3 * addr_size;
   15471   while (count-- > 0)
   15472     {
   15473       bfd_vma start, end, file_ofs;
   15474 
   15475       if (filenames == descend)
   15476 	{
   15477 	  printf (_("    Malformed note - filenames end too early\n"));
   15478 	  return 0;
   15479 	}
   15480 
   15481       start = byte_get (descdata, addr_size);
   15482       descdata += addr_size;
   15483       end = byte_get (descdata, addr_size);
   15484       descdata += addr_size;
   15485       file_ofs = byte_get (descdata, addr_size);
   15486       descdata += addr_size;
   15487 
   15488       printf ("    ");
   15489       print_vma (start, FULL_HEX);
   15490       printf ("  ");
   15491       print_vma (end, FULL_HEX);
   15492       printf ("  ");
   15493       print_vma (file_ofs, FULL_HEX);
   15494       printf ("\n        %s\n", filenames);
   15495 
   15496       filenames += 1 + strlen ((char *) filenames);
   15497     }
   15498 
   15499   return 1;
   15500 }
   15501 
   15502 static const char *
   15503 get_gnu_elf_note_type (unsigned e_type)
   15504 {
   15505   static char buff[64];
   15506 
   15507   switch (e_type)
   15508     {
   15509     case NT_GNU_ABI_TAG:
   15510       return _("NT_GNU_ABI_TAG (ABI version tag)");
   15511     case NT_GNU_HWCAP:
   15512       return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
   15513     case NT_GNU_BUILD_ID:
   15514       return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
   15515     case NT_GNU_GOLD_VERSION:
   15516       return _("NT_GNU_GOLD_VERSION (gold version)");
   15517     default:
   15518       break;
   15519     }
   15520 
   15521   snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   15522   return buff;
   15523 }
   15524 
   15525 static int
   15526 print_gnu_note (Elf_Internal_Note *pnote)
   15527 {
   15528   switch (pnote->type)
   15529     {
   15530     case NT_GNU_BUILD_ID:
   15531       {
   15532 	unsigned long i;
   15533 
   15534 	printf (_("    Build ID: "));
   15535 	for (i = 0; i < pnote->descsz; ++i)
   15536 	  printf ("%02x", pnote->descdata[i] & 0xff);
   15537 	printf ("\n");
   15538       }
   15539       break;
   15540 
   15541     case NT_GNU_ABI_TAG:
   15542       {
   15543 	unsigned long os, major, minor, subminor;
   15544 	const char *osname;
   15545 
   15546 	/* PR 17531: file: 030-599401-0.004.  */
   15547 	if (pnote->descsz < 16)
   15548 	  {
   15549 	    printf (_("    <corrupt GNU_ABI_TAG>\n"));
   15550 	    break;
   15551 	  }
   15552 
   15553 	os = byte_get ((unsigned char *) pnote->descdata, 4);
   15554 	major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
   15555 	minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
   15556 	subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
   15557 
   15558 	switch (os)
   15559 	  {
   15560 	  case GNU_ABI_TAG_LINUX:
   15561 	    osname = "Linux";
   15562 	    break;
   15563 	  case GNU_ABI_TAG_HURD:
   15564 	    osname = "Hurd";
   15565 	    break;
   15566 	  case GNU_ABI_TAG_SOLARIS:
   15567 	    osname = "Solaris";
   15568 	    break;
   15569 	  case GNU_ABI_TAG_FREEBSD:
   15570 	    osname = "FreeBSD";
   15571 	    break;
   15572 	  case GNU_ABI_TAG_NETBSD:
   15573 	    osname = "NetBSD";
   15574 	    break;
   15575 	  case GNU_ABI_TAG_SYLLABLE:
   15576 	    osname = "Syllable";
   15577 	    break;
   15578 	  case GNU_ABI_TAG_NACL:
   15579 	    osname = "NaCl";
   15580 	    break;
   15581 	  default:
   15582 	    osname = "Unknown";
   15583 	    break;
   15584 	  }
   15585 
   15586 	printf (_("    OS: %s, ABI: %ld.%ld.%ld\n"), osname,
   15587 		major, minor, subminor);
   15588       }
   15589       break;
   15590 
   15591     case NT_GNU_GOLD_VERSION:
   15592       {
   15593 	unsigned long i;
   15594 
   15595 	printf (_("    Version: "));
   15596 	for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
   15597 	  printf ("%c", pnote->descdata[i]);
   15598 	printf ("\n");
   15599       }
   15600       break;
   15601     }
   15602 
   15603   return 1;
   15604 }
   15605 
   15606 static const char *
   15607 get_v850_elf_note_type (enum v850_notes n_type)
   15608 {
   15609   static char buff[64];
   15610 
   15611   switch (n_type)
   15612     {
   15613     case V850_NOTE_ALIGNMENT:  return _("Alignment of 8-byte objects");
   15614     case V850_NOTE_DATA_SIZE:  return _("Sizeof double and long double");
   15615     case V850_NOTE_FPU_INFO:   return _("Type of FPU support needed");
   15616     case V850_NOTE_SIMD_INFO:  return _("Use of SIMD instructions");
   15617     case V850_NOTE_CACHE_INFO: return _("Use of cache");
   15618     case V850_NOTE_MMU_INFO:   return _("Use of MMU");
   15619     default:
   15620       snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type);
   15621       return buff;
   15622     }
   15623 }
   15624 
   15625 static int
   15626 print_v850_note (Elf_Internal_Note * pnote)
   15627 {
   15628   unsigned int val;
   15629 
   15630   if (pnote->descsz != 4)
   15631     return 0;
   15632   val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz);
   15633 
   15634   if (val == 0)
   15635     {
   15636       printf (_("not set\n"));
   15637       return 1;
   15638     }
   15639 
   15640   switch (pnote->type)
   15641     {
   15642     case V850_NOTE_ALIGNMENT:
   15643       switch (val)
   15644 	{
   15645 	case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return 1;
   15646 	case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return 1;
   15647 	}
   15648       break;
   15649 
   15650     case V850_NOTE_DATA_SIZE:
   15651       switch (val)
   15652 	{
   15653 	case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return 1;
   15654 	case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return 1;
   15655 	}
   15656       break;
   15657 
   15658     case V850_NOTE_FPU_INFO:
   15659       switch (val)
   15660 	{
   15661 	case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return 1;
   15662 	case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return 1;
   15663 	}
   15664       break;
   15665 
   15666     case V850_NOTE_MMU_INFO:
   15667     case V850_NOTE_CACHE_INFO:
   15668     case V850_NOTE_SIMD_INFO:
   15669       if (val == EF_RH850_SIMD)
   15670 	{
   15671 	  printf (_("yes\n"));
   15672 	  return 1;
   15673 	}
   15674       break;
   15675 
   15676     default:
   15677       /* An 'unknown note type' message will already have been displayed.  */
   15678       break;
   15679     }
   15680 
   15681   printf (_("unknown value: %x\n"), val);
   15682   return 0;
   15683 }
   15684 
   15685 static int
   15686 process_netbsd_elf_note (Elf_Internal_Note * pnote)
   15687 {
   15688   unsigned int version;
   15689 
   15690   switch (pnote->type)
   15691     {
   15692     case NT_NETBSD_IDENT:
   15693       version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
   15694       if ((version / 10000) % 100)
   15695         printf ("  NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
   15696 		version, version / 100000000, (version / 1000000) % 100,
   15697 		(version / 10000) % 100 > 26 ? "Z" : "",
   15698 		'A' + (version / 10000) % 26);
   15699       else
   15700 	printf ("  NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
   15701 	        version, version / 100000000, (version / 1000000) % 100,
   15702 		(version / 100) % 100);
   15703       return 1;
   15704 
   15705     case NT_NETBSD_MARCH:
   15706       printf ("  NetBSD\t0x%08lx\tMARCH <%s>\n", pnote->descsz,
   15707 	      pnote->descdata);
   15708       return 1;
   15709 
   15710     default:
   15711       break;
   15712     }
   15713 
   15714   printf ("  NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz,
   15715 	  pnote->type);
   15716   return 1;
   15717 }
   15718 
   15719 static const char *
   15720 get_freebsd_elfcore_note_type (unsigned e_type)
   15721 {
   15722   switch (e_type)
   15723     {
   15724     case NT_FREEBSD_THRMISC:
   15725       return _("NT_THRMISC (thrmisc structure)");
   15726     case NT_FREEBSD_PROCSTAT_PROC:
   15727       return _("NT_PROCSTAT_PROC (proc data)");
   15728     case NT_FREEBSD_PROCSTAT_FILES:
   15729       return _("NT_PROCSTAT_FILES (files data)");
   15730     case NT_FREEBSD_PROCSTAT_VMMAP:
   15731       return _("NT_PROCSTAT_VMMAP (vmmap data)");
   15732     case NT_FREEBSD_PROCSTAT_GROUPS:
   15733       return _("NT_PROCSTAT_GROUPS (groups data)");
   15734     case NT_FREEBSD_PROCSTAT_UMASK:
   15735       return _("NT_PROCSTAT_UMASK (umask data)");
   15736     case NT_FREEBSD_PROCSTAT_RLIMIT:
   15737       return _("NT_PROCSTAT_RLIMIT (rlimit data)");
   15738     case NT_FREEBSD_PROCSTAT_OSREL:
   15739       return _("NT_PROCSTAT_OSREL (osreldate data)");
   15740     case NT_FREEBSD_PROCSTAT_PSSTRINGS:
   15741       return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
   15742     case NT_FREEBSD_PROCSTAT_AUXV:
   15743       return _("NT_PROCSTAT_AUXV (auxv data)");
   15744     }
   15745   return get_note_type (e_type);
   15746 }
   15747 
   15748 static const char *
   15749 get_netbsd_elfcore_note_type (unsigned e_type)
   15750 {
   15751   static char buff[64];
   15752 
   15753   if (e_type == NT_NETBSDCORE_PROCINFO)
   15754     {
   15755       /* NetBSD core "procinfo" structure.  */
   15756       return _("NetBSD procinfo structure");
   15757     }
   15758 
   15759   /* As of Jan 2002 there are no other machine-independent notes
   15760      defined for NetBSD core files.  If the note type is less
   15761      than the start of the machine-dependent note types, we don't
   15762      understand it.  */
   15763 
   15764   if (e_type < NT_NETBSDCORE_FIRSTMACH)
   15765     {
   15766       snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   15767       return buff;
   15768     }
   15769 
   15770   switch (elf_header.e_machine)
   15771     {
   15772     /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
   15773        and PT_GETFPREGS == mach+2.  */
   15774 
   15775     case EM_OLD_ALPHA:
   15776     case EM_ALPHA:
   15777     case EM_SPARC:
   15778     case EM_SPARC32PLUS:
   15779     case EM_SPARCV9:
   15780       switch (e_type)
   15781 	{
   15782 	case NT_NETBSDCORE_FIRSTMACH + 0:
   15783 	  return _("PT_GETREGS (reg structure)");
   15784 	case NT_NETBSDCORE_FIRSTMACH + 2:
   15785 	  return _("PT_GETFPREGS (fpreg structure)");
   15786 	default:
   15787 	  break;
   15788 	}
   15789       break;
   15790 
   15791     /* On all other arch's, PT_GETREGS == mach+1 and
   15792        PT_GETFPREGS == mach+3.  */
   15793     default:
   15794       switch (e_type)
   15795 	{
   15796 	case NT_NETBSDCORE_FIRSTMACH + 1:
   15797 	  return _("PT_GETREGS (reg structure)");
   15798 	case NT_NETBSDCORE_FIRSTMACH + 3:
   15799 	  return _("PT_GETFPREGS (fpreg structure)");
   15800 	default:
   15801 	  break;
   15802 	}
   15803     }
   15804 
   15805   snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
   15806 	    e_type - NT_NETBSDCORE_FIRSTMACH);
   15807   return buff;
   15808 }
   15809 
   15810 static const char *
   15811 get_stapsdt_note_type (unsigned e_type)
   15812 {
   15813   static char buff[64];
   15814 
   15815   switch (e_type)
   15816     {
   15817     case NT_STAPSDT:
   15818       return _("NT_STAPSDT (SystemTap probe descriptors)");
   15819 
   15820     default:
   15821       break;
   15822     }
   15823 
   15824   snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   15825   return buff;
   15826 }
   15827 
   15828 static int
   15829 print_stapsdt_note (Elf_Internal_Note *pnote)
   15830 {
   15831   int addr_size = is_32bit_elf ? 4 : 8;
   15832   char *data = pnote->descdata;
   15833   char *data_end = pnote->descdata + pnote->descsz;
   15834   bfd_vma pc, base_addr, semaphore;
   15835   char *provider, *probe, *arg_fmt;
   15836 
   15837   pc = byte_get ((unsigned char *) data, addr_size);
   15838   data += addr_size;
   15839   base_addr = byte_get ((unsigned char *) data, addr_size);
   15840   data += addr_size;
   15841   semaphore = byte_get ((unsigned char *) data, addr_size);
   15842   data += addr_size;
   15843 
   15844   provider = data;
   15845   data += strlen (data) + 1;
   15846   probe = data;
   15847   data += strlen (data) + 1;
   15848   arg_fmt = data;
   15849   data += strlen (data) + 1;
   15850 
   15851   printf (_("    Provider: %s\n"), provider);
   15852   printf (_("    Name: %s\n"), probe);
   15853   printf (_("    Location: "));
   15854   print_vma (pc, FULL_HEX);
   15855   printf (_(", Base: "));
   15856   print_vma (base_addr, FULL_HEX);
   15857   printf (_(", Semaphore: "));
   15858   print_vma (semaphore, FULL_HEX);
   15859   printf ("\n");
   15860   printf (_("    Arguments: %s\n"), arg_fmt);
   15861 
   15862   return data == data_end;
   15863 }
   15864 
   15865 static const char *
   15866 get_ia64_vms_note_type (unsigned e_type)
   15867 {
   15868   static char buff[64];
   15869 
   15870   switch (e_type)
   15871     {
   15872     case NT_VMS_MHD:
   15873       return _("NT_VMS_MHD (module header)");
   15874     case NT_VMS_LNM:
   15875       return _("NT_VMS_LNM (language name)");
   15876     case NT_VMS_SRC:
   15877       return _("NT_VMS_SRC (source files)");
   15878     case NT_VMS_TITLE:
   15879       return "NT_VMS_TITLE";
   15880     case NT_VMS_EIDC:
   15881       return _("NT_VMS_EIDC (consistency check)");
   15882     case NT_VMS_FPMODE:
   15883       return _("NT_VMS_FPMODE (FP mode)");
   15884     case NT_VMS_LINKTIME:
   15885       return "NT_VMS_LINKTIME";
   15886     case NT_VMS_IMGNAM:
   15887       return _("NT_VMS_IMGNAM (image name)");
   15888     case NT_VMS_IMGID:
   15889       return _("NT_VMS_IMGID (image id)");
   15890     case NT_VMS_LINKID:
   15891       return _("NT_VMS_LINKID (link id)");
   15892     case NT_VMS_IMGBID:
   15893       return _("NT_VMS_IMGBID (build id)");
   15894     case NT_VMS_GSTNAM:
   15895       return _("NT_VMS_GSTNAM (sym table name)");
   15896     case NT_VMS_ORIG_DYN:
   15897       return "NT_VMS_ORIG_DYN";
   15898     case NT_VMS_PATCHTIME:
   15899       return "NT_VMS_PATCHTIME";
   15900     default:
   15901       snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   15902       return buff;
   15903     }
   15904 }
   15905 
   15906 static int
   15907 print_ia64_vms_note (Elf_Internal_Note * pnote)
   15908 {
   15909   switch (pnote->type)
   15910     {
   15911     case NT_VMS_MHD:
   15912       if (pnote->descsz > 36)
   15913         {
   15914           size_t l = strlen (pnote->descdata + 34);
   15915           printf (_("    Creation date  : %.17s\n"), pnote->descdata);
   15916           printf (_("    Last patch date: %.17s\n"), pnote->descdata + 17);
   15917           printf (_("    Module name    : %s\n"), pnote->descdata + 34);
   15918           printf (_("    Module version : %s\n"), pnote->descdata + 34 + l + 1);
   15919         }
   15920       else
   15921         printf (_("    Invalid size\n"));
   15922       break;
   15923     case NT_VMS_LNM:
   15924       printf (_("   Language: %s\n"), pnote->descdata);
   15925       break;
   15926 #ifdef BFD64
   15927     case NT_VMS_FPMODE:
   15928       printf (_("   Floating Point mode: "));
   15929       printf ("0x%016" BFD_VMA_FMT "x\n",
   15930               (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
   15931       break;
   15932     case NT_VMS_LINKTIME:
   15933       printf (_("   Link time: "));
   15934       print_vms_time
   15935         ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
   15936       printf ("\n");
   15937       break;
   15938     case NT_VMS_PATCHTIME:
   15939       printf (_("   Patch time: "));
   15940       print_vms_time
   15941         ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
   15942       printf ("\n");
   15943       break;
   15944     case NT_VMS_ORIG_DYN:
   15945       printf (_("   Major id: %u,  minor id: %u\n"),
   15946               (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
   15947               (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
   15948       printf (_("   Last modified  : "));
   15949       print_vms_time
   15950         ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
   15951       printf (_("\n   Link flags  : "));
   15952       printf ("0x%016" BFD_VMA_FMT "x\n",
   15953               (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
   15954       printf (_("   Header flags: 0x%08x\n"),
   15955               (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
   15956       printf (_("   Image id    : %s\n"), pnote->descdata + 32);
   15957       break;
   15958 #endif
   15959     case NT_VMS_IMGNAM:
   15960       printf (_("    Image name: %s\n"), pnote->descdata);
   15961       break;
   15962     case NT_VMS_GSTNAM:
   15963       printf (_("    Global symbol table name: %s\n"), pnote->descdata);
   15964       break;
   15965     case NT_VMS_IMGID:
   15966       printf (_("    Image id: %s\n"), pnote->descdata);
   15967       break;
   15968     case NT_VMS_LINKID:
   15969       printf (_("    Linker id: %s\n"), pnote->descdata);
   15970       break;
   15971     default:
   15972       break;
   15973     }
   15974   return 1;
   15975 }
   15976 
   15977 /* Note that by the ELF standard, the name field is already null byte
   15978    terminated, and namesz includes the terminating null byte.
   15979    I.E. the value of namesz for the name "FSF" is 4.
   15980 
   15981    If the value of namesz is zero, there is no name present.  */
   15982 static int
   15983 process_note (Elf_Internal_Note * pnote)
   15984 {
   15985   const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
   15986   const char * nt;
   15987 
   15988   if (pnote->namesz == 0)
   15989     /* If there is no note name, then use the default set of
   15990        note type strings.  */
   15991     nt = get_note_type (pnote->type);
   15992 
   15993   else if (const_strneq (pnote->namedata, "GNU"))
   15994     /* GNU-specific object file notes.  */
   15995     nt = get_gnu_elf_note_type (pnote->type);
   15996 
   15997   else if (const_strneq (pnote->namedata, "FreeBSD"))
   15998     /* FreeBSD-specific core file notes.  */
   15999     nt = get_freebsd_elfcore_note_type (pnote->type);
   16000 
   16001   else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
   16002     /* NetBSD-specific core file notes.  */
   16003     nt = get_netbsd_elfcore_note_type (pnote->type);
   16004 
   16005   else if (const_strneq (pnote->namedata, "NetBSD"))
   16006     /* NetBSD-specific core file notes.  */
   16007     return process_netbsd_elf_note (pnote);
   16008 
   16009   else if (strneq (pnote->namedata, "SPU/", 4))
   16010     {
   16011       /* SPU-specific core file notes.  */
   16012       nt = pnote->namedata + 4;
   16013       name = "SPU";
   16014     }
   16015 
   16016   else if (const_strneq (pnote->namedata, "IPF/VMS"))
   16017     /* VMS/ia64-specific file notes.  */
   16018     nt = get_ia64_vms_note_type (pnote->type);
   16019 
   16020   else if (const_strneq (pnote->namedata, "stapsdt"))
   16021     nt = get_stapsdt_note_type (pnote->type);
   16022 
   16023   else
   16024     /* Don't recognize this note name; just use the default set of
   16025        note type strings.  */
   16026     nt = get_note_type (pnote->type);
   16027 
   16028   printf ("  %-20s 0x%08lx\t%s\n", name, pnote->descsz, nt);
   16029 
   16030   if (const_strneq (pnote->namedata, "IPF/VMS"))
   16031     return print_ia64_vms_note (pnote);
   16032   else if (const_strneq (pnote->namedata, "GNU"))
   16033     return print_gnu_note (pnote);
   16034   else if (const_strneq (pnote->namedata, "stapsdt"))
   16035     return print_stapsdt_note (pnote);
   16036   else if (const_strneq (pnote->namedata, "CORE"))
   16037     return print_core_note (pnote);
   16038   else
   16039     return 1;
   16040 }
   16041 
   16042 
   16043 static int
   16044 process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length)
   16045 {
   16046   Elf_External_Note * pnotes;
   16047   Elf_External_Note * external;
   16048   char * end;
   16049   int res = 1;
   16050 
   16051   if (length <= 0)
   16052     return 0;
   16053 
   16054   pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length,
   16055 					   _("notes"));
   16056   if (pnotes == NULL)
   16057     return 0;
   16058 
   16059   external = pnotes;
   16060 
   16061   printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
   16062 	  (unsigned long) offset, (unsigned long) length);
   16063   printf (_("  %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
   16064 
   16065   end = (char *) pnotes + length;
   16066   while ((char *) external < end)
   16067     {
   16068       Elf_Internal_Note inote;
   16069       size_t min_notesz;
   16070       char *next;
   16071       char * temp = NULL;
   16072       size_t data_remaining = end - (char *) external;
   16073 
   16074       if (!is_ia64_vms ())
   16075 	{
   16076 	  /* PR binutils/15191
   16077 	     Make sure that there is enough data to read.  */
   16078 	  min_notesz = offsetof (Elf_External_Note, name);
   16079 	  if (data_remaining < min_notesz)
   16080 	    {
   16081 	      warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
   16082 		    (int) data_remaining);
   16083 	      break;
   16084 	    }
   16085 	  inote.type     = BYTE_GET (external->type);
   16086 	  inote.namesz   = BYTE_GET (external->namesz);
   16087 	  inote.namedata = external->name;
   16088 	  inote.descsz   = BYTE_GET (external->descsz);
   16089 	  inote.descdata = inote.namedata + align_power (inote.namesz, 2);
   16090 	  /* PR 17531: file: 3443835e.  */
   16091 	  if (inote.descdata < (char *) pnotes || inote.descdata > end)
   16092 	    {
   16093 	      warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
   16094 	      inote.descdata = inote.namedata;
   16095 	      inote.namesz   = 0;
   16096 	    }
   16097 
   16098 	  inote.descpos  = offset + (inote.descdata - (char *) pnotes);
   16099 	  next = inote.descdata + align_power (inote.descsz, 2);
   16100 	}
   16101       else
   16102 	{
   16103 	  Elf64_External_VMS_Note *vms_external;
   16104 
   16105 	  /* PR binutils/15191
   16106 	     Make sure that there is enough data to read.  */
   16107 	  min_notesz = offsetof (Elf64_External_VMS_Note, name);
   16108 	  if (data_remaining < min_notesz)
   16109 	    {
   16110 	      warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
   16111 		    (int) data_remaining);
   16112 	      break;
   16113 	    }
   16114 
   16115 	  vms_external = (Elf64_External_VMS_Note *) external;
   16116 	  inote.type     = BYTE_GET (vms_external->type);
   16117 	  inote.namesz   = BYTE_GET (vms_external->namesz);
   16118 	  inote.namedata = vms_external->name;
   16119 	  inote.descsz   = BYTE_GET (vms_external->descsz);
   16120 	  inote.descdata = inote.namedata + align_power (inote.namesz, 3);
   16121 	  inote.descpos  = offset + (inote.descdata - (char *) pnotes);
   16122 	  next = inote.descdata + align_power (inote.descsz, 3);
   16123 	}
   16124 
   16125       if (inote.descdata < (char *) external + min_notesz
   16126 	  || next < (char *) external + min_notesz
   16127 	  /* PR binutils/17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4.  */
   16128 	  || inote.namedata + inote.namesz < inote.namedata
   16129 	  || inote.descdata + inote.descsz < inote.descdata
   16130 	  || data_remaining < (size_t)(next - (char *) external))
   16131 	{
   16132 	  warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
   16133 		(unsigned long) ((char *) external - (char *) pnotes));
   16134 	  warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx\n"),
   16135 		inote.type, inote.namesz, inote.descsz);
   16136 	  break;
   16137 	}
   16138 
   16139       external = (Elf_External_Note *) next;
   16140 
   16141       /* Verify that name is null terminated.  It appears that at least
   16142 	 one version of Linux (RedHat 6.0) generates corefiles that don't
   16143 	 comply with the ELF spec by failing to include the null byte in
   16144 	 namesz.  */
   16145       if (inote.namedata[inote.namesz - 1] != '\0')
   16146 	{
   16147 	  temp = (char *) malloc (inote.namesz + 1);
   16148 	  if (temp == NULL)
   16149 	    {
   16150 	      error (_("Out of memory allocating space for inote name\n"));
   16151 	      res = 0;
   16152 	      break;
   16153 	    }
   16154 
   16155 	  strncpy (temp, inote.namedata, inote.namesz);
   16156 	  temp[inote.namesz] = 0;
   16157 
   16158 	  /* warn (_("'%s' NOTE name not properly null terminated\n"), temp);  */
   16159 	  inote.namedata = temp;
   16160 	}
   16161 
   16162       res &= process_note (& inote);
   16163 
   16164       if (temp != NULL)
   16165 	{
   16166 	  free (temp);
   16167 	  temp = NULL;
   16168 	}
   16169     }
   16170 
   16171   free (pnotes);
   16172 
   16173   return res;
   16174 }
   16175 
   16176 static int
   16177 process_corefile_note_segments (FILE * file)
   16178 {
   16179   Elf_Internal_Phdr * segment;
   16180   unsigned int i;
   16181   int res = 1;
   16182 
   16183   if (! get_program_headers (file))
   16184       return 0;
   16185 
   16186   for (i = 0, segment = program_headers;
   16187        i < elf_header.e_phnum;
   16188        i++, segment++)
   16189     {
   16190       if (segment->p_type == PT_NOTE)
   16191 	res &= process_corefile_note_segment (file,
   16192 					      (bfd_vma) segment->p_offset,
   16193 					      (bfd_vma) segment->p_filesz);
   16194     }
   16195 
   16196   return res;
   16197 }
   16198 
   16199 static int
   16200 process_v850_notes (FILE * file, bfd_vma offset, bfd_vma length)
   16201 {
   16202   Elf_External_Note * pnotes;
   16203   Elf_External_Note * external;
   16204   char * end;
   16205   int res = 1;
   16206 
   16207   if (length <= 0)
   16208     return 0;
   16209 
   16210   pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length,
   16211                                            _("v850 notes"));
   16212   if (pnotes == NULL)
   16213     return 0;
   16214 
   16215   external = pnotes;
   16216   end = (char*) pnotes + length;
   16217 
   16218   printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
   16219 	  (unsigned long) offset, (unsigned long) length);
   16220 
   16221   while ((char *) external + sizeof (Elf_External_Note) < end)
   16222     {
   16223       Elf_External_Note * next;
   16224       Elf_Internal_Note inote;
   16225 
   16226       inote.type     = BYTE_GET (external->type);
   16227       inote.namesz   = BYTE_GET (external->namesz);
   16228       inote.namedata = external->name;
   16229       inote.descsz   = BYTE_GET (external->descsz);
   16230       inote.descdata = inote.namedata + align_power (inote.namesz, 2);
   16231       inote.descpos  = offset + (inote.descdata - (char *) pnotes);
   16232 
   16233       if (inote.descdata < (char *) pnotes || inote.descdata >= end)
   16234 	{
   16235 	  warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
   16236 	  inote.descdata = inote.namedata;
   16237 	  inote.namesz   = 0;
   16238 	}
   16239 
   16240       next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
   16241 
   16242       if (   ((char *) next > end)
   16243 	  || ((char *) next <  (char *) pnotes))
   16244 	{
   16245 	  warn (_("corrupt descsz found in note at offset 0x%lx\n"),
   16246 		(unsigned long) ((char *) external - (char *) pnotes));
   16247 	  warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
   16248 		inote.type, inote.namesz, inote.descsz);
   16249 	  break;
   16250 	}
   16251 
   16252       external = next;
   16253 
   16254       /* Prevent out-of-bounds indexing.  */
   16255       if (   inote.namedata + inote.namesz > end
   16256 	  || inote.namedata + inote.namesz < inote.namedata)
   16257         {
   16258           warn (_("corrupt namesz found in note at offset 0x%lx\n"),
   16259                 (unsigned long) ((char *) external - (char *) pnotes));
   16260           warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
   16261                 inote.type, inote.namesz, inote.descsz);
   16262           break;
   16263         }
   16264 
   16265       printf ("  %s: ", get_v850_elf_note_type (inote.type));
   16266 
   16267       if (! print_v850_note (& inote))
   16268 	{
   16269 	  res = 0;
   16270 	  printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
   16271 		  inote.namesz, inote.descsz);
   16272 	}
   16273     }
   16274 
   16275   free (pnotes);
   16276 
   16277   return res;
   16278 }
   16279 
   16280 static int
   16281 process_note_sections (FILE * file)
   16282 {
   16283   Elf_Internal_Shdr * section;
   16284   unsigned long i;
   16285   int n = 0;
   16286   int res = 1;
   16287 
   16288   for (i = 0, section = section_headers;
   16289        i < elf_header.e_shnum && section != NULL;
   16290        i++, section++)
   16291     {
   16292       if (section->sh_type == SHT_NOTE)
   16293 	{
   16294 	  res &= process_corefile_note_segment (file,
   16295 						(bfd_vma) section->sh_offset,
   16296 						(bfd_vma) section->sh_size);
   16297 	  n++;
   16298 	}
   16299 
   16300       if ((   elf_header.e_machine == EM_V800
   16301 	   || elf_header.e_machine == EM_V850
   16302 	   || elf_header.e_machine == EM_CYGNUS_V850)
   16303 	  && section->sh_type == SHT_RENESAS_INFO)
   16304 	{
   16305 	  res &= process_v850_notes (file,
   16306 				     (bfd_vma) section->sh_offset,
   16307 				     (bfd_vma) section->sh_size);
   16308 	  n++;
   16309 	}
   16310     }
   16311 
   16312   if (n == 0)
   16313     /* Try processing NOTE segments instead.  */
   16314     return process_corefile_note_segments (file);
   16315 
   16316   return res;
   16317 }
   16318 
   16319 static int
   16320 process_notes (FILE * file)
   16321 {
   16322   /* If we have not been asked to display the notes then do nothing.  */
   16323   if (! do_notes)
   16324     return 1;
   16325 
   16326   if (elf_header.e_type != ET_CORE)
   16327     return process_note_sections (file);
   16328 
   16329   /* No program headers means no NOTE segment.  */
   16330   if (elf_header.e_phnum > 0)
   16331     return process_corefile_note_segments (file);
   16332 
   16333   printf (_("No note segments present in the core file.\n"));
   16334   return 1;
   16335 }
   16336 
   16337 static int
   16338 process_arch_specific (FILE * file)
   16339 {
   16340   if (! do_arch)
   16341     return 1;
   16342 
   16343   switch (elf_header.e_machine)
   16344     {
   16345     case EM_ARM:
   16346       return process_arm_specific (file);
   16347     case EM_MIPS:
   16348     case EM_MIPS_RS3_LE:
   16349       return process_mips_specific (file);
   16350       break;
   16351     case EM_NDS32:
   16352       return process_nds32_specific (file);
   16353       break;
   16354     case EM_PPC:
   16355       return process_power_specific (file);
   16356       break;
   16357     case EM_S390:
   16358     case EM_S390_OLD:
   16359       return process_s390_specific (file);
   16360       break;
   16361     case EM_SPARC:
   16362     case EM_SPARC32PLUS:
   16363     case EM_SPARCV9:
   16364       return process_sparc_specific (file);
   16365       break;
   16366     case EM_TI_C6000:
   16367       return process_tic6x_specific (file);
   16368       break;
   16369     case EM_MSP430:
   16370       return process_msp430x_specific (file);
   16371     default:
   16372       break;
   16373     }
   16374   return 1;
   16375 }
   16376 
   16377 static int
   16378 get_file_header (FILE * file)
   16379 {
   16380   /* Read in the identity array.  */
   16381   if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
   16382     return 0;
   16383 
   16384   /* Determine how to read the rest of the header.  */
   16385   switch (elf_header.e_ident[EI_DATA])
   16386     {
   16387     default: /* fall through */
   16388     case ELFDATANONE: /* fall through */
   16389     case ELFDATA2LSB:
   16390       byte_get = byte_get_little_endian;
   16391       byte_put = byte_put_little_endian;
   16392       break;
   16393     case ELFDATA2MSB:
   16394       byte_get = byte_get_big_endian;
   16395       byte_put = byte_put_big_endian;
   16396       break;
   16397     }
   16398 
   16399   /* For now we only support 32 bit and 64 bit ELF files.  */
   16400   is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
   16401 
   16402   /* Read in the rest of the header.  */
   16403   if (is_32bit_elf)
   16404     {
   16405       Elf32_External_Ehdr ehdr32;
   16406 
   16407       if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
   16408 	return 0;
   16409 
   16410       elf_header.e_type      = BYTE_GET (ehdr32.e_type);
   16411       elf_header.e_machine   = BYTE_GET (ehdr32.e_machine);
   16412       elf_header.e_version   = BYTE_GET (ehdr32.e_version);
   16413       elf_header.e_entry     = BYTE_GET (ehdr32.e_entry);
   16414       elf_header.e_phoff     = BYTE_GET (ehdr32.e_phoff);
   16415       elf_header.e_shoff     = BYTE_GET (ehdr32.e_shoff);
   16416       elf_header.e_flags     = BYTE_GET (ehdr32.e_flags);
   16417       elf_header.e_ehsize    = BYTE_GET (ehdr32.e_ehsize);
   16418       elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
   16419       elf_header.e_phnum     = BYTE_GET (ehdr32.e_phnum);
   16420       elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
   16421       elf_header.e_shnum     = BYTE_GET (ehdr32.e_shnum);
   16422       elf_header.e_shstrndx  = BYTE_GET (ehdr32.e_shstrndx);
   16423     }
   16424   else
   16425     {
   16426       Elf64_External_Ehdr ehdr64;
   16427 
   16428       /* If we have been compiled with sizeof (bfd_vma) == 4, then
   16429 	 we will not be able to cope with the 64bit data found in
   16430 	 64 ELF files.  Detect this now and abort before we start
   16431 	 overwriting things.  */
   16432       if (sizeof (bfd_vma) < 8)
   16433 	{
   16434 	  error (_("This instance of readelf has been built without support for a\n\
   16435 64 bit data type and so it cannot read 64 bit ELF files.\n"));
   16436 	  return 0;
   16437 	}
   16438 
   16439       if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
   16440 	return 0;
   16441 
   16442       elf_header.e_type      = BYTE_GET (ehdr64.e_type);
   16443       elf_header.e_machine   = BYTE_GET (ehdr64.e_machine);
   16444       elf_header.e_version   = BYTE_GET (ehdr64.e_version);
   16445       elf_header.e_entry     = BYTE_GET (ehdr64.e_entry);
   16446       elf_header.e_phoff     = BYTE_GET (ehdr64.e_phoff);
   16447       elf_header.e_shoff     = BYTE_GET (ehdr64.e_shoff);
   16448       elf_header.e_flags     = BYTE_GET (ehdr64.e_flags);
   16449       elf_header.e_ehsize    = BYTE_GET (ehdr64.e_ehsize);
   16450       elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
   16451       elf_header.e_phnum     = BYTE_GET (ehdr64.e_phnum);
   16452       elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
   16453       elf_header.e_shnum     = BYTE_GET (ehdr64.e_shnum);
   16454       elf_header.e_shstrndx  = BYTE_GET (ehdr64.e_shstrndx);
   16455     }
   16456 
   16457   if (elf_header.e_shoff)
   16458     {
   16459       /* There may be some extensions in the first section header.  Don't
   16460 	 bomb if we can't read it.  */
   16461       if (is_32bit_elf)
   16462 	get_32bit_section_headers (file, TRUE);
   16463       else
   16464 	get_64bit_section_headers (file, TRUE);
   16465     }
   16466 
   16467   return 1;
   16468 }
   16469 
   16470 /* Process one ELF object file according to the command line options.
   16471    This file may actually be stored in an archive.  The file is
   16472    positioned at the start of the ELF object.  */
   16473 
   16474 static int
   16475 process_object (char * file_name, FILE * file)
   16476 {
   16477   unsigned int i;
   16478 
   16479   if (! get_file_header (file))
   16480     {
   16481       error (_("%s: Failed to read file header\n"), file_name);
   16482       return 1;
   16483     }
   16484 
   16485   /* Initialise per file variables.  */
   16486   for (i = ARRAY_SIZE (version_info); i--;)
   16487     version_info[i] = 0;
   16488 
   16489   for (i = ARRAY_SIZE (dynamic_info); i--;)
   16490     dynamic_info[i] = 0;
   16491   dynamic_info_DT_GNU_HASH = 0;
   16492 
   16493   /* Process the file.  */
   16494   if (show_name)
   16495     printf (_("\nFile: %s\n"), file_name);
   16496 
   16497   /* Initialise the dump_sects array from the cmdline_dump_sects array.
   16498      Note we do this even if cmdline_dump_sects is empty because we
   16499      must make sure that the dump_sets array is zeroed out before each
   16500      object file is processed.  */
   16501   if (num_dump_sects > num_cmdline_dump_sects)
   16502     memset (dump_sects, 0, num_dump_sects * sizeof (* dump_sects));
   16503 
   16504   if (num_cmdline_dump_sects > 0)
   16505     {
   16506       if (num_dump_sects == 0)
   16507 	/* A sneaky way of allocating the dump_sects array.  */
   16508 	request_dump_bynumber (num_cmdline_dump_sects, 0);
   16509 
   16510       assert (num_dump_sects >= num_cmdline_dump_sects);
   16511       memcpy (dump_sects, cmdline_dump_sects,
   16512 	      num_cmdline_dump_sects * sizeof (* dump_sects));
   16513     }
   16514 
   16515   if (! process_file_header ())
   16516     return 1;
   16517 
   16518   if (! process_section_headers (file))
   16519     {
   16520       /* Without loaded section headers we cannot process lots of
   16521 	 things.  */
   16522       do_unwind = do_version = do_dump = do_arch = 0;
   16523 
   16524       if (! do_using_dynamic)
   16525 	do_syms = do_dyn_syms = do_reloc = 0;
   16526     }
   16527 
   16528   if (! process_section_groups (file))
   16529     {
   16530       /* Without loaded section groups we cannot process unwind.  */
   16531       do_unwind = 0;
   16532     }
   16533 
   16534   if (process_program_headers (file))
   16535     process_dynamic_section (file);
   16536 
   16537   process_relocs (file);
   16538 
   16539   process_unwind (file);
   16540 
   16541   process_symbol_table (file);
   16542 
   16543   process_syminfo (file);
   16544 
   16545   process_version_sections (file);
   16546 
   16547   process_section_contents (file);
   16548 
   16549   process_notes (file);
   16550 
   16551   process_gnu_liblist (file);
   16552 
   16553   process_arch_specific (file);
   16554 
   16555   if (program_headers)
   16556     {
   16557       free (program_headers);
   16558       program_headers = NULL;
   16559     }
   16560 
   16561   if (section_headers)
   16562     {
   16563       free (section_headers);
   16564       section_headers = NULL;
   16565     }
   16566 
   16567   if (string_table)
   16568     {
   16569       free (string_table);
   16570       string_table = NULL;
   16571       string_table_length = 0;
   16572     }
   16573 
   16574   if (dynamic_strings)
   16575     {
   16576       free (dynamic_strings);
   16577       dynamic_strings = NULL;
   16578       dynamic_strings_length = 0;
   16579     }
   16580 
   16581   if (dynamic_symbols)
   16582     {
   16583       free (dynamic_symbols);
   16584       dynamic_symbols = NULL;
   16585       num_dynamic_syms = 0;
   16586     }
   16587 
   16588   if (dynamic_syminfo)
   16589     {
   16590       free (dynamic_syminfo);
   16591       dynamic_syminfo = NULL;
   16592     }
   16593 
   16594   if (dynamic_section)
   16595     {
   16596       free (dynamic_section);
   16597       dynamic_section = NULL;
   16598     }
   16599 
   16600   if (section_headers_groups)
   16601     {
   16602       free (section_headers_groups);
   16603       section_headers_groups = NULL;
   16604     }
   16605 
   16606   if (section_groups)
   16607     {
   16608       struct group_list * g;
   16609       struct group_list * next;
   16610 
   16611       for (i = 0; i < group_count; i++)
   16612 	{
   16613 	  for (g = section_groups [i].root; g != NULL; g = next)
   16614 	    {
   16615 	      next = g->next;
   16616 	      free (g);
   16617 	    }
   16618 	}
   16619 
   16620       free (section_groups);
   16621       section_groups = NULL;
   16622     }
   16623 
   16624   free_debug_memory ();
   16625 
   16626   return 0;
   16627 }
   16628 
   16629 /* Process an ELF archive.
   16630    On entry the file is positioned just after the ARMAG string.  */
   16631 
   16632 static int
   16633 process_archive (char * file_name, FILE * file, bfd_boolean is_thin_archive)
   16634 {
   16635   struct archive_info arch;
   16636   struct archive_info nested_arch;
   16637   size_t got;
   16638   int ret;
   16639 
   16640   show_name = 1;
   16641 
   16642   /* The ARCH structure is used to hold information about this archive.  */
   16643   arch.file_name = NULL;
   16644   arch.file = NULL;
   16645   arch.index_array = NULL;
   16646   arch.sym_table = NULL;
   16647   arch.longnames = NULL;
   16648 
   16649   /* The NESTED_ARCH structure is used as a single-item cache of information
   16650      about a nested archive (when members of a thin archive reside within
   16651      another regular archive file).  */
   16652   nested_arch.file_name = NULL;
   16653   nested_arch.file = NULL;
   16654   nested_arch.index_array = NULL;
   16655   nested_arch.sym_table = NULL;
   16656   nested_arch.longnames = NULL;
   16657 
   16658   if (setup_archive (&arch, file_name, file, is_thin_archive, do_archive_index) != 0)
   16659     {
   16660       ret = 1;
   16661       goto out;
   16662     }
   16663 
   16664   if (do_archive_index)
   16665     {
   16666       if (arch.sym_table == NULL)
   16667 	error (_("%s: unable to dump the index as none was found\n"), file_name);
   16668       else
   16669 	{
   16670 	  unsigned long i, l;
   16671 	  unsigned long current_pos;
   16672 
   16673 	  printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"),
   16674 		  file_name, (unsigned long) arch.index_num, arch.sym_size);
   16675 	  current_pos = ftell (file);
   16676 
   16677 	  for (i = l = 0; i < arch.index_num; i++)
   16678 	    {
   16679 	      if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
   16680 	        {
   16681 	          char * member_name;
   16682 
   16683 		  member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
   16684 
   16685                   if (member_name != NULL)
   16686                     {
   16687 	              char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
   16688 
   16689                       if (qualified_name != NULL)
   16690                         {
   16691 		          printf (_("Contents of binary %s at offset "), qualified_name);
   16692 			  (void) print_vma (arch.index_array[i], PREFIX_HEX);
   16693 			  putchar ('\n');
   16694 		          free (qualified_name);
   16695 		        }
   16696 		    }
   16697 		}
   16698 
   16699 	      if (l >= arch.sym_size)
   16700 		{
   16701 		  error (_("%s: end of the symbol table reached before the end of the index\n"),
   16702 			 file_name);
   16703 		  break;
   16704 		}
   16705 	      /* PR 17531: file: 0b6630b2.  */
   16706 	      printf ("\t%.*s\n", (int) (arch.sym_size - l), arch.sym_table + l);
   16707 	      l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
   16708 	    }
   16709 
   16710 	  if (arch.uses_64bit_indicies)
   16711 	    l = (l + 7) & ~ 7;
   16712 	  else
   16713 	    l += l & 1;
   16714 
   16715 	  if (l < arch.sym_size)
   16716 	    error (_("%s: %ld bytes remain in the symbol table, but without corresponding entries in the index table\n"),
   16717 		   file_name, arch.sym_size - l);
   16718 
   16719 	  if (fseek (file, current_pos, SEEK_SET) != 0)
   16720 	    {
   16721 	      error (_("%s: failed to seek back to start of object files in the archive\n"), file_name);
   16722 	      ret = 1;
   16723 	      goto out;
   16724 	    }
   16725 	}
   16726 
   16727       if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
   16728 	  && !do_segments && !do_header && !do_dump && !do_version
   16729 	  && !do_histogram && !do_debugging && !do_arch && !do_notes
   16730 	  && !do_section_groups && !do_dyn_syms)
   16731 	{
   16732 	  ret = 0; /* Archive index only.  */
   16733 	  goto out;
   16734 	}
   16735     }
   16736 
   16737   ret = 0;
   16738 
   16739   while (1)
   16740     {
   16741       char * name;
   16742       size_t namelen;
   16743       char * qualified_name;
   16744 
   16745       /* Read the next archive header.  */
   16746       if (fseek (file, arch.next_arhdr_offset, SEEK_SET) != 0)
   16747         {
   16748           error (_("%s: failed to seek to next archive header\n"), file_name);
   16749           return 1;
   16750         }
   16751       got = fread (&arch.arhdr, 1, sizeof arch.arhdr, file);
   16752       if (got != sizeof arch.arhdr)
   16753         {
   16754           if (got == 0)
   16755 	    break;
   16756           error (_("%s: failed to read archive header\n"), file_name);
   16757           ret = 1;
   16758           break;
   16759         }
   16760       if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
   16761         {
   16762           error (_("%s: did not find a valid archive header\n"), arch.file_name);
   16763           ret = 1;
   16764           break;
   16765         }
   16766 
   16767       arch.next_arhdr_offset += sizeof arch.arhdr;
   16768 
   16769       archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
   16770       if (archive_file_size & 01)
   16771         ++archive_file_size;
   16772 
   16773       name = get_archive_member_name (&arch, &nested_arch);
   16774       if (name == NULL)
   16775 	{
   16776 	  error (_("%s: bad archive file name\n"), file_name);
   16777 	  ret = 1;
   16778 	  break;
   16779 	}
   16780       namelen = strlen (name);
   16781 
   16782       qualified_name = make_qualified_name (&arch, &nested_arch, name);
   16783       if (qualified_name == NULL)
   16784 	{
   16785 	  error (_("%s: bad archive file name\n"), file_name);
   16786 	  ret = 1;
   16787 	  break;
   16788 	}
   16789 
   16790       if (is_thin_archive && arch.nested_member_origin == 0)
   16791         {
   16792           /* This is a proxy for an external member of a thin archive.  */
   16793           FILE * member_file;
   16794           char * member_file_name = adjust_relative_path (file_name, name, namelen);
   16795           if (member_file_name == NULL)
   16796             {
   16797               ret = 1;
   16798               break;
   16799             }
   16800 
   16801           member_file = fopen (member_file_name, "rb");
   16802           if (member_file == NULL)
   16803             {
   16804               error (_("Input file '%s' is not readable.\n"), member_file_name);
   16805               free (member_file_name);
   16806               ret = 1;
   16807               break;
   16808             }
   16809 
   16810           archive_file_offset = arch.nested_member_origin;
   16811 
   16812           ret |= process_object (qualified_name, member_file);
   16813 
   16814           fclose (member_file);
   16815           free (member_file_name);
   16816         }
   16817       else if (is_thin_archive)
   16818         {
   16819 	  /* PR 15140: Allow for corrupt thin archives.  */
   16820 	  if (nested_arch.file == NULL)
   16821 	    {
   16822 	      error (_("%s: contains corrupt thin archive: %s\n"),
   16823 		     file_name, name);
   16824 	      ret = 1;
   16825 	      break;
   16826 	    }
   16827 
   16828           /* This is a proxy for a member of a nested archive.  */
   16829           archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
   16830 
   16831           /* The nested archive file will have been opened and setup by
   16832              get_archive_member_name.  */
   16833           if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
   16834             {
   16835               error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
   16836               ret = 1;
   16837               break;
   16838             }
   16839 
   16840           ret |= process_object (qualified_name, nested_arch.file);
   16841         }
   16842       else
   16843         {
   16844           archive_file_offset = arch.next_arhdr_offset;
   16845           arch.next_arhdr_offset += archive_file_size;
   16846 
   16847           ret |= process_object (qualified_name, file);
   16848         }
   16849 
   16850       if (dump_sects != NULL)
   16851 	{
   16852 	  free (dump_sects);
   16853 	  dump_sects = NULL;
   16854 	  num_dump_sects = 0;
   16855 	}
   16856 
   16857       free (qualified_name);
   16858     }
   16859 
   16860  out:
   16861   if (nested_arch.file != NULL)
   16862     fclose (nested_arch.file);
   16863   release_archive (&nested_arch);
   16864   release_archive (&arch);
   16865 
   16866   return ret;
   16867 }
   16868 
   16869 static int
   16870 process_file (char * file_name)
   16871 {
   16872   FILE * file;
   16873   struct stat statbuf;
   16874   char armag[SARMAG];
   16875   int ret;
   16876 
   16877   if (stat (file_name, &statbuf) < 0)
   16878     {
   16879       if (errno == ENOENT)
   16880 	error (_("'%s': No such file\n"), file_name);
   16881       else
   16882 	error (_("Could not locate '%s'.  System error message: %s\n"),
   16883 	       file_name, strerror (errno));
   16884       return 1;
   16885     }
   16886 
   16887   if (! S_ISREG (statbuf.st_mode))
   16888     {
   16889       error (_("'%s' is not an ordinary file\n"), file_name);
   16890       return 1;
   16891     }
   16892 
   16893   file = fopen (file_name, "rb");
   16894   if (file == NULL)
   16895     {
   16896       error (_("Input file '%s' is not readable.\n"), file_name);
   16897       return 1;
   16898     }
   16899 
   16900   if (fread (armag, SARMAG, 1, file) != 1)
   16901     {
   16902       error (_("%s: Failed to read file's magic number\n"), file_name);
   16903       fclose (file);
   16904       return 1;
   16905     }
   16906 
   16907   current_file_size = (bfd_size_type) statbuf.st_size;
   16908 
   16909   if (memcmp (armag, ARMAG, SARMAG) == 0)
   16910     ret = process_archive (file_name, file, FALSE);
   16911   else if (memcmp (armag, ARMAGT, SARMAG) == 0)
   16912     ret = process_archive (file_name, file, TRUE);
   16913   else
   16914     {
   16915       if (do_archive_index)
   16916 	error (_("File %s is not an archive so its index cannot be displayed.\n"),
   16917 	       file_name);
   16918 
   16919       rewind (file);
   16920       archive_file_size = archive_file_offset = 0;
   16921       ret = process_object (file_name, file);
   16922     }
   16923 
   16924   fclose (file);
   16925 
   16926   current_file_size = 0;
   16927   return ret;
   16928 }
   16929 
   16930 #ifdef SUPPORT_DISASSEMBLY
   16931 /* Needed by the i386 disassembler.  For extra credit, someone could
   16932    fix this so that we insert symbolic addresses here, esp for GOT/PLT
   16933    symbols.  */
   16934 
   16935 void
   16936 print_address (unsigned int addr, FILE * outfile)
   16937 {
   16938   fprintf (outfile,"0x%8.8x", addr);
   16939 }
   16940 
   16941 /* Needed by the i386 disassembler.  */
   16942 void
   16943 db_task_printsym (unsigned int addr)
   16944 {
   16945   print_address (addr, stderr);
   16946 }
   16947 #endif
   16948 
   16949 int
   16950 main (int argc, char ** argv)
   16951 {
   16952   int err;
   16953 
   16954 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
   16955   setlocale (LC_MESSAGES, "");
   16956 #endif
   16957 #if defined (HAVE_SETLOCALE)
   16958   setlocale (LC_CTYPE, "");
   16959 #endif
   16960   bindtextdomain (PACKAGE, LOCALEDIR);
   16961   textdomain (PACKAGE);
   16962 
   16963   expandargv (&argc, &argv);
   16964 
   16965   parse_args (argc, argv);
   16966 
   16967   if (num_dump_sects > 0)
   16968     {
   16969       /* Make a copy of the dump_sects array.  */
   16970       cmdline_dump_sects = (dump_type *)
   16971           malloc (num_dump_sects * sizeof (* dump_sects));
   16972       if (cmdline_dump_sects == NULL)
   16973 	error (_("Out of memory allocating dump request table.\n"));
   16974       else
   16975 	{
   16976 	  memcpy (cmdline_dump_sects, dump_sects,
   16977 		  num_dump_sects * sizeof (* dump_sects));
   16978 	  num_cmdline_dump_sects = num_dump_sects;
   16979 	}
   16980     }
   16981 
   16982   if (optind < (argc - 1))
   16983     show_name = 1;
   16984   else if (optind >= argc)
   16985     {
   16986       warn (_("Nothing to do.\n"));
   16987       usage (stderr);
   16988     }
   16989 
   16990   err = 0;
   16991   while (optind < argc)
   16992     err |= process_file (argv[optind++]);
   16993 
   16994   if (dump_sects != NULL)
   16995     free (dump_sects);
   16996   if (cmdline_dump_sects != NULL)
   16997     free (cmdline_dump_sects);
   16998 
   16999   return err;
   17000 }
   17001