1 /* readelf.c -- display contents of an ELF format file
2    Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3    Free Software Foundation, Inc.
4 
5    Originally developed by Eric Youngdale <eric@andante.jic.com>
6    Modifications by Nick Clifton <nickc@redhat.com>
7 
8    This file is part of GNU Binutils.
9 
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23    02110-1301, USA.  */
24 
25 /* 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 <assert.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <stdio.h>
48 #include <time.h>
49 
50 #if __GNUC__ >= 2
51 /* Define BFD64 here, even if our default architecture is 32 bit ELF
52    as this will allow us to read in and parse 64bit and 32bit ELF files.
53    Only do this if we believe that the compiler can support a 64 bit
54    data type.  For now we only rely on GCC being able to do this.  */
55 #define BFD64
56 #endif
57 
58 #include "dwarf.h"
59 
60 #include "elf/common.h"
61 #include "elf/external.h"
62 #include "elf/internal.h"
63 
64 /* The following headers use the elf/reloc-macros.h file to
65    automatically generate relocation recognition functions
66    such as elf_mips_reloc_type()  */
67 
68 #define RELOC_MACROS_GEN_FUNC
69 
70 #include "elf/alpha.h"
71 #include "elf/arc.h"
72 #include "elf/arm.h"
73 #include "elf/avr.h"
74 #include "elf/bfin.h"
75 #include "elf/cris.h"
76 #include "elf/d10v.h"
77 #include "elf/d30v.h"
78 #include "elf/dlx.h"
79 #include "elf/fr30.h"
80 #include "elf/frv.h"
81 #include "elf/h8.h"
82 #include "elf/hppa.h"
83 #include "elf/i386.h"
84 #include "elf/i370.h"
85 #include "elf/i860.h"
86 #include "elf/i960.h"
87 #include "elf/ia64.h"
88 #include "elf/ip2k.h"
89 #include "elf/m32c.h"
90 #include "elf/m32r.h"
91 #include "elf/m68k.h"
92 #include "elf/m68hc11.h"
93 #include "elf/mcore.h"
94 #include "elf/mips.h"
95 #include "elf/mmix.h"
96 #include "elf/mn10200.h"
97 #include "elf/mn10300.h"
98 #include "elf/mt.h"
99 #include "elf/msp430.h"
100 #include "elf/or32.h"
101 #include "elf/pj.h"
102 #include "elf/ppc.h"
103 #include "elf/ppc64.h"
104 #include "elf/s390.h"
105 #include "elf/sh.h"
106 #include "elf/sparc.h"
107 #include "elf/v850.h"
108 #include "elf/vax.h"
109 #include "elf/x86-64.h"
110 #include "elf/xstormy16.h"
111 #include "elf/crx.h"
112 #include "elf/iq2000.h"
113 #include "elf/xtensa.h"
114 
115 #include "aout/ar.h"
116 
117 #include "bucomm.h"
118 #include "getopt.h"
119 #include "libiberty.h"
120 
121 char *program_name = "readelf";
122 static long archive_file_offset;
123 static unsigned long archive_file_size;
124 static unsigned long dynamic_addr;
125 static bfd_size_type dynamic_size;
126 static unsigned int dynamic_nent;
127 static char *dynamic_strings;
128 static unsigned long dynamic_strings_length;
129 static char *string_table;
130 static unsigned long string_table_length;
131 static unsigned long num_dynamic_syms;
132 static Elf_Internal_Sym *dynamic_symbols;
133 static Elf_Internal_Syminfo *dynamic_syminfo;
134 static unsigned long dynamic_syminfo_offset;
135 static unsigned int dynamic_syminfo_nent;
136 static char program_interpreter[64];
137 static bfd_vma dynamic_info[DT_JMPREL + 1];
138 static bfd_vma version_info[16];
139 static Elf_Internal_Ehdr elf_header;
140 static Elf_Internal_Shdr *section_headers;
141 static Elf_Internal_Phdr *program_headers;
142 static Elf_Internal_Dyn *dynamic_section;
143 static Elf_Internal_Shdr *symtab_shndx_hdr;
144 static int show_name;
145 static int do_dynamic;
146 static int do_syms;
147 static int do_reloc;
148 static int do_sections;
149 static int do_section_groups;
150 static int do_section_details;
151 static int do_segments;
152 static int do_unwind;
153 static int do_using_dynamic;
154 static int do_header;
155 static int do_dump;
156 static int do_version;
157 static int do_wide;
158 static int do_histogram;
159 static int do_debugging;
160 static int do_arch;
161 static int do_notes;
162 static int is_32bit_elf;
163 
164 struct group_list
165 {
166   struct group_list *next;
167   unsigned int section_index;
168 };
169 
170 struct group
171 {
172   struct group_list *root;
173   unsigned int group_index;
174 };
175 
176 static size_t group_count;
177 static struct group *section_groups;
178 static struct group **section_headers_groups;
179 
180 /* A linked list of the section names for which dumps were requested
181    by name.  */
182 struct dump_list_entry
183 {
184   char *name;
185   int type;
186   struct dump_list_entry *next;
187 };
188 static struct dump_list_entry *dump_sects_byname;
189 
190 /* A dynamic array of flags indicating for which sections a hex dump
191    has been requested (via the -x switch) and/or a disassembly dump
192    (via the -i switch).  */
193 char *cmdline_dump_sects = NULL;
194 unsigned num_cmdline_dump_sects = 0;
195 
196 /* A dynamic array of flags indicating for which sections a dump of
197    some kind has been requested.  It is reset on a per-object file
198    basis and then initialised from the cmdline_dump_sects array,
199    the results of interpreting the -w switch, and the
200    dump_sects_byname list.  */
201 char *dump_sects = NULL;
202 unsigned int num_dump_sects = 0;
203 
204 #define HEX_DUMP	(1 << 0)
205 #define DISASS_DUMP	(1 << 1)
206 #define DEBUG_DUMP	(1 << 2)
207 
208 /* How to print a vma value.  */
209 typedef enum print_mode
210 {
211   HEX,
212   DEC,
213   DEC_5,
214   UNSIGNED,
215   PREFIX_HEX,
216   FULL_HEX,
217   LONG_HEX
218 }
219 print_mode;
220 
221 static void (*byte_put) (unsigned char *, bfd_vma, int);
222 
223 #define UNKNOWN -1
224 
225 #define SECTION_NAME(X)	((X) == NULL ? "<none>" : \
226 			 ((X)->sh_name >= string_table_length \
227 			  ? "<corrupt>" : string_table + (X)->sh_name))
228 
229 /* Given st_shndx I, map to section_headers index.  */
230 #define SECTION_HEADER_INDEX(I)				\
231   ((I) < SHN_LORESERVE					\
232    ? (I)						\
233    : ((I) <= SHN_HIRESERVE				\
234       ? 0						\
235       : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
236 
237 /* Reverse of the above.  */
238 #define SECTION_HEADER_NUM(N)				\
239   ((N) < SHN_LORESERVE					\
240    ? (N)						\
241    : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
242 
243 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
244 
245 #define DT_VERSIONTAGIDX(tag)	(DT_VERNEEDNUM - (tag))	/* Reverse order!  */
246 
247 #define BYTE_GET(field)	byte_get (field, sizeof (field))
248 
249 #define NUM_ELEM(array) 	(sizeof (array) / sizeof ((array)[0]))
250 
251 #define GET_ELF_SYMBOLS(file, section)			\
252   (is_32bit_elf ? get_32bit_elf_symbols (file, section)	\
253    : get_64bit_elf_symbols (file, section))
254 
255 #define VALID_DYNAMIC_NAME(offset)	((dynamic_strings != NULL) && (offset < dynamic_strings_length))
256 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
257    already been called and verified that the string exists.  */
258 #define GET_DYNAMIC_NAME(offset)	(dynamic_strings + offset)
259 
260 /* This is just a bit of syntatic sugar.  */
261 #define streq(a,b)	(strcmp ((a), (b)) == 0)
262 #define strneq(a,b,n)	(strncmp ((a), (b), (n)) == 0)
263 
264 static void *
265 get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb,
266 	  const char *reason)
267 {
268   void *mvar;
269 
270   if (size == 0 || nmemb == 0)
271     return NULL;
272 
273   if (fseek (file, archive_file_offset + offset, SEEK_SET))
274     {
275       error (_("Unable to seek to 0x%lx for %s\n"),
276 	     archive_file_offset + offset, reason);
277       return NULL;
278     }
279 
280   mvar = var;
281   if (mvar == NULL)
282     {
283       /* Check for overflow.  */
284       if (nmemb < (~(size_t) 0 - 1) / size)
285 	/* + 1 so that we can '\0' terminate invalid string table sections.  */
286 	mvar = malloc (size * nmemb + 1);
287 
288       if (mvar == NULL)
289 	{
290 	  error (_("Out of memory allocating 0x%lx bytes for %s\n"),
291 		 (unsigned long)(size * nmemb), reason);
292 	  return NULL;
293 	}
294 
295       ((char *) mvar)[size * nmemb] = '\0';
296     }
297 
298   if (fread (mvar, size, nmemb, file) != nmemb)
299     {
300       error (_("Unable to read in 0x%lx bytes of %s\n"),
301 	     (unsigned long)(size * nmemb), reason);
302       if (mvar != var)
303 	free (mvar);
304       return NULL;
305     }
306 
307   return mvar;
308 }
309 
310 static void
311 byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
312 {
313   switch (size)
314     {
315     case 8:
316       field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
317       field[6] = ((value >> 24) >> 24) & 0xff;
318       field[5] = ((value >> 24) >> 16) & 0xff;
319       field[4] = ((value >> 24) >> 8) & 0xff;
320       /* Fall through.  */
321     case 4:
322       field[3] = (value >> 24) & 0xff;
323       field[2] = (value >> 16) & 0xff;
324       /* Fall through.  */
325     case 2:
326       field[1] = (value >> 8) & 0xff;
327       /* Fall through.  */
328     case 1:
329       field[0] = value & 0xff;
330       break;
331 
332     default:
333       error (_("Unhandled data length: %d\n"), size);
334       abort ();
335     }
336 }
337 
338 #if defined BFD64 && !BFD_HOST_64BIT_LONG
339 static int
340 print_dec_vma (bfd_vma vma, int is_signed)
341 {
342   char buf[40];
343   char *bufp = buf;
344   int nc = 0;
345 
346   if (is_signed && (bfd_signed_vma) vma < 0)
347     {
348       vma = -vma;
349       putchar ('-');
350       nc = 1;
351     }
352 
353   do
354     {
355       *bufp++ = '0' + vma % 10;
356       vma /= 10;
357     }
358   while (vma != 0);
359   nc += bufp - buf;
360 
361   while (bufp > buf)
362     putchar (*--bufp);
363   return nc;
364 }
365 
366 static int
367 print_hex_vma (bfd_vma vma)
368 {
369   char buf[32];
370   char *bufp = buf;
371   int nc;
372 
373   do
374     {
375       char digit = '0' + (vma & 0x0f);
376       if (digit > '9')
377 	digit += 'a' - '0' - 10;
378       *bufp++ = digit;
379       vma >>= 4;
380     }
381   while (vma != 0);
382   nc = bufp - buf;
383 
384   while (bufp > buf)
385     putchar (*--bufp);
386   return nc;
387 }
388 #endif
389 
390 /* Print a VMA value.  */
391 static int
392 print_vma (bfd_vma vma, print_mode mode)
393 {
394 #ifdef BFD64
395   if (is_32bit_elf)
396 #endif
397     {
398       switch (mode)
399 	{
400 	case FULL_HEX:
401 	  return printf ("0x%8.8lx", (unsigned long) vma);
402 
403 	case LONG_HEX:
404 	  return printf ("%8.8lx", (unsigned long) vma);
405 
406 	case DEC_5:
407 	  if (vma <= 99999)
408 	    return printf ("%5ld", (long) vma);
409 	  /* Drop through.  */
410 
411 	case PREFIX_HEX:
412 	  return printf ("0x%lx", (unsigned long) vma);
413 
414 	case HEX:
415 	  return printf ("%lx", (unsigned long) vma);
416 
417 	case DEC:
418 	  return printf ("%ld", (unsigned long) vma);
419 
420 	case UNSIGNED:
421 	  return printf ("%lu", (unsigned long) vma);
422 	}
423     }
424 #ifdef BFD64
425   else
426     {
427       int nc = 0;
428 
429       switch (mode)
430 	{
431 	case FULL_HEX:
432 	  nc = printf ("0x");
433 	  /* Drop through.  */
434 
435 	case LONG_HEX:
436 	  printf_vma (vma);
437 	  return nc + 16;
438 
439 	case PREFIX_HEX:
440 	  nc = printf ("0x");
441 	  /* Drop through.  */
442 
443 	case HEX:
444 #if BFD_HOST_64BIT_LONG
445 	  return nc + printf ("%lx", vma);
446 #else
447 	  return nc + print_hex_vma (vma);
448 #endif
449 
450 	case DEC:
451 #if BFD_HOST_64BIT_LONG
452 	  return printf ("%ld", vma);
453 #else
454 	  return print_dec_vma (vma, 1);
455 #endif
456 
457 	case DEC_5:
458 #if BFD_HOST_64BIT_LONG
459 	  if (vma <= 99999)
460 	    return printf ("%5ld", vma);
461 	  else
462 	    return printf ("%#lx", vma);
463 #else
464 	  if (vma <= 99999)
465 	    return printf ("%5ld", _bfd_int64_low (vma));
466 	  else
467 	    return print_hex_vma (vma);
468 #endif
469 
470 	case UNSIGNED:
471 #if BFD_HOST_64BIT_LONG
472 	  return printf ("%lu", vma);
473 #else
474 	  return print_dec_vma (vma, 0);
475 #endif
476 	}
477     }
478 #endif
479   return 0;
480 }
481 
482 /* Display a symbol on stdout.  If do_wide is not true then
483    format the symbol to be at most WIDTH characters,
484    truncating as necessary.  If WIDTH is negative then
485    format the string to be exactly - WIDTH characters,
486    truncating or padding as necessary.  */
487 
488 static void
489 print_symbol (int width, const char *symbol)
490 {
491   if (do_wide)
492     printf ("%s", symbol);
493   else if (width < 0)
494     printf ("%-*.*s", width, width, symbol);
495   else
496     printf ("%-.*s", width, symbol);
497 }
498 
499 static void
500 byte_put_big_endian (unsigned char *field, bfd_vma value, int size)
501 {
502   switch (size)
503     {
504     case 8:
505       field[7] = value & 0xff;
506       field[6] = (value >> 8) & 0xff;
507       field[5] = (value >> 16) & 0xff;
508       field[4] = (value >> 24) & 0xff;
509       value >>= 16;
510       value >>= 16;
511       /* Fall through.  */
512     case 4:
513       field[3] = value & 0xff;
514       field[2] = (value >> 8) & 0xff;
515       value >>= 16;
516       /* Fall through.  */
517     case 2:
518       field[1] = value & 0xff;
519       value >>= 8;
520       /* Fall through.  */
521     case 1:
522       field[0] = value & 0xff;
523       break;
524 
525     default:
526       error (_("Unhandled data length: %d\n"), size);
527       abort ();
528     }
529 }
530 
531 /* Return a pointer to section NAME, or NULL if no such section exists.  */
532 
533 static Elf_Internal_Shdr *
534 find_section (const char *name)
535 {
536   unsigned int i;
537 
538   for (i = 0; i < elf_header.e_shnum; i++)
539     if (streq (SECTION_NAME (section_headers + i), name))
540       return section_headers + i;
541 
542   return NULL;
543 }
544 
545 /* Guess the relocation size commonly used by the specific machines.  */
546 
547 static int
548 guess_is_rela (unsigned long e_machine)
549 {
550   switch (e_machine)
551     {
552       /* Targets that use REL relocations.  */
553     case EM_ARM:
554     case EM_386:
555     case EM_486:
556     case EM_960:
557     case EM_DLX:
558     case EM_OPENRISC:
559     case EM_OR32:
560     case EM_CYGNUS_M32R:
561     case EM_D10V:
562     case EM_CYGNUS_D10V:
563     case EM_MIPS:
564     case EM_MIPS_RS3_LE:
565       return FALSE;
566 
567       /* Targets that use RELA relocations.  */
568     case EM_68K:
569     case EM_H8_300:
570     case EM_H8_300H:
571     case EM_H8S:
572     case EM_SPARC32PLUS:
573     case EM_SPARCV9:
574     case EM_SPARC:
575     case EM_PPC:
576     case EM_PPC64:
577     case EM_V850:
578     case EM_CYGNUS_V850:
579     case EM_D30V:
580     case EM_CYGNUS_D30V:
581     case EM_MN10200:
582     case EM_CYGNUS_MN10200:
583     case EM_MN10300:
584     case EM_CYGNUS_MN10300:
585     case EM_FR30:
586     case EM_CYGNUS_FR30:
587     case EM_CYGNUS_FRV:
588     case EM_SH:
589     case EM_ALPHA:
590     case EM_MCORE:
591     case EM_IA_64:
592     case EM_AVR:
593     case EM_AVR_OLD:
594     case EM_CRIS:
595     case EM_860:
596     case EM_X86_64:
597     case EM_S390:
598     case EM_S390_OLD:
599     case EM_MMIX:
600     case EM_MSP430:
601     case EM_MSP430_OLD:
602     case EM_XSTORMY16:
603     case EM_CRX:
604     case EM_VAX:
605     case EM_IP2K:
606     case EM_IP2K_OLD:
607     case EM_IQ2000:
608     case EM_XTENSA:
609     case EM_XTENSA_OLD:
610     case EM_M32R:
611     case EM_M32C:
612     case EM_MT:
613     case EM_BLACKFIN:
614     case EM_NIOS32:
615     case EM_ALTERA_NIOS2:
616       return TRUE;
617 
618     case EM_MMA:
619     case EM_PCP:
620     case EM_NCPU:
621     case EM_NDR1:
622     case EM_STARCORE:
623     case EM_ME16:
624     case EM_ST100:
625     case EM_TINYJ:
626     case EM_FX66:
627     case EM_ST9PLUS:
628     case EM_ST7:
629     case EM_68HC16:
630     case EM_68HC11:
631     case EM_68HC08:
632     case EM_68HC05:
633     case EM_SVX:
634     case EM_ST19:
635     default:
636       warn (_("Don't know about relocations on this machine architecture\n"));
637       return FALSE;
638     }
639 }
640 
641 static int
642 slurp_rela_relocs (FILE *file,
643 		   unsigned long rel_offset,
644 		   unsigned long rel_size,
645 		   Elf_Internal_Rela **relasp,
646 		   unsigned long *nrelasp)
647 {
648   Elf_Internal_Rela *relas;
649   unsigned long nrelas;
650   unsigned int i;
651 
652   if (is_32bit_elf)
653     {
654       Elf32_External_Rela *erelas;
655 
656       erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
657       if (!erelas)
658 	return 0;
659 
660       nrelas = rel_size / sizeof (Elf32_External_Rela);
661 
662       relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
663 
664       if (relas == NULL)
665 	{
666 	  free (erelas);
667 	  error (_("out of memory parsing relocs"));
668 	  return 0;
669 	}
670 
671       for (i = 0; i < nrelas; i++)
672 	{
673 	  relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
674 	  relas[i].r_info   = BYTE_GET (erelas[i].r_info);
675 	  relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
676 	}
677 
678       free (erelas);
679     }
680   else
681     {
682       Elf64_External_Rela *erelas;
683 
684       erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
685       if (!erelas)
686 	return 0;
687 
688       nrelas = rel_size / sizeof (Elf64_External_Rela);
689 
690       relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
691 
692       if (relas == NULL)
693 	{
694 	  free (erelas);
695 	  error (_("out of memory parsing relocs"));
696 	  return 0;
697 	}
698 
699       for (i = 0; i < nrelas; i++)
700 	{
701 	  relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
702 	  relas[i].r_info   = BYTE_GET (erelas[i].r_info);
703 	  relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
704 	}
705 
706       free (erelas);
707     }
708   *relasp = relas;
709   *nrelasp = nrelas;
710   return 1;
711 }
712 
713 static int
714 slurp_rel_relocs (FILE *file,
715 		  unsigned long rel_offset,
716 		  unsigned long rel_size,
717 		  Elf_Internal_Rela **relsp,
718 		  unsigned long *nrelsp)
719 {
720   Elf_Internal_Rela *rels;
721   unsigned long nrels;
722   unsigned int i;
723 
724   if (is_32bit_elf)
725     {
726       Elf32_External_Rel *erels;
727 
728       erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
729       if (!erels)
730 	return 0;
731 
732       nrels = rel_size / sizeof (Elf32_External_Rel);
733 
734       rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
735 
736       if (rels == NULL)
737 	{
738 	  free (erels);
739 	  error (_("out of memory parsing relocs"));
740 	  return 0;
741 	}
742 
743       for (i = 0; i < nrels; i++)
744 	{
745 	  rels[i].r_offset = BYTE_GET (erels[i].r_offset);
746 	  rels[i].r_info   = BYTE_GET (erels[i].r_info);
747 	  rels[i].r_addend = 0;
748 	}
749 
750       free (erels);
751     }
752   else
753     {
754       Elf64_External_Rel *erels;
755 
756       erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
757       if (!erels)
758 	return 0;
759 
760       nrels = rel_size / sizeof (Elf64_External_Rel);
761 
762       rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
763 
764       if (rels == NULL)
765 	{
766 	  free (erels);
767 	  error (_("out of memory parsing relocs"));
768 	  return 0;
769 	}
770 
771       for (i = 0; i < nrels; i++)
772 	{
773 	  rels[i].r_offset = BYTE_GET (erels[i].r_offset);
774 	  rels[i].r_info   = BYTE_GET (erels[i].r_info);
775 	  rels[i].r_addend = 0;
776 	}
777 
778       free (erels);
779     }
780   *relsp = rels;
781   *nrelsp = nrels;
782   return 1;
783 }
784 
785 /* Display the contents of the relocation data found at the specified
786    offset.  */
787 
788 static int
789 dump_relocations (FILE *file,
790 		  unsigned long rel_offset,
791 		  unsigned long rel_size,
792 		  Elf_Internal_Sym *symtab,
793 		  unsigned long nsyms,
794 		  char *strtab,
795 		  unsigned long strtablen,
796 		  int is_rela)
797 {
798   unsigned int i;
799   Elf_Internal_Rela *rels;
800 
801 
802   if (is_rela == UNKNOWN)
803     is_rela = guess_is_rela (elf_header.e_machine);
804 
805   if (is_rela)
806     {
807       if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
808 	return 0;
809     }
810   else
811     {
812       if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
813 	return 0;
814     }
815 
816   if (is_32bit_elf)
817     {
818       if (is_rela)
819 	{
820 	  if (do_wide)
821 	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name + Addend\n"));
822 	  else
823 	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
824 	}
825       else
826 	{
827 	  if (do_wide)
828 	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
829 	  else
830 	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
831 	}
832     }
833   else
834     {
835       if (is_rela)
836 	{
837 	  if (do_wide)
838 	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
839 	  else
840 	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n"));
841 	}
842       else
843 	{
844 	  if (do_wide)
845 	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name\n"));
846 	  else
847 	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name\n"));
848 	}
849     }
850 
851   for (i = 0; i < rel_size; i++)
852     {
853       const char *rtype;
854       const char *rtype2 = NULL;
855       const char *rtype3 = NULL;
856       bfd_vma offset;
857       bfd_vma info;
858       bfd_vma symtab_index;
859       bfd_vma type;
860       bfd_vma type2 = 0;
861       bfd_vma type3 = 0;
862 
863       offset = rels[i].r_offset;
864       info   = rels[i].r_info;
865 
866       if (is_32bit_elf)
867 	{
868 	  type         = ELF32_R_TYPE (info);
869 	  symtab_index = ELF32_R_SYM  (info);
870 	}
871       else
872 	{
873 	  /* The #ifdef BFD64 below is to prevent a compile time warning.
874 	     We know that if we do not have a 64 bit data type that we
875 	     will never execute this code anyway.  */
876 #ifdef BFD64
877 	  if (elf_header.e_machine == EM_MIPS)
878 	    {
879 	      /* In little-endian objects, r_info isn't really a 64-bit
880 		 little-endian value: it has a 32-bit little-endian
881 		 symbol index followed by four individual byte fields.
882 		 Reorder INFO accordingly.  */
883 	      if (elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
884 		info = (((info & 0xffffffff) << 32)
885 			| ((info >> 56) & 0xff)
886 			| ((info >> 40) & 0xff00)
887 			| ((info >> 24) & 0xff0000)
888 			| ((info >> 8) & 0xff000000));
889 	      type  = ELF64_MIPS_R_TYPE (info);
890 	      type2 = ELF64_MIPS_R_TYPE2 (info);
891 	      type3 = ELF64_MIPS_R_TYPE3 (info);
892 	    }
893 	  else if (elf_header.e_machine == EM_SPARCV9)
894 	    type = ELF64_R_TYPE_ID (info);
895 	  else
896 	    type = ELF64_R_TYPE (info);
897 
898 	  symtab_index = ELF64_R_SYM  (info);
899 #endif
900 	}
901 
902       if (is_32bit_elf)
903 	{
904 #ifdef _bfd_int64_low
905 	  printf ("%8.8lx  %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
906 #else
907 	  printf ("%8.8lx  %8.8lx ", offset, info);
908 #endif
909 	}
910       else
911 	{
912 #ifdef _bfd_int64_low
913 	  printf (do_wide
914 		  ? "%8.8lx%8.8lx  %8.8lx%8.8lx "
915 		  : "%4.4lx%8.8lx  %4.4lx%8.8lx ",
916 		  _bfd_int64_high (offset),
917 		  _bfd_int64_low (offset),
918 		  _bfd_int64_high (info),
919 		  _bfd_int64_low (info));
920 #else
921 	  printf (do_wide
922 		  ? "%16.16lx  %16.16lx "
923 		  : "%12.12lx  %12.12lx ",
924 		  offset, info);
925 #endif
926 	}
927 
928       switch (elf_header.e_machine)
929 	{
930 	default:
931 	  rtype = NULL;
932 	  break;
933 
934 	case EM_M32R:
935 	case EM_CYGNUS_M32R:
936 	  rtype = elf_m32r_reloc_type (type);
937 	  break;
938 
939 	case EM_386:
940 	case EM_486:
941 	  rtype = elf_i386_reloc_type (type);
942 	  break;
943 
944 	case EM_68HC11:
945 	case EM_68HC12:
946 	  rtype = elf_m68hc11_reloc_type (type);
947 	  break;
948 
949 	case EM_68K:
950 	  rtype = elf_m68k_reloc_type (type);
951 	  break;
952 
953 	case EM_960:
954 	  rtype = elf_i960_reloc_type (type);
955 	  break;
956 
957 	case EM_AVR:
958 	case EM_AVR_OLD:
959 	  rtype = elf_avr_reloc_type (type);
960 	  break;
961 
962 	case EM_OLD_SPARCV9:
963 	case EM_SPARC32PLUS:
964 	case EM_SPARCV9:
965 	case EM_SPARC:
966 	  rtype = elf_sparc_reloc_type (type);
967 	  break;
968 
969 	case EM_V850:
970 	case EM_CYGNUS_V850:
971 	  rtype = v850_reloc_type (type);
972 	  break;
973 
974 	case EM_D10V:
975 	case EM_CYGNUS_D10V:
976 	  rtype = elf_d10v_reloc_type (type);
977 	  break;
978 
979 	case EM_D30V:
980 	case EM_CYGNUS_D30V:
981 	  rtype = elf_d30v_reloc_type (type);
982 	  break;
983 
984 	case EM_DLX:
985 	  rtype = elf_dlx_reloc_type (type);
986 	  break;
987 
988 	case EM_SH:
989 	  rtype = elf_sh_reloc_type (type);
990 	  break;
991 
992 	case EM_MN10300:
993 	case EM_CYGNUS_MN10300:
994 	  rtype = elf_mn10300_reloc_type (type);
995 	  break;
996 
997 	case EM_MN10200:
998 	case EM_CYGNUS_MN10200:
999 	  rtype = elf_mn10200_reloc_type (type);
1000 	  break;
1001 
1002 	case EM_FR30:
1003 	case EM_CYGNUS_FR30:
1004 	  rtype = elf_fr30_reloc_type (type);
1005 	  break;
1006 
1007 	case EM_CYGNUS_FRV:
1008 	  rtype = elf_frv_reloc_type (type);
1009 	  break;
1010 
1011 	case EM_MCORE:
1012 	  rtype = elf_mcore_reloc_type (type);
1013 	  break;
1014 
1015 	case EM_MMIX:
1016 	  rtype = elf_mmix_reloc_type (type);
1017 	  break;
1018 
1019 	case EM_MSP430:
1020 	case EM_MSP430_OLD:
1021 	  rtype = elf_msp430_reloc_type (type);
1022 	  break;
1023 
1024 	case EM_PPC:
1025 	  rtype = elf_ppc_reloc_type (type);
1026 	  break;
1027 
1028 	case EM_PPC64:
1029 	  rtype = elf_ppc64_reloc_type (type);
1030 	  break;
1031 
1032 	case EM_MIPS:
1033 	case EM_MIPS_RS3_LE:
1034 	  rtype = elf_mips_reloc_type (type);
1035 	  if (!is_32bit_elf)
1036 	    {
1037 	      rtype2 = elf_mips_reloc_type (type2);
1038 	      rtype3 = elf_mips_reloc_type (type3);
1039 	    }
1040 	  break;
1041 
1042 	case EM_ALPHA:
1043 	  rtype = elf_alpha_reloc_type (type);
1044 	  break;
1045 
1046 	case EM_ARM:
1047 	  rtype = elf_arm_reloc_type (type);
1048 	  break;
1049 
1050 	case EM_ARC:
1051 	  rtype = elf_arc_reloc_type (type);
1052 	  break;
1053 
1054 	case EM_PARISC:
1055 	  rtype = elf_hppa_reloc_type (type);
1056 	  break;
1057 
1058 	case EM_H8_300:
1059 	case EM_H8_300H:
1060 	case EM_H8S:
1061 	  rtype = elf_h8_reloc_type (type);
1062 	  break;
1063 
1064 	case EM_OPENRISC:
1065 	case EM_OR32:
1066 	  rtype = elf_or32_reloc_type (type);
1067 	  break;
1068 
1069 	case EM_PJ:
1070 	case EM_PJ_OLD:
1071 	  rtype = elf_pj_reloc_type (type);
1072 	  break;
1073 	case EM_IA_64:
1074 	  rtype = elf_ia64_reloc_type (type);
1075 	  break;
1076 
1077 	case EM_CRIS:
1078 	  rtype = elf_cris_reloc_type (type);
1079 	  break;
1080 
1081 	case EM_860:
1082 	  rtype = elf_i860_reloc_type (type);
1083 	  break;
1084 
1085 	case EM_X86_64:
1086 	  rtype = elf_x86_64_reloc_type (type);
1087 	  break;
1088 
1089 	case EM_S370:
1090 	  rtype = i370_reloc_type (type);
1091 	  break;
1092 
1093 	case EM_S390_OLD:
1094 	case EM_S390:
1095 	  rtype = elf_s390_reloc_type (type);
1096 	  break;
1097 
1098 	case EM_XSTORMY16:
1099 	  rtype = elf_xstormy16_reloc_type (type);
1100 	  break;
1101 
1102 	case EM_CRX:
1103 	  rtype = elf_crx_reloc_type (type);
1104 	  break;
1105 
1106 	case EM_VAX:
1107 	  rtype = elf_vax_reloc_type (type);
1108 	  break;
1109 
1110 	case EM_IP2K:
1111 	case EM_IP2K_OLD:
1112 	  rtype = elf_ip2k_reloc_type (type);
1113 	  break;
1114 
1115 	case EM_IQ2000:
1116 	  rtype = elf_iq2000_reloc_type (type);
1117 	  break;
1118 
1119 	case EM_XTENSA_OLD:
1120 	case EM_XTENSA:
1121 	  rtype = elf_xtensa_reloc_type (type);
1122 	  break;
1123 
1124 	case EM_M32C:
1125 	  rtype = elf_m32c_reloc_type (type);
1126 	  break;
1127 
1128 	case EM_MT:
1129 	  rtype = elf_mt_reloc_type (type);
1130 	  break;
1131 
1132 	case EM_BLACKFIN:
1133 	  rtype = elf_bfin_reloc_type (type);
1134 	  break;
1135 
1136 	}
1137 
1138       if (rtype == NULL)
1139 #ifdef _bfd_int64_low
1140 	printf (_("unrecognized: %-7lx"), _bfd_int64_low (type));
1141 #else
1142 	printf (_("unrecognized: %-7lx"), type);
1143 #endif
1144       else
1145 	printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1146 
1147       if (elf_header.e_machine == EM_ALPHA
1148 	  && streq (rtype, "R_ALPHA_LITUSE")
1149 	  && is_rela)
1150 	{
1151 	  switch (rels[i].r_addend)
1152 	    {
1153 	    case LITUSE_ALPHA_ADDR:   rtype = "ADDR";   break;
1154 	    case LITUSE_ALPHA_BASE:   rtype = "BASE";   break;
1155 	    case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1156 	    case LITUSE_ALPHA_JSR:    rtype = "JSR";    break;
1157 	    case LITUSE_ALPHA_TLSGD:  rtype = "TLSGD";  break;
1158 	    case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1159 	    case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1160 	    default: rtype = NULL;
1161 	    }
1162 	  if (rtype)
1163 	    printf (" (%s)", rtype);
1164 	  else
1165 	    {
1166 	      putchar (' ');
1167 	      printf (_("<unknown addend: %lx>"),
1168 		      (unsigned long) rels[i].r_addend);
1169 	    }
1170 	}
1171       else if (symtab_index)
1172 	{
1173 	  if (symtab == NULL || symtab_index >= nsyms)
1174 	    printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1175 	  else
1176 	    {
1177 	      Elf_Internal_Sym *psym;
1178 
1179 	      psym = symtab + symtab_index;
1180 
1181 	      printf (" ");
1182 	      print_vma (psym->st_value, LONG_HEX);
1183 	      printf (is_32bit_elf ? "   " : " ");
1184 
1185 	      if (psym->st_name == 0)
1186 		{
1187 		  const char *sec_name = "<null>";
1188 		  char name_buf[40];
1189 
1190 		  if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1191 		    {
1192 		      bfd_vma sec_index = (bfd_vma) -1;
1193 
1194 		      if (psym->st_shndx < SHN_LORESERVE)
1195 			sec_index = psym->st_shndx;
1196 		      else if (psym->st_shndx > SHN_HIRESERVE)
1197 			sec_index = psym->st_shndx - (SHN_HIRESERVE + 1
1198 						      - SHN_LORESERVE);
1199 
1200 		      if (sec_index != (bfd_vma) -1)
1201 			sec_name = SECTION_NAME (section_headers + sec_index);
1202 		      else if (psym->st_shndx == SHN_ABS)
1203 			sec_name = "ABS";
1204 		      else if (psym->st_shndx == SHN_COMMON)
1205 			sec_name = "COMMON";
1206 		      else if (elf_header.e_machine == EM_X86_64
1207 			       && psym->st_shndx == SHN_X86_64_LCOMMON)
1208 			sec_name = "LARGE_COMMON";
1209 		      else if (elf_header.e_machine == EM_IA_64
1210 			       && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1211 			       && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1212 			sec_name = "ANSI_COM";
1213 		      else
1214 			{
1215 			  sprintf (name_buf, "<section 0x%x>",
1216 				   (unsigned int) psym->st_shndx);
1217 			  sec_name = name_buf;
1218 			}
1219 		    }
1220 		  print_symbol (22, sec_name);
1221 		}
1222 	      else if (strtab == NULL)
1223 		printf (_("<string table index: %3ld>"), psym->st_name);
1224 	      else if (psym->st_name >= strtablen)
1225 		printf (_("<corrupt string table index: %3ld>"), psym->st_name);
1226 	      else
1227 		print_symbol (22, strtab + psym->st_name);
1228 
1229 	      if (is_rela)
1230 		printf (" + %lx", (unsigned long) rels[i].r_addend);
1231 	    }
1232 	}
1233       else if (is_rela)
1234 	{
1235 	  printf ("%*c", is_32bit_elf ?
1236 		  (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1237 	  print_vma (rels[i].r_addend, LONG_HEX);
1238 	}
1239 
1240       if (elf_header.e_machine == EM_SPARCV9 && streq (rtype, "R_SPARC_OLO10"))
1241 	printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1242 
1243       putchar ('\n');
1244 
1245       if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
1246 	{
1247 	  printf ("                    Type2: ");
1248 
1249 	  if (rtype2 == NULL)
1250 #ifdef _bfd_int64_low
1251 	    printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2));
1252 #else
1253 	    printf (_("unrecognized: %-7lx"), type2);
1254 #endif
1255 	  else
1256 	    printf ("%-17.17s", rtype2);
1257 
1258 	  printf ("\n                    Type3: ");
1259 
1260 	  if (rtype3 == NULL)
1261 #ifdef _bfd_int64_low
1262 	    printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3));
1263 #else
1264 	    printf (_("unrecognized: %-7lx"), type3);
1265 #endif
1266 	  else
1267 	    printf ("%-17.17s", rtype3);
1268 
1269 	  putchar ('\n');
1270 	}
1271     }
1272 
1273   free (rels);
1274 
1275   return 1;
1276 }
1277 
1278 static const char *
1279 get_mips_dynamic_type (unsigned long type)
1280 {
1281   switch (type)
1282     {
1283     case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1284     case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1285     case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1286     case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1287     case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1288     case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1289     case DT_MIPS_MSYM: return "MIPS_MSYM";
1290     case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1291     case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1292     case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1293     case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1294     case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1295     case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1296     case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1297     case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1298     case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1299     case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1300     case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1301     case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1302     case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1303     case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1304     case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1305     case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1306     case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1307     case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1308     case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1309     case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1310     case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1311     case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1312     case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1313     case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1314     case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1315     case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1316     case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1317     case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1318     case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1319     case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1320     case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1321     case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1322     case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1323     case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1324     case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1325     case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1326     default:
1327       return NULL;
1328     }
1329 }
1330 
1331 static const char *
1332 get_sparc64_dynamic_type (unsigned long type)
1333 {
1334   switch (type)
1335     {
1336     case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1337     default:
1338       return NULL;
1339     }
1340 }
1341 
1342 static const char *
1343 get_ppc_dynamic_type (unsigned long type)
1344 {
1345   switch (type)
1346     {
1347     case DT_PPC_GOT: return "PPC_GOT";
1348     default:
1349       return NULL;
1350     }
1351 }
1352 
1353 static const char *
1354 get_ppc64_dynamic_type (unsigned long type)
1355 {
1356   switch (type)
1357     {
1358     case DT_PPC64_GLINK: return "PPC64_GLINK";
1359     case DT_PPC64_OPD:   return "PPC64_OPD";
1360     case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1361     default:
1362       return NULL;
1363     }
1364 }
1365 
1366 static const char *
1367 get_parisc_dynamic_type (unsigned long type)
1368 {
1369   switch (type)
1370     {
1371     case DT_HP_LOAD_MAP:	return "HP_LOAD_MAP";
1372     case DT_HP_DLD_FLAGS:	return "HP_DLD_FLAGS";
1373     case DT_HP_DLD_HOOK:	return "HP_DLD_HOOK";
1374     case DT_HP_UX10_INIT:	return "HP_UX10_INIT";
1375     case DT_HP_UX10_INITSZ:	return "HP_UX10_INITSZ";
1376     case DT_HP_PREINIT:		return "HP_PREINIT";
1377     case DT_HP_PREINITSZ:	return "HP_PREINITSZ";
1378     case DT_HP_NEEDED:		return "HP_NEEDED";
1379     case DT_HP_TIME_STAMP:	return "HP_TIME_STAMP";
1380     case DT_HP_CHECKSUM:	return "HP_CHECKSUM";
1381     case DT_HP_GST_SIZE:	return "HP_GST_SIZE";
1382     case DT_HP_GST_VERSION:	return "HP_GST_VERSION";
1383     case DT_HP_GST_HASHVAL:	return "HP_GST_HASHVAL";
1384     case DT_HP_EPLTREL:		return "HP_GST_EPLTREL";
1385     case DT_HP_EPLTRELSZ:	return "HP_GST_EPLTRELSZ";
1386     case DT_HP_FILTERED:	return "HP_FILTERED";
1387     case DT_HP_FILTER_TLS:	return "HP_FILTER_TLS";
1388     case DT_HP_COMPAT_FILTERED:	return "HP_COMPAT_FILTERED";
1389     case DT_HP_LAZYLOAD:	return "HP_LAZYLOAD";
1390     case DT_HP_BIND_NOW_COUNT:	return "HP_BIND_NOW_COUNT";
1391     case DT_PLT:		return "PLT";
1392     case DT_PLT_SIZE:		return "PLT_SIZE";
1393     case DT_DLT:		return "DLT";
1394     case DT_DLT_SIZE:		return "DLT_SIZE";
1395     default:
1396       return NULL;
1397     }
1398 }
1399 
1400 static const char *
1401 get_ia64_dynamic_type (unsigned long type)
1402 {
1403   switch (type)
1404     {
1405     case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1406     default:
1407       return NULL;
1408     }
1409 }
1410 
1411 static const char *
1412 get_alpha_dynamic_type (unsigned long type)
1413 {
1414   switch (type)
1415     {
1416     case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
1417     default:
1418       return NULL;
1419     }
1420 }
1421 
1422 static const char *
1423 get_dynamic_type (unsigned long type)
1424 {
1425   static char buff[64];
1426 
1427   switch (type)
1428     {
1429     case DT_NULL:	return "NULL";
1430     case DT_NEEDED:	return "NEEDED";
1431     case DT_PLTRELSZ:	return "PLTRELSZ";
1432     case DT_PLTGOT:	return "PLTGOT";
1433     case DT_HASH:	return "HASH";
1434     case DT_STRTAB:	return "STRTAB";
1435     case DT_SYMTAB:	return "SYMTAB";
1436     case DT_RELA:	return "RELA";
1437     case DT_RELASZ:	return "RELASZ";
1438     case DT_RELAENT:	return "RELAENT";
1439     case DT_STRSZ:	return "STRSZ";
1440     case DT_SYMENT:	return "SYMENT";
1441     case DT_INIT:	return "INIT";
1442     case DT_FINI:	return "FINI";
1443     case DT_SONAME:	return "SONAME";
1444     case DT_RPATH:	return "RPATH";
1445     case DT_SYMBOLIC:	return "SYMBOLIC";
1446     case DT_REL:	return "REL";
1447     case DT_RELSZ:	return "RELSZ";
1448     case DT_RELENT:	return "RELENT";
1449     case DT_PLTREL:	return "PLTREL";
1450     case DT_DEBUG:	return "DEBUG";
1451     case DT_TEXTREL:	return "TEXTREL";
1452     case DT_JMPREL:	return "JMPREL";
1453     case DT_BIND_NOW:   return "BIND_NOW";
1454     case DT_INIT_ARRAY: return "INIT_ARRAY";
1455     case DT_FINI_ARRAY: return "FINI_ARRAY";
1456     case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1457     case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1458     case DT_RUNPATH:    return "RUNPATH";
1459     case DT_FLAGS:      return "FLAGS";
1460 
1461     case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1462     case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1463 
1464     case DT_CHECKSUM:	return "CHECKSUM";
1465     case DT_PLTPADSZ:	return "PLTPADSZ";
1466     case DT_MOVEENT:	return "MOVEENT";
1467     case DT_MOVESZ:	return "MOVESZ";
1468     case DT_FEATURE:	return "FEATURE";
1469     case DT_POSFLAG_1:	return "POSFLAG_1";
1470     case DT_SYMINSZ:	return "SYMINSZ";
1471     case DT_SYMINENT:	return "SYMINENT"; /* aka VALRNGHI */
1472 
1473     case DT_ADDRRNGLO:  return "ADDRRNGLO";
1474     case DT_CONFIG:	return "CONFIG";
1475     case DT_DEPAUDIT:	return "DEPAUDIT";
1476     case DT_AUDIT:	return "AUDIT";
1477     case DT_PLTPAD:	return "PLTPAD";
1478     case DT_MOVETAB:	return "MOVETAB";
1479     case DT_SYMINFO:	return "SYMINFO"; /* aka ADDRRNGHI */
1480 
1481     case DT_VERSYM:	return "VERSYM";
1482 
1483     case DT_TLSDESC_GOT: return "TLSDESC_GOT";
1484     case DT_TLSDESC_PLT: return "TLSDESC_PLT";
1485     case DT_RELACOUNT:	return "RELACOUNT";
1486     case DT_RELCOUNT:	return "RELCOUNT";
1487     case DT_FLAGS_1:	return "FLAGS_1";
1488     case DT_VERDEF:	return "VERDEF";
1489     case DT_VERDEFNUM:	return "VERDEFNUM";
1490     case DT_VERNEED:	return "VERNEED";
1491     case DT_VERNEEDNUM:	return "VERNEEDNUM";
1492 
1493     case DT_AUXILIARY:	return "AUXILIARY";
1494     case DT_USED:	return "USED";
1495     case DT_FILTER:	return "FILTER";
1496 
1497     case DT_GNU_PRELINKED: return "GNU_PRELINKED";
1498     case DT_GNU_CONFLICT: return "GNU_CONFLICT";
1499     case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
1500     case DT_GNU_LIBLIST: return "GNU_LIBLIST";
1501     case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
1502 
1503     default:
1504       if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1505 	{
1506 	  const char *result;
1507 
1508 	  switch (elf_header.e_machine)
1509 	    {
1510 	    case EM_MIPS:
1511 	    case EM_MIPS_RS3_LE:
1512 	      result = get_mips_dynamic_type (type);
1513 	      break;
1514 	    case EM_SPARCV9:
1515 	      result = get_sparc64_dynamic_type (type);
1516 	      break;
1517 	    case EM_PPC:
1518 	      result = get_ppc_dynamic_type (type);
1519 	      break;
1520 	    case EM_PPC64:
1521 	      result = get_ppc64_dynamic_type (type);
1522 	      break;
1523 	    case EM_IA_64:
1524 	      result = get_ia64_dynamic_type (type);
1525 	      break;
1526 	    case EM_ALPHA:
1527 	      result = get_alpha_dynamic_type (type);
1528 	      break;
1529 	    default:
1530 	      result = NULL;
1531 	      break;
1532 	    }
1533 
1534 	  if (result != NULL)
1535 	    return result;
1536 
1537 	  snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
1538 	}
1539       else if (((type >= DT_LOOS) && (type <= DT_HIOS))
1540 	       || (elf_header.e_machine == EM_PARISC
1541 		   && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
1542 	{
1543 	  const char *result;
1544 
1545 	  switch (elf_header.e_machine)
1546 	    {
1547 	    case EM_PARISC:
1548 	      result = get_parisc_dynamic_type (type);
1549 	      break;
1550 	    default:
1551 	      result = NULL;
1552 	      break;
1553 	    }
1554 
1555 	  if (result != NULL)
1556 	    return result;
1557 
1558 	  snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
1559 		    type);
1560 	}
1561       else
1562 	snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
1563 
1564       return buff;
1565     }
1566 }
1567 
1568 static char *
1569 get_file_type (unsigned e_type)
1570 {
1571   static char buff[32];
1572 
1573   switch (e_type)
1574     {
1575     case ET_NONE:	return _("NONE (None)");
1576     case ET_REL:	return _("REL (Relocatable file)");
1577     case ET_EXEC:	return _("EXEC (Executable file)");
1578     case ET_DYN:	return _("DYN (Shared object file)");
1579     case ET_CORE:	return _("CORE (Core file)");
1580 
1581     default:
1582       if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1583 	snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
1584       else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1585 	snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
1586       else
1587 	snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
1588       return buff;
1589     }
1590 }
1591 
1592 static char *
1593 get_machine_name (unsigned e_machine)
1594 {
1595   static char buff[64]; /* XXX */
1596 
1597   switch (e_machine)
1598     {
1599     case EM_NONE:		return _("None");
1600     case EM_M32:		return "WE32100";
1601     case EM_SPARC:		return "Sparc";
1602     case EM_386:		return "Intel 80386";
1603     case EM_68K:		return "MC68000";
1604     case EM_88K:		return "MC88000";
1605     case EM_486:		return "Intel 80486";
1606     case EM_860:		return "Intel 80860";
1607     case EM_MIPS:		return "MIPS R3000";
1608     case EM_S370:		return "IBM System/370";
1609     case EM_MIPS_RS3_LE:	return "MIPS R4000 big-endian";
1610     case EM_OLD_SPARCV9:	return "Sparc v9 (old)";
1611     case EM_PARISC:		return "HPPA";
1612     case EM_PPC_OLD:		return "Power PC (old)";
1613     case EM_SPARC32PLUS:	return "Sparc v8+" ;
1614     case EM_960:		return "Intel 90860";
1615     case EM_PPC:		return "PowerPC";
1616     case EM_PPC64:		return "PowerPC64";
1617     case EM_V800:		return "NEC V800";
1618     case EM_FR20:		return "Fujitsu FR20";
1619     case EM_RH32:		return "TRW RH32";
1620     case EM_MCORE:		return "MCORE";
1621     case EM_ARM:		return "ARM";
1622     case EM_OLD_ALPHA:		return "Digital Alpha (old)";
1623     case EM_SH:			return "Renesas / SuperH SH";
1624     case EM_SPARCV9:		return "Sparc v9";
1625     case EM_TRICORE:		return "Siemens Tricore";
1626     case EM_ARC:		return "ARC";
1627     case EM_H8_300:		return "Renesas H8/300";
1628     case EM_H8_300H:		return "Renesas H8/300H";
1629     case EM_H8S:		return "Renesas H8S";
1630     case EM_H8_500:		return "Renesas H8/500";
1631     case EM_IA_64:		return "Intel IA-64";
1632     case EM_MIPS_X:		return "Stanford MIPS-X";
1633     case EM_COLDFIRE:		return "Motorola Coldfire";
1634     case EM_68HC12:		return "Motorola M68HC12";
1635     case EM_ALPHA:		return "Alpha";
1636     case EM_CYGNUS_D10V:
1637     case EM_D10V:		return "d10v";
1638     case EM_CYGNUS_D30V:
1639     case EM_D30V:		return "d30v";
1640     case EM_CYGNUS_M32R:
1641     case EM_M32R:		return "Renesas M32R (formerly Mitsubishi M32r)";
1642     case EM_CYGNUS_V850:
1643     case EM_V850:		return "NEC v850";
1644     case EM_CYGNUS_MN10300:
1645     case EM_MN10300:		return "mn10300";
1646     case EM_CYGNUS_MN10200:
1647     case EM_MN10200:		return "mn10200";
1648     case EM_CYGNUS_FR30:
1649     case EM_FR30:		return "Fujitsu FR30";
1650     case EM_CYGNUS_FRV:		return "Fujitsu FR-V";
1651     case EM_PJ_OLD:
1652     case EM_PJ:			return "picoJava";
1653     case EM_MMA:		return "Fujitsu Multimedia Accelerator";
1654     case EM_PCP:		return "Siemens PCP";
1655     case EM_NCPU:		return "Sony nCPU embedded RISC processor";
1656     case EM_NDR1:		return "Denso NDR1 microprocesspr";
1657     case EM_STARCORE:		return "Motorola Star*Core processor";
1658     case EM_ME16:		return "Toyota ME16 processor";
1659     case EM_ST100:		return "STMicroelectronics ST100 processor";
1660     case EM_TINYJ:		return "Advanced Logic Corp. TinyJ embedded processor";
1661     case EM_FX66:		return "Siemens FX66 microcontroller";
1662     case EM_ST9PLUS:		return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1663     case EM_ST7:		return "STMicroelectronics ST7 8-bit microcontroller";
1664     case EM_68HC16:		return "Motorola MC68HC16 Microcontroller";
1665     case EM_68HC11:		return "Motorola MC68HC11 Microcontroller";
1666     case EM_68HC08:		return "Motorola MC68HC08 Microcontroller";
1667     case EM_68HC05:		return "Motorola MC68HC05 Microcontroller";
1668     case EM_SVX:		return "Silicon Graphics SVx";
1669     case EM_ST19:		return "STMicroelectronics ST19 8-bit microcontroller";
1670     case EM_VAX:		return "Digital VAX";
1671     case EM_AVR_OLD:
1672     case EM_AVR:		return "Atmel AVR 8-bit microcontroller";
1673     case EM_CRIS:		return "Axis Communications 32-bit embedded processor";
1674     case EM_JAVELIN:		return "Infineon Technologies 32-bit embedded cpu";
1675     case EM_FIREPATH:		return "Element 14 64-bit DSP processor";
1676     case EM_ZSP:		return "LSI Logic's 16-bit DSP processor";
1677     case EM_MMIX:		return "Donald Knuth's educational 64-bit processor";
1678     case EM_HUANY:		return "Harvard Universitys's machine-independent object format";
1679     case EM_PRISM:		return "Vitesse Prism";
1680     case EM_X86_64:		return "Advanced Micro Devices X86-64";
1681     case EM_S390_OLD:
1682     case EM_S390:		return "IBM S/390";
1683     case EM_XSTORMY16:		return "Sanyo Xstormy16 CPU core";
1684     case EM_OPENRISC:
1685     case EM_OR32:		return "OpenRISC";
1686     case EM_CRX:		return "National Semiconductor CRX microprocessor";
1687     case EM_DLX:		return "OpenDLX";
1688     case EM_IP2K_OLD:
1689     case EM_IP2K:		return "Ubicom IP2xxx 8-bit microcontrollers";
1690     case EM_IQ2000:       	return "Vitesse IQ2000";
1691     case EM_XTENSA_OLD:
1692     case EM_XTENSA:		return "Tensilica Xtensa Processor";
1693     case EM_M32C:	        return "Renesas M32c";
1694     case EM_MT:                 return "Morpho Techologies MT processor";
1695     case EM_BLACKFIN:		return "Analog Devices Blackfin";
1696     case EM_NIOS32:		return "Altera Nios";
1697     case EM_ALTERA_NIOS2:	return "Altera Nios II";
1698     case EM_XC16X:		return "Infineon Technologies xc16x";
1699     default:
1700       snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_machine);
1701       return buff;
1702     }
1703 }
1704 
1705 static void
1706 decode_ARM_machine_flags (unsigned e_flags, char buf[])
1707 {
1708   unsigned eabi;
1709   int unknown = 0;
1710 
1711   eabi = EF_ARM_EABI_VERSION (e_flags);
1712   e_flags &= ~ EF_ARM_EABIMASK;
1713 
1714   /* Handle "generic" ARM flags.  */
1715   if (e_flags & EF_ARM_RELEXEC)
1716     {
1717       strcat (buf, ", relocatable executable");
1718       e_flags &= ~ EF_ARM_RELEXEC;
1719     }
1720 
1721   if (e_flags & EF_ARM_HASENTRY)
1722     {
1723       strcat (buf, ", has entry point");
1724       e_flags &= ~ EF_ARM_HASENTRY;
1725     }
1726 
1727   /* Now handle EABI specific flags.  */
1728   switch (eabi)
1729     {
1730     default:
1731       strcat (buf, ", <unrecognized EABI>");
1732       if (e_flags)
1733 	unknown = 1;
1734       break;
1735 
1736     case EF_ARM_EABI_VER1:
1737       strcat (buf, ", Version1 EABI");
1738       while (e_flags)
1739 	{
1740 	  unsigned flag;
1741 
1742 	  /* Process flags one bit at a time.  */
1743 	  flag = e_flags & - e_flags;
1744 	  e_flags &= ~ flag;
1745 
1746 	  switch (flag)
1747 	    {
1748 	    case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK.  */
1749 	      strcat (buf, ", sorted symbol tables");
1750 	      break;
1751 
1752 	    default:
1753 	      unknown = 1;
1754 	      break;
1755 	    }
1756 	}
1757       break;
1758 
1759     case EF_ARM_EABI_VER2:
1760       strcat (buf, ", Version2 EABI");
1761       while (e_flags)
1762 	{
1763 	  unsigned flag;
1764 
1765 	  /* Process flags one bit at a time.  */
1766 	  flag = e_flags & - e_flags;
1767 	  e_flags &= ~ flag;
1768 
1769 	  switch (flag)
1770 	    {
1771 	    case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK.  */
1772 	      strcat (buf, ", sorted symbol tables");
1773 	      break;
1774 
1775 	    case EF_ARM_DYNSYMSUSESEGIDX:
1776 	      strcat (buf, ", dynamic symbols use segment index");
1777 	      break;
1778 
1779 	    case EF_ARM_MAPSYMSFIRST:
1780 	      strcat (buf, ", mapping symbols precede others");
1781 	      break;
1782 
1783 	    default:
1784 	      unknown = 1;
1785 	      break;
1786 	    }
1787 	}
1788       break;
1789 
1790     case EF_ARM_EABI_VER3:
1791       strcat (buf, ", Version3 EABI");
1792       break;
1793 
1794     case EF_ARM_EABI_VER4:
1795       strcat (buf, ", Version4 EABI");
1796       goto eabi;
1797 
1798     case EF_ARM_EABI_VER5:
1799       strcat (buf, ", Version5 EABI");
1800     eabi:
1801       while (e_flags)
1802 	{
1803 	  unsigned flag;
1804 
1805 	  /* Process flags one bit at a time.  */
1806 	  flag = e_flags & - e_flags;
1807 	  e_flags &= ~ flag;
1808 
1809 	  switch (flag)
1810 	    {
1811 	    case EF_ARM_BE8:
1812 	      strcat (buf, ", BE8");
1813 	      break;
1814 
1815 	    case EF_ARM_LE8:
1816 	      strcat (buf, ", LE8");
1817 	      break;
1818 
1819 	    default:
1820 	      unknown = 1;
1821 	      break;
1822 	    }
1823 	}
1824       break;
1825 
1826     case EF_ARM_EABI_UNKNOWN:
1827       strcat (buf, ", GNU EABI");
1828       while (e_flags)
1829 	{
1830 	  unsigned flag;
1831 
1832 	  /* Process flags one bit at a time.  */
1833 	  flag = e_flags & - e_flags;
1834 	  e_flags &= ~ flag;
1835 
1836 	  switch (flag)
1837 	    {
1838 	    case EF_ARM_INTERWORK:
1839 	      strcat (buf, ", interworking enabled");
1840 	      break;
1841 
1842 	    case EF_ARM_APCS_26:
1843 	      strcat (buf, ", uses APCS/26");
1844 	      break;
1845 
1846 	    case EF_ARM_APCS_FLOAT:
1847 	      strcat (buf, ", uses APCS/float");
1848 	      break;
1849 
1850 	    case EF_ARM_PIC:
1851 	      strcat (buf, ", position independent");
1852 	      break;
1853 
1854 	    case EF_ARM_ALIGN8:
1855 	      strcat (buf, ", 8 bit structure alignment");
1856 	      break;
1857 
1858 	    case EF_ARM_NEW_ABI:
1859 	      strcat (buf, ", uses new ABI");
1860 	      break;
1861 
1862 	    case EF_ARM_OLD_ABI:
1863 	      strcat (buf, ", uses old ABI");
1864 	      break;
1865 
1866 	    case EF_ARM_SOFT_FLOAT:
1867 	      strcat (buf, ", software FP");
1868 	      break;
1869 
1870 	    case EF_ARM_VFP_FLOAT:
1871 	      strcat (buf, ", VFP");
1872 	      break;
1873 
1874 	    case EF_ARM_MAVERICK_FLOAT:
1875 	      strcat (buf, ", Maverick FP");
1876 	      break;
1877 
1878 	    default:
1879 	      unknown = 1;
1880 	      break;
1881 	    }
1882 	}
1883     }
1884 
1885   if (unknown)
1886     strcat (buf,", <unknown>");
1887 }
1888 
1889 static char *
1890 get_machine_flags (unsigned e_flags, unsigned e_machine)
1891 {
1892   static char buf[1024];
1893 
1894   buf[0] = '\0';
1895 
1896   if (e_flags)
1897     {
1898       switch (e_machine)
1899 	{
1900 	default:
1901 	  break;
1902 
1903 	case EM_ARM:
1904 	  decode_ARM_machine_flags (e_flags, buf);
1905 	  break;
1906 
1907 	case EM_CYGNUS_FRV:
1908 	  switch (e_flags & EF_FRV_CPU_MASK)
1909 	    {
1910 	    case EF_FRV_CPU_GENERIC:
1911 	      break;
1912 
1913 	    default:
1914 	      strcat (buf, ", fr???");
1915 	      break;
1916 
1917 	    case EF_FRV_CPU_FR300:
1918 	      strcat (buf, ", fr300");
1919 	      break;
1920 
1921 	    case EF_FRV_CPU_FR400:
1922 	      strcat (buf, ", fr400");
1923 	      break;
1924 	    case EF_FRV_CPU_FR405:
1925 	      strcat (buf, ", fr405");
1926 	      break;
1927 
1928 	    case EF_FRV_CPU_FR450:
1929 	      strcat (buf, ", fr450");
1930 	      break;
1931 
1932 	    case EF_FRV_CPU_FR500:
1933 	      strcat (buf, ", fr500");
1934 	      break;
1935 	    case EF_FRV_CPU_FR550:
1936 	      strcat (buf, ", fr550");
1937 	      break;
1938 
1939 	    case EF_FRV_CPU_SIMPLE:
1940 	      strcat (buf, ", simple");
1941 	      break;
1942 	    case EF_FRV_CPU_TOMCAT:
1943 	      strcat (buf, ", tomcat");
1944 	      break;
1945 	    }
1946 	  break;
1947 
1948 	case EM_68K:
1949 	  if (e_flags & EF_M68K_CPU32)
1950 	    strcat (buf, ", cpu32");
1951 	  if (e_flags & EF_M68K_M68000)
1952 	    strcat (buf, ", m68000");
1953 	  if (e_flags & EF_M68K_ISA_MASK)
1954 	    {
1955 	      char const *isa = _("unknown");
1956 	      char const *mac = _("unknown mac");
1957 	      char const *additional = NULL;
1958 
1959 	      switch (e_flags & EF_M68K_ISA_MASK)
1960 		{
1961 		case EF_M68K_ISA_A_NODIV:
1962 		  isa = "A";
1963 		  additional = ", nodiv";
1964 		  break;
1965 		case EF_M68K_ISA_A:
1966 		  isa = "A";
1967 		  break;
1968 		case EF_M68K_ISA_A_PLUS:
1969 		  isa = "A+";
1970 		  break;
1971 		case EF_M68K_ISA_B_NOUSP:
1972 		  isa = "B";
1973 		  additional = ", nousp";
1974 		  break;
1975 		case EF_M68K_ISA_B:
1976 		  isa = "B";
1977 		  break;
1978 		}
1979 	      strcat (buf, ", cf, isa ");
1980 	      strcat (buf, isa);
1981 	      if (additional)
1982 		strcat (buf, additional);
1983 	      if (e_flags & EF_M68K_FLOAT)
1984 		strcat (buf, ", float");
1985 	      switch (e_flags & EF_M68K_MAC_MASK)
1986 		{
1987 		case 0:
1988 		  mac = NULL;
1989 		  break;
1990 		case EF_M68K_MAC:
1991 		  mac = "mac";
1992 		  break;
1993 		case EF_M68K_EMAC:
1994 		  mac = "emac";
1995 		  break;
1996 		}
1997 	      if (mac)
1998 		{
1999 		  strcat (buf, ", ");
2000 		  strcat (buf, mac);
2001 		}
2002 	    }
2003 	  break;
2004 
2005 	case EM_PPC:
2006 	  if (e_flags & EF_PPC_EMB)
2007 	    strcat (buf, ", emb");
2008 
2009 	  if (e_flags & EF_PPC_RELOCATABLE)
2010 	    strcat (buf, ", relocatable");
2011 
2012 	  if (e_flags & EF_PPC_RELOCATABLE_LIB)
2013 	    strcat (buf, ", relocatable-lib");
2014 	  break;
2015 
2016 	case EM_V850:
2017 	case EM_CYGNUS_V850:
2018 	  switch (e_flags & EF_V850_ARCH)
2019 	    {
2020 	    case E_V850E1_ARCH:
2021 	      strcat (buf, ", v850e1");
2022 	      break;
2023 	    case E_V850E_ARCH:
2024 	      strcat (buf, ", v850e");
2025 	      break;
2026 	    case E_V850_ARCH:
2027 	      strcat (buf, ", v850");
2028 	      break;
2029 	    default:
2030 	      strcat (buf, ", unknown v850 architecture variant");
2031 	      break;
2032 	    }
2033 	  break;
2034 
2035 	case EM_M32R:
2036 	case EM_CYGNUS_M32R:
2037 	  if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
2038 	    strcat (buf, ", m32r");
2039 
2040 	  break;
2041 
2042 	case EM_MIPS:
2043 	case EM_MIPS_RS3_LE:
2044 	  if (e_flags & EF_MIPS_NOREORDER)
2045 	    strcat (buf, ", noreorder");
2046 
2047 	  if (e_flags & EF_MIPS_PIC)
2048 	    strcat (buf, ", pic");
2049 
2050 	  if (e_flags & EF_MIPS_CPIC)
2051 	    strcat (buf, ", cpic");
2052 
2053 	  if (e_flags & EF_MIPS_UCODE)
2054 	    strcat (buf, ", ugen_reserved");
2055 
2056 	  if (e_flags & EF_MIPS_ABI2)
2057 	    strcat (buf, ", abi2");
2058 
2059 	  if (e_flags & EF_MIPS_OPTIONS_FIRST)
2060 	    strcat (buf, ", odk first");
2061 
2062 	  if (e_flags & EF_MIPS_32BITMODE)
2063 	    strcat (buf, ", 32bitmode");
2064 
2065 	  switch ((e_flags & EF_MIPS_MACH))
2066 	    {
2067 	    case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
2068 	    case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
2069 	    case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
2070 	    case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
2071 	    case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
2072 	    case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
2073 	    case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
2074 	    case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
2075 	    case E_MIPS_MACH_SB1:  strcat (buf, ", sb1");  break;
2076 	    case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
2077 	    case 0:
2078 	    /* We simply ignore the field in this case to avoid confusion:
2079 	       MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2080 	       extension.  */
2081 	      break;
2082 	    default: strcat (buf, ", unknown CPU"); break;
2083 	    }
2084 
2085 	  switch ((e_flags & EF_MIPS_ABI))
2086 	    {
2087 	    case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
2088 	    case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
2089 	    case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
2090 	    case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
2091 	    case 0:
2092 	    /* We simply ignore the field in this case to avoid confusion:
2093 	       MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2094 	       This means it is likely to be an o32 file, but not for
2095 	       sure.  */
2096 	      break;
2097 	    default: strcat (buf, ", unknown ABI"); break;
2098 	    }
2099 
2100 	  if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
2101 	    strcat (buf, ", mdmx");
2102 
2103 	  if (e_flags & EF_MIPS_ARCH_ASE_M16)
2104 	    strcat (buf, ", mips16");
2105 
2106 	  switch ((e_flags & EF_MIPS_ARCH))
2107 	    {
2108 	    case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
2109 	    case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
2110 	    case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
2111 	    case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
2112 	    case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
2113 	    case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
2114 	    case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
2115 	    case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
2116 	    case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
2117 	    default: strcat (buf, ", unknown ISA"); break;
2118 	    }
2119 
2120 	  break;
2121 
2122 	case EM_SH:
2123 	  switch ((e_flags & EF_SH_MACH_MASK))
2124 	    {
2125 	    case EF_SH1: strcat (buf, ", sh1"); break;
2126 	    case EF_SH2: strcat (buf, ", sh2"); break;
2127 	    case EF_SH3: strcat (buf, ", sh3"); break;
2128 	    case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
2129 	    case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
2130 	    case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
2131 	    case EF_SH3E: strcat (buf, ", sh3e"); break;
2132 	    case EF_SH4: strcat (buf, ", sh4"); break;
2133 	    case EF_SH5: strcat (buf, ", sh5"); break;
2134 	    case EF_SH2E: strcat (buf, ", sh2e"); break;
2135 	    case EF_SH4A: strcat (buf, ", sh4a"); break;
2136 	    case EF_SH2A: strcat (buf, ", sh2a"); break;
2137 	    case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
2138 	    case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
2139 	    case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
2140 	    case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
2141 	    case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
2142 	    case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2143 	    case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
2144 	    case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
2145 	    case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
2146 	    default: strcat (buf, ", unknown ISA"); break;
2147 	    }
2148 
2149 	  break;
2150 
2151 	case EM_SPARCV9:
2152 	  if (e_flags & EF_SPARC_32PLUS)
2153 	    strcat (buf, ", v8+");
2154 
2155 	  if (e_flags & EF_SPARC_SUN_US1)
2156 	    strcat (buf, ", ultrasparcI");
2157 
2158 	  if (e_flags & EF_SPARC_SUN_US3)
2159 	    strcat (buf, ", ultrasparcIII");
2160 
2161 	  if (e_flags & EF_SPARC_HAL_R1)
2162 	    strcat (buf, ", halr1");
2163 
2164 	  if (e_flags & EF_SPARC_LEDATA)
2165 	    strcat (buf, ", ledata");
2166 
2167 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
2168 	    strcat (buf, ", tso");
2169 
2170 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
2171 	    strcat (buf, ", pso");
2172 
2173 	  if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
2174 	    strcat (buf, ", rmo");
2175 	  break;
2176 
2177 	case EM_PARISC:
2178 	  switch (e_flags & EF_PARISC_ARCH)
2179 	    {
2180 	    case EFA_PARISC_1_0:
2181 	      strcpy (buf, ", PA-RISC 1.0");
2182 	      break;
2183 	    case EFA_PARISC_1_1:
2184 	      strcpy (buf, ", PA-RISC 1.1");
2185 	      break;
2186 	    case EFA_PARISC_2_0:
2187 	      strcpy (buf, ", PA-RISC 2.0");
2188 	      break;
2189 	    default:
2190 	      break;
2191 	    }
2192 	  if (e_flags & EF_PARISC_TRAPNIL)
2193 	    strcat (buf, ", trapnil");
2194 	  if (e_flags & EF_PARISC_EXT)
2195 	    strcat (buf, ", ext");
2196 	  if (e_flags & EF_PARISC_LSB)
2197 	    strcat (buf, ", lsb");
2198 	  if (e_flags & EF_PARISC_WIDE)
2199 	    strcat (buf, ", wide");
2200 	  if (e_flags & EF_PARISC_NO_KABP)
2201 	    strcat (buf, ", no kabp");
2202 	  if (e_flags & EF_PARISC_LAZYSWAP)
2203 	    strcat (buf, ", lazyswap");
2204 	  break;
2205 
2206 	case EM_PJ:
2207 	case EM_PJ_OLD:
2208 	  if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
2209 	    strcat (buf, ", new calling convention");
2210 
2211 	  if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
2212 	    strcat (buf, ", gnu calling convention");
2213 	  break;
2214 
2215 	case EM_IA_64:
2216 	  if ((e_flags & EF_IA_64_ABI64))
2217 	    strcat (buf, ", 64-bit");
2218 	  else
2219 	    strcat (buf, ", 32-bit");
2220 	  if ((e_flags & EF_IA_64_REDUCEDFP))
2221 	    strcat (buf, ", reduced fp model");
2222 	  if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
2223 	    strcat (buf, ", no function descriptors, constant gp");
2224 	  else if ((e_flags & EF_IA_64_CONS_GP))
2225 	    strcat (buf, ", constant gp");
2226 	  if ((e_flags & EF_IA_64_ABSOLUTE))
2227 	    strcat (buf, ", absolute");
2228 	  break;
2229 
2230 	case EM_VAX:
2231 	  if ((e_flags & EF_VAX_NONPIC))
2232 	    strcat (buf, ", non-PIC");
2233 	  if ((e_flags & EF_VAX_DFLOAT))
2234 	    strcat (buf, ", D-Float");
2235 	  if ((e_flags & EF_VAX_GFLOAT))
2236 	    strcat (buf, ", G-Float");
2237 	  break;
2238 	}
2239     }
2240 
2241   return buf;
2242 }
2243 
2244 static const char *
2245 get_osabi_name (unsigned int osabi)
2246 {
2247   static char buff[32];
2248 
2249   switch (osabi)
2250     {
2251     case ELFOSABI_NONE:		return "UNIX - System V";
2252     case ELFOSABI_HPUX:		return "UNIX - HP-UX";
2253     case ELFOSABI_NETBSD:	return "UNIX - NetBSD";
2254     case ELFOSABI_LINUX:	return "UNIX - Linux";
2255     case ELFOSABI_HURD:		return "GNU/Hurd";
2256     case ELFOSABI_SOLARIS:	return "UNIX - Solaris";
2257     case ELFOSABI_AIX:		return "UNIX - AIX";
2258     case ELFOSABI_IRIX:		return "UNIX - IRIX";
2259     case ELFOSABI_FREEBSD:	return "UNIX - FreeBSD";
2260     case ELFOSABI_TRU64:	return "UNIX - TRU64";
2261     case ELFOSABI_MODESTO:	return "Novell - Modesto";
2262     case ELFOSABI_OPENBSD:	return "UNIX - OpenBSD";
2263     case ELFOSABI_OPENVMS:	return "VMS - OpenVMS";
2264     case ELFOSABI_NSK:		return "HP - Non-Stop Kernel";
2265     case ELFOSABI_AROS:		return "Amiga Research OS";
2266     case ELFOSABI_STANDALONE:	return _("Standalone App");
2267     case ELFOSABI_ARM:		return "ARM";
2268     default:
2269       snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
2270       return buff;
2271     }
2272 }
2273 
2274 static const char *
2275 get_arm_segment_type (unsigned long type)
2276 {
2277   switch (type)
2278     {
2279     case PT_ARM_EXIDX:
2280       return "EXIDX";
2281     default:
2282       break;
2283     }
2284 
2285   return NULL;
2286 }
2287 
2288 static const char *
2289 get_mips_segment_type (unsigned long type)
2290 {
2291   switch (type)
2292     {
2293     case PT_MIPS_REGINFO:
2294       return "REGINFO";
2295     case PT_MIPS_RTPROC:
2296       return "RTPROC";
2297     case PT_MIPS_OPTIONS:
2298       return "OPTIONS";
2299     default:
2300       break;
2301     }
2302 
2303   return NULL;
2304 }
2305 
2306 static const char *
2307 get_parisc_segment_type (unsigned long type)
2308 {
2309   switch (type)
2310     {
2311     case PT_HP_TLS:		return "HP_TLS";
2312     case PT_HP_CORE_NONE:	return "HP_CORE_NONE";
2313     case PT_HP_CORE_VERSION:	return "HP_CORE_VERSION";
2314     case PT_HP_CORE_KERNEL:	return "HP_CORE_KERNEL";
2315     case PT_HP_CORE_COMM:	return "HP_CORE_COMM";
2316     case PT_HP_CORE_PROC:	return "HP_CORE_PROC";
2317     case PT_HP_CORE_LOADABLE:	return "HP_CORE_LOADABLE";
2318     case PT_HP_CORE_STACK:	return "HP_CORE_STACK";
2319     case PT_HP_CORE_SHM:	return "HP_CORE_SHM";
2320     case PT_HP_CORE_MMF:	return "HP_CORE_MMF";
2321     case PT_HP_PARALLEL:	return "HP_PARALLEL";
2322     case PT_HP_FASTBIND:	return "HP_FASTBIND";
2323     case PT_HP_OPT_ANNOT:	return "HP_OPT_ANNOT";
2324     case PT_HP_HSL_ANNOT:	return "HP_HSL_ANNOT";
2325     case PT_HP_STACK:		return "HP_STACK";
2326     case PT_HP_CORE_UTSNAME:	return "HP_CORE_UTSNAME";
2327     case PT_PARISC_ARCHEXT:	return "PARISC_ARCHEXT";
2328     case PT_PARISC_UNWIND:	return "PARISC_UNWIND";
2329     case PT_PARISC_WEAKORDER:	return "PARISC_WEAKORDER";
2330     default:
2331       break;
2332     }
2333 
2334   return NULL;
2335 }
2336 
2337 static const char *
2338 get_ia64_segment_type (unsigned long type)
2339 {
2340   switch (type)
2341     {
2342     case PT_IA_64_ARCHEXT:	return "IA_64_ARCHEXT";
2343     case PT_IA_64_UNWIND:	return "IA_64_UNWIND";
2344     case PT_HP_TLS:		return "HP_TLS";
2345     case PT_IA_64_HP_OPT_ANOT:	return "HP_OPT_ANNOT";
2346     case PT_IA_64_HP_HSL_ANOT:	return "HP_HSL_ANNOT";
2347     case PT_IA_64_HP_STACK:	return "HP_STACK";
2348     default:
2349       break;
2350     }
2351 
2352   return NULL;
2353 }
2354 
2355 static const char *
2356 get_segment_type (unsigned long p_type)
2357 {
2358   static char buff[32];
2359 
2360   switch (p_type)
2361     {
2362     case PT_NULL:	return "NULL";
2363     case PT_LOAD:	return "LOAD";
2364     case PT_DYNAMIC:	return "DYNAMIC";
2365     case PT_INTERP:	return "INTERP";
2366     case PT_NOTE:	return "NOTE";
2367     case PT_SHLIB:	return "SHLIB";
2368     case PT_PHDR:	return "PHDR";
2369     case PT_TLS:	return "TLS";
2370 
2371     case PT_GNU_EH_FRAME:
2372 			return "GNU_EH_FRAME";
2373     case PT_GNU_STACK:	return "GNU_STACK";
2374     case PT_GNU_RELRO:  return "GNU_RELRO";
2375     case PT_OPENBSD_RANDOMIZE:
2376 			return "OPENBSD_RANDOMIZE";
2377 
2378     default:
2379       if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
2380 	{
2381 	  const char *result;
2382 
2383 	  switch (elf_header.e_machine)
2384 	    {
2385 	    case EM_ARM:
2386 	      result = get_arm_segment_type (p_type);
2387 	      break;
2388 	    case EM_MIPS:
2389 	    case EM_MIPS_RS3_LE:
2390 	      result = get_mips_segment_type (p_type);
2391 	      break;
2392 	    case EM_PARISC:
2393 	      result = get_parisc_segment_type (p_type);
2394 	      break;
2395 	    case EM_IA_64:
2396 	      result = get_ia64_segment_type (p_type);
2397 	      break;
2398 	    default:
2399 	      result = NULL;
2400 	      break;
2401 	    }
2402 
2403 	  if (result != NULL)
2404 	    return result;
2405 
2406 	  sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
2407 	}
2408       else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
2409 	{
2410 	  const char *result;
2411 
2412 	  switch (elf_header.e_machine)
2413 	    {
2414 	    case EM_PARISC:
2415 	      result = get_parisc_segment_type (p_type);
2416 	      break;
2417 	    case EM_IA_64:
2418 	      result = get_ia64_segment_type (p_type);
2419 	      break;
2420 	    default:
2421 	      result = NULL;
2422 	      break;
2423 	    }
2424 
2425 	  if (result != NULL)
2426 	    return result;
2427 
2428 	  sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
2429 	}
2430       else
2431 	snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
2432 
2433       return buff;
2434     }
2435 }
2436 
2437 static const char *
2438 get_mips_section_type_name (unsigned int sh_type)
2439 {
2440   switch (sh_type)
2441     {
2442     case SHT_MIPS_LIBLIST:	 return "MIPS_LIBLIST";
2443     case SHT_MIPS_MSYM:		 return "MIPS_MSYM";
2444     case SHT_MIPS_CONFLICT:	 return "MIPS_CONFLICT";
2445     case SHT_MIPS_GPTAB:	 return "MIPS_GPTAB";
2446     case SHT_MIPS_UCODE:	 return "MIPS_UCODE";
2447     case SHT_MIPS_DEBUG:	 return "MIPS_DEBUG";
2448     case SHT_MIPS_REGINFO:	 return "MIPS_REGINFO";
2449     case SHT_MIPS_PACKAGE:	 return "MIPS_PACKAGE";
2450     case SHT_MIPS_PACKSYM:	 return "MIPS_PACKSYM";
2451     case SHT_MIPS_RELD:		 return "MIPS_RELD";
2452     case SHT_MIPS_IFACE:	 return "MIPS_IFACE";
2453     case SHT_MIPS_CONTENT:	 return "MIPS_CONTENT";
2454     case SHT_MIPS_OPTIONS:	 return "MIPS_OPTIONS";
2455     case SHT_MIPS_SHDR:		 return "MIPS_SHDR";
2456     case SHT_MIPS_FDESC:	 return "MIPS_FDESC";
2457     case SHT_MIPS_EXTSYM:	 return "MIPS_EXTSYM";
2458     case SHT_MIPS_DENSE:	 return "MIPS_DENSE";
2459     case SHT_MIPS_PDESC:	 return "MIPS_PDESC";
2460     case SHT_MIPS_LOCSYM:	 return "MIPS_LOCSYM";
2461     case SHT_MIPS_AUXSYM:	 return "MIPS_AUXSYM";
2462     case SHT_MIPS_OPTSYM:	 return "MIPS_OPTSYM";
2463     case SHT_MIPS_LOCSTR:	 return "MIPS_LOCSTR";
2464     case SHT_MIPS_LINE:		 return "MIPS_LINE";
2465     case SHT_MIPS_RFDESC:	 return "MIPS_RFDESC";
2466     case SHT_MIPS_DELTASYM:	 return "MIPS_DELTASYM";
2467     case SHT_MIPS_DELTAINST:	 return "MIPS_DELTAINST";
2468     case SHT_MIPS_DELTACLASS:	 return "MIPS_DELTACLASS";
2469     case SHT_MIPS_DWARF:	 return "MIPS_DWARF";
2470     case SHT_MIPS_DELTADECL:	 return "MIPS_DELTADECL";
2471     case SHT_MIPS_SYMBOL_LIB:	 return "MIPS_SYMBOL_LIB";
2472     case SHT_MIPS_EVENTS:	 return "MIPS_EVENTS";
2473     case SHT_MIPS_TRANSLATE:	 return "MIPS_TRANSLATE";
2474     case SHT_MIPS_PIXIE:	 return "MIPS_PIXIE";
2475     case SHT_MIPS_XLATE:	 return "MIPS_XLATE";
2476     case SHT_MIPS_XLATE_DEBUG:	 return "MIPS_XLATE_DEBUG";
2477     case SHT_MIPS_WHIRL:	 return "MIPS_WHIRL";
2478     case SHT_MIPS_EH_REGION:	 return "MIPS_EH_REGION";
2479     case SHT_MIPS_XLATE_OLD:	 return "MIPS_XLATE_OLD";
2480     case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2481     default:
2482       break;
2483     }
2484   return NULL;
2485 }
2486 
2487 static const char *
2488 get_parisc_section_type_name (unsigned int sh_type)
2489 {
2490   switch (sh_type)
2491     {
2492     case SHT_PARISC_EXT:	return "PARISC_EXT";
2493     case SHT_PARISC_UNWIND:	return "PARISC_UNWIND";
2494     case SHT_PARISC_DOC:	return "PARISC_DOC";
2495     case SHT_PARISC_ANNOT:	return "PARISC_ANNOT";
2496     case SHT_PARISC_SYMEXTN:	return "PARISC_SYMEXTN";
2497     case SHT_PARISC_STUBS:	return "PARISC_STUBS";
2498     case SHT_PARISC_DLKM:	return "PARISC_DLKM";
2499     default:
2500       break;
2501     }
2502   return NULL;
2503 }
2504 
2505 static const char *
2506 get_ia64_section_type_name (unsigned int sh_type)
2507 {
2508   /* If the top 8 bits are 0x78 the next 8 are the os/abi ID.  */
2509   if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
2510     return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
2511 
2512   switch (sh_type)
2513     {
2514     case SHT_IA_64_EXT:		  return "IA_64_EXT";
2515     case SHT_IA_64_UNWIND:	  return "IA_64_UNWIND";
2516     case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
2517     default:
2518       break;
2519     }
2520   return NULL;
2521 }
2522 
2523 static const char *
2524 get_x86_64_section_type_name (unsigned int sh_type)
2525 {
2526   switch (sh_type)
2527     {
2528     case SHT_X86_64_UNWIND:	return "X86_64_UNWIND";
2529     default:
2530       break;
2531     }
2532   return NULL;
2533 }
2534 
2535 static const char *
2536 get_arm_section_type_name (unsigned int sh_type)
2537 {
2538   switch (sh_type)
2539     {
2540     case SHT_ARM_EXIDX:
2541       return "ARM_EXIDX";
2542     case SHT_ARM_PREEMPTMAP:
2543       return "ARM_PREEMPTMAP";
2544     case SHT_ARM_ATTRIBUTES:
2545       return "ARM_ATTRIBUTES";
2546     default:
2547       break;
2548     }
2549   return NULL;
2550 }
2551 
2552 static const char *
2553 get_section_type_name (unsigned int sh_type)
2554 {
2555   static char buff[32];
2556 
2557   switch (sh_type)
2558     {
2559     case SHT_NULL:		return "NULL";
2560     case SHT_PROGBITS:		return "PROGBITS";
2561     case SHT_SYMTAB:		return "SYMTAB";
2562     case SHT_STRTAB:		return "STRTAB";
2563     case SHT_RELA:		return "RELA";
2564     case SHT_HASH:		return "HASH";
2565     case SHT_DYNAMIC:		return "DYNAMIC";
2566     case SHT_NOTE:		return "NOTE";
2567     case SHT_NOBITS:		return "NOBITS";
2568     case SHT_REL:		return "REL";
2569     case SHT_SHLIB:		return "SHLIB";
2570     case SHT_DYNSYM:		return "DYNSYM";
2571     case SHT_INIT_ARRAY:	return "INIT_ARRAY";
2572     case SHT_FINI_ARRAY:	return "FINI_ARRAY";
2573     case SHT_PREINIT_ARRAY:	return "PREINIT_ARRAY";
2574     case SHT_GROUP:		return "GROUP";
2575     case SHT_SYMTAB_SHNDX:	return "SYMTAB SECTION INDICIES";
2576     case SHT_GNU_verdef:	return "VERDEF";
2577     case SHT_GNU_verneed:	return "VERNEED";
2578     case SHT_GNU_versym:	return "VERSYM";
2579     case 0x6ffffff0:		return "VERSYM";
2580     case 0x6ffffffc:		return "VERDEF";
2581     case 0x7ffffffd:		return "AUXILIARY";
2582     case 0x7fffffff:		return "FILTER";
2583     case SHT_GNU_LIBLIST:	return "GNU_LIBLIST";
2584 
2585     default:
2586       if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2587 	{
2588 	  const char *result;
2589 
2590 	  switch (elf_header.e_machine)
2591 	    {
2592 	    case EM_MIPS:
2593 	    case EM_MIPS_RS3_LE:
2594 	      result = get_mips_section_type_name (sh_type);
2595 	      break;
2596 	    case EM_PARISC:
2597 	      result = get_parisc_section_type_name (sh_type);
2598 	      break;
2599 	    case EM_IA_64:
2600 	      result = get_ia64_section_type_name (sh_type);
2601 	      break;
2602 	    case EM_X86_64:
2603 	      result = get_x86_64_section_type_name (sh_type);
2604 	      break;
2605 	    case EM_ARM:
2606 	      result = get_arm_section_type_name (sh_type);
2607 	      break;
2608 	    default:
2609 	      result = NULL;
2610 	      break;
2611 	    }
2612 
2613 	  if (result != NULL)
2614 	    return result;
2615 
2616 	  sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2617 	}
2618       else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2619 	sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2620       else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2621 	sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2622       else
2623 	snprintf (buff, sizeof (buff), _("<unknown>: %x"), sh_type);
2624 
2625       return buff;
2626     }
2627 }
2628 
2629 #define OPTION_DEBUG_DUMP	512
2630 
2631 static struct option options[] =
2632 {
2633   {"all",	       no_argument, 0, 'a'},
2634   {"file-header",      no_argument, 0, 'h'},
2635   {"program-headers",  no_argument, 0, 'l'},
2636   {"headers",	       no_argument, 0, 'e'},
2637   {"histogram",	       no_argument, 0, 'I'},
2638   {"segments",	       no_argument, 0, 'l'},
2639   {"sections",	       no_argument, 0, 'S'},
2640   {"section-headers",  no_argument, 0, 'S'},
2641   {"section-groups",   no_argument, 0, 'g'},
2642   {"section-details",  no_argument, 0, 't'},
2643   {"full-section-name",no_argument, 0, 'N'},
2644   {"symbols",	       no_argument, 0, 's'},
2645   {"syms",	       no_argument, 0, 's'},
2646   {"relocs",	       no_argument, 0, 'r'},
2647   {"notes",	       no_argument, 0, 'n'},
2648   {"dynamic",	       no_argument, 0, 'd'},
2649   {"arch-specific",    no_argument, 0, 'A'},
2650   {"version-info",     no_argument, 0, 'V'},
2651   {"use-dynamic",      no_argument, 0, 'D'},
2652   {"hex-dump",	       required_argument, 0, 'x'},
2653   {"debug-dump",       optional_argument, 0, OPTION_DEBUG_DUMP},
2654   {"unwind",	       no_argument, 0, 'u'},
2655 #ifdef SUPPORT_DISASSEMBLY
2656   {"instruction-dump", required_argument, 0, 'i'},
2657 #endif
2658 
2659   {"version",	       no_argument, 0, 'v'},
2660   {"wide",	       no_argument, 0, 'W'},
2661   {"help",	       no_argument, 0, 'H'},
2662   {0,		       no_argument, 0, 0}
2663 };
2664 
2665 static void
2666 usage (void)
2667 {
2668   fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
2669   fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
2670   fprintf (stdout, _(" Options are:\n\
2671   -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2672   -h --file-header       Display the ELF file header\n\
2673   -l --program-headers   Display the program headers\n\
2674      --segments          An alias for --program-headers\n\
2675   -S --section-headers   Display the sections' header\n\
2676      --sections          An alias for --section-headers\n\
2677   -g --section-groups    Display the section groups\n\
2678   -t --section-details   Display the section details\n\
2679   -e --headers           Equivalent to: -h -l -S\n\
2680   -s --syms              Display the symbol table\n\
2681       --symbols          An alias for --syms\n\
2682   -n --notes             Display the core notes (if present)\n\
2683   -r --relocs            Display the relocations (if present)\n\
2684   -u --unwind            Display the unwind info (if present)\n\
2685   -d --dynamic           Display the dynamic section (if present)\n\
2686   -V --version-info      Display the version sections (if present)\n\
2687   -A --arch-specific     Display architecture specific information (if any).\n\
2688   -D --use-dynamic       Use the dynamic section info when displaying symbols\n\
2689   -x --hex-dump=<number> Dump the contents of section <number>\n\
2690   -w[liaprmfFsoR] or\n\
2691   --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2692                          Display the contents of DWARF2 debug sections\n"));
2693 #ifdef SUPPORT_DISASSEMBLY
2694   fprintf (stdout, _("\
2695   -i --instruction-dump=<number>\n\
2696                          Disassemble the contents of section <number>\n"));
2697 #endif
2698   fprintf (stdout, _("\
2699   -I --histogram         Display histogram of bucket list lengths\n\
2700   -W --wide              Allow output width to exceed 80 characters\n\
2701   @<file>                Read options from <file>\n\
2702   -H --help              Display this information\n\
2703   -v --version           Display the version number of readelf\n"));
2704   fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2705 
2706   exit (0);
2707 }
2708 
2709 /* Record the fact that the user wants the contents of section number
2710    SECTION to be displayed using the method(s) encoded as flags bits
2711    in TYPE.  Note, TYPE can be zero if we are creating the array for
2712    the first time.  */
2713 
2714 static void
2715 request_dump (unsigned int section, int type)
2716 {
2717   if (section >= num_dump_sects)
2718     {
2719       char *new_dump_sects;
2720 
2721       new_dump_sects = calloc (section + 1, 1);
2722 
2723       if (new_dump_sects == NULL)
2724 	error (_("Out of memory allocating dump request table."));
2725       else
2726 	{
2727 	  /* Copy current flag settings.  */
2728 	  memcpy (new_dump_sects, dump_sects, num_dump_sects);
2729 
2730 	  free (dump_sects);
2731 
2732 	  dump_sects = new_dump_sects;
2733 	  num_dump_sects = section + 1;
2734 	}
2735     }
2736 
2737   if (dump_sects)
2738     dump_sects[section] |= type;
2739 
2740   return;
2741 }
2742 
2743 /* Request a dump by section name.  */
2744 
2745 static void
2746 request_dump_byname (const char *section, int type)
2747 {
2748   struct dump_list_entry *new_request;
2749 
2750   new_request = malloc (sizeof (struct dump_list_entry));
2751   if (!new_request)
2752     error (_("Out of memory allocating dump request table."));
2753 
2754   new_request->name = strdup (section);
2755   if (!new_request->name)
2756     error (_("Out of memory allocating dump request table."));
2757 
2758   new_request->type = type;
2759 
2760   new_request->next = dump_sects_byname;
2761   dump_sects_byname = new_request;
2762 }
2763 
2764 static void
2765 parse_args (int argc, char **argv)
2766 {
2767   int c;
2768 
2769   if (argc < 2)
2770     usage ();
2771 
2772   while ((c = getopt_long
2773 	  (argc, argv, "ersuahnldSDAINtgw::x:i:vVWH", options, NULL)) != EOF)
2774     {
2775       char *cp;
2776       int section;
2777 
2778       switch (c)
2779 	{
2780 	case 0:
2781 	  /* Long options.  */
2782 	  break;
2783 	case 'H':
2784 	  usage ();
2785 	  break;
2786 
2787 	case 'a':
2788 	  do_syms++;
2789 	  do_reloc++;
2790 	  do_unwind++;
2791 	  do_dynamic++;
2792 	  do_header++;
2793 	  do_sections++;
2794 	  do_section_groups++;
2795 	  do_segments++;
2796 	  do_version++;
2797 	  do_histogram++;
2798 	  do_arch++;
2799 	  do_notes++;
2800 	  break;
2801 	case 'g':
2802 	  do_section_groups++;
2803 	  break;
2804 	case 't':
2805 	case 'N':
2806 	  do_sections++;
2807 	  do_section_details++;
2808 	  break;
2809 	case 'e':
2810 	  do_header++;
2811 	  do_sections++;
2812 	  do_segments++;
2813 	  break;
2814 	case 'A':
2815 	  do_arch++;
2816 	  break;
2817 	case 'D':
2818 	  do_using_dynamic++;
2819 	  break;
2820 	case 'r':
2821 	  do_reloc++;
2822 	  break;
2823 	case 'u':
2824 	  do_unwind++;
2825 	  break;
2826 	case 'h':
2827 	  do_header++;
2828 	  break;
2829 	case 'l':
2830 	  do_segments++;
2831 	  break;
2832 	case 's':
2833 	  do_syms++;
2834 	  break;
2835 	case 'S':
2836 	  do_sections++;
2837 	  break;
2838 	case 'd':
2839 	  do_dynamic++;
2840 	  break;
2841 	case 'I':
2842 	  do_histogram++;
2843 	  break;
2844 	case 'n':
2845 	  do_notes++;
2846 	  break;
2847 	case 'x':
2848 	  do_dump++;
2849 	  section = strtoul (optarg, & cp, 0);
2850 	  if (! *cp && section >= 0)
2851 	    request_dump (section, HEX_DUMP);
2852 	  else
2853 	    request_dump_byname (optarg, HEX_DUMP);
2854 	  break;
2855 	case 'w':
2856 	  do_dump++;
2857 	  if (optarg == 0)
2858 	    do_debugging = 1;
2859 	  else
2860 	    {
2861 	      unsigned int index = 0;
2862 
2863 	      do_debugging = 0;
2864 
2865 	      while (optarg[index])
2866 		switch (optarg[index++])
2867 		  {
2868 		  case 'i':
2869 		  case 'I':
2870 		    do_debug_info = 1;
2871 		    break;
2872 
2873 		  case 'a':
2874 		  case 'A':
2875 		    do_debug_abbrevs = 1;
2876 		    break;
2877 
2878 		  case 'l':
2879 		  case 'L':
2880 		    do_debug_lines = 1;
2881 		    break;
2882 
2883 		  case 'p':
2884 		  case 'P':
2885 		    do_debug_pubnames = 1;
2886 		    break;
2887 
2888 		  case 'r':
2889 		    do_debug_aranges = 1;
2890 		    break;
2891 
2892 		  case 'R':
2893 		    do_debug_ranges = 1;
2894 		    break;
2895 
2896 		  case 'F':
2897 		    do_debug_frames_interp = 1;
2898 		  case 'f':
2899 		    do_debug_frames = 1;
2900 		    break;
2901 
2902 		  case 'm':
2903 		  case 'M':
2904 		    do_debug_macinfo = 1;
2905 		    break;
2906 
2907 		  case 's':
2908 		  case 'S':
2909 		    do_debug_str = 1;
2910 		    break;
2911 
2912 		  case 'o':
2913 		  case 'O':
2914 		    do_debug_loc = 1;
2915 		    break;
2916 
2917 		  default:
2918 		    warn (_("Unrecognized debug option '%s'\n"), optarg);
2919 		    break;
2920 		  }
2921 	    }
2922 	  break;
2923 	case OPTION_DEBUG_DUMP:
2924 	  do_dump++;
2925 	  if (optarg == 0)
2926 	    do_debugging = 1;
2927 	  else
2928 	    {
2929 	      typedef struct
2930 	      {
2931 		const char * option;
2932 		int *        variable;
2933 	      }
2934 	      debug_dump_long_opts;
2935 
2936 	      debug_dump_long_opts opts_table [] =
2937 		{
2938 		  /* Please keep this table alpha- sorted.  */
2939 		  { "Ranges", & do_debug_ranges },
2940 		  { "abbrev", & do_debug_abbrevs },
2941 		  { "aranges", & do_debug_aranges },
2942 		  { "frames", & do_debug_frames },
2943 		  { "frames-interp", & do_debug_frames_interp },
2944 		  { "info", & do_debug_info },
2945 		  { "line", & do_debug_lines },
2946 		  { "loc",  & do_debug_loc },
2947 		  { "macro", & do_debug_macinfo },
2948 		  { "pubnames", & do_debug_pubnames },
2949 		  /* This entry is for compatability
2950 		     with earlier versions of readelf.  */
2951 		  { "ranges", & do_debug_aranges },
2952 		  { "str", & do_debug_str },
2953 		  { NULL, NULL }
2954 		};
2955 
2956 	      const char *p;
2957 
2958 	      do_debugging = 0;
2959 
2960 	      p = optarg;
2961 	      while (*p)
2962 		{
2963 		  debug_dump_long_opts * entry;
2964 
2965 		  for (entry = opts_table; entry->option; entry++)
2966 		    {
2967 		      size_t len = strlen (entry->option);
2968 
2969 		      if (strneq (p, entry->option, len)
2970 			  && (p[len] == ',' || p[len] == '\0'))
2971 			{
2972 			  * entry->variable = 1;
2973 
2974 			  /* The --debug-dump=frames-interp option also
2975 			     enables the --debug-dump=frames option.  */
2976 			  if (do_debug_frames_interp)
2977 			    do_debug_frames = 1;
2978 
2979 			  p += len;
2980 			  break;
2981 			}
2982 		    }
2983 
2984 		  if (entry->option == NULL)
2985 		    {
2986 		      warn (_("Unrecognized debug option '%s'\n"), p);
2987 		      p = strchr (p, ',');
2988 		      if (p == NULL)
2989 			break;
2990 		    }
2991 
2992 		  if (*p == ',')
2993 		    p++;
2994 		}
2995 	    }
2996 	  break;
2997 #ifdef SUPPORT_DISASSEMBLY
2998 	case 'i':
2999 	  do_dump++;
3000 	  section = strtoul (optarg, & cp, 0);
3001 	  if (! *cp && section >= 0)
3002 	    {
3003 	      request_dump (section, DISASS_DUMP);
3004 	      break;
3005 	    }
3006 	  goto oops;
3007 #endif
3008 	case 'v':
3009 	  print_version (program_name);
3010 	  break;
3011 	case 'V':
3012 	  do_version++;
3013 	  break;
3014 	case 'W':
3015 	  do_wide++;
3016 	  break;
3017 	default:
3018 #ifdef SUPPORT_DISASSEMBLY
3019 	oops:
3020 #endif
3021 	  /* xgettext:c-format */
3022 	  error (_("Invalid option '-%c'\n"), c);
3023 	  /* Drop through.  */
3024 	case '?':
3025 	  usage ();
3026 	}
3027     }
3028 
3029   if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
3030       && !do_segments && !do_header && !do_dump && !do_version
3031       && !do_histogram && !do_debugging && !do_arch && !do_notes
3032       && !do_section_groups)
3033     usage ();
3034   else if (argc < 3)
3035     {
3036       warn (_("Nothing to do.\n"));
3037       usage ();
3038     }
3039 }
3040 
3041 static const char *
3042 get_elf_class (unsigned int elf_class)
3043 {
3044   static char buff[32];
3045 
3046   switch (elf_class)
3047     {
3048     case ELFCLASSNONE: return _("none");
3049     case ELFCLASS32:   return "ELF32";
3050     case ELFCLASS64:   return "ELF64";
3051     default:
3052       snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
3053       return buff;
3054     }
3055 }
3056 
3057 static const char *
3058 get_data_encoding (unsigned int encoding)
3059 {
3060   static char buff[32];
3061 
3062   switch (encoding)
3063     {
3064     case ELFDATANONE: return _("none");
3065     case ELFDATA2LSB: return _("2's complement, little endian");
3066     case ELFDATA2MSB: return _("2's complement, big endian");
3067     default:
3068       snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
3069       return buff;
3070     }
3071 }
3072 
3073 /* Decode the data held in 'elf_header'.  */
3074 
3075 static int
3076 process_file_header (void)
3077 {
3078   if (   elf_header.e_ident[EI_MAG0] != ELFMAG0
3079       || elf_header.e_ident[EI_MAG1] != ELFMAG1
3080       || elf_header.e_ident[EI_MAG2] != ELFMAG2
3081       || elf_header.e_ident[EI_MAG3] != ELFMAG3)
3082     {
3083       error
3084 	(_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3085       return 0;
3086     }
3087 
3088   if (do_header)
3089     {
3090       int i;
3091 
3092       printf (_("ELF Header:\n"));
3093       printf (_("  Magic:   "));
3094       for (i = 0; i < EI_NIDENT; i++)
3095 	printf ("%2.2x ", elf_header.e_ident[i]);
3096       printf ("\n");
3097       printf (_("  Class:                             %s\n"),
3098 	      get_elf_class (elf_header.e_ident[EI_CLASS]));
3099       printf (_("  Data:                              %s\n"),
3100 	      get_data_encoding (elf_header.e_ident[EI_DATA]));
3101       printf (_("  Version:                           %d %s\n"),
3102 	      elf_header.e_ident[EI_VERSION],
3103 	      (elf_header.e_ident[EI_VERSION] == EV_CURRENT
3104 	       ? "(current)"
3105 	       : (elf_header.e_ident[EI_VERSION] != EV_NONE
3106 		  ? "<unknown: %lx>"
3107 		  : "")));
3108       printf (_("  OS/ABI:                            %s\n"),
3109 	      get_osabi_name (elf_header.e_ident[EI_OSABI]));
3110       printf (_("  ABI Version:                       %d\n"),
3111 	      elf_header.e_ident[EI_ABIVERSION]);
3112       printf (_("  Type:                              %s\n"),
3113 	      get_file_type (elf_header.e_type));
3114       printf (_("  Machine:                           %s\n"),
3115 	      get_machine_name (elf_header.e_machine));
3116       printf (_("  Version:                           0x%lx\n"),
3117 	      (unsigned long) elf_header.e_version);
3118 
3119       printf (_("  Entry point address:               "));
3120       print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3121       printf (_("\n  Start of program headers:          "));
3122       print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3123       printf (_(" (bytes into file)\n  Start of section headers:          "));
3124       print_vma ((bfd_vma) elf_header.e_shoff, DEC);
3125       printf (_(" (bytes into file)\n"));
3126 
3127       printf (_("  Flags:                             0x%lx%s\n"),
3128 	      (unsigned long) elf_header.e_flags,
3129 	      get_machine_flags (elf_header.e_flags, elf_header.e_machine));
3130       printf (_("  Size of this header:               %ld (bytes)\n"),
3131 	      (long) elf_header.e_ehsize);
3132       printf (_("  Size of program headers:           %ld (bytes)\n"),
3133 	      (long) elf_header.e_phentsize);
3134       printf (_("  Number of program headers:         %ld\n"),
3135 	      (long) elf_header.e_phnum);
3136       printf (_("  Size of section headers:           %ld (bytes)\n"),
3137 	      (long) elf_header.e_shentsize);
3138       printf (_("  Number of section headers:         %ld"),
3139 	      (long) elf_header.e_shnum);
3140       if (section_headers != NULL && elf_header.e_shnum == 0)
3141 	printf (" (%ld)", (long) section_headers[0].sh_size);
3142       putc ('\n', stdout);
3143       printf (_("  Section header string table index: %ld"),
3144 	      (long) elf_header.e_shstrndx);
3145       if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
3146 	printf (" (%ld)", (long) section_headers[0].sh_link);
3147       putc ('\n', stdout);
3148     }
3149 
3150   if (section_headers != NULL)
3151     {
3152       if (elf_header.e_shnum == 0)
3153 	elf_header.e_shnum = section_headers[0].sh_size;
3154       if (elf_header.e_shstrndx == SHN_XINDEX)
3155 	elf_header.e_shstrndx = section_headers[0].sh_link;
3156       free (section_headers);
3157       section_headers = NULL;
3158     }
3159 
3160   return 1;
3161 }
3162 
3163 
3164 static int
3165 get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3166 {
3167   Elf32_External_Phdr *phdrs;
3168   Elf32_External_Phdr *external;
3169   Elf_Internal_Phdr *internal;
3170   unsigned int i;
3171 
3172   phdrs = get_data (NULL, file, elf_header.e_phoff,
3173 		    elf_header.e_phentsize, elf_header.e_phnum,
3174 		    _("program headers"));
3175   if (!phdrs)
3176     return 0;
3177 
3178   for (i = 0, internal = program_headers, external = phdrs;
3179        i < elf_header.e_phnum;
3180        i++, internal++, external++)
3181     {
3182       internal->p_type   = BYTE_GET (external->p_type);
3183       internal->p_offset = BYTE_GET (external->p_offset);
3184       internal->p_vaddr  = BYTE_GET (external->p_vaddr);
3185       internal->p_paddr  = BYTE_GET (external->p_paddr);
3186       internal->p_filesz = BYTE_GET (external->p_filesz);
3187       internal->p_memsz  = BYTE_GET (external->p_memsz);
3188       internal->p_flags  = BYTE_GET (external->p_flags);
3189       internal->p_align  = BYTE_GET (external->p_align);
3190     }
3191 
3192   free (phdrs);
3193 
3194   return 1;
3195 }
3196 
3197 static int
3198 get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3199 {
3200   Elf64_External_Phdr *phdrs;
3201   Elf64_External_Phdr *external;
3202   Elf_Internal_Phdr *internal;
3203   unsigned int i;
3204 
3205   phdrs = get_data (NULL, file, elf_header.e_phoff,
3206 		    elf_header.e_phentsize, elf_header.e_phnum,
3207 		    _("program headers"));
3208   if (!phdrs)
3209     return 0;
3210 
3211   for (i = 0, internal = program_headers, external = phdrs;
3212        i < elf_header.e_phnum;
3213        i++, internal++, external++)
3214     {
3215       internal->p_type   = BYTE_GET (external->p_type);
3216       internal->p_flags  = BYTE_GET (external->p_flags);
3217       internal->p_offset = BYTE_GET (external->p_offset);
3218       internal->p_vaddr  = BYTE_GET (external->p_vaddr);
3219       internal->p_paddr  = BYTE_GET (external->p_paddr);
3220       internal->p_filesz = BYTE_GET (external->p_filesz);
3221       internal->p_memsz  = BYTE_GET (external->p_memsz);
3222       internal->p_align  = BYTE_GET (external->p_align);
3223     }
3224 
3225   free (phdrs);
3226 
3227   return 1;
3228 }
3229 
3230 /* Returns 1 if the program headers were read into `program_headers'.  */
3231 
3232 static int
3233 get_program_headers (FILE *file)
3234 {
3235   Elf_Internal_Phdr *phdrs;
3236 
3237   /* Check cache of prior read.  */
3238   if (program_headers != NULL)
3239     return 1;
3240 
3241   phdrs = cmalloc (elf_header.e_phnum, sizeof (Elf_Internal_Phdr));
3242 
3243   if (phdrs == NULL)
3244     {
3245       error (_("Out of memory\n"));
3246       return 0;
3247     }
3248 
3249   if (is_32bit_elf
3250       ? get_32bit_program_headers (file, phdrs)
3251       : get_64bit_program_headers (file, phdrs))
3252     {
3253       program_headers = phdrs;
3254       return 1;
3255     }
3256 
3257   free (phdrs);
3258   return 0;
3259 }
3260 
3261 /* Returns 1 if the program headers were loaded.  */
3262 
3263 static int
3264 process_program_headers (FILE *file)
3265 {
3266   Elf_Internal_Phdr *segment;
3267   unsigned int i;
3268 
3269   if (elf_header.e_phnum == 0)
3270     {
3271       if (do_segments)
3272 	printf (_("\nThere are no program headers in this file.\n"));
3273       return 0;
3274     }
3275 
3276   if (do_segments && !do_header)
3277     {
3278       printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
3279       printf (_("Entry point "));
3280       print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3281       printf (_("\nThere are %d program headers, starting at offset "),
3282 	      elf_header.e_phnum);
3283       print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3284       printf ("\n");
3285     }
3286 
3287   if (! get_program_headers (file))
3288       return 0;
3289 
3290   if (do_segments)
3291     {
3292       if (elf_header.e_phnum > 1)
3293 	printf (_("\nProgram Headers:\n"));
3294       else
3295 	printf (_("\nProgram Headers:\n"));
3296 
3297       if (is_32bit_elf)
3298 	printf
3299 	  (_("  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align\n"));
3300       else if (do_wide)
3301 	printf
3302 	  (_("  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align\n"));
3303       else
3304 	{
3305 	  printf
3306 	    (_("  Type           Offset             VirtAddr           PhysAddr\n"));
3307 	  printf
3308 	    (_("                 FileSiz            MemSiz              Flags  Align\n"));
3309 	}
3310     }
3311 
3312   dynamic_addr = 0;
3313   dynamic_size = 0;
3314 
3315   for (i = 0, segment = program_headers;
3316        i < elf_header.e_phnum;
3317        i++, segment++)
3318     {
3319       if (do_segments)
3320 	{
3321 	  printf ("  %-14.14s ", get_segment_type (segment->p_type));
3322 
3323 	  if (is_32bit_elf)
3324 	    {
3325 	      printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3326 	      printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
3327 	      printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
3328 	      printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
3329 	      printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
3330 	      printf ("%c%c%c ",
3331 		      (segment->p_flags & PF_R ? 'R' : ' '),
3332 		      (segment->p_flags & PF_W ? 'W' : ' '),
3333 		      (segment->p_flags & PF_X ? 'E' : ' '));
3334 	      printf ("%#lx", (unsigned long) segment->p_align);
3335 	    }
3336 	  else if (do_wide)
3337 	    {
3338 	      if ((unsigned long) segment->p_offset == segment->p_offset)
3339 		printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3340 	      else
3341 		{
3342 		  print_vma (segment->p_offset, FULL_HEX);
3343 		  putchar (' ');
3344 		}
3345 
3346 	      print_vma (segment->p_vaddr, FULL_HEX);
3347 	      putchar (' ');
3348 	      print_vma (segment->p_paddr, FULL_HEX);
3349 	      putchar (' ');
3350 
3351 	      if ((unsigned long) segment->p_filesz == segment->p_filesz)
3352 		printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
3353 	      else
3354 		{
3355 		  print_vma (segment->p_filesz, FULL_HEX);
3356 		  putchar (' ');
3357 		}
3358 
3359 	      if ((unsigned long) segment->p_memsz == segment->p_memsz)
3360 		printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
3361 	      else
3362 		{
3363 		  print_vma (segment->p_offset, FULL_HEX);
3364 		}
3365 
3366 	      printf (" %c%c%c ",
3367 		      (segment->p_flags & PF_R ? 'R' : ' '),
3368 		      (segment->p_flags & PF_W ? 'W' : ' '),
3369 		      (segment->p_flags & PF_X ? 'E' : ' '));
3370 
3371 	      if ((unsigned long) segment->p_align == segment->p_align)
3372 		printf ("%#lx", (unsigned long) segment->p_align);
3373 	      else
3374 		{
3375 		  print_vma (segment->p_align, PREFIX_HEX);
3376 		}
3377 	    }
3378 	  else
3379 	    {
3380 	      print_vma (segment->p_offset, FULL_HEX);
3381 	      putchar (' ');
3382 	      print_vma (segment->p_vaddr, FULL_HEX);
3383 	      putchar (' ');
3384 	      print_vma (segment->p_paddr, FULL_HEX);
3385 	      printf ("\n                 ");
3386 	      print_vma (segment->p_filesz, FULL_HEX);
3387 	      putchar (' ');
3388 	      print_vma (segment->p_memsz, FULL_HEX);
3389 	      printf ("  %c%c%c    ",
3390 		      (segment->p_flags & PF_R ? 'R' : ' '),
3391 		      (segment->p_flags & PF_W ? 'W' : ' '),
3392 		      (segment->p_flags & PF_X ? 'E' : ' '));
3393 	      print_vma (segment->p_align, HEX);
3394 	    }
3395 	}
3396 
3397       switch (segment->p_type)
3398 	{
3399 	case PT_DYNAMIC:
3400 	  if (dynamic_addr)
3401 	    error (_("more than one dynamic segment\n"));
3402 
3403 	  /* Try to locate the .dynamic section. If there is
3404 	     a section header table, we can easily locate it.  */
3405 	  if (section_headers != NULL)
3406 	    {
3407 	      Elf_Internal_Shdr *sec;
3408 
3409 	      sec = find_section (".dynamic");
3410 	      if (sec == NULL || sec->sh_size == 0)
3411 		{
3412 		  error (_("no .dynamic section in the dynamic segment"));
3413 		  break;
3414 		}
3415 
3416 	      dynamic_addr = sec->sh_offset;
3417 	      dynamic_size = sec->sh_size;
3418 
3419 	      if (dynamic_addr < segment->p_offset
3420 		  || dynamic_addr > segment->p_offset + segment->p_filesz)
3421 		warn (_("the .dynamic section is not contained within the dynamic segment"));
3422 	      else if (dynamic_addr > segment->p_offset)
3423 		warn (_("the .dynamic section is not the first section in the dynamic segment."));
3424 	    }
3425 	  else
3426 	    {
3427 	      /* Otherwise, we can only assume that the .dynamic
3428 		 section is the first section in the DYNAMIC segment.  */
3429 	      dynamic_addr = segment->p_offset;
3430 	      dynamic_size = segment->p_filesz;
3431 	    }
3432 	  break;
3433 
3434 	case PT_INTERP:
3435 	  if (fseek (file, archive_file_offset + (long) segment->p_offset,
3436 		     SEEK_SET))
3437 	    error (_("Unable to find program interpreter name\n"));
3438 	  else
3439 	    {
3440 	      program_interpreter[0] = 0;
3441 	      fscanf (file, "%63s", program_interpreter);
3442 
3443 	      if (do_segments)
3444 		printf (_("\n      [Requesting program interpreter: %s]"),
3445 		    program_interpreter);
3446 	    }
3447 	  break;
3448 	}
3449 
3450       if (do_segments)
3451 	putc ('\n', stdout);
3452     }
3453 
3454   if (do_segments && section_headers != NULL && string_table != NULL)
3455     {
3456       printf (_("\n Section to Segment mapping:\n"));
3457       printf (_("  Segment Sections...\n"));
3458 
3459       for (i = 0; i < elf_header.e_phnum; i++)
3460 	{
3461 	  unsigned int j;
3462 	  Elf_Internal_Shdr *section;
3463 
3464 	  segment = program_headers + i;
3465 	  section = section_headers;
3466 
3467 	  printf ("   %2.2d     ", i);
3468 
3469 	  for (j = 1; j < elf_header.e_shnum; j++, section++)
3470 	    {
3471 	      if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section, segment))
3472 		printf ("%s ", SECTION_NAME (section));
3473 	    }
3474 
3475 	  putc ('\n',stdout);
3476 	}
3477     }
3478 
3479   return 1;
3480 }
3481 
3482 
3483 /* Find the file offset corresponding to VMA by using the program headers.  */
3484 
3485 static long
3486 offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
3487 {
3488   Elf_Internal_Phdr *seg;
3489 
3490   if (! get_program_headers (file))
3491     {
3492       warn (_("Cannot interpret virtual addresses without program headers.\n"));
3493       return (long) vma;
3494     }
3495 
3496   for (seg = program_headers;
3497        seg < program_headers + elf_header.e_phnum;
3498        ++seg)
3499     {
3500       if (seg->p_type != PT_LOAD)
3501 	continue;
3502 
3503       if (vma >= (seg->p_vaddr & -seg->p_align)
3504 	  && vma + size <= seg->p_vaddr + seg->p_filesz)
3505 	return vma - seg->p_vaddr + seg->p_offset;
3506     }
3507 
3508   warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3509 	(long) vma);
3510   return (long) vma;
3511 }
3512 
3513 
3514 static int
3515 get_32bit_section_headers (FILE *file, unsigned int num)
3516 {
3517   Elf32_External_Shdr *shdrs;
3518   Elf_Internal_Shdr *internal;
3519   unsigned int i;
3520 
3521   shdrs = get_data (NULL, file, elf_header.e_shoff,
3522 		    elf_header.e_shentsize, num, _("section headers"));
3523   if (!shdrs)
3524     return 0;
3525 
3526   section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3527 
3528   if (section_headers == NULL)
3529     {
3530       error (_("Out of memory\n"));
3531       return 0;
3532     }
3533 
3534   for (i = 0, internal = section_headers;
3535        i < num;
3536        i++, internal++)
3537     {
3538       internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
3539       internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
3540       internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
3541       internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
3542       internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
3543       internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
3544       internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
3545       internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
3546       internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3547       internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
3548     }
3549 
3550   free (shdrs);
3551 
3552   return 1;
3553 }
3554 
3555 static int
3556 get_64bit_section_headers (FILE *file, unsigned int num)
3557 {
3558   Elf64_External_Shdr *shdrs;
3559   Elf_Internal_Shdr *internal;
3560   unsigned int i;
3561 
3562   shdrs = get_data (NULL, file, elf_header.e_shoff,
3563 		    elf_header.e_shentsize, num, _("section headers"));
3564   if (!shdrs)
3565     return 0;
3566 
3567   section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3568 
3569   if (section_headers == NULL)
3570     {
3571       error (_("Out of memory\n"));
3572       return 0;
3573     }
3574 
3575   for (i = 0, internal = section_headers;
3576        i < num;
3577        i++, internal++)
3578     {
3579       internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
3580       internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
3581       internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
3582       internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
3583       internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
3584       internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
3585       internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
3586       internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
3587       internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
3588       internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3589     }
3590 
3591   free (shdrs);
3592 
3593   return 1;
3594 }
3595 
3596 static Elf_Internal_Sym *
3597 get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3598 {
3599   unsigned long number;
3600   Elf32_External_Sym *esyms;
3601   Elf_External_Sym_Shndx *shndx;
3602   Elf_Internal_Sym *isyms;
3603   Elf_Internal_Sym *psym;
3604   unsigned int j;
3605 
3606   esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
3607 		    _("symbols"));
3608   if (!esyms)
3609     return NULL;
3610 
3611   shndx = NULL;
3612   if (symtab_shndx_hdr != NULL
3613       && (symtab_shndx_hdr->sh_link
3614 	  == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3615     {
3616       shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3617 			1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
3618       if (!shndx)
3619 	{
3620 	  free (esyms);
3621 	  return NULL;
3622 	}
3623     }
3624 
3625   number = section->sh_size / section->sh_entsize;
3626   isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3627 
3628   if (isyms == NULL)
3629     {
3630       error (_("Out of memory\n"));
3631       if (shndx)
3632 	free (shndx);
3633       free (esyms);
3634       return NULL;
3635     }
3636 
3637   for (j = 0, psym = isyms;
3638        j < number;
3639        j++, psym++)
3640     {
3641       psym->st_name  = BYTE_GET (esyms[j].st_name);
3642       psym->st_value = BYTE_GET (esyms[j].st_value);
3643       psym->st_size  = BYTE_GET (esyms[j].st_size);
3644       psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3645       if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3646 	psym->st_shndx
3647 	  = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3648       psym->st_info  = BYTE_GET (esyms[j].st_info);
3649       psym->st_other = BYTE_GET (esyms[j].st_other);
3650     }
3651 
3652   if (shndx)
3653     free (shndx);
3654   free (esyms);
3655 
3656   return isyms;
3657 }
3658 
3659 static Elf_Internal_Sym *
3660 get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3661 {
3662   unsigned long number;
3663   Elf64_External_Sym *esyms;
3664   Elf_External_Sym_Shndx *shndx;
3665   Elf_Internal_Sym *isyms;
3666   Elf_Internal_Sym *psym;
3667   unsigned int j;
3668 
3669   esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
3670 		    _("symbols"));
3671   if (!esyms)
3672     return NULL;
3673 
3674   shndx = NULL;
3675   if (symtab_shndx_hdr != NULL
3676       && (symtab_shndx_hdr->sh_link
3677 	  == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3678     {
3679       shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3680 			1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
3681       if (!shndx)
3682 	{
3683 	  free (esyms);
3684 	  return NULL;
3685 	}
3686     }
3687 
3688   number = section->sh_size / section->sh_entsize;
3689   isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3690 
3691   if (isyms == NULL)
3692     {
3693       error (_("Out of memory\n"));
3694       if (shndx)
3695 	free (shndx);
3696       free (esyms);
3697       return NULL;
3698     }
3699 
3700   for (j = 0, psym = isyms;
3701        j < number;
3702        j++, psym++)
3703     {
3704       psym->st_name  = BYTE_GET (esyms[j].st_name);
3705       psym->st_info  = BYTE_GET (esyms[j].st_info);
3706       psym->st_other = BYTE_GET (esyms[j].st_other);
3707       psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3708       if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3709 	psym->st_shndx
3710 	  = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3711       psym->st_value = BYTE_GET (esyms[j].st_value);
3712       psym->st_size  = BYTE_GET (esyms[j].st_size);
3713     }
3714 
3715   if (shndx)
3716     free (shndx);
3717   free (esyms);
3718 
3719   return isyms;
3720 }
3721 
3722 static const char *
3723 get_elf_section_flags (bfd_vma sh_flags)
3724 {
3725   static char buff[1024];
3726   char *p = buff;
3727   int field_size = is_32bit_elf ? 8 : 16;
3728   int index, size = sizeof (buff) - (field_size + 4 + 1);
3729   bfd_vma os_flags = 0;
3730   bfd_vma proc_flags = 0;
3731   bfd_vma unknown_flags = 0;
3732   const struct
3733     {
3734       const char *str;
3735       int len;
3736     }
3737   flags [] =
3738     {
3739 	{ "WRITE", 5 },
3740 	{ "ALLOC", 5 },
3741 	{ "EXEC", 4 },
3742 	{ "MERGE", 5 },
3743 	{ "STRINGS", 7 },
3744 	{ "INFO LINK", 9 },
3745 	{ "LINK ORDER", 10 },
3746 	{ "OS NONCONF", 10 },
3747 	{ "GROUP", 5 },
3748 	{ "TLS", 3 }
3749     };
3750 
3751   if (do_section_details)
3752     {
3753       sprintf (buff, "[%*.*lx]: ",
3754 	       field_size, field_size, (unsigned long) sh_flags);
3755       p += field_size + 4;
3756     }
3757 
3758   while (sh_flags)
3759     {
3760       bfd_vma flag;
3761 
3762       flag = sh_flags & - sh_flags;
3763       sh_flags &= ~ flag;
3764 
3765       if (do_section_details)
3766 	{
3767 	  switch (flag)
3768 	    {
3769 	    case SHF_WRITE:		index = 0; break;
3770 	    case SHF_ALLOC:		index = 1; break;
3771 	    case SHF_EXECINSTR:		index = 2; break;
3772 	    case SHF_MERGE:		index = 3; break;
3773 	    case SHF_STRINGS:		index = 4; break;
3774 	    case SHF_INFO_LINK:		index = 5; break;
3775 	    case SHF_LINK_ORDER:	index = 6; break;
3776 	    case SHF_OS_NONCONFORMING:	index = 7; break;
3777 	    case SHF_GROUP:		index = 8; break;
3778 	    case SHF_TLS:		index = 9; break;
3779 
3780 	    default:
3781 	      index = -1;
3782 	      break;
3783 	    }
3784 
3785 	  if (index != -1)
3786 	    {
3787 	      if (p != buff + field_size + 4)
3788 		{
3789 		  if (size < (10 + 2))
3790 		    abort ();
3791 		  size -= 2;
3792 		  *p++ = ',';
3793 		  *p++ = ' ';
3794 		}
3795 
3796 	      size -= flags [index].len;
3797 #if 0
3798 	      p = stpcpy (p, flags [index].str);
3799 #else
3800 	      strcpy (p, flags [index].str);
3801 	      p += strlen(p);
3802 #endif
3803 	    }
3804 	  else if (flag & SHF_MASKOS)
3805 	    os_flags |= flag;
3806 	  else if (flag & SHF_MASKPROC)
3807 	    proc_flags |= flag;
3808 	  else
3809 	    unknown_flags |= flag;
3810 	}
3811       else
3812 	{
3813 	  switch (flag)
3814 	    {
3815 	    case SHF_WRITE:		*p = 'W'; break;
3816 	    case SHF_ALLOC:		*p = 'A'; break;
3817 	    case SHF_EXECINSTR:		*p = 'X'; break;
3818 	    case SHF_MERGE:		*p = 'M'; break;
3819 	    case SHF_STRINGS:		*p = 'S'; break;
3820 	    case SHF_INFO_LINK:		*p = 'I'; break;
3821 	    case SHF_LINK_ORDER:	*p = 'L'; break;
3822 	    case SHF_OS_NONCONFORMING:	*p = 'O'; break;
3823 	    case SHF_GROUP:		*p = 'G'; break;
3824 	    case SHF_TLS:		*p = 'T'; break;
3825 
3826 	    default:
3827 	      if (elf_header.e_machine == EM_X86_64
3828 		  && flag == SHF_X86_64_LARGE)
3829 		*p = 'l';
3830 	      else if (flag & SHF_MASKOS)
3831 		{
3832 		  *p = 'o';
3833 		  sh_flags &= ~ SHF_MASKOS;
3834 		}
3835 	      else if (flag & SHF_MASKPROC)
3836 		{
3837 		  *p = 'p';
3838 		  sh_flags &= ~ SHF_MASKPROC;
3839 		}
3840 	      else
3841 		*p = 'x';
3842 	      break;
3843 	    }
3844 	  p++;
3845 	}
3846     }
3847 
3848   if (do_section_details)
3849     {
3850       if (os_flags)
3851 	{
3852 	  size -= 5 + field_size;
3853 	  if (p != buff + field_size + 4)
3854 	    {
3855 	      if (size < (2 + 1))
3856 		abort ();
3857 	      size -= 2;
3858 	      *p++ = ',';
3859 	      *p++ = ' ';
3860 	    }
3861 	  sprintf (p, "OS (%*.*lx)", field_size, field_size,
3862 		   (unsigned long) os_flags);
3863 	  p += 5 + field_size;
3864 	}
3865       if (proc_flags)
3866 	{
3867 	  size -= 7 + field_size;
3868 	  if (p != buff + field_size + 4)
3869 	    {
3870 	      if (size < (2 + 1))
3871 		abort ();
3872 	      size -= 2;
3873 	      *p++ = ',';
3874 	      *p++ = ' ';
3875 	    }
3876 	  sprintf (p, "PROC (%*.*lx)", field_size, field_size,
3877 		   (unsigned long) proc_flags);
3878 	  p += 7 + field_size;
3879 	}
3880       if (unknown_flags)
3881 	{
3882 	  size -= 10 + field_size;
3883 	  if (p != buff + field_size + 4)
3884 	    {
3885 	      if (size < (2 + 1))
3886 		abort ();
3887 	      size -= 2;
3888 	      *p++ = ',';
3889 	      *p++ = ' ';
3890 	    }
3891 	  sprintf (p, "UNKNOWN (%*.*lx)", field_size, field_size,
3892 		   (unsigned long) unknown_flags);
3893 	  p += 10 + field_size;
3894 	}
3895     }
3896 
3897   *p = '\0';
3898   return buff;
3899 }
3900 
3901 static int
3902 process_section_headers (FILE *file)
3903 {
3904   Elf_Internal_Shdr *section;
3905   unsigned int i;
3906 
3907   section_headers = NULL;
3908 
3909   if (elf_header.e_shnum == 0)
3910     {
3911       if (do_sections)
3912 	printf (_("\nThere are no sections in this file.\n"));
3913 
3914       return 1;
3915     }
3916 
3917   if (do_sections && !do_header)
3918     printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3919 	    elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3920 
3921   if (is_32bit_elf)
3922     {
3923       if (! get_32bit_section_headers (file, elf_header.e_shnum))
3924 	return 0;
3925     }
3926   else if (! get_64bit_section_headers (file, elf_header.e_shnum))
3927     return 0;
3928 
3929   /* Read in the string table, so that we have names to display.  */
3930   if (SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum)
3931     {
3932       section = SECTION_HEADER (elf_header.e_shstrndx);
3933 
3934       if (section->sh_size != 0)
3935 	{
3936 	  string_table = get_data (NULL, file, section->sh_offset,
3937 				   1, section->sh_size, _("string table"));
3938 
3939 	  string_table_length = string_table != NULL ? section->sh_size : 0;
3940 	}
3941     }
3942 
3943   /* Scan the sections for the dynamic symbol table
3944      and dynamic string table and debug sections.  */
3945   dynamic_symbols = NULL;
3946   dynamic_strings = NULL;
3947   dynamic_syminfo = NULL;
3948   symtab_shndx_hdr = NULL;
3949 
3950   eh_addr_size = is_32bit_elf ? 4 : 8;
3951   switch (elf_header.e_machine)
3952     {
3953     case EM_MIPS:
3954     case EM_MIPS_RS3_LE:
3955       /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
3956 	 FDE addresses.  However, the ABI also has a semi-official ILP32
3957 	 variant for which the normal FDE address size rules apply.
3958 
3959 	 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
3960 	 section, where XX is the size of longs in bits.  Unfortunately,
3961 	 earlier compilers provided no way of distinguishing ILP32 objects
3962 	 from LP64 objects, so if there's any doubt, we should assume that
3963 	 the official LP64 form is being used.  */
3964       if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
3965 	  && find_section (".gcc_compiled_long32") == NULL)
3966 	eh_addr_size = 8;
3967       break;
3968     }
3969 
3970 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
3971   do									    \
3972     {									    \
3973       size_t expected_entsize						    \
3974 	= is_32bit_elf ? size32 : size64;				    \
3975       if (section->sh_entsize != expected_entsize)			    \
3976 	error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
3977 	       i, (unsigned long int) section->sh_entsize,		    \
3978 	       (unsigned long int) expected_entsize);			    \
3979       section->sh_entsize = expected_entsize;				    \
3980     }									    \
3981   while (0)
3982 #define CHECK_ENTSIZE(section, i, type) \
3983   CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type),	    \
3984 			sizeof (Elf64_External_##type))
3985 
3986   for (i = 0, section = section_headers;
3987        i < elf_header.e_shnum;
3988        i++, section++)
3989     {
3990       char *name = SECTION_NAME (section);
3991 
3992       if (section->sh_type == SHT_DYNSYM)
3993 	{
3994 	  if (dynamic_symbols != NULL)
3995 	    {
3996 	      error (_("File contains multiple dynamic symbol tables\n"));
3997 	      continue;
3998 	    }
3999 
4000 	  CHECK_ENTSIZE (section, i, Sym);
4001 	  num_dynamic_syms = section->sh_size / section->sh_entsize;
4002 	  dynamic_symbols = GET_ELF_SYMBOLS (file, section);
4003 	}
4004       else if (section->sh_type == SHT_STRTAB
4005 	       && streq (name, ".dynstr"))
4006 	{
4007 	  if (dynamic_strings != NULL)
4008 	    {
4009 	      error (_("File contains multiple dynamic string tables\n"));
4010 	      continue;
4011 	    }
4012 
4013 	  dynamic_strings = get_data (NULL, file, section->sh_offset,
4014 				      1, section->sh_size, _("dynamic strings"));
4015 	  dynamic_strings_length = section->sh_size;
4016 	}
4017       else if (section->sh_type == SHT_SYMTAB_SHNDX)
4018 	{
4019 	  if (symtab_shndx_hdr != NULL)
4020 	    {
4021 	      error (_("File contains multiple symtab shndx tables\n"));
4022 	      continue;
4023 	    }
4024 	  symtab_shndx_hdr = section;
4025 	}
4026       else if (section->sh_type == SHT_SYMTAB)
4027 	CHECK_ENTSIZE (section, i, Sym);
4028       else if (section->sh_type == SHT_GROUP)
4029 	CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
4030       else if (section->sh_type == SHT_REL)
4031 	CHECK_ENTSIZE (section, i, Rel);
4032       else if (section->sh_type == SHT_RELA)
4033 	CHECK_ENTSIZE (section, i, Rela);
4034       else if ((do_debugging || do_debug_info || do_debug_abbrevs
4035 		|| do_debug_lines || do_debug_pubnames || do_debug_aranges
4036 		|| do_debug_frames || do_debug_macinfo || do_debug_str
4037 		|| do_debug_loc || do_debug_ranges)
4038 	       && strneq (name, ".debug_", 7))
4039 	{
4040 	  name += 7;
4041 
4042 	  if (do_debugging
4043 	      || (do_debug_info     && streq (name, "info"))
4044 	      || (do_debug_abbrevs  && streq (name, "abbrev"))
4045 	      || (do_debug_lines    && streq (name, "line"))
4046 	      || (do_debug_pubnames && streq (name, "pubnames"))
4047 	      || (do_debug_aranges  && streq (name, "aranges"))
4048 	      || (do_debug_ranges   && streq (name, "ranges"))
4049 	      || (do_debug_frames   && streq (name, "frame"))
4050 	      || (do_debug_macinfo  && streq (name, "macinfo"))
4051 	      || (do_debug_str      && streq (name, "str"))
4052 	      || (do_debug_loc      && streq (name, "loc"))
4053 	      )
4054 	    request_dump (i, DEBUG_DUMP);
4055 	}
4056       /* linkonce section to be combined with .debug_info at link time.  */
4057       else if ((do_debugging || do_debug_info)
4058 	       && strneq (name, ".gnu.linkonce.wi.", 17))
4059 	request_dump (i, DEBUG_DUMP);
4060       else if (do_debug_frames && streq (name, ".eh_frame"))
4061 	request_dump (i, DEBUG_DUMP);
4062     }
4063 
4064   if (! do_sections)
4065     return 1;
4066 
4067   if (elf_header.e_shnum > 1)
4068     printf (_("\nSection Headers:\n"));
4069   else
4070     printf (_("\nSection Header:\n"));
4071 
4072   if (is_32bit_elf)
4073     {
4074       if (do_section_details)
4075 	{
4076 	  printf (_("  [Nr] Name\n"));
4077 	  printf (_("       Type            Addr     Off    Size   ES   Lk Inf Al\n"));
4078 	}
4079       else
4080 	printf
4081 	  (_("  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al\n"));
4082     }
4083   else if (do_wide)
4084     {
4085       if (do_section_details)
4086 	{
4087 	  printf (_("  [Nr] Name\n"));
4088 	  printf (_("       Type            Address          Off    Size   ES   Lk Inf Al\n"));
4089 	}
4090       else
4091 	printf
4092 	  (_("  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al\n"));
4093     }
4094   else
4095     {
4096       if (do_section_details)
4097 	{
4098 	  printf (_("  [Nr] Name\n"));
4099 	  printf (_("       Type              Address          Offset            Link\n"));
4100 	  printf (_("       Size              EntSize          Info              Align\n"));
4101 	}
4102       else
4103 	{
4104 	  printf (_("  [Nr] Name              Type             Address           Offset\n"));
4105 	  printf (_("       Size              EntSize          Flags  Link  Info  Align\n"));
4106 	}
4107     }
4108 
4109   if (do_section_details)
4110     printf (_("       Flags\n"));
4111 
4112   for (i = 0, section = section_headers;
4113        i < elf_header.e_shnum;
4114        i++, section++)
4115     {
4116       if (do_section_details)
4117 	{
4118 	  printf ("  [%2u] %s\n",
4119 		  SECTION_HEADER_NUM (i),
4120 		  SECTION_NAME (section));
4121 	  if (is_32bit_elf || do_wide)
4122 	    printf ("       %-15.15s ",
4123 		    get_section_type_name (section->sh_type));
4124 	}
4125       else
4126 	printf ("  [%2u] %-17.17s %-15.15s ",
4127 		SECTION_HEADER_NUM (i),
4128 		SECTION_NAME (section),
4129 		get_section_type_name (section->sh_type));
4130 
4131       if (is_32bit_elf)
4132 	{
4133 	  print_vma (section->sh_addr, LONG_HEX);
4134 
4135 	  printf ( " %6.6lx %6.6lx %2.2lx",
4136 		   (unsigned long) section->sh_offset,
4137 		   (unsigned long) section->sh_size,
4138 		   (unsigned long) section->sh_entsize);
4139 
4140 	  if (do_section_details)
4141 	    fputs ("  ", stdout);
4142 	  else
4143 	    printf (" %3s ", get_elf_section_flags (section->sh_flags));
4144 
4145 	  printf ("%2ld %3lu %2ld\n",
4146 		  (unsigned long) section->sh_link,
4147 		  (unsigned long) section->sh_info,
4148 		  (unsigned long) section->sh_addralign);
4149 	}
4150       else if (do_wide)
4151 	{
4152 	  print_vma (section->sh_addr, LONG_HEX);
4153 
4154 	  if ((long) section->sh_offset == section->sh_offset)
4155 	    printf (" %6.6lx", (unsigned long) section->sh_offset);
4156 	  else
4157 	    {
4158 	      putchar (' ');
4159 	      print_vma (section->sh_offset, LONG_HEX);
4160 	    }
4161 
4162 	  if ((unsigned long) section->sh_size == section->sh_size)
4163 	    printf (" %6.6lx", (unsigned long) section->sh_size);
4164 	  else
4165 	    {
4166 	      putchar (' ');
4167 	      print_vma (section->sh_size, LONG_HEX);
4168 	    }
4169 
4170 	  if ((unsigned long) section->sh_entsize == section->sh_entsize)
4171 	    printf (" %2.2lx", (unsigned long) section->sh_entsize);
4172 	  else
4173 	    {
4174 	      putchar (' ');
4175 	      print_vma (section->sh_entsize, LONG_HEX);
4176 	    }
4177 
4178 	  if (do_section_details)
4179 	    fputs ("  ", stdout);
4180 	  else
4181 	    printf (" %3s ", get_elf_section_flags (section->sh_flags));
4182 
4183 	  printf ("%2ld %3lu ",
4184 		  (unsigned long) section->sh_link,
4185 		  (unsigned long) section->sh_info);
4186 
4187 	  if ((unsigned long) section->sh_addralign == section->sh_addralign)
4188 	    printf ("%2ld\n", (unsigned long) section->sh_addralign);
4189 	  else
4190 	    {
4191 	      print_vma (section->sh_addralign, DEC);
4192 	      putchar ('\n');
4193 	    }
4194 	}
4195       else if (do_section_details)
4196 	{
4197 	  printf ("       %-15.15s  ",
4198 		  get_section_type_name (section->sh_type));
4199 	  print_vma (section->sh_addr, LONG_HEX);
4200 	  if ((long) section->sh_offset == section->sh_offset)
4201 	    printf ("  %16.16lx", (unsigned long) section->sh_offset);
4202 	  else
4203 	    {
4204 	      printf ("  ");
4205 	      print_vma (section->sh_offset, LONG_HEX);
4206 	    }
4207 	  printf ("  %ld\n       ", (unsigned long) section->sh_link);
4208 	  print_vma (section->sh_size, LONG_HEX);
4209 	  putchar (' ');
4210 	  print_vma (section->sh_entsize, LONG_HEX);
4211 
4212 	  printf ("  %-16lu  %ld\n",
4213 		  (unsigned long) section->sh_info,
4214 		  (unsigned long) section->sh_addralign);
4215 	}
4216       else
4217 	{
4218 	  putchar (' ');
4219 	  print_vma (section->sh_addr, LONG_HEX);
4220 	  if ((long) section->sh_offset == section->sh_offset)
4221 	    printf ("  %8.8lx", (unsigned long) section->sh_offset);
4222 	  else
4223 	    {
4224 	      printf ("  ");
4225 	      print_vma (section->sh_offset, LONG_HEX);
4226 	    }
4227 	  printf ("\n       ");
4228 	  print_vma (section->sh_size, LONG_HEX);
4229 	  printf ("  ");
4230 	  print_vma (section->sh_entsize, LONG_HEX);
4231 
4232 	  printf (" %3s ", get_elf_section_flags (section->sh_flags));
4233 
4234 	  printf ("     %2ld   %3lu     %ld\n",
4235 		  (unsigned long) section->sh_link,
4236 		  (unsigned long) section->sh_info,
4237 		  (unsigned long) section->sh_addralign);
4238 	}
4239 
4240       if (do_section_details)
4241 	printf ("       %s\n", get_elf_section_flags (section->sh_flags));
4242     }
4243 
4244   if (!do_section_details)
4245     printf (_("Key to Flags:\n\
4246   W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4247   I (info), L (link order), G (group), x (unknown)\n\
4248   O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4249 
4250   return 1;
4251 }
4252 
4253 static const char *
4254 get_group_flags (unsigned int flags)
4255 {
4256   static char buff[32];
4257   switch (flags)
4258     {
4259     case GRP_COMDAT:
4260       return "COMDAT";
4261 
4262    default:
4263       snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]"), flags);
4264       break;
4265     }
4266   return buff;
4267 }
4268 
4269 static int
4270 process_section_groups (FILE *file)
4271 {
4272   Elf_Internal_Shdr *section;
4273   unsigned int i;
4274   struct group *group;
4275   Elf_Internal_Shdr *symtab_sec, *strtab_sec;
4276   Elf_Internal_Sym *symtab;
4277   char *strtab;
4278   size_t strtab_size;
4279 
4280   /* Don't process section groups unless needed.  */
4281   if (!do_unwind && !do_section_groups)
4282     return 1;
4283 
4284   if (elf_header.e_shnum == 0)
4285     {
4286       if (do_section_groups)
4287 	printf (_("\nThere are no sections in this file.\n"));
4288 
4289       return 1;
4290     }
4291 
4292   if (section_headers == NULL)
4293     {
4294       error (_("Section headers are not available!\n"));
4295       abort ();
4296     }
4297 
4298   section_headers_groups = calloc (elf_header.e_shnum,
4299 				   sizeof (struct group *));
4300 
4301   if (section_headers_groups == NULL)
4302     {
4303       error (_("Out of memory\n"));
4304       return 0;
4305     }
4306 
4307   /* Scan the sections for the group section.  */
4308   group_count = 0;
4309   for (i = 0, section = section_headers;
4310        i < elf_header.e_shnum;
4311        i++, section++)
4312     if (section->sh_type == SHT_GROUP)
4313       group_count++;
4314 
4315   if (group_count == 0)
4316     {
4317       if (do_section_groups)
4318 	printf (_("\nThere are no section groups in this file.\n"));
4319 
4320       return 1;
4321     }
4322 
4323   section_groups = calloc (group_count, sizeof (struct group));
4324 
4325   if (section_groups == NULL)
4326     {
4327       error (_("Out of memory\n"));
4328       return 0;
4329     }
4330 
4331   symtab_sec = NULL;
4332   strtab_sec = NULL;
4333   symtab = NULL;
4334   strtab = NULL;
4335   strtab_size = 0;
4336   for (i = 0, section = section_headers, group = section_groups;
4337        i < elf_header.e_shnum;
4338        i++, section++)
4339     {
4340       if (section->sh_type == SHT_GROUP)
4341 	{
4342 	  char *name = SECTION_NAME (section);
4343 	  char *group_name;
4344 	  unsigned char *start, *indices;
4345 	  unsigned int entry, j, size;
4346 	  Elf_Internal_Shdr *sec;
4347 	  Elf_Internal_Sym *sym;
4348 
4349 	  /* Get the symbol table.  */
4350 	  if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum
4351 	      || ((sec = SECTION_HEADER (section->sh_link))->sh_type
4352 		  != SHT_SYMTAB))
4353 	    {
4354 	      error (_("Bad sh_link in group section `%s'\n"), name);
4355 	      continue;
4356 	    }
4357 
4358 	  if (symtab_sec != sec)
4359 	    {
4360 	      symtab_sec = sec;
4361 	      if (symtab)
4362 		free (symtab);
4363 	      symtab = GET_ELF_SYMBOLS (file, symtab_sec);
4364 	    }
4365 
4366 	  sym = symtab + section->sh_info;
4367 
4368 	  if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4369 	    {
4370 	      bfd_vma sec_index = SECTION_HEADER_INDEX (sym->st_shndx);
4371 	      if (sec_index == 0)
4372 		{
4373 		  error (_("Bad sh_info in group section `%s'\n"), name);
4374 		  continue;
4375 		}
4376 
4377 	      group_name = SECTION_NAME (section_headers + sec_index);
4378 	      strtab_sec = NULL;
4379 	      if (strtab)
4380 		free (strtab);
4381 	      strtab = NULL;
4382 	      strtab_size = 0;
4383 	    }
4384 	  else
4385 	    {
4386 	      /* Get the string table.  */
4387 	      if (SECTION_HEADER_INDEX (symtab_sec->sh_link)
4388 		  >= elf_header.e_shnum)
4389 		{
4390 		  strtab_sec = NULL;
4391 		  if (strtab)
4392 		    free (strtab);
4393 		  strtab = NULL;
4394 		  strtab_size = 0;
4395 		}
4396 	      else if (strtab_sec
4397 		       != (sec = SECTION_HEADER (symtab_sec->sh_link)))
4398 		{
4399 		  strtab_sec = sec;
4400 		  if (strtab)
4401 		    free (strtab);
4402 		  strtab = get_data (NULL, file, strtab_sec->sh_offset,
4403 				     1, strtab_sec->sh_size,
4404 				     _("string table"));
4405 		  strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
4406 		}
4407 	      group_name = sym->st_name < strtab_size
4408 			   ? strtab + sym->st_name : "<corrupt>";
4409 	    }
4410 
4411 	  start = get_data (NULL, file, section->sh_offset,
4412 			    1, section->sh_size, _("section data"));
4413 
4414 	  indices = start;
4415 	  size = (section->sh_size / section->sh_entsize) - 1;
4416 	  entry = byte_get (indices, 4);
4417 	  indices += 4;
4418 
4419 	  if (do_section_groups)
4420 	    {
4421 	      printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4422 		      get_group_flags (entry), i, name, group_name, size);
4423 
4424 	      printf (_("   [Index]    Name\n"));
4425 	    }
4426 
4427 	  group->group_index = i;
4428 
4429 	  for (j = 0; j < size; j++)
4430 	    {
4431 	      struct group_list *g;
4432 
4433 	      entry = byte_get (indices, 4);
4434 	      indices += 4;
4435 
4436 	      if (SECTION_HEADER_INDEX (entry) >= elf_header.e_shnum)
4437 		{
4438 		  error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4439 			 entry, i, elf_header.e_shnum - 1);
4440 		  continue;
4441 		}
4442 	      else if (entry >= SHN_LORESERVE && entry <= SHN_HIRESERVE)
4443 		{
4444 		  error (_("invalid section [%5u] in group section [%5u]\n"),
4445 			 entry, i);
4446 		  continue;
4447 		}
4448 
4449 	      if (section_headers_groups [SECTION_HEADER_INDEX (entry)]
4450 		  != NULL)
4451 		{
4452 		  if (entry)
4453 		    {
4454 		      error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4455 			     entry, i,
4456 			     section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
4457 		      continue;
4458 		    }
4459 		  else
4460 		    {
4461 		      /* Intel C/C++ compiler may put section 0 in a
4462 			 section group. We just warn it the first time
4463 			 and ignore it afterwards.  */
4464 		      static int warned = 0;
4465 		      if (!warned)
4466 			{
4467 			  error (_("section 0 in group section [%5u]\n"),
4468 				 section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
4469 			  warned++;
4470 			}
4471 		    }
4472 		}
4473 
4474 	      section_headers_groups [SECTION_HEADER_INDEX (entry)]
4475 		= group;
4476 
4477 	      if (do_section_groups)
4478 		{
4479 		  sec = SECTION_HEADER (entry);
4480 		  printf ("   [%5u]   %s\n", entry, SECTION_NAME (sec));
4481 		}
4482 
4483 	      g = xmalloc (sizeof (struct group_list));
4484 	      g->section_index = entry;
4485 	      g->next = group->root;
4486 	      group->root = g;
4487 	    }
4488 
4489 	  if (start)
4490 	    free (start);
4491 
4492 	  group++;
4493 	}
4494     }
4495 
4496   if (symtab)
4497     free (symtab);
4498   if (strtab)
4499     free (strtab);
4500   return 1;
4501 }
4502 
4503 static struct
4504 {
4505   const char *name;
4506   int reloc;
4507   int size;
4508   int rela;
4509 } dynamic_relocations [] =
4510 {
4511     { "REL", DT_REL, DT_RELSZ, FALSE },
4512     { "RELA", DT_RELA, DT_RELASZ, TRUE },
4513     { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
4514 };
4515 
4516 /* Process the reloc section.  */
4517 
4518 static int
4519 process_relocs (FILE *file)
4520 {
4521   unsigned long rel_size;
4522   unsigned long rel_offset;
4523 
4524 
4525   if (!do_reloc)
4526     return 1;
4527 
4528   if (do_using_dynamic)
4529     {
4530       int is_rela;
4531       const char *name;
4532       int has_dynamic_reloc;
4533       unsigned int i;
4534 
4535       has_dynamic_reloc = 0;
4536 
4537       for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
4538 	{
4539 	  is_rela = dynamic_relocations [i].rela;
4540 	  name = dynamic_relocations [i].name;
4541 	  rel_size = dynamic_info [dynamic_relocations [i].size];
4542 	  rel_offset = dynamic_info [dynamic_relocations [i].reloc];
4543 
4544 	  has_dynamic_reloc |= rel_size;
4545 
4546 	  if (is_rela == UNKNOWN)
4547 	    {
4548 	      if (dynamic_relocations [i].reloc == DT_JMPREL)
4549 		switch (dynamic_info[DT_PLTREL])
4550 		  {
4551 		  case DT_REL:
4552 		    is_rela = FALSE;
4553 		    break;
4554 		  case DT_RELA:
4555 		    is_rela = TRUE;
4556 		    break;
4557 		  }
4558 	    }
4559 
4560 	  if (rel_size)
4561 	    {
4562 	      printf
4563 		(_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4564 		 name, rel_offset, rel_size);
4565 
4566 	      dump_relocations (file,
4567 				offset_from_vma (file, rel_offset, rel_size),
4568 				rel_size,
4569 				dynamic_symbols, num_dynamic_syms,
4570 				dynamic_strings, dynamic_strings_length, is_rela);
4571 	    }
4572 	}
4573 
4574       if (! has_dynamic_reloc)
4575 	printf (_("\nThere are no dynamic relocations in this file.\n"));
4576     }
4577   else
4578     {
4579       Elf_Internal_Shdr *section;
4580       unsigned long i;
4581       int found = 0;
4582 
4583       for (i = 0, section = section_headers;
4584 	   i < elf_header.e_shnum;
4585 	   i++, section++)
4586 	{
4587 	  if (   section->sh_type != SHT_RELA
4588 	      && section->sh_type != SHT_REL)
4589 	    continue;
4590 
4591 	  rel_offset = section->sh_offset;
4592 	  rel_size   = section->sh_size;
4593 
4594 	  if (rel_size)
4595 	    {
4596 	      Elf_Internal_Shdr *strsec;
4597 	      int is_rela;
4598 
4599 	      printf (_("\nRelocation section "));
4600 
4601 	      if (string_table == NULL)
4602 		printf ("%d", section->sh_name);
4603 	      else
4604 		printf (_("'%s'"), SECTION_NAME (section));
4605 
4606 	      printf (_(" at offset 0x%lx contains %lu entries:\n"),
4607 		 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
4608 
4609 	      is_rela = section->sh_type == SHT_RELA;
4610 
4611 	      if (section->sh_link
4612 		  && SECTION_HEADER_INDEX (section->sh_link)
4613 		     < elf_header.e_shnum)
4614 		{
4615 		  Elf_Internal_Shdr *symsec;
4616 		  Elf_Internal_Sym *symtab;
4617 		  unsigned long nsyms;
4618 		  unsigned long strtablen = 0;
4619 		  char *strtab = NULL;
4620 
4621 		  symsec = SECTION_HEADER (section->sh_link);
4622 		  if (symsec->sh_type != SHT_SYMTAB
4623 		      && symsec->sh_type != SHT_DYNSYM)
4624                     continue;
4625 
4626 		  nsyms = symsec->sh_size / symsec->sh_entsize;
4627 		  symtab = GET_ELF_SYMBOLS (file, symsec);
4628 
4629 		  if (symtab == NULL)
4630 		    continue;
4631 
4632 		  if (SECTION_HEADER_INDEX (symsec->sh_link)
4633 		      < elf_header.e_shnum)
4634 		    {
4635 		      strsec = SECTION_HEADER (symsec->sh_link);
4636 
4637 		      strtab = get_data (NULL, file, strsec->sh_offset,
4638 					 1, strsec->sh_size,
4639 					 _("string table"));
4640 		      strtablen = strtab == NULL ? 0 : strsec->sh_size;
4641 		    }
4642 
4643 		  dump_relocations (file, rel_offset, rel_size,
4644 				    symtab, nsyms, strtab, strtablen, is_rela);
4645 		  if (strtab)
4646 		    free (strtab);
4647 		  free (symtab);
4648 		}
4649 	      else
4650 		dump_relocations (file, rel_offset, rel_size,
4651 				  NULL, 0, NULL, 0, is_rela);
4652 
4653 	      found = 1;
4654 	    }
4655 	}
4656 
4657       if (! found)
4658 	printf (_("\nThere are no relocations in this file.\n"));
4659     }
4660 
4661   return 1;
4662 }
4663 
4664 /* Process the unwind section.  */
4665 
4666 #include "unwind-ia64.h"
4667 
4668 /* An absolute address consists of a section and an offset.  If the
4669    section is NULL, the offset itself is the address, otherwise, the
4670    address equals to LOAD_ADDRESS(section) + offset.  */
4671 
4672 struct absaddr
4673   {
4674     unsigned short section;
4675     bfd_vma offset;
4676   };
4677 
4678 #define ABSADDR(a) \
4679   ((a).section \
4680    ? section_headers [(a).section].sh_addr + (a).offset \
4681    : (a).offset)
4682 
4683 struct ia64_unw_aux_info
4684   {
4685     struct ia64_unw_table_entry
4686       {
4687 	struct absaddr start;
4688 	struct absaddr end;
4689 	struct absaddr info;
4690       }
4691     *table;			/* Unwind table.  */
4692     unsigned long table_len;	/* Length of unwind table.  */
4693     unsigned char *info;	/* Unwind info.  */
4694     unsigned long info_size;	/* Size of unwind info.  */
4695     bfd_vma info_addr;		/* starting address of unwind info.  */
4696     bfd_vma seg_base;		/* Starting address of segment.  */
4697     Elf_Internal_Sym *symtab;	/* The symbol table.  */
4698     unsigned long nsyms;	/* Number of symbols.  */
4699     char *strtab;		/* The string table.  */
4700     unsigned long strtab_size;	/* Size of string table.  */
4701   };
4702 
4703 static void
4704 find_symbol_for_address (Elf_Internal_Sym *symtab,
4705 			 unsigned long nsyms,
4706 			 const char *strtab,
4707 			 unsigned long strtab_size,
4708 			 struct absaddr addr,
4709 			 const char **symname,
4710 			 bfd_vma *offset)
4711 {
4712   bfd_vma dist = 0x100000;
4713   Elf_Internal_Sym *sym, *best = NULL;
4714   unsigned long i;
4715 
4716   for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
4717     {
4718       if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
4719 	  && sym->st_name != 0
4720 	  && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
4721 	  && addr.offset >= sym->st_value
4722 	  && addr.offset - sym->st_value < dist)
4723 	{
4724 	  best = sym;
4725 	  dist = addr.offset - sym->st_value;
4726 	  if (!dist)
4727 	    break;
4728 	}
4729     }
4730   if (best)
4731     {
4732       *symname = (best->st_name >= strtab_size
4733 		  ? "<corrupt>" : strtab + best->st_name);
4734       *offset = dist;
4735       return;
4736     }
4737   *symname = NULL;
4738   *offset = addr.offset;
4739 }
4740 
4741 static void
4742 dump_ia64_unwind (struct ia64_unw_aux_info *aux)
4743 {
4744   struct ia64_unw_table_entry *tp;
4745   int in_body;
4746 
4747   for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
4748     {
4749       bfd_vma stamp;
4750       bfd_vma offset;
4751       const unsigned char *dp;
4752       const unsigned char *head;
4753       const char *procname;
4754 
4755       find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
4756 			       aux->strtab_size, tp->start, &procname, &offset);
4757 
4758       fputs ("\n<", stdout);
4759 
4760       if (procname)
4761 	{
4762 	  fputs (procname, stdout);
4763 
4764 	  if (offset)
4765 	    printf ("+%lx", (unsigned long) offset);
4766 	}
4767 
4768       fputs (">: [", stdout);
4769       print_vma (tp->start.offset, PREFIX_HEX);
4770       fputc ('-', stdout);
4771       print_vma (tp->end.offset, PREFIX_HEX);
4772       printf ("], info at +0x%lx\n",
4773 	      (unsigned long) (tp->info.offset - aux->seg_base));
4774 
4775       head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
4776       stamp = byte_get ((unsigned char *) head, sizeof (stamp));
4777 
4778       printf ("  v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4779 	      (unsigned) UNW_VER (stamp),
4780 	      (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
4781 	      UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
4782 	      UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
4783 	      (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
4784 
4785       if (UNW_VER (stamp) != 1)
4786 	{
4787 	  printf ("\tUnknown version.\n");
4788 	  continue;
4789 	}
4790 
4791       in_body = 0;
4792       for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp);)
4793 	dp = unw_decode (dp, in_body, & in_body);
4794     }
4795 }
4796 
4797 static int
4798 slurp_ia64_unwind_table (FILE *file,
4799 			 struct ia64_unw_aux_info *aux,
4800 			 Elf_Internal_Shdr *sec)
4801 {
4802   unsigned long size, nrelas, i;
4803   Elf_Internal_Phdr *seg;
4804   struct ia64_unw_table_entry *tep;
4805   Elf_Internal_Shdr *relsec;
4806   Elf_Internal_Rela *rela, *rp;
4807   unsigned char *table, *tp;
4808   Elf_Internal_Sym *sym;
4809   const char *relname;
4810 
4811   /* First, find the starting address of the segment that includes
4812      this section: */
4813 
4814   if (elf_header.e_phnum)
4815     {
4816       if (! get_program_headers (file))
4817 	  return 0;
4818 
4819       for (seg = program_headers;
4820 	   seg < program_headers + elf_header.e_phnum;
4821 	   ++seg)
4822 	{
4823 	  if (seg->p_type != PT_LOAD)
4824 	    continue;
4825 
4826 	  if (sec->sh_addr >= seg->p_vaddr
4827 	      && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
4828 	    {
4829 	      aux->seg_base = seg->p_vaddr;
4830 	      break;
4831 	    }
4832 	}
4833     }
4834 
4835   /* Second, build the unwind table from the contents of the unwind section:  */
4836   size = sec->sh_size;
4837   table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
4838   if (!table)
4839     return 0;
4840 
4841   aux->table = xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0]));
4842   tep = aux->table;
4843   for (tp = table; tp < table + size; tp += 3 * eh_addr_size, ++tep)
4844     {
4845       tep->start.section = SHN_UNDEF;
4846       tep->end.section   = SHN_UNDEF;
4847       tep->info.section  = SHN_UNDEF;
4848       if (is_32bit_elf)
4849 	{
4850 	  tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
4851 	  tep->end.offset   = byte_get ((unsigned char *) tp + 4, 4);
4852 	  tep->info.offset  = byte_get ((unsigned char *) tp + 8, 4);
4853 	}
4854       else
4855 	{
4856 	  tep->start.offset = BYTE_GET ((unsigned char *) tp +  0);
4857 	  tep->end.offset   = BYTE_GET ((unsigned char *) tp +  8);
4858 	  tep->info.offset  = BYTE_GET ((unsigned char *) tp + 16);
4859 	}
4860       tep->start.offset += aux->seg_base;
4861       tep->end.offset   += aux->seg_base;
4862       tep->info.offset  += aux->seg_base;
4863     }
4864   free (table);
4865 
4866   /* Third, apply any relocations to the unwind table: */
4867 
4868   for (relsec = section_headers;
4869        relsec < section_headers + elf_header.e_shnum;
4870        ++relsec)
4871     {
4872       if (relsec->sh_type != SHT_RELA
4873 	  || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
4874 	  || SECTION_HEADER (relsec->sh_info) != sec)
4875 	continue;
4876 
4877       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
4878 			      & rela, & nrelas))
4879 	return 0;
4880 
4881       for (rp = rela; rp < rela + nrelas; ++rp)
4882 	{
4883 	  if (is_32bit_elf)
4884 	    {
4885 	      relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
4886 	      sym = aux->symtab + ELF32_R_SYM (rp->r_info);
4887 	    }
4888 	  else
4889 	    {
4890 	      relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
4891 	      sym = aux->symtab + ELF64_R_SYM (rp->r_info);
4892 	    }
4893 
4894 	  if (! strneq (relname, "R_IA64_SEGREL", 13))
4895 	    {
4896 	      warn (_("Skipping unexpected relocation type %s\n"), relname);
4897 	      continue;
4898 	    }
4899 
4900 	  i = rp->r_offset / (3 * eh_addr_size);
4901 
4902 	  switch (rp->r_offset/eh_addr_size % 3)
4903 	    {
4904 	    case 0:
4905 	      aux->table[i].start.section = sym->st_shndx;
4906 	      aux->table[i].start.offset += rp->r_addend + sym->st_value;
4907 	      break;
4908 	    case 1:
4909 	      aux->table[i].end.section   = sym->st_shndx;
4910 	      aux->table[i].end.offset   += rp->r_addend + sym->st_value;
4911 	      break;
4912 	    case 2:
4913 	      aux->table[i].info.section  = sym->st_shndx;
4914 	      aux->table[i].info.offset  += rp->r_addend + sym->st_value;
4915 	      break;
4916 	    default:
4917 	      break;
4918 	    }
4919 	}
4920 
4921       free (rela);
4922     }
4923 
4924   aux->table_len = size / (3 * eh_addr_size);
4925   return 1;
4926 }
4927 
4928 static int
4929 ia64_process_unwind (FILE *file)
4930 {
4931   Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
4932   unsigned long i, unwcount = 0, unwstart = 0;
4933   struct ia64_unw_aux_info aux;
4934 
4935   memset (& aux, 0, sizeof (aux));
4936 
4937   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
4938     {
4939       if (sec->sh_type == SHT_SYMTAB
4940 	  && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
4941 	{
4942 	  aux.nsyms = sec->sh_size / sec->sh_entsize;
4943 	  aux.symtab = GET_ELF_SYMBOLS (file, sec);
4944 
4945 	  strsec = SECTION_HEADER (sec->sh_link);
4946 	  aux.strtab = get_data (NULL, file, strsec->sh_offset,
4947 				 1, strsec->sh_size, _("string table"));
4948 	  aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
4949 	}
4950       else if (sec->sh_type == SHT_IA_64_UNWIND)
4951 	unwcount++;
4952     }
4953 
4954   if (!unwcount)
4955     printf (_("\nThere are no unwind sections in this file.\n"));
4956 
4957   while (unwcount-- > 0)
4958     {
4959       char *suffix;
4960       size_t len, len2;
4961 
4962       for (i = unwstart, sec = section_headers + unwstart;
4963 	   i < elf_header.e_shnum; ++i, ++sec)
4964 	if (sec->sh_type == SHT_IA_64_UNWIND)
4965 	  {
4966 	    unwsec = sec;
4967 	    break;
4968 	  }
4969 
4970       unwstart = i + 1;
4971       len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
4972 
4973       if ((unwsec->sh_flags & SHF_GROUP) != 0)
4974 	{
4975 	  /* We need to find which section group it is in.  */
4976 	  struct group_list *g = section_headers_groups [i]->root;
4977 
4978 	  for (; g != NULL; g = g->next)
4979 	    {
4980 	      sec = SECTION_HEADER (g->section_index);
4981 
4982 	      if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
4983 		break;
4984 	    }
4985 
4986 	  if (g == NULL)
4987 	    i = elf_header.e_shnum;
4988 	}
4989       else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
4990 	{
4991 	  /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO.  */
4992 	  len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
4993 	  suffix = SECTION_NAME (unwsec) + len;
4994 	  for (i = 0, sec = section_headers; i < elf_header.e_shnum;
4995 	       ++i, ++sec)
4996 	    if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
4997 		&& streq (SECTION_NAME (sec) + len2, suffix))
4998 	      break;
4999 	}
5000       else
5001 	{
5002 	  /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5003 	     .IA_64.unwind or BAR -> .IA_64.unwind_info.  */
5004 	  len = sizeof (ELF_STRING_ia64_unwind) - 1;
5005 	  len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
5006 	  suffix = "";
5007 	  if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
5008 	    suffix = SECTION_NAME (unwsec) + len;
5009 	  for (i = 0, sec = section_headers; i < elf_header.e_shnum;
5010 	       ++i, ++sec)
5011 	    if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
5012 		&& streq (SECTION_NAME (sec) + len2, suffix))
5013 	      break;
5014 	}
5015 
5016       if (i == elf_header.e_shnum)
5017 	{
5018 	  printf (_("\nCould not find unwind info section for "));
5019 
5020 	  if (string_table == NULL)
5021 	    printf ("%d", unwsec->sh_name);
5022 	  else
5023 	    printf (_("'%s'"), SECTION_NAME (unwsec));
5024 	}
5025       else
5026 	{
5027 	  aux.info_size = sec->sh_size;
5028 	  aux.info_addr = sec->sh_addr;
5029 	  aux.info = get_data (NULL, file, sec->sh_offset, 1, aux.info_size,
5030 			       _("unwind info"));
5031 
5032 	  printf (_("\nUnwind section "));
5033 
5034 	  if (string_table == NULL)
5035 	    printf ("%d", unwsec->sh_name);
5036 	  else
5037 	    printf (_("'%s'"), SECTION_NAME (unwsec));
5038 
5039 	  printf (_(" at offset 0x%lx contains %lu entries:\n"),
5040 		  (unsigned long) unwsec->sh_offset,
5041 		  (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
5042 
5043 	  (void) slurp_ia64_unwind_table (file, & aux, unwsec);
5044 
5045 	  if (aux.table_len > 0)
5046 	    dump_ia64_unwind (& aux);
5047 
5048 	  if (aux.table)
5049 	    free ((char *) aux.table);
5050 	  if (aux.info)
5051 	    free ((char *) aux.info);
5052 	  aux.table = NULL;
5053 	  aux.info = NULL;
5054 	}
5055     }
5056 
5057   if (aux.symtab)
5058     free (aux.symtab);
5059   if (aux.strtab)
5060     free ((char *) aux.strtab);
5061 
5062   return 1;
5063 }
5064 
5065 struct hppa_unw_aux_info
5066   {
5067     struct hppa_unw_table_entry
5068       {
5069 	struct absaddr start;
5070 	struct absaddr end;
5071 	unsigned int Cannot_unwind:1;			/* 0 */
5072 	unsigned int Millicode:1;			/* 1 */
5073 	unsigned int Millicode_save_sr0:1;		/* 2 */
5074 	unsigned int Region_description:2;		/* 3..4 */
5075 	unsigned int reserved1:1;			/* 5 */
5076 	unsigned int Entry_SR:1;			/* 6 */
5077 	unsigned int Entry_FR:4;     /* number saved */	/* 7..10 */
5078 	unsigned int Entry_GR:5;     /* number saved */	/* 11..15 */
5079 	unsigned int Args_stored:1;			/* 16 */
5080 	unsigned int Variable_Frame:1;			/* 17 */
5081 	unsigned int Separate_Package_Body:1;		/* 18 */
5082 	unsigned int Frame_Extension_Millicode:1;	/* 19 */
5083 	unsigned int Stack_Overflow_Check:1;		/* 20 */
5084 	unsigned int Two_Instruction_SP_Increment:1;	/* 21 */
5085 	unsigned int Ada_Region:1;			/* 22 */
5086 	unsigned int cxx_info:1;			/* 23 */
5087 	unsigned int cxx_try_catch:1;			/* 24 */
5088 	unsigned int sched_entry_seq:1;			/* 25 */
5089 	unsigned int reserved2:1;			/* 26 */
5090 	unsigned int Save_SP:1;				/* 27 */
5091 	unsigned int Save_RP:1;				/* 28 */
5092 	unsigned int Save_MRP_in_frame:1;		/* 29 */
5093 	unsigned int extn_ptr_defined:1;		/* 30 */
5094 	unsigned int Cleanup_defined:1;			/* 31 */
5095 
5096 	unsigned int MPE_XL_interrupt_marker:1;		/* 0 */
5097 	unsigned int HP_UX_interrupt_marker:1;		/* 1 */
5098 	unsigned int Large_frame:1;			/* 2 */
5099 	unsigned int Pseudo_SP_Set:1;			/* 3 */
5100 	unsigned int reserved4:1;			/* 4 */
5101 	unsigned int Total_frame_size:27;		/* 5..31 */
5102       }
5103     *table;			/* Unwind table.  */
5104     unsigned long table_len;	/* Length of unwind table.  */
5105     bfd_vma seg_base;		/* Starting address of segment.  */
5106     Elf_Internal_Sym *symtab;	/* The symbol table.  */
5107     unsigned long nsyms;	/* Number of symbols.  */
5108     char *strtab;		/* The string table.  */
5109     unsigned long strtab_size;	/* Size of string table.  */
5110   };
5111 
5112 static void
5113 dump_hppa_unwind (struct hppa_unw_aux_info *aux)
5114 {
5115   struct hppa_unw_table_entry *tp;
5116 
5117   for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
5118     {
5119       bfd_vma offset;
5120       const char *procname;
5121 
5122       find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
5123 			       aux->strtab_size, tp->start, &procname,
5124 			       &offset);
5125 
5126       fputs ("\n<", stdout);
5127 
5128       if (procname)
5129 	{
5130 	  fputs (procname, stdout);
5131 
5132 	  if (offset)
5133 	    printf ("+%lx", (unsigned long) offset);
5134 	}
5135 
5136       fputs (">: [", stdout);
5137       print_vma (tp->start.offset, PREFIX_HEX);
5138       fputc ('-', stdout);
5139       print_vma (tp->end.offset, PREFIX_HEX);
5140       printf ("]\n\t");
5141 
5142 #define PF(_m) if (tp->_m) printf (#_m " ");
5143 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5144       PF(Cannot_unwind);
5145       PF(Millicode);
5146       PF(Millicode_save_sr0);
5147       /* PV(Region_description);  */
5148       PF(Entry_SR);
5149       PV(Entry_FR);
5150       PV(Entry_GR);
5151       PF(Args_stored);
5152       PF(Variable_Frame);
5153       PF(Separate_Package_Body);
5154       PF(Frame_Extension_Millicode);
5155       PF(Stack_Overflow_Check);
5156       PF(Two_Instruction_SP_Increment);
5157       PF(Ada_Region);
5158       PF(cxx_info);
5159       PF(cxx_try_catch);
5160       PF(sched_entry_seq);
5161       PF(Save_SP);
5162       PF(Save_RP);
5163       PF(Save_MRP_in_frame);
5164       PF(extn_ptr_defined);
5165       PF(Cleanup_defined);
5166       PF(MPE_XL_interrupt_marker);
5167       PF(HP_UX_interrupt_marker);
5168       PF(Large_frame);
5169       PF(Pseudo_SP_Set);
5170       PV(Total_frame_size);
5171 #undef PF
5172 #undef PV
5173     }
5174 
5175   printf ("\n");
5176 }
5177 
5178 static int
5179 slurp_hppa_unwind_table (FILE *file,
5180 			 struct hppa_unw_aux_info *aux,
5181 			 Elf_Internal_Shdr *sec)
5182 {
5183   unsigned long size, unw_ent_size, nentries, nrelas, i;
5184   Elf_Internal_Phdr *seg;
5185   struct hppa_unw_table_entry *tep;
5186   Elf_Internal_Shdr *relsec;
5187   Elf_Internal_Rela *rela, *rp;
5188   unsigned char *table, *tp;
5189   Elf_Internal_Sym *sym;
5190   const char *relname;
5191 
5192   /* First, find the starting address of the segment that includes
5193      this section.  */
5194 
5195   if (elf_header.e_phnum)
5196     {
5197       if (! get_program_headers (file))
5198 	return 0;
5199 
5200       for (seg = program_headers;
5201 	   seg < program_headers + elf_header.e_phnum;
5202 	   ++seg)
5203 	{
5204 	  if (seg->p_type != PT_LOAD)
5205 	    continue;
5206 
5207 	  if (sec->sh_addr >= seg->p_vaddr
5208 	      && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
5209 	    {
5210 	      aux->seg_base = seg->p_vaddr;
5211 	      break;
5212 	    }
5213 	}
5214     }
5215 
5216   /* Second, build the unwind table from the contents of the unwind
5217      section.  */
5218   size = sec->sh_size;
5219   table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
5220   if (!table)
5221     return 0;
5222 
5223   unw_ent_size = 16;
5224   nentries = size / unw_ent_size;
5225   size = unw_ent_size * nentries;
5226 
5227   tep = aux->table = xcmalloc (nentries, sizeof (aux->table[0]));
5228 
5229   for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
5230     {
5231       unsigned int tmp1, tmp2;
5232 
5233       tep->start.section = SHN_UNDEF;
5234       tep->end.section   = SHN_UNDEF;
5235 
5236       tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
5237       tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
5238       tmp1 = byte_get ((unsigned char *) tp + 8, 4);
5239       tmp2 = byte_get ((unsigned char *) tp + 12, 4);
5240 
5241       tep->start.offset += aux->seg_base;
5242       tep->end.offset   += aux->seg_base;
5243 
5244       tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
5245       tep->Millicode = (tmp1 >> 30) & 0x1;
5246       tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
5247       tep->Region_description = (tmp1 >> 27) & 0x3;
5248       tep->reserved1 = (tmp1 >> 26) & 0x1;
5249       tep->Entry_SR = (tmp1 >> 25) & 0x1;
5250       tep->Entry_FR = (tmp1 >> 21) & 0xf;
5251       tep->Entry_GR = (tmp1 >> 16) & 0x1f;
5252       tep->Args_stored = (tmp1 >> 15) & 0x1;
5253       tep->Variable_Frame = (tmp1 >> 14) & 0x1;
5254       tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
5255       tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
5256       tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
5257       tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
5258       tep->Ada_Region = (tmp1 >> 9) & 0x1;
5259       tep->cxx_info = (tmp1 >> 8) & 0x1;
5260       tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
5261       tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
5262       tep->reserved2 = (tmp1 >> 5) & 0x1;
5263       tep->Save_SP = (tmp1 >> 4) & 0x1;
5264       tep->Save_RP = (tmp1 >> 3) & 0x1;
5265       tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
5266       tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
5267       tep->Cleanup_defined = tmp1 & 0x1;
5268 
5269       tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
5270       tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
5271       tep->Large_frame = (tmp2 >> 29) & 0x1;
5272       tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
5273       tep->reserved4 = (tmp2 >> 27) & 0x1;
5274       tep->Total_frame_size = tmp2 & 0x7ffffff;
5275     }
5276   free (table);
5277 
5278   /* Third, apply any relocations to the unwind table.  */
5279 
5280   for (relsec = section_headers;
5281        relsec < section_headers + elf_header.e_shnum;
5282        ++relsec)
5283     {
5284       if (relsec->sh_type != SHT_RELA
5285 	  || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
5286 	  || SECTION_HEADER (relsec->sh_info) != sec)
5287 	continue;
5288 
5289       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
5290 			      & rela, & nrelas))
5291 	return 0;
5292 
5293       for (rp = rela; rp < rela + nrelas; ++rp)
5294 	{
5295 	  if (is_32bit_elf)
5296 	    {
5297 	      relname = elf_hppa_reloc_type (ELF32_R_TYPE (rp->r_info));
5298 	      sym = aux->symtab + ELF32_R_SYM (rp->r_info);
5299 	    }
5300 	  else
5301 	    {
5302 	      relname = elf_hppa_reloc_type (ELF64_R_TYPE (rp->r_info));
5303 	      sym = aux->symtab + ELF64_R_SYM (rp->r_info);
5304 	    }
5305 
5306 	  /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64.  */
5307 	  if (strncmp (relname, "R_PARISC_SEGREL", 15) != 0)
5308 	    {
5309 	      warn (_("Skipping unexpected relocation type %s\n"), relname);
5310 	      continue;
5311 	    }
5312 
5313 	  i = rp->r_offset / unw_ent_size;
5314 
5315 	  switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
5316 	    {
5317 	    case 0:
5318 	      aux->table[i].start.section = sym->st_shndx;
5319 	      aux->table[i].start.offset += sym->st_value + rp->r_addend;
5320 	      break;
5321 	    case 1:
5322 	      aux->table[i].end.section   = sym->st_shndx;
5323 	      aux->table[i].end.offset   += sym->st_value + rp->r_addend;
5324 	      break;
5325 	    default:
5326 	      break;
5327 	    }
5328 	}
5329 
5330       free (rela);
5331     }
5332 
5333   aux->table_len = nentries;
5334 
5335   return 1;
5336 }
5337 
5338 static int
5339 hppa_process_unwind (FILE *file)
5340 {
5341   struct hppa_unw_aux_info aux;
5342   Elf_Internal_Shdr *unwsec = NULL;
5343   Elf_Internal_Shdr *strsec;
5344   Elf_Internal_Shdr *sec;
5345   unsigned long i;
5346 
5347   memset (& aux, 0, sizeof (aux));
5348 
5349   if (string_table == NULL)
5350     return 1;
5351 
5352   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5353     {
5354       if (sec->sh_type == SHT_SYMTAB
5355 	  && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
5356 	{
5357 	  aux.nsyms = sec->sh_size / sec->sh_entsize;
5358 	  aux.symtab = GET_ELF_SYMBOLS (file, sec);
5359 
5360 	  strsec = SECTION_HEADER (sec->sh_link);
5361 	  aux.strtab = get_data (NULL, file, strsec->sh_offset,
5362 				 1, strsec->sh_size, _("string table"));
5363 	  aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
5364 	}
5365       else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
5366 	unwsec = sec;
5367     }
5368 
5369   if (!unwsec)
5370     printf (_("\nThere are no unwind sections in this file.\n"));
5371 
5372   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5373     {
5374       if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
5375 	{
5376 	  printf (_("\nUnwind section "));
5377 	  printf (_("'%s'"), SECTION_NAME (sec));
5378 
5379 	  printf (_(" at offset 0x%lx contains %lu entries:\n"),
5380 		  (unsigned long) sec->sh_offset,
5381 		  (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
5382 
5383           slurp_hppa_unwind_table (file, &aux, sec);
5384 	  if (aux.table_len > 0)
5385 	    dump_hppa_unwind (&aux);
5386 
5387 	  if (aux.table)
5388 	    free ((char *) aux.table);
5389 	  aux.table = NULL;
5390 	}
5391     }
5392 
5393   if (aux.symtab)
5394     free (aux.symtab);
5395   if (aux.strtab)
5396     free ((char *) aux.strtab);
5397 
5398   return 1;
5399 }
5400 
5401 static int
5402 process_unwind (FILE *file)
5403 {
5404   struct unwind_handler {
5405     int machtype;
5406     int (*handler)(FILE *file);
5407   } handlers[] = {
5408     { EM_IA_64, ia64_process_unwind },
5409     { EM_PARISC, hppa_process_unwind },
5410     { 0, 0 }
5411   };
5412   int i;
5413 
5414   if (!do_unwind)
5415     return 1;
5416 
5417   for (i = 0; handlers[i].handler != NULL; i++)
5418     if (elf_header.e_machine == handlers[i].machtype)
5419       return handlers[i].handler (file);
5420 
5421   printf (_("\nThere are no unwind sections in this file.\n"));
5422   return 1;
5423 }
5424 
5425 static void
5426 dynamic_section_mips_val (Elf_Internal_Dyn *entry)
5427 {
5428   switch (entry->d_tag)
5429     {
5430     case DT_MIPS_FLAGS:
5431       if (entry->d_un.d_val == 0)
5432 	printf ("NONE\n");
5433       else
5434 	{
5435 	  static const char * opts[] =
5436 	  {
5437 	    "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5438 	    "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5439 	    "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5440 	    "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5441 	    "RLD_ORDER_SAFE"
5442 	  };
5443 	  unsigned int cnt;
5444 	  int first = 1;
5445 	  for (cnt = 0; cnt < NUM_ELEM (opts); ++cnt)
5446 	    if (entry->d_un.d_val & (1 << cnt))
5447 	      {
5448 		printf ("%s%s", first ? "" : " ", opts[cnt]);
5449 		first = 0;
5450 	      }
5451 	  puts ("");
5452 	}
5453       break;
5454 
5455     case DT_MIPS_IVERSION:
5456       if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
5457 	printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
5458       else
5459 	printf ("<corrupt: %ld>\n", (long) entry->d_un.d_ptr);
5460       break;
5461 
5462     case DT_MIPS_TIME_STAMP:
5463       {
5464 	char timebuf[20];
5465 	struct tm *tmp;
5466 
5467 	time_t time = entry->d_un.d_val;
5468 	tmp = gmtime (&time);
5469 	snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
5470 		  tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
5471 		  tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
5472 	printf ("Time Stamp: %s\n", timebuf);
5473       }
5474       break;
5475 
5476     case DT_MIPS_RLD_VERSION:
5477     case DT_MIPS_LOCAL_GOTNO:
5478     case DT_MIPS_CONFLICTNO:
5479     case DT_MIPS_LIBLISTNO:
5480     case DT_MIPS_SYMTABNO:
5481     case DT_MIPS_UNREFEXTNO:
5482     case DT_MIPS_HIPAGENO:
5483     case DT_MIPS_DELTA_CLASS_NO:
5484     case DT_MIPS_DELTA_INSTANCE_NO:
5485     case DT_MIPS_DELTA_RELOC_NO:
5486     case DT_MIPS_DELTA_SYM_NO:
5487     case DT_MIPS_DELTA_CLASSSYM_NO:
5488     case DT_MIPS_COMPACT_SIZE:
5489       printf ("%ld\n", (long) entry->d_un.d_ptr);
5490       break;
5491 
5492     default:
5493       printf ("%#lx\n", (long) entry->d_un.d_ptr);
5494     }
5495 }
5496 
5497 
5498 static void
5499 dynamic_section_parisc_val (Elf_Internal_Dyn *entry)
5500 {
5501   switch (entry->d_tag)
5502     {
5503     case DT_HP_DLD_FLAGS:
5504       {
5505 	static struct
5506 	{
5507 	  long int bit;
5508 	  const char *str;
5509 	}
5510 	flags[] =
5511 	{
5512 	  { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
5513 	  { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
5514 	  { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
5515 	  { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
5516 	  { DT_HP_BIND_NOW, "HP_BIND_NOW" },
5517 	  { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
5518 	  { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
5519 	  { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
5520 	  { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
5521 	  { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
5522 	  { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
5523 	  { DT_HP_GST, "HP_GST" },
5524 	  { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
5525 	  { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
5526 	  { DT_HP_NODELETE, "HP_NODELETE" },
5527 	  { DT_HP_GROUP, "HP_GROUP" },
5528 	  { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
5529 	};
5530 	int first = 1;
5531 	size_t cnt;
5532 	bfd_vma val = entry->d_un.d_val;
5533 
5534 	for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
5535 	  if (val & flags[cnt].bit)
5536 	    {
5537 	      if (! first)
5538 		putchar (' ');
5539 	      fputs (flags[cnt].str, stdout);
5540 	      first = 0;
5541 	      val ^= flags[cnt].bit;
5542 	    }
5543 
5544 	if (val != 0 || first)
5545 	  {
5546 	    if (! first)
5547 	      putchar (' ');
5548 	    print_vma (val, HEX);
5549 	  }
5550       }
5551       break;
5552 
5553     default:
5554       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5555       break;
5556     }
5557   putchar ('\n');
5558 }
5559 
5560 static void
5561 dynamic_section_ia64_val (Elf_Internal_Dyn *entry)
5562 {
5563   switch (entry->d_tag)
5564     {
5565     case DT_IA_64_PLT_RESERVE:
5566       /* First 3 slots reserved.  */
5567       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5568       printf (" -- ");
5569       print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
5570       break;
5571 
5572     default:
5573       print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5574       break;
5575     }
5576   putchar ('\n');
5577 }
5578 
5579 static int
5580 get_32bit_dynamic_section (FILE *file)
5581 {
5582   Elf32_External_Dyn *edyn, *ext;
5583   Elf_Internal_Dyn *entry;
5584 
5585   edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
5586 		   _("dynamic section"));
5587   if (!edyn)
5588     return 0;
5589 
5590 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5591    might not have the luxury of section headers.  Look for the DT_NULL
5592    terminator to determine the number of entries.  */
5593   for (ext = edyn, dynamic_nent = 0;
5594        (char *) ext < (char *) edyn + dynamic_size;
5595        ext++)
5596     {
5597       dynamic_nent++;
5598       if (BYTE_GET (ext->d_tag) == DT_NULL)
5599 	break;
5600     }
5601 
5602   dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5603   if (dynamic_section == NULL)
5604     {
5605       error (_("Out of memory\n"));
5606       free (edyn);
5607       return 0;
5608     }
5609 
5610   for (ext = edyn, entry = dynamic_section;
5611        entry < dynamic_section + dynamic_nent;
5612        ext++, entry++)
5613     {
5614       entry->d_tag      = BYTE_GET (ext->d_tag);
5615       entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
5616     }
5617 
5618   free (edyn);
5619 
5620   return 1;
5621 }
5622 
5623 static int
5624 get_64bit_dynamic_section (FILE *file)
5625 {
5626   Elf64_External_Dyn *edyn, *ext;
5627   Elf_Internal_Dyn *entry;
5628 
5629   edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
5630 		   _("dynamic section"));
5631   if (!edyn)
5632     return 0;
5633 
5634 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5635    might not have the luxury of section headers.  Look for the DT_NULL
5636    terminator to determine the number of entries.  */
5637   for (ext = edyn, dynamic_nent = 0;
5638        (char *) ext < (char *) edyn + dynamic_size;
5639        ext++)
5640     {
5641       dynamic_nent++;
5642       if (BYTE_GET (ext->d_tag) == DT_NULL)
5643 	break;
5644     }
5645 
5646   dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5647   if (dynamic_section == NULL)
5648     {
5649       error (_("Out of memory\n"));
5650       free (edyn);
5651       return 0;
5652     }
5653 
5654   for (ext = edyn, entry = dynamic_section;
5655        entry < dynamic_section + dynamic_nent;
5656        ext++, entry++)
5657     {
5658       entry->d_tag      = BYTE_GET (ext->d_tag);
5659       entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
5660     }
5661 
5662   free (edyn);
5663 
5664   return 1;
5665 }
5666 
5667 static void
5668 print_dynamic_flags (bfd_vma flags)
5669 {
5670   int first = 1;
5671 
5672   while (flags)
5673     {
5674       bfd_vma flag;
5675 
5676       flag = flags & - flags;
5677       flags &= ~ flag;
5678 
5679       if (first)
5680 	first = 0;
5681       else
5682 	putc (' ', stdout);
5683 
5684       switch (flag)
5685 	{
5686 	case DF_ORIGIN:		fputs ("ORIGIN", stdout); break;
5687 	case DF_SYMBOLIC:	fputs ("SYMBOLIC", stdout); break;
5688 	case DF_TEXTREL:	fputs ("TEXTREL", stdout); break;
5689 	case DF_BIND_NOW:	fputs ("BIND_NOW", stdout); break;
5690 	case DF_STATIC_TLS:	fputs ("STATIC_TLS", stdout); break;
5691 	default:		fputs ("unknown", stdout); break;
5692 	}
5693     }
5694   puts ("");
5695 }
5696 
5697 /* Parse and display the contents of the dynamic section.  */
5698 
5699 static int
5700 process_dynamic_section (FILE *file)
5701 {
5702   Elf_Internal_Dyn *entry;
5703 
5704   if (dynamic_size == 0)
5705     {
5706       if (do_dynamic)
5707 	printf (_("\nThere is no dynamic section in this file.\n"));
5708 
5709       return 1;
5710     }
5711 
5712   if (is_32bit_elf)
5713     {
5714       if (! get_32bit_dynamic_section (file))
5715 	return 0;
5716     }
5717   else if (! get_64bit_dynamic_section (file))
5718     return 0;
5719 
5720   /* Find the appropriate symbol table.  */
5721   if (dynamic_symbols == NULL)
5722     {
5723       for (entry = dynamic_section;
5724 	   entry < dynamic_section + dynamic_nent;
5725 	   ++entry)
5726 	{
5727 	  Elf_Internal_Shdr section;
5728 
5729 	  if (entry->d_tag != DT_SYMTAB)
5730 	    continue;
5731 
5732 	  dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
5733 
5734 	  /* Since we do not know how big the symbol table is,
5735 	     we default to reading in the entire file (!) and
5736 	     processing that.  This is overkill, I know, but it
5737 	     should work.  */
5738 	  section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
5739 
5740 	  if (archive_file_offset != 0)
5741 	    section.sh_size = archive_file_size - section.sh_offset;
5742 	  else
5743 	    {
5744 	      if (fseek (file, 0, SEEK_END))
5745 		error (_("Unable to seek to end of file!"));
5746 
5747 	      section.sh_size = ftell (file) - section.sh_offset;
5748 	    }
5749 
5750 	  if (is_32bit_elf)
5751 	    section.sh_entsize = sizeof (Elf32_External_Sym);
5752 	  else
5753 	    section.sh_entsize = sizeof (Elf64_External_Sym);
5754 
5755 	  num_dynamic_syms = section.sh_size / section.sh_entsize;
5756 	  if (num_dynamic_syms < 1)
5757 	    {
5758 	      error (_("Unable to determine the number of symbols to load\n"));
5759 	      continue;
5760 	    }
5761 
5762 	  dynamic_symbols = GET_ELF_SYMBOLS (file, &section);
5763 	}
5764     }
5765 
5766   /* Similarly find a string table.  */
5767   if (dynamic_strings == NULL)
5768     {
5769       for (entry = dynamic_section;
5770 	   entry < dynamic_section + dynamic_nent;
5771 	   ++entry)
5772 	{
5773 	  unsigned long offset;
5774 	  long str_tab_len;
5775 
5776 	  if (entry->d_tag != DT_STRTAB)
5777 	    continue;
5778 
5779 	  dynamic_info[DT_STRTAB] = entry->d_un.d_val;
5780 
5781 	  /* Since we do not know how big the string table is,
5782 	     we default to reading in the entire file (!) and
5783 	     processing that.  This is overkill, I know, but it
5784 	     should work.  */
5785 
5786 	  offset = offset_from_vma (file, entry->d_un.d_val, 0);
5787 
5788 	  if (archive_file_offset != 0)
5789 	    str_tab_len = archive_file_size - offset;
5790 	  else
5791 	    {
5792 	      if (fseek (file, 0, SEEK_END))
5793 		error (_("Unable to seek to end of file\n"));
5794 	      str_tab_len = ftell (file) - offset;
5795 	    }
5796 
5797 	  if (str_tab_len < 1)
5798 	    {
5799 	      error
5800 		(_("Unable to determine the length of the dynamic string table\n"));
5801 	      continue;
5802 	    }
5803 
5804 	  dynamic_strings = get_data (NULL, file, offset, 1, str_tab_len,
5805 				      _("dynamic string table"));
5806 	  dynamic_strings_length = str_tab_len;
5807 	  break;
5808 	}
5809     }
5810 
5811   /* And find the syminfo section if available.  */
5812   if (dynamic_syminfo == NULL)
5813     {
5814       unsigned long syminsz = 0;
5815 
5816       for (entry = dynamic_section;
5817 	   entry < dynamic_section + dynamic_nent;
5818 	   ++entry)
5819 	{
5820 	  if (entry->d_tag == DT_SYMINENT)
5821 	    {
5822 	      /* Note: these braces are necessary to avoid a syntax
5823 		 error from the SunOS4 C compiler.  */
5824 	      assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
5825 	    }
5826 	  else if (entry->d_tag == DT_SYMINSZ)
5827 	    syminsz = entry->d_un.d_val;
5828 	  else if (entry->d_tag == DT_SYMINFO)
5829 	    dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
5830 						      syminsz);
5831 	}
5832 
5833       if (dynamic_syminfo_offset != 0 && syminsz != 0)
5834 	{
5835 	  Elf_External_Syminfo *extsyminfo, *extsym;
5836 	  Elf_Internal_Syminfo *syminfo;
5837 
5838 	  /* There is a syminfo section.  Read the data.  */
5839 	  extsyminfo = get_data (NULL, file, dynamic_syminfo_offset, 1,
5840 				 syminsz, _("symbol information"));
5841 	  if (!extsyminfo)
5842 	    return 0;
5843 
5844 	  dynamic_syminfo = malloc (syminsz);
5845 	  if (dynamic_syminfo == NULL)
5846 	    {
5847 	      error (_("Out of memory\n"));
5848 	      return 0;
5849 	    }
5850 
5851 	  dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
5852 	  for (syminfo = dynamic_syminfo, extsym = extsyminfo;
5853 	       syminfo < dynamic_syminfo + dynamic_syminfo_nent;
5854 	       ++syminfo, ++extsym)
5855 	    {
5856 	      syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
5857 	      syminfo->si_flags = BYTE_GET (extsym->si_flags);
5858 	    }
5859 
5860 	  free (extsyminfo);
5861 	}
5862     }
5863 
5864   if (do_dynamic && dynamic_addr)
5865     printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5866 	    dynamic_addr, dynamic_nent);
5867   if (do_dynamic)
5868     printf (_("  Tag        Type                         Name/Value\n"));
5869 
5870   for (entry = dynamic_section;
5871        entry < dynamic_section + dynamic_nent;
5872        entry++)
5873     {
5874       if (do_dynamic)
5875 	{
5876 	  const char *dtype;
5877 
5878 	  putchar (' ');
5879 	  print_vma (entry->d_tag, FULL_HEX);
5880 	  dtype = get_dynamic_type (entry->d_tag);
5881 	  printf (" (%s)%*s", dtype,
5882 		  ((is_32bit_elf ? 27 : 19)
5883 		   - (int) strlen (dtype)),
5884 		  " ");
5885 	}
5886 
5887       switch (entry->d_tag)
5888 	{
5889 	case DT_FLAGS:
5890 	  if (do_dynamic)
5891 	    print_dynamic_flags (entry->d_un.d_val);
5892 	  break;
5893 
5894 	case DT_AUXILIARY:
5895 	case DT_FILTER:
5896 	case DT_CONFIG:
5897 	case DT_DEPAUDIT:
5898 	case DT_AUDIT:
5899 	  if (do_dynamic)
5900 	    {
5901 	      switch (entry->d_tag)
5902 		{
5903 		case DT_AUXILIARY:
5904 		  printf (_("Auxiliary library"));
5905 		  break;
5906 
5907 		case DT_FILTER:
5908 		  printf (_("Filter library"));
5909 		  break;
5910 
5911 		case DT_CONFIG:
5912 		  printf (_("Configuration file"));
5913 		  break;
5914 
5915 		case DT_DEPAUDIT:
5916 		  printf (_("Dependency audit library"));
5917 		  break;
5918 
5919 		case DT_AUDIT:
5920 		  printf (_("Audit library"));
5921 		  break;
5922 		}
5923 
5924 	      if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
5925 		printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
5926 	      else
5927 		{
5928 		  printf (": ");
5929 		  print_vma (entry->d_un.d_val, PREFIX_HEX);
5930 		  putchar ('\n');
5931 		}
5932 	    }
5933 	  break;
5934 
5935 	case DT_FEATURE:
5936 	  if (do_dynamic)
5937 	    {
5938 	      printf (_("Flags:"));
5939 
5940 	      if (entry->d_un.d_val == 0)
5941 		printf (_(" None\n"));
5942 	      else
5943 		{
5944 		  unsigned long int val = entry->d_un.d_val;
5945 
5946 		  if (val & DTF_1_PARINIT)
5947 		    {
5948 		      printf (" PARINIT");
5949 		      val ^= DTF_1_PARINIT;
5950 		    }
5951 		  if (val & DTF_1_CONFEXP)
5952 		    {
5953 		      printf (" CONFEXP");
5954 		      val ^= DTF_1_CONFEXP;
5955 		    }
5956 		  if (val != 0)
5957 		    printf (" %lx", val);
5958 		  puts ("");
5959 		}
5960 	    }
5961 	  break;
5962 
5963 	case DT_POSFLAG_1:
5964 	  if (do_dynamic)
5965 	    {
5966 	      printf (_("Flags:"));
5967 
5968 	      if (entry->d_un.d_val == 0)
5969 		printf (_(" None\n"));
5970 	      else
5971 		{
5972 		  unsigned long int val = entry->d_un.d_val;
5973 
5974 		  if (val & DF_P1_LAZYLOAD)
5975 		    {
5976 		      printf (" LAZYLOAD");
5977 		      val ^= DF_P1_LAZYLOAD;
5978 		    }
5979 		  if (val & DF_P1_GROUPPERM)
5980 		    {
5981 		      printf (" GROUPPERM");
5982 		      val ^= DF_P1_GROUPPERM;
5983 		    }
5984 		  if (val != 0)
5985 		    printf (" %lx", val);
5986 		  puts ("");
5987 		}
5988 	    }
5989 	  break;
5990 
5991 	case DT_FLAGS_1:
5992 	  if (do_dynamic)
5993 	    {
5994 	      printf (_("Flags:"));
5995 	      if (entry->d_un.d_val == 0)
5996 		printf (_(" None\n"));
5997 	      else
5998 		{
5999 		  unsigned long int val = entry->d_un.d_val;
6000 
6001 		  if (val & DF_1_NOW)
6002 		    {
6003 		      printf (" NOW");
6004 		      val ^= DF_1_NOW;
6005 		    }
6006 		  if (val & DF_1_GLOBAL)
6007 		    {
6008 		      printf (" GLOBAL");
6009 		      val ^= DF_1_GLOBAL;
6010 		    }
6011 		  if (val & DF_1_GROUP)
6012 		    {
6013 		      printf (" GROUP");
6014 		      val ^= DF_1_GROUP;
6015 		    }
6016 		  if (val & DF_1_NODELETE)
6017 		    {
6018 		      printf (" NODELETE");
6019 		      val ^= DF_1_NODELETE;
6020 		    }
6021 		  if (val & DF_1_LOADFLTR)
6022 		    {
6023 		      printf (" LOADFLTR");
6024 		      val ^= DF_1_LOADFLTR;
6025 		    }
6026 		  if (val & DF_1_INITFIRST)
6027 		    {
6028 		      printf (" INITFIRST");
6029 		      val ^= DF_1_INITFIRST;
6030 		    }
6031 		  if (val & DF_1_NOOPEN)
6032 		    {
6033 		      printf (" NOOPEN");
6034 		      val ^= DF_1_NOOPEN;
6035 		    }
6036 		  if (val & DF_1_ORIGIN)
6037 		    {
6038 		      printf (" ORIGIN");
6039 		      val ^= DF_1_ORIGIN;
6040 		    }
6041 		  if (val & DF_1_DIRECT)
6042 		    {
6043 		      printf (" DIRECT");
6044 		      val ^= DF_1_DIRECT;
6045 		    }
6046 		  if (val & DF_1_TRANS)
6047 		    {
6048 		      printf (" TRANS");
6049 		      val ^= DF_1_TRANS;
6050 		    }
6051 		  if (val & DF_1_INTERPOSE)
6052 		    {
6053 		      printf (" INTERPOSE");
6054 		      val ^= DF_1_INTERPOSE;
6055 		    }
6056 		  if (val & DF_1_NODEFLIB)
6057 		    {
6058 		      printf (" NODEFLIB");
6059 		      val ^= DF_1_NODEFLIB;
6060 		    }
6061 		  if (val & DF_1_NODUMP)
6062 		    {
6063 		      printf (" NODUMP");
6064 		      val ^= DF_1_NODUMP;
6065 		    }
6066 		  if (val & DF_1_CONLFAT)
6067 		    {
6068 		      printf (" CONLFAT");
6069 		      val ^= DF_1_CONLFAT;
6070 		    }
6071 		  if (val != 0)
6072 		    printf (" %lx", val);
6073 		  puts ("");
6074 		}
6075 	    }
6076 	  break;
6077 
6078 	case DT_PLTREL:
6079 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
6080 	  if (do_dynamic)
6081 	    puts (get_dynamic_type (entry->d_un.d_val));
6082 	  break;
6083 
6084 	case DT_NULL	:
6085 	case DT_NEEDED	:
6086 	case DT_PLTGOT	:
6087 	case DT_HASH	:
6088 	case DT_STRTAB	:
6089 	case DT_SYMTAB	:
6090 	case DT_RELA	:
6091 	case DT_INIT	:
6092 	case DT_FINI	:
6093 	case DT_SONAME	:
6094 	case DT_RPATH	:
6095 	case DT_SYMBOLIC:
6096 	case DT_REL	:
6097 	case DT_DEBUG	:
6098 	case DT_TEXTREL	:
6099 	case DT_JMPREL	:
6100 	case DT_RUNPATH	:
6101 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
6102 
6103 	  if (do_dynamic)
6104 	    {
6105 	      char *name;
6106 
6107 	      if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
6108 		name = GET_DYNAMIC_NAME (entry->d_un.d_val);
6109 	      else
6110 		name = NULL;
6111 
6112 	      if (name)
6113 		{
6114 		  switch (entry->d_tag)
6115 		    {
6116 		    case DT_NEEDED:
6117 		      printf (_("Shared library: [%s]"), name);
6118 
6119 		      if (streq (name, program_interpreter))
6120 			printf (_(" program interpreter"));
6121 		      break;
6122 
6123 		    case DT_SONAME:
6124 		      printf (_("Library soname: [%s]"), name);
6125 		      break;
6126 
6127 		    case DT_RPATH:
6128 		      printf (_("Library rpath: [%s]"), name);
6129 		      break;
6130 
6131 		    case DT_RUNPATH:
6132 		      printf (_("Library runpath: [%s]"), name);
6133 		      break;
6134 
6135 		    default:
6136 		      print_vma (entry->d_un.d_val, PREFIX_HEX);
6137 		      break;
6138 		    }
6139 		}
6140 	      else
6141 		print_vma (entry->d_un.d_val, PREFIX_HEX);
6142 
6143 	      putchar ('\n');
6144 	    }
6145 	  break;
6146 
6147 	case DT_PLTRELSZ:
6148 	case DT_RELASZ	:
6149 	case DT_STRSZ	:
6150 	case DT_RELSZ	:
6151 	case DT_RELAENT	:
6152 	case DT_SYMENT	:
6153 	case DT_RELENT	:
6154 	  dynamic_info[entry->d_tag] = entry->d_un.d_val;
6155 	case DT_PLTPADSZ:
6156 	case DT_MOVEENT	:
6157 	case DT_MOVESZ	:
6158 	case DT_INIT_ARRAYSZ:
6159 	case DT_FINI_ARRAYSZ:
6160 	case DT_GNU_CONFLICTSZ:
6161 	case DT_GNU_LIBLISTSZ:
6162 	  if (do_dynamic)
6163 	    {
6164 	      print_vma (entry->d_un.d_val, UNSIGNED);
6165 	      printf (" (bytes)\n");
6166 	    }
6167 	  break;
6168 
6169 	case DT_VERDEFNUM:
6170 	case DT_VERNEEDNUM:
6171 	case DT_RELACOUNT:
6172 	case DT_RELCOUNT:
6173 	  if (do_dynamic)
6174 	    {
6175 	      print_vma (entry->d_un.d_val, UNSIGNED);
6176 	      putchar ('\n');
6177 	    }
6178 	  break;
6179 
6180 	case DT_SYMINSZ:
6181 	case DT_SYMINENT:
6182 	case DT_SYMINFO:
6183 	case DT_USED:
6184 	case DT_INIT_ARRAY:
6185 	case DT_FINI_ARRAY:
6186 	  if (do_dynamic)
6187 	    {
6188 	      if (entry->d_tag == DT_USED
6189 		  && VALID_DYNAMIC_NAME (entry->d_un.d_val))
6190 		{
6191 		  char *name = GET_DYNAMIC_NAME (entry->d_un.d_val);
6192 
6193 		  if (*name)
6194 		    {
6195 		      printf (_("Not needed object: [%s]\n"), name);
6196 		      break;
6197 		    }
6198 		}
6199 
6200 	      print_vma (entry->d_un.d_val, PREFIX_HEX);
6201 	      putchar ('\n');
6202 	    }
6203 	  break;
6204 
6205 	case DT_BIND_NOW:
6206 	  /* The value of this entry is ignored.  */
6207 	  if (do_dynamic)
6208 	    putchar ('\n');
6209 	  break;
6210 
6211 	case DT_GNU_PRELINKED:
6212 	  if (do_dynamic)
6213 	    {
6214 	      struct tm *tmp;
6215 	      time_t time = entry->d_un.d_val;
6216 
6217 	      tmp = gmtime (&time);
6218 	      printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6219 		      tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
6220 		      tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
6221 
6222 	    }
6223 	  break;
6224 
6225 	default:
6226 	  if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
6227 	    version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
6228 	      entry->d_un.d_val;
6229 
6230 	  if (do_dynamic)
6231 	    {
6232 	      switch (elf_header.e_machine)
6233 		{
6234 		case EM_MIPS:
6235 		case EM_MIPS_RS3_LE:
6236 		  dynamic_section_mips_val (entry);
6237 		  break;
6238 		case EM_PARISC:
6239 		  dynamic_section_parisc_val (entry);
6240 		  break;
6241 		case EM_IA_64:
6242 		  dynamic_section_ia64_val (entry);
6243 		  break;
6244 		default:
6245 		  print_vma (entry->d_un.d_val, PREFIX_HEX);
6246 		  putchar ('\n');
6247 		}
6248 	    }
6249 	  break;
6250 	}
6251     }
6252 
6253   return 1;
6254 }
6255 
6256 static char *
6257 get_ver_flags (unsigned int flags)
6258 {
6259   static char buff[32];
6260 
6261   buff[0] = 0;
6262 
6263   if (flags == 0)
6264     return _("none");
6265 
6266   if (flags & VER_FLG_BASE)
6267     strcat (buff, "BASE ");
6268 
6269   if (flags & VER_FLG_WEAK)
6270     {
6271       if (flags & VER_FLG_BASE)
6272 	strcat (buff, "| ");
6273 
6274       strcat (buff, "WEAK ");
6275     }
6276 
6277   if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
6278     strcat (buff, "| <unknown>");
6279 
6280   return buff;
6281 }
6282 
6283 /* Display the contents of the version sections.  */
6284 static int
6285 process_version_sections (FILE *file)
6286 {
6287   Elf_Internal_Shdr *section;
6288   unsigned i;
6289   int found = 0;
6290 
6291   if (! do_version)
6292     return 1;
6293 
6294   for (i = 0, section = section_headers;
6295        i < elf_header.e_shnum;
6296        i++, section++)
6297     {
6298       switch (section->sh_type)
6299 	{
6300 	case SHT_GNU_verdef:
6301 	  {
6302 	    Elf_External_Verdef *edefs;
6303 	    unsigned int idx;
6304 	    unsigned int cnt;
6305 
6306 	    found = 1;
6307 
6308 	    printf
6309 	      (_("\nVersion definition section '%s' contains %ld entries:\n"),
6310 	       SECTION_NAME (section), section->sh_info);
6311 
6312 	    printf (_("  Addr: 0x"));
6313 	    printf_vma (section->sh_addr);
6314 	    printf (_("  Offset: %#08lx  Link: %lx (%s)\n"),
6315 		    (unsigned long) section->sh_offset, section->sh_link,
6316 		    SECTION_HEADER_INDEX (section->sh_link)
6317 		    < elf_header.e_shnum
6318 		    ? SECTION_NAME (SECTION_HEADER (section->sh_link))
6319 		    : "<corrupt>");
6320 
6321 	    edefs = get_data (NULL, file, section->sh_offset, 1,
6322 			      section->sh_size,
6323 			      _("version definition section"));
6324 	    if (!edefs)
6325 	      break;
6326 
6327 	    for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6328 	      {
6329 		char *vstart;
6330 		Elf_External_Verdef *edef;
6331 		Elf_Internal_Verdef ent;
6332 		Elf_External_Verdaux *eaux;
6333 		Elf_Internal_Verdaux aux;
6334 		int j;
6335 		int isum;
6336 
6337 		vstart = ((char *) edefs) + idx;
6338 
6339 		edef = (Elf_External_Verdef *) vstart;
6340 
6341 		ent.vd_version = BYTE_GET (edef->vd_version);
6342 		ent.vd_flags   = BYTE_GET (edef->vd_flags);
6343 		ent.vd_ndx     = BYTE_GET (edef->vd_ndx);
6344 		ent.vd_cnt     = BYTE_GET (edef->vd_cnt);
6345 		ent.vd_hash    = BYTE_GET (edef->vd_hash);
6346 		ent.vd_aux     = BYTE_GET (edef->vd_aux);
6347 		ent.vd_next    = BYTE_GET (edef->vd_next);
6348 
6349 		printf (_("  %#06x: Rev: %d  Flags: %s"),
6350 			idx, ent.vd_version, get_ver_flags (ent.vd_flags));
6351 
6352 		printf (_("  Index: %d  Cnt: %d  "),
6353 			ent.vd_ndx, ent.vd_cnt);
6354 
6355 		vstart += ent.vd_aux;
6356 
6357 		eaux = (Elf_External_Verdaux *) vstart;
6358 
6359 		aux.vda_name = BYTE_GET (eaux->vda_name);
6360 		aux.vda_next = BYTE_GET (eaux->vda_next);
6361 
6362 		if (VALID_DYNAMIC_NAME (aux.vda_name))
6363 		  printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
6364 		else
6365 		  printf (_("Name index: %ld\n"), aux.vda_name);
6366 
6367 		isum = idx + ent.vd_aux;
6368 
6369 		for (j = 1; j < ent.vd_cnt; j++)
6370 		  {
6371 		    isum   += aux.vda_next;
6372 		    vstart += aux.vda_next;
6373 
6374 		    eaux = (Elf_External_Verdaux *) vstart;
6375 
6376 		    aux.vda_name = BYTE_GET (eaux->vda_name);
6377 		    aux.vda_next = BYTE_GET (eaux->vda_next);
6378 
6379 		    if (VALID_DYNAMIC_NAME (aux.vda_name))
6380 		      printf (_("  %#06x: Parent %d: %s\n"),
6381 			      isum, j, GET_DYNAMIC_NAME (aux.vda_name));
6382 		    else
6383 		      printf (_("  %#06x: Parent %d, name index: %ld\n"),
6384 			      isum, j, aux.vda_name);
6385 		  }
6386 
6387 		idx += ent.vd_next;
6388 	      }
6389 
6390 	    free (edefs);
6391 	  }
6392 	  break;
6393 
6394 	case SHT_GNU_verneed:
6395 	  {
6396 	    Elf_External_Verneed *eneed;
6397 	    unsigned int idx;
6398 	    unsigned int cnt;
6399 
6400 	    found = 1;
6401 
6402 	    printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6403 		    SECTION_NAME (section), section->sh_info);
6404 
6405 	    printf (_(" Addr: 0x"));
6406 	    printf_vma (section->sh_addr);
6407 	    printf (_("  Offset: %#08lx  Link to section: %ld (%s)\n"),
6408 		    (unsigned long) section->sh_offset, section->sh_link,
6409 		    SECTION_HEADER_INDEX (section->sh_link)
6410 		    < elf_header.e_shnum
6411 		    ? SECTION_NAME (SECTION_HEADER (section->sh_link))
6412 		    : "<corrupt>");
6413 
6414 	    eneed = get_data (NULL, file, section->sh_offset, 1,
6415 			      section->sh_size,
6416 			      _("version need section"));
6417 	    if (!eneed)
6418 	      break;
6419 
6420 	    for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6421 	      {
6422 		Elf_External_Verneed *entry;
6423 		Elf_Internal_Verneed ent;
6424 		int j;
6425 		int isum;
6426 		char *vstart;
6427 
6428 		vstart = ((char *) eneed) + idx;
6429 
6430 		entry = (Elf_External_Verneed *) vstart;
6431 
6432 		ent.vn_version = BYTE_GET (entry->vn_version);
6433 		ent.vn_cnt     = BYTE_GET (entry->vn_cnt);
6434 		ent.vn_file    = BYTE_GET (entry->vn_file);
6435 		ent.vn_aux     = BYTE_GET (entry->vn_aux);
6436 		ent.vn_next    = BYTE_GET (entry->vn_next);
6437 
6438 		printf (_("  %#06x: Version: %d"), idx, ent.vn_version);
6439 
6440 		if (VALID_DYNAMIC_NAME (ent.vn_file))
6441 		  printf (_("  File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
6442 		else
6443 		  printf (_("  File: %lx"), ent.vn_file);
6444 
6445 		printf (_("  Cnt: %d\n"), ent.vn_cnt);
6446 
6447 		vstart += ent.vn_aux;
6448 
6449 		for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
6450 		  {
6451 		    Elf_External_Vernaux *eaux;
6452 		    Elf_Internal_Vernaux aux;
6453 
6454 		    eaux = (Elf_External_Vernaux *) vstart;
6455 
6456 		    aux.vna_hash  = BYTE_GET (eaux->vna_hash);
6457 		    aux.vna_flags = BYTE_GET (eaux->vna_flags);
6458 		    aux.vna_other = BYTE_GET (eaux->vna_other);
6459 		    aux.vna_name  = BYTE_GET (eaux->vna_name);
6460 		    aux.vna_next  = BYTE_GET (eaux->vna_next);
6461 
6462 		    if (VALID_DYNAMIC_NAME (aux.vna_name))
6463 		      printf (_("  %#06x:   Name: %s"),
6464 			      isum, GET_DYNAMIC_NAME (aux.vna_name));
6465 		    else
6466 		      printf (_("  %#06x:   Name index: %lx"),
6467 			      isum, aux.vna_name);
6468 
6469 		    printf (_("  Flags: %s  Version: %d\n"),
6470 			    get_ver_flags (aux.vna_flags), aux.vna_other);
6471 
6472 		    isum   += aux.vna_next;
6473 		    vstart += aux.vna_next;
6474 		  }
6475 
6476 		idx += ent.vn_next;
6477 	      }
6478 
6479 	    free (eneed);
6480 	  }
6481 	  break;
6482 
6483 	case SHT_GNU_versym:
6484 	  {
6485 	    Elf_Internal_Shdr *link_section;
6486 	    int total;
6487 	    int cnt;
6488 	    unsigned char *edata;
6489 	    unsigned short *data;
6490 	    char *strtab;
6491 	    Elf_Internal_Sym *symbols;
6492 	    Elf_Internal_Shdr *string_sec;
6493 	    long off;
6494 
6495 	    if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
6496 	      break;
6497 
6498 	    link_section = SECTION_HEADER (section->sh_link);
6499 	    total = section->sh_size / sizeof (Elf_External_Versym);
6500 
6501 	    if (SECTION_HEADER_INDEX (link_section->sh_link)
6502 		>= elf_header.e_shnum)
6503 	      break;
6504 
6505 	    found = 1;
6506 
6507 	    symbols = GET_ELF_SYMBOLS (file, link_section);
6508 
6509 	    string_sec = SECTION_HEADER (link_section->sh_link);
6510 
6511 	    strtab = get_data (NULL, file, string_sec->sh_offset, 1,
6512 			       string_sec->sh_size, _("version string table"));
6513 	    if (!strtab)
6514 	      break;
6515 
6516 	    printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6517 		    SECTION_NAME (section), total);
6518 
6519 	    printf (_(" Addr: "));
6520 	    printf_vma (section->sh_addr);
6521 	    printf (_("  Offset: %#08lx  Link: %lx (%s)\n"),
6522 		    (unsigned long) section->sh_offset, section->sh_link,
6523 		    SECTION_NAME (link_section));
6524 
6525 	    off = offset_from_vma (file,
6526 				   version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
6527 				   total * sizeof (short));
6528 	    edata = get_data (NULL, file, off, total, sizeof (short),
6529 			      _("version symbol data"));
6530 	    if (!edata)
6531 	      {
6532 		free (strtab);
6533 		break;
6534 	      }
6535 
6536 	    data = cmalloc (total, sizeof (short));
6537 
6538 	    for (cnt = total; cnt --;)
6539 	      data[cnt] = byte_get (edata + cnt * sizeof (short),
6540 				    sizeof (short));
6541 
6542 	    free (edata);
6543 
6544 	    for (cnt = 0; cnt < total; cnt += 4)
6545 	      {
6546 		int j, nn;
6547 		int check_def, check_need;
6548 		char *name;
6549 
6550 		printf ("  %03x:", cnt);
6551 
6552 		for (j = 0; (j < 4) && (cnt + j) < total; ++j)
6553 		  switch (data[cnt + j])
6554 		    {
6555 		    case 0:
6556 		      fputs (_("   0 (*local*)    "), stdout);
6557 		      break;
6558 
6559 		    case 1:
6560 		      fputs (_("   1 (*global*)   "), stdout);
6561 		      break;
6562 
6563 		    default:
6564 		      nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
6565 				   data[cnt + j] & 0x8000 ? 'h' : ' ');
6566 
6567 		      check_def = 1;
6568 		      check_need = 1;
6569 		      if (SECTION_HEADER_INDEX (symbols[cnt + j].st_shndx)
6570 			  >= elf_header.e_shnum
6571 			  || SECTION_HEADER (symbols[cnt + j].st_shndx)->sh_type
6572 			     != SHT_NOBITS)
6573 			{
6574 			  if (symbols[cnt + j].st_shndx == SHN_UNDEF)
6575 			    check_def = 0;
6576 			  else
6577 			    check_need = 0;
6578 			}
6579 
6580 		      if (check_need
6581 			  && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
6582 			{
6583 			  Elf_Internal_Verneed ivn;
6584 			  unsigned long offset;
6585 
6586 			  offset = offset_from_vma
6587 			    (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
6588 			     sizeof (Elf_External_Verneed));
6589 
6590 			  do
6591 			    {
6592 			      Elf_Internal_Vernaux ivna;
6593 			      Elf_External_Verneed evn;
6594 			      Elf_External_Vernaux evna;
6595 			      unsigned long a_off;
6596 
6597 			      get_data (&evn, file, offset, sizeof (evn), 1,
6598 					_("version need"));
6599 
6600 			      ivn.vn_aux  = BYTE_GET (evn.vn_aux);
6601 			      ivn.vn_next = BYTE_GET (evn.vn_next);
6602 
6603 			      a_off = offset + ivn.vn_aux;
6604 
6605 			      do
6606 				{
6607 				  get_data (&evna, file, a_off, sizeof (evna),
6608 					    1, _("version need aux (2)"));
6609 
6610 				  ivna.vna_next  = BYTE_GET (evna.vna_next);
6611 				  ivna.vna_other = BYTE_GET (evna.vna_other);
6612 
6613 				  a_off += ivna.vna_next;
6614 				}
6615 			      while (ivna.vna_other != data[cnt + j]
6616 				     && ivna.vna_next != 0);
6617 
6618 			      if (ivna.vna_other == data[cnt + j])
6619 				{
6620 				  ivna.vna_name = BYTE_GET (evna.vna_name);
6621 
6622 				  name = strtab + ivna.vna_name;
6623 				  nn += printf ("(%s%-*s",
6624 						name,
6625 						12 - (int) strlen (name),
6626 						")");
6627 				  check_def = 0;
6628 				  break;
6629 				}
6630 
6631 			      offset += ivn.vn_next;
6632 			    }
6633 			  while (ivn.vn_next);
6634 			}
6635 
6636 		      if (check_def && data[cnt + j] != 0x8001
6637 			  && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
6638 			{
6639 			  Elf_Internal_Verdef ivd;
6640 			  Elf_External_Verdef evd;
6641 			  unsigned long offset;
6642 
6643 			  offset = offset_from_vma
6644 			    (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
6645 			     sizeof evd);
6646 
6647 			  do
6648 			    {
6649 			      get_data (&evd, file, offset, sizeof (evd), 1,
6650 					_("version def"));
6651 
6652 			      ivd.vd_next = BYTE_GET (evd.vd_next);
6653 			      ivd.vd_ndx  = BYTE_GET (evd.vd_ndx);
6654 
6655 			      offset += ivd.vd_next;
6656 			    }
6657 			  while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
6658 				 && ivd.vd_next != 0);
6659 
6660 			  if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
6661 			    {
6662 			      Elf_External_Verdaux evda;
6663 			      Elf_Internal_Verdaux ivda;
6664 
6665 			      ivd.vd_aux = BYTE_GET (evd.vd_aux);
6666 
6667 			      get_data (&evda, file,
6668 					offset - ivd.vd_next + ivd.vd_aux,
6669 					sizeof (evda), 1,
6670 					_("version def aux"));
6671 
6672 			      ivda.vda_name = BYTE_GET (evda.vda_name);
6673 
6674 			      name = strtab + ivda.vda_name;
6675 			      nn += printf ("(%s%-*s",
6676 					    name,
6677 					    12 - (int) strlen (name),
6678 					    ")");
6679 			    }
6680 			}
6681 
6682 		      if (nn < 18)
6683 			printf ("%*c", 18 - nn, ' ');
6684 		    }
6685 
6686 		putchar ('\n');
6687 	      }
6688 
6689 	    free (data);
6690 	    free (strtab);
6691 	    free (symbols);
6692 	  }
6693 	  break;
6694 
6695 	default:
6696 	  break;
6697 	}
6698     }
6699 
6700   if (! found)
6701     printf (_("\nNo version information found in this file.\n"));
6702 
6703   return 1;
6704 }
6705 
6706 static const char *
6707 get_symbol_binding (unsigned int binding)
6708 {
6709   static char buff[32];
6710 
6711   switch (binding)
6712     {
6713     case STB_LOCAL:	return "LOCAL";
6714     case STB_GLOBAL:	return "GLOBAL";
6715     case STB_WEAK:	return "WEAK";
6716     default:
6717       if (binding >= STB_LOPROC && binding <= STB_HIPROC)
6718 	snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
6719 		  binding);
6720       else if (binding >= STB_LOOS && binding <= STB_HIOS)
6721 	snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
6722       else
6723 	snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
6724       return buff;
6725     }
6726 }
6727 
6728 static const char *
6729 get_symbol_type (unsigned int type)
6730 {
6731   static char buff[32];
6732 
6733   switch (type)
6734     {
6735     case STT_NOTYPE:	return "NOTYPE";
6736     case STT_OBJECT:	return "OBJECT";
6737     case STT_FUNC:	return "FUNC";
6738     case STT_SECTION:	return "SECTION";
6739     case STT_FILE:	return "FILE";
6740     case STT_COMMON:	return "COMMON";
6741     case STT_TLS:	return "TLS";
6742     default:
6743       if (type >= STT_LOPROC && type <= STT_HIPROC)
6744 	{
6745 	  if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
6746 	    return "THUMB_FUNC";
6747 
6748 	  if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
6749 	    return "REGISTER";
6750 
6751 	  if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
6752 	    return "PARISC_MILLI";
6753 
6754 	  snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
6755 	}
6756       else if (type >= STT_LOOS && type <= STT_HIOS)
6757 	{
6758 	  if (elf_header.e_machine == EM_PARISC)
6759 	    {
6760 	      if (type == STT_HP_OPAQUE)
6761 		return "HP_OPAQUE";
6762 	      if (type == STT_HP_STUB)
6763 		return "HP_STUB";
6764 	    }
6765 
6766 	  snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
6767 	}
6768       else
6769 	snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
6770       return buff;
6771     }
6772 }
6773 
6774 static const char *
6775 get_symbol_visibility (unsigned int visibility)
6776 {
6777   switch (visibility)
6778     {
6779     case STV_DEFAULT:	return "DEFAULT";
6780     case STV_INTERNAL:	return "INTERNAL";
6781     case STV_HIDDEN:	return "HIDDEN";
6782     case STV_PROTECTED: return "PROTECTED";
6783     default: abort ();
6784     }
6785 }
6786 
6787 static const char *
6788 get_mips_symbol_other (unsigned int other)
6789 {
6790   switch (other)
6791     {
6792     case STO_OPTIONAL:  return "OPTIONAL";
6793     case STO_MIPS16:    return "MIPS16";
6794     default:      	return NULL;
6795     }
6796 }
6797 
6798 static const char *
6799 get_symbol_other (unsigned int other)
6800 {
6801   const char * result = NULL;
6802   static char buff [32];
6803 
6804   if (other == 0)
6805     return "";
6806 
6807   switch (elf_header.e_machine)
6808     {
6809     case EM_MIPS:
6810       result = get_mips_symbol_other (other);
6811     default:
6812       break;
6813     }
6814 
6815   if (result)
6816     return result;
6817 
6818   snprintf (buff, sizeof buff, _("<other>: %x"), other);
6819   return buff;
6820 }
6821 
6822 static const char *
6823 get_symbol_index_type (unsigned int type)
6824 {
6825   static char buff[32];
6826 
6827   switch (type)
6828     {
6829     case SHN_UNDEF:	return "UND";
6830     case SHN_ABS:	return "ABS";
6831     case SHN_COMMON:	return "COM";
6832     default:
6833       if (type == SHN_IA_64_ANSI_COMMON
6834 	  && elf_header.e_machine == EM_IA_64
6835 	  && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
6836 	return "ANSI_COM";
6837       else if (elf_header.e_machine == EM_X86_64
6838 	       && type == SHN_X86_64_LCOMMON)
6839 	return "LARGE_COM";
6840       else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
6841 	sprintf (buff, "PRC[0x%04x]", type);
6842       else if (type >= SHN_LOOS && type <= SHN_HIOS)
6843 	sprintf (buff, "OS [0x%04x]", type);
6844       else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
6845 	sprintf (buff, "RSV[0x%04x]", type);
6846       else
6847 	sprintf (buff, "%3d", type);
6848       break;
6849     }
6850 
6851   return buff;
6852 }
6853 
6854 static bfd_vma *
6855 get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
6856 {
6857   unsigned char *e_data;
6858   bfd_vma *i_data;
6859 
6860   e_data = cmalloc (number, ent_size);
6861 
6862   if (e_data == NULL)
6863     {
6864       error (_("Out of memory\n"));
6865       return NULL;
6866     }
6867 
6868   if (fread (e_data, ent_size, number, file) != number)
6869     {
6870       error (_("Unable to read in dynamic data\n"));
6871       return NULL;
6872     }
6873 
6874   i_data = cmalloc (number, sizeof (*i_data));
6875 
6876   if (i_data == NULL)
6877     {
6878       error (_("Out of memory\n"));
6879       free (e_data);
6880       return NULL;
6881     }
6882 
6883   while (number--)
6884     i_data[number] = byte_get (e_data + number * ent_size, ent_size);
6885 
6886   free (e_data);
6887 
6888   return i_data;
6889 }
6890 
6891 /* Dump the symbol table.  */
6892 static int
6893 process_symbol_table (FILE *file)
6894 {
6895   Elf_Internal_Shdr *section;
6896   bfd_vma nbuckets = 0;
6897   bfd_vma nchains = 0;
6898   bfd_vma *buckets = NULL;
6899   bfd_vma *chains = NULL;
6900 
6901   if (! do_syms && !do_histogram)
6902     return 1;
6903 
6904   if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
6905 				|| do_histogram))
6906     {
6907       unsigned char nb[8];
6908       unsigned char nc[8];
6909       int hash_ent_size = 4;
6910 
6911       if ((elf_header.e_machine == EM_ALPHA
6912 	   || elf_header.e_machine == EM_S390
6913 	   || elf_header.e_machine == EM_S390_OLD)
6914 	  && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
6915 	hash_ent_size = 8;
6916 
6917       if (fseek (file,
6918 		 (archive_file_offset
6919 		  + offset_from_vma (file, dynamic_info[DT_HASH],
6920 				     sizeof nb + sizeof nc)),
6921 		 SEEK_SET))
6922 	{
6923 	  error (_("Unable to seek to start of dynamic information"));
6924 	  return 0;
6925 	}
6926 
6927       if (fread (nb, hash_ent_size, 1, file) != 1)
6928 	{
6929 	  error (_("Failed to read in number of buckets\n"));
6930 	  return 0;
6931 	}
6932 
6933       if (fread (nc, hash_ent_size, 1, file) != 1)
6934 	{
6935 	  error (_("Failed to read in number of chains\n"));
6936 	  return 0;
6937 	}
6938 
6939       nbuckets = byte_get (nb, hash_ent_size);
6940       nchains  = byte_get (nc, hash_ent_size);
6941 
6942       buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
6943       chains  = get_dynamic_data (file, nchains, hash_ent_size);
6944 
6945       if (buckets == NULL || chains == NULL)
6946 	return 0;
6947     }
6948 
6949   if (do_syms
6950       && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
6951     {
6952       unsigned long hn;
6953       bfd_vma si;
6954 
6955       printf (_("\nSymbol table for image:\n"));
6956       if (is_32bit_elf)
6957 	printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
6958       else
6959 	printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
6960 
6961       for (hn = 0; hn < nbuckets; hn++)
6962 	{
6963 	  if (! buckets[hn])
6964 	    continue;
6965 
6966 	  for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
6967 	    {
6968 	      Elf_Internal_Sym *psym;
6969 	      int n;
6970 
6971 	      psym = dynamic_symbols + si;
6972 
6973 	      n = print_vma (si, DEC_5);
6974 	      if (n < 5)
6975 		fputs ("     " + n, stdout);
6976 	      printf (" %3lu: ", hn);
6977 	      print_vma (psym->st_value, LONG_HEX);
6978 	      putchar (' ');
6979 	      print_vma (psym->st_size, DEC_5);
6980 
6981 	      printf ("  %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
6982 	      printf (" %6s",  get_symbol_binding (ELF_ST_BIND (psym->st_info)));
6983 	      printf (" %7s",  get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
6984 	      /* Check to see if any other bits in the st_other field are set.
6985 	         Note - displaying this information disrupts the layout of the
6986 	         table being generated, but for the moment this case is very rare.  */
6987 	      if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
6988 		printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
6989 	      printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
6990 	      if (VALID_DYNAMIC_NAME (psym->st_name))
6991 		print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
6992 	      else
6993 		printf (" <corrupt: %14ld>", psym->st_name);
6994 	      putchar ('\n');
6995 	    }
6996 	}
6997     }
6998   else if (do_syms && !do_using_dynamic)
6999     {
7000       unsigned int i;
7001 
7002       for (i = 0, section = section_headers;
7003 	   i < elf_header.e_shnum;
7004 	   i++, section++)
7005 	{
7006 	  unsigned int si;
7007 	  char *strtab = NULL;
7008 	  unsigned long int strtab_size = 0;
7009 	  Elf_Internal_Sym *symtab;
7010 	  Elf_Internal_Sym *psym;
7011 
7012 
7013 	  if (   section->sh_type != SHT_SYMTAB
7014 	      && section->sh_type != SHT_DYNSYM)
7015 	    continue;
7016 
7017 	  printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7018 		  SECTION_NAME (section),
7019 		  (unsigned long) (section->sh_size / section->sh_entsize));
7020 	  if (is_32bit_elf)
7021 	    printf (_("   Num:    Value  Size Type    Bind   Vis      Ndx Name\n"));
7022 	  else
7023 	    printf (_("   Num:    Value          Size Type    Bind   Vis      Ndx Name\n"));
7024 
7025 	  symtab = GET_ELF_SYMBOLS (file, section);
7026 	  if (symtab == NULL)
7027 	    continue;
7028 
7029 	  if (section->sh_link == elf_header.e_shstrndx)
7030 	    {
7031 	      strtab = string_table;
7032 	      strtab_size = string_table_length;
7033 	    }
7034 	  else if (SECTION_HEADER_INDEX (section->sh_link) < elf_header.e_shnum)
7035 	    {
7036 	      Elf_Internal_Shdr *string_sec;
7037 
7038 	      string_sec = SECTION_HEADER (section->sh_link);
7039 
7040 	      strtab = get_data (NULL, file, string_sec->sh_offset,
7041 				 1, string_sec->sh_size, _("string table"));
7042 	      strtab_size = strtab != NULL ? string_sec->sh_size : 0;
7043 	    }
7044 
7045 	  for (si = 0, psym = symtab;
7046 	       si < section->sh_size / section->sh_entsize;
7047 	       si++, psym++)
7048 	    {
7049 	      printf ("%6d: ", si);
7050 	      print_vma (psym->st_value, LONG_HEX);
7051 	      putchar (' ');
7052 	      print_vma (psym->st_size, DEC_5);
7053 	      printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
7054 	      printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
7055 	      printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
7056 	      /* Check to see if any other bits in the st_other field are set.
7057 	         Note - displaying this information disrupts the layout of the
7058 	         table being generated, but for the moment this case is very rare.  */
7059 	      if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
7060 		printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
7061 	      printf (" %4s ", get_symbol_index_type (psym->st_shndx));
7062 	      print_symbol (25, psym->st_name < strtab_size
7063 			    ? strtab + psym->st_name : "<corrupt>");
7064 
7065 	      if (section->sh_type == SHT_DYNSYM &&
7066 		  version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
7067 		{
7068 		  unsigned char data[2];
7069 		  unsigned short vers_data;
7070 		  unsigned long offset;
7071 		  int is_nobits;
7072 		  int check_def;
7073 
7074 		  offset = offset_from_vma
7075 		    (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
7076 		     sizeof data + si * sizeof (vers_data));
7077 
7078 		  get_data (&data, file, offset + si * sizeof (vers_data),
7079 			    sizeof (data), 1, _("version data"));
7080 
7081 		  vers_data = byte_get (data, 2);
7082 
7083 		  is_nobits = (SECTION_HEADER_INDEX (psym->st_shndx)
7084 			       < elf_header.e_shnum
7085 			       && SECTION_HEADER (psym->st_shndx)->sh_type
7086 				  == SHT_NOBITS);
7087 
7088 		  check_def = (psym->st_shndx != SHN_UNDEF);
7089 
7090 		  if ((vers_data & 0x8000) || vers_data > 1)
7091 		    {
7092 		      if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
7093 			  && (is_nobits || ! check_def))
7094 			{
7095 			  Elf_External_Verneed evn;
7096 			  Elf_Internal_Verneed ivn;
7097 			  Elf_Internal_Vernaux ivna;
7098 
7099 			  /* We must test both.  */
7100 			  offset = offset_from_vma
7101 			    (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
7102 			     sizeof evn);
7103 
7104 			  do
7105 			    {
7106 			      unsigned long vna_off;
7107 
7108 			      get_data (&evn, file, offset, sizeof (evn), 1,
7109 					_("version need"));
7110 
7111 			      ivn.vn_aux  = BYTE_GET (evn.vn_aux);
7112 			      ivn.vn_next = BYTE_GET (evn.vn_next);
7113 
7114 			      vna_off = offset + ivn.vn_aux;
7115 
7116 			      do
7117 				{
7118 				  Elf_External_Vernaux evna;
7119 
7120 				  get_data (&evna, file, vna_off,
7121 					    sizeof (evna), 1,
7122 					    _("version need aux (3)"));
7123 
7124 				  ivna.vna_other = BYTE_GET (evna.vna_other);
7125 				  ivna.vna_next  = BYTE_GET (evna.vna_next);
7126 				  ivna.vna_name  = BYTE_GET (evna.vna_name);
7127 
7128 				  vna_off += ivna.vna_next;
7129 				}
7130 			      while (ivna.vna_other != vers_data
7131 				     && ivna.vna_next != 0);
7132 
7133 			      if (ivna.vna_other == vers_data)
7134 				break;
7135 
7136 			      offset += ivn.vn_next;
7137 			    }
7138 			  while (ivn.vn_next != 0);
7139 
7140 			  if (ivna.vna_other == vers_data)
7141 			    {
7142 			      printf ("@%s (%d)",
7143 				      ivna.vna_name < strtab_size
7144 				      ? strtab + ivna.vna_name : "<corrupt>",
7145 				      ivna.vna_other);
7146 			      check_def = 0;
7147 			    }
7148 			  else if (! is_nobits)
7149 			    error (_("bad dynamic symbol"));
7150 			  else
7151 			    check_def = 1;
7152 			}
7153 
7154 		      if (check_def)
7155 			{
7156 			  if (vers_data != 0x8001
7157 			      && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
7158 			    {
7159 			      Elf_Internal_Verdef ivd;
7160 			      Elf_Internal_Verdaux ivda;
7161 			      Elf_External_Verdaux evda;
7162 			      unsigned long offset;
7163 
7164 			      offset = offset_from_vma
7165 				(file,
7166 				 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
7167 				 sizeof (Elf_External_Verdef));
7168 
7169 			      do
7170 				{
7171 				  Elf_External_Verdef evd;
7172 
7173 				  get_data (&evd, file, offset, sizeof (evd),
7174 					    1, _("version def"));
7175 
7176 				  ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
7177 				  ivd.vd_aux = BYTE_GET (evd.vd_aux);
7178 				  ivd.vd_next = BYTE_GET (evd.vd_next);
7179 
7180 				  offset += ivd.vd_next;
7181 				}
7182 			      while (ivd.vd_ndx != (vers_data & 0x7fff)
7183 				     && ivd.vd_next != 0);
7184 
7185 			      offset -= ivd.vd_next;
7186 			      offset += ivd.vd_aux;
7187 
7188 			      get_data (&evda, file, offset, sizeof (evda),
7189 					1, _("version def aux"));
7190 
7191 			      ivda.vda_name = BYTE_GET (evda.vda_name);
7192 
7193 			      if (psym->st_name != ivda.vda_name)
7194 				printf ((vers_data & 0x8000)
7195 					? "@%s" : "@@%s",
7196 					ivda.vda_name < strtab_size
7197 					? strtab + ivda.vda_name : "<corrupt>");
7198 			    }
7199 			}
7200 		    }
7201 		}
7202 
7203 	      putchar ('\n');
7204 	    }
7205 
7206 	  free (symtab);
7207 	  if (strtab != string_table)
7208 	    free (strtab);
7209 	}
7210     }
7211   else if (do_syms)
7212     printf
7213       (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7214 
7215   if (do_histogram && buckets != NULL)
7216     {
7217       unsigned long *lengths;
7218       unsigned long *counts;
7219       unsigned long hn;
7220       bfd_vma si;
7221       unsigned long maxlength = 0;
7222       unsigned long nzero_counts = 0;
7223       unsigned long nsyms = 0;
7224 
7225       printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7226 	      (unsigned long) nbuckets);
7227       printf (_(" Length  Number     %% of total  Coverage\n"));
7228 
7229       lengths = calloc (nbuckets, sizeof (*lengths));
7230       if (lengths == NULL)
7231 	{
7232 	  error (_("Out of memory"));
7233 	  return 0;
7234 	}
7235       for (hn = 0; hn < nbuckets; ++hn)
7236 	{
7237 	  for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
7238 	    {
7239 	      ++nsyms;
7240 	      if (maxlength < ++lengths[hn])
7241 		++maxlength;
7242 	    }
7243 	}
7244 
7245       counts = calloc (maxlength + 1, sizeof (*counts));
7246       if (counts == NULL)
7247 	{
7248 	  error (_("Out of memory"));
7249 	  return 0;
7250 	}
7251 
7252       for (hn = 0; hn < nbuckets; ++hn)
7253 	++counts[lengths[hn]];
7254 
7255       if (nbuckets > 0)
7256 	{
7257 	  unsigned long i;
7258 	  printf ("      0  %-10lu (%5.1f%%)\n",
7259 		  counts[0], (counts[0] * 100.0) / nbuckets);
7260 	  for (i = 1; i <= maxlength; ++i)
7261 	    {
7262 	      nzero_counts += counts[i] * i;
7263 	      printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
7264 		      i, counts[i], (counts[i] * 100.0) / nbuckets,
7265 		      (nzero_counts * 100.0) / nsyms);
7266 	    }
7267 	}
7268 
7269       free (counts);
7270       free (lengths);
7271     }
7272 
7273   if (buckets != NULL)
7274     {
7275       free (buckets);
7276       free (chains);
7277     }
7278 
7279   return 1;
7280 }
7281 
7282 static int
7283 process_syminfo (FILE *file ATTRIBUTE_UNUSED)
7284 {
7285   unsigned int i;
7286 
7287   if (dynamic_syminfo == NULL
7288       || !do_dynamic)
7289     /* No syminfo, this is ok.  */
7290     return 1;
7291 
7292   /* There better should be a dynamic symbol section.  */
7293   if (dynamic_symbols == NULL || dynamic_strings == NULL)
7294     return 0;
7295 
7296   if (dynamic_addr)
7297     printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7298 	    dynamic_syminfo_offset, dynamic_syminfo_nent);
7299 
7300   printf (_(" Num: Name                           BoundTo     Flags\n"));
7301   for (i = 0; i < dynamic_syminfo_nent; ++i)
7302     {
7303       unsigned short int flags = dynamic_syminfo[i].si_flags;
7304 
7305       printf ("%4d: ", i);
7306       if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
7307 	print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
7308       else
7309 	printf ("<corrupt: %19ld>", dynamic_symbols[i].st_name);
7310       putchar (' ');
7311 
7312       switch (dynamic_syminfo[i].si_boundto)
7313 	{
7314 	case SYMINFO_BT_SELF:
7315 	  fputs ("SELF       ", stdout);
7316 	  break;
7317 	case SYMINFO_BT_PARENT:
7318 	  fputs ("PARENT     ", stdout);
7319 	  break;
7320 	default:
7321 	  if (dynamic_syminfo[i].si_boundto > 0
7322 	      && dynamic_syminfo[i].si_boundto < dynamic_nent
7323 	      && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
7324 	    {
7325 	      print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
7326 	      putchar (' ' );
7327 	    }
7328 	  else
7329 	    printf ("%-10d ", dynamic_syminfo[i].si_boundto);
7330 	  break;
7331 	}
7332 
7333       if (flags & SYMINFO_FLG_DIRECT)
7334 	printf (" DIRECT");
7335       if (flags & SYMINFO_FLG_PASSTHRU)
7336 	printf (" PASSTHRU");
7337       if (flags & SYMINFO_FLG_COPY)
7338 	printf (" COPY");
7339       if (flags & SYMINFO_FLG_LAZYLOAD)
7340 	printf (" LAZYLOAD");
7341 
7342       puts ("");
7343     }
7344 
7345   return 1;
7346 }
7347 
7348 #ifdef SUPPORT_DISASSEMBLY
7349 static int
7350 disassemble_section (Elf_Internal_Shdr *section, FILE *file)
7351 {
7352   printf (_("\nAssembly dump of section %s\n"),
7353 	  SECTION_NAME (section));
7354 
7355   /* XXX -- to be done --- XXX */
7356 
7357   return 1;
7358 }
7359 #endif
7360 
7361 static int
7362 dump_section (Elf_Internal_Shdr *section, FILE *file)
7363 {
7364   bfd_size_type bytes;
7365   bfd_vma addr;
7366   unsigned char *data;
7367   unsigned char *start;
7368 
7369   bytes = section->sh_size;
7370 
7371   if (bytes == 0 || section->sh_type == SHT_NOBITS)
7372     {
7373       printf (_("\nSection '%s' has no data to dump.\n"),
7374 	      SECTION_NAME (section));
7375       return 0;
7376     }
7377   else
7378     printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
7379 
7380   addr = section->sh_addr;
7381 
7382   start = get_data (NULL, file, section->sh_offset, 1, bytes,
7383 		    _("section data"));
7384   if (!start)
7385     return 0;
7386 
7387   data = start;
7388 
7389   while (bytes)
7390     {
7391       int j;
7392       int k;
7393       int lbytes;
7394 
7395       lbytes = (bytes > 16 ? 16 : bytes);
7396 
7397       printf ("  0x%8.8lx ", (unsigned long) addr);
7398 
7399       switch (elf_header.e_ident[EI_DATA])
7400 	{
7401 	default:
7402 	case ELFDATA2LSB:
7403 	  for (j = 15; j >= 0; j --)
7404 	    {
7405 	      if (j < lbytes)
7406 		printf ("%2.2x", data[j]);
7407 	      else
7408 		printf ("  ");
7409 
7410 	      if (!(j & 0x3))
7411 		printf (" ");
7412 	    }
7413 	  break;
7414 
7415 	case ELFDATA2MSB:
7416 	  for (j = 0; j < 16; j++)
7417 	    {
7418 	      if (j < lbytes)
7419 		printf ("%2.2x", data[j]);
7420 	      else
7421 		printf ("  ");
7422 
7423 	      if ((j & 3) == 3)
7424 		printf (" ");
7425 	    }
7426 	  break;
7427 	}
7428 
7429       for (j = 0; j < lbytes; j++)
7430 	{
7431 	  k = data[j];
7432 	  if (k >= ' ' && k < 0x7f)
7433 	    printf ("%c", k);
7434 	  else
7435 	    printf (".");
7436 	}
7437 
7438       putchar ('\n');
7439 
7440       data  += lbytes;
7441       addr  += lbytes;
7442       bytes -= lbytes;
7443     }
7444 
7445   free (start);
7446 
7447   return 1;
7448 }
7449 
7450 /* Apply addends of RELA relocations.  */
7451 
7452 static int
7453 debug_apply_rela_addends (void *file,
7454 			  Elf_Internal_Shdr *section,
7455 			  unsigned char *start)
7456 {
7457   Elf_Internal_Shdr *relsec;
7458   unsigned char *end = start + section->sh_size;
7459   /* FIXME: The relocation field size is relocation type dependent.  */
7460   unsigned int reloc_size = 4;
7461 
7462   if (!is_relocatable)
7463     return 1;
7464 
7465   if (section->sh_size < reloc_size)
7466     return 1;
7467 
7468   for (relsec = section_headers;
7469        relsec < section_headers + elf_header.e_shnum;
7470        ++relsec)
7471     {
7472       unsigned long nrelas;
7473       Elf_Internal_Rela *rela, *rp;
7474       Elf_Internal_Shdr *symsec;
7475       Elf_Internal_Sym *symtab;
7476       Elf_Internal_Sym *sym;
7477 
7478       if (relsec->sh_type != SHT_RELA
7479 	  || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
7480 	  || SECTION_HEADER (relsec->sh_info) != section
7481 	  || relsec->sh_size == 0
7482 	  || SECTION_HEADER_INDEX (relsec->sh_link) >= elf_header.e_shnum)
7483 	continue;
7484 
7485       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7486 			      &rela, &nrelas))
7487 	return 0;
7488 
7489       symsec = SECTION_HEADER (relsec->sh_link);
7490       symtab = GET_ELF_SYMBOLS (file, symsec);
7491 
7492       for (rp = rela; rp < rela + nrelas; ++rp)
7493 	{
7494 	  unsigned char *loc;
7495 
7496 	  loc = start + rp->r_offset;
7497 	  if ((loc + reloc_size) > end)
7498 	    {
7499 	      warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7500 		    (unsigned long) rp->r_offset,
7501 		    SECTION_NAME (section));
7502 	      continue;
7503 	    }
7504 
7505 	  if (is_32bit_elf)
7506 	    {
7507 	      sym = symtab + ELF32_R_SYM (rp->r_info);
7508 
7509 	      if (ELF32_R_SYM (rp->r_info) != 0
7510 		  && ELF32_ST_TYPE (sym->st_info) != STT_SECTION
7511 		  /* Relocations against object symbols can happen,
7512 		     eg when referencing a global array.  For an
7513 		     example of this see the _clz.o binary in libgcc.a.  */
7514 		  && ELF32_ST_TYPE (sym->st_info) != STT_OBJECT)
7515 		{
7516 		  warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7517 			get_symbol_type (ELF32_ST_TYPE (sym->st_info)),
7518 			SECTION_NAME (section));
7519 		  continue;
7520 		}
7521 	    }
7522 	  else
7523 	    {
7524 	      /* In MIPS little-endian objects, r_info isn't really a
7525 		 64-bit little-endian value: it has a 32-bit little-endian
7526 		 symbol index followed by four individual byte fields.
7527 		 Reorder INFO accordingly.  */
7528 	      if (elf_header.e_machine == EM_MIPS
7529 		  && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
7530 		rp->r_info = (((rp->r_info & 0xffffffff) << 32)
7531 			      | ((rp->r_info >> 56) & 0xff)
7532 			      | ((rp->r_info >> 40) & 0xff00)
7533 			      | ((rp->r_info >> 24) & 0xff0000)
7534 			      | ((rp->r_info >> 8) & 0xff000000));
7535 
7536 	      sym = symtab + ELF64_R_SYM (rp->r_info);
7537 
7538 	      if (ELF64_R_SYM (rp->r_info) != 0
7539 		  && ELF64_ST_TYPE (sym->st_info) != STT_SECTION
7540 		  && ELF64_ST_TYPE (sym->st_info) != STT_OBJECT)
7541 		{
7542 		  warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7543 			get_symbol_type (ELF64_ST_TYPE (sym->st_info)),
7544 			SECTION_NAME (section));
7545 		  continue;
7546 		}
7547 	    }
7548 
7549 	  byte_put (loc, rp->r_addend, reloc_size);
7550 	}
7551 
7552       free (symtab);
7553       free (rela);
7554       break;
7555     }
7556   return 1;
7557 }
7558 
7559 int
7560 load_debug_section (enum dwarf_section_display_enum debug, void *file)
7561 {
7562   struct dwarf_section *section = &debug_displays [debug].section;
7563   Elf_Internal_Shdr *sec;
7564   char buf [64];
7565 
7566   /* If it is already loaded, do nothing.  */
7567   if (section->start != NULL)
7568     return 1;
7569 
7570   /* Locate the debug section.  */
7571   sec = find_section (section->name);
7572   if (sec == NULL)
7573     return 0;
7574 
7575   snprintf (buf, sizeof (buf), _("%s section data"), section->name);
7576   section->address = sec->sh_addr;
7577   section->size = sec->sh_size;
7578   section->start = get_data (NULL, file, sec->sh_offset, 1,
7579 			     sec->sh_size, buf);
7580 
7581   if (debug_displays [debug].relocate)
7582     debug_apply_rela_addends (file, sec, section->start);
7583 
7584   return section->start != NULL;
7585 }
7586 
7587 void
7588 free_debug_section (enum dwarf_section_display_enum debug)
7589 {
7590   struct dwarf_section *section = &debug_displays [debug].section;
7591 
7592   if (section->start == NULL)
7593     return;
7594 
7595   free ((char *) section->start);
7596   section->start = NULL;
7597   section->address = 0;
7598   section->size = 0;
7599 }
7600 
7601 static int
7602 display_debug_section (Elf_Internal_Shdr *section, FILE *file)
7603 {
7604   char *name = SECTION_NAME (section);
7605   bfd_size_type length;
7606   int result = 1;
7607   enum dwarf_section_display_enum i;
7608 
7609   length = section->sh_size;
7610   if (length == 0)
7611     {
7612       printf (_("\nSection '%s' has no debugging data.\n"), name);
7613       return 0;
7614     }
7615 
7616   if (strneq (name, ".gnu.linkonce.wi.", 17))
7617     name = ".debug_info";
7618 
7619   /* See if we know how to display the contents of this section.  */
7620   for (i = 0; i < max; i++)
7621     if (streq (debug_displays[i].section.name, name))
7622       {
7623 	struct dwarf_section *sec = &debug_displays [i].section;
7624 
7625 	if (load_debug_section (i, file))
7626 	  {
7627 	    result &= debug_displays[i].display (sec, file);
7628 
7629 	    if (i != info && i != abbrev)
7630 	      free_debug_section (i);
7631 	  }
7632 
7633 	break;
7634       }
7635 
7636   if (i == max)
7637     {
7638       printf (_("Unrecognized debug section: %s\n"), name);
7639       result = 0;
7640     }
7641 
7642   return result;
7643 }
7644 
7645 /* Set DUMP_SECTS for all sections where dumps were requested
7646    based on section name.  */
7647 
7648 static void
7649 initialise_dumps_byname (void)
7650 {
7651   struct dump_list_entry *cur;
7652 
7653   for (cur = dump_sects_byname; cur; cur = cur->next)
7654     {
7655       unsigned int i;
7656       int any;
7657 
7658       for (i = 0, any = 0; i < elf_header.e_shnum; i++)
7659 	if (streq (SECTION_NAME (section_headers + i), cur->name))
7660 	  {
7661 	    request_dump (i, cur->type);
7662 	    any = 1;
7663 	  }
7664 
7665       if (!any)
7666 	warn (_("Section '%s' was not dumped because it does not exist!\n"),
7667 	      cur->name);
7668     }
7669 }
7670 
7671 static void
7672 process_section_contents (FILE *file)
7673 {
7674   Elf_Internal_Shdr *section;
7675   unsigned int i;
7676 
7677   if (! do_dump)
7678     return;
7679 
7680   initialise_dumps_byname ();
7681 
7682   for (i = 0, section = section_headers;
7683        i < elf_header.e_shnum && i < num_dump_sects;
7684        i++, section++)
7685     {
7686 #ifdef SUPPORT_DISASSEMBLY
7687       if (dump_sects[i] & DISASS_DUMP)
7688 	disassemble_section (section, file);
7689 #endif
7690       if (dump_sects[i] & HEX_DUMP)
7691 	dump_section (section, file);
7692 
7693       if (dump_sects[i] & DEBUG_DUMP)
7694 	display_debug_section (section, file);
7695     }
7696 
7697   /* Check to see if the user requested a
7698      dump of a section that does not exist.  */
7699   while (i++ < num_dump_sects)
7700     if (dump_sects[i])
7701       warn (_("Section %d was not dumped because it does not exist!\n"), i);
7702 }
7703 
7704 static void
7705 process_mips_fpe_exception (int mask)
7706 {
7707   if (mask)
7708     {
7709       int first = 1;
7710       if (mask & OEX_FPU_INEX)
7711 	fputs ("INEX", stdout), first = 0;
7712       if (mask & OEX_FPU_UFLO)
7713 	printf ("%sUFLO", first ? "" : "|"), first = 0;
7714       if (mask & OEX_FPU_OFLO)
7715 	printf ("%sOFLO", first ? "" : "|"), first = 0;
7716       if (mask & OEX_FPU_DIV0)
7717 	printf ("%sDIV0", first ? "" : "|"), first = 0;
7718       if (mask & OEX_FPU_INVAL)
7719 	printf ("%sINVAL", first ? "" : "|");
7720     }
7721   else
7722     fputs ("0", stdout);
7723 }
7724 
7725 /* ARM EABI attributes section.  */
7726 typedef struct
7727 {
7728   int tag;
7729   const char *name;
7730   /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup.  */
7731   int type;
7732   const char **table;
7733 } arm_attr_public_tag;
7734 
7735 static const char *arm_attr_tag_CPU_arch[] =
7736   {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
7737    "v6K", "v7"};
7738 static const char *arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
7739 static const char *arm_attr_tag_THUMB_ISA_use[] =
7740   {"No", "Thumb-1", "Thumb-2"};
7741 static const char *arm_attr_tag_VFP_arch[] = {"No", "VFPv1", "VFPv2"};
7742 static const char *arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1"};
7743 static const char *arm_attr_tag_NEON_arch[] = {"No", "NEONv1"};
7744 static const char *arm_attr_tag_ABI_PCS_config[] =
7745   {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
7746    "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
7747 static const char *arm_attr_tag_ABI_PCS_R9_use[] =
7748   {"V6", "SB", "TLS", "Unused"};
7749 static const char *arm_attr_tag_ABI_PCS_RW_data[] =
7750   {"Absolute", "PC-relative", "SB-relative", "None"};
7751 static const char *arm_attr_tag_ABI_PCS_RO_DATA[] =
7752   {"Absolute", "PC-relative", "None"};
7753 static const char *arm_attr_tag_ABI_PCS_GOT_use[] =
7754   {"None", "direct", "GOT-indirect"};
7755 static const char *arm_attr_tag_ABI_PCS_wchar_t[] =
7756   {"None", "??? 1", "2", "??? 3", "4"};
7757 static const char *arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
7758 static const char *arm_attr_tag_ABI_FP_denormal[] = {"Unused", "Needed"};
7759 static const char *arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
7760 static const char *arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
7761 static const char *arm_attr_tag_ABI_FP_number_model[] =
7762   {"Unused", "Finite", "RTABI", "IEEE 754"};
7763 static const char *arm_attr_tag_ABI_align8_needed[] = {"No", "Yes", "4-byte"};
7764 static const char *arm_attr_tag_ABI_align8_preserved[] =
7765   {"No", "Yes, except leaf SP", "Yes"};
7766 static const char *arm_attr_tag_ABI_enum_size[] =
7767   {"Unused", "small", "int", "forced to int"};
7768 static const char *arm_attr_tag_ABI_HardFP_use[] =
7769   {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
7770 static const char *arm_attr_tag_ABI_VFP_args[] =
7771   {"AAPCS", "VFP registers", "custom"};
7772 static const char *arm_attr_tag_ABI_WMMX_args[] =
7773   {"AAPCS", "WMMX registers", "custom"};
7774 static const char *arm_attr_tag_ABI_optimization_goals[] =
7775   {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7776     "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
7777 static const char *arm_attr_tag_ABI_FP_optimization_goals[] =
7778   {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7779     "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
7780 
7781 #define LOOKUP(id, name) \
7782   {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
7783 static arm_attr_public_tag arm_attr_public_tags[] =
7784 {
7785   {4, "CPU_raw_name", 1, NULL},
7786   {5, "CPU_name", 1, NULL},
7787   LOOKUP(6, CPU_arch),
7788   {7, "CPU_arch_profile", 0, NULL},
7789   LOOKUP(8, ARM_ISA_use),
7790   LOOKUP(9, THUMB_ISA_use),
7791   LOOKUP(10, VFP_arch),
7792   LOOKUP(11, WMMX_arch),
7793   LOOKUP(12, NEON_arch),
7794   LOOKUP(13, ABI_PCS_config),
7795   LOOKUP(14, ABI_PCS_R9_use),
7796   LOOKUP(15, ABI_PCS_RW_data),
7797   LOOKUP(16, ABI_PCS_RO_DATA),
7798   LOOKUP(17, ABI_PCS_GOT_use),
7799   LOOKUP(18, ABI_PCS_wchar_t),
7800   LOOKUP(19, ABI_FP_rounding),
7801   LOOKUP(20, ABI_FP_denormal),
7802   LOOKUP(21, ABI_FP_exceptions),
7803   LOOKUP(22, ABI_FP_user_exceptions),
7804   LOOKUP(23, ABI_FP_number_model),
7805   LOOKUP(24, ABI_align8_needed),
7806   LOOKUP(25, ABI_align8_preserved),
7807   LOOKUP(26, ABI_enum_size),
7808   LOOKUP(27, ABI_HardFP_use),
7809   LOOKUP(28, ABI_VFP_args),
7810   LOOKUP(29, ABI_WMMX_args),
7811   LOOKUP(30, ABI_optimization_goals),
7812   LOOKUP(31, ABI_FP_optimization_goals),
7813   {32, "compatibility", 0, NULL}
7814 };
7815 #undef LOOKUP
7816 
7817 /* Read an unsigned LEB128 encoded value from p.  Set *PLEN to the number of
7818    bytes read.  */
7819 static unsigned int
7820 read_uleb128 (unsigned char *p, unsigned int *plen)
7821 {
7822   unsigned char c;
7823   unsigned int val;
7824   int shift;
7825   int len;
7826 
7827   val = 0;
7828   shift = 0;
7829   len = 0;
7830   do
7831     {
7832       c = *(p++);
7833       len++;
7834       val |= ((unsigned int)c & 0x7f) << shift;
7835       shift += 7;
7836     }
7837   while (c & 0x80);
7838 
7839   *plen = len;
7840   return val;
7841 }
7842 
7843 static unsigned char *
7844 display_arm_attribute (unsigned char *p)
7845 {
7846   int tag;
7847   unsigned int len;
7848   int val;
7849   arm_attr_public_tag *attr;
7850   unsigned i;
7851   int type;
7852 
7853   tag = read_uleb128 (p, &len);
7854   p += len;
7855   attr = NULL;
7856   for (i = 0; i < ARRAY_SIZE(arm_attr_public_tags); i++)
7857     {
7858       if (arm_attr_public_tags[i].tag == tag)
7859 	{
7860 	  attr = &arm_attr_public_tags[i];
7861 	  break;
7862 	}
7863     }
7864 
7865   if (attr)
7866     {
7867       printf ("  Tag_%s: ", attr->name);
7868       switch (attr->type)
7869 	{
7870 	case 0:
7871 	  switch (tag)
7872 	    {
7873 	    case 7: /* Tag_CPU_arch_profile.  */
7874 	      val = read_uleb128 (p, &len);
7875 	      p += len;
7876 	      switch (val)
7877 		{
7878 		case 0: printf ("None\n"); break;
7879 		case 'A': printf ("Application\n"); break;
7880 		case 'R': printf ("Realtime\n"); break;
7881 		case 'M': printf ("Microcontroller\n"); break;
7882 		default: printf ("??? (%d)\n", val); break;
7883 		}
7884 	      break;
7885 
7886 	    case 32: /* Tag_compatibility.  */
7887 	      val = read_uleb128 (p, &len);
7888 	      p += len;
7889 	      printf ("flag = %d, vendor = %s\n", val, p);
7890 	      p += strlen((char *)p) + 1;
7891 	      break;
7892 
7893 	    default:
7894 	      abort();
7895 	    }
7896 	  return p;
7897 
7898 	case 1:
7899 	case 2:
7900 	  type = attr->type;
7901 	  break;
7902 
7903 	default:
7904 	  assert (attr->type & 0x80);
7905 	  val = read_uleb128 (p, &len);
7906 	  p += len;
7907 	  type = attr->type & 0x7f;
7908 	  if (val >= type)
7909 	    printf ("??? (%d)\n", val);
7910 	  else
7911 	    printf ("%s\n", attr->table[val]);
7912 	  return p;
7913 	}
7914     }
7915   else
7916     {
7917       if (tag & 1)
7918 	type = 1; /* String.  */
7919       else
7920 	type = 2; /* uleb128.  */
7921       printf ("  Tag_unknown_%d: ", tag);
7922     }
7923 
7924   if (type == 1)
7925     {
7926       printf ("\"%s\"\n", p);
7927       p += strlen((char *)p) + 1;
7928     }
7929   else
7930     {
7931       val = read_uleb128 (p, &len);
7932       p += len;
7933       printf ("%d (0x%x)\n", val, val);
7934     }
7935 
7936   return p;
7937 }
7938 
7939 static int
7940 process_arm_specific (FILE *file)
7941 {
7942   Elf_Internal_Shdr *sect;
7943   unsigned char *contents;
7944   unsigned char *p;
7945   unsigned char *end;
7946   bfd_vma section_len;
7947   bfd_vma len;
7948   unsigned i;
7949 
7950   /* Find the section header so that we get the size.  */
7951   for (i = 0, sect = section_headers;
7952        i < elf_header.e_shnum;
7953        i++, sect++)
7954     {
7955       if (sect->sh_type != SHT_ARM_ATTRIBUTES)
7956 	continue;
7957 
7958       contents = get_data (NULL, file, sect->sh_offset, 1, sect->sh_size,
7959 			   _("attributes"));
7960 
7961       if (!contents)
7962 	continue;
7963       p = contents;
7964       if (*p == 'A')
7965 	{
7966 	  len = sect->sh_size - 1;
7967 	  p++;
7968 	  while (len > 0)
7969 	    {
7970 	      int namelen;
7971 	      bfd_boolean public_section;
7972 
7973 	      section_len = byte_get (p, 4);
7974 	      p += 4;
7975 	      if (section_len > len)
7976 		{
7977 		  printf (_("ERROR: Bad section length (%d > %d)\n"),
7978 			  (int)section_len, (int)len);
7979 		  section_len = len;
7980 		}
7981 	      len -= section_len;
7982 	      printf ("Attribute Section: %s\n", p);
7983 	      if (strcmp ((char *)p, "aeabi") == 0)
7984 		public_section = TRUE;
7985 	      else
7986 		public_section = FALSE;
7987 	      namelen = strlen ((char *)p) + 1;
7988 	      p += namelen;
7989 	      section_len -= namelen + 4;
7990 	      while (section_len > 0)
7991 		{
7992 		  int tag = *(p++);
7993 		  int val;
7994 		  bfd_vma size;
7995 		  size = byte_get (p, 4);
7996 		  if (size > section_len)
7997 		    {
7998 		      printf (_("ERROR: Bad subsection length (%d > %d)\n"),
7999 			      (int)size, (int)section_len);
8000 		      size = section_len;
8001 		    }
8002 		  section_len -= size;
8003 		  end = p + size - 1;
8004 		  p += 4;
8005 		  switch (tag)
8006 		    {
8007 		    case 1:
8008 		      printf ("File Attributes\n");
8009 		      break;
8010 		    case 2:
8011 		      printf ("Section Attributes:");
8012 		      goto do_numlist;
8013 		    case 3:
8014 		      printf ("Symbol Attributes:");
8015 		    do_numlist:
8016 		      for (;;)
8017 			{
8018 			  unsigned int i;
8019 			  val = read_uleb128 (p, &i);
8020 			  p += i;
8021 			  if (val == 0)
8022 			    break;
8023 			  printf (" %d", val);
8024 			}
8025 		      printf ("\n");
8026 		      break;
8027 		    default:
8028 		      printf ("Unknown tag: %d\n", tag);
8029 		      public_section = FALSE;
8030 		      break;
8031 		    }
8032 		  if (public_section)
8033 		    {
8034 		      while (p < end)
8035 			p = display_arm_attribute(p);
8036 		    }
8037 		  else
8038 		    {
8039 		      /* ??? Do something sensible, like dump hex.  */
8040 		      printf ("  Unknown section contexts\n");
8041 		      p = end;
8042 		    }
8043 		}
8044 	    }
8045 	}
8046       else
8047 	{
8048 	  printf (_("Unknown format '%c'\n"), *p);
8049 	}
8050 
8051       free(contents);
8052     }
8053   return 1;
8054 }
8055 
8056 static int
8057 process_mips_specific (FILE *file)
8058 {
8059   Elf_Internal_Dyn *entry;
8060   size_t liblist_offset = 0;
8061   size_t liblistno = 0;
8062   size_t conflictsno = 0;
8063   size_t options_offset = 0;
8064   size_t conflicts_offset = 0;
8065 
8066   /* We have a lot of special sections.  Thanks SGI!  */
8067   if (dynamic_section == NULL)
8068     /* No information available.  */
8069     return 0;
8070 
8071   for (entry = dynamic_section; entry->d_tag != DT_NULL; ++entry)
8072     switch (entry->d_tag)
8073       {
8074       case DT_MIPS_LIBLIST:
8075 	liblist_offset
8076 	  = offset_from_vma (file, entry->d_un.d_val,
8077 			     liblistno * sizeof (Elf32_External_Lib));
8078 	break;
8079       case DT_MIPS_LIBLISTNO:
8080 	liblistno = entry->d_un.d_val;
8081 	break;
8082       case DT_MIPS_OPTIONS:
8083 	options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
8084 	break;
8085       case DT_MIPS_CONFLICT:
8086 	conflicts_offset
8087 	  = offset_from_vma (file, entry->d_un.d_val,
8088 			     conflictsno * sizeof (Elf32_External_Conflict));
8089 	break;
8090       case DT_MIPS_CONFLICTNO:
8091 	conflictsno = entry->d_un.d_val;
8092 	break;
8093       default:
8094 	break;
8095       }
8096 
8097   if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
8098     {
8099       Elf32_External_Lib *elib;
8100       size_t cnt;
8101 
8102       elib = get_data (NULL, file, liblist_offset,
8103 		       liblistno, sizeof (Elf32_External_Lib),
8104 		       _("liblist"));
8105       if (elib)
8106 	{
8107 	  printf ("\nSection '.liblist' contains %lu entries:\n",
8108 		  (unsigned long) liblistno);
8109 	  fputs ("     Library              Time Stamp          Checksum   Version Flags\n",
8110 		 stdout);
8111 
8112 	  for (cnt = 0; cnt < liblistno; ++cnt)
8113 	    {
8114 	      Elf32_Lib liblist;
8115 	      time_t time;
8116 	      char timebuf[20];
8117 	      struct tm *tmp;
8118 
8119 	      liblist.l_name = BYTE_GET (elib[cnt].l_name);
8120 	      time = BYTE_GET (elib[cnt].l_time_stamp);
8121 	      liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8122 	      liblist.l_version = BYTE_GET (elib[cnt].l_version);
8123 	      liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8124 
8125 	      tmp = gmtime (&time);
8126 	      snprintf (timebuf, sizeof (timebuf),
8127 			"%04u-%02u-%02uT%02u:%02u:%02u",
8128 			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8129 			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8130 
8131 	      printf ("%3lu: ", (unsigned long) cnt);
8132 	      if (VALID_DYNAMIC_NAME (liblist.l_name))
8133 		print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
8134 	      else
8135 		printf ("<corrupt: %9ld>", liblist.l_name);
8136 	      printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
8137 		      liblist.l_version);
8138 
8139 	      if (liblist.l_flags == 0)
8140 		puts (" NONE");
8141 	      else
8142 		{
8143 		  static const struct
8144 		  {
8145 		    const char *name;
8146 		    int bit;
8147 		  }
8148 		  l_flags_vals[] =
8149 		  {
8150 		    { " EXACT_MATCH", LL_EXACT_MATCH },
8151 		    { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
8152 		    { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
8153 		    { " EXPORTS", LL_EXPORTS },
8154 		    { " DELAY_LOAD", LL_DELAY_LOAD },
8155 		    { " DELTA", LL_DELTA }
8156 		  };
8157 		  int flags = liblist.l_flags;
8158 		  size_t fcnt;
8159 
8160 		  for (fcnt = 0;
8161 		       fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8162 		       ++fcnt)
8163 		    if ((flags & l_flags_vals[fcnt].bit) != 0)
8164 		      {
8165 			fputs (l_flags_vals[fcnt].name, stdout);
8166 			flags ^= l_flags_vals[fcnt].bit;
8167 		      }
8168 		  if (flags != 0)
8169 		    printf (" %#x", (unsigned int) flags);
8170 
8171 		  puts ("");
8172 		}
8173 	    }
8174 
8175 	  free (elib);
8176 	}
8177     }
8178 
8179   if (options_offset != 0)
8180     {
8181       Elf_External_Options *eopt;
8182       Elf_Internal_Shdr *sect = section_headers;
8183       Elf_Internal_Options *iopt;
8184       Elf_Internal_Options *option;
8185       size_t offset;
8186       int cnt;
8187 
8188       /* Find the section header so that we get the size.  */
8189       while (sect->sh_type != SHT_MIPS_OPTIONS)
8190 	++sect;
8191 
8192       eopt = get_data (NULL, file, options_offset, 1, sect->sh_size,
8193 		       _("options"));
8194       if (eopt)
8195 	{
8196 	  iopt = cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (*iopt));
8197 	  if (iopt == NULL)
8198 	    {
8199 	      error (_("Out of memory"));
8200 	      return 0;
8201 	    }
8202 
8203 	  offset = cnt = 0;
8204 	  option = iopt;
8205 
8206 	  while (offset < sect->sh_size)
8207 	    {
8208 	      Elf_External_Options *eoption;
8209 
8210 	      eoption = (Elf_External_Options *) ((char *) eopt + offset);
8211 
8212 	      option->kind = BYTE_GET (eoption->kind);
8213 	      option->size = BYTE_GET (eoption->size);
8214 	      option->section = BYTE_GET (eoption->section);
8215 	      option->info = BYTE_GET (eoption->info);
8216 
8217 	      offset += option->size;
8218 
8219 	      ++option;
8220 	      ++cnt;
8221 	    }
8222 
8223 	  printf (_("\nSection '%s' contains %d entries:\n"),
8224 		  SECTION_NAME (sect), cnt);
8225 
8226 	  option = iopt;
8227 
8228 	  while (cnt-- > 0)
8229 	    {
8230 	      size_t len;
8231 
8232 	      switch (option->kind)
8233 		{
8234 		case ODK_NULL:
8235 		  /* This shouldn't happen.  */
8236 		  printf (" NULL       %d %lx", option->section, option->info);
8237 		  break;
8238 		case ODK_REGINFO:
8239 		  printf (" REGINFO    ");
8240 		  if (elf_header.e_machine == EM_MIPS)
8241 		    {
8242 		      /* 32bit form.  */
8243 		      Elf32_External_RegInfo *ereg;
8244 		      Elf32_RegInfo reginfo;
8245 
8246 		      ereg = (Elf32_External_RegInfo *) (option + 1);
8247 		      reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8248 		      reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8249 		      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8250 		      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8251 		      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8252 		      reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8253 
8254 		      printf ("GPR %08lx  GP 0x%lx\n",
8255 			      reginfo.ri_gprmask,
8256 			      (unsigned long) reginfo.ri_gp_value);
8257 		      printf ("            CPR0 %08lx  CPR1 %08lx  CPR2 %08lx  CPR3 %08lx\n",
8258 			      reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8259 			      reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8260 		    }
8261 		  else
8262 		    {
8263 		      /* 64 bit form.  */
8264 		      Elf64_External_RegInfo *ereg;
8265 		      Elf64_Internal_RegInfo reginfo;
8266 
8267 		      ereg = (Elf64_External_RegInfo *) (option + 1);
8268 		      reginfo.ri_gprmask    = BYTE_GET (ereg->ri_gprmask);
8269 		      reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8270 		      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8271 		      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8272 		      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8273 		      reginfo.ri_gp_value   = BYTE_GET (ereg->ri_gp_value);
8274 
8275 		      printf ("GPR %08lx  GP 0x",
8276 			      reginfo.ri_gprmask);
8277 		      printf_vma (reginfo.ri_gp_value);
8278 		      printf ("\n");
8279 
8280 		      printf ("            CPR0 %08lx  CPR1 %08lx  CPR2 %08lx  CPR3 %08lx\n",
8281 			      reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8282 			      reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8283 		    }
8284 		  ++option;
8285 		  continue;
8286 		case ODK_EXCEPTIONS:
8287 		  fputs (" EXCEPTIONS fpe_min(", stdout);
8288 		  process_mips_fpe_exception (option->info & OEX_FPU_MIN);
8289 		  fputs (") fpe_max(", stdout);
8290 		  process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
8291 		  fputs (")", stdout);
8292 
8293 		  if (option->info & OEX_PAGE0)
8294 		    fputs (" PAGE0", stdout);
8295 		  if (option->info & OEX_SMM)
8296 		    fputs (" SMM", stdout);
8297 		  if (option->info & OEX_FPDBUG)
8298 		    fputs (" FPDBUG", stdout);
8299 		  if (option->info & OEX_DISMISS)
8300 		    fputs (" DISMISS", stdout);
8301 		  break;
8302 		case ODK_PAD:
8303 		  fputs (" PAD       ", stdout);
8304 		  if (option->info & OPAD_PREFIX)
8305 		    fputs (" PREFIX", stdout);
8306 		  if (option->info & OPAD_POSTFIX)
8307 		    fputs (" POSTFIX", stdout);
8308 		  if (option->info & OPAD_SYMBOL)
8309 		    fputs (" SYMBOL", stdout);
8310 		  break;
8311 		case ODK_HWPATCH:
8312 		  fputs (" HWPATCH   ", stdout);
8313 		  if (option->info & OHW_R4KEOP)
8314 		    fputs (" R4KEOP", stdout);
8315 		  if (option->info & OHW_R8KPFETCH)
8316 		    fputs (" R8KPFETCH", stdout);
8317 		  if (option->info & OHW_R5KEOP)
8318 		    fputs (" R5KEOP", stdout);
8319 		  if (option->info & OHW_R5KCVTL)
8320 		    fputs (" R5KCVTL", stdout);
8321 		  break;
8322 		case ODK_FILL:
8323 		  fputs (" FILL       ", stdout);
8324 		  /* XXX Print content of info word?  */
8325 		  break;
8326 		case ODK_TAGS:
8327 		  fputs (" TAGS       ", stdout);
8328 		  /* XXX Print content of info word?  */
8329 		  break;
8330 		case ODK_HWAND:
8331 		  fputs (" HWAND     ", stdout);
8332 		  if (option->info & OHWA0_R4KEOP_CHECKED)
8333 		    fputs (" R4KEOP_CHECKED", stdout);
8334 		  if (option->info & OHWA0_R4KEOP_CLEAN)
8335 		    fputs (" R4KEOP_CLEAN", stdout);
8336 		  break;
8337 		case ODK_HWOR:
8338 		  fputs (" HWOR      ", stdout);
8339 		  if (option->info & OHWA0_R4KEOP_CHECKED)
8340 		    fputs (" R4KEOP_CHECKED", stdout);
8341 		  if (option->info & OHWA0_R4KEOP_CLEAN)
8342 		    fputs (" R4KEOP_CLEAN", stdout);
8343 		  break;
8344 		case ODK_GP_GROUP:
8345 		  printf (" GP_GROUP  %#06lx  self-contained %#06lx",
8346 			  option->info & OGP_GROUP,
8347 			  (option->info & OGP_SELF) >> 16);
8348 		  break;
8349 		case ODK_IDENT:
8350 		  printf (" IDENT     %#06lx  self-contained %#06lx",
8351 			  option->info & OGP_GROUP,
8352 			  (option->info & OGP_SELF) >> 16);
8353 		  break;
8354 		default:
8355 		  /* This shouldn't happen.  */
8356 		  printf (" %3d ???     %d %lx",
8357 			  option->kind, option->section, option->info);
8358 		  break;
8359 		}
8360 
8361 	      len = sizeof (*eopt);
8362 	      while (len < option->size)
8363 		if (((char *) option)[len] >= ' '
8364 		    && ((char *) option)[len] < 0x7f)
8365 		  printf ("%c", ((char *) option)[len++]);
8366 		else
8367 		  printf ("\\%03o", ((char *) option)[len++]);
8368 
8369 	      fputs ("\n", stdout);
8370 	      ++option;
8371 	    }
8372 
8373 	  free (eopt);
8374 	}
8375     }
8376 
8377   if (conflicts_offset != 0 && conflictsno != 0)
8378     {
8379       Elf32_Conflict *iconf;
8380       size_t cnt;
8381 
8382       if (dynamic_symbols == NULL)
8383 	{
8384 	  error (_("conflict list found without a dynamic symbol table"));
8385 	  return 0;
8386 	}
8387 
8388       iconf = cmalloc (conflictsno, sizeof (*iconf));
8389       if (iconf == NULL)
8390 	{
8391 	  error (_("Out of memory"));
8392 	  return 0;
8393 	}
8394 
8395       if (is_32bit_elf)
8396 	{
8397 	  Elf32_External_Conflict *econf32;
8398 
8399 	  econf32 = get_data (NULL, file, conflicts_offset,
8400 			      conflictsno, sizeof (*econf32), _("conflict"));
8401 	  if (!econf32)
8402 	    return 0;
8403 
8404 	  for (cnt = 0; cnt < conflictsno; ++cnt)
8405 	    iconf[cnt] = BYTE_GET (econf32[cnt]);
8406 
8407 	  free (econf32);
8408 	}
8409       else
8410 	{
8411 	  Elf64_External_Conflict *econf64;
8412 
8413 	  econf64 = get_data (NULL, file, conflicts_offset,
8414 			      conflictsno, sizeof (*econf64), _("conflict"));
8415 	  if (!econf64)
8416 	    return 0;
8417 
8418 	  for (cnt = 0; cnt < conflictsno; ++cnt)
8419 	    iconf[cnt] = BYTE_GET (econf64[cnt]);
8420 
8421 	  free (econf64);
8422 	}
8423 
8424       printf (_("\nSection '.conflict' contains %lu entries:\n"),
8425 	      (unsigned long) conflictsno);
8426       puts (_("  Num:    Index       Value  Name"));
8427 
8428       for (cnt = 0; cnt < conflictsno; ++cnt)
8429 	{
8430 	  Elf_Internal_Sym *psym = & dynamic_symbols[iconf[cnt]];
8431 
8432 	  printf ("%5lu: %8lu  ", (unsigned long) cnt, iconf[cnt]);
8433 	  print_vma (psym->st_value, FULL_HEX);
8434 	  putchar (' ');
8435 	  if (VALID_DYNAMIC_NAME (psym->st_name))
8436 	    print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
8437 	  else
8438 	    printf ("<corrupt: %14ld>", psym->st_name);
8439 	  putchar ('\n');
8440 	}
8441 
8442       free (iconf);
8443     }
8444 
8445   return 1;
8446 }
8447 
8448 static int
8449 process_gnu_liblist (FILE *file)
8450 {
8451   Elf_Internal_Shdr *section, *string_sec;
8452   Elf32_External_Lib *elib;
8453   char *strtab;
8454   size_t strtab_size;
8455   size_t cnt;
8456   unsigned i;
8457 
8458   if (! do_arch)
8459     return 0;
8460 
8461   for (i = 0, section = section_headers;
8462        i < elf_header.e_shnum;
8463        i++, section++)
8464     {
8465       switch (section->sh_type)
8466 	{
8467 	case SHT_GNU_LIBLIST:
8468 	  if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
8469 	    break;
8470 
8471 	  elib = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
8472 			   _("liblist"));
8473 
8474 	  if (elib == NULL)
8475 	    break;
8476 	  string_sec = SECTION_HEADER (section->sh_link);
8477 
8478 	  strtab = get_data (NULL, file, string_sec->sh_offset, 1,
8479 			     string_sec->sh_size, _("liblist string table"));
8480 	  strtab_size = string_sec->sh_size;
8481 
8482 	  if (strtab == NULL
8483 	      || section->sh_entsize != sizeof (Elf32_External_Lib))
8484 	    {
8485 	      free (elib);
8486 	      break;
8487 	    }
8488 
8489 	  printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
8490 		  SECTION_NAME (section),
8491 		  (long) (section->sh_size / sizeof (Elf32_External_Lib)));
8492 
8493 	  puts ("     Library              Time Stamp          Checksum   Version Flags");
8494 
8495 	  for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
8496 	       ++cnt)
8497 	    {
8498 	      Elf32_Lib liblist;
8499 	      time_t time;
8500 	      char timebuf[20];
8501 	      struct tm *tmp;
8502 
8503 	      liblist.l_name = BYTE_GET (elib[cnt].l_name);
8504 	      time = BYTE_GET (elib[cnt].l_time_stamp);
8505 	      liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8506 	      liblist.l_version = BYTE_GET (elib[cnt].l_version);
8507 	      liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8508 
8509 	      tmp = gmtime (&time);
8510 	      snprintf (timebuf, sizeof (timebuf),
8511 			"%04u-%02u-%02uT%02u:%02u:%02u",
8512 			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8513 			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8514 
8515 	      printf ("%3lu: ", (unsigned long) cnt);
8516 	      if (do_wide)
8517 		printf ("%-20s", liblist.l_name < strtab_size
8518 				 ? strtab + liblist.l_name : "<corrupt>");
8519 	      else
8520 		printf ("%-20.20s", liblist.l_name < strtab_size
8521 				    ? strtab + liblist.l_name : "<corrupt>");
8522 	      printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
8523 		      liblist.l_version, liblist.l_flags);
8524 	    }
8525 
8526 	  free (elib);
8527 	}
8528     }
8529 
8530   return 1;
8531 }
8532 
8533 static const char *
8534 get_note_type (unsigned e_type)
8535 {
8536   static char buff[64];
8537 
8538   if (elf_header.e_type == ET_CORE)
8539     switch (e_type)
8540       {
8541       case NT_AUXV:
8542 	return _("NT_AUXV (auxiliary vector)");
8543       case NT_PRSTATUS:
8544 	return _("NT_PRSTATUS (prstatus structure)");
8545       case NT_FPREGSET:
8546 	return _("NT_FPREGSET (floating point registers)");
8547       case NT_PRPSINFO:
8548 	return _("NT_PRPSINFO (prpsinfo structure)");
8549       case NT_TASKSTRUCT:
8550 	return _("NT_TASKSTRUCT (task structure)");
8551       case NT_PRXFPREG:
8552 	return _("NT_PRXFPREG (user_xfpregs structure)");
8553       case NT_PSTATUS:
8554 	return _("NT_PSTATUS (pstatus structure)");
8555       case NT_FPREGS:
8556 	return _("NT_FPREGS (floating point registers)");
8557       case NT_PSINFO:
8558 	return _("NT_PSINFO (psinfo structure)");
8559       case NT_LWPSTATUS:
8560 	return _("NT_LWPSTATUS (lwpstatus_t structure)");
8561       case NT_LWPSINFO:
8562 	return _("NT_LWPSINFO (lwpsinfo_t structure)");
8563       case NT_WIN32PSTATUS:
8564 	return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8565       default:
8566 	break;
8567       }
8568   else
8569     switch (e_type)
8570       {
8571       case NT_VERSION:
8572 	return _("NT_VERSION (version)");
8573       case NT_ARCH:
8574 	return _("NT_ARCH (architecture)");
8575       default:
8576 	break;
8577       }
8578 
8579   snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
8580   return buff;
8581 }
8582 
8583 static const char *
8584 get_netbsd_elfcore_note_type (unsigned e_type)
8585 {
8586   static char buff[64];
8587 
8588   if (e_type == NT_NETBSDCORE_PROCINFO)
8589     {
8590       /* NetBSD core "procinfo" structure.  */
8591       return _("NetBSD procinfo structure");
8592     }
8593 
8594   /* As of Jan 2002 there are no other machine-independent notes
8595      defined for NetBSD core files.  If the note type is less
8596      than the start of the machine-dependent note types, we don't
8597      understand it.  */
8598 
8599   if (e_type < NT_NETBSDCORE_FIRSTMACH)
8600     {
8601       snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
8602       return buff;
8603     }
8604 
8605   switch (elf_header.e_machine)
8606     {
8607     /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8608        and PT_GETFPREGS == mach+2.  */
8609 
8610     case EM_OLD_ALPHA:
8611     case EM_ALPHA:
8612     case EM_SPARC:
8613     case EM_SPARC32PLUS:
8614     case EM_SPARCV9:
8615       switch (e_type)
8616 	{
8617 	case NT_NETBSDCORE_FIRSTMACH+0:
8618 	  return _("PT_GETREGS (reg structure)");
8619 	case NT_NETBSDCORE_FIRSTMACH+2:
8620 	  return _("PT_GETFPREGS (fpreg structure)");
8621 	default:
8622 	  break;
8623 	}
8624       break;
8625 
8626     /* On all other arch's, PT_GETREGS == mach+1 and
8627        PT_GETFPREGS == mach+3.  */
8628     default:
8629       switch (e_type)
8630 	{
8631 	case NT_NETBSDCORE_FIRSTMACH+1:
8632 	  return _("PT_GETREGS (reg structure)");
8633 	case NT_NETBSDCORE_FIRSTMACH+3:
8634 	  return _("PT_GETFPREGS (fpreg structure)");
8635 	default:
8636 	  break;
8637 	}
8638     }
8639 
8640   snprintf (buff, sizeof (buff), _("PT_FIRSTMACH+%d"),
8641 	    e_type - NT_NETBSDCORE_FIRSTMACH);
8642   return buff;
8643 }
8644 
8645 /* Note that by the ELF standard, the name field is already null byte
8646    terminated, and namesz includes the terminating null byte.
8647    I.E. the value of namesz for the name "FSF" is 4.
8648 
8649    If the value of namesz is zero, there is no name present.  */
8650 static int
8651 process_note (Elf_Internal_Note *pnote)
8652 {
8653   const char *nt;
8654 
8655   if (pnote->namesz == 0)
8656     /* If there is no note name, then use the default set of
8657        note type strings.  */
8658     nt = get_note_type (pnote->type);
8659 
8660   else if (strneq (pnote->namedata, "NetBSD-CORE", 11))
8661     /* NetBSD-specific core file notes.  */
8662     nt = get_netbsd_elfcore_note_type (pnote->type);
8663 
8664   else
8665     /* Don't recognize this note name; just use the default set of
8666        note type strings.  */
8667       nt = get_note_type (pnote->type);
8668 
8669   printf ("  %s\t\t0x%08lx\t%s\n",
8670 	  pnote->namesz ? pnote->namedata : "(NONE)",
8671 	  pnote->descsz, nt);
8672   return 1;
8673 }
8674 
8675 
8676 static int
8677 process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
8678 {
8679   Elf_External_Note *pnotes;
8680   Elf_External_Note *external;
8681   int res = 1;
8682 
8683   if (length <= 0)
8684     return 0;
8685 
8686   pnotes = get_data (NULL, file, offset, 1, length, _("notes"));
8687   if (!pnotes)
8688     return 0;
8689 
8690   external = pnotes;
8691 
8692   printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8693 	  (unsigned long) offset, (unsigned long) length);
8694   printf (_("  Owner\t\tData size\tDescription\n"));
8695 
8696   while (external < (Elf_External_Note *)((char *) pnotes + length))
8697     {
8698       Elf_External_Note *next;
8699       Elf_Internal_Note inote;
8700       char *temp = NULL;
8701 
8702       inote.type     = BYTE_GET (external->type);
8703       inote.namesz   = BYTE_GET (external->namesz);
8704       inote.namedata = external->name;
8705       inote.descsz   = BYTE_GET (external->descsz);
8706       inote.descdata = inote.namedata + align_power (inote.namesz, 2);
8707       inote.descpos  = offset + (inote.descdata - (char *) pnotes);
8708 
8709       next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
8710 
8711       if (((char *) next) > (((char *) pnotes) + length))
8712 	{
8713 	  warn (_("corrupt note found at offset %lx into core notes\n"),
8714 		(long)((char *)external - (char *)pnotes));
8715 	  warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
8716 		inote.type, inote.namesz, inote.descsz);
8717 	  break;
8718 	}
8719 
8720       external = next;
8721 
8722       /* Verify that name is null terminated.  It appears that at least
8723 	 one version of Linux (RedHat 6.0) generates corefiles that don't
8724 	 comply with the ELF spec by failing to include the null byte in
8725 	 namesz.  */
8726       if (inote.namedata[inote.namesz] != '\0')
8727 	{
8728 	  temp = malloc (inote.namesz + 1);
8729 
8730 	  if (temp == NULL)
8731 	    {
8732 	      error (_("Out of memory\n"));
8733 	      res = 0;
8734 	      break;
8735 	    }
8736 
8737 	  strncpy (temp, inote.namedata, inote.namesz);
8738 	  temp[inote.namesz] = 0;
8739 
8740 	  /* warn (_("'%s' NOTE name not properly null terminated\n"), temp);  */
8741 	  inote.namedata = temp;
8742 	}
8743 
8744       res &= process_note (& inote);
8745 
8746       if (temp != NULL)
8747 	{
8748 	  free (temp);
8749 	  temp = NULL;
8750 	}
8751     }
8752 
8753   free (pnotes);
8754 
8755   return res;
8756 }
8757 
8758 static int
8759 process_corefile_note_segments (FILE *file)
8760 {
8761   Elf_Internal_Phdr *segment;
8762   unsigned int i;
8763   int res = 1;
8764 
8765   if (! get_program_headers (file))
8766       return 0;
8767 
8768   for (i = 0, segment = program_headers;
8769        i < elf_header.e_phnum;
8770        i++, segment++)
8771     {
8772       if (segment->p_type == PT_NOTE)
8773 	res &= process_corefile_note_segment (file,
8774 					      (bfd_vma) segment->p_offset,
8775 					      (bfd_vma) segment->p_filesz);
8776     }
8777 
8778   return res;
8779 }
8780 
8781 static int
8782 process_note_sections (FILE *file)
8783 {
8784   Elf_Internal_Shdr *section;
8785   unsigned long i;
8786   int res = 1;
8787 
8788   for (i = 0, section = section_headers;
8789        i < elf_header.e_shnum;
8790        i++, section++)
8791     if (section->sh_type == SHT_NOTE)
8792       res &= process_corefile_note_segment (file,
8793 					    (bfd_vma) section->sh_offset,
8794 					    (bfd_vma) section->sh_size);
8795 
8796   return res;
8797 }
8798 
8799 static int
8800 process_notes (FILE *file)
8801 {
8802   /* If we have not been asked to display the notes then do nothing.  */
8803   if (! do_notes)
8804     return 1;
8805 
8806   if (elf_header.e_type != ET_CORE)
8807     return process_note_sections (file);
8808 
8809   /* No program headers means no NOTE segment.  */
8810   if (elf_header.e_phnum > 0)
8811     return process_corefile_note_segments (file);
8812 
8813   printf (_("No note segments present in the core file.\n"));
8814   return 1;
8815 }
8816 
8817 static int
8818 process_arch_specific (FILE *file)
8819 {
8820   if (! do_arch)
8821     return 1;
8822 
8823   switch (elf_header.e_machine)
8824     {
8825     case EM_ARM:
8826       return process_arm_specific (file);
8827     case EM_MIPS:
8828     case EM_MIPS_RS3_LE:
8829       return process_mips_specific (file);
8830       break;
8831     default:
8832       break;
8833     }
8834   return 1;
8835 }
8836 
8837 static int
8838 get_file_header (FILE *file)
8839 {
8840   /* Read in the identity array.  */
8841   if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
8842     return 0;
8843 
8844   /* Determine how to read the rest of the header.  */
8845   switch (elf_header.e_ident[EI_DATA])
8846     {
8847     default: /* fall through */
8848     case ELFDATANONE: /* fall through */
8849     case ELFDATA2LSB:
8850       byte_get = byte_get_little_endian;
8851       byte_put = byte_put_little_endian;
8852       break;
8853     case ELFDATA2MSB:
8854       byte_get = byte_get_big_endian;
8855       byte_put = byte_put_big_endian;
8856       break;
8857     }
8858 
8859   /* For now we only support 32 bit and 64 bit ELF files.  */
8860   is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
8861 
8862   /* Read in the rest of the header.  */
8863   if (is_32bit_elf)
8864     {
8865       Elf32_External_Ehdr ehdr32;
8866       /* Temporary var to prevent the GCC -Wbounded checker from firing. */
8867       void *tmp = &ehdr32.e_type[0];
8868 
8869       if (fread (tmp, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
8870 	return 0;
8871 
8872       elf_header.e_type      = BYTE_GET (ehdr32.e_type);
8873       elf_header.e_machine   = BYTE_GET (ehdr32.e_machine);
8874       elf_header.e_version   = BYTE_GET (ehdr32.e_version);
8875       elf_header.e_entry     = BYTE_GET (ehdr32.e_entry);
8876       elf_header.e_phoff     = BYTE_GET (ehdr32.e_phoff);
8877       elf_header.e_shoff     = BYTE_GET (ehdr32.e_shoff);
8878       elf_header.e_flags     = BYTE_GET (ehdr32.e_flags);
8879       elf_header.e_ehsize    = BYTE_GET (ehdr32.e_ehsize);
8880       elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
8881       elf_header.e_phnum     = BYTE_GET (ehdr32.e_phnum);
8882       elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
8883       elf_header.e_shnum     = BYTE_GET (ehdr32.e_shnum);
8884       elf_header.e_shstrndx  = BYTE_GET (ehdr32.e_shstrndx);
8885     }
8886   else
8887     {
8888       Elf64_External_Ehdr ehdr64;
8889       /* Temporary var to prevent the GCC -Wbounded checker from firing. */
8890       void *tmp = &ehdr64.e_type[0];
8891 
8892       /* If we have been compiled with sizeof (bfd_vma) == 4, then
8893 	 we will not be able to cope with the 64bit data found in
8894 	 64 ELF files.  Detect this now and abort before we start
8895 	 overwriting things.  */
8896       if (sizeof (bfd_vma) < 8)
8897 	{
8898 	  error (_("This instance of readelf has been built without support for a\n\
8899 64 bit data type and so it cannot read 64 bit ELF files.\n"));
8900 	  return 0;
8901 	}
8902 
8903       if (fread (tmp, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
8904 	return 0;
8905 
8906       elf_header.e_type      = BYTE_GET (ehdr64.e_type);
8907       elf_header.e_machine   = BYTE_GET (ehdr64.e_machine);
8908       elf_header.e_version   = BYTE_GET (ehdr64.e_version);
8909       elf_header.e_entry     = BYTE_GET (ehdr64.e_entry);
8910       elf_header.e_phoff     = BYTE_GET (ehdr64.e_phoff);
8911       elf_header.e_shoff     = BYTE_GET (ehdr64.e_shoff);
8912       elf_header.e_flags     = BYTE_GET (ehdr64.e_flags);
8913       elf_header.e_ehsize    = BYTE_GET (ehdr64.e_ehsize);
8914       elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
8915       elf_header.e_phnum     = BYTE_GET (ehdr64.e_phnum);
8916       elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
8917       elf_header.e_shnum     = BYTE_GET (ehdr64.e_shnum);
8918       elf_header.e_shstrndx  = BYTE_GET (ehdr64.e_shstrndx);
8919     }
8920 
8921   if (elf_header.e_shoff)
8922     {
8923       /* There may be some extensions in the first section header.  Don't
8924 	 bomb if we can't read it.  */
8925       if (is_32bit_elf)
8926 	get_32bit_section_headers (file, 1);
8927       else
8928 	get_64bit_section_headers (file, 1);
8929     }
8930 
8931   is_relocatable = elf_header.e_type == ET_REL;
8932 
8933   return 1;
8934 }
8935 
8936 /* Process one ELF object file according to the command line options.
8937    This file may actually be stored in an archive.  The file is
8938    positioned at the start of the ELF object.  */
8939 
8940 static int
8941 process_object (char *file_name, FILE *file)
8942 {
8943   unsigned int i;
8944 
8945   if (! get_file_header (file))
8946     {
8947       error (_("%s: Failed to read file header\n"), file_name);
8948       return 1;
8949     }
8950 
8951   /* Initialise per file variables.  */
8952   for (i = NUM_ELEM (version_info); i--;)
8953     version_info[i] = 0;
8954 
8955   for (i = NUM_ELEM (dynamic_info); i--;)
8956     dynamic_info[i] = 0;
8957 
8958   /* Process the file.  */
8959   if (show_name)
8960     printf (_("\nFile: %s\n"), file_name);
8961 
8962   /* Initialise the dump_sects array from the cmdline_dump_sects array.
8963      Note we do this even if cmdline_dump_sects is empty because we
8964      must make sure that the dump_sets array is zeroed out before each
8965      object file is processed.  */
8966   if (num_dump_sects > num_cmdline_dump_sects)
8967     memset (dump_sects, 0, num_dump_sects);
8968 
8969   if (num_cmdline_dump_sects > 0)
8970     {
8971       if (num_dump_sects == 0)
8972 	/* A sneaky way of allocating the dump_sects array.  */
8973 	request_dump (num_cmdline_dump_sects, 0);
8974 
8975       assert (num_dump_sects >= num_cmdline_dump_sects);
8976       memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
8977     }
8978 
8979   if (! process_file_header ())
8980     return 1;
8981 
8982   if (! process_section_headers (file))
8983     {
8984       /* Without loaded section headers we cannot process lots of
8985 	 things.  */
8986       do_unwind = do_version = do_dump = do_arch = 0;
8987 
8988       if (! do_using_dynamic)
8989 	do_syms = do_reloc = 0;
8990     }
8991 
8992   if (! process_section_groups (file))
8993     {
8994       /* Without loaded section groups we cannot process unwind.  */
8995       do_unwind = 0;
8996     }
8997 
8998   if (process_program_headers (file))
8999     process_dynamic_section (file);
9000 
9001   process_relocs (file);
9002 
9003   process_unwind (file);
9004 
9005   process_symbol_table (file);
9006 
9007   process_syminfo (file);
9008 
9009   process_version_sections (file);
9010 
9011   process_section_contents (file);
9012 
9013   process_notes (file);
9014 
9015   process_gnu_liblist (file);
9016 
9017   process_arch_specific (file);
9018 
9019   if (program_headers)
9020     {
9021       free (program_headers);
9022       program_headers = NULL;
9023     }
9024 
9025   if (section_headers)
9026     {
9027       free (section_headers);
9028       section_headers = NULL;
9029     }
9030 
9031   if (string_table)
9032     {
9033       free (string_table);
9034       string_table = NULL;
9035       string_table_length = 0;
9036     }
9037 
9038   if (dynamic_strings)
9039     {
9040       free (dynamic_strings);
9041       dynamic_strings = NULL;
9042       dynamic_strings_length = 0;
9043     }
9044 
9045   if (dynamic_symbols)
9046     {
9047       free (dynamic_symbols);
9048       dynamic_symbols = NULL;
9049       num_dynamic_syms = 0;
9050     }
9051 
9052   if (dynamic_syminfo)
9053     {
9054       free (dynamic_syminfo);
9055       dynamic_syminfo = NULL;
9056     }
9057 
9058   if (section_headers_groups)
9059     {
9060       free (section_headers_groups);
9061       section_headers_groups = NULL;
9062     }
9063 
9064   if (section_groups)
9065     {
9066       struct group_list *g, *next;
9067 
9068       for (i = 0; i < group_count; i++)
9069 	{
9070 	  for (g = section_groups [i].root; g != NULL; g = next)
9071 	    {
9072 	      next = g->next;
9073 	      free (g);
9074 	    }
9075 	}
9076 
9077       free (section_groups);
9078       section_groups = NULL;
9079     }
9080 
9081   free_debug_memory ();
9082 
9083   return 0;
9084 }
9085 
9086 /* Process an ELF archive.  The file is positioned just after the
9087    ARMAG string.  */
9088 
9089 static int
9090 process_archive (char *file_name, FILE *file)
9091 {
9092   struct ar_hdr arhdr;
9093   size_t got;
9094   unsigned long size;
9095   char *longnames = NULL;
9096   unsigned long longnames_size = 0;
9097   size_t file_name_size;
9098   int ret;
9099 
9100   show_name = 1;
9101 
9102   got = fread (&arhdr, 1, sizeof arhdr, file);
9103   if (got != sizeof arhdr)
9104     {
9105       if (got == 0)
9106 	return 0;
9107 
9108       error (_("%s: failed to read archive header\n"), file_name);
9109       return 1;
9110     }
9111 
9112   if (memcmp (arhdr.ar_name, "/               ", 16) == 0)
9113     {
9114       /* This is the archive symbol table.  Skip it.
9115 	 FIXME: We should have an option to dump it.  */
9116       size = strtoul (arhdr.ar_size, NULL, 10);
9117       if (fseek (file, size + (size & 1), SEEK_CUR) != 0)
9118 	{
9119 	  error (_("%s: failed to skip archive symbol table\n"), file_name);
9120 	  return 1;
9121 	}
9122 
9123       got = fread (&arhdr, 1, sizeof arhdr, file);
9124       if (got != sizeof arhdr)
9125 	{
9126 	  if (got == 0)
9127 	    return 0;
9128 
9129 	  error (_("%s: failed to read archive header\n"), file_name);
9130 	  return 1;
9131 	}
9132     }
9133 
9134   if (memcmp (arhdr.ar_name, "//              ", 16) == 0)
9135     {
9136       /* This is the archive string table holding long member
9137 	 names.  */
9138 
9139       longnames_size = strtoul (arhdr.ar_size, NULL, 10);
9140 
9141       longnames = malloc (longnames_size);
9142       if (longnames == NULL)
9143 	{
9144 	  error (_("Out of memory\n"));
9145 	  return 1;
9146 	}
9147 
9148       if (fread (longnames, longnames_size, 1, file) != 1)
9149 	{
9150 	  free (longnames);
9151 	  error (_("%s: failed to read string table\n"), file_name);
9152 	  return 1;
9153 	}
9154 
9155       if ((longnames_size & 1) != 0)
9156 	getc (file);
9157 
9158       got = fread (&arhdr, 1, sizeof arhdr, file);
9159       if (got != sizeof arhdr)
9160 	{
9161 	  free (longnames);
9162 
9163 	  if (got == 0)
9164 	    return 0;
9165 
9166 	  error (_("%s: failed to read archive header\n"), file_name);
9167 	  return 1;
9168 	}
9169     }
9170 
9171   file_name_size = strlen (file_name);
9172   ret = 0;
9173 
9174   while (1)
9175     {
9176       char *name;
9177       char *nameend;
9178       char *namealc;
9179 
9180       if (arhdr.ar_name[0] == '/')
9181 	{
9182 	  unsigned long off;
9183 
9184 	  off = strtoul (arhdr.ar_name + 1, NULL, 10);
9185 	  if (off >= longnames_size)
9186 	    {
9187 	      error (_("%s: invalid archive string table offset %lu\n"), file_name, off);
9188 	      ret = 1;
9189 	      break;
9190 	    }
9191 
9192 	  name = longnames + off;
9193 	  nameend = memchr (name, '/', longnames_size - off);
9194 	}
9195       else
9196 	{
9197 	  name = arhdr.ar_name;
9198 	  nameend = memchr (name, '/', 16);
9199 	}
9200 
9201       if (nameend == NULL)
9202 	{
9203 	  error (_("%s: bad archive file name\n"), file_name);
9204 	  ret = 1;
9205 	  break;
9206 	}
9207 
9208       namealc = malloc (file_name_size + (nameend - name) + 3);
9209       if (namealc == NULL)
9210 	{
9211 	  error (_("Out of memory\n"));
9212 	  ret = 1;
9213 	  break;
9214 	}
9215 
9216       memcpy (namealc, file_name, file_name_size);
9217       namealc[file_name_size] = '(';
9218       memcpy (namealc + file_name_size + 1, name, nameend - name);
9219       namealc[file_name_size + 1 + (nameend - name)] = ')';
9220       namealc[file_name_size + 2 + (nameend - name)] = '\0';
9221 
9222       archive_file_offset = ftell (file);
9223       archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
9224 
9225       ret |= process_object (namealc, file);
9226 
9227       free (namealc);
9228 
9229       if (fseek (file,
9230 		 (archive_file_offset
9231 		  + archive_file_size
9232 		  + (archive_file_size & 1)),
9233 		 SEEK_SET) != 0)
9234 	{
9235 	  error (_("%s: failed to seek to next archive header\n"), file_name);
9236 	  ret = 1;
9237 	  break;
9238 	}
9239 
9240       got = fread (&arhdr, 1, sizeof arhdr, file);
9241       if (got != sizeof arhdr)
9242 	{
9243 	  if (got == 0)
9244 	    break;
9245 
9246 	  error (_("%s: failed to read archive header\n"), file_name);
9247 	  ret = 1;
9248 	  break;
9249 	}
9250     }
9251 
9252   if (longnames != 0)
9253     free (longnames);
9254 
9255   return ret;
9256 }
9257 
9258 static int
9259 process_file (char *file_name)
9260 {
9261   FILE *file;
9262   struct stat statbuf;
9263   char armag[SARMAG];
9264   int ret;
9265 
9266   if (stat (file_name, &statbuf) < 0)
9267     {
9268       if (errno == ENOENT)
9269 	error (_("'%s': No such file\n"), file_name);
9270       else
9271 	error (_("Could not locate '%s'.  System error message: %s\n"),
9272 	       file_name, strerror (errno));
9273       return 1;
9274     }
9275 
9276   if (! S_ISREG (statbuf.st_mode))
9277     {
9278       error (_("'%s' is not an ordinary file\n"), file_name);
9279       return 1;
9280     }
9281 
9282   file = fopen (file_name, "rb");
9283   if (file == NULL)
9284     {
9285       error (_("Input file '%s' is not readable.\n"), file_name);
9286       return 1;
9287     }
9288 
9289   if (fread (armag, SARMAG, 1, file) != 1)
9290     {
9291       error (_("%s: Failed to read file header\n"), file_name);
9292       fclose (file);
9293       return 1;
9294     }
9295 
9296   if (memcmp (armag, ARMAG, SARMAG) == 0)
9297     ret = process_archive (file_name, file);
9298   else
9299     {
9300       rewind (file);
9301       archive_file_size = archive_file_offset = 0;
9302       ret = process_object (file_name, file);
9303     }
9304 
9305   fclose (file);
9306 
9307   return ret;
9308 }
9309 
9310 #ifdef SUPPORT_DISASSEMBLY
9311 /* Needed by the i386 disassembler.  For extra credit, someone could
9312    fix this so that we insert symbolic addresses here, esp for GOT/PLT
9313    symbols.  */
9314 
9315 void
9316 print_address (unsigned int addr, FILE *outfile)
9317 {
9318   fprintf (outfile,"0x%8.8x", addr);
9319 }
9320 
9321 /* Needed by the i386 disassembler.  */
9322 void
9323 db_task_printsym (unsigned int addr)
9324 {
9325   print_address (addr, stderr);
9326 }
9327 #endif
9328 
9329 int
9330 main (int argc, char **argv)
9331 {
9332   int err;
9333 
9334 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9335   setlocale (LC_MESSAGES, "");
9336 #endif
9337 #if defined (HAVE_SETLOCALE)
9338   setlocale (LC_CTYPE, "");
9339 #endif
9340   bindtextdomain (PACKAGE, LOCALEDIR);
9341   textdomain (PACKAGE);
9342 
9343   expandargv (&argc, &argv);
9344 
9345   parse_args (argc, argv);
9346 
9347   if (num_dump_sects > 0)
9348     {
9349       /* Make a copy of the dump_sects array.  */
9350       cmdline_dump_sects = malloc (num_dump_sects);
9351       if (cmdline_dump_sects == NULL)
9352 	error (_("Out of memory allocating dump request table."));
9353       else
9354 	{
9355 	  memcpy (cmdline_dump_sects, dump_sects, num_dump_sects);
9356 	  num_cmdline_dump_sects = num_dump_sects;
9357 	}
9358     }
9359 
9360   if (optind < (argc - 1))
9361     show_name = 1;
9362 
9363   err = 0;
9364   while (optind < argc)
9365     err |= process_file (argv[optind++]);
9366 
9367   if (dump_sects != NULL)
9368     free (dump_sects);
9369   if (cmdline_dump_sects != NULL)
9370     free (cmdline_dump_sects);
9371 
9372   return err;
9373 }
9374